From 862ff4e52ad52bcf352965c1bafcc48e4ceb643d Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Mon, 20 May 2024 18:56:50 -0400 Subject: [PATCH] fix simple php errors --- src/web/core/router.php | 14 +++++++++++++- src/web/helper/error.php | 2 +- src/web/lang/_bin/transpile.sh | 7 ++++--- src/web/lang/en_US/common_lang.php | 2 +- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/web/core/router.php b/src/web/core/router.php index 72c7674..557665b 100644 --- a/src/web/core/router.php +++ b/src/web/core/router.php @@ -66,10 +66,14 @@ class Router { * Gets the curret request info * @return array */ - private function get_req(): array { + private function get_req(): array|bool { $method = $_SERVER['REQUEST_METHOD']; $uri = parse_url($_SERVER['REQUEST_URI']); + if (!$uri) { + return FALSE; + } + $path = $uri['path']; return array_merge( @@ -100,9 +104,11 @@ class Router { die($code . ' (recursed)'); } + $this->main->info = array(); $this->main->info['slug'] = 'index'; $this->main->info['app'] = 'error'; $this->main->info['route'] = 'apps/error'; + $this->main->info['lang'] = $this->get_lang(); $req = $this->main->info; $_GET['code'] = $code; @@ -114,6 +120,12 @@ class Router { * @param bool $recursed */ private function handle_req($req, $recursed = FALSE): void { + + if ($req === FALSE) { + $this->handle_error(500, $recursed); + return; + } + $controller = $this->load->controller($req['route']); if ($controller === NULL) { diff --git a/src/web/helper/error.php b/src/web/helper/error.php index 6fcaddd..2b6959e 100644 --- a/src/web/helper/error.php +++ b/src/web/helper/error.php @@ -4,6 +4,6 @@ function error_page($code, $msg) { $root = $GLOBALS['webroot']; error_reporting(E_ERROR | E_PARSE); http_response_code($code); - require($root . '/views/template/error.php'); + require($root . '/_views/template/error.php'); die(); } diff --git a/src/web/lang/_bin/transpile.sh b/src/web/lang/_bin/transpile.sh index 18bb4c4..e6e826c 100755 --- a/src/web/lang/_bin/transpile.sh +++ b/src/web/lang/_bin/transpile.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env bash lang_part() { echo "$1" | awk "{split(\$0,a,\" = \"); print a[$2]}" @@ -10,7 +10,8 @@ handle_line() { left=$(lang_part "$line" 1) right=$(lang_part "$line" 2) echo "$left" | grep -Ev '_content|_line' > /dev/null - if [ "$?" -eq 0 ]; then + code=$? + if [ $code -eq 0 ]; then right=$(echo "$right" | uwuify) fi; right=${right%;}; @@ -23,7 +24,7 @@ transpile() { out="$2" printf "" > "$out" printf " "$out"; - cat "$file" | grep '$lang' | xargs -d'\n' -I {} bash -c 'handle_line "$@"' _ {} >> "$out" + grep "\$lang" < "$file" | xargs -d'\n' -I{} bash -c 'handle_line "$@"' _ {} >> "$out" } transpile "$1" "$2" diff --git a/src/web/lang/en_US/common_lang.php b/src/web/lang/en_US/common_lang.php index 4e5fd59..ef93ce8 100644 --- a/src/web/lang/en_US/common_lang.php +++ b/src/web/lang/en_US/common_lang.php @@ -1,6 +1,6 @@