FlickrTagBridge.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. class FlickrTagBridge extends BridgeAbstract{
  3. const MAINTAINER = "erwang";
  4. const NAME = "Flickr TagUser";
  5. const URI = "http://www.flickr.com/";
  6. const DESCRIPTION = "Returns the tagged or user images from Flickr";
  7. const PARAMETERS = array(
  8. 'By keyword' => array(
  9. 'q'=>array(
  10. 'name'=>'keyword',
  11. 'required'=>true
  12. )
  13. ),
  14. 'By username' => array(
  15. 'u'=>array(
  16. 'name'=>'Username',
  17. 'required'=>true
  18. )
  19. ),
  20. );
  21. public function collectData(){
  22. switch($this->queriedContext){
  23. case 'By keyword':
  24. $html = getSimpleHTMLDOM(self::URI.'search/?q='.urlencode($this->getInput('q')).'&s=rec')
  25. or returnServerError('No results for this query.');
  26. break;
  27. case 'by username':
  28. $html = getSimpleHTMLDOM(self::URI.'photos/'.urlencode($this->getInput('u')).'/')
  29. or returnServerError('Requested username can\'t be found.');
  30. break;
  31. }
  32. foreach($html->find('span.photo_container') as $element) {
  33. $item = array();
  34. $item['uri'] = self::URI.$element->find('a',0)->href;
  35. $thumbnailUri = $element->find('img',0)->getAttribute('data-defer-src');
  36. $item['content'] = '<a href="' . $item['uri'] . '"><img src="' . $thumbnailUri . '" /></a>'; // FIXME: Filter javascript ?
  37. $item['title'] = $element->find('a',0)->title;
  38. $this->items[] = $item;
  39. }
  40. }
  41. public function getCacheDuration(){
  42. return 21600; // 6 hours
  43. }
  44. }