diff --git a/Classes/Utility/ArrayUtility.php b/Classes/Utility/ArrayUtility.php index 26fd0da..0c0da26 100644 --- a/Classes/Utility/ArrayUtility.php +++ b/Classes/Utility/ArrayUtility.php @@ -45,7 +45,11 @@ class ArrayUtility $value = self::removeEmptyStrings($value); } else { if (is_string($value) && !strlen($value)) { - unset($array[$key]); + if (is_array($array)) { + unset($array[$key]); + } else { + unset($array->$key); + } } } } diff --git a/Classes/Utility/DatabaseUtility.php b/Classes/Utility/DatabaseUtility.php new file mode 100644 index 0000000..aa209d3 --- /dev/null +++ b/Classes/Utility/DatabaseUtility.php @@ -0,0 +1,57 @@ +get(DataMapper::class); + return $dataMapper->getDataMap($class)->getTableName(); + } + + /** + * Creates a new query builder and returns it + * + * @param $tablename string table name + * @return object queryBuilder + */ + public static function getQueryBuilderFromTableName($tableName) + { + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) + ->getConnectionForTable($tableName) + ->createQueryBuilder(); + return $queryBuilder; + } +} diff --git a/Classes/Utility/MailUtility.php b/Classes/Utility/MailUtility.php index 2e6d41d..d90a5d1 100644 --- a/Classes/Utility/MailUtility.php +++ b/Classes/Utility/MailUtility.php @@ -59,6 +59,18 @@ class MailUtility $type = 'list'; $textPart = substr($textPart, 2); } + if (substr($textPart, 0, 3) === '+< ') { + $type = 'buttonleft'; + $textPart = substr($textPart, 3); + } + if (substr($textPart, 0, 3) === '+| ') { + $type = 'buttoncenter'; + $textPart = substr($textPart, 3); + } + if (substr($textPart, 0, 3) === '+> ') { + $type = 'buttonright'; + $textPart = substr($textPart, 3); + } if (substr($textPart, 0, 2) === '| ') { $type = 'table'; $textPart = substr($textPart, 2); @@ -116,6 +128,28 @@ class MailUtility return $result; } + /** + * Gets row from content by given type + * + * @param array $content the mail content + * @param string $type the type to search + */ + public static function extractByType($content, $type) + { + $elementPosition = array_search( + $type, + array_column($content, 'type') + ); + if (!$elementPosition === false) { + return; + } + if (!array_key_exists('data', $content[$elementPosition])) { + return; + } + return $content[$elementPosition]['data']; + } + + /** * tages maildata, builds html and text mails an decides where to send them * allows to intercept sender for testing @@ -195,6 +229,10 @@ class MailUtility case 'headline': case 'headline2': case 'headline3': + case 'button': + case 'buttonleft': + case 'buttoncenter': + case 'buttonright': $row['data'] = str_replace( "\\\n", '', @@ -203,16 +241,33 @@ class MailUtility $htmlRow = $row; $htmlRow['data'] = preg_replace_callback( '/\[.*\]/mU', - function($matches) { + function($matches) use ($row) { foreach ($matches as $match) { return preg_replace_callback( '/\[(\S*)\s(.*)\]/mU', - function($matchesInner) { - return '' - . $matchesInner[2] - . ''; + function($matchesInner) use ($row) { + switch($row['type']) { + case 'button': + case 'buttonleft': + case 'buttoncenter': + case 'buttonright': + return '' + . '' + . 'Button!!!! ' + . $matchesInner[2] + . '' + . ''; + break; + default: + return '' + . $matchesInner[2] + . ''; + break; + } }, $match ); @@ -257,51 +312,77 @@ class MailUtility $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 'button': + // $row['data'] = str_replace( + // "\\\n", + // '', + // $row['data'] + // ); + // $htmlRow = $row; + // $htmlRow['data'] = preg_replace_callback( + // '/\[.*\]/mU', + // function($matches) { + // foreach ($matches as $match) { + // $test = preg_replace_callback( + // '/\[(\S*)\s(.*)\]/mU', + // function($matchesInner) { + // + // return '' + // . $matchesInner[2] + // . ''; + // }, + // $match + // ); + // \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump( + // $test, null, 3, true, false + // ); + // return $test; + // } + // }, + // $htmlRow['data'] + // ); + // \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump( + // $htmlRow['data'], null, 3, true, false + // ); + // $htmlRow['data'] = preg_replace_callback( + // '/\*.*\*/mU', + // function($matches) { + // foreach ($matches as $match) { + // return '' + // . substr($match, 1, -1) + // . ''; + // } + // }, + // $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) { + // if ( + // $matchesInner[2] == $matchesInner[1] + // ) { + // return $matchesInner[1]; + // } + // return $matchesInner[2] + // . ': ' + // . $matchesInner[1]; + // }, + // $match + // ); + // } + // }, + // $textRow['data'] + // ); + // $bodydataText[] = $textRow; + // $bodydataHtml[] = $htmlRow; + // break; case 'attachment': $mail->attach(new \Swift_Attachment( $row['data'][0], @@ -325,6 +406,9 @@ class MailUtility } $textView->assign('content', $bodydataText); $htmlView->assign('content', $bodydataHtml); + //\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump( + // $bodydataHtml, null, 8, true, false + //); $domain = $settings['mailDomain']; if ($assetDomain) { $domain = $assetDomain; diff --git a/Classes/Utility/SiteConfigUtility.php b/Classes/Utility/SiteConfigUtility.php index ab88031..76feb6d 100644 --- a/Classes/Utility/SiteConfigUtility.php +++ b/Classes/Utility/SiteConfigUtility.php @@ -15,6 +15,7 @@ namespace Cjel\TemplatesAide\Utility; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; use TYPO3\CMS\Extbase\Object\ObjectManager; +use TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser; /** * Utility to work with site config @@ -35,20 +36,33 @@ class SiteConfigUtility $objectManager = GeneralUtility::makeInstance( ObjectManager::class ); + $typoScriptParser = GeneralUtility::makeInstance( + TypoScriptParser::class + ); $configurationManager = $objectManager->get( ConfigurationManagerInterface::class ); $typoscript = $configurationManager->getConfiguration( ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT ); - $typoscript = GeneralUtility::removeDotsFromTS($typoscript); $siteConfig = $typoscript; if ($limitToSiteConfig) { - $siteConfig = $typoscript['config']['site']; + $siteConfig = $typoscript['config.']['site.']; } $current = &$siteConfig; foreach ($pathParts as $key) { + if ($current[$key . '.']) { + $key .= '.'; + } $current = &$current[$key]; + if (isset($current[0]) && $current[0] === '<') { + $searchkey = trim(substr($current, 1)); + list($name, $conf) = $typoScriptParser->getVal( + $searchkey, + $typoscript + ); + $current = $conf; + } } if (is_array($current) && array_key_exists('value', $current) diff --git a/Classes/ViewHelpers/SiteConfigViewHelper.php b/Classes/ViewHelpers/SiteConfigViewHelper.php new file mode 100644 index 0000000..1d83ad1 --- /dev/null +++ b/Classes/ViewHelpers/SiteConfigViewHelper.php @@ -0,0 +1,64 @@ + + * + ***/ + +use Cjel\TemplatesAide\Utility\SiteConfigUtility; +use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; +use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; +use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic; + +class SiteConfigViewHelper extends AbstractViewHelper +{ + use CompileWithRenderStatic; + + /** + * Initialize arguements + * + * @return void + */ + public function initializeArguments() + { + $this->registerArgument( + 'key', + 'string', + 'The config key to get', + true + ); + $this->registerArgument( + 'siteConfig', + 'bool', + 'Limit the typoscript to the config.site part', + false, + true + ); + } + + /** + * Render tranlation + * + * @param $arguments array arguments + * @param $renderChildrenClosure Closure + * @param $renderingContext $renderChildrenClosure + * @return string + */ + public static function renderStatic( + array $arguments, + \Closure $renderChildrenClosure, + RenderingContextInterface $renderingContext + ) { + return SiteConfigUtility::getByPath( + $arguments['key'], + $arguments['siteConfig'] + ); + } +} diff --git a/Classes/ViewHelpers/TranslationViewHelper.php b/Classes/ViewHelpers/TranslationViewHelper.php new file mode 100644 index 0000000..6ec2b9b --- /dev/null +++ b/Classes/ViewHelpers/TranslationViewHelper.php @@ -0,0 +1,53 @@ + + * + ***/ + +use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; +use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; +use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic; + +class TranslationViewHelper extends AbstractViewHelper +{ + use CompileWithRenderStatic; + + /** + * Initialize arguements + * + * @return void + */ + public function initializeArguments() + { + $this->registerArgument( + 'key', + 'string', + 'The translation key to render', + true + ); + } + + /** + * Render tranlation + * + * @param $arguments array arguments + * @param $renderChildrenClosure Closure + * @param $renderingContext $renderChildrenClosure + * @return string + */ + public static function renderStatic( + array $arguments, + \Closure $renderChildrenClosure, + RenderingContextInterface $renderingContext + ) { + return 'this.extension.translation'; + } +} diff --git a/Configuration/TCA/Overrides/be_users.php b/Configuration/TCA/Overrides/be_users.php new file mode 100644 index 0000000..102ba9f --- /dev/null +++ b/Configuration/TCA/Overrides/be_users.php @@ -0,0 +1,4 @@ + - +
LFEditor
@@ -9,6 +9,10 @@ + + + + diff --git a/Resources/Private/Language/locallang.xlf b/Resources/Private/Language/locallang.xlf index bb353e3..a2b7adb 100644 --- a/Resources/Private/Language/locallang.xlf +++ b/Resources/Private/Language/locallang.xlf @@ -1,6 +1,6 @@ - +
LFEditor
@@ -8,6 +8,9 @@ + + + diff --git a/Resources/Private/Partials/Mails/DefaultHtml.html b/Resources/Private/Partials/Mails/DefaultHtml.html index 3d1956c..cee579e 100644 --- a/Resources/Private/Partials/Mails/DefaultHtml.html +++ b/Resources/Private/Partials/Mails/DefaultHtml.html @@ -14,7 +14,13 @@ - +