Address changes.
This commit is contained in:
parent
a5949e0401
commit
635b3ddcbc
59 changed files with 7249 additions and 2745 deletions
|
@ -1,36 +1,64 @@
|
|||
<?php
|
||||
|
||||
namespace DJMixHosting;
|
||||
|
||||
class RSS
|
||||
{
|
||||
class RSS {
|
||||
private string $channelTitle;
|
||||
private string $channelLink;
|
||||
private string $channelDescription;
|
||||
private array $items = [];
|
||||
private string $pubDateFormat = "D, d M Y H:i:s O";
|
||||
|
||||
private $db;
|
||||
private string $header = '<?xml version="1.0" encoding="UTF-8" ?>';
|
||||
private string $rss = '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"
|
||||
xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
|
||||
xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0">';
|
||||
|
||||
|
||||
private function itemMix($mix)
|
||||
{
|
||||
$output = new Mix($mix, $this->db);
|
||||
|
||||
if ($output->get_recorded() != "") {
|
||||
$pubdate = date('D, d M Y H:i:s O', strtotime($output->get_recorded()));
|
||||
} elseif ($output->get_created() != "") {
|
||||
$pubdate = date('D, d M Y H:i:s O', strtotime($output->get_created()));
|
||||
} else {
|
||||
$pubdate = date('D, d M Y H:i:s O', strtotime('2008-01-01 12:00:00'));
|
||||
}
|
||||
|
||||
echo '<item>';
|
||||
echo '<title>' . $output->get_name() . '</title>';
|
||||
echo '<description>' . $output->get_description() . '</description>';
|
||||
echo '<link>' . $output->get_url() . '</link>';
|
||||
echo '<guid>' . $output->get_slug() . '</guid>';
|
||||
echo '<pubDate>' . $pubdate . '</pubDate>';
|
||||
echo '</item>';
|
||||
public function __construct(string $title, string $link, string $description) {
|
||||
$this->channelTitle = $title;
|
||||
$this->channelLink = $link;
|
||||
$this->channelDescription = $description;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Add an item to the RSS feed.
|
||||
*
|
||||
* @param string $title Item title.
|
||||
* @param string $description Item description.
|
||||
* @param string $link Item URL.
|
||||
* @param string $pubDate A date/time string (accepted by strtotime).
|
||||
*/
|
||||
public function addItem(string $title, string $description, string $link, string $pubDate): void {
|
||||
$this->items[] = [
|
||||
'title' => htmlspecialchars($title),
|
||||
'description' => htmlspecialchars($description),
|
||||
'link' => $link,
|
||||
'guid' => $link,
|
||||
'pubDate' => date($this->pubDateFormat, strtotime($pubDate))
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the complete RSS XML.
|
||||
*
|
||||
* @return string The RSS XML string.
|
||||
*/
|
||||
public function generateXML(): string {
|
||||
$xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
|
||||
$xml .= '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">' . "\n";
|
||||
$xml .= " <channel>\n";
|
||||
$xml .= " <title>{$this->channelTitle}</title>\n";
|
||||
$xml .= " <link>{$this->channelLink}</link>\n";
|
||||
$xml .= " <description>{$this->channelDescription}</description>\n";
|
||||
$xml .= " <lastBuildDate>" . date($this->pubDateFormat) . "</lastBuildDate>\n";
|
||||
// Optionally add additional channel tags here
|
||||
|
||||
foreach ($this->items as $item) {
|
||||
$xml .= " <item>\n";
|
||||
$xml .= " <title>{$item['title']}</title>\n";
|
||||
$xml .= " <description>{$item['description']}</description>\n";
|
||||
$xml .= " <link>{$item['link']}</link>\n";
|
||||
$xml .= " <guid>{$item['guid']}</guid>\n";
|
||||
$xml .= " <pubDate>{$item['pubDate']}</pubDate>\n";
|
||||
$xml .= " </item>\n";
|
||||
}
|
||||
|
||||
$xml .= " </channel>\n";
|
||||
$xml .= "</rss>";
|
||||
return $xml;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue