return ((isset($GLOBALS['extra_title'])) && (!empty($GLOBALS['extra_title'])));
}
-// Reads a directory recursively by default and searches for files not matching
-// an exclusion pattern. You can now keep the exclusion pattern empty for reading
-// a whole directory.
+/**
+ * Reads a directory recursively by default and searches for files not matching
+ * an exclusion pattern. You can now keep the exclusion pattern empty for reading
+ * a whole directory.
+ *
+ * @param $baseDir Relative base directory to PATH to scan from
+ * @param $prefix Prefix for all positive matches (which files should be found)
+ * @param $fileIncludeDirs Wether to include directories in the final output array
+ * @param $addBaseDir Wether to add $baseDir to all array entries
+ * @param $excludeArray Excluded files and directories, these must be full files names, e.g. 'what-' will exclude all files named 'what-' but won't exclude 'what-foo.php'
+ * @param $extension File extension for all positive matches
+ * @param $excludePattern Regular expression to exclude more files (preg_match())
+ * @param $recursive Wether to scan recursively
+ * @param $suffix Suffix for positive matches ($extension will be appended, too)
+ * @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 = '') {
- // Add default entries we should exclude
- $excludeArray[] = '.';
- $excludeArray[] = '..';
- $excludeArray[] = '.svn';
- $excludeArray[] = '.htaccess';
+ // Add default entries we should always exclude
+ $excludeArray[] = '.'; // Current directory
+ $excludeArray[] = '..'; // Parent directory
+ $excludeArray[] = '.svn'; // Directories created by Subversion
+ $excludeArray[] = '.htaccess'; // Directory protection files (mostly)
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'baseDir=' . $baseDir . ',prefix=' . $prefix . ' - Entered!');
- // Init includes
- $files = array();
+ // Init found includes
+ $foundMatches = array();
// Open directory
$dirPointer = opendir(getPath() . $baseDir) or debug_report_bug(__FUNCTION__, __LINE__, 'Cannot read directory ' . basename($baseDir) . '.');
// Check if the base filenname matches an exclusion pattern and if the pattern is not empty
if ((!empty($excludePattern)) && (preg_match($excludePattern, $baseFile, $match))) {
- // These Lines are only for debugging!!
- //* DEBUG: */ debugOutput('baseDir:' . $baseDir);
- //* DEBUG: */ debugOutput('baseFile:' . $baseFile);
- //* DEBUG: */ debugOutput('FQFN:' . $FQFN);
+ // Debug message
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'baseDir=' . $baseDir . ',baseFile=' . $baseFile . ',FQFN=' . $FQFN);
// Exclude this one
continue;
// Skip also files with non-matching prefix genericly
if (($recursive === true) && (isDirectory($FQFN))) {
// Is a redirectory so read it as well
- $files = merge_array($files, getArrayFromDirectory($baseDir . $baseFile . '/', $prefix, $fileIncludeDirs, $addBaseDir, $excludeArray, $extension, $excludePattern, $recursive));
+ $foundMatches = merge_array($foundMatches, getArrayFromDirectory($baseDir . $baseFile . '/', $prefix, $fileIncludeDirs, $addBaseDir, $excludeArray, $extension, $excludePattern, $recursive));
// And skip further processing
continue;
// Add file with or without base path
if ($addBaseDir === true) {
// With base path
- $files[] = $fileName;
+ $foundMatches[] = $fileName;
} else {
// No base path
- $files[] = $baseFile;
+ $foundMatches[] = $baseFile;
}
} else {
// We found .php file but should not search for them, why?
}
} elseif ($fileExtension == $extension) {
// Other, generic file found
- $files[] = $fileName;
+ $foundMatches[] = $fileName;
}
} // END - while
closedir($dirPointer);
// Sort array
- sort($files);
+ sort($foundMatches);
// Return array with include files
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, '- Left!');
- return $files;
+ return $foundMatches;
}
// Checks wether $prefix is found in $fileName