MoebooruBridge.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. class MoebooruBridge extends BridgeAbstract {
  3. const NAME = 'Moebooru';
  4. const URI = 'https://moe.dev.myconan.net/';
  5. const CACHE_TIMEOUT = 1800; // 30min
  6. const DESCRIPTION = 'Returns images from given page';
  7. const MAINTAINER = 'pmaziere';
  8. const PARAMETERS = array( array(
  9. 'p' => array(
  10. 'name' => 'page',
  11. 'defaultValue' => 1,
  12. 'type' => 'number'
  13. ),
  14. 't' => array(
  15. 'name' => 'tags'
  16. )
  17. ));
  18. protected function getFullURI(){
  19. return $this->getURI()
  20. . 'post?page='
  21. . $this->getInput('p')
  22. . '&tags='
  23. . urlencode($this->getInput('t'));
  24. }
  25. public function collectData(){
  26. $html = getSimpleHTMLDOM($this->getFullURI())
  27. or returnServerError('Could not request ' . $this->getName());
  28. $input_json = explode('Post.register(', $html);
  29. foreach($input_json as $element)
  30. $data[] = preg_replace('/}\)(.*)/', '}', $element);
  31. unset($data[0]);
  32. foreach($data as $datai) {
  33. $json = json_decode($datai, true);
  34. $item = array();
  35. $item['uri'] = $this->getURI() . '/post/show/' . $json['id'];
  36. $item['postid'] = $json['id'];
  37. $item['timestamp'] = $json['created_at'];
  38. $item['imageUri'] = $json['file_url'];
  39. $item['title'] = $this->getName() . ' | ' . $json['id'];
  40. $item['content'] = '<a href="'
  41. . $item['imageUri']
  42. . '"><img src="'
  43. . $json['preview_url']
  44. . '" /></a><br>Tags: '
  45. . $json['tags'];
  46. $this->items[] = $item;
  47. }
  48. }
  49. }