2016-07-30 17:16:02 +03:00
|
|
|
<?php
|
|
|
|
class SensCritiqueBridge extends BridgeAbstract {
|
|
|
|
|
|
|
|
private $request;
|
|
|
|
|
|
|
|
public function loadMetadatas() {
|
|
|
|
$this->maintainer = "kranack";
|
|
|
|
$this->name = "Sens Critique";
|
|
|
|
$this->uri = "http://www.senscritique.com";
|
|
|
|
$this->description = "Sens Critique news";
|
|
|
|
|
2016-08-22 02:25:56 +03:00
|
|
|
$this->parameters[] = array(
|
|
|
|
'm'=>array(
|
|
|
|
'name'=>'Movies',
|
|
|
|
'type'=>'checkbox'
|
|
|
|
),
|
|
|
|
's'=>array(
|
|
|
|
'name'=>'Series',
|
|
|
|
'type'=>'checkbox'
|
|
|
|
),
|
|
|
|
'g'=>array(
|
|
|
|
'name'=>'Video Games',
|
|
|
|
'type'=>'checkbox'
|
|
|
|
),
|
|
|
|
'b'=>array(
|
|
|
|
'name'=>'Books',
|
|
|
|
'type'=>'checkbox'
|
|
|
|
),
|
|
|
|
'bd'=>array(
|
|
|
|
'name'=>'BD',
|
|
|
|
'type'=>'checkbox'
|
|
|
|
),
|
|
|
|
'mu'=>array(
|
|
|
|
'name'=>'Music',
|
|
|
|
'type'=>'checkbox'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2016-07-30 17:16:02 +03:00
|
|
|
|
|
|
|
public function collectData(array $param) {
|
|
|
|
if ((isset($param['m']) && $param['m'])) {
|
|
|
|
$this->collectMoviesData();
|
|
|
|
} else if ((isset($param['s']) && $param['s'])) {
|
|
|
|
$this->collectSeriesData();
|
|
|
|
} else if ((isset($param['g']) && $param['g'])) {
|
|
|
|
$this->collectGamesData();
|
|
|
|
} else if ((isset($param['b']) && $param['b'])) {
|
|
|
|
$this->collectBooksData();
|
|
|
|
} else if ((isset($param['bd']) && $param['bd'])) {
|
|
|
|
$this->collectBDsData();
|
|
|
|
} else if ((isset($param['mu']) && $param['mu'])) {
|
|
|
|
$this->collectMusicsData();
|
|
|
|
} else {
|
2016-08-17 15:45:08 +03:00
|
|
|
$this->returnClientError('You must choose a category');
|
2016-07-30 17:16:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-06 17:00:56 +03:00
|
|
|
private function collectMoviesData() {
|
2016-07-30 17:16:02 +03:00
|
|
|
$html = '';
|
2016-08-09 15:57:42 +03:00
|
|
|
$html = $this->getSimpleHTMLDOM('http://www.senscritique.com/films/cette-semaine') or $this->returnServerError('No results for this query.');
|
2016-07-30 17:16:02 +03:00
|
|
|
$list = $html->find('ul.elpr-list', 0);
|
|
|
|
|
|
|
|
$this->extractDataFromList($list);
|
|
|
|
}
|
|
|
|
|
2016-08-06 17:00:56 +03:00
|
|
|
private function collectSeriesData() {
|
2016-07-30 17:16:02 +03:00
|
|
|
$html = '';
|
2016-08-09 15:57:42 +03:00
|
|
|
$html = $this->getSimpleHTMLDOM('http://www.senscritique.com/series/actualite') or $this->returnServerError('No results for this query.');
|
2016-07-30 17:16:02 +03:00
|
|
|
$list = $html->find('ul.elpr-list', 0);
|
|
|
|
|
|
|
|
$this->extractDataFromList($list);
|
|
|
|
}
|
|
|
|
|
2016-08-06 17:00:56 +03:00
|
|
|
private function collectGamesData() {
|
2016-07-30 17:16:02 +03:00
|
|
|
$html = '';
|
2016-08-09 15:57:42 +03:00
|
|
|
$html = $this->getSimpleHTMLDOM('http://www.senscritique.com/jeuxvideo/actualite') or $this->returnServerError('No results for this query.');
|
2016-07-30 17:16:02 +03:00
|
|
|
$list = $html->find('ul.elpr-list', 0);
|
|
|
|
|
|
|
|
$this->extractDataFromList($list);
|
|
|
|
}
|
|
|
|
|
2016-08-06 17:00:56 +03:00
|
|
|
private function collectBooksData() {
|
2016-07-30 17:16:02 +03:00
|
|
|
$html = '';
|
2016-08-09 15:57:42 +03:00
|
|
|
$html = $this->getSimpleHTMLDOM('http://www.senscritique.com/livres/actualite') or $this->returnServerError('No results for this query.');
|
2016-07-30 17:16:02 +03:00
|
|
|
$list = $html->find('ul.elpr-list', 0);
|
|
|
|
|
|
|
|
$this->extractDataFromList($list);
|
|
|
|
}
|
|
|
|
|
2016-08-06 17:00:56 +03:00
|
|
|
private function collectBDsData() {
|
2016-07-30 17:16:02 +03:00
|
|
|
$html = '';
|
2016-08-09 15:57:42 +03:00
|
|
|
$html = $this->getSimpleHTMLDOM('http://www.senscritique.com/bd/actualite') or $this->returnServerError('No results for this query.');
|
2016-07-30 17:16:02 +03:00
|
|
|
$list = $html->find('ul.elpr-list', 0);
|
|
|
|
|
|
|
|
$this->extractDataFromList($list);
|
|
|
|
}
|
|
|
|
|
2016-08-06 17:00:56 +03:00
|
|
|
private function collectMusicsData() {
|
2016-07-30 17:16:02 +03:00
|
|
|
$html = '';
|
2016-08-09 15:57:42 +03:00
|
|
|
$html = $this->getSimpleHTMLDOM('http://www.senscritique.com/musique/actualite') or $this->returnServerError('No results for this query.');
|
2016-07-30 17:16:02 +03:00
|
|
|
$list = $html->find('ul.elpr-list', 0);
|
|
|
|
|
|
|
|
$this->extractDataFromList($list);
|
|
|
|
}
|
|
|
|
|
2016-08-06 17:00:56 +03:00
|
|
|
private function extractDataFromList($list) {
|
2016-07-30 17:16:02 +03:00
|
|
|
if ($list === null) {
|
2016-08-17 15:45:08 +03:00
|
|
|
$this->returnClientError('Cannot extract data from list');
|
2016-07-30 17:16:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($list->find('li') as $movie) {
|
2016-08-22 19:55:59 +03: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 17:16:02 +03: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 19:55:59 +03: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 17:16:02 +03:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCacheDuration(){
|
2016-07-30 19:19:36 +03:00
|
|
|
return 21600; // 6 hours
|
2016-07-30 17:16:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|