LeJournalDuGeekBridge.php 2.0 KB

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