diff --git a/CHANGELOG.md b/CHANGELOG.md index e8fb31e..05168d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +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-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) 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", 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 58da485..4ee8bf2 100644 --- a/config/routes.yaml +++ b/config/routes.yaml @@ -1,3 +1,5 @@ -pdir_social_feed.controller: - resource: ../src/Controller - type: annotation +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 96% rename from config/services.yml rename to config/services.yaml index 85fd45f..2da324f 100644 --- a/config/services.yml +++ b/config/services.yaml @@ -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/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 @@
-
+
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 154fa77..7bbc3e3 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', defaults: ['_scope' => 'backend', '_token_check' => false])] class FacebookController { private Connection $db; @@ -53,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 3f3eb72..c97e0c6 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', defaults: ['_scope' => 'backend', '_token_check' => false])] class InstagramController { /** @@ -75,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 4725465..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; @@ -30,9 +31,7 @@ use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\RouterInterface; -/** - * @Route("/auth", defaults={"_scope" = "backend", "_token_check" = false}) - */ +#[Route('auth', defaults: ['_scope' => 'backend', '_token_check' => false])] class LinkedinController { private Connection $db; @@ -51,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); @@ -78,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/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'); 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']); } diff --git a/src/EventListener/DataContainer/SocialFeedListener.php b/src/EventListener/DataContainer/SocialFeedListener.php index d8709c9..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 []; @@ -145,7 +138,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));