Gimli2).'; public $html_head = '{title}'; public $html_tail = ''; public $exts = array('jpg','jpeg','png','gif','bmp','tif','tiff','svg','swf','flv','mp4', 'mp3'); public $extsIcon = array('jpg','jpeg','png', 'gif', 'bmp'); public $extsExif = array('jpg','jpeg','tif','tiff'); public $extsVideo = array('swf','flv','mp4'); public $extsAudio = array('mp3'); public $defaultMime = 'text/plain'; public $avMime = array( 'mp3' => 'audio/mpeg', 'mp4' => 'video/mp4', 'swf' => 'application/x-shockwave-flash', 'flv' => 'video/x-flv' ); private $islocked = false; private $validusers = array(); function __construct() { $this->html_head = '{title} '; $this->html_tail = '

Powered by SiGal | Credits & info
'; $ownstyle_replacement = ''; if (file_exists('./ownstyle.css')) { $ownstyle_replacement = ''."\n"; $this->html_head = str_replace('', $ownstyle_replacement, $this->html_head); } $this->html_tail = str_replace('', $this->legal_notice, $this->html_tail); } public function addAccess() { $user = trim($_POST['fuser']); $pass = trim($_POST['fpass']); $_SESSION['givenaccess'][] = $user.':'.$pass; $_SESSION['givenaccess'] = array_unique($_SESSION['givenaccess']); } public function showGallery() { echo str_replace('{title}',$this->galTitle,$this->html_head); echo '
'; echo '

'.$this->galTitle.'

'; echo '
'; $albs=$this->getAlbums(); $albs_by_year = array(); foreach($albs as $a) { $bn = basename($a); $cutpos = strpos($bn, '-'); if ($cutpos === FALSE) $cutpos = strpos($bn, '_'); if ($cutpos === FALSE) $cutpos = strlen($bn); $group = substr($bn, 0,$cutpos); $albs_by_year[$group][] = $a; } $tabs = 100; $years = array_keys($albs_by_year); echo ''; $tabs = 100; foreach ($albs_by_year as $year=>$albs) { echo '
'; echo '
'; echo '
'; echo '

'.$year.'

'; foreach ($albs as $key=>$a) { $titlefoto = $this->getAlbumTitleFile($a); $thumb = $this->getThumbName($titlefoto); $bn = basename($a); $content = glob($a.'*'); $cnt = count($content); $date = filemtime($a); echo '
'; if (array_search($a.$this->lockfname, $content)!==FALSE) { echo 'locked'; } echo ''; if ($thumb===$this->defaultIcon || file_exists($thumb)) { echo ''.$bn.''; } else { echo ''.$bn.''; } echo ''; echo $this->getAlbumTitle($a); echo '
'.date("d. m. Y", $date).' ('.$cnt.' files)
'; echo '
'."\n"; } echo '
'; echo '
'."\n"; echo '
'."\n"; $tabs++; } echo $this->html_tail; } public function showAlbum($alb) { $alb=$this->sanitizePath(urldecode($alb)); $aname=basename($alb); echo str_replace('{title}',$aname,$this->html_head); echo '
'; echo '

'.$this->galTitle.': '.$aname.'

'; echo '
'; echo '
Navigation: Back to album selection
'; $fotos=$this->getImages($alb); if ($this->islocked && !$this->isAccessible()) { $this->showPassForm(); echo ''; echo ''; echo $this->html_tail; } public function showImage($f) { $f=$this->sanitizePath(urldecode($f)); $bn=basename($f); $lf = substr($f, 0, -1*mb_strlen($bn)).$this->lockfname; if (file_exists($lf)) { $this->islocked = true; $this->validusers = file($lf); } else { $this->islocked = false; } $ext = strtolower($this->getExt($f)); echo str_replace('{title}',$bn,$this->html_head); if ($this->islocked && !$this->isAccessible()) { $this->showPassForm(); echo ''; echo $this->html_tail; die(); } echo '
'; if (in_array($ext, $this->extsVideo)) { echo ''; } elseif (in_array($ext, $this->extsAudio)) { echo ''; } else { $middle = $this->getMiddleName($f); if (file_exists($middle)) { echo ''.$bn.''; } else { echo ''.$bn.''; } } echo '
'; echo '
Navigation: Back to album thumbnails

'; echo ''; echo '
'; echo '
'; echo '

'.$bn.'

