-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
90 lines (82 loc) · 3.48 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
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="root">
<div class="row">
<form action="" method="get">
<label for="folder">Folder:</label>
<input
type="text"
id="folder"
name="folder"
value="<?php
require_once 'functions.php';
echo getFromQueryStringOrDie('folder');
?>"
>
<label for="numColumns">Columns:</label>
<input
type="number"
id="numColumns"
name="columns"
value="<?php
require_once 'functions.php';
global $DEFAULT_COLUMNS;
echo getFromQueryStringOrDefault('columns', $DEFAULT_COLUMNS);
?>"
>
<button type="submit">Reload</button>
</form>
</div>
<div class="row">
<?php
require_once 'functions.php';
$directory = $_SERVER['DOCUMENT_ROOT'] . '/' . getFromQueryStringOrDie('folder');
$lastChar = substr($directory, -1);
if ($lastChar !== '/' && $lastChar !== '\\') {
$directory .= '/';
}
if (!is_dir($directory)) {
exit("Directory not found: " . $directory);
}
global $DEFAULT_COLUMNS;
$numColumns = $DEFAULT_COLUMNS;
if (isset($_GET['columns'])) {
$numColumns = intval($_GET['columns']);
}
$mediaInfoList = createMediaInfoList($directory);
$thumbDir = $directory . '__thumbs/';
$mediaInfoList = addThumbnails($mediaInfoList, $thumbDir);
sortInPlaceByModifiedTimeNewestFirst($mediaInfoList);
$columns = splitIntoColumns($mediaInfoList, $numColumns);
// Generates the html for the columns and the media they contain
foreach ($columns as $mediaColumn) {
echo '<div class="column">';
foreach ($mediaColumn as $mediaInfo) {
$url = convertPathToUrl($mediaInfo['path']);
if ($mediaInfo['mediaType'] === "image") {
$imageSrc = "src=\"$url\"";
$imageOptions = 'loading="lazy"';
echo "<img $imageSrc $imageOptions>";
}
else if ($mediaInfo['mediaType'] === "video") {
$videoSrc = "src=\"$url\"";
$videoOptions = 'controls="true" preload="none"';
$videoPoster = '';
if (isset($mediaInfo['thumbpath'])) {
$thumbpath = convertPathToUrl($mediaInfo['thumbpath']);
$videoPoster = "poster=\"$thumbpath\"";
}
echo "<video $videoSrc $videoPoster $videoOptions></video>";
}
}
echo '</div>';
}
?>
</div>
</div>
</body>
</html>