From f373ead95fb5beb962c376b5b7b46dfde8ac4e57 Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Mon, 23 Feb 2026 22:57:27 -0500 Subject: update website to work with crimson framework --- src/web/lib/aria.php | 17 +++++++++ src/web/lib/hooks.php | 10 +++++ src/web/lib/ie.php | 32 ++++++++++++++++ src/web/lib/image.php | 96 ++++++++++++++++++++++++++++++++++++++++++++++++ src/web/lib/markdown.php | 36 ++++++++++++++++++ 5 files changed, 191 insertions(+) create mode 100644 src/web/lib/aria.php create mode 100644 src/web/lib/hooks.php create mode 100644 src/web/lib/ie.php create mode 100644 src/web/lib/image.php create mode 100644 src/web/lib/markdown.php (limited to 'src/web/lib') diff --git a/src/web/lib/aria.php b/src/web/lib/aria.php new file mode 100644 index 0000000..0e06b97 --- /dev/null +++ b/src/web/lib/aria.php @@ -0,0 +1,17 @@ +', + $id, $idh); + $out .= sprintf('

%s

', + $idh, $title); + } else { + $out .= sprintf('
', + $id); + } + return $out; +} diff --git a/src/web/lib/hooks.php b/src/web/lib/hooks.php new file mode 100644 index 0000000..70853e1 --- /dev/null +++ b/src/web/lib/hooks.php @@ -0,0 +1,10 @@ +load_controller('error'); + $error_controller->code($code); + CRIMSON_DIE(); +} diff --git a/src/web/lib/ie.php b/src/web/lib/ie.php new file mode 100644 index 0000000..ead6c1a --- /dev/null +++ b/src/web/lib/ie.php @@ -0,0 +1,32 @@ +\d+)/i', @$_SERVER['HTTP_USER_AGENT'], $B)) { + define('IE_VERSION', $B['v']); + } else { + define('IE_VERSION', FALSE); + } + + if (IE_VERSION == FALSE || IE_VERSION > 4) { + // ADD COND COMMENTS + define('IE_START', ""); + } else { + // IE4 DETECTED, DO NOT ADD COMMENTS + define('IE_START', ''); + define('IE_END', ''); + } +} + +function ie(string $inner) { + return IE_START . $inner . IE_END; +} + +function ie_ua(string $inner, int $ver) { + if (IE_VERSION == $ver) + return $inner; + return ''; +} diff --git a/src/web/lib/image.php b/src/web/lib/image.php new file mode 100644 index 0000000..7b6ec0e --- /dev/null +++ b/src/web/lib/image.php @@ -0,0 +1,96 @@ +', + $mime, $path, $media); +} + +function image( + $name, + $alt, + $formats = array('webp', 'png'), + $animated = FALSE, + $attrs = array(), + + $height = NULL, + $width = NULL, + $size = NULL) :string +{ + + if ($animated === TRUE) { + $animated = array('gif'); + } + + if (!$animated) { + $animated = array(); + } + + $out = ""; + + foreach ($formats as $format) { + $media = count($animated) ? '(prefers-reduced-motion: reduce)' : NULL; + $out .= __make_source($name, $format, $media); + } + + foreach ($animated as $format) { + $out .= __make_source($name, $format, NULL); + } + + $format = end($formats); + $path = Base::get_url('public/' . $name . '.' . $format, TRUE); + $out .= " $value) { + $out .= " $key=\"$value\""; + } + $out .= '>'; + + return $out; +} diff --git a/src/web/lib/markdown.php b/src/web/lib/markdown.php new file mode 100644 index 0000000..5279a1f --- /dev/null +++ b/src/web/lib/markdown.php @@ -0,0 +1,36 @@ +parsedown = new ParsedownExtra(); + } + + /** + * @return array + */ + function parse(string $path): array { + $content = file_get_contents($path); + $data = array( + 'meta' => array(), + 'content' => $content + ); + if (str_starts_with($content, '---')) { + $parts = explode('---', $content); + $data['content'] = trim(implode('---', array_slice($parts, 2))); + $meta = array_filter(explode("\n", $parts[1]), fn($x) => $x != ''); + foreach ($meta as $set) { + $parts = explode(": ", $set); + $key = trim($parts[0]); + $value = trim($parts[1]); + $data['meta'][$key] = $value; + } + + } + $data['content'] = $this->parsedown->text($data['content']); + return $data; + } + +} -- cgit v1.2.3-freya