132 lines
3.5 KiB
PHP
132 lines
3.5 KiB
PHP
<?php
|
|
|
|
use Slim\Views\Twig;
|
|
|
|
class SettingsAPI
|
|
{
|
|
public function __construct()
|
|
{
|
|
}
|
|
|
|
public static function handleSettingsTask($request, $args, $body = null)
|
|
{
|
|
$task = $args["fourth"];
|
|
switch ($task) {
|
|
case "publish":
|
|
//check settings to see if site is a one pager
|
|
$config = new Settings();
|
|
$settings = $config->getSettings();
|
|
$theme = $settings["global"]["theme"];
|
|
$themeConfig = json_decode(
|
|
file_get_contents("../content/themes/" . $theme . "/theme.json"),
|
|
true
|
|
);
|
|
//if render flag is set and false, just render index page for one page sites
|
|
//otherwise, render all pages according to theme template files
|
|
$render = new Render();
|
|
if (isset($themeConfig["render"])) {
|
|
if (!$themeConfig["render"] || $themeConfig["render"] === "false") {
|
|
$render->renderIndex();
|
|
$result = [
|
|
"message" => "Index Rendered. HAND CLAPS",
|
|
"type" => "TASK_NONE",
|
|
];
|
|
} else {
|
|
$result = [
|
|
"message" => "Site Rendered. GOOD EFFORT",
|
|
"type" => "TASK_NONE",
|
|
];
|
|
}
|
|
} else {
|
|
$render->renderTags();
|
|
$render->renderArchive();
|
|
$render->renderPages();
|
|
$result = [
|
|
"message" => "Site Rendered. GOOD EFFORT",
|
|
"type" => "TASK_NONE",
|
|
];
|
|
}
|
|
|
|
break;
|
|
case "add-avatar":
|
|
$result = ImagesAPI::uploadImage($request, "avatar");
|
|
break;
|
|
case "add-feature-background":
|
|
$result = ImagesAPI::uploadImage($request, "background");
|
|
break;
|
|
case "sync":
|
|
Settings::sync($body);
|
|
$result = [
|
|
"message" => "Settings Synced. You're doing great!",
|
|
"type" => "settingsUpdated",
|
|
];
|
|
break;
|
|
case "nav-sync":
|
|
Settings::navSync($body);
|
|
$result = [
|
|
"message" => "Navigation updated. Very slick!",
|
|
"type" => "menuUpdated",
|
|
];
|
|
break;
|
|
default:
|
|
$result = [
|
|
"message" => "Hm, no task. That's unfortunate",
|
|
"type" => "TASK_NONE",
|
|
];
|
|
break;
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
public static function getInfo($request, $args)
|
|
{
|
|
$task = $args["fourth"];
|
|
switch ($task) {
|
|
case "site":
|
|
$config = new Settings();
|
|
$settings = $config->getSettings();
|
|
$data = [
|
|
"title" => $settings["global"]["title"],
|
|
"base_url" => $settings["global"]["base_url"],
|
|
"description" => $settings["global"]["descriptions"],
|
|
];
|
|
$result = [
|
|
"message" => "Settings Found",
|
|
"type" => "GET_SETTINGS",
|
|
"data" => $data,
|
|
];
|
|
break;
|
|
case "member":
|
|
if (Session::active()) {
|
|
$member = $member = Session::get("member");
|
|
$data = ["handle" => $member["handle"], "email" => $member["email"]];
|
|
$result = [
|
|
"message" => "Member Info Found",
|
|
"type" => "GET_MEMBER_INFO",
|
|
"data" => $data,
|
|
];
|
|
} else {
|
|
$result = [
|
|
"message" => "Not logged in. C'mon, bruh",
|
|
"type" => "TASK_NONE",
|
|
];
|
|
}
|
|
break;
|
|
default:
|
|
$result = [
|
|
"message" => "No Settings found. Frowny Face",
|
|
"type" => "TASK_NONE",
|
|
];
|
|
break;
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
public static function createBackup()
|
|
{
|
|
$result = Maintenance::makeBackup();
|
|
return $result;
|
|
}
|
|
}
|