From 95ed5059f0effb0af1d96ee2552ef6997cfdfe40 Mon Sep 17 00:00:00 2001 From: Belle Aerni Date: Tue, 24 Jan 2023 17:48:12 -0800 Subject: [PATCH] Cleaned up the code a bit --- src/AntCMS/AntCMS.php | 11 +---------- src/AntCMS/AntTools.php | 17 ++++++++++++++++- src/Plugins/Admin/AdminPlugin.php | 30 ++++-------------------------- 3 files changed, 21 insertions(+), 37 deletions(-) diff --git a/src/AntCMS/AntCMS.php b/src/AntCMS/AntCMS.php index b79a528..5cca43e 100644 --- a/src/AntCMS/AntCMS.php +++ b/src/AntCMS/AntCMS.php @@ -3,7 +3,6 @@ namespace AntCMS; use AntCMS\AntMarkdown; -use AntCMS\AntKeywords; use AntCMS\AntPages; use AntCMS\AntConfig; @@ -90,14 +89,7 @@ class AntCMS public function getPage(string $page) { $page = strtolower($page); - $pagePath = AntDir . "/Content/{$page}"; - $pagePath = AntTools::repairFilePath($pagePath); - - if (is_dir($pagePath)) { - $pagePath .= '/index.md'; - } else { - $pagePath = (file_exists($pagePath)) ? $pagePath : $pagePath . '.md'; - } + $pagePath = AntTools::convertFunctionaltoFullpath($page); if (file_exists($pagePath)) { try { @@ -173,7 +165,6 @@ class AntCMS */ public static function getPageHeaders(string $pageContent) { - $AntKeywords = new AntKeywords(); $pageHeaders = [ 'title' => 'AntCMS', 'author' => 'AntCMS', diff --git a/src/AntCMS/AntTools.php b/src/AntCMS/AntTools.php index d74ed75..36a89c5 100644 --- a/src/AntCMS/AntTools.php +++ b/src/AntCMS/AntTools.php @@ -20,7 +20,7 @@ class AntTools $files[] = ($returnPath) ? $file->getPathname() : $file->getFilename(); } } - + return $files; } @@ -54,4 +54,19 @@ class AntTools return str_replace('//', '/', $newURL); } + + public static function convertFunctionaltoFullpath(string $path) + { + $pagePath = AntTools::repairFilePath(antContentPath . '/' . $path); + + if (is_dir($pagePath)) { + $pagePath .= '/index.md'; + } + + if (!str_ends_with($pagePath, ".md")) { + $pagePath .= '.md'; + } + + return AntTools::repairFilePath($pagePath); + } } diff --git a/src/Plugins/Admin/AdminPlugin.php b/src/Plugins/Admin/AdminPlugin.php index 9658a34..109dff1 100644 --- a/src/Plugins/Admin/AdminPlugin.php +++ b/src/Plugins/Admin/AdminPlugin.php @@ -149,14 +149,7 @@ class AdminPlugin extends AntPlugin case 'edit': if (!isset($_POST['newpage'])) { array_shift($route); - $pagePath = implode('/', $route); - $pagePath = AntTools::repairFilePath(antContentPath . '/' . $pagePath); - - if (empty($pagePath) || is_dir($pagePath)) { - $pagePath .= '/index.md'; - } - $pagePath = (file_exists($pagePath)) ? $pagePath : $pagePath . '.md'; - $pagePath = AntTools::repairFilePath($pagePath); + $pagePath = AntTools::convertFunctionaltoFullpath(implode('/', $route)); $page = file_get_contents($pagePath); @@ -179,6 +172,7 @@ class AdminPlugin extends AntPlugin case 'save': array_shift($route); $pagePath = AntTools::repairFilePath(antContentPath . '/' . implode('/', $route)); + if (!isset($_POST['textarea'])) { header('Location: //' . AntConfig::currentConfig('baseURL') . "plugin/admin/pages/"); } @@ -200,15 +194,7 @@ class AdminPlugin extends AntPlugin case 'delete': array_shift($route); - $pagePath = AntTools::repairFilePath(antContentPath . '/' . implode('/', $route)); - - if (empty($pagePath) || is_dir($pagePath)) { - $pagePath .= '/index.md'; - } - - if (!str_ends_with($pagePath, ".md")) { - $pagePath .= '.md'; - } + $pagePath = AntTools::convertFunctionaltoFullpath(implode('/', $route)); // Find the key associated with the functional page path, then remove it from our temp pages array foreach ($pages as $key => $page) { @@ -228,15 +214,7 @@ class AdminPlugin extends AntPlugin case 'togglevisibility': array_shift($route); - $pagePath = AntTools::repairFilePath(antContentPath . '/' . implode('/', $route)); - - if (empty($pagePath) || is_dir($pagePath)) { - $pagePath .= '/index.md'; - } - - if (!str_ends_with($pagePath, ".md")) { - $pagePath .= '.md'; - } + $pagePath = AntTools::convertFunctionaltoFullpath(implode('/', $route)); foreach ($pages as $key => $page) { if ($page['fullPagePath'] == $pagePath) {