SensCritiqueBridge.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. class SensCritiqueBridge extends BridgeAbstract {
  3. const MAINTAINER = 'kranack';
  4. const NAME = 'Sens Critique';
  5. const URI = 'http://www.senscritique.com/';
  6. const CACHE_TIMEOUT = 21600; // 6h
  7. const DESCRIPTION = 'Sens Critique news';
  8. const PARAMETERS = array( array(
  9. 'm' => array(
  10. 'name' => 'Movies',
  11. 'type' => 'checkbox'
  12. ),
  13. 's' => array(
  14. 'name' => 'Series',
  15. 'type' => 'checkbox'
  16. ),
  17. 'g' => array(
  18. 'name' => 'Video Games',
  19. 'type' => 'checkbox'
  20. ),
  21. 'b' => array(
  22. 'name' => 'Books',
  23. 'type' => 'checkbox'
  24. ),
  25. 'bd' => array(
  26. 'name' => 'BD',
  27. 'type' => 'checkbox'
  28. ),
  29. 'mu' => array(
  30. 'name' => 'Music',
  31. 'type' => 'checkbox'
  32. )
  33. ));
  34. public function collectData(){
  35. $categories = array();
  36. foreach(self::PARAMETERS[$this->queriedContext] as $category => $properties) {
  37. if($this->getInput($category)) {
  38. $uri = self::URI;
  39. switch($category) {
  40. case 'm': $uri .= 'films/cette-semaine';
  41. break;
  42. case 's': $uri .= 'series/actualite';
  43. break;
  44. case 'g': $uri .= 'jeuxvideo/actualite';
  45. break;
  46. case 'b': $uri .= 'livres/actualite';
  47. break;
  48. case 'bd': $uri .= 'bd/actualite';
  49. break;
  50. case 'mu': $uri .= 'musique/actualite';
  51. break;
  52. }
  53. $html = getSimpleHTMLDOM($uri)
  54. or returnServerError('No results for this query.');
  55. $list = $html->find('ul.elpr-list', 0);
  56. $this->extractDataFromList($list);
  57. }
  58. }
  59. }
  60. private function extractDataFromList($list){
  61. if($list === null) {
  62. returnClientError('Cannot extract data from list');
  63. }
  64. foreach($list->find('li') as $movie) {
  65. $item = array();
  66. $item['author'] = htmlspecialchars_decode($movie->find('.elco-title a', 0)->plaintext, ENT_QUOTES)
  67. . ' '
  68. . $movie->find('.elco-date', 0)->plaintext;
  69. $item['title'] = $movie->find('.elco-title a', 0)->plaintext
  70. . ' '
  71. . $movie->find('.elco-date', 0)->plaintext;
  72. $item['content'] = '<em>'
  73. . $movie->find('.elco-original-title', 0)->plaintext
  74. . '</em><br><br>'
  75. . $movie->find('.elco-baseline', 0)->plaintext
  76. . '<br>'
  77. . $movie->find('.elco-baseline', 1)->plaintext
  78. . '<br><br>'
  79. . $movie->find('.elco-description', 0)->plaintext
  80. . '<br><br>'
  81. . trim($movie->find('.erra-ratings .erra-global', 0)->plaintext)
  82. . ' / 10';
  83. $item['id'] = $this->getURI() . $movie->find('.elco-title a', 0)->href;
  84. $item['uri'] = $this->getURI() . $movie->find('.elco-title a', 0)->href;
  85. $this->items[] = $item;
  86. }
  87. }
  88. }