-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
373 lines (305 loc) · 13.4 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
<?php
# # # # # # # # # # # # # # # # # # # # # # # # #
# _ __ ___ #
# _ __ (_) __\ \ / (_) _____ __ #
# | '_ \| |/ __\ \ / /| |/ _ \ \ /\ / / #
# | |_) | | (__ \ V / | | __/\ V V / #
# | .__/|_|\___| \_/ |_|\___| \_/\_/ #
# |_| picView Version 0.4.20061213 #
# #
# This is GPL. #
# Visit http://scripte.arnep.de #
# # # # # # # # # # # # # # # # # # # # # # # # #
error_reporting(E_ALL);
include('./config.php');
include('./functions.php');
/**
Actions:
t = thumbnail size
m = medium size
i = original size
c = comment
s = save comment
r = rotate
d = delete image cache
p = show path (default)
Parameters:
n = startindex of thumbnails
*/
if (isset($_SERVER['PATH_INFO'])) {
list(, $galleryId, $action, $path)=explode('/',$_SERVER['PATH_INFO'],4);
} else {
$path='/';
$action = '';
$galleryId = 'picview';
}
$galleryConfig = $galleries[$galleryId];
$pictures_path = $galleryConfig['pictures_path'];
if (!$pictures_path) { header("HTTP/1.1 404 Not found"); die("<h2>Nicht gefunden</h2>"); }
$BASE_URI = $_SERVER['SCRIPT_NAME'].'/'.$galleryId;
if (!isset($galleryConfig['title'])) $galleryConfig['title'] = $galleryId;
require_basicauth();
if (strlen($action) != 1) {
$path = $action . '/' . $path;
$action = '';
}
$path = '/'.$path;
if ($path == '') $path = '/';
$path = preg_replace("!/+!", "/", $path);
if ($action === 't') {
if (!legal_image($pictures_path.$path, $pictures_path)) die ('Fehler');
// Filename for thumbnail to save to
$save_name = $thumbs_path.'/'.str_replace('/','_',$pictures_path.$path);
// Thumbnail exists? Load it!
if (file_exists($save_name)) {
$new_image = @ImageCreateFromJPEG($save_name);
} else {
if(preg_match("/\.(png)$/i", $pictures_path.$path))
$im = @ImageCreateFromPNG($pictures_path.$path) or die ("Kann keinen neuen GD-Bild-Stream erzeugen (PNG)");
elseif(preg_match("/\.(jpg)$/i", $pictures_path.$path))
$im = @ImageCreateFromJPEG($pictures_path.$path) or die ("Kann keinen neuen GD-Bild-Stream erzeugen (JPEG)");
$size = GetImageSize ($pictures_path.$path);
$background_color = ImageColorAllocate ($im, 255, 255, 255);
$h = $thumb_size;
$width = $size[0]*$h/$size[1];
$height = $h;
$new_image = imagecreatetruecolor($width, $height); imagefill($new_image, 0, 0, $background_color);
imagecopyresampled($new_image, $im, 0, 0, 0, 0, $width, $height, $size[0], $size[1]);
// Save thumbnail to file
if (is_writable($save_name) || !file_exists($save_name)) {
ImageJPEG($new_image, $save_name, 90);
} else {
print "Die Datei $save_name ist nicht schreibbar";
}
}
// Die Anzahl der Kommentare ins Bild einfuegen
$comments = $_GET['comments'];
if ($comments > 0) {
$comments .= $comments == 1 ? ' Kommentar' : ' Kommentare';
$new_image = image_write($new_image, $comments, 10, 7, 7);
}
// Show image
Header('Content-type: image/jpeg');
ImageJPEG($new_image);
} elseif ($action === 'm') {
if (!legal_image($pictures_path.$path, $pictures_path)) die ('Fehler');
// Filename for thumbnail to save to
$save_name = $thumbs_path.'/m'.str_replace('/','_',$pictures_path.$path);
// Thumbnail exists? Load it!
if (file_exists($save_name)) {
$new_image = @ImageCreateFromJPEG($save_name);
} else {
if(preg_match("/\.(png)/i", $pictures_path.$path))
$im = @ImageCreateFromPNG($pictures_path.$path) or die ("Kann keinen neuen GD-Bild-Stream erzeugen (PNG)");
elseif(preg_match("/\.(jpg)$/i", $pictures_path.$path))
$im = @ImageCreateFromJPEG($pictures_path.$path) or die ("Kann keinen neuen GD-Bild-Stream erzeugen (JPEG)");
$size = GetImageSize ($pictures_path.$path);
$background_color = ImageColorAllocate ($im, 51,51,51);
$h = $medium_size;
if ($size[0] < $size[1]) {
$width = $size[0]*$h/$size[1];
$height = $h;
} else {
$width = $h;
$height = $size[1]*$h/$size[0];
}
$new_image = imagecreatetruecolor($width, $height); imagefill($new_image, 0, 0, $background_color);
imagecopyresampled($new_image, $im, 0, 0, 0, 0, $width, $height, $size[0], $size[1]);
// Save thumbnail to file
if (is_writable($save_name) || !file_exists($save_name)) {
ImageJPEG($new_image, $save_name, 90);
} else {
print "Die Datei $save_name ist nicht schreibbar";
}
}
$copyright_file = dirname($pictures_path.$path).'/'.$copyright_file;
if (file_exists($copyright_file)) $text = join('',file($copyright_file));
$new_image = image_write($new_image, $text, 10, 5, 13);
Header('Content-type: image/jpeg');
ImageJPEG($new_image);
} elseif ($action === 'i') {
if (!legal_image($pictures_path.$path, $pictures_path)) die ('Fehler');
$copyright_file = dirname($pictures_path.$path).'/'.$copyright_file;
if (file_exists($copyright_file)) $text = join('',file($copyright_file));
if(preg_match("/\.(png)$/i", $pictures_path.$path)) {
$im = @ImageCreateFromPNG($pictures_path.$path) or die ("Kann keinen neuen GD-Bild-Stream erzeugen");
$im = image_write($im, $text, 10, 5, 13);
Header('Content-type: image/png');
ImagePNG($im);
}
elseif(preg_match("/\.(jpg)$/i", $pictures_path.$path)) {
$im = @ImageCreateFromJPEG($pictures_path.$path) or die ("Kann keinen neuen GD-Bild-Stream erzeugen");
$im = image_write($im, $text, 10, 5, 13);
Header('Content-type: image/jpeg');
ImageJPEG($im);
}
} elseif ($action === 'c') {
$start = (int)$_GET['n'];
if (!legal_image($pictures_path.$path, $pictures_path)) die('Bild nicht gefunden.');
$no_cache_rand = isset($_GET['r']) ? '?'.rand(0, 86400) : '';
$arr = Array();
$arr['pagetitle'] = $path;
//$arr['navigation'] = '<a href="'.$BASE_URI.'/p'.preg_replace('!^(.*?/)[^/]+$!', '$1', $path).'?n='.$start.'">[Übersicht]</a><br>';
// Filename for thumbnail to save to
$save_name_m = $thumbs_path.'/m'.str_replace('/','_',$pictures_path.$path);
// Get image size for shadow
$size = @getimagesize($save_name_m);
$h = $medium_size;
if ($size[0] < $size[1]) {
if ($size[1] != 0) $width = $size[0]*$h/$size[1];
$height = $h;
} else {
$width = $h;
if ($size[0] != 0) $height = $size[1]*$h/$size[0];
}
// previous and next picture
$curr_dir = preg_replace('!^(.*/)[^/]+$!', '\1', $pictures_path.$path);
$curr_pic = preg_replace('!^.*/([^/]+)$!', '\1', $pictures_path.$path);
$dir = get_dir($curr_dir, '', 'f');
$key = array_search($curr_pic, $dir);
$prev_pic = $dir[$key - 1] != '' ? str_replace($pictures_path, '', $curr_dir.$dir[$key - 1]) : '';
$next_pic = $dir[$key + 1] != '' ? str_replace($pictures_path, '', $curr_dir.$dir[$key + 1]) : '';
$arr['content'] = '';
// Show picture
$arr['content'] .= '<div class="carousel-inner" role="listbox">';
$arr['content'] .= '<div class="item active">';
//$arr['content'] .= '<div style="height:'.(($height ? $height : $medium_size)+15).'px;text-align:center;width:100%" class="mainImage">';
$arr['content'] .= '<a href="'.$BASE_URI.'/i'.$path.'">';
$arr['content'] .= '<img src="'.$BASE_URI.'/m'.$path.$no_cache_rand.'" border="0" />';
$arr['content'] .= '</a>';
$arr['content'] .= '</div></div>';
// Previous Picture
if ($prev_pic) {
$arr['content'] .= '<a class="left carousel-control" href="'.$BASE_URI.'/c'.$prev_pic.'?n='.$start.'#img" role="button" data-slide="prev">';
$arr['content'] .= '<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>';
$arr['content'] .= '<span class="sr-only">Previous</span>';
$arr['content'] .= '</a>';
}
// Next Picture
if ($next_pic) {
$arr['content'] .= '<a class="right carousel-control" href="'.$BASE_URI.'/c'.$next_pic.'#img" role="button" data-slide="next">';
$arr['content'] .= '<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>';
$arr['content'] .= '<span class="sr-only">Next</span>';
$arr['content'] .= '</a>';
// Preload next picture to browser cache
$arr['content'] .= '<img src="'.$BASE_URI.'/m'.$next_pic.'" border="0" width="1" height="1" hspace="20" alt="" style="position:absolute" />';
}
//$arr['content'] .= '<br clear="all"><br>';
// Filename for comments to save to
$save_name = $comments_path.'/'.str_replace('/','_',$path).'.txt';
$arr['comments'] = '';
$arr['comments'] .= '<div class="row">';
$arr['comments'] .= '<div class="col-md-10 col-md-offset-2">';
if (file_exists($save_name)) {
$handle = fopen ($save_name,"r");
while ($data = fgetcsv ($handle, 5000, ",")) {
$arr['comments'] .= '<blockquote>';
$arr['comments'] .= '<p>' . stripslashes(nl2br($data[1])) . '</p>';
$arr['comments'] .= '<footer><b>'.stripslashes($data[0]).'</b>';
$arr['comments'] .= ' am <cite title="Datum">'.date('d.m.Y', $data[2]).'</cite>';
$arr['comments'] .= ' um <cite title="Uhrzeit">'.date('H:i', $data[2]).'</cite></footer>';
$arr['comments'] .= '</blockquote>';
}
fclose ($handle);
}
$arr['comments'] .= '</div></div>';
// Image functions
/*
$arr['breadcrumb'] .= '<span style="float:right"><b>';
$arr['breadcrumb'] .= '<a href="'.$BASE_URI.'/r'.$path.'">[ ⟳ Drehen im mathematisch negativen Sinn ]</a> ';
$arr['breadcrumb'] .= '<a href="'.$BASE_URI.'/d'.$path.'">[ Bildansicht neu erzeugen ]</a> ';
$arr['breadcrumb'] .= '</b></span>';
$arr['breadcrumb'] .= '<b style="float:left; padding: 0 10px;"><a href="'.$BASE_URI.'/p'.preg_replace('!^(.*?/)[^/]+$!', '$1', $path).'?n='.$start.'">[ Zur Übersicht ]</a></b>';
*/
$arr['actions'] = '';
$arr['actions'] .= '<li><a href="'.$BASE_URI.'/r'.$path.'" title="Drehen im mathematisch negativen Sinn"><i class="fa fa-rotate-right"></i></a></li>';
$arr['actions'] .= '<li><a href="'.$BASE_URI.'/d'.$path.'" title="Bildansicht neu erzeugen"><i class="fa fa-window-restore"></i></a></li>';
// Show comment form
$arr['comments'] .= '<form action="'.$BASE_URI.'/s'.$path.'" method="post" class="form-horizontal">';
$arr['comments'] .= ' <div class="form-group">';
$arr['comments'] .= ' <label for="input-name" class="col-sm-2 control-label">Name</label>';
$arr['comments'] .= ' <div class="col-sm-10">';
if ($_SERVER["REMOTE_USER"] != '')
$arr['comments'] .= ' <p class="form-control-static">'.$_SERVER["REMOTE_USER"].'</p>';
else
$arr['comments'] .= ' <input type="text" class="form-control" name="name" id="input-name" placeholder="Name">';
$arr['comments'] .= ' </div>';
$arr['comments'] .= ' </div>';
$arr['comments'] .= ' <div class="form-group">';
$arr['comments'] .= ' <label for="input-comment" class="col-sm-2 control-label">Kommentar</label>';
$arr['comments'] .= ' <div class="col-sm-10">';
$arr['comments'] .= ' <textarea class="form-control" name="comment" id="input-comment" placeholder="Kommentar"></textarea>';
$arr['comments'] .= ' </div>';
$arr['comments'] .= ' </div>';
$arr['comments'] .= ' <div class="form-group">';
$arr['comments'] .= ' <div class="col-sm-offset-2 col-sm-10">';
$arr['comments'] .= ' <input type="submit" value="Kommentar speichern" class="btn btn-default" />';
$arr['comments'] .= ' </div>';
$arr['comments'] .= ' </div>';
$arr['comments'] .= '</form>';
$arr['breadcrumb'] .= show_breadcrumb($path);
$arr['base_uri'] = make_basedir();
echo make_page($lightbox_file, $arr);
} elseif ($action === 's') {
// Filename for comments to save to
$save_name = $comments_path.'/'.str_replace('/','_',$path).'.txt';
$name = $_SERVER['REMOTE_USER'] != '' ? $_SERVER['REMOTE_USER'] : htmlentities($_POST['name']);
$comment = htmlentities($_POST['comment']);
$line = '"'.$name.'","'.$comment.'",'.time()."\n";
// Sichergehen, dass die Datei existiert und beschreibbar ist
if (is_writable($save_name) || !file_exists($save_name)) {
// Wir öffnen $filename im "Anhänge" - Modus.
// Der Dateizeiger befindet sich am Ende der Datei, und
// dort wird $somecontent später mit fwrite() geschrieben.
if (!$handle = fopen($save_name, "a")) {
print "Kann die Datei $save_name nicht öffnen";
exit;
}
// Schreibe $somecontent in die geöffnete Datei.
if (!fwrite($handle, $line)) {
print "Kann in die Datei $save_name nicht schreiben";
exit;
}
fclose($handle);
} else {
print "Die Datei $save_name ist nicht schreibbar";
exit;
}
#echo $line;
Header('Location: '.$BASE_URI.'/c'.$path.'?r#comments');
} elseif ($action === 'r') {
if (!legal_image($pictures_path.$path, $pictures_path)) die('Zugriffsfehler');
// Filename for thumbnail to save to
$save_name_m = $thumbs_path.'/m'.str_replace('/','_',$pictures_path.$path);
$save_name_t = $thumbs_path.'/'.str_replace('/','_',$pictures_path.$path);
ImageRotate_PV ( $save_name_m, 90 );
ImageRotate_PV ( $save_name_t, 90 );
//quickRotate ( $save_name_m, 90 );
//quickRotate ( $save_name_t, 90 );
//exit;
Header('Location: '.$BASE_URI.'/c'.$path.'?r');
} elseif ($action === 'd') {
if (!legal_image($pictures_path.$d, $pictures_path)) die('Zugriffsfehler');
// Filename for thumbnail to save to
$save_name_m = $thumbs_path.'/m'.str_replace('/','_',$pictures_path.$path);
$save_name_t = $thumbs_path.'/'.str_replace('/','_',$pictures_path.$path);
unlink ( $save_name_m );
unlink ( $save_name_t );
//exit;
Header('Location: '.$BASE_URI.'/c'.$path.'?r');
} elseif ($action === 'j') {
header("Content-Type: application/json");
echo json_encode([
"files" => get_dir($pictures_path, $path, 'f'),
"dirs" => get_dir($pictures_path, $path, 'd')
]);
} else {
$arr = Array();
$arr['pagetitle'] = $path;
$arr['navigation'] = show_directory($pictures_path, $path);
$arr['content'] = show_pictures($pictures_path, $path);
$arr['breadcrumb'] = show_breadcrumb($path);
$arr['base_uri'] = make_basedir();
echo make_page($template_file, $arr);
}
?>