FlickrTagBridge.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. class FlickrTagBridge extends BridgeAbstract{
  3. public function loadMetadatas() {
  4. $this->maintainer = "erwang";
  5. $this->name = "Flickr TagUser";
  6. $this->uri = "http://www.flickr.com/";
  7. $this->description = "Returns the tagged or user images from Flickr";
  8. $this->parameters["By keyword"] = array(
  9. 'q'=>array('name'=>'keyword')
  10. );
  11. $this->parameters["By username"] = array(
  12. 'u'=>array('name'=>'Username')
  13. );
  14. }
  15. public function collectData(array $param){
  16. $html = $this->getSimpleHTMLDOM('http://www.flickr.com/search/?q=vendee&s=rec') or $this->returnServerError('Could not request Flickr.');
  17. if (isset($param['q'])) { /* keyword search mode */
  18. $this->request = $param['q'];
  19. $html = $this->getSimpleHTMLDOM('http://www.flickr.com/search/?q='.urlencode($this->request).'&s=rec') or $this->returnServerError('No results for this query.');
  20. }
  21. elseif (isset($param['u'])) { /* user timeline mode */
  22. $this->request = $param['u'];
  23. $html = $this->getSimpleHTMLDOM('http://www.flickr.com/photos/'.urlencode($this->request).'/') or $this->returnServerError('Requested username can\'t be found.');
  24. }
  25. else {
  26. $this->returnClientError('You must specify a keyword or a Flickr username.');
  27. }
  28. foreach($html->find('span.photo_container') as $element) {
  29. $item = array();
  30. $item['uri'] = 'http://flickr.com'.$element->find('a',0)->href;
  31. $thumbnailUri = $element->find('img',0)->getAttribute('data-defer-src');
  32. $item['content'] = '<a href="' . $item['uri'] . '"><img src="' . $thumbnailUri . '" /></a>'; // FIXME: Filter javascript ?
  33. $item['title'] = $element->find('a',0)->title;
  34. $this->items[] = $item;
  35. }
  36. }
  37. public function getCacheDuration(){
  38. return 21600; // 6 hours
  39. }
  40. }