forked from blallo/rss-bridge
[FlickrTagBridge] Fix and improve bridge by using the FlickrExploreBridge approach
This commit is contained in:
parent
0f25684e65
commit
7ad8693b5f
1 changed files with 70 additions and 12 deletions
|
@ -1,5 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
class FlickrTagBridge extends BridgeAbstract{
|
class FlickrTagBridge extends BridgeAbstract {
|
||||||
|
|
||||||
const MAINTAINER = "erwang";
|
const MAINTAINER = "erwang";
|
||||||
const NAME = "Flickr TagUser";
|
const NAME = "Flickr TagUser";
|
||||||
|
@ -26,23 +26,81 @@ class FlickrTagBridge extends BridgeAbstract{
|
||||||
public function collectData(){
|
public function collectData(){
|
||||||
switch($this->queriedContext){
|
switch($this->queriedContext){
|
||||||
case 'By keyword':
|
case 'By keyword':
|
||||||
$html = getSimpleHTMLDOM(self::URI.'search/?q='.urlencode($this->getInput('q')).'&s=rec')
|
$key = 'photos';
|
||||||
|
$html = getSimpleHTMLDOM(self::URI . 'search/?q=' . urlencode($this->getInput('q')) . '&s=rec')
|
||||||
or returnServerError('No results for this query.');
|
or returnServerError('No results for this query.');
|
||||||
break;
|
break;
|
||||||
case 'by username':
|
case 'By username':
|
||||||
$html = getSimpleHTMLDOM(self::URI.'photos/'.urlencode($this->getInput('u')).'/')
|
$key = 'photoPageList';
|
||||||
|
$html = getSimpleHTMLDOM(self::URI . 'photos/' . urlencode($this->getInput('u')))
|
||||||
or returnServerError('Requested username can\'t be found.');
|
or returnServerError('Requested username can\'t be found.');
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
returnClientError('Invalid context: ' . $this->queriedContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($html->find('span.photo_container') as $element) {
|
// Find SCRIPT containing JSON data
|
||||||
$item = array();
|
$model = $html->find('.modelExport', 0);
|
||||||
$item['uri'] = self::URI.$element->find('a',0)->href;
|
$model_text = $model->innertext;
|
||||||
$thumbnailUri = $element->find('img',0)->getAttribute('data-defer-src');
|
|
||||||
$item['content'] = '<a href="' . $item['uri'] . '"><img src="' . $thumbnailUri . '" /></a>'; // FIXME: Filter javascript ?
|
// Find start and end of JSON data
|
||||||
$item['title'] = $element->find('a',0)->title;
|
$start = strpos($model_text, 'modelExport:') + strlen('modelExport:');
|
||||||
$this->items[] = $item;
|
$end = strpos($model_text, 'auth:') - strlen('auth:');
|
||||||
|
|
||||||
|
// Dissect JSON data and remove trailing comma
|
||||||
|
$model_text = trim(substr($model_text, $start, $end - $start));
|
||||||
|
$model_text = substr($model_text, 0, strlen($model_text) - 1);
|
||||||
|
|
||||||
|
$model_json = json_decode($model_text, true);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
// Use JSON data to build items
|
||||||
|
foreach(reset($model_json)[0][$key]['_data'] as $element){
|
||||||
|
if($element['id'] === $imageID){
|
||||||
|
$item = array();
|
||||||
|
|
||||||
|
/* Author name depends on scope. On a keyword search the
|
||||||
|
* author is part of the picture data. On a username search
|
||||||
|
* the author is part of the owner data.
|
||||||
|
*/
|
||||||
|
if(array_key_exists('username', $element)){
|
||||||
|
$item['author'] = $element['username'];
|
||||||
|
} elseif (array_key_exists('owner', reset($model_json)[0])){
|
||||||
|
$item['author'] = reset($model_json)[0]['owner']['username'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$item['title'] = (array_key_exists('title', $element) ? $element['title'] : 'Untitled');
|
||||||
|
$item['uri'] = self::URI . 'photo.gne?id=' . $imageID;
|
||||||
|
|
||||||
|
$description = (array_key_exists('description', $element) ? $element['description'] : '');
|
||||||
|
|
||||||
|
$item['content'] = '<a href="'
|
||||||
|
. $item['uri']
|
||||||
|
. '"><img src="'
|
||||||
|
. $imageURI . '" /></a>'
|
||||||
|
. '<br>'
|
||||||
|
. '<p>'
|
||||||
|
. $description
|
||||||
|
. '</p>';
|
||||||
|
|
||||||
|
$this->items[] = $item;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue