1
0

Rue89Bridge.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * RssBridgeRue89
  4. * Returns the 5 newest posts from http://rue89.nouvelobs.com/ (full text)
  5. *
  6. * @name Rue89
  7. * @description Returns the 5 newest posts from Rue89 (full text)
  8. * @update 2015-01-30
  9. * @maintainer pit-fgfjiudghdf
  10. */
  11. class Rue89Bridge extends BridgeAbstract{
  12. public function collectData(array $param){
  13. function Rue89StripCDATA($string) {
  14. $string = str_replace('<![CDATA[', '', $string);
  15. $string = str_replace(']]>', '', $string);
  16. return $string;
  17. }
  18. function Rue89ExtractContent($url) {
  19. $html2 = file_get_html($url);
  20. //$text = $html2->find('div[class=text]', 0)->innertext;
  21. foreach($html2->find('img') as $image) {
  22. $image->src = $image->getAttribute('data-src');
  23. }
  24. $text = $html2->find('div.content', 0)->innertext;
  25. $text = str_replace('href="/', 'href="http://rue89.nouvelobs.com/', $text);
  26. $text = str_replace('src="/', 'src="http://rue89.nouvelobs.com/', $text);
  27. $text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text);
  28. $text = strip_tags($text, '<h1><h2><strong><p><b><a><blockquote><img><em><ul><ol>');
  29. return $text;
  30. }
  31. $html = file_get_html('http://rue89.feedsportal.com/c/33822/f/608948/index.rss') or $this->returnError('Could not request Rue89.', 404);
  32. $limit = 0;
  33. foreach($html->find('item') as $element) {
  34. if($limit < 5) {
  35. $item = new \Item();
  36. $item->title = Rue89StripCDATA($element->find('title', 0)->innertext);
  37. $item->uri = str_replace('#commentaires', '', Rue89StripCDATA($element->find('comments', 0)->plaintext));
  38. $item->timestamp = strtotime($element->find('pubDate', 0)->plaintext);
  39. $item->content = Rue89ExtractContent($item->uri);
  40. $this->items[] = $item;
  41. $limit++;
  42. }
  43. }
  44. }
  45. public function getName(){
  46. return 'Rue89';
  47. }
  48. public function getURI(){
  49. return 'http://rue89.nouvelobs.com/';
  50. }
  51. public function getCacheDuration(){
  52. return 3600; // 1 hour
  53. }
  54. }