'; echo 'download full size ('.round(filesize($f)/(1024*1024),2).' MB)'; echo '
'; echo '
'; if (in_array($ext, $this->extsExif)) { $exif=exif_read_data($f); echo '
'; echo '
'; echo '
    '; echo '
  • date: '.$exif['DateTimeOriginal'].'
  • '; echo '
  • orig. filesize: '.round($exif['FileSize']/(1024*1024),2).' MB
  • '; echo '
  • orig. size: '.$exif['COMPUTED']['Width'].'*'.$exif['COMPUTED']['Height'].' px
  • '; echo '
  • exposition: '.$exif['ExposureTime'].' s
  • '; echo '
  • ISO: '.$exif['ISOSpeedRatings'].'
  • '; echo '
  • Anum: '.$exif['COMPUTED']['ApertureFNumber'].'
  • '; echo '
  • FocalLength: '.$exif['FocalLength'].' mm
  • '; echo '
  • Orientation: '.$exif['Orientation'].'
  • '; echo '
  • Camera model: '.$exif['Model'].'
  • '; echo '
'; echo '
'; echo '
'; echo '
'; echo '
'; if ($this->hasGPSData($exif)) { $gps = $this->getGPSLatLon($exif); $hgps = $this->getHumanGPS($gps[0], $gps[1]); echo '

'.$hgps['lat'].', '.$hgps['lon'].'

'; echo 'mapy.cz
'; echo 'maps.google.com

'; echo '
'; echo '
'; echo '
'; echo '
'; echo '
'; echo '
'; echo '
'; echo '
'; echo '
'; echo '
'; echo '
'; } else { echo 'No GPS data.'; } echo '
'; echo '
'; } else { echo '
'; echo 'No EXIF data.'; echo '
'; echo '
'; echo 'No GPS data.'; echo '
'; } echo '
'; echo '
'; echo $this->html_tail; } public function showPassForm() { ?>

This album is locked

Please tell me who are you…





