LeJournalDuGeekBridge.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. class LeJournalDuGeekBridge extends BridgeAbstract{
  3. public function loadMetadatas() {
  4. $this->maintainer = "polopollo";
  5. $this->name = "journaldugeek.com (FR)";
  6. $this->uri = "http://www.journaldugeek.com/";
  7. $this->description = "Returns the 5 newest posts from LeJournalDuGeek (full text).";
  8. $this->update = "2014-07-14";
  9. }
  10. public function collectData(array $param){
  11. function LeJournalDuGeekStripCDATA($string) {
  12. $string = str_replace('<![CDATA[', '', $string);
  13. $string = str_replace(']]>', '', $string);
  14. return $string;
  15. }
  16. function LeJournalDuGeekExtractContent($url) {
  17. $articleHTMLContent = $this->file_get_html($url);
  18. $text = $text.$articleHTMLContent->find('div.post-content', 0)->innertext;
  19. foreach($articleHTMLContent->find('a.more') as $element) {
  20. if ($element->innertext == "Source") {
  21. $text = $text.'<p><a href="'.$element->href.'">Source : '.$element->href.'</a></p>';
  22. break;
  23. }
  24. }
  25. foreach($articleHTMLContent->find('iframe') as $element) {
  26. if (preg_match("/youtube/i", $element->src)) {
  27. $text = $text.'// An IFRAME to Youtube was included in the article: <a href="'.$element->src.'">'.$element->src.'</a><br>';
  28. }
  29. }
  30. $text = strip_tags($text, '<p><b><a><blockquote><img><em><br/><br><ul><li>');
  31. return $text;
  32. }
  33. $rssFeed = $this->file_get_html('http://www.journaldugeek.com/rss') or $this->returnError('Could not request http://www.journaldugeek.com/rss', 404);
  34. $limit = 0;
  35. foreach($rssFeed->find('item') as $element) {
  36. if($limit < 5) {
  37. $item = new \Item();
  38. $item->title = LeJournalDuGeekStripCDATA($element->find('title', 0)->innertext);
  39. $item->uri = LeJournalDuGeekStripCDATA($element->find('guid', 0)->plaintext);
  40. $item->timestamp = strtotime($element->find('pubDate', 0)->plaintext);
  41. $item->content = LeJournalDuGeekExtractContent($item->uri);
  42. $this->items[] = $item;
  43. $limit++;
  44. }
  45. }
  46. }
  47. public function getName(){
  48. return 'LeJournalDuGeek';
  49. }
  50. public function getURI(){
  51. return 'http://www.journaldugeek.com/';
  52. }
  53. public function getCacheDuration(){
  54. return 1800; // 30min
  55. }
  56. }