BooruprojectBridge.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. class BooruprojectBridge extends BridgeAbstract{
  3. public function loadMetadatas() {
  4. $this->maintainer = "mitsukarenai";
  5. $this->name = "Booruproject";
  6. $this->uri = "http://booru.org/";
  7. $this->description = "Returns images from given page and booruproject instance (****.booru.org)";
  8. $this->update = "2015-09-12";
  9. $this->parameters[] =
  10. '[
  11. {
  12. "name" : "instance (required)",
  13. "required" : "true",
  14. "identifier" : "i"
  15. },
  16. {
  17. "name" : "page",
  18. "identifier" : "p"
  19. },
  20. {
  21. "name" : "tags",
  22. "identifier" : "t"
  23. }
  24. ]';
  25. }
  26. public function collectData(array $param){
  27. $page = 0; $tags = '';
  28. if (!empty($param['p'])) {
  29. $page = (int)preg_replace("/[^0-9]/",'', $param['p']);
  30. $page = $page - 1;
  31. $page = $page * 20;
  32. }
  33. if (!empty($param['t'])) {
  34. $tags = '&tags='.urlencode($param['t']);
  35. }
  36. if (empty($param['i'])) {
  37. $this->returnError('Please enter a ***.booru.org instance.', 404);
  38. }
  39. $html = $this->file_get_html("http://".$param['i'].".booru.org/index.php?page=post&s=list&pid=".$page.$tags) or $this->returnError('Could not request Booruproject.', 404);
  40. foreach($html->find('div[class=content] span') as $element) {
  41. $item = new \Item();
  42. $item->uri = 'http://'.$param['i'].'.booru.org/'.$element->find('a', 0)->href;
  43. $item->postid = (int)preg_replace("/[^0-9]/",'', $element->find('a', 0)->getAttribute('id'));
  44. $item->timestamp = time();
  45. $item->thumbnailUri = $element->find('img', 0)->src;
  46. $item->tags = $element->find('img', 0)->getAttribute('title');
  47. $item->title = 'Booruproject '.$param['i'].' | '.$item->postid;
  48. $item->content = '<a href="' . $item->uri . '"><img src="' . $item->thumbnailUri . '" /></a><br>Tags: '.$item->tags;
  49. $this->items[] = $item;
  50. }
  51. }
  52. public function getName(){
  53. return 'Booruproject';
  54. }
  55. public function getURI(){
  56. return 'http://booru.org/';
  57. }
  58. public function getCacheDuration(){
  59. return 1800; // 30 minutes
  60. }
  61. }