[MERGE] Branch 'master' of https://phabricator.glanzstueck.agency/source/typo3-template_aide
This commit is contained in:
commit
e08526325d
57
Classes/Utility/DatabaseUtility.php
Normal file
57
Classes/Utility/DatabaseUtility.php
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
namespace Cjel\TemplatesAide\Utility;
|
||||||
|
|
||||||
|
/***
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* (c) 2022 Philipp Dieter
|
||||||
|
*
|
||||||
|
***/
|
||||||
|
|
||||||
|
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||||
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||||
|
use TYPO3\CMS\Extbase\Object\ObjectManager;
|
||||||
|
use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Holds functions to help with database interactions
|
||||||
|
*/
|
||||||
|
class DatabaseUtility
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mysql date format
|
||||||
|
*/
|
||||||
|
const MYSQL_DATE_FORMAT = 'Y-m-d H:i:s';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns table name by model
|
||||||
|
*
|
||||||
|
* @param $model object model
|
||||||
|
* @return string table name
|
||||||
|
*/
|
||||||
|
public static function getTableNameFromModelClass($class)
|
||||||
|
{
|
||||||
|
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
|
||||||
|
$dataMapper = $objectManager->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;
|
||||||
|
}
|
||||||
|
}
|
@ -59,6 +59,18 @@ class MailUtility
|
|||||||
$type = 'list';
|
$type = 'list';
|
||||||
$textPart = substr($textPart, 2);
|
$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) === '| ') {
|
if (substr($textPart, 0, 2) === '| ') {
|
||||||
$type = 'table';
|
$type = 'table';
|
||||||
$textPart = substr($textPart, 2);
|
$textPart = substr($textPart, 2);
|
||||||
@ -116,6 +128,28 @@ class MailUtility
|
|||||||
return $result;
|
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
|
* tages maildata, builds html and text mails an decides where to send them
|
||||||
* allows to intercept sender for testing
|
* allows to intercept sender for testing
|
||||||
@ -195,6 +229,10 @@ class MailUtility
|
|||||||
case 'headline':
|
case 'headline':
|
||||||
case 'headline2':
|
case 'headline2':
|
||||||
case 'headline3':
|
case 'headline3':
|
||||||
|
case 'button':
|
||||||
|
case 'buttonleft':
|
||||||
|
case 'buttoncenter':
|
||||||
|
case 'buttonright':
|
||||||
$row['data'] = str_replace(
|
$row['data'] = str_replace(
|
||||||
"\\\n",
|
"\\\n",
|
||||||
'',
|
'',
|
||||||
@ -203,16 +241,33 @@ class MailUtility
|
|||||||
$htmlRow = $row;
|
$htmlRow = $row;
|
||||||
$htmlRow['data'] = preg_replace_callback(
|
$htmlRow['data'] = preg_replace_callback(
|
||||||
'/\[.*\]/mU',
|
'/\[.*\]/mU',
|
||||||
function($matches) {
|
function($matches) use ($row) {
|
||||||
foreach ($matches as $match) {
|
foreach ($matches as $match) {
|
||||||
return preg_replace_callback(
|
return preg_replace_callback(
|
||||||
'/\[(\S*)\s(.*)\]/mU',
|
'/\[(\S*)\s(.*)\]/mU',
|
||||||
function($matchesInner) {
|
function($matchesInner) use ($row) {
|
||||||
|
switch($row['type']) {
|
||||||
|
case 'button':
|
||||||
|
case 'buttonleft':
|
||||||
|
case 'buttoncenter':
|
||||||
|
case 'buttonright':
|
||||||
|
return '<a style="display: inline-block;" href="'
|
||||||
|
. $matchesInner[1]
|
||||||
|
. '">'
|
||||||
|
. '<span style="display: inline-block; padding: 10px 15px; border-radius: 3px; background-color: red;">'
|
||||||
|
. 'Button!!!! '
|
||||||
|
. $matchesInner[2]
|
||||||
|
. '</span>'
|
||||||
|
. '</a>';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
return '<a href="'
|
return '<a href="'
|
||||||
. $matchesInner[1]
|
. $matchesInner[1]
|
||||||
. '">'
|
. '">'
|
||||||
. $matchesInner[2]
|
. $matchesInner[2]
|
||||||
. '</a>';
|
. '</a>';
|
||||||
|
break;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
$match
|
$match
|
||||||
);
|
);
|
||||||
@ -257,51 +312,77 @@ class MailUtility
|
|||||||
$bodydataText[] = $textRow;
|
$bodydataText[] = $textRow;
|
||||||
$bodydataHtml[] = $htmlRow;
|
$bodydataHtml[] = $htmlRow;
|
||||||
break;
|
break;
|
||||||
case 'button':
|
//case 'button':
|
||||||
case 'buttons':
|
// $row['data'] = str_replace(
|
||||||
$htmlRow = $row;
|
// "\\\n",
|
||||||
//$htmlRow['targets'] = preg_replace_callback(
|
// '',
|
||||||
|
// $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 '<a href="'
|
||||||
|
// . $matchesInner[1]
|
||||||
|
// . '">'
|
||||||
|
// . $matchesInner[2]
|
||||||
|
// . '</a>';
|
||||||
|
// },
|
||||||
|
// $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 '<b>'
|
||||||
|
// . substr($match, 1, -1)
|
||||||
|
// . '</b>';
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
// $htmlRow['data']
|
||||||
|
// );
|
||||||
|
// $textRow = $row;
|
||||||
|
// $textRow['data'] = preg_replace_callback(
|
||||||
// '/\[.*\]/mU',
|
// '/\[.*\]/mU',
|
||||||
// function($matches) {
|
// function($matches) {
|
||||||
// foreach ($matches as $match) {
|
// foreach ($matches as $match) {
|
||||||
// return preg_replace_callback(
|
// return preg_replace_callback(
|
||||||
// '/\[(\S*)\s(.*)\]/mU',
|
// '/\[(\S*)\s(.*)\]/mU',
|
||||||
// function($matchesInner) {
|
// function($matchesInner) {
|
||||||
// return $matchesInner;
|
// if (
|
||||||
// //return '<a href="'
|
// $matchesInner[2] == $matchesInner[1]
|
||||||
// // . $matchesInner[1]
|
// ) {
|
||||||
// // . '">'
|
// return $matchesInner[1];
|
||||||
// // . $matchesInner[2]
|
// }
|
||||||
// // . '</a>';
|
// return $matchesInner[2]
|
||||||
|
// . ': '
|
||||||
|
// . $matchesInner[1];
|
||||||
// },
|
// },
|
||||||
// $match
|
// $match
|
||||||
// );
|
// );
|
||||||
// }
|
// }
|
||||||
// },
|
// },
|
||||||
// $htmlRow['targets']
|
// $textRow['data']
|
||||||
//);
|
|
||||||
$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
|
|
||||||
// );
|
// );
|
||||||
// }
|
// $bodydataText[] = $textRow;
|
||||||
// },
|
// $bodydataHtml[] = $htmlRow;
|
||||||
// $textRow['targets']
|
// break;
|
||||||
//);
|
|
||||||
$bodydataText[] = $textRow;
|
|
||||||
$bodydataHtml[] = $htmlRow;
|
|
||||||
break;
|
|
||||||
case 'attachment':
|
case 'attachment':
|
||||||
$mail->attach(new \Swift_Attachment(
|
$mail->attach(new \Swift_Attachment(
|
||||||
$row['data'][0],
|
$row['data'][0],
|
||||||
@ -325,6 +406,9 @@ class MailUtility
|
|||||||
}
|
}
|
||||||
$textView->assign('content', $bodydataText);
|
$textView->assign('content', $bodydataText);
|
||||||
$htmlView->assign('content', $bodydataHtml);
|
$htmlView->assign('content', $bodydataHtml);
|
||||||
|
//\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump(
|
||||||
|
// $bodydataHtml, null, 8, true, false
|
||||||
|
//);
|
||||||
$domain = $settings['mailDomain'];
|
$domain = $settings['mailDomain'];
|
||||||
if ($assetDomain) {
|
if ($assetDomain) {
|
||||||
$domain = $assetDomain;
|
$domain = $assetDomain;
|
||||||
|
@ -14,7 +14,13 @@
|
|||||||
<f:for each="{content}" as="row" key="rowKey" iteration="rowI" >
|
<f:for each="{content}" as="row" key="rowKey" iteration="rowI" >
|
||||||
<v:condition.type.isArray value="{row.data}">
|
<v:condition.type.isArray value="{row.data}">
|
||||||
<f:else>
|
<f:else>
|
||||||
<f:if condition="{v:condition.string.contains(haystack: '{row.type}', needle: 'headline', then: '1')} || {row.type} == 'text'">
|
<f:if condition="{v:condition.string.contains(haystack: '{row.type}', needle: 'headline', then: '1')}
|
||||||
|
|| {row.type} == 'text'
|
||||||
|
|| {row.type} == 'button'
|
||||||
|
|| {row.type} == 'buttonleft'
|
||||||
|
|| {row.type} == 'buttoncenter'
|
||||||
|
|| {row.type} == 'buttonright'
|
||||||
|
">
|
||||||
<!--[if mso | IE]>
|
<!--[if mso | IE]>
|
||||||
<table align="center" border="0" cellpadding="0" cellspacing="0" class="" style="width:{width}px;" width="{width}" >
|
<table align="center" border="0" cellpadding="0" cellspacing="0" class="" style="width:{width}px;" width="{width}" >
|
||||||
<tr>
|
<tr>
|
||||||
@ -37,8 +43,19 @@
|
|||||||
<td style="vertical-align:top;padding:0;">
|
<td style="vertical-align:top;padding:0;">
|
||||||
<table border="0" cellpadding="0" cellspacing="0" role="presentation" style width="100%">
|
<table border="0" cellpadding="0" cellspacing="0" role="presentation" style width="100%">
|
||||||
<tr>
|
<tr>
|
||||||
<td align="left" style="font-size:0px;padding:0;word-break:break-word;">
|
<f:switch expression="{row.type}">
|
||||||
<div style="font-family:Arial, sans-serif;font-size:16px;line-height:1.4;text-align:left;color:#000000;">
|
<f:case value="buttonright">
|
||||||
|
<f:variable name='align' value='right' />
|
||||||
|
</f:case>
|
||||||
|
<f:case value="buttoncenter">
|
||||||
|
<f:variable name='align' value='center' />
|
||||||
|
</f:case>
|
||||||
|
<f:defaultCase>
|
||||||
|
<f:variable name='align' value='left' />
|
||||||
|
</f:defaultCase>
|
||||||
|
</f:switch>
|
||||||
|
<td align="{align}" style="font-size:0px;padding:0;word-break:break-word;">
|
||||||
|
<div style="font-family:Arial, sans-serif;font-size:16px;line-height:1.4;text-align:{align};color:#000000;">
|
||||||
<f:switch expression="{row.type}">
|
<f:switch expression="{row.type}">
|
||||||
<f:case value="headline">
|
<f:case value="headline">
|
||||||
<h1>{row.data -> f:format.nl2br() -> f:format.raw()}</h1>
|
<h1>{row.data -> f:format.nl2br() -> f:format.raw()}</h1>
|
||||||
@ -49,6 +66,26 @@
|
|||||||
<f:case value="headline3">
|
<f:case value="headline3">
|
||||||
<h3>{row.data -> f:format.nl2br() -> f:format.raw()}</h3>
|
<h3>{row.data -> f:format.nl2br() -> f:format.raw()}</h3>
|
||||||
</f:case>
|
</f:case>
|
||||||
|
<f:case value="button">
|
||||||
|
<span style="display: inline-block;" class="buttonwrapper">
|
||||||
|
{row.data -> f:format.nl2br() -> f:format.raw()}
|
||||||
|
</span>
|
||||||
|
</f:case>
|
||||||
|
<f:case value="buttonleft">
|
||||||
|
<span style="display: inline-block;" class="buttonwrapper">
|
||||||
|
{row.data -> f:format.nl2br() -> f:format.raw()}
|
||||||
|
</span>
|
||||||
|
</f:case>
|
||||||
|
<f:case value="buttoncenter">
|
||||||
|
<span style="display: inline-block;" class="buttonwrapper">
|
||||||
|
{row.data -> f:format.nl2br() -> f:format.raw()}
|
||||||
|
</span>
|
||||||
|
</f:case>
|
||||||
|
<f:case value="buttonright">
|
||||||
|
<span style="display: inline-block;" class="buttonwrapper">
|
||||||
|
{row.data -> f:format.nl2br() -> f:format.raw()}
|
||||||
|
</span>
|
||||||
|
</f:case>
|
||||||
<f:defaultCase>
|
<f:defaultCase>
|
||||||
<p>{row.data -> f:format.nl2br() -> f:format.raw()}</p>
|
<p>{row.data -> f:format.nl2br() -> f:format.raw()}</p>
|
||||||
</f:defaultCase>
|
</f:defaultCase>
|
||||||
|
@ -40,7 +40,7 @@ call_user_func(
|
|||||||
'EXT:templates_aide/Resources/Public/Css/backend/production-stage';
|
'EXT:templates_aide/Resources/Public/Css/backend/production-stage';
|
||||||
}
|
}
|
||||||
|
|
||||||
$GLOBALS['TBE_STYLES']['skins']['backend']['stylesheetDirectories']['default'] =
|
$GLOBALS['TBE_STYLES']['skins']['backend']['stylesheetDirectories']['templates_aide_default'] =
|
||||||
'EXT:templates_aide/Resources/Public/Css/backend/default';
|
'EXT:templates_aide/Resources/Public/Css/backend/default';
|
||||||
|
|
||||||
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::registerPageTSConfigFile(
|
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::registerPageTSConfigFile(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user