1
0

DanbooruBridge.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * RssBridgeDanbooru
  4. * Returns images from given page
  5. * 2014-05-25
  6. *
  7. * @name Danbooru
  8. * @homepage http://donmai.us/
  9. * @description Returns images from given page
  10. * @maintainer mitsukarenai
  11. * @use1(p="page", t="tags")
  12. */
  13. class DanbooruBridge 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://donmai.us/posts?&page=$page&tags=$tags") or $this->returnError('Could not request Danbooru.', 404);
  23. foreach($html->find('div[id=posts] article') as $element) {
  24. $item = new \Item();
  25. $item->uri = 'http://donmai.us'.$element->find('a', 0)->href;
  26. $item->postid = (int)preg_replace("/[^0-9]/",'', $element->getAttribute('data-id'));
  27. $item->timestamp = time();
  28. $item->thumbnailUri = 'http://donmai.us'.$element->find('img', 0)->src;
  29. $item->tags = $element->find('img', 0)->getAttribute('alt');
  30. $item->title = 'Danbooru | '.$item->postid;
  31. $item->content = '<a href="' . $item->uri . '"><img src="' . $item->thumbnailUri . '" /></a><br>Tags: '.$item->tags;
  32. $this->items[] = $item;
  33. }
  34. }
  35. public function getName(){
  36. return 'Danbooru';
  37. }
  38. public function getURI(){
  39. return 'http://donmai.us/';
  40. }
  41. public function getCacheDuration(){
  42. return 1800; // 30 minutes
  43. }
  44. }