From cec4fb7ede7fee7b5621c096f3d5a4863b7b484e Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Sun, 20 Oct 2024 16:49:11 -0400 Subject: [PATCH] refactor config and add allowed_hosts --- src/web/_controller/_meta.php | 12 +++++---- src/web/_views/apps/blog_rss.php | 6 ++--- src/web/_views/comments.php | 2 +- src/web/_views/head.php | 4 +-- src/web/config.php | 42 ++++++++++++++++++++++++++++++++ src/web/config/routes.php | 7 ------ src/web/config/style.php | 9 ------- src/web/core/core.php | 12 ++++++--- src/web/core/model.php | 9 ++++--- src/web/core/router.php | 4 +-- src/web/index.php | 18 +++----------- src/web/lang/common.php | 8 +----- 12 files changed, 77 insertions(+), 56 deletions(-) create mode 100644 src/web/config.php delete mode 100644 src/web/config/routes.php delete mode 100644 src/web/config/style.php diff --git a/src/web/_controller/_meta.php b/src/web/_controller/_meta.php index 4500175..9ea3f47 100644 --- a/src/web/_controller/_meta.php +++ b/src/web/_controller/_meta.php @@ -48,9 +48,11 @@ class _meta_controller extends Controller { public function manifest(): void { + $domain = CONFIG['domain']; + $theme_color = CONFIG['theme_color']; $json = array( - 'short_name' => lang('domain'), - 'name' => lang('domain'), + 'short_name' => $domain, + 'name' => $domain, 'icons' => [ array( 'src' => $this->get_url('public/icons/logo512.png'), @@ -61,10 +63,10 @@ class _meta_controller extends Controller { ], 'id' => $this->get_url('home'), 'start_url' => $this->get_url('home'), - 'background_color' => lang('theme_color'), + 'background_color' => $theme_color, 'display' => 'standalone', - 'scope' => lang('base_path'), - 'theme_color' => lang('theme_color'), + 'scope' => CONFIG['base_path'], + 'theme_color' => $theme_color, 'shortcuts' => [], 'description' => lang('default_short_desc'), 'screenshots' => [] diff --git a/src/web/_views/apps/blog_rss.php b/src/web/_views/apps/blog_rss.php index e112389..121b747 100644 --- a/src/web/_views/apps/blog_rss.php +++ b/src/web/_views/apps/blog_rss.php @@ -2,7 +2,7 @@ <?=lang('title')?> - + get_url('blog')?> ' . $post['meta']['name'] . ''; echo '' . $post['meta']['desc'] . ''; echo '' . $post['meta']['date'] . ''; - echo '' . lang('root_url') . 'blog/post/' . $name . ''; - echo '' . lang('root_url') . 'blog/post/' . $name . ''; + echo '' . $this->get_url('blog/post/' . $name) . ''; + echo '' . $this->get_url('blog/post/' . $name) . ''; echo ''; } ?> diff --git a/src/web/_views/comments.php b/src/web/_views/comments.php index 0828753..d566549 100644 --- a/src/web/_views/comments.php +++ b/src/web/_views/comments.php @@ -17,7 +17,7 @@ ?>

-
+
- + - + <?=$title?> "> diff --git a/src/web/config.php b/src/web/config.php new file mode 100644 index 0000000..8689b8e --- /dev/null +++ b/src/web/config.php @@ -0,0 +1,42 @@ + 'freya.cat', + 'allowed_hosts' => ['freya.cat', 'www.freya.cat'], + 'base_path' => '/', + 'theme_color' => '#181818', + 'git_url' => 'https://g.freya.cat/freya', + /* route overides */ + 'routes' => array( + '' => 'home', + 'robots.txt' => '_meta/robots', + 'sitemap.xml' => '_meta/sitemap', + 'manifest.json' => '_meta/manifest', + 'rss.xml' => 'blog/rss', + ), + /* css to load on each route */ + 'style' => array( + 'home' => 'css/home.css', + 'blog' => ['css/blog.css', 'css/prism.css'], + 'error' => 'css/error.css', + ), + /* js to load on each route */ + 'js' => array( + 'blog' => 'js/prism.js', + ), +)); diff --git a/src/web/config/routes.php b/src/web/config/routes.php deleted file mode 100644 index 1fc3b67..0000000 --- a/src/web/config/routes.php +++ /dev/null @@ -1,7 +0,0 @@ - + */ + public static function get_base_data(?string $app = NULL): array { $data = array(); $data['title'] = lang('first_name'); @@ -10,8 +13,8 @@ abstract class Model extends Component { $data['css'] = array(); $data['js'] = array(); - $style = $GLOBALS['style']; - $js = $GLOBALS['js']; + $style = CONFIG['style']; + $js = CONFIG['js']; if (!$app) $app = CONTEXT['app']; diff --git a/src/web/core/router.php b/src/web/core/router.php index 2cda384..a1307cf 100644 --- a/src/web/core/router.php +++ b/src/web/core/router.php @@ -30,7 +30,8 @@ class Router extends Component { $path = substr($path, 1); // get modified route - foreach ($GLOBALS['routes'] as $key => $value) { + $routes = CONFIG['routes']; + foreach ($routes as $key => $value) { $key = "/^{$key}$/"; if (!preg_match($key, $path, $matches)) continue; @@ -83,7 +84,6 @@ class Router extends Component { 'args' => array_slice($parts, 2), ); - $routes = $GLOBALS['routes']; if (isset($routes[$path])) { $parts = explode('/', $routes[$path]); if (count($parts) == 1) { diff --git a/src/web/index.php b/src/web/index.php index 6b4bf06..c0ed0ef 100644 --- a/src/web/index.php +++ b/src/web/index.php @@ -6,16 +6,6 @@ ini_set('html_errors', '1'); ini_set('browscap', 'browscap.ini'); date_default_timezone_set('America/New_York'); -// ENVIRONMENT -// -// devlopment - do not cache any assets -// - use http host provided by user -// -// production - use generated timestamps for each file -// - hard code http host to 'domain' lang string -// -define('ENVIRONMENT', 'devlopment'); - // FOLDER_ROOT // // define folder directiroy paths based on this file @@ -26,14 +16,13 @@ define('PUBLIC_ROOT', PHP_ROOT . '/public'); // ========================== BOOTSTRAP == +// load the config +require(WEB_ROOT . '/config.php'); + // load all third party require(WEB_ROOT . '/third_party/parsedown.php'); require(WEB_ROOT . '/third_party/parsedown_extra.php'); -// load all the config files -require(WEB_ROOT . '/config/routes.php'); -require(WEB_ROOT . '/config/style.php'); - // load all the helpers require(WEB_ROOT . '/helpers/ie.php'); require(WEB_ROOT . '/helpers/lang.php'); @@ -50,6 +39,7 @@ require(WEB_ROOT . '/core/controller.php'); require(WEB_ROOT . '/core/model.php'); require(WEB_ROOT . '/core/router.php'); + // load file stamps require(WEB_ROOT . '/stamp.php'); diff --git a/src/web/lang/common.php b/src/web/lang/common.php index 8101138..a256ee8 100644 --- a/src/web/lang/common.php +++ b/src/web/lang/common.php @@ -1,15 +1,9 @@