From 9221629d8dabef6e382b6a67a4f6c34481d48217 Mon Sep 17 00:00:00 2001 From: Michael Kuilboer Date: Thu, 6 Mar 2025 02:27:31 +0100 Subject: [PATCH] Fix available templates configuration and adding custom themes --- cfg/conf.sample.php | 21 ++++++++++----------- lib/Configuration.php | 20 ++++++++++---------- lib/Controller.php | 2 +- tst/TemplateSwitcherTest.php | 6 +++--- 4 files changed, 24 insertions(+), 25 deletions(-) diff --git a/cfg/conf.sample.php b/cfg/conf.sample.php index 3908e07e..a372eb5f 100644 --- a/cfg/conf.sample.php +++ b/cfg/conf.sample.php @@ -47,6 +47,16 @@ sizelimit = 10485760 ; a session cookie to store the choice until the browser is closed. templateselection = false +; List of available for selection templates when "templateselection" option is enabled +availabletemplates[] = "bootstrap" +availabletemplates[] = "bootstrap-page" +availabletemplates[] = "bootstrap-dark" +availabletemplates[] = "bootstrap-dark-page" +availabletemplates[] = "bootstrap-compact" +availabletemplates[] = "bootstrap-compact-page" +availabletemplates[] = "bootstrap5" +availabletemplates[] = "page" + ; set the template your installs defaults to, defaults to "bootstrap" (tpl/bootstrap.php), also ; available are "page" (tpl/page.php), the classic ZeroBin style and several ; bootstrap variants: "bootstrap-dark", "bootstrap-compact", "bootstrap-page", @@ -151,17 +161,6 @@ plaintext = "Plain Text" syntaxhighlighting = "Source Code" markdown = "Markdown" -[available_templates] -; List of available for selection templates when "templateselection" option is enabled -bootstrap -bootstrap-page -bootstrap-dark -bootstrap-dark-page -bootstrap-compact -bootstrap-compact-page -bootstrap5 -page - [traffic] ; time limit between calls from the same IP address in seconds ; Set this to 0 to disable rate limiting. diff --git a/lib/Configuration.php b/lib/Configuration.php index a14d62ff..eb0ae48d 100644 --- a/lib/Configuration.php +++ b/lib/Configuration.php @@ -47,6 +47,16 @@ class Configuration 'sizelimit' => 10485760, 'templateselection' => false, 'template' => 'bootstrap', + 'availabletemplates' => array( + 'bootstrap5', + 'bootstrap', + 'bootstrap-page', + 'bootstrap-dark', + 'bootstrap-dark-page', + 'bootstrap-compact', + 'bootstrap-compact-page', + 'page', + ), 'info' => 'More information on the project page.', 'notice' => '', 'languageselection' => false, @@ -78,16 +88,6 @@ class Configuration 'syntaxhighlighting' => 'Source Code', 'markdown' => 'Markdown', ), - 'available_templates' => array( - 'bootstrap5', - 'bootstrap', - 'bootstrap-page', - 'bootstrap-dark', - 'bootstrap-dark-page', - 'bootstrap-compact', - 'bootstrap-compact-page', - 'page', - ), 'traffic' => array( 'limit' => 10, 'header' => '', diff --git a/lib/Controller.php b/lib/Controller.php index a1857f04..b7b7fc1d 100644 --- a/lib/Controller.php +++ b/lib/Controller.php @@ -210,7 +210,7 @@ class Controller { $this->_conf = new Configuration; - $templates = $this->_conf->getSection('available_templates'); + $templates = $this->_conf->getKey('availabletemplates'); $template = $this->_conf->getKey('template'); TemplateSwitcher::setAvailableTemplates($templates); TemplateSwitcher::setTemplateFallback($template); diff --git a/tst/TemplateSwitcherTest.php b/tst/TemplateSwitcherTest.php index d854b36c..d66e320b 100644 --- a/tst/TemplateSwitcherTest.php +++ b/tst/TemplateSwitcherTest.php @@ -13,7 +13,7 @@ class TemplateSwitcherTest extends TestCase $existingTemplateFallback = 'bootstrap-dark'; $wrongTemplateFallback = 'bootstrap-wrong'; - TemplateSwitcher::setAvailableTemplates($conf->getSection('available_templates')); + TemplateSwitcher::setAvailableTemplates($conf->getKey('availabletemplates')); TemplateSwitcher::setTemplateFallback($existingTemplateFallback); $this->assertEquals($existingTemplateFallback, TemplateSwitcher::getTemplate(), 'Correct template fallback'); @@ -24,7 +24,7 @@ class TemplateSwitcherTest extends TestCase public function testSetAvailableTemplates() { $conf = new Configuration; - $availableTemplates = $conf->getSection('available_templates'); + $availableTemplates = $conf->getKey('availabletemplates'); TemplateSwitcher::setAvailableTemplates($availableTemplates); $this->assertEquals($availableTemplates, TemplateSwitcher::getAvailableTemplates(), 'Set available templates'); @@ -57,7 +57,7 @@ class TemplateSwitcherTest extends TestCase $existingTemplate = 'bootstrap'; $nonExistentTemplate = 'bootstrap-wrong'; - TemplateSwitcher::setAvailableTemplates($conf->getSection('available_templates')); + TemplateSwitcher::setAvailableTemplates($conf->getKey('availabletemplates')); $this->assertTrue(TemplateSwitcher::isTemplateAvailable($existingTemplate), 'Existing template'); $this->assertFalse(TemplateSwitcher::isTemplateAvailable($nonExistentTemplate), 'Non-existent template');