From 6c14601ff31b3cdac1d56bce49e807dd6cc9106c Mon Sep 17 00:00:00 2001 From: Knah-Tsaeb Date: Fri, 6 Dec 2024 11:34:32 +0100 Subject: [PATCH] Move default template --- app/Cache.php | 4 ++-- app/Controllers/Dev.php | 2 +- app/Controllers/Home.php | 2 +- app/Controllers/Page.php | 2 +- app/Controllers/Post.php | 2 +- app/Controllers/Posts.php | 2 +- app/Router.php | 2 +- app/Utils/Config.php | 1 + public/index.php | 2 +- template/{ => default}/bone.php | 0 template/{ => default}/dev.php | 0 template/{ => default}/footer.php | 0 template/{ => default}/head.php | 0 template/{ => default}/home.php | 0 template/{ => default}/nav.php | 0 template/{ => default}/page.php | 0 template/{ => default}/post.php | 0 template/{ => default}/posts.php | 0 18 files changed, 10 insertions(+), 9 deletions(-) rename template/{ => default}/bone.php (100%) rename template/{ => default}/dev.php (100%) rename template/{ => default}/footer.php (100%) rename template/{ => default}/head.php (100%) rename template/{ => default}/home.php (100%) rename template/{ => default}/nav.php (100%) rename template/{ => default}/page.php (100%) rename template/{ => default}/post.php (100%) rename template/{ => default}/posts.php (100%) diff --git a/app/Cache.php b/app/Cache.php index 98439fe..535b564 100644 --- a/app/Cache.php +++ b/app/Cache.php @@ -38,11 +38,11 @@ class Cache { * @param array $params An associative array * @return bool Returns true if the cached page is still valid; otherwise, false */ - static function isValidPage(array $params): bool { + static function isValidPage(array $params, string $theme): bool { $mdModifiedTime = 0; // @todo add test if file exist if ($params['type'] === 'home') { - $mdModifiedTime = filemtime(self::$templateDir . '/home.php'); + $mdModifiedTime = filemtime(self::$templateDir . '/'.$theme.'/home.php'); } elseif ($params['type'] === 'post') { $postList = new Blogs($params); $postAttr = $postList->returnPostInfo($params['slug']); diff --git a/app/Controllers/Dev.php b/app/Controllers/Dev.php index 4717172..c073e74 100644 --- a/app/Controllers/Dev.php +++ b/app/Controllers/Dev.php @@ -81,7 +81,7 @@ class Dev { $postRegenCache = 'Post : regen'; } - require __DIR__ . '/../../template/dev.php'; + require __DIR__ . '/../../template/'.$params['config']['theme'].'/dev.php'; $content = ob_get_contents(); ob_end_clean(); return $content; diff --git a/app/Controllers/Home.php b/app/Controllers/Home.php index 4b74e43..c9d6d93 100644 --- a/app/Controllers/Home.php +++ b/app/Controllers/Home.php @@ -78,7 +78,7 @@ class Home { $homeContent = preg_replace("/<% lastAppsUpdates %>/", $lastAppsUpdates, $homeContent); $homeContent = preg_replace("/<% lastPics %>/", $lastPics, $homeContent); - require __DIR__ . '/../../template/home.php'; + require __DIR__ . '/../../template/'.$params['config']['theme'].'/home.php'; $content = ob_get_contents(); ob_end_clean(); return $content; diff --git a/app/Controllers/Page.php b/app/Controllers/Page.php index d0685a0..2d4f1ec 100644 --- a/app/Controllers/Page.php +++ b/app/Controllers/Page.php @@ -32,7 +32,7 @@ class Page { $pageContent = RenderHtml::markdownToHtml($pageContent); - require __DIR__ . '/../../template/page.php'; + require __DIR__ . '/../../template/'.$params['config']['theme'].'/page.php'; $content = ob_get_contents(); ob_end_clean(); diff --git a/app/Controllers/Post.php b/app/Controllers/Post.php index 23db9c4..aa0e9f9 100644 --- a/app/Controllers/Post.php +++ b/app/Controllers/Post.php @@ -26,7 +26,7 @@ class Post { $this->title = $postInfo['title']; $author = $params['config']['author']; - require __DIR__ . '/../../template/post.php'; + require __DIR__ . '/../../template/'.$params['config']['theme'].'/post.php'; $content = ob_get_contents(); ob_end_clean(); return $content; diff --git a/app/Controllers/Posts.php b/app/Controllers/Posts.php index f3395e0..728d055 100644 --- a/app/Controllers/Posts.php +++ b/app/Controllers/Posts.php @@ -39,7 +39,7 @@ class Posts { $getPostList = $posts->getFilesForPage($params['page']); $pagination = $posts->makePagination($params['page']); - require __DIR__ . '/../../template/posts.php'; + require __DIR__ . '/../../template/'.$params['config']['theme'].'/posts.php'; $content = ob_get_contents(); ob_end_clean(); return $content; diff --git a/app/Router.php b/app/Router.php index 176ff35..42e0edd 100644 --- a/app/Router.php +++ b/app/Router.php @@ -90,7 +90,7 @@ class Router { $content = call_user_func_array(array($controller_instance, 'index'), $params); $title = $controller_instance->title(); ob_start(); - require_once __DIR__ . '/../template/bone.php'; + require_once __DIR__ . '/../template/'.$params[0]['config']['theme'].'/bone.php'; $contentFinal = ob_get_contents(); ob_end_clean(); diff --git a/app/Utils/Config.php b/app/Utils/Config.php index 1b5f2ec..080399f 100644 --- a/app/Utils/Config.php +++ b/app/Utils/Config.php @@ -7,6 +7,7 @@ class Config { 'siteName' => 'My super page', 'author' => 'Me !!!', 'useCache' => false, + 'theme' => 'default', 'postPerPage' => 5, 'numberOfLastItem' => 5, 'debug' => false, diff --git a/public/index.php b/public/index.php index e16a76f..15dd1de 100644 --- a/public/index.php +++ b/public/index.php @@ -45,7 +45,7 @@ if (isset($match['params']['extraParams']['live']) && $match['params']['extraPar } if ($match) { - if (Cache::isCache($match['params']) && Cache::isValidPage($match['params']) && Cache::isValidConfig() && $config['useCache'] === true) { + if (Cache::isCache($match['params']) && Cache::isValidPage($match['params'], $config['theme']) && Cache::isValidConfig() && $config['useCache'] === true) { $gen = Cache::getCache($match['params']['cacheName'], $match['params']['type']); $genType = 'Serve from cache in : '; } else { diff --git a/template/bone.php b/template/default/bone.php similarity index 100% rename from template/bone.php rename to template/default/bone.php diff --git a/template/dev.php b/template/default/dev.php similarity index 100% rename from template/dev.php rename to template/default/dev.php diff --git a/template/footer.php b/template/default/footer.php similarity index 100% rename from template/footer.php rename to template/default/footer.php diff --git a/template/head.php b/template/default/head.php similarity index 100% rename from template/head.php rename to template/default/head.php diff --git a/template/home.php b/template/default/home.php similarity index 100% rename from template/home.php rename to template/default/home.php diff --git a/template/nav.php b/template/default/nav.php similarity index 100% rename from template/nav.php rename to template/default/nav.php diff --git a/template/page.php b/template/default/page.php similarity index 100% rename from template/page.php rename to template/default/page.php diff --git a/template/post.php b/template/default/post.php similarity index 100% rename from template/post.php rename to template/default/post.php diff --git a/template/posts.php b/template/default/posts.php similarity index 100% rename from template/posts.php rename to template/default/posts.php