BooruprojectBridge.php 1.8 KB

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