DeveloppezDotComBridge.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. $this->update = "2014-07-14";
  9. }
  10. public function collectData(array $param){
  11. function DeveloppezDotComStripCDATA($string) {
  12. $string = str_replace('<![CDATA[', '', $string);
  13. $string = str_replace(']]>', '', $string);
  14. return $string;
  15. }
  16. function convert_smart_quotes($string)//F***ing quotes from Microsoft Word badly encoded, here was the trick: http://stackoverflow.com/questions/1262038/how-to-replace-microsoft-encoded-quotes-in-php
  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. function DeveloppezDotComExtractContent($url) {
  31. $articleHTMLContent = $this->file_get_html($url);
  32. $text = convert_smart_quotes($articleHTMLContent->find('div.content', 0)->innertext);
  33. $text = utf8_encode($text);
  34. return trim($text);
  35. }
  36. $rssFeed = $this->file_get_html('http://www.developpez.com/index/rss') or $this->returnError('Could not request http://www.developpez.com/index/rss', 404);
  37. $limit = 0;
  38. foreach($rssFeed->find('item') as $element) {
  39. if($limit < 10) {
  40. $item = new \Item();
  41. $item->title = DeveloppezDotComStripCDATA($element->find('title', 0)->innertext);
  42. $item->uri = DeveloppezDotComStripCDATA($element->find('guid', 0)->plaintext);
  43. $item->timestamp = strtotime($element->find('pubDate', 0)->plaintext);
  44. $content = DeveloppezDotComExtractContent($item->uri);
  45. $item->content = strlen($content) ? $content : $element->description;//In case of it is a tutorial, we just keep the original description
  46. $this->items[] = $item;
  47. $limit++;
  48. }
  49. }
  50. }
  51. public function getName(){
  52. return 'DeveloppezDotCom';
  53. }
  54. public function getURI(){
  55. return 'http://www.developpez.com/';
  56. }
  57. public function getCacheDuration(){
  58. return 1800; // 30min
  59. }
  60. }