DeveloppezDotComBridge.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. class DeveloppezDotComBridge extends FeedExpander {
  3. const MAINTAINER = 'polopollo';
  4. const NAME = 'Developpez.com Actus (FR)';
  5. const URI = 'https://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->extractContent($item['uri']);
  14. return $item;
  15. }
  16. // F***ing quotes from Microsoft Word badly encoded, here was the trick:
  17. // http://stackoverflow.com/questions/1262038/how-to-replace-microsoft-encoded-quotes-in-php
  18. private function convertSmartQuotes($string)
  19. {
  20. $search = array(chr(145),
  21. chr(146),
  22. chr(147),
  23. chr(148),
  24. chr(151));
  25. $replace = array(
  26. "'",
  27. "'",
  28. '"',
  29. '"',
  30. '-'
  31. );
  32. return str_replace($search, $replace, $string);
  33. }
  34. private function extractContent($url){
  35. $articleHTMLContent = getSimpleHTMLDOMCached($url);
  36. $text = $this->convertSmartQuotes($articleHTMLContent->find('div.content', 0)->innertext);
  37. $text = utf8_encode($text);
  38. return trim($text);
  39. }
  40. }