'audio/mpeg', 'mp4' => 'video/mp4', 'mts' => 'video/mts', 'mov' => 'video/quicktime', 'swf' => 'application/x-shockwave-flash', 'flv' => 'video/x-flv' ); public $func_sortimages = NULL; public $func_sortalbums = NULL; public $func_scandir = NULL; public $func_albumname = NULL; public $func_groupname = NULL; public $func_sortgroups = NULL; public $langs = array( 'en' => 'English', 'cs' => 'Čeština', ); public $LANG = 'en'; private $islocked = false; private $validusers = array(); public $html_head = '{title} '; public $html_tail = ''; function __construct() { $this->detect_lang(); $ownstyle_replacement = ''; if (file_exists('./ownstyle.css')) { $ownstyle_replacement = ''."\n"; $this->html_head = str_replace('', $ownstyle_replacement, $this->html_head); } if (file_exists('./ga.js')) { $gajs_replacement = ''."\n"; $this->html_head = str_replace('', $gajs_replacement, $this->html_head); } $this->html_tail = '

'.$this->lang('Powered by').' SiGal | '.$this->lang('Settings & info').'
'; $this->html_tail = str_replace('', $this->legal_notice.'
lang='.$this->LANG, $this->html_tail); } public function addAccess() { $user = trim($_POST['fuser']); $pass = trim($_POST['fpass']); $_SESSION['givenaccess'][] = trim($user.':'.$pass); $_SESSION['givenaccess'] = array_unique($_SESSION['givenaccess']); } public function basepathname($path) { $len = strlen($this->dir) + 1; if(0 == strncmp($path, $this->dir . '/', $len)) { $path = substr($path, $len); } return $path; } public function getparentdir($path) { return substr($path, 0, -1 * (1 + strlen(basename($path)))); } function urlpathencode($path) { return implode("/", array_map(function($s) { return urlencode($s); }, explode("/", $path))); } public function showGallery($albtop = NULL) { ob_start(); ob_implicit_flush(true); echo str_replace('{title}', $this->galTitle, $this->html_head); echo '
'; $aname=''; if($albtop!==NULL) { $aname = $this->basepathname($albtop); echo '

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

'; } else { echo '

'.$this->galTitle.'

'; } echo '
'; $albs = $this->getAlbums($albtop); if ($albtop!==NULL) { echo '
'.$this->lang('Navigation').': '; echo ''.$this->lang('Back to parent album').''; echo ' | '.$this->lang('Back to top level').''; echo '
'; } $albs_by_group = array(); foreach($albs as $a) { $bn = $this->basepathname($a); if (isset($this->func_groupname) && $this->func_groupname !== NULL && is_callable($this->func_groupname)) { $group = call_user_func($this->func_groupname, $bn); } else { $cutpos = strpos($bn, '-'); if ($cutpos === FALSE) $cutpos = strpos($bn, '_'); if ($cutpos === FALSE) $cutpos = strlen($bn); $group = substr($bn, 0,$cutpos); } $albs_by_group[$group][] = $a; } $tabs = 100; $groups = array_keys($albs_by_group); if (isset($this->func_sortgroups) && $this->func_sortgroups !== NULL && is_callable($this->func_sortgroups)) { $groups = call_user_func($this->func_sortgroups, $groups); } if(count($groups) > 1 || ( count($groups) == 1 && strlen($groups[0]) > 0) ) { echo ''; } $tabs = 100; foreach ($groups as $group) { $albs = $albs_by_group[$group]; echo '
'; echo '
'; echo '
'; echo '

'.$group.'

'; foreach ($albs as $key=>$a) { $titlefoto = $this->getAlbumTitleFile($a); $thumb = $this->getThumbName($titlefoto); $bn = $this->basepathname($a); $content = glob($a.'/*'); $cnt = count($content); $date = filemtime($a); echo '
'; if (array_search($a.'/'.$this->lockfname, $content)!==FALSE) { echo ''.$this->lang('locked').''; } echo ''; if ($thumb === $this->defaultIcon || $thumb === $this->defaultDirIcon || file_exists($thumb)) { echo ''.$bn.''; } else { echo ''.$bn.''; } echo ''; echo $this->getAlbumTitle($a); echo '
'.date($this->date_format, $date).' ('.$this->lang('%d files',$cnt).')
'; echo '
'."\n"; ob_flush(); } echo '
'; echo '
'."\n"; echo '
'."\n"; $tabs++; } if ($albtop!==NULL) { echo ''; } echo $this->html_tail; } public function showAlbum($alb) { $alb = $this->dir . '/' . $this->sanitizePath(urldecode($alb)); $fotos = $this->getImages($alb); if(count($fotos) == 0) { $this->showGallery($alb); return; } ob_start(); ob_implicit_flush(true); $aname = $this->basepathname($alb); echo str_replace('{title}', $aname, $this->html_head); echo '
'; echo '

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

'; echo '
'; echo '
'.$this->lang('Navigation').': '; echo ''.$this->lang('Back to album selection').''; if ($this->enable_mass_download) { echo ' | '.$this->lang('Functions').': '; echo ''.$this->lang('Download selected images').' (0)'; echo ', '.$this->lang('toggle all').''; } echo '
'; $this->readLock($alb); if ($this->islocked && !$this->isAccessible()) { $this->showPassForm(); echo $this->html_tail; die(); } echo '
'; foreach($fotos as $f) { $bn = $this->basepathname($f); $middle = $this->getMiddleName($f); echo '
'; $ext = strtolower($this->getExt($f)); if($ext !== "mp4" && isset($this->func_avfileplay) && in_array($ext, $this->extsVideo)) { echo ''; } else if ($middle===$this->defaultIcon || file_exists($middle)) { if ($middle===$this->defaultIcon) { if (is_dir($f)) { if (file_exists($f.'/'.$this->lockfname)) { echo ''.$this->lang('locked').''; } echo ''; } else { echo ''; } } else { echo ''; } } else { echo ''; } if (is_dir($f)) { $thumb = $this->getThumbName($this->getAlbumTitleFile($f)); } else { $thumb = $this->getThumbName($f); } if ($thumb === $this->defaultIcon || $thumb === $this->defaultDirIcon || file_exists($thumb)) { echo ''.$bn.''; } else { echo ''.$bn.''; } echo ''; echo $this->getImageTitle($f); echo '
'; echo date($this->date_format, filemtime($f)); echo '
'.$this->lang('Detailed info').'
'; echo '
'.$this->lang('Download').'
'; if ($this->enable_mass_download) { echo '
'; } echo '
'; echo '
'."\n"; ob_flush(); } echo '
'; echo ''; echo ''; echo $this->html_tail; } public function showImage($f) { $f = $this->dir . '/' . $this->sanitizePath(urldecode($f)); $bn = $this->basepathname($f); $lf = substr($f, 0, -1*strlen($bn)).$this->lockfname; if (file_exists($lf)) { $this->islocked = true; $this->validusers = file($lf); foreach ($this->validusers as $key=>$value) { $this->validusers[$key] = trim($value); } } 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 '
'.$this->lang('Navigation').': '.$this->lang('Back to album thumbnails').'

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

'.$this->lang('File name').':

'; echo '

'.basename($bn).'

'; echo '

'.$this->lang('Links').':

'; echo ''.$this->lang('download full size').' ('.round(filesize($f)/(1024*1024),2).' MB)'; echo '
'; echo '
'; if (in_array($ext, $this->extsExif)) { $exif=exif_read_data($f); if ($this->show_exif_tab) { echo '
'; echo '
'; echo '
'.$exif['DateTimeOriginal'].'
'; echo '
'.round($exif['FileSize']/(1024*1024),2).' MB
'; echo '
'.$exif['COMPUTED']['Width'].'×'.$exif['COMPUTED']['Height'].' px
'; echo '
'.$exif['ExposureTime'].' s
'; echo '
'.$exif['ISOSpeedRatings'].'
'; echo '
'.$exif['COMPUTED']['ApertureFNumber'].'
'; echo '
'.$exif['FocalLength'].' mm
'; echo '
'.$exif['Orientation'].'
'; echo '
'.$exif['Model'].'
'; echo '
'; echo '
'; } if ($this->show_gps_tab) { echo '
'; echo '
'; if ($this->hasGPSData($exif)) { $gps = $this->getGPSLatLon($exif); $hgps = $this->getHumanGPS($gps[0], $gps[1]); echo '

'.$this->lang('Position').':

'; echo '

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

'; echo '

'.$this->lang('Links').':

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

'.$this->lang('Maps').':

'; echo '
'; echo '
'; echo '
'; echo '
'; echo '
'; echo '
'; echo '
'; echo '
'; echo '
'; echo '
'; echo '
'; } else { echo $this->lang('No GPS data.'); } echo '
'; echo '
'; } } else { if ($this->show_exif_tab) { echo '
'; echo $this->lang('No EXIF data.'); echo '
'; } if ($this->show_gps_tab) { echo '
'; echo $this->lang('No GPS data.'); echo '
'; } } echo '
'; echo '
'; echo $this->html_tail; } public function showVideo($f) { $f = $this->dir . '/' . urldecode($f); $f = $this->sanitizePath($f); if (isset($this->func_avfileplay) && $this->func_avfileplay !== NULL && is_callable($this->func_avfileplay)) { $group = call_user_func($this->func_avfileplay, $f); } header('Status: 404 Not Found'); } public function showPassForm() { ?>

This album is locked

Please tell me who are you…





galTitle, $this->html_head); echo '

'.$this->lang('Settings, info, credits and license').'

'; echo '
'; echo '

Settings

'; $this->switch_lang(); echo '
'; ?>

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 following projects:

Info:

Author: Martin Šlapák [aka: Gimli2]

History:

You can see it in changelog.txt in github repo: https://github.com/gimli2/sigal/

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.

'.$this->lang('Navigation').': '.$this->lang('Back to album selection').''; echo $this->html_tail; } private function sortItems($array, $callback_id) { $callback = $this->$callback_id; if (isset($callback) && $callback !== NULL && is_callable($callback)) { return call_user_func($callback, $array); } return $array; } public function getAlbums($top = NULL) { if ($top===NULL) $top = $this->dir; if (isset($this->func_getalbums) && $this->func_getalbums !== NULL && is_callable($this->func_getalbums)) { $files = call_user_func($this->func_getalbums, $top, $this->exts); return $this->sortItems($files, 'func_sortalbums'); } $files = glob($top.'/*'); foreach($files as $k => $v) { if (is_dir($v)) { $files[$k] = $v; } else { unset($files[$k]); } } $files = $this->sortItems($files, 'func_sortalbums'); return $files; } public function readLock($dir) { $abslockfname = $dir.'/'.$this->lockfname; $this->islocked = false; if (file_exists($abslockfname)) { $this->islocked = true; $this->validusers = file($abslockfname); foreach ($this->validusers as $key=>$val) { $this->validusers[$key] = trim($val); } } } public function getImages($dir) { $files = array(); if (isset($this->func_scandir) && $this->func_scandir !== NULL && is_callable($this->func_scandir)) { $files = call_user_func($this->func_scandir, $dir); } else { $r = glob($dir.'/*'); foreach($r as $file) { $ext = strtolower($this->getExt($file)); if (in_array($ext, $this->exts) || is_dir($file)) $files[] = $file; } } $files = $this->sortItems($files, 'func_sortimages'); return $files; } 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->defaultDirIcon; } public function downloadZippedImages() { $url = parse_url($_POST['imgalbum'],PHP_URL_QUERY); $archive = urlencode(substr($url, 1 + strpos($url, '='))); $imgs = array(); foreach ($_POST as $key=>$val) { if (preg_match('~img[0-9]{1,}~', $key)) { $imgs[] = $val; } } $zip = new ZipStream($archive.'.zip'); $zip->addDirectory($archive); foreach ($imgs as $file) { if (is_file($file)) { $zip->addLargeFile($file, $archive."/".basename($file), filectime($file)); } } $data = $this->lang('Downloaded').' '.date("Y-m-d H:i")." from ".$_POST['imgalbum']."\r\n--\r\n"; $data .= 'Simple gallery script SiGal: http://gimli2.gipix.net/sigal/ '."\r\n"; $zip->addFile($data, $archive."/readme.txt"); return $zip->finalize(); } public function makeThumbImage($file) { $f = $this->dir . '/' . $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); header('Content-type: image/jpeg'); die(); } header('Status: 404 Not Found'); die(); } public function makeMiddleImage($file) { $f = $this->dir . '/' . $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); $p = str_replace('..','',$p); $p = str_replace('*','',$p); $p = str_replace('://','',$p); return $p; } private function getExt($file) { return substr($file,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 getCacheDir($md5) { return $this->cache.'/'.substr($md5,0,1).'/'.substr($md5,1,1).'/'; } private function getMiddleName($file) { $ext = strtolower($this->getExt($file)); if (in_array($ext, $this->extsIcon) && !in_array($ext, $this->extsVideo)) { $md5 = MD5($file.$this->middle_x); $targetDir = $this->getCacheDir($md5); $targetImagePath = $targetDir.$md5.".jpg"; return $targetImagePath; } return $this->defaultIcon; } private function getThumbName($file) { if ($file === $this->defaultIcon) return $file; if ($file === $this->defaultDirIcon) return $file; $ext = strtolower($this->getExt($file)); if (in_array($ext, $this->extsIcon)) { $md5 = MD5($file.$this->thumb_x); $targetDir = $this->getCacheDir($md5); $targetImagePath = $targetDir.$md5.".jpg"; return $targetImagePath; } return $this->defaultIcon; } private function getImageTitle($file){ $bn = basename($file); $elipse = (strlen($bn) > $this->imgTitleLen) ? '…':''; return '

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

'; } private function getAlbumTitle($file){ $bn = $this->basepathname($file); if (isset($this->func_albumname) && $this->func_albumname !== NULL && is_callable($this->func_albumname)) { $title = call_user_func($this->func_albumname, $bn); } else { $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) ? '…':''; $title = substr($bn, 0, $this->imgTitleLen).$elipse; } return '

'.$title.'

'; } 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); if($exif['GPSLatitudeRef'] == 'S') { $gpslat = -$gpslat; } if($exif['GPSLongitudeRef'] == 'W') { $gpslon = -$gpslon; } 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->getCacheDir($md5); $targetImagePath = $targetDir.$md5.".jpg"; $targetImageTempPath = $targetDir.$md5."-tmp.jpg"; $outputImageQuality = 80; echo $targetDir; if (!file_exists($targetDir)) mkdir($targetDir, 0777, true); if(!file_exists($targetImagePath)) { $ext = strtolower($this->getExt($sourceImagePath)); if(isset($this->func_videoimage) && $this->func_videoimage !== NULL && is_callable($this->func_videoimage) && in_array($ext, $this->extsVideo)) { $group = call_user_func($this->func_videoimage, $path, $targetImageTempPath); $sourceImagePath = $targetImageTempPath; $ext = 'jpg'; } $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; } } 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; } if($sourceImagePath === $targetImageTempPath) { unlink($sourceImagePath); } $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; } function cookie($name, $value, $lifetime = 2592000) { $HTTPS = isset($_SERVER["HTTPS"]) && strcasecmp($_SERVER["HTTPS"], "off"); $params = array( $name, (preg_match("~\n~", $value) ? "" : $value), ($lifetime ? time() + $lifetime : 0), preg_replace('~\\?.*~', '', $_SERVER["REQUEST_URI"]), "", $HTTPS ); if (version_compare(PHP_VERSION, '5.2.0') >= 0) { $params[] = true; } return call_user_func_array('setcookie', $params); } function lang($idf, $number = null) { global $translations; $translations_lang = $translations[$this->LANG]; $translation = (isset($translations_lang[$idf]) ? $translations_lang[$idf] : $idf); if (is_array($translation)) { $pos = ($number == 1 ? 0 : ($this->LANG == 'cs' || $this->LANG == 'sk' ? ($number && $number < 5 ? 1 : 2) : ($this->LANG == 'fr' ? (!$number ? 0 : 1) : ($this->LANG == 'pl' ? ($number % 10 > 1 && $number % 10 < 5 && $number / 10 % 10 != 1 ? 1 : 2) : ($this->LANG == 'sl' ? ($number % 100 == 1 ? 0 : ($number % 100 == 2 ? 1 : ($number % 100 == 3 || $number % 100 == 4 ? 2 : 3))) : ($this->LANG == 'lt' ? ($number % 10 == 1 && $number % 100 != 11 ? 0 : ($number % 10 > 1 && $number / 10 % 10 != 1 ? 1 : 2)) : ($this->LANG == 'ru' || $this->LANG == 'sr' || $this->LANG == 'uk' ? ($number % 10 == 1 && $number % 100 != 11 ? 0 : ($number % 10 > 1 && $number % 10 < 5 && $number / 10 % 10 != 1 ? 1 : 2)) : 1 ))))))); $translation = $translation[$pos]; } $args = func_get_args(); array_shift($args); $format = str_replace("%d", "%s", $translation); if ($format != $translation) { $args[0] = $this->format_number($number); } return vsprintf($format, $args); } function format_number($val) { return strtr(number_format($val, 0, ".", $this->lang(',')), preg_split('~~u', $this->lang('0123456789'), -1, PREG_SPLIT_NO_EMPTY)); } function detect_lang() { $this->LANG = "en"; if (isset($_COOKIE["sigal_lang"]) && isset($this->langs[$_COOKIE["sigal_lang"]])) { $this->cookie("sigal_lang", $_COOKIE["sigal_lang"]); $this->LANG = $_COOKIE["sigal_lang"]; } else { $accept_language = array(); $browserLang = (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) ? $_SERVER["HTTP_ACCEPT_LANGUAGE"] : ''; preg_match_all('~([-a-z]+)(;q=([0-9.]+))?~', str_replace("_", "-", strtolower($browserLang)), $matches, PREG_SET_ORDER); foreach ($matches as $match) { $accept_language[$match[1]] = (isset($match[3]) ? $match[3] : 1); } arsort($accept_language); foreach ($accept_language as $key => $q) { if (isset($this->langs[$key])) { $this->LANG = $key; break; } $key = preg_replace('~-.*~', '', $key); if (!isset($accept_language[$key]) && isset($this->langs[$key])) { $this->LANG = $key; break; } } } return $this->LANG; } function switch_lang() { echo "
\n
"; echo $this->lang('Language') . ": " . html_select("lang", $this->langs, $this->LANG, "this.form.submit();"); echo " \n"; echo "
\n
\n"; } function remove_from_uri($param = "") { return substr(preg_replace("~(?<=[?&])($param" . (SID ? "" : "|" . session_name()) . ")=[^&]*&~", '', "$_SERVER[REQUEST_URI]&"), 0, -1); } } class ZipStream { const VERSION = 1.38; const ZIP_LOCAL_FILE_HEADER = "\x50\x4b\x03\x04"; const ZIP_CENTRAL_FILE_HEADER = "\x50\x4b\x01\x02"; const ZIP_END_OF_CENTRAL_DIRECTORY = "\x50\x4b\x05\x06\x00\x00\x00\x00"; const EXT_FILE_ATTR_DIR = "\x10\x00\xFF\x41"; const EXT_FILE_ATTR_FILE = "\x00\x00\xFF\x81"; const ATTR_VERSION_TO_EXTRACT = "\x14\x00"; const ATTR_MADE_BY_VERSION = "\x1E\x03"; private $zipMemoryThreshold = 1048576; private $zipComment = null; private $cdRec = array(); private $offset = 0; private $isFinalized = FALSE; private $addExtraField = TRUE; private $streamChunkSize = 16384; private $streamFilePath = null; private $streamTimeStamp = null; private $streamComment = null; private $streamFile = null; private $streamData = null; private $streamFileLength = 0; function __construct($archiveName = "", $contentType = "application/zip") { if (!function_exists('sys_get_temp_dir')) { die ("ERROR: ZipStream " . self::VERSION . " requires PHP version 5.2.1 or above."); } $headerFile = null; $headerLine = null; if (!headers_sent($headerFile, $headerLine) or die("

Error: Unable to send file $archiveName. HTML Headers have already been sent from $headerFile in line $headerLine

")) { if ((ob_get_contents() === FALSE || ob_get_contents() == '') or die("\n

Error: Unable to send file $archiveName.epub. Output buffer contains the following text (typically warnings or errors):
" . ob_get_contents() . "

")) { if (ini_get('zlib.output_compression')) { ini_set('zlib.output_compression', 'Off'); } header('Pragma: public'); header("Last-Modified: " . gmdate("D, d M Y H:i:s T")); header("Expires: 0"); header("Accept-Ranges: bytes"); header("Content-Type: " . $contentType); header('Content-Disposition: attachment; filename="' . $archiveName . '";'); header("Content-Transfer-Encoding: binary"); flush(); } } } function __destruct() { $this->isFinalized = TRUE; $this->cdRec = null; exit; } function setExtraField($setExtraField = TRUE) { $this->addExtraField = ($setExtraField === TRUE); } public function setComment($newComment = null) { if ($this->isFinalized) { return FALSE; } $this->zipComment = $newComment; return TRUE; } public function addDirectory($directoryPath, $timestamp = 0, $fileComment = null) { if ($this->isFinalized) { return FALSE; } $directoryPath = str_replace("\\", "/", $directoryPath); $directoryPath = rtrim($directoryPath, "/"); if (strlen($directoryPath) > 0) { $this->buildZipEntry($directoryPath.'/', $fileComment, "\x00\x00", "\x00\x00", $timestamp, "\x00\x00\x00\x00", 0, 0, self::EXT_FILE_ATTR_DIR); return TRUE; } return FALSE; } public function addFile($data, $filePath, $timestamp = 0, $fileComment = null, $compress = TRUE) { if ($this->isFinalized) { return FALSE; } if (is_resource($data) && get_resource_type($data) == "stream") { $this->addLargeFile($data, $filePath, $timestamp, $fileComment); return FALSE; } $gzData = ""; $gzType = "\x08\x00"; $gpFlags = "\x00\x00"; $dataLength = strlen($data); $fileCRC32 = pack("V", crc32($data)); if ($compress) { $gzTmp = gzcompress($data); $gzData = substr(substr($gzTmp, 0, strlen($gzTmp) - 4), 2); $gzLength = strlen($gzData); } else { $gzLength = $dataLength; } if ($gzLength >= $dataLength) { $gzLength = $dataLength; $gzData = $data; $gzType = "\x00\x00"; $gpFlags = "\x00\x00"; } $this->buildZipEntry($filePath, $fileComment, $gpFlags, $gzType, $timestamp, $fileCRC32, $gzLength, $dataLength, self::EXT_FILE_ATTR_FILE); print ($gzData); return TRUE; } public function addDirectoryContent($realPath, $zipPath, $recursive = TRUE, $followSymlinks = TRUE, &$addedFiles = array()) { if (file_exists($realPath) && !isset($addedFiles[realpath($realPath)])) { if (is_dir($realPath)) { $this->addDirectory($zipPath); } $addedFiles[realpath($realPath)] = $zipPath; $iter = new DirectoryIterator($realPath); foreach ($iter as $file) { if ($file->isDot()) { continue; } $newRealPath = $file->getPathname(); $newZipPath = self::pathJoin($zipPath, $file->getFilename()); if (file_exists($newRealPath) && ($followSymlinks === TRUE || !is_link($newRealPath))) { if ($file->isFile()) { $addedFiles[realpath($newRealPath)] = $newZipPath; $this->addLargeFile($newRealPath, $newZipPath); } else if ($recursive === TRUE) { $this->addDirectoryContent($newRealPath, $newZipPath, $recursive); } else { $this->addDirectory($zipPath); } } } } } public function addLargeFile($dataFile, $filePath, $timestamp = 0, $fileComment = null) { if ($this->isFinalized) { return FALSE; } if (is_string($dataFile) && is_file($dataFile)) { $this->processFile($dataFile, $filePath, $timestamp, $fileComment); } else if (is_resource($dataFile) && get_resource_type($dataFile) == "stream") { $fh = $dataFile; $this->openStream($filePath, $timestamp, $fileComment); while (!feof($fh)) { $this->addStreamData(fread($fh, $this->streamChunkSize)); } $this->closeStream($this->addExtraField); } return TRUE; } public function openStream($filePath, $timestamp = 0, $fileComment = null) { if (!function_exists('sys_get_temp_dir')) { die ("ERROR: Zip " . self::VERSION . " requires PHP version 5.2.1 or above if large files are used."); } if ($this->isFinalized) { return FALSE; } if (strlen($this->streamFilePath) > 0) { closeStream(); } $this->streamFile = tempnam(sys_get_temp_dir(), 'ZipStream'); $this->streamData = fopen($this->streamFile, "wb"); $this->streamFilePath = $filePath; $this->streamTimestamp = $timestamp; $this->streamFileComment = $fileComment; $this->streamFileLength = 0; return TRUE; } public function addStreamData($data) { if ($this->isFinalized || strlen($this->streamFilePath) == 0) { return FALSE; } $length = fwrite($this->streamData, $data, strlen($data)); if ($length != strlen($data)) { die ("

Length mismatch

\n"); } $this->streamFileLength += $length; return $length; } public function closeStream() { if ($this->isFinalized || strlen($this->streamFilePath) == 0) { return FALSE; } fflush($this->streamData); fclose($this->streamData); $this->processFile($this->streamFile, $this->streamFilePath, $this->streamTimestamp, $this->streamFileComment); $this->streamData = null; $this->streamFilePath = null; $this->streamTimestamp = null; $this->streamFileComment = null; $this->streamFileLength = 0; unlink($this->streamFile); $this->streamFile = null; return TRUE; } private function processFile($dataFile, $filePath, $timestamp = 0, $fileComment = null) { if ($this->isFinalized) { return FALSE; } $tempzip = tempnam(sys_get_temp_dir(), 'ZipStream'); $zip = new ZipArchive; if ($zip->open($tempzip) === TRUE) { $zip->addFile($dataFile, 'file'); $zip->close(); } $file_handle = fopen($tempzip, "rb"); $stats = fstat($file_handle); $eof = $stats['size']-72; fseek($file_handle, 6); $gpFlags = fread($file_handle, 2); $gzType = fread($file_handle, 2); fread($file_handle, 4); $fileCRC32 = fread($file_handle, 4); $v = unpack("Vval", fread($file_handle, 4)); $gzLength = $v['val']; $v = unpack("Vval", fread($file_handle, 4)); $dataLength = $v['val']; $this->buildZipEntry($filePath, $fileComment, $gpFlags, $gzType, $timestamp, $fileCRC32, $gzLength, $dataLength, self::EXT_FILE_ATTR_FILE); fseek($file_handle, 34); $pos = 34; while (!feof($file_handle) && $pos < $eof) { $datalen = $this->streamChunkSize; if ($pos + $this->streamChunkSize > $eof) { $datalen = $eof-$pos; } echo fread($file_handle, $datalen); $pos += $datalen; flush(); } fclose($file_handle); unlink($tempzip); } public function finalize() { if (!$this->isFinalized) { if (strlen($this->streamFilePath) > 0) { $this->closeStream(); } $cdRecSize = pack("v", sizeof($this->cdRec)); $cd = implode("", $this->cdRec); print($cd); print(self::ZIP_END_OF_CENTRAL_DIRECTORY); print($cdRecSize.$cdRecSize); print(pack("VV", strlen($cd), $this->offset)); if (!empty($this->zipComment)) { print(pack("v", strlen($this->zipComment))); print($this->zipComment); } else { print("\x00\x00"); } flush(); $this->isFinalized = TRUE; $cd = null; $this->cdRec = null; return TRUE; } return FALSE; } private function getDosTime($timestamp = 0) { $timestamp = (int)$timestamp; $oldTZ = @date_default_timezone_get(); date_default_timezone_set('UTC'); $date = ($timestamp == 0 ? getdate() : getdate($timestamp)); date_default_timezone_set($oldTZ); if ($date["year"] >= 1980) { return pack("V", (($date["mday"] + ($date["mon"] << 5) + (($date["year"]-1980) << 9)) << 16) | (($date["seconds"] >> 1) + ($date["minutes"] << 5) + ($date["hours"] << 11))); } return "\x00\x00\x00\x00"; } private function buildZipEntry($filePath, $fileComment, $gpFlags, $gzType, $timestamp, $fileCRC32, $gzLength, $dataLength, $extFileAttr) { $filePath = str_replace("\\", "/", $filePath); $fileCommentLength = (empty($fileComment) ? 0 : strlen($fileComment)); $timestamp = (int)$timestamp; $timestamp = ($timestamp == 0 ? time() : $timestamp); $dosTime = $this->getDosTime($timestamp); $tsPack = pack("V", $timestamp); $ux = "\x75\x78\x0B\x00\x01\x04\xE8\x03\x00\x00\x04\x00\x00\x00\x00"; if (!isset($gpFlags) || strlen($gpFlags) != 2) { $gpFlags = "\x00\x00"; } $isFileUTF8 = mb_check_encoding($filePath, "UTF-8") && !mb_check_encoding($filePath, "ASCII"); $isCommentUTF8 = !empty($fileComment) && mb_check_encoding($fileComment, "UTF-8") && !mb_check_encoding($fileComment, "ASCII"); if ($isFileUTF8 || $isCommentUTF8) { $flag = 0; $gpFlagsV = unpack("vflags", $gpFlags); if (isset($gpFlagsV['flags'])) { $flag = $gpFlagsV['flags']; } $gpFlags = pack("v", $flag | (1 << 11)); } $header = $gpFlags . $gzType . $dosTime. $fileCRC32 . pack("VVv", $gzLength, $dataLength, strlen($filePath)); $zipEntry = self::ZIP_LOCAL_FILE_HEADER; $zipEntry .= self::ATTR_VERSION_TO_EXTRACT; $zipEntry .= $header; $zipEntry .= $this->addExtraField ? "\x1C\x00" : "\x00\x00"; $zipEntry .= $filePath; if ($this->addExtraField) { $zipEntry .= "\x55\x54\x09\x00\x03" . $tsPack . $tsPack . $ux; } print($zipEntry); $cdEntry = self::ZIP_CENTRAL_FILE_HEADER; $cdEntry .= self::ATTR_MADE_BY_VERSION; $cdEntry .= ($dataLength === 0 ? "\x0A\x00" : self::ATTR_VERSION_TO_EXTRACT); $cdEntry .= $header; $cdEntry .= $this->addExtraField ? "\x18\x00" : "\x00\x00"; $cdEntry .= pack("v", $fileCommentLength); $cdEntry .= "\x00\x00"; $cdEntry .= "\x00\x00"; $cdEntry .= $extFileAttr; $cdEntry .= pack("V", $this->offset); $cdEntry .= $filePath; if ($this->addExtraField) { $cdEntry .= "\x55\x54\x05\x00\x03" . $tsPack . $ux; } if (!empty($fileComment)) { $cdEntry .= $fileComment; } $this->cdRec[] = $cdEntry; $this->offset += strlen($zipEntry) + $gzLength; } public static function pathJoin($dir, $file) { if (empty($dir) || empty($file)) { return self::getRelativePath($dir . $file); } return self::getRelativePath($dir . '/' . $file); } public static function getRelativePath($path) { $path = preg_replace("#/+\.?/+#", "/", str_replace("\\", "/", $path)); $dirs = explode("/", rtrim(preg_replace('#^(?:\./)+#', '', $path), '/')); $offset = 0; $sub = 0; $subOffset = 0; $root = ""; if (empty($dirs[0])) { $root = "/"; $dirs = array_splice($dirs, 1); } else if (preg_match("#[A-Za-z]:#", $dirs[0])) { $root = strtoupper($dirs[0]) . "/"; $dirs = array_splice($dirs, 1); } $newDirs = array(); foreach ($dirs as $dir) { if ($dir !== "..") { $subOffset--; $newDirs[++$offset] = $dir; } else { $subOffset++; if (--$offset < 0) { $offset = 0; if ($subOffset > $sub) { $sub++; } } } } if (empty($root)) { $root = str_repeat("../", $sub); } return $root . implode("/", array_slice($newDirs, 0, $offset)); } } function h($string) { return str_replace("\0", "�", htmlspecialchars($string, ENT_QUOTES, 'utf-8')); } function html_select($name, $options, $value = "", $onchange = true) { if ($onchange) { return ""; } $return = ""; foreach ($options as $key => $val) { $return .= ""; } return $return; } function optionlist($options, $selected = null, $use_keys = false) { $return = ""; foreach ($options as $k => $v) { $opts = array($k => $v); if (is_array($v)) { $return .= ''; $opts = $v; } foreach ($opts as $key => $val) { $return .= '' . h($val); } if (is_array($v)) { $return .= ''; } } return $return; } foreach (glob('lang/*.lang.php') as $filename) { include $filename; } $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', 'date_format', 'enable_mass_download', 'show_exif_tab', 'show_gps_tab', 'func_sortimages', 'func_sortalbums', 'func_scandir', 'func_albumname', 'func_groupname', 'func_getalbums', 'func_videoimage', 'func_avfileplay' ); foreach ($kws as $item) { if (isset($conf[$item])) $gg->$item = $conf[$item]; } if(isset($gg->func_videoimage) && $gg->func_videoimage!=='') { $gg->extsIcon = array_merge($gg->extsIcon, $gg->extsVideo); } if (isset($_POST["lang"])) { $gg->cookie("sigal_lang", $_POST["lang"]); $loc = $gg->remove_from_uri(); $loc = ($loc !== '') ? $loc : '.'; header("Location: ".$loc); die(); } if (isset($_GET['credits'])) { $gg->showCreditPage(); die(); } if (isset($_GET['dlselected'])) { $gg->downloadZippedImages(); } 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']) && $_GET['alb']!=='') { session_start(); if (isset($_POST['fakce']) && $_POST['fakce']==='addaccess') $gg->addAccess(); $gg->showAlbum($_GET['alb']); die(); } if (isset($_GET['avfile'])) { $gg->showVideo($_GET['avfile']); die(); } if (isset($_GET['static'])) { header('Location: index.min.php?static='.$_GET['static']); } $gg->showGallery();