1
0

WikipediaENBridge.php 1.4 KB

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