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 # uncomment this if you need group writable files
75 # create the thumbs directory recursively
76 if (! is_dir(dirname($newImgFile))) mkdir(dirname($newImgFile), 0777, true);
80 $newH = $h/($w/$maxSize);
82 $newW = $w/($h/$maxSize);
86 $newImg = imagecreatetruecolor($newW, $newH);
88 imagecopyresampled($newImg, $img, 0, 0, 0, 0, $newW, $newH, $w, $h);
91 imagejpeg($newImg, $newImgFile);
93 imagepng($newImg, $newImgFile);
96 imagedestroy($newImg);
99 return $GLOBALS['rootUrl'].$newImgFile;
102 function getAlbumPreview($dir)
104 foreach (scandir($dir) as $file) if ($file != '.' and $file != '..') {
105 $ext = strtolower(substr($file, -4));
106 if ($ext == ".jpg" or $ext == ".png")
107 return getPreview("$dir/$file");
113 // if url == http://localhost/photos/index.php/toto/titi, path_info == /toto/titi
114 // if url == http://localhost/photos/index.php, path_info is not set
115 // if url == http://localhost/photos/, path_info is not set
116 // if path_info is not set, we are at top level, so we redirect to /photos/index.php/
117 if (! isset($_SERVER["PATH_INFO"])) {
118 header("Location: $scriptUrl/");
122 # simplePath is the simple path to the image
123 # /index.php/toto/titi => simplePath == /toto/titi
124 $simplePath = $_SERVER["PATH_INFO"];
125 if ($simplePath == '/') $simplePath = '';
126 // extra security check to avoid /photos/index/../.. like urls, maybe useless but..
127 if (strpos($simplePath, '..') !== false) die(".. found in url");
130 $imageFiles = array();
131 $otherFiles = array();
133 # realDir is the directory in filesystem
134 # seen from current script directory
135 $realDir = IMAGES_DIR.$simplePath;
137 if (! is_dir($realDir)) {
138 header("HTTP/1.1 404 Not Found");
139 die("Directory Not Found");
142 foreach (scandir($realDir) as $file) if ($file != '.' and $file != '..')
144 if (is_dir("$realDir/$file"))
146 $folders[] = array( "name" => $file, "link" => "$scriptUrl$simplePath/$file", "preview" => getAlbumPreview("$realDir/$file") );
150 $ext = strtolower(substr($file, -4));
151 if ($ext == ".jpg" or $ext == ".png") {
152 $imageFiles[] = array( "name" => $file, "url" => getPreview("$realDir/$file"), "link" => getImageLink("$simplePath/$file") );
154 $otherFiles[] = array( "name" => $file, "link" => "$rootUrl$realDir/$file" );
159 if (dirname($simplePath) !== '')
160 $parentLink = $scriptUrl.dirname($simplePath);
166 ///// template starts here /////
167 header('Content-Type: text/html; charset=utf-8');
168 header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + 3600));
172 <title> <?php echo $realDir ?> </title>
173 <style type="text/css">
176 font-family: sans-serif;
182 text-decoration: none;
185 display: inline-block;
187 .image, .foldername, .image_nopreview, .foldername_nopreview {
189 vertical-align: middle;
191 .image, .image_nopreview {
192 width: <?php echo THUMB_SIZE ?>px;
195 .image, .foldername {
196 height: <?php echo THUMB_SIZE ?>px;
198 .foldername, .foldername_nopreview {
212 <?php foreach ($plugins as $p) if (is_file("plugins/$p/style.css")) { ?>
213 <link rel="stylesheet" type="text/css" href="<?php echo $rootUrl."plugins/$p/style.css" ?>" />
218 <div id="parentfolder"><a href="<?php echo $parentLink ?>">
219 <?php if ($parentLink !== '') { ?>
224 <?php plugins_include("before_content.php") ?>
226 <?php foreach($folders as $folder) { ?>
228 <?php if ($folder["preview"] === "") { ?>
229 <div class="square"><div class="image_nopreview"> - </div></div>
230 <div class="square"><div class="foldername_nopreview"> <a href="<?php echo $folder["link"] ?>"><?php echo $folder["name"] ?></a> </div></div>
232 <div class="square"><div class="image"> <a href="<?php echo $folder["link"] ?>"><img src="<?php echo $folder["preview"] ?>" /></a> </div></div>
233 <div class="square"><div class="foldername"> <a href="<?php echo $folder["link"] ?>"><?php echo $folder["name"] ?></a> </div></div>
238 <?php foreach ($imageFiles as $file) { ?>
239 <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>
242 <?php foreach ($otherFiles as $file) { ?>
243 <div class="miscfile"><a href="<?php echo $file["link"] ?>"><?php echo $file["name"] ?></a></div>
247 Generated by <a href="http://www.positon.org/bizou/">Bizou</a>