Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. class rss_php {
  2.  
  3. public $document;
  4. public $channel;
  5. public $items;
  6.  
  7. /****************************
  8. public load methods
  9. ***/
  10. # load RSS by URL
  11. public function load($url=false, $unblock=true) {
  12. if($url) {
  13. if($unblock) {
  14. $this->loadParser(file_get_contents($url, false, $this->randomContext()));
  15. } else {
  16. $this->loadParser(file_get_contents($url));
  17. }
  18. }
  19. }
  20. # load raw RSS data
  21. public function loadRSS($rawxml=false) {
  22. if($rawxml) {
  23. $this->loadParser($rawxml);
  24. }
  25. }
  26.  
  27. /****************************
  28. public load methods
  29. @param $includeAttributes BOOLEAN
  30. return array; ***/
  31.  
  32. # return full rss array
  33. public function getRSS($includeAttributes=false) {
  34. if($includeAttributes) {
  35. return $this->document;
  36. }
  37. return $this->valueReturner();
  38. }
  39. # return channel data
  40. public function getChannel($includeAttributes=false) {
  41. if($includeAttributes) {
  42. return $this->channel;
  43. }
  44. return $this->valueReturner($this->channel);
  45. }
  46. # return rss items
  47. public function getItems($includeAttributes=false) {
  48. if($includeAttributes) {
  49. return $this->items;
  50. }
  51. return $this->valueReturner($this->items);
  52. }
  53.  
  54. function get_rss($url, $lang, $articles) {
  55. $rss = new rss_php;
  56. $rss->load($url);
  57. $items = $rss->getItems();
  58.  
  59. // Sets the maximum items to be listed
  60. $max_items = $articles;
  61.  
  62. $count = 0;
  63.  
  64. $html = '';
  65. // Translates months to swedish
  66. foreach($items as $index => $item) {
  67. $pubdateForeignString = substr($item['pubDate'], 4);
  68. $pubdateEnglishString = str_replace(array('maj', 'okt'), array('may', 'oct'), $pubdateForeignString);
  69. $pubdate = date("Y-m-d", strtotime($pubdateEnglishString));
  70.  
  71. $html .= '
  72. <ul class="rssList">
  73. <li class="itemTitle"><a href="'.$item['link'].'" title="'.$item['title'].'" rel="external"><h2>'.$item['title'].'</h2></a></li>
  74. <li class="itemText">'.$item['description'].'</li>
  75. <li class="itemLink"><a href="'.$item['link'].'" title="'.$item['title'].'" rel="external" class="readmore">Läs mer</a><em>Publicerad: '.$pubdate.'</em></li>
  76. </ul>';
  77. $count++; //Increase the value of the count by 1
  78. if($count==$max_items) break; //Break the loop is count is equal to the max_loop
  79. }
  80. echo $html;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement