DeveloppezDotComBridge.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. class DeveloppezDotComBridge extends FeedExpander {
  3. const MAINTAINER = "polopollo";
  4. const NAME = "Developpez.com Actus (FR)";
  5. const URI = "http://www.developpez.com/";
  6. const CACHE_TIMEOUT = 1800; // 30min
  7. const DESCRIPTION = "Returns the 15 newest posts from DeveloppezDotCom (full text).";
  8. public function collectData(){
  9. $this->collectExpandableDatas(self::URI . 'index/rss', 15);
  10. }
  11. protected function parseItem($newsItem){
  12. $item = parent::parseItem($newsItem);
  13. $item['content'] = $this->DeveloppezDotComExtractContent($item['uri']);
  14. return $item;
  15. }
  16. private function DeveloppezDotComStripCDATA($string) {
  17. $string = str_replace('<![CDATA[', '', $string);
  18. $string = str_replace(']]>', '', $string);
  19. return $string;
  20. }
  21. // F***ing quotes from Microsoft Word badly encoded, here was the trick:
  22. // http://stackoverflow.com/questions/1262038/how-to-replace-microsoft-encoded-quotes-in-php
  23. private function convert_smart_quotes($string)
  24. {
  25. $search = array(chr(145),
  26. chr(146),
  27. chr(147),
  28. chr(148),
  29. chr(151));
  30. $replace = array("'",
  31. "'",
  32. '"',
  33. '"',
  34. '-');
  35. return str_replace($search, $replace, $string);
  36. }
  37. private function DeveloppezDotComExtractContent($url) {
  38. $articleHTMLContent = getSimpleHTMLDOMCached($url);
  39. $text = $this->convert_smart_quotes($articleHTMLContent->find('div.content', 0)->innertext);
  40. $text = utf8_encode($text);
  41. return trim($text);
  42. }
  43. }