dir.'*'); foreach($files as $k=>$v) { if (is_dir($v)) { $files[$k]=$v.'/'; } else { unset($files[$k]); } } arsort($files); return $files; } public function getImages($dir) { $r = glob($dir.'*'); $photos = array(); $this->islocked = false; foreach($r as $file) { $ext = strtolower($this->getExt($file)); if (in_array($ext, $this->exts)) $photos[] = $file; if (basename($file) == $this->lockfname) { $this->islocked = true; $this->validusers = file($file); foreach ($this->validusers as $key=>$val) { $this->validusers[$key] = trim($val); } } } return $photos; } public function getAlbumTitleFile($album) { if (file_exists($album.$this->icotitlefname)) return $album.trim(file_get_contents($album.$this->icotitlefname)); $files = glob($album.'*'); foreach($files as $file) { $ext = strtolower($this->getExt($file)); if (in_array($ext, $this->extsIcon)) return $file; } return $this->defaultIcon; } public function makeThumbImage($file) { $f = $this->sanitizePath(urldecode($file)); $ext = strtolower($this->getExt($f)); if (file_exists($f) && in_array($ext, $this->extsIcon)) { $thumb = $this->resizeImage($f, $this->thumb_x); header('Location: '.$thumb); die(); } header('Status: 404 Not Found'); die(); } public function makeMiddleImage($file) { $f = $this->sanitizePath(urldecode($file)); $ext = strtolower($this->getExt($f)); if (file_exists($f) && in_array($ext, $this->extsIcon)) { $middle = $this->resizeImage($f, $this->middle_x); header('Location: '.$middle); die(); } header('Status: 404 Not Found'); die(); } private function isAccessible() { if (!isset($_SESSION['givenaccess'])) $_SESSION['givenaccess'] = array(); foreach ($_SESSION['givenaccess'] as $user) { foreach ($this->validusers as $valid) { if ($user == $valid) return true; } } return false; } private function sanitizePath($p) { $p = trim($p); if ($this->dir != mb_substr($p, 0, mb_strlen($this->dir))) return ''; $p = str_replace('..','',$p); $p = str_replace('*','',$p); $p = str_replace('://','',$p); return $p; } private function getExt($file) { return mb_substr($file,mb_strrpos($file, '.')+1); } private function getMimeType($file) { $mime = $this->defaultMime; if (function_exists('mime_content_type')) $mime = mime_content_type($file); return $mime; } private function getMiddleName($file) { $ext = strtolower($this->getExt($file)); if (in_array($ext, $this->extsIcon)) { $md5 = MD5($file.$this->middle_x); $targetDir = $this->cache.substr($md5,0,1).'/'; $targetImagePath = $targetDir.$md5.".jpg"; return $targetImagePath; } return $this->defaultIcon; } private function getThumbName($file) { if ($file === $this->defaultIcon) return $file; $ext = strtolower($this->getExt($file)); if (in_array($ext, $this->extsIcon)) { $md5 = MD5($file.$this->thumb_x); $targetDir = $this->cache.substr($md5,0,1).'/'; $targetImagePath = $targetDir.$md5.".jpg"; return $targetImagePath; } return $this->defaultIcon; } private function getImageTitle($file){ $bn = basename($file); $elipse = (mb_strlen($bn)>$this->imgTitleLen) ? '…':''; return '

'.mb_substr($bn,0,$this->imgTitleLen).$elipse.'

'; } private function getAlbumTitle($file){ $bn = basename($file); $patterns = array('~(19|20)(\d{2})-(\d{1,2})-(\d{1,2})_(.*)~si', '~(19|20)(\d{2})-(\d{1,2})-(\d{1,2})-(\d{1,2})_(.*)~si'); $replacements = array('\5 (\4. \3. \1\2)', '\6 (\4-\5. \3. \1\2)'); $bn = preg_replace($patterns, $replacements , $bn); $elipse = (strlen($bn)>$this->imgTitleLen) ? '…':''; return '

'.substr($bn,0,$this->imgTitleLen).$elipse.'

'; } private function hasGPSData($exif) { return (isset($exif['GPSLatitude']) && isset($exif['GPSLongitude'])); } private function getGPSLatLon($exif) { if (isset($exif['GPSLatitude']) && isset($exif['GPSLongitude'])) { $lat = $exif['GPSLatitude']; $lon = $exif['GPSLongitude']; list($cit,$jmen) = explode('/', $lat[0]); if ($jmen == 0) return array(0,0); $gpslat = $cit/$jmen; list($cit,$jmen) = explode('/', $lat[1]); if ($jmen == 0) return array(0,0); $gpslat += $cit/($jmen*60); list($cit,$jmen) = explode('/', $lat[2]); if ($jmen == 0) return array(0,0); $gpslat += $cit/($jmen*3600); list($cit,$jmen) = explode('/', $lon[0]); if ($jmen == 0) return array(0,0); $gpslon = $cit/$jmen; list($cit,$jmen) = explode('/', $lon[1]); if ($jmen == 0) return array(0,0); $gpslon += $cit/($jmen*60); list($cit,$jmen) = explode('/', $lon[2]); if ($jmen == 0) return array(0,0); $gpslon += $cit/($jmen*3600); return array($gpslat,$gpslon); } else { return array(0,0); } } private function getHumanGPS($lat, $lon) { $slat = ($lat > 0) ? 'N ' : 'S '; $whole = floor($lat); $slat .= $whole.'° '.number_format(($lat-$whole)*60,3); $slon = ($lon > 0) ? 'E ' : 'W '; $whole = floor($lon); $slon .= $whole.'° '.number_format(($lon-$whole)*60,3); return array('lat'=>$slat, 'lon'=>$slon); } public function resizeImage($path, $max_x) { $sourceImagePath = $path; $md5 = MD5($path.$max_x); $targetDir = $this->cache.substr($md5,0,1).'/'; $targetImagePath = $targetDir.$md5.".jpg"; $outputImageQuality = 80; if (!file_exists($targetDir)) mkdir($targetDir); if(!file_exists($targetImagePath)) { $originalImageSize = getimagesize($sourceImagePath); $original_x = $originalImageSize[0]; $original_y = $originalImageSize[1]; $square = 0; if($original_x > $original_y) { $max_y = 0; $max_x = $max_x; } else if($original_x < $original_y) { $max_y = $max_x; $max_x = 0; } else { $max_y = $max_x; $max_x = $max_x; $square = 1; } $state = 0; if($square == 1) { if($max_x == 0) $max_x = $max_y; elseif($max_y == 0) $max_y = $max_x; } if($max_x == 0) $state = 1; elseif($max_y == 0) $state = 2; if($state == 0) { $testratio = $max_x / $max_y; $origratio = $original_x / $original_y; if($origratio > $testratio) $state = 1; elseif($origratio < $testratio) $state = 2; else $state = 3; } if($state == 1) { if($square == 0) { if(($original_y > $max_y) || ($enlarge == 1)) $new_y = $max_y; else $new_y = $original_y; $new_x = round(($original_x / ($original_y / $new_y)), 0); $srcx = 0; $srcy = 0; $srcw = $original_x; $srch = $original_y; } else { if(($original_y > $max_y) || ($enlarge == 1)) $new_y = $max_y; else $new_y = $original_y; $new_x = $new_y; $tempratio = ($original_y / $new_y); $sectionwidth = $new_y * $tempratio; $srcy = 0; $srch = $original_y; $srcx = floor(($original_x - $sectionwidth) / 2); $srcw = floor($sectionwidth); } } elseif($state == 2) { if($square == 0) { if(($original_x > $max_x) || ($enlarge == 1)) $new_x = $max_x; else $new_x = $original_x; $new_y = round(($original_y / ($original_x / $new_x)), 0); $srcx = 0; $srcy = 0; $srcw = $original_x; $srch = $original_y; } else { if(($original_x > $max_x) || ($enlarge == 1)) $new_x = $max_x; else $new_x = $original_x; $new_y = $new_x; $tempratio = ($original_x / $new_x); $sectionheight = $new_x * $tempratio; $srcx = 0; $srcw = $original_x; $srcy = floor(($original_y - $sectionheight) / 2); $srch = floor($sectionheight); } } elseif($state == 3) { if($square == 0) { if(($original_x > $max_x) || ($enlarge == 1)) $new_x = $max_x; else $new_x = $original_x; $new_y = round(($original_y / ($original_x / $new_x)), 0); $srcx = 0; $srcy = 0; $srcw = $original_x; $srch = $original_y; } else { if(($original_x > $max_x) || ($enlarge == 1)) $new_x = $max_x; else $new_x = $original_x; $new_y = $new_x; $srcx = 0; $srcy = 0; $srcw = $original_x; $srch = $original_y; } } $ext = strtolower($this->getExt($path)); switch ($ext) { case 'jpg': case 'jpeg': $originalImage = imagecreatefromjpeg($sourceImagePath); break; case 'png': $originalImage = imagecreatefrompng($sourceImagePath); break; case 'gif': $originalImage = imagecreatefromgif($sourceImagePath); break; case 'bmp': $originalImage = imagecreatefromwbmp($sourceImagePath); break; default: $originalImage = imagecreatefromjpeg($sourceImagePath); break; } $newImage = ImageCreateTrueColor($new_x, $new_y); ImageCopyResampled ($newImage, $originalImage, 0, 0, $srcx, $srcy, $new_x, $new_y, $srcw, $srch); ImageJPEG ($newImage, $targetImagePath, $outputImageQuality); ImageDestroy($newImage); ImageDestroy($originalImage); } $imageSize = getimagesize($targetImagePath); return $targetImagePath; } } $gg = new Sigal(); $conf = array(); if (file_exists('./config.php')) include './config.php'; $kws = array('dir', 'cache', 'defaultIcon', 'icotitlefname', 'lockfname', 'thumb_x', 'thumb_y', 'middle_x', 'imgTitleLen', 'galTitle', 'legal_notice'); foreach ($kws as $item) { if (isset($conf[$item])) $gg->$item = $conf[$item]; } if (isset($_GET['credits'])) { echo str_replace('{title}',$gg->galTitle,$gg->html_head); ?>

Credits, info, license

This script is inspired by simplicity of brilliant MySQL client Adminer from Jakub Vrána. It is completely in only one file. It is very simple to upload it anywhere to hosting and use it in few seconds. And why don't use this idea for web photo gallery?

Based on next works:

Info:

Author: Gimli2

History:

License of SiGal:

Modified BSD License (http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5)

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

html_tail; die(); } if (isset($_GET['mkmid'])) { $gg->makeMiddleImage($_GET['mkmid']); } if (isset($_GET['mkthumb'])) { $gg->makeThumbImage($_GET['mkthumb']); } if (isset($_GET['foto'])) { session_start(); if (isset($_POST['fakce']) && $_POST['fakce']=='addaccess') $gg->addAccess(); $gg->showImage($_GET['foto']); die(); } if (isset($_GET['alb'])) { session_start(); if (isset($_POST['fakce']) && $_POST['fakce']=='addaccess') $gg->addAccess(); $gg->showAlbum($_GET['alb']); die(); } if (isset($_GET['salb'])) { session_start(); if (isset($_POST['fakce']) && $_POST['fakce']=='addaccess') $gg->addAccess(); $gg->showAlbum(urlencode($gg->dir).$_GET['salb'].urlencode('/')); die(); } if (isset($_GET['static'])) { header('Location: index.min.php?static='.$_GET['static']); } $gg->showGallery();