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/>.
23 $plugins = scandir("plugins");
24 array_shift($plugins); array_shift($plugins); // remove . and ..
25 foreach ($plugins as $p) if (is_file("plugins/$p/functions.php"))
26 require "plugins/$p/functions.php";
28 if (! function_exists('getThumbTarget')) {
29 function getThumbTarget($imageSimplePath)
31 return dirname($_SERVER["SCRIPT_NAME"]).'/'.IMAGES_DIR.$imageSimplePath;
35 function getPreview($imgFile, $maxSize = THUMB_SIZE)
37 # example: data/myalbum/100.mypic.jpg
38 $newImgFile = DATA_DIR."/".dirname($imgFile)."/".$maxSize.".".basename($imgFile);
40 if (! is_file($newImgFile))
42 $ext = strtolower(substr($imgFile, -4));
44 $img = imagecreatefromjpeg($imgFile);
46 $img = imagecreatefrompng($imgFile);
50 # don't do anything if the image is already small
51 if ($w <= $maxSize and $h <= $maxSize) {
56 # create the thumbs directory recursively
57 if (! is_dir(dirname($newImgFile))) mkdir(dirname($newImgFile), 0777, true);
61 $newH = $h/($w/$maxSize);
63 $newW = $w/($h/$maxSize);
67 $newImg = imagecreatetruecolor($newW, $newH);
69 imagecopyresampled($newImg, $img, 0, 0, 0, 0, $newW, $newH, $w, $h);
72 imagejpeg($newImg, $newImgFile);
74 imagepng($newImg, $newImgFile);
77 imagedestroy($newImg);
80 return dirname($_SERVER["SCRIPT_NAME"])."/".$newImgFile;
83 function getAlbumPreview($dir)
85 foreach (scandir($dir) as $file) if ($file != '.' and $file != '..') {
86 $ext = strtolower(substr($file, -4));
87 if ($ext == ".jpg" or $ext == ".png")
88 return getPreview("$dir/$file");
94 $scriptUrlPath = $_SERVER["SCRIPT_NAME"];
96 // if url == http://localhost/photos/index.php/toto/titi, path_info == /toto/titi
97 // if url == http://localhost/photos/index.php, path_info is not set
98 // if url == http://localhost/photos/, path_info is not set
99 // if path_info is not set, we are at top level, so we redirect to /photos/index.php/
100 if (! isset($_SERVER["PATH_INFO"])) {
101 header("Location: $scriptUrlPath/");
105 # shortPath is the simple path to the image
106 # /index.php/toto/titi => shortPath == /toto/titi
107 $shortPath = $_SERVER["PATH_INFO"];
108 if ($shortPath == '/') $shortPath = '';
109 // extra security check to avoid /photos/index/../.. like urls, maybe useless but..
110 if (strpos($shortPath, '..') !== false) die(".. found in url");
113 $imageFiles = array();
114 $otherFiles = array();
116 # realDir is the directory in filesystem
117 # seen from current script directory
118 $realDir = IMAGES_DIR.$shortPath;
120 if (! is_dir($realDir)) {
121 header("HTTP/1.1 404 Not Found");
122 die("Directory Not Found");
125 foreach (scandir($realDir) as $file) if ($file != '.' and $file != '..')
127 if (is_dir("$realDir/$file"))
129 $folders[] = array( "name" => $file, "link" => "$scriptUrlPath$shortPath/$file", "preview" => getAlbumPreview("$realDir/$file") );
133 $ext = strtolower(substr($file, -4));
134 if ($ext == ".jpg" or $ext == ".png") {
135 $link = dirname($scriptUrlPath)."/$realDir/$file";
136 $link = getThumbTarget("$shortPath/$file");
138 $imageFiles[] = array( "name" => $file, "url" => getPreview("$realDir/$file"), "link" => $link );
141 $otherFiles[] = array( "name" => $file, "link" => dirname($scriptUrlPath)."/$realDir/$file" );
146 if (dirname($shortPath) !== '')
147 $parentLink = $scriptUrlPath.dirname($shortPath);
153 ///// template starts here /////
154 header('Content-Type: text/html; charset=utf-8');
155 header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + 3600));
159 <style type="text/css">
167 text-decoration: none;
170 display: inline-block;
173 width: <?php echo THUMB_SIZE ?>px;
174 height: <?php echo THUMB_SIZE ?>px;
177 vertical-align: middle;
180 height: <?php echo THUMB_SIZE ?>px;
182 vertical-align: middle;
192 <?php foreach ($plugins as $p) if (is_file("plugins/$p/style.css")) { ?>
193 <link rel="stylesheet" type="text/css" href="<?php echo dirname($scriptUrlPath)."/plugins/$p/style.css" ?>" />
198 <?php if ($parentLink !== '') { ?>
199 <div id="parentfolder"><a href="<?php echo $parentLink ?>">^</a></div>
202 <?php foreach($folders as $folder) { ?>
204 <?php if ($folder["preview"] === "") { ?>
205 <a href="<?php echo $folder["link"] ?>"><?php echo $folder["name"] ?></a>
207 <div class="square"><div class="image"><a href="<?php echo $folder["link"] ?>"><img src="<?php echo $folder["preview"] ?>" /></a></div></div>
208 <div class="square"><div class="foldername"><a href="<?php echo $folder["link"] ?>"><?php echo $folder["name"] ?></a></div></div>
213 <?php foreach ($imageFiles as $file) { ?>
214 <div class="square"><div class="image"><a href="<?php echo $file["link"] ?>"><img src="<?php echo $file["url"] ?>" alt="<?php echo $file["name"] ?>" /></a></div></div>
217 <?php foreach ($otherFiles as $file) { ?>
218 <div class="miscfile"><a href="<?php echo $file["link"] ?>"><?php echo $file["name"] ?></a></div>