SensCritiqueBridge.php 2.7 KB

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