summaryrefslogtreecommitdiff
path: root/lib/bbcnext.php
diff options
context:
space:
mode:
authorjade (winter)2025-12-05 00:34:03 +0000
committerjade (winter)2025-12-05 00:34:03 +0000
commit92d27365cadbd98e6d709673cd0729de8793c494 (patch)
treee7ac18fab25957d39745a865ef269f6b6733f15a /lib/bbcnext.php
initial commit
Diffstat (limited to 'lib/bbcnext.php')
-rw-r--r--lib/bbcnext.php109
1 files changed, 109 insertions, 0 deletions
diff --git a/lib/bbcnext.php b/lib/bbcnext.php
new file mode 100644
index 0000000..988d248
--- /dev/null
+++ b/lib/bbcnext.php
@@ -0,0 +1,109 @@
+<?php
+
+require_once __DIR__ . '/rms.php';
+
+function next_renderFromRms(string $path) {
+ next_renderExperience(rms_fetch($path)->data);
+}
+
+function next_renderExperience(array $modules) {
+ foreach ($modules as $m) {
+ next_renderModule($m);
+ }
+}
+
+function next_renderModule(stdClass $module) {
+ $type = strtr($module->type, '_', '-');
+ $titleTag = $type == 'inline-header-module' ? 'h1' : 'h2';
+ echo "<$type id=\"$module->id\" module-style=\"$module->style\">";
+ echo "<$titleTag>"
+ . htmlspecialchars($module->title ?? '[no title]')
+ . "</$titleTag>";
+ if (isset($module->description)) {
+ echo '<module-description>'
+ . htmlspecialchars($module->description)
+ . '</module-description>';
+ }
+ echo '<module-items>';
+ if (!is_array($module->data)) {
+ next_renderItem($module->data);
+ } else {
+ foreach ($module->data as $item) {
+ next_renderItem($item);
+ }
+ }
+ echo "</module-items></$type>";
+}
+
+function next_renderItem(stdClass $item) {
+ $type = strtr($item->type, '_', '-');
+ $primaryTag = $type == 'segment-item' ? 'primary-title' : 'h3';
+ echo "<$type id=\"$item->id\">";
+ echo '<item-titles><item-first-titles>';
+ echo "<$primaryTag>"
+ . htmlspecialchars($item->titles?->primary ?? '[no primary]')
+ . "</$primaryTag>";
+ if (isset($item->network)) {
+ echo '<item-network>'
+ . htmlspecialchars($item->network->short_title)
+ . '</item-network>';
+ }
+ echo '</item-first-titles>';
+ if (isset($item->titles->secondary)) {
+ echo '<secondary-title>'
+ . htmlspecialchars($item->titles->secondary)
+ . '</secondary-title>';
+ }
+ if (isset($item->titles->tertiary)) {
+ echo '<tertiary-title>'
+ . htmlspecialchars($item->titles->tertiary)
+ . '</tertiary-title>';
+ }
+ echo '</item-titles>';
+ if (isset($item->synopses?->short, $item->synopses?->medium)) {
+ echo '<synopsis><details><summary>'
+ . htmlspecialchars($item->synopses->short)
+ . '</summary>'
+ . htmlspecialchars($item->synopses->long ?? $item->synopses->medium)
+ . '</details></synopsis>';
+ } elseif (isset($item->synopses?->short)) {
+ echo '<synopsis>' . htmlspecialchars($item->synopses->short)
+ . '</synopsis>';
+ }
+
+ if (isset($item->item)) {
+ next_renderItem($item->item);
+ }
+
+ if (isset($item->offset)) {
+ echo '<offset-start>'
+ . gmdate('H:i:s', $item->offset->start)
+ . '</offset-start>';
+ echo '<offset-end>'
+ . gmdate('H:i:s', $item->offset->end)
+ . '</offset-end>';
+ }
+
+ if ($type == 'container-item') {
+ $href = '?path=' . RMS_SOUNDS_CONTAINER . '/' . $item->urn;
+ echo "<a href=\"$href\">View</a>";
+ } elseif ($type == 'playable-item') {
+ $pid = explode(':', $item->urn)[4];
+ $href = '?path=' . RMS_SOUNDS_PLAYABLE . '/' . $pid;
+ echo "<a href=\"$href\">Listen</a>";
+ }
+
+ foreach ($item->uris ?? [] as $uri) {
+ if ($uri->type != 'link') continue;
+ echo '<a href="' . htmlspecialchars($uri->uri) . '" target="_blank">'
+ . htmlspecialchars($uri->label) . '</a>';
+ }
+
+ if (isset($item->download) && $item->download->type == 'non_drm') {
+ $variant = $item->download->quality_variants->high;
+ echo '<a href="' . htmlspecialchars($variant->file_url) . '">'
+ . "Download ($variant->label)</a>";
+ }
+
+ echo "</$type>";
+}