Cleaned up the code a bit

This commit is contained in:
Belle Aerni 2023-01-24 17:48:12 -08:00
parent 686caf149b
commit 95ed5059f0
3 changed files with 21 additions and 37 deletions

View file

@ -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',

View file

@ -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);
}
}

View file

@ -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) {