2015-05-18 12:01:13 +02:00
|
|
|
<?php
|
2015-05-20 21:47:58 +02:00
|
|
|
// simple_html_dom funtion to get the dom from contents instead from file
|
|
|
|
function content_get_html($contents, $maxLen=-1, $lowercase = true, $forceTagsClosed=true, $target_charset = DEFAULT_TARGET_CHARSET, $stripRN=true, $defaultBRText=DEFAULT_BR_TEXT, $defaultSpanText=DEFAULT_SPAN_TEXT)
|
|
|
|
{
|
|
|
|
// We DO force the tags to be terminated.
|
|
|
|
$dom = new simple_html_dom(null, $lowercase, $forceTagsClosed, $target_charset, $stripRN, $defaultBRText, $defaultSpanText);
|
|
|
|
|
|
|
|
if (empty($contents) || strlen($contents) > MAX_FILE_SIZE)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// The second parameter can force the selectors to all be lowercase.
|
|
|
|
$dom->load($contents, $lowercase, $stripRN);
|
|
|
|
return $dom;
|
|
|
|
}
|
|
|
|
|
|
|
|
class CpasbienBridge extends HttpCachingBridgeAbstract{
|
2015-05-18 12:01:13 +02:00
|
|
|
|
|
|
|
private $request;
|
|
|
|
|
2015-12-06 15:55:47 +01:00
|
|
|
public function loadMetadatas() {
|
|
|
|
|
|
|
|
$this->maintainer = "lagaisse";
|
|
|
|
$this->name = "Cpasbien Bridge";
|
2016-01-26 18:39:05 +01:00
|
|
|
$this->uri = "http://www.cpasbien.io";
|
|
|
|
$this->description = "Returns latest torrents from a request query";
|
2016-08-06 18:40:36 +02:00
|
|
|
$this->update = "2016-08-06";
|
2015-12-06 15:55:47 +01:00
|
|
|
|
|
|
|
$this->parameters[] =
|
|
|
|
'[
|
|
|
|
{
|
2016-01-26 18:39:05 +01:00
|
|
|
"name" : "Search",
|
|
|
|
"identifier" : "q",
|
|
|
|
"required" : true,
|
|
|
|
"title" : "Type your search"
|
2015-12-06 15:55:47 +01:00
|
|
|
}
|
|
|
|
]';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-18 12:01:13 +02:00
|
|
|
public function collectData(array $param){
|
2016-01-26 18:39:05 +01:00
|
|
|
$this->loadMetadatas();
|
2015-05-18 12:01:13 +02:00
|
|
|
$html = '';
|
|
|
|
if (isset($param['q'])) { /* keyword search mode */
|
|
|
|
$this->request = str_replace(" ","-",trim($param['q']));
|
2016-06-25 23:17:42 +02:00
|
|
|
$html = $this->file_get_html($this->uri.'/recherche/'.urlencode($this->request).'.html') or $this->returnError('No results for this query.', 404);
|
2015-05-18 12:01:13 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$this->returnError('You must specify a keyword (?q=...).', 400);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($html->find('#gauche',0)->find('div') as $episode) {
|
|
|
|
if ($episode->getAttribute('class')=='ligne0' || $episode->getAttribute('class')=='ligne1')
|
|
|
|
{
|
2015-05-20 21:47:58 +02:00
|
|
|
|
|
|
|
$htmlepisode=content_get_html($this->get_cached($episode->find('a', 0)->getAttribute('href')));
|
2015-05-18 12:01:13 +02:00
|
|
|
|
|
|
|
$item = new \Item();
|
|
|
|
$item->name = $episode->find('a', 0)->text();
|
|
|
|
$item->title = $episode->find('a', 0)->text();
|
2015-05-20 21:47:58 +02:00
|
|
|
$item->timestamp = $this->get_cached_time($episode->find('a', 0)->getAttribute('href'));
|
|
|
|
$textefiche=$htmlepisode->find('#textefiche', 0)->find('p',1);
|
|
|
|
if (isset($textefiche)) {
|
|
|
|
$item->content = $textefiche->text();
|
2015-05-18 12:01:13 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$item->content = $htmlepisode->find('#textefiche', 0)->find('p',0)->text();
|
|
|
|
}
|
|
|
|
|
|
|
|
$item->id = $episode->find('a', 0)->getAttribute('href');
|
2016-01-26 18:39:05 +01:00
|
|
|
$item->uri = $this->uri . $htmlepisode->find('#telecharger',0)->getAttribute('href');
|
2015-05-20 21:47:58 +02:00
|
|
|
$item->thumbnailUri = $htmlepisode->find('#bigcover', 0)->find('img',0)->getAttribute('src');
|
2015-05-18 12:01:13 +02:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function getName(){
|
2016-01-26 18:39:05 +01:00
|
|
|
return (!empty($this->request) ? $this->request .' - ' : '') . $this->name;
|
2015-05-18 12:01:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getCacheDuration(){
|
|
|
|
return 60*60*24; // 24 hours
|
|
|
|
}
|
|
|
|
}
|