DanbooruBridge.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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->parameters[] = array(
  9. 'p'=>array('name'=>'page'),
  10. 't'=>array('name'=>'tags')
  11. );
  12. }
  13. public function collectData(array $param){
  14. $page = 1;$tags='';
  15. if (isset($param['p'])) {
  16. $page = (int)preg_replace("/[^0-9]/",'', $param['p']);
  17. }
  18. if (isset($param['t'])) {
  19. $tags = urlencode($param['t']);
  20. }
  21. $html = $this->getSimpleHTMLDOM("http://donmai.us/posts?&page=$page&tags=$tags") or $this->returnServerError('Could not request Danbooru.');
  22. foreach($html->find('div[id=posts] article') as $element) {
  23. $item = array();
  24. $item['uri'] = 'http://donmai.us'.$element->find('a', 0)->href;
  25. $item['postid'] = (int)preg_replace("/[^0-9]/",'', $element->getAttribute('data-id'));
  26. $item['timestamp'] = time();
  27. $thumbnailUri = 'http://donmai.us'.$element->find('img', 0)->src;
  28. $item['tags'] = $element->find('img', 0)->getAttribute('alt');
  29. $item['title'] = 'Danbooru | '.$item['postid'];
  30. $item['content'] = '<a href="' . $item['uri'] . '"><img src="' . $thumbnailUri . '" /></a><br>Tags: '.$item['tags'];
  31. $this->items[] = $item;
  32. }
  33. }
  34. public function getCacheDuration(){
  35. return 1800; // 30 minutes
  36. }
  37. }