From 0bad55dfef7727c28f504be88d97dbca54f0364c Mon Sep 17 00:00:00 2001 From: Philipp Dieter Date: Tue, 21 Jul 2020 23:53:58 +0200 Subject: [PATCH 01/18] [TASK] Update default template name handling --- Resources/Private/Language/de.locallang.xlf | 22 ++++++++++++++ Resources/Private/Language/locallang.xlf | 17 +++++++++-- .../Private/PageTSConfig/default.tsconfig | 1 + .../Private/PageTSConfig/lib/layout.tsconfig | 29 +++++++++++++++++++ Resources/Private/TypoScript/Setup/lib.ts | 13 +++++++-- Resources/Private/TypoScript/Setup/page.ts | 14 ++++++++- ext_localconf.php | 2 +- ext_tables.php | 6 ++++ 8 files changed, 96 insertions(+), 8 deletions(-) create mode 100644 Resources/Private/Language/de.locallang.xlf create mode 100644 Resources/Private/PageTSConfig/default.tsconfig create mode 100644 Resources/Private/PageTSConfig/lib/layout.tsconfig diff --git a/Resources/Private/Language/de.locallang.xlf b/Resources/Private/Language/de.locallang.xlf new file mode 100644 index 0000000..155c347 --- /dev/null +++ b/Resources/Private/Language/de.locallang.xlf @@ -0,0 +1,22 @@ + + + +
+ LFEditor +
+ + + + + + + + + + + + + + +
+
\ No newline at end of file diff --git a/Resources/Private/Language/locallang.xlf b/Resources/Private/Language/locallang.xlf index 68e365b..bb353e3 100644 --- a/Resources/Private/Language/locallang.xlf +++ b/Resources/Private/Language/locallang.xlf @@ -1,10 +1,21 @@ - -
+ +
+ LFEditor +
+ + + + + + + + + - Dummy +
diff --git a/Resources/Private/PageTSConfig/default.tsconfig b/Resources/Private/PageTSConfig/default.tsconfig new file mode 100644 index 0000000..ffb5fbd --- /dev/null +++ b/Resources/Private/PageTSConfig/default.tsconfig @@ -0,0 +1 @@ + diff --git a/Resources/Private/PageTSConfig/lib/layout.tsconfig b/Resources/Private/PageTSConfig/lib/layout.tsconfig new file mode 100644 index 0000000..7102f7a --- /dev/null +++ b/Resources/Private/PageTSConfig/lib/layout.tsconfig @@ -0,0 +1,29 @@ +mod { + web_layout { + BackendLayouts { + default { + title = LLL:EXT:templates_aide/Resources/Private/Language/locallang.xlf:default + config { + backend_layout { + colCount = 1 + rowCount = 1 + rows { + 1 { + columns { + 1 { + name = LLL:EXT:templates_aide/Resources/Private/Language/locallang.xlf:default + colPos = 0 + } + } + } + } + } + } + } + homepage < .default + homepage.title = LLL:EXT:templates_aide/Resources/Private/Language/locallang.xlf:homepage + subpage < .default + subpage.title = LLL:EXT:templates_aide/Resources/Private/Language/locallang.xlf:subpage + } + } +} diff --git a/Resources/Private/TypoScript/Setup/lib.ts b/Resources/Private/TypoScript/Setup/lib.ts index 37b61ac..b2c2cde 100644 --- a/Resources/Private/TypoScript/Setup/lib.ts +++ b/Resources/Private/TypoScript/Setup/lib.ts @@ -1,18 +1,25 @@ +# legacy + lib.rootpid = TEXT lib.rootpid.data = leveluid : 0 -lib.pidRoot = TEXT -lib.pidRoot.data = leveluid : 0 - lib.currentLevel = TEXT lib.currentLevel.data = level:1 lib.currentPid = TEXT lib.currentPid.data = TSFE:id +# legacy end + +lib.pidRoot = TEXT +lib.pidRoot.data = leveluid : 0 + lib.pidCurrent = TEXT lib.pidCurrent.data = TSFE:id +lib.level = TEXT +lib.level.data = level:1 + lib.gpvar = COA lib.gpvar { stdWrap.htmlSpecialChars = 1 diff --git a/Resources/Private/TypoScript/Setup/page.ts b/Resources/Private/TypoScript/Setup/page.ts index 8535635..618b6d1 100644 --- a/Resources/Private/TypoScript/Setup/page.ts +++ b/Resources/Private/TypoScript/Setup/page.ts @@ -2,7 +2,19 @@ page = PAGE page { 10 = FLUIDTEMPLATE 10 { - templateName = Base + templateName.stdWrap { + cObject = TEXT + cObject { + data = levelfield:-2,backend_layout_next_level,slide + override.field = backend_layout + split { + token = pagets__ + 1.current = 1 + 1.wrap = | + } + } + ifEmpty = Base + } layoutRootPaths { 0 = EXT:site_templates/Resources/Private/Layouts } diff --git a/ext_localconf.php b/ext_localconf.php index 252d822..fd18f63 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -56,4 +56,4 @@ $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'][1549297828] = [ $GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['namespaces']['c'] = []; $GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['namespaces']['c'][] - = 'Cjel\TemplatesAide\ViewHelpers'; \ No newline at end of file + = 'Cjel\TemplatesAide\ViewHelpers'; diff --git a/ext_tables.php b/ext_tables.php index 045a13f..2106264 100644 --- a/ext_tables.php +++ b/ext_tables.php @@ -37,6 +37,12 @@ call_user_func( 'EXT:templates_aide/Resources/Public/Css/backend/production-stage'; } + \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::registerPageTSConfigFile( + 'templates_aide', + 'Resources/Private/PageTSConfig/default.tsconfig', + 'Default Config' + ); + if (TYPO3_MODE == 'BE') { //$pageRenderer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance( // \TYPO3\CMS\Core\Page\PageRenderer::class From 3d0133b70c65d1711d81c32e68115f454e14d0bf Mon Sep 17 00:00:00 2001 From: Philipp Dieter Date: Sun, 26 Jul 2020 23:13:00 +0200 Subject: [PATCH 02/18] [TASK] Add action controoller --- Classes/Controller/ActionController.php | 362 ++++++++++++++++++++++++ 1 file changed, 362 insertions(+) create mode 100644 Classes/Controller/ActionController.php diff --git a/Classes/Controller/ActionController.php b/Classes/Controller/ActionController.php new file mode 100644 index 0000000..c3ae6bf --- /dev/null +++ b/Classes/Controller/ActionController.php @@ -0,0 +1,362 @@ + + * + ***/ + +use \Opis\JsonSchema\{ + Validator, ValidationResult, ValidationError, Schema +}; +use TYPO3\CMS\Core\Cache\CacheManager; +use TYPO3\CMS\Core\Log\LogManager; +use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Extbase\Mvc\Controller\ActionController as BaseController; +use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder; +use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper; +use TYPO3\CMS\Extbase\Service\ExtensionService; +use TYPO3\CMS\Extbase\Utility\LocalizationUtility; + +class ActionController extends BaseController +{ + + /* + * page type + */ + protected $pageType = null; + + /* + * content object uid + */ + protected $contentObjectUid = null; + + /* + * cacheManager + */ + protected $cacheManager = null; + + /* + * cache + */ + protected $cache = null; + + /** + * data mapper + */ + protected $dataMapper = null; + + /* + * logManager + */ + protected $logManager = null; + + /* + * logger + */ + protected $importLogger = null; + + /* + * logger + */ + protected $generalLogger = null; + + /** + * request body + * will only be set if page request action is post + */ + protected $requestBody = null; + + /** + * page type for ajax requests + */ + protected $ajaxPageType = 5000; + + /** + * response stus + */ + protected $responseStatus = 200; + + /** + * redirect url + */ + protected $redirect = null; + + /** + * errors + */ + protected $errors = []; + + /** + * errors labels + */ + protected $errorLabels = []; + + /** + * ajaxEnv + */ + protected $ajaxEnv = []; + + /** + * @var \TYPO3\CMS\Extbase\Service\ExtensionService + */ + protected $extensionService; + + /** + * uribuilder + */ + protected $uriBuilder = null; + + /** + * @param \TYPO3\CMS\Extbase\Service\ExtensionService $extensionService + */ + public function injectExtensionService(ExtensionService $extensionService) + { + $this->extensionService = $extensionService; + } + + /* + * initialize action + * + * @return void + */ + public function initializeAction() + { + $this->pageType = GeneralUtility::_GP('type'); + if (!is_numeric($this->pageType)) { + $this->pageType = 0; + } + if ($this->request->getMethod() == 'POST') { + $this->requestBody = json_decode( + file_get_contents('php://input') + ); + } + $this->contentObjectUid = + $this->configurationManager->getContentObject()->data['uid']; + $this->cacheManager = $this->objectManager->get( + CacheManager::class + ); + $this->cache = $this->cacheManager->getCache( + 'tobereplaced' //TODO: Replaceme + ); + $this->logManager = $this->objectManager->get( + LogManager::Class + ); + $this->importLogger = $this->logManager->getLogger( + 'importLogger' + ); + $this->generalLogger = $this->logManager->getLogger( + __CLASS__ + ); + $this->dataMapper = $this->objectManager->get( + DataMapper::Class + ); + } + + /** + * shortcut to get to know if request is submittet via post + * + * @return void + */ + protected function isPOST() + { + if ($this->request->getMethod() == 'POST'){ + return true; + } + return false; + } + + /** + * shortcut to get translation + * + * @return void + */ + protected function getTranslation($key, $arguments = null) + { + return LocalizationUtility::translate( + $key, + 'tobereplaced', //TODO: Replace me + $arguments + ); + } + + /** + * gets error label based on field and keyword, uses predefined extensionkey + */ + protected function getErrorLabel($field, $keyword) { + $path = 'error.' . $field . '.' . $keyword; + $errorLabel = $this->getTranslation($path); + if ($errorLabel == null) { + return $path; + } + return $errorLabel; + } + + /** + * function to add validation error manually in the controller + */ + protected function addValidationError($field, $keyword) { + $this->responseStatus = [400 => 'validationError']; + $this->errors[$field] = [ + 'keyword' => $keyword, + ]; + $this->errorLabels[$field] = $this->getErrorLabel( + $field, + $keyword + ); + } + + /** + * validate objects + * + * @param $input + * @param schema + * @return void + */ + protected function validateInput($input, $schema) + { + $validator = new Validator(); + $validationResult = $validator->dataValidation( + $input, + json_encode($schema), + -1 + ); + if (!$validationResult->isValid()) { + $this->responseStatus = [400 => 'validationError']; + foreach ($validationResult->getErrors() as $error){ + $errorLabel = null; + $field = $error->dataPointer()[0]; + if ($error->keyword() == 'required') { + $field = ($error->keywordArgs()['missing']); + } + if ($error->keyword() == 'additionalProperties') { + continue; + } + $this->errors[$field] = [ + 'keyword' => $error->keyword(), + 'details' => $error->keywordArgs() + ]; + if ($error->keyword() != 'required') { + $errorLabel = $this->getTranslation( + 'error.' . $field . '.' . $error->keyword() + ); + //if ($errorLabel == null) { + // $errorLabel = $this->getTranslation( + // 'error.' . $field . '.required' + // ); + //} + if ($errorLabel == null) { + $errorLabel = 'error.' + . $field + . '.' + . $error->keyword(); + } + $this->errorLabels[$field] = $errorLabel; + } else { + foreach ($error->keywordArgs() as $arg) { + $errorLabel = $this->getTranslation( + 'error.' . $arg . '.required' + ); + if ($errorLabel == null) { + $errorLabel = 'error.' + . $field + . '.' + . $error->keyword(); + } + $this->errorLabels[$arg] = $errorLabel; + } + } + } + } + return $validationResult->isValid(); + } + + /** + * sets vars which are needed by the ajax requests + * + * @return void + */ + protected function setAjaxEnv($object = null) + { + if ($object == null) { + $object = $this->arguments->getArgumentNames()[0]; + } + $uri = $this->getControllerContext() + ->getUriBuilder() + ->reset() + ->setCreateAbsoluteUri(true) + ->setTargetPageType($this->ajaxPageType) + ->setArguments(['cid' => $this->contentObjectUid]) + ->uriFor($this->request->getControllerActionName()); + $this->ajaxEnv = [ + 'uri' => $uri, + 'object' => $object, + 'namespace' => $this->getPluginNamespace(), + ]; + } + + /** + * return function, checks for page type and decides + * + * @param array $result + * @return void + */ + protected function returnFunction($result = [], $errorStatus = null) + { + $this->setAjaxEnv(); + if ($result == null) { + $result = []; + } + if (!empty($this->errors)) { + $result = array_merge( + $result, + ['errors' => $this->errors] + ); + } + if (!empty($this->errorLabels)) { + $result = array_merge( + $result, + ['errorLabels' => $this->errorLabels] + ); + } + if (is_array($this->responseStatus)) { + $result = array_merge( + $result, + ['errorType' => reset($this->responseStatus)] + ); + } + if ($this->pageType) { + if (is_array($this->responseStatus)) { + $this->response->setStatus( + array_key_first($this->responseStatus) + ); + } else { + $this->response->setStatus($this->responseStatus); + } + $this->response->setHeader( + 'Content-type', + 'application/json' + ); + unset($result['data']); + if ($this->redirect) { + $result['redirect'] = $this->redirect; + } + return json_encode($result); + } + $result = array_merge($result, ['cid' => $this->contentObjectUid]); + if (!empty($this->ajaxEnv)) { + $result = array_merge( + $result, + ['ajaxEnv' => $this->ajaxEnv] + ); + } + $this->view->assignMultiple($result); + } + +} From 33cfcf1abbaca5a7ee7aeab01b05f6ec5f77ff32 Mon Sep 17 00:00:00 2001 From: Philipp Dieter Date: Thu, 30 Jul 2020 01:17:37 +0200 Subject: [PATCH 03/18] [BUGFIX] Disable getting nonexisting cache --- Classes/Controller/ActionController.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Classes/Controller/ActionController.php b/Classes/Controller/ActionController.php index c3ae6bf..ba237c7 100644 --- a/Classes/Controller/ActionController.php +++ b/Classes/Controller/ActionController.php @@ -142,9 +142,9 @@ class ActionController extends BaseController $this->cacheManager = $this->objectManager->get( CacheManager::class ); - $this->cache = $this->cacheManager->getCache( - 'tobereplaced' //TODO: Replaceme - ); + //$this->cache = $this->cacheManager->getCache( + // 'tobereplaced' //TODO: Replaceme + //); $this->logManager = $this->objectManager->get( LogManager::Class ); From 3e37d9882cbbbd231927ae9a2abb4911cb9a0695 Mon Sep 17 00:00:00 2001 From: Philipp Dieter Date: Thu, 30 Jul 2020 01:18:08 +0200 Subject: [PATCH 04/18] [TASK] Start working on additional steps logic --- Classes/Controller/ActionController.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/Classes/Controller/ActionController.php b/Classes/Controller/ActionController.php index ba237c7..7a66219 100644 --- a/Classes/Controller/ActionController.php +++ b/Classes/Controller/ActionController.php @@ -164,7 +164,7 @@ class ActionController extends BaseController * * @return void */ - protected function isPOST() + protected function isPost() { if ($this->request->getMethod() == 'POST'){ return true; @@ -172,6 +172,28 @@ class ActionController extends BaseController return false; } + /** + * shortcut to get to know if request is submittet via post and specific + * step is set + * + * @return void + */ + protected function isPostStep( + $testStep = null + ) { + $step = null; + //if (array_key_exists('step', $this->arguments)){ + // $step = $ + //} + if ( + $this->request->getMethod() == 'POST' + && $step == $testStep + ){ + return true; + } + return false; + } + /** * shortcut to get translation * From fbd07a1545174cb48267a7de15459fe4a9fe8116 Mon Sep 17 00:00:00 2001 From: Philipp Dieter Date: Thu, 30 Jul 2020 01:18:29 +0200 Subject: [PATCH 05/18] [TASK] Improve validation of empty strings --- Classes/Controller/ActionController.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Classes/Controller/ActionController.php b/Classes/Controller/ActionController.php index 7a66219..c2efe83 100644 --- a/Classes/Controller/ActionController.php +++ b/Classes/Controller/ActionController.php @@ -244,8 +244,14 @@ class ActionController extends BaseController protected function validateInput($input, $schema) { $validator = new Validator(); + $input = array_filter($input, function($element) { + if (is_string($element) && !strlen($element)) { + return false; + } + return $element; + }); $validationResult = $validator->dataValidation( - $input, + (object)$input, json_encode($schema), -1 ); @@ -299,6 +305,21 @@ class ActionController extends BaseController return $validationResult->isValid(); } + /** + * returns plugin namespace to build js post request + * + * @return void + */ + protected function getPluginNamespace() + { + $extensionName = $this->request->getControllerExtensionName(); + $pluginName = $this->request->getPluginName(); + return $this->extensionService->getPluginNamespace( + $extensionName, + $pluginName + ); + } + /** * sets vars which are needed by the ajax requests * From 7ed00c1bbbf13f77084c3dfb59b77c15b3e13430 Mon Sep 17 00:00:00 2001 From: Philipp Dieter Date: Mon, 3 Aug 2020 02:26:37 +0200 Subject: [PATCH 06/18] [TASK] Improve input validation for nested elements --- Classes/Controller/ActionController.php | 59 ++++++++++++++++--------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/Classes/Controller/ActionController.php b/Classes/Controller/ActionController.php index c2efe83..298aafd 100644 --- a/Classes/Controller/ActionController.php +++ b/Classes/Controller/ActionController.php @@ -234,6 +234,29 @@ class ActionController extends BaseController ); } + public function arrayRemoveEmptyStrings($array) + { + foreach ($array as $key => &$value) { + if (is_array($value)) { + $value = $this->arrayRemoveEmptyStrings($value); + } else { + if (is_string($value) && !strlen($value)) { + unset($array[$key]); + } + } + } + unset($value); + return $array; + } + + public static function arrayToObject($array) { + if (is_array($array)) { + return (object) array_map([__CLASS__, __METHOD__], $array); + } else { + return $array; + } + } + /** * validate objects * @@ -244,14 +267,10 @@ class ActionController extends BaseController protected function validateInput($input, $schema) { $validator = new Validator(); - $input = array_filter($input, function($element) { - if (is_string($element) && !strlen($element)) { - return false; - } - return $element; - }); + $input = $this->arrayRemoveEmptyStrings($input); + $input = $this->arrayToObject($input); $validationResult = $validator->dataValidation( - (object)$input, + $input, json_encode($schema), -1 ); @@ -259,9 +278,11 @@ class ActionController extends BaseController $this->responseStatus = [400 => 'validationError']; foreach ($validationResult->getErrors() as $error){ $errorLabel = null; - $field = $error->dataPointer()[0]; + $field = implode('.', $error->dataPointer()); if ($error->keyword() == 'required') { - $field = ($error->keywordArgs()['missing']); + $tmp = $error->dataPointer(); + array_push($tmp, $error->keywordArgs()['missing']); + $field = implode('.', $tmp); } if ($error->keyword() == 'additionalProperties') { continue; @@ -287,18 +308,16 @@ class ActionController extends BaseController } $this->errorLabels[$field] = $errorLabel; } else { - foreach ($error->keywordArgs() as $arg) { - $errorLabel = $this->getTranslation( - 'error.' . $arg . '.required' - ); - if ($errorLabel == null) { - $errorLabel = 'error.' - . $field - . '.' - . $error->keyword(); - } - $this->errorLabels[$arg] = $errorLabel; + $errorLabel = $this->getTranslation( + 'error.' . $field . '.required' + ); + if ($errorLabel == null) { + $errorLabel = 'error.' + . $field + . '.' + . $error->keyword(); } + $this->errorLabels[$field] = $errorLabel; } } } From decc709e55cff840edd365644c41418cee9645b7 Mon Sep 17 00:00:00 2001 From: Philipp Dieter Date: Tue, 4 Aug 2020 23:59:33 +0200 Subject: [PATCH 07/18] [TASK] Fix step handling --- Classes/Controller/ActionController.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Classes/Controller/ActionController.php b/Classes/Controller/ActionController.php index 298aafd..16a20d3 100644 --- a/Classes/Controller/ActionController.php +++ b/Classes/Controller/ActionController.php @@ -157,6 +157,7 @@ class ActionController extends BaseController $this->dataMapper = $this->objectManager->get( DataMapper::Class ); + $this->arguments->addNewArgument('step', 'string', false, false); } /** @@ -182,9 +183,9 @@ class ActionController extends BaseController $testStep = null ) { $step = null; - //if (array_key_exists('step', $this->arguments)){ - // $step = $ - //} + if ($this->arguments->hasArgument('step')){ + $step = $this->arguments->getArgument('step')->getValue(); + } if ( $this->request->getMethod() == 'POST' && $step == $testStep From db5c79cef6316703d2746835b73486ebb50ffc0f Mon Sep 17 00:00:00 2001 From: Philipp Dieter Date: Fri, 18 Sep 2020 00:04:28 +0200 Subject: [PATCH 08/18] [TASK] Add propertymapping classes --- Classes/Controller/ActionController.php | 204 +++++++++++++++++++++++- 1 file changed, 199 insertions(+), 5 deletions(-) diff --git a/Classes/Controller/ActionController.php b/Classes/Controller/ActionController.php index 16a20d3..ee5e028 100644 --- a/Classes/Controller/ActionController.php +++ b/Classes/Controller/ActionController.php @@ -21,6 +21,8 @@ use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Mvc\Controller\ActionController as BaseController; use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder; use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper; +use TYPO3\CMS\Extbase\Property\PropertyMapper; +use TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationBuilder; use TYPO3\CMS\Extbase\Service\ExtensionService; use TYPO3\CMS\Extbase\Utility\LocalizationUtility; @@ -113,6 +115,11 @@ class ActionController extends BaseController */ protected $uriBuilder = null; + /** + * propertyMappginConfigrtationBuolder + */ + protected $propertyMapperConfigurationBuilder; + /** * @param \TYPO3\CMS\Extbase\Service\ExtensionService $extensionService */ @@ -121,6 +128,39 @@ class ActionController extends BaseController $this->extensionService = $extensionService; } + /** + * propertyMapper + * + * @var PropertyMapper + */ + protected $propertyMapper; + + /** + * @param + */ + public function injectPropertyMapper( + PropertyMapper $propertyMapper + ) { + $this->propertyMapper = $propertyMapper; + } + + /** + * propertyMappingConfigurationBuilder + * + * @var PropertyMappingConfigurationBuilder + */ + protected $propertyMappingConfigurationBuilder; + + /** + * @param + */ + public function injectPropertyMappingConfigurationBuilder( + PropertyMappingConfigurationBuilder $propertyMappingConfigurationBuilder + ) { + $this->propertyMappingConfigurationBuilder + = $propertyMappingConfigurationBuilder; + } + /* * initialize action * @@ -158,6 +198,7 @@ class ActionController extends BaseController DataMapper::Class ); $this->arguments->addNewArgument('step', 'string', false, false); + $this->arguments->addNewArgument('submit', 'string', false, false); } /** @@ -180,21 +221,77 @@ class ActionController extends BaseController * @return void */ protected function isPostStep( - $testStep = null + $testValue = null ) { - $step = null; - if ($this->arguments->hasArgument('step')){ - $step = $this->arguments->getArgument('step')->getValue(); + return $this->isPostAndArgumentMatches('step', $testValue); + } + + /** + * + */ + protected function isPostSubmit( + $testValue = null + ) { + return $this->isPostAndArgumentMatches('submit', $testValue); + } + + /** + * + */ + protected function isPostAndArgumentMatches( + $argument, + $testValue + ) { + $value = null; + if ($this->arguments->hasArgument($argument)){ + $value = $this->arguments->getArgument($argument)->getValue(); } if ( $this->request->getMethod() == 'POST' - && $step == $testStep + && $value == $testValue ){ return true; } return false; } + protected function einTest( + $actions = [] + ) { + + } + + /** + * + */ + protected function getPostSubmit() + { + return explode('#', $this->getPostValue('submit'))[0]; + } + + /** + * + */ + protected function getPostSubmitItem() + { + return explode('#', $this->getPostValue('submit'))[1]; + } + + /** + * + */ + protected function getPostValue( + $argument + ) { + if ($this->arguments->hasArgument($argument)){ + //\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump( + // $this->arguments->getArgument($argument)->getValue(), null, 3 + //); + return $this->arguments->getArgument($argument)->getValue(); + } + return false; + } + /** * shortcut to get translation * @@ -364,6 +461,103 @@ class ActionController extends BaseController ]; } + /** + * The hash service class to use + * + * @var \TYPO3\CMS\Extbase\Security\Cryptography\HashService + */ + protected $hashService; + + /** + * @param \TYPO3\CMS\Extbase\Security\Cryptography\HashService $hashService + */ + public function injectHashService(\TYPO3\CMS\Extbase\Security\Cryptography\HashService $hashService) + { + $this->hashService = $hashService; + } + + /** + * get property mapper config + * + * @return void + */ + protected function getPropertyMappingConfiguration($attribute) + { + $propertyMappingConfiguration = $this + ->propertyMappingConfigurationBuilder->build(); + $this->initializePropertyMappingConfigurationFromRequest( + $this->request, + $propertyMappingConfiguration, + $attribute + ); + return $propertyMappingConfiguration; + } + + /** + * Initialize the property mapping configuration in $controllerArguments if + * the trusted properties are set inside the request. + * + * @param \TYPO3\CMS\Extbase\Mvc\Request $request + * @param \TYPO3\CMS\Extbase\Mvc\Controller\Arguments $controllerArguments + * @throws BadRequestException + */ + public function initializePropertyMappingConfigurationFromRequest(\TYPO3\CMS\Extbase\Mvc\Request $request, $propertyMappingConfiguration, $propertyNameTest) + { + $trustedPropertiesToken = $request->getInternalArgument('__trustedProperties'); + if (!is_string($trustedPropertiesToken)) { + return; + } + + try { + $serializedTrustedProperties = $this->hashService->validateAndStripHmac($trustedPropertiesToken); + } catch (InvalidHashException | InvalidArgumentForHashGenerationException $e) { + throw new BadRequestException('The HMAC of the form could not be validated.', 1581862822); + } + $trustedProperties = unserialize($serializedTrustedProperties, ['allowed_classes' => false]); + foreach ($trustedProperties as $propertyName => $propertyConfiguration) { + + //if (!$controllerArguments->hasArgument($propertyName)) { + // continue; + //} + if ($propertyName != $propertyNameTest) { + continue; + } + //$propertyMappingConfiguration = $controllerArguments->getArgument($propertyName)->getPropertyMappingConfiguration(); + $this->modifyPropertyMappingConfiguration($propertyConfiguration, $propertyMappingConfiguration); + } + } + + /** + * Modify the passed $propertyMappingConfiguration according to the $propertyConfiguration which + * has been generated by Fluid. In detail, if the $propertyConfiguration contains + * an __identity field, we allow modification of objects; else we allow creation. + * + * All other properties are specified as allowed properties. + * + * @param array $propertyConfiguration + * @param \TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration $propertyMappingConfiguration + */ + protected function modifyPropertyMappingConfiguration($propertyConfiguration, \TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration $propertyMappingConfiguration) + { + if (!is_array($propertyConfiguration)) { + return; + } + + if (isset($propertyConfiguration['__identity'])) { + $propertyMappingConfiguration->setTypeConverterOption(\TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter::class, \TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_MODIFICATION_ALLOWED, true); + unset($propertyConfiguration['__identity']); + } else { + $propertyMappingConfiguration->setTypeConverterOption(\TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter::class, \TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED, true); + } + + foreach ($propertyConfiguration as $innerKey => $innerValue) { + if (is_array($innerValue)) { + $this->modifyPropertyMappingConfiguration($innerValue, $propertyMappingConfiguration->forProperty($innerKey)); + } + $propertyMappingConfiguration->allowProperties($innerKey); + } + } + /** * return function, checks for page type and decides * From 1cd9c2567eb88a8e16a4d70553898b58f677a10a Mon Sep 17 00:00:00 2001 From: Philipp Dieter Date: Sun, 4 Oct 2020 23:48:22 +0200 Subject: [PATCH 09/18] [TASK] Add Double2Converter --- .../TypeConverter/Double2Converter.php | 88 +++++++++++++++++++ ext_tables.php | 6 ++ 2 files changed, 94 insertions(+) create mode 100644 Classes/Property/TypeConverter/Double2Converter.php diff --git a/Classes/Property/TypeConverter/Double2Converter.php b/Classes/Property/TypeConverter/Double2Converter.php new file mode 100644 index 0000000..06ad658 --- /dev/null +++ b/Classes/Property/TypeConverter/Double2Converter.php @@ -0,0 +1,88 @@ + + * + ***/ + +use TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface; +use TYPO3\CMS\Extbase\Property\TypeConverter\AbstractTypeConverter; + +/** + * Converter which transforms arrays to arrays. + */ +class Double2Converter extends AbstractTypeConverter +{ + /** + * @var array + */ + protected $sourceTypes = ['integer', 'string']; + + /** + * @var string + */ + protected $targetType = 'double2'; + + /** + * @var int + */ + protected $priority = 10; + + /** + * @param mixed $source + * @param string $targetType + * @return bool + * @internal only to be used within Extbase, not part of TYPO3 Core API. + */ + public function canConvertFrom($source, $targetType) + { + return is_string($source) ||is_integer($source); + } + + /** + * Copied from + * TYPO3\CMS\Core\DataHandling\DataHandler::checkValue_input_Eval + * + * @param string|array $source + * @param string $targetType + * @param array $convertedChildProperties + * @param PropertyMappingConfigurationInterface $configuration + * @return array + */ + public function convertFrom( + $source, + $targetType, + array $convertedChildProperties = [], + PropertyMappingConfigurationInterface $configuration = null + ) { + $value = preg_replace('/[^0-9,\\.-]/', '', $source); + $negative = $value[0] === '-'; + $value = strtr($value, [',' => '.', '-' => '']); + if (strpos($value, '.') === false) { + $value .= '.0'; + } + $valueArray = explode('.', $value); + $dec = array_pop($valueArray); + $value = implode('', $valueArray) . '.' . $dec; + if ($negative) { + $value *= -1; + } + $value = number_format($value, 2, '.', ''); + //\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump( + // $source, null, 3 + //); + //if (is_string($source)) { + // if ($source === '') { + // $source = []; + // } + //} + return $value; + } +} diff --git a/ext_tables.php b/ext_tables.php index 2106264..778d708 100644 --- a/ext_tables.php +++ b/ext_tables.php @@ -20,6 +20,9 @@ call_user_func( ); ## EXTENSION BUILDER DEFAULTS END TOKEN - Everything BEFORE this line is overwritten with the defaults of the extension builder +use Cjel\TemplatesAide\Property\TypeConverter\Double2Converter; +use TYPO3\CMS\Extbase\Utility\ExtensionUtility; + call_user_func( function() { @@ -43,6 +46,9 @@ call_user_func( 'Default Config' ); + + ExtensionUtility::registerTypeConverter(Double2Converter::class); + if (TYPO3_MODE == 'BE') { //$pageRenderer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance( // \TYPO3\CMS\Core\Page\PageRenderer::class From f40c4b6e742a5235f5c2151128948f03499275c7 Mon Sep 17 00:00:00 2001 From: Philipp Dieter Date: Sun, 4 Oct 2020 23:49:15 +0200 Subject: [PATCH 10/18] [TASK] Improve validation handling --- Classes/Controller/ActionController.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Classes/Controller/ActionController.php b/Classes/Controller/ActionController.php index ee5e028..9be730e 100644 --- a/Classes/Controller/ActionController.php +++ b/Classes/Controller/ActionController.php @@ -90,6 +90,11 @@ class ActionController extends BaseController */ protected $redirect = null; + /** + * is valid + */ + protected $isValid = true; + /** * errors */ @@ -366,6 +371,15 @@ class ActionController extends BaseController { $validator = new Validator(); $input = $this->arrayRemoveEmptyStrings($input); + //@todo make optional when usiing rest api + //array_walk_recursive( + // $input, + // function (&$value) { + // if (filter_var($value, FILTER_VALIDATE_INT)) { + // $value = (int)$value; + // } + // } + //); $input = $this->arrayToObject($input); $validationResult = $validator->dataValidation( $input, @@ -373,6 +387,7 @@ class ActionController extends BaseController -1 ); if (!$validationResult->isValid()) { + $this->isValid = false; $this->responseStatus = [400 => 'validationError']; foreach ($validationResult->getErrors() as $error){ $errorLabel = null; @@ -607,6 +622,7 @@ class ActionController extends BaseController return json_encode($result); } $result = array_merge($result, ['cid' => $this->contentObjectUid]); + $result = array_merge($result, ['isValid' => $this->isValid]); if (!empty($this->ajaxEnv)) { $result = array_merge( $result, From 8a55fa720953b287d7ffef4889646dc9416c886a Mon Sep 17 00:00:00 2001 From: Philipp Dieter Date: Sun, 4 Oct 2020 23:49:43 +0200 Subject: [PATCH 11/18] [CLEANUP] Remove debugging output --- Classes/Controller/ActionController.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/Classes/Controller/ActionController.php b/Classes/Controller/ActionController.php index 9be730e..144d412 100644 --- a/Classes/Controller/ActionController.php +++ b/Classes/Controller/ActionController.php @@ -289,9 +289,6 @@ class ActionController extends BaseController $argument ) { if ($this->arguments->hasArgument($argument)){ - //\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump( - // $this->arguments->getArgument($argument)->getValue(), null, 3 - //); return $this->arguments->getArgument($argument)->getValue(); } return false; From c9bd34eb236c29a93676c0fbf75adbb5620fb036 Mon Sep 17 00:00:00 2001 From: Philipp Dieter Date: Sun, 4 Oct 2020 23:49:58 +0200 Subject: [PATCH 12/18] [TASK] Add MailUtility and default templates --- Classes/Utility/MailUtility.php | 207 +++++++++ .../Templates/Mailing/DefaultHtml.html | 394 ++++++++++++++++++ .../Templates/Mailing/DefaultText.html | 20 + 3 files changed, 621 insertions(+) create mode 100644 Classes/Utility/MailUtility.php create mode 100644 Resources/Private/Templates/Mailing/DefaultHtml.html create mode 100644 Resources/Private/Templates/Mailing/DefaultText.html diff --git a/Classes/Utility/MailUtility.php b/Classes/Utility/MailUtility.php new file mode 100644 index 0000000..e666996 --- /dev/null +++ b/Classes/Utility/MailUtility.php @@ -0,0 +1,207 @@ + + * + ***/ + +use TYPO3\CMS\Core\Mail\MailMessage; +use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder; +use TYPO3\CMS\Extbase\Object\ObjectManager; +use TYPO3\CMS\Extbase\Service\ImageService; +use TYPO3\CMS\Fluid\View\StandaloneView; +use TYPO3\CMS\Fluid\View\TemplatePaths; + +/** + * + */ +class MailUtility +{ + /** + * tages maildata, builds html and text mails an decides where to send them + * allows to intercept sender for testing + * + * @param string $target email or group identifier + * @param string $subject mail subject, prefixed by setting in ts + * @param array $data content for email, gets parsed in different ways + * @return void + */ + public static function sendMail( + $target, + $sender, + $subject, + $data, + $templateRootPaths = null, + $templateNameHtml = null, + $templateNameText = null + ) { + if (!$templateRootPaths) { + $templatePaths = new TemplatePaths(); + $templatePaths->fillDefaultsByPackageName('templates_aide'); + $templateRootPaths = $templatePaths->getTemplateRootPaths(); + } + if (!$templateNameHtml) { + $templateNameHtml = 'Mailing/DefaultHtml'; + } + if (!$templateNameText) { + $templateNameText = 'Mailing/DefaultText'; + } + $htmlView = GeneralUtility::makeInstance(StandaloneView::class); + $htmlView->setTemplateRootPaths($templateRootPaths); + $htmlView->setTemplate($templateNameHtml); + $textView = GeneralUtility::makeInstance(StandaloneView::class); + $textView->setTemplateRootPaths($templateRootPaths); + $textView->setTemplate($templateNameText); + $mail = GeneralUtility::makeInstance(MailMessage::class); + $mail->setFrom($sender); + $mail->setSubject($subject); + $bodydataText = []; + $bodydataHtml = []; + foreach ($data as $row) { + switch($row['type']) { + case 'text': + case 'headline': + $htmlRow = $row; + $htmlRow['data'] = preg_replace_callback( + '/\[.*\]/mU', + function($matches) { + + foreach ($matches as $match) { + return preg_replace_callback( + '/\[(\S*)\s(.*)\]/mU', + function($matchesInner) { + return '' + . $matchesInner[2] + . ''; + }, + $match + ); + } + }, + $htmlRow['data'] + ); + $textRow = $row; + $textRow['data'] = preg_replace_callback( + '/\[.*\]/mU', + function($matches) { + foreach ($matches as $match) { + return preg_replace_callback( + '/\[(\S*)\s(.*)\]/mU', + function($matchesInner) { + return $matchesInner[2] + . ': ' + . $matchesInner[1]; + }, + $match + ); + } + }, + $textRow['data'] + ); + $bodydataText[] = $textRow; + $bodydataHtml[] = $htmlRow; + break; + case 'button': + case 'buttons': + $htmlRow = $row; + //$htmlRow['targets'] = preg_replace_callback( + // '/\[.*\]/mU', + // function($matches) { + // foreach ($matches as $match) { + // return preg_replace_callback( + // '/\[(\S*)\s(.*)\]/mU', + // function($matchesInner) { + // return $matchesInner; + // //return '' + // // . $matchesInner[2] + // // . ''; + // }, + // $match + // ); + // } + // }, + // $htmlRow['targets'] + //); + $textRow = $row; + //$textRow['targets'] = preg_replace_callback( + // '/\[.*\]/mU', + // function($matches) { + // foreach ($matches as $match) { + // return preg_replace_callback( + // '/\[(\S*)\s(.*)\]/mU', + // function($matchesInner) { + // return $matchesInner; + // //return $matchesInner[2] + // // . ': ' + // // . $matchesInner[1]; + // }, + // $match + // ); + // } + // }, + // $textRow['targets'] + //); + $bodydataText[] = $textRow; + $bodydataHtml[] = $htmlRow; + break; + case 'attachmentBase64': + $attachmentdata = explode(',', $row['data']); + preg_match('/\w*:(.*);\w*/', $attachmentdata[0], $matches); + $mimetype = $matches[1]; + preg_match('/\w*\/(.*);\w*/', $attachmentdata[0], $matches); + $fileextension = $matches[1]; + $mail->attach(new \Swift_Attachment( + base64_decode($attachmentdata[1]), + 'attachment.' . $fileextension, + $mimetype + )); + break; + } + } + $textView->assign('content', $bodydataText); + $htmlView->assign('content', $bodydataHtml); + $domain = GeneralUtility::locationHeaderUrl('/'); + $htmlView->assign('domain', $domain); + $textBody = $textView->render(); + $htmlBody = $htmlView->render(); + $mail->setBody($textBody); + $mail->addPart($htmlBody, 'text/html'); + $recipients = explode( + ',', + $target + ); + if ($GLOBALS['TYPO3_CONF_VARS']['MAIL']['intercept_to']) { + $subjectOrig = $mail->getSubject(); + $recipientsIntercecpted = explode( + ',', + $GLOBALS['TYPO3_CONF_VARS']['MAIL']['intercept_to'] + ); + foreach ($recipientsIntercecpted as $recipientIntercepted) { + foreach ($recipients as $recipient) { + $mail->setSubject( + $subjectOrig . ' [ORIG-TO: ' . trim($recipient) . ']' + ); + $mail->setTo(trim($recipientIntercepted)); + $mail->send(); + } + } + } else { + foreach ($recipients as $recipient) { + $mail->setTo(trim($recipient)); + $mail->send(); + } + } + } +} diff --git a/Resources/Private/Templates/Mailing/DefaultHtml.html b/Resources/Private/Templates/Mailing/DefaultHtml.html new file mode 100644 index 0000000..ca7e1a9 --- /dev/null +++ b/Resources/Private/Templates/Mailing/DefaultHtml.html @@ -0,0 +1,394 @@ + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + +
+ +
+ + + + +
+ + + + + + +
+
+
+
+ +
+
+ +
+ + + + + + +
+ +
+ + + + +
+
+
{row.data.0 -> f:format.nl2br() -> f:format.raw()}
+
+
+
+ +
+ + + + +
+
+
{row.data.1 -> f:format.nl2br() -> f:format.raw()}
+
+
+
+ +
+
+ +
+ + + + + + +
+ +
+ + + + +
+
+ + +

