ch1p_io_web/lib/themes.php
2024-01-31 20:45:40 +03:00

42 lines
830 B
PHP

<?php
const THEMES = [
'dark' => [
'bg' => 0x222222,
// 'alpha' => 0x303132,
'alpha' => 0x222222,
],
'light' => [
'bg' => 0xffffff,
// 'alpha' => 0xf2f2f2,
'alpha' => 0xffffff,
]
];
function getThemes(): array {
return array_keys(THEMES);
}
function themeExists(string $name): bool {
return array_key_exists($name, THEMES);
}
function getThemeAlphaColorAsRGB(string $name): array {
$color = THEMES[$name]['alpha'];
$r = ($color >> 16) & 0xff;
$g = ($color >> 8) & 0xff;
$b = $color & 0xff;
return [$r, $g, $b];
}
function getUserTheme(): string {
if (isset($_COOKIE['theme'])) {
$val = $_COOKIE['theme'];
if (is_array($val))
$val = implode($val);
} else
$val = 'auto';
return $val;
}