. */ // This check is useless, if you have PHP < 5 you will get a parse error if (phpversion() < 5) { die("Argh you don't have PHP 5 ! Please install it right now !"); } if (!class_exists('SQLiteDatabase')) { die("You don't have SQLite native extension, please install it."); } if (strpos($_SERVER['HTTP_HOST'], '.free.fr')) { die("Free.fr n'est pas compatible avec Fotoo Gallery (bug dans SQLite)"); } 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, 0700); return $dir . '/' . $hash . '_thumb.jpg'; } public function getSmallPath($hash) { $dir = CACHE_DIR . '/' . $hash[0]; if (!file_exists($dir)) mkdir($dir, 0700); return $dir . '/' . $hash . '_small.jpg'; } public function getTagId($name) { $name = htmlentities($name); $name = preg_replace('!&([aeiouyAEIOUYNcC]|ae)(?:circ|grave|acute|circ|tilde|uml|ring|slash|cedil|lig);!', '\\1', $name); $name = html_entity_decode($name); $name = strtolower($name); return $name; } public function __construct() { $init = false; if (!file_exists(CACHE_DIR)) { if (!mkdir(CACHE_DIR, 0700)) { echo '
'; echo 'Please create the directory '.CACHE_DIR.' and make it writable by this script.'; exit; } } if (!is_writable(CACHE_DIR)) { echo 'Please make the directory '.CACHE_DIR.' writable by this script.'; exit; } if (!file_exists(CACHE_DIR . '/photos.db')) $init = true; $this->db = new SQLiteDatabase(CACHE_DIR . '/photos.db', 0600); if ($init) $this->initDB(); } private function initDB() { $this->db->queryExec(' CREATE TABLE photos ( id INTEGER UNSIGNED PRIMARY KEY NOT NULL, filename VARCHAR(255) NOT NULL, path VARCHAR(255) NOT NULL, width SMALLINT UNSIGNED NOT NULL, height SMALLINT UNSIGNED NOT NULL, year SMALLINT UNSIGNED NOT NULL, month TINYINT UNSIGNED NOT NULL, day TINYINT UNSIGNED NOT NULL, time INTEGER UNSIGNED NOT NULL, comment VARCHAR(255) NOT NULL, hash VARCHAR(50) NOT NULL ); CREATE UNIQUE INDEX hash ON photos (hash); CREATE INDEX file ON photos (filename, path); CREATE INDEX date ON photos (year, month, day); CREATE TABLE tags ( name VARCHAR(255) NOT NULL, name_id VARCHAR(255) NOT NULL, photo INTEGER UNSIGNED, PRIMARY KEY (name_id, photo) );'); } private function upgradeDB($upgrade) { if ($upgrade == 'TAGS_ID') { $res = $this->db->arrayQuery('SELECT name, photo FROM tags;'); $this->db->queryExec(' DROP TABLE tags; CREATE TABLE tags ( name VARCHAR(255) NOT NULL, name_id VARCHAR(255) NOT NULL, photo INTEGER UNSIGNED, PRIMARY KEY (name_id, photo) );'); foreach ($res as $row) { $name_id = $this->getTagId($row['name']); $this->db->unbufferedQuery("INSERT INTO tags (name, name_id, photo) VALUES ('".sqlite_escape_string($row['name'])."', '".sqlite_escape_string($name_id)."', '".(int)$row['photo']."');"); } } die('

Upgrade to new version has been done with success. Reload the page.

