Skip to content

Commit

Permalink
run ecs check and fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MDevster committed Nov 19, 2021
1 parent 4d31540 commit 0b6a939
Show file tree
Hide file tree
Showing 43 changed files with 1,613 additions and 924 deletions.
14 changes: 12 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
.git/
.idea/
# Composer
/composer.lock
/vendor/

# cypress & node
cypress.json
/node_modules/

# PhpUnit
/.idea
/.phpunit.result.cache
/phpunit.xml
29 changes: 29 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
cache:
paths:
- vendor/

before_script:
# - cp ci/php.ini /usr/local/etc/php/conf.d/test.ini
- COMPOSER_MEMORY_LIMIT=-1 composer install -n --prefer-dist --no-progress --ignore-platform-reqs

php:7.4:
# This docker image comes with composer and ant.
image: jorge07/alpine-php:7.4-dev
script:
- vendor/bin/phpunit --configuration phpunit.xml --coverage-text --log-junit report.xml
- vendor/bin/ecs check src tests
artifacts:
when: always
reports:
junit: report.xml

php:8.0:
# This docker image comes with composer and ant.
image: jorge07/alpine-php:8.0-dev
script:
- vendor/bin/phpunit --configuration phpunit.xml --coverage-text --log-junit report.xml
- vendor/bin/ecs check src tests
artifacts:
when: always
reports:
junit: report.xml
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

## [2.10.0](https://github.com/pdir/social-feed-bundle/tree/2.10.0) – 2021-xx-xx
## [2.10.0](https://github.com/pdir/social-feed-bundle/tree/2.10.0) – 2021-11-19

- [feature] linkedin import

Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@
"zoonman/linkedin-api-php-client": "dev-master"
},
"require-dev": {
"contao/manager-plugin": "^2.0"
"contao/manager-plugin": "^2.0",
"contao/easy-coding-standard": "^3.0",
"phpunit/phpunit": "^8.4 || ^9.5",
"symfony/phpunit-bridge": "^4.4 || ^5.1"
},
"conflict": {
"contao/manager-plugin": "<2.0 || >=3.0"
Expand Down
40 changes: 40 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Fixer\Comment\HeaderCommentFixer;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\EasyCodingStandard\ValueObject\Option;

$date = date('Y');

$GLOBALS['ecsHeader'] = <<<EOF
social feed bundle for Contao Open Source CMS
Copyright (c) $date pdir / digital agentur // pdir GmbH
@package social-feed-bundle
@link https://github.com/pdir/social-feed-bundle
@license http://www.gnu.org/licences/lgpl-3.0.html LGPL
@author Mathias Arzberger <[email protected]>
@author Philipp Seibt <[email protected]>
@author pdir GmbH <https://pdir.de>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
EOF;

return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->import(__DIR__.'/vendor/contao/easy-coding-standard/config/set/contao.php');

$parameters = $containerConfigurator->parameters();
$parameters->set(Option::LINE_ENDING, "\n");

$services = $containerConfigurator->services();
$services
->set(HeaderCommentFixer::class)
->call('configure', [[
'header' => $GLOBALS['ecsHeader'],
]])
;
};
43 changes: 26 additions & 17 deletions src/ContaoManager/Plugin.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
<?php

