SensCritiqueBridge.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. class SensCritiqueBridge extends BridgeAbstract {
  3. private $request;
  4. public function loadMetadatas() {
  5. $this->maintainer = "kranack";
  6. $this->name = "Sens Critique";
  7. $this->uri = "http://www.senscritique.com";
  8. $this->description = "Sens Critique news";
  9. $this->update = "2016-07-29";
  10. $this->parameters[] =
  11. '[
  12. {
  13. "name" : "Movies",
  14. "identifier" : "m",
  15. "type": "checkbox"
  16. },
  17. {
  18. "name" : "Series",
  19. "identifier" : "s",
  20. "type": "checkbox"
  21. },
  22. {
  23. "name" : "Video Games",
  24. "identifier" : "g",
  25. "type": "checkbox"
  26. },
  27. {
  28. "name" : "Books",
  29. "identifier" : "b",
  30. "type": "checkbox"
  31. },
  32. {
  33. "name" : "BD",
  34. "identifier" : "bd",
  35. "type": "checkbox"
  36. },
  37. {
  38. "name" : "Music",
  39. "identifier" : "mu",
  40. "type": "checkbox"
  41. }
  42. ]';
  43. }
  44. public function collectData(array $param) {
  45. if ((isset($param['m']) && $param['m'])) {
  46. $this->collectMoviesData();
  47. } else if ((isset($param['s']) && $param['s'])) {
  48. $this->collectSeriesData();
  49. } else if ((isset($param['g']) && $param['g'])) {
  50. $this->collectGamesData();
  51. } else if ((isset($param['b']) && $param['b'])) {
  52. $this->collectBooksData();
  53. } else if ((isset($param['bd']) && $param['bd'])) {
  54. $this->collectBDsData();
  55. } else if ((isset($param['mu']) && $param['mu'])) {
  56. $this->collectMusicsData();
  57. } else {
  58. $this->returnError('You must choose a category', 400);
  59. }
  60. }
  61. public function collectMoviesData() {
  62. $html = '';
  63. $html = $this->file_get_html('http://www.senscritique.com/films/cette-semaine') or $this->returnError('No results for this query.', 404);
  64. $list = $html->find('ul.elpr-list', 0);
  65. $this->extractDataFromList($list);
  66. }
  67. public function collectSeriesData() {
  68. $html = '';
  69. $html = $this->file_get_html('http://www.senscritique.com/series/actualite') or $this->returnError('No results for this query.', 404);
  70. $list = $html->find('ul.elpr-list', 0);
  71. $this->extractDataFromList($list);
  72. }
  73. public function collectGamesData() {
  74. $html = '';
  75. $html = $this->file_get_html('http://www.senscritique.com/jeuxvideo/actualite') or $this->returnError('No results for this query.', 404);
  76. $list = $html->find('ul.elpr-list', 0);
  77. $this->extractDataFromList($list);
  78. }
  79. public function collectBooksData() {
  80. $html = '';
  81. $html = $this->file_get_html('http://www.senscritique.com/livres/actualite') or $this->returnError('No results for this query.', 404);
  82. $list = $html->find('ul.elpr-list', 0);
  83. $this->extractDataFromList($list);
  84. }
  85. public function collectBDsData() {
  86. $html = '';
  87. $html = $this->file_get_html('http://www.senscritique.com/bd/actualite') or $this->returnError('No results for this query.', 404);
  88. $list = $html->find('ul.elpr-list', 0);
  89. $this->extractDataFromList($list);
  90. }
  91. public function collectMusicsData() {
  92. $html = '';
  93. $html = $this->file_get_html('http://www.senscritique.com/musique/actualite') or $this->returnError('No results for this query.', 404);
  94. $list = $html->find('ul.elpr-list', 0);
  95. $this->extractDataFromList($list);
  96. }
  97. public function extractDataFromList($list) {
  98. if ($list === null) {
  99. $this->returnError('Cannot extract data from list', 400);
  100. }
  101. foreach ($list->find('li') as $movie) {
  102. $item = new \Item();
  103. $item->name = htmlspecialchars_decode($movie->find('.elco-title a', 0)->plaintext, ENT_QUOTES) . ' ' . $movie->find('.elco-date', 0)->plaintext;
  104. $item->title = $movie->find('.elco-title a', 0)->plaintext . ' ' . $movie->find('.elco-date', 0)->plaintext;
  105. $item->content = '<em>' . $movie->find('.elco-original-title', 0)->plaintext . '</em><br><br>' .
  106. $movie->find('.elco-baseline', 0)->plaintext . '<br>' .
  107. $movie->find('.elco-baseline', 1)->plaintext . '<br><br>' .
  108. $movie->find('.elco-description', 0)->plaintext . '<br><br>' .
  109. trim($movie->find('.erra-ratings .erra-global', 0)->plaintext) . ' / 10';
  110. $item->id = $this->getURI() . $movie->find('.elco-title a', 0)->href;
  111. $item->uri = $this->getURI() . $movie->find('.elco-title a', 0)->href;
  112. $this->items[] = $item;
  113. }
  114. }
  115. public function getName() {
  116. return $this->name;
  117. }
  118. public function getURI() {
  119. return (trim($this->uri) === "") ? "http://www.senscritique.com" : $this->uri;
  120. }
  121. public function getCacheDuration(){
  122. return 21600; // 6 hours
  123. }
  124. }