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