summaryrefslogtreecommitdiff
path: root/web/helper
diff options
context:
space:
mode:
Diffstat (limited to 'web/helper')
-rw-r--r--web/helper/error.php9
-rw-r--r--web/helper/lang.php77
2 files changed, 86 insertions, 0 deletions
diff --git a/web/helper/error.php b/web/helper/error.php
new file mode 100644
index 0000000..6fcaddd
--- /dev/null
+++ b/web/helper/error.php
@@ -0,0 +1,9 @@
+<?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/web/helper/lang.php b/web/helper/lang.php
new file mode 100644
index 0000000..96944da
--- /dev/null
+++ b/web/helper/lang.php
@@ -0,0 +1,77 @@
+<?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,
+ $id = NULL,
+ $href = NULL,
+ $click = NULL,
+ $attrs = array(),
+ $sub = NULL,
+ $button = FALSE,
+) {
+ $text = lang($key . "_text", FALSE, sub: $sub);
+ $tip = lang($key . "_tip", FALSE);
+ $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 ($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 ' class="ml-sm"';
+ }
+ echo '>' . $text . '</span>';
+ }
+ if ($click) {
+ echo '</button>';
+ } else {
+ echo '</a>';
+ }
+}