Added page titles in viewer
[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
23 $simpleImagePath = $_SERVER["PATH_INFO"];
24 if ($simpleImagePath == '/') $simpleImagePath = '';
25 // extra security check to avoid /photos/index/../.. like urls, maybe useless but..
26 if (strpos($simpleImagePath, '..') !== false) die(".. found in url");
27
28
29 if (! is_file("$bizouRootFromHere/".IMAGES_DIR.$simpleImagePath)) {
30         header("HTTP/1.1 404 Not Found");
31         die("File Not Found");
32 }
33
34 // get all images in an array
35 $images = array();
36
37 $files = scandir("$bizouRootFromHere/".IMAGES_DIR.dirname($simpleImagePath));
38 foreach ($files as $file) {
39         $ext = strtolower(substr($file, -4));
40         if ($ext == ".jpg" or $ext == ".png")
41                 $images[] = $file;
42 }
43
44 // find the image position
45 $pos = array_search(basename($simpleImagePath), $images);
46 if ($pos === false) die("Image not found");
47
48 // get prev and next images
49 $prevImage = '';
50 $nextImage = '';
51 if ($pos > 0)
52         $prevImage = $images[$pos-1];
53 if ($pos < sizeof($images)-1)
54         $nextImage = $images[$pos+1];
55
56 $scriptUrl = $_SERVER["SCRIPT_NAME"];
57 $bizouRootUrl = dirname(dirname(dirname($scriptUrl)));
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 = "$bizouRootUrl/".IMAGES_DIR.dirname($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 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 <html>
82 <head>
83 <title> <?php echo IMAGES_DIR.$simpleImagePath ?> </title>
84 <style type="text/css">
85 html, body {
86 height: 100%;
87 }
88 body {
89 margin: 0;
90 text-align: center;
91 background: black;
92 color: white;
93 }
94 #theimage {
95 max-width: 100%;
96 max-height: 100%;
97 }
98 a {
99         color: white;
100         text-decoration: none;
101 }
102 #next, #previous, #up {
103         position: fixed;
104         font-size: 4em;
105         font-weight: bold;
106 }
107
108 #up {
109         top: 0;
110         left: 0;
111         
112 }
113 #next {
114         top: 50%;
115         right: -0;
116         
117 }
118 #previous {
119         top: 50%;
120         left: 0;
121 }
122 img {
123         border: 0;
124 }
125 </style>
126
127 <?php if ($nextImageUrl !== '' and $firefox) { ?>
128 <link rel="prefetch" href="<?php echo $nextImageUrl ?>" />
129 <link rel="prefetch" href="<?php echo $nextPageUrl ?>" />
130 <?php } ?>
131
132 </head>
133 <body>
134
135 <a href="<?php echo $imageUrl ?>"><img src="<?php echo $imageUrl ?>" id="theimage" /></a>
136
137 <div id="up">
138 <a href="<?php echo $directoryUrl ?>" title="Back to directory">^</a>
139 </div>
140
141 <?php if ($nextPageUrl !== '') { ?>
142 <div id="next">
143 <a href="<?php echo $nextPageUrl ?>" title="Next image">&gt;</a>
144 </div>
145 <?php } ?>
146
147 <?php if ($prevPageUrl !== '') { ?>
148 <div id="previous">
149 <a href="<?php echo $prevPageUrl ?>" title="Previous image">&lt;</a>
150 </div>
151 <?php } ?>
152
153 <script type="text/javascript">
154
155 <?php if ($nextImageUrl !== '' and ! $firefox) { ?>
156 window.onload = function() { // for browsers not supporting link rel=prefetch
157         var im = new Image();
158         im.src = '<?php echo $nextImageUrl ?>';
159         var req = new XMLHttpRequest();
160         req.open('GET', '<?php echo $nextPageUrl ?>', false);
161         req.send(null);
162 };
163 <?php } ?>
164
165 // keyboard navigation
166 function keyup(e)
167 {
168         switch (e.keyCode) {
169                 case 37: // left
170                         window.location = "<?php echo $prevPageUrl ?>";
171                 break;
172                 case 39: // right
173                 case 32: // space
174                         window.location = "<?php echo $nextPageUrl ?>";
175                 break;
176                 case 38: // up  (down is 40)
177                         window.location = "<?php echo $directoryUrl ?>";
178                 break;
179                 case 13: // enter
180                         window.location = "<?php echo $imageUrl ?>";
181                 break;
182         }
183 }
184
185 if (document.addEventListener) {
186         document.addEventListener("keyup", keyup, false);
187 }
188 </script>
189
190 </body>
191 </html>