From c867b6c5085ea790c35bd0dfd7bec56846400fb1 Mon Sep 17 00:00:00 2001 From: Ro Date: Mon, 22 Nov 2021 14:24:26 -0800 Subject: [PATCH] adde page preview feature, updated page edit ui with preview option button --- brain/controller/DashControl.inc.php | 59 ++++++++++++++++++-------- brain/controller/IndexControl.inc.php | 1 + brain/utility/Sorting.inc.php | 1 + brain/views/dash/page-edit.twig | 2 +- brain/views/dash/partials/options.twig | 9 +++- public/assets/css/dash.css | 2 +- src/styles/main/_posts.sass | 9 +++- 7 files changed, 60 insertions(+), 23 deletions(-) diff --git a/brain/controller/DashControl.inc.php b/brain/controller/DashControl.inc.php index 7ded135..6a5d350 100644 --- a/brain/controller/DashControl.inc.php +++ b/brain/controller/DashControl.inc.php @@ -101,24 +101,47 @@ class DashControl if (Session::active()) { $template = "dash/page-edit.twig"; $mode = $args["third"]; - if ($mode == "edit") { - $uuid = $args["fourth"]; - $customPages = (new Themes())->getCustomViews(); - $pageOptions = [ - "title" => "Fipamo | Edit Page", - "page" => (new Book("../content/pages"))->findPageById($uuid), - "mode" => $mode, - "token" => Session::get("form_token"), - "status" => Session::active(), - "views" => $customPages, - ]; - } else { - $pageOptions = [ - "title" => "Fipamo | Create Page", - "token" => Session::get("form_token"), - "mode" => $mode, - "status" => Session::active(), - ]; + $uuid = $args["fourth"]; + switch ($mode) { + case "edit": + $customPages = (new Themes())->getCustomViews(); + $pageOptions = [ + "title" => "Fipamo | Edit Page", + "page" => (new Book("../content/pages"))->findPageById($uuid), + "mode" => $mode, + "token" => Session::get("form_token"), + "status" => Session::active(), + "views" => $customPages, + ]; + break; + case "preview": + $config = new Settings(); + $settings = $config->getSettings(); + $loader = new \Twig\Loader\FilesystemLoader( + "../content/themes" + ); + $display = new \Twig\Environment($loader, []); + + $book = new Book("../content/pages"); + $page = $book->findPageById($uuid); + $pageOptions = Sorting::page($page); + $preview = + $settings["global"]["theme"] . + "/" . + $page["layout"] . + ".twig"; + $html = $display->render($preview, $pageOptions); + $response->getBody()->write($html); + return $response; + break; + default: + $pageOptions = [ + "title" => "Fipamo | Create Page", + "token" => Session::get("form_token"), + "mode" => $mode, + "status" => Session::active(), + ]; + break; } } else { header("Location: /dashboard"); diff --git a/brain/controller/IndexControl.inc.php b/brain/controller/IndexControl.inc.php index 4a0ded3..5643d85 100644 --- a/brain/controller/IndexControl.inc.php +++ b/brain/controller/IndexControl.inc.php @@ -63,6 +63,7 @@ class IndexControl break; default: + //check layout to see what page should be rendered $template = $settings["global"]["theme"] . "/page.twig"; $book = new Book("../content/pages"); $page = $book->findPageBySlug($args["third"]); diff --git a/brain/utility/Sorting.inc.php b/brain/utility/Sorting.inc.php index 1e36121..ee9fe18 100644 --- a/brain/utility/Sorting.inc.php +++ b/brain/utility/Sorting.inc.php @@ -155,6 +155,7 @@ class Sorting "ul", "li", "i", + "em", "h1", "h2", "h3", diff --git a/brain/views/dash/page-edit.twig b/brain/views/dash/page-edit.twig index 56840a7..66c3474 100644 --- a/brain/views/dash/page-edit.twig +++ b/brain/views/dash/page-edit.twig @@ -30,7 +30,7 @@ {% endblock %} {% block stylesheets %} - + {% endblock %} {% block mainContent %} diff --git a/brain/views/dash/partials/options.twig b/brain/views/dash/partials/options.twig index 68c452f..c8a0dfd 100644 --- a/brain/views/dash/partials/options.twig +++ b/brain/views/dash/partials/options.twig @@ -29,9 +29,16 @@ + + +