Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class rss_php {
- public $document;
- public $channel;
- public $items;
- /****************************
- public load methods
- ***/
- # load RSS by URL
- public function load($url=false, $unblock=true) {
- if($url) {
- if($unblock) {
- $this->loadParser(file_get_contents($url, false, $this->randomContext()));
- } else {
- $this->loadParser(file_get_contents($url));
- }
- }
- }
- # load raw RSS data
- public function loadRSS($rawxml=false) {
- if($rawxml) {
- $this->loadParser($rawxml);
- }
- }
- /****************************
- public load methods
- @param $includeAttributes BOOLEAN
- return array; ***/
- # return full rss array
- public function getRSS($includeAttributes=false) {
- if($includeAttributes) {
- return $this->document;
- }
- return $this->valueReturner();
- }
- # return channel data
- public function getChannel($includeAttributes=false) {
- if($includeAttributes) {
- return $this->channel;
- }
- return $this->valueReturner($this->channel);
- }
- # return rss items
- public function getItems($includeAttributes=false) {
- if($includeAttributes) {
- return $this->items;
- }
- return $this->valueReturner($this->items);
- }
- function get_rss($url, $lang, $articles) {
- $rss = new rss_php;
- $rss->load($url);
- $items = $rss->getItems();
- // Sets the maximum items to be listed
- $max_items = $articles;
- $count = 0;
- $html = '';
- // Translates months to swedish
- foreach($items as $index => $item) {
- $pubdateForeignString = substr($item['pubDate'], 4);
- $pubdateEnglishString = str_replace(array('maj', 'okt'), array('may', 'oct'), $pubdateForeignString);
- $pubdate = date("Y-m-d", strtotime($pubdateEnglishString));
- $html .= '
- <ul class="rssList">
- <li class="itemTitle"><a href="'.$item['link'].'" title="'.$item['title'].'" rel="external"><h2>'.$item['title'].'</h2></a></li>
- <li class="itemText">'.$item['description'].'</li>
- <li class="itemLink"><a href="'.$item['link'].'" title="'.$item['title'].'" rel="external" class="readmore">Läs mer</a><em>Publicerad: '.$pubdate.'</em></li>
- </ul>';
- $count++; //Increase the value of the count by 1
- if($count==$max_items) break; //Break the loop is count is equal to the max_loop
- }
- echo $html;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement