2013-08-11 13:30:41 +02:00
< ? php
class FlickrExploreBridge extends BridgeAbstract {
2015-11-05 16:50:18 +01:00
public function loadMetadatas () {
$this -> maintainer = " sebsauvage " ;
$this -> name = " Flickr Explore " ;
2016-07-30 19:24:06 +02:00
$this -> uri = " https://www.flickr.com/explore " ;
2015-11-05 16:50:18 +01:00
$this -> description = " Returns the latest interesting images from Flickr " ;
2016-07-30 19:24:06 +02:00
$this -> update = " 2016-07-30 " ;
2015-11-05 16:50:18 +01:00
}
2013-08-11 13:30:41 +02:00
public function collectData ( array $param ){
2016-07-30 19:24:06 +02:00
$html = $this -> file_get_html ( 'https://www.flickr.com/explore' ) or $this -> returnError ( 'Could not request Flickr.' , 404 );
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
$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...
2013-08-11 13:30:41 +02:00
$item = new \Item ();
2016-07-30 19:24:06 +02:00
$item -> uri = 'https://flickr.com/photo.gne?id=' . $imageID ;
$item -> thumbnailUri = $imageURI ;
2013-08-11 13:30:41 +02:00
$item -> content = '<a href="' . $item -> uri . '"><img src="' . $item -> thumbnailUri . '" /></a>' ; // FIXME: Filter javascript ?
2016-07-30 19:24:06 +02:00
$item -> title = $imageJSON -> photo -> title -> _content ;
2013-08-11 13:30:41 +02:00
$this -> items [] = $item ;
}
}
public function getName (){
return 'Flickr Explore' ;
}
public function getURI (){
2016-07-30 19:24:06 +02:00
return 'https://www.flickr.com/explore' ;
2013-08-11 13:30:41 +02:00
}
public function getCacheDuration (){
return 21600 ; // 6 hours
}
2014-05-21 19:15:52 +02:00
}