FlickrExploreBridge.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. class FlickrExploreBridge extends BridgeAbstract{
  3. const MAINTAINER = "sebsauvage";
  4. const NAME = "Flickr Explore";
  5. const URI = "https://www.flickr.com/";
  6. const CACHE_TIMEOUT = 21600; // 6
  7. const DESCRIPTION = "Returns the latest interesting images from Flickr";
  8. public function collectData(){
  9. $html = getSimpleHTMLDOM(self::URI.'explore')
  10. or returnServerError('Could not request Flickr.');
  11. foreach($html->find('.photo-list-photo-view') as $element) {
  12. // Get the styles
  13. $style = explode(';', $element->style);
  14. // Get the background-image style
  15. $backgroundImage = explode(':', end($style));
  16. // URI type : url(//cX.staticflickr.com/X/XXXXX/XXXXXXXXX.jpg)
  17. $imageURI = trim(str_replace(['url(', ')'], '', end($backgroundImage)));
  18. // Get the image ID
  19. $imageURIs = explode('_', basename($imageURI));
  20. $imageID = reset($imageURIs);
  21. // Get the image JSON via Flickr API
  22. $imageJSON = json_decode(getContents(
  23. 'https://api.flickr.com/services/rest/?'
  24. .'method=flickr.photos.getInfo&'
  25. .'api_key=103b574d49bd51f0e18bfe907da44a0f&'
  26. .'photo_id='.$imageID.'&'
  27. .'format=json&'
  28. .'nojsoncallback=1'
  29. )) or returnServerError('Could not request Flickr.'); // FIXME: Request time too long...
  30. $item = array();
  31. $item['uri'] = self::URI.'photo.gne?id='.$imageID;
  32. $item['content'] = '<a href="' . $item['uri'] . '"><img src="' . $imageURI . '" /></a>'; // FIXME: Filter javascript ?
  33. $item['title'] = $imageJSON->photo->title->_content;
  34. $this->items[] = $item;
  35. }
  36. }
  37. }