CpasbienBridge.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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->update = "2016-01-26";
  23. $this->parameters[] =
  24. '[
  25. {
  26. "name" : "Search",
  27. "identifier" : "q",
  28. "required" : true,
  29. "title" : "Type your search"
  30. }
  31. ]';
  32. }
  33. public function collectData(array $param){
  34. $this->loadMetadatas();
  35. $html = '';
  36. if (isset($param['q'])) { /* keyword search mode */
  37. $this->request = str_replace(" ","-",trim($param['q']));
  38. $html = $this->file_get_html($this->uri.'/recherche/'.urlencode($this->request).'.html') or $this->returnError('No results for this query.', 404);
  39. }
  40. else {
  41. $this->returnError('You must specify a keyword (?q=...).', 400);
  42. }
  43. foreach ($html->find('#gauche',0)->find('div') as $episode) {
  44. if ($episode->getAttribute('class')=='ligne0' || $episode->getAttribute('class')=='ligne1')
  45. {
  46. $htmlepisode=content_get_html($this->get_cached($episode->find('a', 0)->getAttribute('href')));
  47. $item = new \Item();
  48. $item->name = $episode->find('a', 0)->text();
  49. $item->title = $episode->find('a', 0)->text();
  50. $item->timestamp = $this->get_cached_time($episode->find('a', 0)->getAttribute('href'));
  51. $textefiche=$htmlepisode->find('#textefiche', 0)->find('p',1);
  52. if (isset($textefiche)) {
  53. $item->content = $textefiche->text();
  54. }
  55. else {
  56. $item->content = $htmlepisode->find('#textefiche', 0)->find('p',0)->text();
  57. }
  58. $item->id = $episode->find('a', 0)->getAttribute('href');
  59. $item->uri = $this->uri . $htmlepisode->find('#telecharger',0)->getAttribute('href');
  60. $item->thumbnailUri = $htmlepisode->find('#bigcover', 0)->find('img',0)->getAttribute('src');
  61. $this->items[] = $item;
  62. }
  63. }
  64. }
  65. public function getName(){
  66. return (!empty($this->request) ? $this->request .' - ' : '') . $this->name;
  67. }
  68. public function getURI(){
  69. return $this->uri;
  70. }
  71. public function getCacheDuration(){
  72. return 60*60*24; // 24 hours
  73. }
  74. }