2014-05-26 21:45:10 +04:00
< ? php
class FlickrTagBridge extends BridgeAbstract {
2015-11-05 18:50:18 +03: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-22 02:25:56 +03:00
$this -> parameters [ " By keyword " ] = array (
'q' => array ( 'name' => 'keyword' )
);
2015-11-05 18:50:18 +03:00
2016-08-22 02:25:56 +03:00
$this -> parameters [ " By username " ] = array (
'u' => array ( 'name' => 'Username' )
);
2015-11-05 18:50:18 +03:00
}
2016-08-25 02:24:53 +03:00
public function collectData (){
$param = $this -> parameters [ $this -> queriedContext ];
2016-07-08 20:06:35 +03:00
$html = $this -> getSimpleHTMLDOM ( 'http://www.flickr.com/search/?q=vendee&s=rec' ) or $this -> returnServerError ( 'Could not request Flickr.' );
2016-08-25 02:24:53 +03:00
if ( isset ( $param [ 'q' ][ 'value' ])) { /* keyword search mode */
$this -> request = $param [ 'q' ][ 'value' ];
2016-07-08 20:06:35 +03:00
$html = $this -> getSimpleHTMLDOM ( 'http://www.flickr.com/search/?q=' . urlencode ( $this -> request ) . '&s=rec' ) or $this -> returnServerError ( 'No results for this query.' );
2014-05-26 21:45:10 +04:00
}
2016-08-25 02:24:53 +03:00
elseif ( isset ( $param [ 'u' ][ 'value' ])) { /* user timeline mode */
$this -> request = $param [ 'u' ][ 'value' ];
2016-07-08 20:06:35 +03:00
$html = $this -> getSimpleHTMLDOM ( 'http://www.flickr.com/photos/' . urlencode ( $this -> request ) . '/' ) or $this -> returnServerError ( 'Requested username can\'t be found.' );
2014-05-26 21:45:10 +04:00
}
2016-07-08 20:06:35 +03:00
2014-05-26 21:45:10 +04:00
else {
2016-08-17 15:45:08 +03:00
$this -> returnClientError ( 'You must specify a keyword or a Flickr username.' );
2014-05-26 21:45:10 +04:00
}
foreach ( $html -> find ( 'span.photo_container' ) as $element ) {
2016-08-22 19:55:59 +03:00
$item = array ();
$item [ 'uri' ] = 'http://flickr.com' . $element -> find ( 'a' , 0 ) -> href ;
2016-08-09 16:50:25 +03:00
$thumbnailUri = $element -> find ( 'img' , 0 ) -> getAttribute ( 'data-defer-src' );
2016-08-22 19:55:59 +03:00
$item [ 'content' ] = '<a href="' . $item [ 'uri' ] . '"><img src="' . $thumbnailUri . '" /></a>' ; // FIXME: Filter javascript ?
$item [ 'title' ] = $element -> find ( 'a' , 0 ) -> title ;
2014-05-26 21:45:10 +04:00
$this -> items [] = $item ;
}
}
public function getCacheDuration (){
return 21600 ; // 6 hours
}
}