-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgallery.php
executable file
·176 lines (150 loc) · 5.61 KB
/
gallery.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
<?php
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
if ( !empty($_GET['gallery']) && !empty($_GET['category'])) {
$gallery = $_GET['gallery'];
$category = $_GET['category'];
} else {
header("Location:index.php");
die();
}
if(!isset($_SESSION['visitor']) && !isset($_SESSION['admin'])){
header("Location:auth/login.php?role=visitor&redirect=../gallery.php?category=" . $category . "&gallery=" . $gallery);
die();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Wink</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Photo Gallery">
<meta name="keywords" content="PHP, Photography">
<meta name="author" content="Fenimore">
<link rel="icon" href="favicon.ico">
<link href='https://fonts.googleapis.com/css?family=Josefin+Sans' rel='stylesheet' type='text/css'>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<!-- jQuery library -->
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen"/>
<style>
</style>
</head>
<body>
<div class="container">
<div class="row text-center">
<?php
$spaces = array("-", "_");
$gallerytitle = str_replace($spaces, " ", $gallery);
echo '<h1 class="title"> <a href=index.php>'. ucfirst($gallerytitle) .'</a></h1>';
echo '<div class="col-md-1">';
// NOTE: APOLOGIZES FUTURE SELF FOR USING ECHO IN SUCH A FASHION :(
///////////////////
// // Navigation //
///////////////////
// TODO: add zoom/fullscreen
echo '<a href="index.php" class="nav-control arrow"><span class="glyphicon glyphicon-home" aria-hidden="true"></span></a>';
echo '<br>';
$download = 'zip.php?category='. $category .'&gallery='.$gallery;
echo '<a href='.$download.' class="nav-control"><span title="Download" class="glyphicon glyphicon-cloud-download" aria-hidden="true"></span></a>';
echo '<br><br>';
echo '<a href=# onclick="prev()"';
echo ' class="nav-control"><span class="glyphicon glyphicon-chevron-left arrow" aria-hidden="true"></span></a>';
echo '<br><br>';
echo '<a href=# onclick="next()"';
echo ' class="nav-control"><span class="glyphicon glyphicon-chevron-right arrow" aria-hidden="true"></span></a>';
echo '<br><br>';
echo '</div>';
$path = 'media/'. $category . '/' . $gallery . '/';
$images = glob($path."*.{[jJ][pP][gG],gif,jpeg,svg,bmp,png}", GLOB_BRACE);
$thumbnails = glob($path.'thumbnails/'."*.{[jJ][pP][gG],gif,jpeg,svg,bmp,png}", GLOB_BRACE);
$src = 'view.php?category=' . $category . '&gallery=' . $gallery . '&index=';
$title = str_replace($spaces, " ", $info['filename']);
$size = sizeof($images);
echo '<div class="col-md-11">';
echo '<img src="#" id="image" alt="" width="auto" class="img-responsive center-block" >';
echo '<br><div class="image-title">' . $title . '</div>';
echo '</div>'; // Col
// Next Picture
echo '<div class="col-md-1 text-right" style="z-index:100">';
echo '<img src="loading.gif" style="display:none;"; id="loading" alt="" width="auto" height="auto" >';
echo ' </div>'; // Col
echo '</div>'; //<!-- Row -->
echo '<div id="slider" class="row">';
foreach($thumbnails as $key=>$val) {
if ($key % 6 == 0) { // bootstrap column
//echo ' style="display:none" ';
echo '</div>';
echo '<div class="row" style="margin-top:5%;">';
}
echo '<div class="col-md-2" >';
// echo '>';
// Thumbnail should only be visible if...
echo ' <img src="'.$val.'" class="thmb" id="thumbnail-'.$key;
echo '" alt="" width="auto" height="auto" onclick="getImage('. $key .')"';
echo ' class="img-responsive center-block" >';
echo '</div>';// col
}
echo '</div>'; // Row
?>
</div><!-- Container -->
<?php include("footer.php");?>
<script type="text/javascript">
var index = 0;
var size = "<?php echo $size ?>";
function next() {
console.log('next');
index = checkBounds(index, size, 1);
getImage(index);
}
function prev() {
console.log('prev');
index = checkBounds(index, size, -1);
getImage(index);
}
function checkBounds(idx, sze, inc) {
idx += inc;
if (idx == sze) {
return 0;
} else if (idx == -2) {
return sze - 2;
} else {
return idx;
}
}
function getImage(idx) {
// FIXME: add loading
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("image").src = this.responseText;
document.getElementById("loading").display = "none";
index = idx; // when called from thumbnail tabs
var thumbs = document.getElementsByClassName("thmb");
for (var i = 0; i < thumbs.length; i++) {
thumbs[i].style.boxShadow = "";
}
if (idx == -1) {idx = thumbs.length}
thumbs[idx].style.boxShadow = "inset 0 0 1em black, 0 0 1em white";
}
};
xmlhttp.open("GET","<?php echo $src ?>" + idx, true);
xmlhttp.send();
document.getElementById("loading").display = "block";
}
getImage(0);
document.addEventListener("keydown", function (e) {
if (e.keyCode == 37){
prev();
} else if (e.keyCode == 39) {
next();
}
});
</script>
</body>
</html>