Skip to content

Commit

Permalink
[TASK] raise version, add safety to folder naming
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix König committed Jul 31, 2019
1 parent 3444417 commit 01912b2
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 17 deletions.
69 changes: 55 additions & 14 deletions Classes/OptimizeImageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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']));
Expand Down Expand Up @@ -135,17 +126,67 @@ protected function reset()
/**
* @return string
*/
public function getCommand()
public function getCommand(): string
{
return $this->command;
}

/**
* @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;
}
}
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand All @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 01912b2

Please sign in to comment.