浏览代码

Refactored code, wee faster directory information

markseu 1 年之前
父节点
当前提交
2eec57fd0d
共有 3 个文件被更改,包括 27 次插入29 次删除
  1. 23 25
      system/extensions/core.php
  2. 2 2
      system/extensions/update-available.ini
  3. 2 2
      system/extensions/update-current.ini

+ 23 - 25
system/extensions/core.php

@@ -2,7 +2,7 @@
 // Core extension, https://github.com/annaesvensson/yellow-core
 // Core extension, https://github.com/annaesvensson/yellow-core
 
 
 class YellowCore {
 class YellowCore {
-    const VERSION = "0.8.129";
+    const VERSION = "0.8.130";
     const RELEASE = "0.8.23";
     const RELEASE = "0.8.23";
     public $content;        // content files
     public $content;        // content files
     public $media;          // media files
     public $media;          // media files
@@ -1965,10 +1965,17 @@ class YellowToolbox {
     
     
     // Return files and directories
     // Return files and directories
     public function getDirectoryEntries($path, $regex = "/.*/", $sort = true, $directories = true, $includePath = true) {
     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();
         $entries = array();
         $directoryHandle = @opendir($path);
         $directoryHandle = @opendir($path);
         if ($directoryHandle) {
         if ($directoryHandle) {
             $path = rtrim($path, "/");
             $path = rtrim($path, "/");
+            $directoryEntries = array();
             while (($entry = readdir($directoryHandle))!==false) {
             while (($entry = readdir($directoryHandle))!==false) {
                 if (substru($entry, 0, 1)==".") continue;
                 if (substru($entry, 0, 1)==".") continue;
                 $entry = $this->yellow->lookup->normaliseUnicode($entry);
                 $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_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);
             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 $entries;
     }
     }
-
+    
     // Return directory information, modification date and file count
     // Return directory information, modification date and file count
     public function getDirectoryInformation($path) {
     public function getDirectoryInformation($path) {
         return $this->getDirectoryInformationRecursive($path, 1);
         return $this->getDirectoryInformationRecursive($path, 1);
@@ -2010,23 +2012,19 @@ class YellowToolbox {
         $directoryHandle = @opendir($path);
         $directoryHandle = @opendir($path);
         if ($directoryHandle) {
         if ($directoryHandle) {
             $path = rtrim($path, "/");
             $path = rtrim($path, "/");
+            $directoryEntries = array();
             while (($entry = readdir($directoryHandle))!==false) {
             while (($entry = readdir($directoryHandle))!==false) {
                 if (substru($entry, 0, 1)==".") continue;
                 if (substru($entry, 0, 1)==".") continue;
                 $modified = max($modified, $this->getFileModified("$path/$entry"));
                 $modified = max($modified, $this->getFileModified("$path/$entry"));
                 if (is_file("$path/$entry")) ++$fileCount;
                 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);
             closedir($directoryHandle);
+            foreach ($directoryEntries as $directoryEntry) {
+                list($modifiedBelow, $fileCountBelow) = $this->getDirectoryInformationRecursive($directoryEntry, $levelMax);
+                $modified = max($modified, $modifiedBelow);
+                $fileCount += $fileCountBelow;
+            }
         }
         }
         return array($modified, $fileCount);
         return array($modified, $fileCount);
     }
     }

+ 2 - 2
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
 system/themes/copenhagen.png: copenhagen.png, create
 
 
 Extension: Core
 Extension: Core
-Version: 0.8.129
+Version: 0.8.130
 Description: Core functionality of your website.
 Description: Core functionality of your website.
 Developer: Anna Svensson
 Developer: Anna Svensson
 Tag: feature
 Tag: feature
 DownloadUrl: https://github.com/annaesvensson/yellow-core/archive/refs/heads/main.zip
 DownloadUrl: https://github.com/annaesvensson/yellow-core/archive/refs/heads/main.zip
 DocumentationUrl: https://github.com/annaesvensson/yellow-core
 DocumentationUrl: https://github.com/annaesvensson/yellow-core
 DocumentationLanguage: en, de, sv
 DocumentationLanguage: en, de, sv
-Published: 2024-04-01 18:44:16
+Published: 2024-04-02 11:48:14
 Status: available
 Status: available
 system/extensions/core.php: core.php, create, update
 system/extensions/core.php: core.php, create, update
 system/layouts/default.html: default.html, create, update, careful
 system/layouts/default.html: default.html, create, update, careful

+ 2 - 2
system/extensions/update-current.ini

@@ -1,14 +1,14 @@
 # Datenstrom Yellow update settings for installed extensions
 # Datenstrom Yellow update settings for installed extensions
 
 
 Extension: Core
 Extension: Core
-Version: 0.8.129
+Version: 0.8.130
 Description: Core functionality of your website.
 Description: Core functionality of your website.
 Developer: Anna Svensson
 Developer: Anna Svensson
 Tag: feature
 Tag: feature
 DownloadUrl: https://github.com/annaesvensson/yellow-core/archive/refs/heads/main.zip
 DownloadUrl: https://github.com/annaesvensson/yellow-core/archive/refs/heads/main.zip
 DocumentationUrl: https://github.com/annaesvensson/yellow-core
 DocumentationUrl: https://github.com/annaesvensson/yellow-core
 DocumentationLanguage: en, de, sv
 DocumentationLanguage: en, de, sv
-Published: 2024-04-01 18:44:16
+Published: 2024-04-02 11:48:14
 Status: available
 Status: available
 system/extensions/core.php: core.php, create, update
 system/extensions/core.php: core.php, create, update
 system/layouts/default.html: default.html, create, update, careful
 system/layouts/default.html: default.html, create, update, careful