LeJournalDuGeekBridge.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 = "2016-08-06";
  9. }
  10. private function LeJournalDuGeekStripCDATA($string) {
  11. $string = str_replace('<![CDATA[', '', $string);
  12. $string = str_replace(']]>', '', $string);
  13. return $string;
  14. }
  15. private function LeJournalDuGeekExtractContent($url) {
  16. $articleHTMLContent = $this->file_get_html($url);
  17. $text = $articleHTMLContent->find('div.post-content', 0)->innertext;
  18. foreach($articleHTMLContent->find('a.more') as $element) {
  19. if ($element->innertext == "Source") {
  20. $text = $text . '<p><a href="' . $element->href . '">Source : ' . $element->href . '</a></p>';
  21. break;
  22. }
  23. }
  24. foreach($articleHTMLContent->find('iframe') as $element) {
  25. if (preg_match("/youtube/i", $element->src)) {
  26. $text = $text . '// An IFRAME to Youtube was included in the article: <a href="' . $element->src . '">' . $element->src . '</a><br>';
  27. }
  28. }
  29. $text = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $text);
  30. $text = strip_tags($text, '<p><b><a><blockquote><img><em><br/><br><ul><li>');
  31. return $text;
  32. }
  33. public function collectData(array $param){
  34. $rssFeed = $this->file_get_html('http://www.journaldugeek.com/rss') or $this->returnError('Could not request http://www.journaldugeek.com/rss', 404);
  35. $limit = 0;
  36. foreach($rssFeed->find('item') as $element) {
  37. if($limit < 5) {
  38. $item = new \Item();
  39. $item->title = $this->LeJournalDuGeekStripCDATA($element->find('title', 0)->innertext);
  40. $item->uri = $this->LeJournalDuGeekStripCDATA($element->find('guid', 0)->plaintext);
  41. $item->timestamp = strtotime($element->find('pubDate', 0)->plaintext);
  42. $item->content = $this->LeJournalDuGeekExtractContent($item->uri);
  43. $this->items[] = $item;
  44. $limit++;
  45. }
  46. }
  47. }
  48. public function getName(){
  49. return 'LeJournalDuGeek';
  50. }
  51. public function getURI(){
  52. return 'http://www.journaldugeek.com/';
  53. }
  54. public function getCacheDuration(){
  55. return 1800; // 30min
  56. }
  57. }