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