diff --git a/Classes/OptimizeImageService.php b/Classes/OptimizeImageService.php index 0f047c6..0bf3241 100644 --- a/Classes/OptimizeImageService.php +++ b/Classes/OptimizeImageService.php @@ -46,13 +46,12 @@ public function __construct() * @param bool $fileIsUploaded * @param bool $testMode * @param Folder|null $targetFolder - * @return bool + * @return void|bool * @throws BinaryNotFoundException */ public function process($file, $extension = null, $fileIsUploaded = false, $testMode = false, Folder $targetFolder = null) { $this->reset(); - $excludePaths = []; if ($extension === null) { $pathinfo = pathinfo($file); @@ -70,16 +69,8 @@ public function process($file, $extension = null, $fileIsUploaded = false, $test return; } - if ($targetFolder !== null) { - if ($this->configuration[$extension . 'ExcludePaths'] !== '') { - $excludePaths = GeneralUtility::trimExplode(',', $this->configuration[$extension . 'ExcludePaths']); - } - - foreach ($excludePaths as $excludePath) { - if (strpos($targetFolder->getCombinedIdentifier(), $excludePath) !== false) { - return; - } - } + if ($targetFolder !== null && $this->isTargetFolderExcluded($extension, $targetFolder)) { + return; } $binary = CommandUtility::getCommand(escapeshellcmd($this->configuration[$extension . 'Binary'])); @@ -135,7 +126,7 @@ protected function reset() /** * @return string */ - public function getCommand() + public function getCommand(): string { return $this->command; } @@ -143,9 +134,59 @@ public function getCommand() /** * @return array */ - public function getOutput() + public function getOutput(): array { return $this->output; } + /** + * @param $haystack + * @param $needle + * @return bool + */ + private function startsWith(string $haystack, string $needle): bool + { + return strpos($haystack, $needle) === 0; + } + + /** + * @param $haystack + * @param $needle + * @return bool + */ + private function endsWith(string $haystack, string $needle): bool + { + $length = strlen($needle); + if ($length === 0) { + return true; + } + + return substr($haystack, -$length) === $needle; + } + + /** + * @param string $extension + * @param Folder $targetFolder + * @return bool + */ + private function isTargetFolderExcluded(string $extension, Folder $targetFolder): bool + { + $excludePaths = []; + if ($this->configuration[$extension . 'ExcludePaths'] !== '') { + $excludePaths = GeneralUtility::trimExplode(',', $this->configuration[$extension . 'ExcludePaths']); + } + + foreach ($excludePaths as $excludePath) { + if (!$this->startsWith($excludePath, '/')) { + $excludePath = '/' . $excludePath; + } + if (!$this->endsWith($excludePath, '/')) { + $excludePath .= '/'; + } + if (strpos($targetFolder->getCombinedIdentifier(), $excludePath) !== false) { + return true; + } + } + return false; + } } diff --git a/composer.json b/composer.json index 81fdf9e..d937a2f 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "christophlehmann/imageoptimizer", + "name": "theobscenezen/imageoptimizer", "type": "typo3-cms-extension", "description": "Optimize uploaded/processed images with binaries of your choice", "keywords": [ @@ -11,7 +11,8 @@ "progressive" ], "require": { - "typo3/cms-core": ">=7.6.0,<=8.7.99" + "typo3/cms-core": ">=7.6.0,<=8.7.99", + "php": "^7.0" }, "autoload": { "psr-4": { diff --git a/ext_emconf.php b/ext_emconf.php index 7435e92..6a61442 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -12,7 +12,7 @@ 'author_email' => 'post@christophlehmann.eu', 'state' => 'stable', 'clearCacheOnLoad' => 1, - 'version' => '1.1.3', + 'version' => '1.1.4', 'constraints' => [ 'depends' => [ 'typo3' => '7.6.0-8.7.99',