SakugabooruBridge.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. class SakugabooruBridge extends BridgeAbstract{
  3. public function loadMetadatas() {
  4. $this->maintainer = "mitsukarenai";
  5. $this->name = "Sakugabooru";
  6. $this->uri = "http://sakuga.yshi.org/";
  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 = 1;$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://sakuga.yshi.org/post?page=$page&tags=$tags") or $this->returnServerError('Could not request Sakugabooru.');
  25. $input_json = explode('Post.register(', $html);
  26. foreach($input_json as $element)
  27. $data[] = preg_replace('/}\)(.*)/', '}', $element);
  28. unset($data[0]);
  29. foreach($data as $datai) {
  30. $json = json_decode($datai, TRUE);
  31. $item = array();
  32. $item['uri'] = 'http://sakuga.yshi.org/post/show/'.$json['id'];
  33. $item['postid'] = $json['id'];
  34. $item['timestamp'] = $json['created_at'];
  35. $item['imageUri'] = $json['file_url'];
  36. $item['title'] = 'Sakugabooru | '.$json['id'];
  37. $item['content'] = '<a href="' . $item['imageUri'] . '"><img src="' . $json['preview_url'] . '" /></a><br>Tags: '.$json['tags'];
  38. $this->items[] = $item;
  39. }
  40. }
  41. public function getCacheDuration(){
  42. return 1800; // 30 minutes
  43. }
  44. }