diff options
Diffstat (limited to 'src/web/helper')
-rw-r--r-- | src/web/helper/error.php | 9 | ||||
-rw-r--r-- | src/web/helper/image.php | 77 | ||||
-rw-r--r-- | src/web/helper/lang.php | 81 |
3 files changed, 0 insertions, 167 deletions
diff --git a/src/web/helper/error.php b/src/web/helper/error.php deleted file mode 100644 index 2b6959e..0000000 --- a/src/web/helper/error.php +++ /dev/null @@ -1,9 +0,0 @@ -<?php /* Copyright (c) 2024 Freya Murphy */ - -function error_page($code, $msg) { - $root = $GLOBALS['webroot']; - error_reporting(E_ERROR | E_PARSE); - http_response_code($code); - require($root . '/_views/template/error.php'); - die(); -} diff --git a/src/web/helper/image.php b/src/web/helper/image.php deleted file mode 100644 index 6d42678..0000000 --- a/src/web/helper/image.php +++ /dev/null @@ -1,77 +0,0 @@ -<?php /* Copyright (c) 2024 Freya Murphy */ - -function image( - $src, - $class = NULL, - $link = NULL, - $click = NULL, - $height = NULL, - $width = NULL, - $mime = NULL, -): string { - if ($class) { - $class = 'image loading ' . $class; - } else { - $class = 'image loading'; - } - - $content = ''; - - // dont need mime for images - if ($mime && strpos($mime, 'image') !== FALSE) { - $mime = NULL; - } - - if ($link) { - $content .= '<a class="' . $class . '" href="' . $link . '">'; - } else if ($click) { - $content .= '<button class="' . $class . '" onclick="' . $click . '">'; - } else { - $content .= '<span class="' . $class . '">'; - } - if ($mime) { - $content .= '<object class="inner" type="' . $mime . '" data="' . $src . '" '; - } else { - $content .= '<img class="inner" src="' . $src . '" '; - } - if ($height) { - $content .= "height=\"{$height}\" "; - } - if ($width) { - $content .= "width=\"{$width}\" "; - } - if ($mime) { - $content .= '></object>'; - } else { - $content .= 'onerror="onImgError(this)" onload="onImgLoad(this)"/>'; - } - if ($link) { - $content .= '</a>'; - } else if ($click) { - $content .= '</button>'; - } else { - $content .= '</span>'; - } - - return $content; -} - -function pfp( - $user, - $link = TRUE, - $click = NULL -): string { - if ($link === TRUE) { - $link = '/profile?id=' . $user['id']; - } - $mime = NULL; - if (isset($user['avatar_mime'])) { - $mime = $user['avatar_mime']; - } - return image('/api/rpc/profile_avatar?user_id=' . $user['id'], - 'pfp', - link: $link, - click: $click, - mime: $mime - ); -} diff --git a/src/web/helper/lang.php b/src/web/helper/lang.php deleted file mode 100644 index 3397d63..0000000 --- a/src/web/helper/lang.php +++ /dev/null @@ -1,81 +0,0 @@ -<?php /* Copyright (c) 2024 Freya Murphy */ -$lang = array(); - -function lang($key, $default = NULL, $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 { - return $key; - } -} - -function ilang($key, - $class = NULL, - $style = NULL, - $id = NULL, - $href = NULL, - $click = NULL, - $attrs = array(), - $sub = NULL, - $button = FALSE, -) { - $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 '<button '; - } else { - echo '<a '; - } - if ($tip) { - echo 'title="' . $tip . '" '; - echo 'aria-label="' . $tip . '" '; - } - if ($class) { - echo 'class="' . $class . '" '; - } - if ($style) { - echo 'style="' . $style . '" '; - } - if ($id) { - echo 'id="' . $id . '" '; - } - if ($click) { - echo 'onclick="' . $click . '" '; - } - if ($href) { - echo 'href="' . $href . '" '; - } - foreach ($attrs as $key => $attr) { - echo $key . '="' . $attr . '" '; - } - echo '> '; - if ($icon) { - echo '<i class="' . $icon . '">'; - if ($content) { - echo $content; - } - echo '</i>'; - } - if ($text) { - echo '<span'; - if ($icon) { - echo ' style="margin-left: .5em;"'; - } - echo '>' . $text . '</span>'; - } - if ($click || $button) { - echo '</button>'; - } else { - echo '</a>'; - } -} |