MilbooruBridge.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. class MilbooruBridge extends BridgeAbstract{
  3. public function loadMetadatas() {
  4. $this->maintainer = "mitsukarenai";
  5. $this->name = "Milbooru";
  6. $this->uri = "http://sheslostcontrol.net/moe/shimmie/";
  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. }
  21. if (isset($param['t'])) {
  22. $tags = urlencode($param['t']);
  23. }
  24. $html = $this->getSimpleHTMLDOM("http://sheslostcontrol.net/moe/shimmie/index.php?q=/post/list/$tags/$page") or $this->returnServerError('Could not request Milbooru.');
  25. foreach($html->find('div[class=shm-image-list] span[class=thumb]') as $element) {
  26. $item = array();
  27. $item['uri'] = 'http://sheslostcontrol.net/moe/shimmie/'.$element->find('a', 0)->href;
  28. $item['postid'] = (int)preg_replace("/[^0-9]/",'', $element->find('a', 0)->getAttribute('data-post-id'));
  29. $item['timestamp'] = time();
  30. $thumbnailUri = 'http://sheslostcontrol.net/moe/shimmie/'.$element->find('img', 0)->src;
  31. $item['tags'] = $element->find('a', 0)->getAttribute('data-tags');
  32. $item['title'] = 'Milbooru | '.$item['postid'];
  33. $item['content'] = '<a href="' . $item['uri'] . '"><img src="' . $thumbnailUri . '" /></a><br>Tags: '.$item['tags'];
  34. $this->items[] = $item;
  35. }
  36. }
  37. public function getCacheDuration(){
  38. return 1800; // 30 minutes
  39. }
  40. }