diff options
| author | Freya Murphy <freya@freyacat.org> | 2026-02-23 22:57:27 -0500 |
|---|---|---|
| committer | Freya Murphy <freya@freyacat.org> | 2026-02-23 22:57:27 -0500 |
| commit | f373ead95fb5beb962c376b5b7b46dfde8ac4e57 (patch) | |
| tree | c99df23521ff2a5e5e2e4627c525a5e99dc2e3ae /src/web/core/core.php | |
| parent | add 96x96 logo (diff) | |
| download | website-f373ead95fb5beb962c376b5b7b46dfde8ac4e57.tar.gz website-f373ead95fb5beb962c376b5b7b46dfde8ac4e57.tar.bz2 website-f373ead95fb5beb962c376b5b7b46dfde8ac4e57.zip | |
update website to work with crimson framework
Diffstat (limited to 'src/web/core/core.php')
| -rw-r--r-- | src/web/core/core.php | 109 |
1 files changed, 0 insertions, 109 deletions
diff --git a/src/web/core/core.php b/src/web/core/core.php deleted file mode 100644 index 4c341c2..0000000 --- a/src/web/core/core.php +++ /dev/null @@ -1,109 +0,0 @@ -<?php /* Copyright (c) 2024 Freya Murphy */ - -/** - * Core functions needed everywhere - */ -abstract class Core { - - private static ?DatabaseHelper $db = NULL; - - /** - * Loads the database - */ - public static function db(): DatabaseHelper - { - if (!Component::$db) - Component::$db = new DatabaseHelper(); - return Component::$db; - } - - /** - * Gets the stamp for a asset path - * @param string $path - */ - public static function asset_stamp(string $path): int - { - if (ENVIRONMENT == 'devlopment') - return time(); - if (isset(FILE_TIMES[$path])) - return FILE_TIMES[$path]; - return 0; - } - - /** - * Gets a full path url from a relative path - * @param string $path - * @param bool $timestamp - */ - public static function get_url(string $path, bool $timestamp = FALSE): string - { - $scheme = 'http'; - if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) - $scheme = $_SERVER['HTTP_X_FORWARDED_PROTO']; - - $host = $_SERVER['HTTP_HOST']; - - if (ENVIRONMENT == 'production') { - $default = CONFIG['domain']; - $allowed = CONFIG['allowed_hosts']; - if (!is_array($allowed)) - $allowed = [$allowed]; - if (!in_array($host, $allowed)) - $host = $default; - } - - $base = CONFIG['base_path']; - $url = "{$scheme}://{$host}{$base}{$path}"; - if ($timestamp) { - $time = Core::asset_stamp($path); - $url .= "?timestamp={$time}"; - } - return $url; - } - - /** - * Loads a js html link - * @param string $path - the path to the js file - */ - public static function link_js(string $path): string - { - $stamp = Core::asset_stamp("public/$path"); - $href = Core::get_url("public/{$path}?timestamp={$stamp}"); - return '<script src="'. $href .'"></script>'; - } - - /** - * Loads a css html link - * @param string $path - the path to the css file - */ - public static function link_css(string $path): string - { - $stamp = Core::asset_stamp("public/$path"); - $href = Core::get_url("public/{$path}?timestamp={$stamp}"); - return '<link rel="stylesheet" href="'. $href .'">'; - } - - /** - * Loads a css html link - * @param string $path - the path to the css file - */ - public static function embed_css(string $path): string - { - $file = PUBLIC_ROOT . '/' . $path; - if (file_exists($file)) { - $text = file_get_contents($file); - return "<style>{$text}</style>"; - } else { - return ""; - } - } - - /** - * Formats a ISO date - * @param $iso_date the ISO date - */ - public static function format_date(string $iso_date): string - { - return date("Y-m-d D H:i", strtotime($iso_date)) . ' EST'; - } -} |