1
0

DauphineLibereBridge.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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) {
  81. $html2 = $this->file_get_html($url);
  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. if (isset($param['u'])) { /* user timeline mode */
  88. $this->request = $param['u'];
  89. $html = $this->file_get_html('http://www.ledauphine.com/'.$this->request.'/rss') or $this->returnError('Could not request DauphineLibere.', 404);
  90. }
  91. else {
  92. $html = $this->file_get_html('http://www.ledauphine.com/rss') or $this->returnError('Could not request DauphineLibere.', 404);
  93. }
  94. $limit = 0;
  95. foreach($html->find('item') as $element) {
  96. if($limit < 10) {
  97. $item = new \Item();
  98. $item->title = $element->find('title', 0)->innertext;
  99. $item->uri = $element->find('guid', 0)->plaintext;
  100. $item->timestamp = strtotime($element->find('pubDate', 0)->plaintext);
  101. $item->content = $this->ExtractContent($item->uri);
  102. $this->items[] = $item;
  103. $limit++;
  104. }
  105. }
  106. }
  107. public function getName(){
  108. return 'Dauphine Bridge';
  109. }
  110. public function getURI(){
  111. return 'http://ledauphine.com/';
  112. }
  113. public function getCacheDuration(){
  114. return 3600*2; // 2 hours
  115. // return 0; // 2 hours
  116. }
  117. }