DanbooruBridge.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. class DanbooruBridge extends BridgeAbstract{
  3. public function loadMetadatas() {
  4. $this->maintainer = "mitsukarenai";
  5. $this->name = "Danbooru";
  6. $this->uri = "http://donmai.us/";
  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. },
  15. {
  16. "name" : "tags",
  17. "identifier" : "t"
  18. }
  19. ]';
  20. }
  21. public function collectData(array $param){
  22. $page = 1;$tags='';
  23. if (isset($param['p'])) {
  24. $page = (int)preg_replace("/[^0-9]/",'', $param['p']);
  25. }
  26. if (isset($param['t'])) {
  27. $tags = urlencode($param['t']);
  28. }
  29. $html = $this->file_get_html("http://donmai.us/posts?&page=$page&tags=$tags") or $this->returnError('Could not request Danbooru.', 404);
  30. foreach($html->find('div[id=posts] article') as $element) {
  31. $item = new \Item();
  32. $item->uri = 'http://donmai.us'.$element->find('a', 0)->href;
  33. $item->postid = (int)preg_replace("/[^0-9]/",'', $element->getAttribute('data-id'));
  34. $item->timestamp = time();
  35. $item->thumbnailUri = 'http://donmai.us'.$element->find('img', 0)->src;
  36. $item->tags = $element->find('img', 0)->getAttribute('alt');
  37. $item->title = 'Danbooru | '.$item->postid;
  38. $item->content = '<a href="' . $item->uri . '"><img src="' . $item->thumbnailUri . '" /></a><br>Tags: '.$item->tags;
  39. $this->items[] = $item;
  40. }
  41. }
  42. public function getName(){
  43. return 'Danbooru';
  44. }
  45. public function getURI(){
  46. return 'http://donmai.us/';
  47. }
  48. public function getCacheDuration(){
  49. return 1800; // 30 minutes
  50. }
  51. }