From b2f61758d4cc52b9454f9967a0789202be776dd4 Mon Sep 17 00:00:00 2001 From: Matschieu Date: Sat, 28 Dec 2024 01:07:06 +0100 Subject: [PATCH] Add conf to customize the menu --- README.md | 39 ++++++++++++++++++++++++++++++++++ conf/app.ini | 39 ++++++++++++++++++++++++++++++++++ core/AppContext.php | 22 ++++++++++++------- core/Config.php | 34 +++++++++++++++++++++++++++++ core/FileViewerApplication.php | 2 +- index.php | 23 ++++++++++++++++++++ tests/ConfigTest.php | 24 +++++++++++++++++++++ tests/conf/app.ini | 39 ++++++++++++++++++++++++++++++++++ 8 files changed, 213 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 38a570e..43e8e52 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,12 @@ debug = false # Define the default language in which the application is displayed application.default.language = en +# Define if the hidden files are display by default or not, if true then display hidden files +application.default.showhidden = false + +# Define the default view, if false then display block view, else display the list view +application.default.listview = false + # Application information # Will be displayed at least in the tab title application.name = M-WEBNAV @@ -77,6 +83,39 @@ application.header = ./header.php # Empty value means that no footer will be displayed application.footer = ./footer.php +# Enable to display the menu +application.enable.menu = true + +# Enable to display the menu to display folder tree +application.enable.menu.foldertree = true + +# Enable to display the menu to refresh the page +application.enable.menu.refresh = true + +# Enable to display the menu to go back to the previous page +application.enable.menu.back = true + +# Enable to display the menu to go forward to the next page +application.enable.menu.next = true + +# Enable to display the menu to show the hidden files +application.enable.menu.showhidden = true + +# Enable to display the menu to change the view type +application.enable.menu.changeview = true + +# Enable to display the menu to sort the file +application.enable.menu.sort = true + +# Enable to display the menu to change the language +application.enable.menu.changelanguage = true + +# Enable to display the menu to close the page +application.enable.menu.close = true + +# Enable to display the textfield to filter the files +application.enable.menu.filter = true + # The root dir of the file system to explore # It can be a relative to the index.php path or an absolute path # Must be set diff --git a/conf/app.ini b/conf/app.ini index fd3b434..b9264fe 100644 --- a/conf/app.ini +++ b/conf/app.ini @@ -4,6 +4,12 @@ debug = false # Define the default language in which the application is displayed application.default.language = en +# Define if the hidden files are display by default or not, if true then display hidden files +application.default.showhidden = false + +# Define the default view, if false then display block view, else display the list view +application.default.listview = false + # Application information # Will be displayed at least in the tab title application.name = M-WEBNAV @@ -24,6 +30,39 @@ application.header = ./header.php # Empty value means that no footer will be displayed application.footer = ./footer.php +# Enable to display the menu +application.enable.menu = true + +# Enable to display the menu to display folder tree +application.enable.menu.foldertree = true + +# Enable to display the menu to refresh the page +application.enable.menu.refresh = true + +# Enable to display the menu to go back to the previous page +application.enable.menu.back = true + +# Enable to display the menu to go forward to the next page +application.enable.menu.next = true + +# Enable to display the menu to show the hidden files +application.enable.menu.showhidden = true + +# Enable to display the menu to change the view type +application.enable.menu.changeview = true + +# Enable to display the menu to sort the file +application.enable.menu.sort = true + +# Enable to display the menu to change the language +application.enable.menu.changelanguage = true + +# Enable to display the menu to close the page +application.enable.menu.close = true + +# Enable to display the textfield to filter the files +application.enable.menu.filter = true + # The root dir of the file system to explore # It can be a relative to the index.php path or an absolute path # Must be set diff --git a/core/AppContext.php b/core/AppContext.php index 8e37666..919252d 100644 --- a/core/AppContext.php +++ b/core/AppContext.php @@ -135,17 +135,23 @@ public function encode(): string { * @param string $token * @return AppContext */ - public static function decode(?string $token): AppContext { - if ($token == null) { - return new AppContext(); - } - $vars = json_decode(base64_decode($token), true); + public static function decode(?string $token, Config $config): AppContext { $appContext = new AppContext(); - if ($vars != null) { - foreach(array_keys($vars) as $key) { - $appContext->$key = $vars[$key]; + + if ($token != null) { + $vars = json_decode(base64_decode($token), true); + + if ($vars != null) { + foreach(array_keys($vars) as $key) { + $appContext->$key = $vars[$key]; + } } + } else { + $appContext->setLanguage($config->defaultLanguage()); + $appContext->setShowHidden($config->defaultShowHidden()); + $appContext->setDisplayList($config->defaultListView()); } + return $appContext; } diff --git a/core/Config.php b/core/Config.php index 802069a..745e5cf 100755 --- a/core/Config.php +++ b/core/Config.php @@ -53,6 +53,22 @@ public static function defaultLanguage() : string { return self::get()->getValue("application.default.language"); } + /** + * + * @return bool + */ + public static function defaultShowHidden() : bool { + return filter_var(self::get()->getValue("application.default.showhidden"), FILTER_VALIDATE_BOOLEAN); + } + + /** + * + * @return bool + */ + public static function defaultListView() : bool { + return filter_var(self::get()->getValue("application.default.listview"), FILTER_VALIDATE_BOOLEAN); + } + /** * * @return string @@ -109,4 +125,22 @@ public static function dateFormat() : string { return self::get()->getValue("date.format"); } + /** + * + * @return bool + */ + public static function enableMenu(string $key = "") : bool { + $realKey = "application.enable.menu"; + + if (!empty($key)) { + $realKey .= ".".$key; + } + + if (self::get()->getValue($realKey) == null) { + return false; + } + + return filter_var(self::get()->getValue($realKey), FILTER_VALIDATE_BOOLEAN); + } + } diff --git a/core/FileViewerApplication.php b/core/FileViewerApplication.php index 020fcdd..c15cb50 100755 --- a/core/FileViewerApplication.php +++ b/core/FileViewerApplication.php @@ -44,7 +44,7 @@ private function getHttpParam(string $param): ?string { private function __construct() { $this->initDebug(); $this->startExecTime = microtime(true); - $this->appContext = AppContext::decode($this->getHttpParam(self::HTTP_PARAM_CONTEXT)); + $this->appContext = AppContext::decode($this->getHttpParam(self::HTTP_PARAM_CONTEXT), Config::get()); Translation::init($this->appContext->getLanguage()); } diff --git a/index.php b/index.php index 6ba0abb..1634117 100755 --- a/index.php +++ b/index.php @@ -1,5 +1,6 @@ + +
diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 719f238..354169c 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -33,6 +33,14 @@ public function testDefaultLanguage() { $this->assertEquals("fr", Config::get()->defaultLanguage()); } + public function testDefaultShowHidden() { + $this->assertTrue(Config::get()->defaultShowHidden()); + } + + public function testDefaultListView() { + $this->assertTrue(Config::get()->defaultListView()); + } + public function testApplicationName() { $this->assertNotNull(Config::get()->applicationName()); $this->assertEquals("M-WEBNAV TEST", Config::get()->applicationName()); @@ -68,5 +76,21 @@ public function testDateFormat() { $this->assertEquals("Y-m-d G:i", Config::get()->dateFormat()); } + public function testEnableMenu(): void { + $this->assertTrue(Config::get()->enableMenu()); + $this->assertTrue(Config::get()->enableMenu("")); + $this->assertTrue(Config::get()->enableMenu("foldertree")); + $this->assertTrue(Config::get()->enableMenu("refresh")); + $this->assertTrue(Config::get()->enableMenu("back")); + $this->assertTrue(Config::get()->enableMenu("next")); + $this->assertTrue(Config::get()->enableMenu("showhidden")); + $this->assertTrue(Config::get()->enableMenu("changeview")); + $this->assertTrue(Config::get()->enableMenu("sort")); + $this->assertTrue(Config::get()->enableMenu("changelanguage")); + $this->assertTrue(Config::get()->enableMenu("close")); + $this->assertTrue(Config::get()->enableMenu("filter")); + $this->assertFalse(Config::get()->enableMenu("foo")); + } + } diff --git a/tests/conf/app.ini b/tests/conf/app.ini index b25c45f..d110466 100644 --- a/tests/conf/app.ini +++ b/tests/conf/app.ini @@ -4,6 +4,12 @@ debug = false # Define the default language in which the application is displayed application.default.language = fr +# Define if the hidden files are display by default or not, if true then display hidden files +application.default.showhidden = true + +# Define the default view, if false then display block view, else display the list view +application.default.listview = true + # Application information # Will be displayed at least in the tab title application.name = M-WEBNAV TEST @@ -24,6 +30,39 @@ application.header = ./header.php # Empty value means that no footer will be displayed application.footer = ./footer.php +# Enable to display the menu +application.enable.menu = true + +# Enable to display the menu to display folder tree +application.enable.menu.foldertree = true + +# Enable to display the menu to refresh the page +application.enable.menu.refresh = true + +# Enable to display the menu to go back to the previous page +application.enable.menu.back = true + +# Enable to display the menu to go forward to the next page +application.enable.menu.next = true + +# Enable to display the menu to show the hidden files +application.enable.menu.showhidden = true + +# Enable to display the menu to change the view type +application.enable.menu.changeview = true + +# Enable to display the menu to sort the file +application.enable.menu.sort = true + +# Enable to display the menu to change the language +application.enable.menu.changelanguage = true + +# Enable to display the menu to close the page +application.enable.menu.close = true + +# Enable to display the textfield to filter the files +application.enable.menu.filter = true + # The root dir of the file system to explore # It can be a relative to the index.php path or an absolute path # Must be set