FlickrExploreBridge.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. $this->update = "2016-07-30";
  9. }
  10. public function collectData(array $param){
  11. $html = $this->file_get_html('https://www.flickr.com/explore') or $this->returnError('Could not request Flickr.', 404);
  12. foreach($html->find('.photo-list-photo-view') as $element) {
  13. // Get the styles
  14. $style = explode(';', $element->style);
  15. // Get the background-image style
  16. $backgroundImage = explode(':', end($style));
  17. // URI type : url(//cX.staticflickr.com/X/XXXXX/XXXXXXXXX.jpg)
  18. $imageURI = trim(str_replace(['url(', ')'], '', end($backgroundImage)));
  19. // Get the image ID
  20. $imageURIs = explode('_', basename($imageURI));
  21. $imageID = reset($imageURIs);
  22. // Get the image JSON via Flickr API
  23. $imageJSON = json_decode(file_get_contents('https://api.flickr.com/services/rest/?method=flickr.photos.getInfo&api_key=103b574d49bd51f0e18bfe907da44a0f&photo_id='.$imageID.'&format=json&nojsoncallback=1')) or $this->returnError('Could not request Flickr.', 404); // FIXME: Request time too long...
  24. $item = new \Item();
  25. $item->uri = 'https://flickr.com/photo.gne?id='.$imageID;
  26. $item->thumbnailUri = $imageURI;
  27. $item->content = '<a href="' . $item->uri . '"><img src="' . $item->thumbnailUri . '" /></a>'; // FIXME: Filter javascript ?
  28. $item->title = $imageJSON->photo->title->_content;
  29. $this->items[] = $item;
  30. }
  31. }
  32. public function getName(){
  33. return 'Flickr Explore';
  34. }
  35. public function getURI(){
  36. return 'https://www.flickr.com/explore';
  37. }
  38. public function getCacheDuration(){
  39. return 21600; // 6 hours
  40. }
  41. }