XbooruBridge.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. class XbooruBridge extends BridgeAbstract{
  3. public function loadMetadatas() {
  4. $this->maintainer = "mitsukarenai";
  5. $this->name = "Xbooru";
  6. $this->uri = "http://xbooru.com/";
  7. $this->description = "Returns images from given page";
  8. $this->update = "2014-05-25";
  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 = 0;$tags='';
  24. if (isset($param['p'])) {
  25. $page = (int)preg_replace("/[^0-9]/",'', $param['p']);
  26. $page = $page - 1;
  27. $page = $page * 50;
  28. }
  29. if (isset($param['t'])) {
  30. $tags = urlencode($param['t']);
  31. }
  32. $html = $this->file_get_html("http://xbooru.com/index.php?page=post&s=list&tags=$tags&pid=$page") or $this->returnError('Could not request Xbooru.', 404);
  33. foreach($html->find('div[class=content] span') as $element) {
  34. $item = new \Item();
  35. $item->uri = 'http://xbooru.com/'.$element->find('a', 0)->href;
  36. $item->postid = (int)preg_replace("/[^0-9]/",'', $element->getAttribute('id'));
  37. $item->timestamp = time();
  38. $item->thumbnailUri = $element->find('img', 0)->src;
  39. $item->tags = $element->find('img', 0)->getAttribute('alt');
  40. $item->title = 'Xbooru | '.$item->postid;
  41. $item->content = '<a href="' . $item->uri . '"><img src="' . $item->thumbnailUri . '" /></a><br>Tags: '.$item->tags;
  42. $this->items[] = $item;
  43. }
  44. }
  45. public function getName(){
  46. return 'Xbooru';
  47. }
  48. public function getURI(){
  49. return 'http://xbooru.com/';
  50. }
  51. public function getCacheDuration(){
  52. return 1800; // 30 minutes
  53. }
  54. }