function tryindex($fs, $dir) { global $CFG, $RTI; $bdir = basedir($dir); $index_file = ''; $ifile = pathjoin($CFG['cachedir'], $RTI['base'], sha1($dir) . '.idx'); if (isarchive() && ($index_file = @file_get_contents($ifile)) !== false) { return $index_file; } else { foreach ($fs as $f) { if (!isweb($f)) { continue; } if (empty($index_file)) { $index_file = $f; } elseif (preg_match('/^index/i', $f)) { if (preg_match('/^index/i', $index_file)) { if (strlen(getname($f)) < strlen(getname($index_file))) { $index_file = $f; } } else { $index_file = $f; } } elseif (preg_match('/^default/i', $f)) { if (preg_match('/^default/i', $index_file)) { if (strlen(getname($f)) < strlen(getname($index_file))) { $index_file = $f; } } elseif (!preg_match('/^index/i', $index_file)) { $index_file = $f; } } elseif (levenshtein($bdir, $f) < levenshtein($bdir, $index_file) && !preg_match('/^index/i', $index_file) && !preg_match('/^default/i', $index_file)) { $index_file = $f; } } if (isarchive()) { if (!ufile_exists($CFG['cachedir'] . $RTI['base'])) { umkdir($CFG['cachedir'] . $RTI['base']); } file_put_contents($ifile, $index_file); } return $index_file; } }
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; }
$cmd = $CFG['ghostscript'] . ' -dNOPAUSE -dBATCH -dFirstPage=1 -dLastPage=1 -sDEVICE=bmp16 -sOutputFile=' . $CFG['tempdir'] . $thash . '.bmp ' . escapeshellarg($pdf); exe($cmd); rmtry($tfile); rmtry($pdf); } $cmd = $CFG['imagemagick_convert'] . ' -quality 70 -geometry ' . $size . ' ' . escapeshellarg($CFG['tempdir'] . $thash . '.bmp') . ' ' . escapeshellarg($CFG['tempdir'] . $thash . '.jpg'); exe($cmd); rmtry($CFG['tempdir'] . $thash . '.bmp'); if (ufile_exists($CFG['tempdir'] . $thash . '.jpg')) { ucopy($CFG['tempdir'] . $thash . '.jpg', $CFG['cachedir'] . $hash . '_' . $size . '.jpg'); touch($CFG['cachedir'] . $hash . '_' . $size . '.jpg', ufiletime($rootdir . $file), $_now); uunlink($CFG['tempdir'] . $thash . '.jpg'); } myunlock($thash); } } elseif (isweb($file)) { if (newer($rootdir . $file, $CFG['cachedir'] . $hash . '_' . $size . '.jpg')) { mylock($thash) || exit; if (!ufile_exists($CFG['tempdir'] . $thash . '.png')) { while (ufile_exists($CFG['tempdir'] . 'firefox.lock')) { sleep(rand(5, 15)); } utouch($CFG['tempdir'] . 'firefox' . '.lock'); file_put_contents($CFG['tempdir'] . 'firefox' . '.lock', $thash); $cmd = $firefox . ' -no-remote -profile ' . escapeshellarg($ffprofile) . ' -saveimage ' . escapeshellarg('file:///' . r(urealpath($rootdir . $file))) . ' -savedelay 100 -witdh 1024'; #logger($cmd); exe($cmd); ucopy($ffdownload . 'shot.png', $CFG['tempdir'] . $thash . '.png'); uunlink($ffdownload . 'shot.png'); uunlink($CFG['tempdir'] . 'firefox' . '.lock'); $cmd = $imagemagick_identify . ' -format "%wx%h" ' . escapeshellarg($CFG['tempdir'] . $thash . '.png');