XbooruBridge.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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->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;$tags='';
  18. if (isset($param['p'])) {
  19. $page = (int)preg_replace("/[^0-9]/",'', $param['p']);
  20. $page = $page - 1;
  21. $page = $page * 50;
  22. }
  23. if (isset($param['t'])) {
  24. $tags = urlencode($param['t']);
  25. }
  26. $html = $this->getSimpleHTMLDOM("http://xbooru.com/index.php?page=post&s=list&tags=$tags&pid=$page") or $this->returnServerError('Could not request Xbooru.');
  27. foreach($html->find('div[class=content] span') as $element) {
  28. $item = array();
  29. $item['uri'] = 'http://xbooru.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'] = 'Xbooru | '.$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. }