Tweaking and optimizing PR #116

This commit is contained in:
Chris Kankiewicz
2017-06-10 18:54:33 -07:00
parent 01c4a37187
commit 22661b6272
3 changed files with 23 additions and 34 deletions

View File

@@ -233,17 +233,23 @@ class DirectoryLister {
*/
public function containsIndex($dirPath) {
// Check if directory contains an index file
foreach ($this->_config['index_files'] as $indexFile) {
// Check if links_dirs_with_index is enabled
if ($this->linksDirsWithIndex()) {
if (file_exists($dirPath . '/' . $indexFile)) {
// Check if directory contains an index file
foreach ($this->_config['index_files'] as $indexFile) {
return true;
if (file_exists($dirPath . '/' . $indexFile)) {
return true;
}
}
}
return false;
}
@@ -290,19 +296,19 @@ class DirectoryLister {
public function externalLinksNewWindow() {
return $this->_config['external_links_new_window'];
}
/**
* Returns use real url for indexed directories
*
* @return boolean Returns true if in config is enabled links for directories with index, false if not
* @access public
*/
public function linksForDirsWithIndex()
public function linksDirsWithIndex()
{
return $this->_config['links_for_dirs_with_index'];
return $this->_config['links_dirs_with_index'];
}
/**
* Returns the path to the chosen theme directory
@@ -620,15 +626,7 @@ class DirectoryLister {
$urlPath = implode('/', array_map('rawurlencode', explode('/', $relativePath)));
if (is_dir($relativePath)) {
$urlPath = '?dir=' . $urlPath;
} else {
$urlPath = $urlPath;
}
if ($this->linksForDirsWithIndex()) {
if ($this->containsIndex($relativePath)) {
$urlPath = $relativePath;
}
$urlPath = $this->containsIndex($relativePath) ? $relativePath : '?dir=' . $urlPath;
}
// Add the info to the main array

View File

@@ -8,8 +8,6 @@ return array(
'list_folders_first' => true,
'list_sort_order' => 'natcasesort',
'theme_name' => 'bootstrap',
'external_links_new_window' => true,
'links_for_dirs_with_index' => false,
'date_format' => 'Y-m-d H:i:s', // See: http://php.net/manual/en/function.date.php
// Hidden files
@@ -23,6 +21,13 @@ return array(
'footer.php'
),
// If set to 'true' an directory with an index file (as defined below) will
// become a direct link to the index page instead of a browsable directory
'links_dirs_with_index' => false,
// Make linked directories open in a new (_blank) tab
'external_links_new_window' => true,
// Files that, if present in a directory, make the directory
// a direct link rather than a browse link.
'index_files' => array(

View File

@@ -122,20 +122,6 @@
<i class="fa fa-info-circle"></i>
</a>
<?php else: ?>
<?php if (!$lister->linksForDirsWithIndex()): ?>
<?php if ($lister->containsIndex($fileInfo['file_path'])): ?>
<a href="<?php echo $fileInfo['file_path']; ?>" class="web-link-button" <?php if($lister->externalLinksNewWindow()): ?>target="_blank"<?php endif; ?>>
<i class="fa fa-external-link"></i>
</a>
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>
</li>