From d9e3c4c68e58a14248fab6898bd2ea7b304509eb Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Wed, 21 Feb 2024 11:04:06 +0100 Subject: [PATCH 1/2] WIP Read Neos7 Flicker plugin for testing the fusion plugin --- Classes/Controller/FlickrController.php | 81 +++++++++++++++++++ Configuration/Policy.yaml | 7 +- Configuration/Settings.Flickr.yaml | 6 ++ NodeTypes/Content/Flickr.yaml | 33 ++++++++ .../Private/Fusion/Content/Flickr.fusion | 8 ++ Resources/Private/Partials/Flickr/Photo.html | 3 + .../Private/Templates/Flickr/TagStream.html | 13 +++ .../Private/Templates/Flickr/UserStream.html | 13 +++ 8 files changed, 160 insertions(+), 4 deletions(-) create mode 100644 Classes/Controller/FlickrController.php create mode 100644 Configuration/Settings.Flickr.yaml create mode 100644 NodeTypes/Content/Flickr.yaml create mode 100644 Resources/Private/Fusion/Content/Flickr.fusion create mode 100644 Resources/Private/Partials/Flickr/Photo.html create mode 100644 Resources/Private/Templates/Flickr/TagStream.html create mode 100644 Resources/Private/Templates/Flickr/UserStream.html diff --git a/Classes/Controller/FlickrController.php b/Classes/Controller/FlickrController.php new file mode 100644 index 00000000..199f2ad4 --- /dev/null +++ b/Classes/Controller/FlickrController.php @@ -0,0 +1,81 @@ +request->getInternalArgument('__tags') ?: 'default-tag'; // todo how to pass `__tags` from node? + if ($tags === null || $tags === '') { + return '

Please specify Flickr tag(s)

'; + } + $endpointUrl = sprintf($this->tagStreamUriPattern, $tags); + + $this->view->assign('tags', $tags); + $this->view->assign('feed', $this->fetchStream($endpointUrl)); + } + + /** + * @param string|null $userId + * @return void|string + */ + public function userStreamAction($userId = null) + { + if ($userId === null) { + return '

No user specified

'; + } + $endpointUrl = sprintf($this->userStreamUriPattern, $userId); + $this->view->assign('feed', $this->fetchStream($endpointUrl)); + } + + /** + * @param string $endpointUrl + * @return array + */ + protected function fetchStream(string $endpointUrl) + { + $stream = file_get_contents($endpointUrl); + return json_decode($stream, true); + } + + /** + * Disable the default error flash message + * + * @return boolean + */ + protected function getErrorFlashMessage() + { + return false; + } +} diff --git a/Configuration/Policy.yaml b/Configuration/Policy.yaml index 5a23a688..fe7ac4b4 100644 --- a/Configuration/Policy.yaml +++ b/Configuration/Policy.yaml @@ -4,12 +4,11 @@ privilegeTargets: 'Neos\Flow\Security\Authorization\Privilege\Method\MethodPrivilege': - - Neos_Demo_RegistrationAccess: - matcher: method(Neos\Demo\Controller\RegistrationController->(index|newAccount|createAccount|createTemporaryAccount)Action()) + Neos_Demo_FlickrAccess: + matcher: method(Neos\Demo\Controller\FlickrController->(tagStream|userStream)Action()) roles: 'Neos.Flow:Everybody': privileges: - - privilegeTarget: Neos_Demo_RegistrationAccess + - privilegeTarget: Neos_Demo_FlickrAccess permission: GRANT diff --git a/Configuration/Settings.Flickr.yaml b/Configuration/Settings.Flickr.yaml new file mode 100644 index 00000000..ccde136a --- /dev/null +++ b/Configuration/Settings.Flickr.yaml @@ -0,0 +1,6 @@ + +Neos: + Demo: + flickr: + tagStreamUriPattern: 'http://api.flickr.com/services/feeds/photos_public.gne?format=json&nojsoncallback=1&tags=%s' + userStreamUriPattern: 'http://api.flickr.com/services/feeds/photos_public.gne?format=json&nojsoncallback=1&id=%s' diff --git a/NodeTypes/Content/Flickr.yaml b/NodeTypes/Content/Flickr.yaml new file mode 100644 index 00000000..1adcf81a --- /dev/null +++ b/NodeTypes/Content/Flickr.yaml @@ -0,0 +1,33 @@ +## +# A simple "Flickr" plugin that demonstrates the "PluginViews"-feature +# +'Neos.Demo:Content.Flickr': + superTypes: + 'Neos.Demo:Constraint.Content.Main': true + 'Neos.Neos:Plugin': true + ui: + label: 'Flickr Plugin' + icon: 'icon-flickr' + inspector: + groups: + 'feed': + label: 'Feed' + icon: 'icon-rss' + help: + message: 'Displays a gallery of images from a flickr stream based on tags.' + options: + # todo weren't plugin views removed? https://github.com/neos/neos-development-collection/pull/4330 + 'pluginViews': + 'UserFeed': + label: 'Neos.Demo:NodeTypes.Content.Flickr:options.pluginViews.userFeed' + controllerActions: + 'Neos\Demo\Controller\FlickrController': ['userStream'] + properties: + 'tags': + type: string + defaultValue: '' + ui: + label: "Tags" + reloadIfChanged: true + inspector: + group: 'feed' diff --git a/Resources/Private/Fusion/Content/Flickr.fusion b/Resources/Private/Fusion/Content/Flickr.fusion new file mode 100644 index 00000000..cf8f3bdf --- /dev/null +++ b/Resources/Private/Fusion/Content/Flickr.fusion @@ -0,0 +1,8 @@ +## +# "Flickr" element, extending "Plugin" +# +prototype(Neos.Demo:Content.Flickr) < prototype(Neos.Neos:Plugin) { + package = 'Neos.Demo' + controller = 'Flickr' + action = 'tagStream' +} diff --git a/Resources/Private/Partials/Flickr/Photo.html b/Resources/Private/Partials/Flickr/Photo.html new file mode 100644 index 00000000..5f38a68d --- /dev/null +++ b/Resources/Private/Partials/Flickr/Photo.html @@ -0,0 +1,3 @@ + + {photo.title} + diff --git a/Resources/Private/Templates/Flickr/TagStream.html b/Resources/Private/Templates/Flickr/TagStream.html new file mode 100644 index 00000000..7e1627fb --- /dev/null +++ b/Resources/Private/Templates/Flickr/TagStream.html @@ -0,0 +1,13 @@ +
+

Photo Stream for tag(s) "{tags}"

+ +
diff --git a/Resources/Private/Templates/Flickr/UserStream.html b/Resources/Private/Templates/Flickr/UserStream.html new file mode 100644 index 00000000..b7b61c72 --- /dev/null +++ b/Resources/Private/Templates/Flickr/UserStream.html @@ -0,0 +1,13 @@ +
+

{feed.title}

+ +
From 8d8b3a09778e4f81e6ab38ec22743c281f223d97 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Thu, 22 Feb 2024 20:59:35 +0100 Subject: [PATCH 2/2] TASK: Fix passing `tags` to plugin --- Classes/Controller/FlickrController.php | 2 +- Resources/Private/Fusion/Content/Flickr.fusion | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Classes/Controller/FlickrController.php b/Classes/Controller/FlickrController.php index 199f2ad4..0d4ee565 100644 --- a/Classes/Controller/FlickrController.php +++ b/Classes/Controller/FlickrController.php @@ -36,7 +36,7 @@ class FlickrController extends ActionController */ public function tagStreamAction() { - $tags = $this->request->getInternalArgument('__tags') ?: 'default-tag'; // todo how to pass `__tags` from node? + $tags = $this->request->getInternalArgument('__tags'); if ($tags === null || $tags === '') { return '

Please specify Flickr tag(s)

'; } diff --git a/Resources/Private/Fusion/Content/Flickr.fusion b/Resources/Private/Fusion/Content/Flickr.fusion index cf8f3bdf..7dac70ef 100644 --- a/Resources/Private/Fusion/Content/Flickr.fusion +++ b/Resources/Private/Fusion/Content/Flickr.fusion @@ -5,4 +5,6 @@ prototype(Neos.Demo:Content.Flickr) < prototype(Neos.Neos:Plugin) { package = 'Neos.Demo' controller = 'Flickr' action = 'tagStream' + + tags = ${q(node).property('tags')} }