DeveloppezDotComBridge.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. class DeveloppezDotComBridge extends BridgeAbstract{
  3. public function loadMetadatas() {
  4. $this->maintainer = "polopollo";
  5. $this->name = "Developpez.com Actus (FR)";
  6. $this->uri = "http://www.developpez.com/";
  7. $this->description = "Returns the 15 newest posts from DeveloppezDotCom (full text).";
  8. }
  9. private function DeveloppezDotComStripCDATA($string) {
  10. $string = str_replace('<![CDATA[', '', $string);
  11. $string = str_replace(']]>', '', $string);
  12. return $string;
  13. }
  14. // F***ing quotes from Microsoft Word badly encoded, here was the trick:
  15. // http://stackoverflow.com/questions/1262038/how-to-replace-microsoft-encoded-quotes-in-php
  16. private function convert_smart_quotes($string)
  17. {
  18. $search = array(chr(145),
  19. chr(146),
  20. chr(147),
  21. chr(148),
  22. chr(151));
  23. $replace = array("'",
  24. "'",
  25. '"',
  26. '"',
  27. '-');
  28. return str_replace($search, $replace, $string);
  29. }
  30. private function DeveloppezDotComExtractContent($url) {
  31. $articleHTMLContent = $this->getSimpleHTMLDOM($url);
  32. $text = $this->convert_smart_quotes($articleHTMLContent->find('div.content', 0)->innertext);
  33. $text = utf8_encode($text);
  34. return trim($text);
  35. }
  36. public function collectData(array $param){
  37. $rssFeed = $this->getSimpleHTMLDOM('http://www.developpez.com/index/rss') or $this->returnServerError('Could not request http://www.developpez.com/index/rss');
  38. $limit = 0;
  39. foreach($rssFeed->find('item') as $element) {
  40. if($limit < 10) {
  41. $item = array();
  42. $item['title'] = $this->DeveloppezDotComStripCDATA($element->find('title', 0)->innertext);
  43. $item['uri'] = $this->DeveloppezDotComStripCDATA($element->find('guid', 0)->plaintext);
  44. $item['timestamp'] = strtotime($element->find('pubDate', 0)->plaintext);
  45. $content = $this->DeveloppezDotComExtractContent($item['uri']);
  46. $item['content'] = strlen($content) ? $content : $element->description; //In case of it is a tutorial, we just keep the original description
  47. $this->items[] = $item;
  48. $limit++;
  49. }
  50. }
  51. }
  52. public function getCacheDuration(){
  53. return 1800; // 30min
  54. }
  55. }