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