LolibooruBridge.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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->update = "2015-03-21";
  9. $this->parameters[] =
  10. '[
  11. {
  12. "name" : "page",
  13. "identifier" : "p",
  14. "type" : "number"
  15. },
  16. {
  17. "name" : "tags",
  18. "identifier" : "t"
  19. }
  20. ]';
  21. }
  22. public function collectData(array $param){
  23. $page = 1; $tags = '';
  24. if (isset($param['p'])) {
  25. $page = (int)preg_replace("/[^0-9]/",'', $param['p']);
  26. }
  27. if (isset($param['t'])) {
  28. $tags = urlencode($param['t']);
  29. }
  30. $html = $this->file_get_html("http://lolibooru.moe/post?page=$page&tags=$tags") or $this->returnError('Could not request Lolibooru.', 404);
  31. $input_json = explode('Post.register(', $html);
  32. foreach($input_json as $element)
  33. $data[] = preg_replace('/}\)(.*)/', '}', $element);
  34. unset($data[0]);
  35. foreach($data as $datai) {
  36. $json = json_decode($datai, TRUE);
  37. $item = new \Item();
  38. $item->uri = 'http://lolibooru.moe/post/show/'.$json['id'];
  39. $item->postid = $json['id'];
  40. $item->timestamp = $json['created_at'];
  41. $item->imageUri = $json['file_url'];
  42. $item->thumbnailUri = $json['preview_url'];
  43. $item->title = 'Lolibooru | '.$json['id'];
  44. $item->content = '<a href="' . $item->imageUri . '"><img src="' . $item->thumbnailUri . '" /></a><br>Tags: '.$json['tags'];
  45. $this->items[] = $item;
  46. }
  47. }
  48. public function getName(){
  49. return 'Lolibooru';
  50. }
  51. public function getURI(){
  52. return 'http://lolibooru.moe/post';
  53. }
  54. public function getCacheDuration(){
  55. return 1800; // 30 minutes
  56. }
  57. }