{row.data -> f:format.nl2br() -> f:format.raw()}

+
+ +

{row.data -> f:format.nl2br() -> f:format.raw()}

+
+
+
+
+
+ +
+
+ +
+ + + + + + +
+ +
+ + + + + + +
+ + + + +
+ + {row.targets.0.1} + +
+
+
+ +
+
+ +
+ + + + + + +
+ +
+ + + + + + +
+ + + + +
+ + {row.targets.0.1} + +
+
+
+ +
+ + + + + + +
+ + + + +
+ + {row.targets.1.1} + +
+
+
+ +
+
+ +
+ + + + + + +
+ +
+
+ +
+ + diff --git a/Resources/Private/Templates/Mailing/DefaultText.html b/Resources/Private/Templates/Mailing/DefaultText.html new file mode 100644 index 0000000..f923ea4 --- /dev/null +++ b/Resources/Private/Templates/Mailing/DefaultText.html @@ -0,0 +1,20 @@ + + + + + {row.data.0}: {row.data.1} + + = {row.data} = + {row.data} + + +{br}{br} + {br}{br}{row.targets.0.1}:{br}{row.targets.0.0}{br}{br}{row.targets.1.1}:{br}{row.targets.1.0} + + {br}{br}{row.targets.0.1}:{br}{row.targets.0.0} + From 8f24164f031c6a80b16cad64f30fdaada205a7d7 Mon Sep 17 00:00:00 2001 From: Philipp Dieter Date: Mon, 5 Oct 2020 00:56:52 +0200 Subject: [PATCH 13/18] [TASK] add RandomStringUtility --- Classes/Utility/RandomStringUtility.php | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Classes/Utility/RandomStringUtility.php diff --git a/Classes/Utility/RandomStringUtility.php b/Classes/Utility/RandomStringUtility.php new file mode 100644 index 0000000..5a6d4b0 --- /dev/null +++ b/Classes/Utility/RandomStringUtility.php @@ -0,0 +1,32 @@ +, Glanzstück GmbH + * + ***/ + +class RandomStringUtility +{ + public static function getToken( + int $length = 64, + string $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' + ): string { + if ($length < 1) { + throw new \RangeException("Length must be a positive integer"); + } + $pieces = []; + $max = mb_strlen($keyspace, '8bit') - 1; + for ($i = 0; $i < $length; ++$i) { + $pieces []= $keyspace[random_int(0, $max)]; + } + return implode('', $pieces); + } + +} From 4680bce585090dcb30893fb4ee06bd858a27a5b6 Mon Sep 17 00:00:00 2001 From: Philipp Dieter Date: Mon, 5 Oct 2020 00:57:12 +0200 Subject: [PATCH 14/18] [TASK] Add methods to retrieve typoscript --- Classes/Controller/ActionController.php | 37 +++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/Classes/Controller/ActionController.php b/Classes/Controller/ActionController.php index 144d412..1c2addc 100644 --- a/Classes/Controller/ActionController.php +++ b/Classes/Controller/ActionController.php @@ -18,6 +18,7 @@ use \Opis\JsonSchema\{ use TYPO3\CMS\Core\Cache\CacheManager; use TYPO3\CMS\Core\Log\LogManager; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; use TYPO3\CMS\Extbase\Mvc\Controller\ActionController as BaseController; use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder; use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper; @@ -206,6 +207,42 @@ class ActionController extends BaseController $this->arguments->addNewArgument('submit', 'string', false, false); } + /** + * shortcut + * + * @return void + */ + protected function getExtensionKey() + { + return $this->request->getControllerExtensionKey(); + } + + /** + * shortcut function to recieve typoscript + * + * @return array + */ + protected function getPluginTyposcript() + { + return $this->configurationManager->getConfiguration( + ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS, + str_replace('_', '', $this->getExtensionKey), + $this->request->getPluginName() + ); + } + + /** + * shortcut function to recieve typoscript + * + * @return array + */ + protected function getTyposcript() + { + return $this->configurationManager->getConfiguration( + ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS + ); + } + /** * shortcut to get to know if request is submittet via post * From 5e7953acde330b58312919d036545044b9623dd6 Mon Sep 17 00:00:00 2001 From: Philipp Dieter Date: Tue, 6 Oct 2020 00:56:05 +0200 Subject: [PATCH 15/18] [TASK] Add getGetValue() and $componentMode --- Classes/Controller/ActionController.php | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/Classes/Controller/ActionController.php b/Classes/Controller/ActionController.php index 1c2addc..301daaa 100644 --- a/Classes/Controller/ActionController.php +++ b/Classes/Controller/ActionController.php @@ -86,6 +86,11 @@ class ActionController extends BaseController */ protected $responseStatus = 200; + /** + * component mode, used in frontend + */ + protected $componentMode = 'default'; + /** * redirect url */ @@ -331,6 +336,18 @@ class ActionController extends BaseController return false; } + /** + * + */ + protected function getGetValue( + $argument + ) { + if (GeneralUtility::_GP($argument)) { + return GeneralUtility::_GP($argument); + } + return false; + } + /** * shortcut to get translation * @@ -655,8 +672,12 @@ class ActionController extends BaseController } return json_encode($result); } - $result = array_merge($result, ['cid' => $this->contentObjectUid]); - $result = array_merge($result, ['isValid' => $this->isValid]); + $result = array_merge( + $result, + ['cid' => $this->contentObjectUid], + ['isValid' => $this->isValid], + ['componentMode' => $this->componentMode] + ); if (!empty($this->ajaxEnv)) { $result = array_merge( $result, From b7f93518d0cda16d0d6867aa5cdeea74072ceada Mon Sep 17 00:00:00 2001 From: Philipp Dieter Date: Mon, 19 Oct 2020 22:50:47 +0200 Subject: [PATCH 16/18] [BUGFIX] Setting content type for pagetype 5000 --- Classes/Controller/ActionController.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Classes/Controller/ActionController.php b/Classes/Controller/ActionController.php index 301daaa..02a78e6 100644 --- a/Classes/Controller/ActionController.php +++ b/Classes/Controller/ActionController.php @@ -662,10 +662,9 @@ class ActionController extends BaseController } else { $this->response->setStatus($this->responseStatus); } - $this->response->setHeader( - 'Content-type', - 'application/json' - ); + if ($this->pageType == $this->ajaxPageType) { + $GLOBALS['TSFE']->setContentType('application/json'); + } unset($result['data']); if ($this->redirect) { $result['redirect'] = $this->redirect; From 504386c71743abfdf0e794f74fe4b47307442ec1 Mon Sep 17 00:00:00 2001 From: Philipp Dieter Date: Thu, 12 Nov 2020 00:15:26 +0100 Subject: [PATCH 17/18] [TASK] Improve mail template handling --- Classes/Utility/MailUtility.php | 27 +++++++++++++++---- .../Private/Partials/Mails/DefaultHtml.html | 1 + .../{Mailing => Mails}/DefaultHtml.html | 0 .../{Mailing => Mails}/DefaultText.html | 0 4 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 Resources/Private/Partials/Mails/DefaultHtml.html rename Resources/Private/Templates/{Mailing => Mails}/DefaultHtml.html (100%) rename Resources/Private/Templates/{Mailing => Mails}/DefaultText.html (100%) diff --git a/Classes/Utility/MailUtility.php b/Classes/Utility/MailUtility.php index e666996..552d028 100644 --- a/Classes/Utility/MailUtility.php +++ b/Classes/Utility/MailUtility.php @@ -19,6 +19,7 @@ use TYPO3\CMS\Extbase\Object\ObjectManager; use TYPO3\CMS\Extbase\Service\ImageService; use TYPO3\CMS\Fluid\View\StandaloneView; use TYPO3\CMS\Fluid\View\TemplatePaths; +use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; /** * @@ -49,15 +50,31 @@ class MailUtility $templateRootPaths = $templatePaths->getTemplateRootPaths(); } if (!$templateNameHtml) { - $templateNameHtml = 'Mailing/DefaultHtml'; + $templateNameHtml = 'Mails/DefaultHtml'; } if (!$templateNameText) { - $templateNameText = 'Mailing/DefaultText'; + $templateNameText = 'Mails/DefaultText'; } - $htmlView = GeneralUtility::makeInstance(StandaloneView::class); + $objectManager = GeneralUtility::makeInstance(ObjectManager::class); + $configurationManager = $objectManager->get( + ConfigurationManagerInterface::class + ); + $typoScript = $configurationManager->getConfiguration( + ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT + ); + $settings = + (array)$typoScript['module.']['tx_templatesaide.']['settings.']; + $settings = GeneralUtility::removeDotsFromTS($settings); + $htmlView = $objectManager->get(StandaloneView::class); + $htmlView->getTemplatePaths()->fillDefaultsByPackageName( + 'templates_aide' + ); $htmlView->setTemplateRootPaths($templateRootPaths); $htmlView->setTemplate($templateNameHtml); - $textView = GeneralUtility::makeInstance(StandaloneView::class); + $textView = $objectManager->get(StandaloneView::class); + $textView->getTemplatePaths()->fillDefaultsByPackageName( + 'templates_aide' + ); $textView->setTemplateRootPaths($templateRootPaths); $textView->setTemplate($templateNameText); $mail = GeneralUtility::makeInstance(MailMessage::class); @@ -172,7 +189,7 @@ class MailUtility } $textView->assign('content', $bodydataText); $htmlView->assign('content', $bodydataHtml); - $domain = GeneralUtility::locationHeaderUrl('/'); + $domain = $settings['mailDomain']; $htmlView->assign('domain', $domain); $textBody = $textView->render(); $htmlBody = $htmlView->render(); diff --git a/Resources/Private/Partials/Mails/DefaultHtml.html b/Resources/Private/Partials/Mails/DefaultHtml.html new file mode 100644 index 0000000..710a843 --- /dev/null +++ b/Resources/Private/Partials/Mails/DefaultHtml.html @@ -0,0 +1 @@ +

included content

diff --git a/Resources/Private/Templates/Mailing/DefaultHtml.html b/Resources/Private/Templates/Mails/DefaultHtml.html similarity index 100% rename from Resources/Private/Templates/Mailing/DefaultHtml.html rename to Resources/Private/Templates/Mails/DefaultHtml.html diff --git a/Resources/Private/Templates/Mailing/DefaultText.html b/Resources/Private/Templates/Mails/DefaultText.html similarity index 100% rename from Resources/Private/Templates/Mailing/DefaultText.html rename to Resources/Private/Templates/Mails/DefaultText.html From e11c0e813915771767f7cdf26673f5ed39d0620d Mon Sep 17 00:00:00 2001 From: Philipp Dieter Date: Sun, 22 Nov 2020 19:37:47 +0100 Subject: [PATCH 18/18] [TASK] Add mail html content partial and change template path handling --- Classes/Utility/MailUtility.php | 8 --- .../Private/Partials/Mails/DefaultHtml.html | 67 ++++++++++++++++++- 2 files changed, 66 insertions(+), 9 deletions(-) diff --git a/Classes/Utility/MailUtility.php b/Classes/Utility/MailUtility.php index 552d028..061cc1b 100644 --- a/Classes/Utility/MailUtility.php +++ b/Classes/Utility/MailUtility.php @@ -40,15 +40,9 @@ class MailUtility $sender, $subject, $data, - $templateRootPaths = null, $templateNameHtml = null, $templateNameText = null ) { - if (!$templateRootPaths) { - $templatePaths = new TemplatePaths(); - $templatePaths->fillDefaultsByPackageName('templates_aide'); - $templateRootPaths = $templatePaths->getTemplateRootPaths(); - } if (!$templateNameHtml) { $templateNameHtml = 'Mails/DefaultHtml'; } @@ -69,13 +63,11 @@ class MailUtility $htmlView->getTemplatePaths()->fillDefaultsByPackageName( 'templates_aide' ); - $htmlView->setTemplateRootPaths($templateRootPaths); $htmlView->setTemplate($templateNameHtml); $textView = $objectManager->get(StandaloneView::class); $textView->getTemplatePaths()->fillDefaultsByPackageName( 'templates_aide' ); - $textView->setTemplateRootPaths($templateRootPaths); $textView->setTemplate($templateNameText); $mail = GeneralUtility::makeInstance(MailMessage::class); $mail->setFrom($sender); diff --git a/Resources/Private/Partials/Mails/DefaultHtml.html b/Resources/Private/Partials/Mails/DefaultHtml.html index 710a843..c5e88fd 100644 --- a/Resources/Private/Partials/Mails/DefaultHtml.html +++ b/Resources/Private/Partials/Mails/DefaultHtml.html @@ -1 +1,66 @@ -

included content

+ + + + + + + +

+ + + + + + +
+ +
+ + + + + + +
+ + + + +
+
+ + +

{row.data -> f:format.nl2br() -> f:format.raw()}

+
+ +

{row.data -> f:format.nl2br() -> f:format.raw()}

+
+
+
+
+
+
+ +
+
+ + + + +