FlickrTagBridge.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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->update = "2014-05-26";
  9. $this->parameters["By keyword"] =
  10. '[
  11. {
  12. "name" : "Keyword",
  13. "identifier" : "q"
  14. }
  15. ]';
  16. $this->parameters["By username"] =
  17. '[
  18. {
  19. "name" : "Username",
  20. "identifier" : "u"
  21. }
  22. ]';
  23. }
  24. public function collectData(array $param){
  25. $html = $this->file_get_html('http://www.flickr.com/search/?q=vendee&s=rec') or $this->returnError('Could not request Flickr.', 404);
  26. if (isset($param['q'])) { /* keyword search mode */
  27. $this->request = $param['q'];
  28. $html = $this->file_get_html('http://www.flickr.com/search/?q='.urlencode($this->request).'&s=rec') or $this->returnError('No results for this query.', 404);
  29. }
  30. elseif (isset($param['u'])) { /* user timeline mode */
  31. $this->request = $param['u'];
  32. $html = $this->file_get_html('http://www.flickr.com/photos/'.urlencode($this->request).'/') or $this->returnError('Requested username can\'t be found.', 404);
  33. }
  34. else {
  35. $this->returnError('You must specify a keyword or a Flickr username.', 400);
  36. }
  37. foreach($html->find('span.photo_container') as $element) {
  38. $item = new \Item();
  39. $item->uri = 'http://flickr.com'.$element->find('a',0)->href;
  40. $item->thumbnailUri = $element->find('img',0)->getAttribute('data-defer-src');
  41. $item->content = '<a href="' . $item->uri . '"><img src="' . $item->thumbnailUri . '" /></a>'; // FIXME: Filter javascript ?
  42. $item->title = $element->find('a',0)->title;
  43. $this->items[] = $item;
  44. }
  45. }
  46. public function getName(){
  47. return 'Flickr Tag';
  48. }
  49. public function getURI(){
  50. return 'http://www.flickr.com/search/';
  51. }
  52. public function getCacheDuration(){
  53. return 21600; // 6 hours
  54. }
  55. }