/**
* Contao Open Source CMS
declare(strict_types=1);

/*
* social feed bundle for Contao Open Source CMS
*
* Copyright (c) 2021 pdir / digital agentur // pdir GmbH
*
* Copyright (c) 2017 pdir / digital agentur
* @package social-feed-bundle
* @author Mathias Arzberger <[email protected]>
* @license http://www.gnu.org/licences/lgpl-3.0.html LGPL
* @package social-feed-bundle
* @link https://github.com/pdir/social-feed-bundle
* @license http://www.gnu.org/licences/lgpl-3.0.html LGPL
* @author Mathias Arzberger <[email protected]>
* @author Philipp Seibt <[email protected]>
* @author pdir GmbH <https://pdir.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Pdir\SocialFeedBundle\ContaoManager;
Expand All @@ -22,17 +31,17 @@

class Plugin implements BundlePluginInterface, RoutingPluginInterface
{
/**
* {@inheritdoc}
*/
public function getBundles(ParserInterface $parser)
{
return [
BundleConfig::create(PdirSocialFeedBundle::class)
->setLoadAfter([ContaoCoreBundle::class])
->setReplace(['socialfeedbundle']),
];
}
/**
* {@inheritdoc}
*/
public function getBundles(ParserInterface $parser)
{
return [
BundleConfig::create(PdirSocialFeedBundle::class)
->setLoadAfter([ContaoCoreBundle::class])
->setReplace(['socialfeedbundle']),
];
}

