From 52b077a48c743ba4d08ac00520a0bf1ef6deef5f Mon Sep 17 00:00:00 2001 From: Thomas Lange Date: Fri, 24 Feb 2017 21:27:59 +0100 Subject: Initial commit. --- core/namespace/Application.php | 148 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 core/namespace/Application.php (limited to 'core/namespace/Application.php') diff --git a/core/namespace/Application.php b/core/namespace/Application.php new file mode 100644 index 0000000..39cb522 --- /dev/null +++ b/core/namespace/Application.php @@ -0,0 +1,148 @@ +loadLanguage(ROOT.'template/'.self::get('TEMPLATE.NAME').'/lang/'.self::get('TEMPLATE.LANG').'.php'); + self::$Language = $Language; + } + + return self::$Language; + } + + #=============================================================================== + # Return unique CSRF token for the current session + #=============================================================================== + public static function getSecurityToken(): string { + if(!isset($_SESSION['token'])) { + $_SESSION['token'] = getRandomValue(); + } + + return $_SESSION['token']; + } + + #=============================================================================== + # Return boolean if successfully authenticated + #=============================================================================== + public static function isAuthenticated(): bool { + return isset($_SESSION['auth']); + } + + #=============================================================================== + # Return absolute base URL + #=============================================================================== + public static function getURL($more = ''): string { + $prot = self::get('PATHINFO.PROT'); + $host = self::get('PATHINFO.HOST'); + $base = self::get('PATHINFO.BASE'); + + return "{$prot}://{$host}/{$base}{$more}"; + } + + #=============================================================================== + # Return absolute root URL + #=============================================================================== + public static function getAdminURL($more = ''): string { + return self::getURL("admin/{$more}"); + } + + #=============================================================================== + # Return absolute post URL + #=============================================================================== + public static function getPostURL($more = ''): string { + return self::getURL(self::get('POST.DIRECTORY')."/{$more}"); + } + + #=============================================================================== + # Return absolute page URL + #=============================================================================== + public static function getPageURL($more = ''): string { + return self::getURL(self::get('PAGE.DIRECTORY')."/{$more}"); + } + + #=============================================================================== + # Return absolute user URL + #=============================================================================== + public static function getUserURL($more = ''): string { + return self::getURL(self::get('USER.DIRECTORY')."/{$more}"); + } + + #=============================================================================== + # Return absolute file URL + #=============================================================================== + public static function getFileURL($more = ''): string { + return self::getURL("rsrc/{$more}"); + } + + #=============================================================================== + # Return absolute template URL + #=============================================================================== + public static function getTemplateURL($more = ''): string { + $template = self::get('TEMPLATE.NAME'); + return Application::getURL("template/{$template}/{$more}"); + } + + #=============================================================================== + # Exit application with + #=============================================================================== + public static function exit($code = 500) { + http_response_code($code); + $code === 404 AND require_once(ROOT."system/404.php"); + exit(); + } +} +?> \ No newline at end of file -- cgit v1.2.3