-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
112 lines (105 loc) · 3.6 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
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
<?php
/*
* fliegwerk mediacenter
* by fliegwerk
* (c) 2020. MIT License
*/
require "config.php";
require "search.php";
$movies_path = glob("movies/*");
function get_json_from_file($path) {
return file_exists($path) ?
json_decode(file_get_contents($path)) : (object)[];
}
?>
<!doctype html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="robots" content="noindex, nofollow">
<title>Mediathek</title>
<link href="main.css" type="text/css" rel="stylesheet">
</head>
<body>
<header>
<h1>Mediathek</h1>
<form method="get">
<label for="search">Suche nach:</label>
<input type="search" id="search" name="<?= GET_PARAM_NAME_QUERY ?>"
placeholder="James Bond" value="<?= htmlspecialchars($_GET[GET_PARAM_NAME_QUERY] ?? "") ?>">
<button type="submit">Suchen</button>
</form>
</header>
<?php
if (isset($_GET[GET_PARAM_NAME_VIDEO])):
?>
<main>
<?php
$movie_path = urldecode($_GET[GET_PARAM_NAME_VIDEO]);
$found = array_search($movie_path, $movies_path);
if ($found !== false):
$data = get_json_from_file($movie_path . "/data.json");
$badges = $data->badges ?? [];
?>
<video width="100%" controls preload="metadata"
src="<?= $movie_path ?>/video.mp4" poster="<?= $movie_path ?>/artwork.jpg">
</video>
<h2><?= $data->title ?? "Unbekannter Titel" ?><br><span><?= $data->subtitle ?? "" ?></span></h2>
<p><?= empty($data->release) ? "Unbekannt" :
DateTime::createFromFormat(DateTime::ISO8601, $data->release)->format("Y") ?>:
<i><?= $data->director ?? "Unbekannter Regisseur" ?></i></p>
<p><?= $data->description ?? "N/A" ?></p>
<div>
<?php foreach ($badges as $badge) {
$path = "./badges/$badge.svg";
if (file_exists($path)) {
include $path;
} else {
echo "<!-- Invalid badge: " . htmlspecialchars($badge) . ", file not found: " . htmlspecialchars($path) . " -->";
}
}
?>
</div>
<p><small><?= $data->copyright ?? "" ?></small></p>
<?php else: ?>
<p>Video wurde nicht gefunden</p>
<?php endif; ?>
</main>
<?php endif; ?>
<nav>
<?php
// build combined array
$movies_data = array();
foreach ($movies_path as $movie_path) {
$data = get_json_from_file($movie_path . "/data.json");
$movies_data[] = (object)[
"path" => $movie_path,
"title" => $data->title ?? "Unbekannter Titel",
];
}
$sorted_data = isset($_GET[GET_PARAM_NAME_QUERY]) ?
search($movies_data, $_GET[GET_PARAM_NAME_QUERY]) : $movies_data;
if (count($sorted_data) > 0):
?>
<ul>
<?php foreach ($sorted_data as $movie_data):
?>
<li>
<a href="?<?= GET_PARAM_NAME_VIDEO ?>=<?= urlencode($movie_data->path) ?>">
<img loading="lazy" alt="<?= $movie_data->title ?>"
src="<?= $movie_data->path ?>/cover.jpg">
<span><?= $movie_data->title ?></span>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php else:
?>
<p>Keine Einträge gefunden</p>
<?php endif; ?>
</nav>
</body>
</html>