'); } // Returns informations on a photo public function getInfos($filename, $path, $from_list=false) { $res = $this->db->arrayQuery("SELECT * FROM photos WHERE filename='".sqlite_escape_string($filename)."' AND path='".sqlite_escape_string($path)."'", SQLITE_ASSOC); if (empty($res[0])) return false; $pic =& $res[0]; $file = BASE_DIR . '/' . ($path ? $path . '/' : '') . $filename; // If the file doesn't exists anymore, we just delete it's informations if (!file_exists($file)) { $this->cleanInfos($pic['id'], $pic['hash']); return -1; } // Check if the file hash changed and if it's the case, delete the existing informations $hash = $this->getHash($filename, $path, filesize($file), filemtime($file)); if ($hash != $pic['hash']) { $this->cleanInfos($pic['id'], $pic['hash']); if (!$from_list && $pic = $this->addInfos($filename, $path)) return $pic; return false; } $tags = @$this->db->arrayQuery('SELECT name, name_id FROM tags WHERE photo="'.(int)$pic['id'].'";', SQLITE_ASSOC); if ($this->db->lastError() && ($error = error_get_last()) && preg_match('!no such column: name_id!', $error['message'])) { $this->upgradeDB('TAGS_ID'); } $pic['tags'] = array(); foreach ($tags as $row) { $pic['tags'][$row['name_id']] = $row['name']; } $small_path = $this->getSmallPath($hash); if (GEN_SMALL == 2 && !$from_list && !file_exists($small_path)) { $this->resizeImage($file, $small_path, $pic['width'], $pic['height'], 600); } return $res[0]; } public function getPrevAndNext($dir, $file) { $prev = $this->db->arrayQuery('SELECT id, hash, path, filename FROM photos WHERE path="'.sqlite_escape_string($dir).'" AND filename < "'.sqlite_escape_string($file).'" ORDER BY filename DESC LIMIT 0,1;', SQLITE_ASSOC); if (!empty($prev[0])) $prev = $prev[0]; else $prev = false; $next = $this->db->arrayQuery('SELECT id, hash, path, filename FROM photos WHERE path="'.sqlite_escape_string($dir).'" AND filename > "'.sqlite_escape_string($file).'" ORDER BY filename ASC LIMIT 0,1;', SQLITE_ASSOC); if (!empty($next[0])) $next = $next[0]; else $next = false; return array($prev, $next); } // Delete photo informations and thumb private function cleanInfos($id, $hash) { $this->db->queryExec('DELETE FROM photos WHERE id="'.(int)$id.'";'); $this->db->queryExec('DELETE FROM tags WHERE photo="'.(int)$id.'";'); $thumb = $this->getThumbPath($hash); if (file_exists($thumb)) unlink($thumb); $small = $this->getSmallPath($hash); if (file_exists($small)) unlink($small); return true; } // Delete all photos in DB which are deleted in filesystem public function cleanDB() { $res = $this->db->arrayQuery('SELECT id, hash, path, filename FROM photos ORDER BY id;'); foreach ($res as &$row) { $file = BASE_DIR . '/' . ($row['path'] ? $row['path'] . '/' : '') . $row['filename']; if (!file_exists($file)) { $this->cleanInfos($row['id'], $row['hash']); } } unset($res); } private function getHash($file, $path, $size, $time) { return md5($file . $path . $size . $time); } // Extract informations about a photo public function addInfos($filename, $path) { $file = BASE_DIR . '/' . ($path ? $path . '/' : '') . $filename; $file_time = @filemtime($file); if (!$file_time) return false; $hash = $this->getHash($filename, $path, filesize($file), $file_time); $size = getimagesize($file, $infos); $width = $size[0]; $height = $size[1]; $comment = ''; $tags = array(); $date = false; // IPTC contains tags if (!empty($infos['APP13'])) { $iptc = iptcparse($infos['APP13']); if (!empty($iptc['2#025'])) { foreach ($iptc['2#025'] as $tag) { $tags[] = $tag; } } unset($iptc); } unset($infos, $size); // EXIF contains date, comment and thumbnail $exif = exif_read_data($file, 0, true, true); if (!empty($exif)) { if (!empty($exif['IFD0']['DateTimeOriginal'])) $date = strtotime($exif['IDF0']['DateTimeOriginal']); elseif (!empty($exif['IFD0']['DateTime'])) $date = strtotime($exif['IFD0']['DateTime']); elseif (!empty($exif['FILE']['FileDateTime'])) $date = (int) $exif['FILE']['FileDateTime']; if (!empty($exif['COMMENT'])) { $comment = implode("\n", $exif['COMMENT']); $comment = trim($comment); } if (!empty($exif['THUMBNAIL']['THUMBNAIL'])) { $thumb = $exif['THUMBNAIL']['THUMBNAIL']; } } unset($exif); if (!$date) $date = $file_time; if (isset($thumb)) { file_put_contents($this->getThumbPath($hash), $thumb); } else { $this->resizeImage($file, $this->getThumbPath($hash), $width, $height, 160); } if (GEN_SMALL == 1) $this->resizeImage($file, $this->getSmallPath($hash), $width, $height, 600); @$this->db->unbufferedQuery("INSERT INTO photos (id, filename, path, width, height, year, month, day, time, comment, hash) VALUES (NULL, '".sqlite_escape_string($filename)."', '".sqlite_escape_string($path)."', '".(int)$width."', '".(int)$height."', '".date('Y', $date)."', '".date('m', $date)."', '".date('d', $date)."', '".(int)$date."', '".sqlite_escape_string($comment)."', '".sqlite_escape_string($hash)."');"); $id = $this->db->lastInsertRowid(); if (!$id) return false; foreach ($tags as $tag) { $this->db->unbufferedQuery("INSERT INTO tags (name, name_id, photo) VALUES ('".sqlite_escape_string($tag)."', '".sqlite_escape_string($this->getTagId($tag))."', '".(int)$id."');"); } return array( 'id' => $id, 'filename' => $filename, 'path' => $path, 'width' => $width, 'height'=> $height, 'time' => $date, 'comment'=> $comment, 'hash' => $hash, 'year' => date('Y', $date), 'month' => date('m', $date), 'day' => date('d', $date), 'tags' => $tags, ); } // Returns directories and pictures inside a directory public function getDirectory($path='') { $path = preg_replace('!(^/+|/+$)!', '', $path); if ($path == '.' || empty($path)) $dir_path = BASE_DIR . '/'; else $dir_path = BASE_DIR . '/' . $path . '/'; $dir = @dir($dir_path); if (!$dir) return false; $dirs = array(); $pictures = array(); $to_update = array(); while ($file = $dir->read()) { $file_path = $dir_path . $file; if ($file[0] == '.' || $file_path == CACHE_DIR) continue; if (is_dir($file_path)) { $dirs[] = $file; } elseif (!preg_match('!\.jpe?g$!i', $file)) { continue; } elseif ($pic = $this->getInfos($file, $path, true)) { if (is_array($pic)) $pictures[$file] = $pic; } else { $to_update[] = $file; } } $dir->close(); sort($dirs); ksort($pictures); if (file_exists($dir_path . 'README')) { $description = file_get_contents($dir_path . 'README'); } else { $description = false; } return array($dirs, $pictures, $to_update, $description); } public function getByDate($y=false, $m=false, $d=false) { if ($d) { return $this->db->arrayQuery('SELECT * FROM photos WHERE year="'.(int)$y.'" AND month="'.(int)$m.'" AND day="'.(int)$d.'" ORDER BY time;'); } else { // Get all days for a month view, all months for a year view or all years for a global view $req = 'SELECT day, month, year, COUNT(*) AS nb FROM photos WHERE 1 '; if ($y && $m) $req .= 'AND year="'.(int)$y.'" AND month="'.(int)$m.'" GROUP BY day ORDER BY day;'; elseif ($y) $req .= 'AND year="'.(int)$y.'" GROUP BY month ORDER BY month;'; else $req .= 'GROUP BY year ORDER BY year, month;'; $res = $this->db->arrayQuery($req, SQLITE_ASSOC); $list = array(); foreach ($res as &$row) { $start = 0; if ($row['nb'] > 5) $start = mt_rand(0, $row['nb'] - 5); // Get 5 random pictures for each line $res_sub = $this->db->arrayQuery('SELECT * FROM photos WHERE year="'.(int)$row['year'].'" '. ($y ? 'AND month="'.(int)$row['month'].'"' : ''). ($m ? 'AND day="'.(int)$row['day'].'"' : '').' ORDER BY time LIMIT '.$start.', 5;', SQLITE_ASSOC); if ($row['nb'] > 5) { $more = $row['nb'] - 5; foreach ($res_sub as &$row_sub) { $row_sub['nb'] = $row['nb']; $row_sub['more'] = $more; } } $list = array_merge($list, $res_sub); } return $list; } } public function getTagList() { $res = $this->db->arrayQuery('SELECT COUNT(photo) AS nb, name, name_id FROM tags GROUP BY name ORDER BY name;', SQLITE_ASSOC); $tags = array(); foreach ($res as &$row) { $tags[$row['name']] = $row['nb']; } return $tags; } public function getByTag($tag) { $tag = $this->getTagId($tag); $pics = $this->db->arrayQuery('SELECT photos.* FROM photos, tags WHERE photos.id = tags.photo AND tags.name_id = \''.sqlite_escape_string($tag).'\' ORDER BY photos.time, photos.filename;', SQLITE_ASSOC); foreach ($pics as &$pic) { foreach ($pic as $field=>$value) { $name = str_replace('photos.', '', $field); $pic[$name] = $value; if ($field != $name) unset($pic[$field]); } } return $pics; } public function getNearTags($tag) { $tag = $this->getTagId($tag); $res = $this->db->arrayQuery('SELECT tags.name AS name, COUNT(photos.id) AS nb FROM photos, tags, tags AS tago WHERE tago.name_id = \''.sqlite_escape_string($tag).'\' AND tago.photo = photos.id AND tago.name != tags.name AND tags.photo = photos.id GROUP BY tags.name ORDER BY nb DESC;'); $tags = array(); foreach ($res as &$row) { $tags[$row['name']] = $row['nb']; } return $tags; } private function intelligent_utf8_encode($str) { if (preg_match('%^(?: [\x09\x0A\x0D\x20-\x7E] # ASCII | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3 | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15 | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 )*$%xs', $str)) return $str; else return utf8_encode($str); } public function formatText($text) { $text = $this->intelligent_utf8_encode($text); $text = htmlspecialchars($text); // Allow simple, correctly closed, html tags (, , ...) $text = preg_replace('!<([a-z]+)>(.*)</\\1>!isU', '<\\1>\\2', $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; } /* * 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->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 thumb_url($pic) { return BASE_URL . 'cache/' . $pic['hash'][0] . '/' . $pic['hash'] . '_thumb.jpg'; } function img_page_url($pic) { return SELF_URL . '?' . (empty($pic['path']) ? '' : $pic['path'].'/') . $pic['filename']; } error_reporting(E_ALL); // 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 (!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 (!function_exists('__')) { function __($str, $time=false) { if ($time) return strftime($str, $time); else return $str; } } if (!isset($f) || !($f instanceOf fotooManager)) $f = new fotooManager; $mode = false; if (isset($_GET['update_js'])) { header('Content-Type: text/javascript'); echo <<= 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=' + escape(update_dir) + '&updateFile=' + escape(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(); } EOF_UPDATE_JS; exit; } if (isset($_GET['style_css']) || isset($_GET['slideshow_css'])) { header('Content-Type: text/css'); $img_home = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAgVBMVEX%2F%2F%2F%2F%2B%2Ffr%2F%2F%2F%2Fx5svn06W%2FrYL06tPw48T69%2B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g4bc1bXErN7jyW%2F3H9Tn6EkOFE%2BbmHmojH8O8sW1nV2Y395I26xevdROfzeON9Gmtk420LoYZPuYlGOU%2FrlG%2FfufaWWCHwEGAEtagFSXeJBuAAAAAElFTkSuQmCC'; $img_date = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAflBMVEX%2F%2F%2F%2Bbm5vuExPuJSXuUlPuWlnuLi7uSkruQULuNzjuHBzDwsPJysnuDAyZmpqampq3t7eamZqqq6u%2Fvr%2B6urrGxsa%2Bv76fn5%2Bnp6ecnJy9vL2%2Bvr6cm5uam5q5urmzs7Ovr6%2FHxsebnJyjo6PKycruX1%2FMzMyZmZn%2F%2F%2F%2FuAAALeyOvAAAAAXRSTlMAQObYZgAAAAFiS0dEAIgFHUgAAAAJcEhZcwAACxMAAAsTAQCanBgAAAAHdElNRQfUDB4RJToDVvkmAAAAZElEQVR42oWNRw6AMBADQ%2B%2B99x6S%2F38QFhBEAQn7Nh7JCL2zLIqs6YYqmSKlHHDopxGTJyuAiOC969EAgMUYHoDkWqECgJkxagCYN2zGGAEM945Pg31pAKRV2fpdH%2BZTVrjoPxuqaxRtezAMLwAAAABJRU5ErkJggg%3D%3D'; $img_dir = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAABa1BMVEX%2F%2F%2F%2F%2F92v%2F8GPp1CPklwrjjgX%2F9Wn%2F5FX%2F7F7%2F%2FXH%2F%2Bm7%2F%2FnL%2F6lz%2F6Fr%2F82bj1oXlpRDjkAfmpxDkmQrnuRj110jnuxniigP%2F82f1zz71zT3%2F51nozCD%2F%2B2%2Fkkgf16l7jiQPmsxbmshXp1STlqBD14lXmsRTlqxLjigTp0yP%2F72LihgL120zp0iP%2F30%2FpzyLnxR3%2F%2B3D1zDv%2F8mX%2F%2FXLo0SL%2F2UnoxR717mL11Ub%2F92z%2F7mHp0CLntxf%2F%2BW3loA7%2F4FHnvhr%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2BnzR0QLYHoLXjSNBUhcOZQC71%2BIn38VM%2FES0DewhS1P%2BVg2G485Dwe2Xf2NIHI1jcRL7iycAMB5ogC93MwAAAABJRU5ErkJggg%3D%3D'; $img_back = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAyCAYAAACd+7GKAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAADVJREFUCNeFjUEOACAMwiqT/3/Zm3OJUw5NyBjAKQmYG672hoxEtf5/tNfowu3au8oChgASC4cWARUDoKzWAAAAAElFTkSuQmCC'; 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'])) { function update_dir($dir) { global $f; $pics = $dirs = $update = $desc = false; $list = $f->getDirectory($dir, true); 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(''); echo ''; if ($res) { list($dir, $update_list) = $res; echo "\n" .''; } echo '

