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 (! is_file($newImgFile))
58 $ext = strtolower(substr($imgFile, -4));
60 $img = imagecreatefromjpeg($imgFile);
62 $img = imagecreatefrompng($imgFile);
66 # don't do anything if the image is already small
67 if ($w <= $maxSize and $h <= $maxSize) {
72 # create the thumbs directory recursively
73 if (! is_dir(dirname($newImgFile))) mkdir(dirname($newImgFile), 0777, true);
77 $newH = $h/($w/$maxSize);
79 $newW = $w/($h/$maxSize);
83 $newImg = imagecreatetruecolor($newW, $newH);
85 imagecopyresampled($newImg, $img, 0, 0, 0, 0, $newW, $newH, $w, $h);
88 imagejpeg($newImg, $newImgFile);
90 imagepng($newImg, $newImgFile);
93 imagedestroy($newImg);
96 return $GLOBALS['rootUrl'].$newImgFile;
99 function getAlbumPreview($dir)
101 foreach (scandir($dir) as $file) if ($file != '.' and $file != '..') {
102 $ext = strtolower(substr($file, -4));
103 if ($ext == ".jpg" or $ext == ".png")
104 return getPreview("$dir/$file");
110 // if url == http://localhost/photos/index.php/toto/titi, path_info == /toto/titi
111 // if url == http://localhost/photos/index.php, path_info is not set
112 // if url == http://localhost/photos/, path_info is not set
113 // if path_info is not set, we are at top level, so we redirect to /photos/index.php/
114 if (! isset($_SERVER["PATH_INFO"])) {
115 header("Location: $scriptUrl/");
119 # simplePath is the simple path to the image
120 # /index.php/toto/titi => simplePath == /toto/titi
121 $simplePath = $_SERVER["PATH_INFO"];
122 if ($simplePath == '/') $simplePath = '';
123 // extra security check to avoid /photos/index/../.. like urls, maybe useless but..
124 if (strpos($simplePath, '..') !== false) die(".. found in url");
127 $imageFiles = array();
128 $otherFiles = array();
130 # realDir is the directory in filesystem
131 # seen from current script directory
132 $realDir = IMAGES_DIR.$simplePath;
134 if (! is_dir($realDir)) {
135 header("HTTP/1.1 404 Not Found");
136 die("Directory Not Found");
139 foreach (scandir($realDir) as $file) if ($file != '.' and $file != '..')
141 if (is_dir("$realDir/$file"))
143 $folders[] = array( "name" => $file, "link" => "$scriptUrl$simplePath/$file", "preview" => getAlbumPreview("$realDir/$file") );
147 $ext = strtolower(substr($file, -4));
148 if ($ext == ".jpg" or $ext == ".png") {
149 $imageFiles[] = array( "name" => $file, "url" => getPreview("$realDir/$file"), "link" => getImageLink("$simplePath/$file") );
151 $otherFiles[] = array( "name" => $file, "link" => "$rootUrl$realDir/$file" );
156 if (dirname($simplePath) !== '')
157 $parentLink = $scriptUrl.dirname($simplePath);
163 ///// template starts here /////
164 header('Content-Type: text/html; charset=utf-8');
165 header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + 3600));
169 <title> <?php echo $realDir ?> </title>
170 <style type="text/css">
173 font-family: sans-serif;
179 text-decoration: none;
182 display: inline-block;
184 .image, .foldername, .image_nopreview, .foldername_nopreview {
186 vertical-align: middle;
188 .image, .image_nopreview {
189 width: <?php echo THUMB_SIZE ?>px;
192 .image, .foldername {
193 height: <?php echo THUMB_SIZE ?>px;
195 .foldername, .foldername_nopreview {
209 <?php foreach ($plugins as $p) if (is_file("plugins/$p/style.css")) { ?>
210 <link rel="stylesheet" type="text/css" href="<?php echo $rootUrl."plugins/$p/style.css" ?>" />
215 <div id="parentfolder"><a href="<?php echo $parentLink ?>">
216 <?php if ($parentLink !== '') { ?>
221 <?php plugins_include("before_content.php") ?>
223 <?php foreach($folders as $folder) { ?>
225 <?php if ($folder["preview"] === "") { ?>
226 <div class="square"><div class="image_nopreview"> - </div></div>
227 <div class="square"><div class="foldername_nopreview"> <a href="<?php echo $folder["link"] ?>"><?php echo $folder["name"] ?></a> </div></div>
229 <div class="square"><div class="image"> <a href="<?php echo $folder["link"] ?>"><img src="<?php echo $folder["preview"] ?>" /></a> </div></div>
230 <div class="square"><div class="foldername"> <a href="<?php echo $folder["link"] ?>"><?php echo $folder["name"] ?></a> </div></div>
235 <?php foreach ($imageFiles as $file) { ?>
236 <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>
239 <?php foreach ($otherFiles as $file) { ?>
240 <div class="miscfile"><a href="<?php echo $file["link"] ?>"><?php echo $file["name"] ?></a></div>
244 Generated by <a href="http://www.positon.org/bizou/">Bizou</a>