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/>.
24 if (is_dir("plugins")) {
25 $plugins = scandir("plugins");
26 array_shift($plugins); array_shift($plugins); // remove . and ..
27 foreach ($plugins as $p) if (is_file("plugins/$p/functions.php"))
28 require "plugins/$p/functions.php";
31 function plugins_include($phpFile)
33 foreach ($GLOBALS['plugins'] as $p) if (is_file("plugins/$p/$phpFile"))
34 require "plugins/$p/$phpFile";
37 if (! function_exists('getImageLink')) {
38 function getImageLink($imageSimplePath)
40 return dirname($_SERVER["SCRIPT_NAME"]).'/'.IMAGES_DIR.$imageSimplePath;
44 function getPreview($imgFile, $maxSize = THUMB_SIZE)
46 # example: data/myalbum/100.mypic.jpg
47 $newImgFile = DATA_DIR."/".dirname($imgFile)."/".$maxSize.".".basename($imgFile);
49 if (! is_file($newImgFile))
51 $ext = strtolower(substr($imgFile, -4));
53 $img = imagecreatefromjpeg($imgFile);
55 $img = imagecreatefrompng($imgFile);
59 # don't do anything if the image is already small
60 if ($w <= $maxSize and $h <= $maxSize) {
65 # create the thumbs directory recursively
66 if (! is_dir(dirname($newImgFile))) mkdir(dirname($newImgFile), 0777, true);
70 $newH = $h/($w/$maxSize);
72 $newW = $w/($h/$maxSize);
76 $newImg = imagecreatetruecolor($newW, $newH);
78 imagecopyresampled($newImg, $img, 0, 0, 0, 0, $newW, $newH, $w, $h);
81 imagejpeg($newImg, $newImgFile);
83 imagepng($newImg, $newImgFile);
86 imagedestroy($newImg);
89 return dirname($_SERVER["SCRIPT_NAME"])."/".$newImgFile;
92 function getAlbumPreview($dir)
94 foreach (scandir($dir) as $file) if ($file != '.' and $file != '..') {
95 $ext = strtolower(substr($file, -4));
96 if ($ext == ".jpg" or $ext == ".png")
97 return getPreview("$dir/$file");
103 $scriptUrl = $_SERVER["SCRIPT_NAME"];
104 $rootUrl = dirname($scriptUrl);
105 // $scriptUrl = "/path/to/bizou/index.php"
106 // $rootUrl = "/path/to/bizou"
108 // if url == http://localhost/photos/index.php/toto/titi, path_info == /toto/titi
109 // if url == http://localhost/photos/index.php, path_info is not set
110 // if url == http://localhost/photos/, path_info is not set
111 // if path_info is not set, we are at top level, so we redirect to /photos/index.php/
112 if (! isset($_SERVER["PATH_INFO"])) {
113 header("Location: $scriptUrl/");
117 # simplePath is the simple path to the image
118 # /index.php/toto/titi => simplePath == /toto/titi
119 $simplePath = $_SERVER["PATH_INFO"];
120 if ($simplePath == '/') $simplePath = '';
121 // extra security check to avoid /photos/index/../.. like urls, maybe useless but..
122 if (strpos($simplePath, '..') !== false) die(".. found in url");
125 $imageFiles = array();
126 $otherFiles = array();
128 # realDir is the directory in filesystem
129 # seen from current script directory
130 $realDir = IMAGES_DIR.$simplePath;
132 if (! is_dir($realDir)) {
133 header("HTTP/1.1 404 Not Found");
134 die("Directory Not Found");
137 foreach (scandir($realDir) as $file) if ($file != '.' and $file != '..')
139 if (is_dir("$realDir/$file"))
141 $folders[] = array( "name" => $file, "link" => "$scriptUrl$simplePath/$file", "preview" => getAlbumPreview("$realDir/$file") );
145 $ext = strtolower(substr($file, -4));
146 if ($ext == ".jpg" or $ext == ".png") {
147 $imageFiles[] = array( "name" => $file, "url" => getPreview("$realDir/$file"), "link" => getImageLink("$simplePath/$file") );
149 $otherFiles[] = array( "name" => $file, "link" => "$rootUrl/$realDir/$file" );
154 if (dirname($simplePath) !== '')
155 $parentLink = $scriptUrl.dirname($simplePath);
161 ///// template starts here /////
162 header('Content-Type: text/html; charset=utf-8');
163 header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + 3600));
167 <style type="text/css">
175 text-decoration: none;
178 display: inline-block;
181 width: <?php echo THUMB_SIZE ?>px;
182 height: <?php echo THUMB_SIZE ?>px;
185 vertical-align: middle;
188 height: <?php echo THUMB_SIZE ?>px;
190 vertical-align: middle;
200 <?php foreach ($plugins as $p) if (is_file("plugins/$p/style.css")) { ?>
201 <link rel="stylesheet" type="text/css" href="<?php echo "$rootUrl/plugins/$p/style.css" ?>" />
206 <?php if ($parentLink !== '') { ?>
207 <div id="parentfolder"><a href="<?php echo $parentLink ?>">^</a></div>
210 <?php plugins_include("before_content.php") ?>
212 <?php foreach($folders as $folder) { ?>
214 <?php if ($folder["preview"] === "") { ?>
215 <a href="<?php echo $folder["link"] ?>"><?php echo $folder["name"] ?></a>
217 <div class="square"><div class="image"><a href="<?php echo $folder["link"] ?>"><img src="<?php echo $folder["preview"] ?>" /></a></div></div>
218 <div class="square"><div class="foldername"><a href="<?php echo $folder["link"] ?>"><?php echo $folder["name"] ?></a></div></div>
223 <?php foreach ($imageFiles as $file) { ?>
224 <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>
227 <?php foreach ($otherFiles as $file) { ?>
228 <div class="miscfile"><a href="<?php echo $file["link"] ?>"><?php echo $file["name"] ?></a></div>