$b) ? -1 : 1;
}
usort($allvids, 'cmp');
// Fix to include CDATA (from http://stackoverflow.com/a/20511976)
class SimpleXMLElementExtended extends SimpleXMLElement
{
public function addChildWithCDATA($name, $value = null)
{
$new_child = $this->addChild($name);
if (isset($new_child)) {
$node = dom_import_simplexml($new_child);
$no = $node->ownerDocument;
$node->appendChild($no->createCDATASection($value));
}
return $new_child;
}
}
// build the rss
$rss = new SimpleXMLElementExtended('');
$channel = $rss->addChild('channel');
$channel->title = 'Youtube subscriptions for ' . $username;
$channel->link = 'http://www.youtube.com/';
$channel->description = 'YouTube RSS feed generator by Xefir Destiny ; ported from python ytsubs by ali1234 https://github.com/ali1234/ytsubs';
$atom = $channel->addChild('link', null, 'http://www.w3.org/2005/Atom');
$atom->addAttribute('href', 'http://' . $_SERVER['SERVER_NAME'] . dirname($_SERVER['REQUEST_URI']) . '/rss.xml');
$atom->addAttribute('rel', 'self');
// add the most recent
for ($v = 0; $v < $nb_entries; $v++) {
$link = 'http://youtube.com/watch?v=' . $allvids[$v]['id'];
$item = $channel->addChild('item');
$item->link = $link;
$item->addChildWithCDATA('title', $allvids[$v]['snippet']['title']);
$item->addChildWithCDATA('description', '
|
' . str_replace("\n", ' ', htmlentities($allvids[$v]['snippet']['description'])) . ' |
');
$item->guid = $link;
$item->pubDate = date(DATE_RSS, strtotime($allvids[$v]['snippet']['publishedAt']));
$item->addChild('dc:creator', $allvids[$v]['snippet']['channelTitle'], 'http://purl.org/dc/elements/1.1/');
}
$rss->saveXML('rss.xml');
header('Content-Type: application/rss+xml');
echo $rss->asXML();