-
Notifications
You must be signed in to change notification settings - Fork 0
/
viewer.php
129 lines (117 loc) · 4.22 KB
/
viewer.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
<?php
define('BASE_PATH', rtrim(realpath(dirname(__FILE__)), "/") . '/');
//require BASE_PATH . 'includes/settings.php';
//require BASE_PATH . 'lib/translator_class.php';
$settings = array();
$requested_category = '';
$requested_file = '';
$html_title = 'Viewer';
$html_content = '';
$nav_content = '';
$html_backlink = '';
$next_file = false;
$previous_file = false;
$HTML_navigation = '';
if (
(isset($_GET['category'])) &&
(preg_match("/^[a-zA-Z0-9-]/", $_GET['category']))
) {
if ((isset($_GET['filename'])) && (preg_match("/^[^\/\"'<>*]+$/", $_GET['filename']))) {
$HTML_navigation .= '<a href="index.php">Gallery</a>';
$requested_category = $_GET['category'];
$requested_file = $_GET['filename'];
$html_title = $requested_file . ' - ' . $requested_category . ' | ' . $html_title;
$HTML_navigation .= ' ❯ <a href="categories.php?category='.$requested_category.'">' . $requested_category . '</a>';
$HTML_navigation .= ' ❯ <a>' . $requested_file . '</a>';
$files = array_values(list_files());
if (!in_array($requested_file, $files)) {
exit("File not found");
}
$files_count = count($files);
if ($files_count >= 1) {
$i = 0;
while ($i < $files_count) {
if ($files["$i"] == $requested_file) {
$next_i = $i + 1;
$previous_i = $i - 1;
if (isset($files["$previous_i"])) {
$previous_file = $files["$previous_i"];
}
if (isset($files["$next_i"])) {
$next_file = $files["$next_i"];
}
} else {
$file_name = $files["$i"];
$thumb_file_location = 'thumbnails/' . $requested_category . '/thumb-' . $file_name;
$source_file_location = 'gallery/' . $requested_category . '/' . $file_name;
}
++$i;
}
}
$path_to_file = 'gallery/' . $requested_category . '/' . $requested_file;
$nav_content .= '<div class="pagination_style">';
if ($previous_file !== false) {
$nav_content .= '<span class="pagination-prev"><a href="viewer.php?category=' . $requested_category . '&filename=' . $previous_file . '" class="pagination-button left">❮ Previous </a></span>';
}
else {
$nav_content .= '<span class="buttonDisabled leftDisabled">❮ Previous </span>';
}
if ($next_file !== false) {
$nav_content .= '<span class="pagination-next"><a href="viewer.php?category=' . $requested_category . '&filename=' . $next_file . '" class="pagination-button right"> Next ❯</a></span>';
}
else {
$nav_content .= '<span class="buttonDisabled rightDisabled pagination-next"> Next ❯</span>';
}
$nav_content .= '</div>';
$html_content .= '<a class="card"><div class="cardtext flexible"><img src="' . $path_to_file . '" alt="' . $requested_file . '" class="fluidimg"></div></a>';
//$html_action_controls = '<div id="action_controls"><ul><li><a href="categories.php?category=' . $requested_category . '">Back</a></li></ul></div>';
} else {
$html_content = '<p>Invalid filename...</p>';
}
} else {
$html_content = '<p>Invalid category...</p>';
}
// ====================
// Functions
// Note. Besides CreateThumbnail() these functions are unique to this file
// DO NOT assume they are the same as in index.php
// If you combine and move functions to a functions.php, you will need fix code differences!
// ====================
function list_files()
{
$directory = BASE_PATH . 'gallery/' . $_GET['category'];
$thumbs_directory = BASE_PATH . 'thumbnails/' . $_GET['category'];
$item_arr = array_diff(scandir($directory), array('..', '.'));
foreach ($item_arr as $key => $value) {
if (is_dir($directory . '/' . $value)) {
unset($item_arr["$key"]);
} else {
$path_to_file = $thumbs_directory . '/thumb-' . $value;
}
}
return $item_arr;
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title><?php echo $html_title; ?></title>
<link rel="stylesheet" href="templates/default/gallery.css">
</head>
<body>
<header class="header">
<span class="logo">PHP Photo Gallery</span>
</header>
<div class="container">
<div class="catetory"><?php echo $requested_category; ?></div>
<div class="breadcrumbs"><?php echo $HTML_navigation; ?>
</div>
<?php echo $nav_content; ?>
<div class="row-flex">
<?php echo $html_content; ?>
</div>
</div>
</body>
</html>