. **********************************************************************/ // This check is useless, if you have PHP < 5 you will get a parse error if (!version_compare(phpversion(), '5.2', '>=')) { die("You need at least PHP 5.2 to use this application."); } if (!extension_loaded('pdo_sqlite')) { die("You need PHP PDO SQLite extension to use this application."); } error_reporting(E_ALL); class fotooManager { private $db = false; public $html_tags = array('wp' => 'http://en.wikipedia.org/wiki/KEYWORD'); public function getThumbPath($hash) { $dir = CACHE_DIR . '/' . $hash[0]; if (!file_exists($dir)) mkdir($dir, 0777); return $dir . '/' . $hash . '_thumb.jpg'; } public function getSmallPath($hash) { $dir = CACHE_DIR . '/' . $hash[0]; if (!file_exists($dir)) mkdir($dir, 0777); return $dir . '/' . $hash . '_small.jpg'; } public function getTagId($name) { $name = htmlentities($name, ENT_QUOTES, 'UTF-8'); $name = preg_replace('!&([aeiouyAEIOUYNcC]|ae)(?:circ|grave|acute|circ|tilde|uml|ring|slash|cedil|lig);!', '\\1', $name); $name = html_entity_decode($name, ENT_QUOTES, 'UTF-8'); $name = strtolower($name); return $name; } public function __construct() { $init = $upgrade = false; if (!file_exists(CACHE_DIR)) { if (!mkdir(CACHE_DIR, 0777)) { echo '
...)
$text = preg_replace('!<([a-z]+)>(.*)</\\1>!isU', '<\\1>\\2\\1>', $text);
$text = preg_replace('#(^|\s)([a-z]+://([^\s\w/]?[\w/])*)(\s|$)#im', '\\1\\2\\4', $text);
$text = str_replace('\http:', 'http:', $text);
foreach ($this->html_tags as $tag=>$url)
{
$tag_class = preg_replace('![^a-zA-Z0-9_]!', '_', $tag);
$text = preg_replace('#(^|\s)'.preg_quote($tag, '#').':([^\s,.]+)#iem',
"'\\1\\2\\3'", $text);
}
$text = nl2br($text);
return $text;
}
public function formatDetails($details)
{
if (empty($details))
return '';
if (!is_array($details))
$details = json_decode($details, true);
$out = array();
if (isset($details['maker']))
$out[__('Camera maker:')] = $details['maker'];
if (isset($details['model']))
$out[__('Camera model:')] = $details['model'];
if (isset($details['exposure']))
$out[__('Exposure:')] = __('%EXPOSURE seconds', 'REPLACE', array('%EXPOSURE' => $details['exposure']));
if (isset($details['fnumber']))
$out[__('Aperture:')] = 'f' . $details['fnumber'];
if (isset($details['iso']))
$out[__('ISO speed:')] = $details['iso'];
if (isset($details['flash']))
$out[__('Flash:')] = $details['flash'] ? __('On') : __('Off');
if (isset($details['focal']))
$out[__('Focal length:')] = $details['focal'] . ' mm';
if (isset($details['resolution']))
$out[__('Original resolution:')] = $details['resolution'];
return $out;
}
/*
* Resize an image using imlib, imagick or GD, if one fails it tries the next
*/
private function resizeImage($source, $dest, $width, $height, $max)
{
list($new_width, $new_height) = $this->getNewSize($width, $height, $max);
if ($new_width == $width && $new_height == $height)
return true;
// IMLib (fast!)
if (extension_loaded('imlib'))
{
$src = @imlib_load_image($source);
if ($src)
{
$dst = imlib_create_scaled_image($src, $new_width, $new_height);
imlib_free_image($src);
if ($dst)
{
imlib_image_set_format($dst, "jpeg");
if (file_exists($dest)) @unlink($dest);
imlib_save_image($dst, $dest);
imlib_free_image($dst);
return true;
}
}
}
// Imagick >= 2.0 API (quite fast)
if (extension_loaded('imagick') && class_exists('Imagick'))
{
$im = new Imagick;
if ($im->readImage($source) && $im->resizeImage($new_width, $new_height, Imagick::FILTER_UNDEFINED, 1))
{
if (file_exists($dest)) @unlink($dest);
$im->stripImage();
$im->writeImage($dest);
$im->destroy();
return true;
}
}
// Imagick < 2.0 API (quite fast)
if (extension_loaded('imagick') && function_exists('imagick_readimage'))
{
$handle = imagick_readimage($source);
imagick_resize($handle, $new_width, $new_height, IMAGICK_FILTER_UNKNOWN, 1);
imagick_convert($handle,'JPEG');
if (file_exists($dest)) @unlink($dest);
imagick_writeimage($handle, $dest);
imagick_free($handle);
if (file_exists($dest))
return true;
}
// GD >= 2.0 (slow)
if (function_exists('imagecopyresampled') && extension_loaded('gd'))
{
$sourceImage = @imagecreatefromjpeg($source);
if($sourceImage)
{
$newImage = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($newImage, $sourceImage, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
if (file_exists($dest)) @unlink($dest);
if(imagejpeg($newImage, $dest))
return true;
}
}
return false;
}
public function getNewSize($width, $height, $max)
{
if($width > $max OR $height > $max)
{
if($height <= $width)
$ratio = $max / $width;
else
$ratio = $max / $height;
$width = round($width * $ratio);
$height = round($height * $ratio);
}
return array($width, $height);
}
}
function escape($str)
{
return htmlspecialchars($str, ENT_QUOTES, 'UTF-8');
}
function zero_pad($str, $length = 2)
{
return str_pad($str, $length, '0', STR_PAD_LEFT);
}
function get_url($type, $data = null, $args = null)
{
if ($type == 'cache_thumb')
{
return BASE_URL . 'cache/' . $data['hash'][0] . '/' . $data['hash'] . '_thumb.jpg';
}
elseif ($type == 'cache_small')
{
return BASE_URL . 'cache/' . $data['hash'][0] . '/' . $data['hash'] . '_small.jpg';
}
elseif ($type == 'real_image')
{
return BASE_URL . (empty($data['path']) ? '' : $data['path'].'/') . $data['filename'];
}
if (is_array($data) && isset($data['filename']) && isset($data['path']))
{
if (isset($data['filename']))
$data = ($data['path'] ? $data['path'].'/' : '') . $data['filename'];
elseif (isset($data['path']))
$data = $data['path'] ? $data['path'].'/' : '';
}
elseif ($type == 'embed')
{
$data = (empty($data['path']) ? '' : $data['path'].'/') . $data['filename'];
}
if (function_exists('get_custom_url'))
{
$url = get_custom_url($type, $data);
}
elseif ($type == 'image' || $type == 'album')
{
$url = SELF_URL . '?' . rawurlencode($data);
}
elseif ($type == 'embed' || $type == 'slideshow')
{
$url = SELF_URL . '?'.$type.'=' . rawurlencode($data);
}
elseif ($type == 'embed_tag')
{
$url = SELF_URL . '?embed&tag=' . rawurlencode($data);
}
elseif ($type == 'slideshow_tag')
{
$url = SELF_URL . '?slideshow&tag=' . rawurlencode($data);
}
elseif ($type == 'embed_img')
{
$url = SELF_URL . '?i=' . rawurlencode($data);
}
elseif ($type == 'tag')
{
$url = SELF_URL . '?tag=' . rawurlencode($data);
}
elseif ($type == 'date')
{
$url = SELF_URL . '?date=' . rawurlencode($data);
}
elseif ($type == 'tags' || $type == 'timeline' || $type == 'feed')
{
$url = SELF_URL . '?' . $type;
}
else
{
throw new Exception('Unknown type '.$type);
}
if (!is_null($args))
{
if (strpos($url, '?') === false)
$url .= '?' . $args;
else
$url .= '&' . $args;
}
return $url;
}
function embed_html($data)
{
if (is_array($data))
$url = get_url('embed', $data);
else
$url = get_url('embed_tag', $data);
$html = '';
return $html;
}
// Against bad configurations
if (get_magic_quotes_gpc())
{
foreach ($_GET as $k=>$v) { $_GET[$k] = stripslashes($v); }
}
if (file_exists(dirname(__FILE__) . '/user_config.php'))
{
require dirname(__FILE__) . '/user_config.php';
}
if (!function_exists('__'))
{
function __($str, $mode=false, $datas=false) {
if ($mode == 'TIME')
return strftime($str, $time);
elseif ($mode == 'REPLACE')
return strtr($str, $datas);
else
return $str;
}
}
if (!defined('BASE_DIR')) define('BASE_DIR', dirname(__FILE__));
if (!defined('CACHE_DIR')) define('CACHE_DIR', BASE_DIR . '/cache');
if (!defined('BASE_URL')) define('BASE_URL', 'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['SCRIPT_NAME']).'/');
if (!defined('SELF_URL')) define('SELF_URL', BASE_URL . (basename($_SERVER['SCRIPT_NAME']) == 'index.php' ? '' : basename($_SERVER['SCRIPT_NAME'])));
if (!defined('GEN_SMALL')) define('GEN_SMALL', 0);
if (!defined('MAX_IMAGE_SIZE')) define('MAX_IMAGE_SIZE', 2048);
if (!defined('SMALL_IMAGE_SIZE')) define('SMALL_IMAGE_SIZE', 600);
if (!defined('GALLERY_TITLE')) define('GALLERY_TITLE', __('My pictures'));
if (!defined('ALLOW_EMBED')) define('ALLOW_EMBED', true);
if (!isset($f) || !($f instanceOf fotooManager))
$f = new fotooManager;
$mode = false;
if (isset($_GET['update_js']))
{
header('Content-Type: text/javascript');
?>if (typeof need_update != 'undefined')
{
var update_done = 0;
var loading = document.createElement('div');
loading.style.padding = '5px';
loading.style.margin = '0px';
loading.style.fontFamily = 'Sans-serif';
loading.style.fontSize = '12px';
loading.style.position = 'absolute';
loading.style.top = '5px';
loading.style.left = '5px';
loading.style.border = '2px solid #ccc';
loading.style.background = '#fff';
loading.style.color = '#000';
loading.style.width = (Math.round(need_update.length * 5) + 100) + 'px';
loading.id = 'updatingTemp';
if (typeof update_msg != 'undefined')
loading.innerHTML = update_msg;
else
loading.innerHTML = 'Updating';
var body = document.getElementsByTagName('body')[0];
body.appendChild(loading);
function updateNext()
{
var loading = document.getElementById('updatingTemp');
if (update_done >= need_update.length)
{
window.setTimeout('window.location = window.location', 100);
return;
}
var file = need_update[update_done];
var img = document.createElement('img');
img.src = update_url + '?updateDir=' + encodeURI(update_dir) + '&updateFile=' + encodeURI(file);
img.alt = update_done + '/' + need_update.length;
img.width = Math.round(update_done * 5);
img.height = 1;
img.style.borderBottom = "2px solid #000099";
img.style.verticalAlign = "middle";
img.style.margin = "0 10px";
img.onload = function ()
{
update_done++;
var elm = document.getElementById('updatingTemp');
if (update_done < need_update.length)
elm.removeChild(this);
updateNext();
}
loading.appendChild(img);
}
updateNext();
}getNewPhotos(20);
$last_update = $last[0]['time'];
header('Content-Type: text/xml');
echo '
'.GALLERY_TITLE.'
Last pictures added in "'.GALLERY_TITLE.'"
'.SELF_URL.'
'.date(DATE_W3C, $last_update).'
daily
1
'.date(DATE_W3C, $last_update).'
';
foreach ($last as &$photo)
{
echo '
';
}
echo '
';
foreach ($last as &$photo)
{
if (file_exists($f->getSmallPath($photo['hash'])))
$small_url = get_url('cache_small', $photo);
else
$small_url = get_url('cache_thumb', $photo);
$content = ''
. ''.$f->formatText($photo['comment']).'
';
$title = $photo['path'] ? strtr($photo['path'] . '/' . $photo['filename'], array('/' => ' / ', '_' => ' ')) : $photo['filename'];
$title = preg_replace('!\.[a-z]+$!i', '', $title);
echo '
-
'.escape($title).'
'.get_url('image', $photo).'
'.date(DATE_W3C, $photo['time']).'
'.escape($content).'
'.escape($photo['filename']).'
';
}
echo '
';
exit;
}
if (isset($_GET['style_css']))
{
header('Content-Type: text/css');
$img_home =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qtkoZPlleVwJXl7TJ10zy%2B54656wugLSZ44OvL8ITsKoSAJ2M6EsEEqyjp7aNZTp11zMzFgllqa6MAKA9Mnun8hKxxq1PA3SZcTGzQ8KXmJ7MIwAx2xKiPiTw%2BnzR0QLYHoLXjSNBUhcOZQC71%2BIn38VM%2FES0DewhS1P%2BVg2G485Dwe2Xf2NIHI1jcRL7iycAMB5ogC93MwAAAABJRU5ErkJggg%3D%3D';
if (isset($_GET['style_css']))
{
echo <<addInfos($_GET['updateFile'], $_GET['updateDir']);
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header('Content-Type: image/gif');
echo base64_decode("R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==");
exit;
}
if (isset($_GET['index_all']))
{
if (!isset($_SESSION))
{
session_start();
if (!isset($_SESSION['processed']))
$_SESSION['processed'] = array();
if ($_GET['index_all'] == 'done')
{
$_SESSION = array();
session_destroy();
session_write_close();
setcookie(session_name(), '', time() - 3600);
}
}
if ($_GET['index_all'] != 'done')
{
define('TIMER_START', time());
function update_dir($dir)
{
global $f;
// Let's start again if timer seems too late, because processing a lot of
// directories could be very slow
if ((time() - TIMER_START) >= (ini_get('max_execution_time') - 5))
{
header('Location: '.SELF_URL.'?index_all='.time());
exit;
}
if (in_array($dir, $_SESSION['processed']))
$dont_check = true;
else
$dont_check = false;
$pics = $dirs = $update = $desc = false;
$list = $f->getDirectory($dir, $dont_check);
$_SESSION['processed'][] = $dir;
if (empty($list))
return false;
else
list($dirs, $pics, $update, $desc) = $list;
if (!empty($update))
{
return array($dir, $update);
}
foreach ($dirs as $subdir)
{
$subdir = (!empty($dir) ? $dir . '/' : '') . $subdir;
$res = update_dir($subdir);
if ($res)
return $res;
}
return false;
}
$res = update_dir('');
if (!$res)
{
header('Location: '.SELF_URL.'?index_all=done');
exit;
}
}
else
{
$res = false;
}
echo '';
if ($res)
{
list($dir, $update_list) = $res;
echo "\n"
.'';
}
echo '';
if ($res)
{
echo '
'.__('Updating').'
... '.$dir;
}
else
{
echo ''.__('Update done.').'';
}
echo '
';
exit;
}
// For cache force url
if (!empty($_GET['r']))
{
unset($_GET['r']);
$_SERVER['QUERY_STRING'] = '';
}
// Small image redirect
if (!empty($_GET['i']) && preg_match('!^(.*)(?:/?([^/]+)[_.](jpe?g))?$!Ui', $_GET['i'], $match))
{
$selected_dir = fotooManager::getValidDirectory($match[1]);
$selected_file = $match[2] . '.' . $match[3];
$pic = $f->getInfos($selected_file, $selected_dir);
header('Content-Type: ', true);
if (!is_array($pic))
{
header('HTTP/1.1 404 Not Found', true, 404);
exit;
}
$orig_url = get_url('real_image', $pic);
if ($pic['width'] <= SMALL_IMAGE_SIZE && $pic['height'] <= SMALL_IMAGE_SIZE)
{
$small_url = $orig_url;
}
elseif (file_exists($f->getSmallPath($pic['hash'])))
{
$small_url = get_url('cache_small', $pic);
}
else
{
$small_url = false;
}
header('HTTP/1.1 302 Found', true, 302);
header('Location: '.($small_url ? $small_url : $orig_url));
exit;
}
// Get which display mode is asked
elseif (isset($_GET['date']) || isset($_GET['timeline']))
{
$day = $year = $month = $date = false;
if (!empty($_GET['date']) && preg_match('!^[0-9]{4}(/[0-9]{2}){0,2}$!', $_GET['date']))
$date = explode('/', $_GET['date']);
if (!empty($date[0]))
$year = $date[0];
if (!empty($date[1]))
$month = $date[1];
if (!empty($date[2]))
$day = $date[2];
if ($day)
$title = __('Pictures for %A %d %B %Y', 'TIME', strtotime($_GET['date']));
elseif ($month)
$title = __('Pictures for %B %Y', 'TIME', strtotime($_GET['date'].'/01'));
elseif ($year)
$title = __('Pictures for %Y', 'REPLACE', array('%Y' => $year));
else
$title = __('Pictures by date');
$mode = 'date';
}
elseif (isset($_GET['tags']))
{
$title = __('Pictures by tag');
$mode = 'tags';
}
elseif (isset($_GET['slideshow']) || isset($_GET['embed']))
{
$mode = isset($_GET['embed']) ? 'embed' : 'slideshow';
$title = __('Slideshow');
if (!empty($_GET['tag']))
{
$selected_tag = explode('/', $_GET['tag']);
$current_index = isset($selected_tag[1]) ? (int) $selected_tag[1] : 1;
$selected_tag = $f->getTagId($selected_tag[0]);
}
else
{
$src = isset($_GET['embed']) ? $_GET['embed'] : $_GET['slideshow'];
$selected_file = basename($src);
if (preg_match('!\.jpe?g$!i', $selected_file))
{
$selected_dir = fotooManager::getValidDirectory(dirname($src));
}
else
{
$selected_dir = fotooManager::getValidDirectory($src);
$selected_file = false;
}
}
}
elseif (!empty($_GET['tag']))
{
$mode = 'tag';
$tag = $f->getTagId($_GET['tag']);
$tag_name = $f->getTagNameFromId($tag);
$title = __('Pictures in tag %TAG', 'REPLACE', array('%TAG' => $tag_name));
}
else
{
$mode = 'dir';
$title = false;
if (isset($_GET['cleanUpdate']))
{
$cleanUpdate = true;
unset($_GET['cleanUpdate']);
$_SERVER['QUERY_STRING'] = '';
}
if (!empty($_SERVER['QUERY_STRING']) && preg_match('!^(.*)(?:/?([^/]+)[_.](jpe?g))?$!Ui', urldecode($_SERVER['QUERY_STRING']), $match))
{
$selected_dir = fotooManager::getValidDirectory($match[1]);
if ($selected_dir !== false)
{
$title = strtr(escape($match[1]), array('/' => ' / ', '_' => ' '));
if (!empty($match[2]))
{
$selected_file = $match[2] . '.' . $match[3];
$mode = 'pic';
$title = strtr(escape($match[2]), array('_' => ' ', '-' => ' - '));
}
}
}
else
{
$selected_dir = '';
}
}
if (file_exists(BASE_DIR . '/user_style.css'))
$css = BASE_URL . 'user_style.css';
else
$css = SELF_URL . '?style.css';
$f->html_tags['tag'] = get_url('tag', 'KEYWORD');
$f->html_tags['date'] = get_url('date', 'KEYWORD');
$menu = ''.__('My Pictures').'
'.__('By tags').'
'.__('By date').'
';
header('Content-Type: text/html; charset=UTF-8');
if ($mode != 'slideshow' && $mode != 'embed')
{
if (file_exists(BASE_DIR . '/user_header.php'))
require BASE_DIR . '/user_header.php';
else
{
if (!$title) $title = GALLERY_TITLE;
else $title .= ' - '.GALLERY_TITLE;
echo '
'.escape($title).'
';
}
}
if ($mode == 'date')
{
echo ''.escape($title).'
';
echo '
'.$menu.'
'.__('By date').' ';
if ($year)
echo ''.$year.' ';
if ($month)
echo ''.__('%B', 'TIME', strtotime($year.'-'.$month.'-01')).' ';
if ($day)
echo ''.__('%A %d', 'TIME', strtotime($year.'-'.$month.'-'.$day)).' ';
echo '
';
$pics = $f->getByDate($year, $month, $day);
if (empty($pics))
echo ''.__('No picture found.').'
';
if ($day)
{
echo '\n";
}
else
{
echo ''."\n";
$current = 0;
$current_y = 0;
$more = false;
foreach ($pics as &$pic)
{
if ($pic['year'] != $current_y)
{
if ($current_y)
echo '
';
echo '';
if (!$year)
{
echo ''.$pic['year'].'
';
if (isset($pic['more']))
echo ''.__("(%NB more pictures)", 'REPLACE', array('%NB' => $pic['more'])).'
';
echo '';
}
else
echo '';
$current_y = $pic['year'];
}
if (($month && $pic['day'] != $current) || ($year && !$month && $pic['month'] != $current))
{
if ($current)
echo '
';
$url = get_url('date', $pic['year'].'/'.zero_pad($pic['month']).($month ? '/'.zero_pad($pic['day']) : ''));
echo '
'.($month ? __('%A %d', 'TIME', $pic['time']) : __('%B', 'TIME', $pic['time'])).'
';
if (isset($pic['more']))
echo ''.__("(%NB more pictures)", 'REPLACE', array('%NB' => $pic['more'])).'
';
echo '
';
}
}
elseif ($mode == 'tags')
{
echo ''.$title.'
';
echo '
'.$menu.'
';
$tags = $f->getTagList();
if (empty($tags))
echo ''.__('No tag found.').'
';
else
{
$max = max(array_values($tags));
$min = min(array_values($tags));
$spread = $max - $min;
if ($spread == 0) $spread = 1;
$step = 200 / $spread;
echo ' ';
}
}
elseif ($mode == 'tag')
{
$pics = $f->getByTag($tag);
echo ''.$title.'
';
echo '
'.$menu.'
'.__('Tags').'
'.escape($tag_name).'';
if (!empty($pics))
echo ''.__('Slideshow').'';
echo '
';
$tags = $f->getNearTags($tag);
if (!empty($tags))
{
$max = max(array_values($tags));
$min = min(array_values($tags));
$spread = $max - $min;
if ($spread == 0) $spread = 1;
$step = 100 / $spread;
echo ' ';
}
if (empty($pics))
{
echo ''.__('No picture found.').'
';
}
else
{
echo '\n";
if (ALLOW_EMBED)
{
echo '
';
}
}
}
elseif ($mode == 'pic')
{
$pic = $f->getInfos($selected_file, $selected_dir);
if (!is_array($pic))
{
echo '
'.__('Picture not found').'
'.__('Back to homepage').'
';
exit;
}
echo '
'.$title.'
'.$menu.'
'.__('My Pictures')."\n";
if (!empty($selected_dir))
{
$current = '';
$dir = explode('/', $selected_dir);
foreach ($dir as $d)
{
if ($current) $current .= '/';
$current .= $d;
echo ' '.escape(strtr($d, '_-', ' '))."\n";
}
}
echo "
\n\n";
$orig_url = get_url('real_image', $pic);
$wh = '';
if (file_exists($f->getSmallPath($pic['hash'])))
{
$small_url = get_url('cache_small', $pic);
}
elseif ($pic['width'] <= MAX_IMAGE_SIZE && $pic['height'] <= MAX_IMAGE_SIZE)
{
$small_url = $orig_url;
list($nw, $nh) = $f->getNewSize($pic['width'], $pic['height'], SMALL_IMAGE_SIZE);
$wh = 'width="'.$nw.'" height="'.$nh.'"';
}
else
{
$small_url = false;
}
echo '
- ';
if ($small_url)
echo '';
else
echo __("This picture is too big (%W x %H) to be displayed in this page.", 'REPLACE', array('%W' => $pic['width'], '%H' => $pic['height']));
echo '
-
'.__('Download image at original size (%W x %H) - %SIZE KB', 'REPLACE',
array('%W' => $pic['width'], '%H' => $pic['height'], '%SIZE' => round($pic['size'] / 1000))).'
';
echo '
';
if (!empty($pic['details']))
{
$details = $f->formatDetails($pic['details']);
echo '
';
foreach ($details as $name=>$value)
{
echo '
- '.$name.'
- '.$value.'
';
}
echo '
';
}
list($prev, $next) = $f->getPrevAndNext($selected_dir, $selected_file);
echo '
';
}
elseif ($mode == 'slideshow' || $mode == 'embed')
{
if (!empty($selected_tag))
$type = $mode . '_tag';
else
$type = $mode;
$hd = $zoom = $current = false;
if (isset($_COOKIE['slideshow']) && strpos($_COOKIE['slideshow'], 'hd') !== false)
{
$hd = true;
}
if (isset($_COOKIE['slideshow']) && strpos($_COOKIE['slideshow'], 'z') !== false)
{
$zoom = true;
}
if (isset($selected_dir))
{
$list = $f->getDirectory($selected_dir);
if (!empty($list[1]))
$list = array_values($list[1]);
else
$list = false;
$back_url = get_url('album', $selected_dir);
if (!empty($list))
{
if ($selected_file)
{
$current = $f->getInfos($selected_file, $selected_dir);
}
else
{
$current = current($list);
}
}
}
elseif (!empty($selected_tag))
{
$list = array_values($f->getByTag($selected_tag));
$back_url = get_url('tag', $selected_tag);
if (!empty($list))
{
if (!empty($current_index) && !empty($list[$current_index - 1]))
{
$current = $list[$current_index - 1];
}
else
{
$current = current($list);
}
}
}
if (isset($_GET['hd']) || isset($_GET['zoom']))
{
if (isset($_GET['hd']))
$hd = ! $hd;
else
$zoom = ! $zoom;
setcookie('slideshow', ($zoom ? 'z' : '') . ($hd ? 'hd' : ''), time() + (3600 * 24 * 365), '/');
if (!empty($selected_tag))
{
$current = $selected_tag . '/' . ($current_index);
}
header('Location: '.get_url($type, $current));
exit;
}
echo '
'.escape($title).'
';
if (empty($list))
{
echo ''.__('No picture found.').'
';
}
else
{
echo '
';
if (!empty($current['comment']))
{
echo ''.$f->formatText($current['comment']).'
';
}
$url = get_url('real_image', $current);
if (($mode == 'embed' || !$hd) && file_exists($f->getSmallPath($current['hash'])))
{
$url = get_url('cache_small', $current);
}
if ($current['width'] > MAX_IMAGE_SIZE || $current['height'] > MAX_IMAGE_SIZE)
{
echo '';
echo __("This picture is too big (%W x %H) to be displayed in this page.",
'REPLACE', array('%W' => $current['width'], '%H' => $current['height']));
echo '
';
}
else
{
if ($zoom || $hd)
{
echo '';
}
else
{
echo '
';
}
echo '';
echo '
';
}
echo '';
$index = array_search($current, $list);
$prev = $index == 0 ? count($list) - 1 : $index - 1;
$next = $index == (count($list) - 1) ? 0 : $index + 1;
if (!empty($selected_tag))
{
$prev = $selected_tag . '/' . ($prev + 1);
$next = $selected_tag . '/' . ($next + 1);
$current = $selected_tag . '/' . ($index + 1);
}
else
{
$prev = $list[$prev];
$next = $list[$next];
}
echo '
- ← '.__('Previous').'
- '.($index + 1).' / '.count($list).'
- '.__('Next').' →
';
if ($mode != 'embed')
{
echo '
- '.($hd ? ''.__('HD').'' : __('HD')).'
- '.($zoom ? ''.__('Zoom').'' : __('Zoom')).'
';
}
echo '
- '.__('Back').'
';
}
echo '
';
}
else
{
$pics = $dirs = $update = $desc = false;
$list = $f->getDirectory($selected_dir);
echo '
'.escape($title).'
'.$menu.'
'.__('My Pictures').'';
if (!empty($selected_dir))
{
$dir = explode('/', $selected_dir);
$current = '';
foreach ($dir as $d)
{
if ($current) $current .= '/';
$current .= $d;
echo ' '.escape(strtr($d, '_-', ' '))."\n";
}
}
if (!empty($list[1]))
echo ''.__('Slideshow').'';
echo '
';
if ($list === false)
echo ''.__('No picture found.').'
';
else
list($dirs, $pics, $update, $desc) = $list;
if (!empty($update))
echo ''.__('Updating database, please wait, more pictures will appear in a while...').'
';
if ($desc)
{
echo ''.$f->formatText($desc).'';
}
if (!empty($dirs))
{
echo ''."\n";
foreach ($dirs as $dir)
{
echo ' - '.escape(strtr($dir, '_', ' '))."
\n";
}
echo "
\n";
}
if (!empty($pics))
{
echo '\n";
}
if (!empty($update))
{
echo "\n"
.'';
}
}
if ($mode != 'embed' && $mode != 'slideshow')
{
if (file_exists(BASE_DIR . '/user_footer.php'))
require_once BASE_DIR . '/user_footer.php';
else
{
echo '