DauphineLibereBridge.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. class DauphineLibereBridge extends BridgeAbstract {
  3. public function loadMetadatas() {
  4. $this->maintainer = "qwertygc";
  5. $this->name = "DauphineLibereBridge Bridge";
  6. $this->uri = "http://www.ledauphine.com/";
  7. $this->description = "Returns the newest articles.";
  8. $this->update = "2016-08-02";
  9. $this->parameters[] =
  10. '[
  11. {
  12. "name" : "Catégorie de l\'article",
  13. "identifier" : "u",
  14. "type" : "list",
  15. "values" : [
  16. {
  17. "name" : "À la une",
  18. "value" : ""
  19. },
  20. {
  21. "name" : "France Monde",
  22. "value" : "france-monde"
  23. },
  24. {
  25. "name" : "Faits Divers",
  26. "value" : "faits-divers"
  27. },
  28. {
  29. "name" : "Économie et Finance",
  30. "value" : "economie-et-finance"
  31. },
  32. {
  33. "name" : "Politique",
  34. "value" : "politique"
  35. },
  36. {
  37. "name" : "Sport",
  38. "value" : "sport"
  39. },
  40. {
  41. "name" : "Ain",
  42. "value" : "ain"
  43. },
  44. {
  45. "name" : "Alpes-de-Haute-Provence",
  46. "value" : "haute-provence"
  47. },
  48. {
  49. "name" : "Hautes-Alpes",
  50. "value" : "hautes-alpes"
  51. },
  52. {
  53. "name" : "Ardèche",
  54. "value" : "ardeche"
  55. },
  56. {
  57. "name" : "Drôme",
  58. "value" : "drome"
  59. },
  60. {
  61. "name" : "Isère Sud",
  62. "value" : "isere-sud"
  63. },
  64. {
  65. "name" : "Savoie",
  66. "value" : "savoie"
  67. },
  68. {
  69. "name" : "Haute-Savoie",
  70. "value" : "haute-savoie"
  71. },
  72. {
  73. "name" : "Vaucluse",
  74. "value" : "vaucluse"
  75. }
  76. ]
  77. }
  78. ]';
  79. }
  80. function ExtractContent($url, $context) {
  81. $html2 = $this->file_get_html($url, false, $context);
  82. $text = $html2->find('div.column', 0)->innertext;
  83. $text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text);
  84. return $text;
  85. }
  86. public function collectData(array $param){
  87. // Simulate Mozilla user-agent to fix error 403 (Forbidden)
  88. $opts = array('http' =>
  89. array(
  90. 'method' => 'GET',
  91. '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'
  92. )
  93. );
  94. $context = stream_context_create($opts);
  95. if (isset($param['u'])) { /* user timeline mode */
  96. $this->request = $param['u'];
  97. $html = $this->file_get_html('http://www.ledauphine.com/'.$this->request.'/rss', false, $context) or $this->returnError('Could not request DauphineLibere.', 404);
  98. }
  99. else {
  100. $html = $this->file_get_html('http://www.ledauphine.com/rss', false, $context) or $this->returnError('Could not request DauphineLibere.', 404);
  101. }
  102. $limit = 0;
  103. foreach($html->find('item') as $element) {
  104. if($limit < 10) {
  105. $item = new \Item();
  106. $item->title = $element->find('title', 0)->innertext;
  107. $item->uri = $element->find('guid', 0)->plaintext;
  108. $item->timestamp = strtotime($element->find('pubDate', 0)->plaintext);
  109. $item->content = $this->ExtractContent($item->uri, $context);
  110. $this->items[] = $item;
  111. $limit++;
  112. }
  113. }
  114. }
  115. public function getName(){
  116. return 'Dauphine Bridge';
  117. }
  118. public function getURI(){
  119. return 'http://ledauphine.com/';
  120. }
  121. public function getCacheDuration(){
  122. return 3600*2; // 2 hours
  123. }
  124. }
  125. ?>