diff --git a/bridges/FlickrExploreBridge.php b/bridges/FlickrExploreBridge.php index 170bec03..53226592 100644 --- a/bridges/FlickrExploreBridge.php +++ b/bridges/FlickrExploreBridge.php @@ -1,42 +1,68 @@ 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); + // Find SCRIPT containing JSON data + $model = $html->find('.modelExport', 0); + $model_text = $model->innertext; - // Get the image JSON via Flickr API - $imageJSON = json_decode(getContents( - 'https://api.flickr.com/services/rest/?' - .'method=flickr.photos.getInfo&' - .'api_key=103b574d49bd51f0e18bfe907da44a0f&' - .'photo_id='.$imageID.'&' - .'format=json&' - .'nojsoncallback=1' - )) or returnServerError('Could not request Flickr.'); // FIXME: Request time too long... + // Find start and end of JSON data + $start = strpos($model_text, 'modelExport:') + strlen('modelExport:'); + $end = strpos($model_text, 'auth:') - strlen('auth:'); - $item = array(); - $item['uri'] = self::URI.'photo.gne?id='.$imageID; - $item['content'] = ''; // FIXME: Filter javascript ? - $item['title'] = $imageJSON->photo->title->_content; - $this->items[] = $item; + // 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'] = '' + . '
' + . '

' + . $description + . '

'; + + $this->items[] = $item; + + break; + } + } } } }