functions put in a separate file, so that they can be used by plugins
[bizou.git] / plugins / viewer / view.php
1 <?php
2 /*
3     Bizou - a (french) KISS php image gallery
4     Copyright (C) 2010  Marc MAURICE
5
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.
10
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.
15
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/>.
18 */
19
20 $bizouRootFromHere = '../..';
21 require "$bizouRootFromHere/config.php";
22 require "$bizouRootFromHere/functions.php";
23
24 // extract /path/to/image.jpg from /view.php/path/to/image.jpg
25 $simpleImagePath = getPathInfo();
26
27 if (! is_file("$bizouRootFromHere/".IMAGES_DIR.$simpleImagePath)) {
28         header("HTTP/1.1 404 Not Found");
29         die("File Not Found");
30 }
31
32 // get all images in an array
33 $images = array();
34
35 $files = scandir("$bizouRootFromHere/".IMAGES_DIR.dirname($simpleImagePath));
36 foreach ($files as $file) {
37         $ext = strtolower(substr($file, -4));
38         if ($ext == ".jpg" or $ext == ".png")
39                 $images[] = $file;
40 }
41
42 // find the image position
43 $pos = array_search(basename($simpleImagePath), $images);
44 if ($pos === false) die("Image not found");
45
46 // get prev and next images
47 $prevImage = '';
48 $nextImage = '';
49 if ($pos > 0)
50         $prevImage = $images[$pos-1];
51 if ($pos < sizeof($images)-1)
52         $nextImage = $images[$pos+1];
53
54 $scriptUrl = $_SERVER["SCRIPT_NAME"];
55 $bizouRootUrl = dirname(dirname(dirname($scriptUrl)));
56 if (substr($bizouRootUrl, -1) !== '/') $bizouRootUrl.='/';  // add a trailing / to rootUrl
57 // scriptUrl = /path/to/bizou/plugins/viewer/view.php
58 // bizouRootUrl = /path/to/bizou/
59
60 // template variables
61 $imageUrl = $bizouRootUrl.IMAGES_DIR.$simpleImagePath;
62
63 if ($nextImage === '') {
64         $nextImageUrl = '';
65         $nextPageUrl = '';
66 } else {
67         $nextImageUrl = dirname($bizouRootUrl.IMAGES_DIR.$simpleImagePath)."/$nextImage";
68         $nextPageUrl = dirname($_SERVER["REQUEST_URI"])."/$nextImage";
69 }
70 if ($prevImage === '') $prevPageUrl = '';
71 else $prevPageUrl = dirname($_SERVER["REQUEST_URI"])."/$prevImage";
72
73 $directoryUrl = $bizouRootUrl."index.php".dirname($simpleImagePath);
74
75 $firefox = strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') !== false;
76
77 ///// template starts here /////
78 header('Content-Type: text/html; charset=utf-8');
79 header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + 3600));
80
81 require 'template.php';
82
83 ?>