/**
* {@inheritdoc}
Expand Down
26 changes: 14 additions & 12 deletions src/Controller/FacebookController.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
<?php

declare(strict_types=1);

/*
* Instagram Bundle for Contao Open Source CMS.
*
* Copyright (C) 2011-2019 Codefog
* social feed bundle for Contao Open Source CMS
*
* @author Codefog <https://codefog.pl>
* @author Kamil Kuzminski <https://github.com/qzminski>
* @license MIT
* Copyright (c) 2021 pdir / digital agentur // pdir GmbH
*
* https://github.com/codefog/contao-instagram
* @package social-feed-bundle
* @link https://github.com/pdir/social-feed-bundle
* @license http://www.gnu.org/licences/lgpl-3.0.html LGPL
* @author Mathias Arzberger <[email protected]>
* @author Philipp Seibt <[email protected]>
* @author pdir GmbH <https://pdir.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Pdir\SocialFeedBundle\Controller;

use Pdir\SocialFeedBundle\EventListener\SocialFeedListener;
use Doctrine\DBAL\Connection;
use Pdir\SocialFeedBundle\EventListener\SocialFeedListener;
use Symfony\Component\HttpFoundation\RedirectResponse;
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\RouterInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Facebook\Facebook;
use Contao\CoreBundle\Exception\RedirectResponseException;

/**
* @Route("/_facebook", defaults={"_scope" = "backend", "_token_check" = false})
Expand Down Expand Up @@ -68,7 +70,7 @@ public function authAction(Request $request): Response
'client_id' => $sessionData['clientId'],
'client_secret' => $sessionData['clientSecret'],
'redirect_uri' => $this->router->generate('facebook_auth', [], RouterInterface::ABSOLUTE_URL),
'code' => $request->query->get('code')
'code' => $request->query->get('code'),
];

$json = file_get_contents('https://graph.facebook.com/v11.0/oauth/access_token?'.http_build_query($data));
Expand Down
27 changes: 16 additions & 11 deletions src/Controller/InstagramController.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
<?php

declare(strict_types=1);

/*
* Instagram Bundle for Contao Open Source CMS.
*
* Copyright (C) 2011-2019 Codefog
* social feed bundle for Contao Open Source CMS
*
* @author Codefog <https://codefog.pl>
* @author Kamil Kuzminski <https://github.com/qzminski>
* @license MIT
* Copyright (c) 2021 pdir / digital agentur // pdir GmbH
*
* https://github.com/codefog/contao-instagram
* @package social-feed-bundle
* @link https://github.com/pdir/social-feed-bundle
* @license http://www.gnu.org/licences/lgpl-3.0.html LGPL
* @author Mathias Arzberger <[email protected]>
* @author Philipp Seibt <[email protected]>
* @author pdir GmbH <https://pdir.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Pdir\SocialFeedBundle\Controller;

use Pdir\SocialFeedBundle\EventListener\SocialFeedListener;
use Pdir\SocialFeedBundle\Importer\InstagramClient;
use Contao\BackendUser;
use Doctrine\DBAL\Connection;
use Pdir\SocialFeedBundle\EventListener\SocialFeedListener;
use Pdir\SocialFeedBundle\Importer\InstagramClient;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand Down Expand Up @@ -80,7 +85,7 @@ public function authAction(Request $request): Response
}

// User not logged in
if (null === ($user = $this->getBackendUser())) {
if (null === $this->getBackendUser()) {
return new Response(Response::$statusTexts[Response::HTTP_UNAUTHORIZED], Response::HTTP_UNAUTHORIZED);
}

Expand Down Expand Up @@ -109,7 +114,7 @@ public function authAction(Request $request): Response

// Get the user and media data
$this->client->getUserData($accessToken, (int) $module['id'], false);
$mediaData = $this->client->getMediaData($accessToken, (int) $module['id'], false);
// $mediaData = $this->client->getMediaData($accessToken, (int) $module['id'], false);

// Store the access token and remove temporary session key
$this->db->update('tl_social_feed', ['psf_instagramAccessToken' => $accessToken], ['id' => $sessionData['socialFeedId']]);
Expand Down
65 changes: 43 additions & 22 deletions src/Controller/LinkedinController.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,40 @@
<?php

declare(strict_types=1);

/*
* social feed bundle for Contao Open Source CMS
*
* Copyright (C) 2011-2019 Codefog
*
* The code of this class is based on the Instagram Bundle from Codefog
* @author Codefog <https://codefog.pl>
* @author Kamil Kuzminski <https://github.com/qzminski>
* @license MIT
*
* Copyright (c) 2021 pdir / digital agentur // pdir GmbH
*
* @package social-feed-bundle
* @link https://github.com/pdir/social-feed-bundle
* @license http://www.gnu.org/licences/lgpl-3.0.html LGPL
* @author Mathias Arzberger <[email protected]>
* @author Philipp Seibt <[email protected]>
* @author pdir GmbH <https://pdir.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Pdir\SocialFeedBundle\Controller;

use Pdir\SocialFeedBundle\EventListener\SocialFeedListener;
use Doctrine\DBAL\Connection;
use Pdir\SocialFeedBundle\EventListener\SocialFeedListener;
use Symfony\Component\HttpFoundation\RedirectResponse;
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\RouterInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use LinkedIn\Client;

/**
* @Route("/auth", defaults={"_scope" = "backend", "_token_check" = false})
Expand Down Expand Up @@ -51,28 +74,26 @@ public function authAction(Request $request): Response
$sessionData = $this->session->get(SocialFeedListener::SESSION_KEY);

// Missing code query parameter
if (!($code = $request->query->get('code'))) {
if (!$request->query->get('code')) {
return new Response(Response::$statusTexts[Response::HTTP_BAD_REQUEST], Response::HTTP_BAD_REQUEST);
} else {
//get refresh token
$data = [
'grant_type' => 'authorization_code',
'code' => $request->query->get('code'),
'client_id' => $sessionData['clientId'],
'client_secret' => $sessionData['clientSecret'],
'redirect_uri' => $this->router->generate('auth_linkedin', [], RouterInterface::ABSOLUTE_URL)
];

try {
$token = json_decode(file_get_contents('https://www.linkedin.com/oauth/v2/accessToken?'.http_build_query($data)));
}
//get refresh token
$data = [
'grant_type' => 'authorization_code',
'code' => $request->query->get('code'),
'client_id' => $sessionData['clientId'],
'client_secret' => $sessionData['clientSecret'],
'redirect_uri' => $this->router->generate('auth_linkedin', [], RouterInterface::ABSOLUTE_URL),
];

// Store the access token and remove temporary session key
$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);
}
try {
$token = json_decode(file_get_contents('https://www.linkedin.com/oauth/v2/accessToken?'.http_build_query($data)));

// Store the access token and remove temporary session key
$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);
}

return new RedirectResponse($sessionData['backUrl']);
Expand Down
Loading

0 comments on commit 0b6a939

Please sign in to comment.