4in1_ws_web/lib/themes.php

50 lines
1.3 KiB
PHP

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