-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.v-1-0.php
executable file
·393 lines (328 loc) · 10 KB
/
index.v-1-0.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
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
<?php
// ========================================================
// Set The default timezone to GTM London - change this acording your own timezone
// ========================================================
$timeZone = 'Europe/London';
date_default_timezone_set($timeZone);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Smart SandBox</title>
<style>
html, body {
margin: 0;
padding: 0;
font-family: helvetica, arial, sans-serif;
background: #f9f9f9;
}
a, p a {
text-decoration: none;
color: #0984e3;
transition: color 0.4s ease-in-out;
cursor: pointer;
}
a:hover , a:focus {
color: #ff7675;
}
.header {
width: 100%;
height: auto;
position: relative;
background: rgba(250, 177, 160,1.0);
background: -moz-linear-gradient(-45deg, rgba(250, 177, 160,1.0) 0%, rgba(116, 185, 255,1.0) 100%);
background: -webkit-linear-gradient(-45deg, rgba(250, 177, 160,1.0) 0%,rgba(116, 185, 255,1.0) 100%);
background: linear-gradient(135deg, rgba(250, 177, 160,1.0) 0%,rgba(116, 185, 255,1.0) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#fab1a0', endColorstr='#74b9ff',GradientType=1 );
}
.header >.inner {
position: relative;
width: 100%;
max-width: 960px;
height: auto;
text-align: center;
padding: 80px 20px;
margin: 0 auto;
box-sizing: border-box;
color: #EEEEEE;
}
.list {
position: relative;
width: 100%;
margin: 0;
display: inline-block;
}
.list >.list-inner {
width: 100%;
max-width: 960px;
margin: 0 auto;
box-sizing: border-box;
padding: 40px 20px;
}
.list>.sort {
width: 100%;
max-width: 960px;
margin: 0 auto;
box-sizing: border-box;
padding: 20px 20px 10px 20px;
}
#list {
width: 100%;
max-width: 960px;
height: auto;
margin: 0 auto;
padding: 0;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: flex-start;
align-items: stretch;
}
#list .single {
position: relative;
min-width: calc( 20% - 13px );
list-style: none;
float: left;
margin: 5px;
text-align: center;
display: inline-block;
}
#list .single a {
width: 100%;
background: #74b9ff;
border-radius: 5px;
display: inline-block;
padding: 15px 20px;
box-sizing: border-box;
text-decoration: none;
font-weight: lighter;
color: #EEEEEE;
transition: all 0.4s ease-in-out;
}
#list .single a:hover,
#list .single a:focus {
background: #0984e3;
color: #FFFFFF;
}
#list .single a:visited {
background: #a29bfe;
color: #FFFFFF;
}
#list .row-divider {
width: 100%;
box-sizing: border-box;
display: inline-block;
text-transform: uppercase;
font-size: 18px;
font-weight: lighter;
color: #999999;
border-bottom: 1px dashed #0984e3;
padding: 0 0 10px 0;
margin: 10px 0;
}
.search-wrapper {
width: 100%;
text-align: left;
background-color: white;
}
.search-wrapper >.inner {
max-width: 960px;
padding: 20px 20px;
width: 100%;
margin: 0 auto;
box-sizing: border-box;
color: #999999;
text-align: left;
}
#search {
border: none;
background-color: #FFFFFF;
padding: 5px 10px;
font-size: 14px;
text-transform: uppercase;
display: inline-block;
box-sizing: border-box;
width: auto;
min-width: 320px;
}
#search:focus {outline:0 !important;}
footer {
width: 100%;
background-color: white;
padding: 20px;
box-sizing: border-box;
}
footer >.inner {
width: 100%;
max-width: 960px;
margin: 0 auto;
text-align: left;
}
footer >.inner p {
font-size: 10px;
color: #999999;
}
footer >.inner p span {
color: #e74c3c;
}
@media all and (min-width: 320px) and (max-width: 424px) {
#list .single {
width: 100%;
margin: 5px 0;
}
.search-wrapper {
text-align: center;
}
#search {
width: 100%;
}
}
@media all and (min-width: 425px) and (max-width: 767px) {
#list .single {
min-width: calc( 50% - 13px );
}
#search {
width: 80%;
}
.search-wrapper {
text-align: center;
}
}
@media all and (min-width: 768px) and (max-width: 960px) {
#list .single {
min-width: calc( 33.333333% - 13px );
}
}
</style>
</head>
<body>
<div class="header">
<div class="inner">
<h1>Smart Sandbox</h1>
<p>There's no place like 127.0.0.1</p>
</div>
</div>
<div class="search-wrapper">
<div class="inner">
<input id="search" type="text" name="search" placeholder="Search your Projects..." onchange="searchProjects()" />
</div>
</div>
<div class="list">
<div class="sort">sort: <a href="#0" onclick="orderByName()">a-z</a> <a href="#0" onclick="orderByDate()">date</div></a>
<div class="list-inner">
<ul id="list"></ul>
</div>
</div>
<footer>
<div class="inner">
<p>© <?php echo date("Y"); ?>, created with <span>♥</span> by <a href="http://marioduarte.co.uk" target="_blank">Mario Duarte</a> to the dev comunity.</p>
</div>
</footer>
<script>
// creates a holding array for the list folders
var list = [];
// ========================================================
// Search at root level for any folder and loops through each folder converting all characters
// to lower case before pushing to the list array - if you get errors here make sure that apache
// has the right access permitions to the root folder
// ========================================================
<?php $folders = glob("*"); foreach ($folders as $folder){ if(is_dir($folder)){$folder = strtolower($folder); ?>
var obj = {};
obj.name = "<?php echo $folder ?>";
obj.date = "<?php echo date ("ymd", filemtime($folder)); ?>";
list.push(obj);
<?php }} ?>
orderByName();
// On every key press while writing on the search field, it performs a new search and updates
// the displayed list without the alphabetical dividers
document.getElementById('search').onkeypress = function (e) {
searchProjects();
};
//function to order list by name
function orderByName() {
list.sort(compare);
console.table(list);
// sorting function for the object created above
function compare(a,b) {
if (a.name < b.name)
return -1;
if (a.name > b.name)
return 1;
return 0;
}
var listWrapper = document.getElementById('list');
var arrayLength = list.length;
// this array is used to store the first character of the last looped folder name to be used
// to create the alphabetical dividers
var arraySub = [];
listWrapper.innerHTML= "";
// Loop through the array and add the item to the list
for (var i = 0; i < arrayLength; i++) {
var listSubString = list[i]["name"].substring(0, 1);
var lastSub = arraySub[arraySub.length-1];
if ( listSubString != lastSub ) {
listWrapper.innerHTML += "<li class='row-divider " + listSubString + "-row'>" + listSubString + "</li>";
}
arraySub.push(listSubString);
listWrapper.innerHTML += "<li class='single' data-name='" + list[i]["name"] + "' data-last-modified='" + list[i]["date"] + "'><a href='" + list[i]["name"] + "'>" + list[i]["name"].replace(/-/g, " ").replace(/_/g, " ") + "</a></li>";
}
}
// Function to order by date
function orderByDate() {
list.sort(compare);
console.table(list);
// sorting function for the object created above
function compare(a,b) {
if (a.date > b.date)
return -1;
if (a.date < b.date)
return 1;
return 0;
}
var listWrapper = document.getElementById('list');
var arrayLength = list.length;
// this array is used to store the first character of the last looped folder name to be used
// to create the alphabetical dividers
var arraySub = [];
listWrapper.innerHTML= "";
// Loop through the array and add the item to the list
for (var i = 0; i < arrayLength; i++) {
var listSubString = list[i]["name"].substring(0, 1);
var lastSub = arraySub[arraySub.length-1];
// if ( listSubString != lastSub ) {
// listWrapper.innerHTML += "<li class='row-divider " + listSubString + "-row'>" + listSubString + "</li>";
// }
arraySub.push(listSubString);
listWrapper.innerHTML += "<li class='single' data-name='" + list[i]["name"] + "' data-last-modified='" + list[i]["date"] + "'><a href='" + list[i]["name"] + "'>" + list[i]["name"].replace(/-/g, " ").replace(/_/g, " ") + "</a></li>";
}
}
// Function to perform a search on the folder list
function searchProjects() {
var query = document.getElementById('search').value;
var listWrapper = document.getElementById('list');
var arrayLength = list.length;
listWrapper.innerHTML = '';
arraySub = [];
for (var i = 0; i < arrayLength; i++) {
var listSubString = list[i]["name"].substring(0, 1);
var lastSub = arraySub[arraySub.length-1];
// If search field is not empty perform the search, if it's empty show all folders by alphabetical
// order by default
if ( query != '' ) {
if ( list[i]["name"] == query || list[i]["name"].indexOf(query) > -1 ) {
listWrapper.innerHTML += "<li class='single " + listSubString + "-row'><a href='" + list[i]["name"].replace(/-/g, " ").replace(/_/g, " ") + "'>" + list[i]["name"] + "</a></li>";
}
} else {
if ( listSubString != lastSub ) {
listWrapper.innerHTML += "<li class='row-divider " + listSubString + "-row'>" + listSubString + "</li>";
}
listWrapper.innerHTML += "<li class='single " + listSubString + "-row'><a href='" + list[i]["name"] + "'>" + list[i]["name"].replace(/-/g, " ").replace(/_/g, " ") + "</a></li>";
}
arraySub.push(listSubString);
}
}
</script>
</body>
</html>