CpasbienBridge.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. // simple_html_dom funtion to get the dom from contents instead from file
  3. 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)
  4. {
  5. // We DO force the tags to be terminated.
  6. $dom = new simple_html_dom(null, $lowercase, $forceTagsClosed, $target_charset, $stripRN, $defaultBRText, $defaultSpanText);
  7. if (empty($contents) || strlen($contents) > MAX_FILE_SIZE)
  8. {
  9. return false;
  10. }
  11. // The second parameter can force the selectors to all be lowercase.
  12. $dom->load($contents, $lowercase, $stripRN);
  13. return $dom;
  14. }
  15. class CpasbienBridge extends HttpCachingBridgeAbstract{
  16. private $request;
  17. public function loadMetadatas() {
  18. $this->maintainer = "lagaisse";
  19. $this->name = "Cpasbien Bridge";
  20. $this->uri = "http://www.cpasbien.io";
  21. $this->description = "Returns latest torrents from a request query";
  22. $this->parameters[] = array(
  23. 'q'=>array(
  24. 'name'=>'Search',
  25. 'required'=>true,
  26. 'title'=>'Type your search'
  27. )
  28. );
  29. }
  30. public function collectData(array $param){
  31. $this->loadMetadatas();
  32. $html = '';
  33. if (isset($param['q'])) { /* keyword search mode */
  34. $this->request = str_replace(" ","-",trim($param['q']));
  35. $html = $this->getSimpleHTMLDOM($this->uri.'/recherche/'.urlencode($this->request).'.html') or $this->returnServerError('No results for this query.');
  36. }
  37. else {
  38. $this->returnClientError('You must specify a keyword (?q=...).');
  39. }
  40. foreach ($html->find('#gauche',0)->find('div') as $episode) {
  41. if ($episode->getAttribute('class')=='ligne0' || $episode->getAttribute('class')=='ligne1')
  42. {
  43. $htmlepisode=content_get_html($this->get_cached($episode->find('a', 0)->getAttribute('href')));
  44. $item = array();
  45. $item['author'] = $episode->find('a', 0)->text();
  46. $item['title'] = $episode->find('a', 0)->text();
  47. $item['timestamp'] = $this->get_cached_time($episode->find('a', 0)->getAttribute('href'));
  48. $textefiche=$htmlepisode->find('#textefiche', 0)->find('p',1);
  49. if (isset($textefiche)) {
  50. $item['content'] = $textefiche->text();
  51. }
  52. else {
  53. $item['content'] = $htmlepisode->find('#textefiche', 0)->find('p',0)->text();
  54. }
  55. $item['id'] = $episode->find('a', 0)->getAttribute('href');
  56. $item['uri'] = $this->uri . $htmlepisode->find('#telecharger',0)->getAttribute('href');
  57. $this->items[] = $item;
  58. }
  59. }
  60. }
  61. public function getName(){
  62. return (!empty($this->request) ? $this->request .' - ' : '') . $this->name;
  63. }
  64. public function getCacheDuration(){
  65. return 60*60*24; // 24 hours
  66. }
  67. }