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 function plugins_include($phpFile)
30 foreach ($GLOBALS['plugins'] as $p) if (is_file("plugins/$p/$phpFile"))
31 require "plugins/$p/$phpFile";
34 if (! function_exists('getImageLink')) {
35 function getImageLink($imageSimplePath)
37 return dirname($_SERVER["SCRIPT_NAME"]).'/'.IMAGES_DIR.$imageSimplePath;
41 function getPreview($imgFile, $maxSize = THUMB_SIZE)
43 # example: data/myalbum/100.mypic.jpg
44 $newImgFile = DATA_DIR."/".dirname($imgFile)."/".$maxSize.".".basename($imgFile);
46 if (! is_file($newImgFile))
48 $ext = strtolower(substr($imgFile, -4));
50 $img = imagecreatefromjpeg($imgFile);
52 $img = imagecreatefrompng($imgFile);
56 # don't do anything if the image is already small
57 if ($w <= $maxSize and $h <= $maxSize) {
62 # create the thumbs directory recursively
63 if (! is_dir(dirname($newImgFile))) mkdir(dirname($newImgFile), 0777, true);
67 $newH = $h/($w/$maxSize);
69 $newW = $w/($h/$maxSize);
73 $newImg = imagecreatetruecolor($newW, $newH);
75 imagecopyresampled($newImg, $img, 0, 0, 0, 0, $newW, $newH, $w, $h);
78 imagejpeg($newImg, $newImgFile);
80 imagepng($newImg, $newImgFile);
83 imagedestroy($newImg);
86 return dirname($_SERVER["SCRIPT_NAME"])."/".$newImgFile;
89 function getAlbumPreview($dir)
91 foreach (scandir($dir) as $file) if ($file != '.' and $file != '..') {
92 $ext = strtolower(substr($file, -4));
93 if ($ext == ".jpg" or $ext == ".png")
94 return getPreview("$dir/$file");
100 $scriptUrl = $_SERVER["SCRIPT_NAME"];
101 $rootUrl = dirname($scriptUrl);
102 // $scriptUrl = "/path/to/bizou/index.php"
103 // $rootUrl = "/path/to/bizou"
105 // if url == http://localhost/photos/index.php/toto/titi, path_info == /toto/titi
106 // if url == http://localhost/photos/index.php, path_info is not set
107 // if url == http://localhost/photos/, path_info is not set
108 // if path_info is not set, we are at top level, so we redirect to /photos/index.php/
109 if (! isset($_SERVER["PATH_INFO"])) {
110 header("Location: $scriptUrl/");
114 # simplePath is the simple path to the image
115 # /index.php/toto/titi => simplePath == /toto/titi
116 $simplePath = $_SERVER["PATH_INFO"];
117 if ($simplePath == '/') $simplePath = '';
118 // extra security check to avoid /photos/index/../.. like urls, maybe useless but..
119 if (strpos($simplePath, '..') !== false) die(".. found in url");
122 $imageFiles = array();
123 $otherFiles = array();
125 # realDir is the directory in filesystem
126 # seen from current script directory
127 $realDir = IMAGES_DIR.$simplePath;
129 if (! is_dir($realDir)) {
130 header("HTTP/1.1 404 Not Found");
131 die("Directory Not Found");
134 foreach (scandir($realDir) as $file) if ($file != '.' and $file != '..')
136 if (is_dir("$realDir/$file"))
138 $folders[] = array( "name" => $file, "link" => "$scriptUrl$simplePath/$file", "preview" => getAlbumPreview("$realDir/$file") );
142 $ext = strtolower(substr($file, -4));
143 if ($ext == ".jpg" or $ext == ".png") {
144 $imageFiles[] = array( "name" => $file, "url" => getPreview("$realDir/$file"), "link" => getImageLink("$simplePath/$file") );
146 $otherFiles[] = array( "name" => $file, "link" => "$rootUrl/$realDir/$file" );
151 if (dirname($simplePath) !== '')
152 $parentLink = $scriptUrl.dirname($simplePath);
158 ///// template starts here /////
159 header('Content-Type: text/html; charset=utf-8');
160 header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + 3600));
164 <style type="text/css">
172 text-decoration: none;
175 display: inline-block;
178 width: <?php echo THUMB_SIZE ?>px;
179 height: <?php echo THUMB_SIZE ?>px;
182 vertical-align: middle;
185 height: <?php echo THUMB_SIZE ?>px;
187 vertical-align: middle;
197 <?php foreach ($plugins as $p) if (is_file("plugins/$p/style.css")) { ?>
198 <link rel="stylesheet" type="text/css" href="<?php echo "$rootUrl/plugins/$p/style.css" ?>" />
203 <?php if ($parentLink !== '') { ?>
204 <div id="parentfolder"><a href="<?php echo $parentLink ?>">^</a></div>
207 <?php plugins_include("before_content.php") ?>
209 <?php foreach($folders as $folder) { ?>
211 <?php if ($folder["preview"] === "") { ?>
212 <a href="<?php echo $folder["link"] ?>"><?php echo $folder["name"] ?></a>
214 <div class="square"><div class="image"><a href="<?php echo $folder["link"] ?>"><img src="<?php echo $folder["preview"] ?>" /></a></div></div>
215 <div class="square"><div class="foldername"><a href="<?php echo $folder["link"] ?>"><?php echo $folder["name"] ?></a></div></div>
220 <?php foreach ($imageFiles as $file) { ?>
221 <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>
224 <?php foreach ($otherFiles as $file) { ?>
225 <div class="miscfile"><a href="<?php echo $file["link"] ?>"><?php echo $file["name"] ?></a></div>