Refactored code, wee faster directory information

This commit is contained in:
markseu 2024-04-02 12:17:39 +02:00
parent ac111f92f6
commit 2eec57fd0d
3 changed files with 27 additions and 29 deletions

View file

@ -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,20 +1986,15 @@ 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;
@ -2010,24 +2012,20 @@ 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 (is_dir("$path/$entry") && $levelMax!=0) array_push($directoryEntries, "$path/$entry");
}
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);
closedir($directoryHandle);
foreach ($directoryEntries as $directoryEntry) {
list($modifiedBelow, $fileCountBelow) = $this->getDirectoryInformationRecursive($directoryEntry, $levelMax);
$modified = max($modified, $modifiedBelow);
$fileCount += $fileCountBelow;
}
}
}
closedir($directoryHandle);
}
return array($modified, $fileCount);
}

View file

@ -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

View file

@ -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