function walkDir($dir) { $tmpDir = $dir; chdir($dir); $dir = getcwd(); chdir($tmpDir); $dh = opendir($dir); while (FALSE !== ($something = readdir($dh))) { if ($something != '.' && $something != '..') { $something_absolute = $dir . '/' . $something; if (is_dir($something_absolute) && !is_link($something_absolute)) { walkDir($something_absolute); } else { $GLOBALS['WALK_DIR_RESULTS'][$something_absolute] = TRUE; } } } closedir($dh); }
function walkDir($directory, $list=NULL) { global $currentDir; global $navHtml, $mainHtml, $exampleCounter; if ($list == NULL) { $list = scandir($directory); } $navHtml .= '<ul>'; foreach ($list as $filename) { if ($filename[0] == ".") { continue; } $origFilename = $filename; $filename = $directory."/".$filename; if (is_dir($filename)) { if (substr($currentDir, 0, strlen($filename)) == $filename) { $navHtml .= "<li>$origFilename:"; $mainHtml .= "<h2>$origFilename</h2>"; walkDir($filename); } else { $navHtml .= "<li><a href=\"?section={$filename}\">$origFilename</a>"; } continue; } $jsonObj = json_decode(file_get_contents($filename)); $filename = substr($filename, 0, strlen($filename) - 5); $navHtml .= '<li><a href="#'.$filename.'">'.$jsonObj->title.'</a>'; $mainHtml .= "<a name=\"$filename\"></a><div class=\"box\"><h3 class=\"box-heading\">{$jsonObj->title}</h3>"; $mainHtml .= "<div class=\"section\"><div class=\"description\">{$jsonObj->description}</div>"; foreach ($jsonObj->content as $paragraph) { if (is_array($paragraph)) { $mainHtml .= "<ul>"; foreach ($paragraph as $bullet) { $mainHtml .= "<li>$bullet"; } $mainHtml .= "</ul>"; } else { $mainHtml .= "<p>$paragraph"; } } if (isset($jsonObj->exampleSchema)) { $exampleNumber = $exampleCounter++; $mainHtml .= "<pre class=\"example code\"><div class=\"highlight-json-schema\" id=\"example-schema{$exampleNumber}\"></div></pre>"; $mainHtml .= "<div class=\"example\" id=\"example{$exampleNumber}\"></div>"; $mainHtml .= "<script>\n"; $mainHtml .= "var schema = Jsonary.createSchema(".json_encode($jsonObj->exampleSchema).");\n"; if (isset($jsonObj->exampleData)) { $mainHtml .= "var data = Jsonary.create(".json_encode($jsonObj->exampleData).");\n"; } else { $mainHtml .= "var data = Jsonary.create(schema.asList().createValue());\n"; } $mainHtml .= "data.addSchema(schema).renderTo(document.getElementById('example{$exampleNumber}'));\n"; $mainHtml .= "var innerText = JSON.stringify(".json_encode($jsonObj->exampleSchema).", null, 4);\n"; $mainHtml .= "document.getElementById('example-schema{$exampleNumber}').json = innerText;\n"; $mainHtml .= "document.getElementById('example-schema{$exampleNumber}').appendChild(document.createTextNode(innerText));\n"; $mainHtml .= "</script>"; } $mainHtml .= "</div></div>"; } $navHtml .= "</ul>"; $mainHtml .= ""; }
function walkDir($i_recv, $i_dir, &$o_out, $i_depth) { global $FileMaxLength; if ($i_depth > $i_recv['depth']) { return; } if (false == is_dir($i_dir)) { $o_out['error'] = 'No such folder.'; return; } $rufolder = null; if (array_key_exists('rufolder', $i_recv)) { $rufolder = $i_recv['rufolder']; } $rufiles = null; if (array_key_exists('rufiles', $i_recv)) { $rufiles = $i_recv['rufiles']; } $lookahead = null; if (array_key_exists('lookahead', $i_recv)) { $lookahead = $i_recv['lookahead']; } $access = false; $denied = true; if (htaccessPath($i_dir)) { $access = true; $denied = false; } else { $rufiles = array('rules'); $o_out['denied'] = true; } if ($handle = opendir($i_dir)) { $o_out['folders'] = array(); $o_out['files'] = array(); $walk = null; $walk_file = $i_dir . '/' . $rufolder . '/walk.json'; if (is_file($walk_file)) { if ($wHandle = fopen($walk_file, 'r')) { //error_log($path); $wdata = fread($wHandle, $FileMaxLength); //error_log($wdata); $walk = json_decode($wdata, true); fclose($wHandle); } } while (false !== ($entry = readdir($handle))) { if (skipFile($entry)) { continue; } $path = $i_dir . '/' . $entry; if ($access && false == is_dir($path)) { if (is_file($path)) { $fileObj = array(); if (false == is_null($walk) && isset($walk['files']) && isset($walk['files'][$entry])) { $fileObj = $walk['files'][$entry]; } $fileObj['name'] = $entry; $fileObj['size'] = filesize($path); $fileObj['mtime'] = filemtime($path); array_push($o_out['files'], $fileObj); } continue; } if ($entry == $rufolder && is_dir($path)) { $o_out['rufiles'] = array(); $o_out['rules'] = array(); if ($rHandle = opendir($path)) { while (false !== ($ruentry = readdir($rHandle))) { if ($ruentry == '.') { continue; } if ($ruentry == '..') { continue; } if ($access) { array_push($o_out['rufiles'], $ruentry); } if (strrpos($ruentry, '.json') === false) { continue; } if (is_null($rufiles)) { continue; } $found = false; foreach ($rufiles as $rufile) { if (strpos($ruentry, $rufile) === 0) { $found = true; break; } } if (false == $found) { continue; } if ($fHandle = fopen($path . '/' . $ruentry, 'r')) { $rudata = fread($fHandle, $FileMaxLength); $ruobj = json_decode($rudata, true); $o_out['rules'][$ruentry] = $ruobj; fclose($fHandle); } } closedir($rHandle); sort($o_out['rufiles']); ksort($o_out['rules']); } continue; } if ($i_recv['showhidden'] == false && is_file("{$path}/.hidden")) { continue; } if ($denied) { continue; } if (false === htaccessFolder($path)) { continue; } $folderObj = array(); if (is_array($walk)) { if (array_key_exists('folders', $walk)) { if (array_key_exists($entry, $walk['folders'])) { $folderObj = $walk['folders'][$entry]; } } } $folderObj['name'] = $entry; $folderObj['mtime'] = filemtime($path); if ($rufolder && $lookahead) { foreach ($lookahead as $sfile) { $sfilepath = $path . '/' . $rufolder . '/' . $sfile . '.json'; if (is_file($sfilepath)) { if ($fHandle = fopen($sfilepath, 'r')) { $data = fread($fHandle, $FileMaxLength); fclose($fHandle); mergeObjs($folderObj, json_decode($data, true)); } } } } if ($i_depth < $i_recv['depth']) { walkDir($i_recv, $path, $folderObj, $i_depth + 1); } array_push($o_out['folders'], $folderObj); } closedir($handle); } }
static function findUnownedFiles($dir) { $dir = str_replace('./', '', $dir); if (!preg_match('/^\\//', $dir)) { $dir = getcwd() . '/' . $dir; } if (!is_dir($dir)) { return sendMessage('invalidDirectory', array('%dir' => $dir)); } PacmanData::initializeFileList(); walkDir($dir); $dir_strlen = strlen($dir); $progress_position = 0; $progress_length = count($GLOBALS['pacman_file_list']->file_list); foreach ($GLOBALS['pacman_file_list']->file_list as $packageName => $packageData) { echo "\r" . round($progress_position++ / $progress_length * 10000) / 100 . '%'; $tmpFiles = $packageData['%FILES%']; $tmpFiles_count = count($tmpFiles); for ($i = 0; $i < $tmpFiles_count; $i++) { $currFile = $tmpFiles[$i]; $GLOBALS['WALK_DIR_RESULTS'][$currFile] = FALSE; } } echo "\r"; foreach ($GLOBALS['WALK_DIR_RESULTS'] as $file => $ownerMissing) { if ($ownerMissing === TRUE) { echo $file . "\n"; } } if ($GLOBALS['uid'] != 0) { sendMessage('recomendRootOrphans', array()); } }