From dac788c659d4b97f88b72218ed8b4acac7854551 Mon Sep 17 00:00:00 2001 From: christianbarkowsky Date: Tue, 2 Aug 2022 14:31:47 +0200 Subject: [PATCH] #28 --- .../Resources/contao/languages/de/default.xlf | 4 ++++ .../Resources/contao/languages/en/default.xlf | 3 +++ .../TinyPNG/Compressor.php | 21 +++++++++++++++++-- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/Plenta/ContaoTinyCompressImages/Resources/contao/languages/de/default.xlf b/src/Plenta/ContaoTinyCompressImages/Resources/contao/languages/de/default.xlf index 276aa1b..24b610f 100644 --- a/src/Plenta/ContaoTinyCompressImages/Resources/contao/languages/de/default.xlf +++ b/src/Plenta/ContaoTinyCompressImages/Resources/contao/languages/de/default.xlf @@ -14,6 +14,10 @@ You made %s compressions this month (tinify.com). Du hast %s Bildkompressionen in diesem Monat durchgeführt (tinify.com). + + Put the Tinify API key to your Contao settings. (Get your API key: https://tinify.com/developers) + Füge den Tinify-API-Schlüssel zu deinen Contao-Einstellungen hinzu. (Get your API key: https://tinify.com/developers) + diff --git a/src/Plenta/ContaoTinyCompressImages/Resources/contao/languages/en/default.xlf b/src/Plenta/ContaoTinyCompressImages/Resources/contao/languages/en/default.xlf index 76293cf..5a957df 100644 --- a/src/Plenta/ContaoTinyCompressImages/Resources/contao/languages/en/default.xlf +++ b/src/Plenta/ContaoTinyCompressImages/Resources/contao/languages/en/default.xlf @@ -11,6 +11,9 @@ You made %s compressions this month (tinify.com). + + Put the Tinify API key to your Contao settings. (Get your API key: https://tinify.com/developers) + diff --git a/src/Plenta/ContaoTinyCompressImages/TinyPNG/Compressor.php b/src/Plenta/ContaoTinyCompressImages/TinyPNG/Compressor.php index 911d57d..ec7cc85 100644 --- a/src/Plenta/ContaoTinyCompressImages/TinyPNG/Compressor.php +++ b/src/Plenta/ContaoTinyCompressImages/TinyPNG/Compressor.php @@ -3,7 +3,8 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2015-2021, Plenta.io & Christian Barkowsky + * @copyright Copyright (c) 2015-2022, Plenta.io & Christian Barkowsky + * @author Christian Barkowsky * @author David Greminger * @package tiny-compress-images * @license LGPL @@ -53,10 +54,12 @@ public function __construct( /** @var Config $config */ $config = $framework->getAdapter(Config::class); - $this->apiKey = $config->get('tinypng_api_key'); + $this->apiKey = (string) $config->get('tinypng_api_key'); if ('' !== $this->apiKey) { $this->auth = 'Basic ' . base64_encode(sprintf('api:%s', $this->apiKey)); + } else { + $this->showApiKeyWarning(); } } @@ -169,4 +172,18 @@ private function showCompressionCount(int $compressionCount): void ['contao' => new ContaoContext(__METHOD__, ContaoContext::GENERAL)] ); } + + private function showApiKeyWarning(): void + { + $message = $this->framework->getAdapter(Message::class); + + $message->addError( + $this->translator->trans('MSC.TINYCOMPRESSIMAGES.apikey', [], 'contao_default') + ); + + $this->logger->info( + $this->translator->trans('MSC.TINYCOMPRESSIMAGES.apikey', [], 'contao_default'), + ['contao' => new ContaoContext(__METHOD__, ContaoContext::ERROR)] + ); + } }