<?php
/*
* Project Name: phpSnap - http://www.kaibb.co.uk
* Author: Christopher Shaw
* This file belongs to phpSnap, it may be freely modified but this notice, and all copyright marks must be left
* intact. See COPYING.txt
*/
// -- CONFIG -- //
$gallery_home = './files/';
$sitename = 'phpSnap';
$version = '0.1';
// --- DO NOT EDIT BELLOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING. --- //
function safe($value)
{
$value = str_replace(array(' ','[',']'),array('%20','[',']'),$value);
return $value;
}
$output = '';
$output .= '<!DOCTYPE html>
<html>
<head>
<title>' . $sitename . '</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="./style.css" />
</head>
<body>
<div class="nav_left"><b>' . $sitename . '</b> | <a href="./">Home</a></div><div class="nav_right"> Powered By <a href="http://www.kaibb.co.uk" >phpSnap</a> '.$version.'</div><div class="clear"></div> <hr ><a href="./">Index</a> {LINKTREE} <hr />';
if (isset($_GET['album'])) {
$album = $_GET['album'];
} else {
$album = '';
}
if ($album) {
$dir = $gallery_home . '/' . $album . '/';
$title = str_replace('_', ' ', $album);
$linktree = '\ <a href="?album='.safe($album).'" >'.$title.'</a>';
if (!is_dir($dir)) {
$output .= "This gallery does not exist or does not contain and images.";
} else {
if (isset($_GET['img'])) {
$img = $_GET['img'];
} else {
$img = '';
}
if ($img) {
if (isset($_GET['size'])) {
$size = $_GET['size'];
} else {
$size = '';
}
if ($size == 'full') {
$max_size = '';
$link_end = '&size=full';
$change = '<a href="?album=' . safe($album) . '&img=' . safe($img) . '" >Normal Size</a>';
} else {
$max_size = '800';
$link_end = '';
$change = '
<a href="?album=' . safe($album) . '&img=' . safe($img) . '&size=full" >Full Size</a>';
}
if (file_exists($dir . $img)) {
$album = safe($album);
// FIND NEXT IMAGE
$count = 0;
$next = '';
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if ($file != '.' && $file != '..') {
if ($count == '1') {
$count = 0;
$next = safe($file);
$next_link = '| <a href="?album='.$album.'&img='.$next.''.$link_end.'" >Next</a>';
}
if ($file == $img) {
$count = 1;
}
}
}
closedir($dh);
}
if (!$next) {
$next = safe($img);
$next_link ='';
}
$extention = substr(strrchr($img, '.'), 1);
$value = str_replace($extention, '', $img);
$output .= '<div style="text-align:center">' . $change . ' | <a href="?album='.$album.'" >Thumbnails</a> '.$next_link.'<br />
<a href="?album=' . safe($album) . '&img=' . safe($next) . ''.$link_end.'" ><img src="thumb.php?im=' . safe($dir) . safe($img) . '&size=' . $max_size . '" alt="" class="cell"/></a><br /><b>' . safe($img) . '</b></div>';
} else {
$output .= "The image you requested could not be found";
}
} else {
if ($dh = opendir($dir)) {
$output .= '<ul class="thumbs">';
$album = safe($album);
while (($file = readdir($dh)) !== false) {
if ($file != '.' && $file != '..') {
$output .= '
<li><div class="tag"><a href="?album=' . $album . '&img=' . $file . '" ><img src="thumb.php?im=' . safe($dir) . safe($file) . '&size=100" alt=""/><br />'.$file.'</a></div></li>';
}
}
closedir($dh);
$output .= '</ul><div style="clear:both;"></div>';
}
}
}
} else {
if ($dh = opendir($gallery_home)) {
$output .='<ul class="albums">';
while (($file = readdir($dh)) !== false) {
if (is_dir($gallery_home . $file)) {
if ($file != '.' && $file != '..') {
$newdir = $gallery_home . '/' . $file;
if ($album = opendir($newdir)) {
while (($cover = readdir($album)) !== false) {
if ($cover != '.' && $cover != '..') {
$cover_image = $cover;
break;
}
}
closedir($album);
}
$title = $file;
$file = safe($file);
$cover_image = safe($cover_image);
$output .= '<li><div class="tag"><a href="?album=' . $file . '" ><img src="thumb.php?im=' . $gallery_home . $file . '/' . $cover_image . '&size=150" alt="" /><br /> ' . $title . '</a></div></li>';
}
}
}
$output .= '</ul><div style="clear:both;"></div>';
closedir($dh);
}
}
$output .= '</body>
</html>';
if ( ! isset($linktree) )
{ $linktree = ''; }
$output = str_replace(array('{LINKTREE}'),array($linktree),$output);
print $output;
?>