SakugabooruBridge.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * RssBridgeSakugabooru
  4. * Returns images from given page
  5. * 2014-05-25
  6. *
  7. * @name Sakugabooru
  8. * @homepage http://sakuga.yshi.org/
  9. * @description Returns images from given page
  10. * @maintainer mitsukarenai
  11. * @use1(p="page",t="tags")
  12. */
  13. class SakugabooruBridge extends BridgeAbstract{
  14. public function collectData(array $param){
  15. $page = 1;$tags='';
  16. if (isset($param['p'])) {
  17. $page = (int)preg_replace("/[^0-9]/",'', $param['p']);
  18. }
  19. if (isset($param['t'])) {
  20. $tags = urlencode($param['t']);
  21. }
  22. $html = file_get_html("http://sakuga.yshi.org/post?page=$page&tags=$tags") or $this->returnError('Could not request Sakugabooru.', 404);
  23. $input_json = explode('Post.register(', $html);
  24. foreach($input_json as $element)
  25. $data[] = preg_replace('/}\)(.*)/', '}', $element);
  26. unset($data[0]);
  27. foreach($data as $datai) {
  28. $json = json_decode($datai, TRUE);
  29. $item = new \Item();
  30. $item->uri = 'http://sakuga.yshi.org/post/show/'.$json['id'];
  31. $item->postid = $json['id'];
  32. $item->timestamp = $json['created_at'];
  33. $item->imageUri = $json['file_url'];
  34. $item->thumbnailUri = $json['preview_url'];
  35. $item->title = 'Sakugabooru | '.$json['id'];
  36. $item->content = '<a href="' . $item->imageUri . '"><img src="' . $item->thumbnailUri . '" /></a><br>Tags: '.$json['tags'];
  37. $this->items[] = $item;
  38. }
  39. }
  40. public function getName(){
  41. return 'Sakugabooru';
  42. }
  43. public function getURI(){
  44. return 'http://sakuga.yshi.org/post';
  45. }
  46. public function getCacheDuration(){
  47. return 1800; // 30 minutes
  48. }
  49. }