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 $scriptUrlPath = $_SERVER["SCRIPT_NAME"];
102 // if url == http://localhost/photos/index.php/toto/titi, path_info == /toto/titi
103 // if url == http://localhost/photos/index.php, path_info is not set
104 // if url == http://localhost/photos/, path_info is not set
105 // if path_info is not set, we are at top level, so we redirect to /photos/index.php/
106 if (! isset($_SERVER["PATH_INFO"])) {
107 header("Location: $scriptUrlPath/");
111 # simplePath is the simple path to the image
112 # /index.php/toto/titi => simplePath == /toto/titi
113 $simplePath = $_SERVER["PATH_INFO"];
114 if ($simplePath == '/') $simplePath = '';
115 // extra security check to avoid /photos/index/../.. like urls, maybe useless but..
116 if (strpos($simplePath, '..') !== false) die(".. found in url");
119 $imageFiles = array();
120 $otherFiles = array();
122 # realDir is the directory in filesystem
123 # seen from current script directory
124 $realDir = IMAGES_DIR.$simplePath;
126 if (! is_dir($realDir)) {
127 header("HTTP/1.1 404 Not Found");
128 die("Directory Not Found");
131 foreach (scandir($realDir) as $file) if ($file != '.' and $file != '..')
133 if (is_dir("$realDir/$file"))
135 $folders[] = array( "name" => $file, "link" => "$scriptUrlPath$simplePath/$file", "preview" => getAlbumPreview("$realDir/$file") );
139 $ext = strtolower(substr($file, -4));
140 if ($ext == ".jpg" or $ext == ".png") {
141 $imageFiles[] = array( "name" => $file, "url" => getPreview("$realDir/$file"), "link" => getImageLink("$simplePath/$file") );
143 $otherFiles[] = array( "name" => $file, "link" => dirname($scriptUrlPath)."/$realDir/$file" );
148 if (dirname($simplePath) !== '')
149 $parentLink = $scriptUrlPath.dirname($simplePath);
155 ///// template starts here /////
156 header('Content-Type: text/html; charset=utf-8');
157 header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + 3600));
161 <style type="text/css">
169 text-decoration: none;
172 display: inline-block;
175 width: <?php echo THUMB_SIZE ?>px;
176 height: <?php echo THUMB_SIZE ?>px;
179 vertical-align: middle;
182 height: <?php echo THUMB_SIZE ?>px;
184 vertical-align: middle;
194 <?php foreach ($plugins as $p) if (is_file("plugins/$p/style.css")) { ?>
195 <link rel="stylesheet" type="text/css" href="<?php echo dirname($scriptUrlPath)."/plugins/$p/style.css" ?>" />
200 <?php if ($parentLink !== '') { ?>
201 <div id="parentfolder"><a href="<?php echo $parentLink ?>">^</a></div>
204 <?php plugins_include("before_content.php") ?>
206 <?php foreach($folders as $folder) { ?>
208 <?php if ($folder["preview"] === "") { ?>
209 <a href="<?php echo $folder["link"] ?>"><?php echo $folder["name"] ?></a>
211 <div class="square"><div class="image"><a href="<?php echo $folder["link"] ?>"><img src="<?php echo $folder["preview"] ?>" /></a></div></div>
212 <div class="square"><div class="foldername"><a href="<?php echo $folder["link"] ?>"><?php echo $folder["name"] ?></a></div></div>
217 <?php foreach ($imageFiles as $file) { ?>
218 <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>
221 <?php foreach ($otherFiles as $file) { ?>
222 <div class="miscfile"><a href="<?php echo $file["link"] ?>"><?php echo $file["name"] ?></a></div>