LeMondeInformatiqueBridge.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. class LeMondeInformatiqueBridge extends FeedExpander {
  3. const MAINTAINER = "ORelio";
  4. const NAME = "Le Monde Informatique";
  5. const URI = "http://www.lemondeinformatique.fr/";
  6. const DESCRIPTION = "Returns the newest articles.";
  7. public function collectData(){
  8. $this->collectExpandableDatas(self::URI . 'rss/rss.xml', 10);
  9. }
  10. protected function parseItem($newsItem){
  11. $item = parent::parseItem($newsItem);
  12. $article_html = getSimpleHTMLDOMCached($item['uri'])
  13. or returnServerError('Could not request LeMondeInformatique: ' . $item['uri']);
  14. $item['content'] = $this->CleanArticle($article_html->find('div#article', 0)->innertext);
  15. $item['title'] = $article_html->find('h1.cleanprint-title', 0)->plaintext;
  16. return $item;
  17. }
  18. function StripCDATA($string) {
  19. $string = str_replace('<![CDATA[', '', $string);
  20. $string = str_replace(']]>', '', $string);
  21. return $string;
  22. }
  23. function StripWithDelimiters($string, $start, $end) {
  24. while (strpos($string, $start) !== false) {
  25. $section_to_remove = substr($string, strpos($string, $start));
  26. $section_to_remove = substr($section_to_remove, 0, strpos($section_to_remove, $end) + strlen($end));
  27. $string = str_replace($section_to_remove, '', $string);
  28. } return $string;
  29. }
  30. function CleanArticle($article_html) {
  31. $article_html = $this->StripWithDelimiters($article_html, '<script', '</script>');
  32. $article_html = $this->StripWithDelimiters($article_html, '<h1 class="cleanprint-title"', '</h1>');
  33. return $article_html;
  34. }
  35. public function getCacheDuration() {
  36. return 1800; // 30 minutes
  37. }
  38. }