WikipediaENBridge.php 1.4 KB

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