diff --git a/Classes/Controller/AbstractEIDController.php b/Classes/Controller/AbstractEIDController.php index e874211..dfd9d64 100644 --- a/Classes/Controller/AbstractEIDController.php +++ b/Classes/Controller/AbstractEIDController.php @@ -12,6 +12,8 @@ namespace Cjel\TemplatesAide\Controller; * ***/ +use Cjel\TemplatesAide\Traits\ValidationTrait; +use Cjel\TemplatesAide\Traits\FormatResultTrait; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use TYPO3\CMS\Core\Cache\CacheManager; @@ -21,10 +23,10 @@ use TYPO3\CMS\Core\Log\LogManager; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; use TYPO3\CMS\Extbase\Object\ObjectManager; -use TYPO3\CMS\Frontend\Plugin\AbstractPlugin; -use TYPO3\CMS\Frontend\Utility\EidUtility; use TYPO3\CMS\Extbase\Reflection\ClassSchema; use TYPO3\CMS\Extbase\Reflection\ReflectionService; +use TYPO3\CMS\Frontend\Plugin\AbstractPlugin; +use TYPO3\CMS\Frontend\Utility\EidUtility; /** * AbstractEIDController @@ -32,6 +34,18 @@ use TYPO3\CMS\Extbase\Reflection\ReflectionService; class AbstractEIDController { + /** + * ValidationTrait + */ + use ValidationTrait { + validateAgainstSchema as traitValidateAgainstSchema; + } + + /** + * FormatResultTrait + */ + use FormatResultTrait; + /** * @var BackendConfigurationManager */ @@ -99,11 +113,13 @@ class AbstractEIDController $this->apiUtility = $this->objectManager->get( \Cjel\TemplatesAide\Utility\ApiUtility::class ); - $this->configurationManager->setConfiguration(array()); $frameworkConfiguration = $this->configurationManager->getConfiguration( ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK, $this->getExtensionKey() ); + $this->configurationManager->setConfiguration( + $frameworkConfiguration + ); $this->settings = $frameworkConfiguration; $this->storagePids = explode( ',', @@ -241,4 +257,35 @@ class AbstractEIDController } } + /** + * return function + * + * @param array $result + * @return void + */ + protected function returnFunction( + $result = [] + ) { + $result = $this->formatResult($result, 'asd'); + unset($result['cid']); + unset($result['componentMode']); + unset($result['isValid']); + if ($result) { + if (!empty($this->errors)) { + return $result; + } else { + return [ + 'metadata' => [ + 'total' => count($result), + 'count' => count($result), + ], + 'result' => $result, + ]; + } + } else { + return []; + } + //return $result; + } + } diff --git a/Classes/Controller/ActionController.php b/Classes/Controller/ActionController.php index 3ecafa6..dae6c4a 100644 --- a/Classes/Controller/ActionController.php +++ b/Classes/Controller/ActionController.php @@ -3,7 +3,7 @@ namespace Cjel\TemplatesAide\Controller; /*** * - * This file is part of the "Templates Aide" Extension for TYPO3 CMS. + / This file is part of the "Templates Aide" Extension for TYPO3 CMS. * * For the full copyright and license information, please read the * LICENSE.txt file that was distributed with this source code. @@ -24,6 +24,7 @@ use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper; use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager; use TYPO3\CMS\Extbase\Property\PropertyMapper; use TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationBuilder; +use TYPO3\CMS\Extbase\Service\EnvironmentService; use TYPO3\CMS\Extbase\Service\ExtensionService; use TYPO3\CMS\Extbase\Utility\LocalizationUtility; @@ -148,6 +149,22 @@ class ActionController extends BaseController $this->extensionService = $extensionService; } + /** + * environmentService + * + * @var EnvironmentService + */ + protected $environmentService; + + /** + * @param + */ + public function injectEnvironmentService( + EnvironmentService $environmentService + ) { + $this->environmentService = $environmentService; + } + /** * propertyMapper * @@ -204,9 +221,11 @@ class ActionController extends BaseController */ public function initializeAction() { - $this->config = GeneralUtility::removeDotsFromTS( - $GLOBALS['TSFE']->config['config'] - ); + if ($GLOBALS['TSFE']->config['config']) { + $this->config = GeneralUtility::removeDotsFromTS( + $GLOBALS['TSFE']->config['config'] + ); + } $this->pageType = GeneralUtility::_GP('type'); if (!is_numeric($this->pageType)) { $this->pageType = 0; @@ -251,7 +270,7 @@ class ActionController extends BaseController } /** - * returns an instance of uribuilder + * */ public function persistAll() { @@ -396,31 +415,6 @@ class ActionController extends BaseController return false; } - /** - * shortcut to get translation - * - * @return void - */ - protected function getTranslation($key, $arguments = null) - { - $translation = LocalizationUtility::translate( - $key, - $this->getExtensionKey(), - $arguments - ); - if ($translation) { - return $translation; - } - $translation = LocalizationUtility::translate( - $key, - 'site_templates', - $arguments - ); - if ($translation) { - return $translation; - } - return null; - } /** * @@ -435,41 +429,6 @@ class ActionController extends BaseController strtolower($reflection->getShortName()); } - /** - * 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, $overwrite = false - ) { - $this->isValid = false; - $this->responseStatus = [400 => 'validationError']; - if (!array_key_exists($field, $this->errors) - || $overwrite == true - ) { - $this->errors[$field] = [ - 'keyword' => $keyword, - ]; - $this->errorLabels[$field] = $this->getErrorLabel( - $field, - $keyword - ); - } - } - - - /** * legacy function to prevent beaking old code * @@ -594,11 +553,14 @@ class ActionController extends BaseController ->setCreateAbsoluteUri(true) ->setAddQueryString(true) ->setTargetPageType($this->ajaxPageType) - ->setArguments(['cid' => $this->contentObjectUid]) + ->setArguments([ + 'cid' => $this->contentObjectUid, + 'type' => $this->ajaxPageType, + ]) ->uriFor($this->request->getControllerActionName()); $this->ajaxEnv = [ - 'uri' => $uri, - 'object' => $object, + 'uri' => $uri, + 'object' => $object, 'namespace' => $this->getPluginNamespace(), ]; } @@ -742,7 +704,11 @@ class ActionController extends BaseController $this->response->setStatus($this->responseStatus); } if ($this->pageType == $this->ajaxPageType) { - $GLOBALS['TSFE']->setContentType('application/json'); + if ($this->environmentService->isEnvironmentInBackendMode()) { + header('Content-Type: application/json'); + } else { + $GLOBALS['TSFE']->setContentType('application/json'); + } } unset($result['data']); if ($this->redirect) { @@ -767,5 +733,4 @@ class ActionController extends BaseController } $this->view->assignMultiple($result); } - } diff --git a/Classes/Traits/DependencyInjectionTrait.php b/Classes/Traits/DependencyInjectionTrait.php index a9ad822..d2ccc13 100644 --- a/Classes/Traits/DependencyInjectionTrait.php +++ b/Classes/Traits/DependencyInjectionTrait.php @@ -19,18 +19,12 @@ use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; use TYPO3\CMS\Extbase\Object\ObjectManager; use TYPO3\CMS\Extbase\Reflection\ClassSchema; use TYPO3\CMS\Extbase\Reflection\ReflectionService; -use TYPO3\CMS\Frontend\Utility\EidUtility; /** * ValidationTrait */ trait DependencyInjectionTrait { - /* - * extension Key - */ - protected $extensionKey = null; - /* * storagePids */ @@ -86,21 +80,19 @@ trait DependencyInjectionTrait $this->objectManager = GeneralUtility::makeInstance( ObjectManager::class ); - $this->initFrontendController(); $this->configurationManager = $this->objectManager->get( ConfigurationManagerInterface::class ); - $this->configurationManager->setConfiguration( - array() - ); $this->apiUtility = $this->objectManager->get( ApiUtility::class ); $frameworkConfiguration = $this->configurationManager->getConfiguration( ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK, - $this->getExtensionKey() + str_replace('_', '', $this->getExtensionKey()) + ); + $this->configurationManager->setConfiguration( + $frameworkConfiguration ); - $this->configurationManager->setConfiguration($frameworkConfiguration); $this->settings = $frameworkConfiguration; $this->storagePids = explode( ',', @@ -126,29 +118,4 @@ trait DependencyInjectionTrait } } - /** - * Initialize frontentController - * - * @return void - */ - private function initFrontendController() - { - $currentDomain = strtok(GeneralUtility::getIndpEnv('HTTP_HOST'), ':'); - $frontendController = GeneralUtility::makeInstance( - \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::class, - $GLOBALS['TYPO3_CONF_VARS'], - null, - 0, - true - ); - $GLOBALS['TSFE'] = $frontendController; - $frontendController->connectToDB(); - $frontendController->fe_user = EidUtility::initFeUser(); - $frontendController->id = $result[0]['pid']; - $frontendController->determineId(); - $frontendController->initTemplate(); - $frontendController->getConfigArray(); - EidUtility::initTCA(); - } - } diff --git a/Classes/Traits/FormatResultTrait.php b/Classes/Traits/FormatResultTrait.php new file mode 100644 index 0000000..c1bac0e --- /dev/null +++ b/Classes/Traits/FormatResultTrait.php @@ -0,0 +1,84 @@ + + * + ***/ + +/** + * ValidationTrait + */ +trait FormatResultTrait +{ + + /** + * + */ + public function formatResult($result) { + 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); + } + if ($this->pageType == $this->ajaxPageType) { + if ($this->environmentService->isEnvironmentInBackendMode()) { + header('Content-Type: application/json'); + } else { + $GLOBALS['TSFE']->setContentType('application/json'); + } + } + unset($result['data']); + if ($this->redirect) { + $result['redirect'] = $this->redirect; + } + if ($this->reload) { + $result['reload'] = true; + } + return json_encode($result); + } + $result = array_merge( + $result, + ['cid' => $this->contentObjectUid], + ['isValid' => $this->isValid], + ['componentMode' => $this->componentMode] + ); + if (!empty($this->ajaxEnv)) { + $result = array_merge( + $result, + ['ajaxEnv' => $this->ajaxEnv] + ); + } + return $result; + } +} diff --git a/Classes/Traits/PersistenceManagerTrait.php b/Classes/Traits/PersistenceManagerTrait.php new file mode 100644 index 0000000..0ad1e0c --- /dev/null +++ b/Classes/Traits/PersistenceManagerTrait.php @@ -0,0 +1,37 @@ + + * + ***/ + +use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Extbase\Object\ObjectManager; +use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper; +use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager; + +/** + * ValidationTrait + */ +trait PersistenceManagerTrait +{ + + /** + * + */ + public function persistAll() + { + (GeneralUtility::makeInstance( + ObjectManager::class + )->get( + PersistenceManager::class + ))->persistAll(); + } +} diff --git a/Classes/Traits/ValidationTrait.php b/Classes/Traits/ValidationTrait.php index c001e5f..6b4a75a 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 TYPO3\CMS\Extbase\Utility\LocalizationUtility; /** * ValidationTrait @@ -96,4 +97,64 @@ trait ValidationTrait return $validationResult; } + /** + * function to add validation error manually in the controller + */ + protected function addValidationError( + $field, $keyword, $overwrite = false + ) { + $this->isValid = false; + $this->responseStatus = [400 => 'validationError']; + if (!array_key_exists($field, $this->errors) + || $overwrite == true + ) { + $this->errors[$field] = [ + 'keyword' => $keyword, + ]; + $this->errorLabels[$field] = $this->getErrorLabel( + $field, + $keyword + ); + } + } + + /** + * 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; + } + + /** + * shortcut to get translation + * + * @return void + */ + protected function getTranslation($key, $arguments = null) + { + $translation = LocalizationUtility::translate( + $key, + $this->getExtensionKey(), + $arguments + ); + if ($translation) { + return $translation; + } + $translation = LocalizationUtility::translate( + $key, + 'site_templates', + $arguments + ); + if ($translation) { + return $translation; + } + return null; + } + + } diff --git a/Classes/Utility/ApiUtility.php b/Classes/Utility/ApiUtility.php index f36dd0e..5f75905 100644 --- a/Classes/Utility/ApiUtility.php +++ b/Classes/Utility/ApiUtility.php @@ -213,7 +213,13 @@ class ApiUtility return $result; } - private function filereferenceToApi($object) { + public function filereferenceToApi($object) { + $this->objectManager = GeneralUtility::makeInstance( + ObjectManager::class + ); + $this->imageService = $this->objectManager->get( + imageService::class + ); $httpHost = GeneralUtility::getIndpEnv('HTTP_HOST'); $requestHost = GeneralUtility::getIndpEnv('TYPO3_REQUEST_HOST'); $publicUrl = $object->getPublicUrl(); diff --git a/Classes/Utility/MailUtility.php b/Classes/Utility/MailUtility.php index 19129ce..db456d2 100644 --- a/Classes/Utility/MailUtility.php +++ b/Classes/Utility/MailUtility.php @@ -36,9 +36,10 @@ class MailUtility */ public static function parseContentTemplate( $text, - $markers = [] + $markers = [], + $lineEnd = "\r\n" ) { - $textParts = explode("\r\n\r\n", $text); + $textParts = explode($lineEnd . $lineEnd, $text); $result = []; foreach ($textParts as $textPart) { $type = 'text'; @@ -54,6 +55,22 @@ class MailUtility $type = 'headline3'; $textPart = substr($textPart, 4); } + if (substr($textPart, 0, 2) === '- ') { + $type = 'list'; + $textPart = substr($textPart, 2); + } + if (substr($textPart, 0, 2) === '| ') { + $type = 'table'; + $textPart = substr($textPart, 2); + } + if (substr($textPart, 0, 3) === '|| ') { + $type = 'tableLayout'; + $textPart = substr($textPart, 3); + } + if (substr($textPart, 0, 9) === '%subject ') { + $type = 'subject'; + $textPart = substr($textPart, 9); + } foreach ($markers as $markerName => $markerContent) { $textPart = str_replace( '###' . $markerName . '###', @@ -61,10 +78,40 @@ class MailUtility $textPart ); } - $result[] = [ - 'type' => $type, - 'data' => $textPart, - ]; + switch($type) { + case 'table': + case 'tableLayout': + if ( + $result[count($result) - 1]['type'] == $type + && count($result[count($result) - 1]['data']) == 1 + ) { + $result[count($result) - 1]['data'][] = $textPart; + } else { + $result[] = [ + 'type' => $type, + 'data' => [$textPart], + ]; + } + break; + case 'list': + if ( + $result[count($result) - 1]['type'] == 'list' + ) { + $result[count($result) - 1]['data'][] = $textPart; + } else { + $result[] = [ + 'type' => 'list', + 'data' => [$textPart], + ]; + } + break; + default: + $result[] = [ + 'type' => $type, + 'data' => $textPart, + ]; + break; + } } return $result; } @@ -107,12 +154,22 @@ class MailUtility $htmlView->setTemplate($templateNameHtml); $textView = $objectManager->get(StandaloneView::class); if ($templatePaths) { + $partialRootPaths = $htmlView->getPartialRootPaths(); + $partialRootPaths[] = GeneralUtility::getFileAbsFileName( + 'EXT:templates_aide/Resources/Private/Partials/' + ); $htmlView->setTemplateRootPaths( $templatePaths->getTemplateRootPaths() ); + $htmlView->setPartialRootPaths( + $partialRootPaths + ); $textView->setTemplateRootPaths( $templatePaths->getTemplateRootPaths() ); + $textView->setPartialRootPaths( + $partialRootPaths + ); } else { $htmlView->getTemplatePaths()->fillDefaultsByPackageName( 'templates_aide' @@ -130,6 +187,9 @@ class MailUtility foreach ($data as $row) { switch($row['type']) { case 'text': + case 'table': + case 'tableLayout': + case 'list': case 'textbold': case 'headline': case 'headline2': @@ -220,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); 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]; 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] diff --git a/Resources/Private/Partials/Mails/DefaultHtml.html b/Resources/Private/Partials/Mails/DefaultHtml.html index d30001a..464f7c9 100644 --- a/Resources/Private/Partials/Mails/DefaultHtml.html +++ b/Resources/Private/Partials/Mails/DefaultHtml.html @@ -1,23 +1,34 @@ + + + + + + + + + + + + + - - -
+
-
+
@@ -68,5 +79,136 @@ + + Data is array, can be table or list + + + + + + + + + + + + + + +
+
+ + + + + +
+ +
+ + + + +
+
+
{row.data.0 -> f:format.nl2br() -> f:format.raw()}
+
+
+
+ +
+ + + + +
+
+
{row.data.1 -> f:format.nl2br() -> f:format.raw()}
+
+
+
+ +
+
+ + + + +
+ + + + + + +
+ +
+ + + + + + +
+ + + + +
+
+
    + +
  • {dataRow -> f:format.nl2br() -> f:format.raw()}
  • +
    +
+
+
+
+
+ +
+
+ +
+ + diff --git a/Resources/Private/Partials/Mails/DefaultText.html b/Resources/Private/Partials/Mails/DefaultText.html new file mode 100644 index 0000000..ff9aa5b --- /dev/null +++ b/Resources/Private/Partials/Mails/DefaultText.html @@ -0,0 +1,50 @@ + + + + + + + + # {row.data -> f:format.nl2br() -> f:format.raw()} + + + + ## {row.data -> f:format.nl2br() -> f:format.raw()} + + + ### {row.data -> f:format.nl2br() -> f:format.raw()} + + + + {row.data -> f:format.raw()} + + {br}{br} + + + + + + + + {row.data.0 -> f:format.raw()}{br}{br}{row.data.1 -> f:format.raw()}{br} + + + {row.data.0 -> f:format.raw()}: {row.data.1 -> f:format.raw()} + + + - + {dataRow -> f:format.raw()} + + {br}{br} + + + + + + +{br}{br}{br}{br}