"Dutch (Netherlands)", "en_GB" => "English (United Kingdom)", "es_ES" => "Spanish (Spain)", ]; } public static function addAlert($class, $message) { $alerts = $_SESSION["alerts"] ?? []; $alerts[] = [$class, $message]; $_SESSION["alerts"] = $alerts; } public static function addBreadcrumb($url, $name) { Core::$breadcrumbs[] = [$url, $name]; } public static function addScript($path) { Core::$scripts[] = $path; // Path is relative to root directory } public static function getScripts() { return Core::$scripts; } public static function getAlerts() { $alerts = $_SESSION["alerts"] ?? []; unset($_SESSION["alerts"]); return $alerts; } public static function requireLogIn() { if(!Core::$user) { $_SESSION["log_in_redirect_uri"] = $_SERVER["REQUEST_URI"]; http::redirect("/log-in"); } } public static function requireTerms() { Core::requireLogIn(); if(Core::$user->terms_accepted == false) { Core::addAlert("danger", "You must accept Terms and Conditions to view this page."); http::redirect("/account"); } } public static function requireAdmin() { Core::requireLogIn(); if(Core::$user->canAdmin() === false) { throw new Exception("No permission to access this page."); } } public static function requireUserLevel($level) { Core::requireLogIn(); if(Core::$user->level < $level) { throw new Exception("No permission to access this page."); } } public static function isLoggedIn() { return !empty($_SESSION["user_id"]); } public static function validateCSRFToken($token) { if($_SESSION["csrf_token"] !== $token) throw new Exception("CSRF attempt blocked."); return true; } public static function refuseAJAX() { if(HTTP::isAJAX()) { header("HTTP/1.1 403 Forbidden"); throw new Exception("AJAX calls not allowed."); } } } ?>