FlickrTagBridge.php 1.6 KB

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