Rss-Bridge/bridges/FlickrTagBridge.php
Pierre Mazière 235c985901 [BridgeAbstract] replace getCacheDuration method by CACHE_TIMEOUT class constant
Signed-off-by: Pierre Mazière <pierre.maziere@gmx.com>
2016-09-25 17:04:28 +02:00

49 lines
1.6 KiB
PHP

<?php
class FlickrTagBridge extends BridgeAbstract{
const MAINTAINER = "erwang";
const NAME = "Flickr TagUser";
const URI = "http://www.flickr.com/";
const CACHE_TIMEOUT = 21600; //6h
const DESCRIPTION = "Returns the tagged or user images from Flickr";
const PARAMETERS = array(
'By keyword' => array(
'q'=>array(
'name'=>'keyword',
'required'=>true
)
),
'By username' => array(
'u'=>array(
'name'=>'Username',
'required'=>true
)
),
);
public function collectData(){
switch($this->queriedContext){
case 'By keyword':
$html = $this->getSimpleHTMLDOM(self::URI.'search/?q='.urlencode($this->getInput('q')).'&s=rec')
or $this->returnServerError('No results for this query.');
break;
case 'by username':
$html = $this->getSimpleHTMLDOM(self::URI.'photos/'.urlencode($this->getInput('u')).'/')
or $this->returnServerError('Requested username can\'t be found.');
break;
}
foreach($html->find('span.photo_container') as $element) {
$item = array();
$item['uri'] = self::URI.$element->find('a',0)->href;
$thumbnailUri = $element->find('img',0)->getAttribute('data-defer-src');
$item['content'] = '<a href="' . $item['uri'] . '"><img src="' . $thumbnailUri . '" /></a>'; // FIXME: Filter javascript ?
$item['title'] = $element->find('a',0)->title;
$this->items[] = $item;
}
}
}