2015-05-18 12:01:13 +02:00
|
|
|
<?php
|
2016-09-10 19:11:09 +02:00
|
|
|
class CpasbienBridge extends BridgeAbstract {
|
2016-07-08 19:06:35 +02:00
|
|
|
|
2016-08-30 11:23:55 +02:00
|
|
|
const MAINTAINER = "lagaisse";
|
|
|
|
const NAME = "Cpasbien Bridge";
|
2017-01-01 12:05:37 +01:00
|
|
|
const URI = "http://www.cpasbien.cm";
|
2016-09-25 17:04:28 +02:00
|
|
|
const CACHE_TIMEOUT = 86400; // 24h
|
2016-08-30 11:23:55 +02:00
|
|
|
const DESCRIPTION = "Returns latest torrents from a request query";
|
2015-12-06 15:55:47 +01:00
|
|
|
|
2016-08-30 11:23:55 +02:00
|
|
|
const PARAMETERS = array( array(
|
2016-08-27 21:03:26 +02:00
|
|
|
'q'=>array(
|
2016-08-22 01:25:56 +02:00
|
|
|
'name'=>'Search',
|
|
|
|
'required'=>true,
|
|
|
|
'title'=>'Type your search'
|
2016-08-27 21:03:26 +02:00
|
|
|
)
|
|
|
|
));
|
2015-12-06 15:55:47 +01:00
|
|
|
|
2016-08-25 01:24:53 +02:00
|
|
|
public function collectData(){
|
2016-08-28 13:17:28 +02:00
|
|
|
$request = str_replace(" ","-",trim($this->getInput('q')));
|
2016-09-25 23:22:33 +02:00
|
|
|
$html = getSimpleHTMLDOM(self::URI.'/recherche/'.urlencode($request).'.html')
|
|
|
|
or returnServerError('No results for this query.');
|
2015-05-18 12:01:13 +02:00
|
|
|
|
|
|
|
foreach ($html->find('#gauche',0)->find('div') as $episode) {
|
2016-08-28 13:17:28 +02:00
|
|
|
if ($episode->getAttribute('class')=='ligne0' ||
|
|
|
|
$episode->getAttribute('class')=='ligne1')
|
2015-05-18 12:01:13 +02:00
|
|
|
{
|
2017-01-01 12:05:37 +01:00
|
|
|
|
|
|
|
$urlepisode = $episode->find('a', 0)->getAttribute('href');
|
|
|
|
$htmlepisode=getSimpleHTMLDOMCached($urlepisode, 86400*366*30);
|
2015-05-18 12:01:13 +02:00
|
|
|
|
2016-08-22 18:55:59 +02:00
|
|
|
$item = array();
|
|
|
|
$item['author'] = $episode->find('a', 0)->text();
|
|
|
|
$item['title'] = $episode->find('a', 0)->text();
|
2017-01-01 12:05:37 +01:00
|
|
|
$item['pubdate'] = $this->getCachedDate($urlepisode);
|
2015-05-20 21:47:58 +02:00
|
|
|
$textefiche=$htmlepisode->find('#textefiche', 0)->find('p',1);
|
|
|
|
if (isset($textefiche)) {
|
2016-08-22 18:55:59 +02:00
|
|
|
$item['content'] = $textefiche->text();
|
2016-08-25 17:11:49 +02:00
|
|
|
} else {
|
2016-08-25 00:12:33 +02:00
|
|
|
$p=$htmlepisode->find('#textefiche',0)->find('p');
|
|
|
|
if(!empty($p)){
|
|
|
|
$item['content'] = $htmlepisode->find('#textefiche', 0)->find('p',0)->text();
|
|
|
|
}
|
2015-05-18 12:01:13 +02:00
|
|
|
}
|
|
|
|
|
2016-08-22 18:55:59 +02:00
|
|
|
$item['id'] = $episode->find('a', 0)->getAttribute('href');
|
2016-08-30 11:23:55 +02:00
|
|
|
$item['uri'] = self::URI . $htmlepisode->find('#telecharger',0)->getAttribute('href');
|
2015-05-18 12:01:13 +02:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function getName(){
|
2016-08-30 11:23:55 +02:00
|
|
|
return $this->getInput('q').' : '.self::NAME;
|
2015-05-18 12:01:13 +02:00
|
|
|
}
|
2017-01-01 12:05:37 +01:00
|
|
|
|
|
|
|
private function getCachedDate($url){
|
|
|
|
debugMessage('getting pubdate from url ' . $url . '');
|
|
|
|
|
|
|
|
// Initialize cache
|
|
|
|
$cache = Cache::create('FileCache');
|
|
|
|
$cache->setPath(CACHE_DIR . '/pages');
|
|
|
|
|
|
|
|
$params = [$url];
|
|
|
|
$cache->setParameters($params);
|
|
|
|
|
|
|
|
// Get cachefile timestamp
|
|
|
|
$time = $cache->getTime();
|
|
|
|
return ($time!==false?$time:time());
|
|
|
|
}
|
2015-05-18 12:01:13 +02:00
|
|
|
}
|