CpasbienBridge.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. class CpasbienBridge extends BridgeAbstract {
  3. const MAINTAINER = 'lagaisse';
  4. const NAME = 'Cpasbien Bridge';
  5. const URI = 'http://www.cpasbien.cm';
  6. const CACHE_TIMEOUT = 86400; // 24h
  7. const DESCRIPTION = 'Returns latest torrents from a request query';
  8. const PARAMETERS = array( array(
  9. 'q' => array(
  10. 'name' => 'Search',
  11. 'required' => true,
  12. 'title' => 'Type your search'
  13. )
  14. ));
  15. public function collectData(){
  16. $request = str_replace(" ", "-", trim($this->getInput('q')));
  17. $html = getSimpleHTMLDOM(self::URI . '/recherche/' . urlencode($request) . '.html')
  18. or returnServerError('No results for this query.');
  19. foreach($html->find('#gauche',0)->find('div') as $episode){
  20. if($episode->getAttribute('class') == 'ligne0'
  21. || $episode->getAttribute('class') == 'ligne1'){
  22. $urlepisode = $episode->find('a', 0)->getAttribute('href');
  23. $htmlepisode = getSimpleHTMLDOMCached($urlepisode, 86400 * 366 * 30);
  24. $item = array();
  25. $item['author'] = $episode->find('a', 0)->text();
  26. $item['title'] = $episode->find('a', 0)->text();
  27. $item['pubdate'] = $this->getCachedDate($urlepisode);
  28. $textefiche = $htmlepisode->find('#textefiche', 0)->find('p', 1);
  29. if(isset($textefiche)){
  30. $item['content'] = $textefiche->text();
  31. } else {
  32. $p = $htmlepisode->find('#textefiche', 0)->find('p');
  33. if(!empty($p)){
  34. $item['content'] = $htmlepisode->find('#textefiche', 0)->find('p', 0)->text();
  35. }
  36. }
  37. $item['id'] = $episode->find('a', 0)->getAttribute('href');
  38. $item['uri'] = self::URI . $htmlepisode->find('#telecharger', 0)->getAttribute('href');
  39. $this->items[] = $item;
  40. }
  41. }
  42. }
  43. public function getName(){
  44. return $this->getInput('q') . ' : ' . self::NAME;
  45. }
  46. private function getCachedDate($url){
  47. debugMessage('getting pubdate from url ' . $url . '');
  48. // Initialize cache
  49. $cache = Cache::create('FileCache');
  50. $cache->setPath(CACHE_DIR . '/pages');
  51. $params = [$url];
  52. $cache->setParameters($params);
  53. // Get cachefile timestamp
  54. $time = $cache->getTime();
  55. return ($time !== false ? $time : time());
  56. }
  57. }