From 4a1ae9a7a210495d5e568d48f6dd0e8e98c25e89 Mon Sep 17 00:00:00 2001 From: Philipp Dieter Date: Sun, 14 Nov 2021 19:02:51 +0100 Subject: [PATCH 1/8] [FEATURE] Add attachment option to mailutility --- Classes/Utility/MailUtility.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Classes/Utility/MailUtility.php b/Classes/Utility/MailUtility.php index 6f16ebe..db456d2 100644 --- a/Classes/Utility/MailUtility.php +++ b/Classes/Utility/MailUtility.php @@ -280,6 +280,13 @@ class MailUtility $bodydataText[] = $textRow; $bodydataHtml[] = $htmlRow; break; + case 'attachment': + $mail->attach(new \Swift_Attachment( + $row['data'][0], + $row['data'][1], + $row['data'][2] + )); + break; case 'attachmentBase64': $attachmentdata = explode(',', $row['data']); preg_match('/\w*:(.*);\w*/', $attachmentdata[0], $matches); From 04041fa56488412ce45e3546e0656ea7f497e9a0 Mon Sep 17 00:00:00 2001 From: Philipp Dieter Date: Sun, 14 Nov 2021 19:03:55 +0100 Subject: [PATCH 2/8] [FEATURE] Add option to search full typoscript to site config utility --- Classes/Utility/SiteConfigUtility.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Classes/Utility/SiteConfigUtility.php b/Classes/Utility/SiteConfigUtility.php index d14b8be..1a1041a 100644 --- a/Classes/Utility/SiteConfigUtility.php +++ b/Classes/Utility/SiteConfigUtility.php @@ -27,8 +27,10 @@ class SiteConfigUtility * @var string $path * @return string */ - public static function getByPath($path) - { + public static function getByPath( + $path, + $limitToSiteConfig = true + ) { $pathParts = explode('.', $path); $objectManager = GeneralUtility::makeInstance( ObjectManager::class @@ -40,7 +42,10 @@ class SiteConfigUtility ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT ); $typoscript = GeneralUtility::removeDotsFromTS($typoscript); - $siteConfig = $typoscript['config']['site']; + $siteConfig = $typoscript; + if ($limitToSiteConfig) { + $siteConfig = $typoscript['config']['site']; + } $current = &$siteConfig; foreach ($pathParts as $key) { $current = &$current[$key]; From 55b9ae220c466ce56b0e20b775d71b41edbb00da Mon Sep 17 00:00:00 2001 From: Philipp Dieter Date: Sun, 14 Nov 2021 19:05:33 +0100 Subject: [PATCH 3/8] [TASK] Don't hide new pages in dev environment --- Resources/Private/PageTSConfig/default.tsconfig | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Resources/Private/PageTSConfig/default.tsconfig b/Resources/Private/PageTSConfig/default.tsconfig index ffb5fbd..31b6307 100644 --- a/Resources/Private/PageTSConfig/default.tsconfig +++ b/Resources/Private/PageTSConfig/default.tsconfig @@ -1 +1,5 @@ + +[applicationContext = Development] +TCAdefaults.pages.hidden = 0 +[end] From 76c9a738f71507647a1b535f5c5150d57bdc8a07 Mon Sep 17 00:00:00 2001 From: Philipp Dieter Date: Sun, 14 Nov 2021 20:55:09 +0100 Subject: [PATCH 4/8] [BUGFIX] Create correct extension key to get configuration --- Classes/Traits/DependencyInjectionTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/Traits/DependencyInjectionTrait.php b/Classes/Traits/DependencyInjectionTrait.php index 27dbbc8..d2ccc13 100644 --- a/Classes/Traits/DependencyInjectionTrait.php +++ b/Classes/Traits/DependencyInjectionTrait.php @@ -88,7 +88,7 @@ trait DependencyInjectionTrait ); $frameworkConfiguration = $this->configurationManager->getConfiguration( ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK, - $this->getExtensionKey() + str_replace('_', '', $this->getExtensionKey()) ); $this->configurationManager->setConfiguration( $frameworkConfiguration From 4c42637fab0ed8ffa0ba195e6b204e11929dbf2f Mon Sep 17 00:00:00 2001 From: Philipp Dieter Date: Mon, 15 Nov 2021 22:40:16 +0100 Subject: [PATCH 5/8] [TASK] Increase TYPO3 version dependency --- composer.json | 2 +- ext_emconf.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 3b3fc76..477f039 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ } ], "require": { - "typo3/cms-core": "8.7.0 - 9.5.99" + "typo3/cms-core": "8.7.0 - 10.99.99" }, "autoload": { "psr-4": { diff --git a/ext_emconf.php b/ext_emconf.php index 1340658..f3e4cb9 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -23,7 +23,7 @@ $EM_CONF[$_EXTKEY] = [ 'version' => '0.0.1', 'constraints' => [ 'depends' => [ - 'typo3' => '8.7.0-9.5.99', + 'typo3' => '8.7.0-10.99.99', ], 'conflicts' => [], 'suggests' => [], From 9858f663f62d3498e239df88fcd77d9d7a237c37 Mon Sep 17 00:00:00 2001 From: Philipp Dieter Date: Sun, 21 Nov 2021 23:09:16 +0100 Subject: [PATCH 6/8] [FEATURE] Backport function to convert form data input by schema --- Classes/Traits/ValidationTrait.php | 58 ++++++++++++++++++++++++++++++ composer.json | 3 +- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/Classes/Traits/ValidationTrait.php b/Classes/Traits/ValidationTrait.php index 6b4a75a..3803181 100644 --- a/Classes/Traits/ValidationTrait.php +++ b/Classes/Traits/ValidationTrait.php @@ -16,6 +16,7 @@ use \Opis\JsonSchema\{ Validator, ValidationResult, ValidationError, Schema }; use Cjel\TemplatesAide\Utility\ArrayUtility; +use Sarhan\Flatten\Flatten; use TYPO3\CMS\Extbase\Utility\LocalizationUtility; /** @@ -39,6 +40,63 @@ trait ValidationTrait */ protected $errorLabels = []; + /** + * validate objects + * + * @param $input + * @param schema + * @return void + */ + protected function convertInputBySchema($input, $schema) + { + $flatten = new Flatten(); + $schemaFlat = $flatten->flattenToArray($schema); + $typesList = []; + foreach ($schemaFlat as $index => $row) { + if (substr($index, -5) == '.type') { + $dataIndex = preg_replace( + '/(\.)(properties\.|items\.)/', + '$1', + $index + ); + $dataIndex = preg_replace( + '/^properties\./', + '', + $dataIndex + ); + $dataIndex = preg_replace( + '/\.type$/', + '', + $dataIndex + ); + $typesList[$dataIndex] = $row; + } + } + foreach ($input as $index => $row) { + $rowType = $typesList[$index]; + if (!$rowType) { + continue; + } + switch ($rowType) { + case 'integer': + if (is_numeric($row)) { + settype($input[$index], $rowType); + } + break; + case 'boolean': + $testResult = filter_var( + $row, + FILTER_VALIDATE_BOOLEAN, + [FILTER_NULL_ON_FAILURE] + ); + if ($testResult === true || $testResult === false) { + $input[$index] = $testResult; + } + } + } + return $input; + } + /** * validate objects * diff --git a/composer.json b/composer.json index 3b3fc76..d02a60f 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,8 @@ } ], "require": { - "typo3/cms-core": "8.7.0 - 9.5.99" + "typo3/cms-core": "8.7.0 - 9.5.99", + "sarhan/php-flatten": "^4.0" }, "autoload": { "psr-4": { From 8dbc5791d22e0e06095b98cde49a8cdcdb8e5ef3 Mon Sep 17 00:00:00 2001 From: Philipp Dieter Date: Sun, 21 Nov 2021 23:59:12 +0100 Subject: [PATCH 7/8] [FEATURE] Add date parsing for schema based input conversion --- Classes/Traits/ValidationTrait.php | 45 ++++++++++++++++++++---------- composer.json.orig | 33 ++++++++++++++++++++++ 2 files changed, 63 insertions(+), 15 deletions(-) create mode 100644 composer.json.orig diff --git a/Classes/Traits/ValidationTrait.php b/Classes/Traits/ValidationTrait.php index 3803181..b53f47b 100644 --- a/Classes/Traits/ValidationTrait.php +++ b/Classes/Traits/ValidationTrait.php @@ -52,28 +52,33 @@ trait ValidationTrait $flatten = new Flatten(); $schemaFlat = $flatten->flattenToArray($schema); $typesList = []; + $formatsList = []; foreach ($schemaFlat as $index => $row) { + $dataIndex = preg_replace( + '/(\.)(properties\.|items\.)/', + '$1', + $index + ); + $dataIndex = preg_replace( + '/^properties\./', + '', + $dataIndex + ); + $dataIndex = preg_replace( + '/\.(type|format)$/', + '', + $dataIndex + ); if (substr($index, -5) == '.type') { - $dataIndex = preg_replace( - '/(\.)(properties\.|items\.)/', - '$1', - $index - ); - $dataIndex = preg_replace( - '/^properties\./', - '', - $dataIndex - ); - $dataIndex = preg_replace( - '/\.type$/', - '', - $dataIndex - ); $typesList[$dataIndex] = $row; } + if (substr($index, -7) == '.format') { + $formatsList[$dataIndex] = $row; + } } foreach ($input as $index => $row) { $rowType = $typesList[$index]; + $formatType = $formatsList[$index]; if (!$rowType) { continue; } @@ -92,6 +97,16 @@ trait ValidationTrait if ($testResult === true || $testResult === false) { $input[$index] = $testResult; } + case 'string': + switch ($formatType) { + case 'date': + $row = \DateTime::createFromFormat( + 'Y-m-d H:i:s', + $row . ' 00:00:00', + ); + break; + } + break; } } return $input; diff --git a/composer.json.orig b/composer.json.orig new file mode 100644 index 0000000..abf0a9e --- /dev/null +++ b/composer.json.orig @@ -0,0 +1,33 @@ +{ + "name": "cjel/templates-aide", + "type": "typo3-cms-extension", + "description": "", + "authors": [ + { + "name": "Philipp Dieter", + "role": "Developer" + } + ], + "require": { +<<<<<<< HEAD + "typo3/cms-core": "8.7.0 - 9.5.99", + "sarhan/php-flatten": "^4.0" +======= + "typo3/cms-core": "8.7.0 - 10.99.99" +>>>>>>> 4a4b809d13bd33b85d84f03eba5edb603d74abfb + }, + "autoload": { + "psr-4": { + "Cjel\\TemplatesAide\\": "Classes" + } + }, + "autoload-dev": { + "psr-4": { + "Cjel\\TemplatesAide\\Tests\\": "Tests" + } + }, + "replace": { + "templates_aide": "self.version", + "typo3-ter/templates-aide": "self.version" + } +} From 700e592f0566bdc7795d426834177e4d3df07482 Mon Sep 17 00:00:00 2001 From: Philipp Dieter Date: Mon, 22 Nov 2021 15:20:35 +0100 Subject: [PATCH 8/8] [TASK] Differentiate between associative and nonaccociative arrays when mapping to object --- Classes/Traits/ValidationTrait.php | 3 --- Classes/Utility/ArrayUtility.php | 17 ++++++++++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Classes/Traits/ValidationTrait.php b/Classes/Traits/ValidationTrait.php index b53f47b..945fd9c 100644 --- a/Classes/Traits/ValidationTrait.php +++ b/Classes/Traits/ValidationTrait.php @@ -141,9 +141,6 @@ trait ValidationTrait if (!$validationResult->isValid()) { $this->isValid = false; $this->responseStatus = [400 => 'validationError']; - //\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump( - // $validationResult->getErrors(), false, 9, true - //); foreach ($validationResult->getErrors() as $error){ $field = implode('.', $error->dataPointer()); if ($error->keyword() == 'required') { diff --git a/Classes/Utility/ArrayUtility.php b/Classes/Utility/ArrayUtility.php index 7f2a7a0..f43c961 100644 --- a/Classes/Utility/ArrayUtility.php +++ b/Classes/Utility/ArrayUtility.php @@ -22,7 +22,11 @@ class ArrayUtility */ public static function toObject($array) { if (is_array($array)) { - return (object) array_map([__CLASS__, __METHOD__], $array); + if (self::isAssoc($array)) { + return (object) array_map([__CLASS__, __METHOD__], $array); + } else { + return array_map([__CLASS__, __METHOD__], $array); + } } else { return $array; } @@ -46,4 +50,15 @@ class ArrayUtility return $array; } + + /** + * + */ + public static function isAssoc(array $arr) { + if (array() === $arr) { + return false; + } + return array_keys($arr) !== range(0, count($arr) - 1); + } + }