summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortejr <tejr@sqt.wtf>2018-12-05 20:57:21 +1300
committertejr <tejr@sqt.wtf>2018-12-05 20:57:21 +1300
commitddf9c1296d92b8c00d117c15f19297b44c21a216 (patch)
tree3e7c27842502a819aae00482ab1960c13ea4af24
parentCorrect filename membership check (diff)
downloadsoundboard-ddf9c1296d92b8c00d117c15f19297b44c21a216.tar.gz
soundboard-ddf9c1296d92b8c00d117c15f19297b44c21a216.zip
A bit more yak shaving
-rw-r--r--index.php32
1 files changed, 21 insertions, 11 deletions
diff --git a/index.php b/index.php
index 636a220..cad311f 100644
--- a/index.php
+++ b/index.php
@@ -26,7 +26,7 @@ if (isset($_FILES['new'])) {
exit;
}
-$files = glob('sounds/'.$l.'*.mp3');
+$files = glob('sounds/*.mp3');
usort($files, function ($a, $b) {
return filemtime($a) < filemtime($b);
});
@@ -34,8 +34,16 @@ $news = array_slice(array_map(function ($fn) {
return basename($fn, '.mp3');
}, $files), 0, 20);
+$sounds = [];
+$indices = array_merge(range('a','z'), ['0-9']);
+foreach ($indices as $index) {
+ $sounds[$index] = array_map(function ($index) {
+ return basename($index, '.mp3');
+ }, glob("sounds/[$index]*.mp3"));
+}
+
// escape
-function h($s) {
+function html($s) {
return htmlspecialchars($s, ENT_QUOTES|ENT_HTML5, 'UTF-8');
}
@@ -70,19 +78,21 @@ function h($s) {
<p style="font-size:0.8em;">
<strong>Newest:</strong>
<?=implode(', ', array_map(function ($fn) {
- return h($fn);
+ return html($fn);
}, $news))?>
</p>
-<?php foreach (array_merge(range('a','z'), array('[0-9]')) as $l): ?>
-<?php $fns = glob('sounds/'.$l.'*.mp3'); ?>
-<?php if ($fns): ?>
- <section>
- <h2><?=h($l)?></h2>
-<?php foreach ($fns as $fn): ?>
- <button><?=h(basename($fn, '.mp3'))?></button>
+ <p>
+<?php foreach (array_keys($sounds) as $index): ?>
+ <a href="#<?=html($index)?>"><?=html($index)?></a>
+<?php endforeach; ?>
+ </p>
+<?php foreach (array_keys($sounds) as $index): ?>
+ <section id="<?=html($index)?>">
+ <h2><?=html($index)?></h2>
+<?php foreach ($sounds[$index] as $sound): ?>
+ <button><?=html(basename($sound, '.mp3'))?></button>
<?php endforeach; ?>
</section>
-<?php endif; ?>
<?php endforeach; ?>
</body>
</html>