. **********************************************************************/ // 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 '
'; 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') && !file_exists(CACHE_DIR . '/photos.sqlite')) $upgrade = true; elseif (!file_exists(CACHE_DIR . '/photos.sqlite')) $init = true; $this->db = new PDO('sqlite:' . CACHE_DIR . '/photos.sqlite'); $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); if ($upgrade) { $this->upgradeDBv3(); } elseif ($init) { header('Location: '.SELF_URL.'?index_all'); $this->initDB(); exit; } } protected function upgradeDBv3() { $this->initDB(); if (class_exists('SQLiteDatabase')) { $this->db->beginTransaction(); $old = new SQLiteDatabase(CACHE_DIR . '/photos.db'); $res = $old->query('SELECT * FROM photos;'); while ($row = $res->fetch(SQLITE_NUM)) { $row = array_map(array($this->db, 'quote'), $row); $this->db->exec('INSERT INTO photos VALUES ('.implode(',', $row).');'); } $res = $old->query('SELECT * FROM tags;'); while ($row = $res->fetch(SQLITE_NUM)) { $row = array_map(array($this->db, 'quote'), $row); $this->db->exec('INSERT INTO tags VALUES ('.implode(',', $row).');'); } $this->db->commit(); } else { // If there is no SQLite v2 driver, we just erease the old DB // and re-create index header('Location: '.SELF_URL.'?index_all'); unlink(CACHE_DIR . '/photos.db'); exit; } unlink(CACHE_DIR . '/photos.db'); return true; } protected function initDB() { $this->db->exec(' CREATE TABLE photos ( id INTEGER PRIMARY KEY, filename TEXT, path TEXT, width INTEGER, height INTEGER, size INTEGER, year INTEGER, month INTEGER, day INTEGER, time INTEGER, comment TEXT, details TEXT, hash TEXT ); 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 TEXT, name_id TEXT, photo INTEGER, PRIMARY KEY (name_id, photo) ); '); } // Returns informations on a photo public function getInfos($filename, $path, $from_list=false) { $query = $this->db->prepare('SELECT * FROM photos WHERE filename = ? AND path = ?;'); $query->execute(array($filename, $path)); $pic = $query->fetch(PDO::FETCH_ASSOC); if (!$pic) return false; $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; } $query = $this->db->prepare('SELECT name, name_id FROM tags WHERE photo = ?;'); $query->execute(array($pic['id'])); $pic['tags'] = array(); while ($row = $query->fetch(PDO::FETCH_ASSOC)) { $pic['tags'][$row['name_id']] = $row['name']; } $small_path = $this->getSmallPath($hash); if (GEN_SMALL == 2 && !$from_list && !file_exists($small_path) && $pic['width'] <= MAX_IMAGE_SIZE && $pic['height'] <= MAX_IMAGE_SIZE) { $this->resizeImage($file, $small_path, $pic['width'], $pic['height'], SMALL_IMAGE_SIZE); } return $pic; } public function getPrevAndNext($dir, $file) { $query = $this->db->prepare('SELECT id, hash, path, filename FROM photos WHERE path = ? AND filename < ? ORDER BY filename COLLATE NOCASE DESC LIMIT 0,1;'); $query->execute(array($dir, $file)); $prev = $query->fetch(PDO::FETCH_ASSOC); $query = $this->db->prepare('SELECT id, hash, path, filename FROM photos WHERE path = ? AND filename > ? ORDER BY filename COLLATE NOCASE ASC LIMIT 0,1;'); $query->execute(array($dir, $file)); $next = $query->fetch(PDO::FETCH_ASSOC); return array($prev, $next); } // Delete photo informations and thumb private function cleanInfos($id, $hash) { $this->db->exec('DELETE FROM photos WHERE id="'.(int)$id.'";'); $this->db->exec('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() { $query = $this->db->query('SELECT id, hash, path, filename FROM photos ORDER BY id;'); while ($row = $query->fetch(PDO::FETCH_ASSOC)) { $file = BASE_DIR . '/' . ($row['path'] ? $row['path'] . '/' : '') . $row['filename']; if (!file_exists($file)) { $this->cleanInfos($row['id'], $row['hash']); } } unset($query); } public function getNewPhotos($nb=10) { $query = $this->db->query('SELECT * FROM photos ORDER BY time DESC LIMIT 0,'.(int)$nb.';'); return $query->fetchAll(PDO::FETCH_ASSOC); } 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; if (!file_exists($file)) { return false; } $file_time = @filemtime($file); if (!$file_time) return false; $file_size = filesize($file); $hash = $this->getHash($filename, $path, $file_size, $file_time); $query = $this->db->prepare('SELECT 1 FROM photos WHERE hash = ? LIMIT 1;'); $query->execute(array($hash)); if ($query->fetchColumn()) { return false; } $size = getimagesize($file, $infos); $width = $size[0]; $height = $size[1]; $comment = ''; $tags = array(); $date = false; $details = array(); // 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 and other details $exif = @exif_read_data($file, 0, true, true); if (!empty($exif)) { if (!empty($exif['IFD0']['DateTimeOriginal'])) $date = strtotime($exif['IDF0']['DateTimeOriginal']); elseif (!empty($exif['EXIF']['DateTimeOriginal'])) $date = strtotime($exif['EXIF']['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']; } if (!empty($exif['IFD0']['Make'])) { $details['maker'] = trim($exif['IFD0']['Make']); } if (!empty($exif['IFD0']['Model'])) { if (!empty($details['maker'])) { $exif['IFD0']['Model'] = str_replace($details['maker'], '', $exif['IFD0']['Model']); } $details['model'] = trim($exif['IFD0']['Model']); } if (!empty($exif['EXIF']['ExposureTime'])) { $details['exposure'] = $exif['EXIF']['ExposureTime']; // To display a human readable number if (preg_match('!^([0-9.]+)/([0-9.]+)$!', $details['exposure'], $match) && (float)$match[1] > 0 && (float)$match[2] > 0) { $result = round((float)$match[1] / (float)$match[2], 3); $details['exposure'] = $result; } } if (!empty($exif['EXIF']['FNumber'])) { $details['fnumber'] = $exif['EXIF']['FNumber']; if (preg_match('!^([0-9.]+)/([0-9.]+)$!', $details['fnumber'], $match)) { $details['fnumber'] = round($match[1] / $match[2], 1); } } if (!empty($exif['EXIF']['ISOSpeedRatings'])) { $details['iso'] = $exif['EXIF']['ISOSpeedRatings']; } if (!empty($exif['EXIF']['Flash'])) { $details['flash'] = ($exif['EXIF']['Flash'] & 0x01) ? true : false; } if (!empty($exif['EXIF']['ExifImageWidth']) && !empty($exif['EXIF']['ExifImageLength'])) { $details['resolution'] = (int)$exif['EXIF']['ExifImageWidth'] . ' x ' . $exif['EXIF']['ExifImageLength']; } if (!empty($exif['EXIF']['FocalLength'])) { $details['focal'] = $exif['EXIF']['FocalLength']; if (preg_match('!^([0-9.]+)/([0-9.]+)$!', $details['focal'], $match)) { $details['focal'] = round($match[1] / $match[2], 1); } } } unset($exif); if (!$date) $date = $file_time; $can_resize = ($width <= MAX_IMAGE_SIZE && $height <= MAX_IMAGE_SIZE); if (isset($thumb)) { file_put_contents($this->getThumbPath($hash), $thumb); } elseif ($can_resize) { $this->resizeImage($file, $this->getThumbPath($hash), $width, $height, 160); } if (GEN_SMALL == 1 && $can_resize) { $this->resizeImage($file, $this->getSmallPath($hash), $width, $height, SMALL_IMAGE_SIZE); } if (!empty($details)) $details = json_encode($details); else $details = ''; $pic = array( 'filename' => $filename, 'path' => $path, 'width' => (int)$width, 'height' => (int)$height, 'size' => (int)$file_size, 'date_y' => date('Y', $date), 'date_m' => date('m', $date), 'date_d' => date('d', $date), 'time' => (int) $date, 'comment' => $comment, 'details' => $details, 'hash' => $hash, ); $query = $this->db->prepare('INSERT INTO photos (id, filename, path, width, height, size, year, month, day, time, comment, details, hash) VALUES (NULL, :filename, :path, :width, :height, :size, :date_y, :date_m, :date_d, :time, :comment, :details, :hash);'); $query->execute($pic); $pic['id'] = $this->db->lastInsertId(); if (!$pic['id']) { return false; } if (!empty($tags)) { $this->db->beginTransaction(); $query = $this->db->prepare('INSERT OR IGNORE INTO tags (name, name_id, photo) VALUES (?, ?, ?);'); foreach ($tags as $tag) { $query->execute(array($tag, $this->getTagId($tag), (int)$pic['id'])); } $this->db->commit(); } $pic['tags'] = $tags; return $pic; } static public function getValidDirectory($path) { $path = preg_replace('!(^/+|/+$)!', '', $path); if (preg_match('![.]{2,}!', $path)) return false; if ($path == '.') return ''; return $path; } // Returns directories and pictures inside a directory public function getDirectory($path='', $dont_check = false) { $path = self::getValidDirectory($path); if ($path === false) return false; 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; } // Don't detect updates when directory has already been updated // (used in 'index_all' process only, to avoid server load) elseif ($dont_check) { 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) { $query = $this->db->prepare('SELECT * FROM photos WHERE year = ? AND month = ? AND day = ? ORDER BY time;'); $query->execute(array((int)$y, (int)$m, (int)$d)); return $query->fetchAll(PDO::FETCH_ASSOC); } 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;'; $query = $this->db->query($req); $list = array(); while ($row = $query->fetch(PDO::FETCH_ASSOC)) { $start = 0; if ($row['nb'] > 5) { $start = mt_rand(0, $row['nb'] - 5); } // Get 5 random pictures for each line $subquery = 'SELECT * FROM photos WHERE year = '.$this->db->quote((int)$row['year']); if ($y) $subquery .= ' AND month = '.$this->db->quote((int)$row['month']); if ($m) $subquery .= ' AND day = '.$this->db->quote((int)$row['day']); $subquery .= 'ORDER BY time LIMIT '.(int)$start.', 5;'; $subquery = $this->db->query($subquery)->fetchAll(PDO::FETCH_ASSOC); if ($row['nb'] > 5) { $more = $row['nb'] - 5; foreach ($subquery as &$row_sub) { $row_sub['nb'] = $row['nb']; $row_sub['more'] = $more; } } $list = array_merge($list, $subquery); } return $list; } } public function getTagList() { $query = $this->db->query('SELECT COUNT(photo) AS nb, name, name_id FROM tags GROUP BY name_id ORDER BY name_id COLLATE NOCASE;'); $tags = array(); while ($row = $query->fetch(PDO::FETCH_ASSOC)) { $tags[$row['name']] = $row['nb']; } return $tags; } public function getByTag($tag) { $query = $this->db->prepare('SELECT photos.* FROM photos INNER JOIN tags ON tags.photo = photos.id WHERE tags.name_id = ? ORDER BY photos.time, photos.filename COLLATE NOCASE;'); $query->execute(array($this->getTagId($tag))); return $query->fetchAll(PDO::FETCH_ASSOC); } public function getNearTags($tag) { $query = $this->db->prepare('SELECT t2.name, COUNT(t2.photo) AS nb FROM tags INNER JOIN tags AS t2 ON tags.photo = t2.photo WHERE tags.name_id = ? AND t2.name_id != tags.name_id GROUP BY t2.name_id ORDER BY nb DESC;'); $query->execute(array($this->getTagId($tag))); $tags = array(); while ($row = $query->fetch(PDO::FETCH_ASSOC)) { $tags[$row['name']] = $row['nb']; } return $tags; } public function getTagNameFromId($tag) { $query = $this->db->prepare('SELECT name FROM tags WHERE name_id = ? LIMIT 1;'); $query->execute(array($tag)); return $query->fetchColumn(); } private function seems_utf8($str) { $length = strlen($str); for ($i=0; $i < $length; $i++) { $c = ord($str[$i]); if ($c < 0x80) $n = 0; # 0bbbbbbb elseif (($c & 0xE0) == 0xC0) $n=1; # 110bbbbb elseif (($c & 0xF0) == 0xE0) $n=2; # 1110bbbb elseif (($c & 0xF8) == 0xF0) $n=3; # 11110bbb elseif (($c & 0xFC) == 0xF8) $n=4; # 111110bb elseif (($c & 0xFE) == 0xFC) $n=5; # 1111110b else return false; # Does not match any model for ($j=0; $j<$n; $j++) { if ((++$i == $length) || ((ord($str[$i]) & 0xC0) != 0x80)) return false; } } return true; } private function intelligent_utf8_encode($str) { if ($this->seems_utf8($str)) return $str; else return utf8_encode($str); } public function formatText($text) { $text = $this->intelligent_utf8_encode($text); $text = escape($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; } 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 = '

' . ''.escape($photo['filename']).'

' . '

'.$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 = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAgVBMVEX%2F%2F%2F%2F%2B%2Ffr%2F%2F%2F%2Fx5svn06W%2FrYL06tPw48T69%2B769er17drv4sH%2B%2Fv39%2Bvb48uT2793s27SzoXn38ODq163r163q2Kzp2Kzz6dLz6M%2Fv4sP38eHu4L748eLz6dHt3Lfs3Ljw4sPu4L3s3Lfy6M%2Ft3bhmXEXMuIv%2FgICdjmvMAAD8%2BfNB06UXAAAAAXRSTlMAQObYZgAAAAFiS0dEAIgFHUgAAAAJcEhZcwAACxMAAAsTAQCanBgAAAAHdElNRQfUDB4RJBdfkpQSAAAAfElEQVR42o3MyRKCQAxF0WaeZwFRAQdId%2Fj%2FDzQNVEpc8Xb3VCVCbJNSHCYR5V8fhNq2f4S6qS41C3X%2BHqch34X6HnWe94xemyCCdW1dt%2F9YgLjeQJiVj1uZhbA%2FhTRQtCBl8Bc1z2rxGRJDg5EwxKYGM2ZwCv2jcECc2ReExg8II8b%2F0AAAAABJRU5ErkJggg%3D%3D'; $img_tag = 'data:image/png;base64,iVBORw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kpf5luf5Ko%2F99zP5Tqv9vwv5qvf9Qsf1BrPxQqf9Yr%2F6E0f5zxP5KpP9TrP5JpP5Bq%2Fx3yP5Urf5mu%2F5Wrv57y%2F43lv9UrP9buv1Psv06pvyB0P5Wtf00ofyAzv4%2BqfxXr%2F5Krf13x%2F9SrP50xP5uwf6Az%2F57yv49m%2F9YuP1tv%2F40k%2F9Yr%2F9Pqf9htf9zxf55yP5nu%2F9fvf13x%2F5luv5Bpf2Nw%2F8zk%2F%2F%2F%2F%2F9%2Bzf4NgFg2AAAAAXRSTlMAQObYZgAAAAFiS0dEAIgFHUgAAAAJcEhZcwAACxMAAAsTAQCanBgAAAAHdElNRQfUDB4RJAzV913%2BAAAAx0lEQVR42o2P1RaCUBBFAQEFCwU7ELu7u7tbGP7%2FN7zWu%2Fvt7DWz1jkYhtAQOkXRERrsi4HyOIbqtkoZPlleVwJXl7TJ10zy%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 ''; $pics = $f->getByDate($year, $month, $day); if (empty($pics)) echo '

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

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

    '.__("(%NB more pictures)", 'REPLACE', array('%NB' => $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 = 200 / $spread; echo '

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

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

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

    '; } else { echo '
      '."\n"; foreach ($pics as &$pic) { echo '
    • ' .''.escape($pic['filename']).'' ."
    • \n"; } echo "
    \n"; if (ALLOW_EMBED) { echo '
    '.__('Embed:').'
    '; } } } 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 = 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 ''.escape($pic['filename']).''; 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['comment'])) { echo '
    '.__('Comment:').'
    '.$f->formatText($pic['comment']).'
    '; } if (!empty($pic['tags'])) { echo '
    '.__('Tags:').'
    '; foreach ($pic['tags'] as $tag_id=>$tag) echo ''.escape($tag).' '; echo '
    '; } $date = __('%A %d %B %Y at %H:%M'); $date = strtr($date, array( '%1' => escape(get_url('date', $pic['year'].'/'.zero_pad($pic['month']).'/'.zero_pad($pic['day']))), '%2' => escape(get_url('date', $pic['year'].'/'.zero_pad($pic['month']))), '%3' => escape(get_url('date', $pic['year'])), )); $date = __($date, 'TIME', $pic['time']); echo '
    '.__('Date:').'
    '.$date.'
    '; if (ALLOW_EMBED) { echo '
    '.__('Embed:').'
    '.__('Embed as image:').'
    '; } 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 '
    • ' . ($prev ? '' . __('Previous') . '' : '') . '
    • ' . ($next ? '' . __('Next') . '' : '') . '
    '; } 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 ''.escape($current['filename']).''; 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 ' '; } echo ' '; } else { $pics = $dirs = $update = $desc = false; $list = $f->getDirectory($selected_dir); echo '

    '.escape($title).'

    '; 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 '
    • ' .''.escape($pic['filename']).'' ."
    • \n"; } 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 ' '; } } if ((time() % 100 == 0) || isset($cleanUpdate)) { flush(); $f->cleanDB(); } ?>