New function isDirectory() introduced, fixed GET_DIR_AS_ARRAY() (replaces scandir())
authorRoland Häder <roland@mxchange.org>
Sat, 7 Mar 2009 02:48:19 +0000 (02:48 +0000)
committerRoland Häder <roland@mxchange.org>
Sat, 7 Mar 2009 02:48:19 +0000 (02:48 +0000)
inc/functions.php
inc/libs/cache_functions.php
inc/libs/rallye_functions.php
inc/modules/admin/what-config_session.php
inc/modules/admin/what-logs.php

index 90c2bdbed1182808ca97e9b66ec7a612ad9ef819..815e6f72dd98e4dcc7f44929ebad98b02e167bdd 100644 (file)
@@ -2525,27 +2525,43 @@ function clearOutputBuffer () {
        } // END - if
 }
 
-// Function to search for the last modifikated file
-function searchDirsRecoursive ($dir, &$last_changed) {
-       $ds = scandir($dir); // Needs adjustment for PHP < 5.0.0!!
+// Function to search for the last modifified file
+function searchDirsRecursive ($dir, &$last_changed) {
+       // Get dir as array
+       //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):dir=".$dir."<br />\n";
+       $ds = GET_DIR_AS_ARRAY($dir, "", true, false);
+       //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):ds[]=".count($ds)."<br />\n";
+
+       // Walk through all entries
        foreach ($ds as $d) {
-               $f_name = $dir.'/'.$d; // makes a proper Filename
-               if (!preg_match('@(\.|\.\.|\.revision|\.svn|debug\.log|\.cache)$@',$d)) {       // no . or  ..  or .revision or .svn in the filename
-                       $is_dir = is_dir($f_name);
-                       if (!$is_dir) { // $f_name is a filename and no directory
-                               $time = filemtime($f_name);
-                               if ($last_changed['time'] < $time) { // This file is newer as the file before
-                                       $last_changed['path_name'] = $f_name;
+               // Generate proper FQFN
+               $FQFN = str_replace("//", "/", constant('PATH') . $dir. "/". $d);
+
+               // Does it match what we are looking for? (We skip a lot files already!)
+               if (!preg_match('@(\.|\.\.|\.revision|\.svn|debug\.log|\.cache)$@', $d)) {      // no . or  ..  or .revision or .svn in the filename
+                       // Is it a file and readable?
+                       //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):FQFN={$FQFN}<br />\n";
+                       if (isDirectory($FQFN)) {
+                                // $FQFN is a directory so also crawl into this directory
+                               $newDir = $d;
+                               if (!empty($dir)) $newDir = $dir . "/". $d;
+                               //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):DESCENT: ".$newDir."<br />\n";
+                               searchDirsRecursive($newDir, $last_changed);
+                       } elseif (FILE_READABLE($FQFN)) {
+                               // $FQFN is a filename and no directory
+                               $time = filemtime($FQFN);
+                               //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):File: ".$d." found. (".($last_changed['time'] - $time).")<br />\n";
+                               if ($last_changed['time'] < $time) {
+                                       // This file is newer as the file before
+                                       //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>) - NEWER!<br />\n";
+                                       $last_changed['path_name'] = $FQFN;
                                        $last_changed['time'] = $time;
-                               }
-                       } elseif ($is_dir) { // $f_name is a directory so also crawl into this directory
-                               searchDirsRecoursive($f_name, $last_changed);
+                               } // END - if
                        }
-               }
-       }
+               } // END - if
+       } // END - foreach
 }
 
-
 // "Getter" for revision/version data
 function getActualVersion ($type = 'Revision') {
        // By default nothing is new... ;-)
@@ -2624,7 +2640,7 @@ function getSearchFor () {
 
 function getAkt_vers () {
        // Init variables
-       $next_dir = ".";
+       $next_dir = "";
        $last_changed = array(
                'path_name' => "",
                'time'      => 0
@@ -2633,7 +2649,7 @@ function getAkt_vers () {
        $res = 0;
 
        // Searches all Files and there date of the last modifikation and puts the newest File in $last_changed.
-       searchDirsRecoursive($next_dir, $last_changed);
+       searchDirsRecursive($next_dir, $last_changed);
 
        // Get file
        $last_file = READ_FILE($last_changed['path_name']);
@@ -3071,7 +3087,8 @@ function DEBUG_LOG ($funcFile, $line, $message, $force=true) {
 }
 
 // Reads a directory with PHP files in and gets only files back
-function GET_DIR_AS_ARRAY ($baseDir, $prefix) {
+function GET_DIR_AS_ARRAY ($baseDir, $prefix, $includeDirs = false, $addBaseDir = true) {
+       // Init includes
        $INCs = array();
 
        // Open directory
@@ -3079,13 +3096,13 @@ function GET_DIR_AS_ARRAY ($baseDir, $prefix) {
 
        // Read all entries
        while ($baseFile = readdir($dirPointer)) {
-               // Load file only if extension is active
-               $INC = $baseDir.$baseFile;
+               // Construct include filename and FQFN
+               $INC = $baseDir . "/" . $baseFile;
                $FQFN = constant('PATH') . $INC;
 
                // Is this a valid reset file?
                //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):baseDir={$baseDir},prefix={$prefix},baseFile={$baseFile}<br />\n";
-               if ((FILE_READABLE($FQFN)) && (substr($baseFile, 0, strlen($prefix)) == $prefix) && (substr($baseFile, -4, 4) == ".php")) {
+               if (((FILE_READABLE($FQFN)) && (substr($baseFile, 0, strlen($prefix)) == $prefix) && (substr($baseFile, -4, 4) == ".php")) || (($includeDirs) && (isDirectory($FQFN)))) {
                        // Remove both for extension name
                        $extName = substr($baseFile, strlen($prefix), -4);
 
@@ -3095,10 +3112,16 @@ function GET_DIR_AS_ARRAY ($baseDir, $prefix) {
                        // Is the extension valid and active?
                        if (($extId > 0) && (EXT_IS_ACTIVE($extName))) {
                                // Then add this file
+                               //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>): Extension entry ".$baseFile." added.<br />\n";
                                $INCs[] = $INC;
                        } elseif ($extId == 0) {
                                // Add non-extension files as well
-                               $INCs[] = $INC;
+                               //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>): Regular entry ".$baseFile." added.<br />\n";
+                               if ($addBaseDir) {
+                                       $INCs[] = $INC;
+                               } else {
+                                       $INCs[] = $baseFile;
+                               }
                        }
                } // END - if
        } // END - while
@@ -3570,6 +3593,18 @@ function isUserIdSet () {
        return (isset($GLOBALS['userid']));
 }
 
+// Checks wether the given FQFN is a directory and not .,.. or .svn
+function isDirectory ($FQFN) {
+       // Generate baseName
+       $baseName = basename($FQFN);
+
+       // Check it
+       $isDirectory = ((is_dir($FQFN)) && ($baseName != ".") && ($baseName != "..") && ($baseName != ".svn"));
+
+       // Return the result
+       return $isDirectory;
+}
+
 //////////////////////////////////////////////////
 // AUTOMATICALLY RE-GENERATED MISSING FUNCTIONS //
 //////////////////////////////////////////////////
index 7753dd138679fe449382c7dd76d604643dcc230b..8ef45755e83065b164b2d75320bec6a415c0c957 100644 (file)
@@ -64,7 +64,7 @@ class CacheSystem {
                $this->path = $path;
 
                // Check if path exists
-               if ((is_dir($path)) && (!$tested)) {
+               if ((isDirectory($path)) && (!$tested)) {
                        // Check if we can create a file inside the path
                        touch($path."dummy.tmp", 'w');
                        if (FILE_READABLE($path."dummy.tmp")) {
index 4461b4ad53489c884c6279cc07066542eab1b78f..9eaa587fd4be24cd7505cdd03c88144a29211a9a 100644 (file)
@@ -682,11 +682,9 @@ function RALLYE_TEMPLATE_SELECTION($name="template", $default="")
        $OUT = ""; $ral = array();
        $BASE = sprintf("%stemplates/%s/html/rallye/", constant('PATH'), GET_LANGUAGE());
        $dir = opendir($BASE);
-       while ($read = readdir($dir))
-       {
+       while ($read = readdir($dir)) {
                // If it is no dir (so a file)
-               if (!is_dir($BASE.$read))
-               {
+               if (!isDirectory($BASE.$read)) {
                        // Accept only templates matching with rallye_????.tpl.xx
                        if (eregi("^rallye_.*\.tpl", $read))
                        {
index 736886f27ac17936c2dd5ff509c48187a7f22af0..bdf4af075a687bfb112e7c87d88a87eac2a880e1 100644 (file)
@@ -47,7 +47,7 @@ ADD_DESCR("admin", __FILE__);
 
 if (IS_FORM_SENT()) {
        // Test Path
-       if ((!REQUEST_ISSET_POST(('session_save_path'))) || ((is_dir(REQUEST_POST('session_save_path'))) && (is_writeable(REQUEST_POST('session_save_path'))))) {
+       if ((!REQUEST_ISSET_POST(('session_save_path'))) || ((isDirectory(REQUEST_POST('session_save_path'))) && (is_writeable(REQUEST_POST('session_save_path'))))) {
                // Save configuration
                ADMIN_SAVE_SETTINGS_POST();
        } else {
index 794ecff606a3fc7aa226d59b915b504177a49ff5..33c537b6a2d3eeb6b99e372d71bf670a6c9f5831 100644 (file)
@@ -90,7 +90,7 @@ if (REQUEST_ISSET_GET(('access'))) {
 } else {
        // List access logfiles
        $dir = constant('PATH') . getConfig('logs_base') . "/";
-       if (is_dir($dir)) {
+       if (isDirectory($dir)) {
                // logs directory does exist
                OUTPUT_HTML("<ol>");
                $handle = opendir($dir) or mxchange_die("Cannot open directory ".getConfig('logs_base')."!");