WikipediaFRBridge.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. class WikipediaFRBridge extends BridgeAbstract{
  3. public function loadMetadatas() {
  4. $this->maintainer = "gsurrel";
  5. $this->name = "Wikipedia FR 'Lumière sur...'";
  6. $this->uri = "https://fr.wikipedia.org/";
  7. $this->description = "Returns the highlighted fr.wikipedia.org article.";
  8. $this->update = "2016-06-04";
  9. }
  10. public function collectData(array $param){
  11. $html = '';
  12. $host = 'http://fr.wikipedia.org';
  13. // If you want HTTPS access instead, uncomment the following line:
  14. //$host = 'https://fr.wikipedia.org';
  15. $link = '/wiki/Wikip%C3%A9dia:Accueil_principal';
  16. $html = $this->file_get_html($host.$link) or $this->returnError('Could not request Wikipedia FR.', 404);
  17. $element = $html->find('div[id=mf-lumieresur]', 0);
  18. # Use the "Lire la suite" link to dependably get the title of the article
  19. # usually it's a child of a li.BA element (Bon article)
  20. # occasionally it's a li.AdQ (Article de qualité)
  21. $lirelasuite_link = $element->find('.BA > i > a, .AdQ > i > a', 0);
  22. $item = new \Item();
  23. $item->uri = $host.$lirelasuite_link->href;
  24. $item->title = $lirelasuite_link->title;
  25. $item->content = str_replace('href="/', 'href="'.$host.'/', $element->innertext);
  26. $this->items[] = $item;
  27. }
  28. public function getName(){
  29. return 'Wikipedia FR "Lumière sur..."';
  30. }
  31. public function getURI(){
  32. return 'https://fr.wikipedia.org/wiki/Wikip%C3%A9dia:Accueil_principal';
  33. }
  34. public function getCacheDuration(){
  35. return 3600*4; // 4 hours
  36. }
  37. }