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/helpers/aria.php | 17 --- src/web/helpers/database.php | 323 ------------------------------------------- src/web/helpers/ie.php | 32 ----- src/web/helpers/image.php | 94 ------------- src/web/helpers/lang.php | 90 ------------ src/web/helpers/markdown.php | 36 ----- src/web/helpers/sanitize.php | 8 -- 7 files changed, 600 deletions(-) delete mode 100644 src/web/helpers/aria.php delete mode 100644 src/web/helpers/database.php delete mode 100644 src/web/helpers/ie.php delete mode 100644 src/web/helpers/image.php delete mode 100644 src/web/helpers/lang.php delete mode 100644 src/web/helpers/markdown.php delete mode 100644 src/web/helpers/sanitize.php (limited to 'src/web/helpers') diff --git a/src/web/helpers/aria.php b/src/web/helpers/aria.php deleted file mode 100644 index 0e06b97..0000000 --- a/src/web/helpers/aria.php +++ /dev/null @@ -1,17 +0,0 @@ -', - $id, $idh); - $out .= sprintf('

%s

', - $idh, $title); - } else { - $out .= sprintf('
', - $id); - } - return $out; -} diff --git a/src/web/helpers/database.php b/src/web/helpers/database.php deleted file mode 100644 index 82c711d..0000000 --- a/src/web/helpers/database.php +++ /dev/null @@ -1,323 +0,0 @@ -conn = $conn; - $this->query = ''; - - $this->set = FALSE; - $this->where = FALSE; - $this->param = array(); - } - - /// - /// ARBITRARY QUERY - /// - - public function query(string $query): DatabaseQuery - { - $this->query .= $query; - return $this; - } - - /// - /// SELECT - /// - - public function select(string $select): DatabaseQuery - { - $this->query .= "SELECT $select\n"; - return $this; - } - - public function from(string $from): DatabaseQuery - { - $this->query .= "FROM $from\n"; - return $this; - } - - /// - /// INSERT - /// - - public function insert_into(string $insert, string ...$columns): DatabaseQuery - { - $this->query .= "INSERT INTO $insert\n ("; - foreach ($columns as $idx => $column) { - if ($idx !== 0) { - $this->query .= ","; - } - $this->query .= $column; - } - $this->query .= ")\n"; - return $this; - } - - public function values(mixed ...$values): DatabaseQuery - { - $this->query .= "VALUES ("; - foreach ($values as $idx => $value) { - if ($idx !== 0) { - $this->query .= ","; - } - $this->query .= "?"; - array_push($this->param, $value); - } - $this->query .= ")\n"; - return $this; - } - - /// - /// WHERE - /// - - public function where(string $cond): DatabaseQuery - { - if (!$this->where) { - $this->where = TRUE; - $this->query .= "WHERE "; - } else { - $this->query .= "AND "; - } - $this->query .= "$cond "; - return $this; - } - - /** - * @param array $array - */ - public function where_in(string $column, array $array): DatabaseQuery - { - if (!$this->where) { - $this->where = TRUE; - $this->query .= "WHERE "; - } else { - $this->query .= "AND "; - } - if (empty($array)) { - $this->query .= "FALSE\n"; - return $this; - } - $in = $this->in($array); - $this->query .= "$column $in\n"; - return $this; - } - - /** - * @param array $array - */ - private function in(array $array): DatabaseQuery - { - $in = 'IN ('; - foreach ($array as $idx => $item) { - if ($idx != 0) { - $in .= ","; - } - $in .= "?"; - array_push($this->param, $item); - } - $in .= ")"; - return $in; - } - - /// - /// OPERATORS - /// - - public function like(mixed $item): DatabaseQuery - { - $this->query .= "LIKE ?\n"; - array_push($this->param, $item); - return $this; - } - - public function eq(mixed $item): DatabaseQuery - { - $this->query .= "= ?\n"; - array_push($this->param, $item); - return $this; - } - - public function ne(mixed $item): DatabaseQuery - { - $this->query .= "<> ?\n"; - array_push($this->param, $item); - return $this; - } - - public function lt(mixed $item): DatabaseQuery - { - $this->query .= "< ?\n"; - array_push($this->param, $item); - return $this; - } - - public function le(mixed $item): DatabaseQuery - { - $this->query .= "<= ?\n"; - array_push($this->param, $item); - return $this; - } - - /// - /// JOINS - /// - - public function join(string $table, string $on, string $type = 'LEFT'): DatabaseQuery - { - $this->query .= "$type JOIN $table ON $on\n"; - return $this; - } - - /// - /// LIMIT, OFFSET, ORDER - /// - - public function limit(int $limit): DatabaseQuery - { - $this->query .= "LIMIT ?\n"; - array_push($this->param, $limit); - return $this; - } - - public function offset(int $offset): DatabaseQuery - { - $this->query .= "OFFSET ?\n"; - array_push($this->param, $offset); - return $this; - } - - public function order_by(string $column, string $order = 'ASC'): DatabaseQuery - { - $this->query .= "ORDER BY " . $column . ' ' . $order . ' '; - return $this; - } - - /// - /// COLLECT - /// - - public function rows(mixed ...$params): ?array - { - $args = $this->param; - foreach ($params as $param) { - array_push($args, $param); - } - $stmt = $this->conn->prepare($this->query); - try { - $stmt->execute($args); - } catch (Exception $ex) { - echo $ex; - echo '
>> caused by <<
'; - echo str_replace("\n", "
", $this->query); - } - return __nullify($stmt->fetchAll(PDO::FETCH_ASSOC)); - } - - public function row(mixed ...$params): ?array - { - $args = $this->param; - foreach ($params as $param) { - array_push($args, $param); - } - $stmt = $this->conn->prepare($this->query); - $stmt->execute($args); - return __nullify($stmt->fetch(PDO::FETCH_ASSOC)); - } - - public function execute(mixed ...$params): bool - { - $args = $this->param; - foreach ($params as $param) { - array_push($args, $param); - } - $stmt = $this->conn->prepare($this->query); - try { - $stmt->execute($args); - return TRUE; - } catch (Exception $_e) { - echo $_e; - echo '
>> caused by <<
'; - echo str_replace("\n", "
", $this->query); - return FALSE; - } - } -} - -/** - * DatabaseHelper - * allows queries on the - * postgres database - */ -class DatabaseHelper { - - private ?\PDO $conn; - - function __construct() - { - $this->conn = NULL; - } - - private function connect(): \PDO - { - if ($this->conn === NULL) { - $user = getenv("POSTGRES_USER"); - $pass = getenv("POSTGRES_PASSWORD"); - $db = getenv("POSTGRES_DB"); - $host = 'db'; - $port = '5432'; - - $conn_str = sprintf("pgsql:host=%s;port=%d;dbname=%s;user=%s;password=%s", - $host, - $port, - $db, - $user, - $pass - ); - $this->conn = new \PDO($conn_str); - $this->conn->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); - } - return $this->conn; - } - - public function select(string $select): DatabaseQuery - { - $conn = $this->connect(); - $query = new DatabaseQuery($conn); - return $query->select($select); - } - - public function insert_into(string $insert, string ...$columns): DatabaseQuery - { - $conn = $this->connect(); - $query = new DatabaseQuery($conn); - return $query->insert_into($insert, ...$columns); - } - - public function query(string $query_str): DatabaseQuery - { - $conn = $this->connect(); - $query = new DatabaseQuery($conn); - return $query->query($query_str); - } -} - diff --git a/src/web/helpers/ie.php b/src/web/helpers/ie.php deleted file mode 100644 index ead6c1a..0000000 --- a/src/web/helpers/ie.php +++ /dev/null @@ -1,32 +0,0 @@ -\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/helpers/image.php b/src/web/helpers/image.php deleted file mode 100644 index d4683fe..0000000 --- a/src/web/helpers/image.php +++ /dev/null @@ -1,94 +0,0 @@ -', - $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 = Core::get_url('public/' . $name . '.' . $format, TRUE); - $out .= " $value) { - $out .= " $key=\"$value\""; - } - $out .= '>'; - - return $out; -} diff --git a/src/web/helpers/lang.php b/src/web/helpers/lang.php deleted file mode 100644 index 72167fc..0000000 --- a/src/web/helpers/lang.php +++ /dev/null @@ -1,90 +0,0 @@ - $sub - */ -function lang( - string $key, - ?string $default = NULL, - ?array $sub = NULL) { - $lang = $GLOBALS['__lang']; - if(array_key_exists($key, $lang)) { - if ($sub) { - return sprintf($lang[$key], ...$sub); - } else { - return $lang[$key]; - } - } else if ($default !== NULL) { - return $default; - } else { - trigger_error('Undefined lang string: ' . $key, E_USER_WARNING); - return $key; - } -} - -/** - * @param array $attrs - * @param ?array $sub - */ -function ilang( - string $key, - ?string $class = NULL, - ?string $id = NULL, - ?string $href = NULL, - ?string $click = NULL, - array $attrs = array(), - ?array $sub = NULL, - bool $button = FALSE, - string $container = 'span' -) { - $text = ucfirst(lang($key . "_text", FALSE, sub: $sub)); - $tip = lang($key . "_tip", FALSE, sub: $sub); - $icon = lang($key . "_icon", FALSE); - $content = lang($key . "_content", FALSE); - - if ($click || $button) { - echo ''; - } else { - echo ''; - } -} diff --git a/src/web/helpers/markdown.php b/src/web/helpers/markdown.php deleted file mode 100644 index 5279a1f..0000000 --- a/src/web/helpers/markdown.php +++ /dev/null @@ -1,36 +0,0 @@ -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; - } - -} diff --git a/src/web/helpers/sanitize.php b/src/web/helpers/sanitize.php deleted file mode 100644 index 495c249..0000000 --- a/src/web/helpers/sanitize.php +++ /dev/null @@ -1,8 +0,0 @@ -', '>', $data); - return $data; -} -- cgit v1.2.3-freya