LeMotDuJourBridge.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. class LeMotDuJourBridge extends BridgeAbstract{
  3. public function loadMetadatas() {
  4. $this->maintainer = "qwertygc";
  5. $this->name = "LeMotDuJour Bridge";
  6. $this->uri = "http://www.lemotdujour.com/";
  7. $this->description = "Returns the newest articles.";
  8. $this->update = "2014-05-25";
  9. }
  10. public function collectData(array $param){
  11. function StripCDATA($string) {
  12. $string = str_replace('<![CDATA[', '', $string);
  13. $string = str_replace(']]>', '', $string);
  14. return $string;
  15. }
  16. function ExtractContent($url) {
  17. $html2 = file_get_html($url);
  18. $text = $html2->find('div.single-contenu', 0)->innertext;
  19. return $text;
  20. }
  21. $html = file_get_html('http://feeds2.feedburner.com/lemotdujour/lemotdujour') or $this->returnError('Could not request LeMotDuJour.', 404);
  22. $limit = 0;
  23. foreach($html->find('item') as $element) {
  24. if($limit < 10) {
  25. $item = new \Item();
  26. $item->title = StripCDATA($element->find('title', 0)->innertext);
  27. $item->uri = StripCDATA($element->find('guid', 0)->plaintext);
  28. $item->timestamp = strtotime($element->find('pubDate', 0)->plaintext);
  29. $item->content = ExtractContent($item->uri);
  30. $this->items[] = $item;
  31. $limit++;
  32. }
  33. }
  34. }
  35. public function getName(){
  36. return 'LeMotDuJour Bridge';
  37. }
  38. public function getURI(){
  39. return 'http://lemotdujour.com/';
  40. }
  41. public function getCacheDuration(){
  42. return 3600*2; // 2 hours
  43. // return 0; // 2 hours
  44. }
  45. }