Replaced deprecaded Expires headers by Cache-Control
[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) if ($file[0] != '.')
37 {
38         $ext = strtolower(substr($file, -4));
39         if ($ext == ".jpg" or $ext == ".png")
40                 $images[] = $file;
41 }
42
43 // find the image position
44 $pos = array_search(basename($simpleImagePath), $images);
45 if ($pos === false) die("Image not found");
46
47 // get prev and next images
48 $prevImage = '';
49 $nextImage = '';
50 if ($pos > 0)
51         $prevImage = $images[$pos-1];
52 if ($pos < sizeof($images)-1)
53         $nextImage = $images[$pos+1];
54
55 $scriptUrl = $_SERVER["SCRIPT_NAME"];
56 $bizouRootUrl = dirname(dirname(dirname($scriptUrl)));
57 if (substr($bizouRootUrl, -1) !== '/') $bizouRootUrl.='/';  // add a trailing / to rootUrl
58 // scriptUrl = /path/to/bizou/plugins/viewer/view.php
59 // bizouRootUrl = /path/to/bizou/
60
61 // template variables
62 $imageUrl = $bizouRootUrl.IMAGES_DIR.$simpleImagePath;
63
64 if ($nextImage === '') {
65         $nextImageUrl = '';
66         $nextPageUrl = '';
67 } else {
68         $nextImageUrl = dirname($bizouRootUrl.IMAGES_DIR.$simpleImagePath)."/$nextImage";
69         $nextPageUrl = dirname($_SERVER["REQUEST_URI"])."/$nextImage";
70 }
71 if ($prevImage === '') $prevPageUrl = '';
72 else $prevPageUrl = dirname($_SERVER["REQUEST_URI"])."/$prevImage";
73
74 $directoryUrl = $bizouRootUrl."index.php".dirname($simpleImagePath);
75
76 $firefox = strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') !== false;
77
78 ///// template starts here /////
79 header('Content-Type: text/html; charset=utf-8');
80 header('Cache-Control: max-age=3600');
81
82 require 'template.php';
83
84 ?>