diff options
author | Freya Murphy <freya@freyacat.org> | 2024-03-29 22:29:56 -0400 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2024-03-29 22:29:56 -0400 |
commit | 944b6b0526032ad8c1b4a2612d6723bec75e0e4c (patch) | |
tree | d3da5584df33a7878c087622b4fc2ec2883cf880 /web/index.php | |
download | xssbook2-944b6b0526032ad8c1b4a2612d6723bec75e0e4c.tar.gz xssbook2-944b6b0526032ad8c1b4a2612d6723bec75e0e4c.tar.bz2 xssbook2-944b6b0526032ad8c1b4a2612d6723bec75e0e4c.zip |
start database (user and post), and initial barebones home page
Diffstat (limited to 'web/index.php')
-rw-r--r-- | web/index.php | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/web/index.php b/web/index.php new file mode 100644 index 0000000..1032b7f --- /dev/null +++ b/web/index.php @@ -0,0 +1,122 @@ +<?php /* Copyright (c) 2024 Freya Murphy */ + +session_start(); + +$lang = array(); +$__vars = array(); +$webroot = dirname(__FILE__); + +function error_page($code, $msg) { + $root = $GLOBALS['webroot']; + error_reporting(E_ERROR | E_PARSE); + http_response_code($code); + require($root . '/core/error.php'); + die(); +} + +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>'; + } +} + +function __init() { + + $root = $GLOBALS['webroot']; + + // load all core files + require($root . '/core/database.php'); + require($root . '/core/aesthetic.php'); + require($root . '/core/controller.php'); + require($root . '/core/model.php'); + require($root . '/core/loader.php'); + require($root . '/core/main.php'); + require($root . '/core/router.php'); + + $main = new MainModel(); + $load = new Loader(); + $router = new Router($main, $load); + + $GLOBALS['__vars']['main'] = $main; + $GLOBALS['__vars']['load'] = $load; + $GLOBALS['__vars']['router'] = $router; + + $router->handle_request(); +}; + +if (!file_exists('/status/ready')) { + error_page(503, 'Service Unavailable'); +} + +__init(); + +?> |