From f119bdc773cabead328140f4c1de4f5dd02c9cc0 Mon Sep 17 00:00:00 2001 From: Ro Date: Sat, 18 Dec 2021 11:30:41 -0800 Subject: [PATCH] fix for #72, index page not using page themes --- brain/controller/DashControl.inc.php | 12 +++++++++--- brain/data/Themes.inc.php | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/brain/controller/DashControl.inc.php b/brain/controller/DashControl.inc.php index 6a5d350..1c26877 100644 --- a/brain/controller/DashControl.inc.php +++ b/brain/controller/DashControl.inc.php @@ -104,14 +104,20 @@ class DashControl $uuid = $args["fourth"]; switch ($mode) { case "edit": - $customPages = (new Themes())->getCustomViews(); + $page = (new Book("../content/pages"))->findPageById($uuid); + $views = []; + if (str_contains($page["layout"], "index")) { + $views = (new Themes())->getCustomIndex(); + } else { + $views = (new Themes())->getCustomViews(); + } $pageOptions = [ "title" => "Fipamo | Edit Page", - "page" => (new Book("../content/pages"))->findPageById($uuid), + "page" => $page, "mode" => $mode, "token" => Session::get("form_token"), "status" => Session::active(), - "views" => $customPages, + "views" => $views, ]; break; case "preview": diff --git a/brain/data/Themes.inc.php b/brain/data/Themes.inc.php index fbfe4a8..6ad02fb 100644 --- a/brain/data/Themes.inc.php +++ b/brain/data/Themes.inc.php @@ -20,6 +20,25 @@ class Themes return $this->themes; } + public function getCustomIndex() + { + $settings = (new Settings())->getSettings(); + $currentTheme = $settings["global"]["theme"]; + $folder = "../content/themes/" . $currentTheme; + $files = array_filter(glob("$folder/*twig"), "is_file"); + $views = []; + + foreach ($files as $file) { + $path = explode("/", $file); + $fileName = $path[4]; + if (str_contains($fileName, "index")) { + $page = explode(".", $fileName); + $views[] = $page[0]; + } + } + return $views; + } + public function getCustomViews() { $settings = (new Settings())->getSettings();