FlickrTagBridge.php 1.9 KB

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