2013-08-11 15:30:41 +04:00
|
|
|
<?php
|
|
|
|
class FlickrExploreBridge extends BridgeAbstract{
|
|
|
|
|
2016-08-27 22:03:26 +03:00
|
|
|
public $maintainer = "sebsauvage";
|
|
|
|
public $name = "Flickr Explore";
|
2016-08-28 20:46:49 +03:00
|
|
|
public $uri = "https://www.flickr.com/";
|
2016-08-27 22:03:26 +03:00
|
|
|
public $description = "Returns the latest interesting images from Flickr";
|
2015-11-05 18:50:18 +03:00
|
|
|
|
2016-08-25 02:24:53 +03:00
|
|
|
public function collectData(){
|
2016-08-28 20:46:49 +03:00
|
|
|
$html = $this->getSimpleHTMLDOM($this->uri.'explore')
|
|
|
|
or $this->returnServerError('Could not request Flickr.');
|
2016-07-30 20:24:06 +03:00
|
|
|
|
|
|
|
foreach($html->find('.photo-list-photo-view') as $element) {
|
|
|
|
// Get the styles
|
|
|
|
$style = explode(';', $element->style);
|
|
|
|
// Get the background-image style
|
|
|
|
$backgroundImage = explode(':', end($style));
|
|
|
|
// URI type : url(//cX.staticflickr.com/X/XXXXX/XXXXXXXXX.jpg)
|
|
|
|
$imageURI = trim(str_replace(['url(', ')'], '', end($backgroundImage)));
|
|
|
|
// Get the image ID
|
|
|
|
$imageURIs = explode('_', basename($imageURI));
|
|
|
|
$imageID = reset($imageURIs);
|
|
|
|
|
|
|
|
// Get the image JSON via Flickr API
|
2016-08-28 20:46:49 +03:00
|
|
|
$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...
|
2016-07-30 20:24:06 +03:00
|
|
|
|
2016-08-22 19:55:59 +03:00
|
|
|
$item = array();
|
2016-08-28 20:46:49 +03:00
|
|
|
$item['uri'] = $this->uri.'photo.gne?id='.$imageID;
|
2016-08-22 19:55:59 +03:00
|
|
|
$item['content'] = '<a href="' . $item['uri'] . '"><img src="' . $imageURI . '" /></a>'; // FIXME: Filter javascript ?
|
|
|
|
$item['title'] = $imageJSON->photo->title->_content;
|
2013-08-11 15:30:41 +04:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCacheDuration(){
|
|
|
|
return 21600; // 6 hours
|
|
|
|
}
|
2014-05-21 21:15:52 +04:00
|
|
|
}
|