From 2fc2775720daeb8d67f7c01b1091c1e7c0e96cba Mon Sep 17 00:00:00 2001 From: Belle Aerni Date: Sat, 7 Jan 2023 01:28:04 -0800 Subject: [PATCH] Slightly better theming support --- src/.htaccess | 7 ++++++- src/AntCMS/AntCMS.php | 10 ++++++++-- src/AntCMS/AntConfig.php | 2 +- src/AntCMS/AntKeywords.php | 6 ++++++ src/AntCMS/AntPages.php | 6 +++++- src/{Theme => Themes/Default}/default_layout.html | 0 src/index.php | 5 +++-- 7 files changed, 29 insertions(+), 7 deletions(-) rename src/{Theme => Themes/Default}/default_layout.html (100%) diff --git a/src/.htaccess b/src/.htaccess index 90ac1b8..2ac3258 100644 --- a/src/.htaccess +++ b/src/.htaccess @@ -1,2 +1,7 @@ RewriteEngine On -RewriteRule ^(.*)$ index.php [QSA,L] + +# If the requested file is an asset, serve it directly +RewriteCond %{REQUEST_FILENAME} -f +RewriteRule ^Theme/[^/]+/Assets/.+$ - [L] + +RewriteRule ^(.+)$ index.php [L,QSA] diff --git a/src/AntCMS/AntCMS.php b/src/AntCMS/AntCMS.php index 51c2a35..9b132a4 100644 --- a/src/AntCMS/AntCMS.php +++ b/src/AntCMS/AntCMS.php @@ -14,6 +14,7 @@ class AntCMS $start_time = microtime(true); $content = $this->getPage($page); $siteInfo = AntCMS::getSiteInfo(); + $currentConfig = AntConfig::currentConfig(); if (!$content || !is_array($content)) { $this->renderException("404"); @@ -31,10 +32,14 @@ class AntCMS $pageTemplate = str_replace('', $markdown, $pageTemplate); $pageTemplate = str_replace('', $siteInfo['siteTitle'], $pageTemplate); + $pageTemplate = str_replace('', '//' . $currentConfig['baseURL'], $pageTemplate); $end_time = microtime(true); $elapsed_time = round($end_time - $start_time, 4); - $pageTemplate = str_replace('', '

Took ' . $elapsed_time . ' seconds to render the page.', $pageTemplate); + + if($currentConfig['debug']){ + $pageTemplate = str_replace('', '

Took ' . $elapsed_time . ' seconds to render the page.

', $pageTemplate); + } echo $pageTemplate; exit; @@ -79,7 +84,8 @@ class AntCMS public function getThemeContent() { - $themePath = AntDir . "/Theme/default_layout.html"; + $currentConfig = AntConfig::currentConfig(); + $themePath = antThemePath . '/' . $currentConfig['activeTheme'] . "/default_layout.html"; $themeContent = file_get_contents($themePath); if (!$themeContent) { diff --git a/src/AntCMS/AntConfig.php b/src/AntCMS/AntConfig.php index 77587a7..da7edef 100644 --- a/src/AntCMS/AntConfig.php +++ b/src/AntCMS/AntConfig.php @@ -13,7 +13,7 @@ class AntConfig 'siteTitle' => 'AntCMS', ), 'forceHTTPS' => true, - 'activeTheme' => 'default', + 'activeTheme' => 'Default', 'generateKeywords' => true, 'enableCache' => true, 'admin' => array( diff --git a/src/AntCMS/AntKeywords.php b/src/AntCMS/AntKeywords.php index 6bf20c3..6a88ce2 100644 --- a/src/AntCMS/AntKeywords.php +++ b/src/AntCMS/AntKeywords.php @@ -3,6 +3,7 @@ namespace AntCMS; use AntCMS\AntCache; +use AntCMS\AntConfig; class AntKeywords { @@ -10,6 +11,11 @@ class AntKeywords { $cache = new AntCache(); $cacheKey = hash('sha3-512', $content).'keywords'; + $currentConfig = AntConfig::currentConfig(); + + if(!$currentConfig['generateKeywords']){ + return ''; + } if ($cache->isCached($cacheKey)) { $cachedKeywords = $cache->getCache($cacheKey); diff --git a/src/AntCMS/AntPages.php b/src/AntCMS/AntPages.php index 0841d13..b09a2e4 100644 --- a/src/AntCMS/AntPages.php +++ b/src/AntCMS/AntPages.php @@ -28,6 +28,7 @@ class AntPages 'pageTitle' => $pageHeader['title'], 'fullPagePath' => $page, 'functionalPagePath' => $pageFunctionalPath, + 'showInNav' => true, ); $pageList[] = $currentPage; } @@ -49,7 +50,10 @@ class AntPages '; $navHTML = ''; foreach (AntPages::getPages() as $page) { - $url = $_SERVER['REQUEST_SCHEME'] . "://" . str_replace('//', '/',$baseURL . $page['functionalPagePath']); + if(!$page['showInNav']){ + continue; + } + $url = "//" . str_replace('//', '/',$baseURL . $page['functionalPagePath']); $navEntry = str_replace('', $url, $navTemplate); $navEntry = str_replace('', $page['pageTitle'], $navEntry); $navHTML .= $navEntry; diff --git a/src/Theme/default_layout.html b/src/Themes/Default/default_layout.html similarity index 100% rename from src/Theme/default_layout.html rename to src/Themes/Default/default_layout.html diff --git a/src/index.php b/src/index.php index 0780ec4..06a6679 100644 --- a/src/index.php +++ b/src/index.php @@ -5,9 +5,10 @@ ini_set('display_errors', '1'); const AntDir = __DIR__; const AntCachePath = __DIR__ . '/Cache'; -const antConfigFile = __DIR__ . '/config.ymal'; -const antPagesList = __DIR__ . '/pages.ymal'; +const antConfigFile = __DIR__ . '/config.yaml'; +const antPagesList = __DIR__ . '/pages.yaml'; const antContentPath = __DIR__ . '/Content'; +const antThemePath = __DIR__ . '/Themes'; require_once __DIR__ . '/Vendor/autoload.php'; require_once __DIR__ . '/Autoload.php';