1
0

LeJournalDuGeekBridge.php 2.5 KB

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