Address changes.

This commit is contained in:
Cody Cook 2025-02-22 17:20:19 -08:00
commit 635b3ddcbc
59 changed files with 7249 additions and 2745 deletions

110
rss.php
View file

@ -1,2 +1,112 @@
<?php
require_once 'includes/globals.php';
require_once 'vendor/autoload.php';
use DJMixHosting\RSS;
use DJMixHosting\DJ;
use DJMixHosting\Mixshow;
use DJMixHosting\Genre;
// Use your site configuration variables (defined in config.php)
$serverName = $config['app']['name'];
$serverUrl = $config['app']['url'];
// Set default channel information
$channelTitle = $serverName;
$channelDescription = "RSS feed for " . $serverName;
// Instantiate the RSS object
$rss = new RSS($channelTitle, $serverUrl, $channelDescription);
// Check if a mode and slug are provided via the rewritten URLs.
if (isset($_GET['mode']) && isset($_GET['slug'])) {
$mode = $_GET['mode'];
$slug = $_GET['slug'];
if ($mode === 'dj') {
// Load DJ using the new class.
$dj = new DJ($slug, $db);
if ($dj->getID() > 0) {
$channelTitle = $dj->getName() . " | " . $serverName;
$rss = new RSS($channelTitle, $serverUrl, "RSS feed for " . $channelTitle);
// Retrieve mixes for the DJ.
$mixes = $dj->getDJMixes();
foreach ($mixes as $mix) {
$title = $mix['title'] ?? (isset($mix['details']['title']) ? $mix['details']['title'] : "New Untitled Mix");
$description = (!empty($mix['description'])) ? $mix['description'] :
(isset($mix['details']['description']) ? $mix['details']['description'] : $title . " is a mix hosted on " . $serverName);
$link = $serverUrl . 'mix/' . $mix['slug'] . '/';
$pubDate = $mix['recorded'] ?? ($mix['created'] ?? '2008-01-01 12:00:00');
$rss->addItem($title, $description, $link, $pubDate);
}
}
} elseif ($mode === 'mixshow') {
// Load Mixshow using the new class.
$mixshow = new Mixshow($slug, $db);
if ($mixshow->get_id() > 0) {
$channelTitle = $mixshow->get_name() . " | " . $serverName;
$rss = new RSS($channelTitle, $serverUrl, "RSS feed for " . $channelTitle);
// The mixshow object returns an array of mix IDs.
$mixIDs = $mixshow->get_mixes(); // Each element should contain 'mix_id'
foreach ($mixIDs as $mixData) {
$mixID = $mixData['mix_id'];
// getMixByID() should be defined to return a mixs details as an associative array.
$mix = getMixByID($mixID);
if ($mix) {
$title = $mix['title'] ?? (isset($mix['details']['title']) ? $mix['details']['title'] : "New Untitled Mix");
$description = (!empty($mix['description'])) ? $mix['description'] :
(isset($mix['details']['description']) ? $mix['details']['description'] : $title . " is a mix hosted on " . $serverName);
$link = $serverUrl . 'mix/' . $mix['slug'] . '/';
$pubDate = $mix['recorded'] ?? ($mix['created'] ?? '2008-01-01 12:00:00');
$rss->addItem($title, $description, $link, $pubDate);
}
}
}
} elseif ($mode === 'genre') {
// For genres, we assume helper functions exist.
$genre = getGenreSlug($slug); // Should return an associative array with at least 'id' and 'genre'
if (!empty($genre['id'])) {
$channelTitle = $genre['genre'] . " | " . $serverName;
$rss = new RSS($channelTitle, $serverUrl, "RSS feed for " . $channelTitle);
// getMoreMixesByGenre() should return an array of mixes.
$mixes = array_reverse(getMoreMixesByGenre($genre['id']));
foreach ($mixes as $mix) {
$title = $mix['title'] ?? (isset($mix['details']['title']) ? $mix['details']['title'] : "New Untitled Mix");
$description = (!empty($mix['description'])) ? $mix['description'] :
(isset($mix['details']['description']) ? $mix['details']['description'] : $title . " is a mix hosted on " . $serverName);
$link = $serverUrl . 'mix/' . $mix['slug'] . '/';
$pubDate = $mix['recorded'] ?? ($mix['created'] ?? '2008-01-01 12:00:00');
$rss->addItem($title, $description, $link, $pubDate);
}
}
} else {
// Unknown mode fallback to all mixes.
$mixes = getAllMix();
foreach ($mixes as $mix) {
$title = $mix['title'] ?? (isset($mix['details']['title']) ? $mix['details']['title'] : "New Untitled Mix");
$description = (!empty($mix['description'])) ? $mix['description'] :
(isset($mix['details']['description']) ? $mix['details']['description'] : $title . " is a mix hosted on " . $serverName);
$link = $serverUrl . 'mix/' . $mix['slug'] . '/';
$pubDate = $mix['recorded'] ?? ($mix['created'] ?? '2008-01-01 12:00:00');
$rss->addItem($title, $description, $link, $pubDate);
}
}
} else {
// No mode provided default to a feed of all mixes.
$mixes = getAllMix();
foreach ($mixes as $mix) {
$title = $mix['title'] ?? (isset($mix['details']['title']) ? $mix['details']['title'] : "New Untitled Mix");
$description = (!empty($mix['description'])) ? $mix['description'] :
(isset($mix['details']['description']) ? $mix['details']['description'] : $title . " is a mix hosted on " . $serverName);
$link = $serverUrl . 'mix/' . $mix['slug'] . '/';
$pubDate = $mix['recorded'] ?? ($mix['created'] ?? '2008-01-01 12:00:00');
$rss->addItem($title, $description, $link, $pubDate);
}
}
// Set the appropriate header and output the RSS XML.
header("Content-type: application/rss+xml");
echo $rss->generateXML();