LeMondeInformatiqueBridge.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. private function stripCDATA($string){
  20. $string = str_replace('<![CDATA[', '', $string);
  21. $string = str_replace(']]>', '', $string);
  22. return $string;
  23. }
  24. private 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. }
  30. return $string;
  31. }
  32. private function cleanArticle($article_html){
  33. $article_html = $this->stripWithDelimiters($article_html, '<script', '</script>');
  34. $article_html = $this->stripWithDelimiters($article_html, '<h1 class="cleanprint-title"', '</h1>');
  35. return $article_html;
  36. }
  37. }