3 Bizou - a (french) KISS php image gallery
4 Copyright (C) 2010 Marc MAURICE
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 // global variables, globals should remain contant
23 $scriptUrl = $_SERVER["SCRIPT_NAME"];
24 $rootUrl = dirname($scriptUrl);
25 if (substr($rootUrl, -1) !== '/') $rootUrl.='/'; // add a trailing / to rootUrl
26 // $scriptUrl = "/path/to/bizou/index.php"
27 // $rootUrl = "/path/to/bizou/"
31 if (is_dir("plugins")) {
32 $plugins = scandir("plugins");
33 array_shift($plugins); array_shift($plugins); // remove . and ..
34 foreach ($plugins as $p) if (is_file("plugins/$p/functions.php"))
35 require "plugins/$p/functions.php";
38 function plugins_include($phpFile)
40 foreach ($GLOBALS['plugins'] as $p) if (is_file("plugins/$p/$phpFile"))
41 require "plugins/$p/$phpFile";
44 if (! function_exists('getImageLink')) {
45 function getImageLink($imageSimplePath)
47 return $GLOBALS['rootUrl'].IMAGES_DIR.$imageSimplePath;
51 // functions to display a "progress page" when thumbs are generating
52 function beginGenerating ()
54 if (! isset($GLOBALS["generating"])) {
55 echo "<p> <i><b>If you get: \"Fatal error: Maximum execution time exceeded\", refresh this page.</b></i><br/> Please wait while generating thumbnails:<p/>\n";
57 $GLOBALS["generating"] = true;
60 function displayGenerated($thumbFile)
62 if (isset($GLOBALS["generating"])) {
63 echo basename($thumbFile)."\n";
67 function endGenerating() {
68 if (isset($GLOBALS["generating"])) {
69 echo "<p>Finished. This page will be refreshed.</p> <script>window.location.reload();</script>\n";
74 function getPreview($imgFile, $maxSize = THUMB_SIZE)
76 # example: data/myalbum/100.mypic.jpg
77 $newImgFile = DATA_DIR."/".dirname($imgFile)."/".$maxSize.".".basename($imgFile);
79 if (! is_file($newImgFile))
83 # reset script time limit to 20s (wont work in safe mode)
86 $ext = strtolower(substr($imgFile, -4));
88 $img = imagecreatefromjpeg($imgFile);
90 $img = imagecreatefrompng($imgFile);
94 # don't do anything if the image is already small
95 if ($w <= $maxSize and $h <= $maxSize) {
100 # uncomment this if you need group writable files
103 # create the thumbs directory recursively
104 if (! is_dir(dirname($newImgFile))) mkdir(dirname($newImgFile), 0777, true);
108 $newH = $h/($w/$maxSize);
110 $newW = $w/($h/$maxSize);
114 $newImg = imagecreatetruecolor($newW, $newH);
116 imagecopyresampled($newImg, $img, 0, 0, 0, 0, $newW, $newH, $w, $h);
119 imagejpeg($newImg, $newImgFile);
121 imagepng($newImg, $newImgFile);
124 imagedestroy($newImg);
126 displayGenerated($newImgFile);
129 return $GLOBALS['rootUrl'].$newImgFile;
132 function getAlbumPreview($dir)
134 foreach (scandir($dir) as $file) if ($file != '.' and $file != '..') {
135 $ext = strtolower(substr($file, -4));
136 if ($ext == ".jpg" or $ext == ".png")
137 return getPreview("$dir/$file");
143 // if url == http://localhost/photos/index.php/toto/titi, path_info == /toto/titi
144 // if url == http://localhost/photos/index.php, path_info is not set
145 // if url == http://localhost/photos/, path_info is not set
146 // if path_info is not set, we are at top level, so we redirect to /photos/index.php/
147 if (! isset($_SERVER["PATH_INFO"])) {
148 header("Location: $scriptUrl/");
152 # simplePath is the simple path to the image
153 # /index.php/toto/titi => simplePath == /toto/titi
154 $simplePath = $_SERVER["PATH_INFO"];
155 if ($simplePath == '/') $simplePath = '';
156 // extra security check to avoid /photos/index/../.. like urls, maybe useless but..
157 if (strpos($simplePath, '..') !== false) die(".. found in url");
160 $imageFiles = array();
161 $otherFiles = array();
163 # realDir is the directory in filesystem
164 # seen from current script directory
165 $realDir = IMAGES_DIR.$simplePath;
167 if (! is_dir($realDir)) {
168 header("HTTP/1.1 404 Not Found");
169 die("Directory Not Found");
172 foreach (scandir($realDir) as $file) if ($file != '.' and $file != '..')
174 if (is_dir("$realDir/$file"))
176 $folders[] = array( "name" => $file, "link" => "$scriptUrl$simplePath/$file", "preview" => getAlbumPreview("$realDir/$file") );
180 $ext = strtolower(substr($file, -4));
181 if ($ext == ".jpg" or $ext == ".png") {
182 $imageFiles[] = array( "name" => $file, "url" => getPreview("$realDir/$file"), "link" => getImageLink("$simplePath/$file") );
184 $otherFiles[] = array( "name" => $file, "link" => "$rootUrl$realDir/$file" );
191 if (dirname($simplePath) !== '')
192 $parentLink = $scriptUrl.dirname($simplePath);
196 ///// template starts here /////
197 header('Content-Type: text/html; charset=utf-8');
198 header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + 3600));
200 require 'template.php';