2013-08-11 13:30:41 +02:00
|
|
|
<?php
|
2017-02-11 11:26:52 +01:00
|
|
|
class FlickrExploreBridge extends BridgeAbstract {
|
2013-08-11 13:30:41 +02:00
|
|
|
|
2017-02-11 11:26:52 +01:00
|
|
|
const MAINTAINER = "sebsauvage";
|
|
|
|
const NAME = "Flickr Explore";
|
|
|
|
const URI = "https://www.flickr.com/";
|
|
|
|
const CACHE_TIMEOUT = 21600; // 6 hours
|
|
|
|
const DESCRIPTION = "Returns the latest interesting images from Flickr";
|
2015-11-05 16:50:18 +01:00
|
|
|
|
2016-08-25 01:24:53 +02:00
|
|
|
public function collectData(){
|
2017-02-11 11:26:52 +01:00
|
|
|
$html = getSimpleHTMLDOM(self::URI . 'explore')
|
2016-09-25 23:22:33 +02:00
|
|
|
or returnServerError('Could not request Flickr.');
|
2016-07-30 19:24:06 +02:00
|
|
|
|
2017-02-11 11:26:52 +01:00
|
|
|
// Find SCRIPT containing JSON data
|
|
|
|
$model = $html->find('.modelExport', 0);
|
|
|
|
$model_text = $model->innertext;
|
|
|
|
|
|
|
|
// Find start and end of JSON data
|
|
|
|
$start = strpos($model_text, 'modelExport:') + strlen('modelExport:');
|
|
|
|
$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]['photos']['_data'] as $element){
|
|
|
|
if($element['id'] === $imageID){
|
|
|
|
$item = array();
|
|
|
|
$item['author'] = (array_key_exists('username', $element) ? $element['username'] : 'Anonymous');
|
|
|
|
$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;
|
|
|
|
}
|
|
|
|
}
|
2013-08-11 13:30:41 +02:00
|
|
|
}
|
|
|
|
}
|
2014-05-21 19:15:52 +02:00
|
|
|
}
|