MoebooruBridge.php 1.4 KB

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