'."\n"; }else{ $rss = ''; } // Viewer if($enable_viewer && file_exists(dirname(__FILE__).'/'.$viewer_file)){ $viewer = ' Image viewer'."\n"; }else{ $viewer = ''; } // Fixing image directory strings $directory = preg_replace('#/+$#','',$directory); $directory = empty($directory) ? dirname(__FILE__) : $directory; if(strlen($image_url) > 1 && !preg_match('#/$#',$image_url)){ $image_url .= '/'; } function resizeImage($originalImage,$toWidth,$toHeight,$ext){ // Get the original geometry and calculate scales list($width, $height) = getimagesize($originalImage); $xscale=$width/$toWidth; $yscale=$height/$toHeight; // Recalculate new size with default ratio if($yscale>$xscale){ $new_width = round($width * (1/$yscale)); $new_height = round($height * (1/$yscale)); } else { $new_width = round($width * (1/$xscale)); $new_height = round($height * (1/$xscale)); } // Resize the original image $imageResized = imagecreatetruecolor($new_width, $new_height); if($ext === 'png'){ $imageTmp = imagecreatefrompng ($originalImage); } elseif($ext === 'gif'){ $imageTmp = imagecreatefromgif ($originalImage); } else{ $imageTmp = imagecreatefromjpeg ($originalImage); } imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, $new_width, $new_height, $width, $height); return $imageResized; } function generateThumbnails(){ global $thmb_width,$thmb_height,$directory; // Creates thumbs directory if it doesn't exists and an empty index.php inside if(!is_dir($directory.'/thumbs')){ mkdir($directory.'/thumbs',0755); } if(!file_exists($directory.'/thumbs/index.php')){ file_put_contents($directory.'/thumbs/index.php',''); } // Open the actual directory if($handle = opendir($directory)) { // Read all file from the actual directory while ($file = readdir($handle)) { // Check whether tha actual item is a valid file if(is_file($directory.'/'.$file)){ // Check if the actual file is a image if(preg_match('#(.*?)\.(jpg|jpeg|png|gif)$#i',$file,$nameFile)){ $thmbFile = $directory.'/thumbs/'.$nameFile[1].'_th.'.strtolower($nameFile[2]); // If the thumb is older than the image, delete the thumb if(file_exists($thmbFile)){ $create = false; if(filemtime($thmbFile) < filemtime($file)){ unlink($thmbFile); $create = true; } }else{ $create = true; } // If a thumbnail doesn't exist than create a new one if($create){ imagejpeg(resizeImage($directory.'/'.$file,$thmb_width,$thmb_height,strtolower($nameFile[2])),$thmbFile,80); } } } } } } function displayPhotos($addon = 0){ generateThumbnails(); global $lastVisit,$enableVisit,$ippage,$page,$enablePages,$navigation,$sort,$order,$directory,$image_url; if($addon === 'mod' && isset($_GET['bin'])){ $trash = 'trash/'; $urlvar = 'view=bin&'; }else{ $trash = $urlvar = ''; } if(!$dir = scandir($directory.'/thumbs/')){ $dir = array(); } $arr = array(); foreach($dir as $file) { if(preg_match('#(.*?)_th\.(jpg|jpeg|png|gif)$#i',$file,$nameFile)){ $orgFileLow = $nameFile[1].'.'.$nameFile[2]; $orgFileUpp = $nameFile[1].'.'.strtoupper($nameFile[2]); // Deletes thumbs to non-existent images if(file_exists($directory.'/'.$orgFileLow)){ $orgFile = $orgFileLow; } elseif(file_exists($directory.'/'.$orgFileUpp)){ $orgFile = $orgFileUpp; } elseif(file_exists($directory.'/trash/'.$orgFileLow)){ $orgFile = $orgFileLow; } elseif(file_exists($directory.'/trash/'.$orgFileUpp)){ $orgFile = $orgFileUpp; } else{ unlink($directory.'/thumbs/'.$file); continue; } // Skips image if it doesnt exist in the right folder if(!file_exists($directory.'/'.$trash.$orgFile)){ continue; } // Time for the creation of the image $time = filemtime($directory.'/'.$trash.$orgFile); // Sort the images switch($sort){ case(1): // Date Added $info = $time; while(!empty($arr[$info])){ $info++; } break; case(2): // File Size $info = filesize($directory.'/'.$trash.$orgFile); while(!empty($arr[$info])){ $info++; } break; case(3): // Image Resolution list($width, $height) = getimagesize($directory.'/'.$trash.$orgFile); $info = $width * $height; while(!empty($arr[$info])){ $info++; } break; default: // File Name $info = strtolower($orgFile); $w = 2; while(!empty($arr[$info])){ $info .= '_'.$w; $w++; } } if($enableVisit && $time >= $lastVisit){ $newimage[$file] = ' class="newimage"'; }else{ $newimage[$file] = ''; } $arr[$info]['file'] = $file; $arr[$info]['orgf'] = $orgFile; $arr[$info]['time'] = $time; } } // Sorting the images if($order){ krsort($arr); } else{ ksort($arr); } // Making a new array for pages $newarr = array(); $n = 1; if($addon === 'viewer' && isset($_GET['i']) && file_exists($directory.'/'.basename(base64_decode($_GET['i'])))){ foreach($arr as $image){ if(basename(base64_decode($_GET['i'])) === $image['orgf']){ $newarr['current'] = $n; } $newarr[$n]['thumb'] = $image['file']; $newarr[$n]['image'] = $image['orgf']; $newarr[$n]['time'] = $image['time']; $n++; }return $newarr; }else{ foreach($arr as $image){ $newarr[$n]['thumb'] = $image['file']; $newarr[$n]['image'] = $image['orgf']; $newarr[$n]['time'] = $image['time']; $n++; } } if($addon === 'viewer'){ return $newarr; } // Images $i = ($page - 1) * $ippage; $count = count($newarr); $lastpage = ceil($count/$ippage); if($lastpage < 1){ $lastpage = 1; } if($count <= $i){ $i = ($lastpage - 1) * $ippage; $page = $lastpage; } $j = $i + $ippage; if($count < $j || !$enablePages){ $j = $count; } if($count <= $ippage){ $enablePages = false; } if(!$enablePages && $addon !== 'mod'){ $padding = 0; } else{ $padding = '33px'; } $i++; if($i < 1){ $i = 1; } $images = '