Skip to content

Commit

Permalink
#28
Browse files Browse the repository at this point in the history
  • Loading branch information
christianbarkowsky committed Aug 2, 2022
1 parent d21ae01 commit dac788c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
<source>You made %s compressions this month (tinify.com).</source>
<target>Du hast %s Bildkompressionen in diesem Monat durchgeführt (tinify.com).</target>
</trans-unit>
<trans-unit id="MSC.TINYCOMPRESSIMAGES.apikey">
<source>Put the Tinify API key to your Contao settings. (Get your API key: https://tinify.com/developers)</source>
<target>Füge den Tinify-API-Schlüssel zu deinen Contao-Einstellungen hinzu. (Get your API key: https://tinify.com/developers)</target>
</trans-unit>
</body>
</file>
</xliff>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
<trans-unit id="MSC.TINYCOMPRESSIMAGES.count">
<source>You made %s compressions this month (tinify.com).</source>
</trans-unit>
<trans-unit id="MSC.TINYCOMPRESSIMAGES.apikey">
<source>Put the Tinify API key to your Contao settings. (Get your API key: https://tinify.com/developers)</source>
</trans-unit>
</body>
</file>
</xliff>
Expand Down
21 changes: 19 additions & 2 deletions src/Plenta/ContaoTinyCompressImages/TinyPNG/Compressor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/plenta>
* @author David Greminger <https://github.com/bytehead>
* @package tiny-compress-images
* @license LGPL
Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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)]
);
}
}

0 comments on commit dac788c

Please sign in to comment.