mikuli.cz

:)
git clone https://git.sr.ht/~ashymad/mikuli.cz
Log | Files | Refs

commit 2eec57fd0d2a96626801eef0951ab4e126225d07
parent ac111f92f6de90be16c0af0977ba00eb31d3c68f
Author: markseu <mark2011@mayberg.se>
Date:   Tue,  2 Apr 2024 12:17:39 +0200

Refactored code, wee faster directory information

Diffstat:
Msystem/extensions/core.php | 48+++++++++++++++++++++++-------------------------
Msystem/extensions/update-available.ini | 4++--
Msystem/extensions/update-current.ini | 4++--
3 files changed, 27 insertions(+), 29 deletions(-)

diff --git a/system/extensions/core.php b/system/extensions/core.php @@ -2,7 +2,7 @@ // Core extension, https://github.com/annaesvensson/yellow-core class YellowCore { - const VERSION = "0.8.129"; + const VERSION = "0.8.130"; const RELEASE = "0.8.23"; public $content; // content files public $media; // media files @@ -1965,10 +1965,17 @@ class YellowToolbox { // Return files and directories public function getDirectoryEntries($path, $regex = "/.*/", $sort = true, $directories = true, $includePath = true) { + return $this->getDirectoryEntriesRecursive($path, $regex, $sort, $directories, $includePath, 1); + } + + // Return files and directories recursively + public function getDirectoryEntriesRecursive($path, $regex = "/.*/", $sort = true, $directories = true, $includePath = true, $levelMax = 0) { + --$levelMax; $entries = array(); $directoryHandle = @opendir($path); if ($directoryHandle) { $path = rtrim($path, "/"); + $directoryEntries = array(); while (($entry = readdir($directoryHandle))!==false) { if (substru($entry, 0, 1)==".") continue; $entry = $this->yellow->lookup->normaliseUnicode($entry); @@ -1979,25 +1986,20 @@ class YellowToolbox { if (is_file("$path/$entry")) array_push($entries, $includePath ? "$path/$entry" : $entry); } } + if (is_dir("$path/$entry") && $levelMax!=0) array_push($directoryEntries, "$path/$entry"); + } + if ($sort) { + natcasesort($entries); + natcasesort($directoryEntries); } - if ($sort) natcasesort($entries); closedir($directoryHandle); - } - return $entries; - } - - // Return files and directories recursively - public function getDirectoryEntriesRecursive($path, $regex = "/.*/", $sort = true, $directories = true, $levelMax = 0) { - --$levelMax; - $entries = $this->getDirectoryEntries($path, $regex, $sort, $directories); - if ($levelMax!=0) { - foreach ($this->getDirectoryEntries($path, "/.*/", $sort, true) as $entry) { - $entries = array_merge($entries, $this->getDirectoryEntriesRecursive($entry, $regex, $sort, $directories, $levelMax)); + foreach ($directoryEntries as $directoryEntry) { + $entries = array_merge($entries, $this->getDirectoryEntriesRecursive($directoryEntry, $regex, $sort, $directories, $includePath, $levelMax)); } } return $entries; } - + // Return directory information, modification date and file count public function getDirectoryInformation($path) { return $this->getDirectoryInformationRecursive($path, 1); @@ -2010,23 +2012,19 @@ class YellowToolbox { $directoryHandle = @opendir($path); if ($directoryHandle) { $path = rtrim($path, "/"); + $directoryEntries = array(); while (($entry = readdir($directoryHandle))!==false) { if (substru($entry, 0, 1)==".") continue; $modified = max($modified, $this->getFileModified("$path/$entry")); if (is_file("$path/$entry")) ++$fileCount; - } - if ($levelMax!=0) { - rewinddir($directoryHandle); - while (($entry = readdir($directoryHandle))!==false) { - if (substru($entry, 0, 1)==".") continue; - if (is_dir("$path/$entry")) { - list($modifiedBelow, $fileCountBelow) = $this->getDirectoryInformationRecursive("$path/$entry", $levelMax); - $modified = max($modified, $modifiedBelow); - $fileCount += $fileCountBelow; - } - } + if (is_dir("$path/$entry") && $levelMax!=0) array_push($directoryEntries, "$path/$entry"); } closedir($directoryHandle); + foreach ($directoryEntries as $directoryEntry) { + list($modifiedBelow, $fileCountBelow) = $this->getDirectoryInformationRecursive($directoryEntry, $levelMax); + $modified = max($modified, $modifiedBelow); + $fileCount += $fileCountBelow; + } } return array($modified, $fileCount); } diff --git a/system/extensions/update-available.ini b/system/extensions/update-available.ini @@ -148,14 +148,14 @@ system/themes/copenhagen.css: copenhagen.css, create, update, careful system/themes/copenhagen.png: copenhagen.png, create Extension: Core -Version: 0.8.129 +Version: 0.8.130 Description: Core functionality of your website. Developer: Anna Svensson Tag: feature DownloadUrl: https://github.com/annaesvensson/yellow-core/archive/refs/heads/main.zip DocumentationUrl: https://github.com/annaesvensson/yellow-core DocumentationLanguage: en, de, sv -Published: 2024-04-01 18:44:16 +Published: 2024-04-02 11:48:14 Status: available system/extensions/core.php: core.php, create, update system/layouts/default.html: default.html, create, update, careful diff --git a/system/extensions/update-current.ini b/system/extensions/update-current.ini @@ -1,14 +1,14 @@ # Datenstrom Yellow update settings for installed extensions Extension: Core -Version: 0.8.129 +Version: 0.8.130 Description: Core functionality of your website. Developer: Anna Svensson Tag: feature DownloadUrl: https://github.com/annaesvensson/yellow-core/archive/refs/heads/main.zip DocumentationUrl: https://github.com/annaesvensson/yellow-core DocumentationLanguage: en, de, sv -Published: 2024-04-01 18:44:16 +Published: 2024-04-02 11:48:14 Status: available system/extensions/core.php: core.php, create, update system/layouts/default.html: default.html, create, update, careful