GelbooruBridge.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. class GelbooruBridge extends BridgeAbstract{
  3. public function loadMetadatas() {
  4. $this->maintainer = "mitsukarenai";
  5. $this->name = "Gelbooru";
  6. $this->uri = "http://gelbooru.com/";
  7. $this->description = "Returns images from given page";
  8. $this->parameters[] = array(
  9. 'p'=>array(
  10. 'name'=>'page',
  11. 'type'=>'number'
  12. ),
  13. 't'=>array('name'=>'tags')
  14. );
  15. }
  16. public function collectData(array $param){
  17. $page = 0;
  18. if (isset($param['p'])) {
  19. $page = (int)preg_replace("/[^0-9]/",'', $param['p']);
  20. $page = $page - 1;
  21. $page = $page * 63;
  22. }
  23. if (isset($param['t'])) {
  24. $tags = urlencode($param['t']);
  25. }
  26. $html = $this->getSimpleHTMLDOM("http://gelbooru.com/index.php?page=post&s=list&tags=$tags&pid=$page") or $this->returnServerError('Could not request Gelbooru.');
  27. foreach($html->find('div[class=content] span') as $element) {
  28. $item = array();
  29. $item['uri'] = 'http://gelbooru.com/'.$element->find('a', 0)->href;
  30. $item['postid'] = (int)preg_replace("/[^0-9]/",'', $element->getAttribute('id'));
  31. $item['timestamp'] = time();
  32. $thumbnailUri = $element->find('img', 0)->src;
  33. $item['tags'] = $element->find('img', 0)->getAttribute('alt');
  34. $item['title'] = 'Gelbooru | '.$item['postid'];
  35. $item['content'] = '<a href="' . $item['uri'] . '"><img src="' . $thumbnailUri . '" /></a><br>Tags: '.$item['tags'];
  36. $this->items[] = $item;
  37. }
  38. }
  39. public function getCacheDuration(){
  40. return 1800; // 30 minutes
  41. }
  42. }