From 2b388c21a07e07317ccb065d42ef7304cfca7718 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 7 Mar 2009 02:48:19 +0000 Subject: [PATCH] New function isDirectory() introduced, fixed GET_DIR_AS_ARRAY() (replaces scandir()) --- inc/functions.php | 81 ++++++++++++++++------- inc/libs/cache_functions.php | 2 +- inc/libs/rallye_functions.php | 6 +- inc/modules/admin/what-config_session.php | 2 +- inc/modules/admin/what-logs.php | 2 +- 5 files changed, 63 insertions(+), 30 deletions(-) diff --git a/inc/functions.php b/inc/functions.php index 90c2bdbed1..815e6f72dd 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -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__."(".__LINE__."):dir=".$dir."
\n"; + $ds = GET_DIR_AS_ARRAY($dir, "", true, false); + //* DEBUG: */ print __FUNCTION__."(".__LINE__."):ds[]=".count($ds)."
\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__."(".__LINE__."):FQFN={$FQFN}
\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__."(".__LINE__."):DESCENT: ".$newDir."
\n"; + searchDirsRecursive($newDir, $last_changed); + } elseif (FILE_READABLE($FQFN)) { + // $FQFN is a filename and no directory + $time = filemtime($FQFN); + //* DEBUG: */ print __FUNCTION__."(".__LINE__."):File: ".$d." found. (".($last_changed['time'] - $time).")
\n"; + if ($last_changed['time'] < $time) { + // This file is newer as the file before + //* DEBUG: */ print __FUNCTION__."(".__LINE__.") - NEWER!
\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__."(".__LINE__."):baseDir={$baseDir},prefix={$prefix},baseFile={$baseFile}
\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__."(".__LINE__."): Extension entry ".$baseFile." added.
\n"; $INCs[] = $INC; } elseif ($extId == 0) { // Add non-extension files as well - $INCs[] = $INC; + //* DEBUG: */ print __FUNCTION__."(".__LINE__."): Regular entry ".$baseFile." added.
\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 // ////////////////////////////////////////////////// diff --git a/inc/libs/cache_functions.php b/inc/libs/cache_functions.php index 7753dd1386..8ef45755e8 100644 --- a/inc/libs/cache_functions.php +++ b/inc/libs/cache_functions.php @@ -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")) { diff --git a/inc/libs/rallye_functions.php b/inc/libs/rallye_functions.php index 4461b4ad53..9eaa587fd4 100644 --- a/inc/libs/rallye_functions.php +++ b/inc/libs/rallye_functions.php @@ -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)) { diff --git a/inc/modules/admin/what-config_session.php b/inc/modules/admin/what-config_session.php index 736886f27a..bdf4af075a 100644 --- a/inc/modules/admin/what-config_session.php +++ b/inc/modules/admin/what-config_session.php @@ -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 { diff --git a/inc/modules/admin/what-logs.php b/inc/modules/admin/what-logs.php index 794ecff606..33c537b6a2 100644 --- a/inc/modules/admin/what-logs.php +++ b/inc/modules/admin/what-logs.php @@ -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("
    "); $handle = opendir($dir) or mxchange_die("Cannot open directory ".getConfig('logs_base')."!"); -- 2.39.5