Add rx_color_scheme cookie for detecting and setting color scheme

This commit is contained in:
Kijin Sung 2020-12-11 20:35:22 +09:00
parent 6d4fe58c2f
commit 9fffc050b4
4 changed files with 57 additions and 0 deletions

View file

@ -2683,6 +2683,41 @@ class Context
{
return self::$_instance->canonical_url;
}
/**
* Get the current color scheme (none, light, dark)
*
* @return string
*/
public static function getColorScheme(): string
{
if (isset($_COOKIE['rx_color_scheme']) && in_array($_COOKIE['rx_color_scheme'], ['light', 'dark']))
{
return strval($_COOKIE['rx_color_scheme']);
}
else
{
return 'none';
}
}
/**
* Set the color scheme (none, light, dark)
*
* @param string $color_scheme
* @return void
*/
public static function setColorScheme(string $color_scheme)
{
if (in_array($color_scheme, ['light', 'dark']))
{
setcookie('rx_color_scheme', $color_scheme, time() + 86400 * 365, \RX_BASEURL, null, !!config('session.use_ssl_cookies'));
}
else
{
setcookie('rx_color_scheme', 'deleted', time() - 86400, \RX_BASEURL, null);
}
}
}
/* End of file Context.class.php */
/* Location: ./classes/context/Context.class.php */