From ac5a3e778724acb714c517d9387b10c175e4eb7f Mon Sep 17 00:00:00 2001 From: Mathias Arzberger Date: Tue, 7 Jan 2025 14:43:12 +0100 Subject: [PATCH 1/9] fix for instagram business --- src/EventListener/DataContainer/SocialFeedListener.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/EventListener/DataContainer/SocialFeedListener.php b/src/EventListener/DataContainer/SocialFeedListener.php index d8709c9..0b964e6 100644 --- a/src/EventListener/DataContainer/SocialFeedListener.php +++ b/src/EventListener/DataContainer/SocialFeedListener.php @@ -145,7 +145,7 @@ private function requestAccessToken($clientId): void 'app_id' => $clientId, 'redirect_uri' => $this->router->generate('instagram_auth', [], RouterInterface::ABSOLUTE_URL), 'response_type' => 'code', - 'scope' => 'user_profile,user_media', + 'scope' => 'instagram_business_basic', ]; throw new RedirectResponseException('https://api.instagram.com/oauth/authorize/?'.http_build_query($data)); From 9625dd596f556e70db36c9c417f9b875600608b0 Mon Sep 17 00:00:00 2001 From: Philipp Seibt Date: Tue, 7 Jan 2025 16:16:48 +0100 Subject: [PATCH 2/9] Add :TreeBuilder to getConfigTreeBuilder() --- src/DependencyInjection/Configuration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 0dcc0a4..d1abe82 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -28,7 +28,7 @@ class Configuration implements ConfigurationInterface /** * @inheritDoc */ - public function getConfigTreeBuilder() + public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('pdir_socialfeed'); From 8d7eb28cf9f2086d9dd188f49b770ac4bc4175fe Mon Sep 17 00:00:00 2001 From: Mathias Arzberger Date: Tue, 7 Jan 2025 17:00:20 +0100 Subject: [PATCH 3/9] use attribute --- config/routes.yaml | 2 +- src/Controller/FacebookController.php | 4 +--- src/Controller/InstagramController.php | 4 +--- src/Controller/LinkedinController.php | 4 +--- 4 files changed, 4 insertions(+), 10 deletions(-) diff --git a/config/routes.yaml b/config/routes.yaml index 58da485..23b4204 100644 --- a/config/routes.yaml +++ b/config/routes.yaml @@ -1,3 +1,3 @@ pdir_social_feed.controller: resource: ../src/Controller - type: annotation + type: attribute diff --git a/src/Controller/FacebookController.php b/src/Controller/FacebookController.php index 154fa77..5535aba 100644 --- a/src/Controller/FacebookController.php +++ b/src/Controller/FacebookController.php @@ -32,9 +32,7 @@ use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\RouterInterface; -/** - * @Route("/_facebook", defaults={"_scope" = "backend", "_token_check" = false}) - */ +#[Route('/_facebook', name: ExampleController::class, defaults: ['_scope' => 'backend', '_token_check' => false])] class FacebookController { private Connection $db; diff --git a/src/Controller/InstagramController.php b/src/Controller/InstagramController.php index 3f3eb72..31c0131 100644 --- a/src/Controller/InstagramController.php +++ b/src/Controller/InstagramController.php @@ -33,9 +33,7 @@ use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; -/** - * @Route("/_instagram", defaults={"_scope" = "backend", "_token_check" = false}) - */ +#[Route('/_instagram', name: ExampleController::class, defaults: ['_scope' => 'backend', '_token_check' => false])] class InstagramController { /** diff --git a/src/Controller/LinkedinController.php b/src/Controller/LinkedinController.php index 4725465..8a4c5b5 100644 --- a/src/Controller/LinkedinController.php +++ b/src/Controller/LinkedinController.php @@ -30,9 +30,7 @@ use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\RouterInterface; -/** - * @Route("/auth", defaults={"_scope" = "backend", "_token_check" = false}) - */ +#[Route('/auth', name: ExampleController::class, defaults: ['_scope' => 'backend', '_token_check' => false])] class LinkedinController { private Connection $db; From 97d7836ddc645d0e3f823e20c153b043a02949a9 Mon Sep 17 00:00:00 2001 From: Mathias Arzberger Date: Tue, 7 Jan 2025 17:01:42 +0100 Subject: [PATCH 4/9] use attribute --- src/Controller/FacebookController.php | 2 +- src/Controller/InstagramController.php | 2 +- src/Controller/LinkedinController.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Controller/FacebookController.php b/src/Controller/FacebookController.php index 5535aba..1afd749 100644 --- a/src/Controller/FacebookController.php +++ b/src/Controller/FacebookController.php @@ -29,7 +29,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Session\SessionInterface; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attributes\Route; use Symfony\Component\Routing\RouterInterface; #[Route('/_facebook', name: ExampleController::class, defaults: ['_scope' => 'backend', '_token_check' => false])] diff --git a/src/Controller/InstagramController.php b/src/Controller/InstagramController.php index 31c0131..79df2df 100644 --- a/src/Controller/InstagramController.php +++ b/src/Controller/InstagramController.php @@ -29,7 +29,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Session\SessionInterface; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; diff --git a/src/Controller/LinkedinController.php b/src/Controller/LinkedinController.php index 8a4c5b5..98fe5b3 100644 --- a/src/Controller/LinkedinController.php +++ b/src/Controller/LinkedinController.php @@ -27,7 +27,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Session\SessionInterface; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Routing\RouterInterface; #[Route('/auth', name: ExampleController::class, defaults: ['_scope' => 'backend', '_token_check' => false])] From 5931a4c9e2311a981ff20c7a038356233dd78c0a Mon Sep 17 00:00:00 2001 From: Mathias Arzberger Date: Tue, 7 Jan 2025 17:39:54 +0100 Subject: [PATCH 5/9] use attribute --- CHANGELOG.md | 5 +++++ config/services.yml | 4 ---- .../DataContainer/SocialFeedListener.php | 21 +++++++------------ 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e8fb31e..e182e1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,11 @@ Types of changes > [!Tip] > Thank you to all [EAP](https://pdir.de/crowdfunding/social-feed-bundle.html) supporters! +## [2.14.0](https://github.com/pdir/social-feed-bundle/tree/2.14.0) - 2025-01-08 + +- [Added] Add compatibility for Contao 5.4+ +- [Fixed] Instagram import (You need a Business ?) + ## [2.13.6](https://github.com/pdir/social-feed-bundle/tree/2.13.6) - 2024-11-21 -[Fixed] Update kevinrob/guzzle-cache-middleware fix #150 🤗 [contaoacademy](https://github.com/contaoacademy) diff --git a/config/services.yml b/config/services.yml index 85fd45f..2da324f 100644 --- a/config/services.yml +++ b/config/services.yml @@ -47,10 +47,6 @@ services: Pdir\SocialFeedBundle\EventListener\DataContainer\SocialFeedListener: public: true - arguments: - - "@router" - - '@security.helper' - - '@contao.image.sizes' pdir_social_feed_moderate.controller: class: Pdir\SocialFeedBundle\Controller\ModerateController diff --git a/src/EventListener/DataContainer/SocialFeedListener.php b/src/EventListener/DataContainer/SocialFeedListener.php index 0b964e6..e71817b 100644 --- a/src/EventListener/DataContainer/SocialFeedListener.php +++ b/src/EventListener/DataContainer/SocialFeedListener.php @@ -30,34 +30,27 @@ use Pdir\SocialFeedBundle\EventListener\Config; use Symfony\Component\HttpFoundation\Session\SessionInterface; use Symfony\Component\Routing\RouterInterface; -use Symfony\Component\Security\Core\Security; +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; class SocialFeedListener { public const SESSION_KEY = 'social-feed-id'; - /** - * @var RouterInterface - */ - private $router; - /** * @var SessionInterface */ private $session; - private Security $security; - private ImageSizes $imageSizes; - /** * ModuleListener constructor. */ - public function __construct(RouterInterface $router, Security $security, ImageSizes $imageSizes) + public function __construct( + private readonly RouterInterface $router, + private readonly TokenStorageInterface $tokenStorage, + private readonly ImageSizes $imageSizes + ) { - $this->router = $router; $this->session = System::getContainer()->get('request_stack')->getCurrentRequest()->getSession(); - $this->security = $security; - $this->imageSizes = $imageSizes; } /** @@ -92,7 +85,7 @@ public function onRequestTokenSave() */ public function getImageSizeOptions(): array { - $user = $this->security->getUser(); + $user = $this->tokenStorage->getToken()?->getUser(); if (!$user instanceof BackendUser) { return []; From 9f8f36d2b551f32e5fe4326a53e22fecac6c1411 Mon Sep 17 00:00:00 2001 From: Mathias Arzberger Date: Mon, 13 Jan 2025 16:58:11 +0100 Subject: [PATCH 6/9] use attribute --- config/{commands.yml => commands.yaml} | 0 config/controller.yaml | 18 ++++++++++++++++++ config/routes.yaml | 6 ++++-- config/{services.yml => services.yaml} | 0 src/ContaoManager/Plugin.php | 2 +- src/Controller/FacebookController.php | 12 +++++++----- src/Controller/InstagramController.php | 8 +++----- src/Controller/LinkedinController.php | 11 +++++------ .../PdirSocialFeedExtension.php | 5 +++-- 9 files changed, 41 insertions(+), 21 deletions(-) rename config/{commands.yml => commands.yaml} (100%) create mode 100644 config/controller.yaml rename config/{services.yml => services.yaml} (100%) diff --git a/config/commands.yml b/config/commands.yaml similarity index 100% rename from config/commands.yml rename to config/commands.yaml diff --git a/config/controller.yaml b/config/controller.yaml new file mode 100644 index 0000000..ebbd8d1 --- /dev/null +++ b/config/controller.yaml @@ -0,0 +1,18 @@ +services: + _defaults: + autoconfigure: true + + Pdir\SocialFeedBundle\Controller\FacebookController: + public: true + arguments: + - '@database_connection' + - '@router' + + Pdir\SocialFeedBundle\Controller\InstagramController: + public: true + + Pdir\SocialFeedBundle\Controller\LinkedinController: + public: true + arguments: + - '@database_connection' + - '@router' diff --git a/config/routes.yaml b/config/routes.yaml index 23b4204..4ee8bf2 100644 --- a/config/routes.yaml +++ b/config/routes.yaml @@ -1,3 +1,5 @@ -pdir_social_feed.controller: - resource: ../src/Controller +pdir_social_feed.controllers: + resource: + path: ../src/Controller/ + namespace: Pdir\SocialFeedBundle\Controller type: attribute diff --git a/config/services.yml b/config/services.yaml similarity index 100% rename from config/services.yml rename to config/services.yaml diff --git a/src/ContaoManager/Plugin.php b/src/ContaoManager/Plugin.php index 561bddb..699d804 100644 --- a/src/ContaoManager/Plugin.php +++ b/src/ContaoManager/Plugin.php @@ -56,6 +56,6 @@ public function getRouteCollection(LoaderResolverInterface $resolver, KernelInte return $resolver ->resolve(__DIR__.'/../../config/routes.yaml') ->load(__DIR__.'/../../config/routes.yaml') - ; + ; } } diff --git a/src/Controller/FacebookController.php b/src/Controller/FacebookController.php index 1afd749..7bbc3e3 100644 --- a/src/Controller/FacebookController.php +++ b/src/Controller/FacebookController.php @@ -29,10 +29,10 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Session\SessionInterface; -use Symfony\Component\Routing\Attributes\Route; +use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\RouterInterface; -#[Route('/_facebook', name: ExampleController::class, defaults: ['_scope' => 'backend', '_token_check' => false])] +#[Route('_facebook', defaults: ['_scope' => 'backend', '_token_check' => false])] class FacebookController { private Connection $db; @@ -51,13 +51,15 @@ public function __construct(Connection $db, RouterInterface $router) $this->session = System::getContainer()->get('request_stack')->getCurrentRequest()->getSession(); } - /** - * @Route("/auth", name="facebook_auth", methods={"GET"}) - */ + #[Route('/auth', name: 'facebook_auth', methods: ['GET'])] public function authAction(Request $request): Response { $sessionData = $this->session->get(SocialFeedListener::SESSION_KEY); + if (empty($sessionData['backUrl'])) { + return new Response(Response::$statusTexts[Response::HTTP_BAD_REQUEST], Response::HTTP_BAD_REQUEST); + } + $data = [ 'client_id' => $sessionData['clientId'], 'client_secret' => $sessionData['clientSecret'], diff --git a/src/Controller/InstagramController.php b/src/Controller/InstagramController.php index 79df2df..c97e0c6 100644 --- a/src/Controller/InstagramController.php +++ b/src/Controller/InstagramController.php @@ -29,11 +29,11 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Session\SessionInterface; -use Symfony\Component\Routing\Attribute\Route; +use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; -#[Route('/_instagram', name: ExampleController::class, defaults: ['_scope' => 'backend', '_token_check' => false])] +#[Route('_instagram', defaults: ['_scope' => 'backend', '_token_check' => false])] class InstagramController { /** @@ -73,9 +73,7 @@ public function __construct(InstagramClient $client, Connection $db, RouterInter $this->tokenStorage = $tokenStorage; } - /** - * @Route("/auth", name="instagram_auth", methods={"GET"}) - */ + #[Route('/auth', name: 'instagram_auth', methods: ['GET'])] public function authAction(Request $request): Response { // Missing code query parameter diff --git a/src/Controller/LinkedinController.php b/src/Controller/LinkedinController.php index 98fe5b3..7f25493 100644 --- a/src/Controller/LinkedinController.php +++ b/src/Controller/LinkedinController.php @@ -20,6 +20,7 @@ namespace Pdir\SocialFeedBundle\Controller; +use Contao\CoreBundle\Monolog\ContaoContext; use Contao\System; use Doctrine\DBAL\Connection; use Pdir\SocialFeedBundle\EventListener\DataContainer\SocialFeedListener; @@ -27,10 +28,10 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Session\SessionInterface; -use Symfony\Component\Routing\Attribute\Route; +use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\RouterInterface; -#[Route('/auth', name: ExampleController::class, defaults: ['_scope' => 'backend', '_token_check' => false])] +#[Route('auth', defaults: ['_scope' => 'backend', '_token_check' => false])] class LinkedinController { private Connection $db; @@ -49,9 +50,7 @@ public function __construct(Connection $db, RouterInterface $router) $this->session = System::getContainer()->get('request_stack')->getCurrentRequest()->getSession(); } - /** - * @Route("/linkedin", name="auth_linkedin", methods={"GET"}) - */ + #[Route('/linkedin', name: 'auth_linkedin', methods: ['GET'])] public function authAction(Request $request): Response { $sessionData = $this->session->get(SocialFeedListener::SESSION_KEY); @@ -76,7 +75,7 @@ public function authAction(Request $request): Response $this->db->update('tl_social_feed', ['linkedin_access_token' => $token->access_token, 'access_token_expires' => time() + $token->expires_in, 'linkedin_refresh_token' => $token->refresh_token, 'linkedin_refresh_token_expires' => time() + $token->refresh_token_expires_in], ['id' => $sessionData['socialFeedId']]); $this->session->remove(SocialFeedListener::SESSION_KEY); } catch (\Exception $e) { - System::log($e->getMessage(), __METHOD__, TL_GENERAL); + System::log($e->getMessage(), __METHOD__, ContaoContext::GENERAL); } return new RedirectResponse($sessionData['backUrl']); diff --git a/src/DependencyInjection/PdirSocialFeedExtension.php b/src/DependencyInjection/PdirSocialFeedExtension.php index e121c85..0615449 100644 --- a/src/DependencyInjection/PdirSocialFeedExtension.php +++ b/src/DependencyInjection/PdirSocialFeedExtension.php @@ -38,8 +38,9 @@ protected function loadInternal(array $mergedConfig, ContainerBuilder $container new FileLocator(__DIR__.'/../../config') ); - $loader->load('commands.yml'); - $loader->load('services.yml'); + $loader->load('commands.yaml'); + $loader->load('controller.yaml'); + $loader->load('services.yaml'); $container->getDefinition(InstagramRequestCache::class)->setArgument(1, (int) $mergedConfig['cache_ttl']); } From 369ec665f609cd1468e9c942ff21b9fa2f0b6875 Mon Sep 17 00:00:00 2001 From: Mathias Arzberger Date: Mon, 13 Jan 2025 17:35:20 +0100 Subject: [PATCH 7/9] fix instagram moderation in Contao 5.4 --- contao/config/config.php | 4 ++-- contao/templates/be/be_sf_moderate.html5 | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/contao/config/config.php b/contao/config/config.php index e3d09e9..3e307f3 100644 --- a/contao/config/config.php +++ b/contao/config/config.php @@ -62,6 +62,6 @@ $scopeMatcher = System::getContainer()->get('contao.routing.scope_matcher'); if ($request && $scopeMatcher->isBackendRequest($request)) { - $GLOBALS['TL_CSS'][] = $assetsDir.'/css/sf_moderation.scss|static'; - $GLOBALS['TL_CSS'][] = $assetsDir.'/css/backend.css|static'; + $GLOBALS['TL_CSS'][] = $assetsDir.'/css/sf_moderation.min.css|static'; + $GLOBALS['TL_CSS'][] = $assetsDir.'/css/backend.min.css|static'; } diff --git a/contao/templates/be/be_sf_moderate.html5 b/contao/templates/be/be_sf_moderate.html5 index 56fad1d..e102897 100644 --- a/contao/templates/be/be_sf_moderate.html5 +++ b/contao/templates/be/be_sf_moderate.html5 @@ -1,5 +1,5 @@
-
+
From a77ae08b4a1d617f41e50b6932e2317baa02f110 Mon Sep 17 00:00:00 2001 From: Mathias Arzberger Date: Wed, 15 Jan 2025 17:16:17 +0100 Subject: [PATCH 8/9] fix instagram moderation in Contao 5.4 --- CHANGELOG.md | 2 +- composer.json | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e182e1e..b300bd1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,7 @@ Types of changes ## [2.14.0](https://github.com/pdir/social-feed-bundle/tree/2.14.0) - 2025-01-08 - [Added] Add compatibility for Contao 5.4+ -- [Fixed] Instagram import (You need a Business ?) +- [Fixed] Instagram import (You need a business app, see [docs](https://pdir.de/docs/de/contao/extensions/socialfeed/configuration/instagram/)) ## [2.13.6](https://github.com/pdir/social-feed-bundle/tree/2.13.6) - 2024-11-21 diff --git a/composer.json b/composer.json index c4d136b..9e40770 100644 --- a/composer.json +++ b/composer.json @@ -43,11 +43,11 @@ "donate": "https://contao-themes.net/sponsoring.html" }, "require": { - "php": "^8.0", + "php": "^8.1", "ext-json": "*", - "contao/core-bundle": "^4.13 || ^5.3", - "contao/news-bundle": "^4.13 || ^5.3", - "nickdnk/graph-sdk": "^6.0 || ^7.0", + "contao/core-bundle": "^5.3", + "contao/news-bundle": "^5.3", + "nickdnk/graph-sdk": "^7.0", "abraham/twitteroauth": "~4.0", "guzzlehttp/guzzle": "6.0 | ~7.7", "kevinrob/guzzle-cache-middleware": "^5.1", From 2cce83e3f17ba148914bef027dcb3e5599cf9b9a Mon Sep 17 00:00:00 2001 From: Mathias Arzberger Date: Wed, 15 Jan 2025 17:19:12 +0100 Subject: [PATCH 9/9] update changelog --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b300bd1..05168d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,11 +13,15 @@ Types of changes > [!Tip] > Thank you to all [EAP](https://pdir.de/crowdfunding/social-feed-bundle.html) supporters! -## [2.14.0](https://github.com/pdir/social-feed-bundle/tree/2.14.0) - 2025-01-08 +## [2.14.0](https://github.com/pdir/social-feed-bundle/tree/2.14.0) - 2025-01-15 - [Added] Add compatibility for Contao 5.4+ - [Fixed] Instagram import (You need a business app, see [docs](https://pdir.de/docs/de/contao/extensions/socialfeed/configuration/instagram/)) +## [2.13.7](https://github.com/pdir/social-feed-bundle/tree/2.13.6) - 2025-01-15 + +- [Fixed] Instagram import (You need a business app, see [docs](https://pdir.de/docs/de/contao/extensions/socialfeed/configuration/instagram/)) + ## [2.13.6](https://github.com/pdir/social-feed-bundle/tree/2.13.6) - 2024-11-21 -[Fixed] Update kevinrob/guzzle-cache-middleware fix #150 🤗 [contaoacademy](https://github.com/contaoacademy)