function filedirs($dirstart, $level, $theidparent) { $theidparent2 = $theidparent; $level2 = $level; $dirstart2 = $dirstart; global $fileids, $dirids, $node, $uniq, $checkfiletype; #,$foldernode; $i = 1; if ($dirstart2 !== '.') { $dirextra = "{$dirstart2}/"; } if ($level2 == 0) { $rootfolder = 1; } if ($handle = opendir($dirstart2)) { ++$level2; $dirs = array(); $diri = 0; $files = array(); $filei = 0; while (false != ($entry = readdir($handle))) { if ($entry != "." && $entry != "..") { if (filetype($dirextra . $entry) == "dir") { $dirs[$diri] = $dirextra . $entry; ++$diri; $thefile = ""; } elseif ($entry !== 'config.inc.php') { preg_match('/\\.([^\\.]*)$/i', $entry, $match); $thefile = $match[1]; if ($thefile == $checkfiletype) { $files[$filei] = $dirextra . $entry; ++$filei; $thefile = ""; } } } } $i2 = 0; $n = count($dirs); $nm = $n - 1; $nf = count($files); $nfm = $nf - 1; foreach ($dirs as $dirpart) { $diddir = 1; if (!empty($dirpart)) { $theid = "id-{$level2}-{$i}-{$uniq}"; ++$uniq; if ($dirstart2 != ".") { $newdir = $dirstart2 . '/' . $dirpart; } else { $newdir = $dirpart; } $dirids[$theid] = $newdir; if ($i2 !== 0) { echo ",\n"; } #echo str_repeat("\t",$level); echo "{folder: true, key:\"{$theid}\""; $i3 = 0; if ($handle2 = opendir($newdir)) { while (false != ($entry2 = readdir($handle2))) { if ($entry2 != "." && $entry2 != "..") { if (filetype($newdir . '/' . $entry2) == "dir") { $found1 = 1; ++$i3; } else { preg_match('/\\.([^\\.]*)$/i', $entry2, $match); $thefile = $match[1]; } if ($thefile == 'php') { $found1 = 1; ++$i3; } } } } if (isset($found1)) { echo ", title:\"{$dirpart} *{$i3}\", children: [\n"; filedirs($newdir, $level2, $theid); echo "]}"; unset($found1); $found2 = 1; } else { echo ", title: \"{$dirpart}\"}"; } ++$i; ++$i2; } } if (isset($rootfolder)) { $theid = "id-{$level2}-{$i}-{$uniq}"; ++$uniq; ++$i; $theidparent2 = $theid; $dirids[$theid] = '.'; echo ",\n{folder: true,title: \"RootFolder\", key:\"{$theid}\""; if ($nf > 0) { echo ", children: [\n"; $closeroot = 1; } else { echo "}"; } } elseif ($i2 > 0 && $nf > 0 && isset($diddir)) { echo ",\n"; } elseif (isset($found2)) { unset($found2); echo ",\n"; } $i2 = 0; foreach ($files as $filepart) { if (!empty($filepart)) { $theid = "id-{$level2}-{$i}-{$uniq}"; ++$uniq; if (!empty($theidparent2)) { if (!empty($node[$theidparent2])) { $node[$theidparent2] .= ',' . $theid; } else { $node[$theidparent2] = $theid; } } $fileids[$theid] = $filepart; preg_match('/([^\\/]*)$/i', $filepart, $match); if ($i2 !== 0) { echo ",\n"; } echo "{title: \"{$match['1']}\", key:\"{$theid}\"}"; ++$i; ++$i2; } } if (isset($diddir)) { unset($diddir); } if (isset($closeroot)) { echo "]}"; unset($closeroot); } } closedir($handle); }
function filedirs($dirstart, $level) { global $fileids, $dirids; $i = 1; if ($dirstart !== '.') { $dirextra = "{$dirstart}/"; } else { $rootfolder = 1; } if ($handle = opendir($dirstart)) { ++$level; $dirs = array(); $diri = 0; $files = array(); $filei = 0; while (false != ($entry = readdir($handle))) { if ($entry != "." && $entry != "..") { if (is_dir($dirextra . $entry) === true) { $dirs[$diri] = $entry; ++$diri; $thefile = ""; } else { preg_match('/\\.([^\\.]*)$/i', $entry, $match); $thefile = $match[1]; } if ($thefile == 'php') { $files[$filei] = $dirextra . $entry; ++$filei; } } } foreach ($dirs as $dirpart) { $theid = "id{$level}.{$i}"; echo "<li id='{$theid}' class='folder'>{$dirpart}<ul>\n"; ++$i; if ($dirstart != ".") { $newdir = $dirstart . '/' . $dirpart; } else { $newdir = $dirpart; } $dirids[$theid] = $newdir . $dirpart; filedirs($newdir, $level); echo '</ul>'; } if (isset($rootfolder)) { echo "<li id='id{$level}.{$i}' class='folder expanded'>ROOT_FOLDER<ul>\n"; } foreach ($files as $filepart) { $theid = "id{$level}.{$i}"; $fileids[$theid] = $filepart; preg_match('/([^\\/]*)$/i', $filepart, $match); echo "<li id='{$theid}'>" . $match[1] . "\n"; ++$i; } if (isset($rootfolder)) { echo '</ul>'; } closedir($handle); } }