LeMondeInformatiqueBridge.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 CACHE_TIMEOUT = 1800; // 30min
  7. const DESCRIPTION = "Returns the newest articles.";
  8. public function collectData(){
  9. $this->collectExpandableDatas(self::URI . 'rss/rss.xml', 10);
  10. }
  11. protected function parseItem($newsItem){
  12. $item = parent::parseItem($newsItem);
  13. $article_html = getSimpleHTMLDOMCached($item['uri'])
  14. or returnServerError('Could not request LeMondeInformatique: ' . $item['uri']);
  15. $item['content'] = $this->CleanArticle($article_html->find('div#article', 0)->innertext);
  16. $item['title'] = $article_html->find('h1.cleanprint-title', 0)->plaintext;
  17. return $item;
  18. }
  19. function StripCDATA($string) {
  20. $string = str_replace('<![CDATA[', '', $string);
  21. $string = str_replace(']]>', '', $string);
  22. return $string;
  23. }
  24. function StripWithDelimiters($string, $start, $end) {
  25. while (strpos($string, $start) !== false) {
  26. $section_to_remove = substr($string, strpos($string, $start));
  27. $section_to_remove = substr($section_to_remove, 0, strpos($section_to_remove, $end) + strlen($end));
  28. $string = str_replace($section_to_remove, '', $string);
  29. } return $string;
  30. }
  31. function CleanArticle($article_html) {
  32. $article_html = $this->StripWithDelimiters($article_html, '<script', '</script>');
  33. $article_html = $this->StripWithDelimiters($article_html, '<h1 class="cleanprint-title"', '</h1>');
  34. return $article_html;
  35. }
  36. }