Refactored code, wee faster directory information
This commit is contained in:
parent
ac111f92f6
commit
2eec57fd0d
|
@ -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);
|
||||
foreach ($directoryEntries as $directoryEntry) {
|
||||
$entries = array_merge($entries, $this->getDirectoryEntriesRecursive($directoryEntry, $regex, $sort, $directories, $includePath, $levelMax));
|
||||
}
|
||||
}
|
||||
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));
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue