Exclude directories now
[mailer.git] / inc / functions.php
index 4cd9373bec8338167d3e97019aadd59a7a490d38..9060a90193d3f85512b0599ca1a7a87efe22a99b 100644 (file)
@@ -51,7 +51,7 @@ function getFatalArray () {
 }
 
 // Add a fatal error message to the queue array
-function addFatalMessage ($F, $L, $message, $extra = '') {
+function addFatalMessage ($file, $line, $message, $extra = '') {
        if (is_array($extra)) {
                // Multiple extras for a message with masks
                $message = call_user_func_array('sprintf', $extra);
@@ -64,7 +64,7 @@ function addFatalMessage ($F, $L, $message, $extra = '') {
        array_push($GLOBALS['fatal_messages'], $message);
 
        // Log fatal messages away
-       logDebugMessage($F, $L, 'Fatal error message: ' . compileCode($message));
+       logDebugMessage($file, $line, 'Fatal error message: ' . compileCode($message));
 }
 
 // Getter for total fatal message count
@@ -1772,9 +1772,10 @@ function isExtraTitleSet () {
  * @param      $excludePattern         Regular expression to exclude more files (preg_match())
  * @param      $recursive                      whether to scan recursively
  * @param      $suffix                         Suffix for positive matches ($extension will be appended, too)
+ * @param      $withPrefixSuffix       Whether to include prefix/suffix in found entries
  * @return     $foundMatches           All found positive matches for above criteria
  */
-function getArrayFromDirectory ($baseDir, $prefix, $fileIncludeDirs = FALSE, $addBaseDir = TRUE, $excludeArray = array(), $extension = '.php', $excludePattern = '@(\.|\.\.)$@', $recursive = TRUE, $suffix = '') {
+function getArrayFromDirectory ($baseDir, $prefix, $fileIncludeDirs = FALSE, $addBaseDir = TRUE, $excludeArray = array(), $extension = '.php', $excludePattern = '@(\.|\.\.)$@', $recursive = TRUE, $suffix = '', $withPrefixSuffix = TRUE) {
        // Add default entries we should always exclude
        array_unshift($excludeArray, '.', '..', '.svn', '.htaccess');
 
@@ -1853,6 +1854,9 @@ function getArrayFromDirectory ($baseDir, $prefix, $fileIncludeDirs = FALSE, $ad
                                if ($addBaseDir === TRUE) {
                                        // With base path
                                        array_push($foundMatches, $fileName);
+                               } elseif (($withPrefixSuffix === FALSE) && (!empty($extension))) {
+                                       // No prefix/suffix
+                                       array_push($foundMatches, substr($baseFile, strlen($prefix), -strlen($suffix . $extension)));
                                } else {
                                        // No base path
                                        array_push($foundMatches, $baseFile);
@@ -1861,9 +1865,18 @@ function getArrayFromDirectory ($baseDir, $prefix, $fileIncludeDirs = FALSE, $ad
                                // We found .php file but should not search for them, why?
                                reportBug(__FUNCTION__, __LINE__, 'We should find files with extension=' . $extension . ', but we found a PHP script. (baseFile=' . $baseFile . ')');
                        }
-               } elseif ($fileExtension == $extension) {
+               } elseif ((($fileExtension == $extension) || (empty($extension))) && (isFileReadable($FQFN))) {
                        // Other, generic file found
-                       array_push($foundMatches, $fileName);
+                       if ($addBaseDir === TRUE) {
+                               // With base path
+                               array_push($foundMatches, $fileName);
+                       } elseif (($withPrefixSuffix === FALSE) && (!empty($extension))) {
+                               // No prefix/suffix
+                               array_push($foundMatches, substr($baseFile, strlen($prefix), -strlen($suffix . $extension)));
+                       } else {
+                               // No base path
+                               array_push($foundMatches, $baseFile);
+                       }
                }
        } // END - while
 
@@ -1903,7 +1916,7 @@ function mapModuleToTable ($moduleName) {
 }
 
 // Add SQL debug data to array for later output
-function addSqlToDebug ($result, $sqlString, $timing, $F, $L) {
+function addSqlToDebug ($result, $sqlString, $timing, $file, $line) {
        // Is there cache?
        if (!isset($GLOBALS['debug_sql_available'])) {
                // Check it and cache it in $GLOBALS
@@ -1916,13 +1929,13 @@ function addSqlToDebug ($result, $sqlString, $timing, $F, $L) {
        } // END - if
 
        // Already executed?
-       if (isset($GLOBALS['debug_sqls'][$F][$L][$sqlString])) {
+       if (isset($GLOBALS['debug_sqls'][$file][$line][$sqlString])) {
                // Then abort here, we don't need to profile a query twice
                return;
        } // END - if
 
        // Remeber this as profiled (or not, but we don't care here)
-       $GLOBALS['debug_sqls'][$F][$L][$sqlString] = TRUE;
+       $GLOBALS['debug_sqls'][$file][$line][$sqlString] = TRUE;
 
        // Generate record
        $record = array(
@@ -1930,8 +1943,8 @@ function addSqlToDebug ($result, $sqlString, $timing, $F, $L) {
                'affected' => sqlAffectedRows(),
                'sql_str'  => $sqlString,
                'timing'   => $timing,
-               'file'     => basename($F),
-               'line'     => $L
+               'file'     => basename($file),
+               'line'     => $line
        );
 
        // Add it