DeveloppezDotComBridge.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * RssBridgeDeveloppezDotCom
  4. * Returns the 15 newest posts from http://www.developpez.com (full text)
  5. * 2014-07-14
  6. *
  7. * @name Developpez.com Actus (FR)
  8. * @homepage http://www.developpez.com/
  9. * @description Returns the 15 newest posts from DeveloppezDotCom (full text).
  10. * @maintainer polopollo
  11. */
  12. class DeveloppezDotComBridge extends BridgeAbstract{
  13. public function collectData(array $param){
  14. function DeveloppezDotComStripCDATA($string) {
  15. $string = str_replace('<![CDATA[', '', $string);
  16. $string = str_replace(']]>', '', $string);
  17. return $string;
  18. }
  19. 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
  20. {
  21. $search = array(chr(145),
  22. chr(146),
  23. chr(147),
  24. chr(148),
  25. chr(151));
  26. $replace = array("'",
  27. "'",
  28. '"',
  29. '"',
  30. '-');
  31. return str_replace($search, $replace, $string);
  32. }
  33. function DeveloppezDotComExtractContent($url) {
  34. $articleHTMLContent = file_get_html($url);
  35. $text = convert_smart_quotes($articleHTMLContent->find('div.content', 0)->innertext);
  36. $text = utf8_encode($text);
  37. return trim($text);
  38. }
  39. $rssFeed = file_get_html('http://www.developpez.com/index/rss') or $this->returnError('Could not request http://www.developpez.com/index/rss', 404);
  40. $limit = 0;
  41. foreach($rssFeed->find('item') as $element) {
  42. if($limit < 10) {
  43. $item = new \Item();
  44. $item->title = DeveloppezDotComStripCDATA($element->find('title', 0)->innertext);
  45. $item->uri = DeveloppezDotComStripCDATA($element->find('guid', 0)->plaintext);
  46. $item->timestamp = strtotime($element->find('pubDate', 0)->plaintext);
  47. $content = DeveloppezDotComExtractContent($item->uri);
  48. $item->content = strlen($content) ? $content : $element->description;//In case of it is a tutorial, we just keep the original description
  49. $this->items[] = $item;
  50. $limit++;
  51. }
  52. }
  53. }
  54. public function getName(){
  55. return 'DeveloppezDotCom';
  56. }
  57. public function getURI(){
  58. return 'http://www.developpez.com/';
  59. }
  60. public function getCacheDuration(){
  61. return 1800; // 30min
  62. }
  63. }