WikipediaENBridge.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /**
  3. * RssBridgeWikipediaEN
  4. * Retrieve latest highlighted articles from Wikipedia in English.
  5. *
  6. * @name Wikipedia EN "Today's Featured Article..."
  7. * @description Returns the highlighted en.wikipedia.org article.
  8. * @maintainer gsurrel
  9. */
  10. class WikipediaENBridge extends BridgeAbstract{
  11. public function collectData(array $param){
  12. $html = '';
  13. $host = 'http://en.wikipedia.org';
  14. // If you want HTTPS access instead, uncomment the following line:
  15. //$host = 'https://en.wikipedia.org';
  16. $link = '/wiki/Main_Page';
  17. $html = file_get_html($host.$link) or $this->returnError('Could not request Wikipedia EN.', 404);
  18. $element = $html->find('div[id=mp-tfa]', 0);
  19. // Clean the bottom of the featured article
  20. $element->find('div', -1)->outertext = '';
  21. $item = new \Item();
  22. $item->uri = $host.$element->find('p', 0)->find('a', 0)->href;
  23. $item->title = $element->find('p',0)->find('a',0)->title;
  24. $item->content = str_replace('href="/', 'href="'.$host.'/', $element->innertext);
  25. $this->items[] = $item;
  26. }
  27. public function getName(){
  28. return 'Wikipedia EN "Today\'s Featued Article"';
  29. }
  30. public function getURI(){
  31. return 'https://en.wikipedia.org/wiki/Main_Page';
  32. }
  33. public function getCacheDuration(){
  34. return 3600*4; // 4 hours
  35. }
  36. }