'; if ($res) { echo ' '.__('Updating').'
... '.$dir; } else { echo ''.__('Update done.').''; } echo '

'; exit; } // Get which display mode is asked if (isset($_GET['date'])) { $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', strtotime($_GET['date'])); elseif ($month) $title = __('Pictures for %B %Y', strtotime($_GET['date'].'/01')); elseif ($year) $title = str_replace('%Y', $year, __('Pictures for %Y')); else $title = __('Pictures by date'); $mode = 'date'; } elseif (isset($_GET['tags'])) { $title = __('Pictures by tag'); $mode = 'tags'; } elseif (!empty($_GET['tag'])) { $mode = 'tag'; $tag = $_GET['tag']; $title = sprintf(__('Pictures in tag %s'), htmlspecialchars($tag)); } elseif (isset($_GET['slideshow'])) { $mode = 'slideshow'; $selected_dir = $_GET['slideshow']; $title = __('Slideshow'); } 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 = $match[1]; $title = strtr(htmlspecialchars($match[1]), array('/' => ' / ', '_' => ' ')); if (!empty($match[2])) { $selected_file = $match[2] . '.' . $match[3]; $mode = 'pic'; $title = strtr(htmlspecialchars($match[2]), array('_' => ' ', '-' => ' - ')); } } else { $selected_dir = ''; } } if ($mode == 'slideshow') $css = SELF_URL . '?slideshow.css'; elseif (file_exists(BASE_DIR . '/user_style.css')) $css = BASE_URL . 'user_style.css'; else $css = SELF_URL . '?style.css'; $f->html_tags['tag'] = SELF_URL . '?tag={KEYWORD}'; $f->html_tags['date'] = SELF_URL . '?date={KEYWORD}'; $menu = '
'.__('My Pictures').' '.__('By tags').' '.__('By date').'
'; header('Content-Type: text/html; charset=UTF-8'); if ($mode != 'slideshow' && file_exists(BASE_DIR . '/user_header.php')) require BASE_DIR . '/user_header.php'; else { if (!$title) $title = __('My Pictures'); echo ' '.$title.' '; } if ($mode == 'date') { echo '

'.$title.'

'; echo ''; $pics = $f->getByDate($year, $month, $day); if (empty($pics)) echo '

'.__('No picture found.').'

'; if ($day) { echo '
    '."\n"; foreach ($pics as &$pic) { echo '
  • ' .''.htmlspecialchars($pic['filename']).'' ."
  • \n"; } 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 '

    '.sprintf(__("(%s more pictures)"), $pic['more']).'

    '; echo ''; } } elseif ($mode == 'tags') { echo '

    '.$title.'

    '; echo ''; $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 = 100 / $spread; echo '

    '; foreach ($tags as $tag=>$nb) { $size = 100 + round(($nb - $min) * $step); echo '' .htmlspecialchars($tag).' ('.$nb.') '; } echo '

    '; } } elseif ($mode == 'tag') { echo '

    '.$title.'

    '; 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 = 50 / $spread; echo ''; } $pics = $f->getByTag($tag); if (empty($pics)) echo '

    '.__('No picture found.').'

    '; { echo '
      '."\n"; foreach ($pics as &$pic) { echo '
    • ' .''.htmlspecialchars($pic['filename']).'' ."
    • \n"; } echo "
    \n"; } } elseif ($mode == 'pic') { $pic = $f->getInfos($selected_file, $selected_dir); if (!is_array($pic)) { echo '

    '.__('Picture not found').'

    '.__('Back to homepage').'

    '; exit; } echo '

    '.$title.'

    \n"; $orig_url = BASE_URL . (empty($pic['path']) ? '' : $pic['path'].'/') . $pic['filename']; $wh = ''; if (file_exists($f->getSmallPath($pic['hash']))) $small_url = BASE_URL.'cache/'.$pic['hash'][0].'/'.$pic['hash'].'_small.jpg'; else { $small_url = $orig_url; list($nw, $nh) = $f->getNewSize($pic['width'], $pic['height'], 600); $wh = 'width="'.$nw.'" height="'.$nh.'"'; } echo '
    '.$pic['filename'].'
    '.sprintf(__('Download image at original size (%s x %s)'), $pic['width'], $pic['height']).'
    '; echo '
    '; if (!empty($pic['comment'])) { echo '
    '.__('Comment:').'
    '.$f->formatText($pic['comment']).'
    '; } if (!empty($pic['tags'])) { echo '
    '.__('Tags:').'
    '; foreach ($pic['tags'] as $tag_id=>$tag) echo ''.htmlspecialchars($tag).' '; echo '
    '; } $date = __('%A %d %B %Y at %H:%M'); $date = strtr($date, array( '%1' => SELF_URL . '?date='.$pic['year'].'/'.$pic['month'].'/'.$pic['day'], '%2' => SELF_URL . '?date='.$pic['year'].'/'.$pic['month'], '%3' => SELF_URL . '?date='.$pic['year'], )); $date = __($date, $pic['time']); echo '
    '.__('Date:').'
    '.$date.'
    '; list($prev, $next) = $f->getPrevAndNext($selected_dir, $selected_file); echo '
    • ' . ($prev ? '' . __('Previous') . '' : '') . '
    • ' . ($next ? '' . __('Next') . '' : '') . '
    '; } elseif ($mode == 'slideshow') { $list = $f->getDirectory($selected_dir, true); if ($list === false || empty($list[1])) echo '

    '.__('No picture found.').'

    '; else { echo '
    '; } } else { $pics = $dirs = $update = $desc = false; $list = $f->getDirectory($selected_dir, true); echo "

    ".$title."

    \n"; echo '\n"; 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"; } if (!empty($pics)) { echo '
      '."\n"; foreach ($pics as &$pic) { echo '
    • ' .''.htmlspecialchars($pic['filename']).'' ."
    • \n"; } echo "
    \n"; } if (!empty($update)) { echo "\n" .''; } } if (file_exists(BASE_DIR . '/user_footer.php')) require_once BASE_DIR . '/user_footer.php'; else { echo ' '; } if ((time() % 100 == 0) || isset($cleanUpdate)) { flush(); $f->cleanDB(); } ?>