function mkhash($f) { if (uis_dir($f)) { return sha1(basename(rtrim($f, '\\/'))) . md5(serialize(uscandir($f))); } return sha1(basename($f)) . ufilesize($f); }
function ls($curpath) { global $_lang; global $excludes, $editablefiles, $inlineviewablefiles, $viewablefiles, $enablefileunzip, $enablefiledownload, $uploadablefiles, $folders, $files, $filesizes, $len, $dirs_array, $files_array, $webstart_path, $manager_theme, $modx; $dircounter = 0; $filecounter = 0; $curpath = str_replace('//', '/', $curpath . '/'); if (!is_dir($curpath)) { echo 'Invalid path "', $curpath, '"<br />'; return; } $dir = dir($curpath); // first, get info while ($file = $dir->read()) { if (!in_array($file, $excludes)) { $newpath = $curpath . $file; if (is_dir($newpath)) { $dirs_array[$dircounter]['dir'] = $newpath; $dirs_array[$dircounter]['stats'] = lstat($newpath); $dirs_array[$dircounter]['text'] = '<img src="media/style/' . $manager_theme . 'images/tree/folder.gif" border="0" align="absmiddle" alt="" /> <a href="index.php?a=31&mode=drill&path=' . urlencode($newpath) . '"><b>' . $file . '</b></a>'; $dirs_array[$dircounter]['delete'] = is_writable($curpath) ? '<span style="width:20px"><a href="javascript: deleteFolder(\'' . urlencode($curpath) . '\', \'' . urlencode($newpath) . '\');"><img src="media/style/' . $manager_theme . 'images/icons/delete.gif" alt="' . $_lang['file_delete_folder'] . '" title="' . $_lang['file_delete_folder'] . '" /></a></span>' : ''; // increment the counter $dircounter++; } else { $type = getExtension($newpath); $files_array[$filecounter]['file'] = $newpath; $files_array[$filecounter]['stats'] = lstat($newpath); $files_array[$filecounter]['text'] = '<img src="media/style/' . $manager_theme . 'images/tree/page-html.gif" border="0" align="absmiddle" alt="" />' . $file; $files_array[$filecounter]['view'] = in_array($type, $viewablefiles) ? '<span style="cursor:pointer; width:20px;" onclick="viewfile(\'' . $webstart_path . substr($newpath, $len, strlen($newpath)) . '\');"><img src="media/style/' . $manager_theme . 'images/icons/context_view.gif" border="0" align="absmiddle" alt="' . $_lang['files_viewfile'] . '" title="' . $_lang['files_viewfile'] . '" /></span>' : ($enablefiledownload && in_array($type, $uploadablefiles) ? '<a href="' . $webstart_path . implode('/', array_map('rawurlencode', explode('/', substr($newpath, $len, strlen($newpath))))) . '" style="cursor:pointer; width:20px;"><img src="media/style/' . $manager_theme . 'images/misc/ed_save.gif" border="0" align="absmiddle" alt="' . $_lang['file_download_file'] . '" title="' . $_lang['file_download_file'] . '" /></a>' : '<span class="disabledImage"><img src="media/style/' . $manager_theme . 'images/icons/context_view.gif" border="0" align="absmiddle" alt="' . $_lang['files_viewfile'] . '" title="' . $_lang['files_viewfile'] . '" /></span>'); $files_array[$filecounter]['view'] = in_array($type, $inlineviewablefiles) ? '<span style="width:20px;"><a href="index.php?a=31&mode=view&path=' . urlencode($newpath) . '"><img src="media/style/' . $manager_theme . 'images/icons/context_view.gif" border="0" align="absmiddle" alt="' . $_lang['files_viewfile'] . '" title="' . $_lang['files_viewfile'] . '" /></a></span>' : $files_array[$filecounter]['view']; $files_array[$filecounter]['unzip'] = $enablefileunzip && $type == '.zip' ? '<span style="width:20px;"><a href="index.php?a=31&mode=unzip&path=' . $curpath . '&file=' . urlencode($file) . '" onclick="return confirmUnzip();"><img src="media/style/' . $manager_theme . 'images/icons/unzip.gif" border="0" align="absmiddle" alt="' . $_lang['file_download_unzip'] . '" title="' . $_lang['file_download_unzip'] . '" /></a></span>' : ''; $files_array[$filecounter]['edit'] = in_array($type, $editablefiles) && is_writable($curpath) && is_writable($newpath) ? '<span style="width:20px;"><a href="index.php?a=31&mode=edit&path=' . urlencode($newpath) . '#file_editfile"><img src="media/style/' . $manager_theme . 'images/icons/save.png" border="0" align="absmiddle" alt="' . $_lang['files_editfile'] . '" title="' . $_lang['files_editfile'] . '" /></a></span>' : '<span class="disabledImage"><img src="media/style/' . $manager_theme . 'images/icons/save.png" border="0" align="absmiddle" alt="' . $_lang['files_editfile'] . '" title="' . $_lang['files_editfile'] . '" /></span>'; $files_array[$filecounter]['delete'] = is_writable($curpath) && is_writable($newpath) ? '<span style="width:20px;"><a href="javascript:deleteFile(\'' . urlencode($newpath) . '\');"><img src="media/style/' . $manager_theme . 'images/icons/delete.gif" border="0" align="absmiddle" alt="' . $_lang['file_delete_file'] . '" title="' . $_lang['file_delete_file'] . '" /></a></span>' : '<span class="disabledImage"><img src="media/style/' . $manager_theme . 'images/icons/delete.gif" border="0" align="absmiddle" alt="' . $_lang['file_delete_file'] . '" title="' . $_lang['file_delete_file'] . '" /></span>'; // increment the counter $filecounter++; } } } $dir->close(); // dump array entries for directories $folders = count($dirs_array); sort($dirs_array); // sorting the array alphabetically (Thanks pxl8r!) for ($i = 0; $i < $folders; $i++) { $filesizes += $dirs_array[$i]['stats']['7']; echo '<tr style="cursor:default;" onmouseout="setColor(this,0)" onmouseover="setColor(this,1)">'; echo '<td>', $dirs_array[$i]['text'], '</td>'; echo '<td>', $modx->toDateFormat($dirs_array[$i]['stats']['9']), '</td>'; echo '<td dir="ltr">', ufilesize($dirs_array[$i]['stats']['7']), '</td>'; echo '<td>'; echo $dirs_array[$i]['delete']; echo '</td>'; echo '</tr>'; } // dump array entries for files $files = count($files_array); sort($files_array); // sorting the array alphabetically (Thanks pxl8r!) for ($i = 0; $i < $files; $i++) { $filesizes += $files_array[$i]['stats']['7']; echo '<tr onmouseout="setColor(this,0)" onmouseover="setColor(this,1)">'; echo '<td>', $files_array[$i]['text'], '</td>'; echo '<td>', $modx->toDateFormat($files_array[$i]['stats']['9']), '</td>'; echo '<td dir="ltr">', ufilesize($files_array[$i]['stats']['7']), '</td>'; echo '<td>'; echo $files_array[$i]['unzip']; echo $files_array[$i]['view']; echo $files_array[$i]['edit']; echo $files_array[$i]['delete']; echo '</td>'; echo '</tr>'; } return; }
function ls($curpath) { global $excludes, $editablefiles, $inlineviewablefiles, $viewablefiles, $folders, $files, $filesizes, $len, $dirs_array, $files_array, $timestampFormat, $server_offset_time; $dircounter = 0; $filecounter = 0; $dir = dir($curpath); // first, get info while ($file = $dir->read()) { if (!in_array($file, $excludes)) { $newpath = $curpath . "/" . $file; if (is_dir($newpath)) { $dirs_array[$dircounter]['dir'] = $newpath; $dirs_array[$dircounter]['stats'] = lstat($newpath); $dirs_array[$dircounter]['text'] = "<img src='media/images/tree/folder.gif' border=0> <a href='index.php?a=31&mode=drill&path={$newpath}'><b style=' font-size: 11px;'>{$file}</b></a>"; // increment the counter $dircounter++; } else { $type = getExtension($newpath); $files_array[$filecounter]['file'] = $newpath; $files_array[$filecounter]['stats'] = lstat($newpath); $files_array[$filecounter]['text'] = "<img src='media/images/tree/page.gif' border=0> {$file}"; $files_array[$filecounter]['view'] = in_array($type, $viewablefiles) ? "<span style='cursor:pointer; width:20px;' onClick='viewfile(\"" . substr($newpath, $len, strlen($newpath)) . "\");'><img src='media/images/icons/context_view.gif' border=0></span> " : "<span class='disabledImage'><img src='media/images/icons/context_view.gif' border=0></span> "; $files_array[$filecounter]['view'] = in_array($type, $inlineviewablefiles) ? "<span style='width:20px;'><a href='index.php?a=31&mode=view&path={$newpath}'><img src='media/images/icons/context_view.gif' border=0></a></span> " : $files_array[$filecounter]['view']; $files_array[$filecounter]['edit'] = in_array($type, $editablefiles) && is_writable($curpath) && is_writable($newpath) ? "<span style='width:20px;'><a href='index.php?a=31&mode=edit&path={$newpath}'><img src='media/images/icons/save.gif' border=0></a></span> " : "<span class='disabledImage'><img src='media/images/icons/save.gif' border=0></span> "; $files_array[$filecounter]['delete'] = is_writable($curpath) && is_writable($newpath) ? "<span style='width:20px;'><a href='javascript:confirmDelete(\"" . addslashes("index.php?a=31&mode=delete&path={$newpath}") . "\");'><img src='media/images/icons/delete.gif' border=0></a></span>" : "<span class='disabledImage'><img src='media/images/icons/delete.gif' border=0></span>"; // increment the counter $filecounter++; } } } $dir->close(); // dump array entries for directories $folders = count($dirs_array); sort($dirs_array); for ($i = 0; $i < $folders; $i++) { $filesizes += $dirs_array[$i]['stats']['7']; echo "<div style='position: relative; float: left; width: 300px; font-size: 11px;'>" . $dirs_array[$i]['text'] . "</div>"; echo "<div style='position: relative; float: left; width: 140px; text-align:right; font-size: 11px;'>" . strftime($timestampFormat, $dirs_array[$i]['stats']['9'] + $server_offset_time) . "</div>"; echo "<div style='position: relative; float: left; width: 120px; text-align:right; font-size: 11px;'>" . ufilesize($dirs_array[$i]['stats']['7']) . "</div>"; echo "<br clear='all' />\n"; } // dump array entries for files $files = count($files_array); sort($files_array); for ($i = 0; $i < $files; $i++) { $filesizes += $files_array[$i]['stats']['7']; echo "<div style='position: relative; float: left; width: 300px; font-size: 11px;'>" . $files_array[$i]['text'] . "</div>"; echo "<div style='position: relative; float: left; width: 140px; text-align:right; font-size: 11px;'>" . strftime($timestampFormat, $files_array[$i]['stats']['9'] + $server_offset_time) . "</div>"; echo "<div style='position: relative; float: left; width: 120px; text-align:right; font-size: 11px;'>" . ufilesize($files_array[$i]['stats']['7']) . "</div>"; echo "<div style='position: relative; float: left; width: 120px; text-align:right; font-size: 11px;'>"; echo $files_array[$i]['view']; echo $files_array[$i]['edit']; echo $files_array[$i]['delete']; echo "</div>"; echo "<br clear='all' />\n"; } return; }
function renderdir($rootdir, $dir) { global $ignore; $ret = ''; $r = $fnlist = $dirlist = array(); $r['index'] = null; if (($dir = safepath($rootdir, $dir)) === false) { redirect('index.php'); } $r['dir'] = $dir; $list = (array) uscandir(pathjoin($rootdir, $dir)); if ($list === false) { redirect('index.php?base=' . $_GET['base']); } foreach ($list as $e) { if ($e == '.' || $e == '..' || in_array(strtolower($e), $ignore)) { continue; } if (uis_dir(pathjoin($rootdir, $dir, $e))) { $dirlist[] = $e; } else { $fnlist[] = $e; } } $index_file = tryindex($fnlist, $dir); if (!empty($index_file)) { $r['index'] = pathjoin($rootdir, $dir, $index_file); } natsort($dirlist); natsort($fnlist); foreach ($dirlist as $e) { $cfg = loadcfg(pathjoin($rootdir, $dir, $e)); if (isset($cfg['index'])) { $idx = pathjoin($dir, $e, upath($cfg['index'])); $ahref = urlenc(pathjoin($rootdir, $idx)); $img = 'thumb.php?base=' . $_GET['base'] . '&file=' . urlencode($idx); } else { $ahref = 'index.php?base=' . $_GET['base'] . '&dir=' . urlencode(pathjoin($dir, $e)); $img = 'images/dir.gif'; } if (isset($cfg['icon'])) { $img = 'thumb.php?base=' . $_GET['base'] . '&file=' . urlencode(pathjoin($dir, $e, upath($cfg['icon']))); } $ret .= mkitem($e, $e, $e, '<a href="' . $ahref . '"' . ($cfg['target'] == '_blank' ? ' target="_blank"' : '') . '>', $img, istoday(pathjoin($rootdir, $dir, $e)), ($dz = udirsize(pathjoin($rootdir, $dir, $e))) > 0 ? '<br /><a name="pack" style="visibility: hidden; float:right;" href="pack.php?base=' . $_GET['base'] . '&dir=' . urlencode(pathjoin($dir, $e)) . '"><img alt="Download" title="Download - ' . fsize($dz) . '" src="images/pack.gif" /></a>' : ''); } foreach ($fnlist as $e) { if (isvideo($e) || isaudio($e)) { $ahref = '<a href="flowplayer.php?base=' . $_GET['base'] . '&file=' . urlencode(pathjoin($dir, $e)) . '">'; } elseif (isimage($e)) { $ahref = '<a href="image.php?base=' . $_GET['base'] . '&file=' . urlencode(pathjoin($dir, $e)) . '">'; } elseif (isweb($e)) { $ahref = '<a href="' . urlenc(pathjoin($rootdir, $dir, $e)) . '">'; } elseif (isdocument($e)) { $ahref = '<a href="document.php?base=' . $_GET['base'] . '&file=' . urlencode(pathjoin($dir, $e)) . '">'; } elseif (iscode($e)) { $ahref = '<a href="code.php?base=' . $_GET['base'] . '&file=' . urlencode(pathjoin($dir, $e)) . '">'; } else { $ahref = '<a href="' . urlenc(pathjoin($rootdir, $dir, $e)) . '">'; } # echo $dir.$e."\t".urlencode($dir.$e)."\n"; $ret .= mkitem($e, $e, $e . ' - (' . fsize(ufilesize(pathjoin($rootdir, $dir, $e))) . ')', $ahref, 'thumb.php?base=' . $_GET['base'] . '&file=' . urlencode(pathjoin($dir, $e)), istoday(pathjoin($rootdir, $dir, $e)), null); } $r['html'] = $ret; return $r; }
plugins: { streaming: { url: 'flowplayer/flowplayer.pseudostreaming-3.2.7.swf' }, audio: { url: 'flowplayer/flowplayer.audio-3.2.2.swf' } } }); </script> <br /><br /> <a href="<?php echo urlenc($rootdir . $file); ?> " style="color:#555;">原始檔案下載(<?php echo fsize(ufilesize($rootdir . $_GET['file'])); ?> )</a> </center> </body> </html> <?php } else { $job = array('base' => $_GET['base'], 'file' => $file); $gmc = new Gearmanclient(); $gmc->addServer(); $gmc->doBackground("webnautilus", serialize($job)); ?> <html> <head> <meta http-equiv="refresh" content="10" />