<?php
//THIS FUNCTION WILL RETURN A SORTED ARRAY OF ALL FILES AND FOLDERS IN THE CURRENT DIRECTORY
function getDirList($input_dir="")
{
global $dir;
if($input_dir == '')
$input_dir = $dir;
$dh = opendir(stripslashes($input_dir));
while (false !== ($filename = readdir($dh)))
{
$files[] = $filename;
}
@sort($files);
return $files;
}
function subDirExist()
{
global $dirlink;
$exist = false;
if(count($dirlink)!=0)
$exist = true;
return $exist;
}
function getImgLinks()
{
global $imglink;
return $imglink;
}
function getDirDescription()
{
global $dir;
global $descriptions;
$path = explode('/',$dir);
$file = $path[count($path)-1];
if(is_numeric($file)) $file += 0;
$description = $descriptions[$file]['desc'];
return stripslashes($description);
}
//THIS FUNCTION GENERATES THE SUB-DIRECTORY LINKS FOR THE CURRENT DIRECTORY. IT RETURNS VOID.
function getDirLinks()
{
global $dirlink,$cat_thumbs;
?>
<h3><?php echo $GLOBALS['lang_sub_folders']; ?></h3>
<?php
if($cat_thumbs==true){
echo "<div class=\"catthumbs\">
";
foreach($dirlink as $link){
echo "<div>$link</div>";
}
echo "</div>
<div class=\"clearer\"></div>";
}else{
echo "<ul class=\"cat\">
";
foreach($dirlink as $link){
echo "<li>$link</li>";
}
echo "</ul>
";
}
}
function getPageTitle() {
global $page_title;
echo stripslashes($page_title);
}
function getCurrentWorkingDirectory() {
$parts = pathinfo($_SERVER['PHP_SELF']);
if($parts['dirname'] != '/')
echo $parts['dirname'];
else
echo '';
}
function returnCurrentWorkingDirectory() {
$parts = pathinfo($_SERVER['PHP_SELF']);
if($parts['dirname'] != '/')
return $parts['dirname'];
else
return '';
}
function gd_version() {
static $gd_version_number = null;
if ($gd_version_number === null) {
// Use output buffering to get results from phpinfo()
// without disturbing the page we're in. Output
// buffering is "stackable" so we don't even have to
// worry about previous or encompassing buffering.
ob_start();
phpinfo(8);
$module_info = ob_get_contents();
ob_end_clean();
if (preg_match("/\bgd\s+version\b[^\d
\r]+?([\d\.]+)/i",
$module_info,$matches)) {
$gd_version_number = $matches[1];
} else {
$gd_version_number = 0;
}
}
return $gd_version_number;
}
function getFile() {
global $display_file, $resize_file, $maxwidth, $maxheight, $resize, $cacheresizedfolder, $cacheresized, $img_attr, $modrewrite;
$cached_img = $cacheresizedfolder . "/" . md5(substr($resize_file,2,strlen($resize_file)-2)) . ".jpg";
$path = pathinfo($_SERVER['PHP_SELF']);
$path = $path['dirname'];
if($path == '/') $path = '';
$local_resize = $resize;
list($actual_width, $actual_height) = getimagesize($resize_file);
if ( $actual_width <= $maxwidth && $actual_height <= $maxheight ) $local_resize = false;
if(!function_exists('imagecreate') || $maxwidth == 0 || $maxheight ==0 || !$local_resize)
echo '<img id="single" src="' . $display_file;
else
{
echo '<a href="' . $display_file . '" title="'.$GLOBALS['lang_full_img'].'"><img id="single" src="';
if($cacheresized && file_exists($cached_img) && sizeMatches($cached_img, 'full') && resizedCacheFilesizeMatch(md5(substr($resize_file,2,strlen($resize_file)-2)), filesize($resize_file)))
echo $path . '/' . $cached_img;
else
{
if($modrewrite)
echo $path . "/resize/" . $resize_file;
else
echo $path . "/sp_resize.php?source=" . $resize_file;
}
}
echo '" ' . $img_attr . ' alt="';
getAltText();
echo '" title="';
getTitleText();
if(function_exists('imagecreate') && $maxwidth > 0 && $maxheight > 0 && $local_resize)
echo '" /></a>';
else
echo '" />';
}
function getAltText() {
global $descriptions, $current;
if(!empty($descriptions[$current]['alt']))
echo stripslashes($descriptions[$current]['alt']);
else if(!empty($descriptions[$current]['desc']))
echo stripslashes($descriptions[$current]['desc']);
else
echo stripslashes($current);
}
function getTitleText() {
global $descriptions, $current;
echo stripslashes($descriptions[$current]['popup']);
}
function getImageDate() {
global $descriptions, $current;
echo stripslashes($descriptions[$current]['date']);
}
function dateExists(){
global $descriptions, $current;
// if($descriptions[$current]['date'] != ''){
if(!empty($descriptions[$current]['date'])){
return true;
}else{
return false;
}
}
function getDescription() {
global $descriptions, $current;
$getdesc=preg_replace( '!<br />!iU', "<br />", $descriptions[$current]["desc"] );
echo stripslashes($getdesc);
}
function showDescription() {
global $descriptions, $current;
echo unstriphtml(stripslashes($descriptions[$current]["desc"]));
}
function unstriphtml($string){
$trans_tbl = get_html_translation_table(HTML_ENTITIES);
$trans_tbl = array_flip($trans_tbl);
return strtr($string, $trans_tbl);
}
function descriptionExists() {
global $descriptions;
global $current;
$exists = false;
if(!empty($descriptions[$current]['desc']))
$exists = true;
return $exists;
}
function sizeMatches($image, $size='thumb') {
global $maxthumbwidth, $maxthumbheight, $maxwidth, $maxheight;
$match = false;
if(file_exists($image))
{
$path = pathinfo($image);
switch(strtolower($path["extension"])){
case "jpeg":
case "jpg":
$image=imagecreatefromjpeg($image);
break;
case "gif":
$image=imagecreatefromgif($image);
break;
case "png":
$image=imagecreatefrompng($image);
break;
case "swf":
$image="gallerygraphic/flash.jpg"
break;
default:
break;
}
$x = imagesx($image);
$y = imagesy($image);
imagedestroy($image);
if($size == 'thumb')
{
if((($x == $maxthumbwidth) && ($y <= $maxthumbheight)) || (($x <= $maxthumbwidth) && ($y == $maxthumbheight)))
$match = true;
}
if($size == 'full')
{
if((($x == $maxwidth) && ($y <= $maxheight)) || (($x <= $maxwidth) && ($y == $maxheight)))
$match = true;
}
}
return $match;
}
function clearCache() {
clearThumbCache();
clearResizedCache();
}
function clearThumbCache() {
global $cachefolder;
rmdirr($cachefolder);
@mkdir($cachefolder, 0755);
$cache_ini = @fopen($cachefolder . "/cache.ini","a");
@fclose($cache_ini);
}
function clearResizedCache() {
global $cacheresizedfolder;
rmdirr($cacheresizedfolder);
@mkdir($cacheresizedfolder, 0755);
$cache_ini = @fopen($cacheresizedfolder . "/resized_cache.ini","a");
@fclose($cache_ini);
}
function rmdirr($dirname)
{
// Sanity check
if (!file_exists($dirname)) {
return false;
}
// Simple delete for a file
if (is_file($dirname)) {
return unlink($dirname);
}
// Loop through the folder
$dir = dir($dirname);
while (false !== $entry = $dir->read()) {
// Skip pointers
if ($entry == '.' || $entry == '..') {
continue;
}
// Deep delete directories
if (is_dir("$dirname/$entry")) {
rmdirr("$dirname/$entry");
} else {
unlink("$dirname/$entry");
}
}
// Clean up
$dir->close();
return rmdir($dirname);
}
function cacheLinkMatch($hash)
{
global $cache_ini, $cachethumbs, $modrewrite;
$match = false;
if($modrewrite && !eregi('sp_',$cache_ini[$hash]['url']))
$match = true;
if(!$modrewrite && eregi('sp_',$cache_ini[$hash]['url']))
$match = true;
return $match;
}
function cacheFilesizeMatch($hash, $filesize)
{
global $cache_ini;
$match = false;
if($filesize == $cache_ini[$hash]['size'])
$match = true;
return $match;
}
function resizedCacheFilesizeMatch($hash, $filesize)
{
global $resized_cache_ini;
$match = false;
if($filesize == $resized_cache_ini[$hash]['size'])
$match = true;
return $match;
}
function getPrevAndNext() {
global $modrewrite, $precache, $resize, $maxwidth, $maxheight;
$files = getDirList('./' . dirname($_GET['file']) . '/');
foreach($files as $img)
{
if(eregi(".*(\.jpg|\.gif|\.png|\.jpeg|\.swf)", $img))
$imgfiles[] = $img;
}
$current_index = array_search(basename($_GET['file']),$imgfiles);
$prev_index = $current_index-1;
if($prev_index == -1)
$prev_index = count($imgfiles)-1;
$next_index = $current_index+1;
if($next_index == count($imgfiles))
$next_index = 0;
if ($modrewrite)
{
$prev_link = " <a accesskey=\"-\" id=\"prev\" href=\"" . returnCurrentWorkingDirectory() . "/file/" . dirname($_GET['file']) . '/' . $imgfiles[$prev_index] . "\">« ".$GLOBALS['lang_prev']." [-]</a>";
$next_link = " <a accesskey=\"=\" id=\"next\" href=\"" . returnCurrentWorkingDirectory() . "/file/" . dirname($_GET['file']) . '/' . $imgfiles[$next_index] . "\">[+] ".$GLOBALS['lang_next']." »</a>" . "<a accesskey=\"+\" href=\"" . returnCurrentWorkingDirectory() . "/file/" . dirname($_GET['file']) . '/' . $imgfiles[$next_index] . "\"></a>";
}
else
{
$prev_link = " <a accesskey=\"-\" id=\"prev\" href=\"" . $_SERVER['PHP_SELF'] . "?file=" . dirname($_GET['file']) . '/' . $imgfiles[$prev_index] . "\">«".$GLOBALS['lang_prev']." [-]</a>";
$next_link = " <a accesskey=\"=\" id=\"next\" href=\"" . $_SERVER['PHP_SELF'] . "?file=" . dirname($_GET['file']) . '/' . $imgfiles[$next_index] . "\">[+] ".$GLOBALS['lang_next']." »</a>" . "<a accesskey=\"+\" href=\"" . $_SERVER['PHP_SELF'] . "?file=" . dirname($_GET['file']) . '/' . $imgfiles[$next_index] . "\"></a>";
}
echo $prev_link . "
" . $next_link;
if ($precache)
{
$trueimagepath = dirname($_SERVER['PHP_SELF']) . "/" . dirname($_GET['file']);
if(function_exists('imagecreate') && $maxwidth > 0 && $maxheight > 0 && $resize)
{
list($actual_width, $actual_height) = getimagesize('./' . dirname($_GET['file']) . '/' . $imgfiles[$prev_index]);
if ( $actual_width <= $maxwidth && $actual_height <= $maxheight )
echo "
<img src=\"" . $trueimagepath . "/" . $imgfiles[$prev_index] . "\" width=\"1\" height=\"1\" alt=\"\" class=\"precache\" />";
else
{
if ($modrewrite)
echo "
<img src=\"" . dirname($_SERVER['PHP_SELF']) . "/resize/" . dirname($_GET['file']) . "/" . $imgfiles[$prev_index] . "\" width=\"1\" height=\"1\" alt=\"\" class=\"precache\" />";
else
echo "
<img src=\"" . dirname($_SERVER['PHP_SELF']) . "/sp_resize.php?source=" . dirname($_GET['file']) . "/" . $imgfiles[$prev_index] . "\" width=\"1\" height=\"1\" alt=\"\" class=\"precache\" />";
}
list($actual_width, $actual_height) = getimagesize('./' . dirname($_GET['file']) . '/' . $imgfiles[$next_index]);
if ( $actual_width <= $maxwidth && $actual_height <= $maxheight )
echo "
<img src=\"" . $trueimagepath . "/" . $imgfiles[$next_index] . "\" width=\"1\" height=\"1\" alt=\"\" class=\"precache\" />";
else
{
if ($modrewrite)
echo "
<img src=\"" . dirname($_SERVER['PHP_SELF']) . "/resize/" . dirname($_GET['file']) . "/" . $imgfiles[$next_index] . "\" width=\"1\" height=\"1\" alt=\"\" class=\"precache\" />";
else
echo "
<img src=\"" . dirname($_SERVER['PHP_SELF']) . "/sp_resize.php?source=" . dirname($_GET['file']) . "/" . $imgfiles[$next_index] . "\" width=\"1\" height=\"1\" alt=\"\" class=\"precache\" />";
}
}
else
{
echo "
<img src=\"" . $trueimagepath . "/" . $imgfiles[$prev_index] . "\" width=\"1\" height=\"1\" alt=\"\" class=\"precache\" />";
echo "
<img src=\"" . $trueimagepath . "/" . $imgfiles[$next_index] . "\" width=\"1\" height=\"1\" alt=\"\" class=\"precache\" />";
}
}
}
//THIS FUNCTION GENERATES THE BREADCRUMB TRAIL DISPLAYED AT THE TOP OF THE PAGE. IT RETURNS VOID.
function getBreadCrumbs()
{
global $descriptions;
global $dir;
global $display_file;
global $current_working_directory;
global $title;
global $modrewrite;
global $editmode;
$nodir = false;
if($dir != '.')
$patharr = explode('/', $dir);
else
{
$cwd = returnCurrentWorkingDirectory() . '/';
$path = @str_replace($cwd,'',$display_file);
//echo $path;
if(!$path)
$path = $display_file;
if($cwd == '/')
$path = substr($display_file,1,strlen($display_file)-1);
//echo $path;
$patharr = explode('/', $path);
$nodir = true;
}
$linkpath = '.';
$counter = 0;
// amend breadcrumb to work when in editing mode assumed sp_editor.php
if($editmode){
echo "<strong>".$GLOBALS['lang_curr_view']."</strong> <a href=\"" . returnCurrentWorkingDirectory() . "/sp_editor.php\"";
}else{
echo "<strong>".$GLOBALS['lang_curr_view']."</strong> <a href=\"" . returnCurrentWorkingDirectory() . "/\"";
}
if((count($patharr) == 2 && isset($_GET['dir']))||(count($patharr) == 1 && isset($_GET['file'])))
echo " accesskey=\"u\"";
echo ">" . $title . "</a> ";
foreach($patharr as $folder)
{
$test_file = $folder; //DWW
if(is_numeric($test_file)) $test_file += 0; //DWW
if(!empty($descriptions[$test_file]['title']))
$foldername = stripslashes($descriptions[$test_file]['title']);
else
$foldername = $folder;
if(!eregi('^\.',$folder))
{
$linkpath .= "/$folder";
if($patharr[count($patharr)-1] != $folder)
{
if ($modrewrite)
{
echo '» <a href="' . returnCurrentWorkingDirectory() . '/folder/' . $linkpath . '"';
if($counter == (count($patharr)-2))
echo " accesskey=\"u\"";
echo ">$foldername</a> ";
}
else
{
echo "» <a href=\"" . $_SERVER['PHP_SELF'] . "?dir=$linkpath\"";
if($counter == count($patharr)-2)
echo " accesskey=\"u\"";
echo ">$foldername</a> ";
}
}
else if($patharr[count($patharr)-1] == '')
;
else
{
if($nodir)
{
if(!empty($descriptions[$folder]['title']))
echo "» <strong>" . stripslashes($descriptions[$test_file]['title']) . "</strong>";
else
echo "» <strong>$folder</strong>";
}
else
echo "» <strong>$foldername</strong>";
}
}
$counter++;
}
}
function getNumImages($dir)
{
$num_images = 0;
foreach(getDirList($dir) as $file)
{
if( eregi(".*(\.jpg|\.gif|\.png|\.jpeg|\.swf)", $file))
{
$num_images++;
}
}
return $num_images;
}
function getNumDir($directory)
{
global $cachefolder;
$num_dir = 0;
foreach(getDirList($directory) as $item)
{
$path = $directory . '/' . $item;
if(is_dir($path) && $item != '.' && $item != '..' && $item != $cachefolder)
$num_dir++;
}
return $num_dir;
}
function write_ini_file($path, $assoc_array) {
$content = '';
foreach ($assoc_array as $key => $item) {
if (is_array($item)) {
$content .= "
[$key]
";
foreach ($item as $key2 => $item2) {
$content .= "$key2 = \"$item2\"
";
}
} else {
$content .= "$key = \"$item\"
";
}
}
if (!$handle = fopen($path, 'w')) {
return false;
}
if (!fwrite($handle, $content)) {
return false;
}
fclose($handle);
return true;
}
function getPrevAndNextLink() {
global $modrewrite;
$files = getDirList('./' . dirname($_GET['file']) . '/');
foreach($files as $img)
{
if(eregi(".*(\.jpg|\.gif|\.png|\.jpeg|\.swf)", $img))
$imgfiles[] = $img;
}
$current_index = array_search(basename($_GET['file']),$imgfiles);
$prev_index = $current_index-1;
if($prev_index == -1)
$prev_index = count($imgfiles)-1;
$next_index = $current_index+1;
if($next_index == count($imgfiles))
$next_index = 0;
if($modrewrite)
{
$up_link = "<link rel=\"Up\" href=\"" . returnCurrentWorkingDirectory() . "/folder/" . dirname($_GET['file']) . "/\" />";
$prev_link = "<link rel=\"Prev\" href=\"" . returnCurrentWorkingDirectory() . "/file/" . dirname($_GET['file']) . '/' . $imgfiles[$prev_index] . "\" />";
$next_link = "<link rel=\"Next\" href=\"" . returnCurrentWorkingDirectory() . "/file/" . dirname($_GET['file']) . '/' . $imgfiles[$next_index] . "\" />";
}
else
{
$up_link = "<link rel=\"Up\" href=\"" . $_SERVER['PHP_SELF'] . "?dir=" . dirname($_GET['file']) . "/\" />";
$prev_link = "<link rel=\"Prev\" href=\"" . $_SERVER['PHP_SELF'] . "?file=" . dirname($_GET['file']) . '/' . $imgfiles[$prev_index] . "\" />";
$next_link = "<link rel=\"Next\" href=\"" . $_SERVER['PHP_SELF'] . "?file=" . dirname($_GET['file']) . '/' . $imgfiles[$next_index] . "\" />";
}
echo $up_link . "
" . $prev_link . "
" . $next_link . "
";
}
function getStartLink() {
global $imglist;
if(empty($imglist[0])){
$start_link='';
}else{
$start_link = "<link rel=\"Next\" href=\"" . $imglist[0] . "\" />";
}
echo $start_link . "
";
}
function paginate() {
global $limit, $dir, $modrewrite;
$totalrows = getNumImages($dir);
$numofpages = $totalrows / $limit;
$page = $_GET['page'];
$limitvalue = $page * $limit - ($limit);
if($numofpages > 1)
{
echo $GLOBALS['lang_page_now'].$page.$GLOBALS['lang_of'].ceil($numofpages)."<br />
";
}
if($page != 1)
{
$pageprev = $page - 1;
if ($modrewrite)
echo("<a href=\"" . returnCurrentWorkingDirectory() . "/folder/$dir&page=" . $pageprev . "\" title=\"" . $GLOBALS['lang_prev'] . $limit . $GLOBALS['lang_results']."\">".$GLOBALS['lang_prev']."</a> ");
else
echo("<a href=\"" . $_SERVER['PHP_SELF'] . "?dir=" . $dir . "&page=" . $pageprev . "\" title=\"" . $GLOBALS['lang_prev'] . $limit . $GLOBALS['lang_results']."\">".$GLOBALS['lang_prev']."</a> ");
}
if($numofpages > 1)
{
for($i = 1; $i <= $numofpages; $i++)
{
if ($i == $page)
{
echo($i." ");
}
else
{
if ($modrewrite)
echo("<a href=\"" . returnCurrentWorkingDirectory() . "/folder/$dir&page=" . $i . "\" title=\"".$GLOBALS['lang_results']. (($i*$limit)-$limit+1) . $GLOBALS['lang_to'] . ($i*$limit) . "\">" . $i . "</a> ");
else
echo("<a href=\"" . $_SERVER['PHP_SELF'] . "?dir=" . $dir . "&page=" . $i . "\" title=\"".$GLOBALS['lang_results']. (($i*$limit)-$limit+1) . $GLOBALS['lang_to'] . ($i*$limit) . "\">" . $i . "</a> ");
}
}
if(($totalrows % $limit) != 0)
{
if($i == $page)
{
echo($i." ");
}
else
{
if ($modrewrite)
echo("<a href=\"" . returnCurrentWorkingDirectory() . "/folder/$dir&page=" . $i . "\" title=\"".$GLOBALS['lang_results']. (($i*$limit)-$limit+1) . $GLOBALS['lang_to'] . $totalrows . "\">" . $i . "</a> ");
else
echo("<a href=\"" . $_SERVER['PHP_SELF'] . "?dir=" . $dir . "&page=" . $i . "\" title=\"".$GLOBALS['lang_results'] . (($i*$limit)-$limit+1) . $GLOBALS['lang_to'] . $totalrows . "\">" . $i . "</a> ");
}
}
if(($totalrows - ($limit * $page)) > 0)
{
$pagenext = $page + 1;
$lastpage = $totalrows - ($limit * $page);
if($limit > $lastpage)
{
$nextresults = $lastpage;
}
else
{
$nextresults = $limit;
}
if ($modrewrite)
echo("<a href=\"" . returnCurrentWorkingDirectory() . "/folder/$dir&page=" . $pagenext . "\" title=\"" . $GLOBALS['lang_next'] . $nextresults . " ".$GLOBALS['lang_results']."\">".$GLOBALS['lang_next']."</a>");
else
echo("<a href=\"" . $_SERVER['PHP_SELF'] . "?dir=" . $dir . "&page=" . $pagenext . "\" title=\"" . $GLOBALS['lang_next'] . $nextresults . " ".$GLOBALS['lang_results']."\">".$GLOBALS['lang_next']."</a>");
}
}
}
function randImg($webpath){
$idir=opendir($webpath);
//This is the directory route to the folder
$idirectory=$webpath.'/';
//This is a relative link to the directory if it is not in the same directory as the file you are displaying the images on
$pattern="\.(gif|jpg|jpeg|png|swf)$";
if(!$idir){
die("Failed to read directory");
}
$s=readdir($idir);
$count="0";
$image='';
while($s){
if(ereg($pattern, $s)){
$image[$count]=$s;
$count++;
}
$s=readdir($idir);
}
closedir($idir);
//Spit it out
$limit=count($image);
$limit--;
$randNum=rand(0,$limit);
if(!empty($limit) || $limit==0){
$size=getimagesize("$idirectory$image[$randNum]");
$random = "
<img class=\"tnexample\"src=\"sp_getthumb.php?source=$idirectory$image[$randNum]\" alt=\"\" />";
}else{
$random="
";
}
return $random;
}
?>
hmm, i’m not sure how to make it work with a flash file
so basically i want a flash file to have a flash.jpg as a thumbnail