function getChildIncludes($liveFile) { global $xmlr; $localRootDir = getLCIRootFolderFromPagePath($liveFile); $localPreviewDir = $localRootDir . '/cms_preview'; $localLiveDir = $localRootDir . '/cms_live'; if (!is_dir($localPreviewDir) || !is_dir($localLiveDir)) { return false; } $localPreviewDirHandle = opendir($localPreviewDir); while (False !== ($lciFile = readdir($localPreviewDirHandle))) { if ($lciFile != '.' & $lciFile != '..' && !is_dir($localPreviewDir . '/' . $lciFile)) { $xmlr .= '<lci>'; $xmlr .= '<type>' . getFileExtension($lciFile) . '</type>'; $xmlr .= '<filename>' . $lciFile . '</filename>'; $xmlr .= '<filestatus>' . matchFiles($localPreviewDir . '/' . $lciFile, getLiveLCIFromPreview($localPreviewDir . '/' . $lciFile)) . '</filestatus>'; $xmlr .= '</lci>'; } } closedir($localPreviewDirHandle); }
/** * 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; }
//Handle query for files. Must try to generate patterns over the query //attributes. $patterns = array(); if (is_array($query)) { //Generate a series of RegExp patterns as necessary. $keys = array_keys($query); $total = count($keys); if ($total > 0) { for ($i = 0; $i < $total; $i++) { $key = $keys[$i]; $pattern = $query[$key]; if (is_string($pattern)) { $patterns[$key] = patternToRegExp($pattern); } } $files = matchFiles($query, $patterns, $ignoreCase, ".", $rootDir, $deep, $dirsOnly, $expand, $showHiddenFiles); } else { $files = getAllFiles(".", $rootDir, $deep, $dirsOnly, $expand, $showHiddenFiles); } } else { $files = getAllFiles(".", $rootDir, $deep, $dirsOnly, $expand, $showHiddenFiles); } $total = count($files); //Handle the sorting and paging. $sortSpec = false; if (array_key_exists("sort", $_GET)) { $sortSpec = $_GET['sort']; $sortSpec = str_replace("\\\"", "\"", $sortSpec); $sortSpec = json_decode($sortSpec); } if ($sortSpec != null) {