settings paged plugged in, scoping out page publishing api methodology
This commit is contained in:
parent
a699fd1926
commit
b68d4c190e
7 changed files with 268 additions and 2 deletions
52
brain/api/v1/SettingsAPI.inc.php
Normal file
52
brain/api/v1/SettingsAPI.inc.php
Normal file
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
use Slim\Views\Twig;
|
||||
|
||||
class SettingsAPI
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public static function handleSettingsTask($request, $args)
|
||||
{
|
||||
$task = $args["fourth"];
|
||||
echo $task;
|
||||
switch ($task) {
|
||||
case "publish":
|
||||
$view = Twig::fromRequest($request);
|
||||
|
||||
$template = "dash/start.twig";
|
||||
$pageOptions = [
|
||||
"title" => "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;
|
||||
}
|
||||
}
|
|
@ -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",
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
31
brain/views/dash/partials/mailforms.twig
Normal file
31
brain/views/dash/partials/mailforms.twig
Normal file
|
@ -0,0 +1,31 @@
|
|||
{% if mailOption == "option-smtp" %}
|
||||
<div id="mail-smtp" data-enabled='true'>
|
||||
<input type='text' name='smtp-domain' id='smtp-domain' placeholder='domain'value="settings.email.smtp.domain"/>
|
||||
<input type='text' name='smtp-email' id='smtp-email' placeholder='email' value="settings.email.smtp.email" />
|
||||
<input type='text' name='smtp-pass' id='smtp-pass' placeholder='password' value="settings.email.smtp.password"/>
|
||||
</div>
|
||||
<div id="mail-mg" data-enabled='false'>
|
||||
<input type='text' name='mg-domain' id='mg-domain' placeholder='domain' value="settings.email.mailgun.domain" />
|
||||
<input type='text' name='mg-key' id='mg-key' placeholder='api key' value="settings.email.mailgun.key "/>
|
||||
</div>
|
||||
{% elseif(mailOption == 'option-mg') %}
|
||||
<div id="mail-smtp" data-enabled='false'>
|
||||
<input type='text' name='smtp-domain' id='smtp-domain' placeholder='domain'value="settings.email.smtp.domain"/>
|
||||
<input type='text' name='smtp-email' id='smtp-email' placeholder='email' value="settings.email.smtp.email" />
|
||||
<input type='text' name='smtp-pass' id='smtp-pass' placeholder='password' value="settings.email.smtp.password"/>
|
||||
</div>
|
||||
<div id="mail-mg" data-enabled='true'>
|
||||
<input type='text' name='mg-domain' id='mg-domain' placeholder='domain' value="settings.email.mailgun.domain" />
|
||||
<input type='text' name='mg-key' id='mg-key' placeholder='api key' value="settings.email.mailgun.key "/>
|
||||
</div>
|
||||
{% else %}
|
||||
<div id="mail-smtp" data-enabled='false'>
|
||||
<input type='text' name='smtp-domain' id='smtp-domain' placeholder='domain'value="settings.email.smtp.domain"/>
|
||||
<input type='text' name='smtp-email' id='smtp-email' placeholder='email' value="settings.email.smtp.email" />
|
||||
<input type='text' name='smtp-pass' id='smtp-pass' placeholder='password' value="settings.email.smtp.password"/>
|
||||
</div>
|
||||
<div id="mail-mg" data-enabled='false'>
|
||||
<input type='text' name='mg-domain' id='mg-domain' placeholder='domain' value="settings.email.mailgun.domain" />
|
||||
<input type='text' name='mg-key' id='mg-key' placeholder='api key' value="settings.email.mailgun.key "/>
|
||||
</div>
|
||||
{% endif %}
|
125
brain/views/dash/settings.twig
Normal file
125
brain/views/dash/settings.twig
Normal file
|
@ -0,0 +1,125 @@
|
|||
{% extends "dash/_frame.twig" %}
|
||||
|
||||
{% if render %}
|
||||
{% set renderOnSave = 'true' %}
|
||||
{% else %}
|
||||
{% set renderOnSave = 'false' %}
|
||||
{% endif %}
|
||||
|
||||
{% block title %}
|
||||
{{ title }}
|
||||
{% endblock %}
|
||||
|
||||
{% block stylesheets %}
|
||||
<link rel="stylesheet" type="text/css" href="/assets/css/dash.css?=adfafd">
|
||||
{% endblock %}
|
||||
|
||||
{% block mainContent %}
|
||||
<div id="settings-actions">
|
||||
<div id="buttons">
|
||||
<button id="save-toggle">
|
||||
<svg id="submit-update" viewbox="0 0 20 20" class="icons">
|
||||
<use id="submit-update" xlink:href="/assets/images/global/sprite.svg#entypo-save"/>
|
||||
</svg>
|
||||
</button>
|
||||
<button id="publish-pages">
|
||||
<svg id="submit-update" viewbox="0 0 20 20" class="icons">
|
||||
<use id="submit-update" xlink:href="/assets/images/global/sprite.svg#entypo-publish"/>
|
||||
</svg>
|
||||
</button>
|
||||
<button id="render-toggle" data-render="{{render}}">
|
||||
<svg id="submit-update" viewbox="0 0 20 20" class="icons">
|
||||
<use id="submit-update" xlink:href="/assets/images/global/sprite.svg#entypo-ccw"/>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div id="site-background">
|
||||
<label>Header</label>
|
||||
<img id="background" src="{{background}}" alt="image for site background" for="background-upload"/>
|
||||
<input id="background-upload" type="file" name="backgrond-upload" />
|
||||
</div>
|
||||
<div id="settings-index">
|
||||
<div id="settings-index-wrapper">
|
||||
<div id="member-settings" class="columns">
|
||||
<div id="member-settings-1" class="column">
|
||||
<label> AVATAR </label>
|
||||
<div id="member-avatar-drop">
|
||||
<img id="avatar" src="{{member['avatar']}}" for="avatar-upload"/>
|
||||
<input id="avatar-upload" type="file" name="avatar-upload" />
|
||||
</div>
|
||||
</div>
|
||||
<div id="member-settings-2" class="column">
|
||||
<label>INFO</label>
|
||||
<input type='text' name='handle' id='settings-handle' placeholder='handle' value="{{member['handle']}}" autofocus />
|
||||
<input type='text' name='email' id='settings-email' placeholder='email' value="{{member['email']}}" autofocus />
|
||||
<input type='text' name='base-url' id='settings-url' placeholder='url' value="{{baseUrl}}" autofocus />
|
||||
<input type='text' name='base-title' id='settings-title' placeholder='site title' value="{{siteTitle}}" autofocus />
|
||||
<textarea id="settings-desc" type='text' name='settings_desc' class='settings-dec' placeholder='description stuff', autofocus>{{desc}}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div id="member-utils" class="columns">
|
||||
<div id="util-1" class="column">
|
||||
<label>BACK UP TOOLS</label> <br />
|
||||
<button id="create-backup">CREATE BACK UP</button><br />
|
||||
{% if lastBackup != '' %}
|
||||
<div class="backup-meta">
|
||||
The last back up was created <a href="">{{lastBackup}}</a><br />
|
||||
</div>
|
||||
{% else %}
|
||||
<span>span No back ups. Frowny face.</span>
|
||||
{% endif %}
|
||||
<button id="restore-backup" for='backup-upload'>RESTORE BACKUP</button>
|
||||
<input id="backup-upload" type="file" name="backup-upload" />
|
||||
</div>
|
||||
<div id="util-2" class="column">
|
||||
<label> MAINTENANCE </label><br />
|
||||
<button id="reindex-pages">REINDEX PAGES</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div id="option-settings" class="columns">
|
||||
<div id="theme-settings" class="column">
|
||||
<label>THEMES</label>
|
||||
{% for theme in themes %}
|
||||
{% if theme.name == currentTheme %}
|
||||
<a href="#" id="{{theme.name}}" class="theme-select" data-enabled="true">{{theme['display-name']}}</a>
|
||||
{% else %}
|
||||
<a href="#" id="{{theme.name}}" class="theme-select" data-enabled="false">{{theme['display-name']}}</a>
|
||||
{% endif %}
|
||||
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div id="mail-settings" class="column">
|
||||
<label>EMAIL</label>
|
||||
{% if mailOption == "option-none" or mailOption == "" %}
|
||||
<a href="#" class="mail-option" id="option-none" data-enabled="true">NONE</a>
|
||||
{% else %}
|
||||
<a href="#" class="mail-option" id="option-none" data-enabled="false">NONE</a>
|
||||
{% endif %}
|
||||
{% if mailOption == "option-mg" or mailOption == "" %}
|
||||
<a href="#" class="mail-option" id="option-mg" data-enabled="true">MAILGUN</a>
|
||||
{% else %}
|
||||
<a href="#" class="mail-option" id="option-mg" data-enabled="false">MAILGUN</a>
|
||||
{% endif %}
|
||||
{% if mailOption == "option-smtp" or mailOption == "" %}
|
||||
<a href="#" class="mail-option" id="option-smtp" data-enabled="true">SMTP</a>
|
||||
{% else %}
|
||||
<a href="#" class="mail-option" id="option-smtp" data-enabled="false">SMTP</a>
|
||||
{% endif %}
|
||||
|
||||
{% apply spaceless %}
|
||||
{{ include("dash/partials/mailforms.twig") }}
|
||||
{% endapply %}
|
||||
<button id="send-mail">TEST MAIL</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block javascripts %}
|
||||
<script src="/assets/scripts/dash.min.js" type="text/javascript"></script>
|
||||
{% endblock %}
|
|
@ -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";
|
||||
|
|
Loading…
Reference in a new issue