2022-01-05 18:11:00 -05:00
|
|
|
<?php
|
2022-01-30 18:02:52 -05:00
|
|
|
namespace App\Helpers;
|
2022-01-05 18:11:00 -05:00
|
|
|
|
2022-09-25 13:53:00 -04:00
|
|
|
use App\Constants\Themes;
|
2022-01-05 18:11:00 -05:00
|
|
|
|
2022-09-25 13:53:00 -04:00
|
|
|
class Cookies {
|
2023-04-27 14:23:23 -04:00
|
|
|
public static function get(string $name, string $default_value = ''): string {
|
2022-01-05 18:11:00 -05:00
|
|
|
if (isset($_COOKIE[$name]) && !empty($_COOKIE[$name])) {
|
|
|
|
return $_COOKIE[$name];
|
|
|
|
}
|
2022-03-29 13:30:31 -04:00
|
|
|
return $default_value;
|
|
|
|
}
|
|
|
|
|
2023-04-27 14:23:23 -04:00
|
|
|
public static function theme(): string {
|
2022-03-29 13:30:31 -04:00
|
|
|
$theme = self::get('theme');
|
2022-09-25 13:53:00 -04:00
|
|
|
$ref = new \ReflectionClass(Themes::class);
|
|
|
|
$themes = $ref->getConstants();
|
|
|
|
if ($theme && in_array($theme, $themes)) {
|
2022-03-29 13:30:31 -04:00
|
|
|
return $theme;
|
|
|
|
}
|
|
|
|
return 'default';
|
2022-01-05 18:11:00 -05:00
|
|
|
}
|
|
|
|
|
2023-04-27 14:23:23 -04:00
|
|
|
public static function downloader(): string {
|
2022-09-25 13:53:00 -04:00
|
|
|
$downloader = self::get('api-downloader', 'default');
|
|
|
|
return $downloader;
|
|
|
|
}
|
|
|
|
|
2023-04-27 14:23:23 -04:00
|
|
|
public static function exists(string $name): bool {
|
2022-01-05 18:11:00 -05:00
|
|
|
return isset($_COOKIE[$name]);
|
|
|
|
}
|
|
|
|
|
2023-04-27 14:23:23 -04:00
|
|
|
public static function check(string $name, string $value): bool {
|
2022-06-28 14:41:51 -04:00
|
|
|
return self::exists($name) && $_COOKIE[$name] === $value;
|
|
|
|
}
|
|
|
|
|
2023-04-27 14:23:23 -04:00
|
|
|
public static function set(string $name, string $value) {
|
2022-01-28 09:54:09 -05:00
|
|
|
setcookie($name, $value, time()+60*60*24*30, '/', '', isset($_SERVER['HTTPS']), true);
|
2022-01-05 18:11:00 -05:00
|
|
|
}
|
|
|
|
};
|