WikipediaDEBridge.php 1.6 KB

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