e60cc25d7a97f1bfe9f1ffb11e88efaa3a37028f
[bizou.git] / view.php
1 <?php
2
3 define('IMAGES_DIR', 'images');
4
5 $shortPath = $_SERVER["PATH_INFO"];
6 if ($shortPath == '/') $shortPath = '';
7 // extra security check to avoid /photos/index/../.. like urls, maybe useless but..
8 if (strpos($shortPath, '..') !== false) die(".. found in url");
9
10 $scriptPath = $_SERVER["SCRIPT_NAME"];
11
12 // get all images in an array
13 $images = array();
14
15 $files = scandir(IMAGES_DIR.dirname($shortPath));
16 foreach ($files as $file) {
17         $ext = strtolower(substr($file, -4));
18         if ($ext == ".jpg" or $ext == ".png")
19                 $images[] = $file;
20 }
21
22 // find the image position
23 $pos = array_search(basename($shortPath), $images);
24 if ($pos === false) die("Image not found");
25
26 // get prev and next images
27 $prevImage = '';
28 $nextImage = '';
29 if ($pos > 0)
30         $prevImage = $images[$pos-1];
31 if ($pos < sizeof($images)-1)
32         $nextImage = $images[$pos+1];
33
34 // template variables
35 $imageUrl = dirname($scriptPath)."/".IMAGES_DIR.$shortPath;
36
37 if ($nextImage === '') {
38         $nextImageUrl = '';
39         $nextPageUrl = '';
40 } else {
41         $nextImageUrl = dirname($scriptPath)."/".IMAGES_DIR.dirname($shortPath)."/$nextImage";
42         $nextPageUrl = dirname($_SERVER["REQUEST_URI"])."/$nextImage";
43 }
44 if ($prevImage === '') $prevPageUrl = '';
45 else $prevPageUrl = dirname($_SERVER["REQUEST_URI"])."/$prevImage";
46
47 $directoryUrl = dirname($_SERVER["SCRIPT_NAME"])."/index.php".dirname($shortPath);
48
49 header('Content-Type: text/html; charset=utf-8');
50 header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + 3600));
51 ?>
52 <html>
53 <head>
54 <style type="text/css">
55 html, body {
56 height: 100%;
57 }
58 body {
59 margin: 0;
60 text-align: center;
61 background: black;
62 color: white;
63 }
64 #theimage {
65 max-width: 100%;
66 max-height: 100%;
67 }
68 a {
69         color: white;
70         text-decoration: none;
71 }
72 #next, #previous, #up {
73         position: fixed;
74         font-size: 4em;
75         font-weight: bold;
76 }
77
78 #up {
79         top: 0;
80         left: 0;
81         
82 }
83 #next {
84         top: 50%;
85         right: -0;
86         
87 }
88 #previous {
89         top: 50%;
90         left: 0;
91 }
92 img {
93         border: 0;
94 }
95 </style>
96
97 <?php if ($nextImageUrl !== '') { ?>
98 <link rel="prefetch" href="<?php echo $nextImageUrl ?>" />
99 <link rel="prefetch" href="<?php echo $nextPageUrl ?>" />
100 <?php } ?>
101
102 </head>
103 <body>
104
105 <a href="<?php echo $imageUrl ?>"><img src="<?php echo $imageUrl ?>" id="theimage" /></a>
106
107 <div id="up">
108 <a href="<?php echo $directoryUrl ?>" title="Back to directory">^</a>
109 </div>
110
111 <?php if ($nextPageUrl !== '') { ?>
112 <div id="next">
113 <a href="<?php echo $nextPageUrl ?>" title="Next image">&gt;</a>
114 </div>
115 <?php } ?>
116
117 <?php if ($prevPageUrl !== '') { ?>
118 <div id="previous">
119 <a href="<?php echo $prevPageUrl ?>" title="Previous image">&lt;</a>
120 </div>
121 <?php } ?>
122
123 </body>
124 </html>