2014-05-26 19:45:10 +02:00
|
|
|
<?php
|
|
|
|
class FlickrTagBridge extends BridgeAbstract{
|
|
|
|
|
2016-08-30 11:23:55 +02:00
|
|
|
const MAINTAINER = "erwang";
|
|
|
|
const NAME = "Flickr TagUser";
|
|
|
|
const URI = "http://www.flickr.com/";
|
|
|
|
const DESCRIPTION = "Returns the tagged or user images from Flickr";
|
2015-11-05 16:50:18 +01:00
|
|
|
|
2016-08-30 11:23:55 +02:00
|
|
|
const PARAMETERS = array(
|
2016-08-27 21:03:26 +02:00
|
|
|
'By keyword' => array(
|
2016-08-28 19:53:05 +02:00
|
|
|
'q'=>array(
|
|
|
|
'name'=>'keyword',
|
|
|
|
'required'=>true
|
|
|
|
)
|
2016-08-27 21:03:26 +02:00
|
|
|
),
|
2015-11-05 16:50:18 +01:00
|
|
|
|
2016-08-27 21:03:26 +02:00
|
|
|
'By username' => array(
|
2016-08-28 19:53:05 +02:00
|
|
|
'u'=>array(
|
|
|
|
'name'=>'Username',
|
|
|
|
'required'=>true
|
|
|
|
)
|
2016-08-27 21:03:26 +02:00
|
|
|
),
|
|
|
|
);
|
2015-11-05 16:50:18 +01:00
|
|
|
|
2016-08-25 01:24:53 +02:00
|
|
|
public function collectData(){
|
2016-08-28 19:53:05 +02:00
|
|
|
switch($this->queriedContext){
|
|
|
|
case 'By keyword':
|
2016-08-30 11:23:55 +02:00
|
|
|
$html = $this->getSimpleHTMLDOM(self::URI.'search/?q='.urlencode($this->getInput('q')).'&s=rec')
|
2016-08-28 19:53:05 +02:00
|
|
|
or $this->returnServerError('No results for this query.');
|
|
|
|
break;
|
|
|
|
case 'by username':
|
2016-08-30 11:23:55 +02:00
|
|
|
$html = $this->getSimpleHTMLDOM(self::URI.'photos/'.urlencode($this->getInput('u')).'/')
|
2016-08-28 19:53:05 +02:00
|
|
|
or $this->returnServerError('Requested username can\'t be found.');
|
|
|
|
break;
|
2014-05-26 19:45:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach($html->find('span.photo_container') as $element) {
|
2016-08-22 18:55:59 +02:00
|
|
|
$item = array();
|
2016-08-30 11:23:55 +02:00
|
|
|
$item['uri'] = self::URI.$element->find('a',0)->href;
|
2016-08-09 15:50:25 +02:00
|
|
|
$thumbnailUri = $element->find('img',0)->getAttribute('data-defer-src');
|
2016-08-22 18:55:59 +02:00
|
|
|
$item['content'] = '<a href="' . $item['uri'] . '"><img src="' . $thumbnailUri . '" /></a>'; // FIXME: Filter javascript ?
|
|
|
|
$item['title'] = $element->find('a',0)->title;
|
2014-05-26 19:45:10 +02:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCacheDuration(){
|
|
|
|
return 21600; // 6 hours
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|