FlickrExploreBridge.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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-08-09";
  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->content = '<a href="' . $item->uri . '"><img src="' . $imageURI . '" /></a>'; // FIXME: Filter javascript ?
  27. $item->title = $imageJSON->photo->title->_content;
  28. $this->items[] = $item;
  29. }
  30. }
  31. public function getName(){
  32. return 'Flickr Explore';
  33. }
  34. public function getURI(){
  35. return 'https://www.flickr.com/explore';
  36. }
  37. public function getCacheDuration(){
  38. return 21600; // 6 hours
  39. }
  40. }