rendered paste bodyclass RSSParser { public $oXML = false; public $cFeed = false; public $oChannel = false; public $aItems = false; public $aNameSpaces = false; public $cExtFeed = "http://steampowered.com/rss.xml"; public $cFeed = false; function __construct() { $this->getFeed($this->cExtFeed); $this->parseRSS(); } function getFeed($cFeed) { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $cURL); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_USERAGENT, 'Keloran - RSS Reader'); $cContent = curl_exec($curl); curl_close($curl); $this->cFeed = $cContent; } function parseRSS() { if ($this->cFeed) { try { $this->oXML = new SimpleXMLElement($this->cFeed); } catch (Excepton $e) { return false; } } else { return false; } $this->oChannel = $this->oXML->channel ? $this->oXML->channel : $this->oXML->feed; $this->aNameSpaces = $this->oXML->getNamespaces(true); //Feed Details if ($this->oXML->channel) { $this->feedDetails($this->oXML->channel); } else if ($this->oXML->feed) { $this->feedDetails($this->oXML->feed); } else { $this->feedDetails($this->oXML); } //Items, based on the actual feed settings if (is_object($this->oChannel->item) && count($this->oChannel->item)) { $this->setItems($this->oChannel->item); } else if (is_object($this->oChannel->entry) && count($this->oChannel->entry)) { $this->setItems($this->oChannel->entry); } else if (is_object($this->oXML->item) && count($this->oXML->item)) { $this->setItems($this->oXML->item); } else if (is_object($this->oXML->entry) && count($this->oXML->entry)) { $this->setItems($this->oXML->entry); } } function clean($cString) { $aPattern = array('`<!\[CDATA\[(.*?)\]\]>`is'); $aReplace = array('\\1'); $cString = preg_replace($aPattern, $aReplace, $cString); return (string) addslashes($cString); } function setItems($oItems) { foreach ($oItems as $cItem) { //Title if ($cItem->title) { $cTitle = $this->clean($cItem->title); } //Link if ($cItem->link['href']) { $cLink = $this->clean($cItem->link['href']); } else { $cLink = $this->clean($cItem->link); } //Description if ($cItem->description) { $cDescription = $this->clean($cItem->description); } else if ($cItem->summary) { $cDescription = $this->clean($cItem->summary); } else if ($cItem->content) { $nsDC = $cItem->children($aNameSpaces['dc']); $nsContent = $cItem->children($aNameSpaces['content']); if ($nsDC) { $cDescription = $dc->encoded; } else if ($nsContent) { $cDescription = $nsContent->encoded; } else { $cDescription = $cItem->content; } } //Category if ($cItem->category) { $cCategory = $this->clean($cItem->category); } else if ($cItem->author) { if ($cItem->author['name']) { if ($cItem->author['name']) { $cCategory = $this->clean($cItem->author['name']); } else { $cCategory = $this->clean($cItem->author->name); } } else { $cCategory = $this->clean($cItem->author->name); } } else if ($cItem->section) { $cCategory = $this->clean($cItem->section); } //GUID if ($cItem->guid) { $cGUID = $this->clean($cItem->guid); } else if ($cItem->id) { $cGUID = $this->clean($cItem->id); } else { $cGUID = $this->clean($cLink); } //PubDate if ($cItem->pubDate) { $dPubDate = $this->clean($cItem->pubDate); } else if ($cItem->issued) { $dPubDate = $this->clean($cItem->issued); } $this->aItems[] = array( 'Title' => $cTitle, 'Link' => $cLink, 'Description' => $cDescription, 'Category' => $cCategory, 'GUID' => $cGUID, 'PubDate' => $dPubDate, ); } } function feedDetails($oFeed) { //Description if ($oFeed->summary) { $cDescription = $oFeed->summary; } else if ($oFeed->content) { $cDescription = $oFeed->content; } else if ($oFeed->tagline) { $cDescription = $oFeed->tagline; } else { $cDescription = $oFeed->description; } //Image if ($oFeed->image) { if ($oFeed->image['url']) { $cImage = $oFeed->image['url']; } else if ($oFeed->image->url) { $cImage = $oFeed->image->url; } else { $cImage = $oFeed->image; } } else if ($oFeed->url) { if (is_object($oFeed->url)) { $cImage = $oFeed->url['href']; } else { $cImage = $oFeed->url; } } //Pubdate if ($oFeed->updated) { $dPubDate = $oFeed->updated; } else if ($oFeed->modified) { $dPubDate = $oFeed->modified; } else if ($oFeed->pubDate) { $dPubDate = $oFeed->pubDate; } else { $dPubDate = time(); } //Link if ($oFeed->link['href']) { $cLink = $oFeed->link['href']; } else { $cLink = $oFeed->link; } //Title if ($oFeed->title) { $cTitle = $oFeed->title; } $this->aFeed = array( 'Title' => $this->clean($cTitle), 'Description' => $this->clean($cDescription), 'Link' => $this->clean($cLink), 'Image' => $this->clean($cImage), 'pubDate' => $this->clean($dPubDate), ); }}