LolibooruBridge.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. class LolibooruBridge extends BridgeAbstract{
  3. public function loadMetadatas() {
  4. $this->maintainer = "mitsukarenai";
  5. $this->name = "Lolibooru";
  6. $this->uri = "http://lolibooru.moe/";
  7. $this->description = "Returns images from given page and tags";
  8. $this->parameters[] = array(
  9. 'p'=>array(
  10. 'name'=>'page',
  11. 'type'=>'number'
  12. ),
  13. 't'=>array('name'=>'tags')
  14. );
  15. }
  16. public function collectData(array $param){
  17. $page = 1; $tags = '';
  18. if (isset($param['p'])) {
  19. $page = (int)preg_replace("/[^0-9]/",'', $param['p']);
  20. }
  21. if (isset($param['t'])) {
  22. $tags = urlencode($param['t']);
  23. }
  24. $html = $this->getSimpleHTMLDOM("http://lolibooru.moe/post?page=$page&tags=$tags") or $this->returnServerError('Could not request Lolibooru.');
  25. $input_json = explode('Post.register(', $html);
  26. foreach($input_json as $element)
  27. $data[] = preg_replace('/}\)(.*)/', '}', $element);
  28. unset($data[0]);
  29. foreach($data as $datai) {
  30. $json = json_decode($datai, TRUE);
  31. $item = array();
  32. $item['uri'] = 'http://lolibooru.moe/post/show/'.$json['id'];
  33. $item['postid'] = $json['id'];
  34. $item['timestamp'] = $json['created_at'];
  35. $item['imageUri'] = $json['file_url'];
  36. $item['title'] = 'Lolibooru | '.$json['id'];
  37. $item['content'] = '<a href="' . $item['imageUri'] . '"><img src="' . $json['preview_url'] . '" /></a><br>Tags: '.$json['tags'];
  38. $this->items[] = $item;
  39. }
  40. }
  41. public function getCacheDuration(){
  42. return 1800; // 30 minutes
  43. }
  44. }