MoebooruBridge.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 PARAMETERS = array( array(
  8. 'p'=>array(
  9. 'name'=>'page',
  10. 'defaultValue'=>1,
  11. 'type'=>'number'
  12. ),
  13. 't'=>array('name'=>'tags')
  14. ));
  15. protected function getFullURI(){
  16. return $this->getURI().'post?'
  17. .'page='.$this->getInput('p')
  18. .'&tags='.urlencode($this->getInput('t'));
  19. }
  20. public function collectData(){
  21. $html = getSimpleHTMLDOM($this->getFullURI())
  22. or returnServerError('Could not request '.$this->getName());
  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 = array();
  30. $item['uri'] = $this->getURI().'/post/show/'.$json['id'];
  31. $item['postid'] = $json['id'];
  32. $item['timestamp'] = $json['created_at'];
  33. $item['imageUri'] = $json['file_url'];
  34. $item['title'] = $this->getName().' | '.$json['id'];
  35. $item['content'] = '<a href="' . $item['imageUri'] . '"><img src="' . $json['preview_url'] . '" /></a><br>Tags: '.$json['tags'];
  36. $this->items[] = $item;
  37. }
  38. }
  39. }