From ba585f76169dd6488418e88cdaec6c6452d10949 Mon Sep 17 00:00:00 2001 From: Belle Aerni Date: Fri, 6 Jan 2023 14:17:33 -0800 Subject: [PATCH] Initial config support + force HTTPs --- composer.json | 5 ----- src/AntCMS/AntCache.php | 46 ++++++++++++++++++++++++++-------------- src/AntCMS/AntConfig.php | 35 ++++++++++++++++++++++++++++++ src/AntCMS/AntYaml.php | 14 ++++++++++-- src/Autoload.php | 2 +- src/index.php | 32 ++++++++++++++++++++++++++-- 6 files changed, 108 insertions(+), 26 deletions(-) create mode 100644 src/AntCMS/AntConfig.php diff --git a/composer.json b/composer.json index fc82e88..5cfbd25 100644 --- a/composer.json +++ b/composer.json @@ -7,11 +7,6 @@ "michelf/php-markdown": "^2.0", "symfony/yaml": "^6.0" }, - "autoload": { - "psr-4": { - "Belle\\AntCms\\": "src/" - } - }, "authors": [ { "name": "Belle Aerni", diff --git a/src/AntCMS/AntCache.php b/src/AntCMS/AntCache.php index 8d8b572..fd1f840 100644 --- a/src/AntCMS/AntCache.php +++ b/src/AntCMS/AntCache.php @@ -2,36 +2,50 @@ namespace AntCMS; +use AntCMS\AntConfig; + class AntCache { public function setCache($key, $content) { - $cachePath = AntCache . "/$key.cache"; - try { - $cache = fopen($cachePath, "w"); - - fwrite($cache, (string)$content); - fclose($cache); - return true; - } catch (\Exception $e) { - return false; + $cachePath = AntCachePath . "/$key.cache"; + $config = AntConfig::currentConfig(); + if ($config['enableCache']) { + try { + $cache = fopen($cachePath, "w"); + fwrite($cache, (string)$content); + fclose($cache); + return true; + } catch (\Exception $e) { + return false; + } } } public function getCache($key) { - $cachePath = AntCache . "/$key.cache"; - try { - $contents = file_get_contents($cachePath); - return $contents; - } catch (\Exception $e) { + $cachePath = AntCachePath . "/$key.cache"; + $config = AntConfig::currentConfig(); + if ($config['enableCache']) { + try { + $contents = file_get_contents($cachePath); + return $contents; + } catch (\Exception $e) { + return false; + } + } else { return false; } } public function isCached($key) { - $cachePath = AntCache . "/$key.cache"; - return file_exists($cachePath); + $config = AntConfig::currentConfig(); + if ($config['enableCache']) { + $cachePath = AntCachePath . "/$key.cache"; + return file_exists($cachePath); + } else { + return false; + } } } diff --git a/src/AntCMS/AntConfig.php b/src/AntCMS/AntConfig.php new file mode 100644 index 0000000..27a5f7f --- /dev/null +++ b/src/AntCMS/AntConfig.php @@ -0,0 +1,35 @@ + true, + 'activeTheme' => 'default', + 'generateKeywords' => true, + 'enableCache' => true, + 'admin' => array( + 'password' => '', + 'username' => '', + ), + 'debug' => true, + ); + + AntYaml::saveFile(antConfigFile, $defaultOptions); + } + + public static function currentConfig() + { + return AntYaml::parseFile(antConfigFile); + } + + public static function saveConfig($config) + { + AntYaml::saveFile(antConfigFile, $config); + } +} diff --git a/src/AntCMS/AntYaml.php b/src/AntCMS/AntYaml.php index 91d64fd..b801c0b 100644 --- a/src/AntCMS/AntYaml.php +++ b/src/AntCMS/AntYaml.php @@ -1,9 +1,19 @@ diff --git a/src/Autoload.php b/src/Autoload.php index 59f751c..4fe487a 100644 --- a/src/Autoload.php +++ b/src/Autoload.php @@ -1,6 +1,6 @@