BooruprojectBridge.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * RssBridgeBooruproject
  4. * Returns images from given page
  5. * 2014-05-25
  6. *
  7. * @name Booruproject
  8. * @homepage http://booru.org/
  9. * @description Returns images from given page and booruproject instance (****.booru.org)
  10. * @maintainer mitsukarenai
  11. * @use1(i="instance (required)", p="page", t="tags")
  12. */
  13. class BooruprojectBridge extends BridgeAbstract{
  14. public function collectData(array $param){
  15. $page = 0; $tags = '';
  16. if (isset($param['p'])) {
  17. $page = (int)preg_replace("/[^0-9]/",'', $param['p']);
  18. $page = $page - 1;
  19. $page = $page * 20;
  20. }
  21. if (isset($param['t'])) {
  22. $tags = '&tags='.urlencode($param['t']);
  23. }
  24. if (empty($param['i'])) {
  25. $this->returnError('Please enter a ***.booru.org instance.', 404);
  26. }
  27. $html = file_get_html("http://".$param['i'].".booru.org/index.php?page=post&s=list&pid=".$page.$tags) or $this->returnError('Could not request Booruproject.', 404);
  28. foreach($html->find('div[class=content] span') as $element) {
  29. $item = new \Item();
  30. $item->uri = 'http://'.$param['i'].'.booru.org/'.$element->find('a', 0)->href;
  31. $item->postid = (int)preg_replace("/[^0-9]/",'', $element->find('a', 0)->getAttribute('id'));
  32. $item->timestamp = time();
  33. $item->thumbnailUri = $element->find('img', 0)->src;
  34. $item->tags = $element->find('img', 0)->getAttribute('title');
  35. $item->title = 'Booruproject '.$param['i'].' | '.$item->postid;
  36. $item->content = '<a href="' . $item->uri . '"><img src="' . $item->thumbnailUri . '" /></a><br>Tags: '.$item->tags;
  37. $this->items[] = $item;
  38. }
  39. }
  40. public function getName(){
  41. return 'Booruproject';
  42. }
  43. public function getURI(){
  44. return 'http://booru.org/';
  45. }
  46. public function getCacheDuration(){
  47. return 1800; // 30 minutes
  48. }
  49. }