diff options
author | Freya Murphy <freya@freyacat.org> | 2024-10-20 16:49:11 -0400 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2024-10-20 16:49:11 -0400 |
commit | cec4fb7ede7fee7b5621c096f3d5a4863b7b484e (patch) | |
tree | 9f0af211e9b2f9035220d94d07cd8edf381f61c1 /src | |
parent | update john (diff) | |
download | website-cec4fb7ede7fee7b5621c096f3d5a4863b7b484e.tar.gz website-cec4fb7ede7fee7b5621c096f3d5a4863b7b484e.tar.bz2 website-cec4fb7ede7fee7b5621c096f3d5a4863b7b484e.zip |
refactor config and add allowed_hosts
Diffstat (limited to 'src')
-rw-r--r-- | src/web/_controller/_meta.php | 12 | ||||
-rw-r--r-- | src/web/_views/apps/blog_rss.php | 6 | ||||
-rw-r--r-- | src/web/_views/comments.php | 2 | ||||
-rw-r--r-- | src/web/_views/head.php | 4 | ||||
-rw-r--r-- | src/web/config.php | 42 | ||||
-rw-r--r-- | src/web/config/routes.php | 7 | ||||
-rw-r--r-- | src/web/config/style.php | 9 | ||||
-rw-r--r-- | src/web/core/core.php | 12 | ||||
-rw-r--r-- | src/web/core/model.php | 9 | ||||
-rw-r--r-- | src/web/core/router.php | 4 | ||||
-rw-r--r-- | src/web/index.php | 18 | ||||
-rw-r--r-- | src/web/lang/common.php | 8 |
12 files changed, 77 insertions, 56 deletions
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 @@ <rss version="2.0"> <channel> <title><?=lang('title')?></title> - <link><?=lang('root_url') . '/blog'?></link> + <link><?=$this->get_url('blog')?></link> <description><?=lang('blog_short_desc')?></description> <language><?=lang('lang_short')?></language> <?php @@ -12,8 +12,8 @@ echo '<title>' . $post['meta']['name'] . '</title>'; echo '<description>' . $post['meta']['desc'] . '</description>'; echo '<pubDate>' . $post['meta']['date'] . '</pubDate>'; - echo '<link>' . lang('root_url') . 'blog/post/' . $name . '</link>'; - echo '<guid>' . lang('root_url') . 'blog/post/' . $name . '</guid>'; + echo '<link>' . $this->get_url('blog/post/' . $name) . '</link>'; + echo '<guid>' . $this->get_url('blog/post/' . $name) . '</guid>'; echo '</item>'; } ?> 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 @@ ?> <div class="new"> <h3><?=lang('new_comment_title')?></h3> - <form id="new_comment" method="get" action="<?=lang('base_path') . '_comments/post'?>"> + <form id="new_comment" method="get" action="<?=$this->get_url('_comments/post')?>"> <div><input type="text" name="author" diff --git a/src/web/_views/head.php b/src/web/_views/head.php index ead45d6..ab7bb1b 100644 --- a/src/web/_views/head.php +++ b/src/web/_views/head.php @@ -6,12 +6,12 @@ <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="author" content="freya"> <meta name="description" content="<?=$desc?>"> - <meta name="theme-color" content="<?=lang('theme_color')?>"> + <meta name="theme-color" content="<?=CONFIG['theme_color']?>"> <meta name="referrer" content="origin"> <meta name="color-scheme" content="none"> <meta property="og:description" content="<?=$desc?>"> <meta property="og:title" content="<?=$title?>"> - <meta property="og:site_name" content="<?=lang('domain')?>"> + <meta property="og:site_name" content="<?=CONFIG['domain']?>"> <meta property="og:image" content="<?=$this->get_url('public/icons/logo640.png', TRUE)?>"> <title><?=$title?></title> <link rel="icon" type="image/png" sizes="16x16" href="<?=$this->get_url("public/icons/logo16.png", TRUE)?>"> 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 @@ +<?php /* Copyright (c) 2024 Freya Murphy */ + +// 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'); + +// CONFIG +// +// config values needed across the website + +define('CONFIG', array( + /* core config settings */ + 'domain' => '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 @@ -<?php /* Copyright (c) 2024 Freya Murphy */ -$routes = array(); -$routes[''] = 'home'; -$routes['robots.txt'] = '_meta/robots'; -$routes['sitemap.xml'] = '_meta/sitemap'; -$routes['manifest.json'] = '_meta/manifest'; -$routes['rss.xml'] = 'blog/rss'; diff --git a/src/web/config/style.php b/src/web/config/style.php deleted file mode 100644 index 33a0f8b..0000000 --- a/src/web/config/style.php +++ /dev/null @@ -1,9 +0,0 @@ -<?php /* Copyright (c) 2024 Freya Murphy */ -$style = array(); -$style['home'] = 'css/home.css'; -$style['blog'] = ['css/blog.css', 'css/prism.css']; -$style['error'] = 'css/error.css'; -$style['prism'] = 'css/prism.css'; - -$js = array(); -$js['blog'] = 'js/prism.js'; diff --git a/src/web/core/core.php b/src/web/core/core.php index feaecdf..4c341c2 100644 --- a/src/web/core/core.php +++ b/src/web/core/core.php @@ -43,10 +43,16 @@ abstract class Core { $host = $_SERVER['HTTP_HOST']; - if (ENVIRONMENT == 'production') - $host = lang('domain'); + if (ENVIRONMENT == 'production') { + $default = CONFIG['domain']; + $allowed = CONFIG['allowed_hosts']; + if (!is_array($allowed)) + $allowed = [$allowed]; + if (!in_array($host, $allowed)) + $host = $default; + } - $base = lang('base_path'); + $base = CONFIG['base_path']; $url = "{$scheme}://{$host}{$base}{$path}"; if ($timestamp) { $time = Core::asset_stamp($path); diff --git a/src/web/core/model.php b/src/web/core/model.php index c57fd5c..6a42a98 100644 --- a/src/web/core/model.php +++ b/src/web/core/model.php @@ -2,7 +2,10 @@ abstract class Model extends Component { - public static function get_base_data(?string $app = NULL): array + /** + * @return array<string,mixed> + */ + 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 @@ <?php /* Copyright (c) 2024 Freya Murphy */ -# things +# lang $lang['lang_short'] = 'en'; $lang['lang_full'] = 'en_US'; -$lang['domain'] = 'freya.cat'; -$lang['base_path'] = '/'; -$lang['root_url'] = sprintf("https://%s%s", $lang['domain'], $lang['base_path']); -$lang['git_url'] = 'https://g.freya.cat/freya'; -$lang['theme_color'] = '#181818'; - # names $lang['first_name'] = 'Freya'; $lang['last_name'] = 'Murphy'; |