-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
84 lines (72 loc) · 2.35 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
<?php
/**
* @file
* Dead-simple fullpage, flat PHP photo gallery based on gallery.io
*/
require_once 'config.php';
$local_override = 'local.config.php';
if (is_file($local_override) && is_readable($local_override)) {
require_once $local_override;
}
header('Content-Type: text/html; charset=utf-8');
if (isset($user) && isset($pass)) {
$validated = FALSE;
if (isset($_SERVER['PHP_AUTH_PW'])) {
$validated = ($user == $_SERVER['PHP_AUTH_USER']) && ($pass == md5($_SERVER['PHP_AUTH_PW']));
}
if (!$validated) {
header('WWW-Authenticate: Basic realm=""');
header('HTTP/1.0 401 Unauthorized');
die ("Not authorized");
}
}
if (!isset($gallery_path)) {
$gallery_path = getcwd();
}
$gallery_path = realpath($gallery_path);
$directory = new RecursiveDirectoryIterator($gallery_path);
$iterator = new RecursiveIteratorIterator($directory);
$types = implode('|', $allowed_filetypes);
$filtered = new RegexIterator($iterator, '/^.+\.(' . $types . ')$/i', RecursiveRegexIterator::GET_MATCH);
$output = "";
$images = [];
// Either downloading all the images in a ZIP file.
if (isset($_GET['download'])) {
$zip = new ZipArchive();
$temp_file = tempnam(sys_get_temp_dir(), 'phpgalleriaio');
$zip->open($temp_file, ZipArchive::CREATE);
foreach ($filtered as $file) {
$zip->addFile($file[0]);
}
$zip->close();
header('Content-Type: application/zip');
header('Content-disposition: attachment; filename=gallery.zip');
header('Content-Length: ' . filesize($temp_file));
readfile($temp_file);
unlink($temp_file);
exit(0);
}
// Or serving them as a web-based gallery.
foreach ($filtered as $file) {
// Clean up the image path from the gallery path.
$pos = strpos($file[0], $gallery_path);
if ($pos !== FALSE) {
$file[0] = substr_replace($file[0], '', $pos, strlen($gallery_path));
}
$image = trim($file[0], '/');
$basename = pathinfo($image, PATHINFO_FILENAME);;
$images[$basename . $image] = '<img data-layer="<h2>' . $basename . '</h2>" src="' . $image . '">';
}
ksort($images);
$galleria = implode('', $images);
if (!isset($css)) {
$css = is_file('local.css') ? 'local.css' : 'index.css';
}
if (!isset($js)) {
$js = is_file('local.js') ? 'local.js' : 'index.js';
}
if (!isset($title)) {
$title = basename(getcwd()) . ' (' . count($images) . ')';
}
$galleria_config = json_encode($galleria_config);
require_once 'index.tpl.php';