CpasbienBridge.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. if(!is_null($this->getInput('q'))) {
  45. return $this->getInput('q') . ' : ' . self::NAME;
  46. }
  47. return parent::getName();
  48. }
  49. private function getCachedDate($url){
  50. debugMessage('getting pubdate from url ' . $url . '');
  51. // Initialize cache
  52. $cache = Cache::create('FileCache');
  53. $cache->setPath(CACHE_DIR . '/pages');
  54. $params = [$url];
  55. $cache->setParameters($params);
  56. // Get cachefile timestamp
  57. $time = $cache->getTime();
  58. return ($time !== false ? $time : time());
  59. }
  60. }