rendered paste body<?php
require("./picKLE-conf.php");
// Set defaults if anything in conf file is blank
$title = 'picKLE' ;
$version = 'version 0.3' ;
$theme = 'normal' ; // 0.3 will have themes
if (!$gallery_title) { $gallery_title = 'My Gallery'; }
if (!$filename) { $filename = 'index.php'; }
if (!$numcol) { $numcol = '4'; }
if (!$resampled_width) { $resampled_width = '800'; }
if (!$thumb_width) { $thumb_width = '75'; }
if (!$dis_files) { $dis_files = '20'; }
if (!$picKLE_debug) { $picKLE_debug = '0'; }
if (!$convert_path) { $convert_path = ''; }
if (!$allow_user_size) { $allow_user_size = 'yes'; }
if (!$allow_original) { $allow_original = 'yes'; }
if (!$allow_slideshow) { $allow_slideshow = 'yes'; }
if ($picKLE_debug == '0') { error_reporting(1); }
$error = '<table bgcolor="black" width="100%" align="center" cellspacing="0" cellpadding="1"><tr><td><table bgcolor="white" width="100%"
align="center"><tr><td><center><br><b>ERROR:</b> Something went wrong. Please click <a href="' .$filename. '">here</a> to get back
to the gallery home.<br><br></center></td></tr></table></td></tr></table>';
$album = $_GET['album'];
$pic = $_GET['pic'];
$nav = $_GET['nav'];
$slide = $_GET['slide'];
$delay = $_GET['delay'];
if (!$delay) {
$delay = '4';
}
if ($allow_user_size == 'yes') {
// Size variables - should be able to trim this code down
$tiny_res['width']='320';
$tiny_res['text']='320x240';
$small_res['width']='640';
$small_res['text']='640x480';
$medium_res['width']='800';
$medium_res['text']='800x600';
$large_res['width']='1024';
$large_res['text']='1024x768';
session_start();
if($_POST['custsize']) {
switch ($_POST['custsize']) {
case 'tiny':
$cust_size=$tiny_res['width'];
$tiny_res['selected']='SELECTED';
break;
case 'small':
$cust_size=$small_res['width'];
$small_res['selected']='SELECTED';
break;
case 'medium':
$cust_size=$medium_res['width'];
$medium_res['selected']='SELECTED';
break;
case 'large':
$cust_size=$large_res['width'];
$large_res['selected']='SELECTED';
break;
default:
$cust_size='';
}
if(!$_SESSION['cust_size']) {
session_register('cust_size');
}
}
if($cust_size) {
$resampled_width=$cust_size;
}
switch ($resampled_width) {
case $tiny_res['width']:
$tiny_res['selected']='SELECTED';
break;
case $small_res['width']:
$small_res['selected']='SELECTED';
break;
case $medium_res['width']:
$medium_res['selected']='SELECTED';
break;
case $large_res['width']:
$large_res['selected']='SELECTED';
break;
}
// end size variables
}
class picKLE
{
function picKLEsetup($album,$pic,$nav,$gallery_title,$title,$version,$filename,$numcol,$resampled_width,$thumb_width,$dis_files,$theme,$background,$error,$allow_user_size,$slide,$delay,$convert_path,$allow_original,$allow_slideshow,$admin_name,$admin_email)
{
$this->album = trim(urldecode($album));
$this->pic = trim(urldecode($pic));
$this->nav = trim($nav);
$this->gallery_title = $gallery_title;
$this->admin_name = $admin_name;
$this->admin_email = $admin_email;
$this->title = $title;
$this->version = $version;
$this->filename = $filename;
$this->numcol = $numcol;
$this->resampled_width = $resampled_width;
$this->thumb_width = $thumb_width;
$this->dis_files = $dis_files;
$this->theme = $theme;
$this->error = $error;
$this->path = getcwd();
$this->allow_user_size = $allow_user_size;
$this->allow_original = $allow_original;
$this->allow_slideshow = $allow_slideshow;
$this->convert_path = $convert_path;
$this->slide = $slide;
$this->delay = $delay;
}
function picKLEheader()
{
include("./picKLE-includes/header.php");
echo '<table width="100%" align="center"><tr><td><h3>' .$this->gallery_title. '</h3>';
if (!$this->album){
} else {
// we'll kill the script later this just stops us from printing shit we don't want at the top
if (ereg("^/", $this->album) or ereg("^../", $this->album) or ereg("^./", $this->album) or eregi("/\.\./", $this->album) or ereg("//$", $this->album)) {
} else {
$split = explode('/', $this->album);
echo '<a href="' .$this->filename. '">Home</a> / ';
for ($i = 0; $i < count($split)-1; $i++) {
echo '<a href="' .$this->filename. '?album=';
for ($j=0; $j < $i+1; $j++) {
echo '' .urlencode($split[$j]). '/';
}
echo '">' .$split[$i]. '</a> /';
}
if (ereg("^/", $this->pic) or ereg("^../", $this->pic) or ereg("^./", $this->pic) or eregi("/\.\./", $this->pic) or ereg("/$", $this->pic) or
!eregi(".(jpg|png|gif|jpeg)$", $this->pic)) {
} else {
if (is_file("picKLE-albums/$this->album$this->pic") == '1') {
echo ' ' .$this->pic. '';
}
}
}
}
echo '</td></tr></table><table bgcolor="black" width="100%" align="center" cellspacing="0" cellpadding="1"><tr><td><table bgcolor="white" width="100%"
align="center"><tr><td>';
}
function DirAndFile()
{
if (!$this->pic) {
} else {
if (ereg("^/", $this->pic) or ereg("^../", $this->pic) or ereg("^./", $this->pic) or eregi("/\.\./", $this->pic) or ereg("/$", $this->pic) or
!eregi(".(jpg|png|gif|jpeg)$", $this->pic)) {
echo $this->error;
die();
}
if (!eregi("[0-9]$", $this->delay)) {
echo $this->error;
die();
}
}
$this->album_dir = './picKLE-albums';
if (!$this->album) {
if (is_dir($this->album_dir) == '1') {
chdir($this->album_dir);
} else {
echo $this->error;
die();
}
}
// This checks for a trialing / at the end of the album name, it has to be there
elseif (ereg("^/", $this->album) or ereg("^../", $this->album) or ereg("^./", $this->album) or eregi("/\.\./", $this->album) or ereg("//$", $this->album)) {
echo $this->error;
die();
}
elseif (is_dir('' .$this->album_dir. '/' .$this->album. '') == '1') {
chdir('' .$this->album_dir. '/' .$this->album. '');
} else {
echo $this->error;
die();
}
$handle=opendir('.');
$i=0;
$j=0;
while ($file = readdir($handle)) {
if (is_file($file) == '1' && eregi(".(jpg|png|gif|jpeg)$", $file)) {
$get_files[$i] = array('sortby' => strtolower($file), 'real' => $file);
$i++;
}
// Remove the video check when we add in the video feature
elseif (is_dir($file) == '1' && $file <> '.' && $file <> '..' && $file <> 'video') {
$get_dirs[$j] = array('sortby' => strtolower($file), 'real' => $file);
$j++;
} else {
}
}
$this->get_files = $get_files;
$this->get_dirs = $get_dirs;
closedir($handle);
// gets the count of the pic and the prev and next thumb
sort($this->get_files);
for ($i=0; $i < count($this->get_files); $i++) {
if ($this->get_files[$i]['real'] == $this->pic) {
$this->num = $i + 1;
if ($i - 1 >= 0) {
$this->prev = substr($this->get_files[$i - 1]['real'], 0, strrpos($this->get_files[$i - 1]['real'], "."))."_thumb_$this->thumb_width".substr($this->get_files[$i - 1]['real'], strrpos($this->get_files[$i - 1]['real'], "."));
$this->prev_real = $this->get_files[$i - 1]['real'];
}
if ($i + 1 < count($this->get_files)) {
$this->next = substr($this->get_files[$i + 1]['real'], 0, strrpos($this->get_files[$i + 1]['real'], "."))."_thumb_$this->thumb_width".substr($this->get_files[$i + 1]['real'], strrpos($this->get_files[$i + 1]['real'], "."));
$this->next_real = $this->get_files[$i + 1]['real'];
}
$this->slide_start = $this->get_files[$i];
$this->slide_stop = $this->get_files[$i - 1];
}
}
}
function GenerateFolders()
{
if (isset($this->get_dirs) and !$this->pic) {
sort($this->get_dirs);
echo '<table width="100%">';
for ($i=0; $i < count($this->get_dirs); $i++) {
// Check if directory is there for the cache
$cache_path='' .$this->path. '/' .$this->dotdot. 'picKLE-cache/' .$this->album. '' .$this->get_dirs[$i]['real']. '';
$check_cache_path=is_dir("$cache_path");
// Make sure you add this back or it won't create the cache dir
if ($check_cache_path=='1') {
} else {
mkdir ("$cache_path", 0777);
chmod ("$cache_path", 0777);
}
// Count for table columns
$j++;
if ($j == '1') {
echo '<tr align="center">';
}
echo '<td><br><br><a href="' .$this->filename. '?album=' .urlencode($this->album).'' .urlencode($this->get_dirs[$i]['real']). '/">
<img src="./picKLE-images/' .$this->theme. '/folder.png" border="0"></a><br>' .$this->get_dirs[$i]['real']. '<br><br></td>';
if ($j == $this->numcol) {
echo '</tr>';
$j=0;
}
}
echo '</table>';
}
}
function DisplayThumbs()
{
// If text file is there and we are not viewing a picture include it
if (is_file("album.txt") == '1' && !$this->pic) {
echo '<br><table width="50%" bgcolor="#cccccc" cellspacing="0" cellpadding="1" align="center"><tr><td><table
bgcolor="white" width="100%"><tr><td><p align="left"><b>Album description:</b><br>';
include("album.txt");
echo '<br></td></tr></table></td></tr></table>';
}
// I will get rid of this soon - legacy support, actually this whole fucking description setup kinda sucks
elseif (is_file(str_replace("/", "", substr(getcwd(), strrpos(getcwd(), "/"))).".txt") == '1' && !$this->pic) {
echo '<br><table width="50%" bgcolor="#cccccc" cellspacing="0" cellpadding="1" align="center"><tr><td><table
bgcolor="white" width="100%"><tr><td><p align="left"><b>Album description:</b><br>';
include(str_replace("/", "", substr(getcwd(), strrpos(getcwd(), "/"))).".txt");
echo '<br></td></tr></table></td></tr></table>';
}
// $this->album <> NULL was added so pics don't display in the root of the album
if (!$this->pic && $this->album <> NULL) {
if (!$this->get_files && !$this->get_dirs) {
echo '<br>This folder is empty.<br><br>';
}
elseif (!$this->get_files && isset($this->get_dirs)) {
} else {
sort($this->get_files);
echo '<table width="100%">';
// this loop will generate all the thumbs
$cache_path='' .$this->path. '/' .$this->dotdot. 'picKLE-cache/' .$this->album. '';
for ($i=0; $i < count($this->get_files); $i++) {
$thumb = substr($this->get_files[$i]['real'], 0, strrpos($this->get_files[$i]['real'], "."))."_thumb_$this->thumb_width".substr($this->get_files[$i]['real'], strrpos($this->get_files[$i]['real'], "."));
if (!is_file("$cache_path/$thumb") == '1') {
$file = $this->get_files[$i]['real'];
$pic_info = getimagesize($this->get_files[$i]['real']);
$ratio = $pic_info[0] / $this->thumb_width;
$new_h = $pic_info[1] / $ratio;
$x='x';
$make_magick = system(''.$this->convert_path.'convert -size '.$this->thumb_width.''.$x.''.$new_h.' -geometry '.$this->thumb_width.''.$x.''.$new_h.' "'.$file.'" "'.$cache_path.''.$thumb.'" >/dev/null 2>/dev/null', $retval);
if (!($retval)) {
chmod ("$cache_path/$thumb", 0666);
} else {
echo 'That didn\'t work as planned. (imagemagick isn\'t installed, isn\'working right, or you didn\'t make picKLE-cache writable)<br>';
}
}
}
if(!$this->nav){
} else {
if (!eregi("[0-9]$", $this->nav)) {
echo $this->error;
die();
}
}
// this loop will display the thumbs
if (!$this->nav or $this->nav == '1') {
$nav_count = $this->dis_files;
if ($nav_count < count($this->get_files)) {
$this->nav_m = 1;
$this->nav = 1;
}
elseif ($nav_count >= count($this->get_files)) {
$nav_count = count($this->get_files);
}
$start = 0;
} else {
$nav_count = $this->nav * $this->dis_files;
if ($nav_count / count($this->get_files) > 2) {
echo $this->error;
die();
}
elseif ($nav_count >= count($this->get_files)) {
$nav_count = count($this->get_files);
$this->nav_l = 1;
} else {
$this->nav_m = 1;
$this->nav_l = 1;
}
$start = ($this->nav - 1)* $this->dis_files;
}
for ($i=$start; $i < $nav_count; $i++) {
$thumb = substr($this->get_files[$i]['real'], 0, strrpos($this->get_files[$i]['real'], "."))."_thumb_$this->thumb_width".substr($this->get_files[$i]['real'], strrpos($this->get_files[$i]['real'], "."));
$j++;
if ($j == '1') {
echo '<tr>';
}
echo '<td align="center"><br><a href="' .$this->filename. '?album=' .urlencode($this->album). '&pic=' .urlencode($this->get_files[$i]['real']). '">
<img src="picKLE-cache/' .str_replace(" ", "%20", $this->album). '' .str_replace(" ", "%20", $thumb). '" border="1"></a><br>
' .substr($this->get_files[$i]['real'], 0, strrpos($this->get_files[$i]['real'], ".")). '<br></td>';
if ($j == $this->numcol) {
echo '</tr>';
$j=0;
}
}
echo '</table><table width="50%" align="center"><tr><td><br><br><center>';
if ($this->nav_l == '1') {
$nav_l = $this->nav - 1;
echo '<a href="' .$this->filename. '?album=' .urlencode($this->album). '&nav=' .$nav_l. '"><img src="./picKLE-images/left-arrow.gif" border="0"
align="absmiddle"></a> ';
}
$start_pic = $start + 1;
echo '' .$start_pic. ' - ' .$nav_count. ' of ' .count($this->get_files). '';
if ($this->nav_m == '1') {
$nav_m = $this->nav + 1;
echo ' <a href="' .$this->filename. '?album=' .urlencode($this->album). '&nav=' .$nav_m. '"><img src="./picKLE-images/right-arrow.gif" border="0" align="absmiddle"></a>';
}
echo '</center></td></tr></table>';
}
}
}
function DisplayPic()
{
echo '<table width="100%" align="center"><tr align="center"><td colspan="3">';
if (is_file($this->pic) == '1' && eregi(".(jpg|png|gif|jpeg)$", $this->pic)) {
$cache_path='' .$this->path. '/' .$this->dotdot. 'picKLE-cache/' .$this->album. '';
$resampled = substr($this->pic, 0, strrpos($this->pic, "."))."_$this->resampled_width".substr($this->pic, strrpos($this->pic, "."));
$pic_info = getimagesize($this->pic);
$ratio = $pic_info[0] / $this->resampled_width;
$new_h = round($pic_info[1] / $ratio);
$x='x';
$display = '<center><br>Viewing picture ' .$this->num. ' of ' .count($this->get_files). '<br>';
if ($this->allow_user_size == 'yes') {
$display .= '<form action='.$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'].' method="post"><select name="custsize" onChange="submit();"><option value=""> Change image size </option>';
if ($pic_info[0] >= '320'){ $display .= '<option '.$GLOBALS['tiny_res']['selected'].' value="tiny">Tiny ('.$GLOBALS['tiny_res']['text'].')</option>'; }
if ($pic_info[0] >= '640'){ $display .= '<option '.$GLOBALS['small_res']['selected'].' value="small">Small ('.$GLOBALS['small_res']['text'].')</option>'; }
if ($pic_info[0] >= '800'){ $display .= '<option '.$GLOBALS['medium_res']['selected'].' value="medium">Medium ('.$GLOBALS['medium_res']['text'].')</option>'; }
if ($pic_info[0] >= '1024'){ $display .= '<option '.$GLOBALS['large_res']['selected'].' value="large">Large ('.$GLOBALS['large_res']['text'].')</option>'; }
if ($pic_info[0] <= '320'){ $display .= '<option value=""> No other sizes </option>'; }
$display .= '</select></form>';
}
$display .= '<img src="picKLE-cache/' .str_replace(" ", "%20", $this->album). '' .str_replace(" ", "%20", $resampled). '" border="1"></center>';
if ($this->allow_slideshow == 'yes') {
$display .= 'Slideshow: <a href="' .$this->filename. '?album=' .urlencode($this->album). '&pic=' .urlencode($this->next_real). '&slide=1">start</a> -
<a href="' .$this->filename. '?album=' .urlencode($this->album). '&pic=' .urlencode($this->pic). '">stop</a><br>Second delay:
[ <a href="' .$this->filename. '?album=' .urlencode($this->album). '&pic=' .urlencode($this->next_real). '&slide=1&delay=2">2</a> -
<a href="' .$this->filename. '?album=' .urlencode($this->album). '&pic=' .urlencode($this->next_real). '&slide=1&delay=4">4</a> -
<a href="' .$this->filename. '?album=' .urlencode($this->album). '&pic=' .urlencode($this->next_real). '&slide=1&delay=6">6</a> -
<a href="' .$this->filename. '?album=' .urlencode($this->album). '&pic=' .urlencode($this->next_real). '&slide=1&delay=8">8</a> -
<a href="' .$this->filename. '?album=' .urlencode($this->album). '&pic=' .urlencode($this->next_real). '&slide=1&delay=10">10</a> ]<br>';
}
$display2 = '<center><br>' .'File uploaded on:<br><font color="gray">'.date("F j Y, H:i:s", filemtime("$this->pic")). '</font></center>';
$size_orig = '<center>' .$pic_info[0]. ' x ' .$pic_info[1]. ' pixels</center>';
if ($pic_info[0] <= $this->resampled_width) {
$size_new = $size_orig;
} else {
$size_new = '<center>' .$this->resampled_width. ' x ' .$new_h. ' pixels</center>';
}
if (is_file("$cache_path$resampled") == '1' && eregi(".(jpg|png|gif|jpeg)$", "$cache_path$resampled")) {
nop;
}
elseif ($pic_info[0] < $this->resampled_width) {
$make_magick = system(''.$this->convert_path.'convert "'.$this->pic.'" "'.$cache_path.''.$resampled.'" >/dev/null 2>/dev/null', $retval);
if (!($retval)) {
chmod ("$cache_path$resampled", 0666);
} else {
echo 'That didn\'t work as planned. (imagemagick isn\'t installed, isn\'working right, or you didn\'t make picKLE-cache writable)<br>';
}
} else {
$make_magick = system(''.$this->convert_path.'convert -geometry '.$this->resampled_width.''.$x.''.$new_h.' "'.$this->pic.'" "'.$cache_path.''.$resampled.'" >/dev/null 2>/dev/null', $retval);
if (!($retval)) {
chmod ("$cache_path$resampled", 0666);
} else {
echo 'That didn\'t work as planned. (imagemagick isn\'t installed, isn\'working right, or you didn\'t make picKLE-cache writable)<br>';
}
}
echo '' .$display. '</td></tr>';
if (!$this->prev_real) {
echo '<td align="left"><img src="picKLE-images/blank.gif" border=0 align="left" width="' .$this->thumb_width. '" height=1></td>';
} else {
echo '<tr><td align="left"><a href="' .$this->filename. '?album=' .urlencode($this->album). '&pic=' .urlencode($this->prev_real). '">
<img src="picKLE-cache/' .str_replace(" ", "%20", $this->album). ''. str_replace(" ", "%20", $this->prev) . '" align="left"
border="1"><BR CLEAR="ALL"><-prev</a></td>';
}
echo '<td><br><center><b>' .$this->pic. '</b></center>';
// If text file is there it
if (is_file('' .$this->pic. '.txt') == '1') {
echo '<br><table width="60%" bgcolor="#cccccc" align="center" cellspacing="0" cellpadding="1"><tr><td><table
bgcolor="white" width="100%" align="center"><tr><td><p align="left"><b>Pic description:</b><br>';
include('' .$this->pic. '.txt');
echo '<br></td></tr></table></td></tr></table>';
}
echo '' .$display2. '<center>Resampled size:<font color="gray">' .$size_new. '</font>Original size:</center><font color="gray">' .$size_orig. '</font><center>';
if($this->allow_original == 'yes') {
echo '<a href="picKLE-albums/'.$this->album.$this->pic.'" target="_blank">View original</a></center>';
}
echo '<br></td>';
} else {
if (!$this->pic) {
} else {
echo $this->error;
die();
}
}
if (!$this->next_real) {
echo '<td align="right"><img src="picKLE-images/blank.gif" border=0 align="right" width="' .$this->thumb_width. '" height=1></td></tr>';
} else {
echo '<td align="right"><a href="' .$this->filename. '?album=' .urlencode($this->album). '&pic=' .urlencode($this->next_real). '">
<img src="picKLE-cache/' .str_replace(" ", "%20", $this->album). ''. str_replace(" ", "%20", $this->next). '" align="right"
border="1"><BR CLEAR="ALL">next-></a></td></tr>';
}
echo '</table>';
}
function picKLEslide()
{
if ($this->pic) {
if (!$this->next_real) {
echo '<META http-equiv="refresh" content="' .$this->delay. ';URL=' .$this->filename. '?album=' .urlencode($this->album). '&pic=' .urlencode($this->get_files[0]['real']). '&slide=1&delay=' .$this->delay. '">';
} else {
echo '<META http-equiv="refresh" content="' .$this->delay. ';URL=' .$this->filename. '?album=' .urlencode($this->album). '&pic=' .urlencode($this->next_real). '&slide=1&delay=' .$this->delay. '">';
}
}
}
function picKLEfooter()
{
echo '</td></tr></table></td></tr></table><table width="100%" align="center"><tr><td><center>
Indexed by <a href="http://picklegallery.sourceforge.net">' .$this->title. ' ' .$this->version. '</a> © '.date(Y).'<br>
Content by <a href="mailto:' .$this->admin_email. '">' .$this->admin_name. '</a> © '.date(Y).'
</center></td></tr></table>';
include("$this->path/picKLE-includes/footer.php");
}
}
?>
<?php
$gallery = new picKLE;
$gallery->picKLEsetup($album,$pic,$nav,$gallery_title,$title,$version,$filename,$numcol,$resampled_width,$thumb_width,$dis_files,$theme,$background,$error,$allow_user_size,$slide,$delay,$convert_path,$allow_original,$allow_slideshow,$admin_name,$admin_email);
$gallery->DirAndFile();
?>
<HTML>
<HEAD>
<TITLE>
<?php echo '' .$gallery_title. ' - ' .$title. ' ' .$version. '';?>
</TITLE>
<link href="style.css" rel="stylesheet" type="text/css">
<?php
if ($slide == '1') {
$gallery->picKLEslide();
}
?>
</HEAD>
<BODY BGCOLOR="<?php echo '' .$background. '';?>">
<table width="80%" align="center"><tr><td>
<?php
$gallery->picKLEheader();
$gallery->GenerateFolders();
$gallery->DisplayThumbs();
$gallery->DisplayPic();
$gallery->picKLEfooter();
?>
</td></tr></table>
</BODY>
</HTML>
<?php
die();
?>