SensCritiqueBridge.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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'; break;
  41. case 's': $uri.='series/actualite'; break;
  42. case 'g': $uri.='jeuxvideo/actualite'; break;
  43. case 'b': $uri.='livres/actualite'; break;
  44. case 'bd': $uri.='bd/actualite'; break;
  45. case 'mu': $uri.='musique/actualite'; break;
  46. }
  47. $html = getSimpleHTMLDOM($uri)
  48. or returnServerError('No results for this query.');
  49. $list = $html->find('ul.elpr-list', 0);
  50. $this->extractDataFromList($list);
  51. }
  52. }
  53. }
  54. private function extractDataFromList($list) {
  55. if ($list === null) {
  56. returnClientError('Cannot extract data from list');
  57. }
  58. foreach ($list->find('li') as $movie) {
  59. $item = array();
  60. $item['author'] = htmlspecialchars_decode($movie->find('.elco-title a', 0)->plaintext, ENT_QUOTES) . ' ' . $movie->find('.elco-date', 0)->plaintext;
  61. $item['title'] = $movie->find('.elco-title a', 0)->plaintext . ' ' . $movie->find('.elco-date', 0)->plaintext;
  62. $item['content'] = '<em>' . $movie->find('.elco-original-title', 0)->plaintext . '</em><br><br>' .
  63. $movie->find('.elco-baseline', 0)->plaintext . '<br>' .
  64. $movie->find('.elco-baseline', 1)->plaintext . '<br><br>' .
  65. $movie->find('.elco-description', 0)->plaintext . '<br><br>' .
  66. trim($movie->find('.erra-ratings .erra-global', 0)->plaintext) . ' / 10';
  67. $item['id'] = $this->getURI() . $movie->find('.elco-title a', 0)->href;
  68. $item['uri'] = $this->getURI() . $movie->find('.elco-title a', 0)->href;
  69. $this->items[] = $item;
  70. }
  71. }
  72. }