Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ig business #159

Merged
merged 9 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
File renamed without changes.
18 changes: 18 additions & 0 deletions config/controller.yaml
Original file line number Diff line number Diff line change
@@ -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'
8 changes: 5 additions & 3 deletions config/routes.yaml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 0 additions & 4 deletions config/services.yml → config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions contao/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
2 changes: 1 addition & 1 deletion contao/templates/be/be_sf_moderate.html5
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="mod_sf_moderate">
<form action="<?= Contao\StringUtil::ampersand($this->action) ?>" id="tl_news_moderate" class="tl_form" method="post">
<form id="tl_news_moderate" class="tl_form" method="post" data-turbo="false">

<div class="tl_formbody_edit">

Expand Down
2 changes: 1 addition & 1 deletion src/ContaoManager/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ public function getRouteCollection(LoaderResolverInterface $resolver, KernelInte
return $resolver
->resolve(__DIR__.'/../../config/routes.yaml')
->load(__DIR__.'/../../config/routes.yaml')
;
;
}
}
12 changes: 6 additions & 6 deletions src/Controller/FacebookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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'],
Expand Down
8 changes: 2 additions & 6 deletions src/Controller/InstagramController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/**
Expand Down Expand Up @@ -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
Expand Down
11 changes: 4 additions & 7 deletions src/Controller/LinkedinController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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']);
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Configuration implements ConfigurationInterface
/**
* @inheritDoc
*/
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('pdir_socialfeed');

Expand Down
5 changes: 3 additions & 2 deletions src/DependencyInjection/PdirSocialFeedExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
Expand Down
23 changes: 8 additions & 15 deletions src/EventListener/DataContainer/SocialFeedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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 [];
Expand Down Expand Up @@ -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));
Expand Down
Loading