You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Fipamo/brain/controller/DashControl.inc.php

163 lines
5.4 KiB
PHP

<?php
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Slim\Views\Twig;
include "../brain/data/Book.inc.php";
class DashControl
{
public static function start(
ServerRequestInterface $request,
ResponseInterface $response,
array $args
): ResponseInterface {
$view = Twig::fromRequest($request);
$pageOptions = [];
$template = "";
if (Setup::status()) {
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");
$form_token = Session::get("form_token");
$updated = new \Moment\Moment($settings["global"]["last_backup"]);
$pageOptions = [
"title" => "Dash Settings",
"private" => $settings["global"]["private"],
"render" => $settings["global"]["renderOnSave"],
"background" => $settings["global"]["background"],
"member" => $member,
"ftoken" => $form_token,
"siteTitle" => $settings["global"]["title"],
"baseUrl" => $settings["global"]["base_url"],
"desc" => $settings["global"]["descriptions"],
"lastBackup" => $updated->format("Y M D d"),
"currentTheme" => $settings["global"]["theme"],
"themes" => $themes,
"apiStatus" => isset($settings["global"]["externalAPI"])
? $settings["global"]["externalAPI"]
: "false",
"dynamicRenderStatus" => isset(
$settings["global"]["dynamicRender"]
)
? $settings["global"]["dynamicRender"]
: "false",
"mailOption" => $settings["email"]["active"],
"mailConfig" => $settings["email"],
"status" => Session::active(),
];
} else {
header("Location: /dashboard");
die();
}
break;
case "navigation":
if (Session::active()) {
$config = new Settings();
$settings = $config->getSettings();
$template = "dash/navigation.twig";
$pageOptions = [
"title" => "Edit Dash Navigation",
"status" => Session::active(),
"menu" => $settings["menu"],
];
} else {
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";
$pageOptions = [
"entryCount" => $data["entryCount"],
"numOfPages" => $data["numOfPages"],
"currentPage" => $currentPage,
"filter" => $data["paginate"]["sort"],
"stats" => $data["stats"],
"pages" => $data["pages"],
"paginate" => $data["paginate"],
"status" => Session::active(),
];
} 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"];
$pageOptions = [
"title" => "Fipamo | Edit Page",
"page" => (new Book("../content/pages"))->findPageById($uuid),
"mode" => $mode,
"token" => Session::get("form_token"),
"status" => Session::active(),
];
} else {
$pageOptions = [
"title" => "Fipamo | Create Page",
"token" => Session::get("form_token"),
"mode" => $mode,
"status" => Session::active(),
];
}
} else {
header("Location: /dashboard");
die();
}
break;
case "logout":
Session::kill();
header("Location: /dashboard");
die();
break;
case "reset-password":
$template = "dash/reset-password.twig";
$pageOptions = [
"title" => "Reset Password",
];
break;
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"];
}
return $view->render($response, $template, $pageOptions);
}
}