diff --git a/brain/api/v1/SettingsAPI.inc.php b/brain/api/v1/SettingsAPI.inc.php new file mode 100644 index 0000000..291a958 --- /dev/null +++ b/brain/api/v1/SettingsAPI.inc.php @@ -0,0 +1,52 @@ + "Welcome to Fucking Fipamo", + "status" => false, + ]; + + $html = $view->fetch($template, $pageOptions); + + $location = "../content/test.html"; + if (!is_file($location)) { + file_put_contents($location, $html); + } else { + ($new = fopen($location, "w")) or die("Unable to open file!"); + fwrite($new, $html); + fclose($new); + } + + $result = [ + "message" => "Site published. GOOD EFFORT", + "type" => "TASK_NONE", + ]; + + break; + default: + $result = [ + "message" => "Hm, no task. That's unfortunate", + "type" => "TASK_NONE", + ]; + break; + } + + return $result; + } +} diff --git a/brain/controller/APIControl.inc.php b/brain/controller/APIControl.inc.php index 0cea17b..3875930 100644 --- a/brain/controller/APIControl.inc.php +++ b/brain/controller/APIControl.inc.php @@ -4,6 +4,7 @@ use Psr\Http\Message\ServerRequestInterface; include "../brain/api/v1/ImagesAPI.inc.php"; include "../brain/api/v1/PagesAPI.inc.php"; +include "../brain/api/v1/SettingsAPI.inc.php"; class APIControl { @@ -55,6 +56,17 @@ class APIControl ]; } break; + case "settings": + $token = $request->getHeader("fipamo-access-token"); + if (Session::verifyToken($token[0])) { + $result = SettingsAPI::handleSettingsTask($request, $args); + } else { + $result = [ + "message" => "API access denied, homie", + "type" => "API_ERROR", + ]; + } + break; default: $result = [ "message" => "Oh, nothing to do. That's unfortunate", diff --git a/brain/controller/DashControl.inc.php b/brain/controller/DashControl.inc.php index 67f7330..22d7cdc 100644 --- a/brain/controller/DashControl.inc.php +++ b/brain/controller/DashControl.inc.php @@ -16,6 +16,33 @@ class DashControl $pageOptions = []; $template = ""; switch (isset($args["second"]) ? $args["second"] : "index") { + case "settings": + if (Session::active()) { + $config = new Settings(); + $settings = $config->getSettings(); + $themes = $config->getThemes(); + $template = "dash/settings.twig"; + $member = Session::get("member"); + $pageOptions = [ + "title" => "Dash Settings", + "private" => $settings["global"]["private"], + "render" => $settings["global"]["renderOnSave"], + "background" => $settings["global"]["background"], + "member" => $member, + "siteTitle" => $settings["global"]["title"], + "baseUrl" => $settings["global"]["base_url"], + "desc" => $settings["global"]["descriptions"], + "lastBackup" => $settings["global"]["last_backup"], + "currentTheme" => $settings["global"]["theme"], + "themes" => $themes, + "mailOption" => $settings["email"]["active"], + ]; + } else { + header("Location: /dashboard"); + die(); + } + + break; case "pages": if (Session::active()) { $currentPage = isset($args["fourth"]) ? $args["fourth"] : 1; @@ -65,7 +92,6 @@ class DashControl header("Location: /dashboard"); die(); } - break; case "logout": Session::kill(); @@ -88,6 +114,7 @@ class DashControl } break; } + return $view->render($response, $template, $pageOptions); } } diff --git a/brain/data/Settings.inc.php b/brain/data/Settings.inc.php index 8ce817a..e5bac1c 100644 --- a/brain/data/Settings.inc.php +++ b/brain/data/Settings.inc.php @@ -4,6 +4,7 @@ class Settings { private $folks; private $tags; + private $themes = []; private static $settings; public function __construct() @@ -15,6 +16,19 @@ class Settings file_get_contents("../config/settings.json"), true ); + + $_themes = glob("../content/themes/*", GLOB_ONLYDIR); + foreach ($_themes as $theme) { + array_push( + $this->themes, + json_decode(file_get_contents($theme . "/theme.json"), true) + ); + } + } + + public function getThemes() + { + return $this->themes; } public function getFolks($key = null) @@ -28,6 +42,11 @@ class Settings } } + public function getSettings($key = null) + { + return self::$settings; + } + public static function getCurrentIndex() { $settings = self::$settings; diff --git a/brain/views/dash/partials/mailforms.twig b/brain/views/dash/partials/mailforms.twig new file mode 100644 index 0000000..492f42c --- /dev/null +++ b/brain/views/dash/partials/mailforms.twig @@ -0,0 +1,31 @@ +{% if mailOption == "option-smtp" %} +