2014-05-26 19:45:10 +02:00
< ? php
class FlickrTagBridge extends BridgeAbstract {
2015-11-05 16:50:18 +01:00
public function loadMetadatas () {
$this -> maintainer = " erwang " ;
$this -> name = " Flickr TagUser " ;
$this -> uri = " http://www.flickr.com/ " ;
$this -> description = " Returns the tagged or user images from Flickr " ;
2016-08-09 15:50:25 +02:00
$this -> update = " 2016-08-09 " ;
2015-11-05 16:50:18 +01:00
$this -> parameters [ " By keyword " ] =
' [
{
" name " : " Keyword " ,
" identifier " : " q "
}
] ' ;
$this -> parameters [ " By username " ] =
' [
{
" name " : " Username " ,
" identifier " : " u "
}
] ' ;
}
2014-05-26 19:45:10 +02:00
public function collectData ( array $param ){
2016-06-25 23:17:42 +02:00
$html = $this -> file_get_html ( 'http://www.flickr.com/search/?q=vendee&s=rec' ) or $this -> returnError ( 'Could not request Flickr.' , 404 );
2014-05-26 19:45:10 +02:00
if ( isset ( $param [ 'q' ])) { /* keyword search mode */
$this -> request = $param [ 'q' ];
2016-06-25 23:17:42 +02:00
$html = $this -> file_get_html ( 'http://www.flickr.com/search/?q=' . urlencode ( $this -> request ) . '&s=rec' ) or $this -> returnError ( 'No results for this query.' , 404 );
2014-05-26 19:45:10 +02:00
}
elseif ( isset ( $param [ 'u' ])) { /* user timeline mode */
$this -> request = $param [ 'u' ];
2016-06-25 23:17:42 +02:00
$html = $this -> file_get_html ( 'http://www.flickr.com/photos/' . urlencode ( $this -> request ) . '/' ) or $this -> returnError ( 'Requested username can\'t be found.' , 404 );
2014-05-26 19:45:10 +02:00
}
else {
$this -> returnError ( 'You must specify a keyword or a Flickr username.' , 400 );
}
foreach ( $html -> find ( 'span.photo_container' ) as $element ) {
$item = new \Item ();
$item -> uri = 'http://flickr.com' . $element -> find ( 'a' , 0 ) -> href ;
2016-08-09 15:50:25 +02:00
$thumbnailUri = $element -> find ( 'img' , 0 ) -> getAttribute ( 'data-defer-src' );
$item -> content = '<a href="' . $item -> uri . '"><img src="' . $thumbnailUri . '" /></a>' ; // FIXME: Filter javascript ?
2014-05-26 19:45:10 +02:00
$item -> title = $element -> find ( 'a' , 0 ) -> title ;
$this -> items [] = $item ;
}
}
public function getCacheDuration (){
return 21600 ; // 6 hours
}
}