Created
March 26, 2015 23:10
-
-
Save aertmann/0ae87374d4eb3576c631 to your computer and use it in GitHub Desktop.
Get custom data (Flickr feed) in TypoScript using a custom FlowQuery operation in Neos – Included in https://speakerdeck.com/aertmann/tasty-recipes-for-every-day-neos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Venstre\VenstreDk\TypoScript\FlowQueryOperations; | |
use TYPO3\Eel\FlowQuery\FlowQuery; | |
use TYPO3\Eel\FlowQuery\Operations\AbstractOperation; | |
use TYPO3\Flow\Annotations as Flow; | |
class FlickrOperation extends AbstractOperation { | |
const API_KEY = ''; | |
/** | |
* {@inheritdoc} | |
* | |
* @var string | |
*/ | |
static protected $shortName = 'flickr'; | |
/** | |
* {@inheritdoc} | |
* | |
* @var integer | |
*/ | |
static protected $priority = 100; | |
/** | |
* {@inheritdoc} | |
* | |
* @param array (or array-like object) $context onto which this operation should be applied | |
* @return boolean TRUE if the operation can be applied onto the $context, FALSE otherwise | |
*/ | |
public function canEvaluate($context) { | |
return TRUE; | |
} | |
/** | |
* @param FlowQuery $flowQuery the FlowQuery object | |
* @param array $arguments the arguments for this operation | |
* @return void | |
*/ | |
public function evaluate(FlowQuery $flowQuery, array $arguments) { | |
$output = array(); | |
$photos = $this->query('method=flickr.people.getPublicPhotos&api_key=' . self::API_KEY . '&user_id=49542087@N05&safe_search=&per_page=8&page=1&format=json&nojsoncallback=1'); | |
foreach ($photos['photos']['photo'] as $photo) { | |
$sizes = $this->query('method=flickr.photos.getSizes&api_key=' . self::API_KEY . '&photo_id=' . $photo['id'] . '&format=json&nojsoncallback=1'); | |
$output[] = array('source' => $sizes['sizes']['size'][0]['source'], 'url' => 'https://www.flickr.com/photos/101566716@N03/' . $photo['id'], 'title' => $photo['title']); | |
} | |
$flowQuery->setContext($output); | |
} | |
/** | |
* @param string $query | |
* @return array | |
*/ | |
protected function query($query) { | |
return json_decode(file_get_contents('https://api.flickr.com/services/rest/?' . $query), TRUE); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment