DeveloppezDotComBridge.php 1.4 KB

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