-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
executable file
·123 lines (118 loc) · 3.97 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
/*
This page is made by Nero and Centzilius using Twitter Bootstrap available at twitter.github.io/bootstrap
Thanks to Nero and nilsding for the PHP Code
Thanks to pixeldesu for the idea
*/
define("IMAGE_WIDTH",200);
define("PAGE_IMAGES",5);
date_default_timezone_set("UTC");
if (isset($_GET['thumbnail'])) {
$fn=$_GET['thumbnail'];
$fn=str_replace("\\/|<>","",$fn);
if (file_exists($fn)) {
$meta=stat($fn);
header("ETag: ".md5($meta["ino"]));
header("Last-Modified: ".gmdate('D, d M Y H:i:s',$meta["mtime"]).' GMT');
header("Expires: ".gmdate('D, d M Y H:i:s',$meta["mtime"]+60*60).' GMT'); # Erst nach ner Stunde wieder neu fragen
header("Cache-Control: public");
if (strtotime(@$_SERVER['HTTP_IF_MODIFIED_SINCE'])==$meta["mtime"] || @$_SERVER['HTTP_IF_NONE_MATCH']==md5($meta["ino"])) {
header("HTTP/1.1 304 Not Modified"); # use that file from your cache, browser. We dont want to generate it again.
exit;
}
$type=pathinfo($fn,PATHINFO_EXTENSION);
$createfunc="imagecreatefrom".($type=="jpg"?"jpeg":$type);
if (!function_exists($createfunc)) { # this is not an usable image, echo default image
header("Content-Type: image/gif");
echo base64_decode("R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==");
exit;
}
$img=$createfunc($fn);
$w=imagesx($img);
$h=imagesy($img);
$nw=IMAGE_WIDTH;
$nh=floor($h*($nw/$w));
$new=imagecreatetruecolor($nw,$nh);
#imagealphablending($new, false);
$color = imagecolorallocatealpha($new, 0, 0, 0, 127);
imagefill($new, 0, 0, $color);
imagesavealpha($new, true);
imagecopyresampled($new,$img,0,0,0,0,$nw,$nh,$w,$h);
header("Content-Type: image/png");
imagepng($new);
exit;
}
}
# Start here with HTML!
?><!DOCTYPE html>
<html>
<head>
<title>centzilius.de - Bilder</title>
<link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.css">
<script src="http://code.jquery.com/jquery.js"></script>
<script src="bootstrap/js/bootstrap.js"></script>
<meta charset="utf-8">
<style type="text/css">
body {
padding-top: 60px;
}
</style>
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="https://centzilius.de">centzilius.de</a>
<div class="nav-collapse collapse">
<ul class="nav">
<li><a href="https://ask.centzilius.de">Frag den Cent</a></li>
<li class="active"><a href="#">Bilder</a></li>
<li><a href="https://actioncraft.de">ActionCraft</a></li>
</ul>
</div>
</div>
</div>
</div>
<div class="container">
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>Vorschau</th>
<th>Dateiname</th>
</tr>
</thead>
<tbody>
<?php
$page=(isset($_GET['page'])?((int)$_GET['page']):1);
if ($h = opendir(__DIR__)) {
$files=array();
while (false !== ($e = readdir($h))) {
if ($e[0]!='.' && in_array(pathinfo($e,PATHINFO_EXTENSION),array("jpg","png","gif","jpeg"))) {
$files[$e]=filemtime($e);
}
}
arsort($files);
$files=array_keys($files);
$start=($page-1)*PAGE_IMAGES;
for ($i=$start;$i<$start+PAGE_IMAGES; $i++) {
if (!isset($files[$i])) break;
$e=$files[$i];
echo('<tr><td><a href="'.$e.'"><img src="index.php?thumbnail='.$e.'" class=img-polaroid alt=Vorschau></a></td><td><a href="'.$e.'">'.$e.'</a></td></tr>'.PHP_EOL);
}
} ?>
</tbody>
</table>
<div class="pagination pagination-centered">
<ul>
<?php
if ($page>1) echo('<li><a href="?page='.($page-1).'">«</a></li>'.PHP_EOL);
for ($j=$page-3;$j<=$page+3; $j++) {
if ($j>0 && ($j-1)*PAGE_IMAGES<count($files)) echo('<li>'.($j==$page?'<span>'.$j.'</span>':'<a href="?page='.$j.'">'.$j.'</a>').'</li>'.PHP_EOL);
}
if ($i<count($files)) echo('<li><a href="?page='.($page+1).'">»</a></li>'.PHP_EOL);
?>
</ul>
</div>
</div>
</body>
</html>