2021-03-25 00:59:28 +01:00
|
|
|
<?php
|
2021-03-27 04:24:16 +01:00
|
|
|
use Psr\Http\Message\ResponseInterface;
|
|
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
|
|
use Slim\Views\Twig;
|
|
|
|
|
2021-03-29 00:22:00 +02:00
|
|
|
include "../brain/data/Book.inc.php";
|
2021-03-25 00:59:28 +01:00
|
|
|
|
|
|
|
class DashControl
|
|
|
|
{
|
2021-03-27 04:24:16 +01:00
|
|
|
public static function start(
|
|
|
|
ServerRequestInterface $request,
|
|
|
|
ResponseInterface $response,
|
|
|
|
array $args
|
|
|
|
): ResponseInterface {
|
|
|
|
$view = Twig::fromRequest($request);
|
|
|
|
$pageOptions = [];
|
2021-04-07 23:09:40 +02:00
|
|
|
$template = "";
|
2021-04-24 05:54:56 +02:00
|
|
|
if (Setup::status()) {
|
|
|
|
switch (isset($args["second"]) ? $args["second"] : "index") {
|
|
|
|
case "settings":
|
|
|
|
if (Session::active()) {
|
|
|
|
$config = new Settings();
|
|
|
|
$settings = $config->getSettings();
|
2021-11-18 01:59:53 +01:00
|
|
|
$themes = (new Themes())->getThemes(); //$config->getThemes();
|
2021-04-24 05:54:56 +02:00
|
|
|
$template = "dash/settings.twig";
|
|
|
|
$member = Session::get("member");
|
2021-11-03 00:19:03 +01:00
|
|
|
$form_token = Session::get("form_token");
|
2021-04-26 00:48:46 +02:00
|
|
|
$updated = new \Moment\Moment($settings["global"]["last_backup"]);
|
2021-04-24 05:54:56 +02:00
|
|
|
$pageOptions = [
|
|
|
|
"title" => "Dash Settings",
|
|
|
|
"private" => $settings["global"]["private"],
|
2021-11-08 22:52:33 +01:00
|
|
|
"renderOnSave" => $settings["global"]["renderOnSave"],
|
2021-04-24 05:54:56 +02:00
|
|
|
"background" => $settings["global"]["background"],
|
|
|
|
"member" => $member,
|
2021-11-03 00:19:03 +01:00
|
|
|
"ftoken" => $form_token,
|
2021-04-24 05:54:56 +02:00
|
|
|
"siteTitle" => $settings["global"]["title"],
|
|
|
|
"baseUrl" => $settings["global"]["base_url"],
|
|
|
|
"desc" => $settings["global"]["descriptions"],
|
2021-04-26 00:48:46 +02:00
|
|
|
"lastBackup" => $updated->format("Y M D d"),
|
2021-04-24 05:54:56 +02:00
|
|
|
"currentTheme" => $settings["global"]["theme"],
|
|
|
|
"themes" => $themes,
|
2021-06-09 22:36:08 +02:00
|
|
|
"apiStatus" => isset($settings["global"]["externalAPI"])
|
|
|
|
? $settings["global"]["externalAPI"]
|
|
|
|
: "false",
|
2021-11-03 00:19:03 +01:00
|
|
|
"dynamicRenderStatus" => isset(
|
|
|
|
$settings["global"]["dynamicRender"]
|
|
|
|
)
|
|
|
|
? $settings["global"]["dynamicRender"]
|
|
|
|
: "false",
|
2021-04-24 05:54:56 +02:00
|
|
|
"mailOption" => $settings["email"]["active"],
|
2021-05-04 00:48:20 +02:00
|
|
|
"mailConfig" => $settings["email"],
|
2021-04-24 05:54:56 +02:00
|
|
|
"status" => Session::active(),
|
|
|
|
];
|
|
|
|
} else {
|
|
|
|
header("Location: /dashboard");
|
|
|
|
die();
|
|
|
|
}
|
2021-04-10 22:19:05 +02:00
|
|
|
|
2021-04-24 05:54:56 +02:00
|
|
|
break;
|
|
|
|
case "navigation":
|
|
|
|
if (Session::active()) {
|
|
|
|
$config = new Settings();
|
|
|
|
$settings = $config->getSettings();
|
|
|
|
$template = "dash/navigation.twig";
|
2021-04-10 22:19:05 +02:00
|
|
|
$pageOptions = [
|
2021-04-24 05:54:56 +02:00
|
|
|
"title" => "Edit Dash Navigation",
|
2021-04-10 22:44:43 +02:00
|
|
|
"status" => Session::active(),
|
2021-04-24 05:54:56 +02:00
|
|
|
"menu" => $settings["menu"],
|
2021-04-10 22:19:05 +02:00
|
|
|
];
|
|
|
|
} else {
|
2021-04-24 05:54:56 +02:00
|
|
|
header("Location: /dashboard");
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "pages":
|
|
|
|
if (Session::active()) {
|
|
|
|
$currentPage = isset($args["fourth"]) ? $args["fourth"] : 1;
|
|
|
|
$filter = isset($args["third"]) ? $args["third"] : "all";
|
|
|
|
$data = (new Book("../content/pages"))->getPages(
|
|
|
|
$currentPage,
|
|
|
|
4,
|
|
|
|
$filter
|
|
|
|
);
|
|
|
|
$template = "dash/book.twig";
|
2021-04-14 21:48:57 +02:00
|
|
|
$pageOptions = [
|
2021-04-24 05:54:56 +02:00
|
|
|
"entryCount" => $data["entryCount"],
|
|
|
|
"numOfPages" => $data["numOfPages"],
|
|
|
|
"currentPage" => $currentPage,
|
|
|
|
"filter" => $data["paginate"]["sort"],
|
|
|
|
"stats" => $data["stats"],
|
|
|
|
"pages" => $data["pages"],
|
|
|
|
"paginate" => $data["paginate"],
|
2021-04-14 21:48:57 +02:00
|
|
|
"status" => Session::active(),
|
|
|
|
];
|
2021-04-24 05:54:56 +02:00
|
|
|
} else {
|
|
|
|
header("Location: /dashboard");
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "page":
|
|
|
|
if (Session::active()) {
|
|
|
|
$template = "dash/page-edit.twig";
|
|
|
|
$mode = $args["third"];
|
|
|
|
if ($mode == "edit") {
|
|
|
|
$uuid = $args["fourth"];
|
2021-11-18 01:59:53 +01:00
|
|
|
$customPages = (new Themes())->getCustomViews();
|
2021-04-24 05:54:56 +02:00
|
|
|
$pageOptions = [
|
|
|
|
"title" => "Fipamo | Edit Page",
|
|
|
|
"page" => (new Book("../content/pages"))->findPageById($uuid),
|
|
|
|
"mode" => $mode,
|
2021-09-12 23:40:27 +02:00
|
|
|
"token" => Session::get("form_token"),
|
2021-04-24 05:54:56 +02:00
|
|
|
"status" => Session::active(),
|
2021-11-18 01:59:53 +01:00
|
|
|
"views" => $customPages,
|
2021-04-24 05:54:56 +02:00
|
|
|
];
|
|
|
|
} else {
|
|
|
|
$pageOptions = [
|
|
|
|
"title" => "Fipamo | Create Page",
|
2021-10-21 22:27:48 +02:00
|
|
|
"token" => Session::get("form_token"),
|
2021-04-24 05:54:56 +02:00
|
|
|
"mode" => $mode,
|
|
|
|
"status" => Session::active(),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
header("Location: /dashboard");
|
|
|
|
die();
|
2021-04-10 22:19:05 +02:00
|
|
|
}
|
2021-04-24 05:54:56 +02:00
|
|
|
break;
|
|
|
|
case "logout":
|
|
|
|
Session::kill();
|
2021-04-14 21:48:57 +02:00
|
|
|
header("Location: /dashboard");
|
|
|
|
die();
|
2021-04-24 05:54:56 +02:00
|
|
|
break;
|
2021-05-06 21:45:39 +02:00
|
|
|
case "reset-password":
|
|
|
|
$template = "dash/reset-password.twig";
|
|
|
|
$pageOptions = [
|
|
|
|
"title" => "Reset Password",
|
|
|
|
];
|
|
|
|
break;
|
2021-04-26 00:48:46 +02:00
|
|
|
|
2021-04-24 05:54:56 +02:00
|
|
|
default:
|
|
|
|
$template = "dash/start.twig";
|
|
|
|
if (Session::active()) {
|
|
|
|
$pageOptions = [
|
|
|
|
"title" => "Welcome Back",
|
|
|
|
"status" => Session::active(),
|
|
|
|
"data" => (new Book("../content/pages"))->getPages(1, 4),
|
|
|
|
];
|
|
|
|
} else {
|
|
|
|
$pageOptions = [
|
|
|
|
"title" => "Welcome to Fipamo",
|
|
|
|
"status" => Session::active(),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$template = "dash/init.twig";
|
|
|
|
$pageOptions = ["title" => "Fipamo Setup"];
|
2021-03-25 00:59:28 +01:00
|
|
|
}
|
2021-04-16 07:19:59 +02:00
|
|
|
|
2021-04-07 23:09:40 +02:00
|
|
|
return $view->render($response, $template, $pageOptions);
|
2021-03-25 00:59:28 +01:00
|
|
|
}
|
|
|
|
}
|