DauphineLibereBridge.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. class DauphineLibereBridge extends BridgeAbstract {
  3. public function loadMetadatas() {
  4. $this->maintainer = "qwertygc";
  5. $this->name = "Dauphine Bridge";
  6. $this->uri = "http://www.ledauphine.com/";
  7. $this->description = "Returns the newest articles.";
  8. $this->parameters[] = array(
  9. 'u'=>array(
  10. 'name'=>'Catégorie de l\'article',
  11. 'type'=>'list',
  12. 'values'=>array(
  13. 'À la une'=>'',
  14. 'France Monde'=>'france-monde',
  15. 'Faits Divers'=>'faits-divers',
  16. 'Économie et Finance'=>'economie-et-finance',
  17. 'Politique'=>'politique',
  18. 'Sport'=>'sport',
  19. 'Ain'=>'ain',
  20. 'Alpes-de-Haute-Provence'=>'haute-provence',
  21. 'Hautes-Alpes'=>'hautes-alpes',
  22. 'Ardèche'=>'ardeche',
  23. 'Drôme'=>'drome',
  24. 'Isère Sud'=>'isere-sud',
  25. 'Savoie'=>'savoie',
  26. 'Haute-Savoie'=>'haute-savoie',
  27. 'Vaucluse'=>'vaucluse'
  28. )
  29. )
  30. );
  31. }
  32. private function ExtractContent($url, $context) {
  33. $html2 = $this->getSimpleHTMLDOM($url,false,$context);
  34. $text = $html2->find('div.column', 0)->innertext;
  35. $text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text);
  36. return $text;
  37. }
  38. public function collectData(array $param){
  39. // Simulate Mozilla user-agent to fix error 403 (Forbidden)
  40. $opts = array('http' =>
  41. array(
  42. 'method' => 'GET',
  43. 'header' => 'User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'
  44. )
  45. );
  46. $context = stream_context_create($opts);
  47. if (isset($param['u'])) { /* user timeline mode */
  48. $this->request = $param['u'];
  49. $html = $this->getSimpleHTMLDOM('http://www.ledauphine.com/'.$this->request.'/rss',false,$context) or $this->returnServerError('Could not request DauphineLibere.');
  50. }
  51. else {
  52. $html = $this->getSimpleHTMLDOM('http://www.ledauphine.com/rss',false,$context) or $this->returnServerError('Could not request DauphineLibere.');
  53. }
  54. $limit = 0;
  55. foreach($html->find('item') as $element) {
  56. if($limit < 10) {
  57. $item = array();
  58. $item['title'] = $element->find('title', 0)->innertext;
  59. $item['uri'] = $element->find('guid', 0)->plaintext;
  60. $item['timestamp'] = strtotime($element->find('pubDate', 0)->plaintext);
  61. $item['content'] = $this->ExtractContent($item['uri'], $context);
  62. $this->items[] = $item;
  63. $limit++;
  64. }
  65. }
  66. }
  67. public function getCacheDuration(){
  68. return 3600*2; // 2 hours
  69. }
  70. }
  71. ?>