Skip to content

Commit

Permalink
Add conf to customize the menu
Browse files Browse the repository at this point in the history
  • Loading branch information
matschieu committed Dec 28, 2024
1 parent 08586c9 commit b2f6175
Show file tree
Hide file tree
Showing 8 changed files with 213 additions and 9 deletions.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
39 changes: 39 additions & 0 deletions conf/app.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
22 changes: 14 additions & 8 deletions core/AppContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
34 changes: 34 additions & 0 deletions core/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

}
2 changes: 1 addition & 1 deletion core/FileViewerApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
23 changes: 23 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use core\Config;
use core\FileViewerApplication;
use core\FileSystem;
use core\Translation;
Expand Down Expand Up @@ -48,6 +49,7 @@
</div>

<!-- MENU -->
<?php if (Config::enableMenu()) { ?>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="<?php echo $app->getRootUrl() ?>" >
Expand All @@ -59,30 +61,39 @@
</button>
<div class="collapse navbar-collapse" id="navbarNav">>
<ul class="navbar-nav me-auto">
<?php if (Config::enableMenu("foldertree")) { ?>
<li class="nav-item">
<a class="nav-link" href="#" onclick="loadTree();return false;" data-bs-toggle="modal" data-bs-target="#folderTreeModal">
<span class="fa-solid fa-folder-tree"></span>
<?php echo Translation::get('menu.folderTree') ?>
</a>
</li>
<?php } ?>
<?php if (Config::enableMenu("refresh")) { ?>
<li class="nav-item">
<a class="nav-link" href="<?php echo $app->getUrl() ?>">
<span class="fa-solid fa-rotate-right"></span>
<?php echo Translation::get('menu.refresh') ?>
</a>
</li>
<?php } ?>
<?php if (Config::enableMenu("back")) { ?>
<li class="nav-item">
<a class="nav-link" href="#" onclick="javascript:window.history.back();">
<span class="fa-solid fa-left-long"></span>
<?php echo Translation::get('menu.back') ?>
</a>
</li>
<?php } ?>
<?php if (Config::enableMenu("next")) { ?>
<li class="nav-item">
<a class="nav-link" href="#" onclick="javascript:window.history.forward();">
<span class="fa-solid fa-right-long"></span>
<?php echo Translation::get('menu.next') ?>
</a>
</li>
<?php } ?>
<?php if (Config::enableMenu("showhidden")) { ?>
<li class="nav-item">
<?php if ($app->getAppContext()->getShowHidden()) { ?>
<a class="nav-link" href="<?php echo $app->getUrlWithShowHidden(false) ?>">
Expand All @@ -96,6 +107,8 @@
</a>
<?php } ?>
</li>
<?php } ?>
<?php if (Config::enableMenu("changeview")) { ?>
<li class="nav-item">
<?php if ($app->getAppContext()->getDisplayList()) { ?>
<a class="nav-link" href="<?php echo $app->getUrlWithDisplayList(false) ?>">
Expand All @@ -109,6 +122,8 @@
</a>
<?php } ?>
</li>
<?php } ?>
<?php if (Config::enableMenu("sort")) { ?>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" class="dropdown-toggle" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<span class="fa-solid fa-sort"></span>
Expand Down Expand Up @@ -136,15 +151,19 @@
</li>
</ul>
</li>
<?php } ?>
</ul>
<ul class="navbar-nav ms-auto">
<?php if (Config::enableMenu("filter")) { ?>
<form class="d-flex" onreset="javascript:resetField('filterfield'); return false;">
<input id="filterfield" class="form-control me-2" type="search" placeholder="<?php echo Translation::get('menu.filter') ?>" aria-label="<?php echo Translation::get('menu.filter') ?>" onkeyup="javascript:filter(this.value)" />
<button class="btn btn-primary me-4" type="reset">
<?php echo Translation::get('menu.reset') ?>
</button>
</form>
<?php } ?>

<?php if (Config::enableMenu("changelanguage")) { ?>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" class="dropdown-toggle" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<span class="fa-solid fa-flag"></span>
Expand Down Expand Up @@ -181,16 +200,20 @@
</li>
</ul>
</li>
<?php } ?>
<?php if (Config::enableMenu("close")) { ?>
<li class="nav-item">
<a class="nav-link" href="#" onclick="javascript:open(location, '_self').close(); return true;">
<span class="fa-solid fa-xmark"></span>
<?php echo Translation::get('menu.close') ?>
</a>
</li>
<?php } ?>
</ul>
</div>
</div>
</nav>
<?php } ?>

<!-- TOP STATE BAR -->
<div id="statebarTop" class="bg-primary p-1 text-white">
Expand Down
24 changes: 24 additions & 0 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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"));
}

}

39 changes: 39 additions & 0 deletions tests/conf/app.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit b2f6175

Please sign in to comment.