-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
105 lines (75 loc) · 2.1 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
<?php
$audioDir = 'audio';
$imageDir = 'images';
$audioLabelMap = get_audio_labels("audio_labels.json");
$audioFiles = scan_files($audioDir, "filter_audio");
$imageFiles = scan_files($imageDir, "filter_image");
function get_audio_labels($file) {
$fileData = file_get_contents($file);
$labelMap = json_decode($fileData);
return $labelMap;
}
function filter_image($fileName) {
return preg_match("/.+\.jpg$/i", $fileName);
}
function filter_audio($fileName) {
return preg_match("/.+\.mp3$/i", $fileName);
}
function scan_files($dir, $filter) {
$files = array_slice(scandir($dir), 2);
$filtered = array_filter($files, $filter);
$pathed = Array();
foreach ($filtered as $file) {
$pathed[] = join_paths($dir, $file);
}
return $pathed;
}
function join_paths() {
$paths = array();
foreach (func_get_args() as $arg) {
if ($arg !== '') { $paths[] = $arg; }
}
$path = preg_replace('#/+#','/', join('/', $paths));
return $path;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Rick & Morty Soundboard</title>
<meta charset="UTF-8">
<meta name="description" content="Grass tastes bad">
<meta name="keywords" content="Soundboard, Rick and Morty">
<meta name="author" content="ryunp">
<link rel="shortcut icon" href="favicon.ico" />
<script type="text/javascript" src="js/images.js"></script>
<script type="text/javascript" src="js/audio.js"></script>
<link rel="stylesheet" type="text/css" href="css/normalize.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<div id="imageDisplay" data-files="<?php echo join(",", $imageFiles); ?>">
<div id="image"></div>
</div>
<div id="logDisplay">
<div id="log"></div>
</div>
<div id="audioDisplay">
<div id="audioContainer">
<?php
foreach ($audioFiles as $file) {
$data = "data-file=\"{$file}\"";
$fileName = basename($file);
$text = ($audioLabelMap->$fileName) ? $audioLabelMap->$fileName : $fileName;
$html = "<div class=\"audio\" {$data}>{$text}</div>";
echo $html;
}
?>
</div>
</div>
<script>
initAudio();
initImages();
</script>
</body>
</html>