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 function getPreview($imgFile, $maxSize = THUMB_SIZE)
53 # example: data/myalbum/100.mypic.jpg
54 $newImgFile = DATA_DIR."/".dirname($imgFile)."/".$maxSize.".".basename($imgFile);
56 # if the preview is a symlink, image is already good sized
57 if (is_link($newImgFile)) return $imgFile;
59 if (! is_file($newImgFile))
61 # this tels the template to flush output after displaying previews
62 $GLOBALS["generating"] = true;
64 # reset script time limit to 20s (wont work in safe mode)
67 $ext = strtolower(substr($imgFile, -4));
69 $img = imagecreatefromjpeg($imgFile);
71 $img = imagecreatefrompng($imgFile);
75 # if the image is already small, make a symlink, and return it
76 if ($w <= $maxSize and $h <= $maxSize) {
78 symlink($imgFile, $newImgFile);
82 # uncomment this if you need group writable files
84 # create the thumbs directory recursively
85 if (! is_dir(dirname($newImgFile))) mkdir(dirname($newImgFile), 0777, true);
89 $newH = $h/($w/$maxSize);
91 $newW = $w/($h/$maxSize);
95 $newImg = imagecreatetruecolor($newW, $newH);
97 imagecopyresampled($newImg, $img, 0, 0, 0, 0, $newW, $newH, $w, $h);
100 imagejpeg($newImg, $newImgFile);
102 imagepng($newImg, $newImgFile);
105 imagedestroy($newImg);
111 function getAlbumPreview($dir)
113 $previewFile = DATA_DIR."/$dir/albumpreview";
115 if (is_file("$previewFile.jpg")) {
116 return "$previewFile.jpg";
117 } else if (is_file("$previewFile.empty")) {
119 } else if (is_file("$previewFile.png")) {
120 return "$previewFile.png";
122 # uncomment this if you need group writable files
124 # create the thumbs directory recursively
125 if (! is_dir(dirname($previewFile))) mkdir(dirname($previewFile), 0777, true);
127 // no preview: look for a preview in current dir, write it, return it
128 foreach (scandir($dir) as $file) if ($file != '.' and $file != '..') {
129 $ext = strtolower(substr($file, -4));
130 if ($ext == ".jpg" or $ext == ".png") {
131 $thumb = getPreview("$dir/$file");
132 copy($thumb, $previewFile.$ext);
133 return $previewFile.$ext;
134 } else if (is_dir("$dir/$file")) {
135 $subPreview = getAlbumPreview("$dir/$file");
137 $myPreview = dirname($previewFile)."/".basename($subPreview);
138 copy($subPreview, $myPreview);
144 // nothing found. create empty file
145 touch("$previewFile.empty");
150 // if url == http://localhost/photos/index.php/toto/titi, path_info == /toto/titi
151 // if url == http://localhost/photos/index.php, path_info is not set
152 // if url == http://localhost/photos/, path_info is not set
153 // if path_info is not set, we are at top level, so we redirect to /photos/index.php/
154 if (! isset($_SERVER["PATH_INFO"])) {
155 header("Location: $scriptUrl/");
159 # simplePath is the simple path to the image
160 # /index.php/toto/titi => simplePath == /toto/titi
161 $simplePath = $_SERVER["PATH_INFO"];
162 if ($simplePath == '/') $simplePath = '';
163 // extra security check to avoid /photos/index/../.. like urls, maybe useless but..
164 if (strpos($simplePath, '..') !== false) die(".. found in url");
167 $imageFiles = array();
168 $otherFiles = array();
170 # realDir is the directory in filesystem
171 # seen from current script directory
172 $realDir = IMAGES_DIR.$simplePath;
174 if (! is_dir($realDir)) {
175 header("HTTP/1.1 404 Not Found");
176 die("Directory Not Found");
179 foreach (scandir($realDir) as $file) if ($file != '.' and $file != '..')
181 if (is_dir("$realDir/$file"))
183 $folders[] = array( "name" => $file, "file" => "$realDir/$file", "link" => "$scriptUrl$simplePath/$file" );
187 $ext = strtolower(substr($file, -4));
188 if ($ext == ".jpg" or $ext == ".png") {
189 $imageFiles[] = array( "name" => $file, "file" => "$realDir/$file", "link" => getImageLink("$simplePath/$file") );
191 $otherFiles[] = array( "name" => $file, "link" => "$rootUrl$realDir/$file" );
196 if (dirname($simplePath) !== '')
197 $parentLink = $scriptUrl.dirname($simplePath);
201 ///// template starts here /////
202 header('Content-Type: text/html; charset=utf-8');
203 header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + 3600));
205 require 'template.php';