From b68d4c190e332de9a79e6b653411335ebb6b32ff Mon Sep 17 00:00:00 2001 From: Ro Date: Thu, 15 Apr 2021 22:19:59 -0700 Subject: [PATCH] settings paged plugged in, scoping out page publishing api methodology --- brain/api/v1/SettingsAPI.inc.php | 52 ++++++++++ brain/controller/APIControl.inc.php | 12 +++ brain/controller/DashControl.inc.php | 29 +++++- brain/data/Settings.inc.php | 19 ++++ brain/views/dash/partials/mailforms.twig | 31 ++++++ brain/views/dash/settings.twig | 125 +++++++++++++++++++++++ src/libraries/FipamoAdminAPI.js | 2 +- 7 files changed, 268 insertions(+), 2 deletions(-) create mode 100644 brain/api/v1/SettingsAPI.inc.php create mode 100644 brain/views/dash/partials/mailforms.twig create mode 100644 brain/views/dash/settings.twig 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" %} +
+ + + +
+
+ + +
+{% elseif(mailOption == 'option-mg') %} +
+ + + +
+
+ + +
+{% else %} +
+ + + +
+
+ + +
+{% endif %} \ No newline at end of file diff --git a/brain/views/dash/settings.twig b/brain/views/dash/settings.twig new file mode 100644 index 0000000..1742040 --- /dev/null +++ b/brain/views/dash/settings.twig @@ -0,0 +1,125 @@ +{% extends "dash/_frame.twig" %} + +{% if render %} + {% set renderOnSave = 'true' %} +{% else %} + {% set renderOnSave = 'false' %} +{% endif %} + +{% block title %} + {{ title }} +{% endblock %} + +{% block stylesheets %} + + {% endblock %} + + {% block mainContent %} +
+
+ + + +
+
+
+ + image for site background + +
+
+
+
+
+ +
+ + +
+
+
+ + + + + + +
+
+
+
+
+
+ {% if lastBackup != '' %} +
+ The last back up was created {{lastBackup}}
+
+ {% else %} + span No back ups. Frowny face. + {% endif %} + + +
+
+
+ +
+ +
+
+
+ + {% for theme in themes %} + {% if theme.name == currentTheme %} + {{theme['display-name']}} + {% else %} + {{theme['display-name']}} + {% endif %} + + {% endfor %} +
+
+ + {% if mailOption == "option-none" or mailOption == "" %} + NONE + {% else %} + NONE + {% endif %} + {% if mailOption == "option-mg" or mailOption == "" %} + MAILGUN + {% else %} + MAILGUN + {% endif %} + {% if mailOption == "option-smtp" or mailOption == "" %} + SMTP + {% else %} + SMTP + {% endif %} + + {% apply spaceless %} + {{ include("dash/partials/mailforms.twig") }} + {% endapply %} + +
+
+ +
+ +
+ {% endblock %} + + {% block javascripts %} + + {% endblock %} \ No newline at end of file diff --git a/src/libraries/FipamoAdminAPI.js b/src/libraries/FipamoAdminAPI.js index 56fd737..f0c2c25 100644 --- a/src/libraries/FipamoAdminAPI.js +++ b/src/libraries/FipamoAdminAPI.js @@ -16,7 +16,7 @@ export const API_IMAGE_UPLOAD = "/api/v1/page/add-entry-image"; export const API_SETTINGS_SYNC = "/api/v1/settings/sync"; export const API_UPLOAD_AVATAR = "/api/v1/settings/add-avatar"; export const API_UPLOAD_BACKGROUND = "/api/v1/settings/add-feature-background"; -export const API_PUBLISH_PAGES = "/api/v1/settings/publish-pages"; +export const API_PUBLISH_PAGES = "/api/v1/settings/publish"; export const API_NAV_SYNC = "/api/v1/settings/nav-sync"; export const API_REINDEX_PAGES = "/api/v1/settings/reindex"; export const API_CREATE_BACKUP = "/api/v1/backup/create";