/** * Function to match a set of queries against a directory and possibly all subfiles. * @param query The Query send in to process and test against. * @param patterns The set of regexp patterns generated off the query. * @param dir the directory to search in. * @param recurse Whether or not to recurse into subdirs and test files there too. * * @return Array. Returns an array of all matches of the query. */ function matchFiles($query, $patterns, $ignoreCase, $dir, $rootDir, $recurse, $dirsOnly, $expand, $showHiddenFiles) { $files = array(); $fullDir = $rootDir . "/" . $dir; if ($fullDir != null && is_dir($fullDir)) { $dirHandle = opendir($fullDir); while ($file = readdir($dirHandle)) { if ($file != "." && $file != "..") { $item = generateFileObj($file, $dir, $rootDir, $expand, $showHiddenFiles); $keys = array_keys($patterns); $total = count($keys); for ($i = 0; $i < $total; $i++) { $key = $keys[$i]; $pattern = $query[$key]; $matched = containsValue($item, $key, $query[$key], $patterns[$key], $ignoreCase); if (!$matched) { break; } } if ($matched) { if (!$dirsOnly || $item["directory"]) { if ($showHiddenFiles || $item["name"][0] != '.') { $files[] = $item; } } } if (is_dir($rootDir . "/" . $item["path"]) && $recurse) { if ($showHiddenFiles || $item["name"][0] != '.') { $files = array_merge($files, matchFiles($query, $patterns, $ignoreCase, $item["path"], $rootDir, $recurse, $dirsOnly, $expand, $showHiddenFiles)); } } } } closedir($dirHandle); } return $files; }
} if (file_exists($fullPath)) { $arr = split("/", $path); $size = count($arr); if ($size > 0) { $fName = $arr[$size - 1]; if ($size == 1) { print "Setting path to: ."; $path = "."; } else { $path = $arr[0]; } for ($i = 1; $i < $size - 1; $i++) { $path = $path . "/" . $arr[$i]; } $file = generateFileObj($fName, $path, $rootDir, $expand, $showHiddenFiles); header("Content-Type", "text/json"); print "/* " . json_encode($file) . " */"; } else { header("HTTP/1.0 404 Not Found"); header("Status: 404 Not Found"); print "<b>Cannot access file: [" . $path . "]<b>"; } } else { header("HTTP/1.0 404 Not Found"); header("Status: 404 Not Found"); print "<b>Cannot access file: [" . $path . "]<b>"; } } else { header("HTTP/1.0 403 Forbidden"); header("Status: 403 Forbidden");