Merge pull request #1482 from kijin/pr/color-scheme

다크모드 감지 및 설정을 위한 rx_color_scheme 쿠키값의 표준화
This commit is contained in:
Kijin Sung 2020-12-15 01:59:17 +09:00 committed by GitHub
commit c275702fbf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 91 additions and 2 deletions

View file

@ -439,4 +439,41 @@ class UA
return 'filename="' . preg_replace('/\./', '%2e', $filename, substr_count($filename, '.') - 1) . '"';
}
}
/**
* Get the current color scheme (auto, 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 'auto';
}
}
/**
* Set the color scheme (auto, light, dark)
*
* @param string $color_scheme
* @return void
*/
public static function setColorScheme(string $color_scheme)
{
if (in_array($color_scheme, ['light', 'dark']))
{
$_COOKIE['rx_color_scheme'] = $color_scheme;
setcookie('rx_color_scheme', $color_scheme, time() + 86400 * 365, \RX_BASEURL, null, !!config('session.use_ssl_cookies'));
}
else
{
unset($_COOKIE['rx_color_scheme']);
setcookie('rx_color_scheme', 'deleted', time() - 86400, \RX_BASEURL, null);
}
}
}