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