2016-07-30 16:16:02 +02:00
|
|
|
<?php
|
|
|
|
class SensCritiqueBridge extends BridgeAbstract {
|
|
|
|
|
2016-08-27 21:03:26 +02:00
|
|
|
public $maintainer = "kranack";
|
|
|
|
public $name = "Sens Critique";
|
|
|
|
public $uri = "http://www.senscritique.com";
|
|
|
|
public $description = "Sens Critique news";
|
2016-07-30 16:16:02 +02:00
|
|
|
|
2016-08-27 21:03:26 +02:00
|
|
|
public $parameters = array( array(
|
|
|
|
'm'=>array(
|
2016-08-22 01:25:56 +02:00
|
|
|
'name'=>'Movies',
|
|
|
|
'type'=>'checkbox'
|
2016-08-27 21:03:26 +02:00
|
|
|
),
|
|
|
|
's'=>array(
|
2016-08-22 01:25:56 +02:00
|
|
|
'name'=>'Series',
|
|
|
|
'type'=>'checkbox'
|
2016-08-27 21:03:26 +02:00
|
|
|
),
|
|
|
|
'g'=>array(
|
2016-08-22 01:25:56 +02:00
|
|
|
'name'=>'Video Games',
|
|
|
|
'type'=>'checkbox'
|
2016-08-27 21:03:26 +02:00
|
|
|
),
|
|
|
|
'b'=>array(
|
2016-08-22 01:25:56 +02:00
|
|
|
'name'=>'Books',
|
|
|
|
'type'=>'checkbox'
|
2016-08-27 21:03:26 +02:00
|
|
|
),
|
|
|
|
'bd'=>array(
|
2016-08-22 01:25:56 +02:00
|
|
|
'name'=>'BD',
|
|
|
|
'type'=>'checkbox'
|
2016-08-27 21:03:26 +02:00
|
|
|
),
|
|
|
|
'mu'=>array(
|
2016-08-22 01:25:56 +02:00
|
|
|
'name'=>'Music',
|
|
|
|
'type'=>'checkbox'
|
2016-08-27 21:03:26 +02:00
|
|
|
)
|
|
|
|
));
|
2016-07-30 16:16:02 +02:00
|
|
|
|
2016-08-25 01:24:53 +02:00
|
|
|
public function collectData(){
|
2016-08-28 20:38:01 +02:00
|
|
|
if (($this->getInput('m') && $this->getInput('m'))) {
|
2016-07-30 16:16:02 +02:00
|
|
|
$this->collectMoviesData();
|
2016-08-28 20:38:01 +02:00
|
|
|
} else if (($this->getInput('s') && $this->getInput('s'))) {
|
2016-07-30 16:16:02 +02:00
|
|
|
$this->collectSeriesData();
|
2016-08-28 20:38:01 +02:00
|
|
|
} else if (($this->getInput('g') && $this->getInput('g'))) {
|
2016-07-30 16:16:02 +02:00
|
|
|
$this->collectGamesData();
|
2016-08-28 20:38:01 +02:00
|
|
|
} else if (($this->getInput('b') && $this->getInput('b'))) {
|
2016-07-30 16:16:02 +02:00
|
|
|
$this->collectBooksData();
|
2016-08-28 20:38:01 +02:00
|
|
|
} else if (($this->getInput('bd') && $this->getInput('bd'))) {
|
2016-07-30 16:16:02 +02:00
|
|
|
$this->collectBDsData();
|
2016-08-28 20:38:01 +02:00
|
|
|
} else if (($this->getInput('mu') && $this->getInput('mu'))) {
|
2016-07-30 16:16:02 +02:00
|
|
|
$this->collectMusicsData();
|
|
|
|
} else {
|
2016-08-17 14:45:08 +02:00
|
|
|
$this->returnClientError('You must choose a category');
|
2016-07-30 16:16:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-06 16:00:56 +02:00
|
|
|
private function collectMoviesData() {
|
2016-07-30 16:16:02 +02:00
|
|
|
$html = '';
|
2016-08-09 14:57:42 +02:00
|
|
|
$html = $this->getSimpleHTMLDOM('http://www.senscritique.com/films/cette-semaine') or $this->returnServerError('No results for this query.');
|
2016-07-30 16:16:02 +02:00
|
|
|
$list = $html->find('ul.elpr-list', 0);
|
|
|
|
|
|
|
|
$this->extractDataFromList($list);
|
|
|
|
}
|
|
|
|
|
2016-08-06 16:00:56 +02:00
|
|
|
private function collectSeriesData() {
|
2016-07-30 16:16:02 +02:00
|
|
|
$html = '';
|
2016-08-09 14:57:42 +02:00
|
|
|
$html = $this->getSimpleHTMLDOM('http://www.senscritique.com/series/actualite') or $this->returnServerError('No results for this query.');
|
2016-07-30 16:16:02 +02:00
|
|
|
$list = $html->find('ul.elpr-list', 0);
|
|
|
|
|
|
|
|
$this->extractDataFromList($list);
|
|
|
|
}
|
|
|
|
|
2016-08-06 16:00:56 +02:00
|
|
|
private function collectGamesData() {
|
2016-07-30 16:16:02 +02:00
|
|
|
$html = '';
|
2016-08-09 14:57:42 +02:00
|
|
|
$html = $this->getSimpleHTMLDOM('http://www.senscritique.com/jeuxvideo/actualite') or $this->returnServerError('No results for this query.');
|
2016-07-30 16:16:02 +02:00
|
|
|
$list = $html->find('ul.elpr-list', 0);
|
|
|
|
|
|
|
|
$this->extractDataFromList($list);
|
|
|
|
}
|
|
|
|
|
2016-08-06 16:00:56 +02:00
|
|
|
private function collectBooksData() {
|
2016-07-30 16:16:02 +02:00
|
|
|
$html = '';
|
2016-08-09 14:57:42 +02:00
|
|
|
$html = $this->getSimpleHTMLDOM('http://www.senscritique.com/livres/actualite') or $this->returnServerError('No results for this query.');
|
2016-07-30 16:16:02 +02:00
|
|
|
$list = $html->find('ul.elpr-list', 0);
|
|
|
|
|
|
|
|
$this->extractDataFromList($list);
|
|
|
|
}
|
|
|
|
|
2016-08-06 16:00:56 +02:00
|
|
|
private function collectBDsData() {
|
2016-07-30 16:16:02 +02:00
|
|
|
$html = '';
|
2016-08-09 14:57:42 +02:00
|
|
|
$html = $this->getSimpleHTMLDOM('http://www.senscritique.com/bd/actualite') or $this->returnServerError('No results for this query.');
|
2016-07-30 16:16:02 +02:00
|
|
|
$list = $html->find('ul.elpr-list', 0);
|
|
|
|
|
|
|
|
$this->extractDataFromList($list);
|
|
|
|
}
|
|
|
|
|
2016-08-06 16:00:56 +02:00
|
|
|
private function collectMusicsData() {
|
2016-07-30 16:16:02 +02:00
|
|
|
$html = '';
|
2016-08-09 14:57:42 +02:00
|
|
|
$html = $this->getSimpleHTMLDOM('http://www.senscritique.com/musique/actualite') or $this->returnServerError('No results for this query.');
|
2016-07-30 16:16:02 +02:00
|
|
|
$list = $html->find('ul.elpr-list', 0);
|
|
|
|
|
|
|
|
$this->extractDataFromList($list);
|
|
|
|
}
|
|
|
|
|
2016-08-06 16:00:56 +02:00
|
|
|
private function extractDataFromList($list) {
|
2016-07-30 16:16:02 +02:00
|
|
|
if ($list === null) {
|
2016-08-17 14:45:08 +02:00
|
|
|
$this->returnClientError('Cannot extract data from list');
|
2016-07-30 16:16:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($list->find('li') as $movie) {
|
2016-08-22 18:55:59 +02:00
|
|
|
$item = array();
|
|
|
|
$item['author'] = htmlspecialchars_decode($movie->find('.elco-title a', 0)->plaintext, ENT_QUOTES) . ' ' . $movie->find('.elco-date', 0)->plaintext;
|
|
|
|
$item['title'] = $movie->find('.elco-title a', 0)->plaintext . ' ' . $movie->find('.elco-date', 0)->plaintext;
|
|
|
|
$item['content'] = '<em>' . $movie->find('.elco-original-title', 0)->plaintext . '</em><br><br>' .
|
2016-07-30 16:16:02 +02:00
|
|
|
$movie->find('.elco-baseline', 0)->plaintext . '<br>' .
|
|
|
|
$movie->find('.elco-baseline', 1)->plaintext . '<br><br>' .
|
|
|
|
$movie->find('.elco-description', 0)->plaintext . '<br><br>' .
|
|
|
|
trim($movie->find('.erra-ratings .erra-global', 0)->plaintext) . ' / 10';
|
2016-08-22 18:55:59 +02:00
|
|
|
$item['id'] = $this->getURI() . $movie->find('.elco-title a', 0)->href;
|
|
|
|
$item['uri'] = $this->getURI() . $movie->find('.elco-title a', 0)->href;
|
2016-07-30 16:16:02 +02:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCacheDuration(){
|
2016-07-30 18:19:36 +02:00
|
|
|
return 21600; // 6 hours
|
2016-07-30 16:16:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|