FlickrExploreBridge.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. class FlickrExploreBridge extends BridgeAbstract{
  3. public function loadMetadatas() {
  4. $this->maintainer = "sebsauvage";
  5. $this->name = "Flickr Explore";
  6. $this->uri = "https://www.flickr.com/explore";
  7. $this->description = "Returns the latest interesting images from Flickr";
  8. }
  9. public function collectData(array $param){
  10. $html = $this->getSimpleHTMLDOM('https://www.flickr.com/explore') or $this->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($this->getContents('https://api.flickr.com/services/rest/?method=flickr.photos.getInfo&api_key=103b574d49bd51f0e18bfe907da44a0f&photo_id='.$imageID.'&format=json&nojsoncallback=1')) or $this->returnServerError('Could not request Flickr.'); // FIXME: Request time too long...
  23. $item = array();
  24. $item['uri'] = 'https://flickr.com/photo.gne?id='.$imageID;
  25. $item['content'] = '<a href="' . $item['uri'] . '"><img src="' . $imageURI . '" /></a>'; // FIXME: Filter javascript ?
  26. $item['title'] = $imageJSON->photo->title->_content;
  27. $this->items[] = $item;
  28. }
  29. }
  30. public function getCacheDuration(){
  31. return 21600; // 6 hours
  32. }
  33. }