From 74cdebbf8cb001db402f5be4ab114e77dae2becd Mon Sep 17 00:00:00 2001 From: Ivan Kartolo Date: Tue, 17 Aug 2021 11:40:53 +0200 Subject: [PATCH 001/342] [TASK] release v7.0.1 --- ext_emconf.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext_emconf.php b/ext_emconf.php index 39ddf7ae8..f830e8749 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -14,7 +14,7 @@ 'title' => 'Direct Mail', 'description' => 'Advanced Direct Mail/Newsletter mailer system with sophisticated options for personalization of emails including response statistics.', 'category' => 'module', - 'version' => '7.1.0-dev', + 'version' => '7.0.1', 'state' => 'stable', 'clearcacheonload' => 0, 'lockType' => '', From 3c2187407bb8365ca61ba324e112e174969260b6 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sat, 30 Oct 2021 17:50:47 +0000 Subject: [PATCH 002/342] remove jumpurl and rdct from composer.json --- composer.json | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index d4565fb37..5eee0479f 100644 --- a/composer.json +++ b/composer.json @@ -22,10 +22,8 @@ "issues": "https://github.com/kartolo/direct_mail/issues" }, "require": { - "typo3/cms-core": "^10.4", - "friendsoftypo3/jumpurl": "^8.0", - "friendsoftypo3/tt-address": "^4.3 || ^5.0", - "friendsoftypo3/rdct": "^2.0" + "typo3/cms-core": "^11.5", + "friendsoftypo3/tt-address": "dev-master" }, "require-dev": { "roave/security-advisories": "dev-master" From 58f80528eeaca633783a2f4e70c9ce2781a7a784 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sat, 30 Oct 2021 18:01:36 +0000 Subject: [PATCH 003/342] replace in ext_localconf.php --- ext_localconf.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext_localconf.php b/ext_localconf.php index 019f0f766..e9a7c8ece 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -74,7 +74,7 @@ /** * Use implicit port in URL for fetching Newsletter-Content: Even if your TYPO3 Backend is on a non-standard-port, the URL for fetching the newsletter contents from one of your Frontend-Domains will not use the PORT you are using to access your TYPO3 Backend, but use implicit port instead (e.g. no explicit port in URL) */ -$TYPO3_CONF_VARS['EXTCONF'][$_EXTKEY]['UseImplicitPortToFetch'] = $extConf['UseImplicitPortToFetch']; +$TYPO3_CONF_VARS['EXTCONF']['direct_mail']['UseImplicitPortToFetch'] = $extConf['UseImplicitPortToFetch']; /** * Registering class to scheduler From a94c9d8cdd205299f18dc8aecf8c1ecd7f960ca7 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sat, 30 Oct 2021 20:58:02 +0000 Subject: [PATCH 004/342] add .editorconfig --- .editorconfig | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..410d80ba1 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,56 @@ +# EditorConfig is awesome: http://EditorConfig.org + +# top-most EditorConfig file +root = true + +# Unix-style newlines with a newline ending every file +[*] +charset = utf-8 +end_of_line = lf +indent_style = space +indent_size = 4 +insert_final_newline = true +trim_trailing_whitespace = true + +# TS/JS-Files +[*.{ts,js}] +indent_size = 2 + +# JSON-Files +[*.json] +indent_style = tab + +# ReST-Files +[*.rst] +indent_size = 4 +max_line_length = 80 + +# YAML-Files +[*.{yaml,yml}] +indent_size = 2 + +# NEON-Files +[*.neon] +indent_size = 2 +indent_style = tab + +# package.json +[package.json] +indent_size = 2 + +# TypoScript +[*.{typoscript,tsconfig}] +indent_size = 2 + +# XLF-Files +[*.xlf] +indent_style = tab + +# SQL-Files +[*.sql] +indent_style = tab +indent_size = 2 + +# .htaccess +[{_.htaccess,.htaccess}] +indent_style = tab From 8b05a91f2336e2faee796708db688c3bad37bc9d Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sat, 30 Oct 2021 21:21:08 +0000 Subject: [PATCH 005/342] update tca field sys_language_uid --- Configuration/TCA/sys_dmail.php | 10 +--------- Configuration/TCA/sys_dmail_category.php | 9 +-------- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/Configuration/TCA/sys_dmail.php b/Configuration/TCA/sys_dmail.php index a5e8e6dc5..9fd2ea423 100644 --- a/Configuration/TCA/sys_dmail.php +++ b/Configuration/TCA/sys_dmail.php @@ -18,15 +18,7 @@ 'exclude' => 1, 'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.language', 'config' => [ - 'default' => 0, - 'type' => 'select', - 'renderType' => 'selectSingle', - 'foreign_table' => 'sys_language', - 'foreign_table_where' => 'ORDER BY sys_language.title', - 'items' => [ - ['LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.allLanguages', -1], - ['LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.default_value', 0] - ], + 'type' => 'language' ], ], 'subject' => [ diff --git a/Configuration/TCA/sys_dmail_category.php b/Configuration/TCA/sys_dmail_category.php index 0aefadd36..1d091212c 100644 --- a/Configuration/TCA/sys_dmail_category.php +++ b/Configuration/TCA/sys_dmail_category.php @@ -21,14 +21,7 @@ 'sys_language_uid' => [ 'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.language', 'config' => [ - 'type' => 'select', - 'renderType' => 'selectSingle', - 'foreign_table' => 'sys_language', - 'foreign_table_where' => 'ORDER BY sys_language.title', - 'items' => [ - ['LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.allLanguages', -1], - ['LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.default_value', 0] - ] + 'type' => 'language' ] ], 'l18n_parent' => [ From 751673a123a085b1db0ec6490772f8e10c09551c Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sun, 31 Oct 2021 13:56:05 +0000 Subject: [PATCH 006/342] test with moduleTemplate --- Classes/Module/NavFrameController.php | 209 ++++++++++++++++++++++ Resources/Private/Layouts/Default.html | 7 + Resources/Private/Templates/NavFrame.html | 52 +++--- ext_localconf.php | 4 +- ext_tables.php | 2 +- 5 files changed, 241 insertions(+), 33 deletions(-) create mode 100644 Classes/Module/NavFrameController.php create mode 100644 Resources/Private/Layouts/Default.html diff --git a/Classes/Module/NavFrameController.php b/Classes/Module/NavFrameController.php new file mode 100644 index 000000000..077112c70 --- /dev/null +++ b/Classes/Module/NavFrameController.php @@ -0,0 +1,209 @@ +moduleTemplate = $moduleTemplate ?? GeneralUtility::makeInstance(ModuleTemplate::class); + } + + public function indexAction(ServerRequestInterface $request) : ResponseInterface + { + $currentModule = (string)($request->getQueryParams()['currentModule'] ?? $request->getParsedBody()['currentModule'] ?? 'DirectMailNavFrame_Configuration###'); + /** @var UriBuilder $uriBuilder */ + $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); + $currentSubScript = $uriBuilder->buildUriFromRoute($currentModule); + + // Setting highlight mode: + $disableTitleHighlight = $GLOBALS['BE_USER']->getTSConfig()['options.']['pageTree.']['disableTitleHighlight'] ?? false; + $this->doHighlight = (bool)($disableTitleHighlight) ? false : true; + + /** + * Configure template paths for your backend module + */ + $this->view = GeneralUtility::makeInstance(StandaloneView::class); + $this->view->setTemplateRootPaths(['EXT:direct_mail/Resources/Private/Templates/']); + $this->view->setPartialRootPaths(['EXT:direct_mail/Resources/Private/Partials/']); + $this->view->setLayoutRootPaths(['EXT:direct_mail/Resources/Private/Layouts/']); + $this->view->setTemplate('NavFrame'); + + $rows = $this->getPages(); + $pages = []; + while (($row = $rows->fetchAssociative()) !== false) { + if (BackendUtility::readPageAccess($row['uid'], $GLOBALS['BE_USER']->getPagePermsClause(1))) { + $icon = $this->moduleTemplate->getIconFactory()->getIconForRecord('pages', $row, Icon::SIZE_SMALL)->render(); + $pages[] = ['icon' => $icon, 'page' => $row]; + } + } + unset($rows); + + $this->setDocHeader('index'); + + $this->moduleTemplate->addJavaScriptCode($this->getJS($currentModule, $currentSubScript)); + + $this->view->assignMultiple( + [ + 'pages' => $pages, + ] + ); + + /** + * Render template and return html content + */ + $this->moduleTemplate->setContent($this->view->render()); + return new HtmlResponse($this->moduleTemplate->renderContent()); + } + + protected function getJS($currentModule, $currentSubScript) { + //@TODO Uncaught Error: Writing to fsMod is not possible anymore, use ModuleStateStorage instead. + //https://docs.typo3.org/c/typo3/cms-core/master/en-us/Changelog/11.4/Deprecation-94762-DeprecateJavaScriptTopfsModState.html + return GeneralUtility::wrapJS( + ($currentModule ? 'top.currentSubScript=unescape("' . rawurlencode($currentSubScript) . '");' : '') . ' + + function jumpTo(params,linkObj,highLightID) { + var theUrl = top.currentSubScript+"&"+params; + + if (top.condensedMode) { + top.content.document.location=theUrl; + } else { + parent.list_frame.document.location=theUrl; + } + ' . ($this->doHighlight ? 'hilight_row("row"+top.fsMod.recentIds["DirectMailNavFrame"],highLightID);' : '') . ' + ' . ((!isset($GLOBALS['CLIENT']['FORMSTYLE']) || !$GLOBALS['CLIENT']['FORMSTYLE']) ? '' : 'if (linkObj) {linkObj.blur();}') . ' + return false; + } + + // Call this function, refresh_nav(), from another script in the backend if you want to refresh the navigation frame (eg. after having changed a page title or moved pages etc.) + // See t3lib_BEfunc::getSetUpdateSignal() + function refresh_nav() { // + window.setTimeout("_refresh_nav();",0); + } + + function _refresh_nav() { // + document.location="' . htmlspecialchars(GeneralUtility::getIndpEnv('SCRIPT_NAME') . '?unique=' . time()) . '"; + } + + // Highlighting rows in the page tree: + function hilight_row(frameSetModule,highLightID) { + // Remove old: + theObj = document.getElementById(top.fsMod.navFrameHighlightedID[frameSetModule]); + if (theObj) { + theObj.style.backgroundColor=""; + } + + // Set new: + top.fsMod.navFrameHighlightedID[frameSetModule] = highLightID; + theObj = document.getElementById(highLightID); + } + ' + ); + } + + protected function getPages() { + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages'); + $queryBuilder + ->getRestrictions() + ->removeAll() + ->add(GeneralUtility::makeInstance(DeletedRestriction::class)); + + $statement = $queryBuilder + ->select('uid', 'title') + ->from('pages') + ->where( + $queryBuilder->expr()->eq( + 'doktype', + '254' + ) + ) + ->andWhere( + $queryBuilder->expr()->in( + 'module', + $queryBuilder->createNamedParameter( + ['dmail'], + Connection::PARAM_STR_ARRAY + ) + ) + ) + ->andWhere( + $queryBuilder->expr()->eq( + 'sys_language_uid', + '0' + ) + ) + ->orderBy('title') +// debug($statement->getSQL()); +// debug($statement->getParameters()); + ->execute(); + + return $statement; + } + + private function setDocHeader(string $active) { + /** + $docHeaderButtons = [ + 'CSH' => BackendUtility::cshItem('_MOD_DirectMailNavFrame', 'folders', $GLOBALS['BACK_PATH'], true), + 'REFRESH' => '' + ]; + */ + $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar(); + $list = $buttonBar->makeLinkButton() + ->setHref('') //@TODO + ->setTitle('refresh') + ->setShowLabelText('Link') + ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-refresh', Icon::SIZE_SMALL)); + $buttonBar->addButton($list, ButtonBar::BUTTON_POSITION_RIGHT, 1); + } +} diff --git a/Resources/Private/Layouts/Default.html b/Resources/Private/Layouts/Default.html new file mode 100644 index 000000000..4d62b0d59 --- /dev/null +++ b/Resources/Private/Layouts/Default.html @@ -0,0 +1,7 @@ + + + \ No newline at end of file diff --git a/Resources/Private/Templates/NavFrame.html b/Resources/Private/Templates/NavFrame.html index 83f9d69d9..0104df704 100644 --- a/Resources/Private/Templates/NavFrame.html +++ b/Resources/Private/Templates/NavFrame.html @@ -1,33 +1,23 @@ - -
- -
-
-
###HEADLINE###
-
-
-
###BUTTONLIST_LEFT###
-
###BUTTONLIST_RIGHT###
-
+ -
- -
- ###CONTENT### -
+ +
+
- - - - - - - - - - - - - -###REFRESH######CSH### - \ No newline at end of file +
diff --git a/ext_localconf.php b/ext_localconf.php index e9a7c8ece..4a4e3d03a 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -72,7 +72,9 @@ $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['direct_mail']['UseHttpToFetch'] = $extConf['UseHttpToFetch']; /** - * Use implicit port in URL for fetching Newsletter-Content: Even if your TYPO3 Backend is on a non-standard-port, the URL for fetching the newsletter contents from one of your Frontend-Domains will not use the PORT you are using to access your TYPO3 Backend, but use implicit port instead (e.g. no explicit port in URL) + * Use implicit port in URL for fetching Newsletter-Content: Even if your TYPO3 Backend is on a non-standard-port, + * the URL for fetching the newsletter contents from one of your Frontend-Domains will not use the PORT you are using to access your TYPO3 Backend, + * but use implicit port instead (e.g. no explicit port in URL) */ $TYPO3_CONF_VARS['EXTCONF']['direct_mail']['UseImplicitPortToFetch'] = $extConf['UseImplicitPortToFetch']; diff --git a/ext_tables.php b/ext_tables.php index 3bfd1cb3b..c92f9802a 100755 --- a/ext_tables.php +++ b/ext_tables.php @@ -33,7 +33,7 @@ '', '', [ - 'routeTarget' => DirectMailTeam\DirectMail\Module\NavFrame::class . '::mainAction', + 'routeTarget' => DirectMailTeam\DirectMail\Module\NavFrameController::class . '::indexAction', 'access' => 'group,user', 'name' => 'DirectMailNavFrame', 'icon' => 'EXT:direct_mail/Resources/Public/Images/module-directmail.svg', From bfd0fb26ab271e5b0660234ccd9d0960f35b3a85 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sun, 31 Oct 2021 16:46:30 +0000 Subject: [PATCH 007/342] update ext_emconf.php --- ext_emconf.php | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/ext_emconf.php b/ext_emconf.php index f830e8749..5468ac54c 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -1,15 +1,5 @@ 'Direct Mail', 'description' => 'Advanced Direct Mail/Newsletter mailer system with sophisticated options for personalization of emails including response statistics.', @@ -25,7 +15,7 @@ 'depends' => [ 'tt_address' => '4.0.0-', 'php' => '7.2.0', - 'typo3' => '10.4.0-10.4.99', + 'typo3' => '11.5.0-11.9.99', 'jumpurl' => '8.0.0-', 'rdct' => '2.0.0' ], From 6086c5083b453dcfc4c59498e8ea166534864bb2 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sun, 31 Oct 2021 16:59:41 +0000 Subject: [PATCH 008/342] remove comment from sql --- ext_tables.sql | 8 -------- 1 file changed, 8 deletions(-) diff --git a/ext_tables.sql b/ext_tables.sql index 0b40b7bb2..bf9609847 100755 --- a/ext_tables.sql +++ b/ext_tables.sql @@ -1,10 +1,3 @@ -## -## @package TYPO3 -## @subpackage tx_directmail -## @version $Id$ -## - - # # Table structure for table 'cache_sys_dmail_stat' # @@ -240,4 +233,3 @@ CREATE TABLE tt_address ( CREATE TABLE tt_content ( module_sys_dmail_category int(10) unsigned DEFAULT '0' NOT NULL, ); - From 4b7547a234d286171155e80a5d8d0e5c79ec9662 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sun, 31 Oct 2021 17:33:44 +0000 Subject: [PATCH 009/342] test with module configuration --- .../Hooks/TypoScriptFrontendController.php | 4 +- Classes/Module/Configuration.php | 20 +++-- Classes/Module/ConfigurationController.php | 73 +++++++++++++++++++ Classes/Module/NavFrameController.php | 2 +- Classes/Plugin/DirectMail.php | 2 +- .../Private/Templates/Configuration.html | 7 ++ ext_tables.php | 2 +- 7 files changed, 94 insertions(+), 16 deletions(-) create mode 100644 Classes/Module/ConfigurationController.php create mode 100644 Resources/Private/Templates/Configuration.html diff --git a/Classes/Hooks/TypoScriptFrontendController.php b/Classes/Hooks/TypoScriptFrontendController.php index 563fe2318..0fa09c8f0 100644 --- a/Classes/Hooks/TypoScriptFrontendController.php +++ b/Classes/Hooks/TypoScriptFrontendController.php @@ -44,9 +44,9 @@ public function simulateUsergroup($parameters, \TYPO3\CMS\Frontend\Controller\Ty if ($typoScriptFrontendController->fe_user->user) { $typoScriptFrontendController->fe_user->user[$typoScriptFrontendController->usergroup_column] = $directMailFeGroup; } else { - $typoScriptFrontendController->fe_user->user = array( + $typoScriptFrontendController->fe_user->user = [ $typoScriptFrontendController->fe_user->usergroup_column => $directMailFeGroup - ); + ]; } } } diff --git a/Classes/Module/Configuration.php b/Classes/Module/Configuration.php index f17917299..a8850b909 100644 --- a/Classes/Module/Configuration.php +++ b/Classes/Module/Configuration.php @@ -41,7 +41,7 @@ class Configuration extends BaseScriptClass { public $TSconfPrefix = 'mod.web_modules.dmail.'; // Internal - public $params = array(); + public $params = []; public $perms_clause = ''; public $pageinfo = ''; public $sys_dmail_uid; @@ -49,11 +49,11 @@ class Configuration extends BaseScriptClass public $pages_uid; public $categories; public $id; - public $implodedParams = array(); + public $implodedParams = []; // If set a valid user table is around public $userTable; public $sys_language_uid = 0; - public $allowedTables = array('tt_address','fe_users'); + public $allowedTables = ['tt_address','fe_users']; public $MCONF; public $cshTable; public $formname = 'dmailform'; @@ -223,18 +223,17 @@ function toggleDisplay(toggleId, e, countBox) { // '; - - $markers = array( + $markers = [ 'FLASHMESSAGES' => '', 'CONTENT' => '', - ); + ]; - $docHeaderButtons = array( + $docHeaderButtons = [ 'PAGEPATH' => $this->getLanguageService()->getLL('labels.path') . ': ' . GeneralUtility::fixed_lgd_cs($this->pageinfo['_thePath'], 50), 'SHORTCUT' => '', 'CSH' => BackendUtility::cshItem($this->cshTable, '', $GLOBALS['BACK_PATH']) - ); + ]; // shortcut icon if ($GLOBALS['BE_USER']->mayMakeShortcut()) { $docHeaderButtons['SHORTCUT'] = $this->doc->makeShortcutIcon('id', implode(',', array_keys($this->MOD_MENU)), $this->MCONF['name']); @@ -276,7 +275,6 @@ function toggleDisplay(toggleId, e, countBox) { // ]); } - $this->content = $this->doc->startPage($this->getLanguageService()->getLL('title')); $this->content.= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers, array()); } else { @@ -387,7 +385,7 @@ protected function moduleContent() * * @return string The compiled input form */ - public function makeConfigForm(array $configArray, array$params, $dataPrefix) + public function makeConfigForm(array $configArray, array $params, $dataPrefix) { $boxFlag = 0; @@ -396,7 +394,7 @@ public function makeConfigForm(array $configArray, array$params, $dataPrefix) ' '; $wrapHelp2 = ''; - $lines = array(); + $lines = []; if (is_array($configArray)) { foreach ($configArray as $fname => $config) { if (is_array($config)) { diff --git a/Classes/Module/ConfigurationController.php b/Classes/Module/ConfigurationController.php new file mode 100644 index 000000000..b3dfa9afd --- /dev/null +++ b/Classes/Module/ConfigurationController.php @@ -0,0 +1,73 @@ +moduleTemplate = $moduleTemplate ?? GeneralUtility::makeInstance(ModuleTemplate::class); + } + + public function indexAction(ServerRequestInterface $request) : ResponseInterface + { + /** + * Configure template paths for your backend module + */ + $this->view = GeneralUtility::makeInstance(StandaloneView::class); + $this->view->setTemplateRootPaths(['EXT:direct_mail/Resources/Private/Templates/']); + $this->view->setPartialRootPaths(['EXT:direct_mail/Resources/Private/Partials/']); + $this->view->setLayoutRootPaths(['EXT:direct_mail/Resources/Private/Layouts/']); + $this->view->setTemplate('Configuration'); + +// $this->view->assignMultiple( +// [ +// 'some-variable' => 'some-value', +// ] +// ); + + /** + * Render template and return html content + */ + $this->moduleTemplate->setContent($this->view->render()); + return new HtmlResponse($this->moduleTemplate->renderContent()); + } +} diff --git a/Classes/Module/NavFrameController.php b/Classes/Module/NavFrameController.php index 077112c70..75c4989ac 100644 --- a/Classes/Module/NavFrameController.php +++ b/Classes/Module/NavFrameController.php @@ -62,7 +62,7 @@ public function __construct(ModuleTemplate $moduleTemplate = null) public function indexAction(ServerRequestInterface $request) : ResponseInterface { - $currentModule = (string)($request->getQueryParams()['currentModule'] ?? $request->getParsedBody()['currentModule'] ?? 'DirectMailNavFrame_Configuration###'); + $currentModule = (string)($request->getQueryParams()['currentModule'] ?? $request->getParsedBody()['currentModule'] ?? 'DirectMailNavFrame_Configuration'); /** @var UriBuilder $uriBuilder */ $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); $currentSubScript = $uriBuilder->buildUriFromRoute($currentModule); diff --git a/Classes/Plugin/DirectMail.php b/Classes/Plugin/DirectMail.php index b40f16ac1..4d07e4f88 100644 --- a/Classes/Plugin/DirectMail.php +++ b/Classes/Plugin/DirectMail.php @@ -66,7 +66,7 @@ class DirectMail extends AbstractPlugin * @var MarkerBasedTemplateService */ protected $templateService; - public $conf = array(); + public $conf = []; public $prefixId = 'tx_directmail_pi1'; public $scriptRelPath = 'pi1/class.tx_directmail_pi1.php'; public $extKey = 'direct_mail'; diff --git a/Resources/Private/Templates/Configuration.html b/Resources/Private/Templates/Configuration.html new file mode 100644 index 000000000..cc4d6d2aa --- /dev/null +++ b/Resources/Private/Templates/Configuration.html @@ -0,0 +1,7 @@ + + + +

+
+
+
\ No newline at end of file diff --git a/ext_tables.php b/ext_tables.php index c92f9802a..3470cc3f2 100755 --- a/ext_tables.php +++ b/ext_tables.php @@ -125,7 +125,7 @@ 'bottom', '', [ - 'routeTarget' => DirectMailTeam\DirectMail\Module\Configuration::class . '::mainAction', + 'routeTarget' => DirectMailTeam\DirectMail\Module\ConfigurationController::class . '::indexAction', 'access' => 'group,user', 'name' => 'DirectMailNavFrame_Configuration', 'workspaces' => 'online', From 40690ecbc0f569f4a98caab12371228124793be8 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sun, 31 Oct 2021 19:06:35 +0000 Subject: [PATCH 010/342] add modul ConfigurationController --- Classes/Module/Configuration.php | 6 +- Classes/Module/ConfigurationController.php | 266 +++++++++++++++++- .../Private/Templates/Configuration.html | 2 + 3 files changed, 266 insertions(+), 8 deletions(-) diff --git a/Classes/Module/Configuration.php b/Classes/Module/Configuration.php index a8850b909..3a4d7bed3 100644 --- a/Classes/Module/Configuration.php +++ b/Classes/Module/Configuration.php @@ -276,7 +276,7 @@ function toggleDisplay(toggleId, e, countBox) { // } $this->content = $this->doc->startPage($this->getLanguageService()->getLL('title')); - $this->content.= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers, array()); + $this->content.= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers, []); } else { // If no access or if ID == zero @@ -307,7 +307,7 @@ public function printContent() */ protected function moduleContent() { - $configArray[1] = array( + $configArray[1] = [ 'box-1' => $this->getLanguageService()->getLL('configure_default_headers'), 'from_email' => array('string', DirectMailUtility::fName('from_email'), $this->getLanguageService()->getLL('from_email.description') . '
' . $this->getLanguageService()->getLL('from_email.details')), 'from_name' => array('string', DirectMailUtility::fName('from_name'), $this->getLanguageService()->getLL('from_name.description') . '
' . $this->getLanguageService()->getLL('from_name.details')), @@ -316,7 +316,7 @@ protected function moduleContent() 'return_path' => array('string', DirectMailUtility::fName('return_path'), $this->getLanguageService()->getLL('return_path.description') . '
' . $this->getLanguageService()->getLL('return_path.details')), 'organisation' => array('string', DirectMailUtility::fName('organisation'), $this->getLanguageService()->getLL('organisation.description') . '
' . $this->getLanguageService()->getLL('organisation.details')), 'priority' => array('select', DirectMailUtility::fName('priority'), $this->getLanguageService()->getLL('priority.description') . '
' . $this->getLanguageService()->getLL('priority.details'), array(3 => $this->getLanguageService()->getLL('configure_priority_normal'), 1 => $this->getLanguageService()->getLL('configure_priority_high'), 5 => $this->getLanguageService()->getLL('configure_priority_low'))), - ); + ]; $configArray[2] = array( 'box-2' => $this->getLanguageService()->getLL('configure_default_content'), 'sendOptions' => array('select', DirectMailUtility::fName('sendOptions'), $this->getLanguageService()->getLL('sendOptions.description') . '
' . $this->getLanguageService()->getLL('sendOptions.details'), array(3 => $this->getLanguageService()->getLL('configure_plain_and_html') ,1 => $this->getLanguageService()->getLL('configure_plain_only') ,2 => $this->getLanguageService()->getLL('configure_html_only'))), diff --git a/Classes/Module/ConfigurationController.php b/Classes/Module/ConfigurationController.php index b3dfa9afd..cb940b127 100644 --- a/Classes/Module/ConfigurationController.php +++ b/Classes/Module/ConfigurationController.php @@ -18,10 +18,13 @@ use Psr\Http\Message\ServerRequestInterface; use TYPO3\CMS\Backend\Template\Components\ButtonBar; use TYPO3\CMS\Backend\Template\ModuleTemplate; +use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Core\Http\HtmlResponse; use TYPO3\CMS\Core\Imaging\Icon; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Fluid\View\StandaloneView; +use TYPO3\CMS\Core\Localization\LanguageService; +use DirectMailTeam\DirectMail\DirectMailUtility; class ConfigurationController { @@ -45,10 +48,26 @@ class ConfigurationController public function __construct(ModuleTemplate $moduleTemplate = null) { $this->moduleTemplate = $moduleTemplate ?? GeneralUtility::makeInstance(ModuleTemplate::class); + $this->getLanguageService()->includeLLFile('EXT:direct_mail/Resources/Private/Language/locallang_mod2-6.xlf'); } public function indexAction(ServerRequestInterface $request) : ResponseInterface { + /** + debug($request->getQueryParams()); + $currentModule = (string)($request->getQueryParams()['currentModule'] ?? $request->getParsedBody()['currentModule'] ?? 'DirectMailNavFrame_Configuration###'); + + $this->CMD = GeneralUtility::_GP('CMD'); + $this->pages_uid = intval(GeneralUtility::_GP('pages_uid')); + $sys_dmail_uid = intval(GeneralUtility::_GP('sys_dmail_uid')); + $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause); + $access = is_array($this->pageinfo) ? 1 : 0; + + if (($this->id && $access) || ($GLOBALS['BE_USER']->user['admin'] && !$this->id)) { + + */ + $sys_dmail_uid = 0; + /** * Configure template paths for your backend module */ @@ -58,11 +77,14 @@ public function indexAction(ServerRequestInterface $request) : ResponseInterface $this->view->setLayoutRootPaths(['EXT:direct_mail/Resources/Private/Layouts/']); $this->view->setTemplate('Configuration'); -// $this->view->assignMultiple( -// [ -// 'some-variable' => 'some-value', -// ] -// ); + $this->moduleTemplate->addJavaScriptCode($this->getJS($sys_dmail_uid)); + + $formcontent = $this->moduleContent(); + $this->view->assignMultiple( + [ + 'formcontent' => $formcontent + ] + ); /** * Render template and return html content @@ -70,4 +92,238 @@ public function indexAction(ServerRequestInterface $request) : ResponseInterface $this->moduleTemplate->setContent($this->view->render()); return new HtmlResponse($this->moduleTemplate->renderContent()); } + + protected function getJS($sys_dmail_uid) { + return GeneralUtility::wrapJS(' + '); + } + + /** + * Shows the content of configuration module + * compiling the configuration form and fill it with default values + * + * @return string The compiled content of the module. + */ + protected function moduleContent() + { + $configArray[1] = [ + 'box-1' => $this->getLanguageService()->getLL('configure_default_headers'), + 'from_email' => ['string', DirectMailUtility::fName('from_email'), $this->getLanguageService()->getLL('from_email.description') . '
' . $this->getLanguageService()->getLL('from_email.details')], + 'from_name' => ['string', DirectMailUtility::fName('from_name'), $this->getLanguageService()->getLL('from_name.description') . '
' . $this->getLanguageService()->getLL('from_name.details')], + 'replyto_email' => ['string', DirectMailUtility::fName('replyto_email'), $this->getLanguageService()->getLL('replyto_email.description') . '
' . $this->getLanguageService()->getLL('replyto_email.details')], + 'replyto_name' => ['string', DirectMailUtility::fName('replyto_name'), $this->getLanguageService()->getLL('replyto_name.description') . '
' . $this->getLanguageService()->getLL('replyto_name.details')], + 'return_path' => ['string', DirectMailUtility::fName('return_path'), $this->getLanguageService()->getLL('return_path.description') . '
' . $this->getLanguageService()->getLL('return_path.details')], + 'organisation' => ['string', DirectMailUtility::fName('organisation'), $this->getLanguageService()->getLL('organisation.description') . '
' . $this->getLanguageService()->getLL('organisation.details')], + 'priority' => [ + 'select', DirectMailUtility::fName('priority'), + $this->getLanguageService()->getLL('priority.description') . '
' . $this->getLanguageService()->getLL('priority.details'), + [ + 3 => $this->getLanguageService()->getLL('configure_priority_normal'), + 1 => $this->getLanguageService()->getLL('configure_priority_high'), + 5 => $this->getLanguageService()->getLL('configure_priority_low')]], + ]; + $configArray[2] = [ + 'box-2' => $this->getLanguageService()->getLL('configure_default_content'), + 'sendOptions' => [ + 'select', DirectMailUtility::fName('sendOptions'), $this->getLanguageService()->getLL('sendOptions.description') . '
' . $this->getLanguageService()->getLL('sendOptions.details'), + [ + 3 => $this->getLanguageService()->getLL('configure_plain_and_html'), + 1 => $this->getLanguageService()->getLL('configure_plain_only'), + 2 => $this->getLanguageService()->getLL('configure_html_only')]], + 'includeMedia' => ['check', DirectMailUtility::fName('includeMedia'), $this->getLanguageService()->getLL('includeMedia.description') . '
' . $this->getLanguageService()->getLL('includeMedia.details')], + 'flowedFormat' => ['check', DirectMailUtility::fName('flowedFormat'), $this->getLanguageService()->getLL('flowedFormat.description') . '
' . $this->getLanguageService()->getLL('flowedFormat.details')], + ]; + $configArray[3] = [ + 'box-3' => $this->getLanguageService()->getLL('configure_default_fetching'), + 'HTMLParams' => ['short', DirectMailUtility::fName('HTMLParams'), $this->getLanguageService()->getLL('configure_HTMLParams_description') . '
' . $this->getLanguageService()->getLL('configure_HTMLParams_details')], + 'plainParams' => ['short', DirectMailUtility::fName('plainParams'), $this->getLanguageService()->getLL('configure_plainParams_description') . '
' . $this->getLanguageService()->getLL('configure_plainParams_details')], + ]; + $configArray[4] = [ + 'box-4' => $this->getLanguageService()->getLL('configure_options_encoding'), + 'quick_mail_encoding' => ['select', $this->getLanguageService()->getLL('configure_quickmail_encoding'), $this->getLanguageService()->getLL('configure_quickmail_encoding_description'), ['quoted-printable'=>'quoted-printable','base64'=>'base64','8bit'=>'8bit']], + 'direct_mail_encoding' => ['select', $this->getLanguageService()->getLL('configure_directmail_encoding'), $this->getLanguageService()->getLL('configure_directmail_encoding_description'), ['quoted-printable'=>'quoted-printable','base64'=>'base64','8bit'=>'8bit']], + 'quick_mail_charset' => ['short', $this->getLanguageService()->getLL('configure_quickmail_charset'), $this->getLanguageService()->getLL('configure_quickmail_charset_description')], + 'direct_mail_charset' => ['short', $this->getLanguageService()->getLL('configure_directmail_charset'), $this->getLanguageService()->getLL('configure_directmail_charset_description')], + ]; + $configArray[5] = [ + 'box-5' => $this->getLanguageService()->getLL('configure_options_links'), + 'use_rdct' => ['check', DirectMailUtility::fName('use_rdct'), $this->getLanguageService()->getLL('use_rdct.description') . '
' . $this->getLanguageService()->getLL('use_rdct.details') . '
' . $this->getLanguageService()->getLL('configure_options_links_rdct')], + 'long_link_mode' => ['check', DirectMailUtility::fName('long_link_mode'), $this->getLanguageService()->getLL('long_link_mode.description')], + 'enable_jump_url' => ['check', $this->getLanguageService()->getLL('configure_options_links_jumpurl'), $this->getLanguageService()->getLL('configure_options_links_jumpurl_description')], + 'jumpurl_tracking_privacy' => ['check', $this->getLanguageService()->getLL('configure_jumpurl_tracking_privacy'), $this->getLanguageService()->getLL('configure_jumpurl_tracking_privacy_description')], + 'enable_mailto_jump_url' => ['check', $this->getLanguageService()->getLL('configure_options_mailto_jumpurl'), $this->getLanguageService()->getLL('configure_options_mailto_jumpurl_description')], + 'authcode_fieldList' => ['short', DirectMailUtility::fName('authcode_fieldList'), $this->getLanguageService()->getLL('authcode_fieldList.description')], + ]; + $configArray[6] = [ + 'box-6' => $this->getLanguageService()->getLL('configure_options_additional'), + 'http_username' => ['short', $this->getLanguageService()->getLL('configure_http_username'), $this->getLanguageService()->getLL('configure_http_username_description') . '
' . $this->getLanguageService()->getLL('configure_http_username_details')], + 'http_password' => ['short', $this->getLanguageService()->getLL('configure_http_password'), $this->getLanguageService()->getLL('configure_http_password_description')], + 'simulate_usergroup' => ['short', $this->getLanguageService()->getLL('configure_simulate_usergroup'), $this->getLanguageService()->getLL('configure_simulate_usergroup_description') . '
' . $this->getLanguageService()->getLL('configure_simulate_usergroup_details')], + 'userTable' => ['short', $this->getLanguageService()->getLL('configure_user_table'), $this->getLanguageService()->getLL('configure_user_table_description')], + 'test_tt_address_uids' => ['short', $this->getLanguageService()->getLL('configure_test_tt_address_uids'), $this->getLanguageService()->getLL('configure_test_tt_address_uids_description')], + 'test_dmail_group_uids' => ['short', $this->getLanguageService()->getLL('configure_test_dmail_group_uids'), $this->getLanguageService()->getLL('configure_test_dmail_group_uids_description')], + 'testmail' => ['short', $this->getLanguageService()->getLL('configure_testmail'), $this->getLanguageService()->getLL('configure_testmail_description')] + ]; + + // Set default values + if (!isset($this->implodedParams['plainParams'])) { + $this->implodedParams['plainParams'] = '&type=99'; + } + if (!isset($this->implodedParams['quick_mail_charset'])) { + $this->implodedParams['quick_mail_charset'] = 'utf-8'; + } + if (!isset($this->implodedParams['direct_mail_charset'])) { + $this->implodedParams['direct_mail_charset'] = 'iso-8859-1'; + } + + $this->configArray_length = count($configArray); + $form = ''; + for ($i = 1; $i <= count($configArray); $i++) { + $form .= $this->makeConfigForm($configArray[$i], $this->implodedParams, 'pageTS'); + } + + return $form; + } + + /** + * @return LanguageService + */ + protected function getLanguageService(): LanguageService + { + return $GLOBALS['LANG']; + } + + /** + * Compiling the form from an array and put in to boxes + * + * @param array $configArray The input array parameter + * @param array $params Default values array + * @param string $dataPrefix Prefix of the input field's name + * + * @return string The compiled input form + */ + public function makeConfigForm(array $configArray, array $params, $dataPrefix) + { + $boxFlag = 0; + + $wrapHelp1 = ' ' . + $this->moduleTemplate->getIconFactory()->getIcon('actions-system-help-open', Icon::SIZE_SMALL) . + ' '; + $wrapHelp2 = ''; + + $lines = []; + if (is_array($configArray)) { + foreach ($configArray as $fname => $config) { + if (is_array($config)) { + $lines[$fname] = '' . htmlspecialchars($config[1]) . ''; + $lines[$fname] .= $wrapHelp1 . $config[2] . $wrapHelp2 . '
'; + $formEl = ''; + switch ($config[0]) { + case 'string': + case 'short': + $formEl = ''; + break; + case 'check': + $formEl = ''; + break; + case 'comment': + $formEl = ''; + break; + case 'select': + $opt = []; + foreach ($config[3] as $k => $v) { + $opt[] = ''; + } + $formEl = ''; + break; + default: + } + $lines[$fname] .= $formEl; + $lines[$fname] .= '
'; + } else { + if (!strpos($fname, 'box')) { + $lines[$fname] =''; + } + return $out; + } } diff --git a/Resources/Private/Templates/Configuration.html b/Resources/Private/Templates/Configuration.html index cc4d6d2aa..cf9cccf78 100644 --- a/Resources/Private/Templates/Configuration.html +++ b/Resources/Private/Templates/Configuration.html @@ -3,5 +3,7 @@

+ {formcontent} +
\ No newline at end of file From 3ea6784d2b3fa53d346d5d60236956e94c36cead Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sun, 31 Oct 2021 19:53:50 +0000 Subject: [PATCH 011/342] add crowdin.yml --- Classes/Module/NavFrameController.php | 4 ++-- crowdin.yml | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 crowdin.yml diff --git a/Classes/Module/NavFrameController.php b/Classes/Module/NavFrameController.php index 75c4989ac..f1e81a380 100644 --- a/Classes/Module/NavFrameController.php +++ b/Classes/Module/NavFrameController.php @@ -128,11 +128,11 @@ function jumpTo(params,linkObj,highLightID) { // Call this function, refresh_nav(), from another script in the backend if you want to refresh the navigation frame (eg. after having changed a page title or moved pages etc.) // See t3lib_BEfunc::getSetUpdateSignal() - function refresh_nav() { // + function refresh_nav() { window.setTimeout("_refresh_nav();",0); } - function _refresh_nav() { // + function _refresh_nav() { document.location="' . htmlspecialchars(GeneralUtility::getIndpEnv('SCRIPT_NAME') . '?unique=' . time()) . '"; } diff --git a/crowdin.yml b/crowdin.yml new file mode 100644 index 000000000..61c310583 --- /dev/null +++ b/crowdin.yml @@ -0,0 +1,3 @@ +files: + - source: /Resources/Private/Language/locallang*.xlf + translation: /Resources/Private/Language/%two_letters_code%.%original_file_name% From 2335233980492e6b3c1d9d8cb19c3af6afa4ff86 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sun, 31 Oct 2021 20:37:45 +0000 Subject: [PATCH 012/342] add stylesheetDirectories --- ext_tables.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ext_tables.php b/ext_tables.php index 3470cc3f2..a60b9321d 100755 --- a/ext_tables.php +++ b/ext_tables.php @@ -142,3 +142,5 @@ if (TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionNumberToInteger(TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getExtensionVersion('tt_address')) <= TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionNumberToInteger('2.3.5')) { include_once(TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('direct_mail').'Configuration/TCA/Overrides/tt_address.php'); } + +$GLOBALS['TBE_STYLES']['skins']['direct_mail']['stylesheetDirectories'][] = 'EXT:direct_mail/Resources/Public/StyleSheets/'; \ No newline at end of file From 271b6004ec28cd208c28b941c7cd71a0129a1d9d Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Mon, 1 Nov 2021 10:22:15 +0000 Subject: [PATCH 013/342] use addJsInlineCode --- Classes/Module/NavFrame.php | 16 +++++++--------- Classes/Module/NavFrameController.php | 12 ++++++++---- Resources/Public/StyleSheets/modules.css | 8 +++++++- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/Classes/Module/NavFrame.php b/Classes/Module/NavFrame.php index 4ef881d98..d34818bf9 100644 --- a/Classes/Module/NavFrame.php +++ b/Classes/Module/NavFrame.php @@ -75,9 +75,9 @@ class NavFrame */ public function __construct() { - $this->MCONF = array( + $this->MCONF = [ 'name' => $this->moduleName - ); + ]; } /** @@ -120,27 +120,25 @@ function jumpTo(params,linkObj,highLightID) { // return false; } - - // Call this function, refresh_nav(), from another script in the backend if you want to refresh the navigation frame (eg. after having changed a page title or moved pages etc.) - // See t3lib_BEfunc::getSetUpdateSignal() + // Call this function, refresh_nav(), from another script in the backend if you want to refresh the navigation frame (eg. after having changed a page title or moved pages etc.) + // See t3lib_BEfunc::getSetUpdateSignal() function refresh_nav() { // window.setTimeout("_refresh_nav();",0); } - function _refresh_nav() { // document.location="' . htmlspecialchars(GeneralUtility::getIndpEnv('SCRIPT_NAME') . '?unique=' . time()) . '"; } - // Highlighting rows in the page tree: + // Highlighting rows in the page tree: function hilight_row(frameSetModule,highLightID) { // - // Remove old: + // Remove old: theObj = document.getElementById(top.fsMod.navFrameHighlightedID[frameSetModule]); if (theObj) { theObj.style.backgroundColor=""; } - // Set new: + // Set new: top.fsMod.navFrameHighlightedID[frameSetModule] = highLightID; theObj = document.getElementById(highLightID); } diff --git a/Classes/Module/NavFrameController.php b/Classes/Module/NavFrameController.php index f1e81a380..de01a8980 100644 --- a/Classes/Module/NavFrameController.php +++ b/Classes/Module/NavFrameController.php @@ -92,8 +92,9 @@ public function indexAction(ServerRequestInterface $request) : ResponseInterface $this->setDocHeader('index'); - $this->moduleTemplate->addJavaScriptCode($this->getJS($currentModule, $currentSubScript)); - + //$this->moduleTemplate->addJavaScriptCode($this->getJS($currentModule, $currentSubScript)); + $this->moduleTemplate->getPageRenderer()->addJsInlineCode($currentModule, $this->getJS($currentModule, $currentSubScript)); + $this->view->assignMultiple( [ 'pages' => $pages, @@ -110,7 +111,9 @@ public function indexAction(ServerRequestInterface $request) : ResponseInterface protected function getJS($currentModule, $currentSubScript) { //@TODO Uncaught Error: Writing to fsMod is not possible anymore, use ModuleStateStorage instead. //https://docs.typo3.org/c/typo3/cms-core/master/en-us/Changelog/11.4/Deprecation-94762-DeprecateJavaScriptTopfsModState.html - return GeneralUtility::wrapJS( + //https://github.com/typo3/typo3/commit/ca4afee813 + //https://git.higidi.com/TYPO3/TYPO3.CMS/-/commit/1da997b9d7823900300568e181d7d1c17ecef71f + return //GeneralUtility::wrapJS( ($currentModule ? 'top.currentSubScript=unescape("' . rawurlencode($currentSubScript) . '");' : '') . ' function jumpTo(params,linkObj,highLightID) { @@ -149,7 +152,8 @@ function hilight_row(frameSetModule,highLightID) { theObj = document.getElementById(highLightID); } ' - ); + //) + ; } protected function getPages() { diff --git a/Resources/Public/StyleSheets/modules.css b/Resources/Public/StyleSheets/modules.css index f195da554..80bce328f 100644 --- a/Resources/Public/StyleSheets/modules.css +++ b/Resources/Public/StyleSheets/modules.css @@ -55,7 +55,13 @@ div.toggleTitle a img { vertical-align: bottom; } - .t3-wizard-steps span.t3-wizard-item-active { color: #000000; +} + +#typo3-docheader-row2 { + line-height: 14px !important; +} +#typo3-docheader-row2 span { + font-weight: bold; margin-top: -3px; color: #000; margin-top: 0; padding-left: 20px; } \ No newline at end of file From 0cb50685ac6206395a677ab5479847273550a440 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Mon, 1 Nov 2021 10:47:59 +0000 Subject: [PATCH 014/342] test with refresh button --- Classes/Module/NavFrameController.php | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/Classes/Module/NavFrameController.php b/Classes/Module/NavFrameController.php index de01a8980..e2e122cfb 100644 --- a/Classes/Module/NavFrameController.php +++ b/Classes/Module/NavFrameController.php @@ -26,6 +26,7 @@ use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction; use TYPO3\CMS\Core\Http\HtmlResponse; use TYPO3\CMS\Core\Imaging\Icon; +use TYPO3\CMS\Core\Localization\LanguageService; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Fluid\View\StandaloneView; @@ -58,6 +59,8 @@ class NavFrameController public function __construct(ModuleTemplate $moduleTemplate = null) { $this->moduleTemplate = $moduleTemplate ?? GeneralUtility::makeInstance(ModuleTemplate::class); + # $this->getLanguageService()->includeLLFile('EXT:direct_mail/Resources/Private/Language/locallang_mod2-6.xlf'); + $this->getLanguageService()->includeLLFile('EXT:core/Resources/Private/Language/locallang_core.xlf'); } public function indexAction(ServerRequestInterface $request) : ResponseInterface @@ -113,8 +116,7 @@ protected function getJS($currentModule, $currentSubScript) { //https://docs.typo3.org/c/typo3/cms-core/master/en-us/Changelog/11.4/Deprecation-94762-DeprecateJavaScriptTopfsModState.html //https://github.com/typo3/typo3/commit/ca4afee813 //https://git.higidi.com/TYPO3/TYPO3.CMS/-/commit/1da997b9d7823900300568e181d7d1c17ecef71f - return //GeneralUtility::wrapJS( - ($currentModule ? 'top.currentSubScript=unescape("' . rawurlencode($currentSubScript) . '");' : '') . ' + return ($currentModule ? 'top.currentSubScript=unescape("' . rawurlencode($currentSubScript) . '");' : '') . ' function jumpTo(params,linkObj,highLightID) { var theUrl = top.currentSubScript+"&"+params; @@ -152,7 +154,6 @@ function hilight_row(frameSetModule,highLightID) { theObj = document.getElementById(highLightID); } ' - //) ; } @@ -199,15 +200,25 @@ private function setDocHeader(string $active) { /** $docHeaderButtons = [ 'CSH' => BackendUtility::cshItem('_MOD_DirectMailNavFrame', 'folders', $GLOBALS['BACK_PATH'], true), - 'REFRESH' => '' + 'REFRESH' => '' ]; */ + $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar(); $list = $buttonBar->makeLinkButton() - ->setHref('') //@TODO - ->setTitle('refresh') + ->setHref(GeneralUtility::linkThisScript(['unique' => uniqid('directmail_navframe')])) + //->setHref(GeneralUtility::getIndpEnv('REQUEST_URI')) + ->setTitle($this->getLanguageService()->getLL('labels.reload')) ->setShowLabelText('Link') ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-refresh', Icon::SIZE_SMALL)); $buttonBar->addButton($list, ButtonBar::BUTTON_POSITION_RIGHT, 1); } + + /** + * @return LanguageService + */ + protected function getLanguageService(): LanguageService + { + return $GLOBALS['LANG']; + } } From 906753e86f3c6f593c3be9a656a956d257148abf Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Tue, 2 Nov 2021 14:06:28 +0000 Subject: [PATCH 015/342] add column for icon in the tree --- Classes/Module/NavFrameController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Classes/Module/NavFrameController.php b/Classes/Module/NavFrameController.php index e2e122cfb..691718ce9 100644 --- a/Classes/Module/NavFrameController.php +++ b/Classes/Module/NavFrameController.php @@ -87,6 +87,7 @@ public function indexAction(ServerRequestInterface $request) : ResponseInterface $pages = []; while (($row = $rows->fetchAssociative()) !== false) { if (BackendUtility::readPageAccess($row['uid'], $GLOBALS['BE_USER']->getPagePermsClause(1))) { + debug($row); $icon = $this->moduleTemplate->getIconFactory()->getIconForRecord('pages', $row, Icon::SIZE_SMALL)->render(); $pages[] = ['icon' => $icon, 'page' => $row]; } @@ -165,7 +166,7 @@ protected function getPages() { ->add(GeneralUtility::makeInstance(DeletedRestriction::class)); $statement = $queryBuilder - ->select('uid', 'title') + ->select('uid', 'title', 'module') ->from('pages') ->where( $queryBuilder->expr()->eq( From 70422f9dc6101881f5f82b55a9ce953e8989caeb Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Tue, 2 Nov 2021 14:12:34 +0000 Subject: [PATCH 016/342] remove debug --- Classes/Module/NavFrameController.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Classes/Module/NavFrameController.php b/Classes/Module/NavFrameController.php index 691718ce9..1acf697d9 100644 --- a/Classes/Module/NavFrameController.php +++ b/Classes/Module/NavFrameController.php @@ -87,7 +87,6 @@ public function indexAction(ServerRequestInterface $request) : ResponseInterface $pages = []; while (($row = $rows->fetchAssociative()) !== false) { if (BackendUtility::readPageAccess($row['uid'], $GLOBALS['BE_USER']->getPagePermsClause(1))) { - debug($row); $icon = $this->moduleTemplate->getIconFactory()->getIconForRecord('pages', $row, Icon::SIZE_SMALL)->render(); $pages[] = ['icon' => $icon, 'page' => $row]; } From 081f204e9488c26d7a3269be2ba4c83f8abb13b5 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Tue, 2 Nov 2021 14:17:54 +0000 Subject: [PATCH 017/342] add MainController --- Classes/Module/ConfigurationController.php | 11 +---------- Classes/Module/MainController.php | 17 +++++++++++++++++ Classes/Module/NavFrameController.php | 11 +---------- 3 files changed, 19 insertions(+), 20 deletions(-) create mode 100644 Classes/Module/MainController.php diff --git a/Classes/Module/ConfigurationController.php b/Classes/Module/ConfigurationController.php index cb940b127..4a060e2da 100644 --- a/Classes/Module/ConfigurationController.php +++ b/Classes/Module/ConfigurationController.php @@ -23,10 +23,9 @@ use TYPO3\CMS\Core\Imaging\Icon; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Fluid\View\StandaloneView; -use TYPO3\CMS\Core\Localization\LanguageService; use DirectMailTeam\DirectMail\DirectMailUtility; -class ConfigurationController +class ConfigurationController extends MainController { /** * ModuleTemplate Container @@ -242,14 +241,6 @@ protected function moduleContent() return $form; } - /** - * @return LanguageService - */ - protected function getLanguageService(): LanguageService - { - return $GLOBALS['LANG']; - } - /** * Compiling the form from an array and put in to boxes * diff --git a/Classes/Module/MainController.php b/Classes/Module/MainController.php new file mode 100644 index 000000000..f47c018f7 --- /dev/null +++ b/Classes/Module/MainController.php @@ -0,0 +1,17 @@ +setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-refresh', Icon::SIZE_SMALL)); $buttonBar->addButton($list, ButtonBar::BUTTON_POSITION_RIGHT, 1); } - - /** - * @return LanguageService - */ - protected function getLanguageService(): LanguageService - { - return $GLOBALS['LANG']; - } } From 7ec19bf2e897eba4b921c6045d47b17ca68ed258 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Tue, 2 Nov 2021 14:46:24 +0000 Subject: [PATCH 018/342] add MaileEngineController --- Classes/Module/MailerEngineController.php | 41 +++++++++++++++++++ Classes/Module/MainController.php | 15 ++++++- Resources/Private/Templates/MailerEngine.html | 5 +++ ext_tables.php | 2 +- 4 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 Classes/Module/MailerEngineController.php create mode 100644 Resources/Private/Templates/MailerEngine.html diff --git a/Classes/Module/MailerEngineController.php b/Classes/Module/MailerEngineController.php new file mode 100644 index 000000000..7e23d82d5 --- /dev/null +++ b/Classes/Module/MailerEngineController.php @@ -0,0 +1,41 @@ +view = GeneralUtility::makeInstance(StandaloneView::class); + $this->view->setTemplateRootPaths(['EXT:direct_mail/Resources/Private/Templates/']); + $this->view->setPartialRootPaths(['EXT:direct_mail/Resources/Private/Partials/']); + $this->view->setLayoutRootPaths(['EXT:direct_mail/Resources/Private/Layouts/']); + $this->view->setTemplate('MailerEngine'); + + /** + * Render template and return html content + */ + $this->moduleTemplate->setContent($this->view->render()); + return new HtmlResponse($this->moduleTemplate->renderContent()); + } +} \ No newline at end of file diff --git a/Classes/Module/MainController.php b/Classes/Module/MainController.php index f47c018f7..2448b643b 100644 --- a/Classes/Module/MainController.php +++ b/Classes/Module/MainController.php @@ -1,12 +1,23 @@ moduleTemplate = $moduleTemplate ?? GeneralUtility::makeInstance(ModuleTemplate::class); + $this->getLanguageService()->includeLLFile('EXT:direct_mail/Resources/Private/Language/locallang_mod2-6.xlf'); + } + /** * @return LanguageService */ diff --git a/Resources/Private/Templates/MailerEngine.html b/Resources/Private/Templates/MailerEngine.html new file mode 100644 index 000000000..b9e25e035 --- /dev/null +++ b/Resources/Private/Templates/MailerEngine.html @@ -0,0 +1,5 @@ + + + +

+
\ No newline at end of file diff --git a/ext_tables.php b/ext_tables.php index a60b9321d..9ba6f3a61 100755 --- a/ext_tables.php +++ b/ext_tables.php @@ -106,7 +106,7 @@ 'bottom', '', [ - 'routeTarget' => DirectMailTeam\DirectMail\Module\MailerEngine::class . '::mainAction', + 'routeTarget' => DirectMailTeam\DirectMail\Module\MailerEngineController::class . '::indexAction', 'access' => 'group,user', 'name' => 'DirectMailNavFrame_MailerEngine', 'workspaces' => 'online', From eb0e6f842dca841ea781180fe8cd0f5b23ff3cb4 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Tue, 2 Nov 2021 15:06:50 +0000 Subject: [PATCH 019/342] update MailerEngineController --- Classes/Module/MailerEngine.php | 22 +- Classes/Module/MailerEngineController.php | 214 ++++++++++++++++++ Resources/Private/Templates/MailerEngine.html | 4 + 3 files changed, 229 insertions(+), 11 deletions(-) diff --git a/Classes/Module/MailerEngine.php b/Classes/Module/MailerEngine.php index 4cae567d9..4e9dad4d2 100644 --- a/Classes/Module/MailerEngine.php +++ b/Classes/Module/MailerEngine.php @@ -48,17 +48,17 @@ class MailerEngine extends BaseScriptClass public $extKey = 'direct_mail'; public $TSconfPrefix = 'mod.web_modules.dmail.'; // Internal - public $params=array(); + public $params = []; public $perms_clause=''; public $pageinfo=''; public $sys_dmail_uid; public $pages_uid; public $id; - public $implodedParams=array(); + public $implodedParams = []; // If set a valid user table is around public $userTable; public $sys_language_uid = 0; - public $allowedTables = array('tt_address','fe_users'); + public $allowedTables = ['tt_address','fe_users']; public $MCONF; public $cshTable; public $formname = 'dmailform'; @@ -148,23 +148,23 @@ function jumpToUrlD(URL) { // '; - $this->doc->postCode=' + $this->doc->postCode = ' '; - $markers = array( + $markers = [ 'FLASHMESSAGES' => '', 'CONTENT' => '', - ); + ]; - $docHeaderButtons = array( + $docHeaderButtons = [ 'PAGEPATH' => $this->getLanguageService()->getLL('labels.path') . ': ' . GeneralUtility::fixed_lgd_cs($this->pageinfo['_thePath'], 50), 'SHORTCUT' => '', 'CSH' => BackendUtility::cshItem($this->cshTable, '', $GLOBALS['BACK_PATH']) - ); + ]; // shortcut icon if ($GLOBALS['BE_USER']->mayMakeShortcut()) { $docHeaderButtons['SHORTCUT'] = $this->doc->makeShortcutIcon('id', implode(',', array_keys($this->MOD_MENU)), $this->MCONF['name']); @@ -172,8 +172,8 @@ function jumpToUrlD(URL) { // $module = $this->pageinfo['module']; if (!$module) { - $pidrec=BackendUtility::getRecord('pages', intval($this->pageinfo['pid'])); - $module=$pidrec['module']; + $pidrec = BackendUtility::getRecord('pages', intval($this->pageinfo['pid'])); + $module = $pidrec['module']; } // Render content: if ($module == 'dmail') { @@ -211,7 +211,7 @@ function jumpToUrlD(URL) { // } $this->content = $this->doc->startPage($this->getLanguageService()->getLL('title')); - $this->content.= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers, array()); + $this->content.= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers, []); } else { // If no access or if ID == zero diff --git a/Classes/Module/MailerEngineController.php b/Classes/Module/MailerEngineController.php index 7e23d82d5..7b73653ca 100644 --- a/Classes/Module/MailerEngineController.php +++ b/Classes/Module/MailerEngineController.php @@ -3,7 +3,14 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; +use TYPO3\CMS\Backend\Routing\UriBuilder; +use TYPO3\CMS\Backend\Utility\BackendUtility; +use TYPO3\CMS\Core\Core\Environment; +use TYPO3\CMS\Core\Database\ConnectionPool; +use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction; use TYPO3\CMS\Core\Http\HtmlResponse; +use TYPO3\CMS\Core\Messaging\FlashMessage; +use TYPO3\CMS\Core\Messaging\FlashMessageRendererResolver; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Fluid\View\StandaloneView; @@ -21,6 +28,8 @@ class MailerEngineController extends MainController */ protected $view; + public $id; + public function indexAction(ServerRequestInterface $request) : ResponseInterface { /** @@ -32,10 +41,215 @@ public function indexAction(ServerRequestInterface $request) : ResponseInterface $this->view->setLayoutRootPaths(['EXT:direct_mail/Resources/Private/Layouts/']); $this->view->setTemplate('MailerEngine'); + $cronMonitor = $this->cmd_cronMonitor(); + $mailerEngine = $this->cmd_mailerengine(); + + $this->view->assignMultiple( + [ + 'cronMonitor' => $cronMonitor, + 'mailerEngine' => $mailerEngine + ] + ); /** * Render template and return html content */ $this->moduleTemplate->setContent($this->view->render()); return new HtmlResponse($this->moduleTemplate->renderContent()); } + + /** + * Monitor the cronjob. + * + * @return string status of the cronjob in HTML Tableformat + */ + public function cmd_cronMonitor() + { + $content = ''; + $mailerStatus = 0; + $lastExecutionTime = 0; + $logContent = ''; + + + // seconds + $cronInterval = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['direct_mail']['cronInt'] * 60; + $lastCronjobShouldBeNewThan = (time() - $cronInterval); + + $filename = Environment::getPublicPath() . '/typo3temp/tx_directmail_dmailer_log.txt'; + if (file_exists($filename)) { + $logContent = file_get_contents($filename); + $lastExecutionTime = substr($logContent, 0, 10); + } + + /* + * status: + * 1 = ok + * 0 = check + * -1 = cron stopped + */ + + // cron running or error (die function in dmailer_log) + if (file_exists(Environment::getPublicPath() . '/typo3temp/tx_directmail_cron.lock')) { + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) + ->getQueryBuilderForTable('sys_dmail_maillog'); + $res = $queryBuilder + ->select('uid') + ->from('sys_dmail_maillog') + ->where($queryBuilder->expr()->eq('response_type', $queryBuilder->createNamedParameter(0))) + ->orderBy('tstamp','DESC') + ->execute() + ->fetchAll(); + + foreach($res as $lastSend) { + if (($lastSend['tstamp'] < time()) && ($lastSend['tstamp'] > $lastCronjobShouldBeNewThan)) { + // cron is sending + $mailerStatus = 1; + } else { + // there's lock file but cron is not sending + $mailerStatus = -1; + } + } + // cron is idle or no cron + } elseif (strpos($logContent, 'error')) { + // error in log file + $mailerStatus = -1; + $error = substr($logContent, strpos($logContent, 'error') + 7); + } elseif (!strlen($logContent) || ($lastExecutionTime < $lastCronjobShouldBeNewThan)) { + // cron is not set or not running + $mailerStatus = 0; + } else { + // last run of cron is in the interval + $mailerStatus = 1; + } + + + $currentDate = ' / ' . $this->getLanguageService()->getLL('dmail_mailerengine_current_time') . ' ' . BackendUtility::datetime(time()) . '. '; + $lastRun = ' ' . $this->getLanguageService()->getLL('dmail_mailerengine_cron_lastrun') . ($lastExecutionTime ? BackendUtility::datetime($lastExecutionTime) : '-') . $currentDate; + switch ($mailerStatus) { + case -1: + $flashMessage = GeneralUtility::makeInstance( + FlashMessage::class, + $this->getLanguageService()->getLL('dmail_mailerengine_cron_warning') . ': ' . ($error ? $error : $this->getLanguageService()->getLL('dmail_mailerengine_cron_warning_msg')) . $lastRun, + $this->getLanguageService()->getLL('dmail_mailerengine_cron_status'), + FlashMessage::ERROR + ); + break; + case 0: + $flashMessage = GeneralUtility::makeInstance( + FlashMessage::class, + $this->getLanguageService()->getLL('dmail_mailerengine_cron_caution') . ': ' . $this->getLanguageService()->getLL('dmail_mailerengine_cron_caution_msg') . $lastRun, + $this->getLanguageService()->getLL('dmail_mailerengine_cron_status'), + FlashMessage::WARNING + ); + break; + case 1: + $flashMessage = GeneralUtility::makeInstance( + FlashMessage::class, + $this->getLanguageService()->getLL('dmail_mailerengine_cron_ok') . ': ' . $this->getLanguageService()->getLL('dmail_mailerengine_cron_ok_msg') . $lastRun, + $this->getLanguageService()->getLL('dmail_mailerengine_cron_status'), + FlashMessage::OK + ); + break; + default: + } + return GeneralUtility::makeInstance(FlashMessageRendererResolver::class) + ->resolve() + ->render([$flashMessage]); + } + + /** + * Shows the status of the mailer engine. + * TODO: Should really only show some entries, or provide a browsing interface. + * + * @return string List of the mailing status + * @throws RouteNotFoundException If the named route doesn't exist + */ + public function cmd_mailerengine() + { + $invokeMessage = ''; + + // enable manual invocation of mailer engine; enabled by default + $enableTrigger = ! (isset($this->params['menu.']['dmail_mode.']['mailengine.']['disable_trigger']) && $this->params['menu.']['dmail_mode.']['mailengine.']['disable_trigger']); + if ($enableTrigger && GeneralUtility::_GP('invokeMailerEngine')) { + $this->invokeMEngine(); + $invokeMessage = GeneralUtility::makeInstance(FlashMessageRendererResolver::class) + ->resolve() + ->render([ + GeneralUtility::makeInstance( + FlashMessage::class, + '', + $this->getLanguageService()->getLL('dmail_mailerengine_invoked'), + FlashMessage::INFO + ) + ]); + } + + // Invoke engine + if ($enableTrigger) { + /** @var UriBuilder $uriBuilder */ + $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); + $moduleUrl = $uriBuilder->buildUriFromRoute( + 'DirectMailNavFrame_MailerEngine', + [ + 'id' => $this->id, + 'invokeMailerEngine' => 1 + ] + ); + $invokeMessage .= '

' . $this->getLanguageService()->getLL('dmail_mailerengine_manual_invoke') . '

' . + '

' . $this->getLanguageService()->getLL('dmail_mailerengine_manual_explain') . '

' . + '' . $this->getLanguageService()->getLL('dmail_mailerengine_invoke_now') . ''. + '

'; + $invokeMessage .= '
'; + } + + // Display mailer engine status + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_dmail'); + $queryBuilder + ->getRestrictions() + ->removeAll() + ->add(GeneralUtility::makeInstance(DeletedRestriction::class)); + $res = $queryBuilder->select('uid', 'pid', 'subject', 'scheduled', 'scheduled_begin', 'scheduled_end') + ->from('sys_dmail') + ->add('where','pid=' . intval($this->id) .' AND scheduled>0') + ->orderBy('scheduled','DESC') + ->execute() + ->fetchAll(); + + + $out = ' +   + ' . $this->getLanguageService()->getLL('dmail_mailerengine_subject') . '   + ' . $this->getLanguageService()->getLL('dmail_mailerengine_scheduled') . '   + ' . $this->getLanguageService()->getLL('dmail_mailerengine_delivery_begun') . '   + ' . $this->getLanguageService()->getLL('dmail_mailerengine_delivery_ended') . '   +  ' . $this->getLanguageService()->getLL('dmail_mailerengine_number_sent') . '  +  ' . $this->getLanguageService()->getLL('dmail_mailerengine_delete') . '  + '; + + + + foreach ($res as $row) { + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_dmail_maillog'); + $countres = $queryBuilder->count('*') + ->from('sys_dmail_maillog') + ->add('where','mid=' . intval($row['uid']) . + ' AND response_type=0' . + ' AND html_sent>0') + ->execute(); + + foreach($countres as $cRow) $count = $cRow['COUNT(*)']; + + $out .=' + ' . $this->iconFactory->getIconForRecord('sys_dmail', $row, Icon::SIZE_SMALL)->render() . ' + ' . $this->linkDMail_record(htmlspecialchars(GeneralUtility::fixed_lgd_cs($row['subject'], 100)) . '  ', $row['uid']) . ' + ' . BackendUtility::datetime($row['scheduled']) . '   + ' . ($row['scheduled_begin']?BackendUtility::datetime($row['scheduled_begin']):'') . '   + ' . ($row['scheduled_end']?BackendUtility::datetime($row['scheduled_end']):'') . '   + ' . ($count?$count:' ') . ' + ' . $this->deleteLink($row['uid']) . ' + '; + } + + $out = $invokeMessage . '' . $out . '
'; + return '

' . $this->getLanguageService()->getLL('dmail_mailerengine_status') .'

' . $out; + } } \ No newline at end of file diff --git a/Resources/Private/Templates/MailerEngine.html b/Resources/Private/Templates/MailerEngine.html index b9e25e035..d072ce88a 100644 --- a/Resources/Private/Templates/MailerEngine.html +++ b/Resources/Private/Templates/MailerEngine.html @@ -2,4 +2,8 @@

+{cronMonitor} +{mailerEngine} +
+
\ No newline at end of file From f324e43402a56f56a997bb489842f44f98bce2a6 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sun, 14 Nov 2021 11:05:06 +0000 Subject: [PATCH 020/342] add StatisticsController --- Classes/Module/Statistics.php | 1711 +++++++++---------- Classes/Module/StatisticsController.php | 52 + Resources/Private/Templates/Statistics.html | 5 + ext_tables.php | 2 +- 4 files changed, 909 insertions(+), 861 deletions(-) create mode 100644 Classes/Module/StatisticsController.php create mode 100644 Resources/Private/Templates/Statistics.html diff --git a/Classes/Module/Statistics.php b/Classes/Module/Statistics.php index 0753051d7..785227f05 100644 --- a/Classes/Module/Statistics.php +++ b/Classes/Module/Statistics.php @@ -48,8 +48,8 @@ class Statistics extends BaseScriptClass public $extKey = 'direct_mail'; public $fieldList = 'uid,name,title,email,phone,www,address,company,city,zip,country,fax,module_sys_dmail_category,module_sys_dmail_html'; // Internal - public $params = array(); - public $implodedParams = array(); + public $params = []; + public $implodedParams = []; public $perms_clause = ''; public $pageinfo = ''; public $sys_dmail_uid; @@ -61,29 +61,29 @@ class Statistics extends BaseScriptClass public $url_plain; public $url_html; public $sys_language_uid = 0; - public $allowedTables = array('tt_address','fe_users'); + public $allowedTables = ['tt_address','fe_users']; public $MCONF; public $cshTable; public $formname = 'dmailform'; - + /* * @var array */ public $categories; - + /** * IconFactory for skinning * @var \TYPO3\CMS\Core\Imaging\IconFactory */ protected $iconFactory; - + /** * The name of the module * * @var string */ protected $moduleName = 'DirectMailNavFrame_Statistics'; - + /** * Constructor */ @@ -93,7 +93,7 @@ public function __construct() 'name' => $this->moduleName ]; } - + /** * Prints out the module HTML * @@ -103,7 +103,7 @@ public function printContent() { $this->content.=$this->doc->endPage(); } - + /** * Entrance from the backend module. This replace the _dispatch * @@ -115,15 +115,15 @@ public function mainAction(ServerRequestInterface $request) : ResponseInterface { /** @var ResponseInterface $response */ $response = func_num_args() === 2 ? func_get_arg(1) : null; - + $this->getLanguageService()->includeLLFile('EXT:direct_mail/Resources/Private/Language/locallang_mod2-6.xlf'); $this->getLanguageService()->includeLLFile('EXT:direct_mail/Resources/Private/Language/locallang_csh_sysdmail.xlf'); - + $this->init(); - + $this->main(); $this->printContent(); - + if ($response !== null) { $response->getBody()->write($this->content); } else { @@ -132,7 +132,7 @@ public function mainAction(ServerRequestInterface $request) : ResponseInterface } return $response; } - + /** * The main function. * @@ -145,15 +145,15 @@ public function main() $this->sys_dmail_uid = intval(GeneralUtility::_GP('sys_dmail_uid')); $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause); $access = is_array($this->pageinfo) ? 1 : 0; - + if (($this->id && $access) || ($GLOBALS['BE_USER']->user['admin'] && !$this->id)) { - + // Draw the header. $this->doc = GeneralUtility::makeInstance(DocumentTemplate::class); $this->doc->backPath = $GLOBALS['BACK_PATH']; $this->doc->setModuleTemplate('EXT:direct_mail/Resources/Private/Templates/Module.html'); $this->doc->form='
'; - + // Add CSS $this->doc->inDocStyles = ' a.bubble {position:relative; z-index:24; color:#000; text-decoration:none} @@ -162,7 +162,7 @@ public function main() a.bubble:hover span.help {display:block; position:absolute; top:2em; left:2em; width:25em; border:1px solid #0cf; background-color:#cff; padding: 2px;} td { vertical-align: top; } '; - + // JavaScript $this->doc->JScode = ' '; - + $this->doc->postCode=' '; - - - - $markers = array( + + $markers = [ 'FLASHMESSAGES' => '', 'CONTENT' => '', - ); - - $docHeaderButtons = array( + ]; + + $docHeaderButtons = [ 'PAGEPATH' => $this->getLanguageService()->getLL('labels.path') . ': ' . GeneralUtility::fixed_lgd_cs($this->pageinfo['_thePath'], 50), 'SHORTCUT' => '', 'CSH' => BackendUtility::cshItem($this->cshTable, '', $GLOBALS['BACK_PATH']) - ); + ]; // shortcut icon if ($GLOBALS['BE_USER']->mayMakeShortcut()) { $docHeaderButtons['SHORTCUT'] = $this->doc->makeShortcutIcon('id', implode(',', array_keys($this->MOD_MENU)), $this->MCONF['name']); } - + $module = $this->pageinfo['module']; if (!$module) { $pidrec=BackendUtility::getRecord('pages', intval($this->pageinfo['pid'])); $module=$pidrec['module']; } - + if ($module == 'dmail') { // Direct mail module // Render content: @@ -213,45 +211,45 @@ function jumpToUrlD(URL) { // $markers['CONTENT'] = '

' . $this->getLanguageService()->getLL('stats_overview_header') . '

' . $this->moduleContent(); } elseif ($this->id != 0) { $markers['FLASHMESSAGES'] = GeneralUtility::makeInstance(FlashMessageRendererResolver::class) - ->resolve() - ->render([ - GeneralUtility::makeInstance( - FlashMessage::class, - $this->getLanguageService()->getLL('dmail_noRegular'), - $this->getLanguageService()->getLL('dmail_newsletters'), - FlashMessage::WARNING - ) - ]); - } - } else { - $markers['FLASHMESSAGES'] = GeneralUtility::makeInstance(FlashMessageRendererResolver::class) ->resolve() ->render([ GeneralUtility::makeInstance( FlashMessage::class, - $this->getLanguageService()->getLL('select_folder'), - $this->getLanguageService()->getLL('header_stat'), + $this->getLanguageService()->getLL('dmail_noRegular'), + $this->getLanguageService()->getLL('dmail_newsletters'), FlashMessage::WARNING - ) + ) ]); - + } + } else { + $markers['FLASHMESSAGES'] = GeneralUtility::makeInstance(FlashMessageRendererResolver::class) + ->resolve() + ->render([ + GeneralUtility::makeInstance( + FlashMessage::class, + $this->getLanguageService()->getLL('select_folder'), + $this->getLanguageService()->getLL('header_stat'), + FlashMessage::WARNING + ) + ]); + $markers['CONTENT'] = '

' . $this->getLanguageService()->getLL('stats_overview_header') . '

'; } - + $this->content = $this->doc->startPage($this->getLanguageService()->getLL('stats_overview_header')); - $this->content.= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers, array()); + $this->content.= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers, []); } else { // If no access or if ID == zero - + $this->doc = GeneralUtility::makeInstance(DocumentTemplate::class); $this->doc->backPath = $GLOBALS['BACK_PATH']; - + $this->content .= $this->doc->startPage($this->getLanguageService()->getLL('title')); $this->content .= '

' . htmlspecialchars($this->getLanguageService()->getLL('title')) . '

'; // $this->doc->header $this->content .= '
'; } } - + /** * Compiled content of the module * @@ -260,51 +258,51 @@ function jumpToUrlD(URL) { // public function moduleContent() { $theOutput = ''; - + if (!$this->sys_dmail_uid) { $theOutput = $this->cmd_displayPageInfo(); } else { // Here the single dmail record is shown. $this->sys_dmail_uid = intval($this->sys_dmail_uid); - + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_dmail'); $queryBuilder - ->getRestrictions() - ->removeAll() - ->add(GeneralUtility::makeInstance(DeletedRestriction::class)); + ->getRestrictions() + ->removeAll() + ->add(GeneralUtility::makeInstance(DeletedRestriction::class)); $res = $queryBuilder->select('*') - ->from('sys_dmail') - ->add('where', 'pid=' . intval($this->id) . - ' AND uid=' . intval($this->sys_dmail_uid)) + ->from('sys_dmail') + ->add('where', 'pid=' . intval($this->id) . + ' AND uid=' . intval($this->sys_dmail_uid)) ->execute(); - - $this->noView = 0; - if (($row = $res->fetch())) { - // Set URL data for commands - $this->setURLs($row); - - // COMMAND: - switch ($this->CMD) { - case 'displayUserInfo': - $theOutput = $this->cmd_displayUserInfo(); - break; - case 'stats': - $theOutput = $this->cmd_stats($row); - break; - default: - // Hook for handling of custom direct mail commands: - if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXT']['directmail']['handledirectmailcmd-' . $this->CMD])) { - foreach ($GLOBALS['TYPO3_CONF_VARS']['EXT']['directmail']['handledirectmailcmd-' . $this->CMD] as $funcRef) { - $params = array('pObj' => &$this); - $theOutput = GeneralUtility::callUserFunction($funcRef, $params, $this); + + $this->noView = 0; + if (($row = $res->fetch())) { + // Set URL data for commands + $this->setURLs($row); + + // COMMAND: + switch ($this->CMD) { + case 'displayUserInfo': + $theOutput = $this->cmd_displayUserInfo(); + break; + case 'stats': + $theOutput = $this->cmd_stats($row); + break; + default: + // Hook for handling of custom direct mail commands: + if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXT']['directmail']['handledirectmailcmd-' . $this->CMD])) { + foreach ($GLOBALS['TYPO3_CONF_VARS']['EXT']['directmail']['handledirectmailcmd-' . $this->CMD] as $funcRef) { + $params = ['pObj' => &$this]; + $theOutput = GeneralUtility::callUserFunction($funcRef, $params, $this); + } } - } + } } - } } return $theOutput; } - + /** * Shows user's info and categories * @@ -315,26 +313,26 @@ public function cmd_displayUserInfo() $uid = intval(GeneralUtility::_GP('uid')); $indata = GeneralUtility::_GP('indata'); $table = GeneralUtility::_GP('table'); - + $mmTable = $GLOBALS['TCA'][$table]['columns']['module_sys_dmail_category']['config']['MM']; - + if (GeneralUtility::_GP('submit')) { $indata = GeneralUtility::_GP('indata'); if (!$indata) { $indata['html']= 0; } } - + switch ($table) { case 'tt_address': // see fe_users case 'fe_users': if (is_array($indata)) { - $data=array(); + $data = []; if (is_array($indata['categories'])) { reset($indata['categories']); foreach ($indata['categories'] as $recValues) { - $enabled = array(); + $enabled = []; foreach ($recValues as $k => $b) { if ($b) { $enabled[] = $k; @@ -344,74 +342,74 @@ public function cmd_displayUserInfo() } } $data[$table][$uid]['module_sys_dmail_html'] = $indata['html'] ? 1 : 0; - + /* @var $tce \TYPO3\CMS\Core\DataHandling\DataHandler */ $tce = GeneralUtility::makeInstance(DataHandler::class); - $tce->stripslashes_values=0; - $tce->start($data, array()); + $tce->stripslashes_values = 0; + $tce->start($data, []); $tce->process_datamap(); } break; default: // do nothing } - + switch ($table) { case 'tt_address': - + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_language'); $res = $queryBuilder - ->select('tt_address.*') - ->from('tt_address','tt_address') - ->leftjoin( - 'tt_address', - 'pages', - 'pages', - $queryBuilder->expr()->eq('pages.uid', $queryBuilder->quoteIdentifier('tt_address.pid')) + ->select('tt_address.*') + ->from('tt_address','tt_address') + ->leftjoin( + 'tt_address', + 'pages', + 'pages', + $queryBuilder->expr()->eq('pages.uid', $queryBuilder->quoteIdentifier('tt_address.pid')) ) ->add('where','tt_address.uid=' . intval($uid) . ' AND ' . $this->perms_clause . ' AND pages.deleted = 0') - ->execute(); - break; + ->execute(); + break; case 'fe_users': $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('fe_users'); $res = $queryBuilder - ->select('fe_users.*') - ->from('fe_users','fe_users') - ->leftjoin( - 'fe_users', - 'pages', - 'pages', - $queryBuilder->expr()->eq('pages.uid', $queryBuilder->quoteIdentifier('fe_users.pid')) + ->select('fe_users.*') + ->from('fe_users','fe_users') + ->leftjoin( + 'fe_users', + 'pages', + 'pages', + $queryBuilder->expr()->eq('pages.uid', $queryBuilder->quoteIdentifier('fe_users.pid')) ) ->add('where','fe_users.uid=' . intval($uid) . ' AND ' . $this->perms_clause . ' AND pages.deleted = 0') - ->execute(); - break; + ->execute(); + break; default: // do nothing } - - $row = array(); + + $row = []; if ($res) { $row = $res->fetch(); } - + $theOutput = ''; if (is_array($row)) { $categories = ''; - + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($mmTable); $resCat = $queryBuilder - ->select('uid_foreign') - ->from($mmTable) - ->add('where','uid_local=' . $row['uid']) - ->execute(); + ->select('uid_foreign') + ->from($mmTable) + ->add('where','uid_local=' . $row['uid']) + ->execute(); while (($rowCat = $resCat->fetch())) { $categories .= $rowCat['uid_foreign'] . ','; } $categories = rtrim($categories, ','); - + $editOnClickLink = DirectMailUtility::getEditOnClickLink([ 'edit' => [ $table => [ @@ -420,38 +418,38 @@ public function cmd_displayUserInfo() ], 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI'), ]); - + $out = ''; $out .= $this->iconFactory->getIconForRecord($table, $row)->render() . htmlspecialchars($row['name'] . ' <' . $row['email'] . '>'); $out .= '  ' . $this->iconFactory->getIcon('actions-open', Icon::SIZE_SMALL) . $this->getLanguageService()->getLL('dmail_edit') . ''; - $theOutput = '

' . $this->getLanguageService()->getLL('subscriber_info') . '

' . $out; - - $out = ''; - - $this->categories = DirectMailUtility::makeCategories($table, $row, $this->sys_language_uid); - - foreach ($this->categories as $pKey => $pVal) { - $out .='' . - ' ' . - htmlspecialchars($pVal) . '
'; - } - $out .= '

'; - $out .= $this->getLanguageService()->getLL('subscriber_profile_htmlemail') . '
'; - - $out .= '' . - '' . - '
' . - ''; - $theOutput .= '
'; - $theOutput .= '

' . $this->getLanguageService()->getLL('subscriber_profile') . '

' . - $this->getLanguageService()->getLL('subscriber_profile_instructions') . '

' . $out; + $theOutput = '

' . $this->getLanguageService()->getLL('subscriber_info') . '

' . $out; + + $out = ''; + + $this->categories = DirectMailUtility::makeCategories($table, $row, $this->sys_language_uid); + + foreach ($this->categories as $pKey => $pVal) { + $out .='' . + ' ' . + htmlspecialchars($pVal) . '
'; + } + $out .= '

'; + $out .= $this->getLanguageService()->getLL('subscriber_profile_htmlemail') . '
'; + + $out .= '' . + '' . + '
' . + ''; + $theOutput .= '
'; + $theOutput .= '

' . $this->getLanguageService()->getLL('subscriber_profile') . '

' . + $this->getLanguageService()->getLL('subscriber_profile_instructions') . '

' . $out; } - + return $theOutput; } - + /** * Shows the info of a page * @@ -460,45 +458,43 @@ public function cmd_displayUserInfo() public function cmd_displayPageInfo() { // Here the dmail list is rendered: - + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_dmail'); $queryBuilder - ->getRestrictions() - ->removeAll() - ->add(GeneralUtility::makeInstance(DeletedRestriction::class)); + ->getRestrictions() + ->removeAll() + ->add(GeneralUtility::makeInstance(DeletedRestriction::class)); $res = $queryBuilder - ->selectLiteral('sys_dmail.uid', 'sys_dmail.subject', 'sys_dmail.scheduled', 'sys_dmail.scheduled_begin', 'sys_dmail.scheduled_end', 'COUNT(sys_dmail_maillog.mid) AS count') - ->from('sys_dmail','sys_dmail') - ->leftJoin( - 'sys_dmail', - 'sys_dmail_maillog', - 'sys_dmail_maillog', - $queryBuilder->expr()->eq('sys_dmail.uid', $queryBuilder->quoteIdentifier('sys_dmail_maillog.mid')) + ->selectLiteral('sys_dmail.uid', 'sys_dmail.subject', 'sys_dmail.scheduled', 'sys_dmail.scheduled_begin', 'sys_dmail.scheduled_end', 'COUNT(sys_dmail_maillog.mid) AS count') + ->from('sys_dmail','sys_dmail') + ->leftJoin( + 'sys_dmail', + 'sys_dmail_maillog', + 'sys_dmail_maillog', + $queryBuilder->expr()->eq('sys_dmail.uid', $queryBuilder->quoteIdentifier('sys_dmail_maillog.mid')) ) ->add('where','sys_dmail.pid=' . intval($this->id) . ' AND sys_dmail.type IN (0,1)' . ' AND sys_dmail.issent = 1'. ' AND sys_dmail_maillog.response_type=0'. ' AND sys_dmail_maillog.html_sent>0') - ->groupBy('sys_dmail_maillog.mid') - ->orderBy('sys_dmail.scheduled','DESC') - ->addOrderBy('sys_dmail.scheduled_begin','DESC') - ->execute() - ->fetchAll(); - - - if ($res) { - $onClick = ' onClick="return confirm(' . GeneralUtility::quoteJSvalue(sprintf($this->getLanguageService()->getLL('nl_l_warning'), count($res))) . ');"'; - - } else { - $onClick = ''; - } - $out = ''; - - - if ($res) { - $out .=''; - $out .=' + ->groupBy('sys_dmail_maillog.mid') + ->orderBy('sys_dmail.scheduled','DESC') + ->addOrderBy('sys_dmail.scheduled_begin','DESC') + ->execute() + ->fetchAll(); + + if ($res) { + $onClick = ' onClick="return confirm(' . GeneralUtility::quoteJSvalue(sprintf($this->getLanguageService()->getLL('nl_l_warning'), count($res))) . ');"'; + + } else { + $onClick = ''; + } + $out = ''; + + if ($res) { + $out .='
'; + $out .=' @@ -507,21 +503,20 @@ public function cmd_displayPageInfo() '; - - - foreach ($res as $row) { - - if (!empty($row['scheduled_begin'])) { - if (!empty($row['scheduled_end'])) { - $sent = $this->getLanguageService()->getLL('stats_overview_sent'); - } else { - $sent = $this->getLanguageService()->getLL('stats_overview_sending'); - } - } else { - $sent = $this->getLanguageService()->getLL('stats_overview_queuing'); - } - - $out.=' + + foreach ($res as $row) { + + if (!empty($row['scheduled_begin'])) { + if (!empty($row['scheduled_end'])) { + $sent = $this->getLanguageService()->getLL('stats_overview_sent'); + } else { + $sent = $this->getLanguageService()->getLL('stats_overview_sending'); + } + } else { + $sent = $this->getLanguageService()->getLL('stats_overview_queuing'); + } + + $out.=' @@ -530,17 +525,17 @@ public function cmd_displayPageInfo() '; - } - $out.='
  ' . $this->getLanguageService()->getLL('stats_overview_subject') . ' ' . $this->getLanguageService()->getLL('stats_overview_scheduled') . '' . $this->getLanguageService()->getLL('stats_overview_total_sent') . ' ' . $this->getLanguageService()->getLL('stats_overview_status') . '
' . $this->iconFactory->getIconForRecord('sys_dmail', $row, Icon::SIZE_SMALL)->render() . ' ' . $this->linkDMail_record(GeneralUtility::fixed_lgd_cs($row['subject'], 30) . ' ', $row['uid'], $row['subject']) . '   ' . BackendUtility::datetime($row['scheduled']) . '' . ($row['count']?$row['count']:' ') . ' ' . $sent . '
'; - } - - $theOutput = '

' . $this->getLanguageService()->getLL('stats_overview_choose') . '

' . - $out; - $theOutput .= '
'; - - return $theOutput; + } + $out.=''; + } + + $theOutput = '

' . $this->getLanguageService()->getLL('stats_overview_choose') . '

' . + $out; + $theOutput .= '
'; + + return $theOutput; } - + /** * Wrap a string with a link * @@ -563,10 +558,10 @@ public function linkDMail_record($str, $uid, $aTitle='') 'CMD' => 'stats', 'SET[dmail_mode]' => 'direct' ] - ); + ); return '' . htmlspecialchars($str) . ''; } - + /** * Get statistics from DB and compile them. * @@ -590,13 +585,13 @@ public function cmd_stats($row) 'CMD' => $this->CMD, 'recalcCache' => 1 ] - ); + ); $output = $this->directMail_compactView($row); - + // ***************************** // Mail responses, general: // ***************************** - + $mailingId = intval($row['uid']); $fieldRows = 'response_type'; $addFieldRows = '*'; @@ -605,102 +600,98 @@ public function cmd_stats($row) $groupByRows = 'response_type'; $orderByRows = ''; $queryArray = [$fieldRows, $addFieldRows, $tableRows, $whereRows, $groupByRows, $orderByRows]; - + $table = $this->getQueryRows($queryArray, 'response_type'); - + // Plaintext/HTML $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_dmail_maillog'); - + $res = $queryBuilder - ->count('*') - ->addSelect('html_sent') - ->from('sys_dmail_maillog') - ->add('where','mid=' . $mailingId . ' AND response_type=0') - ->groupBy('html_sent') - ->execute() - ->fetchAll(); - + ->count('*') + ->addSelect('html_sent') + ->from('sys_dmail_maillog') + ->add('where','mid=' . $mailingId . ' AND response_type=0') + ->groupBy('html_sent') + ->execute() + ->fetchAll(); + /* this function is called to change the key from 'COUNT(*)' to 'counter' */ $res = $this->changekeyname($res,'counter','COUNT(*)'); - - - $textHtml = array(); + + $textHtml = []; foreach($res as $row2){ // 0:No mail; 1:HTML; 2:TEXT; 3:HTML+TEXT $textHtml[$row2['html_sent']] = $row2['counter']; } - - + // Unique responses, html $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_dmail_maillog'); - + $res = $queryBuilder - ->count('*') - ->from('sys_dmail_maillog') - ->add('where','mid=' . $mailingId . ' AND response_type=1') - ->groupBy('rid') - ->addGroupBy('rtbl') - ->orderBy('COUNT(*)') - ->execute() - ->fetchAll(); - + ->count('*') + ->from('sys_dmail_maillog') + ->add('where','mid=' . $mailingId . ' AND response_type=1') + ->groupBy('rid') + ->addGroupBy('rtbl') + ->orderBy('COUNT(*)') + ->execute() + ->fetchAll(); + $uniqueHtmlResponses = count($res);//sql_num_rows($res); - - + // Unique responses, Plain - $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_dmail_maillog'); - + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_dmail_maillog'); + $res = $queryBuilder - ->count('*') - ->from('sys_dmail_maillog') - ->add('where','mid=' . $mailingId . ' AND response_type=2') - ->groupBy('rid') - ->addGroupBy('rtbl') - ->orderBy('COUNT(*)') - ->execute() - ->fetchAll(); + ->count('*') + ->from('sys_dmail_maillog') + ->add('where','mid=' . $mailingId . ' AND response_type=2') + ->groupBy('rid') + ->addGroupBy('rtbl') + ->orderBy('COUNT(*)') + ->execute() + ->fetchAll(); $uniquePlainResponses = count($res); //sql_num_rows($res); - - + // Unique responses, pings $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_dmail_maillog'); - + $res = $queryBuilder - ->count('*') - ->from('sys_dmail_maillog') - ->add('where','mid=' . $mailingId . ' AND response_type=-1') - ->groupBy('rid') - ->addGroupBy('rtbl') - ->orderBy('COUNT(*)') - ->execute() - ->fetchAll(); + ->count('*') + ->from('sys_dmail_maillog') + ->add('where','mid=' . $mailingId . ' AND response_type=-1') + ->groupBy('rid') + ->addGroupBy('rtbl') + ->orderBy('COUNT(*)') + ->execute() + ->fetchAll(); $uniquePingResponses = count($res);//sql_num_rows($res); - ; - - $tblLines = array(); + ; + + $tblLines = []; $tblLines[]=array('',$this->getLanguageService()->getLL('stats_total'),$this->getLanguageService()->getLL('stats_HTML'),$this->getLanguageService()->getLL('stats_plaintext')); - + $totalSent = intval($textHtml['1'] + $textHtml['2'] + $textHtml['3']); $htmlSent = intval($textHtml['1']+$textHtml['3']); $plainSent = intval($textHtml['2']); - + $tblLines[] = array($this->getLanguageService()->getLL('stats_mails_sent'),$totalSent,$htmlSent,$plainSent); $tblLines[] = array($this->getLanguageService()->getLL('stats_mails_returned'),$this->showWithPercent($table['-127']['counter'], $totalSent)); $tblLines[] = array($this->getLanguageService()->getLL('stats_HTML_mails_viewed'),'',$this->showWithPercent($uniquePingResponses, $htmlSent)); $tblLines[] = array($this->getLanguageService()->getLL('stats_unique_responses'),$this->showWithPercent($uniqueHtmlResponses+$uniquePlainResponses, $totalSent),$this->showWithPercent($uniqueHtmlResponses, $htmlSent),$this->showWithPercent($uniquePlainResponses, $plainSent?$plainSent:$htmlSent)); - + $output.='

' . $this->getLanguageService()->getLL('stats_general_information') . '

'; - $output.= DirectMailUtility::formatTable($tblLines, array('nowrap', 'nowrap', 'nowrap', 'nowrap'), 1, array()); - + $output.= DirectMailUtility::formatTable($tblLines, array('nowrap', 'nowrap', 'nowrap', 'nowrap'), 1, []); + // ****************** // Links: // ****************** - + // initialize $urlCounter $urlCounter = array( - 'total' => array(), - 'plain' => array(), - 'html' => array(), + 'total' => [], + 'plain' => [], + 'html' => [], ); // Most popular links, html: $fieldRows = 'url_id'; @@ -712,7 +703,7 @@ public function cmd_stats($row) //$queryArray = array('url_id,count(*) as counter', 'sys_dmail_maillog', 'mid=' . intval($row['uid']) . ' AND response_type=1', 'url_id', 'counter'); $queryArray = [$fieldRows, $addFieldRows, $tableRows, $whereRows, $groupByRows, $orderByRows]; $htmlUrlsTable=$this->getQueryRows($queryArray, 'url_id'); - + // Most popular links, plain: $fieldRows = 'url_id'; $addFieldRows = '*'; @@ -723,14 +714,14 @@ public function cmd_stats($row) //$queryArray = array('url_id,count(*) as counter', 'sys_dmail_maillog', 'mid=' . intval($row['uid']) . ' AND response_type=2', 'url_id', 'counter'); $queryArray = [$fieldRows, $addFieldRows, $tableRows, $whereRows, $groupByRows, $orderByRows]; $plainUrlsTable=$this->getQueryRows($queryArray, 'url_id'); - - + + // Find urls: $unpackedMail = unserialize(base64_decode($row['mailContent'])); // this array will include a unique list of all URLs that are used in the mailing - $urlArr = array(); - - $urlMd5Map = array(); + $urlArr = []; + + $urlMd5Map = []; if (is_array($unpackedMail['html']['hrefs'])) { foreach ($unpackedMail['html']['hrefs'] as $k => $v) { // convert & of query params back @@ -743,9 +734,9 @@ public function cmd_stats($row) $urlArr[intval(-$k)] = $v; } } - + // Traverse plain urls: - $mappedPlainUrlsTable = array(); + $mappedPlainUrlsTable = []; foreach ($plainUrlsTable as $id => $c) { $url = $urlArr[intval($id)]; if (isset($urlMd5Map[md5($url)])) { @@ -754,18 +745,18 @@ public function cmd_stats($row) $mappedPlainUrlsTable[$id] = $c; } } - - $urlCounter['total'] = array(); + + $urlCounter['total'] = []; // Traverse html urls: - $urlCounter['html'] = array(); + $urlCounter['html'] = []; if (count($htmlUrlsTable) > 0) { foreach ($htmlUrlsTable as $id => $c) { $urlCounter['html'][$id]['counter'] = $urlCounter['total'][$id]['counter'] = $c['counter']; } } - + // Traverse plain urls: - $urlCounter['plain'] = array(); + $urlCounter['plain'] = []; foreach ($mappedPlainUrlsTable as $id => $c) { // Look up plain url in html urls $htmlLinkFound = false; @@ -783,8 +774,8 @@ public function cmd_stats($row) $urlCounter['total'][$id]['counter'] = $urlCounter['total'][$id]['counter'] + $c['counter']; } } - - $tblLines = array(); + + $tblLines = []; $tblLines[] = array('',$this->getLanguageService()->getLL('stats_total'),$this->getLanguageService()->getLL('stats_HTML'),$this->getLanguageService()->getLL('stats_plaintext')); $tblLines[] = array($this->getLanguageService()->getLL('stats_total_responses'),$table['1']['counter'] + $table['2']['counter'],$table['1']['counter']?$table['1']['counter']:'0',$table['2']['counter']?$table['2']['counter']:'0'); $tblLines[] = array($this->getLanguageService()->getLL('stats_unique_responses'),$this->showWithPercent($uniqueHtmlResponses+$uniquePlainResponses, $totalSent), $this->showWithPercent($uniqueHtmlResponses, $htmlSent), $this->showWithPercent($uniquePlainResponses, $plainSent?$plainSent:$htmlSent)); @@ -793,23 +784,23 @@ public function cmd_stats($row) ($uniqueHtmlResponses ? number_format(($table['1']['counter'])/($uniqueHtmlResponses), 2) : '-'), ($uniquePlainResponses ? number_format(($table['2']['counter'])/($uniquePlainResponses), 2) : '-') ); - + $output.='

' . $this->getLanguageService()->getLL('stats_response') . '

'; $output.=DirectMailUtility::formatTable($tblLines, array('nowrap', 'nowrap', 'nowrap', 'nowrap'), 1, array(0, 0, 0, 0)); - + arsort($urlCounter['total']); arsort($urlCounter['html']); arsort($urlCounter['plain']); reset($urlCounter['total']); - - $tblLines = array(); + + $tblLines = []; $tblLines[] = array('',$this->getLanguageService()->getLL('stats_HTML_link_nr'),$this->getLanguageService()->getLL('stats_plaintext_link_nr'),$this->getLanguageService()->getLL('stats_total'),$this->getLanguageService()->getLL('stats_HTML'),$this->getLanguageService()->getLL('stats_plaintext'),''); - + // HTML mails if (intval($row['sendOptions']) & 0x2) { $htmlContent = $unpackedMail['html']['content']; - - $htmlLinks = array(); + + $htmlLinks = []; if (is_array($unpackedMail['html']['hrefs'])) { foreach ($unpackedMail['html']['hrefs'] as $jumpurlId => $data) { $htmlLinks[$jumpurlId] = array( @@ -818,54 +809,54 @@ public function cmd_stats($row) ); } } - + // Parse mail body $dom = new \DOMDocument; @$dom->loadHTML($htmlContent); - $links = array(); + $links = []; // Get all links foreach ($dom->getElementsByTagName('a') as $node) { $links[] = $node; } - + // Process all links found foreach ($links as $link) { /* @var \DOMElement $link */ $url = $link->getAttribute('href'); - + if (empty($url)) { // Drop a tags without href continue; } - + if (GeneralUtility::isFirstPartOfStr($url, 'mailto:')) { // Drop mail links continue; } - + $parsedUrl = GeneralUtility::explodeUrl2Array($url); - + if (!array_key_exists('jumpurl', $parsedUrl)) { // Ignore non-jumpurl links continue; } - + $jumpurlId = $parsedUrl['jumpurl']; $targetUrl = $htmlLinks[$jumpurlId]['url']; - + $title = $link->getAttribute('title'); - + if (!empty($title)) { // no title attribute $label = '' . GeneralUtility::fixed_lgd_cs(substr($targetUrl, -40), 40) . ''; } else { $label = '' . GeneralUtility::fixed_lgd_cs(substr($targetUrl, -40), 40) . ''; } - + $htmlLinks[$jumpurlId]['label'] = $label; } } - + foreach ($urlCounter['total'] as $id => $_) { // $id is the jumpurl ID $origId = $id; @@ -874,11 +865,11 @@ public function cmd_stats($row) // a link to this host? $uParts = @parse_url($url); $urlstr = $this->getUrlStr($uParts); - + $label = $this->getLinkLabel($url, $urlstr, false, $htmlLinks[$id]['label']); - + $img = '' . $this->iconFactory->getIcon('apps-toolbar-menu-search', Icon::SIZE_SMALL) . ''; - + if (isset($urlCounter['html'][$id]['plainId'])) { $tblLines[] = array( $label, @@ -902,8 +893,8 @@ public function cmd_stats($row) ); } } - - + + // go through all links that were not clicked yet and that have a label $clickedLinks = array_keys($urlCounter['total']); foreach ($urlArr as $id => $link) { @@ -911,7 +902,7 @@ public function cmd_stats($row) // a link to this host? $uParts = @parse_url($link); $urlstr = $this->getUrlStr($uParts); - + $label = $htmlLinks[$id]['label'] . ' (' . ($urlstr ? $urlstr : '/') . ')'; $img = '' . $this->iconFactory->getIcon('apps-toolbar-menu-search', Icon::SIZE_SMALL) . ''; $tblLines[] = array( @@ -925,19 +916,19 @@ public function cmd_stats($row) ); } } - + if ($urlCounter['total']) { $output .= '

' . $this->getLanguageService()->getLL('stats_response_link') . '

'; - + /** * Hook for cmd_stats_linkResponses */ if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['direct_mail']['mod4']['cmd_stats_linkResponses'])) { - $hookObjectsArr = array(); + $hookObjectsArr = []; foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['direct_mail']['mod4']['cmd_stats_linkResponses'] as $classRef) { $hookObjectsArr[] = GeneralUtility::makeInstance($classRef); } - + foreach ($hookObjectsArr as $hookObj) { if (method_exists($hookObj, 'cmd_stats_linkResponses')) { $output .= $hookObj->cmd_stats_linkResponses($tblLines, $this); @@ -947,50 +938,50 @@ public function cmd_stats($row) $output .= DirectMailUtility::formatTable($tblLines, array('nowrap', 'nowrap width="100"', 'nowrap width="100"', 'nowrap', 'nowrap', 'nowrap', 'nowrap'), 1, array(1, 0, 0, 0, 0, 0, 1)); } } - - - - + + + + // ****************** // Returned mails // ****************** - + // The icons: $listIcons = $this->iconFactory->getIcon('actions-system-list-open', Icon::SIZE_SMALL); $csvIcons = $this->iconFactory->getIcon('actions-document-export-csv', Icon::SIZE_SMALL); $hideIcons = $this->iconFactory->getIcon('actions-lock', Icon::SIZE_SMALL); - + // Icons mails returned $iconsMailReturned[] = ' ' . $listIcons . ''; $iconsMailReturned[] = ' ' . $hideIcons . ''; $iconsMailReturned[] = ' ' . $csvIcons . ''; - + // Icons unknown recip $iconsUnknownRecip[] = ' ' . $listIcons . ''; $iconsUnknownRecip[] = ' ' . $hideIcons . ''; $iconsUnknownRecip[] = ' ' . $csvIcons . ''; - + // Icons mailbox full $iconsMailbox[] = ' ' . $listIcons . ''; $iconsMailbox[] = ' ' . $hideIcons . ''; $iconsMailbox[] = ' ' . $csvIcons . ''; - + // Icons bad host $iconsBadhost[] = ' ' . $listIcons . ''; $iconsBadhost[] = ' ' . $hideIcons . ''; $iconsBadhost[] = ' ' . $csvIcons . ''; - + // Icons bad header $iconsBadheader[] = ' ' . $listIcons . ''; $iconsBadheader[] = ' ' . $hideIcons . ''; $iconsBadheader[] = ' ' . $csvIcons . ''; - + // Icons unknown reasons // TODO: link to show all reason $iconsUnknownReason[] = ' ' . $listIcons . ''; $iconsUnknownReason[] = ' ' . $hideIcons . ''; $iconsUnknownReason[] = ' ' . $csvIcons . ''; - + // Table with Icon $fieldRows = 'return_code'; $addFieldRows = '*'; @@ -1001,8 +992,8 @@ public function cmd_stats($row) $queryArray = [$fieldRows, $addFieldRows, $tableRows, $whereRows, $groupByRows, $orderByRows]; //$queryArray = array('COUNT(*) as counter'.','.'return_code', 'sys_dmail_maillog', 'mid=' . intval($row['uid']) . ' AND response_type=-127', 'return_code'); $responseResult = $this->getQueryRows($queryArray, 'return_code'); - - $tblLines = array(); + + $tblLines = []; $tblLines[] = array('',$this->getLanguageService()->getLL('stats_count'),''); $tblLines[] = array($this->getLanguageService()->getLL('stats_total_mails_returned'), ($table['-127']['counter']?number_format(intval($table['-127']['counter'])):'0'), implode(' ', $iconsMailReturned)); $tblLines[] = array($this->getLanguageService()->getLL('stats_recipient_unknown'), $this->showWithPercent($responseResult['550']['counter']+$responseResult['553']['counter'], $table['-127']['counter']), implode(' ', $iconsUnknownRecip)); @@ -1010,484 +1001,484 @@ public function cmd_stats($row) $tblLines[] = array($this->getLanguageService()->getLL('stats_bad_host'), $this->showWithPercent($responseResult['552']['counter'], $table['-127']['counter']), implode(' ', $iconsBadhost)); $tblLines[] = array($this->getLanguageService()->getLL('stats_error_in_header'), $this->showWithPercent($responseResult['554']['counter'], $table['-127']['counter']),implode(' ', $iconsBadheader)); $tblLines[] = array($this->getLanguageService()->getLL('stats_reason_unkown'), $this->showWithPercent($responseResult['-1']['counter'], $table['-127']['counter']),implode(' ', $iconsUnknownReason)); - + $output.='

' . $this->getLanguageService()->getLL('stats_mails_returned') . '

'; $output .= DirectMailUtility::formatTable($tblLines, array('nowrap', 'nowrap', ''), 1, array(0, 0, 1)); - + // Find all returned mail if (GeneralUtility::_GP('returnList')||GeneralUtility::_GP('returnDisable')||GeneralUtility::_GP('returnCSV')) { $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) - ->getQueryBuilderForTable('sys_dmail_maillog'); + ->getQueryBuilderForTable('sys_dmail_maillog'); $res = $queryBuilder - ->select('rid','rtbl','email') - ->from('sys_dmail_maillog') - ->add('where','mid=' . intval($row['uid']) . - ' AND response_type=-127') + ->select('rid','rtbl','email') + ->from('sys_dmail_maillog') + ->add('where','mid=' . intval($row['uid']) . + ' AND response_type=-127') ->execute(); - - - $idLists = array(); - - while (($rrow = $res->fetch())) { - switch ($rrow['rtbl']) { - case 't': - $idLists['tt_address'][]=$rrow['rid']; - break; - case 'f': - $idLists['fe_users'][]=$rrow['rid']; - break; - case 'P': - $idLists['PLAINLIST'][] = $rrow['email']; - break; - default: - $idLists[$rrow['rtbl']][]=$rrow['rid']; - } - } - - if (GeneralUtility::_GP('returnList')) { - if (is_array($idLists['tt_address'])) { - $output .= '

' . $this->getLanguageService()->getLL('stats_emails') . '

' . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address', $this->id, 1, $this->sys_dmail_uid); - } - if (is_array($idLists['fe_users'])) { - $output .= '

' . $this->getLanguageService()->getLL('stats_website_users') . '

' . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users', $this->id, 1, $this->sys_dmail_uid); - } - if (is_array($idLists['PLAINLIST'])) { - $output .= '

' . $this->getLanguageService()->getLL('stats_plainlist') . '

'; - $output .= '
  • ' . join('
  • ', $idLists['PLAINLIST']) . '
'; - } - } - if (GeneralUtility::_GP('returnDisable')) { - if (is_array($idLists['tt_address'])) { - $c=$this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address'); - $output.='
' . $c . ' ' . $this->getLanguageService()->getLL('stats_emails_disabled'); - } - if (is_array($idLists['fe_users'])) { - $c=$this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users'); - $output.='
' . $c . ' ' . $this->getLanguageService()->getLL('stats_website_users_disabled'); + + + $idLists = []; + + while (($rrow = $res->fetch())) { + switch ($rrow['rtbl']) { + case 't': + $idLists['tt_address'][]=$rrow['rid']; + break; + case 'f': + $idLists['fe_users'][]=$rrow['rid']; + break; + case 'P': + $idLists['PLAINLIST'][] = $rrow['email']; + break; + default: + $idLists[$rrow['rtbl']][]=$rrow['rid']; + } } - } - if (GeneralUtility::_GP('returnCSV')) { - $emails=array(); - if (is_array($idLists['tt_address'])) { - $arr=DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'); - foreach ($arr as $v) { - $emails[]=$v['email']; + + if (GeneralUtility::_GP('returnList')) { + if (is_array($idLists['tt_address'])) { + $output .= '

' . $this->getLanguageService()->getLL('stats_emails') . '

' . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address', $this->id, 1, $this->sys_dmail_uid); + } + if (is_array($idLists['fe_users'])) { + $output .= '

' . $this->getLanguageService()->getLL('stats_website_users') . '

' . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users', $this->id, 1, $this->sys_dmail_uid); + } + if (is_array($idLists['PLAINLIST'])) { + $output .= '

' . $this->getLanguageService()->getLL('stats_plainlist') . '

'; + $output .= '
  • ' . join('
  • ', $idLists['PLAINLIST']) . '
'; } } - if (is_array($idLists['fe_users'])) { - $arr=DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'); - foreach ($arr as $v) { - $emails[]=$v['email']; + if (GeneralUtility::_GP('returnDisable')) { + if (is_array($idLists['tt_address'])) { + $c=$this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address'); + $output.='
' . $c . ' ' . $this->getLanguageService()->getLL('stats_emails_disabled'); + } + if (is_array($idLists['fe_users'])) { + $c=$this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users'); + $output.='
' . $c . ' ' . $this->getLanguageService()->getLL('stats_website_users_disabled'); } } - if (is_array($idLists['PLAINLIST'])) { - $emails = array_merge($emails, $idLists['PLAINLIST']); + if (GeneralUtility::_GP('returnCSV')) { + $emails=[]; + if (is_array($idLists['tt_address'])) { + $arr=DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'); + foreach ($arr as $v) { + $emails[]=$v['email']; + } + } + if (is_array($idLists['fe_users'])) { + $arr=DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'); + foreach ($arr as $v) { + $emails[]=$v['email']; + } + } + if (is_array($idLists['PLAINLIST'])) { + $emails = array_merge($emails, $idLists['PLAINLIST']); + } + $output .= '
' . $this->getLanguageService()->getLL('stats_emails_returned_list') . '
'; + $output .= ''; } - $output .= '
' . $this->getLanguageService()->getLL('stats_emails_returned_list') . '
'; - $output .= ''; - } } - + // Find Unknown Recipient if (GeneralUtility::_GP('unknownList')||GeneralUtility::_GP('unknownDisable')||GeneralUtility::_GP('unknownCSV')) { - + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) - ->getQueryBuilderForTable('sys_dmail_maillog'); + ->getQueryBuilderForTable('sys_dmail_maillog'); $res = $queryBuilder - ->select('rid','rtbl','email') - ->from('sys_dmail_maillog') - ->add('where','mid=' . intval($row['uid']) . - ' AND response_type=-127' . - ' AND (return_code=550 OR return_code=553)') + ->select('rid','rtbl','email') + ->from('sys_dmail_maillog') + ->add('where','mid=' . intval($row['uid']) . + ' AND response_type=-127' . + ' AND (return_code=550 OR return_code=553)') ->execute(); - $idLists = array(); - while (($rrow = $res->fetch())) { - switch ($rrow['rtbl']) { - case 't': - $idLists['tt_address'][]=$rrow['rid']; - break; - case 'f': - $idLists['fe_users'][]=$rrow['rid']; - break; - case 'P': - $idLists['PLAINLIST'][] = $rrow['email']; - break; - default: - $idLists[$rrow['rtbl']][]=$rrow['rid']; - } - } - - if (GeneralUtility::_GP('unknownList')) { - if (is_array($idLists['tt_address'])) { - $output .='
' . $this->getLanguageService()->getLL('stats_emails') . '
' . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address', $this->id, 1, $this->sys_dmail_uid); - } - if (is_array($idLists['fe_users'])) { - $output .= '
' . $this->getLanguageService()->getLL('stats_website_users') . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users', $this->id, 1, $this->sys_dmail_uid); - } - if (is_array($idLists['PLAINLIST'])) { - $output .= '
' . $this->getLanguageService()->getLL('stats_plainlist'); - $output .= '
  • ' . join('
  • ', $idLists['PLAINLIST']) . '
'; - } - } - if (GeneralUtility::_GP('unknownDisable')) { - if (is_array($idLists['tt_address'])) { - $c = $this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address'); - $output .='
' . $c . ' ' . $this->getLanguageService()->getLL('stats_emails_disabled'); - } - if (is_array($idLists['fe_users'])) { - $c = $this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users'); - $output .='
' . $c . ' ' . $this->getLanguageService()->getLL('stats_website_users_disabled'); + $idLists = []; + while (($rrow = $res->fetch())) { + switch ($rrow['rtbl']) { + case 't': + $idLists['tt_address'][]=$rrow['rid']; + break; + case 'f': + $idLists['fe_users'][]=$rrow['rid']; + break; + case 'P': + $idLists['PLAINLIST'][] = $rrow['email']; + break; + default: + $idLists[$rrow['rtbl']][]=$rrow['rid']; + } } - } - if (GeneralUtility::_GP('unknownCSV')) { - $emails = array(); - if (is_array($idLists['tt_address'])) { - $arr = DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'); - foreach ($arr as $v) { - $emails[]=$v['email']; + + if (GeneralUtility::_GP('unknownList')) { + if (is_array($idLists['tt_address'])) { + $output .='
' . $this->getLanguageService()->getLL('stats_emails') . '
' . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address', $this->id, 1, $this->sys_dmail_uid); + } + if (is_array($idLists['fe_users'])) { + $output .= '
' . $this->getLanguageService()->getLL('stats_website_users') . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users', $this->id, 1, $this->sys_dmail_uid); + } + if (is_array($idLists['PLAINLIST'])) { + $output .= '
' . $this->getLanguageService()->getLL('stats_plainlist'); + $output .= '
  • ' . join('
  • ', $idLists['PLAINLIST']) . '
'; } } - if (is_array($idLists['fe_users'])) { - $arr=DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'); - foreach ($arr as $v) { - $emails[]=$v['email']; + if (GeneralUtility::_GP('unknownDisable')) { + if (is_array($idLists['tt_address'])) { + $c = $this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address'); + $output .='
' . $c . ' ' . $this->getLanguageService()->getLL('stats_emails_disabled'); + } + if (is_array($idLists['fe_users'])) { + $c = $this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users'); + $output .='
' . $c . ' ' . $this->getLanguageService()->getLL('stats_website_users_disabled'); } } - if (is_array($idLists['PLAINLIST'])) { - $emails = array_merge($emails, $idLists['PLAINLIST']); + if (GeneralUtility::_GP('unknownCSV')) { + $emails = []; + if (is_array($idLists['tt_address'])) { + $arr = DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'); + foreach ($arr as $v) { + $emails[]=$v['email']; + } + } + if (is_array($idLists['fe_users'])) { + $arr=DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'); + foreach ($arr as $v) { + $emails[]=$v['email']; + } + } + if (is_array($idLists['PLAINLIST'])) { + $emails = array_merge($emails, $idLists['PLAINLIST']); + } + $output .='
' . $this->getLanguageService()->getLL('stats_emails_returned_unknown_recipient_list') . '
'; + $output .=''; } - $output .='
' . $this->getLanguageService()->getLL('stats_emails_returned_unknown_recipient_list') . '
'; - $output .=''; - } } - + // Mailbox Full if (GeneralUtility::_GP('fullList')||GeneralUtility::_GP('fullDisable')||GeneralUtility::_GP('fullCSV')) { - + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) - ->getQueryBuilderForTable('sys_dmail_maillog'); + ->getQueryBuilderForTable('sys_dmail_maillog'); $res = $queryBuilder - ->select('rid','rtbl','email') - ->from('sys_dmail_maillog') - ->add('where','mid=' . intval($row['uid']) . - ' AND response_type=-127' . - ' AND return_code=551') + ->select('rid','rtbl','email') + ->from('sys_dmail_maillog') + ->add('where','mid=' . intval($row['uid']) . + ' AND response_type=-127' . + ' AND return_code=551') ->execute(); - $idLists = array(); - while (($rrow = $res->fetch())) { - switch ($rrow['rtbl']) { - case 't': - $idLists['tt_address'][]=$rrow['rid']; - break; - case 'f': - $idLists['fe_users'][]=$rrow['rid']; - break; - case 'P': - $idLists['PLAINLIST'][] = $rrow['email']; - break; - default: - $idLists[$rrow['rtbl']][]=$rrow['rid']; - } - } - - if (GeneralUtility::_GP('fullList')) { - if (is_array($idLists['tt_address'])) { - $output .='
' . $this->getLanguageService()->getLL('stats_emails') . '
' . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address', $this->id, 1, $this->sys_dmail_uid); - } - if (is_array($idLists['fe_users'])) { - $output.= '
' . $this->getLanguageService()->getLL('stats_website_users') . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users', $this->id, 1, $this->sys_dmail_uid); - } - if (is_array($idLists['PLAINLIST'])) { - $output .= '
' . $this->getLanguageService()->getLL('stats_plainlist'); - $output .= '
  • ' . join('
  • ', $idLists['PLAINLIST']) . '
'; - } - } - if (GeneralUtility::_GP('fullDisable')) { - if (is_array($idLists['tt_address'])) { - $c=$this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address'); - $output.='
' . $c . ' ' . $this->getLanguageService()->getLL('stats_emails_disabled'); - } - if (is_array($idLists['fe_users'])) { - $c=$this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users'); - $output.='
' . $c . ' ' . $this->getLanguageService()->getLL('stats_website_users_disabled'); + $idLists = []; + while (($rrow = $res->fetch())) { + switch ($rrow['rtbl']) { + case 't': + $idLists['tt_address'][]=$rrow['rid']; + break; + case 'f': + $idLists['fe_users'][]=$rrow['rid']; + break; + case 'P': + $idLists['PLAINLIST'][] = $rrow['email']; + break; + default: + $idLists[$rrow['rtbl']][]=$rrow['rid']; + } } - } - if (GeneralUtility::_GP('fullCSV')) { - $emails=array(); - if (is_array($idLists['tt_address'])) { - $arr=DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'); - foreach ($arr as $v) { - $emails[]=$v['email']; + + if (GeneralUtility::_GP('fullList')) { + if (is_array($idLists['tt_address'])) { + $output .='
' . $this->getLanguageService()->getLL('stats_emails') . '
' . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address', $this->id, 1, $this->sys_dmail_uid); + } + if (is_array($idLists['fe_users'])) { + $output.= '
' . $this->getLanguageService()->getLL('stats_website_users') . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users', $this->id, 1, $this->sys_dmail_uid); + } + if (is_array($idLists['PLAINLIST'])) { + $output .= '
' . $this->getLanguageService()->getLL('stats_plainlist'); + $output .= '
  • ' . join('
  • ', $idLists['PLAINLIST']) . '
'; } } - if (is_array($idLists['fe_users'])) { - $arr=DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'); - foreach ($arr as $v) { - $emails[]=$v['email']; + if (GeneralUtility::_GP('fullDisable')) { + if (is_array($idLists['tt_address'])) { + $c=$this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address'); + $output.='
' . $c . ' ' . $this->getLanguageService()->getLL('stats_emails_disabled'); + } + if (is_array($idLists['fe_users'])) { + $c=$this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users'); + $output.='
' . $c . ' ' . $this->getLanguageService()->getLL('stats_website_users_disabled'); } } - if (is_array($idLists['PLAINLIST'])) { - $emails = array_merge($emails, $idLists['PLAINLIST']); + if (GeneralUtility::_GP('fullCSV')) { + $emails=[]; + if (is_array($idLists['tt_address'])) { + $arr=DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'); + foreach ($arr as $v) { + $emails[]=$v['email']; + } + } + if (is_array($idLists['fe_users'])) { + $arr=DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'); + foreach ($arr as $v) { + $emails[]=$v['email']; + } + } + if (is_array($idLists['PLAINLIST'])) { + $emails = array_merge($emails, $idLists['PLAINLIST']); + } + $output .='
' . $this->getLanguageService()->getLL('stats_emails_returned_mailbox_full_list') . '
'; + $output .=''; } - $output .='
' . $this->getLanguageService()->getLL('stats_emails_returned_mailbox_full_list') . '
'; - $output .=''; - } } - + // find Bad Host if (GeneralUtility::_GP('badHostList')||GeneralUtility::_GP('badHostDisable')||GeneralUtility::_GP('badHostCSV')) { - $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) - ->getQueryBuilderForTable('sys_dmail_maillog'); + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) + ->getQueryBuilderForTable('sys_dmail_maillog'); $res = $queryBuilder - ->select('rid','rtbl','email') - ->from('sys_dmail_maillog') - ->add('where','mid=' . intval($row['uid']) . - ' AND response_type=-127' . - ' AND return_code=552') + ->select('rid','rtbl','email') + ->from('sys_dmail_maillog') + ->add('where','mid=' . intval($row['uid']) . + ' AND response_type=-127' . + ' AND return_code=552') ->execute(); - $idLists = array(); - while (($rrow = $res->fetch())) { - switch ($rrow['rtbl']) { - case 't': - $idLists['tt_address'][]=$rrow['rid']; - break; - case 'f': - $idLists['fe_users'][]=$rrow['rid']; - break; - case 'P': - $idLists['PLAINLIST'][] = $rrow['email']; - break; - default: - $idLists[$rrow['rtbl']][]=$rrow['rid']; - } - } - - if (GeneralUtility::_GP('badHostList')) { - if (is_array($idLists['tt_address'])) { - $output .='
' . $this->getLanguageService()->getLL('stats_emails') . '
' . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address', $this->id, 1, $this->sys_dmail_uid); - } - if (is_array($idLists['fe_users'])) { - $output .= '
' . $this->getLanguageService()->getLL('stats_website_users') . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users', $this->id, 1, $this->sys_dmail_uid); - } - if (is_array($idLists['PLAINLIST'])) { - $output .= '
' . $this->getLanguageService()->getLL('stats_plainlist'); - $output .= '
  • ' . join('
  • ', $idLists['PLAINLIST']) . '
'; - } - } - if (GeneralUtility::_GP('badHostDisable')) { - if (is_array($idLists['tt_address'])) { - $c = $this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address'); - $output .='
' . $c . ' ' . $this->getLanguageService()->getLL('stats_emails_disabled'); - } - if (is_array($idLists['fe_users'])) { - $c = $this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users'); - $output .= '
' . $c . ' ' . $this->getLanguageService()->getLL('stats_website_users_disabled'); + $idLists = []; + while (($rrow = $res->fetch())) { + switch ($rrow['rtbl']) { + case 't': + $idLists['tt_address'][]=$rrow['rid']; + break; + case 'f': + $idLists['fe_users'][]=$rrow['rid']; + break; + case 'P': + $idLists['PLAINLIST'][] = $rrow['email']; + break; + default: + $idLists[$rrow['rtbl']][]=$rrow['rid']; + } } - } - if (GeneralUtility::_GP('badHostCSV')) { - $emails = array(); - if (is_array($idLists['tt_address'])) { - $arr = DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'); - foreach ($arr as $v) { - $emails[] = $v['email']; + + if (GeneralUtility::_GP('badHostList')) { + if (is_array($idLists['tt_address'])) { + $output .='
' . $this->getLanguageService()->getLL('stats_emails') . '
' . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address', $this->id, 1, $this->sys_dmail_uid); + } + if (is_array($idLists['fe_users'])) { + $output .= '
' . $this->getLanguageService()->getLL('stats_website_users') . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users', $this->id, 1, $this->sys_dmail_uid); + } + if (is_array($idLists['PLAINLIST'])) { + $output .= '
' . $this->getLanguageService()->getLL('stats_plainlist'); + $output .= '
  • ' . join('
  • ', $idLists['PLAINLIST']) . '
'; } } - if (is_array($idLists['fe_users'])) { - $arr = DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'); - foreach ($arr as $v) { - $emails[] = $v['email']; + if (GeneralUtility::_GP('badHostDisable')) { + if (is_array($idLists['tt_address'])) { + $c = $this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address'); + $output .='
' . $c . ' ' . $this->getLanguageService()->getLL('stats_emails_disabled'); + } + if (is_array($idLists['fe_users'])) { + $c = $this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users'); + $output .= '
' . $c . ' ' . $this->getLanguageService()->getLL('stats_website_users_disabled'); } } - if (is_array($idLists['PLAINLIST'])) { - $emails = array_merge($emails, $idLists['PLAINLIST']); + if (GeneralUtility::_GP('badHostCSV')) { + $emails = []; + if (is_array($idLists['tt_address'])) { + $arr = DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'); + foreach ($arr as $v) { + $emails[] = $v['email']; + } + } + if (is_array($idLists['fe_users'])) { + $arr = DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'); + foreach ($arr as $v) { + $emails[] = $v['email']; + } + } + if (is_array($idLists['PLAINLIST'])) { + $emails = array_merge($emails, $idLists['PLAINLIST']); + } + $output .= '
' . $this->getLanguageService()->getLL('stats_emails_returned_bad_host_list') . '
'; + $output .= ''; } - $output .= '
' . $this->getLanguageService()->getLL('stats_emails_returned_bad_host_list') . '
'; - $output .= ''; - } } - + // find Bad Header if (GeneralUtility::_GP('badHeaderList')||GeneralUtility::_GP('badHeaderDisable')||GeneralUtility::_GP('badHeaderCSV')) { $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) - ->getQueryBuilderForTable('sys_dmail_maillog'); + ->getQueryBuilderForTable('sys_dmail_maillog'); $res = $queryBuilder - ->select('rid','rtbl','email') - ->from('sys_dmail_maillog') - ->add('where','mid=' . intval($row['uid']) . - ' AND response_type=-127' . - ' AND return_code=554') + ->select('rid','rtbl','email') + ->from('sys_dmail_maillog') + ->add('where','mid=' . intval($row['uid']) . + ' AND response_type=-127' . + ' AND return_code=554') ->execute(); - - $idLists = array(); - while (($rrow = $res->fetch())) { - switch ($rrow['rtbl']) { - case 't': - $idLists['tt_address'][] = $rrow['rid']; - break; - case 'f': - $idLists['fe_users'][] = $rrow['rid']; - break; - case 'P': - $idLists['PLAINLIST'][] = $rrow['email']; - break; - default: - $idLists[$rrow['rtbl']][] = $rrow['rid']; - } - } - - if (GeneralUtility::_GP('badHeaderList')) { - if (is_array($idLists['tt_address'])) { - $output .='
' . $this->getLanguageService()->getLL('stats_emails') . '
' . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address', $this->id, 1, $this->sys_dmail_uid); - } - if (is_array($idLists['fe_users'])) { - $output .= '
' . $this->getLanguageService()->getLL('stats_website_users') . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users', $this->id, 1, $this->sys_dmail_uid); - } - if (is_array($idLists['PLAINLIST'])) { - $output .= '
' . $this->getLanguageService()->getLL('stats_plainlist'); - $output .= '
  • ' . join('
  • ', $idLists['PLAINLIST']) . '
'; - } - } - - if (GeneralUtility::_GP('badHeaderDisable')) { - if (is_array($idLists['tt_address'])) { - $c = $this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address'); - $output .='
' . $c . ' ' . $this->getLanguageService()->getLL('stats_emails_disabled'); - } - if (is_array($idLists['fe_users'])) { - $c = $this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users'); - $output .='
' . $c . ' ' . $this->getLanguageService()->getLL('stats_website_users_disabled'); + + $idLists = []; + while (($rrow = $res->fetch())) { + switch ($rrow['rtbl']) { + case 't': + $idLists['tt_address'][] = $rrow['rid']; + break; + case 'f': + $idLists['fe_users'][] = $rrow['rid']; + break; + case 'P': + $idLists['PLAINLIST'][] = $rrow['email']; + break; + default: + $idLists[$rrow['rtbl']][] = $rrow['rid']; + } } - } - if (GeneralUtility::_GP('badHeaderCSV')) { - $emails = array(); - if (is_array($idLists['tt_address'])) { - $arr = DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'); - foreach ($arr as $v) { - $emails[] = $v['email']; + + if (GeneralUtility::_GP('badHeaderList')) { + if (is_array($idLists['tt_address'])) { + $output .='
' . $this->getLanguageService()->getLL('stats_emails') . '
' . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address', $this->id, 1, $this->sys_dmail_uid); + } + if (is_array($idLists['fe_users'])) { + $output .= '
' . $this->getLanguageService()->getLL('stats_website_users') . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users', $this->id, 1, $this->sys_dmail_uid); + } + if (is_array($idLists['PLAINLIST'])) { + $output .= '
' . $this->getLanguageService()->getLL('stats_plainlist'); + $output .= '
  • ' . join('
  • ', $idLists['PLAINLIST']) . '
'; } } - if (is_array($idLists['fe_users'])) { - $arr = DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'); - foreach ($arr as $v) { - $emails[] = $v['email']; + + if (GeneralUtility::_GP('badHeaderDisable')) { + if (is_array($idLists['tt_address'])) { + $c = $this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address'); + $output .='
' . $c . ' ' . $this->getLanguageService()->getLL('stats_emails_disabled'); + } + if (is_array($idLists['fe_users'])) { + $c = $this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users'); + $output .='
' . $c . ' ' . $this->getLanguageService()->getLL('stats_website_users_disabled'); } } - if (is_array($idLists['PLAINLIST'])) { - $emails = array_merge($emails, $idLists['PLAINLIST']); + if (GeneralUtility::_GP('badHeaderCSV')) { + $emails = []; + if (is_array($idLists['tt_address'])) { + $arr = DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'); + foreach ($arr as $v) { + $emails[] = $v['email']; + } + } + if (is_array($idLists['fe_users'])) { + $arr = DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'); + foreach ($arr as $v) { + $emails[] = $v['email']; + } + } + if (is_array($idLists['PLAINLIST'])) { + $emails = array_merge($emails, $idLists['PLAINLIST']); + } + $output .= '
' . $this->getLanguageService()->getLL('stats_emails_returned_bad_header_list') . '
'; + $output .= ''; } - $output .= '
' . $this->getLanguageService()->getLL('stats_emails_returned_bad_header_list') . '
'; - $output .= ''; - } } - + // find Unknown Reasons // TODO: list all reason if (GeneralUtility::_GP('reasonUnknownList')||GeneralUtility::_GP('reasonUnknownDisable')||GeneralUtility::_GP('reasonUnknownCSV')) { - + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) - ->getQueryBuilderForTable('sys_dmail_maillog'); + ->getQueryBuilderForTable('sys_dmail_maillog'); $res = $queryBuilder - ->select('rid','rtbl','email') - ->from('sys_dmail_maillog') - ->add('where','mid=' . intval($row['uid']) . - ' AND response_type=-127' . - ' AND return_code=-1') + ->select('rid','rtbl','email') + ->from('sys_dmail_maillog') + ->add('where','mid=' . intval($row['uid']) . + ' AND response_type=-127' . + ' AND return_code=-1') ->execute(); - $idLists = array(); - while (($rrow = $res->fetch())) { - switch ($rrow['rtbl']) { - case 't': - $idLists['tt_address'][] = $rrow['rid']; - break; - case 'f': - $idLists['fe_users'][] = $rrow['rid']; - break; - case 'P': - $idLists['PLAINLIST'][] = $rrow['email']; - break; - default: - $idLists[$rrow['rtbl']][] = $rrow['rid']; - } - } - - if (GeneralUtility::_GP('reasonUnknownList')) { - if (is_array($idLists['tt_address'])) { - $output .='
' . $this->getLanguageService()->getLL('stats_emails') . '
' . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address', $this->id, 1, $this->sys_dmail_uid); - } - if (is_array($idLists['fe_users'])) { - $output .= '
' . $this->getLanguageService()->getLL('stats_website_users') . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users', $this->id, 1, $this->sys_dmail_uid); - } - if (is_array($idLists['PLAINLIST'])) { - $output .= '
' . $this->getLanguageService()->getLL('stats_plainlist'); - $output .= '
  • ' . join('
  • ', $idLists['PLAINLIST']) . '
'; - } - } - if (GeneralUtility::_GP('reasonUnknownDisable')) { - if (is_array($idLists['tt_address'])) { - $c = $this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address'); - $output .= '
' . $c . ' ' . $this->getLanguageService()->getLL('stats_emails_disabled'); - } - if (is_array($idLists['fe_users'])) { - $c = $this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users'); - $output .= '
' . $c . ' ' . $this->getLanguageService()->getLL('stats_website_users_disabled'); + $idLists = []; + while (($rrow = $res->fetch())) { + switch ($rrow['rtbl']) { + case 't': + $idLists['tt_address'][] = $rrow['rid']; + break; + case 'f': + $idLists['fe_users'][] = $rrow['rid']; + break; + case 'P': + $idLists['PLAINLIST'][] = $rrow['email']; + break; + default: + $idLists[$rrow['rtbl']][] = $rrow['rid']; + } } - } - if (GeneralUtility::_GP('reasonUnknownCSV')) { - $emails = array(); - if (is_array($idLists['tt_address'])) { - $arr = DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'); - foreach ($arr as $v) { - $emails[]=$v['email']; + + if (GeneralUtility::_GP('reasonUnknownList')) { + if (is_array($idLists['tt_address'])) { + $output .='
' . $this->getLanguageService()->getLL('stats_emails') . '
' . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address', $this->id, 1, $this->sys_dmail_uid); + } + if (is_array($idLists['fe_users'])) { + $output .= '
' . $this->getLanguageService()->getLL('stats_website_users') . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users', $this->id, 1, $this->sys_dmail_uid); + } + if (is_array($idLists['PLAINLIST'])) { + $output .= '
' . $this->getLanguageService()->getLL('stats_plainlist'); + $output .= '
  • ' . join('
  • ', $idLists['PLAINLIST']) . '
'; } } - if (is_array($idLists['fe_users'])) { - $arr = DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'); - foreach ($arr as $v) { - $emails[]=$v['email']; + if (GeneralUtility::_GP('reasonUnknownDisable')) { + if (is_array($idLists['tt_address'])) { + $c = $this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address'); + $output .= '
' . $c . ' ' . $this->getLanguageService()->getLL('stats_emails_disabled'); + } + if (is_array($idLists['fe_users'])) { + $c = $this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users'); + $output .= '
' . $c . ' ' . $this->getLanguageService()->getLL('stats_website_users_disabled'); } } - if (is_array($idLists['PLAINLIST'])) { - $emails = array_merge($emails, $idLists['PLAINLIST']); + if (GeneralUtility::_GP('reasonUnknownCSV')) { + $emails = []; + if (is_array($idLists['tt_address'])) { + $arr = DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'); + foreach ($arr as $v) { + $emails[]=$v['email']; + } + } + if (is_array($idLists['fe_users'])) { + $arr = DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'); + foreach ($arr as $v) { + $emails[]=$v['email']; + } + } + if (is_array($idLists['PLAINLIST'])) { + $emails = array_merge($emails, $idLists['PLAINLIST']); + } + $output .= '
' . $this->getLanguageService()->getLL('stats_emails_returned_reason_unknown_list') . '
'; + $output .= ''; } - $output .= '
' . $this->getLanguageService()->getLL('stats_emails_returned_reason_unknown_list') . '
'; - $output .= ''; - } } - + /** * Hook for cmd_stats_postProcess * insert a link to open extended importer */ if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['direct_mail']['mod4']['cmd_stats'])) { - $hookObjectsArr = array(); + $hookObjectsArr = []; foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['direct_mail']['mod4']['cmd_stats'] as $classRef) { $hookObjectsArr[] = GeneralUtility::makeInstance($classRef); } - + // assigned $output to class property to make it acesssible inside hook $this->output = $output; - + // and clear the former $output to collect hoot return code there $output = ''; - + foreach ($hookObjectsArr as $hookObj) { if (method_exists($hookObj, 'cmd_stats_postProcess')) { $output .= $hookObj->cmd_stats_postProcess($row, $this); } } } - + $this->noView = 1; // put all the stats tables in a section $theOutput = '

' . $this->getLanguageService()->getLL('stats_direct_mail') .'

' . $output; $theOutput .= '
'; - + $theOutput .= '

' . $this->getLanguageService()->getLL('stats_recalculate_cached_data') . '

' . '

' . $this->getLanguageService()->getLL('stats_recalculate_stats') . '

'; return $theOutput; } - - + + /** * This method returns the label for a specified URL. * If the page is local and contains a fragment it returns the label of the content element linked to. @@ -1505,7 +1496,7 @@ public function getLinkLabel($url, $urlStr, $forceFetch = false, $linkedWord = ' $pathSite = $this->getBaseURL(); $label = $linkedWord; $contentTitle = ''; - + $urlParts = parse_url($url); if (!$forceFetch && (substr($url, 0, strlen($pathSite)) === $pathSite)) { if ($urlParts['fragment'] && (substr($urlParts['fragment'], 0, 1) == 'c')) { @@ -1523,9 +1514,9 @@ public function getLinkLabel($url, $urlStr, $forceFetch = false, $linkedWord = ' // it's internal $url = $pathSite . $url; } - + $content = GeneralUtility::getURL($url); - + if (preg_match('/\<\s*title\s*\>(.*)\<\s*\/\s*title\s*\>/i', $content, $matches)) { // get the page title $contentTitle = GeneralUtility::fixed_lgd_cs(trim($matches[1]), 50); @@ -1535,35 +1526,35 @@ public function getLinkLabel($url, $urlStr, $forceFetch = false, $linkedWord = ' $contentTitle = $file['file']; } } - + if ($this->params['showContentTitle'] == 1) { $label = $contentTitle; } - + if ($this->params['prependContentTitle'] == 1) { $label = $contentTitle . ' (' . $linkedWord . ')'; } - + if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXT']['directmail']['getLinkLabel'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXT']['directmail']['getLinkLabel'] as $funcRef) { $params = array('pObj' => &$this, 'url' => $url, 'urlStr' => $urlStr, 'label' => $label); $label = GeneralUtility::callUserFunction($funcRef, $params, $this); } } - + // Fallback to url if ($label === '') { $label = $url; } - + if (isset($this->params['maxLabelLength']) && ($this->params['maxLabelLength'] > 0)) { $label = GeneralUtility::fixed_lgd_cs($label, $this->params['maxLabelLength']); } - + return $label; } - - + + /** * Generates a string for the URL * @@ -1574,9 +1565,9 @@ public function getLinkLabel($url, $urlStr, $forceFetch = false, $linkedWord = ' public function getUrlStr(array $urlParts) { $baseUrl = $this->getBaseURL(); - + if (is_array($urlParts) && GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY') == $urlParts['host']) { - $m = array(); + $m = []; // do we have an id? if (preg_match('/(?:^|&)id=([0-9a-z_]+)/', $urlParts['query'], $m)) { $isInt = MathUtility::canBeInterpretedAsInteger($m[1]); @@ -1605,10 +1596,10 @@ public function getUrlStr(array $urlParts) $urlstr .= $urlParts['query'] ? '?' . $urlParts['query'] : ''; $urlstr .= $urlParts['fragment'] ? '#' . $urlParts['fragment'] : ''; } - + return $urlstr; } - + /** * Get baseURL of the FE * force http if UseHttpToFetch is set @@ -1618,15 +1609,15 @@ public function getUrlStr(array $urlParts) public function getBaseURL() { $baseUrl = GeneralUtility::getIndpEnv('TYPO3_SITE_URL'); - + # if fetching the newsletter using http, set the url to http here if ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['direct_mail']['UseHttpToFetch'] == 1) { $baseUrl = str_replace('https', 'http', $baseUrl); } - + return $baseUrl; } - + /** * Set disable=1 to all record in an array * @@ -1638,7 +1629,7 @@ public function getBaseURL() public function disableRecipients(array $arr, $table) { if ($GLOBALS['TCA'][$table]) { - $values = array(); + $values = []; $enField = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled']; if ($enField) { $values[$enField] = 1; @@ -1653,14 +1644,14 @@ public function disableRecipients(array $arr, $table) [ 'uid' => $uid ] - ); + ); } } } } return intval($count); } - + /** * Write the statistic to a temporary table * @@ -1671,41 +1662,41 @@ public function disableRecipients(array $arr, $table) public function makeStatTempTableContent(array $mrow) { // Remove old: - + GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('cache_sys_dmail_stat') - ->delete( - 'cache_sys_dmail_stat', // from - [ 'mid' => intval($mrow['uid']) ] // where + ->delete( + 'cache_sys_dmail_stat', // from + [ 'mid' => intval($mrow['uid']) ] // where ); - + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_dmail_maillog'); $res = $queryBuilder - ->select('rid','rtbl','tstamp','response_type','url_id','html_sent','size') - ->from('sys_dmail_maillog') - ->add('where', 'mid=' . intval($mrow['uid'])) - ->orderBy('rtbl') - ->addOrderBy('rid') - ->addOrderBy('tstamp') - ->execute(); - + ->select('rid','rtbl','tstamp','response_type','url_id','html_sent','size') + ->from('sys_dmail_maillog') + ->add('where', 'mid=' . intval($mrow['uid'])) + ->orderBy('rtbl') + ->addOrderBy('rid') + ->addOrderBy('tstamp') + ->execute(); + $currentRec = ''; - $recRec = array(); - - + $recRec = []; + + while (($row = $res->fetch())) { $thisRecPointer = $row['rtbl'] . $row['rid']; - + if ($thisRecPointer != $currentRec) { $recRec = array( 'mid' => intval($mrow['uid']), 'rid' => $row['rid'], 'rtbl' => $row['rtbl'], - 'pings' => array(), - 'plain_links' => array(), - 'html_links' => array(), - 'response' => array(), - 'links' => array() - ); + 'pings' => [], + 'plain_links' => [], + 'html_links' => [], + 'response' => [], + 'links' => [] + ); $currentRec = $thisRecPointer; } switch ($row['response_type']) { @@ -1747,11 +1738,11 @@ public function makeStatTempTableContent(array $mrow) // do nothing } } - - + + $this->storeRecRec($recRec); } - + /** * Insert statistic to a temporary table * @@ -1765,41 +1756,41 @@ public function storeRecRec(array $recRec) $recRec['pings_first'] = intval(@min($recRec['pings'])); $recRec['pings_last'] = intval(@max($recRec['pings'])); $recRec['pings'] = count($recRec['pings']); - + $recRec['html_links_first'] = intval(@min($recRec['html_links'])); $recRec['html_links_last'] = intval(@max($recRec['html_links'])); $recRec['html_links'] = count($recRec['html_links']); - + $recRec['plain_links_first'] = intval(@min($recRec['plain_links'])); $recRec['plain_links_last'] = intval(@max($recRec['plain_links'])); $recRec['plain_links'] = count($recRec['plain_links']); - + $recRec['links_first'] = intval(@min($recRec['links'])); $recRec['links_last'] = intval(@max($recRec['links'])); $recRec['links'] = count($recRec['links']); - + $recRec['response_first'] = DirectMailUtility::intInRangeWrapper((int)((int)(@min($recRec['response']))-$recRec['tstamp']), 0); $recRec['response_last'] = DirectMailUtility::intInRangeWrapper((int)((int)(@max($recRec['response']))-$recRec['tstamp']), 0); $recRec['response'] = count($recRec['response']); - + $recRec['time_firstping'] = DirectMailUtility::intInRangeWrapper((int)($recRec['pings_first']-$recRec['tstamp']), 0); $recRec['time_lastping'] = DirectMailUtility::intInRangeWrapper((int)($recRec['pings_last']-$recRec['tstamp']), 0); - + $recRec['time_first_link'] = DirectMailUtility::intInRangeWrapper((int)($recRec['links_first']-$recRec['tstamp']), 0); $recRec['time_last_link'] = DirectMailUtility::intInRangeWrapper((int)($recRec['links_last']-$recRec['tstamp']), 0); - - - + + + GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('cache_sys_dmail_stat') - ->insert( - 'cache_sys_dmail_stat', - $recRec - ); - - + ->insert( + 'cache_sys_dmail_stat', + $recRec + ); + + } } - + /** * Make a select query * @@ -1810,35 +1801,35 @@ public function storeRecRec(array $recRec) */ public function getQueryRows(array $queryArray, $fieldName) { - + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($queryArray[2]); - + if (empty($queryArray[5])){ $res = $queryBuilder - ->count($queryArray[1]) - ->addSelect($queryArray[0]) - ->from($queryArray[2]) - ->add('where',$queryArray[3]) - ->groupBy($queryArray[4]) - ->execute() - ->fetchAll(); + ->count($queryArray[1]) + ->addSelect($queryArray[0]) + ->from($queryArray[2]) + ->add('where',$queryArray[3]) + ->groupBy($queryArray[4]) + ->execute() + ->fetchAll(); }else{ $res = $queryBuilder - ->count($queryArray[1]) - ->addSelect($queryArray[0]) - ->from($queryArray[2]) - ->add('where',$queryArray[3]) - ->groupBy($queryArray[4]) - ->orderBy($queryArray[5]) - ->execute() - ->fetchAll(); + ->count($queryArray[1]) + ->addSelect($queryArray[0]) + ->from($queryArray[2]) + ->add('where',$queryArray[3]) + ->groupBy($queryArray[4]) + ->orderBy($queryArray[5]) + ->execute() + ->fetchAll(); } - - - /*questa funzione viene chiamata per cambiare la key 'COUNT(*)' in 'counter'*/ + + + /*questa funzione viene chiamata per cambiare la key 'COUNT(*)' in 'counter'*/ $res = $this->changekeyname($res,'counter','COUNT(*)'); - - $lines = array(); + + $lines = []; foreach($res as $row){ if ($fieldName) { $lines[$row[$fieldName]] = $row; @@ -1848,7 +1839,7 @@ public function getQueryRows(array $queryArray, $fieldName) } return $lines; } - + /** * Make a percent from the given parameters * @@ -1866,7 +1857,7 @@ public function showWithPercent($pieces, $total) } return $str; } - + /** * Set up URL variables for this $row. * @@ -1878,7 +1869,7 @@ public function setURLs(array $row) { // Finding the domain to use $this->urlbase = DirectMailUtility::getUrlBase((int)$row['page']); - + // Finding the url to fetch content from switch ((string)$row['type']) { case 1: @@ -1889,7 +1880,7 @@ public function setURLs(array $row) $this->url_html = $this->urlbase . '?id=' . $row['page'] . $row['HTMLParams']; $this->url_plain = $this->urlbase . '?id=' . $row['page'] . $row['plainParams']; } - + // plain if (!($row['sendOptions']&1) || !$this->url_plain) { $this->url_plain = ''; @@ -1899,7 +1890,7 @@ public function setURLs(array $row) $this->url_plain = 'http://' . $this->url_plain; } } - + // html if (!($row['sendOptions']&2) || !$this->url_html) { $this->url_html = ''; @@ -1910,7 +1901,7 @@ public function setURLs(array $row) } } } - + /** * Show the compact information of a direct mail record * @@ -1926,91 +1917,91 @@ public function directMail_compactView($row) } else { $page = BackendUtility::getRecord('pages', $row['page'], 'title'); $dmailData = $row['page'] . ', ' . htmlspecialchars($page['title']); - + $dmailInfo = DirectMailUtility::fName('plainParams') . ' ' . htmlspecialchars($row['plainParams'] . LF . DirectMailUtility::fName('HTMLParams') . $row['HTMLParams']) . '; ' . LF; } - + $dmailInfo .= $this->getLanguageService()->getLL('view_media') . ' ' . BackendUtility::getProcessedValue('sys_dmail', 'includeMedia', $row['includeMedia']) . '; ' . LF . - $this->getLanguageService()->getLL('view_flowed') . ' ' . BackendUtility::getProcessedValue('sys_dmail', 'flowedFormat', $row['flowedFormat']); - + $this->getLanguageService()->getLL('view_flowed') . ' ' . BackendUtility::getProcessedValue('sys_dmail', 'flowedFormat', $row['flowedFormat']); + $dmailInfo = '' . $this->iconFactory->getIcon('actions-document-info', Icon::SIZE_SMALL) . ''; - - $fromInfo = $this->getLanguageService()->getLL('view_replyto') . ' ' . htmlspecialchars($row['replyto_name'] . ' <' . $row['replyto_email'] . '>') . '; ' . LF . + + $fromInfo = $this->getLanguageService()->getLL('view_replyto') . ' ' . htmlspecialchars($row['replyto_name'] . ' <' . $row['replyto_email'] . '>') . '; ' . LF . DirectMailUtility::fName('organisation') . ' ' . htmlspecialchars($row['organisation']) . '; ' . LF . DirectMailUtility::fName('return_path') . ' ' . htmlspecialchars($row['return_path']); - $fromInfo = '' . - $this->iconFactory->getIcon('actions-document-info', Icon::SIZE_SMALL) . - ''; - - $mailInfo = DirectMailUtility::fName('priority') . ' ' . BackendUtility::getProcessedValue('sys_dmail', 'priority', $row['priority']) . '; ' . LF . - DirectMailUtility::fName('encoding') . ' ' . BackendUtility::getProcessedValue('sys_dmail', 'encoding', $row['encoding']) . '; ' . LF . - DirectMailUtility::fName('charset') . ' ' . BackendUtility::getProcessedValue('sys_dmail', 'charset', $row['charset']); - $mailInfo = '' . - $this->iconFactory->getIcon('actions-document-info', Icon::SIZE_SMALL) . - ''; - - $delBegin = ($row['scheduled_begin']?BackendUtility::datetime($row['scheduled_begin']):'-'); - $delEnd = ($row['scheduled_end']?BackendUtility::datetime($row['scheduled_begin']):'-'); - - // count total recipient from the query_info - $totalRecip = 0; - $idLists = unserialize($row['query_info']); - foreach ($idLists['id_lists'] as $idArray) { - $totalRecip += count($idArray); - } - - $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_dmail_maillog'); - $res = $queryBuilder->select('*') - ->from('sys_dmail_maillog') - ->add('where', 'mid=' . $row['uid'] . ' AND response_type = 0') - ->orderBy('rid','ASC') - ->execute() - ->fetchAll(); - - $sentRecip = count($res); - - $out = ''; - $out .= ''; - $out .= '' . - '' . - ''; - $out .= '' . - '' . - ''; - $out .= '' . - '' . - ''; - $out .= '' . - '' . - ''; - $out .= '' . - '' . - ''; - $out .= '
' . $this->iconFactory->getIconForRecord('sys_dmail', $row, Icon::SIZE_SMALL)->render() . htmlspecialchars($row['subject']) . '
' . $this->getLanguageService()->getLL('view_from') . '' . htmlspecialchars($row['from_name'] . ' <' . htmlspecialchars($row['from_email']) . '>') . '' . $fromInfo . '
' . $this->getLanguageService()->getLL('view_dmail') . '' . BackendUtility::getProcessedValue('sys_dmail', 'type', $row['type']) . ': ' . $dmailData . '' . $dmailInfo . '
' . $this->getLanguageService()->getLL('view_mail') . '' . BackendUtility::getProcessedValue('sys_dmail', 'sendOptions', $row['sendOptions']) . ($row['attachment']?'; ':'') . BackendUtility::getProcessedValue('sys_dmail', 'attachment', $row['attachment']) . '' . $mailInfo . '
' . $this->getLanguageService()->getLL('view_delivery_begin_end') . '' . $delBegin . ' / ' . $delEnd . ' 
' . $this->getLanguageService()->getLL('view_recipient_total_sent') . '' . $totalRecip . ' / ' . $sentRecip . ' 
'; - $out .= '
'; - - return $out; + $fromInfo = '' . + $this->iconFactory->getIcon('actions-document-info', Icon::SIZE_SMALL) . + ''; + + $mailInfo = DirectMailUtility::fName('priority') . ' ' . BackendUtility::getProcessedValue('sys_dmail', 'priority', $row['priority']) . '; ' . LF . + DirectMailUtility::fName('encoding') . ' ' . BackendUtility::getProcessedValue('sys_dmail', 'encoding', $row['encoding']) . '; ' . LF . + DirectMailUtility::fName('charset') . ' ' . BackendUtility::getProcessedValue('sys_dmail', 'charset', $row['charset']); + $mailInfo = '' . + $this->iconFactory->getIcon('actions-document-info', Icon::SIZE_SMALL) . + ''; + + $delBegin = ($row['scheduled_begin']?BackendUtility::datetime($row['scheduled_begin']):'-'); + $delEnd = ($row['scheduled_end']?BackendUtility::datetime($row['scheduled_begin']):'-'); + + // count total recipient from the query_info + $totalRecip = 0; + $idLists = unserialize($row['query_info']); + foreach ($idLists['id_lists'] as $idArray) { + $totalRecip += count($idArray); + } + + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_dmail_maillog'); + $res = $queryBuilder->select('*') + ->from('sys_dmail_maillog') + ->add('where', 'mid=' . $row['uid'] . ' AND response_type = 0') + ->orderBy('rid','ASC') + ->execute() + ->fetchAll(); + + $sentRecip = count($res); + + $out = ''; + $out .= ''; + $out .= '' . + '' . + ''; + $out .= '' . + '' . + ''; + $out .= '' . + '' . + ''; + $out .= '' . + '' . + ''; + $out .= '' . + '' . + ''; + $out .= '
' . $this->iconFactory->getIconForRecord('sys_dmail', $row, Icon::SIZE_SMALL)->render() . htmlspecialchars($row['subject']) . '
' . $this->getLanguageService()->getLL('view_from') . '' . htmlspecialchars($row['from_name'] . ' <' . htmlspecialchars($row['from_email']) . '>') . '' . $fromInfo . '
' . $this->getLanguageService()->getLL('view_dmail') . '' . BackendUtility::getProcessedValue('sys_dmail', 'type', $row['type']) . ': ' . $dmailData . '' . $dmailInfo . '
' . $this->getLanguageService()->getLL('view_mail') . '' . BackendUtility::getProcessedValue('sys_dmail', 'sendOptions', $row['sendOptions']) . ($row['attachment']?'; ':'') . BackendUtility::getProcessedValue('sys_dmail', 'attachment', $row['attachment']) . '' . $mailInfo . '
' . $this->getLanguageService()->getLL('view_delivery_begin_end') . '' . $delBegin . ' / ' . $delEnd . ' 
' . $this->getLanguageService()->getLL('view_recipient_total_sent') . '' . $totalRecip . ' / ' . $sentRecip . ' 
'; + $out .= '
'; + + return $out; } - - - /** - * Switch the key of an array - * - * @return $array - */ + + + /** + * Switch the key of an array + * + * @return $array + */ private function changekeyname($array, $newkey, $oldkey) { foreach ($array as $key => $value) { if (is_array($value)) $array[$key] = $this->changekeyname($value,$newkey,$oldkey); - else - { - $array[$newkey] = $array[$oldkey]; - } - + else + { + $array[$newkey] = $array[$oldkey]; + } + } unset($array[$oldkey]); return $array; diff --git a/Classes/Module/StatisticsController.php b/Classes/Module/StatisticsController.php new file mode 100644 index 000000000..2c020433e --- /dev/null +++ b/Classes/Module/StatisticsController.php @@ -0,0 +1,52 @@ +moduleTemplate = $moduleTemplate ?? GeneralUtility::makeInstance(ModuleTemplate::class); + } + + public function indexAction(ServerRequestInterface $request) : ResponseInterface + { + /** + * Configure template paths for your backend module + */ + $this->view = GeneralUtility::makeInstance(StandaloneView::class); + $this->view->setTemplateRootPaths(['EXT:direct_mail/Resources/Private/Templates/']); + $this->view->setPartialRootPaths(['EXT:direct_mail/Resources/Private/Partials/']); + $this->view->setLayoutRootPaths(['EXT:direct_mail/Resources/Private/Layouts/']); + $this->view->setTemplate('Statistics'); + + /** + * Render template and return html content + */ + $this->moduleTemplate->setContent($this->view->render()); + return new HtmlResponse($this->moduleTemplate->renderContent()); + } +} \ No newline at end of file diff --git a/Resources/Private/Templates/Statistics.html b/Resources/Private/Templates/Statistics.html new file mode 100644 index 000000000..d883692b5 --- /dev/null +++ b/Resources/Private/Templates/Statistics.html @@ -0,0 +1,5 @@ + + + +

+
\ No newline at end of file diff --git a/ext_tables.php b/ext_tables.php index 9ba6f3a61..4a4dff321 100755 --- a/ext_tables.php +++ b/ext_tables.php @@ -87,7 +87,7 @@ 'bottom', '', [ - 'routeTarget' => DirectMailTeam\DirectMail\Module\Statistics::class . '::mainAction', + 'routeTarget' => DirectMailTeam\DirectMail\Module\StatisticsController::class . '::indexAction', 'access' => 'group,user', 'name' => 'DirectMailNavFrame_Statistics', 'workspaces' => 'online', From 2664641355643cc103ea60abc72480a99cca508e Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sun, 14 Nov 2021 12:18:14 +0000 Subject: [PATCH 021/342] add old functions --- Classes/Module/MainController.php | 7 + Classes/Module/StatisticsController.php | 178 ++++++++++++++++++++ Resources/Private/Templates/Statistics.html | 1 + 3 files changed, 186 insertions(+) diff --git a/Classes/Module/MainController.php b/Classes/Module/MainController.php index 2448b643b..8d18cb332 100644 --- a/Classes/Module/MainController.php +++ b/Classes/Module/MainController.php @@ -2,6 +2,8 @@ namespace DirectMailTeam\DirectMail\Module; use TYPO3\CMS\Backend\Template\ModuleTemplate; +use TYPO3\CMS\Core\Database\ConnectionPool; +use TYPO3\CMS\Core\Database\Query\QueryBuilder; use TYPO3\CMS\Core\Localization\LanguageService; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -25,4 +27,9 @@ protected function getLanguageService(): LanguageService { return $GLOBALS['LANG']; } + + protected function getQueryBuilder($table): QueryBuilder + { + return GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table); + } } \ No newline at end of file diff --git a/Classes/Module/StatisticsController.php b/Classes/Module/StatisticsController.php index 2c020433e..467c14dd1 100644 --- a/Classes/Module/StatisticsController.php +++ b/Classes/Module/StatisticsController.php @@ -7,6 +7,7 @@ use TYPO3\CMS\Core\Http\HtmlResponse; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Fluid\View\StandaloneView; +use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction; class StatisticsController extends MainController { @@ -22,6 +23,9 @@ class StatisticsController extends MainController */ protected $view; + protected $id = 0; + protected $sys_dmail_uid = 0; + /** * Constructor Method * @@ -34,6 +38,16 @@ public function __construct(ModuleTemplate $moduleTemplate = null) public function indexAction(ServerRequestInterface $request) : ResponseInterface { +/** + $this->CMD = GeneralUtility::_GP('CMD'); + $this->pages_uid = intval(GeneralUtility::_GP('pages_uid')); + $this->sys_dmail_uid = intval(GeneralUtility::_GP('sys_dmail_uid')); + $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause); + $access = is_array($this->pageinfo) ? 1 : 0; + + if (($this->id && $access) || ($GLOBALS['BE_USER']->user['admin'] && !$this->id)) { +*/ + /** * Configure template paths for your backend module */ @@ -43,10 +57,174 @@ public function indexAction(ServerRequestInterface $request) : ResponseInterface $this->view->setLayoutRootPaths(['EXT:direct_mail/Resources/Private/Layouts/']); $this->view->setTemplate('Statistics'); + $formcontent = $this->moduleContent(); + $this->view->assignMultiple( + [ + 'formcontent' => $formcontent + ] + ); + /** * Render template and return html content */ $this->moduleTemplate->setContent($this->view->render()); return new HtmlResponse($this->moduleTemplate->renderContent()); } + + protected function moduleContent() + { + $theOutput = ''; + + if (!$this->sys_dmail_uid) { + $theOutput = $this->displayPageInfo(); + } else { + $table = 'sys_dmail'; + $queryBuilder = $this->getQueryBuilder($table); + $queryBuilder + ->getRestrictions() + ->removeAll() + ->add(GeneralUtility::makeInstance(DeletedRestriction::class)); + $res = $queryBuilder->select('*') + ->from('sys_dmail') + ->where( + $queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)), + $queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($this->sys_dmail_uid, \PDO::PARAM_INT)) + ) + // debug($statement->getSQL()); + // debug($statement->getParameters()); + ->execute(); + +// $this->noView = 0; + if (($row = $res->fetch())) { + // Set URL data for commands + $this->setURLs($row); + + // COMMAND: + switch ($this->CMD) { + case 'displayUserInfo': + $theOutput = $this->displayUserInfo(); + break; + case 'stats': + $theOutput = $this->stats($row); + break; + default: + // Hook for handling of custom direct mail commands: + if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXT']['directmail']['handledirectmailcmd-' . $this->CMD])) { + foreach ($GLOBALS['TYPO3_CONF_VARS']['EXT']['directmail']['handledirectmailcmd-' . $this->CMD] as $funcRef) { + $params = ['pObj' => &$this]; + $theOutput = GeneralUtility::callUserFunction($funcRef, $params, $this); + } + } + } + } + } + return $theOutput; + } + + /** + * Shows the info of a page + * + * @return string The infopage of the sent newsletters + */ + protected function displayPageInfo() + { + // Here the dmail list is rendered: + $table = 'sys_dmail'; + $queryBuilder = $this->getQueryBuilder($table); + $queryBuilder + ->getRestrictions() + ->removeAll() + ->add(GeneralUtility::makeInstance(DeletedRestriction::class)); + + $res = $queryBuilder + ->selectLiteral('sys_dmail.uid', 'sys_dmail.subject', 'sys_dmail.scheduled', 'sys_dmail.scheduled_begin', 'sys_dmail.scheduled_end', 'COUNT(sys_dmail_maillog.mid) AS count') + ->from('sys_dmail','sys_dmail') + ->leftJoin( + 'sys_dmail', + 'sys_dmail_maillog', + 'sys_dmail_maillog', + $queryBuilder->expr()->eq('sys_dmail.uid', $queryBuilder->quoteIdentifier('sys_dmail_maillog.mid')) + ) + ->add('where','sys_dmail.pid=' . intval($this->id) . + ' AND sys_dmail.type IN (0,1)' . + ' AND sys_dmail.issent = 1'. + ' AND sys_dmail_maillog.response_type=0'. + ' AND sys_dmail_maillog.html_sent>0') + ->groupBy('sys_dmail_maillog.mid') + ->orderBy('sys_dmail.scheduled','DESC') + ->addOrderBy('sys_dmail.scheduled_begin','DESC') + ->execute() + ->fetchAll(); + + $onClick = ''; + if ($res) { + $onClick = ' onClick="return confirm(' . GeneralUtility::quoteJSvalue(sprintf($this->getLanguageService()->getLL('nl_l_warning'), count($res))) . ');"'; + } + $out = ''; + + if ($res) { + $out .=''; + $out .=' + + + + + + + + '; + + foreach ($res as $row) { + if (!empty($row['scheduled_begin'])) { + if (!empty($row['scheduled_end'])) { + $sent = $this->getLanguageService()->getLL('stats_overview_sent'); + } else { + $sent = $this->getLanguageService()->getLL('stats_overview_sending'); + } + } else { + $sent = $this->getLanguageService()->getLL('stats_overview_queuing'); + } + + $out.=' + + + + + + + + '; + } + $out.='
 ' . $this->getLanguageService()->getLL('stats_overview_subject') . '' . $this->getLanguageService()->getLL('stats_overview_scheduled') . '' . $this->getLanguageService()->getLL('stats_overview_delivery_begun') . '' . $this->getLanguageService()->getLL('stats_overview_delivery_ended') . '' . $this->getLanguageService()->getLL('stats_overview_total_sent') . '' . $this->getLanguageService()->getLL('stats_overview_status') . '
' . $this->iconFactory->getIconForRecord('sys_dmail', $row, Icon::SIZE_SMALL)->render() . '' . $this->linkDMail_record(GeneralUtility::fixed_lgd_cs($row['subject'], 30) . ' ', $row['uid'], $row['subject']) . '  ' . BackendUtility::datetime($row['scheduled']) . '' . ($row['scheduled_begin']?BackendUtility::datetime($row['scheduled_begin']):' ') . '' . ($row['scheduled_end']?BackendUtility::datetime($row['scheduled_end']):' ') . '' . ($row['count']?$row['count']:' ') . '' . $sent . '
'; + } + + $theOutput = '

' . $this->getLanguageService()->getLL('stats_overview_choose') . '

' . + $out; + $theOutput .= '
'; + + return $theOutput; + } + + /** + * Shows user's info and categories + * + * @return string HTML showing user's info and the categories + */ + protected function displayUserInfo() + { + return 'TEST 2'; + } + + /** + * Get statistics from DB and compile them. + * + * @param array $row DB record + * + * @return string Statistics of a mail + * @throws RouteNotFoundException If the named route doesn't exist + */ + protected function stats($row) + { + return 'TEST 3'; + } } \ No newline at end of file diff --git a/Resources/Private/Templates/Statistics.html b/Resources/Private/Templates/Statistics.html index d883692b5..8a8183f18 100644 --- a/Resources/Private/Templates/Statistics.html +++ b/Resources/Private/Templates/Statistics.html @@ -2,4 +2,5 @@

+{formcontent}
\ No newline at end of file From 614ac4ec36ef0a744624c598fd8fc1a1005e4dd6 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sat, 20 Nov 2021 13:31:25 +0000 Subject: [PATCH 022/342] RecipientListController --- Classes/Module/RecipientListController.php | 53 +++++++++++++++++++ .../Private/Templates/RecipientList.html | 5 ++ ext_tables.php | 2 +- 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 Classes/Module/RecipientListController.php create mode 100644 Resources/Private/Templates/RecipientList.html diff --git a/Classes/Module/RecipientListController.php b/Classes/Module/RecipientListController.php new file mode 100644 index 000000000..365fe1da5 --- /dev/null +++ b/Classes/Module/RecipientListController.php @@ -0,0 +1,53 @@ +moduleTemplate = $moduleTemplate ?? GeneralUtility::makeInstance(ModuleTemplate::class); + } + + public function indexAction(ServerRequestInterface $request) : ResponseInterface + { + /** + * Configure template paths for your backend module + */ + $this->view = GeneralUtility::makeInstance(StandaloneView::class); + $this->view->setTemplateRootPaths(['EXT:direct_mail/Resources/Private/Templates/']); + $this->view->setPartialRootPaths(['EXT:direct_mail/Resources/Private/Partials/']); + $this->view->setLayoutRootPaths(['EXT:direct_mail/Resources/Private/Layouts/']); + $this->view->setTemplate('RecipientList'); + + /** + * Render template and return html content + */ + $this->moduleTemplate->setContent($this->view->render()); + return new HtmlResponse($this->moduleTemplate->renderContent()); + } +} \ No newline at end of file diff --git a/Resources/Private/Templates/RecipientList.html b/Resources/Private/Templates/RecipientList.html new file mode 100644 index 000000000..8b6359a7f --- /dev/null +++ b/Resources/Private/Templates/RecipientList.html @@ -0,0 +1,5 @@ + + + +

+
\ No newline at end of file diff --git a/ext_tables.php b/ext_tables.php index 4a4dff321..4df4d8eba 100755 --- a/ext_tables.php +++ b/ext_tables.php @@ -68,7 +68,7 @@ 'bottom', '', [ - 'routeTarget' => DirectMailTeam\DirectMail\Module\RecipientList::class . '::mainAction', + 'routeTarget' => DirectMailTeam\DirectMail\Module\RecipientListController::class . '::indexAction', 'access' => 'group,user', 'name' => 'DirectMailNavFrame_RecipientList', 'workspaces' => 'online', From 5c934592ed234953a0f2d43189f7917f979d9d64 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sat, 20 Nov 2021 13:47:29 +0000 Subject: [PATCH 023/342] style --- Classes/Module/RecipientList.php | 57 +++++++++++++++----------------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/Classes/Module/RecipientList.php b/Classes/Module/RecipientList.php index fd05880da..ebf104297 100644 --- a/Classes/Module/RecipientList.php +++ b/Classes/Module/RecipientList.php @@ -48,7 +48,7 @@ class RecipientList extends BaseScriptClass { public $fieldList = 'uid,name,first_name,middle_name,last_name,title,email,phone,www,address,company,city,zip,country,fax,module_sys_dmail_category,module_sys_dmail_html'; // Internal - public $params = array(); + public $params = []; public $perms_clause = ''; public $pageinfo = ''; public $sys_dmail_uid; @@ -62,12 +62,12 @@ class RecipientList extends BaseScriptClass public $url_plain; public $url_html; public $mode; - public $implodedParams=array(); + public $implodedParams=[]; // If set a valid user table is around public $userTable; public $sys_language_uid = 0; public $error=''; - public $allowedTables = array('tt_address','fe_users'); + public $allowedTables = ['tt_address','fe_users']; /** * Query generator @@ -188,22 +188,21 @@ function jumpToUrlD(URL) { // '; - $markers = array( + $markers = [ 'FLASHMESSAGES' => '', 'CONTENT' => '', - ); + ]; - $docHeaderButtons = array( + $docHeaderButtons = [ 'PAGEPATH' => $this->getLanguageService()->getLL('labels.path') . ': ' . GeneralUtility::fixed_lgd_cs($this->pageinfo['_thePath'], 50), 'SHORTCUT' => '', 'CSH' => BackendUtility::cshItem($this->cshTable, '', $GLOBALS['BACK_PATH']) - ); + ]; // shortcut icon if ($GLOBALS['BE_USER']->mayMakeShortcut()) { $docHeaderButtons['SHORTCUT'] = $this->doc->makeShortcutIcon('id', implode(',', array_keys($this->MOD_MENU)), $this->MCONF['name'], '', 'btn btn-default btn-sm'); } - $module = $this->pageinfo['module']; if (!$module) { $pidrec = BackendUtility::getRecord('pages', intval($this->pageinfo['pid'])); @@ -242,7 +241,7 @@ function jumpToUrlD(URL) { // } $this->content = $this->doc->startPage($this->getLanguageService()->getLL('mailgroup_header')); - $this->content.= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers, array()); + $this->content.= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers, []); } else { // If no access or if ID == zero @@ -271,8 +270,7 @@ public function printContent() */ protected function moduleContent() { - - // COMMAND: + // COMMAND: switch ($this->CMD) { case 'displayUserInfo': $theOutput = $this->cmd_displayUserInfo(); @@ -371,7 +369,7 @@ public function showExistingRecipientLists() // New: $out = '' . - $this->iconFactory->getIconForRecord('sys_dmail_group', array(), Icon::SIZE_SMALL) . + $this->iconFactory->getIconForRecord('sys_dmail_group', [], Icon::SIZE_SMALL) . $this->getLanguageService()->getLL('recip_create_mailgroup_msg') . ''; $theOutput .= '
'; $theOutput .= '

' . $this->getLanguageService()->getLL('recip_select_mailgroup') . '

' . @@ -458,7 +456,7 @@ public function linkRecip_record($str, $uid) */ public function cmd_compileMailGroup($groupUid) { - $idLists = array(); + $idLists = []; if ($groupUid) { $mailGroup = BackendUtility::getRecord('sys_dmail_group', $groupUid); if (is_array($mailGroup) && $mailGroup['pid']==$this->id) { @@ -469,7 +467,7 @@ public function cmd_compileMailGroup($groupUid) $thePages = $mailGroup['pages'] ? $mailGroup['pages'] : $this->id; // Explode the pages $pages = GeneralUtility::intExplode(',', $thePages); - $pageIdArray=array(); + $pageIdArray = []; foreach ($pages as $pageUid) { if ($pageUid>0) { $pageinfo = BackendUtility::readPageAccess($pageUid, $this->perms_clause); @@ -505,7 +503,7 @@ public function cmd_compileMailGroup($groupUid) // fe_groups if ($whichTables&8) { if (!is_array($idLists['fe_users'])) { - $idLists['fe_users'] = array(); + $idLists['fe_users'] = []; } $idLists['fe_users'] = array_unique(array_merge($idLists['fe_users'], DirectMailUtility::getIdList('fe_groups', $pidList, $groupUid, $mailGroup['select_categories']))); } @@ -578,7 +576,7 @@ public function cmd_compileMailGroup($groupUid) * manipulate the generated id_lists */ if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['direct_mail']['mod3']['cmd_compileMailGroup'])) { - $hookObjectsArr = array(); + $hookObjectsArr = []; foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['direct_mail']['mod3']['cmd_compileMailGroup'] as $classRef) { $hookObjectsArr[] = GeneralUtility::makeInstance($classRef); @@ -593,10 +591,9 @@ public function cmd_compileMailGroup($groupUid) $idLists = $temporaryList; } - - return array( - 'queryInfo' => array('id_lists' => $idLists) - ); + return [ + 'queryInfo' => ['id_lists' => $idLists] + ]; } /** @@ -687,7 +684,7 @@ public function cmd_displayMailGroup($result) if (is_array($idLists['tt_address']) && count($idLists['tt_address'])) { $recipContent = $csvError . $this->getLanguageService()->getLL('mailgroup_recip_number') . ' ' . count($idLists['tt_address']) . - '
' . $this->getLanguageService()->getLL('mailgroup_download') . ''; + '
' . $this->getLanguageService()->getLL('mailgroup_download') . ''; $theOutput.= '

' . $this->getLanguageService()->getLL('mailgroup_table_address') .'

' . $csvError . $recipContent; @@ -696,7 +693,7 @@ public function cmd_displayMailGroup($result) if (is_array($idLists['fe_users']) && count($idLists['fe_users'])) { $recipContent = $csvError . $this->getLanguageService()->getLL('mailgroup_recip_number') . ' ' . count($idLists['fe_users']) . - '
' . $this->getLanguageService()->getLL('mailgroup_download') . ''; + '
' . $this->getLanguageService()->getLL('mailgroup_download') . ''; $theOutput.= '

' . $this->getLanguageService()->getLL('mailgroup_table_fe_users') . '

' . $csvError . $recipContent; @@ -705,7 +702,7 @@ public function cmd_displayMailGroup($result) if (is_array($idLists['PLAINLIST']) && count($idLists['PLAINLIST'])) { $recipContent = $csvError . $this->getLanguageService()->getLL('mailgroup_recip_number') . ' ' . count($idLists['PLAINLIST']) . - '
' . $this->getLanguageService()->getLL('mailgroup_download') . ''; + '
' . $this->getLanguageService()->getLL('mailgroup_download') . ''; $theOutput.= '

' . $this->getLanguageService()->getLL('mailgroup_plain_list') .'

' . $csvError . $recipContent; @@ -714,7 +711,7 @@ public function cmd_displayMailGroup($result) if (is_array($idLists[$this->userTable]) && count($idLists[$this->userTable])) { $recipContent = $csvError . $this->getLanguageService()->getLL('mailgroup_recip_number') . ' ' . count($idLists[$this->userTable]) . - '
' . $this->getLanguageService()->getLL('mailgroup_download') . ''; + '
' . $this->getLanguageService()->getLL('mailgroup_download') . ''; $theOutput.= '

' . $this->getLanguageService()->getLL('mailgroup_table_custom') . '

' . $csvError . $recipContent; @@ -771,10 +768,10 @@ public function update_specialQuery($mailGroup) } elseif ($this->MOD_SETTINGS['queryTable'] == $this->userTable) { $whichTables = 4; } - $updateFields = array( + $updateFields = [ 'whichtables' => intval($whichTables), 'query' => $this->MOD_SETTINGS['queryConfig'] - ); + ]; $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); @@ -834,7 +831,7 @@ public function cmd_specialQuery($mailGroup) */ public function downloadCSV(array $idArr) { - $lines = array(); + $lines = []; if (is_array($idArr) && count($idArr)) { reset($idArr); $lines[] = CsvUtility::csvValues(array_keys(current($idArr)), ',', ''); @@ -878,12 +875,12 @@ public function cmd_displayUserInfo() // see fe_users case 'fe_users': if (is_array($indata)) { - $data=array(); + $data=[]; if (is_array($indata['categories'])) { reset($indata['categories']); foreach ($indata['categories'] as $recValues) { reset($recValues); - $enabled = array(); + $enabled = []; foreach ($recValues as $k => $b) { if ($b) { $enabled[] = $k; @@ -896,7 +893,7 @@ public function cmd_displayUserInfo() /* @var $tce \TYPO3\CMS\Core\DataHandling\DataHandler*/ $tce = GeneralUtility::makeInstance(DataHandler::class); $tce->stripslashes_values = 0; - $tce->start($data, array()); + $tce->start($data, []); $tce->process_datamap(); } break; From 476b39b6e4cd57b765392ef906e16debcbe0d859 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sun, 21 Nov 2021 12:27:25 +0000 Subject: [PATCH 024/342] change branch --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5eee0479f..ba79e01b2 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ }, "require": { "typo3/cms-core": "^11.5", - "friendsoftypo3/tt-address": "dev-master" + "friendsoftypo3/tt-address": ""^5.3" }, "require-dev": { "roave/security-advisories": "dev-master" From f2bb07fa7f13a8cb8f6f462fcd3aa4ef731e4222 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sun, 21 Nov 2021 12:28:35 +0000 Subject: [PATCH 025/342] typo --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ba79e01b2..399e69d93 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ }, "require": { "typo3/cms-core": "^11.5", - "friendsoftypo3/tt-address": ""^5.3" + "friendsoftypo3/tt-address": "^5.3" }, "require-dev": { "roave/security-advisories": "dev-master" From 596f721588bca0f7df5c2345c039966c7f9328a5 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sun, 21 Nov 2021 13:12:46 +0000 Subject: [PATCH 026/342] change branch --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 399e69d93..5eee0479f 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ }, "require": { "typo3/cms-core": "^11.5", - "friendsoftypo3/tt-address": "^5.3" + "friendsoftypo3/tt-address": "dev-master" }, "require-dev": { "roave/security-advisories": "dev-master" From 91272efbeab3a079375de4a48e37ad18f83e25ec Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sat, 27 Nov 2021 14:26:50 +0000 Subject: [PATCH 027/342] update new controllers --- Classes/Module/MailerEngineController.php | 2 +- Classes/Module/RecipientListController.php | 163 +++ Classes/Module/StatisticsController.php | 1043 ++++++++++++++++- .../Private/Templates/RecipientList.html | 1 + 4 files changed, 1205 insertions(+), 4 deletions(-) diff --git a/Classes/Module/MailerEngineController.php b/Classes/Module/MailerEngineController.php index 7b73653ca..59ce1c3c5 100644 --- a/Classes/Module/MailerEngineController.php +++ b/Classes/Module/MailerEngineController.php @@ -239,7 +239,7 @@ public function cmd_mailerengine() foreach($countres as $cRow) $count = $cRow['COUNT(*)']; $out .=' - ' . $this->iconFactory->getIconForRecord('sys_dmail', $row, Icon::SIZE_SMALL)->render() . ' + ' . $this->moduleTemplate->getIconFactory()->getIconForRecord('sys_dmail', $row, Icon::SIZE_SMALL)->render() . ' ' . $this->linkDMail_record(htmlspecialchars(GeneralUtility::fixed_lgd_cs($row['subject'], 100)) . '  ', $row['uid']) . ' ' . BackendUtility::datetime($row['scheduled']) . '   ' . ($row['scheduled_begin']?BackendUtility::datetime($row['scheduled_begin']):'') . '   diff --git a/Classes/Module/RecipientListController.php b/Classes/Module/RecipientListController.php index 365fe1da5..fdecf0978 100644 --- a/Classes/Module/RecipientListController.php +++ b/Classes/Module/RecipientListController.php @@ -3,11 +3,15 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; +use TYPO3\CMS\Backend\Routing\UriBuilder; use TYPO3\CMS\Backend\Template\ModuleTemplate; +use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Http\HtmlResponse; +use TYPO3\CMS\Core\Imaging\Icon; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Fluid\View\StandaloneView; use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction; +use DirectMailTeam\DirectMail\DirectMailUtility; class RecipientListController extends MainController { @@ -23,6 +27,17 @@ class RecipientListController extends MainController */ protected $view; + protected $CMD = ''; + protected $id; + protected $sys_dmail_uid = 0; + + /** + * The name of the module + * + * @var string + */ + protected $moduleName = ''; + /** * Constructor Method * @@ -35,6 +50,17 @@ public function __construct(ModuleTemplate $moduleTemplate = null) public function indexAction(ServerRequestInterface $request) : ResponseInterface { + $this->moduleName = (string)($request->getQueryParams()['currentModule'] ?? $request->getParsedBody()['currentModule'] ?? 'DirectMailNavFrame_RecipientList'); + /* + $this->CMD = GeneralUtility::_GP('CMD'); + $this->pages_uid = intval(GeneralUtility::_GP('pages_uid')); + $this->sys_dmail_uid = intval(GeneralUtility::_GP('sys_dmail_uid')); + $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause); + $access = is_array($this->pageinfo) ? 1 : 0; + + if (($this->id && $access) || ($GLOBALS['BE_USER']->user['admin'] && !$this->id)) { + */ + /** * Configure template paths for your backend module */ @@ -44,10 +70,147 @@ public function indexAction(ServerRequestInterface $request) : ResponseInterface $this->view->setLayoutRootPaths(['EXT:direct_mail/Resources/Private/Layouts/']); $this->view->setTemplate('RecipientList'); + $formcontent = $this->moduleContent(); + $this->view->assignMultiple( + [ + 'formcontent' => $formcontent + ] + ); + /** * Render template and return html content */ $this->moduleTemplate->setContent($this->view->render()); return new HtmlResponse($this->moduleTemplate->renderContent()); } + + /** + * Show the module content + * + * @return string The compiled content of the module. + */ + protected function moduleContent() + { + // COMMAND: + switch ($this->CMD) { + case 'displayUserInfo': + $theOutput = $this->cmd_displayUserInfo(); + break; + case 'displayMailGroup': + $result = $this->cmd_compileMailGroup(intval(GeneralUtility::_GP('group_uid'))); + $theOutput = $this->cmd_displayMailGroup($result); + break; + case 'displayImport': + /* @var $importer \DirectMailTeam\DirectMail\Importer */ + $importer = GeneralUtility::makeInstance(Importer::class); + $importer->init($this); + $theOutput = $importer->cmd_displayImport(); + break; + default: + $theOutput = $this->showExistingRecipientLists(); + } + + return $theOutput; + } + + /** + * Shows the existing recipient lists and shows link to create a new one or import a list + * + * @return string List of existing recipient list, link to create a new list and link to import + * @throws RouteNotFoundException If the named route doesn't exist + */ + protected function showExistingRecipientLists() + { + + $out = ' +   + ' . $this->getLanguageService()->getLL('title') . ' + ' . $this->getLanguageService()->getLL('type') . ' + ' . $this->getLanguageService()->getLL('description') . ' + ' . $this->getLanguageService()->getLL('recip_group_amount') . ' + '; + + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_dmail_group'); + $queryBuilder + ->getRestrictions() + ->removeAll() + ->add(GeneralUtility::makeInstance(DeletedRestriction::class)); + $res = $queryBuilder->select('uid','pid','title','description','type') + ->from('sys_dmail_group') + ->where( + $queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($this->id,\PDO::PARAM_INT)) + ) + ->orderBy( + preg_replace( + '/^(?:ORDER[[:space:]]*BY[[:space:]]*)+/i', '', + trim($GLOBALS['TCA']['sys_dmail_group']['ctrl']['default_sortby']) + ) + ) + ->execute() + ->fetchAll(); + + foreach($res as $row) { + $result = $this->cmd_compileMailGroup(intval($row['uid'])); + $count = 0; + $idLists = $result['queryInfo']['id_lists']; + if (is_array($idLists['tt_address'])) { + $count+=count($idLists['tt_address']); + } + if (is_array($idLists['fe_users'])) { + $count+=count($idLists['fe_users']); + } + if (is_array($idLists['PLAINLIST'])) { + $count+=count($idLists['PLAINLIST']); + } + if (is_array($idLists[$this->userTable])) { + $count+=count($idLists[$this->userTable]); + } + + $out .= ' + ' . $this->moduleTemplate->getIconFactory()->getIconForRecord('sys_dmail_group', $row, Icon::SIZE_SMALL)->render() . ' + ' . $this->editLink('sys_dmail_group', $row['uid']) . ' + ' . $this->linkRecip_record('' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($row['title'], 30)) . '  ', $row['uid']) . ' + ' . htmlspecialchars(BackendUtility::getProcessedValue('sys_dmail_group', 'type', $row['type'])) . '   + ' . BackendUtility::getProcessedValue('sys_dmail_group', 'description', htmlspecialchars($row['description'])) . '   + ' . $count . ' + '; + } + + $out =' ' . $out . '
'; + $theOutput = '

' . $this->getLanguageService()->getLL('recip_select_mailgroup') . '

' . + $out; + + $editOnClickLink = DirectMailUtility::getEditOnClickLink([ + 'edit' => [ + 'sys_dmail_group' => [ + $this->id => 'new' + ] + ], + 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI'), + ]); + + // New: + $out = '' . + $this->moduleTemplate->getIconFactory()->getIconForRecord('sys_dmail_group', [], Icon::SIZE_SMALL) . + $this->getLanguageService()->getLL('recip_create_mailgroup_msg') . ''; + $theOutput .= '
'; + $theOutput .= '

' . $this->getLanguageService()->getLL('recip_select_mailgroup') . '

' . + $out; + + // Import + /** @var UriBuilder $uriBuilder */ + $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); + $moduleUrl = $uriBuilder->buildUriFromRoute( + $this->moduleName, + [ + 'id' => $this->id, + 'CMD' => 'displayImport' + ] + ); + $out = '' . $this->getLanguageService()->getLL('recip_import_mailgroup_msg') . ''; + $theOutput.= '
'; + $theOutput.= '

' . $this->getLanguageService()->getLL('mailgroup_import') . '

' . $out; + return $theOutput; + } + } \ No newline at end of file diff --git a/Classes/Module/StatisticsController.php b/Classes/Module/StatisticsController.php index 467c14dd1..81e568d6b 100644 --- a/Classes/Module/StatisticsController.php +++ b/Classes/Module/StatisticsController.php @@ -23,6 +23,7 @@ class StatisticsController extends MainController */ protected $view; + protected $CMD = ''; protected $id = 0; protected $sys_dmail_uid = 0; @@ -186,7 +187,7 @@ protected function displayPageInfo() } $out.=' - ' . $this->iconFactory->getIconForRecord('sys_dmail', $row, Icon::SIZE_SMALL)->render() . ' + ' . $this->moduleTemplate->getIconFactory()->getIconForRecord('sys_dmail', $row, Icon::SIZE_SMALL)->render() . ' ' . $this->linkDMail_record(GeneralUtility::fixed_lgd_cs($row['subject'], 30) . ' ', $row['uid'], $row['subject']) . '   ' . BackendUtility::datetime($row['scheduled']) . ' ' . ($row['scheduled_begin']?BackendUtility::datetime($row['scheduled_begin']):' ') . ' @@ -212,7 +213,144 @@ protected function displayPageInfo() */ protected function displayUserInfo() { - return 'TEST 2'; + $uid = intval(GeneralUtility::_GP('uid')); + $indata = GeneralUtility::_GP('indata'); + $table = GeneralUtility::_GP('table'); + + $mmTable = $GLOBALS['TCA'][$table]['columns']['module_sys_dmail_category']['config']['MM']; + + if (GeneralUtility::_GP('submit')) { + $indata = GeneralUtility::_GP('indata'); + if (!$indata) { + $indata['html']= 0; + } + } + + switch ($table) { + case 'tt_address': + // see fe_users + case 'fe_users': + if (is_array($indata)) { + $data = []; + if (is_array($indata['categories'])) { + reset($indata['categories']); + foreach ($indata['categories'] as $recValues) { + $enabled = []; + foreach ($recValues as $k => $b) { + if ($b) { + $enabled[] = $k; + } + } + $data[$table][$uid]['module_sys_dmail_category'] = implode(',', $enabled); + } + } + $data[$table][$uid]['module_sys_dmail_html'] = $indata['html'] ? 1 : 0; + + /* @var $tce \TYPO3\CMS\Core\DataHandling\DataHandler */ + $tce = GeneralUtility::makeInstance(DataHandler::class); + $tce->stripslashes_values = 0; + $tce->start($data, []); + $tce->process_datamap(); + } + break; + default: + // do nothing + } + + switch ($table) { + case 'tt_address': + + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_language'); + $res = $queryBuilder + ->select('tt_address.*') + ->from('tt_address','tt_address') + ->leftjoin( + 'tt_address', + 'pages', + 'pages', + $queryBuilder->expr()->eq('pages.uid', $queryBuilder->quoteIdentifier('tt_address.pid')) + ) + ->add('where','tt_address.uid=' . intval($uid) . + ' AND ' . $this->perms_clause . ' AND pages.deleted = 0') + ->execute(); + break; + case 'fe_users': + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('fe_users'); + $res = $queryBuilder + ->select('fe_users.*') + ->from('fe_users','fe_users') + ->leftjoin( + 'fe_users', + 'pages', + 'pages', + $queryBuilder->expr()->eq('pages.uid', $queryBuilder->quoteIdentifier('fe_users.pid')) + ) + ->add('where','fe_users.uid=' . intval($uid) . + ' AND ' . $this->perms_clause . ' AND pages.deleted = 0') + ->execute(); + break; + default: + // do nothing + } + + $row = []; + if ($res) { + $row = $res->fetch(); + } + + $theOutput = ''; + if (is_array($row)) { + $categories = ''; + + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($mmTable); + $resCat = $queryBuilder + ->select('uid_foreign') + ->from($mmTable) + ->add('where','uid_local=' . $row['uid']) + ->execute(); + while (($rowCat = $resCat->fetch())) { + $categories .= $rowCat['uid_foreign'] . ','; + } + $categories = rtrim($categories, ','); + + $editOnClickLink = DirectMailUtility::getEditOnClickLink([ + 'edit' => [ + $table => [ + $row['uid'] => 'edit', + ], + ], + 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI'), + ]); + + $out = ''; + $out .= $this->moduleTemplate->getIconFactory()->getIconForRecord($table, $row)->render() . htmlspecialchars($row['name'] . ' <' . $row['email'] . '>'); + $out .= '  ' . + $this->moduleTemplate->getIconFactory()->getIcon('actions-open', Icon::SIZE_SMALL) . + $this->getLanguageService()->getLL('dmail_edit') . ''; + $theOutput = '

' . $this->getLanguageService()->getLL('subscriber_info') . '

' . $out; + + $out = ''; + + $this->categories = DirectMailUtility::makeCategories($table, $row, $this->sys_language_uid); + + foreach ($this->categories as $pKey => $pVal) { + $out .='' . + ' ' . + htmlspecialchars($pVal) . '
'; + } + $out .= '

'; + $out .= $this->getLanguageService()->getLL('subscriber_profile_htmlemail') . '
'; + + $out .= '' . + '' . + '
' . + ''; + $theOutput .= '
'; + $theOutput .= '

' . $this->getLanguageService()->getLL('subscriber_profile') . '

' . + $this->getLanguageService()->getLL('subscriber_profile_instructions') . '

' . $out; + } + + return $theOutput; } /** @@ -225,6 +363,905 @@ protected function displayUserInfo() */ protected function stats($row) { - return 'TEST 3'; + if (GeneralUtility::_GP('recalcCache')) { + $this->makeStatTempTableContent($row); + } + /** @var UriBuilder $uriBuilder */ + $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); + $thisurl = $uriBuilder->buildUriFromRoute( + $this->moduleName, + [ + 'id' => $this->id, + 'sys_dmail_uid' => $row['uid'], + 'CMD' => $this->CMD, + 'recalcCache' => 1 + ] + ); + $output = $this->directMail_compactView($row); + + // ***************************** + // Mail responses, general: + // ***************************** + + $mailingId = intval($row['uid']); + $fieldRows = 'response_type'; + $addFieldRows = '*'; + $tableRows = 'sys_dmail_maillog'; + $whereRows = 'mid=' . $mailingId; + $groupByRows = 'response_type'; + $orderByRows = ''; + $queryArray = [$fieldRows, $addFieldRows, $tableRows, $whereRows, $groupByRows, $orderByRows]; + + $table = $this->getQueryRows($queryArray, 'response_type'); + + // Plaintext/HTML + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_dmail_maillog'); + + $res = $queryBuilder + ->count('*') + ->addSelect('html_sent') + ->from('sys_dmail_maillog') + ->add('where','mid=' . $mailingId . ' AND response_type=0') + ->groupBy('html_sent') + ->execute() + ->fetchAll(); + + /* this function is called to change the key from 'COUNT(*)' to 'counter' */ + $res = $this->changekeyname($res,'counter','COUNT(*)'); + + $textHtml = []; + foreach($res as $row2){ + // 0:No mail; 1:HTML; 2:TEXT; 3:HTML+TEXT + $textHtml[$row2['html_sent']] = $row2['counter']; + } + + // Unique responses, html + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_dmail_maillog'); + + $res = $queryBuilder + ->count('*') + ->from('sys_dmail_maillog') + ->add('where','mid=' . $mailingId . ' AND response_type=1') + ->groupBy('rid') + ->addGroupBy('rtbl') + ->orderBy('COUNT(*)') + ->execute() + ->fetchAll(); + + $uniqueHtmlResponses = count($res);//sql_num_rows($res); + + // Unique responses, Plain + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_dmail_maillog'); + + $res = $queryBuilder + ->count('*') + ->from('sys_dmail_maillog') + ->add('where','mid=' . $mailingId . ' AND response_type=2') + ->groupBy('rid') + ->addGroupBy('rtbl') + ->orderBy('COUNT(*)') + ->execute() + ->fetchAll(); + $uniquePlainResponses = count($res); //sql_num_rows($res); + + // Unique responses, pings + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_dmail_maillog'); + + $res = $queryBuilder + ->count('*') + ->from('sys_dmail_maillog') + ->add('where','mid=' . $mailingId . ' AND response_type=-1') + ->groupBy('rid') + ->addGroupBy('rtbl') + ->orderBy('COUNT(*)') + ->execute() + ->fetchAll(); + $uniquePingResponses = count($res);//sql_num_rows($res); + ; + + $tblLines = []; + $tblLines[] = ['',$this->getLanguageService()->getLL('stats_total'),$this->getLanguageService()->getLL('stats_HTML'),$this->getLanguageService()->getLL('stats_plaintext')]; + + $totalSent = intval($textHtml['1'] + $textHtml['2'] + $textHtml['3']); + $htmlSent = intval($textHtml['1']+$textHtml['3']); + $plainSent = intval($textHtml['2']); + + $tblLines[] = array($this->getLanguageService()->getLL('stats_mails_sent'),$totalSent,$htmlSent,$plainSent); + $tblLines[] = array($this->getLanguageService()->getLL('stats_mails_returned'),$this->showWithPercent($table['-127']['counter'], $totalSent)); + $tblLines[] = array($this->getLanguageService()->getLL('stats_HTML_mails_viewed'),'',$this->showWithPercent($uniquePingResponses, $htmlSent)); + $tblLines[] = array($this->getLanguageService()->getLL('stats_unique_responses'),$this->showWithPercent($uniqueHtmlResponses+$uniquePlainResponses, $totalSent),$this->showWithPercent($uniqueHtmlResponses, $htmlSent),$this->showWithPercent($uniquePlainResponses, $plainSent?$plainSent:$htmlSent)); + + $output.='

' . $this->getLanguageService()->getLL('stats_general_information') . '

'; + $output.= DirectMailUtility::formatTable($tblLines, ['nowrap', 'nowrap', 'nowrap', 'nowrap'], 1, []); + + // ****************** + // Links: + // ****************** + + // initialize $urlCounter + $urlCounter = [ + 'total' => [], + 'plain' => [], + 'html' => [], + ]; + // Most popular links, html: + $fieldRows = 'url_id'; + $addFieldRows = '*'; + $tableRows = 'sys_dmail_maillog'; + $whereRows = 'mid=' . intval($row['uid']) . ' AND response_type=1'; + $groupByRows = 'url_id'; + $orderByRows = 'COUNT(*)'; + //$queryArray = array('url_id,count(*) as counter', 'sys_dmail_maillog', 'mid=' . intval($row['uid']) . ' AND response_type=1', 'url_id', 'counter'); + $queryArray = [$fieldRows, $addFieldRows, $tableRows, $whereRows, $groupByRows, $orderByRows]; + $htmlUrlsTable=$this->getQueryRows($queryArray, 'url_id'); + + // Most popular links, plain: + $fieldRows = 'url_id'; + $addFieldRows = '*'; + $tableRows = 'sys_dmail_maillog'; + $whereRows = 'mid=' . intval($row['uid']) . ' AND response_type=2'; + $groupByRows = 'url_id'; + $orderByRows = 'COUNT(*)'; + //$queryArray = array('url_id,count(*) as counter', 'sys_dmail_maillog', 'mid=' . intval($row['uid']) . ' AND response_type=2', 'url_id', 'counter'); + $queryArray = [$fieldRows, $addFieldRows, $tableRows, $whereRows, $groupByRows, $orderByRows]; + $plainUrlsTable=$this->getQueryRows($queryArray, 'url_id'); + + + // Find urls: + $unpackedMail = unserialize(base64_decode($row['mailContent'])); + // this array will include a unique list of all URLs that are used in the mailing + $urlArr = []; + + $urlMd5Map = []; + if (is_array($unpackedMail['html']['hrefs'])) { + foreach ($unpackedMail['html']['hrefs'] as $k => $v) { + // convert & of query params back + $urlArr[$k] = html_entity_decode($v['absRef']); + $urlMd5Map[md5($v['absRef'])] = $k; + } + } + if (is_array($unpackedMail['plain']['link_ids'])) { + foreach ($unpackedMail['plain']['link_ids'] as $k => $v) { + $urlArr[intval(-$k)] = $v; + } + } + + // Traverse plain urls: + $mappedPlainUrlsTable = []; + foreach ($plainUrlsTable as $id => $c) { + $url = $urlArr[intval($id)]; + if (isset($urlMd5Map[md5($url)])) { + $mappedPlainUrlsTable[$urlMd5Map[md5($url)]] = $c; + } else { + $mappedPlainUrlsTable[$id] = $c; + } + } + + $urlCounter['total'] = []; + // Traverse html urls: + $urlCounter['html'] = []; + if (count($htmlUrlsTable) > 0) { + foreach ($htmlUrlsTable as $id => $c) { + $urlCounter['html'][$id]['counter'] = $urlCounter['total'][$id]['counter'] = $c['counter']; + } + } + + // Traverse plain urls: + $urlCounter['plain'] = []; + foreach ($mappedPlainUrlsTable as $id => $c) { + // Look up plain url in html urls + $htmlLinkFound = false; + foreach ($urlCounter['html'] as $htmlId => $_) { + if ($urlArr[$id] == $urlArr[$htmlId]) { + $urlCounter['html'][$htmlId]['plainId'] = $id; + $urlCounter['html'][$htmlId]['plainCounter'] = $c['counter']; + $urlCounter['total'][$htmlId]['counter'] = $urlCounter['total'][$htmlId]['counter'] + $c['counter']; + $htmlLinkFound = true; + break; + } + } + if (!$htmlLinkFound) { + $urlCounter['plain'][$id]['counter'] = $c['counter']; + $urlCounter['total'][$id]['counter'] = $urlCounter['total'][$id]['counter'] + $c['counter']; + } + } + + $tblLines = []; + $tblLines[] = array('',$this->getLanguageService()->getLL('stats_total'),$this->getLanguageService()->getLL('stats_HTML'),$this->getLanguageService()->getLL('stats_plaintext')); + $tblLines[] = array($this->getLanguageService()->getLL('stats_total_responses'),$table['1']['counter'] + $table['2']['counter'],$table['1']['counter']?$table['1']['counter']:'0',$table['2']['counter']?$table['2']['counter']:'0'); + $tblLines[] = array($this->getLanguageService()->getLL('stats_unique_responses'),$this->showWithPercent($uniqueHtmlResponses+$uniquePlainResponses, $totalSent), $this->showWithPercent($uniqueHtmlResponses, $htmlSent), $this->showWithPercent($uniquePlainResponses, $plainSent?$plainSent:$htmlSent)); + $tblLines[] = array($this->getLanguageService()->getLL('stats_links_clicked_per_respondent'), + ($uniqueHtmlResponses+$uniquePlainResponses ? number_format(($table['1']['counter']+$table['2']['counter'])/($uniqueHtmlResponses+$uniquePlainResponses), 2) : '-'), + ($uniqueHtmlResponses ? number_format(($table['1']['counter'])/($uniqueHtmlResponses), 2) : '-'), + ($uniquePlainResponses ? number_format(($table['2']['counter'])/($uniquePlainResponses), 2) : '-') + ); + + $output.='

' . $this->getLanguageService()->getLL('stats_response') . '

'; + $output.=DirectMailUtility::formatTable($tblLines, ['nowrap', 'nowrap', 'nowrap', 'nowrap'], 1, [0, 0, 0, 0]); + + arsort($urlCounter['total']); + arsort($urlCounter['html']); + arsort($urlCounter['plain']); + reset($urlCounter['total']); + + $tblLines = []; + $tblLines[] = array('',$this->getLanguageService()->getLL('stats_HTML_link_nr'),$this->getLanguageService()->getLL('stats_plaintext_link_nr'),$this->getLanguageService()->getLL('stats_total'),$this->getLanguageService()->getLL('stats_HTML'),$this->getLanguageService()->getLL('stats_plaintext'),''); + + // HTML mails + if (intval($row['sendOptions']) & 0x2) { + $htmlContent = $unpackedMail['html']['content']; + + $htmlLinks = []; + if (is_array($unpackedMail['html']['hrefs'])) { + foreach ($unpackedMail['html']['hrefs'] as $jumpurlId => $data) { + $htmlLinks[$jumpurlId] = [ + 'url' => $data['ref'], + 'label' => '' + ]; + } + } + + // Parse mail body + $dom = new \DOMDocument; + @$dom->loadHTML($htmlContent); + $links = []; + // Get all links + foreach ($dom->getElementsByTagName('a') as $node) { + $links[] = $node; + } + + // Process all links found + foreach ($links as $link) { + /* @var \DOMElement $link */ + $url = $link->getAttribute('href'); + + if (empty($url)) { + // Drop a tags without href + continue; + } + + if (GeneralUtility::isFirstPartOfStr($url, 'mailto:')) { + // Drop mail links + continue; + } + + $parsedUrl = GeneralUtility::explodeUrl2Array($url); + + if (!array_key_exists('jumpurl', $parsedUrl)) { + // Ignore non-jumpurl links + continue; + } + + $jumpurlId = $parsedUrl['jumpurl']; + $targetUrl = $htmlLinks[$jumpurlId]['url']; + + $title = $link->getAttribute('title'); + + if (!empty($title)) { + // no title attribute + $label = '' . GeneralUtility::fixed_lgd_cs(substr($targetUrl, -40), 40) . ''; + } else { + $label = '' . GeneralUtility::fixed_lgd_cs(substr($targetUrl, -40), 40) . ''; + } + + $htmlLinks[$jumpurlId]['label'] = $label; + } + } + + foreach ($urlCounter['total'] as $id => $_) { + // $id is the jumpurl ID + $origId = $id; + $id = abs(intval($id)); + $url = $htmlLinks[$id]['url'] ? $htmlLinks[$id]['url'] : $urlArr[$origId]; + // a link to this host? + $uParts = @parse_url($url); + $urlstr = $this->getUrlStr($uParts); + + $label = $this->getLinkLabel($url, $urlstr, false, $htmlLinks[$id]['label']); + + $img = '' . $this->moduleTemplate->getIconFactory()->getIcon('apps-toolbar-menu-search', Icon::SIZE_SMALL) . ''; + + if (isset($urlCounter['html'][$id]['plainId'])) { + $tblLines[] = array( + $label, + $id, + $urlCounter['html'][$id]['plainId'], + $urlCounter['total'][$origId]['counter'], + $urlCounter['html'][$id]['counter'], + $urlCounter['html'][$id]['plainCounter'], + $img + ); + } else { + $html = (empty($urlCounter['html'][$id]['counter']) ? 0 : 1); + $tblLines[] = array( + $label, + ($html ? $id : '-'), + ($html ? '-' : $id), + ($html ? $urlCounter['html'][$id]['counter'] : $urlCounter['plain'][$origId]['counter']), + $urlCounter['html'][$id]['counter'], + $urlCounter['plain'][$origId]['counter'], + $img + ); + } + } + + + // go through all links that were not clicked yet and that have a label + $clickedLinks = array_keys($urlCounter['total']); + foreach ($urlArr as $id => $link) { + if (!in_array($id, $clickedLinks) && (isset($htmlLinks['id']))) { + // a link to this host? + $uParts = @parse_url($link); + $urlstr = $this->getUrlStr($uParts); + + $label = $htmlLinks[$id]['label'] . ' (' . ($urlstr ? $urlstr : '/') . ')'; + $img = '' . $this->moduleTemplate->getIconFactory()->getIcon('apps-toolbar-menu-search', Icon::SIZE_SMALL) . ''; + $tblLines[] = array( + $label, + ($html ? $id : '-'), + ($html ? '-' : abs($id)), + ($html ? $urlCounter['html'][$id]['counter'] : $urlCounter['plain'][$id]['counter']), + $urlCounter['html'][$id]['counter'], + $urlCounter['plain'][$id]['counter'], + $img + ); + } + } + + if ($urlCounter['total']) { + $output .= '

' . $this->getLanguageService()->getLL('stats_response_link') . '

'; + + /** + * Hook for cmd_stats_linkResponses + */ + if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['direct_mail']['mod4']['cmd_stats_linkResponses'])) { + $hookObjectsArr = []; + foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['direct_mail']['mod4']['cmd_stats_linkResponses'] as $classRef) { + $hookObjectsArr[] = GeneralUtility::makeInstance($classRef); + } + + foreach ($hookObjectsArr as $hookObj) { + if (method_exists($hookObj, 'cmd_stats_linkResponses')) { + $output .= $hookObj->cmd_stats_linkResponses($tblLines, $this); + } + } + } else { + $output .= DirectMailUtility::formatTable($tblLines, array('nowrap', 'nowrap width="100"', 'nowrap width="100"', 'nowrap', 'nowrap', 'nowrap', 'nowrap'), 1, [1, 0, 0, 0, 0, 0, 1]); + } + } + + // ****************** + // Returned mails + // ****************** + + // The icons: + $listIcons = $this->moduleTemplate->getIconFactory()->getIcon('actions-system-list-open', Icon::SIZE_SMALL); + $csvIcons = $this->moduleTemplate->getIconFactory()->getIcon('actions-document-export-csv', Icon::SIZE_SMALL); + $hideIcons = $this->moduleTemplate->getIconFactory()->getIcon('actions-lock', Icon::SIZE_SMALL); + + // Icons mails returned + $iconsMailReturned[] = ' ' . $listIcons . ''; + $iconsMailReturned[] = ' ' . $hideIcons . ''; + $iconsMailReturned[] = ' ' . $csvIcons . ''; + + // Icons unknown recip + $iconsUnknownRecip[] = ' ' . $listIcons . ''; + $iconsUnknownRecip[] = ' ' . $hideIcons . ''; + $iconsUnknownRecip[] = ' ' . $csvIcons . ''; + + // Icons mailbox full + $iconsMailbox[] = ' ' . $listIcons . ''; + $iconsMailbox[] = ' ' . $hideIcons . ''; + $iconsMailbox[] = ' ' . $csvIcons . ''; + + // Icons bad host + $iconsBadhost[] = ' ' . $listIcons . ''; + $iconsBadhost[] = ' ' . $hideIcons . ''; + $iconsBadhost[] = ' ' . $csvIcons . ''; + + // Icons bad header + $iconsBadheader[] = ' ' . $listIcons . ''; + $iconsBadheader[] = ' ' . $hideIcons . ''; + $iconsBadheader[] = ' ' . $csvIcons . ''; + + // Icons unknown reasons + // TODO: link to show all reason + $iconsUnknownReason[] = ' ' . $listIcons . ''; + $iconsUnknownReason[] = ' ' . $hideIcons . ''; + $iconsUnknownReason[] = ' ' . $csvIcons . ''; + + // Table with Icon + $fieldRows = 'return_code'; + $addFieldRows = '*'; + $tableRows = 'sys_dmail_maillog'; + $whereRows = 'mid=' . intval($row['uid']) . ' AND response_type=-127'; + $groupByRows = 'return_code'; + $orderByRows = ''; + $queryArray = [$fieldRows, $addFieldRows, $tableRows, $whereRows, $groupByRows, $orderByRows]; + //$queryArray = array('COUNT(*) as counter'.','.'return_code', 'sys_dmail_maillog', 'mid=' . intval($row['uid']) . ' AND response_type=-127', 'return_code'); + $responseResult = $this->getQueryRows($queryArray, 'return_code'); + + $tblLines = []; + $tblLines[] = array('',$this->getLanguageService()->getLL('stats_count'),''); + $tblLines[] = array($this->getLanguageService()->getLL('stats_total_mails_returned'), ($table['-127']['counter']?number_format(intval($table['-127']['counter'])):'0'), implode(' ', $iconsMailReturned)); + $tblLines[] = array($this->getLanguageService()->getLL('stats_recipient_unknown'), $this->showWithPercent($responseResult['550']['counter']+$responseResult['553']['counter'], $table['-127']['counter']), implode(' ', $iconsUnknownRecip)); + $tblLines[] = array($this->getLanguageService()->getLL('stats_mailbox_full'), $this->showWithPercent($responseResult['551']['counter'], $table['-127']['counter']), implode(' ', $iconsMailbox)); + $tblLines[] = array($this->getLanguageService()->getLL('stats_bad_host'), $this->showWithPercent($responseResult['552']['counter'], $table['-127']['counter']), implode(' ', $iconsBadhost)); + $tblLines[] = array($this->getLanguageService()->getLL('stats_error_in_header'), $this->showWithPercent($responseResult['554']['counter'], $table['-127']['counter']),implode(' ', $iconsBadheader)); + $tblLines[] = array($this->getLanguageService()->getLL('stats_reason_unkown'), $this->showWithPercent($responseResult['-1']['counter'], $table['-127']['counter']),implode(' ', $iconsUnknownReason)); + + $output.='

' . $this->getLanguageService()->getLL('stats_mails_returned') . '

'; + $output .= DirectMailUtility::formatTable($tblLines, ['nowrap', 'nowrap', ''], 1, [0, 0, 1]); + + // Find all returned mail + if (GeneralUtility::_GP('returnList')||GeneralUtility::_GP('returnDisable')||GeneralUtility::_GP('returnCSV')) { + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) + ->getQueryBuilderForTable('sys_dmail_maillog'); + $res = $queryBuilder + ->select('rid','rtbl','email') + ->from('sys_dmail_maillog') + ->add('where','mid=' . intval($row['uid']) . + ' AND response_type=-127') + ->execute(); + + $idLists = []; + + while (($rrow = $res->fetch())) { + switch ($rrow['rtbl']) { + case 't': + $idLists['tt_address'][]=$rrow['rid']; + break; + case 'f': + $idLists['fe_users'][]=$rrow['rid']; + break; + case 'P': + $idLists['PLAINLIST'][] = $rrow['email']; + break; + default: + $idLists[$rrow['rtbl']][]=$rrow['rid']; + } + } + + if (GeneralUtility::_GP('returnList')) { + if (is_array($idLists['tt_address'])) { + $output .= '

' . $this->getLanguageService()->getLL('stats_emails') . '

' . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address', $this->id, 1, $this->sys_dmail_uid); + } + if (is_array($idLists['fe_users'])) { + $output .= '

' . $this->getLanguageService()->getLL('stats_website_users') . '

' . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users', $this->id, 1, $this->sys_dmail_uid); + } + if (is_array($idLists['PLAINLIST'])) { + $output .= '

' . $this->getLanguageService()->getLL('stats_plainlist') . '

'; + $output .= '
  • ' . join('
  • ', $idLists['PLAINLIST']) . '
'; + } + } + if (GeneralUtility::_GP('returnDisable')) { + if (is_array($idLists['tt_address'])) { + $c=$this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address'); + $output.='
' . $c . ' ' . $this->getLanguageService()->getLL('stats_emails_disabled'); + } + if (is_array($idLists['fe_users'])) { + $c=$this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users'); + $output.='
' . $c . ' ' . $this->getLanguageService()->getLL('stats_website_users_disabled'); + } + } + if (GeneralUtility::_GP('returnCSV')) { + $emails=[]; + if (is_array($idLists['tt_address'])) { + $arr=DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'); + foreach ($arr as $v) { + $emails[]=$v['email']; + } + } + if (is_array($idLists['fe_users'])) { + $arr=DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'); + foreach ($arr as $v) { + $emails[]=$v['email']; + } + } + if (is_array($idLists['PLAINLIST'])) { + $emails = array_merge($emails, $idLists['PLAINLIST']); + } + $output .= '
' . $this->getLanguageService()->getLL('stats_emails_returned_list') . '
'; + $output .= ''; + } + } + + // Find Unknown Recipient + if (GeneralUtility::_GP('unknownList')||GeneralUtility::_GP('unknownDisable')||GeneralUtility::_GP('unknownCSV')) { + + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) + ->getQueryBuilderForTable('sys_dmail_maillog'); + $res = $queryBuilder + ->select('rid','rtbl','email') + ->from('sys_dmail_maillog') + ->add('where','mid=' . intval($row['uid']) . + ' AND response_type=-127' . + ' AND (return_code=550 OR return_code=553)') + ->execute(); + $idLists = []; + while (($rrow = $res->fetch())) { + switch ($rrow['rtbl']) { + case 't': + $idLists['tt_address'][]=$rrow['rid']; + break; + case 'f': + $idLists['fe_users'][]=$rrow['rid']; + break; + case 'P': + $idLists['PLAINLIST'][] = $rrow['email']; + break; + default: + $idLists[$rrow['rtbl']][]=$rrow['rid']; + } + } + + if (GeneralUtility::_GP('unknownList')) { + if (is_array($idLists['tt_address'])) { + $output .='
' . $this->getLanguageService()->getLL('stats_emails') . '
' . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address', $this->id, 1, $this->sys_dmail_uid); + } + if (is_array($idLists['fe_users'])) { + $output .= '
' . $this->getLanguageService()->getLL('stats_website_users') . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users', $this->id, 1, $this->sys_dmail_uid); + } + if (is_array($idLists['PLAINLIST'])) { + $output .= '
' . $this->getLanguageService()->getLL('stats_plainlist'); + $output .= '
  • ' . join('
  • ', $idLists['PLAINLIST']) . '
'; + } + } + if (GeneralUtility::_GP('unknownDisable')) { + if (is_array($idLists['tt_address'])) { + $c = $this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address'); + $output .='
' . $c . ' ' . $this->getLanguageService()->getLL('stats_emails_disabled'); + } + if (is_array($idLists['fe_users'])) { + $c = $this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users'); + $output .='
' . $c . ' ' . $this->getLanguageService()->getLL('stats_website_users_disabled'); + } + } + if (GeneralUtility::_GP('unknownCSV')) { + $emails = []; + if (is_array($idLists['tt_address'])) { + $arr = DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'); + foreach ($arr as $v) { + $emails[]=$v['email']; + } + } + if (is_array($idLists['fe_users'])) { + $arr=DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'); + foreach ($arr as $v) { + $emails[]=$v['email']; + } + } + if (is_array($idLists['PLAINLIST'])) { + $emails = array_merge($emails, $idLists['PLAINLIST']); + } + $output .='
' . $this->getLanguageService()->getLL('stats_emails_returned_unknown_recipient_list') . '
'; + $output .=''; + } + } + + // Mailbox Full + if (GeneralUtility::_GP('fullList')||GeneralUtility::_GP('fullDisable')||GeneralUtility::_GP('fullCSV')) { + + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) + ->getQueryBuilderForTable('sys_dmail_maillog'); + $res = $queryBuilder + ->select('rid','rtbl','email') + ->from('sys_dmail_maillog') + ->add('where','mid=' . intval($row['uid']) . + ' AND response_type=-127' . + ' AND return_code=551') + ->execute(); + $idLists = []; + while (($rrow = $res->fetch())) { + switch ($rrow['rtbl']) { + case 't': + $idLists['tt_address'][]=$rrow['rid']; + break; + case 'f': + $idLists['fe_users'][]=$rrow['rid']; + break; + case 'P': + $idLists['PLAINLIST'][] = $rrow['email']; + break; + default: + $idLists[$rrow['rtbl']][]=$rrow['rid']; + } + } + + if (GeneralUtility::_GP('fullList')) { + if (is_array($idLists['tt_address'])) { + $output .='
' . $this->getLanguageService()->getLL('stats_emails') . '
' . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address', $this->id, 1, $this->sys_dmail_uid); + } + if (is_array($idLists['fe_users'])) { + $output.= '
' . $this->getLanguageService()->getLL('stats_website_users') . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users', $this->id, 1, $this->sys_dmail_uid); + } + if (is_array($idLists['PLAINLIST'])) { + $output .= '
' . $this->getLanguageService()->getLL('stats_plainlist'); + $output .= '
  • ' . join('
  • ', $idLists['PLAINLIST']) . '
'; + } + } + if (GeneralUtility::_GP('fullDisable')) { + if (is_array($idLists['tt_address'])) { + $c=$this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address'); + $output.='
' . $c . ' ' . $this->getLanguageService()->getLL('stats_emails_disabled'); + } + if (is_array($idLists['fe_users'])) { + $c=$this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users'); + $output.='
' . $c . ' ' . $this->getLanguageService()->getLL('stats_website_users_disabled'); + } + } + if (GeneralUtility::_GP('fullCSV')) { + $emails=[]; + if (is_array($idLists['tt_address'])) { + $arr=DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'); + foreach ($arr as $v) { + $emails[]=$v['email']; + } + } + if (is_array($idLists['fe_users'])) { + $arr=DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'); + foreach ($arr as $v) { + $emails[]=$v['email']; + } + } + if (is_array($idLists['PLAINLIST'])) { + $emails = array_merge($emails, $idLists['PLAINLIST']); + } + $output .='
' . $this->getLanguageService()->getLL('stats_emails_returned_mailbox_full_list') . '
'; + $output .=''; + } + } + + // find Bad Host + if (GeneralUtility::_GP('badHostList')||GeneralUtility::_GP('badHostDisable')||GeneralUtility::_GP('badHostCSV')) { + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) + ->getQueryBuilderForTable('sys_dmail_maillog'); + $res = $queryBuilder + ->select('rid','rtbl','email') + ->from('sys_dmail_maillog') + ->add('where','mid=' . intval($row['uid']) . + ' AND response_type=-127' . + ' AND return_code=552') + ->execute(); + $idLists = []; + while (($rrow = $res->fetch())) { + switch ($rrow['rtbl']) { + case 't': + $idLists['tt_address'][]=$rrow['rid']; + break; + case 'f': + $idLists['fe_users'][]=$rrow['rid']; + break; + case 'P': + $idLists['PLAINLIST'][] = $rrow['email']; + break; + default: + $idLists[$rrow['rtbl']][]=$rrow['rid']; + } + } + + if (GeneralUtility::_GP('badHostList')) { + if (is_array($idLists['tt_address'])) { + $output .='
' . $this->getLanguageService()->getLL('stats_emails') . '
' . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address', $this->id, 1, $this->sys_dmail_uid); + } + if (is_array($idLists['fe_users'])) { + $output .= '
' . $this->getLanguageService()->getLL('stats_website_users') . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users', $this->id, 1, $this->sys_dmail_uid); + } + if (is_array($idLists['PLAINLIST'])) { + $output .= '
' . $this->getLanguageService()->getLL('stats_plainlist'); + $output .= '
  • ' . join('
  • ', $idLists['PLAINLIST']) . '
'; + } + } + if (GeneralUtility::_GP('badHostDisable')) { + if (is_array($idLists['tt_address'])) { + $c = $this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address'); + $output .='
' . $c . ' ' . $this->getLanguageService()->getLL('stats_emails_disabled'); + } + if (is_array($idLists['fe_users'])) { + $c = $this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users'); + $output .= '
' . $c . ' ' . $this->getLanguageService()->getLL('stats_website_users_disabled'); + } + } + if (GeneralUtility::_GP('badHostCSV')) { + $emails = []; + if (is_array($idLists['tt_address'])) { + $arr = DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'); + foreach ($arr as $v) { + $emails[] = $v['email']; + } + } + if (is_array($idLists['fe_users'])) { + $arr = DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'); + foreach ($arr as $v) { + $emails[] = $v['email']; + } + } + if (is_array($idLists['PLAINLIST'])) { + $emails = array_merge($emails, $idLists['PLAINLIST']); + } + $output .= '
' . $this->getLanguageService()->getLL('stats_emails_returned_bad_host_list') . '
'; + $output .= ''; + } + } + + // find Bad Header + if (GeneralUtility::_GP('badHeaderList')||GeneralUtility::_GP('badHeaderDisable')||GeneralUtility::_GP('badHeaderCSV')) { + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) + ->getQueryBuilderForTable('sys_dmail_maillog'); + $res = $queryBuilder + ->select('rid','rtbl','email') + ->from('sys_dmail_maillog') + ->add('where','mid=' . intval($row['uid']) . + ' AND response_type=-127' . + ' AND return_code=554') + ->execute(); + + $idLists = []; + while (($rrow = $res->fetch())) { + switch ($rrow['rtbl']) { + case 't': + $idLists['tt_address'][] = $rrow['rid']; + break; + case 'f': + $idLists['fe_users'][] = $rrow['rid']; + break; + case 'P': + $idLists['PLAINLIST'][] = $rrow['email']; + break; + default: + $idLists[$rrow['rtbl']][] = $rrow['rid']; + } + } + + if (GeneralUtility::_GP('badHeaderList')) { + if (is_array($idLists['tt_address'])) { + $output .='
' . $this->getLanguageService()->getLL('stats_emails') . '
' . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address', $this->id, 1, $this->sys_dmail_uid); + } + if (is_array($idLists['fe_users'])) { + $output .= '
' . $this->getLanguageService()->getLL('stats_website_users') . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users', $this->id, 1, $this->sys_dmail_uid); + } + if (is_array($idLists['PLAINLIST'])) { + $output .= '
' . $this->getLanguageService()->getLL('stats_plainlist'); + $output .= '
  • ' . join('
  • ', $idLists['PLAINLIST']) . '
'; + } + } + + if (GeneralUtility::_GP('badHeaderDisable')) { + if (is_array($idLists['tt_address'])) { + $c = $this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address'); + $output .='
' . $c . ' ' . $this->getLanguageService()->getLL('stats_emails_disabled'); + } + if (is_array($idLists['fe_users'])) { + $c = $this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users'); + $output .='
' . $c . ' ' . $this->getLanguageService()->getLL('stats_website_users_disabled'); + } + } + if (GeneralUtility::_GP('badHeaderCSV')) { + $emails = []; + if (is_array($idLists['tt_address'])) { + $arr = DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'); + foreach ($arr as $v) { + $emails[] = $v['email']; + } + } + if (is_array($idLists['fe_users'])) { + $arr = DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'); + foreach ($arr as $v) { + $emails[] = $v['email']; + } + } + if (is_array($idLists['PLAINLIST'])) { + $emails = array_merge($emails, $idLists['PLAINLIST']); + } + $output .= '
' . $this->getLanguageService()->getLL('stats_emails_returned_bad_header_list') . '
'; + $output .= ''; + } + } + + // find Unknown Reasons + // TODO: list all reason + if (GeneralUtility::_GP('reasonUnknownList')||GeneralUtility::_GP('reasonUnknownDisable')||GeneralUtility::_GP('reasonUnknownCSV')) { + + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) + ->getQueryBuilderForTable('sys_dmail_maillog'); + $res = $queryBuilder + ->select('rid','rtbl','email') + ->from('sys_dmail_maillog') + ->add('where','mid=' . intval($row['uid']) . + ' AND response_type=-127' . + ' AND return_code=-1') + ->execute(); + $idLists = []; + while (($rrow = $res->fetch())) { + switch ($rrow['rtbl']) { + case 't': + $idLists['tt_address'][] = $rrow['rid']; + break; + case 'f': + $idLists['fe_users'][] = $rrow['rid']; + break; + case 'P': + $idLists['PLAINLIST'][] = $rrow['email']; + break; + default: + $idLists[$rrow['rtbl']][] = $rrow['rid']; + } + } + + if (GeneralUtility::_GP('reasonUnknownList')) { + if (is_array($idLists['tt_address'])) { + $output .='
' . $this->getLanguageService()->getLL('stats_emails') . '
' . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address', $this->id, 1, $this->sys_dmail_uid); + } + if (is_array($idLists['fe_users'])) { + $output .= '
' . $this->getLanguageService()->getLL('stats_website_users') . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users', $this->id, 1, $this->sys_dmail_uid); + } + if (is_array($idLists['PLAINLIST'])) { + $output .= '
' . $this->getLanguageService()->getLL('stats_plainlist'); + $output .= '
  • ' . join('
  • ', $idLists['PLAINLIST']) . '
'; + } + } + if (GeneralUtility::_GP('reasonUnknownDisable')) { + if (is_array($idLists['tt_address'])) { + $c = $this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address'); + $output .= '
' . $c . ' ' . $this->getLanguageService()->getLL('stats_emails_disabled'); + } + if (is_array($idLists['fe_users'])) { + $c = $this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users'); + $output .= '
' . $c . ' ' . $this->getLanguageService()->getLL('stats_website_users_disabled'); + } + } + if (GeneralUtility::_GP('reasonUnknownCSV')) { + $emails = []; + if (is_array($idLists['tt_address'])) { + $arr = DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'); + foreach ($arr as $v) { + $emails[]=$v['email']; + } + } + if (is_array($idLists['fe_users'])) { + $arr = DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'); + foreach ($arr as $v) { + $emails[]=$v['email']; + } + } + if (is_array($idLists['PLAINLIST'])) { + $emails = array_merge($emails, $idLists['PLAINLIST']); + } + $output .= '
' . $this->getLanguageService()->getLL('stats_emails_returned_reason_unknown_list') . '
'; + $output .= ''; + } + } + + /** + * Hook for cmd_stats_postProcess + * insert a link to open extended importer + */ + if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['direct_mail']['mod4']['cmd_stats'])) { + $hookObjectsArr = []; + foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['direct_mail']['mod4']['cmd_stats'] as $classRef) { + $hookObjectsArr[] = GeneralUtility::makeInstance($classRef); + } + + // assigned $output to class property to make it acesssible inside hook + $this->output = $output; + + // and clear the former $output to collect hoot return code there + $output = ''; + + foreach ($hookObjectsArr as $hookObj) { + if (method_exists($hookObj, 'cmd_stats_postProcess')) { + $output .= $hookObj->cmd_stats_postProcess($row, $this); + } + } + } + + $this->noView = 1; + // put all the stats tables in a section + $theOutput = '

' . $this->getLanguageService()->getLL('stats_direct_mail') .'

' . $output; + $theOutput .= '
'; + + $theOutput .= '

' . $this->getLanguageService()->getLL('stats_recalculate_cached_data') . '

' . + '

' . $this->getLanguageService()->getLL('stats_recalculate_stats') . '

'; + return $theOutput; } } \ No newline at end of file diff --git a/Resources/Private/Templates/RecipientList.html b/Resources/Private/Templates/RecipientList.html index 8b6359a7f..5f99f8f5e 100644 --- a/Resources/Private/Templates/RecipientList.html +++ b/Resources/Private/Templates/RecipientList.html @@ -2,4 +2,5 @@

+{formcontent}
\ No newline at end of file From 277c6b544391406a3521860e47a771cc896cf3de Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sat, 27 Nov 2021 15:02:32 +0000 Subject: [PATCH 028/342] update be labels --- Classes/Module/RecipientListController.php | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/Classes/Module/RecipientListController.php b/Classes/Module/RecipientListController.php index fdecf0978..018fc531d 100644 --- a/Classes/Module/RecipientListController.php +++ b/Classes/Module/RecipientListController.php @@ -5,6 +5,7 @@ use Psr\Http\Message\ServerRequestInterface; use TYPO3\CMS\Backend\Routing\UriBuilder; use TYPO3\CMS\Backend\Template\ModuleTemplate; +use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Http\HtmlResponse; use TYPO3\CMS\Core\Imaging\Icon; @@ -38,16 +39,6 @@ class RecipientListController extends MainController */ protected $moduleName = ''; - /** - * Constructor Method - * - * @var ModuleTemplate $moduleTemplate - */ - public function __construct(ModuleTemplate $moduleTemplate = null) - { - $this->moduleTemplate = $moduleTemplate ?? GeneralUtility::makeInstance(ModuleTemplate::class); - } - public function indexAction(ServerRequestInterface $request) : ResponseInterface { $this->moduleName = (string)($request->getQueryParams()['currentModule'] ?? $request->getParsedBody()['currentModule'] ?? 'DirectMailNavFrame_RecipientList'); @@ -124,12 +115,13 @@ protected function showExistingRecipientLists() $out = '   - ' . $this->getLanguageService()->getLL('title') . ' - ' . $this->getLanguageService()->getLL('type') . ' - ' . $this->getLanguageService()->getLL('description') . ' + ' . $this->getLanguageService()->sL(BackendUtility::getItemLabel('sys_dmail_group', 'title')) . ' + ' . $this->getLanguageService()->sL(BackendUtility::getItemLabel('sys_dmail_group', 'type')) . ' + ' . $this->getLanguageService()->sL(BackendUtility::getItemLabel('sys_dmail_group', 'description')) . ' ' . $this->getLanguageService()->getLL('recip_group_amount') . ' '; + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_dmail_group'); $queryBuilder ->getRestrictions() From bfcc2ebd691a9bab9785a0a04129a696a70fddb9 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sun, 5 Dec 2021 12:47:54 +0000 Subject: [PATCH 029/342] add DmailController.php --- Classes/Module/DmailController.php | 48 ++++++++++++++++++++++++++ Resources/Private/Templates/Dmail.html | 4 +++ ext_tables.php | 2 +- 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 Classes/Module/DmailController.php create mode 100644 Resources/Private/Templates/Dmail.html diff --git a/Classes/Module/DmailController.php b/Classes/Module/DmailController.php new file mode 100644 index 000000000..f7badf203 --- /dev/null +++ b/Classes/Module/DmailController.php @@ -0,0 +1,48 @@ +view = GeneralUtility::makeInstance(StandaloneView::class); + $this->view->setTemplateRootPaths(['EXT:direct_mail/Resources/Private/Templates/']); + $this->view->setPartialRootPaths(['EXT:direct_mail/Resources/Private/Partials/']); + $this->view->setLayoutRootPaths(['EXT:direct_mail/Resources/Private/Layouts/']); + $this->view->setTemplate('Dmail'); + + /** + * Render template and return html content + */ + $this->moduleTemplate->setContent($this->view->render()); + return new HtmlResponse($this->moduleTemplate->renderContent()); + } +} \ No newline at end of file diff --git a/Resources/Private/Templates/Dmail.html b/Resources/Private/Templates/Dmail.html new file mode 100644 index 000000000..8bb5650d1 --- /dev/null +++ b/Resources/Private/Templates/Dmail.html @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/ext_tables.php b/ext_tables.php index 4df4d8eba..53420144a 100755 --- a/ext_tables.php +++ b/ext_tables.php @@ -49,7 +49,7 @@ 'bottom', '', [ - 'routeTarget' => DirectMailTeam\DirectMail\Module\Dmail::class . '::mainAction', + 'routeTarget' => DirectMailTeam\DirectMail\Module\DmailController::class . '::indexAction', 'access' => 'group,user', 'name' => 'DirectMailNavFrame_DirectMail', 'workspaces' => 'online', From cda9dd605220b76db355924fef93cbb0d7acf3d9 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sun, 5 Dec 2021 13:06:57 +0000 Subject: [PATCH 030/342] update controllers --- Classes/Module/ConfigurationController.php | 9 +-------- Classes/Module/DmailController.php | 10 +--------- Classes/Module/MailerEngineController.php | 9 +-------- Classes/Module/MainController.php | 15 +++++++++++++++ Classes/Module/NavFrameController.php | 9 +-------- Classes/Module/RecipientListController.php | 9 +-------- Classes/Module/StatisticsController.php | 9 +-------- 7 files changed, 21 insertions(+), 49 deletions(-) diff --git a/Classes/Module/ConfigurationController.php b/Classes/Module/ConfigurationController.php index 4a060e2da..703ffb524 100644 --- a/Classes/Module/ConfigurationController.php +++ b/Classes/Module/ConfigurationController.php @@ -67,14 +67,7 @@ public function indexAction(ServerRequestInterface $request) : ResponseInterface */ $sys_dmail_uid = 0; - /** - * Configure template paths for your backend module - */ - $this->view = GeneralUtility::makeInstance(StandaloneView::class); - $this->view->setTemplateRootPaths(['EXT:direct_mail/Resources/Private/Templates/']); - $this->view->setPartialRootPaths(['EXT:direct_mail/Resources/Private/Partials/']); - $this->view->setLayoutRootPaths(['EXT:direct_mail/Resources/Private/Layouts/']); - $this->view->setTemplate('Configuration'); + $this->view = $this->configureTemplatePaths('Configuration'); $this->moduleTemplate->addJavaScriptCode($this->getJS($sys_dmail_uid)); diff --git a/Classes/Module/DmailController.php b/Classes/Module/DmailController.php index f7badf203..fe81cc3b5 100644 --- a/Classes/Module/DmailController.php +++ b/Classes/Module/DmailController.php @@ -30,15 +30,7 @@ class DmailController extends MainController public function indexAction(ServerRequestInterface $request) : ResponseInterface { - /** - * Configure template paths for your backend module - */ - $this->view = GeneralUtility::makeInstance(StandaloneView::class); - $this->view->setTemplateRootPaths(['EXT:direct_mail/Resources/Private/Templates/']); - $this->view->setPartialRootPaths(['EXT:direct_mail/Resources/Private/Partials/']); - $this->view->setLayoutRootPaths(['EXT:direct_mail/Resources/Private/Layouts/']); - $this->view->setTemplate('Dmail'); - + $this->view = $this->configureTemplatePaths('Dmail'); /** * Render template and return html content */ diff --git a/Classes/Module/MailerEngineController.php b/Classes/Module/MailerEngineController.php index 59ce1c3c5..98cc064c7 100644 --- a/Classes/Module/MailerEngineController.php +++ b/Classes/Module/MailerEngineController.php @@ -32,14 +32,7 @@ class MailerEngineController extends MainController public function indexAction(ServerRequestInterface $request) : ResponseInterface { - /** - * Configure template paths for your backend module - */ - $this->view = GeneralUtility::makeInstance(StandaloneView::class); - $this->view->setTemplateRootPaths(['EXT:direct_mail/Resources/Private/Templates/']); - $this->view->setPartialRootPaths(['EXT:direct_mail/Resources/Private/Partials/']); - $this->view->setLayoutRootPaths(['EXT:direct_mail/Resources/Private/Layouts/']); - $this->view->setTemplate('MailerEngine'); + $this->view = $this->configureTemplatePaths('MailerEngine'); $cronMonitor = $this->cmd_cronMonitor(); $mailerEngine = $this->cmd_mailerengine(); diff --git a/Classes/Module/MainController.php b/Classes/Module/MainController.php index 8d18cb332..39e9bf157 100644 --- a/Classes/Module/MainController.php +++ b/Classes/Module/MainController.php @@ -6,6 +6,7 @@ use TYPO3\CMS\Core\Database\Query\QueryBuilder; use TYPO3\CMS\Core\Localization\LanguageService; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Fluid\View\StandaloneView; class MainController { @@ -20,6 +21,20 @@ public function __construct(ModuleTemplate $moduleTemplate = null) $this->getLanguageService()->includeLLFile('EXT:direct_mail/Resources/Private/Language/locallang_mod2-6.xlf'); } + /** + * Configure template paths for your backend module + * @return StandaloneView + */ + protected function configureTemplatePaths (string $templateName): StandaloneView + { + $view = GeneralUtility::makeInstance(StandaloneView::class); + $view->setTemplateRootPaths(['EXT:direct_mail/Resources/Private/Templates/']); + $view->setPartialRootPaths(['EXT:direct_mail/Resources/Private/Partials/']); + $view->setLayoutRootPaths(['EXT:direct_mail/Resources/Private/Layouts/']); + $view->setTemplate($templateName); + return $view; + } + /** * @return LanguageService */ diff --git a/Classes/Module/NavFrameController.php b/Classes/Module/NavFrameController.php index d57bbd54e..5e6f56376 100644 --- a/Classes/Module/NavFrameController.php +++ b/Classes/Module/NavFrameController.php @@ -73,14 +73,7 @@ public function indexAction(ServerRequestInterface $request) : ResponseInterface $disableTitleHighlight = $GLOBALS['BE_USER']->getTSConfig()['options.']['pageTree.']['disableTitleHighlight'] ?? false; $this->doHighlight = (bool)($disableTitleHighlight) ? false : true; - /** - * Configure template paths for your backend module - */ - $this->view = GeneralUtility::makeInstance(StandaloneView::class); - $this->view->setTemplateRootPaths(['EXT:direct_mail/Resources/Private/Templates/']); - $this->view->setPartialRootPaths(['EXT:direct_mail/Resources/Private/Partials/']); - $this->view->setLayoutRootPaths(['EXT:direct_mail/Resources/Private/Layouts/']); - $this->view->setTemplate('NavFrame'); + $this->view = $this->configureTemplatePaths('NavFrame'); $rows = $this->getPages(); $pages = []; diff --git a/Classes/Module/RecipientListController.php b/Classes/Module/RecipientListController.php index 018fc531d..950919ce0 100644 --- a/Classes/Module/RecipientListController.php +++ b/Classes/Module/RecipientListController.php @@ -52,14 +52,7 @@ public function indexAction(ServerRequestInterface $request) : ResponseInterface if (($this->id && $access) || ($GLOBALS['BE_USER']->user['admin'] && !$this->id)) { */ - /** - * Configure template paths for your backend module - */ - $this->view = GeneralUtility::makeInstance(StandaloneView::class); - $this->view->setTemplateRootPaths(['EXT:direct_mail/Resources/Private/Templates/']); - $this->view->setPartialRootPaths(['EXT:direct_mail/Resources/Private/Partials/']); - $this->view->setLayoutRootPaths(['EXT:direct_mail/Resources/Private/Layouts/']); - $this->view->setTemplate('RecipientList'); + $this->view = $this->configureTemplatePaths('RecipientList'); $formcontent = $this->moduleContent(); $this->view->assignMultiple( diff --git a/Classes/Module/StatisticsController.php b/Classes/Module/StatisticsController.php index 81e568d6b..0a145bce9 100644 --- a/Classes/Module/StatisticsController.php +++ b/Classes/Module/StatisticsController.php @@ -49,14 +49,7 @@ public function indexAction(ServerRequestInterface $request) : ResponseInterface if (($this->id && $access) || ($GLOBALS['BE_USER']->user['admin'] && !$this->id)) { */ - /** - * Configure template paths for your backend module - */ - $this->view = GeneralUtility::makeInstance(StandaloneView::class); - $this->view->setTemplateRootPaths(['EXT:direct_mail/Resources/Private/Templates/']); - $this->view->setPartialRootPaths(['EXT:direct_mail/Resources/Private/Partials/']); - $this->view->setLayoutRootPaths(['EXT:direct_mail/Resources/Private/Layouts/']); - $this->view->setTemplate('Statistics'); + $this->view = $this->configureTemplatePaths('Statistics'); $formcontent = $this->moduleContent(); $this->view->assignMultiple( From 1b4532fc1c651284dd94a4a711d1e93e2a420043 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sun, 5 Dec 2021 13:09:46 +0000 Subject: [PATCH 031/342] style --- Classes/Module/Dmail.php | 46 ++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/Classes/Module/Dmail.php b/Classes/Module/Dmail.php index cf490e429..c733b2f18 100644 --- a/Classes/Module/Dmail.php +++ b/Classes/Module/Dmail.php @@ -54,7 +54,7 @@ class Dmail extends BaseScriptClass public $TSconfPrefix = 'mod.web_modules.dmail.'; public $fieldList = 'uid,name,title,email,phone,www,address,company,city,zip,country,fax,module_sys_dmail_category,module_sys_dmail_html'; // Internal - public $params = array(); + public $params = []; public $perms_clause = ''; public $pageinfo = ''; public $sys_dmail_uid; @@ -66,7 +66,7 @@ class Dmail extends BaseScriptClass public $back; public $noView; public $mode; - public $implodedParams = array(); + public $implodedParams = []; // If set a valid user table is around public $userTable; @@ -304,7 +304,7 @@ function toggleDisplay(toggleId, e, countBox) { // } $this->content = $this->doc->startPage($this->getLanguageService()->getLL('title')); - $this->content.= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers, array()); + $this->content.= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers, []); } else { // If no access or if ID == zero @@ -329,7 +329,7 @@ public function createDMail_quick(array $indata) { $theOutput = ''; // Set default values: - $dmail = array(); + $dmail = []; $dmail['sys_dmail']['NEW'] = array( 'from_email' => $indata['senderEmail'], 'from_name' => $indata['senderName'], @@ -368,7 +368,7 @@ public function createDMail_quick(array $indata) /* @var $tce \TYPO3\CMS\Core\DataHandling\DataHandler */ $tce = GeneralUtility::makeInstance(DataHandler::class); $tce->stripslashes_values = 0; - $tce->start($dmail, array()); + $tce->start($dmail, []); $tce->process_datamap(); $this->sys_dmail_uid = $tce->substNEWwithIDs['NEW']; @@ -494,7 +494,7 @@ public function moduleContent() $this->deleteDMail(intval(GeneralUtility::_GP('uid'))); } - $row = array(); + $row = []; if (intval($this->sys_dmail_uid)) { $row = BackendUtility::getRecord('sys_dmail', intval($this->sys_dmail_uid)); $isExternalDirectMailRecord = (is_array($row) && $row['type'] == 1); @@ -814,7 +814,7 @@ public function cmd_finalmail($direct_mail_row) $hookSelectDisabled = ''; $hookContents = ''; if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['direct_mail']['mod2']['cmd_finalmail'])) { - $hookObjectsArr = array(); + $hookObjectsArr = []; foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['direct_mail']['mod2']['cmd_finalmail'] as $classRef) { $hookObjectsArr[] = GeneralUtility::makeInstance($classRef); } @@ -852,7 +852,7 @@ public function cmd_finalmail($direct_mail_row) ->execute(); - $opt = array(); + $opt = []; $lastGroup = null; while (($group = $statement->fetch())) { $result = $this->cmd_compileMailGroup(array($group['uid'])); @@ -1193,7 +1193,7 @@ public function cmd_testmail() $msg = $this->getLanguageService()->getLL('testmail_individual_msg') . '

'; - $ids = array(); + $ids = []; foreach ($res as $row) { $ids[] = $row['uid']; @@ -1322,7 +1322,7 @@ public function cmd_displayMailGroup_test($result) public function getRecordList(array $listArr, $table, $editLinkFlag=1, $testMailLink=0) { $count = 0; - $lines = array(); + $lines = []; $out = ''; if (is_array($listArr)) { $count = count($listArr); @@ -1396,11 +1396,11 @@ public function cmd_compileMailGroup(array $groups) { // If supplied with an empty array, quit instantly as there is nothing to do if (!count($groups)) { - return array(); + return []; } // Looping through the selected array, in order to fetch recipient details - $idLists = array(); + $idLists = []; foreach ($groups as $group) { // Testing to see if group ID is a valid integer, if not - skip to next group ID $group = MathUtility::convertToPositiveInteger($group); @@ -1438,7 +1438,7 @@ public function cmd_compileMailGroup(array $groups) * manipulate the generated id_lists */ if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['direct_mail']['mod2']['cmd_compileMailGroup'])) { - $hookObjectsArr = array(); + $hookObjectsArr = []; $temporaryList = ''; foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['direct_mail']['mod2']['cmd_compileMailGroup'] as $classRef) { @@ -1469,7 +1469,7 @@ public function cmd_compileMailGroup(array $groups) */ protected function getSingleMailGroup($groupUid) { - $idLists = array(); + $idLists = []; if ($groupUid) { $mailGroup = BackendUtility::getRecord('sys_dmail_group', $groupUid); @@ -1481,7 +1481,7 @@ protected function getSingleMailGroup($groupUid) $thePages = $mailGroup['pages'] ? $mailGroup['pages'] : $this->id; // Explode the pages $pages = GeneralUtility::intExplode(',', $thePages); - $pageIdArray = array(); + $pageIdArray = []; foreach ($pages as $pageUid) { if ($pageUid > 0) { @@ -1518,7 +1518,7 @@ protected function getSingleMailGroup($groupUid) if ($whichTables&8) { // fe_groups if (!is_array($idLists['fe_users'])) { - $idLists['fe_users'] = array(); + $idLists['fe_users'] = []; } $idLists['fe_users'] = array_unique(array_merge($idLists['fe_users'], DirectMailUtility::getIdList('fe_groups', $pidList, $groupUid, $mailGroup['select_categories']))); } @@ -1650,9 +1650,9 @@ public function makeCategoriesForm(array $row) { $indata = GeneralUtility::_GP('indata'); if (is_array($indata['categories'])) { - $data = array(); + $data = []; foreach ($indata['categories'] as $recUid => $recValues) { - $enabled = array(); + $enabled = []; foreach ($recValues as $k => $b) { if ($b) { $enabled[] = $k; @@ -1664,7 +1664,7 @@ public function makeCategoriesForm(array $row) /* @var $tce \TYPO3\CMS\Core\DataHandling\DataHandler */ $tce = GeneralUtility::makeInstance(DataHandler::class); $tce->stripslashes_values = 0; - $tce->start($data, array()); + $tce->start($data, []); $tce->process_datamap(); // remove cache @@ -1873,7 +1873,7 @@ public function makeListDMail($boxId, $totalBox, $open=false) ->execute() ->fetchAll(); - $tblLines = array(); + $tblLines = []; $tblLines[] = array( '', $this->getLanguageService()->getLL('nl_l_subject'), @@ -1905,7 +1905,7 @@ public function makeListDMail($boxId, $totalBox, $open=false) $output.= '' . $imgSrc . $this->getLanguageService()->getLL('dmail_wiz1_list_dmail') . ''; $output.= '
'; $output.= '

' . $this->getLanguageService()->getLL('dmail_wiz1_list_header') . '

'; - $output.= DirectMailUtility::formatTable($tblLines, array(), 1, array(1, 1, 1, 0, 0, 1, 0, 1)); + $output.= DirectMailUtility::formatTable($tblLines, [], 1, array(1, 1, 1, 0, 0, 1, 0, 1)); $output.= '
'; return $output; } @@ -1986,7 +1986,7 @@ public function cmd_news() if (empty($rows)) { $theOutput = '

' . $this->getLanguageService()->getLL('nl_select') . '

' . $this->getLanguageService()->getLL('nl_select_msg1'); } else { - $outLines = array(); + $outLines = []; foreach ($rows as $row) { $languages = $this->getAvailablePageLanguages($row['uid']); @@ -2065,7 +2065,7 @@ public function cmd_news() $previewLink ]; } - $out = DirectMailUtility::formatTable($outLines, array(), 0, array(1, 1, 1, 1)); + $out = DirectMailUtility::formatTable($outLines, [], 0, array(1, 1, 1, 1)); $theOutput = '

' . $this->getLanguageService()->getLL('dmail_dovsk_crFromNL') . BackendUtility::cshItem($this->cshTable, 'select_newsletter', $GLOBALS['BACK_PATH']) . '

' . From 4cc0706689e0e9b47a8d8dee8145d5ad0dd0f959 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sun, 5 Dec 2021 16:40:26 +0000 Subject: [PATCH 032/342] update dmailcontroller --- Classes/DirectMailUtility.php | 48 +- Classes/Module/Dmail.php | 27 +- Classes/Module/DmailController.php | 799 +++++++++++++++++++++++++ Resources/Private/Templates/Dmail.html | 13 +- 4 files changed, 849 insertions(+), 38 deletions(-) diff --git a/Classes/DirectMailUtility.php b/Classes/DirectMailUtility.php index d8900c4ce..16db89f99 100644 --- a/Classes/DirectMailUtility.php +++ b/Classes/DirectMailUtility.php @@ -66,7 +66,7 @@ class DirectMailUtility */ public static function fetchRecordsListValues(array $listArr, $table, $fields='uid,name,email') { - $outListArr = array(); + $outListArr = []; if (is_array($listArr) && count($listArr)) { $idlist = implode(',', $listArr); @@ -297,7 +297,7 @@ public static function getIdList($table, $pidList, $groupUid, $cat) ->execute(); } } - $outArr = array(); + $outArr = []; while (($row = $res->fetch())) { $outArr[] = $row['uid']; } @@ -401,7 +401,7 @@ public static function getStaticIdList($table, $uid) ->execute(); } - $outArr = array(); + $outArr = []; while (($row = $res->fetch())) { $outArr[] = $row['uid']; @@ -494,7 +494,7 @@ public static function getStaticIdList($table, $uid) */ public static function getSpecialQueryIdList(MailSelect &$queryGenerator, $table, array $group): array { - $outArr = array(); + $outArr = []; if ($group['query']) { $queryGenerator->init('dmail_queryConfig', $table); $queryGenerator->queryConfig = $queryGenerator->cleanUpQueryConfig(unserialize($group['query'])); @@ -524,7 +524,7 @@ public static function getSpecialQueryIdList(MailSelect &$queryGenerator, $table public static function getMailGroups($list, array $parsedGroups, $perms_clause) { $groupIdList = GeneralUtility::intExplode(',', $list); - $groups = array(); + $groups = []; $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_dmail_group'); $queryBuilder @@ -568,7 +568,7 @@ public static function getMailGroups($list, array $parsedGroups, $perms_clause) */ public static function rearrangeCsvValues(array $lines, $fieldList) { - $out = array(); + $out = []; if (is_array($lines) && count($lines)>0) { // Analyse if first line is fieldnames. // Required is it that every value is either @@ -585,7 +585,7 @@ public static function rearrangeCsvValues(array $lines, $fieldList) $fieldListArr = array_merge($fieldListArr, explode(',', $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['direct_mail']['addRecipFields'])); } $fieldName = 1; - $fieldOrder = array(); + $fieldOrder = []; foreach ($first as $v) { list($fName, $fConf) = preg_split('|[\[\]]|', $v); @@ -647,7 +647,7 @@ public static function rearrangeCsvValues(array $lines, $fieldList) */ public static function rearrangePlainMails(array $plainMails) { - $out = array(); + $out = []; if (is_array($plainMails)) { $c = 0; foreach ($plainMails as $v) { @@ -670,7 +670,7 @@ public static function rearrangePlainMails(array $plainMails) */ public static function makeCategories($table, array $row, $sysLanguageUid) { - $categories = array(); + $categories = []; $mmField = 'module_sys_dmail_category'; if ($table == 'sys_dmail_group') { @@ -776,24 +776,26 @@ public static function getRecordOverlay($table, array $row, $sys_language_conten * * @return string HTML table */ - public static function formatTable(array $tableLines, array $cellParams, $header, array $cellcmd = array(), $tableParams = 'class="table table-striped table-hover"') + public static function formatTable(array $tableLines, array $cellParams, $header, array $cellcmd = [], $tableParams = 'class="table table-striped table-hover"') { reset($tableLines); $cols = empty($tableLines) ? 0 : count(current($tableLines)); reset($tableLines); - $lines = array(); + $lines = []; $first = $header?1:0; foreach ($tableLines as $r) { - $rowA = array(); + $rowA = []; for ($k=0; $k<$cols; $k++) { $v = $r[$k]; $v = strlen($v) ? ($cellcmd[$k]?$v:htmlspecialchars($v)) : ' '; if ($first) { $rowA[] = '' . $v . ''; } else { - $rowA[] = '' . $v . ''; + $cellParam = $cellParams[$k] ?? ''; + $cellParam = $cellParam != '' ? ' '.$cellParam : ''; + $rowA[] = '' . $v . ''; } } $lines[] = '' . implode('', $rowA) . ''; @@ -880,7 +882,7 @@ public static function getCsvValues($str, $sep=',') $fh = tmpfile(); fwrite($fh, trim($str)); fseek($fh, 0); - $lines = array(); + $lines = []; if ($sep == 'tab') { $sep = "\t"; } @@ -1014,7 +1016,7 @@ public static function getFEgroupSubgroups($groupId) ) ->andWhere('INSTR( CONCAT(\',\',fe_groups.subgroup,\',\'),\',' . intval($groupId) . ',\' )') ->execute(); - $groupArr = array(); + $groupArr = []; while (($row = $res->fetch())) { $groupArr[] = $row['uid']; @@ -1116,7 +1118,7 @@ public static function createDirectMailRecordFromPage($pageUid, array $parameter /* @var $tce \TYPO3\CMS\Core\DataHandling\DataHandler */ $tce = GeneralUtility::makeInstance(DataHandler::class); $tce->stripslashes_values = 0; - $tce->start($tcemainData, array()); + $tce->start($tcemainData, []); $tce->process_datamap(); $result = $tce->substNEWwithIDs['NEW']; } elseif (!$newRecord['sendOptions']) { @@ -1219,7 +1221,7 @@ public static function createDirectMailRecordFromExternalURL($subject, $external /* @var $tce \TYPO3\CMS\Core\DataHandling\DataHandler */ $tce = GeneralUtility::makeInstance(DataHandler::class); $tce->stripslashes_values = 0; - $tce->start($tcemainData, array()); + $tce->start($tcemainData, []); $tce->process_datamap(); $result = $tce->substNEWwithIDs['NEW']; } elseif (!$newRecord['sendOptions']) { @@ -1241,8 +1243,8 @@ public static function createDirectMailRecordFromExternalURL($subject, $external public static function fetchUrlContentsForDirectMailRecord(array $row, array $params, $returnArray = false) { $theOutput = ''; - $errorMsg = array(); - $warningMsg = array(); + $errorMsg = []; + $warningMsg = []; $urls = self::getFullUrlsForDirectMailRecord($row); $plainTextUrl = $urls['plainTextUrl']; $htmlUrl = $urls['htmlUrl']; @@ -1297,7 +1299,7 @@ public static function fetchUrlContentsForDirectMailRecord(array $row, array $pa // If type = 1, we have an external page. if ($row['type'] == 1) { // Try to auto-detect the charset of the message - $matches = array(); + $matches = []; $res = preg_match('/theParts['html_content'], $matches); if ($res == 1) { $htmlmail->charset = $matches[1]; @@ -1389,7 +1391,7 @@ protected static function addUserPass($url, array $params) { $user = $params['http_username']; $pass = $params['http_password']; - $matches = array(); + $matches = []; if ($user && $pass && preg_match('/^(?:http)s?:\/\//', $url, $matches)) { $url = $matches[0] . $user . ':' . $pass . '@' . substr($url, strlen($matches[0])); } @@ -1574,7 +1576,7 @@ public static function updatePagesTSconfig($id, array $pageTs, $tsConfPrefix, $i if (!is_array($impParams)) { $impParams = DirectMailUtility::implodeTSParams(BackendUtility::getPagesTSconfig($id)); } - $set = array(); + $set = []; foreach ($pageTs as $f => $v) { $f = $tsConfPrefix . $f; if ((!isset($impParams[$f]) && trim($v)) || strcmp(trim($impParams[$f]), trim($v))) { @@ -1629,7 +1631,7 @@ public static function updatePagesTSconfig($id, array $pageTs, $tsConfPrefix, $i */ public static function implodeTSParams(array $p, $k = '') { - $implodeParams = array(); + $implodeParams = []; if (is_array($p)) { foreach ($p as $kb => $val) { if (is_array($val)) { diff --git a/Classes/Module/Dmail.php b/Classes/Module/Dmail.php index c733b2f18..53e7eb8c8 100644 --- a/Classes/Module/Dmail.php +++ b/Classes/Module/Dmail.php @@ -72,12 +72,11 @@ class Dmail extends BaseScriptClass public $userTable; public $sys_language_uid = 0; public $error=''; - public $allowedTables = array('tt_address','fe_users'); + public $allowedTables = ['tt_address', 'fe_users']; public $MCONF; public $cshTable; public $formname = 'dmailform'; - /** * IconFactory for skinning * @var \TYPO3\CMS\Core\Imaging\IconFactory @@ -175,11 +174,11 @@ public function main() $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/DateTimePicker'); // Define settings for Date Picker - $typo3Settings = array( + $typo3Settings = [ 'datePickerUSmode' => $GLOBALS['TYPO3_CONF_VARS']['SYS']['USdateFormat'] ? 1 : 0, - 'dateFormat' => array('j-n-Y', 'G:i j-n-Y'), - 'dateFormatUS' => array('n-j-Y', 'G:i n-j-Y'), - ); + 'dateFormat' => ['j-n-Y', 'G:i j-n-Y'], + 'dateFormatUS' => ['n-j-Y', 'G:i n-j-Y'], + ]; $this->getPageRenderer()->addInlineSettingArray('', $typo3Settings); } @@ -251,18 +250,18 @@ function toggleDisplay(toggleId, e, countBox) { // '; - $markers = array( + $markers = [ 'TITLE' => '', 'FLASHMESSAGES' => '', 'CONTENT' => '', 'WIZARDSTEPS' => '', 'NAVIGATION' => '' - ); + ]; - $docHeaderButtons = array( + $docHeaderButtons = [ 'PAGEPATH' => $this->getLanguageService()->getLL('labels.path') . ': ' . GeneralUtility::fixed_lgd_cs($this->pageinfo['_thePath'], 50), 'SHORTCUT' => '' - ); + ]; // shortcut icon if ($BE_USER->mayMakeShortcut()) { $docHeaderButtons['SHORTCUT'] = $this->doc->makeShortcutIcon('id', implode(',', array_keys($this->MOD_MENU)), $this->MCONF['name'], 1, 'btn btn-default btn-sm'); @@ -330,7 +329,7 @@ public function createDMail_quick(array $indata) $theOutput = ''; // Set default values: $dmail = []; - $dmail['sys_dmail']['NEW'] = array( + $dmail['sys_dmail']['NEW'] = [ 'from_email' => $indata['senderEmail'], 'from_name' => $indata['senderName'], 'replyto_email' => $this->params['replyto_email'], @@ -342,7 +341,7 @@ public function createDMail_quick(array $indata) 'organisation' => $this->params['organisation'], 'authcode_fieldList'=> $this->params['authcode_fieldList'], 'plainParams' => '' - ); + ]; // always plaintext $dmail['sys_dmail']['NEW']['sendOptions'] = 1; @@ -483,12 +482,12 @@ public function moduleContent() $theOutput = ''; $isExternalDirectMailRecord = false; - $markers = array( + $markers = [ 'WIZARDSTEPS' => '', 'FLASHMESSAGES' => '', 'NAVIGATION' => '', 'TITLE' => '' - ); + ]; if ($this->CMD == 'delete') { $this->deleteDMail(intval(GeneralUtility::_GP('uid'))); diff --git a/Classes/Module/DmailController.php b/Classes/Module/DmailController.php index fe81cc3b5..96d714c7f 100644 --- a/Classes/Module/DmailController.php +++ b/Classes/Module/DmailController.php @@ -3,16 +3,20 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; +use TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider; use TYPO3\CMS\Backend\Routing\UriBuilder; +use TYPO3\CMS\Backend\Template\ModuleTemplate; use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Core\Core\Environment; use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction; use TYPO3\CMS\Core\Http\HtmlResponse; +use TYPO3\CMS\Core\Imaging\Icon; use TYPO3\CMS\Core\Messaging\FlashMessage; use TYPO3\CMS\Core\Messaging\FlashMessageRendererResolver; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Fluid\View\StandaloneView; +use DirectMailTeam\DirectMail\DirectMailUtility; class DmailController extends MainController { @@ -28,13 +32,808 @@ class DmailController extends MainController */ protected $view; + protected array $implodedParams = []; + protected $cshTable; + protected string $error = ''; + + protected int $id = 0; + protected string $cmd = ''; + protected array $pageinfo = []; + protected string $perms_clause = ''; + protected string $pages_uid = ''; + protected int $sys_dmail_uid = 0; + + protected int $currentStep = 1; + + /** + * The name of the module + * + * @var string + */ + protected string $moduleName = 'DirectMailNavFrame_DirectMail'; + + /** + * Constructor Method + * + * @var ModuleTemplate $moduleTemplate + */ + public function __construct(ModuleTemplate $moduleTemplate = null) + { + $this->moduleTemplate = $moduleTemplate ?? GeneralUtility::makeInstance(ModuleTemplate::class); + $this->getLanguageService()->includeLLFile('EXT:direct_mail/Resources/Private/Language/locallang_mod2-6.xlf'); + $this->getLanguageService()->includeLLFile('EXT:direct_mail/Resources/Private/Language/locallang_csh_sysdmail.xlf'); + } + public function indexAction(ServerRequestInterface $request) : ResponseInterface { $this->view = $this->configureTemplatePaths('Dmail'); + + $queryParams = $request->getQueryParams(); + $parsedBody = $request->getParsedBody(); + + $this->id = (int)($parsedBody['id'] ?? $queryParams['id'] ?? 0); + $this->cmd = (string)($parsedBody['cmd'] ?? $queryParams['cmd'] ?? ''); + $this->pages_uid = (string)($parsedBody['pages_uid'] ?? $queryParams['pages_uid'] ?? ''); + $this->sys_dmail_uid = (int)($parsedBody['sys_dmail_uid'] ?? $queryParams['sys_dmail_uid'] ?? 0); + + $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause); + // get the config from pageTS + $this->params = BackendUtility::getPagesTSconfig($this->id)['mod.']['web_modules.']['dmail.'] ?? []; + $this->implodedParams = DirectMailUtility::implodeTSParams($this->params); + $this->params['pid'] = intval($this->id); + + $this->cshTable = '_MOD_' . $this->moduleName; + + $access = is_array($this->pageinfo) ? 1 : 0; + + if (($this->id && $access) || ($GLOBALS['BE_USER']->isAdmin() && !$this->id)) { + $markers = $this->moduleContent(); + $formcontent = $markers['CONTENT']; + $this->view->assignMultiple( + [ + 'wizardsteps' => $markers['WIZARDSTEPS'], + 'navigation' => $markers['NAVIGATION'], + 'flashmessages' => $markers['FLASHMESSAGES'], + 'title' => $markers['TITLE'], + 'content' => $markers['CONTENT'] + ] + ); + } + else { + // If no access or if ID == zero + } + + /** * Render template and return html content */ $this->moduleTemplate->setContent($this->view->render()); return new HtmlResponse($this->moduleTemplate->renderContent()); } + + protected function moduleContent() + { + $theOutput = ''; + $isExternalDirectMailRecord = false; + + $markers = [ + 'WIZARDSTEPS' => '', + 'FLASHMESSAGES' => '', + 'NAVIGATION' => '', + 'TITLE' => '' + ]; + + if ($this->cmd == 'delete') { + $this->deleteDMail(intval(GeneralUtility::_GP('uid'))); //@TODO + } + + $row = []; + if (intval($this->sys_dmail_uid)) { + $row = BackendUtility::getRecord('sys_dmail', intval($this->sys_dmail_uid)); + $isExternalDirectMailRecord = (is_array($row) && $row['type'] == 1); + } + + $hideCategoryStep = false; + $tsconfig = $GLOBALS['BE_USER']->getTSConfig(); + + if ((isset($tsconfig['tx_directmail.']['hideSteps']) && + $tsconfig['tx_directmail.']['hideSteps'] === 'cat') || $isExternalDirectMailRecord) { + $hideCategoryStep = true; + } + + if (GeneralUtility::_GP('update_cats')) { //@TODO + $this->cmd = 'cats'; + } + + if (GeneralUtility::_GP('mailingMode_simple')) { //@TODO + $this->cmd = 'send_mail_test'; + } + + $backButtonPressed = GeneralUtility::_GP('back'); //@TODO + if ($backButtonPressed) { + // CMD move 1 step back + switch (GeneralUtility::_GP('currentCMD')) { //@TODO + case 'info': + $this->cmd = ''; + break; + case 'cats': + $this->cmd = 'info'; + break; + case 'send_test': + // Sameas send_mail_test + case 'send_mail_test': + if (($this->cmd == 'send_mass') && $hideCategoryStep) { + $this->cmd = 'info'; + } else { + $this->cmd = 'cats'; + } + break; + + case 'send_mail_final': + // The same as send_mass + case 'send_mass': + $this->cmd = 'send_test'; + break; + default: + // Do nothing + } + } + + $nextCmd = ''; + if ($hideCategoryStep) { + $totalSteps = 4; + if ($this->cmd == 'info') { + $nextCmd = 'send_test'; + } + } else { + $totalSteps = 5; + if ($this->cmd == 'info') { + $nextCmd = 'cats'; + } + } + + $navigationButtons = ''; + switch ($this->cmd) { + case 'info': + $fetchMessage = ''; + + // step 2: create the Direct Mail record, or use existing + $this->currentStep = 2; + $markers['TITLE'] = $this->getLanguageService()->getLL('dmail_wiz2_detail'); + + // greyed out next-button if fetching is not successful (on error) + $fetchError = true; + + // Create DirectMail and fetch the data + $shouldFetchData = GeneralUtility::_GP('fetchAtOnce'); + + $quickmail = GeneralUtility::_GP('quickmail'); + + $createMailFromInternalPage = intval(GeneralUtility::_GP('createMailFrom_UID')); + $createMailFromExternalUrl = GeneralUtility::_GP('createMailFrom_URL'); + + // internal page + if ($createMailFromInternalPage && !$quickmail['send']) { + $createMailFromInternalPageLang = (int)GeneralUtility::_GP('createMailFrom_LANG'); + $newUid = DirectMailUtility::createDirectMailRecordFromPage($createMailFromInternalPage, $this->params, $createMailFromInternalPageLang); + + if (is_numeric($newUid)) { + $this->sys_dmail_uid = $newUid; + // Read new record (necessary because TCEmain sets default field values) + $row = BackendUtility::getRecord('sys_dmail', $newUid); + // fetch the data + if ($shouldFetchData) { + $fetchMessage = DirectMailUtility::fetchUrlContentsForDirectMailRecord($row, $this->params); + $fetchError = ((strstr($fetchMessage, $this->getLanguageService()->getLL('dmail_error')) === false) ? false : true); + } + $theOutput .= ''; + } else { + // TODO: Error message - Error while adding the DB set + } + + // external URL + } elseif ($createMailFromExternalUrl && !$quickmail['send']) { + // $createMailFromExternalUrl is the External URL subject + $htmlUrl = GeneralUtility::_GP('createMailFrom_HTMLUrl'); + $plainTextUrl = GeneralUtility::_GP('createMailFrom_plainUrl'); + $newUid = DirectMailUtility::createDirectMailRecordFromExternalURL($createMailFromExternalUrl, $htmlUrl, $plainTextUrl, $this->params); + if (is_numeric($newUid)) { + $this->sys_dmail_uid = $newUid; + // Read new record (necessary because TCEmain sets default field values) + $row = BackendUtility::getRecord('sys_dmail', $newUid); + // fetch the data + if ($shouldFetchData) { + $fetchMessage = DirectMailUtility::fetchUrlContentsForDirectMailRecord($row, $this->params); + $fetchError = ((strstr($fetchMessage, $this->getLanguageService()->getLL('dmail_error')) === false) ? false : true); + } + $theOutput .= ''; + } else { + // TODO: Error message - Error while adding the DB set + $this->error = 'no_valid_url'; + } + + // Quickmail + } elseif ($quickmail['send']) { + $fetchMessage = $this->createDMail_quick($quickmail); + $fetchError = ((strstr($fetchMessage, $this->getLanguageService()->getLL('dmail_error')) === false) ? false : true); + $row = BackendUtility::getRecord('sys_dmail', $this->sys_dmail_uid); + $theOutput.= ''; + // existing dmail + } elseif ($row) { + if ($row['type'] == '1' && ((empty($row['HTMLParams'])) || (empty($row['plainParams'])))) { + + // it's a quickmail + $fetchError = false; + $theOutput .= ''; + + // add attachment here, since attachment added in 2nd step + $unserializedMailContent = unserialize(base64_decode($row['mailContent'])); + $theOutput .= $this->compileQuickMail($row, $unserializedMailContent['plain']['content'], false); + } else { + if ($shouldFetchData) { + $fetchMessage = DirectMailUtility::fetchUrlContentsForDirectMailRecord($row, $this->params); + $fetchError = ((strstr($fetchMessage, $this->getLanguageService()->getLL('dmail_error')) === false) ? false : true); + } + + if ($row['type'] == 0) { + $theOutput .= ''; + } else { + $theOutput .= ''; + } + } + } + + $navigationButtons = '  '; + $navigationButtons .= ''; + + if ($fetchMessage) { + $markers['FLASHMESSAGES'] = $fetchMessage; + } elseif (!$fetchError && $shouldFetchData) { + $markers['FLASHMESSAGES'] = GeneralUtility::makeInstance(FlashMessageRendererResolver::class) + ->resolve() + ->render([ + GeneralUtility::makeInstance( + FlashMessage::class, + '', + $this->getLanguageService()->getLL('dmail_wiz2_fetch_success'), + FlashMessage::OK + ) + ]); + } + + if (is_array($row)) { + $theOutput .= '
'; + $theOutput .= $this->renderRecordDetailsTable($row); + $theOutput .= '
'; + } + + $theOutput .= ''; + $theOutput .= !empty($row['page'])?'':''; + $theOutput .= ''; + break; + + case 'cats': + // shows category if content-based cat + $this->currentStep = 3; + $markers['TITLE'] = $this->getLanguageService()->getLL('dmail_wiz3_cats'); + + $navigationButtons = ' '; + $navigationButtons .= ''; + + $theOutput .= '
'; + $theOutput .= $this->makeCategoriesForm($row); + $theOutput .= '
'; + + $theOutput .= ''; + $theOutput .= ''; + $theOutput .= ''; + $theOutput .= ''; + break; + + case 'send_test': + // Same as send_mail_test + case 'send_mail_test': + // send test mail + $this->currentStep = (4 - (5 - $totalSteps)); + $markers['TITLE'] = $this->getLanguageService()->getLL('dmail_wiz4_testmail'); + + $navigationButtons = ' '; + $navigationButtons.= ''; + + if ($this->CMD == 'send_mail_test') { + // using Flashmessages to show sent test mail + $markers['FLASHMESSAGES'] = $this->cmd_send_mail($row); + } + $theOutput .= '
'; + $theOutput .= $this->cmd_testmail(); + $theOutput .= '
'; + + $theOutput .= ''; + $theOutput .= ''; + $theOutput .= ''; + $theOutput .= ''; + break; + + case 'send_mail_final': + // same as send_mass + case 'send_mass': + $this->currentStep = (5 - (5 - $totalSteps)); + + if ($this->cmd == 'send_mass') { + $navigationButtons = ''; + } + + if ($this->cmd == 'send_mail_final') { + $selectedMailGroups = GeneralUtility::_GP('mailgroup_uid'); + if (is_array($selectedMailGroups)) { + $markers['FLASHMESSAGES'] = $this->cmd_send_mail($row); + break; + } else { + $theOutput .= 'no recipients'; + } + } + // send mass, show calendar + $theOutput .= '
'; + $theOutput .= $this->cmd_finalmail($row); + $theOutput .= '
'; + + $theOutput = '

' . $this->getLanguageService()->getLL('dmail_wiz5_sendmass') . '

' . + $theOutput; + + $theOutput .= ''; + $theOutput .= ''; + $theOutput .= ''; + $theOutput .= ''; + break; + + default: + // choose source newsletter + $this->currentStep = 1; + $markers['TITLE'] = $this->getLanguageService()->getLL('dmail_wiz1_new_newsletter') . ' - ' . $this->getLanguageService()->getLL('dmail_wiz1_select_nl_source'); + + $showTabs = ['int', 'ext', 'quick', 'dmail']; + if(isset($tsconfig['tx_directmail.']['hideTabs'])) { + $hideTabs = GeneralUtility::trimExplode(',', $tsconfig['tx_directmail.']['hideTabs']); + foreach ($hideTabs as $hideTab) { + $showTabs = ArrayUtility::removeArrayEntryByValue($showTabs, $hideTab); + } + } + if (!isset($tsconfig['tx_directmail.']['defaultTab'])) { + $tsconfig['tx_directmail.']['defaultTab'] = 'dmail'; + } + + $i = 1; + $countTabs = count($showTabs); + foreach ($showTabs as $showTab) { + $open = false; + if ($tsconfig['tx_directmail.']['defaultTab'] == $showTab) { + $open = true; + } + switch ($showTab) { + case 'int': + $theOutput .= $this->makeFormInternal('box-' . $i, $countTabs, $open); + break; + case 'ext': + $theOutput .= $this->makeFormExternal('box-' . $i, $countTabs, $open); + break; + case 'quick': + $theOutput .= $this->makeFormQuickMail('box-' . $i, $countTabs, $open); + break; + case 'dmail': + $theOutput .= $this->makeListDMail('box-' . $i, $countTabs, $open); + break; + default: + } + $i++; + } + $theOutput .= ''; + } + + $markers['NAVIGATION'] = $navigationButtons; + $markers['CONTENT'] = $theOutput; + $markers['WIZARDSTEPS'] = $this->showSteps($totalSteps); + return $markers; + } + + /** + * Showing steps number on top of every page + * + * @param int $totalSteps Total step + * + * @return string HTML + */ + protected function showSteps($totalSteps) + { + $content = ''; + for ($i = 1; $i <= $totalSteps; $i++) { + $cssClass = ($i == $this->currentStep) ? 't3-wizard-item t3-wizard-item-active' : 't3-wizard-item'; + $content .= ' ' . $i . ' '; + } + + return '
' . $content . '
'; + } + + /** + * Makes box for internal page. (first step) + * + * @param string $boxId ID name for the HTML element + * @param int $totalBox Total of all boxes + * @param bool $open State of the box + * + * @return string HTML with list of internal pages + */ + protected function makeFormInternal($boxId, $totalBox, $open = false) + { + $imgSrc = $this->getNewsletterTabIcon($open); + + $output = '
'; + $output .= $this->cmd_news(); + $output .= '
'; + return $output; + } + + /** + * The icon for the source tab + * + * @param bool $expand State of the tab + * + * @return string + */ + protected function getNewsletterTabIcon($expand = false) + { + if ($expand) { + // opened + return $this->moduleTemplate->getIconFactory()->getIcon('apps-pagetree-expand', Icon::SIZE_SMALL); + } + + // closes + return $this->moduleTemplate->getIconFactory()->getIcon('apps-pagetree-collapse', Icon::SIZE_SMALL); + } + + /** + * Show the list of existing directmail records, which haven't been sent + * + * @return string HTML + * @throws RouteNotFoundException If the named route doesn't exist + */ + public function cmd_news() + { + // Here the list of subpages, news, is rendered + + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) + ->getQueryBuilderForTable('pages'); + + $queryBuilder + ->select('uid', 'doktype', 'title', 'abstract') + ->from('pages') + ->where( + $queryBuilder->expr()->eq( + 'pid', + $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT) + ), + $queryBuilder->expr()->eq('l10n_parent', 0), // Exclude translated page records from list + $this->perms_clause + ); + /** + * Postbone Breaking: #82803 - Global configuration option "content_doktypes" removed in TYPO3 v9 + * Regards custom configurations, otherwise ignores spacers (199), recyclers (255) and folders (254) + * + * @deprecated since TYPO3 v9. + **/ + if (isset($GLOBALS['TYPO3_CONF_VARS']['FE']['content_doktypes']) + && !empty($GLOBALS['TYPO3_CONF_VARS']['FE']['content_doktypes']) + ) { + $queryBuilder->andWhere( + $queryBuilder->expr()->in( + 'doktype', + GeneralUtility::intExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['content_doktypes']) + ) + ); + } else { + $queryBuilder->andWhere( + $queryBuilder->expr()->notIn( + 'doktype', + [199,254,255] + ) + ); + } + $rows = $queryBuilder->orderBy('sorting')->execute()->fetchAll(); + + if (empty($rows)) { + $theOutput = '

' . $this->getLanguageService()->getLL('nl_select') . '

' . $this->getLanguageService()->getLL('nl_select_msg1'); + } else { + $outLines = []; + foreach ($rows as $row) { + $languages = $this->getAvailablePageLanguages($row['uid']); + + /** @var UriBuilder $uriBuilder */ + $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); + $createDmailLink = $uriBuilder->buildUriFromRoute( + $this->moduleName, + [ + 'id' => $this->id, + 'createMailFrom_UID' => $row['uid'], + 'fetchAtOnce' => 1, + 'CMD' => 'info' + ] + ); + $pageIcon = $this->moduleTemplate->getIconFactory()->getIconForRecord('pages', $row, Icon::SIZE_SMALL) . ' ' . htmlspecialchars($row['title']); + + $previewHTMLLink = $previewTextLink = $createLink = ''; + foreach ($languages as $languageUid => $lang) { + $langParam = DirectMailUtility::getLanguageParam($languageUid, $this->params); + $createLangParam = ($languageUid ? '&createMailFrom_LANG=' . $languageUid : ''); + $langIconOverlay = (count($languages) > 1 ? $lang['flagIcon'] : null); + $langTitle = (count($languages) > 1 ? ' - ' . $lang['title'] : ''); + $plainParams = $this->implodedParams['plainParams'] ?? '' . $langParam; + $htmlParams = $this->implodedParams['HTMLParams'] ?? '' . $langParam; + $htmlIcon = $this->moduleTemplate->getIconFactory()->getIcon('directmail-dmail-preview-html', Icon::SIZE_SMALL, $langIconOverlay); + $plainIcon = $this->moduleTemplate->getIconFactory()->getIcon('directmail-dmail-preview-text', Icon::SIZE_SMALL, $langIconOverlay); + $createIcon = $this->moduleTemplate->getIconFactory()->getIcon('directmail-dmail-new', Icon::SIZE_SMALL, $langIconOverlay); + + $previewHTMLLink .= '' . $htmlIcon . ''; + + $previewTextLink .= '' . $plainIcon . ''; + $createLink .= '' . $createIcon . ''; + } + + switch ($this->params['sendOptions'] ?? 0) { + case 1: + $previewLink = $previewTextLink; + break; + case 2: + $previewLink = $previewHTMLLink; + break; + case 3: + // also as default + default: + $previewLink = $previewHTMLLink . '  ' . $previewTextLink; + } + + $params = [ + 'edit' => [ + 'pages' => [ + $row['uid'] => 'edit', + ] + ], + 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI'), + ]; + $editOnClickLink = DirectMailUtility::getEditOnClickLink($params); + + $outLines[] = [ + '' . $pageIcon . '', + $createLink, + '' . + $this->moduleTemplate->getIconFactory()->getIcon('actions-open', Icon::SIZE_SMALL) . '', + $previewLink + ]; + } + $out = DirectMailUtility::formatTable($outLines, [], 0, array(1, 1, 1, 1)); + $theOutput = '

' . $this->getLanguageService()->getLL('dmail_dovsk_crFromNL') . + BackendUtility::cshItem($this->cshTable, 'select_newsletter', $GLOBALS['BACK_PATH'] ?? '#') . + '

' . + $out; + } + + return $theOutput; + } + + /** + * Get available languages for a page + * + * @param $pageUid + * @return array + */ + protected function getAvailablePageLanguages($pageUid) + { + static $languages; + $languageUids = []; + + if ($languages === null) { + $languages = GeneralUtility::makeInstance(TranslationConfigurationProvider::class)->getSystemLanguages(); + } + + // loop trough all sys languages and check if there is matching page translation + foreach ($languages as $lang) { + // we skip -1 + if ((int)$lang['uid'] < 0) { + continue; + } + + // 0 is always present so only for > 0 + if ((int)$lang['uid'] > 0) { + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages'); + + $langRow = $queryBuilder + ->select('sys_language_uid') + ->from('pages') + ->where($queryBuilder->expr()->eq('l10n_parent', $queryBuilder->createNamedParameter($pageUid, \PDO::PARAM_INT))) + ->andWhere($queryBuilder->expr()->eq('sys_language_uid', $queryBuilder->createNamedParameter($lang['uid'], \PDO::PARAM_INT))) + ->execute() + ->fetchAll(); + + if (empty($langRow)) { + continue; + } + } + + $languageUids[(int)$lang['uid']] = $lang; + } + + return $languageUids; + } + + /** + * Make input form for external URL (first step) + * + * @param string $boxId ID name for the HTML element + * @param int $totalBox Total of the boxes + * @param bool $open State of the box + * + * @return string HTML input form for inputing the external page information + */ + protected function makeFormExternal($boxId, $totalBox, $open = false) + { + $imgSrc = $this->getNewsletterTabIcon($open); + + $output = '
'; + + // Create + $out = $this->getLanguageService()->getLL('dmail_HTML_url') . '
+
' . + $this->getLanguageService()->getLL('dmail_plaintext_url') . '
+
' . + $this->getLanguageService()->getLL('dmail_subject') . '
' . + '
' . + (($this->error == 'no_valid_url')?('
' . $this->getLanguageService()->getLL('dmail_no_valid_url') . '

'):'') . + ' + '; + $output.= '

' . $this->getLanguageService()->getLL('dmail_dovsk_crFromUrl') . BackendUtility::cshItem($this->cshTable, 'create_directmail_from_url', $GLOBALS['BACK_PATH'] ?? '') . '

'; + $output.= $out; + + $output.= '
'; + return $output; + } + + /** + * Makes input form for the quickmail (first step) + * + * @param string $boxId ID name for the HTML element + * @param int $totalBox Total of the boxes + * @param bool $open State of the box + * + * @return string HTML input form for the quickmail + */ + protected function makeFormQuickMail($boxId, $totalBox, $open = false) + { + $imgSrc = $this->getNewsletterTabIcon($open); + + $output = '
'; + $output.= '

' . $this->getLanguageService()->getLL('dmail_wiz1_quickmail_header') . '

'; + $output.= $this->cmd_quickmail(); + $output.= '
'; + return $output; + } + + /** + * Show the quickmail input form (first step) + * + * @return string HTML input form + */ + protected function cmd_quickmail() + { + $theOutput = ''; + $indata = GeneralUtility::_GP('quickmail'); //@TODO + + $senderName = ($indata['senderName'] ?? $GLOBALS['BE_USER']->user['realName']); + $senderMail = ($indata['senderEmail'] ?? $GLOBALS['BE_USER']->user['email']); + + $breakLines = $indata['breakLines'] ?? false; + // Set up form: + $theOutput.= ''; + $theOutput.= $this->getLanguageService()->getLL('quickmail_sender_name') . '

'; + $theOutput.= $this->getLanguageService()->getLL('quickmail_sender_email') . '

'; + $theOutput.= $this->getLanguageService()->getLL('dmail_subject') . '

'; + $theOutput.= $this->getLanguageService()->getLL('quickmail_message') . '

'; + $theOutput.= $this->getLanguageService()->getLL('quickmail_break_lines') . '

'; + $theOutput.= ''; + + return $theOutput; + } + + /** + * List all direct mail, which have not been sent (first step) + * + * @param string $boxId ID name for the HTML element + * @param int $totalBox Total of the boxes + * @param bool $open State of the box + * + * @return string HTML lists of all existing dmail records + */ + protected function makeListDMail($boxId, $totalBox, $open=false) + { + + $sOrder = preg_replace( + '/^(?:ORDER[[:space:]]*BY[[:space:]]*)+/i', '', + trim($GLOBALS['TCA']['sys_dmail']['ctrl']['default_sortby']) + ); + if (!empty($sOrder)){ + if (substr_count($sOrder, 'ASC') > 0 ){ + $sOrder = trim(str_replace('ASC','',$sOrder)); + $ascDesc = 'ASC'; + }else{ + $sOrder = trim(str_replace('DESC','',$sOrder)); + $ascDesc = 'DESC'; + } + + } + + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_dmail'); + $queryBuilder + ->getRestrictions() + ->removeAll() + ->add(GeneralUtility::makeInstance(DeletedRestriction::class)); + $res = $queryBuilder->select('uid','pid','subject','tstamp','issent','renderedsize','attachment','type') + ->from('sys_dmail') + ->add('where','pid = ' . intval($this->id) . + ' AND scheduled=0 AND issent=0') + ->orderBy($sOrder,$ascDesc) + ->execute() + ->fetchAll(); + + $tblLines = []; + $tblLines[] = [ + '', + $this->getLanguageService()->getLL('nl_l_subject'), + $this->getLanguageService()->getLL('nl_l_lastM'), + $this->getLanguageService()->getLL('nl_l_sent'), + $this->getLanguageService()->getLL('nl_l_size'), + $this->getLanguageService()->getLL('nl_l_attach'), + $this->getLanguageService()->getLL('nl_l_type'), + '' + ]; + + foreach ($res as $row) { + $tblLines[] = [ + $this->iconFactory->getIconForRecord('sys_dmail', $row, Icon::SIZE_SMALL)->render(), + $this->linkDMail_record($row['subject'], $row['uid']), + BackendUtility::date($row['tstamp']), + ($row['issent'] ? $this->getLanguageService()->getLL('dmail_yes') : $this->getLanguageService()->getLL('dmail_no')), + ($row['renderedsize'] ? GeneralUtility::formatSize($row['renderedsize']) : ''), + ($row['attachment'] ? $this->iconFactory->getIcon('directmail-attachment', Icon::SIZE_SMALL) : ''), + ($row['type'] & 0x1 ? $this->getLanguageService()->getLL('nl_l_tUrl') : $this->getLanguageService()->getLL('nl_l_tPage')) . ($row['type'] & 0x2 ? ' (' . $this->getLanguageService()->getLL('nl_l_tDraft') . ')' : ''), + $this->deleteLink($row['uid']) + ]; + } + + $imgSrc = $this->getNewsletterTabIcon($open); + + $output = ''; + return $output; + } } \ No newline at end of file diff --git a/Resources/Private/Templates/Dmail.html b/Resources/Private/Templates/Dmail.html index 8bb5650d1..e6538cb84 100644 --- a/Resources/Private/Templates/Dmail.html +++ b/Resources/Private/Templates/Dmail.html @@ -1,4 +1,15 @@ - \ No newline at end of file +
+
+ {wizardsteps} + {navigation} +
+
+ {flashmessages} +

{title}

+ {content} +
+
+ From 9854145d9abac7238367df48955e3f71a0d1b523 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sat, 11 Dec 2021 13:38:56 +0000 Subject: [PATCH 033/342] update modulcontrollers --- Classes/Module/ConfigurationController.php | 59 +++---- Classes/Module/DmailController.php | 22 +-- Classes/Module/MailerEngineController.php | 49 +++--- Classes/Module/MainController.php | 22 +++ Classes/Module/NavFrameController.php | 14 +- Classes/Module/RecipientListController.php | 194 +++++++++++---------- Classes/Module/StatisticsController.php | 55 +++--- Resources/Private/Templates/NoAccess.html | 5 + 8 files changed, 207 insertions(+), 213 deletions(-) create mode 100644 Resources/Private/Templates/NoAccess.html diff --git a/Classes/Module/ConfigurationController.php b/Classes/Module/ConfigurationController.php index 703ffb524..34870c3cd 100644 --- a/Classes/Module/ConfigurationController.php +++ b/Classes/Module/ConfigurationController.php @@ -26,19 +26,7 @@ use DirectMailTeam\DirectMail\DirectMailUtility; class ConfigurationController extends MainController -{ - /** - * ModuleTemplate Container - * - * @var ModuleTemplate - */ - protected $moduleTemplate; - - /** - * @var StandaloneView - */ - protected $view; - +{ /** * Constructor Method * @@ -52,32 +40,35 @@ public function __construct(ModuleTemplate $moduleTemplate = null) public function indexAction(ServerRequestInterface $request) : ResponseInterface { - /** - debug($request->getQueryParams()); - $currentModule = (string)($request->getQueryParams()['currentModule'] ?? $request->getParsedBody()['currentModule'] ?? 'DirectMailNavFrame_Configuration###'); + $this->view = $this->configureTemplatePaths('Configuration'); + + $queryParams = $request->getQueryParams(); + $parsedBody = $request->getParsedBody(); + + $this->id = (int)($parsedBody['id'] ?? $queryParams['id'] ?? 0); + $this->cmd = (string)($parsedBody['cmd'] ?? $queryParams['cmd'] ?? ''); + $this->pages_uid = (string)($parsedBody['pages_uid'] ?? $queryParams['pages_uid'] ?? ''); + $this->sys_dmail_uid = (int)($parsedBody['sys_dmail_uid'] ?? $queryParams['sys_dmail_uid'] ?? 0); - $this->CMD = GeneralUtility::_GP('CMD'); - $this->pages_uid = intval(GeneralUtility::_GP('pages_uid')); - $sys_dmail_uid = intval(GeneralUtility::_GP('sys_dmail_uid')); $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause); + $access = is_array($this->pageinfo) ? 1 : 0; - - if (($this->id && $access) || ($GLOBALS['BE_USER']->user['admin'] && !$this->id)) { + + if (($this->id && $access) || ($this->isAdmin() && !$this->id)) { + $this->moduleTemplate->addJavaScriptCode($this->getJS($this->sys_dmail_uid)); - */ - $sys_dmail_uid = 0; + $formcontent = $this->moduleContent(); + $this->view->assignMultiple( + [ + 'formcontent' => $formcontent + ] + ); + } + else { + // If no access or if ID == zero + $this->view = $this->configureTemplatePaths('NoAccess'); + } - $this->view = $this->configureTemplatePaths('Configuration'); - - $this->moduleTemplate->addJavaScriptCode($this->getJS($sys_dmail_uid)); - - $formcontent = $this->moduleContent(); - $this->view->assignMultiple( - [ - 'formcontent' => $formcontent - ] - ); - /** * Render template and return html content */ diff --git a/Classes/Module/DmailController.php b/Classes/Module/DmailController.php index 96d714c7f..65164a11d 100644 --- a/Classes/Module/DmailController.php +++ b/Classes/Module/DmailController.php @@ -20,28 +20,12 @@ class DmailController extends MainController { - /** - * ModuleTemplate Container - * - * @var ModuleTemplate - */ - protected $moduleTemplate; - - /** - * @var StandaloneView - */ - protected $view; - protected array $implodedParams = []; protected $cshTable; protected string $error = ''; - - protected int $id = 0; - protected string $cmd = ''; + protected array $pageinfo = []; - protected string $perms_clause = ''; protected string $pages_uid = ''; - protected int $sys_dmail_uid = 0; protected int $currentStep = 1; @@ -86,7 +70,7 @@ public function indexAction(ServerRequestInterface $request) : ResponseInterface $access = is_array($this->pageinfo) ? 1 : 0; - if (($this->id && $access) || ($GLOBALS['BE_USER']->isAdmin() && !$this->id)) { + if (($this->id && $access) || ($this->isAdmin() && !$this->id)) { $markers = $this->moduleContent(); $formcontent = $markers['CONTENT']; $this->view->assignMultiple( @@ -101,8 +85,8 @@ public function indexAction(ServerRequestInterface $request) : ResponseInterface } else { // If no access or if ID == zero + $this->view = $this->configureTemplatePaths('NoAccess'); } - /** * Render template and return html content diff --git a/Classes/Module/MailerEngineController.php b/Classes/Module/MailerEngineController.php index 98cc064c7..6141c121d 100644 --- a/Classes/Module/MailerEngineController.php +++ b/Classes/Module/MailerEngineController.php @@ -16,33 +16,38 @@ class MailerEngineController extends MainController { - /** - * ModuleTemplate Container - * - * @var ModuleTemplate - */ - protected $moduleTemplate; - - /** - * @var StandaloneView - */ - protected $view; - - public $id; - public function indexAction(ServerRequestInterface $request) : ResponseInterface { $this->view = $this->configureTemplatePaths('MailerEngine'); - $cronMonitor = $this->cmd_cronMonitor(); - $mailerEngine = $this->cmd_mailerengine(); + $queryParams = $request->getQueryParams(); + $parsedBody = $request->getParsedBody(); + + $this->id = (int)($parsedBody['id'] ?? $queryParams['id'] ?? 0); + $this->cmd = (string)($parsedBody['cmd'] ?? $queryParams['cmd'] ?? ''); + $this->pages_uid = (string)($parsedBody['pages_uid'] ?? $queryParams['pages_uid'] ?? ''); + $this->sys_dmail_uid = (int)($parsedBody['sys_dmail_uid'] ?? $queryParams['sys_dmail_uid'] ?? 0); - $this->view->assignMultiple( - [ - 'cronMonitor' => $cronMonitor, - 'mailerEngine' => $mailerEngine - ] - ); + $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause); + + $access = is_array($this->pageinfo) ? 1 : 0; + + if (($this->id && $access) || ($this->isAdmin() && !$this->id)) { + $cronMonitor = $this->cmd_cronMonitor(); + $mailerEngine = $this->cmd_mailerengine(); + + $this->view->assignMultiple( + [ + 'cronMonitor' => $cronMonitor, + 'mailerEngine' => $mailerEngine + ] + ); + } + else { + // If no access or if ID == zero + $this->view = $this->configureTemplatePaths('NoAccess'); + } + /** * Render template and return html content */ diff --git a/Classes/Module/MainController.php b/Classes/Module/MainController.php index 39e9bf157..924d2b50e 100644 --- a/Classes/Module/MainController.php +++ b/Classes/Module/MainController.php @@ -10,6 +10,23 @@ class MainController { + /** + * ModuleTemplate Container + * + * @var ModuleTemplate + */ + protected $moduleTemplate; + + /** + * @var StandaloneView + */ + protected $view; + + protected string $cmd = ''; + protected int $id = 0; + protected string $perms_clause = ''; + protected int $sys_dmail_uid = 0; + /** * Constructor Method * @@ -43,6 +60,11 @@ protected function getLanguageService(): LanguageService return $GLOBALS['LANG']; } + protected function isAdmin(): bool + { + return $GLOBALS['BE_USER']->isAdmin(); + } + protected function getQueryBuilder($table): QueryBuilder { return GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table); diff --git a/Classes/Module/NavFrameController.php b/Classes/Module/NavFrameController.php index 5e6f56376..2d66c6be7 100644 --- a/Classes/Module/NavFrameController.php +++ b/Classes/Module/NavFrameController.php @@ -31,19 +31,7 @@ class NavFrameController extends MainController -{ - /** - * ModuleTemplate Container - * - * @var ModuleTemplate - */ - protected $moduleTemplate; - - /** - * @var StandaloneView - */ - protected $view; - +{ /** * Set highlight * @var string diff --git a/Classes/Module/RecipientListController.php b/Classes/Module/RecipientListController.php index 950919ce0..86a823f56 100644 --- a/Classes/Module/RecipientListController.php +++ b/Classes/Module/RecipientListController.php @@ -17,50 +17,56 @@ class RecipientListController extends MainController { /** - * ModuleTemplate Container + * The name of the module * - * @var ModuleTemplate - */ - protected $moduleTemplate; - - /** - * @var StandaloneView + * @var string */ - protected $view; + protected $moduleName = ''; - protected $CMD = ''; - protected $id; - protected $sys_dmail_uid = 0; - /** - * The name of the module + * Constructor Method * - * @var string + * @var ModuleTemplate $moduleTemplate */ - protected $moduleName = ''; + public function __construct(ModuleTemplate $moduleTemplate = null) + { + $this->moduleTemplate = $moduleTemplate ?? GeneralUtility::makeInstance(ModuleTemplate::class); + $this->getLanguageService()->includeLLFile('EXT:direct_mail/Resources/Private/Language/locallang_mod2-6.xlf'); + } public function indexAction(ServerRequestInterface $request) : ResponseInterface { - $this->moduleName = (string)($request->getQueryParams()['currentModule'] ?? $request->getParsedBody()['currentModule'] ?? 'DirectMailNavFrame_RecipientList'); - /* - $this->CMD = GeneralUtility::_GP('CMD'); - $this->pages_uid = intval(GeneralUtility::_GP('pages_uid')); - $this->sys_dmail_uid = intval(GeneralUtility::_GP('sys_dmail_uid')); - $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause); - $access = is_array($this->pageinfo) ? 1 : 0; - - if (($this->id && $access) || ($GLOBALS['BE_USER']->user['admin'] && !$this->id)) { - */ - $this->view = $this->configureTemplatePaths('RecipientList'); - $formcontent = $this->moduleContent(); - $this->view->assignMultiple( - [ - 'formcontent' => $formcontent - ] - ); + $queryParams = $request->getQueryParams(); + $parsedBody = $request->getParsedBody(); + + $this->id = (int)($parsedBody['id'] ?? $queryParams['id'] ?? 0); + $this->cmd = (string)($parsedBody['cmd'] ?? $queryParams['cmd'] ?? ''); + $this->pages_uid = (string)($parsedBody['pages_uid'] ?? $queryParams['pages_uid'] ?? ''); + $this->sys_dmail_uid = (int)($parsedBody['sys_dmail_uid'] ?? $queryParams['sys_dmail_uid'] ?? 0); + $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause); + + $access = is_array($this->pageinfo) ? 1 : 0; + + if (($this->id && $access) || ($this->isAdmin() && !$this->id)) { + $this->moduleName = (string)($request->getQueryParams()['currentModule'] ?? $request->getParsedBody()['currentModule'] ?? 'DirectMailNavFrame_RecipientList'); + + $this->view = $this->configureTemplatePaths('RecipientList'); + + $formcontent = $this->moduleContent(); + $this->view->assignMultiple( + [ + 'formcontent' => $formcontent + ] + ); + } + else { + // If no access or if ID == zero + $this->view = $this->configureTemplatePaths('NoAccess'); + } + /** * Render template and return html content */ @@ -76,12 +82,12 @@ public function indexAction(ServerRequestInterface $request) : ResponseInterface protected function moduleContent() { // COMMAND: - switch ($this->CMD) { + switch ($this->cmd) { case 'displayUserInfo': $theOutput = $this->cmd_displayUserInfo(); break; case 'displayMailGroup': - $result = $this->cmd_compileMailGroup(intval(GeneralUtility::_GP('group_uid'))); + $result = $this->cmd_compileMailGroup(intval(GeneralUtility::_GP('group_uid'))); //@TODO $theOutput = $this->cmd_displayMailGroup($result); break; case 'displayImport': @@ -134,68 +140,68 @@ protected function showExistingRecipientLists() ->execute() ->fetchAll(); - foreach($res as $row) { - $result = $this->cmd_compileMailGroup(intval($row['uid'])); - $count = 0; - $idLists = $result['queryInfo']['id_lists']; - if (is_array($idLists['tt_address'])) { - $count+=count($idLists['tt_address']); - } - if (is_array($idLists['fe_users'])) { - $count+=count($idLists['fe_users']); - } - if (is_array($idLists['PLAINLIST'])) { - $count+=count($idLists['PLAINLIST']); - } - if (is_array($idLists[$this->userTable])) { - $count+=count($idLists[$this->userTable]); - } - - $out .= ' - ' . $this->moduleTemplate->getIconFactory()->getIconForRecord('sys_dmail_group', $row, Icon::SIZE_SMALL)->render() . ' - ' . $this->editLink('sys_dmail_group', $row['uid']) . ' - ' . $this->linkRecip_record('' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($row['title'], 30)) . '  ', $row['uid']) . ' - ' . htmlspecialchars(BackendUtility::getProcessedValue('sys_dmail_group', 'type', $row['type'])) . '   - ' . BackendUtility::getProcessedValue('sys_dmail_group', 'description', htmlspecialchars($row['description'])) . '   - ' . $count . ' - '; - } + foreach($res as $row) { + $result = $this->cmd_compileMailGroup(intval($row['uid'])); + $count = 0; + $idLists = $result['queryInfo']['id_lists']; + if (is_array($idLists['tt_address'])) { + $count+=count($idLists['tt_address']); + } + if (is_array($idLists['fe_users'])) { + $count+=count($idLists['fe_users']); + } + if (is_array($idLists['PLAINLIST'])) { + $count+=count($idLists['PLAINLIST']); + } + if (is_array($idLists[$this->userTable])) { + $count+=count($idLists[$this->userTable]); + } + + $out .= ' + ' . $this->moduleTemplate->getIconFactory()->getIconForRecord('sys_dmail_group', $row, Icon::SIZE_SMALL)->render() . ' + ' . $this->editLink('sys_dmail_group', $row['uid']) . ' + ' . $this->linkRecip_record('' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($row['title'], 30)) . '  ', $row['uid']) . ' + ' . htmlspecialchars(BackendUtility::getProcessedValue('sys_dmail_group', 'type', $row['type'])) . '   + ' . BackendUtility::getProcessedValue('sys_dmail_group', 'description', htmlspecialchars($row['description'])) . '   + ' . $count . ' + '; + } - $out =' ' . $out . '
'; - $theOutput = '

' . $this->getLanguageService()->getLL('recip_select_mailgroup') . '

' . - $out; - - $editOnClickLink = DirectMailUtility::getEditOnClickLink([ - 'edit' => [ - 'sys_dmail_group' => [ - $this->id => 'new' - ] - ], - 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI'), - ]); + $out =' ' . $out . '
'; + $theOutput = '

' . $this->getLanguageService()->getLL('recip_select_mailgroup') . '

' . + $out; + + $editOnClickLink = DirectMailUtility::getEditOnClickLink([ + 'edit' => [ + 'sys_dmail_group' => [ + $this->id => 'new' + ] + ], + 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI'), + ]); - // New: - $out = '' . - $this->moduleTemplate->getIconFactory()->getIconForRecord('sys_dmail_group', [], Icon::SIZE_SMALL) . - $this->getLanguageService()->getLL('recip_create_mailgroup_msg') . ''; - $theOutput .= '
'; - $theOutput .= '

' . $this->getLanguageService()->getLL('recip_select_mailgroup') . '

' . - $out; - - // Import - /** @var UriBuilder $uriBuilder */ - $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); - $moduleUrl = $uriBuilder->buildUriFromRoute( - $this->moduleName, - [ - 'id' => $this->id, - 'CMD' => 'displayImport' - ] - ); - $out = '' . $this->getLanguageService()->getLL('recip_import_mailgroup_msg') . ''; - $theOutput.= '
'; - $theOutput.= '

' . $this->getLanguageService()->getLL('mailgroup_import') . '

' . $out; - return $theOutput; + // New: + $out = '' . + $this->moduleTemplate->getIconFactory()->getIconForRecord('sys_dmail_group', [], Icon::SIZE_SMALL) . + $this->getLanguageService()->getLL('recip_create_mailgroup_msg') . ''; + $theOutput .= '
'; + $theOutput .= '

' . $this->getLanguageService()->getLL('recip_select_mailgroup') . '

' . + $out; + + // Import + /** @var UriBuilder $uriBuilder */ + $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); + $moduleUrl = $uriBuilder->buildUriFromRoute( + $this->moduleName, + [ + 'id' => $this->id, + 'cmd' => 'displayImport' + ] + ); + $out = '' . $this->getLanguageService()->getLL('recip_import_mailgroup_msg') . ''; + $theOutput.= '
'; + $theOutput.= '

' . $this->getLanguageService()->getLL('mailgroup_import') . '

' . $out; + return $theOutput; } } \ No newline at end of file diff --git a/Classes/Module/StatisticsController.php b/Classes/Module/StatisticsController.php index 0a145bce9..67cfd748f 100644 --- a/Classes/Module/StatisticsController.php +++ b/Classes/Module/StatisticsController.php @@ -4,6 +4,7 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use TYPO3\CMS\Backend\Template\ModuleTemplate; +use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Core\Http\HtmlResponse; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Fluid\View\StandaloneView; @@ -11,22 +12,6 @@ class StatisticsController extends MainController { - /** - * ModuleTemplate Container - * - * @var ModuleTemplate - */ - protected $moduleTemplate; - - /** - * @var StandaloneView - */ - protected $view; - - protected $CMD = ''; - protected $id = 0; - protected $sys_dmail_uid = 0; - /** * Constructor Method * @@ -39,25 +24,33 @@ public function __construct(ModuleTemplate $moduleTemplate = null) public function indexAction(ServerRequestInterface $request) : ResponseInterface { -/** - $this->CMD = GeneralUtility::_GP('CMD'); - $this->pages_uid = intval(GeneralUtility::_GP('pages_uid')); - $this->sys_dmail_uid = intval(GeneralUtility::_GP('sys_dmail_uid')); + $this->view = $this->configureTemplatePaths('Statistics'); + + $queryParams = $request->getQueryParams(); + $parsedBody = $request->getParsedBody(); + + $this->id = (int)($parsedBody['id'] ?? $queryParams['id'] ?? 0); + $this->cmd = (string)($parsedBody['cmd'] ?? $queryParams['cmd'] ?? ''); + $this->pages_uid = (string)($parsedBody['pages_uid'] ?? $queryParams['pages_uid'] ?? ''); + $this->sys_dmail_uid = (int)($parsedBody['sys_dmail_uid'] ?? $queryParams['sys_dmail_uid'] ?? 0); + $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause); + $access = is_array($this->pageinfo) ? 1 : 0; - if (($this->id && $access) || ($GLOBALS['BE_USER']->user['admin'] && !$this->id)) { -*/ + if (($this->id && $access) || ($this->isAdmin() && !$this->id)) { + $formcontent = $this->moduleContent(); + $this->view->assignMultiple( + [ + 'formcontent' => $formcontent + ] + ); + } + else { + // If no access or if ID == zero + $this->view = $this->configureTemplatePaths('NoAccess'); + } - $this->view = $this->configureTemplatePaths('Statistics'); - - $formcontent = $this->moduleContent(); - $this->view->assignMultiple( - [ - 'formcontent' => $formcontent - ] - ); - /** * Render template and return html content */ diff --git a/Resources/Private/Templates/NoAccess.html b/Resources/Private/Templates/NoAccess.html new file mode 100644 index 000000000..aad9fa6d1 --- /dev/null +++ b/Resources/Private/Templates/NoAccess.html @@ -0,0 +1,5 @@ + + + +

If no access or if ID == zero @TODO

+
From eed3508fa1383830e913a629cf9374e3b383b9a5 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sat, 11 Dec 2021 13:51:27 +0000 Subject: [PATCH 034/342] code style --- Classes/Module/DmailController.php | 2 +- Classes/Module/MainController.php | 4 ++++ Classes/Module/NavFrameController.php | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Classes/Module/DmailController.php b/Classes/Module/DmailController.php index 65164a11d..d049403e1 100644 --- a/Classes/Module/DmailController.php +++ b/Classes/Module/DmailController.php @@ -118,7 +118,7 @@ protected function moduleContent() } $hideCategoryStep = false; - $tsconfig = $GLOBALS['BE_USER']->getTSConfig(); + $tsconfig = $this->getTSConfig(); if ((isset($tsconfig['tx_directmail.']['hideSteps']) && $tsconfig['tx_directmail.']['hideSteps'] === 'cat') || $isExternalDirectMailRecord) { diff --git a/Classes/Module/MainController.php b/Classes/Module/MainController.php index 924d2b50e..322a81fe3 100644 --- a/Classes/Module/MainController.php +++ b/Classes/Module/MainController.php @@ -65,6 +65,10 @@ protected function isAdmin(): bool return $GLOBALS['BE_USER']->isAdmin(); } + protected function getTSConfig() { + return $GLOBALS['BE_USER']->getTSConfig(); + } + protected function getQueryBuilder($table): QueryBuilder { return GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table); diff --git a/Classes/Module/NavFrameController.php b/Classes/Module/NavFrameController.php index 2d66c6be7..1cee195aa 100644 --- a/Classes/Module/NavFrameController.php +++ b/Classes/Module/NavFrameController.php @@ -58,7 +58,7 @@ public function indexAction(ServerRequestInterface $request) : ResponseInterface $currentSubScript = $uriBuilder->buildUriFromRoute($currentModule); // Setting highlight mode: - $disableTitleHighlight = $GLOBALS['BE_USER']->getTSConfig()['options.']['pageTree.']['disableTitleHighlight'] ?? false; + $disableTitleHighlight = $this->getTSConfig()['options.']['pageTree.']['disableTitleHighlight'] ?? false; $this->doHighlight = (bool)($disableTitleHighlight) ? false : true; $this->view = $this->configureTemplatePaths('NavFrame'); From c18ef1768803e625a0da62589842a8af586aaf63 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sat, 11 Dec 2021 15:40:37 +0000 Subject: [PATCH 035/342] init modul controllers --- Classes/Module/ConfigurationController.php | 15 +----- Classes/Module/DmailController.php | 18 ++----- Classes/Module/MailerEngineController.php | 14 +---- Classes/Module/MainController.php | 63 ++++++++++++++++++++-- Classes/Module/RecipientListController.php | 14 +---- Classes/Module/StatisticsController.php | 14 +---- 6 files changed, 70 insertions(+), 68 deletions(-) diff --git a/Classes/Module/ConfigurationController.php b/Classes/Module/ConfigurationController.php index 34870c3cd..2457b36e2 100644 --- a/Classes/Module/ConfigurationController.php +++ b/Classes/Module/ConfigurationController.php @@ -22,7 +22,6 @@ use TYPO3\CMS\Core\Http\HtmlResponse; use TYPO3\CMS\Core\Imaging\Icon; use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\Fluid\View\StandaloneView; use DirectMailTeam\DirectMail\DirectMailUtility; class ConfigurationController extends MainController @@ -42,19 +41,9 @@ public function indexAction(ServerRequestInterface $request) : ResponseInterface { $this->view = $this->configureTemplatePaths('Configuration'); - $queryParams = $request->getQueryParams(); - $parsedBody = $request->getParsedBody(); - - $this->id = (int)($parsedBody['id'] ?? $queryParams['id'] ?? 0); - $this->cmd = (string)($parsedBody['cmd'] ?? $queryParams['cmd'] ?? ''); - $this->pages_uid = (string)($parsedBody['pages_uid'] ?? $queryParams['pages_uid'] ?? ''); - $this->sys_dmail_uid = (int)($parsedBody['sys_dmail_uid'] ?? $queryParams['sys_dmail_uid'] ?? 0); - - $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause); - - $access = is_array($this->pageinfo) ? 1 : 0; + $this->init($request); - if (($this->id && $access) || ($this->isAdmin() && !$this->id)) { + if (($this->id && $this->access) || ($this->isAdmin() && !$this->id)) { $this->moduleTemplate->addJavaScriptCode($this->getJS($this->sys_dmail_uid)); $formcontent = $this->moduleContent(); diff --git a/Classes/Module/DmailController.php b/Classes/Module/DmailController.php index d049403e1..9b3f15027 100644 --- a/Classes/Module/DmailController.php +++ b/Classes/Module/DmailController.php @@ -20,12 +20,8 @@ class DmailController extends MainController { - protected array $implodedParams = []; protected $cshTable; protected string $error = ''; - - protected array $pageinfo = []; - protected string $pages_uid = ''; protected int $currentStep = 1; @@ -52,25 +48,17 @@ public function indexAction(ServerRequestInterface $request) : ResponseInterface { $this->view = $this->configureTemplatePaths('Dmail'); + $this->init($request); + $queryParams = $request->getQueryParams(); $parsedBody = $request->getParsedBody(); - $this->id = (int)($parsedBody['id'] ?? $queryParams['id'] ?? 0); - $this->cmd = (string)($parsedBody['cmd'] ?? $queryParams['cmd'] ?? ''); - $this->pages_uid = (string)($parsedBody['pages_uid'] ?? $queryParams['pages_uid'] ?? ''); - $this->sys_dmail_uid = (int)($parsedBody['sys_dmail_uid'] ?? $queryParams['sys_dmail_uid'] ?? 0); - - $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause); // get the config from pageTS - $this->params = BackendUtility::getPagesTSconfig($this->id)['mod.']['web_modules.']['dmail.'] ?? []; - $this->implodedParams = DirectMailUtility::implodeTSParams($this->params); $this->params['pid'] = intval($this->id); $this->cshTable = '_MOD_' . $this->moduleName; - $access = is_array($this->pageinfo) ? 1 : 0; - - if (($this->id && $access) || ($this->isAdmin() && !$this->id)) { + if (($this->id && $this->access) || ($this->isAdmin() && !$this->id)) { $markers = $this->moduleContent(); $formcontent = $markers['CONTENT']; $this->view->assignMultiple( diff --git a/Classes/Module/MailerEngineController.php b/Classes/Module/MailerEngineController.php index 6141c121d..8a11dde4e 100644 --- a/Classes/Module/MailerEngineController.php +++ b/Classes/Module/MailerEngineController.php @@ -20,19 +20,9 @@ public function indexAction(ServerRequestInterface $request) : ResponseInterface { $this->view = $this->configureTemplatePaths('MailerEngine'); - $queryParams = $request->getQueryParams(); - $parsedBody = $request->getParsedBody(); - - $this->id = (int)($parsedBody['id'] ?? $queryParams['id'] ?? 0); - $this->cmd = (string)($parsedBody['cmd'] ?? $queryParams['cmd'] ?? ''); - $this->pages_uid = (string)($parsedBody['pages_uid'] ?? $queryParams['pages_uid'] ?? ''); - $this->sys_dmail_uid = (int)($parsedBody['sys_dmail_uid'] ?? $queryParams['sys_dmail_uid'] ?? 0); - - $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause); - - $access = is_array($this->pageinfo) ? 1 : 0; + $this->init($request); - if (($this->id && $access) || ($this->isAdmin() && !$this->id)) { + if (($this->id && $this->access) || ($this->isAdmin() && !$this->id)) { $cronMonitor = $this->cmd_cronMonitor(); $mailerEngine = $this->cmd_mailerengine(); diff --git a/Classes/Module/MainController.php b/Classes/Module/MainController.php index 322a81fe3..e4bee8a06 100644 --- a/Classes/Module/MainController.php +++ b/Classes/Module/MainController.php @@ -1,10 +1,14 @@ getLanguageService()->includeLLFile('EXT:direct_mail/Resources/Private/Language/locallang_mod2-6.xlf'); } + protected function init(ServerRequestInterface $request): void { + $queryParams = $request->getQueryParams(); + $parsedBody = $request->getParsedBody(); + + $this->id = (int)($parsedBody['id'] ?? $queryParams['id'] ?? 0); + $this->cmd = (string)($parsedBody['cmd'] ?? $queryParams['cmd'] ?? ''); + $this->pages_uid = (string)($parsedBody['pages_uid'] ?? $queryParams['pages_uid'] ?? ''); + $this->sys_dmail_uid = (int)($parsedBody['sys_dmail_uid'] ?? $queryParams['sys_dmail_uid'] ?? 0); + + $this->perms_clause = $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW); + $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause); + + $this->access = is_array($this->pageinfo) ? true : false; + + // get the config from pageTS + $this->params = BackendUtility::getPagesTSconfig($this->id)['mod.']['web_modules.']['dmail.'] ?? []; + $this->implodedParams = DirectMailUtility::implodeTSParams($this->params); + if ($this->params['userTable'] ?? false && isset($GLOBALS['TCA'][$this->params['userTable']]) && is_array($GLOBALS['TCA'][$this->params['userTable']])) { + $this->userTable = $this->params['userTable']; + $this->allowedTables[] = $this->userTable; + } + // initialize backend user language + //$this->sys_language_uid = 0; //@TODO + } + /** * Configure template paths for your backend module * @return StandaloneView @@ -60,15 +106,24 @@ protected function getLanguageService(): LanguageService return $GLOBALS['LANG']; } + /** + * Returns the Backend User + * @return BackendUserAuthentication + */ + protected function getBackendUser() + { + return $GLOBALS['BE_USER']; + } + protected function isAdmin(): bool { return $GLOBALS['BE_USER']->isAdmin(); } - + protected function getTSConfig() { return $GLOBALS['BE_USER']->getTSConfig(); } - + protected function getQueryBuilder($table): QueryBuilder { return GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table); diff --git a/Classes/Module/RecipientListController.php b/Classes/Module/RecipientListController.php index 86a823f56..ca38ee981 100644 --- a/Classes/Module/RecipientListController.php +++ b/Classes/Module/RecipientListController.php @@ -38,19 +38,9 @@ public function indexAction(ServerRequestInterface $request) : ResponseInterface { $this->view = $this->configureTemplatePaths('RecipientList'); - $queryParams = $request->getQueryParams(); - $parsedBody = $request->getParsedBody(); + $this->init($request); - $this->id = (int)($parsedBody['id'] ?? $queryParams['id'] ?? 0); - $this->cmd = (string)($parsedBody['cmd'] ?? $queryParams['cmd'] ?? ''); - $this->pages_uid = (string)($parsedBody['pages_uid'] ?? $queryParams['pages_uid'] ?? ''); - $this->sys_dmail_uid = (int)($parsedBody['sys_dmail_uid'] ?? $queryParams['sys_dmail_uid'] ?? 0); - - $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause); - - $access = is_array($this->pageinfo) ? 1 : 0; - - if (($this->id && $access) || ($this->isAdmin() && !$this->id)) { + if (($this->id && $this->access) || ($this->isAdmin() && !$this->id)) { $this->moduleName = (string)($request->getQueryParams()['currentModule'] ?? $request->getParsedBody()['currentModule'] ?? 'DirectMailNavFrame_RecipientList'); $this->view = $this->configureTemplatePaths('RecipientList'); diff --git a/Classes/Module/StatisticsController.php b/Classes/Module/StatisticsController.php index 67cfd748f..df1517161 100644 --- a/Classes/Module/StatisticsController.php +++ b/Classes/Module/StatisticsController.php @@ -26,19 +26,9 @@ public function indexAction(ServerRequestInterface $request) : ResponseInterface { $this->view = $this->configureTemplatePaths('Statistics'); - $queryParams = $request->getQueryParams(); - $parsedBody = $request->getParsedBody(); + $this->init($request); - $this->id = (int)($parsedBody['id'] ?? $queryParams['id'] ?? 0); - $this->cmd = (string)($parsedBody['cmd'] ?? $queryParams['cmd'] ?? ''); - $this->pages_uid = (string)($parsedBody['pages_uid'] ?? $queryParams['pages_uid'] ?? ''); - $this->sys_dmail_uid = (int)($parsedBody['sys_dmail_uid'] ?? $queryParams['sys_dmail_uid'] ?? 0); - - $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause); - - $access = is_array($this->pageinfo) ? 1 : 0; - - if (($this->id && $access) || ($this->isAdmin() && !$this->id)) { + if (($this->id && $this->access) || ($this->isAdmin() && !$this->id)) { $formcontent = $this->moduleContent(); $this->view->assignMultiple( [ From 75a2bbe9b5b8362fcd264f91d999202256c7c7c0 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sat, 11 Dec 2021 15:41:18 +0000 Subject: [PATCH 036/342] init modul controllers --- Classes/Module/MainController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/Module/MainController.php b/Classes/Module/MainController.php index e4bee8a06..3eb91d089 100644 --- a/Classes/Module/MainController.php +++ b/Classes/Module/MainController.php @@ -45,7 +45,7 @@ class MainController { protected $userTable; protected $allowedTables = []; protected int $sys_language_uid = 0; - protected $pageinfo; + protected array $pageinfo = []; protected bool $access = false; /** From 96a76287b05749dcb5dd89aa045d5d89673df440 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sat, 11 Dec 2021 16:19:28 +0000 Subject: [PATCH 037/342] add FlashMessage --- Classes/Module/ConfigurationController.php | 3 +- Classes/Module/DmailController.php | 2 ++ Classes/Module/MailerEngineController.php | 2 ++ Classes/Module/MainController.php | 33 +++++++++++++++++++ Classes/Module/RecipientListController.php | 2 ++ Classes/Module/StatisticsController.php | 2 ++ .../Private/Templates/Configuration.html | 1 + Resources/Private/Templates/Dmail.html | 1 + Resources/Private/Templates/MailerEngine.html | 1 + Resources/Private/Templates/NoAccess.html | 2 +- .../Private/Templates/RecipientList.html | 1 + Resources/Private/Templates/Statistics.html | 1 + 12 files changed, 49 insertions(+), 2 deletions(-) diff --git a/Classes/Module/ConfigurationController.php b/Classes/Module/ConfigurationController.php index 2457b36e2..f4c47db8a 100644 --- a/Classes/Module/ConfigurationController.php +++ b/Classes/Module/ConfigurationController.php @@ -42,7 +42,6 @@ public function indexAction(ServerRequestInterface $request) : ResponseInterface $this->view = $this->configureTemplatePaths('Configuration'); $this->init($request); - if (($this->id && $this->access) || ($this->isAdmin() && !$this->id)) { $this->moduleTemplate->addJavaScriptCode($this->getJS($this->sys_dmail_uid)); @@ -56,6 +55,8 @@ public function indexAction(ServerRequestInterface $request) : ResponseInterface else { // If no access or if ID == zero $this->view = $this->configureTemplatePaths('NoAccess'); + $message = $this->createFlashMessage('If no access or if ID == zero', 'No Access', 1, false); + $this->messageQueue->addMessage($message); } /** diff --git a/Classes/Module/DmailController.php b/Classes/Module/DmailController.php index 9b3f15027..b06071c78 100644 --- a/Classes/Module/DmailController.php +++ b/Classes/Module/DmailController.php @@ -74,6 +74,8 @@ public function indexAction(ServerRequestInterface $request) : ResponseInterface else { // If no access or if ID == zero $this->view = $this->configureTemplatePaths('NoAccess'); + $message = $this->createFlashMessage('If no access or if ID == zero', 'No Access', 1, false); + $this->messageQueue->addMessage($message); } /** diff --git a/Classes/Module/MailerEngineController.php b/Classes/Module/MailerEngineController.php index 8a11dde4e..f1109948e 100644 --- a/Classes/Module/MailerEngineController.php +++ b/Classes/Module/MailerEngineController.php @@ -36,6 +36,8 @@ public function indexAction(ServerRequestInterface $request) : ResponseInterface else { // If no access or if ID == zero $this->view = $this->configureTemplatePaths('NoAccess'); + $message = $this->createFlashMessage('If no access or if ID == zero', 'No Access', 1, false); + $this->messageQueue->addMessage($message); } /** diff --git a/Classes/Module/MainController.php b/Classes/Module/MainController.php index 3eb91d089..50e30ba05 100644 --- a/Classes/Module/MainController.php +++ b/Classes/Module/MainController.php @@ -8,6 +8,8 @@ use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Database\Query\QueryBuilder; use TYPO3\CMS\Core\Localization\LanguageService; +use TYPO3\CMS\Core\Messaging\FlashMessage; +use TYPO3\CMS\Core\Messaging\FlashMessageService; use TYPO3\CMS\Core\Type\Bitmask\Permission; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Fluid\View\StandaloneView; @@ -48,6 +50,8 @@ class MainController { protected array $pageinfo = []; protected bool $access = false; + protected $messageQueue; + /** * Constructor Method * @@ -82,6 +86,8 @@ protected function init(ServerRequestInterface $request): void { } // initialize backend user language //$this->sys_language_uid = 0; //@TODO + + $this->messageQueue = $this->getMessageQueue(); } /** @@ -98,6 +104,33 @@ protected function configureTemplatePaths (string $templateName): StandaloneView return $view; } + /** + * + https://api.typo3.org/11.5/class_t_y_p_o3_1_1_c_m_s_1_1_core_1_1_messaging_1_1_abstract_message.html + const NOTICE = -2 + const INFO = -1 + const OK = 0 + const WARNING = 1 + const ERROR = 2 + * @param string $messageText + * @param string $messageHeader + * @param int $messageType + * @param bool $storeInSession + */ + protected function createFlashMessage(string $messageText, string $messageHeader = '', int $messageType = 0, bool $storeInSession = false) { + return GeneralUtility::makeInstance(FlashMessage::class, + $messageText, + $messageHeader, // [optional] the header + $messageType, // [optional] the severity defaults to \TYPO3\CMS\Core\Messaging\FlashMessage::OK + $storeInSession // [optional] whether the message should be stored in the session or only in the \TYPO3\CMS\Core\Messaging\FlashMessageQueue object (default is false) + ); + } + + protected function getMessageQueue() { + $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class); + return $flashMessageService->getMessageQueueByIdentifier(); + } + /** * @return LanguageService */ diff --git a/Classes/Module/RecipientListController.php b/Classes/Module/RecipientListController.php index ca38ee981..d74c31448 100644 --- a/Classes/Module/RecipientListController.php +++ b/Classes/Module/RecipientListController.php @@ -55,6 +55,8 @@ public function indexAction(ServerRequestInterface $request) : ResponseInterface else { // If no access or if ID == zero $this->view = $this->configureTemplatePaths('NoAccess'); + $message = $this->createFlashMessage('If no access or if ID == zero', 'No Access', 1, false); + $this->messageQueue->addMessage($message); } /** diff --git a/Classes/Module/StatisticsController.php b/Classes/Module/StatisticsController.php index df1517161..b3c4e8c54 100644 --- a/Classes/Module/StatisticsController.php +++ b/Classes/Module/StatisticsController.php @@ -39,6 +39,8 @@ public function indexAction(ServerRequestInterface $request) : ResponseInterface else { // If no access or if ID == zero $this->view = $this->configureTemplatePaths('NoAccess'); + $message = $this->createFlashMessage('If no access or if ID == zero', 'No Access', 1, false); + $this->messageQueue->addMessage($message); } /** diff --git a/Resources/Private/Templates/Configuration.html b/Resources/Private/Templates/Configuration.html index cf9cccf78..37bfadee9 100644 --- a/Resources/Private/Templates/Configuration.html +++ b/Resources/Private/Templates/Configuration.html @@ -1,6 +1,7 @@ +

{formcontent} diff --git a/Resources/Private/Templates/Dmail.html b/Resources/Private/Templates/Dmail.html index e6538cb84..42ab37d5e 100644 --- a/Resources/Private/Templates/Dmail.html +++ b/Resources/Private/Templates/Dmail.html @@ -1,6 +1,7 @@ +
{wizardsteps} diff --git a/Resources/Private/Templates/MailerEngine.html b/Resources/Private/Templates/MailerEngine.html index d072ce88a..f4ef755a3 100644 --- a/Resources/Private/Templates/MailerEngine.html +++ b/Resources/Private/Templates/MailerEngine.html @@ -1,6 +1,7 @@ +

{cronMonitor} {mailerEngine} diff --git a/Resources/Private/Templates/NoAccess.html b/Resources/Private/Templates/NoAccess.html index aad9fa6d1..69d4cdf6d 100644 --- a/Resources/Private/Templates/NoAccess.html +++ b/Resources/Private/Templates/NoAccess.html @@ -1,5 +1,5 @@ -

If no access or if ID == zero @TODO

+
diff --git a/Resources/Private/Templates/RecipientList.html b/Resources/Private/Templates/RecipientList.html index 5f99f8f5e..9b35afd44 100644 --- a/Resources/Private/Templates/RecipientList.html +++ b/Resources/Private/Templates/RecipientList.html @@ -1,6 +1,7 @@ +

{formcontent}
\ No newline at end of file diff --git a/Resources/Private/Templates/Statistics.html b/Resources/Private/Templates/Statistics.html index 8a8183f18..0c439d645 100644 --- a/Resources/Private/Templates/Statistics.html +++ b/Resources/Private/Templates/Statistics.html @@ -1,6 +1,7 @@ +

{formcontent}
\ No newline at end of file From c458656746bf7f3e44e759df14c343ef9b15cecf Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sat, 11 Dec 2021 16:54:44 +0000 Subject: [PATCH 038/342] update ConfigurationController --- Classes/Module/Configuration.php | 4 +-- Classes/Module/ConfigurationController.php | 33 +++++++++++++++---- Classes/Module/MainController.php | 3 +- .../Private/Templates/Configuration.html | 2 ++ 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/Classes/Module/Configuration.php b/Classes/Module/Configuration.php index 3a4d7bed3..6143ababf 100644 --- a/Classes/Module/Configuration.php +++ b/Classes/Module/Configuration.php @@ -241,8 +241,8 @@ function toggleDisplay(toggleId, e, countBox) { // $module = $this->pageinfo['module']; if (!$module) { - $pidrec=BackendUtility::getRecord('pages', intval($this->pageinfo['pid'])); - $module=$pidrec['module']; + $pidrec = BackendUtility::getRecord('pages', intval($this->pageinfo['pid'])); + $module = $pidrec['module']; } if ($module == 'dmail') { diff --git a/Classes/Module/ConfigurationController.php b/Classes/Module/ConfigurationController.php index f4c47db8a..ef966c139 100644 --- a/Classes/Module/ConfigurationController.php +++ b/Classes/Module/ConfigurationController.php @@ -44,13 +44,32 @@ public function indexAction(ServerRequestInterface $request) : ResponseInterface $this->init($request); if (($this->id && $this->access) || ($this->isAdmin() && !$this->id)) { $this->moduleTemplate->addJavaScriptCode($this->getJS($this->sys_dmail_uid)); - - $formcontent = $this->moduleContent(); - $this->view->assignMultiple( - [ - 'formcontent' => $formcontent - ] - ); + + $module = $this->pageinfo['module'] ?? false; + if (!$module && isset($this->pageinfo['pid'])) { + $pidrec = BackendUtility::getRecord('pages', intval($this->pageinfo['pid'])); + $module = $pidrec['module'] ?? false; + } + + if ($module == 'dmail') { + // Direct mail module + if (($this->pageinfo['doktype'] ?? 0) == 254) { + $formcontent = $this->moduleContent(); + $this->view->assignMultiple( + [ + 'formcontent' => $formcontent + ] + ); + } + elseif ($this->id != 0) { + $message = $this->createFlashMessage($this->getLanguageService()->getLL('dmail_noRegular'), $this->getLanguageService()->getLL('dmail_newsletters'), 1, false); + $this->messageQueue->addMessage($message); + } + } + else { + $message = $this->createFlashMessage($this->getLanguageService()->getLL('select_folder'), $this->getLanguageService()->getLL('header_conf'), 1, false); + $this->messageQueue->addMessage($message); + } } else { // If no access or if ID == zero diff --git a/Classes/Module/MainController.php b/Classes/Module/MainController.php index 50e30ba05..30a5d39cc 100644 --- a/Classes/Module/MainController.php +++ b/Classes/Module/MainController.php @@ -117,7 +117,8 @@ protected function configureTemplatePaths (string $templateName): StandaloneView * @param int $messageType * @param bool $storeInSession */ - protected function createFlashMessage(string $messageText, string $messageHeader = '', int $messageType = 0, bool $storeInSession = false) { + protected function createFlashMessage(string $messageText, string $messageHeader = '', int $messageType = 0, bool $storeInSession = false) + { return GeneralUtility::makeInstance(FlashMessage::class, $messageText, $messageHeader, // [optional] the header diff --git a/Resources/Private/Templates/Configuration.html b/Resources/Private/Templates/Configuration.html index 37bfadee9..fbc11d690 100644 --- a/Resources/Private/Templates/Configuration.html +++ b/Resources/Private/Templates/Configuration.html @@ -2,9 +2,11 @@ +

{formcontent} +
\ No newline at end of file From d38c70963413e106bdd2eae2ba3f29bf52383bb5 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sat, 11 Dec 2021 21:15:36 +0000 Subject: [PATCH 039/342] update MailerEngineController --- Classes/Module/ConfigurationController.php | 22 +- Classes/Module/MailerEngine.php | 2 +- Classes/Module/MailerEngineController.php | 209 +++++++++++++----- Classes/Module/MainController.php | 14 ++ .../Private/Templates/Configuration.html | 2 +- Resources/Private/Templates/MailerEngine.html | 2 + 6 files changed, 174 insertions(+), 77 deletions(-) diff --git a/Classes/Module/ConfigurationController.php b/Classes/Module/ConfigurationController.php index ef966c139..f754339b1 100644 --- a/Classes/Module/ConfigurationController.php +++ b/Classes/Module/ConfigurationController.php @@ -25,18 +25,7 @@ use DirectMailTeam\DirectMail\DirectMailUtility; class ConfigurationController extends MainController -{ - /** - * Constructor Method - * - * @var ModuleTemplate $moduleTemplate - */ - public function __construct(ModuleTemplate $moduleTemplate = null) - { - $this->moduleTemplate = $moduleTemplate ?? GeneralUtility::makeInstance(ModuleTemplate::class); - $this->getLanguageService()->includeLLFile('EXT:direct_mail/Resources/Private/Language/locallang_mod2-6.xlf'); - } - +{ public function indexAction(ServerRequestInterface $request) : ResponseInterface { $this->view = $this->configureTemplatePaths('Configuration'); @@ -45,11 +34,7 @@ public function indexAction(ServerRequestInterface $request) : ResponseInterface if (($this->id && $this->access) || ($this->isAdmin() && !$this->id)) { $this->moduleTemplate->addJavaScriptCode($this->getJS($this->sys_dmail_uid)); - $module = $this->pageinfo['module'] ?? false; - if (!$module && isset($this->pageinfo['pid'])) { - $pidrec = BackendUtility::getRecord('pages', intval($this->pageinfo['pid'])); - $module = $pidrec['module'] ?? false; - } + $module = $this->getModulName(); if ($module == 'dmail') { // Direct mail module @@ -57,7 +42,8 @@ public function indexAction(ServerRequestInterface $request) : ResponseInterface $formcontent = $this->moduleContent(); $this->view->assignMultiple( [ - 'formcontent' => $formcontent + 'formcontent' => $formcontent, + 'show' => true ] ); } diff --git a/Classes/Module/MailerEngine.php b/Classes/Module/MailerEngine.php index 4e9dad4d2..63b6c6231 100644 --- a/Classes/Module/MailerEngine.php +++ b/Classes/Module/MailerEngine.php @@ -231,7 +231,7 @@ function jumpToUrlD(URL) { // */ public function printContent() { - $this->content.=$this->doc->endPage(); + $this->content .= $this->doc->endPage(); } /** diff --git a/Classes/Module/MailerEngineController.php b/Classes/Module/MailerEngineController.php index f1109948e..0f8ca8e00 100644 --- a/Classes/Module/MailerEngineController.php +++ b/Classes/Module/MailerEngineController.php @@ -1,6 +1,7 @@ view = $this->configureTemplatePaths('MailerEngine'); $this->init($request); - + $this->getLanguageService()->includeLLFile('EXT:direct_mail/Resources/Private/Language/locallang_csh_sysdmail.xlf'); + if (($this->id && $this->access) || ($this->isAdmin() && !$this->id)) { - $cronMonitor = $this->cmd_cronMonitor(); - $mailerEngine = $this->cmd_mailerengine(); - - $this->view->assignMultiple( - [ - 'cronMonitor' => $cronMonitor, - 'mailerEngine' => $mailerEngine - ] - ); + $module = $this->getModulName(); + debug($module); + if ($module == 'dmail') { + //@TODO $this->cmd + if (GeneralUtility::_GP('cmd') == 'delete') { + $this->deleteDMail(GeneralUtility::_GP('uid')); + } + $this->pageinfo['doktype'] = 254;//TEST + // Direct mail module + if (($this->pageinfo['doktype'] ?? 0) == 254) { + $cronMonitor = $this->cmd_cronMonitor(); + $mailerEngine = $this->cmd_mailerengine(); + + $this->view->assignMultiple( + [ + 'cronMonitor' => $cronMonitor, + 'mailerEngine' => $mailerEngine, + 'show' => true + ] + ); + } + elseif ($this->id != 0) { + $message = $this->createFlashMessage($this->getLanguageService()->getLL('dmail_noRegular'), $this->getLanguageService()->getLL('dmail_newsletters'), 1, false); + $this->messageQueue->addMessage($message); + } + } + else { + $message = $this->createFlashMessage($this->getLanguageService()->getLL('select_folder'), $this->getLanguageService()->getLL('header_conf'), 1, false); + $this->messageQueue->addMessage($message); + } } else { // If no access or if ID == zero @@ -146,6 +169,32 @@ public function cmd_cronMonitor() ->render([$flashMessage]); } + protected function getSysDmails() { + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_dmail'); + $queryBuilder + ->getRestrictions() + ->removeAll() + ->add(GeneralUtility::makeInstance(DeletedRestriction::class)); + + $statement = $queryBuilder->select('uid', 'pid', 'subject', 'scheduled', 'scheduled_begin', 'scheduled_end') + ->from('sys_dmail') + ->add('where','pid = ' . intval($this->id) .' AND scheduled > 0') + ->orderBy('scheduled','DESC') + ->execute(); + + return $statement; + } + + protected function countSysDmailMaillogs($uid) { + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_dmail_maillog'); + return $queryBuilder->count('*') + ->from('sys_dmail_maillog') + ->add('where', 'mid = ' . intval($row['uid']) . + ' AND response_type = 0' . + ' AND html_sent > 0') + ->execute(); + } + /** * Shows the status of the mailer engine. * TODO: Should really only show some entries, or provide a browsing interface. @@ -161,16 +210,8 @@ public function cmd_mailerengine() $enableTrigger = ! (isset($this->params['menu.']['dmail_mode.']['mailengine.']['disable_trigger']) && $this->params['menu.']['dmail_mode.']['mailengine.']['disable_trigger']); if ($enableTrigger && GeneralUtility::_GP('invokeMailerEngine')) { $this->invokeMEngine(); - $invokeMessage = GeneralUtility::makeInstance(FlashMessageRendererResolver::class) - ->resolve() - ->render([ - GeneralUtility::makeInstance( - FlashMessage::class, - '', - $this->getLanguageService()->getLL('dmail_mailerengine_invoked'), - FlashMessage::INFO - ) - ]); + $message = $this->createFlashMessage('', $this->getLanguageService()->getLL('dmail_mailerengine_invoked'), -1, false); + $this->messageQueue->addMessage($message); } // Invoke engine @@ -192,19 +233,6 @@ public function cmd_mailerengine() } // Display mailer engine status - $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_dmail'); - $queryBuilder - ->getRestrictions() - ->removeAll() - ->add(GeneralUtility::makeInstance(DeletedRestriction::class)); - $res = $queryBuilder->select('uid', 'pid', 'subject', 'scheduled', 'scheduled_begin', 'scheduled_end') - ->from('sys_dmail') - ->add('where','pid=' . intval($this->id) .' AND scheduled>0') - ->orderBy('scheduled','DESC') - ->execute() - ->fetchAll(); - - $out = '   ' . $this->getLanguageService()->getLL('dmail_mailerengine_subject') . '   @@ -214,32 +242,99 @@ public function cmd_mailerengine()  ' . $this->getLanguageService()->getLL('dmail_mailerengine_number_sent') . '   ' . $this->getLanguageService()->getLL('dmail_mailerengine_delete') . '  '; - - - - foreach ($res as $row) { - $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_dmail_maillog'); - $countres = $queryBuilder->count('*') - ->from('sys_dmail_maillog') - ->add('where','mid=' . intval($row['uid']) . - ' AND response_type=0' . - ' AND html_sent>0') - ->execute(); - - foreach($countres as $cRow) $count = $cRow['COUNT(*)']; - - $out .=' - ' . $this->moduleTemplate->getIconFactory()->getIconForRecord('sys_dmail', $row, Icon::SIZE_SMALL)->render() . ' - ' . $this->linkDMail_record(htmlspecialchars(GeneralUtility::fixed_lgd_cs($row['subject'], 100)) . '  ', $row['uid']) . ' - ' . BackendUtility::datetime($row['scheduled']) . '   - ' . ($row['scheduled_begin']?BackendUtility::datetime($row['scheduled_begin']):'') . '   - ' . ($row['scheduled_end']?BackendUtility::datetime($row['scheduled_end']):'') . '   - ' . ($count?$count:' ') . ' - ' . $this->deleteLink($row['uid']) . ' - '; + + $rows = $this->getSysDmails(); + while (($row = $rows->fetchAssociative()) !== false) { + $countres = $this->countSysDmailMaillogs($row['uid']); + + //@TODO + foreach($countres as $cRow) { + $count = $cRow['COUNT(*)']; + } + unset($countres); + + $out .=' + ' . $this->moduleTemplate->getIconFactory()->getIconForRecord('sys_dmail', $row, Icon::SIZE_SMALL)->render() . ' + ' . $this->linkDMail_record(htmlspecialchars(GeneralUtility::fixed_lgd_cs($row['subject'], 100)) . '  ', $row['uid']) . ' + ' . BackendUtility::datetime($row['scheduled']) . '   + ' . ($row['scheduled_begin'] ? BackendUtility::datetime($row['scheduled_begin']) : '') . '   + ' . ($row['scheduled_end'] ? BackendUtility::datetime($row['scheduled_end']) : '') . '   + ' . ($count ? $count : ' ') . ' + ' . $this->deleteLink($row['uid']) . ' + '; } - + unset($rows); $out = $invokeMessage . '' . $out . '
'; return '

' . $this->getLanguageService()->getLL('dmail_mailerengine_status') .'

' . $out; } + + /** + * Create delete link with trash icon + * + * @param int $uid Uid of the record + * + * @return string Link with the trash icon + * @throws RouteNotFoundException If the named route doesn't exist + */ + public function deleteLink($uid) + { + $icon = $this->moduleTemplate->getIconFactory()->getIcon('actions-edit-delete', Icon::SIZE_SMALL); + $dmail = BackendUtility::getRecord('sys_dmail', $uid); + + // show delete icon if newsletter hasn't been sent, or not yet finished sending + if (!($dmail['scheduled_begin']) || + ($dmail['scheduled_begin'] && $dmail['scheduled_end'] === 0)) { + /** @var UriBuilder $uriBuilder */ + $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); + $moduleUrl = $uriBuilder->buildUriFromRoute( + $this->moduleName, + [ + 'id' => $this->id, + 'uid' => $uid, + 'cmd' => 'delete' + ] + ); + return '' . $icon . ''; + } + return ''; + } + + /** + * Delete existing dmail record + * + * @param int $uid Record uid to be deleted + * + * @return void + */ + public function deleteDMail($uid) + { + $table = 'sys_dmail'; + if ($GLOBALS['TCA'][$table]['ctrl']['delete']) { + $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); + $connection = $connectionPool->getConnectionForTable($table); + + $connection->update( + $table, // table + [ $GLOBALS['TCA'][$table]['ctrl']['delete'] => 1 ], + [ 'uid' => $uid ] // where + ); + } + } + + /** + * Invoking the mail engine + * This method no longer returns logs in backend modul directly + * + * @see Dmailer::start + * @see Dmailer::runcron + */ + public function invokeMEngine() + { + // TODO: remove htmlmail + /* @var $htmlmail \DirectMailTeam\DirectMail\Dmailer */ + $htmlmail = GeneralUtility::makeInstance(Dmailer::class); + $htmlmail->nonCron = 1; + $htmlmail->start(); + $htmlmail->runcron(); + } } \ No newline at end of file diff --git a/Classes/Module/MainController.php b/Classes/Module/MainController.php index 30a5d39cc..577fc761f 100644 --- a/Classes/Module/MainController.php +++ b/Classes/Module/MainController.php @@ -132,6 +132,20 @@ protected function getMessageQueue() { return $flashMessageService->getMessageQueueByIdentifier(); } + protected function getModulName() { + $module = $this->pageinfo['module'] ?? false; + + $this->pageinfo['pid'] = 108; //TEST + if (!$module && isset($this->pageinfo['pid'])) { + + $pidrec = BackendUtility::getRecord('pages', intval($this->pageinfo['pid'])); + + $module = $pidrec['module'] ?? false; + } + + return $module; + } + /** * @return LanguageService */ diff --git a/Resources/Private/Templates/Configuration.html b/Resources/Private/Templates/Configuration.html index fbc11d690..79ff9298f 100644 --- a/Resources/Private/Templates/Configuration.html +++ b/Resources/Private/Templates/Configuration.html @@ -2,7 +2,7 @@ - +

{formcontent} diff --git a/Resources/Private/Templates/MailerEngine.html b/Resources/Private/Templates/MailerEngine.html index f4ef755a3..7210f3dbf 100644 --- a/Resources/Private/Templates/MailerEngine.html +++ b/Resources/Private/Templates/MailerEngine.html @@ -2,9 +2,11 @@ +

{cronMonitor} {mailerEngine} +
\ No newline at end of file From 04389bcd5c569ba72a05b2fef8d8bec90e3dcb41 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sat, 11 Dec 2021 21:47:12 +0000 Subject: [PATCH 040/342] update StatisticsController --- Classes/Module/MailerEngineController.php | 4 +- Classes/Module/MainController.php | 5 +- Classes/Module/StatisticsController.php | 79 ++++++++++----------- Resources/Private/Templates/Statistics.html | 4 +- 4 files changed, 45 insertions(+), 47 deletions(-) diff --git a/Classes/Module/MailerEngineController.php b/Classes/Module/MailerEngineController.php index 0f8ca8e00..2d40d1dee 100644 --- a/Classes/Module/MailerEngineController.php +++ b/Classes/Module/MailerEngineController.php @@ -26,13 +26,13 @@ public function indexAction(ServerRequestInterface $request) : ResponseInterface if (($this->id && $this->access) || ($this->isAdmin() && !$this->id)) { $module = $this->getModulName(); - debug($module); + if ($module == 'dmail') { //@TODO $this->cmd if (GeneralUtility::_GP('cmd') == 'delete') { $this->deleteDMail(GeneralUtility::_GP('uid')); } - $this->pageinfo['doktype'] = 254;//TEST + // Direct mail module if (($this->pageinfo['doktype'] ?? 0) == 254) { $cronMonitor = $this->cmd_cronMonitor(); diff --git a/Classes/Module/MainController.php b/Classes/Module/MainController.php index 577fc761f..147a1fc90 100644 --- a/Classes/Module/MainController.php +++ b/Classes/Module/MainController.php @@ -134,12 +134,9 @@ protected function getMessageQueue() { protected function getModulName() { $module = $this->pageinfo['module'] ?? false; - - $this->pageinfo['pid'] = 108; //TEST + if (!$module && isset($this->pageinfo['pid'])) { - $pidrec = BackendUtility::getRecord('pages', intval($this->pageinfo['pid'])); - $module = $pidrec['module'] ?? false; } diff --git a/Classes/Module/StatisticsController.php b/Classes/Module/StatisticsController.php index b3c4e8c54..8b473899b 100644 --- a/Classes/Module/StatisticsController.php +++ b/Classes/Module/StatisticsController.php @@ -11,30 +11,37 @@ use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction; class StatisticsController extends MainController -{ - /** - * Constructor Method - * - * @var ModuleTemplate $moduleTemplate - */ - public function __construct(ModuleTemplate $moduleTemplate = null) - { - $this->moduleTemplate = $moduleTemplate ?? GeneralUtility::makeInstance(ModuleTemplate::class); - } - +{ public function indexAction(ServerRequestInterface $request) : ResponseInterface { $this->view = $this->configureTemplatePaths('Statistics'); $this->init($request); + $this->getLanguageService()->includeLLFile('EXT:direct_mail/Resources/Private/Language/locallang_csh_sysdmail.xlf'); if (($this->id && $this->access) || ($this->isAdmin() && !$this->id)) { - $formcontent = $this->moduleContent(); - $this->view->assignMultiple( - [ - 'formcontent' => $formcontent - ] - ); + $module = $this->getModulName(); + + if ($module == 'dmail') { + // Direct mail module + if (($this->pageinfo['doktype'] ?? 0) == 254) { + $formcontent = $this->moduleContent(); + $this->view->assignMultiple( + [ + 'formcontent' => $formcontent, + 'show' => true + ] + ); + } + elseif ($this->id != 0) { + $message = $this->createFlashMessage($this->getLanguageService()->getLL('dmail_noRegular'), $this->getLanguageService()->getLL('dmail_newsletters'), 1, false); + $this->messageQueue->addMessage($message); + } + } + else { + $message = $this->createFlashMessage($this->getLanguageService()->getLL('select_folder'), $this->getLanguageService()->getLL('header_conf'), 1, false); + $this->messageQueue->addMessage($message); + } } else { // If no access or if ID == zero @@ -79,7 +86,7 @@ protected function moduleContent() $this->setURLs($row); // COMMAND: - switch ($this->CMD) { + switch ($this->cmd) { case 'displayUserInfo': $theOutput = $this->displayUserInfo(); break; @@ -88,8 +95,8 @@ protected function moduleContent() break; default: // Hook for handling of custom direct mail commands: - if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXT']['directmail']['handledirectmailcmd-' . $this->CMD])) { - foreach ($GLOBALS['TYPO3_CONF_VARS']['EXT']['directmail']['handledirectmailcmd-' . $this->CMD] as $funcRef) { + if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXT']['directmail']['handledirectmailcmd-' . $this->cmd])) { + foreach ($GLOBALS['TYPO3_CONF_VARS']['EXT']['directmail']['handledirectmailcmd-' . $this->cmd] as $funcRef) { $params = ['pObj' => &$this]; $theOutput = GeneralUtility::callUserFunction($funcRef, $params, $this); } @@ -124,26 +131,19 @@ protected function displayPageInfo() 'sys_dmail_maillog', $queryBuilder->expr()->eq('sys_dmail.uid', $queryBuilder->quoteIdentifier('sys_dmail_maillog.mid')) ) - ->add('where','sys_dmail.pid=' . intval($this->id) . + ->add('where','sys_dmail.pid = ' . intval($this->id) . ' AND sys_dmail.type IN (0,1)' . ' AND sys_dmail.issent = 1'. - ' AND sys_dmail_maillog.response_type=0'. - ' AND sys_dmail_maillog.html_sent>0') + ' AND sys_dmail_maillog.response_type = 0'. + ' AND sys_dmail_maillog.html_sent > 0') ->groupBy('sys_dmail_maillog.mid') ->orderBy('sys_dmail.scheduled','DESC') ->addOrderBy('sys_dmail.scheduled_begin','DESC') ->execute() ->fetchAll(); - - $onClick = ''; - if ($res) { - $onClick = ' onClick="return confirm(' . GeneralUtility::quoteJSvalue(sprintf($this->getLanguageService()->getLL('nl_l_warning'), count($res))) . ');"'; - } - $out = ''; - - if ($res) { - $out .=''; - $out .=' + + $out ='
'; + $out .=' @@ -152,7 +152,8 @@ protected function displayPageInfo() '; - + + if ($res) { foreach ($res as $row) { if (!empty($row['scheduled_begin'])) { if (!empty($row['scheduled_end'])) { @@ -174,14 +175,12 @@ protected function displayPageInfo() '; } - $out.='
  ' . $this->getLanguageService()->getLL('stats_overview_subject') . ' ' . $this->getLanguageService()->getLL('stats_overview_scheduled') . '' . $this->getLanguageService()->getLL('stats_overview_total_sent') . ' ' . $this->getLanguageService()->getLL('stats_overview_status') . '
' . $sent . '
'; } + $out .= ''; + $out = '

' . $this->getLanguageService()->getLL('stats_overview_choose') . '

' .$out; + $out .= '
'; - $theOutput = '

' . $this->getLanguageService()->getLL('stats_overview_choose') . '

' . - $out; - $theOutput .= '
'; - - return $theOutput; + return $out; } /** diff --git a/Resources/Private/Templates/Statistics.html b/Resources/Private/Templates/Statistics.html index 0c439d645..3088a1646 100644 --- a/Resources/Private/Templates/Statistics.html +++ b/Resources/Private/Templates/Statistics.html @@ -2,6 +2,8 @@ -

+ +

{formcontent} +
\ No newline at end of file From afb35693590d7b268106a3264ce895c0818842b8 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sat, 11 Dec 2021 22:22:39 +0000 Subject: [PATCH 041/342] bugfix Importer --- Classes/Importer.php | 117 ++++++++++++++++++++++--------------------- 1 file changed, 60 insertions(+), 57 deletions(-) diff --git a/Classes/Importer.php b/Classes/Importer.php index 8f30e84f8..31f55d8d0 100644 --- a/Classes/Importer.php +++ b/Classes/Importer.php @@ -41,8 +41,8 @@ class Importer * The GET-Data * @var array */ - public $indata = array(); - public $params = array(); + public $indata = []; + public $params = []; /** * Parent object @@ -100,11 +100,11 @@ public function cmd_displayImport() } if (empty($this->indata)) { - $this->indata = array(); + $this->indata = []; } if (empty($this->params)) { - $this->params = array(); + $this->params = []; } // merge it with inData, but inData has priority. $this->indata += $this->params; @@ -122,22 +122,23 @@ public function cmd_displayImport() $this->indata['newFile'] = rtrim($storageConfig['basePath'], '/') . '/' . ltrim($this->indata['newFile'][0]->getIdentifier(), '/'); } } elseif (!empty($this->indata['csv']) && empty($_FILES['upload_1']['name'])) { - if (((strpos($currentFileInfo['file'], 'import')=== false)?0:1) && ($currentFileInfo['realFileext'] === 'txt')) { + if (((strpos($currentFileInfo['file'], 'import')=== false) ? 0 : 1) && ($currentFileInfo['realFileext'] === 'txt')) { // do nothing } else { unset($this->indata['newFile']); } } - if ($this->indata['back']) { + $stepCurrent = ''; + if ($this->indata['back'] ?? false) { $stepCurrent = $step['back']; - } elseif ($this->indata['next']) { + } elseif ($this->indata['next'] ?? false) { $stepCurrent = $step['next']; - } elseif ($this->indata['update']) { + } elseif ($this->indata['update'] ?? false) { $stepCurrent = 'mapping'; } - if (strlen($this->indata['csv']) > 0) { + if (strlen($this->indata['csv'] ?? 0) > 0) { $this->indata['mode'] = 'csv'; $this->indata['newFile'] = $this->writeTempFile(); } elseif (!empty($this->indata['newFile'])) { @@ -147,9 +148,9 @@ public function cmd_displayImport() } // check if "email" is mapped - if ($stepCurrent === 'import') { + if (isset($stepCurrent) && $stepCurrent === 'import') { $map = $this->indata['map']; - $error = array(); + $error = []; // check noMap $newMap = ArrayUtility::removeArrayEntryByValue(array_unique($map), 'noMap'); if (empty($newMap)) { @@ -183,7 +184,7 @@ public function cmd_displayImport() ->orderBy('uid') ->execute(); - $optStorage = array(); + $optStorage = []; while (($row = $statement->fetch())) { if (BackendUtility::readPageAccess($row['uid'], $GLOBALS['BE_USER']->getPagePermsClause(1))) { $optStorage[] = array($row['uid'],$row['title'] . ' [uid:' . $row['uid'] . ']'); @@ -212,7 +213,7 @@ public function cmd_displayImport() // show configuration $out = '

' . $this->getLanguageService()->getLL('mailgroup_import_header_conf') . '

'; - $tblLines = array(); + $tblLines = []; // get the all sysfolder $tblLines[] = array( @@ -282,7 +283,7 @@ public function cmd_displayImport() case 'mapping': // show charset selector $cs = array_unique(array_values(mb_list_encodings())); - $charSets = array(); + $charSets = []; foreach ($cs as $charset) { $charSets[] = array($charset,$charset); } @@ -291,7 +292,7 @@ public function cmd_displayImport() $this->indata['charset'] = 'ISO-8859-1'; } $out .= '

' . $this->getLanguageService()->getLL('mailgroup_import_mapping_charset') . '

'; - $tblLines = array(); + $tblLines = []; $tblLines[] = array($this->getLanguageService()->getLL('mailgroup_import_mapping_charset_choose'), $this->makeDropdown('CSV_IMPORT[charset]', $charSets, $this->indata['charset'])); $out .= $this->formatTable($tblLines, array('nowrap', 'nowrap'), 0, array(1, 1), 'border="0" cellpadding="0" cellspacing="0" class="table table-striped table-hover"'); $out .= ''; @@ -309,7 +310,7 @@ public function cmd_displayImport() // read csv $csvData = $this->readExampleCSV(3); $fieldsAmount = count($csvData[0]); - $csv_firstRow = array(); + $csv_firstRow = []; for ($i=0; $i<$fieldsAmount; $i++) { $csv_firstRow[] = 'field_' . $i; } @@ -321,7 +322,7 @@ public function cmd_displayImport() foreach ($no_map as $v) { $ttAddressFields = ArrayUtility::removeArrayEntryByValue($ttAddressFields, $v); } - $mapFields = array(); + $mapFields = []; foreach ($ttAddressFields as $map) { $mapFields[] = array($map, str_replace(':', '', $this->getLanguageService()->sL($GLOBALS['TCA']['tt_address']['columns'][$map]['label']))); } @@ -331,11 +332,11 @@ public function cmd_displayImport() reset($csv_firstRow); reset($csvData); - $tblLines = array(); + $tblLines = []; $tblLines[] = array($this->getLanguageService()->getLL('mailgroup_import_mapping_number'),$this->getLanguageService()->getLL('mailgroup_import_mapping_description'),$this->getLanguageService()->getLL('mailgroup_import_mapping_mapping'),$this->getLanguageService()->getLL('mailgroup_import_mapping_value')); for ($i=0; $i<(count($csv_firstRow)); $i++) { // example CSV - $exampleLines = array(); + $exampleLines = []; for ($j=0;$j<(count($csvData));$j++) { $exampleLines[] = array($csvData[$j][$i]); } @@ -352,7 +353,7 @@ public function cmd_displayImport() } // additional options - $tblLinesAdd = array(); + $tblLinesAdd = []; // header $tblLinesAdd[] = array($this->getLanguageService()->getLL('mailgroup_import_mapping_all_html'), 'indata['all_html']?'':' checked="checked"') . '/> '); @@ -433,7 +434,7 @@ public function cmd_displayImport() 'CSV_IMPORT[add_cat]' => $this->indata['add_cat'], 'CSV_IMPORT[charset]' => $this->indata['charset'], )); - $hiddenMapped = array(); + $hiddenMapped = []; foreach ($this->indata['map'] as $fieldNr => $fieldMapped) { $hiddenMapped[] = $this->makeHidden('CSV_IMPORT[map][' . $fieldNr . ']', $fieldMapped); } @@ -466,14 +467,14 @@ public function cmd_displayImport() if (!empty($this->params['resultOrder'])) { $resultOrder = GeneralUtility::trimExplode(',', $this->params['resultOrder']); } else { - $resultOrder = array(); + $resultOrder = []; } $diffOrder = array_diff($defaultOrder, $resultOrder); $endOrder = array_merge($resultOrder, $diffOrder); foreach ($endOrder as $order) { - $tblLines = array(); + $tblLines = []; $tblLines[] = array($this->getLanguageService()->getLL('mailgroup_import_report_' . $order)); if (is_array($result[$order])) { foreach ($result[$order] as $k => $v) { @@ -501,7 +502,7 @@ public function cmd_displayImport() 'CSV_IMPORT[all_html]' => $this->indata['all_html'], 'CSV_IMPORT[charset]' => $this->indata['charset'], )); - $hiddenMapped = array(); + $hiddenMapped = []; foreach ($this->indata['map'] as $fieldNr => $fieldMapped) { $hiddenMapped[] = $this->makeHidden('CSV_IMPORT[map][' . $fieldNr . ']', $fieldMapped); } @@ -520,22 +521,22 @@ public function cmd_displayImport() $tempDir = $this->userTempFolder(); $tblLines[] = $this->getLanguageService()->getLL('mailgroup_import_upload_file') . ''; - if (($this->indata['mode'] === 'file') && !(((strpos($currentFileInfo['file'], 'import')=== false)?0:1) && ($currentFileInfo['realFileext'] === 'txt'))) { + if (($this->indata['mode'] === 'file') && !(((strpos($currentFileInfo['file'], 'import')=== false) ? 0 : 1) && ($currentFileInfo['realFileext'] === 'txt'))) { $currentFileMessage = ''; $tblLines[] = $this->getLanguageService()->getLL('mailgroup_import_current_file') . '' . $currentFileMessage . ''; } - - if (((strpos($currentFileInfo['file'], 'import')=== false)?0:1) && ($currentFileInfo['realFileext'] === 'txt')) { + + if (((strpos(($currentFileInfo['file'] ?? ''), 'import') === false) ? 0 : 1) && (($currentFileInfo['realFileext'] ?? '') === 'txt')) { $handleCsv = fopen($this->indata['newFile'], 'r'); $this->indata['csv'] = fread($handleCsv, filesize($this->indata['newFile'])); fclose($handleCsv); } - + $tblLines[] = ''; $tblLines[] = '' . $this->getLanguageService()->getLL('mailgroup_import_or') . ''; $tblLines[] = ''; $tblLines[] = $this->getLanguageService()->getLL('mailgroup_import_paste_csv'); - $tblLines[] = ''; + $tblLines[] = ''; $tblLines[] = ''; $out .= implode('
', $tblLines); @@ -547,9 +548,10 @@ public function cmd_displayImport() '; } + //@TODO $this->cshTable => Undefined property; $GLOBALS['BACK_PATH'] => Undefined array key $theOutput = sprintf( '

%s

%s
', - $this->getLanguageService()->getLL('mailgroup_import') . BackendUtility::cshItem($this->cshTable, 'mailgroup_import', $GLOBALS['BACK_PATH']), + $this->getLanguageService()->getLL('mailgroup_import') . BackendUtility::cshItem($this->cshTable ?? '', 'mailgroup_import', $GLOBALS['BACK_PATH'] ?? ''), $out ); @@ -557,13 +559,14 @@ public function cmd_displayImport() * Hook for cmd_displayImport * use it to manipulate the steps in the import process */ - if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['direct_mail/mod3/class.tx_directmail_recipient_list.php']['cmd_displayImport'])) { - $hookObjectsArr = array(); + $hookObjectsArr = []; + if (isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['direct_mail/mod3/class.tx_directmail_recipient_list.php']['cmd_displayImport']) && + is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['direct_mail/mod3/class.tx_directmail_recipient_list.php']['cmd_displayImport'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['direct_mail/mod3/class.tx_directmail_recipient_list.php']['cmd_displayImport'] as $classRef) { $hookObjectsArr[] = GeneralUtility::makeInstance($classRef); } } - if (is_array($hookObjectsArr)) { + if (count($hookObjectsArr)) { foreach ($hookObjectsArr as $hookObj) { if (method_exists($hookObj, 'cmd_displayImport')) { $theOutput = $hookObj->cmd_displayImport($this); @@ -588,9 +591,9 @@ public function cmd_displayImport() public function filterCSV(array $mappedCsv) { $cmpCsv = $mappedCsv; - $remove = array(); - $filtered = array(); - $double = array(); + $remove = []; + $filtered = []; + $double = []; foreach ($mappedCsv as $k => $csvData) { if (!in_array($k, $remove)) { @@ -627,8 +630,8 @@ public function filterCSV(array $mappedCsv) */ public function doImport(array $csvData) { - $resultImport = array(); - $filteredCSV = array(); + $resultImport = []; + $filteredCSV = []; //empty table if flag is set if ($this->indata['remove_existing']) { @@ -644,10 +647,10 @@ public function doImport(array $csvData) ->execute(); } - $mappedCSV = array(); - $invalidEmailCSV = array(); + $mappedCSV = []; + $invalidEmailCSV = []; foreach ($csvData as $dataArray) { - $tempData = array(); + $tempData = []; $invalidEmail = 0; foreach ($dataArray as $kk => $fieldData) { if ($this->indata['map'][$kk] !== 'noMap') { @@ -681,10 +684,10 @@ public function doImport(array $csvData) } // array for the process_datamap(); - $data = array(); + $data = []; if ($this->indata['update_unique']) { - $user = array(); - $userID = array(); + $user = []; + $userID = []; $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_address'); // only add deleteClause @@ -779,14 +782,14 @@ public function doImport(array $csvData) } $resultImport['invalid_email'] = $invalidEmailCSV; - $resultImport['double'] = (is_array($filteredCSV['double']))?$filteredCSV['double']: array(); + $resultImport['double'] = (is_array($filteredCSV['double']))?$filteredCSV['double']: []; // start importing /* @var $tce DataHandler */ $tce = GeneralUtility::makeInstance(DataHandler::class); $tce->stripslashes_values = 0; $tce->enableLogging = 0; - $tce->start($data, array()); + $tce->start($data, []); $tce->process_datamap(); /** @@ -794,7 +797,7 @@ public function doImport(array $csvData) * will be called every time a record is inserted */ if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['direct_mail/mod3/class.tx_directmail_recipient_list.php']['doImport'])) { - $hookObjectsArr = array(); + $hookObjectsArr = []; foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['direct_mail/mod3/class.tx_directmail_recipient_list.php']['doImport'] as $classRef) { $hookObjectsArr[] = GeneralUtility::makeInstance($classRef); } @@ -844,7 +847,7 @@ public function addDataArray(array &$data, $id, array $dataArray) */ public function makeDropdown($name, array $option, $selected, $disableInput='') { - $opt = array(); + $opt = []; foreach ($option as $v) { if (is_array($v)) { $opt[] = '
'; - $theOutput = '

' . $this->getLanguageService()->getLL('dmail_wiz5_sendmass') . '

' . - $theOutput; + $theOutput = '

' . $this->getLanguageService()->getLL('dmail_wiz5_sendmass') . '

' . $theOutput; $theOutput .= ''; $theOutput .= ''; diff --git a/Classes/Module/MainController.php b/Classes/Module/MainController.php index 147a1fc90..ef237df9f 100644 --- a/Classes/Module/MainController.php +++ b/Classes/Module/MainController.php @@ -67,9 +67,9 @@ protected function init(ServerRequestInterface $request): void { $queryParams = $request->getQueryParams(); $parsedBody = $request->getParsedBody(); - $this->id = (int)($parsedBody['id'] ?? $queryParams['id'] ?? 0); - $this->cmd = (string)($parsedBody['cmd'] ?? $queryParams['cmd'] ?? ''); - $this->pages_uid = (string)($parsedBody['pages_uid'] ?? $queryParams['pages_uid'] ?? ''); + $this->id = (int)($parsedBody['id'] ?? $queryParams['id'] ?? 0); + $this->cmd = (string)($parsedBody['cmd'] ?? $queryParams['cmd'] ?? ''); + $this->pages_uid = (string)($parsedBody['pages_uid'] ?? $queryParams['pages_uid'] ?? ''); $this->sys_dmail_uid = (int)($parsedBody['sys_dmail_uid'] ?? $queryParams['sys_dmail_uid'] ?? 0); $this->perms_clause = $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW); From a8211817fa5826708c4e8eef06d205684f5027b1 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sun, 19 Dec 2021 14:05:20 +0000 Subject: [PATCH 055/342] update controllers --- Classes/DirectMailUtility.php | 6 +- Classes/Module/ConfigurationController.php | 29 ++++++++ Classes/Module/DmailController.php | 84 +++++++++++++++++++++- Classes/Module/MainController.php | 1 + 4 files changed, 117 insertions(+), 3 deletions(-) diff --git a/Classes/DirectMailUtility.php b/Classes/DirectMailUtility.php index 16db89f99..e50d32b6e 100644 --- a/Classes/DirectMailUtility.php +++ b/Classes/DirectMailUtility.php @@ -1578,9 +1578,11 @@ public static function updatePagesTSconfig($id, array $pageTs, $tsConfPrefix, $i } $set = []; foreach ($pageTs as $f => $v) { + $v = trim($v); $f = $tsConfPrefix . $f; - if ((!isset($impParams[$f]) && trim($v)) || strcmp(trim($impParams[$f]), trim($v))) { - $set[$f] = trim($v); + $tempF = isset($impParams[$f]) ? trim($tempF) : ''; + if (strcmp($tempF, $v)) { + $set[$f] = $v; } } if (count($set)) { diff --git a/Classes/Module/ConfigurationController.php b/Classes/Module/ConfigurationController.php index b5550d641..909fc2a68 100644 --- a/Classes/Module/ConfigurationController.php +++ b/Classes/Module/ConfigurationController.php @@ -26,12 +26,18 @@ class ConfigurationController extends MainController { + protected string $TSconfPrefix = 'mod.web_modules.dmail.'; + protected array $pageTS = []; + public function indexAction(ServerRequestInterface $request) : ResponseInterface { $currentModule = 'Configuration'; $this->view = $this->configureTemplatePaths($currentModule); $this->init($request); + $this->initConfiguration($request); + $this->updatePageTS(); + if (($this->id && $this->access) || ($this->isAdmin() && !$this->id)) { $this->moduleTemplate->addJavaScriptCode($this->getJS($this->sys_dmail_uid)); @@ -73,6 +79,13 @@ public function indexAction(ServerRequestInterface $request) : ResponseInterface return new HtmlResponse($this->moduleTemplate->renderContent()); } + protected function initConfiguration(ServerRequestInterface $request): void { + $queryParams = $request->getQueryParams(); + $parsedBody = $request->getParsedBody(); + + $this->pageTS = $parsedBody['pageTS'] ?? $queryParams['pageTS'] ?? []; + } + protected function getJS($sys_dmail_uid) { return ' script_ended = 0; @@ -297,4 +310,20 @@ public function makeConfigForm(array $configArray, array $params, $dataPrefix) } return $out; } + + /** + * Update the pageTS + * No return value: sent header to the same page + * + * @return void + */ + protected function updatePageTS() + { + if ($GLOBALS['BE_USER']->doesUserHaveAccess(BackendUtility::getRecord('pages', $this->id), 2)) { + if (is_array($this->pageTS) && count($this->pageTS)) { + DirectMailUtility::updatePagesTSconfig($this->id, $this->pageTS, $this->TSconfPrefix); + header('Location: ' . GeneralUtility::locationHeaderUrl(GeneralUtility::getIndpEnv('REQUEST_URI'))); + } + } + } } diff --git a/Classes/Module/DmailController.php b/Classes/Module/DmailController.php index fa01bcb98..310830544 100644 --- a/Classes/Module/DmailController.php +++ b/Classes/Module/DmailController.php @@ -100,13 +100,16 @@ public function indexAction(ServerRequestInterface $request) : ResponseInterface $this->moduleTemplate->getPageRenderer()->addJsInlineCode($currentModule, $this->getJS($this->sys_dmail_uid)); $markers = $this->moduleContent(); $formcontent = $markers['CONTENT']; + + $formcontent = '
'.$formcontent.'
'; + $this->view->assignMultiple( [ 'wizardsteps' => $markers['WIZARDSTEPS'], 'navigation' => $markers['NAVIGATION'], 'flashmessages' => $markers['FLASHMESSAGES'], 'title' => $markers['TITLE'], - 'content' => $markers['CONTENT'] + 'content' => $formcontent ] ); } @@ -907,4 +910,83 @@ protected function makeListDMail($boxId, $totalBox, $open=false) $output.= '
'; return $output; } + + /** + * Creates a directmail entry in th DB. + * used only for quickmail. + * + * @param array $indata Quickmail data (quickmail content, etc.) + * + * @return string error or warning message produced during the process + */ + protected function createDMail_quick(array $indata) + { + $theOutput = ''; + // Set default values: + $dmail = []; + $dmail['sys_dmail']['NEW'] = [ + 'from_email' => $indata['senderEmail'], + 'from_name' => $indata['senderName'], + 'replyto_email' => $this->params['replyto_email'], + 'replyto_name' => $this->params['replyto_name'], + 'return_path' => $this->params['return_path'], + 'priority' => (int) $this->params['priority'], + 'use_rdct' => (int) $this->params['use_rdct'], + 'long_link_mode' => (int) $this->params['long_link_mode'], + 'organisation' => $this->params['organisation'], + 'authcode_fieldList'=> $this->params['authcode_fieldList'], + 'plainParams' => '' + ]; + + // always plaintext + $dmail['sys_dmail']['NEW']['sendOptions'] = 1; + $dmail['sys_dmail']['NEW']['long_link_rdct_url'] = DirectMailUtility::getUrlBase((int)$this->params['pid']); + $dmail['sys_dmail']['NEW']['subject'] = $indata['subject']; + $dmail['sys_dmail']['NEW']['type'] = 1; + $dmail['sys_dmail']['NEW']['pid'] = $this->pageinfo['uid']; + $dmail['sys_dmail']['NEW']['charset'] = isset($this->params['quick_mail_charset']) ? $this->params['quick_mail_charset'] : 'utf-8'; + + // If params set, set default values: + if (isset($this->params['includeMedia'])) { + $dmail['sys_dmail']['NEW']['includeMedia'] = $this->params['includeMedia']; + } + if (isset($this->params['flowedFormat'])) { + $dmail['sys_dmail']['NEW']['flowedFormat'] = $this->params['flowedFormat']; + } + if (isset($this->params['direct_mail_encoding'])) { + $dmail['sys_dmail']['NEW']['encoding'] = $this->params['direct_mail_encoding']; + } + + if ($dmail['sys_dmail']['NEW']['pid'] && $dmail['sys_dmail']['NEW']['sendOptions']) { + /* @var $tce \TYPO3\CMS\Core\DataHandling\DataHandler */ + $tce = GeneralUtility::makeInstance(DataHandler::class); + $tce->stripslashes_values = 0; + $tce->start($dmail, []); + $tce->process_datamap(); + $this->sys_dmail_uid = $tce->substNEWwithIDs['NEW']; + + $row = BackendUtility::getRecord('sys_dmail', intval($this->sys_dmail_uid)); + // link in the mail + $message = '' . $indata['message'] . ''; + if (trim($this->params['use_rdct'])) { + $message = DirectMailUtility::substUrlsInPlainText( + $message, + $this->params['long_link_mode']?'all':'76', + DirectMailUtility::getUrlBase((int)$this->params['pid']) + ); + } + if ($indata['breakLines']) { + $message = wordwrap($message, 76, "\n"); + } + // fetch functions + $theOutput = $this->compileQuickMail($row, $message); + // end fetch function + } else { + if (!$dmail['sys_dmail']['NEW']['sendOptions']) { + $this->error = 'no_valid_url'; + } + } + + return $theOutput; + } } \ No newline at end of file diff --git a/Classes/Module/MainController.php b/Classes/Module/MainController.php index ef237df9f..24cce1cd9 100644 --- a/Classes/Module/MainController.php +++ b/Classes/Module/MainController.php @@ -79,6 +79,7 @@ protected function init(ServerRequestInterface $request): void { // get the config from pageTS $this->params = BackendUtility::getPagesTSconfig($this->id)['mod.']['web_modules.']['dmail.'] ?? []; + $this->implodedParams = DirectMailUtility::implodeTSParams($this->params); if ($this->params['userTable'] ?? false && isset($GLOBALS['TCA'][$this->params['userTable']]) && is_array($GLOBALS['TCA'][$this->params['userTable']])) { $this->userTable = $this->params['userTable']; From e8acf807eb3f3ef663a39e2521be69dcb15cdef2 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sun, 19 Dec 2021 15:17:45 +0000 Subject: [PATCH 056/342] fix --- Classes/DirectMailUtility.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/DirectMailUtility.php b/Classes/DirectMailUtility.php index e50d32b6e..efb9bd962 100644 --- a/Classes/DirectMailUtility.php +++ b/Classes/DirectMailUtility.php @@ -1580,7 +1580,7 @@ public static function updatePagesTSconfig($id, array $pageTs, $tsConfPrefix, $i foreach ($pageTs as $f => $v) { $v = trim($v); $f = $tsConfPrefix . $f; - $tempF = isset($impParams[$f]) ? trim($tempF) : ''; + $tempF = isset($impParams[$f]) ? trim($impParams[$f]) : ''; if (strcmp($tempF, $v)) { $set[$f] = $v; } From a1d0d37cac8edc9d7609d0520617029959097321 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sun, 19 Dec 2021 15:33:40 +0000 Subject: [PATCH 057/342] update DmailController --- Classes/Module/DmailController.php | 76 ++++++++++++++++++++++++++---- 1 file changed, 66 insertions(+), 10 deletions(-) diff --git a/Classes/Module/DmailController.php b/Classes/Module/DmailController.php index 310830544..48384410a 100644 --- a/Classes/Module/DmailController.php +++ b/Classes/Module/DmailController.php @@ -10,6 +10,7 @@ use TYPO3\CMS\Core\Core\Environment; use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction; +use TYPO3\CMS\Core\DataHandling\DataHandler; use TYPO3\CMS\Core\Http\HtmlResponse; use TYPO3\CMS\Core\Imaging\Icon; use TYPO3\CMS\Core\Messaging\FlashMessage; @@ -889,12 +890,12 @@ protected function makeListDMail($boxId, $totalBox, $open=false) foreach ($res as $row) { $tblLines[] = [ - $this->iconFactory->getIconForRecord('sys_dmail', $row, Icon::SIZE_SMALL)->render(), + $this->moduleTemplate->getIconFactory()->getIconForRecord('sys_dmail', $row, Icon::SIZE_SMALL)->render(), $this->linkDMail_record($row['subject'], $row['uid']), BackendUtility::date($row['tstamp']), ($row['issent'] ? $this->getLanguageService()->getLL('dmail_yes') : $this->getLanguageService()->getLL('dmail_no')), ($row['renderedsize'] ? GeneralUtility::formatSize($row['renderedsize']) : ''), - ($row['attachment'] ? $this->iconFactory->getIcon('directmail-attachment', Icon::SIZE_SMALL) : ''), + ($row['attachment'] ? $this->moduleTemplate->getIconFactory()->getIcon('directmail-attachment', Icon::SIZE_SMALL) : ''), ($row['type'] & 0x1 ? $this->getLanguageService()->getLL('nl_l_tUrl') : $this->getLanguageService()->getLL('nl_l_tPage')) . ($row['type'] & 0x2 ? ' (' . $this->getLanguageService()->getLL('nl_l_tDraft') . ')' : ''), $this->deleteLink($row['uid']) ]; @@ -927,14 +928,14 @@ protected function createDMail_quick(array $indata) $dmail['sys_dmail']['NEW'] = [ 'from_email' => $indata['senderEmail'], 'from_name' => $indata['senderName'], - 'replyto_email' => $this->params['replyto_email'], - 'replyto_name' => $this->params['replyto_name'], - 'return_path' => $this->params['return_path'], + 'replyto_email' => $this->params['replyto_email'] ?? '', + 'replyto_name' => $this->params['replyto_name'] ?? '', + 'return_path' => $this->params['return_path'] ?? '', 'priority' => (int) $this->params['priority'], 'use_rdct' => (int) $this->params['use_rdct'], 'long_link_mode' => (int) $this->params['long_link_mode'], - 'organisation' => $this->params['organisation'], - 'authcode_fieldList'=> $this->params['authcode_fieldList'], + 'organisation' => $this->params['organisation'] ?? '', + 'authcode_fieldList'=> $this->params['authcode_fieldList'] ?? '', 'plainParams' => '' ]; @@ -971,11 +972,11 @@ protected function createDMail_quick(array $indata) if (trim($this->params['use_rdct'])) { $message = DirectMailUtility::substUrlsInPlainText( $message, - $this->params['long_link_mode']?'all':'76', + $this->params['long_link_mode'] ? 'all' : '76', DirectMailUtility::getUrlBase((int)$this->params['pid']) - ); + ); } - if ($indata['breakLines']) { + if ($indata['breakLines'] ?? false) { $message = wordwrap($message, 76, "\n"); } // fetch functions @@ -989,4 +990,59 @@ protected function createDMail_quick(array $indata) return $theOutput; } + + /** + * Wrap a string as a link + * + * @param string $str String to be linked + * @param int $uid UID of the directmail record + * + * @return string the link + * @throws RouteNotFoundException If the named route doesn't exist + */ + protected function linkDMail_record($str, $uid) + { + /** @var UriBuilder $uriBuilder */ + $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); + $moduleUrl = $uriBuilder->buildUriFromRoute( + $this->moduleName, + [ + 'id' => $this->id, + 'sys_dmail_uid' => $uid, + 'fetchAtOnce' => 1, + 'cmd' => 'info' + ] + ); + return '' . htmlspecialchars($str) . ''; + } + + /** + * Create delete link with trash icon + * + * @param int $uid Uid of the record + * + * @return string link with the trash icon + * @throws RouteNotFoundException If the named route doesn't exist + */ + protected function deleteLink($uid) + { + $icon = $this->moduleTemplate->getIconFactory()->getIcon('actions-edit-delete', Icon::SIZE_SMALL); + $dmail = BackendUtility::getRecord('sys_dmail', $uid); + + if (!$dmail['scheduled_begin']) { + /** @var UriBuilder $uriBuilder */ + $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); + $moduleUrl = $uriBuilder->buildUriFromRoute( + $this->moduleName, + [ + 'id' => $this->id, + 'uid' => $uid, + 'CMD' => 'delete' + ] + ); + return '' . $icon . ''; + } + + return ''; + } } \ No newline at end of file From 8ce4651b2436b43de6eb1cf9739be7e1a922f346 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sun, 19 Dec 2021 16:42:01 +0000 Subject: [PATCH 058/342] update DmailController --- Classes/Dmailer.php | 15 +- Classes/Module/DmailController.php | 623 ++++++++++++++++++++++++- Resources/Private/Templates/Dmail.html | 20 +- 3 files changed, 636 insertions(+), 22 deletions(-) diff --git a/Classes/Dmailer.php b/Classes/Dmailer.php index 0028e2a88..7e4adbf61 100755 --- a/Classes/Dmailer.php +++ b/Classes/Dmailer.php @@ -187,7 +187,7 @@ public function dmailer_prepare(array $row) $this->authCode_fieldList = ($row['authcode_fieldList'] ? $row['authcode_fieldList'] : 'uid'); $this->dmailer['sectionBoundary'] = '', $bContent, 2); } - $this->flag_html = ($this->theParts['html']['content'] ? 1 : 0); + $this->flag_html = (($this->theParts['html']['content'] ?? false) ? 1 : 0); $this->flag_plain = ($this->theParts['plain']['content'] ? 1 : 0); $this->includeMedia = $row['includeMedia']; } @@ -234,7 +237,6 @@ public function removeHTMLComments($content) return preg_replace('/\/\*theParts['html']['content']) { + if ($this->theParts['html']['content'] ?? false) { $this->theParts['html']['content'] = $this->encodeMsg($this->dmailer_getBoundaryParts($this->dmailer['boundaryParts_html'], -1)); } else { $this->theParts['html']['content'] = ''; } - if ($this->theParts['plain']['content']) { + if ($this->theParts['plain']['content'] ?? false) { $this->theParts['plain']['content'] = $this->encodeMsg($this->dmailer_getBoundaryParts($this->dmailer['boundaryParts_plain'], -1)); } else { $this->theParts['plain']['content'] = ''; @@ -417,6 +419,7 @@ public function dmailer_getBoundaryParts($cArray, $userCategories) foreach ($cArray as $bKey => $cP) { $key = substr($cP[0], 1); $isSubscribed = false; + $cP['mediaList'] = $cP['mediaList'] ?? ''; if (!$key || (intval($userCategories) == -1)) { $returnVal .= $cP[1]; $this->mediaList .= $cP['mediaList']; @@ -1146,7 +1149,7 @@ public function addPlain($content) */ public function substHTTPurlsInPlainText($content) { - if (!$this->jumperURL_prefix) { + if (!isset($this->jumperURL_prefix) || !$this->jumperURL_prefix) { return $content; } diff --git a/Classes/Module/DmailController.php b/Classes/Module/DmailController.php index 48384410a..81b1cef9f 100644 --- a/Classes/Module/DmailController.php +++ b/Classes/Module/DmailController.php @@ -1,6 +1,8 @@ currentCMD = (string)($parsedBody['currentCMD'] ?? $queryParams['currentCMD'] ?? ''); // Create DirectMail and fetch the data $this->fetchAtOnce = (bool)($parsedBody['fetchAtOnce'] ?? $queryParams['fetchAtOnce'] ?? false); + + $this->quickmail = $parsedBody['quickmail'] ?? $queryParams['quickmail'] ?? []; } public function indexAction(ServerRequestInterface $request) : ResponseInterface @@ -101,9 +106,7 @@ public function indexAction(ServerRequestInterface $request) : ResponseInterface $this->moduleTemplate->getPageRenderer()->addJsInlineCode($currentModule, $this->getJS($this->sys_dmail_uid)); $markers = $this->moduleContent(); $formcontent = $markers['CONTENT']; - - $formcontent = '
'.$formcontent.'
'; - + $this->view->assignMultiple( [ 'wizardsteps' => $markers['WIZARDSTEPS'], @@ -283,7 +286,7 @@ protected function moduleContent() // greyed out next-button if fetching is not successful (on error) $fetchError = true; - $quickmail = GeneralUtility::_GP('quickmail'); //@TODO + $quickmail = $this->quickmail; $createMailFromInternalPage = intval(GeneralUtility::_GP('createMailFrom_UID')); $createMailFromExternalUrl = GeneralUtility::_GP('createMailFrom_URL'); @@ -573,7 +576,7 @@ protected function getNewsletterTabIcon($expand = false) * @return string HTML * @throws RouteNotFoundException If the named route doesn't exist */ - public function cmd_news() + protected function cmd_news() { // Here the list of subpages, news, is rendered @@ -1037,7 +1040,7 @@ protected function deleteLink($uid) [ 'id' => $this->id, 'uid' => $uid, - 'CMD' => 'delete' + 'cmd' => 'delete' ] ); return '' . $icon . ''; @@ -1045,4 +1048,610 @@ protected function deleteLink($uid) return ''; } + + /** + * Delete existing dmail record + * + * @param int $uid record uid to be deleted + * + * @return void + */ + protected function deleteDMail($uid) + { + $table = 'sys_dmail'; + if ($GLOBALS['TCA'][$table]['ctrl']['delete']) { + + $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); + $connection = $connectionPool->getConnectionForTable($table); + + $connection->update( + $table, // table + [ $GLOBALS['TCA'][$table]['ctrl']['delete'] => 1 ], + [ 'uid' => $uid ] // where + ); + } + + return; + } + + /** + * Compiling the quickmail content and save to DB + * + * @param array $row The sys_dmail record + * @param string $message Body of the mail + * + * @return string + * @TODO: remove htmlmail, compiling mail + */ + protected function compileQuickMail(array $row, $message) + { + $errorMsg = ''; + $warningMsg = ''; + + // Compile the mail + /* @var $htmlmail Dmailer */ + $htmlmail = GeneralUtility::makeInstance(Dmailer::class); + $htmlmail->nonCron = 1; + $htmlmail->start(); + $htmlmail->charset = $row['charset']; + $htmlmail->addPlain($message); + + if (!$message || !$htmlmail->theParts['plain']['content']) { + $errorMsg .= ' ' . $this->getLanguageService()->getLL('dmail_no_plain_content') . ''; + } elseif (!strstr(base64_decode($htmlmail->theParts['plain']['content']), ' + +
+ +
+
+ +
+
- - -
@@ -44,208 +98,198 @@

- - - - - - + + +

+ +
+ + +

+ +
+ + +

+ +
+ + +

+ +
+ + +

+ +
+ + +

+ +
+ + +

+ + + + + +
+
- + + +

+ + + + + +
+ + +
+
+ +
+ + +
+
+ +
+
- + + +

+ +
+ + +

+ +
+
- + + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+
- + + +

+
+ +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
+ + +
+ +
+
- - \ No newline at end of file + + +

+ +
+ + +
+ +
+ + +

+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ +
+ +
+ +
From 740e9c3f0b883cf63e6d14aba6fc2d9aaa025849 Mon Sep 17 00:00:00 2001 From: Dmitry Dulepov Date: Wed, 26 Jan 2022 15:58:24 +0200 Subject: [PATCH 157/342] [BUGFIX] SSFGizmo/direct_mail#8: Html markup instead of delete icon in the mailengine status module --- Classes/Module/MailerEngineController.php | 38 +++++++------------ .../Private/Language/locallang_mod2-6.xlf | 2 +- Resources/Private/Templates/MailerEngine.html | 10 ++++- 3 files changed, 22 insertions(+), 28 deletions(-) diff --git a/Classes/Module/MailerEngineController.php b/Classes/Module/MailerEngineController.php index f3290bb63..6251af0dc 100644 --- a/Classes/Module/MailerEngineController.php +++ b/Classes/Module/MailerEngineController.php @@ -67,7 +67,9 @@ public function indexAction(ServerRequestInterface $request) : ResponseInterface [ 'cronMonitor' => $cronMonitor, 'data' => $mailerEngine['data'], + 'id' => $this->id, 'invoke' => $mailerEngine['invoke'], + 'moduleName' => $this->moduleName, 'moduleUrl' => $mailerEngine['moduleUrl'], 'show' => true ] @@ -225,21 +227,22 @@ public function mailerengine() if(is_array($rows)) { foreach($rows as $row) { $data[] = [ + 'uid' => $row['uid'], 'icon' => $this->iconFactory->getIconForRecord('sys_dmail', $row, Icon::SIZE_SMALL)->render(), 'subject' => $this->linkDMail_record(htmlspecialchars(GeneralUtility::fixed_lgd_cs($row['subject'], 100)), $row['uid']), 'scheduled' => BackendUtility::datetime($row['scheduled']), 'scheduled_begin' => $row['scheduled_begin'] ? BackendUtility::datetime($row['scheduled_begin']) : '', 'scheduled_end' => $row['scheduled_end'] ? BackendUtility::datetime($row['scheduled_end']) : '', 'sent' => $this->getSysDmailMaillogsCountres($row['uid']), - 'delete' => $this->deleteLink($row['uid']) + 'delete' => $this->canDelete($row['uid']) ]; } } unset($rows); - + return ['invoke' => $invoke, 'moduleUrl' => $moduleUrl, 'data' => $data]; } - + private function getSysDmailMaillogsCountres(int $uid): int { $countres = GeneralUtility::makeInstance(SysDmailMaillogRepository::class)->countSysDmailMaillogs($uid); @@ -253,36 +256,21 @@ private function getSysDmailMaillogsCountres(int $uid): int return $count; } - + /** - * Create delete link with trash icon + * Checks if the record can be deleted * * @param int $uid Uid of the record - * - * @return string Link with the trash icon - * @throws RouteNotFoundException If the named route doesn't exist + * @return bool */ - public function deleteLink($uid) + public function canDelete($uid) { $dmail = BackendUtility::getRecord('sys_dmail', $uid); - + // show delete icon if newsletter hasn't been sent, or not yet finished sending - if (!($dmail['scheduled_begin']) || - ($dmail['scheduled_begin'] && $dmail['scheduled_end'] === 0)) { - $moduleUrl = $this->buildUriFromRoute( - $this->moduleName, - [ - 'id' => $this->id, - 'uid' => $uid, - 'cmd' => 'delete' - ] - ); - $icon = $this->iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL); - return '' . $icon . ''; - } - return ''; + return ($dmail['scheduled_begin'] === 0 || $dmail['scheduled_end'] === 0); } - + /** * Delete existing dmail record * diff --git a/Resources/Private/Language/locallang_mod2-6.xlf b/Resources/Private/Language/locallang_mod2-6.xlf index 70ac339a9..4e69eeed2 100644 --- a/Resources/Private/Language/locallang_mod2-6.xlf +++ b/Resources/Private/Language/locallang_mod2-6.xlf @@ -214,7 +214,7 @@ Current time: - delete + Delete Delivery begun diff --git a/Resources/Private/Templates/MailerEngine.html b/Resources/Private/Templates/MailerEngine.html index 7affa439c..354ba0f57 100644 --- a/Resources/Private/Templates/MailerEngine.html +++ b/Resources/Private/Templates/MailerEngine.html @@ -35,10 +35,16 @@

{row.scheduled_begin} {row.scheduled_end} {row.sent} - {row.delete} + + + + + + + -
\ No newline at end of file + From cdce79f239f6710479fc23ac42ca814c776bdc2d Mon Sep 17 00:00:00 2001 From: Dmitry Dulepov Date: Wed, 26 Jan 2022 16:00:32 +0200 Subject: [PATCH 158/342] [FEATURE] SSFGizmo/direct_mail#8: Use TYPO3 panels in the mail preparation module --- Classes/Module/DmailController.php | 192 +++++++++++++++-------------- 1 file changed, 101 insertions(+), 91 deletions(-) diff --git a/Classes/Module/DmailController.php b/Classes/Module/DmailController.php index b2fba5b55..a11d0ecfe 100644 --- a/Classes/Module/DmailController.php +++ b/Classes/Module/DmailController.php @@ -121,7 +121,6 @@ public function indexAction(ServerRequestInterface $request) : ResponseInterface if ($module == 'dmail') { // Direct mail module if (($this->pageinfo['doktype'] ?? 0) == 254) { - $this->pageRenderer->addJsInlineCode($currentModule, $this->getJS($this->sys_dmail_uid)); $markers = $this->moduleContent(); $formcontent = $markers['CONTENT']; @@ -439,26 +438,21 @@ protected function moduleContent() if (!isset($tsconfig['tx_directmail.']['defaultTab'])) { $tsconfig['tx_directmail.']['defaultTab'] = 'dmail'; } - - $i = 1; - $countTabs = count($showTabs); + foreach ($showTabs as $showTab) { - $open = false; - if ($tsconfig['tx_directmail.']['defaultTab'] == $showTab) { - $open = true; - } + $open = ($tsconfig['tx_directmail.']['defaultTab'] == $showTab); switch ($showTab) { case 'int': - $theOutput .= $this->makeFormInternal('box-' . $i, $countTabs, $open); + $theOutput .= $this->makeFormInternal($open); break; case 'ext': - $theOutput .= $this->makeFormExternal('box-' . $i, $countTabs, $open); + $theOutput .= $this->makeFormExternal($open); break; case 'quick': - $theOutput .= $this->makeFormQuickMail('box-' . $i, $countTabs, $open); + $theOutput .= $this->makeFormQuickMail($open); break; case 'dmail': - $theOutput .= $this->makeListDMail('box-' . $i, $countTabs, $open); + $theOutput .= $this->makeListDMail($open); break; default: } @@ -490,27 +484,58 @@ protected function showSteps($totalSteps) return '
' . $content . '
'; } - + + /** + * Makes expandable section using TYPO3-typical markup. + * + * @param int $sectionId + * @param string $title + * @param string $content + * @return string + */ + protected function makeSection(string $title, string $content, bool $isOpen): string + { + static $sectionId = 1; + + return sprintf( + '
+ +
+
+ %3$s +
+
+
+ ', + $sectionId++, + $this->getLanguageService()->getLL($title), + $content + ); + } + /** * Makes box for internal page. (first step) * - * @param string $boxId ID name for the HTML element - * @param int $totalBox Total of all boxes * @param bool $open State of the box * * @return string HTML with list of internal pages */ - protected function makeFormInternal($boxId, $totalBox, $open = false) + protected function makeFormInternal($open) { - $imgSrc = $this->getNewsletterTabIcon($open); - $output = '
'; - $output .= $this->cmd_news(); - $output .= '
'; - return $output; + return $this->makeSection( + 'dmail_wiz1_internal_page', + $this->cmd_news(), + $open + ); } - + /** * The icon for the source tab * @@ -722,22 +747,16 @@ protected function getAvailablePageLanguages($pageUid) /** * Make input form for external URL (first step) * - * @param string $boxId ID name for the HTML element - * @param int $totalBox Total of the boxes * @param bool $open State of the box * * @return string HTML input form for inputing the external page information */ - protected function makeFormExternal($boxId, $totalBox, $open = false) + protected function makeFormExternal($open) { - $imgSrc = $this->getNewsletterTabIcon($open); - - $output = '
'; - - // Create - $out = $this->getLanguageService()->getLL('dmail_HTML_url') . '
+ $content = '

' . $this->getLanguageService()->getLL('dmail_dovsk_crFromUrl') . + BackendUtility::cshItem($this->cshTable, 'create_directmail_from_url', $GLOBALS['BACK_PATH'] ?? '') . + '

' . + $this->getLanguageService()->getLL('dmail_HTML_url') . '

' . $this->getLanguageService()->getLL('dmail_plaintext_url') . '

' . @@ -745,35 +764,32 @@ protected function makeFormExternal($boxId, $totalBox, $open = false) '
' . (($this->error == 'no_valid_url')?('
' . $this->getLanguageService()->getLL('dmail_no_valid_url') . '

'):'') . ' - '; - $output .= '

' . $this->getLanguageService()->getLL('dmail_dovsk_crFromUrl') . BackendUtility::cshItem($this->cshTable, 'create_directmail_from_url', $GLOBALS['BACK_PATH'] ?? '') . '

'; - $output .= $out; - $output .= '
'; - return $output; + ' + ; + + return $this->makeSection( + 'dmail_wiz1_external_page', + $content, + $open + ); } - + /** * Makes input form for the quickmail (first step) * - * @param string $boxId ID name for the HTML element - * @param int $totalBox Total of the boxes * @param bool $open State of the box * * @return string HTML input form for the quickmail */ - protected function makeFormQuickMail($boxId, $totalBox, $open = false) + protected function makeFormQuickMail($open) { - $imgSrc = $this->getNewsletterTabIcon($open); - - $output = '
'; - $output .= '

' . $this->getLanguageService()->getLL('dmail_wiz1_quickmail_header') . '

'; - $output .= $this->cmd_quickmail(); - $output .= '
'; - return $output; + return $this->makeSection( + 'dmail_wiz1_quickmail', + $this->cmd_quickmail(), + $open + ); } - + /** * Show the quickmail input form (first step) * @@ -803,13 +819,11 @@ protected function cmd_quickmail() /** * List all direct mail, which have not been sent (first step) * - * @param string $boxId ID name for the HTML element - * @param int $totalBox Total of the boxes * @param bool $open State of the box * * @return string HTML lists of all existing dmail records */ - protected function makeListDMail($boxId, $totalBox, $open=false) + protected function makeListDMail($open = false) { $sOrder = preg_replace( '/^(?:ORDER[[:space:]]*BY[[:space:]]*)+/i', '', @@ -837,43 +851,39 @@ protected function makeListDMail($boxId, $totalBox, $open=false) ->orderBy($sOrder,$ascDesc) ->execute() ->fetchAll(); - - $tblLines = []; + + $tblLines = []; + $tblLines[] = [ + '', + $this->getLanguageService()->getLL('nl_l_subject'), + $this->getLanguageService()->getLL('nl_l_lastM'), + $this->getLanguageService()->getLL('nl_l_sent'), + $this->getLanguageService()->getLL('nl_l_size'), + $this->getLanguageService()->getLL('nl_l_attach'), + $this->getLanguageService()->getLL('nl_l_type'), + '' + ]; + + foreach ($res as $row) { $tblLines[] = [ - '', - $this->getLanguageService()->getLL('nl_l_subject'), - $this->getLanguageService()->getLL('nl_l_lastM'), - $this->getLanguageService()->getLL('nl_l_sent'), - $this->getLanguageService()->getLL('nl_l_size'), - $this->getLanguageService()->getLL('nl_l_attach'), - $this->getLanguageService()->getLL('nl_l_type'), - '' + $this->iconFactory->getIconForRecord('sys_dmail', $row, Icon::SIZE_SMALL)->render(), + $this->linkDMail_record($row['subject'], $row['uid']), + BackendUtility::date($row['tstamp']), + ($row['issent'] ? $this->getLanguageService()->getLL('dmail_yes') : $this->getLanguageService()->getLL('dmail_no')), + ($row['renderedsize'] ? GeneralUtility::formatSize($row['renderedsize']) : ''), + ($row['attachment'] ? $this->iconFactory->getIcon('directmail-attachment', Icon::SIZE_SMALL) : ''), + ($row['type'] & 0x1 ? $this->getLanguageService()->getLL('nl_l_tUrl') : $this->getLanguageService()->getLL('nl_l_tPage')) . ($row['type'] & 0x2 ? ' (' . $this->getLanguageService()->getLL('nl_l_tDraft') . ')' : ''), + $this->deleteLink($row['uid']) ]; - - foreach ($res as $row) { - $tblLines[] = [ - $this->iconFactory->getIconForRecord('sys_dmail', $row, Icon::SIZE_SMALL)->render(), - $this->linkDMail_record($row['subject'], $row['uid']), - BackendUtility::date($row['tstamp']), - ($row['issent'] ? $this->getLanguageService()->getLL('dmail_yes') : $this->getLanguageService()->getLL('dmail_no')), - ($row['renderedsize'] ? GeneralUtility::formatSize($row['renderedsize']) : ''), - ($row['attachment'] ? $this->iconFactory->getIcon('directmail-attachment', Icon::SIZE_SMALL) : ''), - ($row['type'] & 0x1 ? $this->getLanguageService()->getLL('nl_l_tUrl') : $this->getLanguageService()->getLL('nl_l_tPage')) . ($row['type'] & 0x2 ? ' (' . $this->getLanguageService()->getLL('nl_l_tDraft') . ')' : ''), - $this->deleteLink($row['uid']) - ]; - } - - $imgSrc = $this->getNewsletterTabIcon($open); - - $output = ''; - return $output; + } + + return $this->makeSection( + 'dmail_wiz1_list_dmail', + DirectMailUtility::formatTable($tblLines, [], 1, [1, 1, 1, 0, 0, 1, 0, 1]), + $open + ); } - + /** * Creates a directmail entry in th DB. * used only for quickmail. From 5d828e8362ebe0889979ad0f8ed571f69a2de154 Mon Sep 17 00:00:00 2001 From: Dmitry Dulepov Date: Wed, 26 Jan 2022 16:12:51 +0200 Subject: [PATCH 159/342] [FEATURE] SSFGizmo/direct_mail#8: use full width boxes --- Resources/Public/StyleSheets/modules.css | 1 - 1 file changed, 1 deletion(-) diff --git a/Resources/Public/StyleSheets/modules.css b/Resources/Public/StyleSheets/modules.css index 80bce328f..38c6ff73c 100644 --- a/Resources/Public/StyleSheets/modules.css +++ b/Resources/Public/StyleSheets/modules.css @@ -30,7 +30,6 @@ div.toggleTitle a img { background: #ffffff; border: 1px solid #aaaaaa; padding: 1em; - width: 70%; } From e6d56e1c7c87ad3740f562de9b2bccead099b028 Mon Sep 17 00:00:00 2001 From: Dmitry Dulepov Date: Wed, 26 Jan 2022 16:13:36 +0200 Subject: [PATCH 160/342] [FEATURE] SSFGizmo/direct_mail#8: upper case back/next buttons --- Resources/Private/Language/locallang_mod2-6.xlf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Resources/Private/Language/locallang_mod2-6.xlf b/Resources/Private/Language/locallang_mod2-6.xlf index 4e69eeed2..62b2b8d9b 100644 --- a/Resources/Private/Language/locallang_mod2-6.xlf +++ b/Resources/Private/Language/locallang_mod2-6.xlf @@ -358,10 +358,10 @@ Mass Send - back + Back - next + Next [write subject] From 59db4b33ee78969837a612a383d5b5daeffd9ddc Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sat, 29 Jan 2022 12:31:49 +0000 Subject: [PATCH 161/342] remove inline js from ConfigurationController --- Classes/Module/ConfigurationController.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Classes/Module/ConfigurationController.php b/Classes/Module/ConfigurationController.php index be03a6c63..05aef1526 100644 --- a/Classes/Module/ConfigurationController.php +++ b/Classes/Module/ConfigurationController.php @@ -32,7 +32,6 @@ public function indexAction(ServerRequestInterface $request) : ResponseInterface if ($module == 'dmail') { // Direct mail module if (($this->pageinfo['doktype'] ?? 0) == 254) { - $this->pageRenderer->addJsInlineCode($currentModule, $this->getJS($this->sys_dmail_uid)); $this->setDefaultValues(); $this->view->assignMultiple([ 'implodedParams' => $this->implodedParams From 9cef9bf4221471542a3bb688773ee4165974188b Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sat, 29 Jan 2022 12:45:56 +0000 Subject: [PATCH 162/342] fix:Warning: Undefined variable --- Classes/Module/DmailController.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Classes/Module/DmailController.php b/Classes/Module/DmailController.php index a11d0ecfe..6737a3f7c 100644 --- a/Classes/Module/DmailController.php +++ b/Classes/Module/DmailController.php @@ -456,7 +456,6 @@ protected function moduleContent() break; default: } - $i++; } $theOutput .= ''; } From 1b9b98aa80f2669a18ea829d4aa73d7e3aeeb371 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sat, 29 Jan 2022 13:55:51 +0000 Subject: [PATCH 163/342] update Recipient part --- Classes/Module/RecipientListController.php | 30 ++++++++++--------- .../Private/Templates/RecipientList.html | 9 ++++++ 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/Classes/Module/RecipientListController.php b/Classes/Module/RecipientListController.php index dfd5af161..243dc34ca 100644 --- a/Classes/Module/RecipientListController.php +++ b/Classes/Module/RecipientListController.php @@ -109,7 +109,9 @@ protected function moduleContent() break; case 'displayMailGroup': $result = $this->cmd_compileMailGroup($this->group_uid); - $theOutput = $this->cmd_displayMailGroup($result); + $temp = $this->displayMailGroup($result); + $theOutput = $temp['out']; + $data = $temp['data']; $type = 2; break; case 'displayImport': @@ -258,7 +260,7 @@ protected function cmd_compileMailGroup(int $groupUid) break; case 1: // List of mails - if ($mailGroup['csv']==1) { + if ($mailGroup['csv'] == 1) { $recipients = DirectMailUtility::rearrangeCsvValues(DirectMailUtility::getCsvValues($mailGroup['list']), $this->fieldList); } else { $recipients = DirectMailUtility::rearrangePlainMails(array_unique(preg_split('|[[:space:],;]+|', $mailGroup['list']))); @@ -402,7 +404,7 @@ protected function linkRecip_record($str, $uid) * * @return string list of all recipient (HTML) */ - protected function cmd_displayMailGroup($result) + protected function displayMailGroup($result) { $totalRecipients = 0; $idLists = $result['queryInfo']['id_lists']; @@ -421,15 +423,15 @@ protected function cmd_displayMailGroup($result) $group = BackendUtility::getRecord('sys_dmail_group', $this->group_uid); $group = is_array($group) ? $group : []; - $out = $this->iconFactory->getIconForRecord('sys_dmail_group', $group, Icon::SIZE_SMALL) . htmlspecialchars($group['title'] ?? ''); - $mainC = $this->getLanguageService()->getLL('mailgroup_recip_number') . ' ' . $totalRecipients . ''; - if (!$this->lCmd) { - $mainC.= '

' . $this->getLanguageService()->getLL('mailgroup_list_all') . ''; + $data = []; + $data['group_icon'] = $this->iconFactory->getIconForRecord('sys_dmail_group', $group, Icon::SIZE_SMALL); + $data['group_title'] = htmlspecialchars($group['title'] ?? ''); + $data['group_totalRecipients'] = $totalRecipients; + $data['group_link_listall'] = ''; + if ($this->lCmd == '') { + $data['group_link_listall'] = GeneralUtility::linkThisScript(['lCmd'=>'listall']); } - - $theOutput = '

' . $this->getLanguageService()->getLL('mailgroup_recip_from') . ' ' . $out . '

' . $mainC; - $theOutput .= '
'; // do the CSV export $csvValue = $this->csv; @@ -452,7 +454,7 @@ protected function cmd_displayMailGroup($result) } } } - + $theOutput = ''; switch ($this->lCmd) { case 'listall': if (is_array($idLists['tt_address'] ?? false)) { @@ -511,7 +513,7 @@ protected function cmd_displayMailGroup($result) } } } - return $theOutput; + return ['out' => $theOutput, 'data' => $data]; } /** @@ -650,7 +652,7 @@ protected function cmd_displayUserInfo() if (GeneralUtility::_GP('submit')) { $indata = GeneralUtility::_GP('indata'); if (!$indata) { - $indata['html']= 0; + $indata['html'] = 0; } } @@ -659,7 +661,7 @@ protected function cmd_displayUserInfo() // see fe_users case 'fe_users': if (is_array($indata)) { - $data=[]; + $data = []; if (is_array($indata['categories'])) { reset($indata['categories']); foreach ($indata['categories'] as $recValues) { diff --git a/Resources/Private/Templates/RecipientList.html b/Resources/Private/Templates/RecipientList.html index 67062715e..17fda38a9 100644 --- a/Resources/Private/Templates/RecipientList.html +++ b/Resources/Private/Templates/RecipientList.html @@ -7,6 +7,15 @@

+ +

{data.group_icon} {data.group_title}

+ {data.group_totalRecipients} + +

+
+
+ +

From a0fa49ed7d69e6b7b97ee3773afb641c929ce85b Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sat, 29 Jan 2022 15:37:22 +0000 Subject: [PATCH 164/342] update Recipient part --- Classes/Module/RecipientListController.php | 80 ++++++++++--------- .../Private/Templates/RecipientList.html | 11 ++- 2 files changed, 52 insertions(+), 39 deletions(-) diff --git a/Classes/Module/RecipientListController.php b/Classes/Module/RecipientListController.php index 243dc34ca..e42a3857b 100644 --- a/Classes/Module/RecipientListController.php +++ b/Classes/Module/RecipientListController.php @@ -424,14 +424,18 @@ protected function displayMailGroup($result) $group = BackendUtility::getRecord('sys_dmail_group', $this->group_uid); $group = is_array($group) ? $group : []; - $data = []; - $data['group_icon'] = $this->iconFactory->getIconForRecord('sys_dmail_group', $group, Icon::SIZE_SMALL); - $data['group_title'] = htmlspecialchars($group['title'] ?? ''); - $data['group_totalRecipients'] = $totalRecipients; - $data['group_link_listall'] = ''; - if ($this->lCmd == '') { - $data['group_link_listall'] = GeneralUtility::linkThisScript(['lCmd'=>'listall']); - } + $data = [ + 'group_icon' => $this->iconFactory->getIconForRecord('sys_dmail_group', $group, Icon::SIZE_SMALL), + 'group_title' => htmlspecialchars($group['title'] ?? ''), + 'group_totalRecipients' => $totalRecipients, + 'group_link_listall' => ($this->lCmd == '') ? GeneralUtility::linkThisScript(['lCmd'=>'listall']) : '', + 'title_table' => '', + 'table_custom' => '', + 'title_recip' => '', + 'recip_counter' => 0, + 'mailgroup_download_link' => '', + 'recip_list' => '' + ]; // do the CSV export $csvValue = $this->csv; @@ -441,7 +445,10 @@ protected function displayMailGroup($result) } elseif (GeneralUtility::inList('tt_address,fe_users,' . $this->userTable, $csvValue)) { if($this->getBackendUser()->check('tables_select', $csvValue)) { - $this->downloadCSV(DirectMailUtility::fetchRecordsListValues($idLists[$csvValue], $csvValue, (($csvValue == 'fe_users') ? str_replace('phone', 'telephone', $this->fieldList) : $this->fieldList) . ',tstamp')); + $this->downloadCSV(DirectMailUtility::fetchRecordsListValues($idLists[$csvValue], $csvValue, (($csvValue == 'fe_users') + ? str_replace('phone', 'telephone', $this->fieldList) + : $this->fieldList) . ',tstamp') + ); } else { $message = $this->createFlashMessage( @@ -458,58 +465,55 @@ protected function displayMailGroup($result) switch ($this->lCmd) { case 'listall': if (is_array($idLists['tt_address'] ?? false)) { - $theOutput.= '

' . $this->getLanguageService()->getLL('mailgroup_table_address') . '

' . - DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address', $this->id); - $theOutput.= '
'; + $data['title_table'] = 'mailgroup_table_address'; + $data['recip_list'] = DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address', $this->id); } if (is_array($idLists['fe_users'] ?? false)) { - $theOutput.= '

' . $this->getLanguageService()->getLL('mailgroup_table_fe_users') .'

' . - DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users', $this->id); - $theOutput.= '
'; + $data['title_table'] = 'mailgroup_table_fe_users'; + $data['recip_list'] = DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users', $this->id); } if (is_array($idLists['PLAINLIST'] ?? false)) { - $theOutput.= '

' . $this->getLanguageService()->getLL('mailgroup_plain_list') .'

' . - DirectMailUtility::getRecordList($idLists['PLAINLIST'], 'sys_dmail_group', $this->id); - $theOutput.= '
'; + $data['title_table'] = 'mailgroup_plain_list'; + $data['recip_list'] = DirectMailUtility::getRecordList($idLists['PLAINLIST'], 'sys_dmail_group', $this->id); } if (is_array($idLists[$this->userTable] ?? false)) { - $theOutput.= '

' . $this->getLanguageService()->getLL('mailgroup_table_custom') . ' ' . $this->userTable . '

' . - DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists[$this->userTable], $this->userTable), $this->userTable, $this->id); + $data['title_table'] = 'mailgroup_table_custom'; + $data['table_custom'] = ' '.$this->userTable; + $data['recip_list'] = DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists[$this->userTable], $this->userTable), $this->userTable, $this->id); } break; default: - if (is_array($idLists['tt_address'] ?? false) && count($idLists['tt_address'])) { - $recipContent = $this->getLanguageService()->getLL('mailgroup_recip_number') . ' ' . count($idLists['tt_address']) . - '
' . $this->getLanguageService()->getLL('mailgroup_download') . ''; - $theOutput .= '

' . $this->getLanguageService()->getLL('mailgroup_table_address') .'

' . $recipContent; - $theOutput .= '
'; + $data['title_table'] = 'mailgroup_table_address'; + $data['title_recip'] = 'mailgroup_recip_number'; + $data['recip_counter'] = ' ' . count($idLists['tt_address']); + $data['mailgroup_download_link'] = GeneralUtility::linkThisScript(['csv'=>'tt_address']); } if (is_array($idLists['fe_users'] ?? false) && count($idLists['fe_users'])) { - $recipContent = $this->getLanguageService()->getLL('mailgroup_recip_number') . ' ' . count($idLists['fe_users']) . - '
' . $this->getLanguageService()->getLL('mailgroup_download') . ''; - $theOutput .= '

' . $this->getLanguageService()->getLL('mailgroup_table_fe_users') . '

' . $recipContent; - $theOutput .= '
'; + $data['title_table'] = 'mailgroup_table_fe_users'; + $data['title_recip'] = 'mailgroup_recip_number'; + $data['recip_counter'] = ' ' . count($idLists['fe_users']); + $data['mailgroup_download_link'] = GeneralUtility::linkThisScript(['csv'=>'fe_users']); } if (is_array($idLists['PLAINLIST'] ?? false) && count($idLists['PLAINLIST'])) { - $recipContent = $this->getLanguageService()->getLL('mailgroup_recip_number') . ' ' . count($idLists['PLAINLIST']) . - '
' . $this->getLanguageService()->getLL('mailgroup_download') . ''; - $theOutput .= '

' . $this->getLanguageService()->getLL('mailgroup_plain_list') .'

' . $recipContent; - $theOutput .= '
'; + $data['title_table'] = 'mailgroup_plain_list'; + $data['title_recip'] = 'mailgroup_recip_number'; + $data['recip_counter'] = ' ' . count($idLists['PLAINLIST']); + $data['mailgroup_download_link'] = GeneralUtility::linkThisScript(['csv'=>'PLAINLIST']); } if (is_array($idLists[$this->userTable] ?? false) && count($idLists[$this->userTable])) { - $recipContent = $this->getLanguageService()->getLL('mailgroup_recip_number') . ' ' . count($idLists[$this->userTable]) . - '
' . $this->getLanguageService()->getLL('mailgroup_download') . ''; - $theOutput .= '

' . $this->getLanguageService()->getLL('mailgroup_table_custom') . '

' . $recipContent; - $theOutput .= '
'; + $data['title_table'] = 'mailgroup_table_custom'; + $data['title_recip'] = 'mailgroup_recip_number'; + $data['recip_counter'] = ' ' . count($idLists[$this->userTable]); + $data['mailgroup_download_link'] = GeneralUtility::linkThisScript(['csv' => $this->userTable]); } if (($group['type'] ?? false) == 3) { if ($this->getBackendUser()->check('tables_modify', 'sys_dmail_group')) { - $theOutput .= $this->cmd_specialQuery($group); + $theOutput = $this->cmd_specialQuery($group); } } } diff --git a/Resources/Private/Templates/RecipientList.html b/Resources/Private/Templates/RecipientList.html index 17fda38a9..40c2893e8 100644 --- a/Resources/Private/Templates/RecipientList.html +++ b/Resources/Private/Templates/RecipientList.html @@ -14,7 +14,16 @@

{data.group_i

- + +

{data.table_custom}

+
+
+ + {data.recip_counter} +
+ +
+ {data.recip_list}

From 1686258ace13b1373a24d8ebd21df14e829cdf3d Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sat, 29 Jan 2022 17:45:47 +0000 Subject: [PATCH 165/342] update Recipient part --- Classes/Module/RecipientListController.php | 76 +++++++++++-------- .../Private/Templates/RecipientList.html | 22 +++--- 2 files changed, 58 insertions(+), 40 deletions(-) diff --git a/Classes/Module/RecipientListController.php b/Classes/Module/RecipientListController.php index e42a3857b..65a7302ce 100644 --- a/Classes/Module/RecipientListController.php +++ b/Classes/Module/RecipientListController.php @@ -429,12 +429,7 @@ protected function displayMailGroup($result) 'group_title' => htmlspecialchars($group['title'] ?? ''), 'group_totalRecipients' => $totalRecipients, 'group_link_listall' => ($this->lCmd == '') ? GeneralUtility::linkThisScript(['lCmd'=>'listall']) : '', - 'title_table' => '', - 'table_custom' => '', - 'title_recip' => '', - 'recip_counter' => 0, - 'mailgroup_download_link' => '', - 'recip_list' => '' + 'tables' => [] ]; // do the CSV export @@ -465,50 +460,69 @@ protected function displayMailGroup($result) switch ($this->lCmd) { case 'listall': if (is_array($idLists['tt_address'] ?? false)) { - $data['title_table'] = 'mailgroup_table_address'; - $data['recip_list'] = DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address', $this->id); + $data['tables'][] = [ + 'title_table' => 'mailgroup_table_address', + 'recip_list' => DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address', $this->id), + 'table_custom' => '' + ]; } if (is_array($idLists['fe_users'] ?? false)) { - $data['title_table'] = 'mailgroup_table_fe_users'; - $data['recip_list'] = DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users', $this->id); + $data['tables'][] = [ + 'title_table' => 'mailgroup_table_fe_users', + 'recip_list' => DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users', $this->id), + 'table_custom' => '' + ]; } if (is_array($idLists['PLAINLIST'] ?? false)) { - $data['title_table'] = 'mailgroup_plain_list'; - $data['recip_list'] = DirectMailUtility::getRecordList($idLists['PLAINLIST'], 'sys_dmail_group', $this->id); + $data['tables'][] = [ + 'title_table' => 'mailgroup_plain_list', + 'recip_list' => DirectMailUtility::getRecordList($idLists['PLAINLIST'], 'sys_dmail_group', $this->id), + 'table_custom' => '' + ]; } if (is_array($idLists[$this->userTable] ?? false)) { - $data['title_table'] = 'mailgroup_table_custom'; - $data['table_custom'] = ' '.$this->userTable; - $data['recip_list'] = DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists[$this->userTable], $this->userTable), $this->userTable, $this->id); + $data['tables'][] = [ + 'title_table' => 'mailgroup_table_custom', + 'recip_list' => DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists[$this->userTable], $this->userTable), $this->userTable, $this->id), + 'table_custom' => ' '.$this->userTable + ]; } break; default: if (is_array($idLists['tt_address'] ?? false) && count($idLists['tt_address'])) { - $data['title_table'] = 'mailgroup_table_address'; - $data['title_recip'] = 'mailgroup_recip_number'; - $data['recip_counter'] = ' ' . count($idLists['tt_address']); - $data['mailgroup_download_link'] = GeneralUtility::linkThisScript(['csv'=>'tt_address']); + $data['tables'][] = [ + 'title_table' => 'mailgroup_table_address', + 'title_recip' => 'mailgroup_recip_number', + 'recip_counter' => ' ' . count($idLists['tt_address']), + 'mailgroup_download_link' => GeneralUtility::linkThisScript(['csv'=>'tt_address']) + ]; } if (is_array($idLists['fe_users'] ?? false) && count($idLists['fe_users'])) { - $data['title_table'] = 'mailgroup_table_fe_users'; - $data['title_recip'] = 'mailgroup_recip_number'; - $data['recip_counter'] = ' ' . count($idLists['fe_users']); - $data['mailgroup_download_link'] = GeneralUtility::linkThisScript(['csv'=>'fe_users']); + $data['tables'][] = [ + 'title_table' => 'mailgroup_table_fe_users', + 'title_recip' => 'mailgroup_recip_number', + 'recip_counter' => ' ' . count($idLists['fe_users']), + 'mailgroup_download_link' => GeneralUtility::linkThisScript(['csv'=>'fe_users']) + ]; } if (is_array($idLists['PLAINLIST'] ?? false) && count($idLists['PLAINLIST'])) { - $data['title_table'] = 'mailgroup_plain_list'; - $data['title_recip'] = 'mailgroup_recip_number'; - $data['recip_counter'] = ' ' . count($idLists['PLAINLIST']); - $data['mailgroup_download_link'] = GeneralUtility::linkThisScript(['csv'=>'PLAINLIST']); + $data['tables'][] = [ + 'title_table' => 'mailgroup_plain_list', + 'title_recip' => 'mailgroup_recip_number', + 'recip_counter' => ' ' . count($idLists['PLAINLIST']), + 'mailgroup_download_link' => GeneralUtility::linkThisScript(['csv'=>'PLAINLIST']) + ]; } if (is_array($idLists[$this->userTable] ?? false) && count($idLists[$this->userTable])) { - $data['title_table'] = 'mailgroup_table_custom'; - $data['title_recip'] = 'mailgroup_recip_number'; - $data['recip_counter'] = ' ' . count($idLists[$this->userTable]); - $data['mailgroup_download_link'] = GeneralUtility::linkThisScript(['csv' => $this->userTable]); + $data['tables'][] = [ + 'title_table' => 'mailgroup_table_custom', + 'title_recip' => 'mailgroup_recip_number', + 'recip_counter' => ' ' . count($idLists[$this->userTable]), + 'mailgroup_download_link' => GeneralUtility::linkThisScript(['csv' => $this->userTable]) + ]; } if (($group['type'] ?? false) == 3) { diff --git a/Resources/Private/Templates/RecipientList.html b/Resources/Private/Templates/RecipientList.html index 40c2893e8..8d3e23d48 100644 --- a/Resources/Private/Templates/RecipientList.html +++ b/Resources/Private/Templates/RecipientList.html @@ -14,16 +14,20 @@

{data.group_i

- -

{data.table_custom}

-
-
- - {data.recip_counter} -
- + + + +

{table.table_custom}

+
+
+ + {table.recip_counter} +
+ +
+ {table.recip_list} +
- {data.recip_list}

From 8675a2232b39790069f61f41a2613f9fed13d2cb Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sat, 29 Jan 2022 20:14:42 +0000 Subject: [PATCH 166/342] update Recipient part --- Classes/MailSelect.php | 4 ++ Classes/Module/RecipientListController.php | 44 +++++++++---------- .../Private/Templates/RecipientList.html | 19 +++++++- 3 files changed, 44 insertions(+), 23 deletions(-) diff --git a/Classes/MailSelect.php b/Classes/MailSelect.php index 847c3ca04..72e18a8fd 100644 --- a/Classes/MailSelect.php +++ b/Classes/MailSelect.php @@ -14,6 +14,10 @@ * The TYPO3 project - inspiring people to share! */ +/* + * https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/11.0/Deprecation-92080-DeprecatedQueryGeneratorAndQueryView.html + */ + use TYPO3\CMS\Core\Database\QueryGenerator; /** diff --git a/Classes/Module/RecipientListController.php b/Classes/Module/RecipientListController.php index 65a7302ce..9ef44fb07 100644 --- a/Classes/Module/RecipientListController.php +++ b/Classes/Module/RecipientListController.php @@ -33,6 +33,9 @@ class RecipientListController extends MainController protected array $set = []; protected string $fieldList = 'uid,name,first_name,middle_name,last_name,title,email,phone,www,address,company,city,zip,country,fax,module_sys_dmail_category,module_sys_dmail_html'; + protected $queryGenerator; + protected $MOD_SETTINGS; + protected function initRecipientList(ServerRequestInterface $request): void { $queryParams = $request->getQueryParams(); $parsedBody = $request->getParsedBody(); @@ -41,6 +44,8 @@ protected function initRecipientList(ServerRequestInterface $request): void { $this->lCmd = $parsedBody['lCmd'] ?? $queryParams['lCmd'] ?? ''; $this->csv = $parsedBody['csv'] ?? $queryParams['csv'] ?? ''; $this->set = is_array($parsedBody['csv'] ?? '') ? $parsedBody['csv'] : (is_array($queryParams['csv'] ?? '') ? $queryParams['csv'] : []); + + $this->queryGenerator = GeneralUtility::makeInstance(MailSelect::class); } public function indexAction(ServerRequestInterface $request) : ResponseInterface @@ -109,9 +114,7 @@ protected function moduleContent() break; case 'displayMailGroup': $result = $this->cmd_compileMailGroup($this->group_uid); - $temp = $this->displayMailGroup($result); - $theOutput = $temp['out']; - $data = $temp['data']; + $data = $this->displayMailGroup($result); $type = 2; break; case 'displayImport': @@ -423,13 +426,15 @@ protected function displayMailGroup($result) $group = BackendUtility::getRecord('sys_dmail_group', $this->group_uid); $group = is_array($group) ? $group : []; - + $data = [ + 'group_id' => $this->group_uid, 'group_icon' => $this->iconFactory->getIconForRecord('sys_dmail_group', $group, Icon::SIZE_SMALL), 'group_title' => htmlspecialchars($group['title'] ?? ''), 'group_totalRecipients' => $totalRecipients, 'group_link_listall' => ($this->lCmd == '') ? GeneralUtility::linkThisScript(['lCmd'=>'listall']) : '', - 'tables' => [] + 'tables' => [], + 'special' => [] ]; // do the CSV export @@ -524,14 +529,14 @@ protected function displayMailGroup($result) 'mailgroup_download_link' => GeneralUtility::linkThisScript(['csv' => $this->userTable]) ]; } - + if (($group['type'] ?? false) == 3) { if ($this->getBackendUser()->check('tables_modify', 'sys_dmail_group')) { - $theOutput = $this->cmd_specialQuery($group); + $data['special'] = $this->specialQuery($group); } } } - return ['out' => $theOutput, 'data' => $data]; + return $data; } /** @@ -599,30 +604,25 @@ protected function update_specialQuery($mailGroup) * * @return string HTML form to make a special query */ - protected function cmd_specialQuery($mailGroup) + protected function specialQuery($mailGroup) { - $out = ''; + $special = []; + $this->queryGenerator->init('dmail_queryConfig', $this->MOD_SETTINGS['queryTable']); if ($this->MOD_SETTINGS['queryTable'] && $this->MOD_SETTINGS['queryConfig']) { $this->queryGenerator->queryConfig = $this->queryGenerator->cleanUpQueryConfig(unserialize($this->MOD_SETTINGS['queryConfig'])); $this->queryGenerator->extFieldLists['queryFields'] = 'uid'; - $out .= $this->queryGenerator->getSelectQuery(); - $out .= '
'; + $special['selected'] = $this->queryGenerator->getSelectQuery(); } - $this->queryGenerator->setFormName($this->formname); + $this->queryGenerator->setFormName('dmailform'); $this->queryGenerator->noWrap = ''; $this->queryGenerator->allowedTables = $this->allowedTables; - $tmpCode = $this->queryGenerator->makeSelectorTable($this->MOD_SETTINGS, 'table,query'); - $tmpCode .= ''; - $tmpCode .= ''; - $out .= '

' . $this->getLanguageService()->getLL('dmail_makeQuery') . '

' . $tmpCode; - - $theOutput = '
'; - $theOutput .= '

' . $this->getLanguageService()->getLL('dmail_query') . '

' . $out; - - return $theOutput; + + $special['selectTables'] = $this->queryGenerator->makeSelectorTable($this->MOD_SETTINGS, 'table,query'); + + return $special; } /** diff --git a/Resources/Private/Templates/RecipientList.html b/Resources/Private/Templates/RecipientList.html index 8d3e23d48..c10f685be 100644 --- a/Resources/Private/Templates/RecipientList.html +++ b/Resources/Private/Templates/RecipientList.html @@ -14,7 +14,7 @@

{data.group_i

- +

{table.table_custom}

@@ -28,6 +28,23 @@

{table.table_custom}

{table.recip_list}
+ +
+

+ +

+ + + + {data.special.selected} +
+
+ {data.special.selectTables} + + + +
+

From 04b82c2146f0412005600777fc6faee3d2b82738 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sat, 29 Jan 2022 22:23:20 +0000 Subject: [PATCH 167/342] update Recipient part --- Classes/Module/RecipientListController.php | 194 ++++++++---------- Classes/Module/StatisticsController.php | 7 +- .../Private/Templates/RecipientList.html | 27 +++ Resources/Private/Templates/Statistics.html | 2 +- 4 files changed, 118 insertions(+), 112 deletions(-) diff --git a/Classes/Module/RecipientListController.php b/Classes/Module/RecipientListController.php index 9ef44fb07..17a81fa3a 100644 --- a/Classes/Module/RecipientListController.php +++ b/Classes/Module/RecipientListController.php @@ -10,6 +10,7 @@ use TYPO3\CMS\Backend\Template\ModuleTemplate; use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Core\Database\ConnectionPool; +use TYPO3\CMS\Core\DataHandling\DataHandler; use TYPO3\CMS\Core\Http\HtmlResponse; use TYPO3\CMS\Core\Imaging\Icon; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -17,6 +18,8 @@ use TYPO3\CMS\Core\Utility\CsvUtility; use DirectMailTeam\DirectMail\DirectMailUtility; use DirectMailTeam\DirectMail\Repository\SysDmailGroupRepository; +use DirectMailTeam\DirectMail\Repository\FeUsersRepository; +use DirectMailTeam\DirectMail\Repository\TtAddressRepository; class RecipientListController extends MainController { @@ -36,6 +39,11 @@ class RecipientListController extends MainController protected $queryGenerator; protected $MOD_SETTINGS; + protected int $uid = 0; + protected string $table = ''; + protected array $indata = []; + private bool $submit = false; + protected function initRecipientList(ServerRequestInterface $request): void { $queryParams = $request->getQueryParams(); $parsedBody = $request->getParsedBody(); @@ -45,6 +53,11 @@ protected function initRecipientList(ServerRequestInterface $request): void { $this->csv = $parsedBody['csv'] ?? $queryParams['csv'] ?? ''; $this->set = is_array($parsedBody['csv'] ?? '') ? $parsedBody['csv'] : (is_array($queryParams['csv'] ?? '') ? $queryParams['csv'] : []); + $this->uid = (int)($parsedBody['uid'] ?? $queryParams['uid'] ?? 0); + $this->table = (string)($parsedBody['table'] ?? $queryParams['table'] ?? ''); + $this->indata = $parsedBody['indata'] ?? $queryParams['indata'] ?? []; + $this->submit = (bool)($parsedBody['submit'] ?? $queryParams['submit'] ?? false); + $this->queryGenerator = GeneralUtility::makeInstance(MailSelect::class); } @@ -109,7 +122,7 @@ protected function moduleContent() // COMMAND: switch ($this->cmd) { case 'displayUserInfo': //@TODO ??? - $theOutput = $this->cmd_displayUserInfo(); + $data = $this->displayUserInfo(); $type = 1; break; case 'displayMailGroup': @@ -659,30 +672,26 @@ protected function downloadCSV(array $idArr) * * @return string HTML showing user's info and the categories */ - protected function cmd_displayUserInfo() + protected function displayUserInfo() { - $uid = intval(GeneralUtility::_GP('uid')); - $indata = GeneralUtility::_GP('indata'); - $table = GeneralUtility::_GP('table'); - - $mmTable = $GLOBALS['TCA'][$table]['columns']['module_sys_dmail_category']['config']['MM']; - - if (GeneralUtility::_GP('submit')) { - $indata = GeneralUtility::_GP('indata'); - if (!$indata) { - $indata['html'] = 0; + if(!in_array($this->table, ['tt_address', 'fe_users'])) { + return []; + } + if ($this->submit) { + if (count($this->indata) < 1) { + $this->indata['html'] = 0; } } - switch ($table) { + switch ($this->table) { case 'tt_address': // see fe_users case 'fe_users': - if (is_array($indata)) { + if (is_array($this->indata) && count($this->indata)) { $data = []; - if (is_array($indata['categories'])) { - reset($indata['categories']); - foreach ($indata['categories'] as $recValues) { + if (is_array($this->indata['categories'] ?? false)) { + reset($this->indata['categories']); + foreach ($this->indata['categories'] as $recValues) { reset($recValues); $enabled = []; foreach ($recValues as $k => $b) { @@ -690,10 +699,10 @@ protected function cmd_displayUserInfo() $enabled[] = $k; } } - $data[$table][$uid]['module_sys_dmail_category'] = implode(',', $enabled); + $data[$this->table][$this->uid]['module_sys_dmail_category'] = implode(',', $enabled); } } - $data[$table][$uid]['module_sys_dmail_html'] = $indata['html'] ? 1 : 0; + $data[$this->table][$this->uid]['module_sys_dmail_html'] = $this->indata['html'] ? 1 : 0; /* @var $tce \TYPO3\CMS\Core\DataHandling\DataHandler*/ $tce = GeneralUtility::makeInstance(DataHandler::class); $tce->stripslashes_values = 0; @@ -704,104 +713,75 @@ protected function cmd_displayUserInfo() default: // do nothing } - - switch ($table) { - case 'tt_address': - $queryBuilder = $this->getQueryBuilder('tt_address'); - $res = $queryBuilder - ->select('tt_address.*') - ->from('tt_address') - ->leftJoin( - 'tt_address', - 'pages', - 'pages', - $queryBuilder->expr()->eq('pages.uid', $queryBuilder->quoteIdentifier('tt_address.pid')) - ) - ->add('where','tt_address.uid=' . intval($uid) . - ' AND ' . $this->perms_clause ) - ->execute() - ->fetchAll(); + $rows = []; + switch ($this->table) { + case 'tt_address': + $rows = GeneralUtility::makeInstance(TtAddressRepository::class)->selectTtAddressByUid($this->uid, $this->perms_clause); break; case 'fe_users': - $queryBuilder = $this->getQueryBuilder('fe_users'); - $res = $queryBuilder - ->select('fe_users.*') - ->from('fe_users') - ->leftJoin( - 'fe_users', - 'pages', - 'pages', - $queryBuilder->expr()->eq('pages.uid', $queryBuilder->quoteIdentifier('fe_users.pid')) - ) - ->add('where','fe_users.uid=' . intval($uid) . - ' AND ' . $this->perms_clause ) - ->execute() - ->fetchAll(); - - break; + $rows = GeneralUtility::makeInstance(FeUsersRepository::class)->selectFeUsersByUid($this->uid, $this->perms_clause); + break; default: // do nothing } $theOutput = ''; - if (is_array($res)) { - foreach($res as $row){ - $queryBuilder = $this->getQueryBuilder($mmTable); - $resCat = $queryBuilder - ->select('uid_foreign') - ->from($mmTable) - ->where($queryBuilder->expr()->eq('uid_local', $queryBuilder->createNamedParameter($row['uid']))) - ->execute() - ->fetchAll(); - - foreach ($resCat as $rowCat) { - $categoriesArray[] = $rowCat['uid_foreign']; - } - - $categories = implode($categoriesArray, ','); - - $editOnClickLink = DirectMailUtility::getEditOnClickLink([ - 'edit' => [ - $table => [ - $row['uid'] => 'edit' - ] - ], - 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI'), - ]); - - $out = ''; - $out .= $this->iconFactory->getIconForRecord($table, $row)->render() . htmlspecialchars($row['name']) . htmlspecialchars(' <' . $row['email'] . '>'); - $out .= '  ' . - $this->iconFactory->getIcon('actions-open', Icon::SIZE_SMALL) . - '' . $this->getLanguageService()->getLL('dmail_edit') . ''; - $theOutput = '

' . $this->getLanguageService()->getLL('subscriber_info') . '

' . - $out; - - $out = ''; - $outCheckBox = ''; - - $this->categories = DirectMailUtility::makeCategories($table, $row, $this->sys_language_uid); - - reset($this->categories); - foreach ($this->categories as $pKey => $pVal) { - $outCheckBox .= '' . - ' ' . htmlspecialchars($pVal) . '
'; - } - $outCheckBox .= '

'; - $outCheckBox .= $this->getLanguageService()->getLL('subscriber_profile_htmlemail') . '
'; - $out .= $outCheckBox; - - $out .= '' . - '' . - '' . - '
'; - $theOutput .= '
'; - $theOutput .= '

' . $this->getLanguageService()->getLL('subscriber_profile') . '

' . - $this->getLanguageService()->getLL('subscriber_profile_instructions') . '

' . $out; + $row = $rows[0] ?? []; + + if (is_array($row) && count($row)) { + $mmTable = $GLOBALS['TCA'][$this->table]['columns']['module_sys_dmail_category']['config']['MM']; + + $queryBuilder = $this->getQueryBuilder($mmTable); + $resCat = $queryBuilder + ->select('uid_foreign') + ->from($mmTable) + ->where($queryBuilder->expr()->eq('uid_local', $queryBuilder->createNamedParameter($row['uid']))) + ->execute() + ->fetchAll(); + + $categoriesArray = []; + foreach ($resCat as $rowCat) { + $categoriesArray[] = $rowCat['uid_foreign']; + } + + $categories = implode(',', $categoriesArray); + + $editOnClickLink = DirectMailUtility::getEditOnClickLink([ + 'edit' => [ + $this->table => [ + $row['uid'] => 'edit' + ] + ], + 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI'), + ]); + + $dataout = [ + 'icon' => $this->iconFactory->getIconForRecord($this->table, $row)->render(), + 'iconActionsOpen' => $this->iconFactory->getIcon('actions-open', Icon::SIZE_SMALL), + 'name' => htmlspecialchars($row['name']), + 'email' => htmlspecialchars($row['email']), + 'uid' => $row['uid'], + 'editOnClickLink' => $editOnClickLink, + 'categories' => [], + 'table' => $this->table, + 'thisID' => $this->uid, + 'cmd' => $this->cmd, + 'html' => $row['module_sys_dmail_html'] ? true : false + ]; + + $this->categories = DirectMailUtility::makeCategories($this->table, $row, $this->sys_language_uid); + + reset($this->categories); + foreach ($this->categories as $pKey => $pVal) { + $dataout['categories'][] = [ + 'pkey' => $pKey, + 'pVal' => htmlspecialchars($pVal), + 'checked' => GeneralUtility::inList($categories, $pKey) ? true : false + ]; } } - return $theOutput; + return $dataout; } } \ No newline at end of file diff --git a/Classes/Module/StatisticsController.php b/Classes/Module/StatisticsController.php index 0a56855c9..882b67ae3 100644 --- a/Classes/Module/StatisticsController.php +++ b/Classes/Module/StatisticsController.php @@ -12,6 +12,7 @@ use Psr\Http\Message\ServerRequestInterface; use TYPO3\CMS\Backend\Template\ModuleTemplate; use TYPO3\CMS\Backend\Utility\BackendUtility; +use TYPO3\CMS\Core\DataHandling\DataHandler; use TYPO3\CMS\Core\Http\HtmlResponse; use TYPO3\CMS\Core\Imaging\Icon; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -239,8 +240,6 @@ protected function getSentStatus(array $row): string { */ protected function displayUserInfo() { - $indata = $this->indata; - if ($this->submit) { if (count($this->indata) < 1) { $this->indata['html'] = 0; @@ -253,7 +252,7 @@ protected function displayUserInfo() case 'fe_users': if (is_array($this->indata) && count($this->indata)) { $data = []; - if (is_array($this->indata['categories'])) { + if (is_array($this->indata['categories'] ?? false)) { reset($this->indata['categories']); foreach ($this->indata['categories'] as $recValues) { $enabled = []; @@ -291,7 +290,7 @@ protected function displayUserInfo() $row = $rows[0] ?? []; - if (is_array($row)) { + if (is_array($row) && count($row)) { $categories = ''; if($GLOBALS['TCA'][$this->table] ?? false) { diff --git a/Resources/Private/Templates/RecipientList.html b/Resources/Private/Templates/RecipientList.html index c10f685be..1f90a9969 100644 --- a/Resources/Private/Templates/RecipientList.html +++ b/Resources/Private/Templates/RecipientList.html @@ -7,6 +7,33 @@

+ +

+ {data.icon} {data.name} <{data.email}> +    + + {data.iconActionsOpen} + + +
+

+ +

+ + + {cat.pVal} +
+
+

+ +
+ + + +
+ +
+

{data.group_icon} {data.group_title}

{data.group_totalRecipients} diff --git a/Resources/Private/Templates/Statistics.html b/Resources/Private/Templates/Statistics.html index 74ea666d8..e84c88c95 100644 --- a/Resources/Private/Templates/Statistics.html +++ b/Resources/Private/Templates/Statistics.html @@ -177,7 +177,7 @@



- {cat.pVal} + {cat.pVal}


From dfb8a0a97e97ebaacbb783f4ee4b1c559c5bc8d8 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sat, 29 Jan 2022 23:00:07 +0000 Subject: [PATCH 168/342] update locallang_mod2-6.xlf --- .../Private/Language/locallang_mod2-6.xlf | 694 +++++++++--------- 1 file changed, 346 insertions(+), 348 deletions(-) diff --git a/Resources/Private/Language/locallang_mod2-6.xlf b/Resources/Private/Language/locallang_mod2-6.xlf index 62b2b8d9b..a42f529c7 100644 --- a/Resources/Private/Language/locallang_mod2-6.xlf +++ b/Resources/Private/Language/locallang_mod2-6.xlf @@ -1,1048 +1,1046 @@ - - + +
Labels for the main Direct Mail module module - EXT:direct_mail/mod/locallang.xml Ivan Kartolo ivan.kartolo@gmail.com - LFEditor
- + Enter the additional URL parameters used to fetch the HTML content from a TYPO3 page. - + The specified parameters will be added to the URL used to fetch the HTML content of the direct mail from a TYPO3 page. If in doubt, leave it blank. - + Default values for mail content format - + Default values for mail content fetching options - + Default values for Direct Mails headers - + Configure direct mail module - + Default character set for direct mails built from external pages - + Specify the character set used in direct mails when they are built from external pages and character set cannot be auto-detected. - + Default encoding of direct mails - + Select the default content transfer encoding of direct mails. - + HTML only - + HTTP Password - + If mail content is protected by HTTP authentication, enter the password here. - + HTTP Username - + If mail content is protected by HTTP authentication, enter the username here. - + - + Privacy jumpurl - + Set this option, to anonymize click statistics - + Additional module options - + Options for content transfer encoding and character set - + Options for links in mail content - + Enable jump URL's: - + Check this option to enable jump URL's and the collection of click statistics. - + This configuration determines how QuickMails are handled and further sets the default value for Direct Mails. - + Enable jump URL's for mailto links: - + Check this option to enable jump URL's for mailto links. - + Enter the additional URL parameters used to fetch the plain text content from a TYPO3 page. - + The specified parameters will be added to the URL used to fetch the plain text content of the direct mail from a TYPO3 page. If in doubt, set it either to '&type=99' or, when using TemplaVoila, to '&print=1'. - + Plain text and HTML - + Plain text only - + High - + Low - + Normal - + Character set for quick mails - + Specify the character set to use when sending quick mails. - + Encoding for quick mails - + Select the content transfer encoding to use when sending quick mails. - + Frontend User Group - + If mail content is protected by Frontend user authentication, enter the user group here. - + - + List of UID numbers of test recipient lists: - + Alternatively to sending test-mails to individuals, you can choose to send to a whole list. This is the list of recipient lists UID numbers available for this action. - + List of UID numbers of test recipients (tt_address): - + Before sending mails, you should test the mail content by sending test mails to one or more test recipients. The available recipients for testing are determined by this list of UID numbers. So first, find out the UID numbers (tt_address) of the recipients you wish to use for testing, then enter them here in a comma-separated list. - + Subject for the testmail. - + This will be prepended to the test newsletter subject - + Update configuration - + Custom-defined table: - + Enter the name of a custom-defined table, with compatible columns defined, which may also be used for direct mails distribution. - + URL of HTML content: - + Cancel - + Create mail - + Create a new Direct Mail from a page - + Create a new Direct Mail from external URL - + Edit - + An error was encountered. - + Available Direct Mail folders - + Pages with HTML frames may not be fetched. - + Caution - + Please check the cronjob or cronjob is not set. - + Last run: - + OK - + Cronjob is running. - + Cron job status - + Warning - + Please check the cronjob. - + Current time: - + Delete - + Delivery begun - + Delivery ended - + Invoke Mailer Engine - + Mailer Engine Invoked! - + If TYPO3 is not configured to automatically invoke the Mailer Engine, you can invoke it by clicking here: - + Manually Invoke Engine - + # sent - + Scheduled - + Mail Engine Status - + Subject - + Make query - + Send a testmail - + Module configuration - + Categories Conversion - + QuickMail - + Direct Mail Extension - + NO - + You cannot create direct mails using pages that are hidden or access-restricted. - + Cannot edit - mail has been sent - + Cannot edit - you don't have permissions to edit Direct Mails. - + This type of page cannot be used to create direct mails. Please select a regular page. - + The HTML content does not contain any direct mail boundaries. - + The HTML content could not be fetched. - + The plain text content does not contain any direct mail boundaries. - + The plain text content could not be fetched. - + Enter at least one valid URL! - + Number of records: - + URL of plain text content: - + Query - + Send - + Subject: - + Update query - + Information on direct mail record: - + Check the following warning. - + External Pages - + Internal Pages - + Direct Mail - + Select a newsletter to continue sending: - + New Newsletter - + Quickmail - + New Quickmail - + Select newsletter source: - + Detailed Information - + Page is successfully fetched. - + Categories - + Test Mail - + Mass Send - + Back - + Next - + [write subject] - + YES - + Ending, parsetime: - + Invoked at - + Job begin - + Job end - + Job No: - + Nothing to do. - + processed... - + Sending - + mails using records from table - + sys_dmail record - + Configuration - + Direct Mail - + Mailer Engine - + Recipient Lists - + Statistics - + Download CSV file - + Recipient List - + Import CSV into 'ADDRESS' table - + Back - + Filter email dublettes from csv data. If a dublette is found, only the first entry is imported. - + Only update/import valid emails from csv data. - + Current file: - + Import is finished. - + Field encapsulation character (data fields are encapsed with...): - + First row of import file has fieldnames: - + Import settings - + Upload CSV - + Import - + All recipients receive HTML newsletter - + Categories - + Assign the following categories to all recipients: - + Add categories - + Settings - + Please select the character set of the import file: - + Field mapping - + Additional options - + Description - + Mapping error - + Please fix following error(s): - + "Email" field has to be mapped. - + No mapping is found. You have to map at least "email" field. - + Maps to ... - + Mapping - + # - + Value - + Next - + OR - + Overwrite existing file: - + Paste the CSV data: - + Ready to import - + - + Specify the field which determines the uniqueness of imported users: - + Remove all Addresses in the storage folder before importing: - + Double records found in the CSV Data: - + Do not insert/update invalid emails found in csv data: - + Insert the following records: - + Update the following records: - + Field delimiter (data fields are separated by...): - + colon [:] - + comma [,] - + semicolon [;] - + horizontal tab [TAB] - + Please select the storage folder for the imported users: - + update - + Update existing user, instead renaming the new user: - + Choose a file from your local computer: - + List all recipients - + Plain List - + Recipients from recipient list: - + Number of recipients: - + Address Table - + Custom Table - + Website User Table - + Missing permission to display data - + CSV export failed. Insufficient access right. - + Assign categories to content elements - + There are no content elements on the page. - + Create a newsletter - + Click here to create a new page that you can later send as a direct mail. - + Edit page - + ALL - + ONLY - + Attach. - + Column - + Last mod. - + Sent? - + Size - + Subject - + Draft - + PAGE - + EXT URL - + Type - + Update category settings - + There are already %s Direct Mails based on this newsletter. Are you sure you want to create another one? - + Select a newsletter - + There are no pages in the mail module. - + View page in HTML format - + View page in Text format - + Break lines to 76 char: - + Message: - + Sender Email: - + Sender Name: - + New recipient list - + Create a new recipient list? - + Amount: - + Click here to import CSV - + Select a recipient list - + Save these settings as draft (for recurring sendings) - + Recipient list: - + Send mail - recipient list - + Send to all subscribers in recipient list - + Send this as test newsletter - + Distribution time (hh:mm dd-mm-yyyy): - + Please select Direct Mail folder. - + Draft saved - + Your directmail was sent as draft and can now be used from the scheduler. - + Recipients: - + Sending mail - + Mail scheduled for distribution - + The mail was scheduled for distribution at - + The mail was sent. - + The mail was sent to %s. - + The mail was sent to %s recipients. - + CSV of returned recipients - + CSV of returned recipients with error in header - + CSV of returned recipients with bad host - + CSV of returned recipients with mailbox full - + CSV of returned recipients for unknown reason - + CSV of returned recipients with unknown recipient - + HTML: - + HTML Link # - + HTML mails viewed: - + Bad host: - + Count: - + Statistics for direct mail: - + Disable returned recipients - + Disable returned recipients with error in header - + Disable returned recipients with bad host - + Disable returned recipients with mailbox full - + Disable returned recipients for unknown reason - + Disable returned recipients with unknown recipient - + List of recipients from tt_address table: - + adresses disabled - + Email adresses of returned mails with error in header: - + Email adresses of returned mails with bad host: - + Email adresses of returned mails: - + Email adresses of returned mails with mailbox full: - + Email adresses of returned mails for unknown reason: - + Email adresses of returned mails with unknown recipient: - + Error in Header: - + General information: - + Imagelink: - + Total responses/Unique responses: - + List returned recipients - + List returned recipients with error in header - + List returned recipients with bad host - + List returned recipients with mailbox full - + List returned recipients for unknown reason - + List returned recipients with unknown recipient - + Mailbox full: - + Mails returned: - + Mails sent: - + Choose a newsletter - + Delivery begun - + Delivery ended - + Newsletter Statistics - + queuing - + Scheduled - + sending - + sent - + Status - + Subject - + # sent - + List of recipients: - + Plaintext: - + Plaintext Link # - + Reason unknown: - + Re-calculate Cached Data: - + Re-calculate cached statistics data - + Recipient unknown: - + Responses: - + Link Responses: - + Total: - + Total mails returned: - + Total responses (links clicked): - + Unique responses (links clicked): - + List of recipients from fe_users: - + website users disabled - + Subscriber Info - + Subscriber Profile - + Receive HTML based mails - + Set categories of interest for the subscriber. - + Update profile settings - + Testmail - Individual - + Select a recipient of the testmail. The mail will be generated based on the profile of the recipient you select. - + Testmail - Recipient list - + Select a recipient list for the testmail. The mails will be generated based on the profiles of the recipients in that list. - + Testmail - Simple - + A simple testmail includes all mail elements regardless of category. But any USER_fields are not substituted with data. Enter an email-address for the testmail: - + Delivery begun/ended: - + Direct Mail: - + Flowed text: - + Sender: - + Email format/attachments: - + Include media: - + Recipient total/sent: - + Reply: - + Yes - + Server URL/IP - + URL or IP of the mail server - + Port number - + Port number of the mail server - + Username - + Username to authenticate - + Password - + Password of the user - + Type of mailserver - + IMAP or POP3 - + Number of bounce mail to be processed - + Maximum number of bounce mail to be processed on one scheduler cycle - + - + No recipient groups found - + Please install PHP IMAP extension - + Path - + no access From 0cec238fa8188e4bf9307ebdd271bb4a390cee36 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sun, 30 Jan 2022 11:51:22 +0000 Subject: [PATCH 169/342] update AnalyzeBounceMail --- .../Repository/SysDmailMaillogRepository.php | 28 +++++++++++++ Classes/Scheduler/AnalyzeBounceMail.php | 40 +++++-------------- 2 files changed, 37 insertions(+), 31 deletions(-) diff --git a/Classes/Repository/SysDmailMaillogRepository.php b/Classes/Repository/SysDmailMaillogRepository.php index 1c7eedcd9..437444d04 100644 --- a/Classes/Repository/SysDmailMaillogRepository.php +++ b/Classes/Repository/SysDmailMaillogRepository.php @@ -236,4 +236,32 @@ public function findUnknownReasons(int $uid): array|bool { ->execute() ->fetchAll(); } + + public function selectForAnalyzeBounceMail(int $rid, string $rtbl, int $mid): array|bool { + $queryBuilder = $this->getQueryBuilder($this->table); + + $row = $queryBuilder + ->select('uid','email') + ->from($this->table) + ->where( + $queryBuilder->expr()->andX( + $queryBuilder->expr()->eq( + 'rid', + $queryBuilder->createNamedParameter((int)$rid, \PDO::PARAM_INT) + ), + $queryBuilder->expr()->eq( + 'rtbl', + $queryBuilder->createNamedParameter($rtbl, \PDO::PARAM_STR) + ), + $queryBuilder->expr()->eq( + 'mid', + $queryBuilder->createNamedParameter((int)$mid, \PDO::PARAM_INT) + ), + $queryBuilder->expr()->eq('response_type', 0) + ) + ) + ->setMaxResults(1) + ->execute() + ->fetchAssociative(); + } } \ No newline at end of file diff --git a/Classes/Scheduler/AnalyzeBounceMail.php b/Classes/Scheduler/AnalyzeBounceMail.php index 4d2d30c79..41cb41210 100644 --- a/Classes/Scheduler/AnalyzeBounceMail.php +++ b/Classes/Scheduler/AnalyzeBounceMail.php @@ -15,12 +15,11 @@ */ use DirectMailTeam\DirectMail\Readmail; -use Doctrine\DBAL\FetchMode; +use DirectMailTeam\DirectMail\Repository\SysDmailMaillogRepository; use Fetch\Message; use Fetch\Server; use TYPO3\CMS\Core\Database\Connection; use TYPO3\CMS\Core\Database\ConnectionPool; -use TYPO3\CMS\Core\Database\Query\QueryBuilder; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Scheduler\Task\AbstractTask; @@ -233,41 +232,16 @@ private function processBounceMail($message) // Extract text content $cp = $readMail->analyseReturnError($message->getMessageBody()); - /** @var QueryBuilder $queryBuilder */ - $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) - ->getQueryBuilderForTable('sys_dmail_maillog'); - $row = $queryBuilder - ->select('uid','email') - ->from('sys_dmail_maillog') - ->where( - $queryBuilder->expr()->andX( - $queryBuilder->expr()->eq( - 'rid', - $queryBuilder->createNamedParameter((int)$midArray['rid'], \PDO::PARAM_INT) - ), - $queryBuilder->expr()->eq( - 'rtbl', - $queryBuilder->createNamedParameter($midArray['rtbl'], \PDO::PARAM_STR) - ), - $queryBuilder->expr()->eq( - 'mid', - $queryBuilder->createNamedParameter((int)$midArray['mid'], \PDO::PARAM_INT) - ), - $queryBuilder->expr()->eq('response_type', 0) - ) - ) - ->setMaxResults(1) - ->execute() - ->fetch(FetchMode::ASSOCIATIVE); + $row = GeneralUtility::makeInstance(SysDmailMaillogRepository::class)->selectForAnalyzeBounceMail($midArray['rid'], $midArray['rtbl'], $midArray['mid']); + // only write to log table, if we found a corresponding recipient record if (!empty($row)) { /** @var Connection $connection */ - $connection = GeneralUtility::makeInstance(ConnectionPool::class) - ->getConnectionForTable('sys_dmail_maillog'); + $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('sys_dmail_maillog'); try { $midArray['email'] = $row['email']; $insertFields = [ - 'tstamp' => $GLOBALS['EXEC_TIME'], + 'tstamp' => $this->getEXEC_TIME(), 'response_type' => -127, 'mid' => (int)$midArray['mid'], 'rid' => (int)$midArray['rid'], @@ -315,4 +289,8 @@ private function connectMailServer() return false; } } + + private function getEXEC_TIME() { + return $GLOBALS['EXEC_TIME']; + } } From b5e0d01223478c68ca1e43d2c6e4701170d85fd4 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sun, 30 Jan 2022 12:36:36 +0000 Subject: [PATCH 170/342] remove fetch, update composer.json --- Classes/Scheduler/AnalyzeBounceMail.php | 2 +- Resources/Private/Php/Fetch/.coveralls.yml | 3 - Resources/Private/Php/Fetch/.gitignore | 9 - Resources/Private/Php/Fetch/.travis.yml | 24 - Resources/Private/Php/Fetch/CONTRIBUTING.md | 54 -- Resources/Private/Php/Fetch/LICENSE | 24 - Resources/Private/Php/Fetch/README.md | 67 -- Resources/Private/Php/Fetch/autoload.php | 25 - Resources/Private/Php/Fetch/composer.json | 28 - Resources/Private/Php/Fetch/phpunit.xml.dist | 27 - .../Php/Fetch/src/Fetch/Attachment.php | 234 ----- .../Private/Php/Fetch/src/Fetch/Message.php | 797 ------------------ .../Private/Php/Fetch/src/Fetch/Server.php | 515 ----------- .../Fetch/tests/Fetch/Test/AttachmentTest.php | 118 --- .../Fetch/tests/Fetch/Test/MessageTest.php | 286 ------- .../Php/Fetch/tests/Fetch/Test/ServerTest.php | 234 ----- .../Private/Php/Fetch/tests/bootstrap.php | 40 - Resources/Private/Php/Fetch/tests/runTests.sh | 17 - composer.json | 6 +- ext_emconf.php | 3 +- 20 files changed, 5 insertions(+), 2508 deletions(-) delete mode 100644 Resources/Private/Php/Fetch/.coveralls.yml delete mode 100644 Resources/Private/Php/Fetch/.gitignore delete mode 100644 Resources/Private/Php/Fetch/.travis.yml delete mode 100644 Resources/Private/Php/Fetch/CONTRIBUTING.md delete mode 100644 Resources/Private/Php/Fetch/LICENSE delete mode 100644 Resources/Private/Php/Fetch/README.md delete mode 100644 Resources/Private/Php/Fetch/autoload.php delete mode 100644 Resources/Private/Php/Fetch/composer.json delete mode 100644 Resources/Private/Php/Fetch/phpunit.xml.dist delete mode 100644 Resources/Private/Php/Fetch/src/Fetch/Attachment.php delete mode 100755 Resources/Private/Php/Fetch/src/Fetch/Message.php delete mode 100644 Resources/Private/Php/Fetch/src/Fetch/Server.php delete mode 100644 Resources/Private/Php/Fetch/tests/Fetch/Test/AttachmentTest.php delete mode 100644 Resources/Private/Php/Fetch/tests/Fetch/Test/MessageTest.php delete mode 100644 Resources/Private/Php/Fetch/tests/Fetch/Test/ServerTest.php delete mode 100644 Resources/Private/Php/Fetch/tests/bootstrap.php delete mode 100755 Resources/Private/Php/Fetch/tests/runTests.sh diff --git a/Classes/Scheduler/AnalyzeBounceMail.php b/Classes/Scheduler/AnalyzeBounceMail.php index 41cb41210..4ee9d6912 100644 --- a/Classes/Scheduler/AnalyzeBounceMail.php +++ b/Classes/Scheduler/AnalyzeBounceMail.php @@ -176,7 +176,7 @@ public function execute() // get unread mails $messages = $mailServer->search('UNSEEN', $this->maxProcessed); /** @var Message $message The message object */ - foreach ($messages as $i => $message) { + foreach ($messages as $message) { // process the mail if ($this->processBounceMail($message)) { // set delete diff --git a/Resources/Private/Php/Fetch/.coveralls.yml b/Resources/Private/Php/Fetch/.coveralls.yml deleted file mode 100644 index cbd906c6a..000000000 --- a/Resources/Private/Php/Fetch/.coveralls.yml +++ /dev/null @@ -1,3 +0,0 @@ -src_dir: src -coverage_clover: build/logs/clover.xml -json_path: build/logs/coveralls-upload.json \ No newline at end of file diff --git a/Resources/Private/Php/Fetch/.gitignore b/Resources/Private/Php/Fetch/.gitignore deleted file mode 100644 index 75ec3873b..000000000 --- a/Resources/Private/Php/Fetch/.gitignore +++ /dev/null @@ -1,9 +0,0 @@ -.vagrant -/.idea -/.settings -/.buildpath -/.project -/composer.lock -/vendor -/report -/build \ No newline at end of file diff --git a/Resources/Private/Php/Fetch/.travis.yml b/Resources/Private/Php/Fetch/.travis.yml deleted file mode 100644 index 96a7b6941..000000000 --- a/Resources/Private/Php/Fetch/.travis.yml +++ /dev/null @@ -1,24 +0,0 @@ -language: php - -php: - - 5.3 - - 5.4 - - 5.5 - - 5.6 - - hhvm - - hhvm-nightly - -before_script: - - composer self-update && composer install --dev - - vendor/tedivm/dovecottesting/SetupEnvironment.sh - -script: ./tests/runTests.sh - -after_script: - - php vendor/bin/coveralls -v - -matrix: - fast_finish: true - allow_failures: - - php: hhvm - - php: hhvm-nightly \ No newline at end of file diff --git a/Resources/Private/Php/Fetch/CONTRIBUTING.md b/Resources/Private/Php/Fetch/CONTRIBUTING.md deleted file mode 100644 index 8fe815a9d..000000000 --- a/Resources/Private/Php/Fetch/CONTRIBUTING.md +++ /dev/null @@ -1,54 +0,0 @@ -# Contributions Welcome! - -Pull Requests and Community Contributions are the bread and butter of open source software. Every contribution- from bug -reports to feature requests, typos to full new features- are greatly appreciated. - - -## Important Guidelines - -* One Item Per Pull Request or Issue. This makes it much easier to review code and merge it back in, and prevents issues - with one request from blocking another. - -* Code Coverage is extremely important, and pull requests are much more likely to be accepted if testing is also improved. - New code should be properly tested, and all tests must pass. - -* Read the LICENSE document and make sure you understand it, because your code is going to be released under it. - -* Be prepared to make revisions. Don't be discouraged if you're asked to make changes, as that is just another step - towards refining the code and getting it merged back in. - -* Remember to add the relevant documentation, particular the docblock comments. - - -## Code Styling - -This project follows the PSR standards set forth by the [PHP Framework Interop Group](http://www.php-fig.org/). - -* [PSR-0: Class and file naming conventions](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md) -* [PSR-1: Basic coding standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md) -* [PSR-2: Coding style guide](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md) - -All code most follow these standards to be accepted. The easiest way to accomplish this is to run php-cs-fixer once the -new changes are finished. The php-cs-fixer package is installed as a development dependency of this project. - - composer install --dev - vendor/bin/php-cs-fixer fix ./ --level="all" -vv - - -## Running the test suite - -First install dependencies using Composer. It's important to include the dev packages: - - composer install --dev - -The "runTests.sh" script runs the full test suite- phpunit, php-cs-fixer, as well as any environmental setup: - - tests/runTests.sh - -To call phpunit directly: - - vendor/bin/phpunit - -To call php-cs-fixer directly: - - vendor/bin/php-cs-fixer fix ./ --level="all" -vv --dry-run diff --git a/Resources/Private/Php/Fetch/LICENSE b/Resources/Private/Php/Fetch/LICENSE deleted file mode 100644 index 68caa37c6..000000000 --- a/Resources/Private/Php/Fetch/LICENSE +++ /dev/null @@ -1,24 +0,0 @@ -Copyright (c) 2009, Robert Hafner -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * Neither the name of the Stash Project nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL Robert Hafner BE LIABLE FOR ANY -DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/Resources/Private/Php/Fetch/README.md b/Resources/Private/Php/Fetch/README.md deleted file mode 100644 index b157a49c9..000000000 --- a/Resources/Private/Php/Fetch/README.md +++ /dev/null @@ -1,67 +0,0 @@ -# Fetch [![Build Status](https://travis-ci.org/tedious/Fetch.svg?branch=master)](https://travis-ci.org/tedious/Fetch) - -[![License](http://img.shields.io/packagist/l/tedivm/fetch.svg)](https://github.com/tedious/fetch/blob/master/LICENSE) -[![Latest Stable Version](http://img.shields.io/github/release/tedious/fetch.svg)](https://packagist.org/packages/tedivm/fetch) -[![Coverage Status](http://img.shields.io/coveralls/tedious/Fetch.svg)](https://coveralls.io/r/tedious/Fetch?branch=master) -[![Total Downloads](http://img.shields.io/packagist/dt/tedivm/fetch.svg)](https://packagist.org/packages/tedivm/fetch) - -Fetch is a library for reading email and attachments, primarily using the POP -and IMAP protocols. - - -## Installing - > N.b. A note on Ubuntu 14.04 (probably other Debian-based / Apt managed systems), the install of php5-imap does not enable the extension for CLI (possibly others as well), which can cause composer to report fetch requires ext-imap - ``` -sudo ln -s /etc/php5/mods-available/imap.ini /etc/php5/cli/conf.d/30-imap.ini - ``` - -### Composer - -Installing Fetch can be done through a variety of methods, although Composer is -recommended. - -Until Fetch reaches a stable API with version 1.0 it is recommended that you -review changes before even Minor updates, although bug fixes will always be -backwards compatible. - -``` -"require": { - "tedivm/fetch": "0.6.*" -} -``` - -### Pear - -Fetch is also available through Pear. - -``` -$ pear channel-discover pear.tedivm.com -$ pear install tedivm/Fetch -``` - -### Github - -Releases of Fetch are available on [Github](https://github.com/tedious/Fetch/releases). - - -## Sample Usage - -This is just a simple code to show how to access messages by using Fetch. It uses Fetch -own autoload, but it can (and should be, if applicable) replaced with the one generated -by composer. - - - $server = new \Fetch\Server('imap.example.com', 993); - $server->setAuthentication('dummy', 'dummy'); - - - $messages = $server->getMessages(); - /** @var $message \Fetch\Message */ - foreach ($messages as $message) { - echo "Subject: {$message->getSubject()}\nBody: {$message->getMessageBody()}\n"; - } - - -## License - -Fetch is licensed under the BSD License. See the LICENSE file for details. diff --git a/Resources/Private/Php/Fetch/autoload.php b/Resources/Private/Php/Fetch/autoload.php deleted file mode 100644 index 97c6b0029..000000000 --- a/Resources/Private/Php/Fetch/autoload.php +++ /dev/null @@ -1,25 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -spl_autoload_register(function ($class) { - $base = '/src/'; - - if (strpos($class, 'Fetch\Test') === 0) { - $base = '/tests/'; - } - - $file = __DIR__.$base.strtr($class, '\\', '/').'.php'; - if (file_exists($file)) { - require $file; - - return true; - } -}); diff --git a/Resources/Private/Php/Fetch/composer.json b/Resources/Private/Php/Fetch/composer.json deleted file mode 100644 index 43ca4a16f..000000000 --- a/Resources/Private/Php/Fetch/composer.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "name": "tedivm/fetch", - "description": "A PHP IMAP Library", - "keywords": ["email","imap","pop3"], - "homepage": "http://github.com/tedious/Fetch", - "type": "library", - "license": "BSD-3-Clause", - "authors": [ - { - "name": "Robert Hafner", - "email": "tedivm@tedivm.com" - } - ], - "require": { - "php": ">=5.3.0", - "ext-imap": "*" - }, - "require-dev": { - "tedivm/dovecottesting": "1.2.3", - "phpunit/phpunit": "4.2.*", - "fabpot/php-cs-fixer": "0.5.*", - "satooshi/php-coveralls": "dev-master" - - }, - "autoload": { - "psr-0": {"Fetch": "src/"} - } -} diff --git a/Resources/Private/Php/Fetch/phpunit.xml.dist b/Resources/Private/Php/Fetch/phpunit.xml.dist deleted file mode 100644 index 26aa32392..000000000 --- a/Resources/Private/Php/Fetch/phpunit.xml.dist +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - ./tests - - - - - ./src/Fetch/ - - - - - - diff --git a/Resources/Private/Php/Fetch/src/Fetch/Attachment.php b/Resources/Private/Php/Fetch/src/Fetch/Attachment.php deleted file mode 100644 index 431153f86..000000000 --- a/Resources/Private/Php/Fetch/src/Fetch/Attachment.php +++ /dev/null @@ -1,234 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Fetch; - -/** - * This library is a wrapper around the Imap library functions included in php. This class wraps around an attachment - * in a message, allowing developers to easily save or display attachments. - * - * @package Fetch - * @author Robert Hafner - */ -class Attachment -{ - - /** - * This is the structure object for the piece of the message body that the attachment is located it. - * - * @var \stdClass - */ - protected $structure; - - /** - * This is the unique identifier for the message this attachment belongs to. - * - * @var int - */ - protected $messageId; - - /** - * This is the ImapResource. - * - * @var resource - */ - protected $imapStream; - - /** - * This is the id pointing to the section of the message body that contains the attachment. - * - * @var int - */ - protected $partId; - - /** - * This is the attachments filename. - * - * @var string - */ - protected $filename; - - /** - * This is the size of the attachment. - * - * @var int - */ - protected $size; - - /** - * This stores the data of the attachment so it doesn't have to be retrieved from the server multiple times. It is - * only populated if the getData() function is called and should not be directly used. - * - * @internal - * @var array - */ - protected $data; - - /** - * This function takes in an ImapMessage, the structure object for the particular piece of the message body that the - * attachment is located at, and the identifier for that body part. As a general rule you should not be creating - * instances of this yourself, but rather should get them from an ImapMessage class. - * - * @param Message $message - * @param \stdClass $structure - * @param string $partIdentifier - */ - public function __construct(Message $message, $structure, $partIdentifier = null) - { - $this->messageId = $message->getUid(); - $this->imapStream = $message->getImapBox()->getImapStream(); - $this->structure = $structure; - - if (isset($partIdentifier)) - $this->partId = $partIdentifier; - - $parameters = Message::getParametersFromStructure($structure); - - if (isset($parameters['filename'])) { - $this->filename = imap_utf8($parameters['filename']); - } elseif (isset($parameters['name'])) { - $this->filename = imap_utf8($parameters['name']); - } - - $this->size = $structure->bytes; - - $this->mimeType = Message::typeIdToString($structure->type); - - if (isset($structure->subtype)) - $this->mimeType .= '/' . strtolower($structure->subtype); - - $this->encoding = $structure->encoding; - } - - /** - * This function returns the data of the attachment. Combined with getMimeType() it can be used to directly output - * data to a browser. - * - * @return string - */ - public function getData() - { - if (!isset($this->data)) { - $messageBody = isset($this->partId) ? - imap_fetchbody($this->imapStream, $this->messageId, $this->partId, FT_UID) - : imap_body($this->imapStream, $this->messageId, FT_UID); - - $messageBody = Message::decode($messageBody, $this->encoding); - $this->data = $messageBody; - } - - return $this->data; - } - - /** - * This returns the filename of the attachment, or false if one isn't given. - * - * @return string - */ - public function getFileName() - { - return (isset($this->filename)) ? $this->filename : false; - } - - /** - * This function returns the mimetype of the attachment. - * - * @return string - */ - public function getMimeType() - { - return $this->mimeType; - } - - /** - * This returns the size of the attachment. - * - * @return int - */ - public function getSize() - { - return $this->size; - } - - /** - * This function returns the object that contains the structure of this attachment. - * - * @return \stdClass - */ - public function getStructure() - { - return $this->structure; - } - - /** - * This function saves the attachment to the passed directory, keeping the original name of the file. - * - * @param string $path - * @return bool - */ - public function saveToDirectory($path) - { - $path = rtrim($path, '/') . '/'; - - if (is_dir($path)) - return $this->saveAs($path . $this->getFileName()); - - return false; - } - - /** - * This function saves the attachment to the exact specified location. - * - * @param string $path - * @return bool - */ - public function saveAs($path) - { - $dirname = dirname($path); - if (file_exists($path)) { - if (!is_writable($path)) { - return false; - } - } elseif (!is_dir($dirname) || !is_writable($dirname)) { - return false; - } - - if (($filePointer = fopen($path, 'w')) == false) { - return false; - } - - switch ($this->encoding) { - case 3: //base64 - $streamFilter = stream_filter_append($filePointer, 'convert.base64-decode', STREAM_FILTER_WRITE); - break; - - case 4: //quoted-printable - $streamFilter = stream_filter_append($filePointer, 'convert.quoted-printable-decode', STREAM_FILTER_WRITE); - break; - - default: - $streamFilter = null; - } - - // Fix an issue causing server to throw an error - // See: https://github.com/tedious/Fetch/issues/74 for more details - $fetch = imap_fetchbody($this->imapStream, $this->messageId, $this->partId ?: 1, FT_UID); - $result = imap_savebody($this->imapStream, $filePointer, $this->messageId, $this->partId ?: 1, FT_UID); - - if ($streamFilter) { - stream_filter_remove($streamFilter); - } - - fclose($filePointer); - - return $result; - } -} diff --git a/Resources/Private/Php/Fetch/src/Fetch/Message.php b/Resources/Private/Php/Fetch/src/Fetch/Message.php deleted file mode 100755 index 8305345b3..000000000 --- a/Resources/Private/Php/Fetch/src/Fetch/Message.php +++ /dev/null @@ -1,797 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Fetch; - -/** - * This library is a wrapper around the Imap library functions included in php. This class represents a single email - * message as retrieved from the Imap. - * - * @package Fetch - * @author Robert Hafner - */ -class Message -{ - /** - * This is the connection/mailbox class that the email came from. - * - * @var Server - */ - protected $imapConnection; - - /** - * This is the unique identifier for the message. This corresponds to the imap "uid", which we use instead of the - * sequence number. - * - * @var int - */ - protected $uid; - - /** - * This is a reference to the Imap stream generated by 'imap_open'. - * - * @var resource - */ - protected $imapStream; - - /** - * This as an string which contains raw header information for the message. - * - * @var string - */ - protected $rawHeaders; - - /** - * This as an object which contains header information for the message. - * - * @var \stdClass - */ - protected $headers; - - /** - * This is an object which contains various status messages and other information about the message. - * - * @var \stdClass - */ - protected $messageOverview; - - /** - * This is an object which contains information about the structure of the message body. - * - * @var \stdClass - */ - protected $structure; - - /** - * This is an array with the index being imap flags and the value being a boolean specifying whether that flag is - * set or not. - * - * @var array - */ - protected $status = array(); - - /** - * This is an array of the various imap flags that can be set. - * - * @var string - */ - protected static $flagTypes = array(self::FLAG_RECENT, self::FLAG_FLAGGED, self::FLAG_ANSWERED, self::FLAG_DELETED, self::FLAG_SEEN, self::FLAG_DRAFT); - - /** - * This holds the plantext email message. - * - * @var string - */ - protected $plaintextMessage; - - /** - * This holds the html version of the email. - * - * @var string - */ - protected $htmlMessage; - - /** - * This is the date the email was sent. - * - * @var int - */ - protected $date; - - /** - * This is the subject of the email. - * - * @var string - */ - protected $subject; - - /** - * This is the size of the email. - * - * @var int - */ - protected $size; - - /** - * This is an array containing information about the address the email came from. - * - * @var string - */ - protected $from; - - /** - * This is an array containing information about the address the email was sent from. - * - * @var string - */ - protected $sender; - - /** - * This is an array of arrays that contains information about the addresses the email was sent to. - * - * @var array - */ - protected $to; - - /** - * This is an array of arrays that contains information about the addresses the email was cc'd to. - * - * @var array - */ - protected $cc; - - /** - * This is an array of arrays that contains information about the addresses the email was bcc'd to. - * - * @var array - */ - protected $bcc; - - /** - * This is an array of arrays that contain information about the addresses that should receive replies to the email. - * - * @var array - */ - protected $replyTo; - - /** - * This is an array of ImapAttachments retrieved from the message. - * - * @var Attachment[] - */ - protected $attachments = array(); - - /** - * Contains the mailbox that the message resides in. - * - * @var string - */ - protected $mailbox; - - /** - * This value defines the encoding we want the email message to use. - * - * @var string - */ - public static $charset = 'UTF-8'; - - /** - * This value defines the flag set for encoding if the mb_convert_encoding - * function can't be found, and in this case iconv encoding will be used. - * - * @var string - */ - public static $charsetFlag = '//TRANSLIT'; - - /** - * These constants can be used to easily access available flags - */ - const FLAG_RECENT = 'recent'; - const FLAG_FLAGGED = 'flagged'; - const FLAG_ANSWERED = 'answered'; - const FLAG_DELETED = 'deleted'; - const FLAG_SEEN = 'seen'; - const FLAG_DRAFT = 'draft'; - - /** - * This constructor takes in the uid for the message and the Imap class representing the mailbox the - * message should be opened from. This constructor should generally not be called directly, but rather retrieved - * through the apprioriate Imap functions. - * - * @param int $messageUniqueId - * @param Server $mailbox - */ - public function __construct($messageUniqueId, Server $connection) - { - $this->imapConnection = $connection; - $this->mailbox = $connection->getMailBox(); - $this->uid = $messageUniqueId; - $this->imapStream = $this->imapConnection->getImapStream(); - if($this->loadMessage() !== true) - throw new \RuntimeException('Message with ID ' . $messageUniqueId . ' not found.'); - } - - /** - * This function is called when the message class is loaded. It loads general information about the message from the - * imap server. - * - */ - protected function loadMessage() - { - - /* First load the message overview information */ - - if(!is_object($messageOverview = $this->getOverview())) - - return false; - - $this->subject = isset($messageOverview->subject) ? imap_utf8($messageOverview->subject) : null; - $this->date = strtotime($messageOverview->date); - $this->size = $messageOverview->size; - - foreach (self::$flagTypes as $flag) - $this->status[$flag] = ($messageOverview->$flag == 1); - - /* Next load in all of the header information */ - - $headers = $this->getHeaders(); - - if (isset($headers->to)) - $this->to = $this->processAddressObject($headers->to); - - if (isset($headers->cc)) - $this->cc = $this->processAddressObject($headers->cc); - - if (isset($headers->bcc)) - $this->bcc = $this->processAddressObject($headers->bcc); - - if (isset($headers->sender)) - $this->sender = $this->processAddressObject($headers->sender); - - $this->from = isset($headers->from) ? $this->processAddressObject($headers->from) : array(''); - $this->replyTo = isset($headers->reply_to) ? $this->processAddressObject($headers->reply_to) : $this->from; - - /* Finally load the structure itself */ - - $structure = $this->getStructure(); - - if (!isset($structure->parts)) { - // not multipart - $this->processStructure($structure); - } else { - // multipart - foreach ($structure->parts as $id => $part) - $this->processStructure($part, $id + 1); - } - - return true; - } - - /** - * This function returns an object containing information about the message. This output is similar to that over the - * imap_fetch_overview function, only instead of an array of message overviews only a single result is returned. The - * results are only retrieved from the server once unless passed true as a parameter. - * - * @param bool $forceReload - * @return \stdClass - */ - public function getOverview($forceReload = false) - { - if ($forceReload || !isset($this->messageOverview)) { - // returns an array, and since we just want one message we can grab the only result - $results = imap_fetch_overview($this->imapStream, $this->uid, FT_UID); - if ( sizeof($results) == 0 ) { - throw new \RuntimeException('Error fetching overview'); - } - $this->messageOverview = array_shift($results); - if ( ! isset($this->messageOverview->date)) { - $this->messageOverview->date = null; - } - } - - return $this->messageOverview; - } - - /** - * This function returns an object containing the raw headers of the message. - * - * @param bool $forceReload - * @return string - */ - public function getRawHeaders($forceReload = false) - { - if ($forceReload || !isset($this->rawHeaders)) { - // raw headers (since imap_headerinfo doesn't use the unique id) - $this->rawHeaders = imap_fetchheader($this->imapStream, $this->uid, FT_UID); - } - - return $this->rawHeaders; - } - - /** - * This function returns an object containing the headers of the message. This is done by taking the raw headers - * and running them through the imap_rfc822_parse_headers function. The results are only retrieved from the server - * once unless passed true as a parameter. - * - * @param bool $forceReload - * @return \stdClass - */ - public function getHeaders($forceReload = false) - { - if ($forceReload || !isset($this->headers)) { - // raw headers (since imap_headerinfo doesn't use the unique id) - $rawHeaders = $this->getRawHeaders(); - - // convert raw header string into a usable object - $headerObject = imap_rfc822_parse_headers($rawHeaders); - - // to keep this object as close as possible to the original header object we add the udate property - if (isset($headerObject->date)) { - $headerObject->udate = strtotime($headerObject->date); - } else { - $headerObject->date = null; - $headerObject->udate = null; - } - - $this->headers = $headerObject; - } - - return $this->headers; - } - - /** - * This function returns an object containing the structure of the message body. This is the same object thats - * returned by imap_fetchstructure. The results are only retrieved from the server once unless passed true as a - * parameter. - * - * @param bool $forceReload - * @return \stdClass - */ - public function getStructure($forceReload = false) - { - if ($forceReload || !isset($this->structure)) { - $this->structure = imap_fetchstructure($this->imapStream, $this->uid, FT_UID); - } - - return $this->structure; - } - - /** - * This function returns the message body of the email. By default it returns the plaintext version. If a plaintext - * version is requested but not present, the html version is stripped of tags and returned. If the opposite occurs, - * the plaintext version is given some html formatting and returned. If neither are present the return value will be - * false. - * - * @param bool $html Pass true to receive an html response. - * @return string|bool Returns false if no body is present. - */ - public function getMessageBody($html = false) - { - if ($html) { - if (!isset($this->htmlMessage) && isset($this->plaintextMessage)) { - $output = nl2br($this->plaintextMessage); - - return $output; - - } elseif (isset($this->htmlMessage)) { - return $this->htmlMessage; - } - } else { - if (!isset($this->plaintextMessage) && isset($this->htmlMessage)) { - $output = preg_replace('/\s*\/i', PHP_EOL, trim($this->htmlMessage) ); - $output = strip_tags($output); - - return $output; - } elseif (isset($this->plaintextMessage)) { - return $this->plaintextMessage; - } - } - - return false; - } - - /** - * This function returns the plain text body of the email or false if not present. - * @return string|bool Returns false if not present - */ - public function getPlainTextBody() - { - return isset($this->plaintextMessage) ? $this->plaintextMessage : false; - } - - /** - * This function returns the HTML body of the email or false if not present. - * @return string|bool Returns false if not present - */ - public function getHtmlBody() - { - return isset($this->htmlMessage) ? $this->htmlMessage : false; - } - - /** - * This function returns either an array of email addresses and names or, optionally, a string that can be used in - * mail headers. - * - * @param string $type Should be 'to', 'cc', 'bcc', 'from', 'sender', or 'reply-to'. - * @param bool $asString - * @return array|string|bool - */ - public function getAddresses($type, $asString = false) - { - $type = ( $type == 'reply-to' ) ? 'replyTo' : $type; - $addressTypes = array('to', 'cc', 'bcc', 'from', 'sender', 'replyTo'); - - if (!in_array($type, $addressTypes) || !isset($this->$type) || count($this->$type) < 1) - return false; - - if (!$asString) { - if ($type == 'from') - return $this->from[0]; - elseif ($type == 'sender') - return $this->sender[0]; - - return $this->$type; - } else { - $outputString = ''; - foreach ($this->$type as $address) { - if (isset($set)) - $outputString .= ', '; - if (!isset($set)) - $set = true; - - $outputString .= isset($address['name']) ? - $address['name'] . ' <' . $address['address'] . '>' - : $address['address']; - } - - return $outputString; - } - } - - /** - * This function returns the date, as a timestamp, of when the email was sent. - * - * @return int - */ - public function getDate() - { - return isset($this->date) ? $this->date : false; - } - - /** - * This returns the subject of the message. - * - * @return string - */ - public function getSubject() - { - return isset($this->subject) ? $this->subject : null; - } - - /** - * This function marks a message for deletion. It is important to note that the message will not be deleted form the - * mailbox until the Imap->expunge it run. - * - * @return bool - */ - public function delete() - { - return imap_delete($this->imapStream, $this->uid, FT_UID); - } - - /** - * This function returns Imap this message came from. - * - * @return Server - */ - public function getImapBox() - { - return $this->imapConnection; - } - - /** - * This function takes in a structure and identifier and processes that part of the message. If that portion of the - * message has its own subparts, those are recursively processed using this function. - * - * @param \stdClass $structure - * @param string $partIdentifier - */ - protected function processStructure($structure, $partIdentifier = null) - { - $parameters = self::getParametersFromStructure($structure); - - if ((isset($parameters['name']) || isset($parameters['filename'])) - || (isset($structure->subtype) && stripos($structure->subtype, 'rfc822') !== false) - ) { - $attachment = new Attachment($this, $structure, $partIdentifier); - $this->attachments[] = $attachment; - } elseif ($structure->type == 0 || $structure->type == 1) { - $messageBody = isset($partIdentifier) ? - imap_fetchbody($this->imapStream, $this->uid, $partIdentifier, FT_UID | FT_PEEK) - : imap_body($this->imapStream, $this->uid, FT_UID | FT_PEEK); - - $messageBody = self::decode($messageBody, $structure->encoding); - - if (!empty($parameters['charset']) && $parameters['charset'] !== self::$charset) { - $mb_converted = false; - if (function_exists('mb_convert_encoding')) { - if (!in_array($parameters['charset'], mb_list_encodings())) { - if ($structure->encoding === 0) { - $parameters['charset'] = 'US-ASCII'; - } else { - $parameters['charset'] = 'UTF-8'; - } - } - - $messageBody = @mb_convert_encoding($messageBody, self::$charset, $parameters['charset']); - $mb_converted = true; - } - if (!$mb_converted) { - $messageBodyConv = @iconv($parameters['charset'], self::$charset . self::$charsetFlag, $messageBody); - - if ($messageBodyConv !== false) { - $messageBody = $messageBodyConv; - } - } - } - - if ((strtolower($structure->subtype) === 'plain') || ($structure->type == 1 && strtolower($structure->subtype) !== 'alternative') || ($structure->type == 0 && strtolower($structure->subtype) == 'rfc822-headers')) { - if (isset($this->plaintextMessage)) { - $this->plaintextMessage .= PHP_EOL . PHP_EOL; - } else { - $this->plaintextMessage = ''; - } - - $this->plaintextMessage .= trim($messageBody); - } elseif (strtolower($structure->subtype) === 'html') { - if (isset($this->htmlMessage)) { - $this->htmlMessage .= '

'; - } else { - $this->htmlMessage = ''; - } - - $this->htmlMessage .= $messageBody; - } - } - - if (isset($structure->parts)) { // multipart: iterate through each part - - foreach ($structure->parts as $partIndex => $part) { - $partId = $partIndex + 1; - - if (isset($partIdentifier)) - $partId = $partIdentifier . '.' . $partId; - - $this->processStructure($part, $partId); - } - } - } - - /** - * This function takes in the message data and encoding type and returns the decoded data. - * - * @param string $data - * @param int|string $encoding - * @return string - */ - public static function decode($data, $encoding) - { - if (!is_numeric($encoding)) { - $encoding = strtolower($encoding); - } - - switch (true) { - case $encoding === 'quoted-printable': - case $encoding === 4: - return quoted_printable_decode($data); - - case $encoding === 'base64': - case $encoding === 3: - return base64_decode($data); - - default: - return $data; - } - } - - /** - * This function returns the body type that an imap integer maps to. - * - * @param int $id - * @return string - */ - public static function typeIdToString($id) - { - switch ($id) { - case 0: - return 'text'; - - case 1: - return 'multipart'; - - case 2: - return 'message'; - - case 3: - return 'application'; - - case 4: - return 'audio'; - - case 5: - return 'image'; - - case 6: - return 'video'; - - default: - case 7: - return 'other'; - } - } - - /** - * Takes in a section structure and returns its parameters as an associative array. - * - * @param \stdClass $structure - * @return array - */ - public static function getParametersFromStructure($structure) - { - $parameters = array(); - if (isset($structure->parameters)) - foreach ($structure->parameters as $parameter) - $parameters[strtolower($parameter->attribute)] = $parameter->value; - - if (isset($structure->dparameters)) - foreach ($structure->dparameters as $parameter) - $parameters[strtolower($parameter->attribute)] = $parameter->value; - - return $parameters; - } - - /** - * This function takes in an array of the address objects generated by the message headers and turns them into an - * associative array. - * - * @param array $addresses - * @return array - */ - protected function processAddressObject($addresses) - { - $outputAddresses = array(); - if (is_array($addresses)) - foreach ($addresses as $address) { - if (property_exists($address, 'mailbox') && $address->mailbox != 'undisclosed-recipients') { - $currentAddress = array(); - $currentAddress['address'] = $address->mailbox . '@' . $address->host; - if (isset($address->personal)) { - $currentAddress['name'] = $address->personal; - } - $outputAddresses[] = $currentAddress; - } - } - - return $outputAddresses; - } - - /** - * This function returns the unique id that identifies the message on the server. - * - * @return int - */ - public function getUid() - { - return $this->uid; - } - - /** - * This function returns the attachments a message contains. If a filename is passed then just that ImapAttachment - * is returned, unless - * - * @param null|string $filename - * @return array|bool|Attachment[] - */ - public function getAttachments($filename = null) - { - if (!isset($this->attachments) || count($this->attachments) < 1) - return false; - - if (!isset($filename)) - return $this->attachments; - - $results = array(); - foreach ($this->attachments as $attachment) { - if ($attachment->getFileName() == $filename) - $results[] = $attachment; - } - - switch (count($results)) { - case 0: - return false; - - case 1: - return array_shift($results); - - default: - return $results; - break; - } - } - - /** - * This function checks to see if an imap flag is set on the email message. - * - * @param string $flag Recent, Flagged, Answered, Deleted, Seen, Draft - * @return bool - */ - public function checkFlag($flag = self::FLAG_FLAGGED) - { - return (isset($this->status[$flag]) && $this->status[$flag] === true); - } - - /** - * This function is used to enable or disable one or more flags on the imap message. - * - * @param string|array $flag Flagged, Answered, Deleted, Seen, Draft - * @param bool $enable - * @throws \InvalidArgumentException - * @return bool - */ - public function setFlag($flag, $enable = true) - { - $flags = (is_array($flag)) ? $flag : array($flag); - - foreach ($flags as $i => $flag) { - $flag = ltrim(strtolower($flag), '\\'); - if (!in_array($flag, self::$flagTypes) || $flag == self::FLAG_RECENT) - throw new \InvalidArgumentException('Unable to set invalid flag "' . $flag . '"'); - - if ($enable) { - $this->status[$flag] = true; - } else { - unset($this->status[$flag]); - } - - $flags[$i] = $flag; - } - - $imapifiedFlag = '\\'.implode(' \\', array_map('ucfirst', $flags)); - - if ($enable === true) { - return imap_setflag_full($this->imapStream, $this->uid, $imapifiedFlag, ST_UID); - } else { - return imap_clearflag_full($this->imapStream, $this->uid, $imapifiedFlag, ST_UID); - } - } - - /** - * This function is used to move a mail to the given mailbox. - * - * @param $mailbox - * - * @return bool - */ - public function moveToMailBox($mailbox) - { - $currentBox = $this->imapConnection->getMailBox(); - $this->imapConnection->setMailBox($this->mailbox); - - $returnValue = imap_mail_copy($this->imapStream, $this->uid, $mailbox, CP_UID | CP_MOVE); - imap_expunge($this->imapStream); - - $this->mailbox = $mailbox; - - $this->imapConnection->setMailBox($currentBox); - - return $returnValue; - } -} diff --git a/Resources/Private/Php/Fetch/src/Fetch/Server.php b/Resources/Private/Php/Fetch/src/Fetch/Server.php deleted file mode 100644 index 32e57c1b3..000000000 --- a/Resources/Private/Php/Fetch/src/Fetch/Server.php +++ /dev/null @@ -1,515 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Fetch; - -/** - * This library is a wrapper around the Imap library functions included in php. This class in particular manages a - * connection to the server (imap, pop, etc) and allows for the easy retrieval of stored messages. - * - * @package Fetch - * @author Robert Hafner - */ -class Server -{ - /** - * When SSL isn't compiled into PHP we need to make some adjustments to prevent soul crushing annoyances. - * - * @var bool - */ - public static $sslEnable = true; - - /** - * These are the flags that depend on ssl support being compiled into imap. - * - * @var array - */ - public static $sslFlags = array('ssl', 'validate-cert', 'novalidate-cert', 'tls', 'notls'); - - /** - * This is used to prevent the class from putting up conflicting tags. Both directions- key to value, value to key- - * are checked, so if "novalidate-cert" is passed then "validate-cert" is removed, and vice-versa. - * - * @var array - */ - public static $exclusiveFlags = array('validate-cert' => 'novalidate-cert', 'tls' => 'notls'); - - /** - * This is the domain or server path the class is connecting to. - * - * @var string - */ - protected $serverPath; - - /** - * This is the name of the current mailbox the connection is using. - * - * @var string - */ - protected $mailbox = ''; - - /** - * This is the username used to connect to the server. - * - * @var string - */ - protected $username; - - /** - * This is the password used to connect to the server. - * - * @var string - */ - protected $password; - - /** - * This is an array of flags that modify how the class connects to the server. Examples include "ssl" to enforce a - * secure connection or "novalidate-cert" to allow for self-signed certificates. - * - * @link http://us.php.net/manual/en/function.imap-open.php - * @var array - */ - protected $flags = array(); - - /** - * This is the port used to connect to the server - * - * @var int - */ - protected $port; - - /** - * This is the set of options, represented by a bitmask, to be passed to the server during connection. - * - * @var int - */ - protected $options = 0; - - /** - * This is the set of connection parameters - * - * @var array - */ - protected $params = array(); - - /** - * This is the resource connection to the server. It is required by a number of imap based functions to specify how - * to connect. - * - * @var resource - */ - protected $imapStream; - - /** - * This is the name of the service currently being used. Imap is the default, although pop3 and nntp are also - * options - * - * @var string - */ - protected $service = 'imap'; - - /** - * This constructor takes the location and service thats trying to be connected to as its arguments. - * - * @param string $serverPath - * @param null|int $port - * @param null|string $service - */ - public function __construct($serverPath, $port = 143, $service = 'imap') - { - $this->serverPath = $serverPath; - - $this->port = $port; - - switch ($port) { - case 143: - $this->setFlag('novalidate-cert'); - break; - - case 993: - $this->setFlag('ssl'); - break; - } - - $this->service = $service; - } - - /** - * This function sets the username and password used to connect to the server. - * - * @param string $username - * @param string $password - * @param bool $tryFasterAuth tries to auth faster by disabling GSSAPI & NTLM auth methods (set to false if you use either of these auth methods) - */ - public function setAuthentication($username, $password, $tryFasterAuth=true) - { - $this->username = $username; - $this->password = $password; - if ($tryFasterAuth) { - $this->setParam('DISABLE_AUTHENTICATOR', array('GSSAPI','NTLM')); - } - } - - /** - * This function sets the mailbox to connect to. - * - * @param string $mailbox - * @return bool - */ - public function setMailBox($mailbox = '') - { - if (!$this->hasMailBox($mailbox)) { - return false; - } - - $this->mailbox = $mailbox; - if (isset($this->imapStream)) { - $this->setImapStream(); - } - - return true; - } - - public function getMailBox() - { - return $this->mailbox; - } - - /** - * This function sets or removes flag specifying connection behavior. In many cases the flag is just a one word - * deal, so the value attribute is not required. However, if the value parameter is passed false it will clear that - * flag. - * - * @param string $flag - * @param null|string|bool $value - */ - public function setFlag($flag, $value = null) - { - if (!self::$sslEnable && in_array($flag, self::$sslFlags)) - return; - - if (isset(self::$exclusiveFlags[$flag])) { - $kill = self::$exclusiveFlags[$flag]; - } elseif ($index = array_search($flag, self::$exclusiveFlags)) { - $kill = $index; - } - - if (isset($kill) && false !== $index = array_search($kill, $this->flags)) - unset($this->flags[$index]); - - $index = array_search($flag, $this->flags); - if (isset($value) && $value !== true) { - if ($value == false && $index !== false) { - unset($this->flags[$index]); - } elseif ($value != false) { - $match = preg_grep('/' . $flag . '/', $this->flags); - if (reset($match)) { - $this->flags[key($match)] = $flag . '=' . $value; - } else { - $this->flags[] = $flag . '=' . $value; - } - } - } elseif ($index === false) { - $this->flags[] = $flag; - } - } - - /** - * This funtion is used to set various options for connecting to the server. - * - * @param int $bitmask - * @throws \Exception - */ - public function setOptions($bitmask = 0) - { - if (!is_numeric($bitmask)) - throw new \RuntimeException('Function requires numeric argument.'); - - $this->options = $bitmask; - } - - /** - * This function is used to set connection parameters - * - * @param string $key - * @param string $value - */ - public function setParam($key, $value) - { - $this->params[$key] = $value; - } - - /** - * This function gets the current saved imap resource and returns it. - * - * @return resource - */ - public function getImapStream() - { - if (empty($this->imapStream)) - $this->setImapStream(); - - return $this->imapStream; - } - - /** - * This function takes in all of the connection date (server, port, service, flags, mailbox) and creates the string - * thats passed to the imap_open function. - * - * @return string - */ - public function getServerString() - { - $mailboxPath = $this->getServerSpecification(); - - if (isset($this->mailbox)) - $mailboxPath .= $this->mailbox; - - return $mailboxPath; - } - - /** - * Returns the server specification, without adding any mailbox. - * - * @return string - */ - protected function getServerSpecification() - { - $mailboxPath = '{' . $this->serverPath; - - if (isset($this->port)) - $mailboxPath .= ':' . $this->port; - - if ($this->service != 'imap') - $mailboxPath .= '/' . $this->service; - - foreach ($this->flags as $flag) { - $mailboxPath .= '/' . $flag; - } - - $mailboxPath .= '}'; - - return $mailboxPath; - } - - /** - * This function creates or reopens an imapStream when called. - * - */ - protected function setImapStream() - { - if (!empty($this->imapStream)) { - if (!imap_reopen($this->imapStream, $this->getServerString(), $this->options, 1)) - throw new \RuntimeException(imap_last_error()); - } else { - $imapStream = @imap_open($this->getServerString(), $this->username, $this->password, $this->options, 1, $this->params); - - if ($imapStream === false) - throw new \RuntimeException(imap_last_error()); - - $this->imapStream = $imapStream; - } - } - - /** - * This returns the number of messages that the current mailbox contains. - * - * @param string $mailbox - * @return int - */ - public function numMessages($mailbox='') - { - $cnt = 0; - if ($mailbox==='') { - $cnt = imap_num_msg($this->getImapStream()); - } elseif ($this->hasMailbox($mailbox) && $mailbox !== '') { - $oldMailbox = $this->getMailBox(); - $this->setMailbox($mailbox); - $cnt = $this->numMessages(); - $this->setMailbox($oldMailbox); - } - - return ((int) $cnt); - } - - /** - * This function returns an array of ImapMessage object for emails that fit the criteria passed. The criteria string - * should be formatted according to the imap search standard, which can be found on the php "imap_search" page or in - * section 6.4.4 of RFC 2060 - * - * @link http://us.php.net/imap_search - * @link http://www.faqs.org/rfcs/rfc2060 - * @param string $criteria - * @param null|int $limit - * @return array An array of ImapMessage objects - */ - public function search($criteria = 'ALL', $limit = null) - { - if ($results = imap_search($this->getImapStream(), $criteria, SE_UID)) { - if (isset($limit) && count($results) > $limit) - $results = array_slice($results, 0, $limit); - - $messages = array(); - - foreach ($results as $messageId) - $messages[] = new Message($messageId, $this); - - return $messages; - } else { - return array(); - } - } - - /** - * This function returns the recently received emails as an array of ImapMessage objects. - * - * @param null|int $limit - * @return array An array of ImapMessage objects for emails that were recently received by the server. - */ - public function getRecentMessages($limit = null) - { - return $this->search('Recent', $limit); - } - - /** - * Returns the emails in the current mailbox as an array of ImapMessage objects. - * - * @param null|int $limit - * @return Message[] - */ - public function getMessages($limit = null) - { - $numMessages = $this->numMessages(); - - if (isset($limit) && is_numeric($limit) && $limit < $numMessages) - $numMessages = $limit; - - if ($numMessages < 1) - return array(); - - $stream = $this->getImapStream(); - $messages = array(); - for ($i = 1; $i <= $numMessages; $i++) { - $uid = imap_uid($stream, $i); - $messages[] = new Message($uid, $this); - } - - return $messages; - } - - /** - * Returns the emails in the current mailbox as an array of ImapMessage objects - * ordered by some ordering - * - * @see http://php.net/manual/en/function.imap-sort.php - * @param int $orderBy - * @param bool $reverse - * @param int $limit - * @return Message[] - */ - public function getOrderedMessages($orderBy, $reverse, $limit) - { - $msgIds = imap_sort($this->getImapStream(), $orderBy, $reverse ? 1 : 0, SE_UID); - - return array_map(array($this, 'getMessageByUid'), array_slice($msgIds, 0, $limit)); - } - - /** - * Returns the requested email or false if it is not found. - * - * @param int $uid - * @return Message|bool - */ - public function getMessageByUid($uid) - { - try { - $message = new \Fetch\Message($uid, $this); - - return $message; - } catch (\Exception $e) { - return false; - } - } - - /** - * This function removes all of the messages flagged for deletion from the mailbox. - * - * @return bool - */ - public function expunge() - { - return imap_expunge($this->getImapStream()); - } - - /** - * Checks if the given mailbox exists. - * - * @param $mailbox - * - * @return bool - */ - public function hasMailBox($mailbox) - { - return (boolean) $this->getMailBoxDetails($mailbox); - } - - /** - * Return information about the mailbox or mailboxes - * - * @param $mailbox - * - * @return array - */ - public function getMailBoxDetails($mailbox) - { - return imap_getmailboxes( - $this->getImapStream(), - $this->getServerString(), - $this->getServerSpecification() . $mailbox - ); - } - - /** - * Creates the given mailbox. - * - * @param $mailbox - * - * @return bool - */ - public function createMailBox($mailbox) - { - return imap_createmailbox($this->getImapStream(), $this->getServerSpecification() . $mailbox); - } - - /** - * List available mailboxes - * - * @param string $pattern - * - * @return array - */ - public function listMailBoxes($pattern = '*') - { - return imap_list($this->getImapStream(), $this->getServerSpecification(), $pattern); - } - - /** - * Deletes the given mailbox. - * - * @param $mailbox - * - * @return bool - */ - public function deleteMailBox($mailbox) - { - return imap_deletemailbox($this->getImapStream(), $this->getServerSpecification() . $mailbox); - } -} diff --git a/Resources/Private/Php/Fetch/tests/Fetch/Test/AttachmentTest.php b/Resources/Private/Php/Fetch/tests/Fetch/Test/AttachmentTest.php deleted file mode 100644 index ffec66b9f..000000000 --- a/Resources/Private/Php/Fetch/tests/Fetch/Test/AttachmentTest.php +++ /dev/null @@ -1,118 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Fetch\Test; - -/** - * @package Fetch - * @author Robert Hafner - */ -class AttachmentTest extends \PHPUnit_Framework_TestCase -{ - - public static function getAttachments($MessageId) - { - $server = ServerTest::getServer(); - $message = new \Fetch\Message($MessageId, $server); - $attachments = $message->getAttachments(); - $returnAttachments = array(); - foreach($attachments as $attachment) - $returnAttachments[$attachment->getFileName()] = $attachment; - - return $returnAttachments; - } - - public function testGetData() - { - $attachments = static::getAttachments('6'); - - $attachment_RCA = $attachments['RCA_Indian_Head_test_pattern.JPG.zip']; - $md5_RCA = '3e9b6f02551590a7bcfff5d50b5b7b20'; - $this->assertEquals($md5_RCA, md5($attachment_RCA->getData())); - - $attachment_TestCard = $attachments['Test_card.png.zip']; - $md5_TestCard = '94c40bd83fbfa03b29bf1811f9aaccea'; - $this->assertEquals($md5_TestCard, md5($attachment_TestCard->getData())); - } - - public function testGetMimeType() - { - $attachments = static::getAttachments('6'); - - $attachment_RCA = $attachments['RCA_Indian_Head_test_pattern.JPG.zip']; - $mimetype_RCA = 'application/zip'; - $this->assertEquals($mimetype_RCA, $attachment_RCA->getMimeType()); - - $attachment_TestCard = $attachments['Test_card.png.zip']; - $mimetype_TestCard = 'application/zip'; - $this->assertEquals($mimetype_TestCard, $attachment_TestCard->getMimeType()); - } - - public function testGetSize() - { - $attachments = static::getAttachments('6'); - - $attachment_RCA = $attachments['RCA_Indian_Head_test_pattern.JPG.zip']; - $size_RCA = 378338; - $this->assertEquals($size_RCA, $attachment_RCA->getSize()); - - $attachment_TestCard = $attachments['Test_card.png.zip']; - $size_TestCard = 32510; - $this->assertEquals($size_TestCard, $attachment_TestCard->getSize()); - } - - public function testGetStructure() - { - $attachments = static::getAttachments('6'); - - $attachment_RCA = $attachments['RCA_Indian_Head_test_pattern.JPG.zip']; - $structure_RCA = $attachment_RCA->getStructure(); - - $this->assertObjectHasAttribute('type', $structure_RCA); - $this->assertEquals(3, $structure_RCA->type); - - $this->assertObjectHasAttribute('subtype', $structure_RCA); - $this->assertEquals('ZIP', $structure_RCA->subtype); - - $this->assertObjectHasAttribute('bytes', $structure_RCA); - $this->assertEquals(378338, $structure_RCA->bytes); - } - - public function testSaveToDirectory() - { - $attachments = static::getAttachments('6'); - - $attachment_RCA = $attachments['RCA_Indian_Head_test_pattern.JPG.zip']; - - $tmpdir = rtrim(sys_get_temp_dir(), '/') . '/'; - $filepath = $tmpdir . 'RCA_Indian_Head_test_pattern.JPG.zip'; - - $this->assertTrue($attachment_RCA->saveToDirectory($tmpdir)); - - $this->assertFileExists($filepath); - $this->assertEquals(md5(file_get_contents($filepath)), md5($attachment_RCA->getData())); - - $attachments = static::getAttachments('6'); - $attachment_RCA = $attachments['RCA_Indian_Head_test_pattern.JPG.zip']; - $this->assertFalse($attachment_RCA->saveToDirectory('/'), 'Returns false when attempting to save without filesystem permission.'); - - $attachments = static::getAttachments('6'); - $attachment_RCA = $attachments['RCA_Indian_Head_test_pattern.JPG.zip']; - $this->assertFalse($attachment_RCA->saveToDirectory($filepath), 'Returns false when attempting to save over a file.'); - } - - public static function tearDownAfterClass() - { - $tmpdir = rtrim(sys_get_temp_dir(), '/') . '/'; - $filepath = $tmpdir . 'RCA_Indian_Head_test_pattern.JPG.zip'; - unlink($filepath); - } -} diff --git a/Resources/Private/Php/Fetch/tests/Fetch/Test/MessageTest.php b/Resources/Private/Php/Fetch/tests/Fetch/Test/MessageTest.php deleted file mode 100644 index 0cb9a7637..000000000 --- a/Resources/Private/Php/Fetch/tests/Fetch/Test/MessageTest.php +++ /dev/null @@ -1,286 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Fetch\Test; -use Fetch\Message; - -/** - * @package Fetch - * @author Robert Hafner - */ -class MessageTest extends \PHPUnit_Framework_TestCase -{ - public static function getMessage($id) - { - $server = ServerTest::getServer(); - - return new \Fetch\Message($id, $server); - } - - public function testConstructMessage() - { - $message = static::getMessage(3); - $this->assertInstanceOf('\Fetch\Message', $message); - } - - public function testGetOverview() - { - $message = static::getMessage(3); - $overview = $message->getOverview(); - $this->assertEquals('Welcome', $overview->subject, 'Subject available from overview'); - $this->assertEquals('tedivm@tedivm.com', $overview->from, 'From available from overview'); - $this->assertEquals('testuser@tedivm.com', $overview->to, 'To available from overview'); - $this->assertEquals(1465, $overview->size, 'Size available from overview'); - $this->assertEquals(0, $overview->flagged, 'Flagged available from overview'); - $this->assertEquals(1, $overview->seen, 'Seen available from overview'); - } - - public function testGetHeaders() - { - $message = static::getMessage(3); - $headers = $message->getHeaders(); - $this->assertEquals('Sun, 1 Dec 2013 21:14:03 -0800 (PST)', $headers->date, 'Headers contain the right date.'); - $this->assertEquals('testuser@tedivm.com', $headers->toaddress, 'Headers contain toaddress.'); - $this->assertEquals('tedivm@tedivm.com', $headers->fromaddress, 'Headers contain fromaddress'); - } - - public function testGetStructure() - { - - } - - public function testGetMessageBody() - { - // easiest way to deal with php encoding issues is simply not to. - $plaintextTest = 'f9377a89c9c935463a2b35c92dd61042'; - $convertedHtmlTest = '11498bcf191900d634ff8772a64ca523'; - $pureHtmlTest = '6a366ddecf080199284146d991d52169'; - - $message = static::getMessage(3); - $messageNonHTML = $message->getMessageBody(); - $this->assertEquals($plaintextTest, md5($messageNonHTML), 'Message returns as plaintext.'); - - $messageHTML = $message->getMessageBody(true); - $this->assertEquals($convertedHtmlTest, md5($messageHTML), 'Message converts from plaintext to HTML when requested.'); - - $message = static::getMessage(4); - $messageHTML = $message->getMessageBody(true); - $this->assertEquals($pureHtmlTest, md5($messageHTML), 'Message returns as HTML.'); - - } - - public function testGetPlainTextBody() - { - // easiest way to deal with php encoding issues is simply not to. - $plaintextTest1 = 'f9377a89c9c935463a2b35c92dd61042'; - $plaintextTest2 = '0b8fc9b534a1789f1071f996f238a07a'; - $plaintextTest3 = 'd41d8cd98f00b204e9800998ecf8427e'; - - $message = static::getMessage(3); - $messagePlainText = $message->getPlainTextBody(); - $this->assertEquals($plaintextTest1, md5($messagePlainText), 'Message returns as plaintext.'); - - $message = static::getMessage(4); - $messagePlainText = $message->getPlainTextBody(); - $this->assertEquals($plaintextTest2, md5($messagePlainText), 'Message returns as plaintext.'); - - $message = static::getMessage(6); - $messagePlainText = $message->getPlainTextBody(); - $this->assertEquals($plaintextTest3, md5($messagePlainText), 'Message does not return as plaintext.'); - - } - - public function testGetHtmlBody() - { - // easiest way to deal with php encoding issues is simply not to. - $HtmlTest1 = 'd41d8cd98f00b204e9800998ecf8427e'; - $HtmlTest2 = '6a366ddecf080199284146d991d52169'; - - $message = static::getMessage(3); - $messageHtml = $message->getHtmlBody(); - $this->assertEquals($HtmlTest1, md5($messageHtml), 'Message does not return as HTML.'); - - $message = static::getMessage(4); - $messageHtml = $message->getHtmlBody(); - $this->assertEquals($HtmlTest2, md5($messageHtml), 'Message returns as HTML.'); - - } - - public function testGetAddresses() - { - $message = static::getMessage(3); - - $addresses = $message->getAddresses('to'); - $this->assertEquals('testuser@tedivm.com', $addresses[0]['address'], 'Retrieving to user from address array.'); - - $addressString = $message->getAddresses('to', true); - $this->assertEquals('testuser@tedivm.com', $addressString, 'Returning To address as string.'); - - $addresses = $message->getAddresses('from'); - $this->assertEquals('tedivm@tedivm.com', $addresses['address'], 'Returning From address as an address array.'); - - $addressString = $message->getAddresses('from', true); - $this->assertEquals('tedivm@tedivm.com', $addressString, 'Returning From address as string.'); - } - - public function testGetDate() - { - $message = static::getMessage(3); - $this->assertEquals(1385961243, $message->getDate(), 'Returns date as timestamp.'); - } - - public function testGetSubject() - { - $message = static::getMessage(3); - $this->assertEquals('Welcome', $message->getSubject(), 'Returns Subject.'); - } - - public function testDelete() - { - - } - - public function testGetImapBox() - { - $server = ServerTest::getServer(); - $message = new \Fetch\Message('3', $server); - $this->assertEquals($server, $message->getImapBox(), 'getImapBox returns Server used to create Message.'); - } - - public function testGetUid() - { - $message = static::getMessage('3'); - $this->assertEquals(3, $message->getUid(), 'Message returns UID'); - } - - public function testGetAttachments() - { - $messageWithoutAttachments = static::getMessage('3'); - $this->assertFalse($messageWithoutAttachments->getAttachments(), 'getAttachments returns false when no attachments present.'); - - $messageWithAttachments = static::getMessage('6'); - $attachments = $messageWithAttachments->getAttachments(); - $this->assertCount(2, $attachments); - foreach($attachments as $attachment) - $this->assertInstanceOf('\Fetch\Attachment', $attachment, 'getAttachments returns Fetch\Attachment objects.'); - - $attachment = $messageWithAttachments->getAttachments('Test_card.png.zip'); - $this->assertInstanceOf('\Fetch\Attachment', $attachment, 'getAttachment returns specified Fetch\Attachment object.'); - } - - public function testCheckFlag() - { - $message = static::getMessage('3'); - $this->assertFalse($message->checkFlag('flagged')); - $this->assertTrue($message->checkFlag('seen')); - } - - public function testSetFlag() - { - $message = static::getMessage('3'); - $this->assertFalse($message->checkFlag('answered'), 'Message is not answered.'); - - $this->assertTrue($message->setFlag('answered'), 'setFlag returned true.'); - $this->assertTrue($message->checkFlag('answered'), 'Message was successfully answered.'); - - $this->assertTrue($message->setFlag('answered', false), 'setFlag returned true.'); - $this->assertFalse($message->checkFlag('answered'), 'Message was successfully unanswered.'); - - $message = static::getMessage('2'); - $this->assertFalse($message->checkFlag('flagged'), 'Message is not flagged.'); - - $this->assertTrue($message->setFlag('flagged'), 'setFlag returned true.'); - $this->assertTrue($message->checkFlag('flagged'), 'Message was successfully flagged.'); - - $message = static::getMessage('2'); - $this->assertTrue($message->setFlag('flagged', false), 'setFlag returned true.'); - $this->assertFalse($message->checkFlag('flagged'), 'Message was successfully unflagged.'); - } - - public function testMoveToMailbox() - { - $server = ServerTest::getServer(); - - // Testing by moving message from "Test Folder" to "Sent" - - // Count Test Folder - $testFolderNumStart = $server->numMessages('Test Folder'); - $server->setMailbox('Test Folder'); - $this->assertEquals($testFolderNumStart, $server->numMessages(), 'Server presents consistent information between numMessages when mailbox set and directly queried for number of messages'); - - // Get message from Test Folder - $message = current($server->getMessages(1)); - $this->assertInstanceOf('\Fetch\Message', $message, 'Server returned Message.'); - - // Switch to Sent folder, count messages - $sentFolderNumStart = $server->numMessages('Sent'); - $server->setMailbox('Sent'); - $this->assertEquals($sentFolderNumStart, $server->numMessages(), 'Server presents consistent information between numMessages when mailbox set and directly queried for number of messages'); - - // Switch to "Flagged" folder in order to test that function properly returns to it - $this->assertTrue($server->setMailBox('Flagged Email')); - // Move the message! - $this->assertTrue($message->moveToMailBox('Sent')); - // Make sure we're still in the same folder - $this->assertEquals('Flagged Email', $server->getMailBox(), 'Returned Server back to right mailbox.'); - $this->assertAttributeEquals('Sent', 'mailbox', $message, 'Message mailbox changed to new location.'); - // Make sure Test Folder lost a message - $this->assertTrue($server->setMailBox('Test Folder')); - $this->assertEquals($testFolderNumStart - 1, $server->numMessages(), 'Message moved out of Test Folder.'); - // Make sure Sent folder gains one - $this->assertTrue($server->setMailBox('Sent')); - $this->assertEquals($sentFolderNumStart + 1, $server->numMessages(), 'Message moved into Sent Folder.'); - } - - public function testDecode() - { - $quotedPrintableDecoded = "Now's the time for all folk to come to the aid of their country."; - $quotedPrintable = <<<'ENCODE' -Now's the time = -for all folk to come= - to the aid of their country. -ENCODE; - $this->assertEquals($quotedPrintableDecoded, Message::decode($quotedPrintable, 'quoted-printable'), 'Decodes quoted printable'); - $this->assertEquals($quotedPrintableDecoded, Message::decode($quotedPrintable, 4), 'Decodes quoted printable'); - - $testString = 'This is a test string'; - $base64 = base64_encode($testString); - $this->assertEquals($testString, Message::decode($base64, 'base64'), 'Decodes quoted base64'); - $this->assertEquals($testString, Message::decode($base64, 3), 'Decodes quoted base64'); - - $notEncoded = '> w - www.somesite.com.au'; - $this->assertEquals($notEncoded, Message::decode($notEncoded, 0), 'Nothing to decode'); - } - - public function testTypeIdToString() - { - $types = array(); - $types[0] = 'text'; - $types[1] = 'multipart'; - $types[2] = 'message'; - $types[3] = 'application'; - $types[4] = 'audio'; - $types[5] = 'image'; - $types[6] = 'video'; - $types[7] = 'other'; - $types[8] = 'other'; - $types[32] = 'other'; - - foreach($types as $id => $type) - $this->assertEquals($type, Message::typeIdToString($id)); - } - - public function testGetParametersFromStructure() - { - - } - -} diff --git a/Resources/Private/Php/Fetch/tests/Fetch/Test/ServerTest.php b/Resources/Private/Php/Fetch/tests/Fetch/Test/ServerTest.php deleted file mode 100644 index a90ee7f67..000000000 --- a/Resources/Private/Php/Fetch/tests/Fetch/Test/ServerTest.php +++ /dev/null @@ -1,234 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Fetch\Test; - -use Fetch\Server; - -/** - * @package Fetch - * @author Robert Hafner - */ -class ServerTest extends \PHPUnit_Framework_TestCase -{ - public static $num_messages_inbox = 12; - - /** - * @dataProvider flagsDataProvider - * @param string $expected server string with %host% placeholder - * @param integer $port to use (needed to test behavior on port 143 and 993 from constructor) - * @param array $flags to set/unset ($flag => $value) - */ - public function testFlags($expected, $port, $flags) - { - $server = new Server(TESTING_SERVER_HOST, $port); - - foreach ($flags as $flag => $value) { - $server->setFlag($flag, $value); - } - - $this->assertEquals(str_replace('%host%', TESTING_SERVER_HOST, $expected), $server->getServerString()); - } - - public function testFlagOverwrite() - { - $server = static::getServer(); - - $server->setFlag('TestFlag', 'true'); - $this->assertAttributeContains('TestFlag=true', 'flags', $server); - - $server->setFlag('TestFlag', 'false'); - $this->assertAttributeContains('TestFlag=false', 'flags', $server); - } - - public function flagsDataProvider() - { - return array( - array('{%host%:143/novalidate-cert}', 143, array()), - array('{%host%:143/validate-cert}', 143, array('validate-cert' => true)), - array('{%host%:143}', 143, array('novalidate-cert' => false)), - array('{%host%:993/ssl}', 993, array()), - array('{%host%:993}', 993, array('ssl' => false)), - array('{%host%:100/tls}', 100, array('tls' => true)), - array('{%host%:100/tls}', 100, array('tls' => true, 'tls' => true)), - array('{%host%:100/notls}', 100, array('tls' => true, 'notls' => true)), - array('{%host%:100}', 100, array('ssl' => true, 'ssl' => false)), - array('{%host%:100/user=foo}', 100, array('user' => 'foo')), - array('{%host%:100/user=foo}', 100, array('user' => 'foo', 'user' => 'foo')), - array('{%host%:100/user=bar}', 100, array('user' => 'foo', 'user' => 'bar')), - array('{%host%:100}', 100, array('user' => 'foo', 'user' => false)), - ); - } - - /** - * @dataProvider connectionDataProvider - * @param integer $port to use (needed to test behavior on port 143 and 993 from constructor) - * @param array $flags to set/unset ($flag => $value) - * @param string $message Assertion message - */ - public function testConnection($port, $flags, $message) - { - $server = new Server(TESTING_SERVER_HOST, $port); - $server->setAuthentication(TEST_USER, TEST_PASSWORD); - - foreach ($flags as $flag => $value) { - $server->setFlag($flag, $value); - } - - $imapSteam = $server->getImapStream(); - $this->assertInternalType('resource', $imapSteam, $message); - } - - public function connectionDataProvider() - { - return array( - array(143, array(), 'Connects with default settings.'), - array(993, array('novalidate-cert' => true), 'Connects over SSL (self signed).'), - ); - } - - public function testNumMessages() - { - $server = static::getServer(); - $numMessages = $server->numMessages(); - $this->assertEquals(self::$num_messages_inbox, $numMessages); - $this->assertEquals(0, $server->numMessages( 'DOESNOTEXIST'.time() ) ); - } - - public function testGetMessages() - { - $server = static::getServer(); - $messages = $server->getMessages(5); - - $this->assertCount(5, $messages, 'Five messages returned'); - foreach ($messages as $message) { - $this->assertInstanceOf('\Fetch\Message', $message, 'Returned values are Messages'); - } - } - - public function testGetMessagesOrderedByDateAsc() - { - $server = static::getServer(); - $messages = $server->getOrderedMessages(SORTDATE, false, 2); - - $this->assertCount(2, $messages, 'Two messages returned'); - $this->assertGreaterThan($messages[0]->getDate(), $messages[1]->getDate(), 'Messages in ascending order'); - } - - public function testGetMessagesOrderedByDateDesc() - { - $server = static::getServer(); - $messages = $server->getOrderedMessages(SORTDATE, true, 2); - - $this->assertCount(2, $messages, 'Two messages returned'); - $this->assertLessThan($messages[0]->getDate(), $messages[1]->getDate(), 'Messages in descending order'); - } - - public function testGetMailBox() - { - $server = static::getServer(); - $this->assertEquals('', $server->getMailBox()); - $this->assertTrue($server->setMailBox('Sent')); - $this->assertEquals('Sent', $server->getMailBox()); - } - - public function testSetMailBox() - { - $server = static::getServer(); - - $this->assertTrue($server->setMailBox('Sent')); - $this->assertEquals('Sent', $server->getMailBox()); - - $this->assertTrue($server->setMailBox('Flagged Email')); - $this->assertEquals('Flagged Email', $server->getMailBox()); - - $this->assertFalse($server->setMailBox('Cheese')); - - $this->assertTrue($server->setMailBox('')); - $this->assertEquals('', $server->getMailBox()); - } - - public function testHasMailBox() - { - $server = static::getServer(); - - $this->assertTrue($server->hasMailBox('Sent'), 'Has mailbox "Sent"'); - $this->assertTrue($server->hasMailBox('Flagged Email'), 'Has mailbox "Flagged Email"'); - $this->assertFalse($server->hasMailBox('Cheese'), 'Does not have mailbox "Cheese"'); - } - - public function testListMailBoxes() - { - $server = static::getServer(); - $spec = sprintf('{%s:143/novalidate-cert}', TESTING_SERVER_HOST); - - $list = $server->listMailboxes('*'); - $this->assertContains($spec.'Sent', $list, 'Has mailbox "Sent"'); - $this->assertNotContains($spec.'Cheese', $list, 'Does not have mailbox "Cheese"'); - } - - public function testCreateMailbox() - { - $server = static::getServer(); - - $this->assertFalse($server->hasMailBox('Cheese'), 'Does not have mailbox "Cheese"'); - $this->assertTrue($server->createMailBox('Cheese'), 'createMailbox returns true.'); - $this->assertTrue($server->hasMailBox('Cheese'), 'Mailbox "Cheese" was created'); - } - - public function testDeleteMailbox() - { - $server = static::getServer(); - $this->assertTrue($server->hasMailBox('Cheese'), 'Does have mailbox "Cheese"'); - $this->assertTrue($server->deleteMailBox('Cheese'), 'deleteMailBox returns true.'); - $this->assertFalse($server->hasMailBox('Cheese'), 'Mailbox "Cheese" was deleted'); - } - - /** - * @expectedException \RuntimeException - */ - public function testSetOptionsException() - { - $server = static::getServer(); - $server->setOptions('purple'); - } - - public function testSetOptions() - { - $server = static::getServer(); - $server->setOptions(5); - $this->assertAttributeEquals(5, 'options', $server); - } - - public function testExpunge() - { - $server = static::getServer(); - $message = $server->getMessageByUid(12); - - $this->assertInstanceOf('\Fetch\Message', $message, 'Message exists'); - - $message->delete(); - - $this->assertInstanceOf('\Fetch\Message', $server->getMessageByUid(12), 'Message still present after being deleted but before being expunged.'); - - $server->expunge(); - - $this->assertFalse($server->getMessageByUid(12), 'Message successfully expunged'); - } - - public static function getServer() - { - $server = new Server(TESTING_SERVER_HOST, 143); - $server->setAuthentication(TEST_USER, TEST_PASSWORD); - - return $server; - } -} diff --git a/Resources/Private/Php/Fetch/tests/bootstrap.php b/Resources/Private/Php/Fetch/tests/bootstrap.php deleted file mode 100644 index c656c67fc..000000000 --- a/Resources/Private/Php/Fetch/tests/bootstrap.php +++ /dev/null @@ -1,40 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -error_reporting(-1); - -define('TESTING', true); -define('TEST_USER', 'testuser'); -define('TEST_PASSWORD', 'applesauce'); - -date_default_timezone_set('UTC'); - -if (getenv('TRAVIS')) { - define('TESTING_ENVIRONMENT', 'TRAVIS'); - define('TESTING_SERVER_HOST', '127.0.0.1'); -} else { - define('TESTING_ENVIRONMENT', 'VAGRANT'); - define('TESTING_SERVER_HOST', '172.31.1.2'); -} - -$filename = __DIR__ .'/../vendor/autoload.php'; - -if (!file_exists($filename)) { - echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" . PHP_EOL; - echo " You need to execute `composer install` before running the tests. " . PHP_EOL; - echo " Vendors are required for complete test execution. " . PHP_EOL; - echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" . PHP_EOL . PHP_EOL; - $filename = __DIR__ .'/../autoload.php'; - require_once $filename; -} else { - $loader = require $filename; - $loader->add('Fetch\\Test', __DIR__); -} diff --git a/Resources/Private/Php/Fetch/tests/runTests.sh b/Resources/Private/Php/Fetch/tests/runTests.sh deleted file mode 100755 index 0547fd730..000000000 --- a/Resources/Private/Php/Fetch/tests/runTests.sh +++ /dev/null @@ -1,17 +0,0 @@ -#/usr/bin/env/sh -set -e - -if [ ! -n "$TRAVIS" ]; then - ./vendor/tedivm/dovecottesting/SetupEnvironment.sh - sleep 5 -fi - -echo 'Running unit tests.' -./vendor/bin/phpunit --verbose --coverage-clover build/logs/clover.xml - -echo '' -echo '' -echo '' -echo 'Testing for Coding Styling Compliance.' -echo 'All code should follow PSR standards.' -./vendor/bin/php-cs-fixer fix ./ --level="all" -vv --dry-run \ No newline at end of file diff --git a/composer.json b/composer.json index 5eee0479f..df1496997 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,8 @@ }, "require": { "typo3/cms-core": "^11.5", - "friendsoftypo3/tt-address": "dev-master" + "friendsoftypo3/tt-address": "dev-master", + "tedivm/fetch": "0.7.*" }, "require-dev": { "roave/security-advisories": "dev-master" @@ -31,8 +32,7 @@ "minimum-stability": "dev", "autoload": { "psr-4": { - "DirectMailTeam\\DirectMail\\": "Classes", - "Fetch\\": "Resources/Private/Php/Fetch/src/Fetch" + "DirectMailTeam\\DirectMail\\": "Classes" } }, "replace": { diff --git a/ext_emconf.php b/ext_emconf.php index 100594c75..f72817f9c 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -27,8 +27,7 @@ ], 'autoload' => [ 'psr-4' => [ - 'DirectMailTeam\\DirectMail\\' => 'Classes/', - 'Fetch\\' => 'Resources/Private/Php/Fetch/src/Fetch/' + 'DirectMailTeam\\DirectMail\\' => 'Classes/' ] ], ]; From 9ed12b6a3b309497540d7a7d5e825e8efdc94a05 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sun, 30 Jan 2022 13:00:38 +0000 Subject: [PATCH 171/342] fix warning Undefined array key 'mid' --- Classes/Middleware/JumpurlController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Classes/Middleware/JumpurlController.php b/Classes/Middleware/JumpurlController.php index 3a5f25950..27bf6bfeb 100644 --- a/Classes/Middleware/JumpurlController.php +++ b/Classes/Middleware/JumpurlController.php @@ -216,7 +216,8 @@ public function getRawRecord($table, $uid, $fields = '*') */ protected function shouldProcess(): bool { - return ($this->request->getQueryParams()['mid'] !== null); + $mid = $this->request->getQueryParams()['mid'] ?? null; + return ($mid !== null); } /** From 7428347868a4c955d297f6d6a5575bf4bbfbc450 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sun, 30 Jan 2022 13:50:55 +0000 Subject: [PATCH 172/342] update DmailController, SysDmailRepository --- Classes/Module/DmailController.php | 16 +++------------- Classes/Repository/SysDmailRepository.php | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/Classes/Module/DmailController.php b/Classes/Module/DmailController.php index 6737a3f7c..5032d8eab 100644 --- a/Classes/Module/DmailController.php +++ b/Classes/Module/DmailController.php @@ -5,6 +5,7 @@ use DirectMailTeam\DirectMail\Dmailer; use DirectMailTeam\DirectMail\DirectMailUtility; +use DirectMailTeam\DirectMail\Repository\SysDmailRepository; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider; @@ -838,18 +839,7 @@ protected function makeListDMail($open = false) $ascDesc = 'DESC'; } } - $queryBuilder = $this->getQueryBuilder('sys_dmail'); - $queryBuilder - ->getRestrictions() - ->removeAll() - ->add(GeneralUtility::makeInstance(DeletedRestriction::class)); - $res = $queryBuilder->select('uid','pid','subject','tstamp','issent','renderedsize','attachment','type') - ->from('sys_dmail') - ->add('where','pid = ' . intval($this->id) . - ' AND scheduled=0 AND issent=0') - ->orderBy($sOrder,$ascDesc) - ->execute() - ->fetchAll(); + $rows = GeneralUtility::makeInstance(SysDmailRepository::class)->selectForMkeListDMail($this->id, $sOrder, $ascDesc); $tblLines = []; $tblLines[] = [ @@ -863,7 +853,7 @@ protected function makeListDMail($open = false) '' ]; - foreach ($res as $row) { + foreach ($rows as $row) { $tblLines[] = [ $this->iconFactory->getIconForRecord('sys_dmail', $row, Icon::SIZE_SMALL)->render(), $this->linkDMail_record($row['subject'], $row['uid']), diff --git a/Classes/Repository/SysDmailRepository.php b/Classes/Repository/SysDmailRepository.php index 05d3b062d..8aab3bc8a 100644 --- a/Classes/Repository/SysDmailRepository.php +++ b/Classes/Repository/SysDmailRepository.php @@ -50,7 +50,7 @@ public function selectForPageInfo(int $id): array|bool { ->add(GeneralUtility::makeInstance(DeletedRestriction::class)); return $queryBuilder->selectLiteral('sys_dmail.uid', 'sys_dmail.subject', 'sys_dmail.scheduled', 'sys_dmail.scheduled_begin', 'sys_dmail.scheduled_end', 'COUNT(sys_dmail_maillog.mid) AS count') - ->from('sys_dmail','sys_dmail') + ->from($this->table, $this->table) ->leftJoin( 'sys_dmail', 'sys_dmail_maillog', @@ -68,4 +68,21 @@ public function selectForPageInfo(int $id): array|bool { ->execute() ->fetchAll(); } + + public function selectForMkeListDMail(int $id, string $sOrder, string $ascDesc): array|bool { + $queryBuilder = $this->getQueryBuilder($this->table); + + $queryBuilder + ->getRestrictions() + ->removeAll() + ->add(GeneralUtility::makeInstance(DeletedRestriction::class)); + + return $queryBuilder->select('uid','pid','subject','tstamp','issent','renderedsize','attachment','type') + ->from($this->table) + ->add('where','pid = ' . intval($id) . + ' AND scheduled=0 AND issent=0') + ->orderBy($sOrder,$ascDesc) + ->execute() + ->fetchAll(); + } } \ No newline at end of file From ee27e651e097f5c94fd82d09e66d31e23623bbe6 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sun, 30 Jan 2022 17:07:55 +0000 Subject: [PATCH 173/342] update first step quickmail --- Classes/Module/DmailController.php | 60 ++++++--------- Resources/Private/Templates/Dmail.html | 74 ++++++++++++++++++- .../Private/Templates/RecipientList.html | 2 +- 3 files changed, 95 insertions(+), 41 deletions(-) diff --git a/Classes/Module/DmailController.php b/Classes/Module/DmailController.php index 5032d8eab..2361b36ae 100644 --- a/Classes/Module/DmailController.php +++ b/Classes/Module/DmailController.php @@ -131,7 +131,8 @@ public function indexAction(ServerRequestInterface $request) : ResponseInterface 'navigation' => $markers['NAVIGATION'], 'flashmessages' => $markers['FLASHMESSAGES'], 'title' => $markers['TITLE'], - 'content' => $formcontent + 'content' => $formcontent, + 'data' => $markers['data'] ] ); } @@ -168,7 +169,8 @@ protected function moduleContent() 'WIZARDSTEPS' => '', 'FLASHMESSAGES' => '', 'NAVIGATION' => '', - 'TITLE' => '' + 'TITLE' => '', + 'data' => [] ]; if ($this->cmd == 'delete') { @@ -230,6 +232,8 @@ protected function moduleContent() } } + $data = []; + $navigationButtons = ''; switch ($this->cmd) { case 'info': @@ -450,7 +454,9 @@ protected function moduleContent() $theOutput .= $this->makeFormExternal($open); break; case 'quick': - $theOutput .= $this->makeFormQuickMail($open); + $temp = $this->getConfigFormQuickMail(); + $temp['open'] = $open; + $data['default']['quick'] = $temp; break; case 'dmail': $theOutput .= $this->makeListDMail($open); @@ -464,6 +470,7 @@ protected function moduleContent() $markers['NAVIGATION'] = $navigationButtons; $markers['CONTENT'] = $theOutput; $markers['WIZARDSTEPS'] = $this->showSteps($totalSteps); + $markers['data'] = $data; return $markers; } @@ -775,45 +782,20 @@ protected function makeFormExternal($open) } /** - * Makes input form for the quickmail (first step) - * - * @param bool $open State of the box - * - * @return string HTML input form for the quickmail - */ - protected function makeFormQuickMail($open) - { - return $this->makeSection( - 'dmail_wiz1_quickmail', - $this->cmd_quickmail(), - $open - ); - } - - /** - * Show the quickmail input form (first step) + * Makes config for form for the quickmail (first step) * - * @return string HTML input form + * @return array config for form for the quickmail */ - protected function cmd_quickmail() + protected function getConfigFormQuickMail() { - $theOutput = ''; - $indata = $this->quickmail; - - $senderName = ($indata['senderName'] ?? $this->getBackendUser()->user['realName']); - $senderMail = ($indata['senderEmail'] ?? $this->getBackendUser()->user['email']); - - $breakLines = $indata['breakLines'] ?? false; - // Set up form: - $theOutput .= ''; - $theOutput .= $this->getLanguageService()->getLL('quickmail_sender_name') . '

'; - $theOutput .= $this->getLanguageService()->getLL('quickmail_sender_email') . '

'; - $theOutput .= $this->getLanguageService()->getLL('dmail_subject') . '

'; - $theOutput .= $this->getLanguageService()->getLL('quickmail_message') . '

'; - $theOutput .= $this->getLanguageService()->getLL('quickmail_break_lines') . '

'; - $theOutput .= ''; - - return $theOutput; + return [ + 'id' => $this->id, + 'senderName' => htmlspecialchars($this->quickmail['senderName'] ?? $this->getBackendUser()->user['realName']), + 'senderMail' => htmlspecialchars($this->quickmail['senderEmail'] ?? $this->getBackendUser()->user['email']), + 'subject' => htmlspecialchars($this->quickmail['subject'] ?? ''), + 'message' => htmlspecialchars($this->quickmail['message'] ?? ''), + 'breakLines' => (bool)($this->quickmail['breakLines'] ?? false) + ]; } /** diff --git a/Resources/Private/Templates/Dmail.html b/Resources/Private/Templates/Dmail.html index d05672da6..b2366e5fe 100644 --- a/Resources/Private/Templates/Dmail.html +++ b/Resources/Private/Templates/Dmail.html @@ -12,7 +12,79 @@ {flashmessages}

{title}

{content} + + + - \ No newline at end of file + + + + + + + + + + + + + + + +
+ +
+
+ +
+
+
+
+ + + + + +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ + +

+ +
diff --git a/Resources/Private/Templates/RecipientList.html b/Resources/Private/Templates/RecipientList.html index 1f90a9969..9f7491dfc 100644 --- a/Resources/Private/Templates/RecipientList.html +++ b/Resources/Private/Templates/RecipientList.html @@ -11,7 +11,7 @@

{data.icon} {data.name} <{data.email}>    - + {data.iconActionsOpen} From 0047896699daa2372d19fbbcaca1efbb84bf72a1 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sun, 30 Jan 2022 17:56:30 +0000 Subject: [PATCH 174/342] update first step external --- Classes/Module/DmailController.php | 38 ++++++----------- Resources/Private/Templates/Dmail.html | 56 ++++++++++++++++++++++---- 2 files changed, 60 insertions(+), 34 deletions(-) diff --git a/Classes/Module/DmailController.php b/Classes/Module/DmailController.php index 2361b36ae..fb3dbed71 100644 --- a/Classes/Module/DmailController.php +++ b/Classes/Module/DmailController.php @@ -451,7 +451,9 @@ protected function moduleContent() $theOutput .= $this->makeFormInternal($open); break; case 'ext': - $theOutput .= $this->makeFormExternal($open); + $temp = $this->getConfigFormExternal(); + $temp['open'] = $open; + $data['default']['external'] = $temp; break; case 'quick': $temp = $this->getConfigFormQuickMail(); @@ -752,33 +754,17 @@ protected function getAvailablePageLanguages($pageUid) } /** - * Make input form for external URL (first step) - * - * @param bool $open State of the box + * Makes config for form for external URL (first step) * - * @return string HTML input form for inputing the external page information + * @return array config for form for inputing the external page information */ - protected function makeFormExternal($open) + protected function getConfigFormExternal() { - $content = '

' . $this->getLanguageService()->getLL('dmail_dovsk_crFromUrl') . - BackendUtility::cshItem($this->cshTable, 'create_directmail_from_url', $GLOBALS['BACK_PATH'] ?? '') . - '

' . - $this->getLanguageService()->getLL('dmail_HTML_url') . '
-
' . - $this->getLanguageService()->getLL('dmail_plaintext_url') . '
-
' . - $this->getLanguageService()->getLL('dmail_subject') . '
' . - '
' . - (($this->error == 'no_valid_url')?('
' . $this->getLanguageService()->getLL('dmail_no_valid_url') . '

'):'') . - ' - ' - ; - - return $this->makeSection( - 'dmail_wiz1_external_page', - $content, - $open - ); + return [ + 'title' => 'dmail_dovsk_crFromUrl', + 'cshItem' => BackendUtility::cshItem($this->cshTable, 'create_directmail_from_url', $GLOBALS['BACK_PATH'] ?? ''), + 'no_valid_url' => (bool)($this->error == 'no_valid_url') + ]; } /** @@ -810,7 +796,7 @@ protected function makeListDMail($open = false) $sOrder = preg_replace( '/^(?:ORDER[[:space:]]*BY[[:space:]]*)+/i', '', trim($GLOBALS['TCA']['sys_dmail']['ctrl']['default_sortby']) - ); + ); if (!empty($sOrder)){ if (substr_count($sOrder, 'ASC') > 0 ){ $sOrder = trim(str_replace('ASC','',$sOrder)); diff --git a/Resources/Private/Templates/Dmail.html b/Resources/Private/Templates/Dmail.html index b2366e5fe..549ad83f1 100644 --- a/Resources/Private/Templates/Dmail.html +++ b/Resources/Private/Templates/Dmail.html @@ -12,16 +12,30 @@ {flashmessages}

{title}

{content} + + + + arguments="{ + data: data.default.external, + index: 5, + section: 'DefaultExternal', + title: 'dmail_wiz1_external_page' + }" + section="Panel" + /> + + + @@ -64,6 +78,32 @@

+ + +

+ {data.cshItem} +

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

+
+ + +
+ From 5d27312782a2f6093b56b72092855f896c515fe6 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sun, 30 Jan 2022 18:44:06 +0000 Subject: [PATCH 175/342] update first step dmail list --- Classes/Module/DmailController.php | 49 +++++++++----------------- Resources/Private/Templates/Dmail.html | 46 +++++++++++++++++++++--- 2 files changed, 59 insertions(+), 36 deletions(-) diff --git a/Classes/Module/DmailController.php b/Classes/Module/DmailController.php index fb3dbed71..3f7a034fb 100644 --- a/Classes/Module/DmailController.php +++ b/Classes/Module/DmailController.php @@ -461,7 +461,9 @@ protected function moduleContent() $data['default']['quick'] = $temp; break; case 'dmail': - $theOutput .= $this->makeListDMail($open); + $temp = $this->getConfigFormDMail(); + $temp['open'] = $open; + $data['default']['dmail'] = $temp; break; default: } @@ -787,11 +789,9 @@ protected function getConfigFormQuickMail() /** * List all direct mail, which have not been sent (first step) * - * @param bool $open State of the box - * - * @return string HTML lists of all existing dmail records + * @return array config for form lists of all existing dmail records */ - protected function makeListDMail($open = false) + protected function getConfigFormDMail() { $sOrder = preg_replace( '/^(?:ORDER[[:space:]]*BY[[:space:]]*)+/i', '', @@ -809,36 +809,21 @@ protected function makeListDMail($open = false) } $rows = GeneralUtility::makeInstance(SysDmailRepository::class)->selectForMkeListDMail($this->id, $sOrder, $ascDesc); - $tblLines = []; - $tblLines[] = [ - '', - $this->getLanguageService()->getLL('nl_l_subject'), - $this->getLanguageService()->getLL('nl_l_lastM'), - $this->getLanguageService()->getLL('nl_l_sent'), - $this->getLanguageService()->getLL('nl_l_size'), - $this->getLanguageService()->getLL('nl_l_attach'), - $this->getLanguageService()->getLL('nl_l_type'), - '' - ]; - + $data = []; foreach ($rows as $row) { - $tblLines[] = [ - $this->iconFactory->getIconForRecord('sys_dmail', $row, Icon::SIZE_SMALL)->render(), - $this->linkDMail_record($row['subject'], $row['uid']), - BackendUtility::date($row['tstamp']), - ($row['issent'] ? $this->getLanguageService()->getLL('dmail_yes') : $this->getLanguageService()->getLL('dmail_no')), - ($row['renderedsize'] ? GeneralUtility::formatSize($row['renderedsize']) : ''), - ($row['attachment'] ? $this->iconFactory->getIcon('directmail-attachment', Icon::SIZE_SMALL) : ''), - ($row['type'] & 0x1 ? $this->getLanguageService()->getLL('nl_l_tUrl') : $this->getLanguageService()->getLL('nl_l_tPage')) . ($row['type'] & 0x2 ? ' (' . $this->getLanguageService()->getLL('nl_l_tDraft') . ')' : ''), - $this->deleteLink($row['uid']) + $data[] = [ + 'icon' => $this->iconFactory->getIconForRecord('sys_dmail', $row, Icon::SIZE_SMALL)->render(), + 'link' => $this->linkDMail_record($row['subject'] ?: '_', $row['uid']), + 'tstamp' => BackendUtility::date($row['tstamp']), + 'issent' => ($row['issent'] ? $this->getLanguageService()->getLL('dmail_yes') : $this->getLanguageService()->getLL('dmail_no')), + 'renderedsize' => ($row['renderedsize'] ? GeneralUtility::formatSize($row['renderedsize']) : ''), + 'attachment' => ($row['attachment'] ? $this->iconFactory->getIcon('directmail-attachment', Icon::SIZE_SMALL) : ''), + 'type' => ($row['type'] & 0x1 ? $this->getLanguageService()->getLL('nl_l_tUrl') : $this->getLanguageService()->getLL('nl_l_tPage')) . ($row['type'] & 0x2 ? ' (' . $this->getLanguageService()->getLL('nl_l_tDraft') . ')' : ''), + 'deleteLink' => $this->deleteLink($row['uid']) ]; } - - return $this->makeSection( - 'dmail_wiz1_list_dmail', - DirectMailUtility::formatTable($tblLines, [], 1, [1, 1, 1, 0, 0, 1, 0, 1]), - $open - ); + + return $data; } /** diff --git a/Resources/Private/Templates/Dmail.html b/Resources/Private/Templates/Dmail.html index 549ad83f1..b7f8826ef 100644 --- a/Resources/Private/Templates/Dmail.html +++ b/Resources/Private/Templates/Dmail.html @@ -11,11 +11,9 @@
{flashmessages}

{title}

- {content} + {content} - - - + + + + @@ -128,3 +137,32 @@



+ + + + +

+ + + + + + + + + + + + + + + + + + + + + + +
  
{row.icon}{row.link}{row.tstamp}{row.issent}{row.renderedsize}{row.attachment}{row.type}{row.deleteLink}
+ From 831d0d82eb2c321e87dda4b4041d47fc85f85329 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sat, 5 Feb 2022 14:20:45 +0000 Subject: [PATCH 176/342] update Dmail part --- Classes/Module/DmailController.php | 30 ++++----- Resources/Private/Templates/Dmail.html | 88 ++++++++++++++++---------- 2 files changed, 69 insertions(+), 49 deletions(-) diff --git a/Classes/Module/DmailController.php b/Classes/Module/DmailController.php index 3f7a034fb..30fa6fe2a 100644 --- a/Classes/Module/DmailController.php +++ b/Classes/Module/DmailController.php @@ -431,7 +431,6 @@ protected function moduleContent() default: // choose source newsletter $this->currentStep = 1; - $markers['TITLE'] = $this->getLanguageService()->getLL('dmail_wiz1_new_newsletter') . ' - ' . $this->getLanguageService()->getLL('dmail_wiz1_select_nl_source'); $showTabs = ['int', 'ext', 'quick', 'dmail']; if(isset($tsconfig['tx_directmail.']['hideTabs'])) { @@ -448,7 +447,9 @@ protected function moduleContent() $open = ($tsconfig['tx_directmail.']['defaultTab'] == $showTab); switch ($showTab) { case 'int': - $theOutput .= $this->makeFormInternal($open); + $temp = $this->getConfigFormInternal(); + $temp['open'] = $open; + $data['default']['internal'] = $temp; break; case 'ext': $temp = $this->getConfigFormExternal(); @@ -468,7 +469,6 @@ protected function moduleContent() default: } } - $theOutput .= ''; } $markers['NAVIGATION'] = $navigationButtons; @@ -504,6 +504,7 @@ protected function showSteps($totalSteps) * @param string $content * @return string */ +/** protected function makeSection(string $title, string $content, bool $isOpen): string { static $sectionId = 1; @@ -530,21 +531,19 @@ protected function makeSection(string $title, string $content, bool $isOpen): st $content ); } - +*/ /** * Makes box for internal page. (first step) * - * @param bool $open State of the box - * - * @return string HTML with list of internal pages + * @return array config for form list of internal pages */ - protected function makeFormInternal($open) + protected function getConfigFormInternal() { - return $this->makeSection( - 'dmail_wiz1_internal_page', - $this->cmd_news(), - $open - ); + return [ + 'title' => 'dmail_dovsk_crFromNL', + 'news' => $this->cmd_news(), + 'cshItem' => BackendUtility::cshItem($this->cshTable, 'select_newsletter', $GLOBALS['BACK_PATH'] ?? ''), + ]; } /** @@ -701,10 +700,7 @@ protected function cmd_news() ]; } $out = DirectMailUtility::formatTable($outLines, [], 0, [1, 1, 1, 1]); - $theOutput = '

' . $this->getLanguageService()->getLL('dmail_dovsk_crFromNL') . - BackendUtility::cshItem($this->cshTable, 'select_newsletter', $GLOBALS['BACK_PATH'] ?? '#') . - '

' . - $out; + $theOutput = $out; } return $theOutput; diff --git a/Resources/Private/Templates/Dmail.html b/Resources/Private/Templates/Dmail.html index b7f8826ef..f7b84b101 100644 --- a/Resources/Private/Templates/Dmail.html +++ b/Resources/Private/Templates/Dmail.html @@ -1,6 +1,7 @@ +
@@ -13,38 +14,53 @@

{title}

{content} - - - - - - - - + +

-

+ + + + + + + + + + + + +
@@ -87,6 +103,14 @@

+ + +

+ {data.cshItem} +

+ {data.news} +
+

From 19f920df254874a4635b0742ab9c52994bab8cd4 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sat, 5 Feb 2022 14:49:27 +0000 Subject: [PATCH 177/342] update Dmail part --- Classes/Module/DmailController.php | 129 +++++++++++++------------ Resources/Private/Templates/Dmail.html | 6 +- 2 files changed, 72 insertions(+), 63 deletions(-) diff --git a/Classes/Module/DmailController.php b/Classes/Module/DmailController.php index 30fa6fe2a..b6da451a3 100644 --- a/Classes/Module/DmailController.php +++ b/Classes/Module/DmailController.php @@ -541,7 +541,7 @@ protected function getConfigFormInternal() { return [ 'title' => 'dmail_dovsk_crFromNL', - 'news' => $this->cmd_news(), + 'news' => $this->getNews(), 'cshItem' => BackendUtility::cshItem($this->cshTable, 'select_newsletter', $GLOBALS['BACK_PATH'] ?? ''), ]; } @@ -566,7 +566,7 @@ protected function getNewsletterTabIcon($expand = false) * @return string HTML * @throws RouteNotFoundException If the named route doesn't exist */ - protected function cmd_news() + protected function getNews() { // Here the list of subpages, news, is rendered $queryBuilder = $this->getQueryBuilder('pages'); @@ -580,7 +580,8 @@ protected function cmd_news() ), $queryBuilder->expr()->eq('l10n_parent', 0), // Exclude translated page records from list $this->perms_clause - ); + ); + /** * Postbone Breaking: #82803 - Global configuration option "content_doktypes" removed in TYPO3 v9 * Regards custom configurations, otherwise ignores spacers (199), recyclers (255) and folders (254) @@ -588,76 +589,81 @@ protected function cmd_news() * @deprecated since TYPO3 v9. **/ if (isset($GLOBALS['TYPO3_CONF_VARS']['FE']['content_doktypes']) - && !empty($GLOBALS['TYPO3_CONF_VARS']['FE']['content_doktypes']) - ) { - $queryBuilder->andWhere( - $queryBuilder->expr()->in( - 'doktype', - GeneralUtility::intExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['content_doktypes']) - ) - ); - } else { - $queryBuilder->andWhere( - $queryBuilder->expr()->notIn( - 'doktype', - [199,254,255] - ) - ); - } - $rows = $queryBuilder->orderBy('sorting')->execute()->fetchAll(); - - if (empty($rows)) { - $theOutput = '

' . $this->getLanguageService()->getLL('nl_select') . '

' . $this->getLanguageService()->getLL('nl_select_msg1'); - } else { - $outLines = []; + && !empty($GLOBALS['TYPO3_CONF_VARS']['FE']['content_doktypes']) ) + { + $queryBuilder->andWhere( + $queryBuilder->expr()->in( + 'doktype', + GeneralUtility::intExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['content_doktypes']) + ) + ); + } + else { + $queryBuilder->andWhere( + $queryBuilder->expr()->notIn( + 'doktype', + [199,254,255] + ) + ); + } + + $rows = $queryBuilder->orderBy('sorting')->execute()->fetchAll(); - foreach ($rows as $row) { - $languages = $this->getAvailablePageLanguages($row['uid']); - $createDmailLink = $this->buildUriFromRoute( - $this->moduleName, - [ - 'id' => $this->id, - 'createMailFrom_UID' => $row['uid'], - 'fetchAtOnce' => 1, - 'cmd' => 'info' - ] - ); - $pageIcon = $this->iconFactory->getIconForRecord('pages', $row, Icon::SIZE_SMALL) . ' ' . htmlspecialchars($row['title']); + $out = ''; + $empty = false; + if (empty($rows)) { + $empty = true; + } + else { + $outLines = []; + + foreach ($rows as $row) { + $languages = $this->getAvailablePageLanguages($row['uid']); + $createDmailLink = $this->buildUriFromRoute( + $this->moduleName, + [ + 'id' => $this->id, + 'createMailFrom_UID' => $row['uid'], + 'fetchAtOnce' => 1, + 'cmd' => 'info' + ] + ); + $pageIcon = $this->iconFactory->getIconForRecord('pages', $row, Icon::SIZE_SMALL) . ' ' . htmlspecialchars($row['title']); - $previewHTMLLink = $previewTextLink = $createLink = ''; - foreach ($languages as $languageUid => $lang) { - $langParam = DirectMailUtility::getLanguageParam($languageUid, $this->params); - $createLangParam = ($languageUid ? '&createMailFrom_LANG=' . $languageUid : ''); - $langIconOverlay = (count($languages) > 1 ? $lang['flagIcon'] : null); - $langTitle = (count($languages) > 1 ? ' - ' . $lang['title'] : ''); - $plainParams = $this->implodedParams['plainParams'] ?? '' . $langParam; - $htmlParams = $this->implodedParams['HTMLParams'] ?? '' . $langParam; - $htmlIcon = $this->iconFactory->getIcon('directmail-dmail-preview-html', Icon::SIZE_SMALL, $langIconOverlay); - $plainIcon = $this->iconFactory->getIcon('directmail-dmail-preview-text', Icon::SIZE_SMALL, $langIconOverlay); - $createIcon = $this->iconFactory->getIcon('directmail-dmail-new', Icon::SIZE_SMALL, $langIconOverlay); + $previewHTMLLink = $previewTextLink = $createLink = ''; + foreach ($languages as $languageUid => $lang) { + $langParam = DirectMailUtility::getLanguageParam($languageUid, $this->params); + $createLangParam = ($languageUid ? '&createMailFrom_LANG=' . $languageUid : ''); + $langIconOverlay = (count($languages) > 1 ? $lang['flagIcon'] : null); + $langTitle = (count($languages) > 1 ? ' - ' . $lang['title'] : ''); + $plainParams = $this->implodedParams['plainParams'] ?? '' . $langParam; + $htmlParams = $this->implodedParams['HTMLParams'] ?? '' . $langParam; + $htmlIcon = $this->iconFactory->getIcon('directmail-dmail-preview-html', Icon::SIZE_SMALL, $langIconOverlay); + $plainIcon = $this->iconFactory->getIcon('directmail-dmail-preview-text', Icon::SIZE_SMALL, $langIconOverlay); + $createIcon = $this->iconFactory->getIcon('directmail-dmail-new', Icon::SIZE_SMALL, $langIconOverlay); - $attributes = \TYPO3\CMS\Backend\Routing\PreviewUriBuilder::create($row['uid'], '') + $attributes = \TYPO3\CMS\Backend\Routing\PreviewUriBuilder::create($row['uid'], '') ->withRootLine(BackendUtility::BEgetRootLine($row['uid'])) //->withSection('') ->withAdditionalQueryParameters($htmlParams) ->buildDispatcherDataAttributes([]); - $serializedAttributes = GeneralUtility::implodeAttributes([ - 'href' => '#', - 'data-dispatch-action' => $attributes['dispatch-action'], - 'data-dispatch-args' => $attributes['dispatch-args'], - 'title' => htmlentities($this->getLanguageService()->getLL('nl_viewPage_HTML') . $langTitle) - ], true); + $serializedAttributes = GeneralUtility::implodeAttributes([ + 'href' => '#', + 'data-dispatch-action' => $attributes['dispatch-action'], + 'data-dispatch-args' => $attributes['dispatch-args'], + 'title' => htmlentities($this->getLanguageService()->getLL('nl_viewPage_HTML') . $langTitle) + ], true); - $previewHTMLLink .= '' . $htmlIcon . ''; + $previewHTMLLink .= '' . $htmlIcon . ''; - $attributes = \TYPO3\CMS\Backend\Routing\PreviewUriBuilder::create($row['uid'], '') + $attributes = \TYPO3\CMS\Backend\Routing\PreviewUriBuilder::create($row['uid'], '') ->withRootLine(BackendUtility::BEgetRootLine($row['uid'])) //->withSection('') ->withAdditionalQueryParameters($plainParams) ->buildDispatcherDataAttributes([]); - $serializedAttributes = GeneralUtility::implodeAttributes([ + $serializedAttributes = GeneralUtility::implodeAttributes([ 'href' => '#', 'data-dispatch-action' => $attributes['dispatch-action'], 'data-dispatch-args' => $attributes['dispatch-args'], @@ -698,12 +704,11 @@ protected function cmd_news() $this->iconFactory->getIcon('actions-open', Icon::SIZE_SMALL) . '', $previewLink ]; - } - $out = DirectMailUtility::formatTable($outLines, [], 0, [1, 1, 1, 1]); - $theOutput = $out; } + $out = DirectMailUtility::formatTable($outLines, [], 0, [1, 1, 1, 1]); + } - return $theOutput; + return ['out' => $out, 'empty' => $empty]; } /** diff --git a/Resources/Private/Templates/Dmail.html b/Resources/Private/Templates/Dmail.html index f7b84b101..72f31192e 100644 --- a/Resources/Private/Templates/Dmail.html +++ b/Resources/Private/Templates/Dmail.html @@ -108,7 +108,11 @@

{data.cshItem}

- {data.news} + +

+ +
+ {data.news.out} From d422b68a572290bfaee03717e4c16fd5268a2852 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sat, 5 Feb 2022 15:17:17 +0000 Subject: [PATCH 178/342] update Dmail part --- Classes/Module/DmailController.php | 42 ++----------------------- Classes/Repository/PagesRepository.php | 43 ++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 40 deletions(-) create mode 100644 Classes/Repository/PagesRepository.php diff --git a/Classes/Module/DmailController.php b/Classes/Module/DmailController.php index b6da451a3..7ba7f4cfd 100644 --- a/Classes/Module/DmailController.php +++ b/Classes/Module/DmailController.php @@ -5,6 +5,7 @@ use DirectMailTeam\DirectMail\Dmailer; use DirectMailTeam\DirectMail\DirectMailUtility; +use DirectMailTeam\DirectMail\Repository\PagesRepository; use DirectMailTeam\DirectMail\Repository\SysDmailRepository; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; @@ -568,47 +569,8 @@ protected function getNewsletterTabIcon($expand = false) */ protected function getNews() { - // Here the list of subpages, news, is rendered - $queryBuilder = $this->getQueryBuilder('pages'); - $queryBuilder - ->select('uid', 'doktype', 'title', 'abstract') - ->from('pages') - ->where( - $queryBuilder->expr()->eq( - 'pid', - $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT) - ), - $queryBuilder->expr()->eq('l10n_parent', 0), // Exclude translated page records from list - $this->perms_clause - ); - - /** - * Postbone Breaking: #82803 - Global configuration option "content_doktypes" removed in TYPO3 v9 - * Regards custom configurations, otherwise ignores spacers (199), recyclers (255) and folders (254) - * - * @deprecated since TYPO3 v9. - **/ - if (isset($GLOBALS['TYPO3_CONF_VARS']['FE']['content_doktypes']) - && !empty($GLOBALS['TYPO3_CONF_VARS']['FE']['content_doktypes']) ) - { - $queryBuilder->andWhere( - $queryBuilder->expr()->in( - 'doktype', - GeneralUtility::intExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['content_doktypes']) - ) - ); - } - else { - $queryBuilder->andWhere( - $queryBuilder->expr()->notIn( - 'doktype', - [199,254,255] - ) - ); - } + $rows = GeneralUtility::makeInstance(PagesRepository::class)->selectPagesForDmail($this->id, $this->perms_clause); - $rows = $queryBuilder->orderBy('sorting')->execute()->fetchAll(); - $out = ''; $empty = false; if (empty($rows)) { diff --git a/Classes/Repository/PagesRepository.php b/Classes/Repository/PagesRepository.php new file mode 100644 index 000000000..a4e35a6b8 --- /dev/null +++ b/Classes/Repository/PagesRepository.php @@ -0,0 +1,43 @@ +getQueryBuilder($this->table); + $queryBuilder + ->select('uid', 'doktype', 'title', 'abstract') + ->from($this->table) + ->where( + $queryBuilder->expr()->eq( + 'pid', + $queryBuilder->createNamedParameter($pid, \PDO::PARAM_INT) + ), + $queryBuilder->expr()->eq('l10n_parent', 0), // Exclude translated page records from list + $permsClause + ); + + /** + * https://docs.typo3.org/m/typo3/reference-coreapi/11.5/en-us/ApiOverview/PageTypes/TypesOfPages.html + * typo3/sysext/core/Classes/Domain/Repository/PageRepository.php + * + * Regards custom configurations, otherwise ignores spacers (199), recyclers (255) and folders (254) + * + **/ + + return $queryBuilder + ->andWhere( + $queryBuilder->expr()->notIn( + 'doktype', + [199,254,255] + ) + ) + ->orderBy('sorting') + ->execute() + ->fetchAll(); + } +} \ No newline at end of file From d2101323198bda55dc612f2836fe1a1a5de0f0cb Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sat, 5 Feb 2022 16:13:42 +0000 Subject: [PATCH 179/342] update Dmail part --- Classes/Module/DmailController.php | 72 +++++++++++++------------- Resources/Private/Templates/Dmail.html | 25 ++++++++- 2 files changed, 59 insertions(+), 38 deletions(-) diff --git a/Classes/Module/DmailController.php b/Classes/Module/DmailController.php index 7ba7f4cfd..bc013bc20 100644 --- a/Classes/Module/DmailController.php +++ b/Classes/Module/DmailController.php @@ -570,15 +570,13 @@ protected function getNewsletterTabIcon($expand = false) protected function getNews() { $rows = GeneralUtility::makeInstance(PagesRepository::class)->selectPagesForDmail($this->id, $this->perms_clause); - - $out = ''; + $data = []; $empty = false; + $iconActionsOpen = $this->iconFactory->getIcon('actions-open', Icon::SIZE_SMALL); if (empty($rows)) { $empty = true; } else { - $outLines = []; - foreach ($rows as $row) { $languages = $this->getAvailablePageLanguages($row['uid']); $createDmailLink = $this->buildUriFromRoute( @@ -634,43 +632,43 @@ protected function getNews() $previewTextLink .= '' . $plainIcon . ''; $createLink .= '' . $createIcon . ''; - } - - switch ($this->params['sendOptions'] ?? 0) { - case 1: - $previewLink = $previewTextLink; - break; - case 2: - $previewLink = $previewHTMLLink; - break; - case 3: - // also as default - default: - $previewLink = $previewHTMLLink . '  ' . $previewTextLink; - } - - $params = [ - 'edit' => [ - 'pages' => [ - $row['uid'] => 'edit', - ] - ], - 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI'), - ]; - $editOnClickLink = DirectMailUtility::getEditOnClickLink($params); + } - $outLines[] = [ - '' . $pageIcon . '', - $createLink, - '' . - $this->iconFactory->getIcon('actions-open', Icon::SIZE_SMALL) . '', - $previewLink - ]; + switch ($this->params['sendOptions'] ?? 0) { + case 1: + $previewLink = $previewTextLink; + break; + case 2: + $previewLink = $previewHTMLLink; + break; + case 3: + // also as default + default: + $previewLink = $previewHTMLLink . '  ' . $previewTextLink; + } + + $params = [ + 'edit' => [ + 'pages' => [ + $row['uid'] => 'edit', + ] + ], + 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI'), + ]; + $editOnClickLink = DirectMailUtility::getEditOnClickLink($params); + + $data[] = [ + 'pageIcon' => $pageIcon, + 'createDmailLink' => $createDmailLink, + 'createLink' => $createLink, + 'editOnClickLink' => $editOnClickLink, + 'iconActionsOpen' => $iconActionsOpen, + 'previewLink' => $previewLink + ]; } - $out = DirectMailUtility::formatTable($outLines, [], 0, [1, 1, 1, 1]); } - return ['out' => $out, 'empty' => $empty]; + return ['empty' => $empty, 'rows' => $data]; } /** diff --git a/Resources/Private/Templates/Dmail.html b/Resources/Private/Templates/Dmail.html index 72f31192e..b768e8697 100644 --- a/Resources/Private/Templates/Dmail.html +++ b/Resources/Private/Templates/Dmail.html @@ -112,7 +112,30 @@

- {data.news.out} + + + + + + + + + + + + + +
+ {row.pageIcon} + + {row.createLink} + + + {row.iconActionsOpen} + + {row.previewLink}
+
+
From f5e5a9127b2dc4d1fa1eb683cd62b09c03bee2f2 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sat, 5 Feb 2022 17:10:45 +0000 Subject: [PATCH 180/342] update Dmail part --- Classes/Module/DmailController.php | 7 +++---- Resources/Private/Templates/Dmail.html | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Classes/Module/DmailController.php b/Classes/Module/DmailController.php index bc013bc20..b857ba88a 100644 --- a/Classes/Module/DmailController.php +++ b/Classes/Module/DmailController.php @@ -588,7 +588,6 @@ protected function getNews() 'cmd' => 'info' ] ); - $pageIcon = $this->iconFactory->getIconForRecord('pages', $row, Icon::SIZE_SMALL) . ' ' . htmlspecialchars($row['title']); $previewHTMLLink = $previewTextLink = $createLink = ''; foreach ($languages as $languageUid => $lang) { @@ -655,13 +654,13 @@ protected function getNews() ], 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI'), ]; - $editOnClickLink = DirectMailUtility::getEditOnClickLink($params); $data[] = [ - 'pageIcon' => $pageIcon, + 'pageIcon' => $this->iconFactory->getIconForRecord('pages', $row, Icon::SIZE_SMALL), + 'title' => htmlspecialchars($row['title']), 'createDmailLink' => $createDmailLink, 'createLink' => $createLink, - 'editOnClickLink' => $editOnClickLink, + 'editOnClickLink' => DirectMailUtility::getEditOnClickLink($params), 'iconActionsOpen' => $iconActionsOpen, 'previewLink' => $previewLink ]; diff --git a/Resources/Private/Templates/Dmail.html b/Resources/Private/Templates/Dmail.html index b768e8697..6e5455917 100644 --- a/Resources/Private/Templates/Dmail.html +++ b/Resources/Private/Templates/Dmail.html @@ -119,7 +119,7 @@

- {row.pageIcon} + {row.pageIcon} {row.title} {row.createLink} From 63a6692b9e3e8d100f2bb4b2822e4b0a37061f6e Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sat, 5 Feb 2022 17:14:08 +0000 Subject: [PATCH 181/342] update Dmail part --- Classes/Module/DmailController.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Classes/Module/DmailController.php b/Classes/Module/DmailController.php index b857ba88a..5413ba6fa 100644 --- a/Classes/Module/DmailController.php +++ b/Classes/Module/DmailController.php @@ -564,10 +564,10 @@ protected function getNewsletterTabIcon($expand = false) /** * Show the list of existing directmail records, which haven't been sent * - * @return string HTML + * @return array * @throws RouteNotFoundException If the named route doesn't exist */ - protected function getNews() + protected function getNews(): array { $rows = GeneralUtility::makeInstance(PagesRepository::class)->selectPagesForDmail($this->id, $this->perms_clause); $data = []; @@ -629,8 +629,8 @@ protected function getNews() 'title' => htmlentities($this->getLanguageService()->getLL('nl_viewPage_TXT') . $langTitle) ], true); - $previewTextLink .= '' . $plainIcon . ''; - $createLink .= '' . $createIcon . ''; + $previewTextLink .= '' . $plainIcon . ''; + $createLink .= '' . $createIcon . ''; } switch ($this->params['sendOptions'] ?? 0) { From d9072d0d1ec33a967f9b0e5b6b3163c283e7fda7 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sat, 5 Feb 2022 18:21:38 +0000 Subject: [PATCH 182/342] update Dmail part --- Classes/Module/DmailController.php | 36 ++++++++++++++------------ Resources/Private/Templates/Dmail.html | 8 +++++- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/Classes/Module/DmailController.php b/Classes/Module/DmailController.php index 5413ba6fa..263c1f4d2 100644 --- a/Classes/Module/DmailController.php +++ b/Classes/Module/DmailController.php @@ -129,7 +129,6 @@ public function indexAction(ServerRequestInterface $request) : ResponseInterface $this->view->assignMultiple( [ 'wizardsteps' => $markers['WIZARDSTEPS'], - 'navigation' => $markers['NAVIGATION'], 'flashmessages' => $markers['FLASHMESSAGES'], 'title' => $markers['TITLE'], 'content' => $formcontent, @@ -169,7 +168,6 @@ protected function moduleContent() $markers = [ 'WIZARDSTEPS' => '', 'FLASHMESSAGES' => '', - 'NAVIGATION' => '', 'TITLE' => '', 'data' => [] ]; @@ -233,9 +231,14 @@ protected function moduleContent() } } - $data = []; + $data = [ + 'navigation' => [ + 'back' => false, + 'next' => false, + 'next_error' => false + ] + ]; - $navigationButtons = ''; switch ($this->cmd) { case 'info': // step 2: create the Direct Mail record, or use existing @@ -304,9 +307,10 @@ protected function moduleContent() $theOutput .= ''; if($quickmail['breakLines'] ?? false) { $theOutput .= ''; - } - // existing dmail - } elseif ($row) { + } + } + // existing dmail + elseif ($row) { if ($row['type'] == '1' && ((empty($row['HTMLParams'])) || (empty($row['plainParams'])))) { // it's a quickmail @@ -330,8 +334,9 @@ protected function moduleContent() } } - $navigationButtons = '  '; - $navigationButtons .= ''; + $data['navigation']['back'] = true; + $data['navigation']['next'] = true; + $data['navigation']['next_error'] = $fetchError; if ($fetchMessage) { $markers['FLASHMESSAGES'] = $fetchMessage; @@ -362,8 +367,8 @@ protected function moduleContent() $this->currentStep = 3; $markers['TITLE'] = $this->getLanguageService()->getLL('dmail_wiz3_cats'); - $navigationButtons = ' '; - $navigationButtons .= ''; + $data['navigation']['back'] = true; + $data['navigation']['next'] = true; $theOutput .= '
'; $theOutput .= $this->makeCategoriesForm($row); @@ -382,8 +387,8 @@ protected function moduleContent() $this->currentStep = (4 - (5 - $totalSteps)); $markers['TITLE'] = $this->getLanguageService()->getLL('dmail_wiz4_testmail'); - $navigationButtons = ' '; - $navigationButtons.= ''; + $data['navigation']['back'] = true; + $data['navigation']['next'] = true; if ($this->cmd == 'send_mail_test') { // using Flashmessages to show sent test mail @@ -405,7 +410,7 @@ protected function moduleContent() $this->currentStep = (5 - (5 - $totalSteps)); if ($this->cmd == 'send_mass') { - $navigationButtons = ''; + $data['navigation']['back'] = true; } if ($this->cmd == 'send_mail_final') { @@ -471,8 +476,7 @@ protected function moduleContent() } } } - - $markers['NAVIGATION'] = $navigationButtons; + $markers['CONTENT'] = $theOutput; $markers['WIZARDSTEPS'] = $this->showSteps($totalSteps); $markers['data'] = $data; diff --git a/Resources/Private/Templates/Dmail.html b/Resources/Private/Templates/Dmail.html index 6e5455917..48f79bc10 100644 --- a/Resources/Private/Templates/Dmail.html +++ b/Resources/Private/Templates/Dmail.html @@ -7,7 +7,13 @@
{wizardsteps} - {navigation} + +   + + + + +

{flashmessages} From 78bf0c77afea7e317c3d326be01f36e31b1cf5b8 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sat, 5 Feb 2022 19:12:47 +0000 Subject: [PATCH 183/342] update Dmail part --- Classes/Module/DmailController.php | 16 ++++------------ Classes/Repository/PagesRepository.php | 12 ++++++++++++ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Classes/Module/DmailController.php b/Classes/Module/DmailController.php index 263c1f4d2..7f40f72e7 100644 --- a/Classes/Module/DmailController.php +++ b/Classes/Module/DmailController.php @@ -688,7 +688,7 @@ protected function getAvailablePageLanguages($pageUid) if ($languages === null) { $languages = GeneralUtility::makeInstance(TranslationConfigurationProvider::class)->getSystemLanguages(); } - + // loop trough all sys languages and check if there is matching page translation foreach ($languages as $lang) { // we skip -1 @@ -697,18 +697,10 @@ protected function getAvailablePageLanguages($pageUid) } // 0 is always present so only for > 0 - if ((int)$lang['uid'] > 0) { - $queryBuilder = $this->getQueryBuilder('pages'); + if ((int)$lang['uid'] > 0) { + $langRow = GeneralUtility::makeInstance(PagesRepository::class)->selectPageByL10nAndSysLanguageUid($pageUid, $lang['uid']); - $langRow = $queryBuilder - ->select('sys_language_uid') - ->from('pages') - ->where($queryBuilder->expr()->eq('l10n_parent', $queryBuilder->createNamedParameter($pageUid, \PDO::PARAM_INT))) - ->andWhere($queryBuilder->expr()->eq('sys_language_uid', $queryBuilder->createNamedParameter($lang['uid'], \PDO::PARAM_INT))) - ->execute() - ->fetchAll(); - - if (empty($langRow)) { + if (!$langRow || empty($langRow)) { continue; } } diff --git a/Classes/Repository/PagesRepository.php b/Classes/Repository/PagesRepository.php index a4e35a6b8..c14c59fda 100644 --- a/Classes/Repository/PagesRepository.php +++ b/Classes/Repository/PagesRepository.php @@ -40,4 +40,16 @@ public function selectPagesForDmail(int $pid, string $permsClause): array|bool { ->execute() ->fetchAll(); } + + public function selectPageByL10nAndSysLanguageUid(int $pageUid, int $langUid): array|bool { + $queryBuilder = $this->getQueryBuilder($this->table); + + return $queryBuilder + ->select('sys_language_uid') + ->from($this->table) + ->where($queryBuilder->expr()->eq('l10n_parent', $queryBuilder->createNamedParameter($pageUid, \PDO::PARAM_INT))) + ->andWhere($queryBuilder->expr()->eq('sys_language_uid', $queryBuilder->createNamedParameter($langUid, \PDO::PARAM_INT))) + ->execute() + ->fetchAll(); + } } \ No newline at end of file From 826349f579ff1af3a1c0946f506a5d4d9db3668b Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sat, 5 Feb 2022 19:39:35 +0000 Subject: [PATCH 184/342] disable union types --- Classes/Repository/FeUsersRepository.php | 6 +- Classes/Repository/PagesRepository.php | 12 +- .../Repository/SysDmailGroupRepository.php | 6 +- .../Repository/SysDmailMaillogRepository.php | 114 +++++++++++++++--- Classes/Repository/SysDmailRepository.php | 24 +++- Classes/Repository/TtAddressRepository.php | 6 +- 6 files changed, 140 insertions(+), 28 deletions(-) diff --git a/Classes/Repository/FeUsersRepository.php b/Classes/Repository/FeUsersRepository.php index 63275d697..08db383c8 100644 --- a/Classes/Repository/FeUsersRepository.php +++ b/Classes/Repository/FeUsersRepository.php @@ -6,7 +6,11 @@ class FeUsersRepository extends MainRepository { protected string $table = 'fe_users'; - public function selectFeUsersByUid(int $uid, string $permsClause): array|bool { + /** + * @return array|bool + */ + public function selectFeUsersByUid(int $uid, string $permsClause) //: array|bool + { $queryBuilder = $this->getQueryBuilder($this->table); return $queryBuilder diff --git a/Classes/Repository/PagesRepository.php b/Classes/Repository/PagesRepository.php index c14c59fda..796921d95 100644 --- a/Classes/Repository/PagesRepository.php +++ b/Classes/Repository/PagesRepository.php @@ -6,7 +6,11 @@ class PagesRepository extends MainRepository { protected string $table = 'pages'; - public function selectPagesForDmail(int $pid, string $permsClause): array|bool { + /** + * @return array|bool + */ + public function selectPagesForDmail(int $pid, string $permsClause) //: array|bool + { // Here the list of subpages, news, is rendered $queryBuilder = $this->getQueryBuilder($this->table); $queryBuilder @@ -41,7 +45,11 @@ public function selectPagesForDmail(int $pid, string $permsClause): array|bool { ->fetchAll(); } - public function selectPageByL10nAndSysLanguageUid(int $pageUid, int $langUid): array|bool { + /** + * @return array|bool + */ + public function selectPageByL10nAndSysLanguageUid(int $pageUid, int $langUid) //: array|bool + { $queryBuilder = $this->getQueryBuilder($this->table); return $queryBuilder diff --git a/Classes/Repository/SysDmailGroupRepository.php b/Classes/Repository/SysDmailGroupRepository.php index c02d29cfe..a1584637e 100644 --- a/Classes/Repository/SysDmailGroupRepository.php +++ b/Classes/Repository/SysDmailGroupRepository.php @@ -9,7 +9,11 @@ class SysDmailGroupRepository extends MainRepository { protected string $table = 'sys_dmail_group'; - public function selecetSysDmailGroupByPid(int $pid, string $defaultSortBy): array|bool { + /** + * @return array|bool + */ + public function selecetSysDmailGroupByPid(int $pid, string $defaultSortBy) //: array|bool + { $queryBuilder = $this->getQueryBuilder($this->table); $queryBuilder ->getRestrictions() diff --git a/Classes/Repository/SysDmailMaillogRepository.php b/Classes/Repository/SysDmailMaillogRepository.php index 437444d04..380049ce5 100644 --- a/Classes/Repository/SysDmailMaillogRepository.php +++ b/Classes/Repository/SysDmailMaillogRepository.php @@ -8,7 +8,11 @@ class SysDmailMaillogRepository extends MainRepository { protected string $table = 'sys_dmail_maillog'; - public function countSysDmailMaillogAllByMid(int $mid): array|bool { + /** + * @return array|bool + */ + public function countSysDmailMaillogAllByMid(int $mid) //: array|bool + { $queryBuilder = $this->getQueryBuilder($this->table); return $queryBuilder @@ -21,7 +25,11 @@ public function countSysDmailMaillogAllByMid(int $mid): array|bool { ->fetchAll(); } - public function countSysDmailMaillogHtmlByMid(int $mid): array|bool { + /** + * @return array|bool + */ + public function countSysDmailMaillogHtmlByMid(int $mid) //: array|bool + { $queryBuilder = $this->getQueryBuilder($this->table); return $queryBuilder @@ -35,7 +43,11 @@ public function countSysDmailMaillogHtmlByMid(int $mid): array|bool { ->fetchAll(); } - public function countSysDmailMaillogPlainByMid(int $mid): array|bool { + /** + * @return array|bool + */ + public function countSysDmailMaillogPlainByMid(int $mid) //: array|bool + { $queryBuilder = $this->getQueryBuilder($this->table); return $queryBuilder @@ -49,7 +61,11 @@ public function countSysDmailMaillogPlainByMid(int $mid): array|bool { ->fetchAll(); } - public function countSysDmailMaillogPingByMid(int $mid): array|bool { + /** + * @return array|bool + */ + public function countSysDmailMaillogPingByMid(int $mid) //: array|bool + { $queryBuilder = $this->getQueryBuilder($this->table); return $queryBuilder @@ -63,7 +79,11 @@ public function countSysDmailMaillogPingByMid(int $mid): array|bool { ->fetchAll(); } - public function selectByResponseType(int $responseType): array|bool { + /** + * @return array|bool + */ + public function selectByResponseType(int $responseType) //: array|bool + { $queryBuilder = $this->getQueryBuilder($this->table); return $queryBuilder @@ -75,7 +95,11 @@ public function selectByResponseType(int $responseType): array|bool { ->fetchAll(); } - public function countSysDmailMaillogs(int $uid): array|bool { + /** + * @return array|bool + */ + public function countSysDmailMaillogs(int $uid) //: array|bool + { $queryBuilder = $this->getQueryBuilder($this->table); return $queryBuilder->count('*') @@ -87,7 +111,11 @@ public function countSysDmailMaillogs(int $uid): array|bool { ->fetchAll(); } - public function countSysDmailMaillogsResponseTypeByMid(int $uid): array|bool { + /** + * @return array|bool + */ + public function countSysDmailMaillogsResponseTypeByMid(int $uid) //: array|bool + { $queryBuilder = $this->getQueryBuilder($this->table); return $queryBuilder->count('*') @@ -99,7 +127,11 @@ public function countSysDmailMaillogsResponseTypeByMid(int $uid): array|bool { ->fetchAll(); } - public function selectSysDmailMaillogsCompactView(int $uid): array|bool { + /** + * @return array|bool + */ + public function selectSysDmailMaillogsCompactView(int $uid) //: array|bool + { $queryBuilder = $this->getQueryBuilder($this->table); return $queryBuilder->select('uid') @@ -111,7 +143,11 @@ public function selectSysDmailMaillogsCompactView(int $uid): array|bool { ->fetchAll(); } - public function selectMostPopularLinksHtml(int $uid): array|bool { + /** + * @return array|bool + */ + public function selectMostPopularLinksHtml(int $uid) //: array|bool + { $queryBuilder = $this->getQueryBuilder($this->table); return $queryBuilder->count('*') @@ -125,7 +161,11 @@ public function selectMostPopularLinksHtml(int $uid): array|bool { ->fetchAll(); } - public function selectMostPopularLinksPlain(int $uid): array|bool { + /** + * @return array|bool + */ + public function selectMostPopularLinksPlain(int $uid) //: array|bool + { $queryBuilder = $this->getQueryBuilder($this->table); return $queryBuilder->count('*') @@ -139,7 +179,11 @@ public function selectMostPopularLinksPlain(int $uid): array|bool { ->fetchAll(); } - public function countReturnCode(int $uid, int $responseType = -127): array|bool { + /** + * @return array|bool + */ + public function countReturnCode(int $uid, int $responseType = -127) //: array|bool + { $queryBuilder = $this->getQueryBuilder($this->table); return $queryBuilder->count('*') @@ -153,7 +197,11 @@ public function countReturnCode(int $uid, int $responseType = -127): array|bool ->fetchAll(); } - public function selectStatTempTableContent(int $uid): array|bool { + /** + * @return array|bool + */ + public function selectStatTempTableContent(int $uid) //: array|bool + { $queryBuilder = $this->getQueryBuilder($this->table); return $queryBuilder->select('rid','rtbl','tstamp','response_type','url_id','html_sent','size') @@ -166,7 +214,11 @@ public function selectStatTempTableContent(int $uid): array|bool { ->fetchAll(); } - public function findAllReturnedMail(int $uid): array|bool { + /** + * @return array|bool + */ + public function findAllReturnedMail(int $uid) //: array|bool + { $queryBuilder = $this->getQueryBuilder($this->table); return $queryBuilder->select('rid','rtbl','email') @@ -177,7 +229,11 @@ public function findAllReturnedMail(int $uid): array|bool { ->fetchAll(); } - public function findUnknownRecipient(int $uid): array|bool { + /** + * @return array|bool + */ + public function findUnknownRecipient(int $uid) //: array|bool + { $queryBuilder = $this->getQueryBuilder($this->table); return $queryBuilder->select('rid','rtbl','email') @@ -189,7 +245,11 @@ public function findUnknownRecipient(int $uid): array|bool { ->fetchAll(); } - public function findMailboxFull(int $uid): array|bool { + /** + * @return array|bool + */ + public function findMailboxFull(int $uid) //: array|bool + { $queryBuilder = $this->getQueryBuilder($this->table); return $queryBuilder->select('rid','rtbl','email') @@ -201,7 +261,11 @@ public function findMailboxFull(int $uid): array|bool { ->fetchAll(); } - public function findBadHost(int $uid): array|bool { + /** + * @return array|bool + */ + public function findBadHost(int $uid) //: array|bool + { $queryBuilder = $this->getQueryBuilder($this->table); return $queryBuilder->select('rid','rtbl','email') @@ -213,7 +277,11 @@ public function findBadHost(int $uid): array|bool { ->fetchAll(); } - public function findBadHeader(int $uid): array|bool { + /** + * @return array|bool + */ + public function findBadHeader(int $uid) //: array|bool + { $queryBuilder = $this->getQueryBuilder($this->table); return $queryBuilder->select('rid','rtbl','email') @@ -225,7 +293,11 @@ public function findBadHeader(int $uid): array|bool { ->fetchAll(); } - public function findUnknownReasons(int $uid): array|bool { + /** + * @return array|bool + */ + public function findUnknownReasons(int $uid) //: array|bool + { $queryBuilder = $this->getQueryBuilder($this->table); return $queryBuilder->select('rid','rtbl','email') @@ -237,7 +309,11 @@ public function findUnknownReasons(int $uid): array|bool { ->fetchAll(); } - public function selectForAnalyzeBounceMail(int $rid, string $rtbl, int $mid): array|bool { + /** + * @return array|bool + */ + public function selectForAnalyzeBounceMail(int $rid, string $rtbl, int $mid) //: array|bool + { $queryBuilder = $this->getQueryBuilder($this->table); $row = $queryBuilder diff --git a/Classes/Repository/SysDmailRepository.php b/Classes/Repository/SysDmailRepository.php index 8aab3bc8a..829232178 100644 --- a/Classes/Repository/SysDmailRepository.php +++ b/Classes/Repository/SysDmailRepository.php @@ -9,7 +9,11 @@ class SysDmailRepository extends MainRepository { protected string $table = 'sys_dmail'; - public function selectSysDmailById(int $sys_dmail_uid, int $pid): array|bool { + /** + * @return array|bool + */ + public function selectSysDmailById(int $sys_dmail_uid, int $pid) //: array|bool + { $queryBuilder = $this->getQueryBuilder($this->table); $queryBuilder ->getRestrictions() @@ -27,7 +31,11 @@ public function selectSysDmailById(int $sys_dmail_uid, int $pid): array|bool { ->fetch(); } - public function selectSysDmailsByPid(int $pid): array|bool { + /** + * @return array|bool + */ + public function selectSysDmailsByPid(int $pid) //: array|bool + { $queryBuilder = $this->getQueryBuilder($this->table); $queryBuilder ->getRestrictions() @@ -42,7 +50,11 @@ public function selectSysDmailsByPid(int $pid): array|bool { ->fetchAllAssociative(); } - public function selectForPageInfo(int $id): array|bool { + /** + * @return array|bool + */ + public function selectForPageInfo(int $id) //: array|bool + { $queryBuilder = $this->getQueryBuilder($this->table); $queryBuilder ->getRestrictions() @@ -69,7 +81,11 @@ public function selectForPageInfo(int $id): array|bool { ->fetchAll(); } - public function selectForMkeListDMail(int $id, string $sOrder, string $ascDesc): array|bool { + /** + * @return array|bool + */ + public function selectForMkeListDMail(int $id, string $sOrder, string $ascDesc) //: array|bool + { $queryBuilder = $this->getQueryBuilder($this->table); $queryBuilder diff --git a/Classes/Repository/TtAddressRepository.php b/Classes/Repository/TtAddressRepository.php index 2709ff396..51422dae2 100644 --- a/Classes/Repository/TtAddressRepository.php +++ b/Classes/Repository/TtAddressRepository.php @@ -6,7 +6,11 @@ class TtAddressRepository extends MainRepository { protected string $table = 'tt_address'; - public function selectTtAddressByUid(int $uid, string $permsClause): array|bool { + /** + * @return array|bool + */ + public function selectTtAddressByUid(int $uid, string $permsClause) //: array|bool + { $queryBuilder = $this->getQueryBuilder($this->table); return $queryBuilder From c42073d637ee64395359a13a9a7ed947f2917ce5 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sat, 5 Feb 2022 20:02:03 +0000 Subject: [PATCH 185/342] update Dmail part --- Classes/Module/DmailController.php | 7 +++---- Resources/Private/Templates/Dmail.html | 4 +++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Classes/Module/DmailController.php b/Classes/Module/DmailController.php index 7f40f72e7..a16023def 100644 --- a/Classes/Module/DmailController.php +++ b/Classes/Module/DmailController.php @@ -494,11 +494,10 @@ protected function showSteps($totalSteps) { $content = ''; for ($i = 1; $i <= $totalSteps; $i++) { - $cssClass = ($i == $this->currentStep) ? 't3-wizard-item t3-wizard-item-active' : 't3-wizard-item'; - $content .= ' ' . $i . ' '; + $cssClass = ($i == $this->currentStep) ? 't3-wizard-item-active' : ''; + $content .= ' ' . $i . ' '; } - - return '
' . $content . '
'; + return $content; } /** diff --git a/Resources/Private/Templates/Dmail.html b/Resources/Private/Templates/Dmail.html index 48f79bc10..19f3cc94e 100644 --- a/Resources/Private/Templates/Dmail.html +++ b/Resources/Private/Templates/Dmail.html @@ -6,7 +6,9 @@
- {wizardsteps} +
+ {wizardsteps} +
  From e74b4323672d9ccb735b8aa4c387a274452d5dca Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sun, 6 Feb 2022 13:32:31 +0000 Subject: [PATCH 186/342] update Dmail part --- Classes/Module/DmailController.php | 67 +++++++------------ Classes/Module/RecipientListController.php | 2 +- .../Repository/SysDmailGroupRepository.php | 30 ++++++++- 3 files changed, 54 insertions(+), 45 deletions(-) diff --git a/Classes/Module/DmailController.php b/Classes/Module/DmailController.php index a16023def..274ee8f02 100644 --- a/Classes/Module/DmailController.php +++ b/Classes/Module/DmailController.php @@ -6,6 +6,7 @@ use DirectMailTeam\DirectMail\Dmailer; use DirectMailTeam\DirectMail\DirectMailUtility; use DirectMailTeam\DirectMail\Repository\PagesRepository; +use DirectMailTeam\DirectMail\Repository\SysDmailGroupRepository; use DirectMailTeam\DirectMail\Repository\SysDmailRepository; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; @@ -1389,53 +1390,33 @@ protected function cmd_finalmail($direct_mail_row) } } - // Mail groups - $queryBuilder = $this->getQueryBuilder('sys_dmail_group'); - $statement = $queryBuilder - ->select('uid','pid','title') - ->from('sys_dmail_group') - ->where( - $queryBuilder->expr()->eq( - 'pid', - intval($this->id) - ) - ) - ->andWhere( - $queryBuilder->expr()->in( - 'sys_language_uid', - '-1, ' . $direct_mail_row['sys_language_uid'] - ) - ) - ->orderBy( - preg_replace( - '/^(?:ORDER[[:space:]]*BY[[:space:]]*)+/i', '', - trim($GLOBALS['TCA']['sys_dmail_group']['ctrl']['default_sortby']) - ) - ) - ->execute(); - + // Mail groups + $groups = GeneralUtility::makeInstance(SysDmailGroupRepository::class)->selectSysDmailGroupForFinalMail($this->id, (int)$direct_mail_row['sys_language_uid'], trim($GLOBALS['TCA']['sys_dmail_group']['ctrl']['default_sortby'])); + $opt = []; $lastGroup = null; - while (($group = $statement->fetch())) { - $result = $this->cmd_compileMailGroup([$group['uid']]); - $count = 0; - $idLists = $result['queryInfo']['id_lists']; - if (is_array($idLists['tt_address'] ?? false)) { - $count += count($idLists['tt_address']); - } - if (is_array($idLists['fe_users'] ?? false)) { - $count += count($idLists['fe_users']); - } - if (is_array($idLists['PLAINLIST'] ?? false)) { - $count += count($idLists['PLAINLIST']); - } - if (is_array($idLists[$this->userTable] ?? false)) { - $count += count($idLists[$this->userTable]); + if($groups) { + foreach($groups as $group) { + $result = $this->cmd_compileMailGroup([$group['uid']]); + $count = 0; + $idLists = $result['queryInfo']['id_lists']; + if (is_array($idLists['tt_address'] ?? false)) { + $count += count($idLists['tt_address']); + } + if (is_array($idLists['fe_users'] ?? false)) { + $count += count($idLists['fe_users']); + } + if (is_array($idLists['PLAINLIST'] ?? false)) { + $count += count($idLists['PLAINLIST']); + } + if (is_array($idLists[$this->userTable] ?? false)) { + $count += count($idLists[$this->userTable]); + } + $opt[] = ''; + $lastGroup = $group; } - $opt[] = ''; - $lastGroup = $group; } - + $groupInput = ''; // added disabled. see hook if (count($opt) === 0) { diff --git a/Classes/Module/RecipientListController.php b/Classes/Module/RecipientListController.php index 17a81fa3a..83194c29d 100644 --- a/Classes/Module/RecipientListController.php +++ b/Classes/Module/RecipientListController.php @@ -158,7 +158,7 @@ protected function showExistingRecipientLists() 'rows' => [] ]; - $rows = GeneralUtility::makeInstance(SysDmailGroupRepository::class)->selecetSysDmailGroupByPid($this->id, trim($GLOBALS['TCA']['sys_dmail_group']['ctrl']['default_sortby'])); + $rows = GeneralUtility::makeInstance(SysDmailGroupRepository::class)->selectSysDmailGroupByPid($this->id, trim($GLOBALS['TCA']['sys_dmail_group']['ctrl']['default_sortby'])); foreach($rows as $row) { $result = $this->cmd_compileMailGroup(intval($row['uid'])); diff --git a/Classes/Repository/SysDmailGroupRepository.php b/Classes/Repository/SysDmailGroupRepository.php index a1584637e..2dbfa48ed 100644 --- a/Classes/Repository/SysDmailGroupRepository.php +++ b/Classes/Repository/SysDmailGroupRepository.php @@ -12,7 +12,7 @@ class SysDmailGroupRepository extends MainRepository { /** * @return array|bool */ - public function selecetSysDmailGroupByPid(int $pid, string $defaultSortBy) //: array|bool + public function selectSysDmailGroupByPid(int $pid, string $defaultSortBy) //: array|bool { $queryBuilder = $this->getQueryBuilder($this->table); $queryBuilder @@ -34,4 +34,32 @@ public function selecetSysDmailGroupByPid(int $pid, string $defaultSortBy) //: a ->execute() ->fetchAll(); } + + /** + * @return array|bool + */ + public function selectSysDmailGroupForFinalMail(int $pid, int $sysLanguageUid, string $defaultSortBy) //: array|bool + { + $queryBuilder = $this->getQueryBuilder($this->table); + + return $queryBuilder->select('uid','pid','title') + ->from($this->table) + ->where( + $queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($pid, \PDO::PARAM_INT)) + ) + ->andWhere( + $queryBuilder->expr()->in( + 'sys_language_uid', + '-1, ' . $sysLanguageUid + ) + ) + ->orderBy( + preg_replace( + '/^(?:ORDER[[:space:]]*BY[[:space:]]*)+/i', '', + $defaultSortBy + ) + ) + ->execute() + ->fetchAll(); + } } \ No newline at end of file From 10d27d7be27d40ae64d4e2fdb9604138015e5024 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sun, 6 Feb 2022 14:36:49 +0000 Subject: [PATCH 187/342] update Dmail part --- Classes/Module/DmailController.php | 201 ++++++++++++------ .../Repository/SysDmailGroupRepository.php | 26 +++ Classes/Repository/TtAddressRepository.php | 22 ++ 3 files changed, 184 insertions(+), 65 deletions(-) diff --git a/Classes/Module/DmailController.php b/Classes/Module/DmailController.php index 274ee8f02..d448f2750 100644 --- a/Classes/Module/DmailController.php +++ b/Classes/Module/DmailController.php @@ -8,10 +8,12 @@ use DirectMailTeam\DirectMail\Repository\PagesRepository; use DirectMailTeam\DirectMail\Repository\SysDmailGroupRepository; use DirectMailTeam\DirectMail\Repository\SysDmailRepository; +use DirectMailTeam\DirectMail\Repository\TtAddressRepository; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider; use TYPO3\CMS\Backend\Routing\PreviewUriBuilder; +use TYPO3\CMS\Backend\Routing\UriBuilder; use TYPO3\CMS\Backend\Template\ModuleTemplate; use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Core\Core\Environment; @@ -1074,66 +1076,32 @@ protected function renderRecordDetailsTable(array $row) protected function cmd_testmail() { $theOutput = ''; - + if ($this->params['test_tt_address_uids'] ?? false) { - $intList = implode(',', GeneralUtility::intExplode(',', $this->params['test_tt_address_uids'])); - $queryBuilder = $this->getQueryBuilder('tt_address'); - $res = $queryBuilder - ->select('tt_address.*') - ->from('tt_address') - ->leftJoin( - 'tt_address', - 'pages', - 'pages', - $queryBuilder->expr()->eq('pages.uid', $queryBuilder->quoteIdentifier('tt_address.pid')) - ) - ->add('where','tt_address.uid IN (' . $intList . ')' . - ' AND ' . $this->perms_clause ) - ->execute() - ->fetchAll(); - - $msg = $this->getLanguageService()->getLL('testmail_individual_msg') . '

'; - - $ids = []; - - foreach ($res as $row) { - $ids[] = $row['uid']; - } + $intList = implode(',', GeneralUtility::intExplode(',', $this->params['test_tt_address_uids'])); + $res = GeneralUtility::makeInstance(TtAddressRepository::class)->selectTtAddressForTestmail($intList, $this->perms_clause); + + $ids = []; - $msg .= $this->getRecordList(DirectMailUtility::fetchRecordsListValues($ids, 'tt_address'), 'tt_address', 1, 1); + foreach ($res as $row) { + $ids[] = $row['uid']; + } + + $msg = $this->getLanguageService()->getLL('testmail_individual_msg') . '

'; + $msg .= $this->getRecordList(DirectMailUtility::fetchRecordsListValues($ids, 'tt_address'), 'tt_address', 1, 1); - $theOutput.= '

' . $this->getLanguageService()->getLL('testmail_individual') . '

' . - $msg; - - $theOutput.= '
'; + $theOutput .= '

' . $this->getLanguageService()->getLL('testmail_individual') . '

' . $msg; + $theOutput .= '
'; } if ($this->params['test_dmail_group_uids'] ?? false) { $intList = implode(',', GeneralUtility::intExplode(',', $this->params['test_dmail_group_uids'])); - - $queryBuilder = $this->getQueryBuilder('sys_dmail_group'); - $queryBuilder - ->getRestrictions() - ->removeAll() - ->add(GeneralUtility::makeInstance(DeletedRestriction::class)); - $res = $queryBuilder - ->select('sys_dmail_group.*') - ->from('sys_dmail_group') - ->leftJoin( - 'sys_dmail_group', - 'pages', - 'pages', - $queryBuilder->expr()->eq('sys_dmail_group.pid', $queryBuilder->quoteIdentifier('pages.uid')) - ) - ->add('where','sys_dmail_group.uid IN (' . $intList . ')' . - ' AND ' . $this->perms_clause ) - ->execute() - ->fetchAll(); - - $msg = $this->getLanguageService()->getLL('testmail_mailgroup_msg') . '

'; + $res = GeneralUtility::makeInstance(SysDmailGroupRepository::class)->selectSysDmailGroupForTestmail($intList, $this->perms_clause); + + $msg = $this->getLanguageService()->getLL('testmail_mailgroup_msg') . '

'; - foreach ($res as $row) { - $moduleUrl = $this->buildUriFromRoute( + foreach ($res as $row) { + $moduleUrl = $this->buildUriFromRoute( $this->moduleName, [ 'id' => $this->id, @@ -1152,28 +1120,53 @@ protected function cmd_testmail() ' . $this->cmd_displayMailGroup_test($result) . ' '; - } + } - $theOutput.= '

' . $this->getLanguageService()->getLL('testmail_mailgroup') . '

' . - $msg; - $theOutput.= '
'; + $theOutput .= '

' . $this->getLanguageService()->getLL('testmail_mailgroup') . '

' . $msg; + $theOutput .= '
'; } $msg = ''; - $msg.= $this->getLanguageService()->getLL('testmail_simple_msg') . '

'; - $msg.= '

'; + $msg .= $this->getLanguageService()->getLL('testmail_simple_msg') . '

'; + $msg .= '

'; - $msg.= ''; - $msg.= ''; - $msg.= ''; - $msg.= ''; + $msg .= ''; + $msg .= ''; + $msg .= ''; + $msg .= ''; - $theOutput.= '

' . $this->getLanguageService()->getLL('testmail_simple') . '

' . - $msg; + $theOutput .= '

' . $this->getLanguageService()->getLL('testmail_simple') . '

' . $msg; $this->noView = 1; return $theOutput; } + + /** + * Display the test mail group, which configured in the configuration module + * + * @param array $result Lists of the recipient IDs based on directmail DB record + * + * @return string List of the recipient (in HTML) + */ + public function cmd_displayMailGroup_test($result) + { + $idLists = $result['queryInfo']['id_lists']; + $out = ''; + if (is_array($idLists['tt_address'] ?? false)) { + $out .= $this->getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address'); + } + if (is_array($idLists['fe_users'] ?? false)) { + $out .= $this->getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users'); + } + if (is_array($idLists['PLAINLIST'] ?? false)) { + $out.=$this->getRecordList($idLists['PLAINLIST'], 'default'); + } + if (is_array($idLists[$this->userTable] ?? false)) { + $out.=$this->getRecordList(DirectMailUtility::fetchRecordsListValues($idLists[$this->userTable], $this->userTable), $this->userTable); + } + + return $out; + } /** * Sending the mail. @@ -1236,7 +1229,7 @@ protected function cmd_send_mail($row) // step 4, sending test personalized test emails // setting Testmail flag $htmlmail->testmail = $this->params['testmail']; - + if ($this->tt_address_uid) { // personalized to tt_address $queryBuilder = $this->getQueryBuilder('tt_address'); @@ -1249,6 +1242,7 @@ protected function cmd_send_mail($row) ->execute() ->fetchAll(); + if (!empty($res)) { foreach ($res as $recipRow) { $recipRow = Dmailer::convertFields($recipRow); @@ -1362,6 +1356,83 @@ protected function cmd_send_mail($row) ); } } + + /** + * Show the recipient info and a link to edit it + * + * @param array $listArr List of recipients ID + * @param string $table Table name + * @param bool|int $editLinkFlag If set, edit link is showed + * @param bool|int $testMailLink If set, send mail link is showed + * + * @return string HTML, the table showing the recipient's info + * @throws RouteNotFoundException If the named route doesn't exist + */ + public function getRecordList(array $listArr, $table, $editLinkFlag=1, $testMailLink=0) + { + $count = 0; + $lines = []; + $out = ''; + if (is_array($listArr)) { + $count = count($listArr); + /** @var UriBuilder $uriBuilder */ + $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); + foreach ($listArr as $row) { + $tableIcon = ''; + $editLink = ''; + $testLink = ''; + + if ($row['uid']) { + $tableIcon = '' . $this->iconFactory->getIconForRecord($table, $row, Icon::SIZE_SMALL) . ''; + if ($editLinkFlag) { + $requestUri = GeneralUtility::getIndpEnv('REQUEST_URI') . '&CMD=send_test&sys_dmail_uid=' . $this->sys_dmail_uid . '&pages_uid=' . $this->pages_uid; + + $params = [ + 'edit' => [ + $table => [ + $row['uid'] => 'edit', + ] + ], + 'returnUrl' => $requestUri + ]; + + $editOnClick = DirectMailUtility::getEditOnClickLink($params); + + $editLink = '' . + $this->iconFactory->getIcon('actions-open', Icon::SIZE_SMALL) . + ''; + } + + if ($testMailLink) { + $moduleUrl = $uriBuilder->buildUriFromRoute( + $this->moduleName, + [ + 'id' => $this->id, + 'sys_dmail_uid' => $this->sys_dmail_uid, + 'CMD' => 'send_mail_test', + 'tt_address_uid' => $row['uid'] + ] + ); + $testLink = '' . htmlspecialchars($row['email']) . ''; + } else { + $testLink = htmlspecialchars($row['email']); + } + } + + $lines[] = ' + ' . $tableIcon . ' + ' . $editLink . ' + ' . $testLink . ' + ' . htmlspecialchars($row['name']) . ' + '; + } + } + if (count($lines)) { + $out= $this->getLanguageService()->getLL('dmail_number_records') . '' . $count . '
'; + $out.='' . implode(LF, $lines) . '
'; + } + return $out; + } /** * Shows the final steps of the process. Show recipient list and calendar library diff --git a/Classes/Repository/SysDmailGroupRepository.php b/Classes/Repository/SysDmailGroupRepository.php index 2dbfa48ed..71750c91a 100644 --- a/Classes/Repository/SysDmailGroupRepository.php +++ b/Classes/Repository/SysDmailGroupRepository.php @@ -62,4 +62,30 @@ public function selectSysDmailGroupForFinalMail(int $pid, int $sysLanguageUid, s ->execute() ->fetchAll(); } + + /** + * @return array|bool + */ + public function selectSysDmailGroupForTestmail(string $intList, string $permsClause) //: array|bool + { + $queryBuilder = $this->getQueryBuilder($this->table); + $queryBuilder + ->getRestrictions() + ->removeAll() + ->add(GeneralUtility::makeInstance(DeletedRestriction::class)); + + return $queryBuilder + ->select($this->table.'.*') + ->from($this->table) + ->leftJoin( + $this->table, + 'pages', + 'pages', + $queryBuilder->expr()->eq($this->table.'.pid', $queryBuilder->quoteIdentifier('pages.uid')) + ) + ->add('where', $this->table.'.uid IN (' . $intList . ')' . + ' AND ' . $permsClause ) + ->execute() + ->fetchAll(); + } } \ No newline at end of file diff --git a/Classes/Repository/TtAddressRepository.php b/Classes/Repository/TtAddressRepository.php index 51422dae2..529c5e513 100644 --- a/Classes/Repository/TtAddressRepository.php +++ b/Classes/Repository/TtAddressRepository.php @@ -30,4 +30,26 @@ public function selectTtAddressByUid(int $uid, string $permsClause) //: array|bo ->execute() ->fetchAll(); } + + /** + * @return array|bool + */ + public function selectTtAddressForTestmail(string $intList, string $permsClause) //: array|bool + { + $queryBuilder = $this->getQueryBuilder($this->table); + + return $queryBuilder + ->select($this->table.'.*') + ->from($this->table) + ->leftJoin( + $this->table, + 'pages', + 'pages', + $queryBuilder->expr()->eq('pages.uid', $queryBuilder->quoteIdentifier($this->table.'.pid')) + ) + ->add('where', $this->table.'.uid IN (' . $intList . ')' . + ' AND ' . $permsClause) + ->execute() + ->fetchAll(); + } } \ No newline at end of file From 5b3bbb384a61d6f7081e460284e2943508598db6 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sun, 6 Feb 2022 15:36:38 +0000 Subject: [PATCH 188/342] update Dmail part --- Classes/Module/DmailController.php | 29 +++++++---------------- Classes/Repository/SysDmailRepository.php | 19 +++++++++++++++ 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/Classes/Module/DmailController.php b/Classes/Module/DmailController.php index d448f2750..ffea69557 100644 --- a/Classes/Module/DmailController.php +++ b/Classes/Module/DmailController.php @@ -961,7 +961,8 @@ protected function compileQuickMail(array $row, $message) if (!$message || !$htmlmail->theParts['plain']['content']) { $errorMsg .= ' ' . $this->getLanguageService()->getLL('dmail_no_plain_content') . ''; - } elseif (!strstr(base64_decode($htmlmail->theParts['plain']['content']), ' + + +

+ + + + + + + + + + + + + + + + + + + {formcontent.theOutput} From 00d98433d493f166ad94679a6c6ac9a82ce3d40e Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Wed, 17 Aug 2022 11:13:30 +0200 Subject: [PATCH 261/342] move html from Importer to 'RecipientList' template --- Classes/Importer.php | 39 ++++++------------- .../Private/Templates/RecipientList.html | 32 ++++++++++++++- 2 files changed, 42 insertions(+), 29 deletions(-) diff --git a/Classes/Importer.php b/Classes/Importer.php index 1449ee1d9..6a248c67c 100644 --- a/Classes/Importer.php +++ b/Classes/Importer.php @@ -123,7 +123,9 @@ public function displayImport() 'all_html' => false, 'mapping_cats' => [], 'show_add_cat' => false, - 'add_cat' => false + 'add_cat' => false, + 'error' => [], + 'table' => [] ] ]; @@ -202,10 +204,10 @@ public function displayImport() $newMap = ArrayUtility::removeArrayEntryByValue(array_unique($map), 'noMap'); if (empty($newMap)) { $error[] = 'noMap'; - } elseif (!in_array('email', $map)) { + } + elseif (!in_array('email', $map)) { $error[] = 'email'; } - if ($error) { $stepCurrent = 'mapping'; } @@ -298,7 +300,8 @@ public function displayImport() $output['mapping']['update_unique'] = $this->indata['update_unique']; $output['mapping']['record_unique'] = $this->indata['record_unique']; $output['mapping']['all_html'] = !$this->indata['all_html'] ? false : true; - + $output['mapping']['error'] = $error; + // show charset selector $cs = array_unique(array_values(mb_list_encodings())); $charSets = []; @@ -351,37 +354,18 @@ public function displayImport() reset($csv_firstRow); reset($csvData); - $tblLines = []; - $tblLines[] = [ - $this->getLanguageService()->getLL('mailgroup_import_mapping_number'), - $this->getLanguageService()->getLL('mailgroup_import_mapping_description'), - $this->getLanguageService()->getLL('mailgroup_import_mapping_mapping'), - $this->getLanguageService()->getLL('mailgroup_import_mapping_value') - ]; for ($i = 0; $i < (count($csv_firstRow)); $i++) { // example CSV $exampleLines = []; for ($j = 0; $j < (count($csvData)); $j++) { $exampleLines[] = [$csvData[$j][$i]]; } - $tblLines[] = [ - $i+1, - $csv_firstRow[$i], - $this->makeDropdown('CSV_IMPORT[map][' . ($i) . ']', $mapFields, $this->indata['map'][$i]), - $this->formatTable($exampleLines, ['nowrap'], 0, [0], 'border="0" cellpadding="0" cellspacing="0" class="table table-striped table-hover" style="width:100%; border:0px; margin:0px;"') + $output['mapping']['table'][] = [ + 'mapping_description' => $csv_firstRow[$i], + 'mapping_mapping' => $this->makeDropdown('CSV_IMPORT[map][' . ($i) . ']', $mapFields, $this->indata['map'][$i]), + 'mapping_value' => $this->formatTable($exampleLines, ['nowrap'], 0, [0], 'border="0" cellpadding="0" cellspacing="0" class="table table-striped table-hover" style="width:100%; border:0px; margin:0px;"') ]; } - - if ($error) { - $out .= '

' . $this->getLanguageService()->getLL('mailgroup_import_mapping_error') . '

'; - $out .= $this->getLanguageService()->getLL('mailgroup_import_mapping_error_detail') . '
    '; - foreach ($error as $errorDetail) { - $out .= '
  • ' . $this->getLanguageService()->getLL('mailgroup_import_mapping_error_' . $errorDetail) . '
  • '; - } - $out.= '
'; - } - - $out .= $this->formatTable($tblLines, ['nowrap', 'nowrap', 'nowrap', 'nowrap'], 1, [0, 0, 1, 1], 'border="0" cellpadding="0" cellspacing="0" class="table table-striped table-hover"'); // get categories $temp['value'] = BackendUtility::getPagesTSconfig($this->parent->getId())['TCEFORM.']['sys_dmail_group.']['select_categories.']['PAGE_TSCONFIG_IDLIST'] ?? null; @@ -404,7 +388,6 @@ public function displayImport() } } } - break; case 'import': diff --git a/Resources/Private/Templates/RecipientList.html b/Resources/Private/Templates/RecipientList.html index 27a423abe..b640ad57b 100644 --- a/Resources/Private/Templates/RecipientList.html +++ b/Resources/Private/Templates/RecipientList.html @@ -225,9 +225,39 @@

{formcontent.output.subtitle}

+ +

+
+
    + +
  • +
    +
+

- + + + + + + + + + + + + + + + + + + + + +
+
{iterator.cycle}{row.mapping_description}{row.mapping_mapping}{row.mapping_value}



From 933dfaba525555b41eb038540ccef365a5e0941e Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Wed, 17 Aug 2022 13:13:07 +0200 Subject: [PATCH 262/342] use file id instead of the path part --- Classes/Importer.php | 74 ++++++++++++------- .../Private/Templates/RecipientList.html | 20 +++-- 2 files changed, 59 insertions(+), 35 deletions(-) diff --git a/Classes/Importer.php b/Classes/Importer.php index 6a248c67c..f5d33093b 100644 --- a/Classes/Importer.php +++ b/Classes/Importer.php @@ -26,6 +26,7 @@ use TYPO3\CMS\Core\DataHandling\DataHandler; use TYPO3\CMS\Core\Localization\LanguageService; use TYPO3\CMS\Core\Resource\DuplicationBehavior; +use TYPO3\CMS\Core\Resource\ResourceFactory; use TYPO3\CMS\Core\Utility\ArrayUtility; use TYPO3\CMS\Core\Utility\File\ExtendedFileUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -92,7 +93,8 @@ public function displayImport() 'csv' => '', 'target' => '', 'target_disabled' => '', - 'newFile' => '' + 'newFile' => '', + 'newFileUid' => 0 ], 'conf' => [ 'show' => false, @@ -105,12 +107,14 @@ public function displayImport() 'update_unique' => false, 'record_unique' => '', 'newFile' => '', + 'newFileUid' => 0, 'disableInput' => false ], 'mapping' => [ 'show' => false, 'charset' => '', 'newFile' => '', + 'newFileUid' => 0, 'storage' => '', 'remove_existing' => false, 'first_fieldname' => false, @@ -165,34 +169,41 @@ public function displayImport() if (empty($this->indata['csv']) && !empty($_FILES['upload_1']['name'])) { $this->indata['newFile'] = $this->checkUpload(); - // TYPO3 6.0 returns an object... if (is_object($this->indata['newFile'][0])) { $storageConfig = $this->indata['newFile'][0]->getStorage()->getConfiguration(); + $this->indata['newFileUid'] = $this->indata['newFile'][0]->getUid(); $this->indata['newFile'] = rtrim($storageConfig['basePath'], '/') . '/' . ltrim($this->indata['newFile'][0]->getIdentifier(), '/'); } - } elseif (!empty($this->indata['csv']) && empty($_FILES['upload_1']['name'])) { + } + elseif (!empty($this->indata['csv']) && empty($_FILES['upload_1']['name'])) { if (((strpos($currentFileInfo['file'], 'import') === false) ? 0 : 1) && ($currentFileInfo['realFileext'] === 'txt')) { // do nothing - } else { + } + else { unset($this->indata['newFile']); + unset($this->indata['newFileUid']); } } - + $stepCurrent = ''; if ($this->indata['back'] ?? false) { $stepCurrent = $step['back']; - } elseif ($this->indata['next'] ?? false) { + } + elseif ($this->indata['next'] ?? false) { $stepCurrent = $step['next']; - } elseif ($this->indata['update'] ?? false) { + } + elseif ($this->indata['update'] ?? false) { $stepCurrent = 'mapping'; } if (strlen($this->indata['csv'] ?? '') > 0) { $this->indata['mode'] = 'csv'; $this->indata['newFile'] = $this->writeTempFile(); - } elseif (!empty($this->indata['newFile'])) { + } + elseif (!empty($this->indata['newFile'])) { $this->indata['mode'] = 'file'; - } else { + } + else { unset($stepCurrent); } @@ -218,6 +229,8 @@ public function displayImport() case 'conf': $output['conf']['show'] = true; $output['conf']['newFile'] = $this->indata['newFile']; + $output['conf']['newFileUid'] = $this->indata['newFileUid']; + $pagePermsClause3 = $beUser->getPagePermsClause(3); $pagePermsClause1 = $beUser->getPagePermsClause(1); // get list of sysfolder @@ -252,8 +265,6 @@ public function displayImport() ]; $output['conf']['disableInput'] = $this->params['inputDisable'] == 1 ? true : false; - - ($this->params['inputDisable'] == 1) ? $disableInput = 'disabled="disabled"' : $disableInput = ''; // show configuration $output['subtitle'] = $this->getLanguageService()->getLL('mailgroup_import_header_conf'); @@ -268,10 +279,10 @@ public function displayImport() $output['conf']['first_fieldname'] = !$this->indata['first_fieldname'] ? false : true; // csv separator - $output['conf']['delimiter'] = $this->makeDropdown('CSV_IMPORT[delimiter]', $optDelimiter, $this->indata['delimiter'], $disableInput); + $output['conf']['delimiter'] = $this->makeDropdown('CSV_IMPORT[delimiter]', $optDelimiter, $this->indata['delimiter'], $output['conf']['disableInput']); // csv encapsulation - $output['conf']['encapsulation'] = $this->makeDropdown('CSV_IMPORT[encapsulation]', $optEncap, $this->indata['encapsulation'], $disableInput); + $output['conf']['encapsulation'] = $this->makeDropdown('CSV_IMPORT[encapsulation]', $optEncap, $this->indata['encapsulation'], $output['conf']['disableInput']); // import only valid email $output['conf']['valid_email'] = !$this->indata['valid_email'] ? false : true; @@ -283,13 +294,14 @@ public function displayImport() $output['conf']['update_unique'] = !$this->indata['update_unique'] ? false : true; // which field should be use to show uniqueness of the records - $output['conf']['record_unique'] = $this->makeDropdown('CSV_IMPORT[record_unique]', $optUnique, $this->indata['record_unique'], $disableInput); + $output['conf']['record_unique'] = $this->makeDropdown('CSV_IMPORT[record_unique]', $optUnique, $this->indata['record_unique'], $output['conf']['disableInput']); break; case 'mapping': $output['mapping']['show'] = true; $output['mapping']['newFile'] = $this->indata['newFile']; + $output['mapping']['newFileUid'] = $this->indata['newFileUid']; $output['mapping']['storage'] = $this->indata['storage']; $output['mapping']['remove_existing'] = $this->indata['remove_existing']; $output['mapping']['first_fieldname'] = $this->indata['first_fieldname']; @@ -432,25 +444,20 @@ public function displayImport() case 'startImport': // starting import & show errors // read csv + $csvData = $this->readCSV(); if ($this->indata['first_fieldname']) { - // read csv - $csvData = $this->readCSV(); $csvData = array_slice($csvData, 1); - } else { - // read csv - $csvData = $this->readCSV(); } // show not imported record and reasons, $result = $this->doImport($csvData); $output['subtitle'] = $this->getLanguageService()->getLL('mailgroup_import_done'); - $defaultOrder = ['new','update','invalid_email','double']; + $defaultOrder = ['new', 'update', 'invalid_email', 'double']; + $resultOrder = []; if (!empty($this->params['resultOrder'])) { $resultOrder = GeneralUtility::trimExplode(',', $this->params['resultOrder']); - } else { - $resultOrder = []; } $diffOrder = array_diff($defaultOrder, $resultOrder); @@ -858,12 +865,17 @@ public function makeHidden($name, $value='') */ public function readCSV() { - ini_set('auto_detect_line_endings', true); $mydata = []; - $handle = fopen($this->indata['newFile'], 'r'); - if($handle === false) { + + if((int)$this->indata['newFileUid'] < 1) { return $mydata; } + + $publicPath = Environment::getPublicPath(); + $resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class); + $file = $resourceFactory->getFileObject((int)$this->indata['newFileUid']); + $fileAbsolutePath = Environment::getPublicPath() . '/' . str_replace('//', '/', $file->getStorage()->getConfiguration()['basePath'] . $file->getProperty('identifier')); + $delimiter = $this->indata['delimiter']; $encaps = $this->indata['encapsulation']; $delimiter = ($delimiter === 'comma') ? ',' : $delimiter; @@ -872,6 +884,13 @@ public function readCSV() $delimiter = ($delimiter === 'tab') ? "\t" : $delimiter; $encaps = ($encaps === 'singleQuote') ? "'" : $encaps; $encaps = ($encaps === 'doubleQuote') ? '"' : $encaps; + + ini_set('auto_detect_line_endings', true); + $handle = fopen($fileAbsolutePath, 'r'); + if($handle === false) { + return $mydata; + } + while (($data = fgetcsv($handle, 10000, $delimiter, $encaps)) !== false) { // remove empty line in csv if ((count($data) >= 1)) { @@ -1098,7 +1117,7 @@ public function writeTempFile() /** * Checks if a file has been uploaded and returns the complete physical fileinfo if so. * - * @return string the complete physical file name, including path info. + * @return array \TYPO3\CMS\Core\Resource\File the complete physical file name, including path info. * @throws \Exception */ public function checkUpload() @@ -1127,7 +1146,8 @@ public function checkUpload() if ($httpHost != $refInfo['host'] && !$GLOBALS['TYPO3_CONF_VARS']['SYS']['doNotCheckReferer']) { $this->fileProcessor->writeLog(0, 2, 1, 'Referer host "%s" and server host "%s" did not match!', [$refInfo['host'], $httpHost]); - } else { + } + else { $this->fileProcessor->start($file); $this->fileProcessor->setExistingFilesConflictMode(DuplicationBehavior::cast(DuplicationBehavior::REPLACE)); $newfile = $this->fileProcessor->func_upload($file['upload']['1']); diff --git a/Resources/Private/Templates/RecipientList.html b/Resources/Private/Templates/RecipientList.html index b640ad57b..e9c99b0f0 100644 --- a/Resources/Private/Templates/RecipientList.html +++ b/Resources/Private/Templates/RecipientList.html @@ -117,13 +117,15 @@

{formcontent.output.subtitle}




- {formcontent.output.upload.csv}

- + + {formcontent.output.upload.csv}

+ +
@@ -203,13 +205,14 @@

{formcontent.output.subtitle}


- - - + + + +
@@ -304,13 +307,14 @@



- - - + + + + From 394b2a0ee7d93de78a3a2d7ec5d3aaa71350777a Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Wed, 17 Aug 2022 13:37:46 +0200 Subject: [PATCH 263/342] fix value of charset --- Classes/Importer.php | 2 ++ Resources/Private/Templates/RecipientList.html | 4 +--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Classes/Importer.php b/Classes/Importer.php index f5d33093b..71e089f41 100644 --- a/Classes/Importer.php +++ b/Classes/Importer.php @@ -113,6 +113,7 @@ public function displayImport() 'mapping' => [ 'show' => false, 'charset' => '', + 'charsetSelected' => '', 'newFile' => '', 'newFileUid' => 0, 'storage' => '', @@ -326,6 +327,7 @@ public function displayImport() } $output['subtitle'] = $this->getLanguageService()->getLL('mailgroup_import_mapping_charset'); $output['mapping']['charset'] = $this->makeDropdown('CSV_IMPORT[charset]', $charSets, $this->indata['charset']); + $output['mapping']['charsetSelected'] = $this->indata['charset']; // show mapping form if ($this->indata['first_fieldname']) { diff --git a/Resources/Private/Templates/RecipientList.html b/Resources/Private/Templates/RecipientList.html index e9c99b0f0..0c7623982 100644 --- a/Resources/Private/Templates/RecipientList.html +++ b/Resources/Private/Templates/RecipientList.html @@ -302,8 +302,6 @@

- -

@@ -326,7 +324,7 @@

- + {formcontent.theOutput} From b083c5b42db16b7b4fccdadf980f603875150a2c Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Wed, 17 Aug 2022 16:15:24 +0200 Subject: [PATCH 264/342] move html from Importer to 'RecipientList' template --- Classes/Importer.php | 156 ++++++++++-------- .../Private/Templates/RecipientList.html | 56 ++++++- 2 files changed, 144 insertions(+), 68 deletions(-) diff --git a/Classes/Importer.php b/Classes/Importer.php index 71e089f41..df3c33b0b 100644 --- a/Classes/Importer.php +++ b/Classes/Importer.php @@ -131,6 +131,26 @@ public function displayImport() 'add_cat' => false, 'error' => [], 'table' => [] + ], + 'startImport' => [ + 'show' => false, + 'charset' => '', + 'charsetSelected' => '', + 'newFile' => '', + 'newFileUid' => 0, + 'storage' => '', + 'remove_existing' => false, + 'first_fieldname' => false, + 'delimiter' => '', + 'encapsulation' => '', + 'valid_email' => false, + 'remove_dublette' => false, + 'update_unique' => false, + 'record_unique' => '', + 'all_html' => false, + 'hiddenMap' => [], + 'hiddenCat' => [], + 'tables' => [] ] ]; @@ -326,8 +346,8 @@ public function displayImport() $this->indata['charset'] = 'ISO-8859-1'; } $output['subtitle'] = $this->getLanguageService()->getLL('mailgroup_import_mapping_charset'); - $output['mapping']['charset'] = $this->makeDropdown('CSV_IMPORT[charset]', $charSets, $this->indata['charset']); $output['mapping']['charsetSelected'] = $this->indata['charset']; + $output['mapping']['charset'] = $this->makeDropdown('CSV_IMPORT[charset]', $charSets, $this->indata['charset']); // show mapping form if ($this->indata['first_fieldname']) { @@ -404,46 +424,63 @@ public function displayImport() } break; - case 'import': +// case 'import': // show import messages - $output['subtitle'] = $this->getLanguageService()->getLL('mailgroup_import_ready_import'); +// $output['subtitle'] = $this->getLanguageService()->getLL('mailgroup_import_ready_import'); - $out .= $this->getLanguageService()->getLL('mailgroup_import_ready_import_label') . '

'; +// $out .= $this->getLanguageService()->getLL('mailgroup_import_ready_import_label') . '

'; - $out .= ' - ' . - $this->makeHidden([ - 'cmd' => 'displayImport', - 'importStep[next]' => 'startImport', - 'importStep[back]' => 'mapping', +// $out .= ' +// ' . +// $this->makeHidden([ +// 'cmd' => 'displayImport', +// 'importStep[next]' => 'startImport', +// 'importStep[back]' => 'mapping', - 'CSV_IMPORT[newFile]' => $this->indata['newFile'], - 'CSV_IMPORT[storage]' => $this->indata['storage'], - 'CSV_IMPORT[remove_existing]' => $this->indata['remove_existing'], - 'CSV_IMPORT[first_fieldname]' => $this->indata['first_fieldname'], - 'CSV_IMPORT[delimiter]' => $this->indata['delimiter'], - 'CSV_IMPORT[encapsulation]' => $this->indata['encapsulation'], - 'CSV_IMPORT[valid_email]' => $this->indata['valid_email'], - 'CSV_IMPORT[remove_dublette]' => $this->indata['remove_dublette'], - 'CSV_IMPORT[update_unique]' => $this->indata['update_unique'], - 'CSV_IMPORT[record_unique]' => $this->indata['record_unique'], - 'CSV_IMPORT[all_html]' => $this->indata['all_html'], - 'CSV_IMPORT[add_cat]' => $this->indata['add_cat'], - 'CSV_IMPORT[charset]' => $this->indata['charset'], - ]); - $hiddenMapped = []; - foreach ($this->indata['map'] as $fieldNr => $fieldMapped) { - $hiddenMapped[] = $this->makeHidden('CSV_IMPORT[map][' . $fieldNr . ']', $fieldMapped); - } - if (is_array($this->indata['cat'])) { - foreach ($this->indata['cat'] as $k => $catUid) { - $hiddenMapped[] = $this->makeHidden('CSV_IMPORT[cat][' . $k . ']', $catUid); - } - } - $out.=implode('', $hiddenMapped); - break; +// 'CSV_IMPORT[newFile]' => $this->indata['newFile'], +// 'CSV_IMPORT[storage]' => $this->indata['storage'], +// 'CSV_IMPORT[remove_existing]' => $this->indata['remove_existing'], +// 'CSV_IMPORT[first_fieldname]' => $this->indata['first_fieldname'], +// 'CSV_IMPORT[delimiter]' => $this->indata['delimiter'], +// 'CSV_IMPORT[encapsulation]' => $this->indata['encapsulation'], +// 'CSV_IMPORT[valid_email]' => $this->indata['valid_email'], +// 'CSV_IMPORT[remove_dublette]' => $this->indata['remove_dublette'], +// 'CSV_IMPORT[update_unique]' => $this->indata['update_unique'], +// 'CSV_IMPORT[record_unique]' => $this->indata['record_unique'], +// 'CSV_IMPORT[all_html]' => $this->indata['all_html'], +// 'CSV_IMPORT[add_cat]' => $this->indata['add_cat'], +// 'CSV_IMPORT[charset]' => $this->indata['charset'], +// ]); +// $hiddenMapped = []; +// foreach ($this->indata['map'] as $fieldNr => $fieldMapped) { +// $hiddenMapped[] = $this->makeHidden('CSV_IMPORT[map][' . $fieldNr . ']', $fieldMapped); +// } +// if (is_array($this->indata['cat'])) { +// foreach ($this->indata['cat'] as $k => $catUid) { +// $hiddenMapped[] = $this->makeHidden('CSV_IMPORT[cat][' . $k . ']', $catUid); +// } +// } +// $out .= implode('', $hiddenMapped); +// break; case 'startImport': + $output['startImport']['show'] = true; + + $output['startImport']['charsetSelected'] = $this->indata['charset']; + $output['startImport']['newFile'] = $this->indata['newFile']; + $output['startImport']['newFileUid'] = $this->indata['newFileUid']; + $output['startImport']['storage'] = $this->indata['storage']; + $output['startImport']['remove_existing'] = $this->indata['remove_existing']; + $output['startImport']['first_fieldname'] = $this->indata['first_fieldname']; + $output['startImport']['delimiter'] = $this->indata['delimiter']; + $output['startImport']['encapsulation'] = $this->indata['encapsulation']; + $output['startImport']['valid_email'] = $this->indata['valid_email']; + $output['startImport']['remove_dublette'] = $this->indata['remove_dublette']; + $output['startImport']['update_unique'] = $this->indata['update_unique']; + $output['startImport']['record_unique'] = $this->indata['record_unique']; + $output['startImport']['all_html'] = !$this->indata['all_html'] ? false : true; + $output['startImport']['error'] = $error; + // starting import & show errors // read csv $csvData = $this->readCSV(); @@ -455,55 +492,44 @@ public function displayImport() $result = $this->doImport($csvData); $output['subtitle'] = $this->getLanguageService()->getLL('mailgroup_import_done'); - $defaultOrder = ['new', 'update', 'invalid_email', 'double']; - $resultOrder = []; if (!empty($this->params['resultOrder'])) { $resultOrder = GeneralUtility::trimExplode(',', $this->params['resultOrder']); } + $defaultOrder = ['new', 'update', 'invalid_email', 'double']; $diffOrder = array_diff($defaultOrder, $resultOrder); $endOrder = array_merge($resultOrder, $diffOrder); foreach ($endOrder as $order) { - $tblLines = []; - $tblLines[] = [$this->getLanguageService()->getLL('mailgroup_import_report_' . $order)]; + $rowsTable = []; if (is_array($result[$order])) { - foreach ($result[$order] as $k => $v) { + foreach ($result[$order] as $v) { $mapKeys = array_keys($v); - $tblLines[] = [$k+1, $v[$mapKeys[0]], $v['email']]; + $rowsTable[] = [ + 'val' => $v[$mapKeys[0]], + 'email' => $v['email'] + ]; } } - $out .= $this->formatTable($tblLines, ['nowrap', 'first' => 'colspan="3"'], 1, [1]); + + $output['startImport']['tables'][] = [ + 'header' => $this->getLanguageService()->getLL('mailgroup_import_report_' . $order), + 'rows' => $rowsTable + ]; } // back button - $out .= $this->makeHidden([ - 'cmd' => 'displayImport', - 'importStep[back]' => 'import', - 'CSV_IMPORT[newFile]' => $this->indata['newFile'], - 'CSV_IMPORT[storage]' => $this->indata['storage'], - 'CSV_IMPORT[remove_existing]' => $this->indata['remove_existing'], - 'CSV_IMPORT[first_fieldname]' => $this->indata['first_fieldname'], - 'CSV_IMPORT[delimiter]' => $this->indata['delimiter'], - 'CSV_IMPORT[encapsulation]' => $this->indata['encapsulation'], - 'CSV_IMPORT[valid_email]' => $this->indata['valid_email'], - 'CSV_IMPORT[remove_dublette]' => $this->indata['remove_dublette'], - 'CSV_IMPORT[update_unique]' => $this->indata['update_unique'], - 'CSV_IMPORT[record_unique]' => $this->indata['record_unique'], - 'CSV_IMPORT[all_html]' => $this->indata['all_html'], - 'CSV_IMPORT[charset]' => $this->indata['charset'], - ]); - $hiddenMapped = []; - foreach ($this->indata['map'] as $fieldNr => $fieldMapped) { - $hiddenMapped[] = $this->makeHidden('CSV_IMPORT[map][' . $fieldNr . ']', $fieldMapped); + if (is_array($this->indata['map'])) { + foreach ($this->indata['map'] as $fieldNr => $fieldMapped) { + $output['startImport']['hiddenMap'][] = ['name' => htmlspecialchars('CSV_IMPORT[map][' . $fieldNr . ']'), 'value' => htmlspecialchars($fieldMapped)]; + } } if (is_array($this->indata['cat'])) { foreach ($this->indata['cat'] as $k => $catUid) { - $hiddenMapped[] = $this->makeHidden('CSV_IMPORT[cat][' . $k . ']', $catUid); + $output['startImport']['hiddenCat'][] = ['name' => htmlspecialchars('CSV_IMPORT[cat][' . $k . ']'), 'value' => htmlspecialchars($catUid)]; } } - $out .= implode('', $hiddenMapped); break; case 'upload': @@ -914,7 +940,7 @@ public function readCSV() * * @return array File content in array */ - public function readExampleCSV($records=3) + public function readExampleCSV($records = 3) { ini_set('auto_detect_line_endings', true); @@ -941,7 +967,7 @@ public function readExampleCSV($records=3) if ((count($data) >= 1)) { $mydata[] = $data; $i++; - if ($i>=$records) { + if ($i >= $records) { break; } } diff --git a/Resources/Private/Templates/RecipientList.html b/Resources/Private/Templates/RecipientList.html index 0c7623982..575e026a1 100644 --- a/Resources/Private/Templates/RecipientList.html +++ b/Resources/Private/Templates/RecipientList.html @@ -242,7 +242,7 @@

- @@ -307,7 +307,7 @@



- + @@ -324,7 +324,57 @@

- + + + + + +
+
+ + + + + + + + + + + + + + + +
{table.header}
{iterator.cycle}{row.val}{row.email}
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + {formcontent.theOutput} From fc18caf383c192967a6e7d68f3bd84e680255b23 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Wed, 17 Aug 2022 16:26:26 +0200 Subject: [PATCH 265/342] remove old import step --- Classes/Importer.php | 40 ---------------------------------------- 1 file changed, 40 deletions(-) diff --git a/Classes/Importer.php b/Classes/Importer.php index df3c33b0b..a7f4223cb 100644 --- a/Classes/Importer.php +++ b/Classes/Importer.php @@ -423,46 +423,6 @@ public function displayImport() } } break; - -// case 'import': - // show import messages -// $output['subtitle'] = $this->getLanguageService()->getLL('mailgroup_import_ready_import'); - -// $out .= $this->getLanguageService()->getLL('mailgroup_import_ready_import_label') . '

'; - -// $out .= ' -// ' . -// $this->makeHidden([ -// 'cmd' => 'displayImport', -// 'importStep[next]' => 'startImport', -// 'importStep[back]' => 'mapping', - -// 'CSV_IMPORT[newFile]' => $this->indata['newFile'], -// 'CSV_IMPORT[storage]' => $this->indata['storage'], -// 'CSV_IMPORT[remove_existing]' => $this->indata['remove_existing'], -// 'CSV_IMPORT[first_fieldname]' => $this->indata['first_fieldname'], -// 'CSV_IMPORT[delimiter]' => $this->indata['delimiter'], -// 'CSV_IMPORT[encapsulation]' => $this->indata['encapsulation'], -// 'CSV_IMPORT[valid_email]' => $this->indata['valid_email'], -// 'CSV_IMPORT[remove_dublette]' => $this->indata['remove_dublette'], -// 'CSV_IMPORT[update_unique]' => $this->indata['update_unique'], -// 'CSV_IMPORT[record_unique]' => $this->indata['record_unique'], -// 'CSV_IMPORT[all_html]' => $this->indata['all_html'], -// 'CSV_IMPORT[add_cat]' => $this->indata['add_cat'], -// 'CSV_IMPORT[charset]' => $this->indata['charset'], -// ]); -// $hiddenMapped = []; -// foreach ($this->indata['map'] as $fieldNr => $fieldMapped) { -// $hiddenMapped[] = $this->makeHidden('CSV_IMPORT[map][' . $fieldNr . ']', $fieldMapped); -// } -// if (is_array($this->indata['cat'])) { -// foreach ($this->indata['cat'] as $k => $catUid) { -// $hiddenMapped[] = $this->makeHidden('CSV_IMPORT[cat][' . $k . ']', $catUid); -// } -// } -// $out .= implode('', $hiddenMapped); -// break; - case 'startImport': $output['startImport']['show'] = true; From 6434b4b828417b150774733f9c105da9071cdac0 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Wed, 17 Aug 2022 16:28:11 +0200 Subject: [PATCH 266/342] remove function 'makeHidden' --- Classes/Importer.php | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/Classes/Importer.php b/Classes/Importer.php index a7f4223cb..9c1d17f44 100644 --- a/Classes/Importer.php +++ b/Classes/Importer.php @@ -822,29 +822,6 @@ public function makeDropdown($name, array $option, $selected, $disableInput='') return ''; } - /** - * Make hidden field - * - * @param mixed $name Name of the hidden field (string) or name => value (array) - * @param string $value Value of the hidden field - * - * @return string HTML code - */ - public function makeHidden($name, $value='') - { - if (is_array($name)) { - $hiddenFields = []; - foreach ($name as $n=>$v) { - $hiddenFields[] = ''; - } - $inputFields = implode('', $hiddenFields); - } else { - $inputFields = ''; - } - - return $inputFields; - } - /** * Read in the given CSV file. The function is used during the final file import. * Removes first the first data row if the CSV has fieldnames. From 417d0e3b1be36a55cdcb0b2c932e3cc370dd59b3 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Wed, 17 Aug 2022 16:39:45 +0200 Subject: [PATCH 267/342] update readCSV functions --- Classes/Importer.php | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/Classes/Importer.php b/Classes/Importer.php index 9c1d17f44..73efe128c 100644 --- a/Classes/Importer.php +++ b/Classes/Importer.php @@ -822,6 +822,18 @@ public function makeDropdown($name, array $option, $selected, $disableInput='') return ''; } + /** + * + * @param int $fileUid + * @return string + */ + private function getFileAbsolutePath(int $fileUid): string + { + $resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class); + $file = $resourceFactory->getFileObject($fileUid); + return Environment::getPublicPath() . '/' . str_replace('//', '/', $file->getStorage()->getConfiguration()['basePath'] . $file->getProperty('identifier')); + } + /** * Read in the given CSV file. The function is used during the final file import. * Removes first the first data row if the CSV has fieldnames. @@ -836,10 +848,7 @@ public function readCSV() return $mydata; } - $publicPath = Environment::getPublicPath(); - $resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class); - $file = $resourceFactory->getFileObject((int)$this->indata['newFileUid']); - $fileAbsolutePath = Environment::getPublicPath() . '/' . str_replace('//', '/', $file->getStorage()->getConfiguration()['basePath'] . $file->getProperty('identifier')); + $fileAbsolutePath = $this->getFileAbsolutePath((int)$this->indata['newFileUid']); $delimiter = $this->indata['delimiter']; $encaps = $this->indata['encapsulation']; @@ -879,17 +888,14 @@ public function readCSV() */ public function readExampleCSV($records = 3) { - ini_set('auto_detect_line_endings', true); - $mydata = []; - // TYPO3 6.0 works with relative path, we need absolute here - if (!is_file($this->indata['newFile']) && (strpos($this->indata['newFile'], Environment::getPublicPath() . '/') === false)) { - $this->indata['newFile'] = Environment::getPublicPath() . '/' . $this->indata['newFile']; - } - $handle = fopen($this->indata['newFile'], 'r'); - if($handle === false) { + + if((int)$this->indata['newFileUid'] < 1) { return $mydata; } + + $fileAbsolutePath = $this->getFileAbsolutePath((int)$this->indata['newFileUid']); + $i = 0; $delimiter = $this->indata['delimiter']; $encaps = $this->indata['encapsulation']; @@ -899,6 +905,13 @@ public function readExampleCSV($records = 3) $delimiter = ($delimiter === 'tab') ? "\t" : $delimiter; $encaps = ($encaps === 'singleQuote') ? "'" : $encaps; $encaps = ($encaps === 'doubleQuote') ? '"' : $encaps; + + ini_set('auto_detect_line_endings', true); + $handle = fopen($fileAbsolutePath, 'r'); + if($handle === false) { + return $mydata; + } + while ((($data = fgetcsv($handle, 10000, $delimiter, $encaps)) !== false)) { // remove empty line in csv if ((count($data) >= 1)) { From 68a5af112b07d241ce2b89f6a157b5515b6e9d4f Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Wed, 17 Aug 2022 16:47:54 +0200 Subject: [PATCH 268/342] replace ['BE_USER'] --- Classes/Importer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/Importer.php b/Classes/Importer.php index 73efe128c..b95c8a6c5 100644 --- a/Classes/Importer.php +++ b/Classes/Importer.php @@ -1008,7 +1008,7 @@ public function formatTable( public function userTempFolder() { /** @var \TYPO3\CMS\Core\Resource\Folder $folder */ - $folder = $GLOBALS['BE_USER']->getDefaultUploadTemporaryFolder(); + $folder = $this->getBeUser()->getDefaultUploadTemporaryFolder(); return $folder->getPublicUrl(); } From 8cf4f3b173a827b3d28278d8163250fe594c8481 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Wed, 17 Aug 2022 17:57:54 +0200 Subject: [PATCH 269/342] move quiery to repository --- Classes/Importer.php | 71 ++++++++-------------- Classes/Repository/TtAddressRepository.php | 50 +++++++++++++++ 2 files changed, 76 insertions(+), 45 deletions(-) diff --git a/Classes/Importer.php b/Classes/Importer.php index b95c8a6c5..0585a6fa3 100644 --- a/Classes/Importer.php +++ b/Classes/Importer.php @@ -17,12 +17,12 @@ use DirectMailTeam\DirectMail\Module\RecipientList; use DirectMailTeam\DirectMail\Repository\PagesRepository; use DirectMailTeam\DirectMail\Repository\SysDmailCategoryRepository; +use DirectMailTeam\DirectMail\Repository\TtAddressRepository; use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Core\Charset\CharsetConverter; use TYPO3\CMS\Core\Context\Context; use TYPO3\CMS\Core\Core\Environment; use TYPO3\CMS\Core\Database\ConnectionPool; -use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction; use TYPO3\CMS\Core\DataHandling\DataHandler; use TYPO3\CMS\Core\Localization\LanguageService; use TYPO3\CMS\Core\Resource\DuplicationBehavior; @@ -598,16 +598,7 @@ public function doImport(array $csvData) //empty table if flag is set if ($this->indata['remove_existing']) { - $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_address'); - $queryBuilder - ->delete('tt_address') - ->where( - $queryBuilder->expr()->eq( - 'pid', - $queryBuilder->createNamedParameter($this->indata['storage']) - ) - ) - ->execute(); + GeneralUtility::makeInstance(TtAddressRepository::class)->deleteRowsByPid((int)$this->indata['storage']); } $mappedCSV = []; @@ -618,12 +609,14 @@ public function doImport(array $csvData) foreach ($dataArray as $kk => $fieldData) { if ($this->indata['map'][$kk] !== 'noMap') { if (($this->indata['valid_email']) && ($this->indata['map'][$kk] === 'email')) { - $invalidEmail = GeneralUtility::validEmail(trim($fieldData))?0:1; + $invalidEmail = GeneralUtility::validEmail(trim($fieldData)) ? 0 : 1; $tempData[$this->indata['map'][$kk]] = trim($fieldData); - } else { + } + else { if ($this->indata['map'][$kk] !== 'cats') { $tempData[$this->indata['map'][$kk]] = $fieldData; - } else { + } + else { $tempCats = explode(',', $fieldData); foreach ($tempCats as $catC => $tempCat) { $tempData['module_sys_dmail_category'][$catC] = $tempCat; @@ -634,8 +627,9 @@ public function doImport(array $csvData) } if ($invalidEmail) { $invalidEmailCSV[] = $tempData; - } else { - $mappedCSV[]=$tempData; + } + else { + $mappedCSV[] = $tempData; } } @@ -652,30 +646,13 @@ public function doImport(array $csvData) $user = []; $userID = []; - $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_address'); - // only add deleteClause - $queryBuilder - ->getRestrictions() - ->removeAll() - ->add(GeneralUtility::makeInstance(DeletedRestriction::class)); - - $statement = $queryBuilder - ->select( - 'uid', - $this->indata['record_unique'] - ) - ->from('tt_address') - ->where( - $queryBuilder->expr()->eq( - 'pid', - $this->indata['storage'] - ) - ) - ->execute(); - - while (($row = $statement->fetch())) { - $user[] = $row[1]; - $userID[] = $row[0]; + $rows = GeneralUtility::makeInstance(TtAddressRepository::class)->selectTtAddressByPid((int)$this->indata['storage'], $this->indata['record_unique']); + + if(is_array($rows)) { + foreach ($rows as $row) { + $user[] = $row['email']; + $userID[] = $row['uid']; + } } // check user one by one, new or update @@ -718,7 +695,8 @@ public function doImport(array $csvData) } } $resultImport['update'][]=$dataArray; - } else { + } + else { // which one to update? all? foreach ($foundUser as $kk => $_) { $data['tt_address'][$userID[$foundUser[$kk]]]= $dataArray; @@ -726,7 +704,8 @@ public function doImport(array $csvData) } $resultImport['update'][]=$dataArray; } - } else { + } + else { // write new user $this->addDataArray($data, 'NEW' . $c, $dataArray); $resultImport['new'][] = $dataArray; @@ -734,7 +713,8 @@ public function doImport(array $csvData) $c++; } } - } else { + } + else { // no update, import all $c = 1; foreach ($mappedCSV as $dataArray) { @@ -813,7 +793,7 @@ public function makeDropdown($name, array $option, $selected, $disableInput='') $opt = []; foreach ($option as $v) { if (is_array($v)) { - $opt[] = ''; } @@ -1080,7 +1060,8 @@ public function writeTempFile() $newfile = $storageConfig['basePath'] . ltrim($newfileObj->getIdentifier(), '/'); } } - } else { + } + else { $newfile = $this->indata['newFile']; } diff --git a/Classes/Repository/TtAddressRepository.php b/Classes/Repository/TtAddressRepository.php index a8fe3479b..bde73a2a1 100644 --- a/Classes/Repository/TtAddressRepository.php +++ b/Classes/Repository/TtAddressRepository.php @@ -3,6 +3,9 @@ namespace DirectMailTeam\DirectMail\Repository; +use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction; +use TYPO3\CMS\Core\Utility\GeneralUtility; + class TtAddressRepository extends MainRepository { protected string $table = 'tt_address'; @@ -30,6 +33,35 @@ public function selectTtAddressByUid(int $uid, string $permsClause) //: array|bo ->execute() ->fetchAll(); } + + /** + * @return array|bool + */ + public function selectTtAddressByPid(int $pid, string $recordUnique) //: array|bool + { + $queryBuilder = $this->getQueryBuilder($this->table); + // only add deleteClause + //https://github.com/FriendsOfTYPO3/tt_address/blob/master/Configuration/TCA/tt_address.php + $queryBuilder + ->getRestrictions() + ->removeAll() + ->add(GeneralUtility::makeInstance(DeletedRestriction::class)); + + return $queryBuilder + ->select( + 'uid', + $recordUnique + ) + ->from($this->table) + ->where( + $queryBuilder->expr()->eq( + 'pid', + $queryBuilder->createNamedParameter($pid, \PDO::PARAM_INT) + ) + ) + ->execute() + ->fetchAll(); + } /** * @return array|bool @@ -76,4 +108,22 @@ public function selectTtAddressForSendMailTest(int $ttAddressUid, string $permsC ->execute() ->fetchAll(); } + + /** + * @return array|bool + */ + public function deleteRowsByPid(int $pid) //: array|bool + { + $queryBuilder = $this->getQueryBuilder($this->table); + + return $queryBuilder + ->delete($this->table) + ->where( + $queryBuilder->expr()->eq( + 'pid', + $queryBuilder->createNamedParameter($pid, \PDO::PARAM_INT) + ) + ) + ->execute(); + } } \ No newline at end of file From 47321bfaf1d63d8e59af39c0ea0d93ad97b66f0d Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Wed, 17 Aug 2022 18:27:12 +0200 Subject: [PATCH 270/342] update output of select with delimiters --- Classes/Importer.php | 24 ++++++++++--------- .../Private/Templates/RecipientList.html | 8 ++++++- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/Classes/Importer.php b/Classes/Importer.php index 0585a6fa3..9826d886d 100644 --- a/Classes/Importer.php +++ b/Classes/Importer.php @@ -101,6 +101,7 @@ public function displayImport() 'remove_existing' => false, 'first_fieldname' => false, 'delimiter' => '', + 'delimiterSelected' => '', 'encapsulation' => '', 'valid_email' => false, 'remove_dublette' => false, @@ -268,10 +269,10 @@ public function displayImport() } $optDelimiter = [ - ['comma', $this->getLanguageService()->getLL('mailgroup_import_separator_comma')], - ['semicolon', $this->getLanguageService()->getLL('mailgroup_import_separator_semicolon')], - ['colon', $this->getLanguageService()->getLL('mailgroup_import_separator_colon')], - ['tab', $this->getLanguageService()->getLL('mailgroup_import_separator_tab')] + ['val' => 'comma', 'text' => $this->getLanguageService()->getLL('mailgroup_import_separator_comma')], + ['val' => 'semicolon', 'text' => $this->getLanguageService()->getLL('mailgroup_import_separator_semicolon')], + ['val' => 'colon', 'text' => $this->getLanguageService()->getLL('mailgroup_import_separator_colon')], + ['val' => 'tab', 'text' => $this->getLanguageService()->getLL('mailgroup_import_separator_tab')] ]; $optEncap = [ @@ -300,8 +301,9 @@ public function displayImport() $output['conf']['first_fieldname'] = !$this->indata['first_fieldname'] ? false : true; // csv separator - $output['conf']['delimiter'] = $this->makeDropdown('CSV_IMPORT[delimiter]', $optDelimiter, $this->indata['delimiter'], $output['conf']['disableInput']); - + $output['conf']['delimiter'] = $optDelimiter; + $output['conf']['delimiterSelected'] = $this->indata['delimiter'] ?? ''; + // csv encapsulation $output['conf']['encapsulation'] = $this->makeDropdown('CSV_IMPORT[encapsulation]', $optEncap, $this->indata['encapsulation'], $output['conf']['disableInput']); @@ -699,7 +701,7 @@ public function doImport(array $csvData) else { // which one to update? all? foreach ($foundUser as $kk => $_) { - $data['tt_address'][$userID[$foundUser[$kk]]]= $dataArray; + $data['tt_address'][$userID[$foundUser[$kk]]] = $dataArray; $data['tt_address'][$userID[$foundUser[$kk]]]['pid'] = $this->indata['storage']; } $resultImport['update'][]=$dataArray; @@ -725,7 +727,7 @@ public function doImport(array $csvData) } $resultImport['invalid_email'] = $invalidEmailCSV; - $resultImport['double'] = (is_array($filteredCSV['double']))?$filteredCSV['double']: []; + $resultImport['double'] = is_array($filteredCSV['double']) ? $filteredCSV['double'] : []; // start importing /* @var $tce DataHandler */ @@ -799,7 +801,7 @@ public function makeDropdown($name, array $option, $selected, $disableInput='') } } - return ''; + return ''; } /** @@ -830,7 +832,7 @@ public function readCSV() $fileAbsolutePath = $this->getFileAbsolutePath((int)$this->indata['newFileUid']); - $delimiter = $this->indata['delimiter']; + $delimiter = $this->indata['delimiter'] ?: 'comma'; $encaps = $this->indata['encapsulation']; $delimiter = ($delimiter === 'comma') ? ',' : $delimiter; $delimiter = ($delimiter === 'semicolon') ? ';' : $delimiter; @@ -877,7 +879,7 @@ public function readExampleCSV($records = 3) $fileAbsolutePath = $this->getFileAbsolutePath((int)$this->indata['newFileUid']); $i = 0; - $delimiter = $this->indata['delimiter']; + $delimiter = $this->indata['delimiter'] ?: 'comma'; $encaps = $this->indata['encapsulation']; $delimiter = ($delimiter === 'comma') ? ',' : $delimiter; $delimiter = ($delimiter === 'semicolon') ? ';' : $delimiter; diff --git a/Resources/Private/Templates/RecipientList.html b/Resources/Private/Templates/RecipientList.html index 575e026a1..fcae8475e 100644 --- a/Resources/Private/Templates/RecipientList.html +++ b/Resources/Private/Templates/RecipientList.html @@ -159,7 +159,13 @@

{formcontent.output.subtitle}

- {formcontent.output.conf.delimiter} + + + + {del.text} + + + From 078ac6ea89994099605c1b2eb986a3985497be2e Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Thu, 18 Aug 2022 10:10:02 +0200 Subject: [PATCH 271/342] update output of select with encapsulation --- Classes/Importer.php | 11 ++++++----- Resources/Private/Templates/RecipientList.html | 10 ++++++++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Classes/Importer.php b/Classes/Importer.php index 9826d886d..941f9a083 100644 --- a/Classes/Importer.php +++ b/Classes/Importer.php @@ -276,8 +276,8 @@ public function displayImport() ]; $optEncap = [ - ['doubleQuote', ' " '], - ['singleQuote', " ' "], + ['val' => 'doubleQuote', 'text' => ' " '], + ['val' => 'singleQuote', 'text' => " ' "], ]; // TODO: make it variable? @@ -305,7 +305,8 @@ public function displayImport() $output['conf']['delimiterSelected'] = $this->indata['delimiter'] ?? ''; // csv encapsulation - $output['conf']['encapsulation'] = $this->makeDropdown('CSV_IMPORT[encapsulation]', $optEncap, $this->indata['encapsulation'], $output['conf']['disableInput']); + $output['conf']['encapsulation'] = $optEncap; + $output['conf']['encapsulationSelected'] = $this->indata['encapsulation'] ?? ''; // import only valid email $output['conf']['valid_email'] = !$this->indata['valid_email'] ? false : true; @@ -833,7 +834,7 @@ public function readCSV() $fileAbsolutePath = $this->getFileAbsolutePath((int)$this->indata['newFileUid']); $delimiter = $this->indata['delimiter'] ?: 'comma'; - $encaps = $this->indata['encapsulation']; + $encaps = $this->indata['encapsulation'] ?: 'doubleQuote'; $delimiter = ($delimiter === 'comma') ? ',' : $delimiter; $delimiter = ($delimiter === 'semicolon') ? ';' : $delimiter; $delimiter = ($delimiter === 'colon') ? ':' : $delimiter; @@ -880,7 +881,7 @@ public function readExampleCSV($records = 3) $i = 0; $delimiter = $this->indata['delimiter'] ?: 'comma'; - $encaps = $this->indata['encapsulation']; + $encaps = $this->indata['encapsulation'] ?: 'doubleQuote'; $delimiter = ($delimiter === 'comma') ? ',' : $delimiter; $delimiter = ($delimiter === 'semicolon') ? ';' : $delimiter; $delimiter = ($delimiter === 'colon') ? ':' : $delimiter; diff --git a/Resources/Private/Templates/RecipientList.html b/Resources/Private/Templates/RecipientList.html index fcae8475e..548a19eac 100644 --- a/Resources/Private/Templates/RecipientList.html +++ b/Resources/Private/Templates/RecipientList.html @@ -160,7 +160,7 @@

{formcontent.output.subtitle}

- + {del.text} @@ -173,7 +173,13 @@

{formcontent.output.subtitle}

- {formcontent.output.conf.encapsulation} + + + + {en.text} + + + From 70ee0752b3e1a439f72f3a940192b70e991edc78 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Thu, 18 Aug 2022 13:04:35 +0200 Subject: [PATCH 272/342] update output of select with record_unique --- Classes/Importer.php | 10 +- .../Private/Templates/RecipientList.html | 400 +++++++++--------- 2 files changed, 216 insertions(+), 194 deletions(-) diff --git a/Classes/Importer.php b/Classes/Importer.php index 941f9a083..87ee1c179 100644 --- a/Classes/Importer.php +++ b/Classes/Importer.php @@ -282,8 +282,8 @@ public function displayImport() // TODO: make it variable? $optUnique = [ - ['email', 'email'], - ['name', 'name'] + ['val' => 'email', 'text' => 'email'], + ['val' =>'name', 'text' => 'name'] ]; $output['conf']['disableInput'] = $this->params['inputDisable'] == 1 ? true : false; @@ -318,7 +318,9 @@ public function displayImport() $output['conf']['update_unique'] = !$this->indata['update_unique'] ? false : true; // which field should be use to show uniqueness of the records - $output['conf']['record_unique'] = $this->makeDropdown('CSV_IMPORT[record_unique]', $optUnique, $this->indata['record_unique'], $output['conf']['disableInput']); + $output['conf']['record_unique'] = $optUnique; + $output['conf']['record_uniqueSelected'] = $this->indata['record_unique'] ?? ''; + #$output['conf']['record_unique'] = $this->makeDropdown('CSV_IMPORT[record_unique]', $optUnique, $this->indata['record_unique'], $output['conf']['disableInput']); break; @@ -802,7 +804,7 @@ public function makeDropdown($name, array $option, $selected, $disableInput='') } } - return ''; + return ''; } /** diff --git a/Resources/Private/Templates/RecipientList.html b/Resources/Private/Templates/RecipientList.html index 548a19eac..7d8337bd8 100644 --- a/Resources/Private/Templates/RecipientList.html +++ b/Resources/Private/Templates/RecipientList.html @@ -110,136 +110,151 @@

{formcontent.output.title}

{formcontent.output.subtitle}

-
+ +
+ +
-
+
-
-


-
+
+


+
+
+ {formcontent.output.upload.csv}

+
+
- - {formcontent.output.upload.csv}

- - - - + + + +
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - {formcontent.output.conf.storage} -
- - - -
- - - -
- - - - - - {del.text} - - - -
- - - - - - {en.text} - - - -
- - - -
- - - -
- - - -
- - - {formcontent.output.conf.record_unique} -
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + {formcontent.output.conf.storage} +
+ + + +
+ + + +
+ + + + + + {del.text} + + + +
+ + + + + + {en.text} + + + +
+ + + +
+ + + +
+ + + +
+ + + + + + {ru.text} + + + +
+

- - + +
- - - - - - - -
- - - {formcontent.output.mapping.charset} -
- +
+ + + + + + + +
+ + + {formcontent.output.mapping.charset} +
+

+


@@ -249,80 +264,82 @@

-

- - - - - - - - - - - - - - - - - - - - - -
{iterator.cycle}{row.mapping_description}{row.mapping_mapping}{row.mapping_value}
-

-
+
+ + + + + + + + + + + + + + + + + + + + + +
{iterator.cycle}{row.mapping_description}{row.mapping_mapping}{row.mapping_value}
+
+

- - - - - - - +
+
- - - -
+ - - + + + + + + + + + + + + + + - - - - - - - - - -
- + + +
- + -
+ + + +
 {mapping_cat.cat} + +
 {mapping_cat.cat} - -
-

+ + + +
- - + + @@ -340,25 +357,27 @@

- - - - - - - - - - - - - - - - - -
{table.header}
{iterator.cycle}{row.val}{row.email}
-
+
+ + + + + + + + + + + + + + + + + +
{table.header}
{iterator.cycle}{row.val}{row.email}
+
+
@@ -370,10 +389,11 @@

+
- + From 8daf7004d8a2d3bb9ebc003ccb178dccb160995d Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Thu, 18 Aug 2022 13:18:12 +0200 Subject: [PATCH 273/342] update output of select with storage --- Classes/Importer.php | 8 ++++++-- Resources/Private/Templates/RecipientList.html | 8 +++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Classes/Importer.php b/Classes/Importer.php index 87ee1c179..dfe52f258 100644 --- a/Classes/Importer.php +++ b/Classes/Importer.php @@ -263,7 +263,10 @@ public function displayImport() if($subfolders && count($subfolders)) { foreach($subfolders as $subfolder) { if (BackendUtility::readPageAccess($subfolder['uid'], $pagePermsClause1)) { - $optStorage[] = [$subfolder['uid'], $subfolder['title'] . ' [uid:' . $subfolder['uid'] . ']']; + $optStorage[] = [ + 'val' => $subfolder['uid'], + 'text' => $subfolder['title'] . ' [uid:' . $subfolder['uid'] . ']' + ]; } } } @@ -292,7 +295,8 @@ public function displayImport() $output['subtitle'] = $this->getLanguageService()->getLL('mailgroup_import_header_conf'); // get the all sysfolder - $output['conf']['storage'] = $this->makeDropdown('CSV_IMPORT[storage]', $optStorage, $this->indata['storage']); + $output['conf']['storage'] = $optStorage; + $output['conf']['storageSelected'] = $this->indata['storage'] ?? ''; // remove existing option $output['conf']['remove_existing'] = !$this->indata['remove_existing'] ? false : true; diff --git a/Resources/Private/Templates/RecipientList.html b/Resources/Private/Templates/RecipientList.html index 7d8337bd8..a2b8222e4 100644 --- a/Resources/Private/Templates/RecipientList.html +++ b/Resources/Private/Templates/RecipientList.html @@ -141,7 +141,13 @@

{formcontent.output.subtitle}

- {formcontent.output.conf.storage} + + + + {st.text} + + + From 7f9d5fb270b7ea9ccacaf758a734d0b5513ebd31 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Thu, 18 Aug 2022 13:32:34 +0200 Subject: [PATCH 274/342] update output of select with charset --- Classes/Importer.php | 6 +++--- Resources/Private/Templates/RecipientList.html | 8 +++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Classes/Importer.php b/Classes/Importer.php index dfe52f258..1cf2c91ab 100644 --- a/Classes/Importer.php +++ b/Classes/Importer.php @@ -324,7 +324,6 @@ public function displayImport() // which field should be use to show uniqueness of the records $output['conf']['record_unique'] = $optUnique; $output['conf']['record_uniqueSelected'] = $this->indata['record_unique'] ?? ''; - #$output['conf']['record_unique'] = $this->makeDropdown('CSV_IMPORT[record_unique]', $optUnique, $this->indata['record_unique'], $output['conf']['disableInput']); break; @@ -348,15 +347,16 @@ public function displayImport() $cs = array_unique(array_values(mb_list_encodings())); $charSets = []; foreach ($cs as $charset) { - $charSets[] = [$charset, $charset]; + $charSets[] = ['val' => $charset, 'text' => $charset]; } if (!isset($this->indata['charset'])) { $this->indata['charset'] = 'ISO-8859-1'; } $output['subtitle'] = $this->getLanguageService()->getLL('mailgroup_import_mapping_charset'); + + $output['mapping']['charset'] = $charSets; $output['mapping']['charsetSelected'] = $this->indata['charset']; - $output['mapping']['charset'] = $this->makeDropdown('CSV_IMPORT[charset]', $charSets, $this->indata['charset']); // show mapping form if ($this->indata['first_fieldname']) { diff --git a/Resources/Private/Templates/RecipientList.html b/Resources/Private/Templates/RecipientList.html index a2b8222e4..1f3c68a67 100644 --- a/Resources/Private/Templates/RecipientList.html +++ b/Resources/Private/Templates/RecipientList.html @@ -254,7 +254,13 @@

{formcontent.output.subtitle}

- {formcontent.output.mapping.charset} + + + + {cs.text} + + + From 24f3cdc65ce1d82d6b93528c78e914bb52ae5b6d Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Thu, 18 Aug 2022 14:22:30 +0200 Subject: [PATCH 275/342] update output of table with mapping examples --- Classes/Importer.php | 55 +------------------ .../Private/Templates/RecipientList.html | 14 ++++- 2 files changed, 15 insertions(+), 54 deletions(-) diff --git a/Classes/Importer.php b/Classes/Importer.php index 1cf2c91ab..43153ab7e 100644 --- a/Classes/Importer.php +++ b/Classes/Importer.php @@ -401,12 +401,12 @@ public function displayImport() // example CSV $exampleLines = []; for ($j = 0; $j < (count($csvData)); $j++) { - $exampleLines[] = [$csvData[$j][$i]]; + $exampleLines[] = $csvData[$j][$i]; } $output['mapping']['table'][] = [ 'mapping_description' => $csv_firstRow[$i], 'mapping_mapping' => $this->makeDropdown('CSV_IMPORT[map][' . ($i) . ']', $mapFields, $this->indata['map'][$i]), - 'mapping_value' => $this->formatTable($exampleLines, ['nowrap'], 0, [0], 'border="0" cellpadding="0" cellspacing="0" class="table table-striped table-hover" style="width:100%; border:0px; margin:0px;"') + 'mapping_value' => $exampleLines ]; } @@ -938,57 +938,6 @@ public function convCharset(array $data) return $data; } - - /** - * Formating the given array in to HTML table - * - * @param array $tableLines Array of table row -> array of cells - * @param array $cellParams Cells' parameter - * @param bool $header First tableLines is table header - * @param array $cellcmd Escaped cells' value - * @param string $tableParams Table's parameter - * - * @return string HTML the table - */ - public function formatTable( - array $tableLines, - array $cellParams, - $header, - array $cellcmd = [], - $tableParams = 'border="0" cellpadding="0" cellspacing="0" class="table table-striped table-hover"') - { - $lines = []; - $first = $header?1:0; - $c = 0; - - reset($tableLines); - foreach ($tableLines as $r) { - $rowA = []; - for ($k = 0, $kMax = count($r); $k < $kMax; $k++) { - $v = $r[$k]; - $v = strlen($v) ? ($cellcmd[$k]?$v:htmlspecialchars($v)) : ' '; - if ($first) { - $v = '' . $v . ''; - } - - $cellParam = []; - if ($cellParams[$k]) { - $cellParam[] = $cellParams[$k]; - } - - if ($first && isset($cellParams['first'])) { - $cellParam[] = $cellParams['first']; - } - $rowA[] = '' . $v . ''; - } - - $lines[] = '' . implode('', $rowA) . ''; - $first = 0; - $c++; - } - return '' . implode('', $lines) . '
'; - } - /** * Returns first temporary folder of the user account (from $FILEMOUNTS) * diff --git a/Resources/Private/Templates/RecipientList.html b/Resources/Private/Templates/RecipientList.html index 1f3c68a67..c3abf61ee 100644 --- a/Resources/Private/Templates/RecipientList.html +++ b/Resources/Private/Templates/RecipientList.html @@ -294,7 +294,19 @@

{iterator.cycle} {row.mapping_description} {row.mapping_mapping} - {row.mapping_value} + + + + + + + + +
+ {mv} +
+
+
From 1a19011f6ae50820bf765046a66ca6070132dec5 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Thu, 18 Aug 2022 15:36:13 +0200 Subject: [PATCH 276/342] update output of select with mapping fields --- Classes/Importer.php | 7 +++++-- Resources/Private/Templates/RecipientList.html | 10 +++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Classes/Importer.php b/Classes/Importer.php index 43153ab7e..5d1bd4fc5 100644 --- a/Classes/Importer.php +++ b/Classes/Importer.php @@ -131,7 +131,8 @@ public function displayImport() 'show_add_cat' => false, 'add_cat' => false, 'error' => [], - 'table' => [] + 'table' => [], + 'fields' => [] ], 'startImport' => [ 'show' => false, @@ -397,6 +398,7 @@ public function displayImport() reset($csv_firstRow); reset($csvData); + $output['mapping']['fields'] = $mapFields; for ($i = 0; $i < (count($csv_firstRow)); $i++) { // example CSV $exampleLines = []; @@ -405,7 +407,8 @@ public function displayImport() } $output['mapping']['table'][] = [ 'mapping_description' => $csv_firstRow[$i], - 'mapping_mapping' => $this->makeDropdown('CSV_IMPORT[map][' . ($i) . ']', $mapFields, $this->indata['map'][$i]), + 'mapping_i' => $i, + 'mapping_mappingSelected' => $this->indata['map'][$i], 'mapping_value' => $exampleLines ]; } diff --git a/Resources/Private/Templates/RecipientList.html b/Resources/Private/Templates/RecipientList.html index c3abf61ee..2f15fabeb 100644 --- a/Resources/Private/Templates/RecipientList.html +++ b/Resources/Private/Templates/RecipientList.html @@ -293,7 +293,15 @@

{iterator.cycle} {row.mapping_description} - {row.mapping_mapping} + + + + + {field.1} + + + + From 1c4fe268ff9baae092e8e62d158c813f28148bc2 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Thu, 18 Aug 2022 15:42:36 +0200 Subject: [PATCH 277/342] remove function 'makeDropdown' --- Classes/Importer.php | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/Classes/Importer.php b/Classes/Importer.php index 5d1bd4fc5..b19813fdb 100644 --- a/Classes/Importer.php +++ b/Classes/Importer.php @@ -790,30 +790,6 @@ public function addDataArray(array &$data, $id, array $dataArray) } } - /** - * Make dropdown menu - * - * @param string $name Name of the dropdown - * @param array $option Array of array (v,k) - * @param string $selected Set selected flag - * @param string $disableInput Flag to disable the input field - * - * @return string HTML code of the dropdown - */ - public function makeDropdown($name, array $option, $selected, $disableInput='') - { - $opt = []; - foreach ($option as $v) { - if (is_array($v)) { - $opt[] = ''; - } - } - - return ''; - } - /** * * @param int $fileUid From 1b6c8365e53d402a4baff88ec45bc441cb7582fe Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Thu, 18 Aug 2022 16:19:00 +0200 Subject: [PATCH 278/342] rename in --- Classes/Importer.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Classes/Importer.php b/Classes/Importer.php index b19813fdb..43b2c8ab4 100644 --- a/Classes/Importer.php +++ b/Classes/Importer.php @@ -740,12 +740,12 @@ public function doImport(array $csvData) $resultImport['double'] = is_array($filteredCSV['double']) ? $filteredCSV['double'] : []; // start importing - /* @var $tce DataHandler */ - $tce = GeneralUtility::makeInstance(DataHandler::class); - $tce->stripslashes_values = 0; - $tce->enableLogging = 0; - $tce->start($data, []); - $tce->process_datamap(); + /* @var $dataHandler DataHandler */ + $dataHandler = GeneralUtility::makeInstance(DataHandler::class); + $dataHandler->stripslashes_values = 0; + $dataHandler->enableLogging = 0; + $dataHandler->start($data, []); + $dataHandler->process_datamap(); /** * Hook for doImport Mail From 1b22a72eb516fa58404dd8642fa01d53af9f43b5 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Thu, 18 Aug 2022 17:13:22 +0200 Subject: [PATCH 279/342] add output of file info --- Resources/Private/Templates/RecipientList.html | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Resources/Private/Templates/RecipientList.html b/Resources/Private/Templates/RecipientList.html index 2f15fabeb..e193292f7 100644 --- a/Resources/Private/Templates/RecipientList.html +++ b/Resources/Private/Templates/RecipientList.html @@ -113,9 +113,14 @@

{formcontent.output.subtitle}

+

-
+ + + {formcontent.output.upload.fileInfo.name} ({formcontent.output.upload.fileInfo.extension}; {formcontent.output.upload.fileInfo.size}) + +


From 01357b5ecf3583713d29b6a2af9fef4843a36a9a Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Thu, 18 Aug 2022 17:18:20 +0200 Subject: [PATCH 280/342] replace class 'form-control' with 'form-control-adapt' --- Resources/Private/Templates/Configuration.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Resources/Private/Templates/Configuration.html b/Resources/Private/Templates/Configuration.html index 25d3b975b..5c0697bf1 100644 --- a/Resources/Private/Templates/Configuration.html +++ b/Resources/Private/Templates/Configuration.html @@ -135,7 +135,7 @@



- + @@ -151,7 +151,7 @@



- + @@ -193,12 +193,12 @@


- +

- +
From 316324ba62cbeb3ae47220d2ce2540fb66149ab4 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Thu, 18 Aug 2022 17:18:56 +0200 Subject: [PATCH 281/342] add output of file info --- Classes/Importer.php | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/Classes/Importer.php b/Classes/Importer.php index 43b2c8ab4..d8182cdba 100644 --- a/Classes/Importer.php +++ b/Classes/Importer.php @@ -90,6 +90,7 @@ public function displayImport() 'upload' => [ 'show' => false, 'current' => false, + 'fileInfo' => [], 'csv' => '', 'target' => '', 'target_disabled' => '', @@ -184,12 +185,6 @@ public function displayImport() } // merge it with inData, but inData has priority. $this->indata += $this->params; - - // $currentFileInfo = BasicFileUtility::getTotalFileInfo($this->indata['newFile']); - // $currentFileName = $currentFileInfo['file']; - // $currentFileSize = GeneralUtility::formatSize($currentFileInfo['size']); - // $currentFileMessage = $currentFileName . ' (' . $currentFileSize . ')'; - if (empty($this->indata['csv']) && !empty($_FILES['upload_1']['name'])) { $this->indata['newFile'] = $this->checkUpload(); if (is_object($this->indata['newFile'][0])) { @@ -207,7 +202,6 @@ public function displayImport() unset($this->indata['newFileUid']); } } - $stepCurrent = ''; if ($this->indata['back'] ?? false) { $stepCurrent = $step['back']; @@ -511,7 +505,14 @@ public function displayImport() if (($this->indata['mode'] === 'file') && !(((strpos($currentFileInfo['file'], 'import') === false) ? 0 : 1) && ($currentFileInfo['realFileext'] === 'txt'))) { $output['upload']['current'] = true; - // @TODO add $currentFileMessage after 'mailgroup_import_current_file' + $file = $this->getFileById((int)$this->indata['newFileUid']); + if(is_object($file)) { + $output['upload']['fileInfo'] = [ + 'name' => $file->getName(), + 'extension' => $file->getProperty('extension'), + 'size' => GeneralUtility::formatSize($file->getProperty('size')) + ]; + } } if (((strpos(($currentFileInfo['file'] ?? ''), 'import') === false) ? 0 : 1) && (($currentFileInfo['realFileext'] ?? '') === 'txt')) { @@ -525,6 +526,7 @@ public function displayImport() $output['upload']['target'] = htmlspecialchars($this->userTempFolder()); $output['upload']['target_disabled'] = GeneralUtility::_POST('importNow') ? 'disabled' : ''; $output['upload']['newFile'] = $this->indata['newFile']; + $output['upload']['newFileUid'] = $this->indata['newFileUid']; } $output['title'] = $this->getLanguageService()->getLL('mailgroup_import') . BackendUtility::cshItem($this->cshTable ?? '', 'mailgroup_import'); @@ -790,6 +792,23 @@ public function addDataArray(array &$data, $id, array $dataArray) } } + /** + * + * @param int $fileUid + * @return \TYPO3\CMS\Core\Resource\File|bool + */ + private function getFileById(int $fileUid) //: \TYPO3\CMS\Core\Resource\File|bool + { + $resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class); + try { + return $resourceFactory->getFileObject($fileUid); + } + catch(\TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException $e) { + + } + return false; + } + /** * * @param int $fileUid @@ -797,8 +816,7 @@ public function addDataArray(array &$data, $id, array $dataArray) */ private function getFileAbsolutePath(int $fileUid): string { - $resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class); - $file = $resourceFactory->getFileObject($fileUid); + $file = $this->getFileById($fileUid); return Environment::getPublicPath() . '/' . str_replace('//', '/', $file->getStorage()->getConfiguration()['basePath'] . $file->getProperty('identifier')); } From 0a5577c185c2f23d5b705c9dcfd28cb89b8a1cf0 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Fri, 19 Aug 2022 13:58:53 +0200 Subject: [PATCH 282/342] update function 'writeTempFile' --- Classes/Importer.php | 184 +++++++++++++++++++------------------------ 1 file changed, 82 insertions(+), 102 deletions(-) diff --git a/Classes/Importer.php b/Classes/Importer.php index d8182cdba..6797c0fac 100644 --- a/Classes/Importer.php +++ b/Classes/Importer.php @@ -194,13 +194,8 @@ public function displayImport() } } elseif (!empty($this->indata['csv']) && empty($_FILES['upload_1']['name'])) { - if (((strpos($currentFileInfo['file'], 'import') === false) ? 0 : 1) && ($currentFileInfo['realFileext'] === 'txt')) { - // do nothing - } - else { - unset($this->indata['newFile']); - unset($this->indata['newFileUid']); - } + unset($this->indata['newFile']); + unset($this->indata['newFileUid']); } $stepCurrent = ''; if ($this->indata['back'] ?? false) { @@ -215,7 +210,9 @@ public function displayImport() if (strlen($this->indata['csv'] ?? '') > 0) { $this->indata['mode'] = 'csv'; - $this->indata['newFile'] = $this->writeTempFile(); + $tempFile = $this->writeTempFile($this->indata['csv'] ?? '', $this->indata['newFile'] ?? '', $this->indata['newFileUid'] ?? 0); + $this->indata['newFile'] = $tempFile['newFile']; + $this->indata['newFileUid'] = $tempFile['newFileUid']; } elseif (!empty($this->indata['newFile'])) { $this->indata['mode'] = 'file'; @@ -353,6 +350,7 @@ public function displayImport() $output['mapping']['charset'] = $charSets; $output['mapping']['charsetSelected'] = $this->indata['charset']; + $csv_firstRow = []; // show mapping form if ($this->indata['first_fieldname']) { // read csv @@ -364,7 +362,6 @@ public function displayImport() // read csv $csvData = $this->readExampleCSV(3); $fieldsAmount = count($csvData[0] ?? []); - $csv_firstRow = []; for ($i = 0; $i < $fieldsAmount; $i++) { $csv_firstRow[] = 'field_' . $i; } @@ -791,34 +788,6 @@ public function addDataArray(array &$data, $id, array $dataArray) } } } - - /** - * - * @param int $fileUid - * @return \TYPO3\CMS\Core\Resource\File|bool - */ - private function getFileById(int $fileUid) //: \TYPO3\CMS\Core\Resource\File|bool - { - $resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class); - try { - return $resourceFactory->getFileObject($fileUid); - } - catch(\TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException $e) { - - } - return false; - } - - /** - * - * @param int $fileUid - * @return string - */ - private function getFileAbsolutePath(int $fileUid): string - { - $file = $this->getFileById($fileUid); - return Environment::getPublicPath() . '/' . str_replace('//', '/', $file->getStorage()->getConfiguration()['basePath'] . $file->getProperty('identifier')); - } /** * Read in the given CSV file. The function is used during the final file import. @@ -935,95 +904,54 @@ public function convCharset(array $data) return $data; } - /** - * Returns first temporary folder of the user account (from $FILEMOUNTS) - * - * @return string Absolute path to first "_temp_" folder of the current user, otherwise blank. - */ - public function userTempFolder() - { - /** @var \TYPO3\CMS\Core\Resource\Folder $folder */ - $folder = $this->getBeUser()->getDefaultUploadTemporaryFolder(); - return $folder->getPublicUrl(); - } - - /** - * - * @return int - */ - private function getTimestampFromAspect(): int { - $context = GeneralUtility::makeInstance(Context::class); - return $context->getPropertyFromAspect('date', 'timestamp'); - } - /** * Write CSV Data to a temporary file and will be used for the import * - * @return string path of the temp file + * @return array path and uid of the temp file */ - public function writeTempFile() + public function writeTempFile(string $csv, string $newFile, int $newFileUid) { - $newfile = ''; - $beUser = $this->getBeUser(); - $userPermissions = $beUser->getFilePermissions(); - unset($this->fileProcessor); - - // add uploads/tx_directmail to user filemounts - $GLOBALS['FILEMOUNTS']['tx_directmail'] = [ - 'name' => 'direct_mail', - 'path' => GeneralUtility::getFileAbsFileName('uploads/tx_directmail/'), - 'type' - ]; + $newfile = ['newFile' => '', 'newFileUid' => 0]; + $userPermissions = $this->getBeUser()->getFilePermissions(); // Initializing: - /* @var $fileProcessor ExtendedFileUtility */ - $this->fileProcessor = GeneralUtility::makeInstance(ExtendedFileUtility::class); - $this->fileProcessor->setActionPermissions($userPermissions); - $this->fileProcessor->dontCheckForUnique = 1; - - if (is_array($GLOBALS['FILEMOUNTS']) && !empty($GLOBALS['FILEMOUNTS'])) { - // we have a filemount - // do something here - } - else { - // we don't have a valid file mount - // should be fixed - - // this throws a error message because we have no rights to upload files - // to our extension's own upload folder - // further investigation needed - $file['upload']['1']['target'] = GeneralUtility::getFileAbsFileName('uploads/tx_directmail/'); - } + /* @var $extendedFileUtility ExtendedFileUtility */ + $extendedFileUtility = GeneralUtility::makeInstance(ExtendedFileUtility::class); + $extendedFileUtility->setActionPermissions($userPermissions); + //https://docs.typo3.org/c/typo3/cms-core/11.5/en-us/Changelog/7.4/Deprecation-63603-ExtendedFileUtilitydontCheckForUniqueIsDeprecated.html + $extendedFileUtility->setExistingFilesConflictMode(DuplicationBehavior::REPLACE); if (empty($this->indata['newFile'])) { // Checking referer / executing: $refInfo = parse_url(GeneralUtility::getIndpEnv('HTTP_REFERER')); $httpHost = GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY'); - // new file - $file['newfile']['1']['target'] = $this->userTempFolder(); - $file['newfile']['1']['data'] = 'import_' . $this->getTimestampFromAspect() . '.txt'; if ($httpHost != $refInfo['host'] && !$GLOBALS['TYPO3_CONF_VARS']['SYS']['doNotCheckReferer']) { - $this->fileProcessor->writeLog(0, 2, 1, 'Referer host "%s" and server host "%s" did not match!', [$refInfo['host'], $httpHost]); + $extendedFileUtility->writeLog(0, 2, 1, 'Referer host "%s" and server host "%s" did not match!', [$refInfo['host'], $httpHost]); } else { - $this->fileProcessor->start($file); - $newfileObj = $this->fileProcessor->func_newfile($file['newfile']['1']); - // in TYPO3 6.0 func_newfile returns an object, but we need the path to the new file name later on! + // new file + $file['newfile']['target'] = $this->userTempFolder(); + $file['newfile']['data'] = 'import_' . $this->getTimestampFromAspect() . '.txt'; + $extendedFileUtility->start($file); + $newfileObj = $extendedFileUtility->func_newfile($file['newfile']); if (is_object($newfileObj)) { $storageConfig = $newfileObj->getStorage()->getConfiguration(); - $newfile = $storageConfig['basePath'] . ltrim($newfileObj->getIdentifier(), '/'); + $newfile['newFile'] = $storageConfig['basePath'] . ltrim($newfileObj->getIdentifier(), '/'); + $newfile['newFileUid'] = $newfileObj->getUid(); } } } else { - $newfile = $this->indata['newFile']; + $newfile = ['newFile' => $newFile, 'newFileUid' => $newFileUid]; } - if ($newfile) { - $csvFile['data'] = $this->indata['csv'] ?? ''; - $csvFile['target'] = $newfile; - $write = $this->fileProcessor->func_edit($csvFile); + if ($newfile['newFile']) { + $csvFile = [ + 'data' => $csv, + 'target' => $newfile['newFile'] + ]; + $write = $extendedFileUtility->func_edit($csvFile); } return $newfile; } @@ -1069,6 +997,58 @@ public function checkUpload() return $newfile; } + /** + * + * @param int $fileUid + * @return \TYPO3\CMS\Core\Resource\File|bool + */ + private function getFileById(int $fileUid) //: \TYPO3\CMS\Core\Resource\File|bool + { + $resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class); + try { + return $resourceFactory->getFileObject($fileUid); + } + catch(\TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException $e) { + + } + return false; + } + + /** + * + * @param int $fileUid + * @return string + */ + private function getFileAbsolutePath(int $fileUid): string + { + $file = $this->getFileById($fileUid); + if(!is_object($file)) { + return ''; + } + return Environment::getPublicPath() . '/' . str_replace('//', '/', $file->getStorage()->getConfiguration()['basePath'] . $file->getProperty('identifier')); + } + + /** + * Returns first temporary folder of the user account + * + * @return string Absolute path to first "_temp_" folder of the current user, otherwise blank. + */ + public function userTempFolder() + { + /** @var \TYPO3\CMS\Core\Resource\Folder $folder */ + $folder = $this->getBeUser()->getDefaultUploadTemporaryFolder(); + return $folder->getPublicUrl(); + } + + /** + * + * @return int + */ + private function getTimestampFromAspect(): int { + $context = GeneralUtility::makeInstance(Context::class); + return $context->getPropertyFromAspect('date', 'timestamp'); + } + /** * Returns LanguageService * From db23d514d5f06cdb8d670201706f445f054ea3c7 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Fri, 19 Aug 2022 14:33:59 +0200 Subject: [PATCH 283/342] update function 'checkUpload' --- Classes/Importer.php | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/Classes/Importer.php b/Classes/Importer.php index 6797c0fac..8691e858f 100644 --- a/Classes/Importer.php +++ b/Classes/Importer.php @@ -55,13 +55,6 @@ class Importer */ public $parent; - /** - * File Processor FAL - * - * @var ExtendedFileUtility - */ - public $fileProcessor; - /** * Init the class * @@ -977,22 +970,22 @@ public function checkUpload() ]; // Initializing: - /* @var $fileProcessor ExtendedFileUtility */ - $this->fileProcessor = GeneralUtility::makeInstance(ExtendedFileUtility::class); - $this->fileProcessor->setActionPermissions(); - $this->fileProcessor->dontCheckForUnique = 1; - + /* @var $extendedFileUtility ExtendedFileUtility */ + $extendedFileUtility = GeneralUtility::makeInstance(ExtendedFileUtility::class); + $extendedFileUtility->setActionPermissions(); + $extendedFileUtility->setExistingFilesConflictMode(DuplicationBehavior::REPLACE); + // Checking referer / executing: $refInfo = parse_url(GeneralUtility::getIndpEnv('HTTP_REFERER')); $httpHost = GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY'); if ($httpHost != $refInfo['host'] && !$GLOBALS['TYPO3_CONF_VARS']['SYS']['doNotCheckReferer']) { - $this->fileProcessor->writeLog(0, 2, 1, 'Referer host "%s" and server host "%s" did not match!', [$refInfo['host'], $httpHost]); + $extendedFileUtility->writeLog(0, 2, 1, 'Referer host "%s" and server host "%s" did not match!', [$refInfo['host'], $httpHost]); } else { - $this->fileProcessor->start($file); - $this->fileProcessor->setExistingFilesConflictMode(DuplicationBehavior::cast(DuplicationBehavior::REPLACE)); - $newfile = $this->fileProcessor->func_upload($file['upload']['1']); + $extendedFileUtility->start($file); + $extendedFileUtility->setExistingFilesConflictMode(DuplicationBehavior::cast(DuplicationBehavior::REPLACE)); + $newfile = $extendedFileUtility->func_upload($file['upload']['1']); } return $newfile; } From d03f661564b163b05faed3dfc1c11c4233f6bed5 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Fri, 19 Aug 2022 15:09:04 +0200 Subject: [PATCH 284/342] update function 'checkUpload' --- Classes/Importer.php | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/Classes/Importer.php b/Classes/Importer.php index 8691e858f..4b9faa11f 100644 --- a/Classes/Importer.php +++ b/Classes/Importer.php @@ -179,12 +179,9 @@ public function displayImport() // merge it with inData, but inData has priority. $this->indata += $this->params; if (empty($this->indata['csv']) && !empty($_FILES['upload_1']['name'])) { - $this->indata['newFile'] = $this->checkUpload(); - if (is_object($this->indata['newFile'][0])) { - $storageConfig = $this->indata['newFile'][0]->getStorage()->getConfiguration(); - $this->indata['newFileUid'] = $this->indata['newFile'][0]->getUid(); - $this->indata['newFile'] = rtrim($storageConfig['basePath'], '/') . '/' . ltrim($this->indata['newFile'][0]->getIdentifier(), '/'); - } + $tempFile = $this->checkUpload(); + $this->indata['newFile'] = $tempFile['newFile']; + $this->indata['newFileUid'] = $tempFile['newFileUid']; } elseif (!empty($this->indata['csv']) && empty($_FILES['upload_1']['name'])) { unset($this->indata['newFile']); @@ -957,18 +954,8 @@ public function writeTempFile(string $csv, string $newFile, int $newFileUid) */ public function checkUpload() { - $file = GeneralUtility::_GP('file'); - $fm = []; - - $tempFolder = $this->userTempFolder(); - $array = explode('/', trim($tempFolder, '/')); - $fm = [ - $this->getTimestampFromAspect() => [ - 'path' => $tempFolder, - 'name' => array_pop($array) . '/', - ] - ]; - + $newfile = ['newFile' => '', 'newFileUid' => 0]; + // Initializing: /* @var $extendedFileUtility ExtendedFileUtility */ $extendedFileUtility = GeneralUtility::makeInstance(ExtendedFileUtility::class); @@ -983,10 +970,20 @@ public function checkUpload() $extendedFileUtility->writeLog(0, 2, 1, 'Referer host "%s" and server host "%s" did not match!', [$refInfo['host'], $httpHost]); } else { + $file = GeneralUtility::_GP('file'); $extendedFileUtility->start($file); $extendedFileUtility->setExistingFilesConflictMode(DuplicationBehavior::cast(DuplicationBehavior::REPLACE)); - $newfile = $extendedFileUtility->func_upload($file['upload']['1']); + $tempFile = $extendedFileUtility->func_upload($file['upload']['1']); + + if (is_object($tempFile[0])) { + $storageConfig = $tempFile[0]->getStorage()->getConfiguration(); + $newfile = [ + 'newFile' => rtrim($storageConfig['basePath'], '/') . '/' . ltrim($tempFile[0]->getIdentifier(), '/'), + 'newFileUid' => $tempFile[0]->getUid() + ]; + } } + return $newfile; } From 1a470772e4e5a58b5241635b171ecacee77ca0be Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Fri, 19 Aug 2022 16:08:47 +0200 Subject: [PATCH 285/342] replace getIndpEnv with 'HTTP_REFERER' and 'TYPO3_HOST_ONLY' --- Classes/Importer.php | 8 ++++---- Classes/Module/RecipientListController.php | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Classes/Importer.php b/Classes/Importer.php index 4b9faa11f..7b15b6a7b 100644 --- a/Classes/Importer.php +++ b/Classes/Importer.php @@ -913,8 +913,8 @@ public function writeTempFile(string $csv, string $newFile, int $newFileUid) if (empty($this->indata['newFile'])) { // Checking referer / executing: - $refInfo = parse_url(GeneralUtility::getIndpEnv('HTTP_REFERER')); - $httpHost = GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY'); + $refInfo = parse_url($this->parent->getHttpReferer()); + $httpHost = $this->parent->getRequestHostOnly(); if ($httpHost != $refInfo['host'] && !$GLOBALS['TYPO3_CONF_VARS']['SYS']['doNotCheckReferer']) { $extendedFileUtility->writeLog(0, 2, 1, 'Referer host "%s" and server host "%s" did not match!', [$refInfo['host'], $httpHost]); @@ -963,8 +963,8 @@ public function checkUpload() $extendedFileUtility->setExistingFilesConflictMode(DuplicationBehavior::REPLACE); // Checking referer / executing: - $refInfo = parse_url(GeneralUtility::getIndpEnv('HTTP_REFERER')); - $httpHost = GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY'); + $refInfo = parse_url($this->parent->getHttpReferer()); + $httpHost = $this->parent->getRequestHostOnly(); if ($httpHost != $refInfo['host'] && !$GLOBALS['TYPO3_CONF_VARS']['SYS']['doNotCheckReferer']) { $extendedFileUtility->writeLog(0, 2, 1, 'Referer host "%s" and server host "%s" did not match!', [$refInfo['host'], $httpHost]); diff --git a/Classes/Module/RecipientListController.php b/Classes/Module/RecipientListController.php index 9cf4605d5..d275cde1d 100644 --- a/Classes/Module/RecipientListController.php +++ b/Classes/Module/RecipientListController.php @@ -42,12 +42,20 @@ class RecipientListController extends MainController protected int $uid = 0; protected string $table = ''; protected array $indata = []; + + protected $requestHostOnly = ''; + protected $httpReferer = ''; + private bool $submit = false; protected function initRecipientList(ServerRequestInterface $request): void { $queryParams = $request->getQueryParams(); $parsedBody = $request->getParsedBody(); + $normalizedParams = $request->getAttribute('normalizedParams'); + $this->requestHostOnly = $normalizedParams->getRequestHostOnly(); + $this->httpReferer = $request->getServerParams()['HTTP_REFERER']; + $this->group_uid = (int)($parsedBody['group_uid'] ?? $queryParams['group_uid'] ?? 0); $this->lCmd = $parsedBody['lCmd'] ?? $queryParams['lCmd'] ?? ''; $this->csv = $parsedBody['csv'] ?? $queryParams['csv'] ?? ''; @@ -783,4 +791,14 @@ protected function displayUserInfo() } return $dataout; } + + public function getRequestHostOnly(): string + { + return $this->requestHostOnly; + } + + public function getHttpReferer(): string + { + return $this->httpReferer; + } } \ No newline at end of file From f24cc9c0f8c427c0742d677e6ddf881775a8e98e Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Fri, 19 Aug 2022 16:16:57 +0200 Subject: [PATCH 286/342] replace getIndpEnv with 'REQUEST_URI' --- Classes/Module/RecipientListController.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Classes/Module/RecipientListController.php b/Classes/Module/RecipientListController.php index d275cde1d..caebc7a2b 100644 --- a/Classes/Module/RecipientListController.php +++ b/Classes/Module/RecipientListController.php @@ -44,6 +44,7 @@ class RecipientListController extends MainController protected array $indata = []; protected $requestHostOnly = ''; + protected $requestUri = ''; protected $httpReferer = ''; private bool $submit = false; @@ -54,6 +55,7 @@ protected function initRecipientList(ServerRequestInterface $request): void { $normalizedParams = $request->getAttribute('normalizedParams'); $this->requestHostOnly = $normalizedParams->getRequestHostOnly(); + $this->requestUri = $normalizedParams->getRequestUri(); $this->httpReferer = $request->getServerParams()['HTTP_REFERER']; $this->group_uid = (int)($parsedBody['group_uid'] ?? $queryParams['group_uid'] ?? 0); @@ -202,7 +204,7 @@ protected function showExistingRecipientLists() $this->id => 'new' ] ], - 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI'), + 'returnUrl' => $this->requestUri, ]); $data['sysDmailGroupIcon'] = $this->iconFactory->getIconForRecord('sys_dmail_group', [], Icon::SIZE_SMALL); @@ -387,7 +389,7 @@ protected function editLink($table, $uid) $uid => 'edit', ], ], - 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI'), + 'returnUrl' => $this->requestUri, ]); $str = '' . $this->getIconActionsOpen() . @@ -761,7 +763,7 @@ protected function displayUserInfo() $row['uid'] => 'edit' ] ], - 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI'), + 'returnUrl' => $this->requestUri, ]); $dataout = [ From c57f5239a0ca7360c38fb5998506beb96ad7c9ff Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Fri, 19 Aug 2022 16:36:20 +0200 Subject: [PATCH 287/342] replace getIndpEnv with 'REQUEST_URI' --- Classes/Module/ConfigurationController.php | 7 ++++++- Classes/Module/DmailController.php | 9 +++++++-- Classes/Module/StatisticsController.php | 7 ++++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Classes/Module/ConfigurationController.php b/Classes/Module/ConfigurationController.php index 05aef1526..540d9569e 100644 --- a/Classes/Module/ConfigurationController.php +++ b/Classes/Module/ConfigurationController.php @@ -15,6 +15,8 @@ class ConfigurationController extends MainController protected string $TSconfPrefix = 'mod.web_modules.dmail.'; protected array $pageTS = []; + protected $requestUri = ''; + public function indexAction(ServerRequestInterface $request) : ResponseInterface { $currentModule = 'Configuration'; @@ -65,6 +67,9 @@ protected function initConfiguration(ServerRequestInterface $request): void { $queryParams = $request->getQueryParams(); $parsedBody = $request->getParsedBody(); + $normalizedParams = $request->getAttribute('normalizedParams'); + $this->requestUri = $normalizedParams->getRequestUri(); + $this->pageTS = $parsedBody['pageTS'] ?? $queryParams['pageTS'] ?? []; } @@ -92,7 +97,7 @@ protected function updatePageTS() if ($this->getBackendUser()->doesUserHaveAccess(BackendUtility::getRecord('pages', $this->id), 2)) { if (is_array($this->pageTS) && count($this->pageTS)) { DirectMailUtility::updatePagesTSconfig($this->id, $this->pageTS, $this->TSconfPrefix); - header('Location: ' . GeneralUtility::locationHeaderUrl(GeneralUtility::getIndpEnv('REQUEST_URI'))); + header('Location: ' . GeneralUtility::locationHeaderUrl($this->requestUri)); } } } diff --git a/Classes/Module/DmailController.php b/Classes/Module/DmailController.php index b7787f45f..1b7de4554 100644 --- a/Classes/Module/DmailController.php +++ b/Classes/Module/DmailController.php @@ -60,6 +60,8 @@ class DmailController extends MainController protected bool $mailingMode_simple = false; protected int $tt_address_uid = 0; + protected $requestUri = ''; + /** * The name of the module * @@ -83,6 +85,9 @@ protected function initDmail(ServerRequestInterface $request): void { $queryParams = $request->getQueryParams(); $parsedBody = $request->getParsedBody(); + $normalizedParams = $request->getAttribute('normalizedParams'); + $this->requestUri = $normalizedParams->getRequestUri(); + $this->uid = (int)($parsedBody['uid'] ?? $queryParams['uid'] ?? 0); $update_cats = $parsedBody['update_cats'] ?? $queryParams['update_cats'] ?? false; @@ -676,7 +681,7 @@ protected function getNews(): array $row['uid'] => 'edit', ] ], - 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI'), + 'returnUrl' => $this->requestUri, ]; $data[] = [ @@ -1408,7 +1413,7 @@ public function getRecordList(array $listArr, $table, $editLinkFlag=1, $testMail if ($row['uid']) { $tableIcon = '

'; if ($editLinkFlag) { - $requestUri = GeneralUtility::getIndpEnv('REQUEST_URI') . '&cmd=send_test&sys_dmail_uid=' . $this->sys_dmail_uid . '&pages_uid=' . $this->pages_uid; + $requestUri = $this->requestUri . '&cmd=send_test&sys_dmail_uid=' . $this->sys_dmail_uid . '&pages_uid=' . $this->pages_uid; $params = [ 'edit' => [ diff --git a/Classes/Module/StatisticsController.php b/Classes/Module/StatisticsController.php index 9a46229e5..cdf3d8c09 100644 --- a/Classes/Module/StatisticsController.php +++ b/Classes/Module/StatisticsController.php @@ -30,6 +30,8 @@ class StatisticsController extends MainController */ protected $moduleName = 'DirectMailNavFrame_Statistics'; + protected $requestUri = ''; + private int $uid = 0; private string $table = ''; private array $tables = ['tt_address', 'fe_users']; @@ -69,6 +71,9 @@ protected function initStatistics(ServerRequestInterface $request): void { $queryParams = $request->getQueryParams(); $parsedBody = $request->getParsedBody(); + $normalizedParams = $request->getAttribute('normalizedParams'); + $this->requestUri = $normalizedParams->getRequestUri(); + $this->uid = (int)($parsedBody['uid'] ?? $queryParams['uid'] ?? 0); $table = (string)($parsedBody['table'] ?? $queryParams['table'] ?? ''); @@ -320,7 +325,7 @@ protected function displayUserInfo() $row['uid'] => 'edit', ], ], - 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI'), + 'returnUrl' => $this->requestUri, ]); $this->categories = DirectMailUtility::makeCategories($this->table, $row, $this->sys_language_uid); From aa5886a7f1b1568613a06890d04d0ee600a7607a Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Fri, 19 Aug 2022 17:08:52 +0200 Subject: [PATCH 288/342] fix mandatory mapping --- Classes/Importer.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Classes/Importer.php b/Classes/Importer.php index 7b15b6a7b..2091711db 100644 --- a/Classes/Importer.php +++ b/Classes/Importer.php @@ -212,7 +212,7 @@ public function displayImport() } // check if "email" is mapped - if (isset($stepCurrent) && $stepCurrent === 'import') { + if (isset($stepCurrent) && $stepCurrent === 'startImport') { $map = $this->indata['map']; $error = []; // check noMap @@ -223,7 +223,7 @@ public function displayImport() elseif (!in_array('email', $map)) { $error[] = 'email'; } - if ($error) { + if (count($error)) { $stepCurrent = 'mapping'; } } @@ -552,7 +552,7 @@ public function displayImport() * * @return array Filtered csv and double csv */ - public function filterCSV(array $mappedCsv) + public function filterCSV(array $mappedCsv): array { $cmpCsv = $mappedCsv; $remove = []; @@ -561,7 +561,7 @@ public function filterCSV(array $mappedCsv) foreach ($mappedCsv as $k => $csvData) { if (!in_array($k, $remove)) { - $found=0; + $found = 0; foreach ($cmpCsv as $kk =>$cmpData) { if ($k != $kk) { if ($csvData[$this->indata['record_unique']] == $cmpData[$this->indata['record_unique']]) { @@ -569,8 +569,8 @@ public function filterCSV(array $mappedCsv) if (!$found) { $filtered[] = $csvData; } - $remove[]=$kk; - $found=1; + $remove[] = $kk; + $found = 1; } } } From b2bdf7857575e9a043556f6fee8108c5e841613a Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Fri, 19 Aug 2022 17:30:17 +0200 Subject: [PATCH 289/342] add SysDmailTtAddressCategoryMmRepository --- Classes/Importer.php | 3 ++ .../SysDmailTtAddressCategoryMmRepository.php | 32 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 Classes/Repository/SysDmailTtAddressCategoryMmRepository.php diff --git a/Classes/Importer.php b/Classes/Importer.php index 2091711db..48fc4d611 100644 --- a/Classes/Importer.php +++ b/Classes/Importer.php @@ -17,6 +17,7 @@ use DirectMailTeam\DirectMail\Module\RecipientList; use DirectMailTeam\DirectMail\Repository\PagesRepository; use DirectMailTeam\DirectMail\Repository\SysDmailCategoryRepository; +use DirectMailTeam\DirectMail\Repository\SysDmailTtAddressCategoryMmRepository; use DirectMailTeam\DirectMail\Repository\TtAddressRepository; use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Core\Charset\CharsetConverter; @@ -669,6 +670,8 @@ public function doImport(array $csvData) } if (is_array($this->indata['cat']) && !in_array('cats', $this->indata['map'])) { if ($this->indata['add_cat']) { + //@TODO + //$rows = GeneralUtility::makeInstance(SysDmailTtAddressCategoryMmRepository::class)->selectUidsByUidLocal((int)$userID[$foundUser[0]]); // Load already assigned categories $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_dmail_ttaddress_category_mm'); $statement = $queryBuilder diff --git a/Classes/Repository/SysDmailTtAddressCategoryMmRepository.php b/Classes/Repository/SysDmailTtAddressCategoryMmRepository.php new file mode 100644 index 000000000..1999d18f7 --- /dev/null +++ b/Classes/Repository/SysDmailTtAddressCategoryMmRepository.php @@ -0,0 +1,32 @@ +getQueryBuilder($this->table); + + return $queryBuilder + ->select( + 'uid_local', + 'uid_foreign' + ) + ->from($this->table) + ->where( + $queryBuilder->expr()->eq( + 'uid_local', + $queryBuilder->createNamedParameter($uidLocal, \PDO::PARAM_INT) + ) + ) + ->orderBy('sorting') + ->execute() + ->fetchAll(); + } +} \ No newline at end of file From e1845190091b3951e0334868094e6797531a5d9f Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sun, 21 Aug 2022 19:07:58 +0200 Subject: [PATCH 290/342] use function from SysDmailTtAddressCategoryMmRepository --- Classes/Importer.php | 37 ++++++------------- .../Private/Templates/RecipientList.html | 2 +- 2 files changed, 12 insertions(+), 27 deletions(-) diff --git a/Classes/Importer.php b/Classes/Importer.php index 48fc4d611..940121c29 100644 --- a/Classes/Importer.php +++ b/Classes/Importer.php @@ -23,7 +23,6 @@ use TYPO3\CMS\Core\Charset\CharsetConverter; use TYPO3\CMS\Core\Context\Context; use TYPO3\CMS\Core\Core\Environment; -use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\DataHandling\DataHandler; use TYPO3\CMS\Core\Localization\LanguageService; use TYPO3\CMS\Core\Resource\DuplicationBehavior; @@ -147,6 +146,7 @@ public function displayImport() 'all_html' => false, 'hiddenMap' => [], 'hiddenCat' => [], + 'add_cat' => false, 'tables' => [] ] ]; @@ -399,7 +399,6 @@ public function displayImport() $temp['value'] = BackendUtility::getPagesTSconfig($this->parent->getId())['TCEFORM.']['sys_dmail_group.']['select_categories.']['PAGE_TSCONFIG_IDLIST'] ?? null; if (is_numeric($temp['value'])) { $rowCat = GeneralUtility::makeInstance(SysDmailCategoryRepository::class)->selectSysDmailCategoryByPid((int)$temp['value']); - if (!empty($rowCat)) { // additional options if ($output['mapping']['update_unique']) { @@ -433,8 +432,10 @@ public function displayImport() $output['startImport']['update_unique'] = $this->indata['update_unique']; $output['startImport']['record_unique'] = $this->indata['record_unique']; $output['startImport']['all_html'] = !$this->indata['all_html'] ? false : true; - $output['startImport']['error'] = $error; + $output['startImport']['add_cat'] = $this->indata['add_cat'] ? true : false; + $output['startImport']['error'] = $error; + // starting import & show errors // read csv $csvData = $this->readCSV(); @@ -670,27 +671,11 @@ public function doImport(array $csvData) } if (is_array($this->indata['cat']) && !in_array('cats', $this->indata['map'])) { if ($this->indata['add_cat']) { - //@TODO - //$rows = GeneralUtility::makeInstance(SysDmailTtAddressCategoryMmRepository::class)->selectUidsByUidLocal((int)$userID[$foundUser[0]]); - // Load already assigned categories - $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_dmail_ttaddress_category_mm'); - $statement = $queryBuilder - ->select( - 'uid_local', - 'uid_foreign' - ) - ->from('sys_dmail_ttaddress_category_mm') - ->where( - $queryBuilder->expr()->eq( - 'uid_local', - $userID[$foundUser[0]] - ) - ) - ->orderBy('sorting') - ->execute(); - - while (($row = $statement->fetch())) { - $data['tt_address'][$userID[$foundUser[0]]]['module_sys_dmail_category'][] = $row[1]; + $rows = GeneralUtility::makeInstance(SysDmailTtAddressCategoryMmRepository::class)->selectUidsByUidLocal((int)$userID[$foundUser[0]]); + if(is_array($rows)) { + foreach($rows as $row) { + $data['tt_address'][$userID[$foundUser[0]]]['module_sys_dmail_category'][] = $row['uid_foreign']; + } } } // Add categories @@ -698,7 +683,7 @@ public function doImport(array $csvData) $data['tt_address'][$userID[$foundUser[0]]]['module_sys_dmail_category'][] = $v; } } - $resultImport['update'][]=$dataArray; + $resultImport['update'][] = $dataArray; } else { // which one to update? all? @@ -706,7 +691,7 @@ public function doImport(array $csvData) $data['tt_address'][$userID[$foundUser[$kk]]] = $dataArray; $data['tt_address'][$userID[$foundUser[$kk]]]['pid'] = $this->indata['storage']; } - $resultImport['update'][]=$dataArray; + $resultImport['update'][] = $dataArray; } } else { diff --git a/Resources/Private/Templates/RecipientList.html b/Resources/Private/Templates/RecipientList.html index e193292f7..4e545547b 100644 --- a/Resources/Private/Templates/RecipientList.html +++ b/Resources/Private/Templates/RecipientList.html @@ -389,7 +389,6 @@

- @@ -444,6 +443,7 @@

+
{formcontent.theOutput} From b82c5bd24e378de8c33460359f99e1d0c0dd7e69 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sun, 21 Aug 2022 20:09:58 +0200 Subject: [PATCH 291/342] fix output of special.selectTables --- Classes/MailSelect.php | 2 +- Resources/Private/Templates/RecipientList.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Classes/MailSelect.php b/Classes/MailSelect.php index 72e18a8fd..6e21b5113 100644 --- a/Classes/MailSelect.php +++ b/Classes/MailSelect.php @@ -23,7 +23,7 @@ /** * Used to generate queries for selecting users in the database * - * @author Kasper Sk�rh�j + * @author Kasper Skårhøj * @author Stanislas Rolland * * @package TYPO3 diff --git a/Resources/Private/Templates/RecipientList.html b/Resources/Private/Templates/RecipientList.html index 4e545547b..ca770c6d8 100644 --- a/Resources/Private/Templates/RecipientList.html +++ b/Resources/Private/Templates/RecipientList.html @@ -66,7 +66,7 @@

{data.special.selected}
- {data.special.selectTables} + {data.special.selectTables} From df20541b4d8567255975a17257da18baf530e55e Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sun, 21 Aug 2022 21:10:19 +0200 Subject: [PATCH 292/342] add in RecipientListController --- Classes/Module/RecipientListController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Classes/Module/RecipientListController.php b/Classes/Module/RecipientListController.php index caebc7a2b..bf7f3275b 100644 --- a/Classes/Module/RecipientListController.php +++ b/Classes/Module/RecipientListController.php @@ -46,6 +46,7 @@ class RecipientListController extends MainController protected $requestHostOnly = ''; protected $requestUri = ''; protected $httpReferer = ''; + protected $allowedTables = ['tt_address', 'fe_users']; private bool $submit = false; From 44ad40c795877f2488e6181c38ff4b4fa2bb5a06 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Sun, 21 Aug 2022 21:15:11 +0200 Subject: [PATCH 293/342] fix comment --- Classes/Dmailer.php | 2 +- Classes/Module/Configuration.php | 2 +- Classes/Module/MailerEngine.php | 2 +- Classes/Module/RecipientList.php | 2 +- Classes/Module/Statistics.php | 2 +- Classes/Plugin/DirectMail.php | 4 ++-- Classes/Readmail.php | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Classes/Dmailer.php b/Classes/Dmailer.php index 26e117e9d..9b2122f42 100755 --- a/Classes/Dmailer.php +++ b/Classes/Dmailer.php @@ -30,7 +30,7 @@ /** * Class, doing the sending of Direct-mails, eg. through a cron-job * - * @author Kasper Skaarhoj + * @author Kasper Skårhøj * @author Stanislas Rolland * * @package TYPO3 diff --git a/Classes/Module/Configuration.php b/Classes/Module/Configuration.php index cfbdf73e7..742058ca7 100644 --- a/Classes/Module/Configuration.php +++ b/Classes/Module/Configuration.php @@ -29,7 +29,7 @@ /** * Module Configuration for tx_directmail extension * - * @author Kasper Sk�rh�j + * @author Kasper Skårhøj * @author Jan-Erik Revsbech * @author Stanislas Rolland * @author Ivan-Dharma Kartolo diff --git a/Classes/Module/MailerEngine.php b/Classes/Module/MailerEngine.php index 63b6c6231..81f03bf77 100644 --- a/Classes/Module/MailerEngine.php +++ b/Classes/Module/MailerEngine.php @@ -34,7 +34,7 @@ /** * Module Mailer-Engine for tx_directmail extension * - * @author Kasper Sk�rh�j + * @author Kasper Skårhøj * @author Jan-Erik Revsbech * @author Stanislas Rolland * @author Ivan-Dharma Kartolo diff --git a/Classes/Module/RecipientList.php b/Classes/Module/RecipientList.php index ebf104297..7cdbfb7a9 100644 --- a/Classes/Module/RecipientList.php +++ b/Classes/Module/RecipientList.php @@ -36,7 +36,7 @@ /** * Recipient list module for tx_directmail extension * - * @author Kasper Sk�rh�j + * @author Kasper Skårhøj * @author Jan-Erik Revsbech * @author Stanislas Rolland * @author Ivan-Dharma Kartolo diff --git a/Classes/Module/Statistics.php b/Classes/Module/Statistics.php index 785227f05..689ec7428 100644 --- a/Classes/Module/Statistics.php +++ b/Classes/Module/Statistics.php @@ -35,7 +35,7 @@ /** * Module Statistics of tx_directmail extension * - * @author Kasper Sk�rh�j + * @author Kasper Skårhøj * @author Jan-Erik Revsbech * @author Stanislas Rolland * @author Ivan-Dharma Kartolo diff --git a/Classes/Plugin/DirectMail.php b/Classes/Plugin/DirectMail.php index 07a84edd7..fc1bb142e 100644 --- a/Classes/Plugin/DirectMail.php +++ b/Classes/Plugin/DirectMail.php @@ -4,7 +4,7 @@ /*************************************************************** * Copyright notice * -* (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com) +* (c) 1999-2005 Kasper Skårhøj (kasperYYYY@typo3.com) * (c) 2006 Stanislas Rolland * All rights reserved * @@ -29,7 +29,7 @@ ***************************************************************/ /** - * @author Kasper Skaarhoj + * @author Kasper Skårhøj * @author Stanislas Rolland * * @package TYPO3 diff --git a/Classes/Readmail.php b/Classes/Readmail.php index c5a4e387a..7cc17a43f 100644 --- a/Classes/Readmail.php +++ b/Classes/Readmail.php @@ -21,7 +21,7 @@ * Analysis of return mail reason is enhanced by checking more possible reason texts. * Tested on mailing list of approx. 1500 members with most domains in M�xico and reason text in English or Spanish. * - * @author Kasper Sk�rh�j + * @author Kasper Skårhøj * @author Stanislas Rolland * * @package TYPO3 From 296900882d618666d883bb044887c81ff0fac096 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Wed, 24 Aug 2022 17:20:32 +0200 Subject: [PATCH 294/342] move function in temp repository --- Classes/Module/RecipientListController.php | 12 ++-- Classes/Repository/TempRepository.php | 64 ++++++++++++++++++++++ 2 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 Classes/Repository/TempRepository.php diff --git a/Classes/Module/RecipientListController.php b/Classes/Module/RecipientListController.php index bf7f3275b..f778ca93f 100644 --- a/Classes/Module/RecipientListController.php +++ b/Classes/Module/RecipientListController.php @@ -19,6 +19,7 @@ use DirectMailTeam\DirectMail\DirectMailUtility; use DirectMailTeam\DirectMail\Repository\SysDmailGroupRepository; use DirectMailTeam\DirectMail\Repository\FeUsersRepository; +use DirectMailTeam\DirectMail\Repository\TempRepository; use DirectMailTeam\DirectMail\Repository\TtAddressRepository; class RecipientListController extends MainController @@ -461,17 +462,18 @@ protected function displayMailGroup($result) ]; // do the CSV export - $csvValue = $this->csv; + $csvValue = $this->csv; //'tt_address', 'fe_users', 'PLAINLIST', $this->userTable if ($csvValue) { if ($csvValue == 'PLAINLIST') { $this->downloadCSV($idLists['PLAINLIST']); } elseif (GeneralUtility::inList('tt_address,fe_users,' . $this->userTable, $csvValue)) { if($this->getBackendUser()->check('tables_select', $csvValue)) { - $this->downloadCSV(DirectMailUtility::fetchRecordsListValues($idLists[$csvValue], $csvValue, (($csvValue == 'fe_users') - ? str_replace('phone', 'telephone', $this->fieldList) - : $this->fieldList) . ',tstamp') - ); + $fields = $csvValue == 'fe_users' ? str_replace('phone', 'telephone', $this->fieldList) : $this->fieldList; + $fields .= ',tstamp'; + + $rows = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists[$csvValue], $csvValue, $fields); + $this->downloadCSV($rows); } else { $message = $this->createFlashMessage( diff --git a/Classes/Repository/TempRepository.php b/Classes/Repository/TempRepository.php new file mode 100644 index 000000000..ca33be98d --- /dev/null +++ b/Classes/Repository/TempRepository.php @@ -0,0 +1,64 @@ +getQueryBuilderForTable($table); + $queryBuilder + ->getRestrictions() + ->removeAll() + ->add(GeneralUtility::makeInstance(DeletedRestriction::class)); + + $fieldArray = GeneralUtility::trimExplode(',', $fields); + + // handle selecting multiple fields + foreach ($fieldArray as $i => $field) { + if ($i) { + $queryBuilder->addSelect($field); + } + else { + $queryBuilder->select($field); + } + } + + $res = $queryBuilder->from($table) + ->where( + $queryBuilder->expr()->in( + 'uid', + $queryBuilder->createNamedParameter( + GeneralUtility::intExplode(',', $idlist), + Connection::PARAM_INT_ARRAY + ) + ) + ) + ->execute(); + + while ($row = $res->fetch()) { + $outListArr[$row['uid']] = $row; + } + } + return $outListArr; + } +} \ No newline at end of file From 79018822e43ec6bf300eef885947b48bac28deb7 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Wed, 24 Aug 2022 19:37:03 +0200 Subject: [PATCH 295/342] use function from temp repository --- Classes/DirectMailUtility.php | 2 +- Classes/Module/RecipientListController.php | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Classes/DirectMailUtility.php b/Classes/DirectMailUtility.php index ec6fc4ad9..fbce830b7 100644 --- a/Classes/DirectMailUtility.php +++ b/Classes/DirectMailUtility.php @@ -64,7 +64,7 @@ class DirectMailUtility * * @return array recipients' data */ - public static function fetchRecordsListValues(array $listArr, $table, $fields='uid,name,email') + public static function fetchRecordsListValues(array $listArr, $table, $fields = 'uid,name,email') { $outListArr = []; if (is_array($listArr) && count($listArr)) { diff --git a/Classes/Module/RecipientListController.php b/Classes/Module/RecipientListController.php index f778ca93f..1536b8c14 100644 --- a/Classes/Module/RecipientListController.php +++ b/Classes/Module/RecipientListController.php @@ -490,16 +490,18 @@ protected function displayMailGroup($result) switch ($this->lCmd) { case 'listall': if (is_array($idLists['tt_address'] ?? false)) { + $rows = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists['tt_address'], 'tt_address'); $data['tables'][] = [ 'title_table' => 'mailgroup_table_address', - 'recip_list' => DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address', $this->id), + 'recip_list' => DirectMailUtility::getRecordList($rows, 'tt_address', $this->id), 'table_custom' => '' ]; } if (is_array($idLists['fe_users'] ?? false)) { + $rows = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists['fe_users'], 'fe_users'); $data['tables'][] = [ 'title_table' => 'mailgroup_table_fe_users', - 'recip_list' => DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users', $this->id), + 'recip_list' => DirectMailUtility::getRecordList($rows, 'fe_users', $this->id), 'table_custom' => '' ]; } @@ -511,9 +513,10 @@ protected function displayMailGroup($result) ]; } if (is_array($idLists[$this->userTable] ?? false)) { + $rows = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists[$this->userTable], $this->userTable); $data['tables'][] = [ 'title_table' => 'mailgroup_table_custom', - 'recip_list' => DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists[$this->userTable], $this->userTable), $this->userTable, $this->id), + 'recip_list' => DirectMailUtility::getRecordList($rows, $this->userTable, $this->id), 'table_custom' => ' '.$this->userTable ]; } From ad325080471fc963d17cc9c8b9ef2c1dd490f446 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Wed, 24 Aug 2022 19:51:16 +0200 Subject: [PATCH 296/342] use function from temp repository --- Classes/Module/DmailController.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Classes/Module/DmailController.php b/Classes/Module/DmailController.php index 1b7de4554..efa17675c 100644 --- a/Classes/Module/DmailController.php +++ b/Classes/Module/DmailController.php @@ -9,6 +9,7 @@ use DirectMailTeam\DirectMail\Repository\PagesRepository; use DirectMailTeam\DirectMail\Repository\SysDmailGroupRepository; use DirectMailTeam\DirectMail\Repository\SysDmailRepository; +use DirectMailTeam\DirectMail\Repository\TempRepository; use DirectMailTeam\DirectMail\Repository\TtAddressRepository; use DirectMailTeam\DirectMail\Repository\TtContentCategoryMmRepository; use DirectMailTeam\DirectMail\Repository\TtContentRepository; @@ -1103,8 +1104,8 @@ protected function getTestMailConfig(): array foreach ($rows as $row) { $ids[] = $row['uid']; } - - $data['test_tt_address'] = $this->getRecordList(DirectMailUtility::fetchRecordsListValues($ids, 'tt_address'), 'tt_address', 1, 1); + $rows = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($ids, 'tt_address'); + $data['test_tt_address'] = $this->getRecordList($rows, 'tt_address', 1, 1); } if ($this->params['test_dmail_group_uids'] ?? false) { @@ -1155,16 +1156,19 @@ public function displayMailGroup_test($result) $idLists = $result['queryInfo']['id_lists']; $out = ''; if (is_array($idLists['tt_address'] ?? false)) { - $out .= $this->getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address'); + $rows = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists['tt_address'], 'tt_address'); + $out .= $this->getRecordList($rows, 'tt_address'); } if (is_array($idLists['fe_users'] ?? false)) { - $out .= $this->getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users'); + $rows = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists['fe_users'], 'fe_users'); + $out .= $this->getRecordList($rows, 'fe_users'); } if (is_array($idLists['PLAINLIST'] ?? false)) { $out .= $this->getRecordList($idLists['PLAINLIST'], 'default'); } if (is_array($idLists[$this->userTable] ?? false)) { - $out .= $this->getRecordList(DirectMailUtility::fetchRecordsListValues($idLists[$this->userTable], $this->userTable), $this->userTable); + $rows = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists[$this->userTable], $this->userTable); + $out .= $this->getRecordList($rows, $this->userTable); } return $out; @@ -1366,12 +1370,12 @@ protected function sendTestMailToTable(array $idLists, $table, Dmailer $htmlmail $sentFlag = 0; if (is_array($idLists[$table])) { if ($table != 'PLAINLIST') { - $recs = DirectMailUtility::fetchRecordsListValues($idLists[$table], $table, '*'); + $rows = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists[$table], $table, '*'); } else { - $recs = $idLists['PLAINLIST']; + $rows = $idLists['PLAINLIST']; } - foreach ($recs as $rec) { + foreach ($rows as $rec) { $recipRow = $htmlmail->convertFields($rec); $recipRow['sys_dmail_categories_list'] = $htmlmail->getListOfRecipentCategories($table, $recipRow['uid']); $kc = substr($table, 0, 1); From 36179b201078b49948f1fcd57dfbe91217a01ddd Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Wed, 24 Aug 2022 20:36:42 +0200 Subject: [PATCH 297/342] use function from temp repository --- Classes/Module/StatisticsController.php | 97 ++++++++++++++++--------- 1 file changed, 61 insertions(+), 36 deletions(-) diff --git a/Classes/Module/StatisticsController.php b/Classes/Module/StatisticsController.php index cdf3d8c09..7f4dee2b2 100644 --- a/Classes/Module/StatisticsController.php +++ b/Classes/Module/StatisticsController.php @@ -7,6 +7,7 @@ use DirectMailTeam\DirectMail\Repository\SysDmailRepository; use DirectMailTeam\DirectMail\Repository\SysDmailMaillogRepository; use DirectMailTeam\DirectMail\Repository\FeUsersRepository; +use DirectMailTeam\DirectMail\Repository\TempRepository; use DirectMailTeam\DirectMail\Repository\TtAddressRepository; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; @@ -849,10 +850,12 @@ protected function stats($row) if ($this->returnList) { if (count($idLists['tt_address'])) { - $output .= '

' . $this->getLanguageService()->getLL('stats_emails') . '

' . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address', $this->id, 1, $this->sys_dmail_uid); + $tempRows = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists['tt_address'], 'tt_address'); + $output .= '

' . $this->getLanguageService()->getLL('stats_emails') . '

' . DirectMailUtility::getRecordList($tempRows, 'tt_address', $this->id, 1, $this->sys_dmail_uid); } if (count($idLists['fe_users'])) { - $output .= '

' . $this->getLanguageService()->getLL('stats_website_users') . '

' . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users', $this->id, 1, $this->sys_dmail_uid); + $tempRows = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists['fe_users'], 'fe_users'); + $output .= '

' . $this->getLanguageService()->getLL('stats_website_users') . '

' . DirectMailUtility::getRecordList($tempRows, 'fe_users', $this->id, 1, $this->sys_dmail_uid); } if (count($idLists['PLAINLIST'])) { $output .= '

' . $this->getLanguageService()->getLL('stats_plainlist') . '

'; @@ -862,11 +865,13 @@ protected function stats($row) if ($this->returnDisable) { if (count($idLists['tt_address'])) { - $c = $this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address'); + $tempRows = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists['tt_address'], 'tt_address'); + $c = $this->disableRecipients($tempRows, 'tt_address'); $output .= '
' . $c . ' ' . $this->getLanguageService()->getLL('stats_emails_disabled'); } if (count($idLists['fe_users'])) { - $c = $this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users'); + $tempRows = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists['fe_users'], 'fe_users'); + $c = $this->disableRecipients($tempRows, 'fe_users'); $output .= '
' . $c . ' ' . $this->getLanguageService()->getLL('stats_website_users_disabled'); } } @@ -874,13 +879,13 @@ protected function stats($row) if ($this->returnCSV) { $emails = []; if (count($idLists['tt_address'])) { - $arr = DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'); + $arr = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists['tt_address'], 'tt_address'); foreach ($arr as $v) { $emails[] = $v['email']; } } if (count($idLists['fe_users'])) { - $arr=DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'); + $arr = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists['fe_users'], 'fe_users'); foreach ($arr as $v) { $emails[] = $v['email']; } @@ -901,10 +906,12 @@ protected function stats($row) if ($this->unknownList) { if (count($idLists['tt_address'])) { - $output .= '
' . $this->getLanguageService()->getLL('stats_emails') . '
' . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address', $this->id, 1, $this->sys_dmail_uid); + $tempRows = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists['tt_address'], 'tt_address'); + $output .= '
' . $this->getLanguageService()->getLL('stats_emails') . '
' . DirectMailUtility::getRecordList($tempRows, 'tt_address', $this->id, 1, $this->sys_dmail_uid); } if (count($idLists['fe_users'])) { - $output .= '
' . $this->getLanguageService()->getLL('stats_website_users') . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users', $this->id, 1, $this->sys_dmail_uid); + $tempRows = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists['fe_users'], 'fe_users'); + $output .= '
' . $this->getLanguageService()->getLL('stats_website_users') . DirectMailUtility::getRecordList($tempRows, 'fe_users', $this->id, 1, $this->sys_dmail_uid); } if (count($idLists['PLAINLIST'])) { $output .= '
' . $this->getLanguageService()->getLL('stats_plainlist'); @@ -914,11 +921,13 @@ protected function stats($row) if ($this->unknownDisable) { if (count($idLists['tt_address'])) { - $c = $this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address'); + $tempRows = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists['tt_address'], 'tt_address'); + $c = $this->disableRecipients($tempRows, 'tt_address'); $output .= '
' . $c . ' ' . $this->getLanguageService()->getLL('stats_emails_disabled'); } if (count($idLists['fe_users'])) { - $c = $this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users'); + $tempRows = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists['tt_address'], 'tt_address'); + $c = $this->disableRecipients($tempRows, 'fe_users'); $output .= '
' . $c . ' ' . $this->getLanguageService()->getLL('stats_website_users_disabled'); } } @@ -926,13 +935,13 @@ protected function stats($row) if ($this->unknownCSV) { $emails = []; if (count($idLists['tt_address'])) { - $arr = DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'); + $arr = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists['tt_address'], 'tt_address'); foreach ($arr as $v) { $emails[] = $v['email']; } } if (count($idLists['fe_users'])) { - $arr = DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'); + $arr = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists['fe_users'], 'fe_users'); foreach ($arr as $v) { $emails[] = $v['email']; } @@ -953,10 +962,12 @@ protected function stats($row) if ($this->fullList) { if (count($idLists['tt_address'])) { - $output .= '
' . $this->getLanguageService()->getLL('stats_emails') . '
' . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address', $this->id, 1, $this->sys_dmail_uid); + $tempRows = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists['tt_address'], 'tt_address'); + $output .= '
' . $this->getLanguageService()->getLL('stats_emails') . '
' . DirectMailUtility::getRecordList($tempRows, 'tt_address', $this->id, 1, $this->sys_dmail_uid); } if (count($idLists['fe_users'])) { - $output .= '
' . $this->getLanguageService()->getLL('stats_website_users') . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users', $this->id, 1, $this->sys_dmail_uid); + $tempRows = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists['fe_users'], 'fe_users'); + $output .= '
' . $this->getLanguageService()->getLL('stats_website_users') . DirectMailUtility::getRecordList($tempRows, 'fe_users', $this->id, 1, $this->sys_dmail_uid); } if (count($idLists['PLAINLIST'])) { $output .= '
' . $this->getLanguageService()->getLL('stats_plainlist'); @@ -966,11 +977,13 @@ protected function stats($row) if ($this->fullDisable) { if (count($idLists['tt_address'])) { - $c = $this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address'); + $tempRows = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists['tt_address'], 'tt_address'); + $c = $this->disableRecipients($tempRows, 'tt_address'); $output .= '
' . $c . ' ' . $this->getLanguageService()->getLL('stats_emails_disabled'); } if (count($idLists['fe_users'])) { - $c = $this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users'); + $tempRows = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists['fe_users'], 'fe_users'); + $c = $this->disableRecipients($tempRows, 'fe_users'); $output .= '
' . $c . ' ' . $this->getLanguageService()->getLL('stats_website_users_disabled'); } } @@ -978,13 +991,13 @@ protected function stats($row) if ($this->fullCSV) { $emails = []; if (count($idLists['tt_address'])) { - $arr = DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'); + $arr = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists['tt_address'], 'tt_address'); foreach ($arr as $v) { $emails[] = $v['email']; } } if (count($idLists['fe_users'])) { - $arr = DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'); + $arr = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists['fe_users'], 'fe_users'); foreach ($arr as $v) { $emails[] = $v['email']; } @@ -1005,10 +1018,12 @@ protected function stats($row) if ($this->badHostList) { if (count($idLists['tt_address'])) { - $output .= '
' . $this->getLanguageService()->getLL('stats_emails') . '
' . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address', $this->id, 1, $this->sys_dmail_uid); + $tempRows = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists['tt_address'], 'tt_address'); + $output .= '
' . $this->getLanguageService()->getLL('stats_emails') . '
' . DirectMailUtility::getRecordList($tempRows, 'tt_address', $this->id, 1, $this->sys_dmail_uid); } if (count($idLists['fe_users'])) { - $output .= '
' . $this->getLanguageService()->getLL('stats_website_users') . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users', $this->id, 1, $this->sys_dmail_uid); + $tempRows = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists['fe_users'], 'fe_users'); + $output .= '
' . $this->getLanguageService()->getLL('stats_website_users') . DirectMailUtility::getRecordList($tempRows, 'fe_users', $this->id, 1, $this->sys_dmail_uid); } if (count($idLists['PLAINLIST'])) { $output .= '
' . $this->getLanguageService()->getLL('stats_plainlist'); @@ -1018,11 +1033,13 @@ protected function stats($row) if ($this->badHostDisable) { if (count($idLists['tt_address'])) { - $c = $this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address'); + $tempRows = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists['tt_address'], 'tt_address'); + $c = $this->disableRecipients($tempRows, 'tt_address'); $output .= '
' . $c . ' ' . $this->getLanguageService()->getLL('stats_emails_disabled'); } if (count($idLists['fe_users'])) { - $c = $this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users'); + $tempRows = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists['fe_users'], 'fe_users'); + $c = $this->disableRecipients($tempRows, 'fe_users'); $output .= '
' . $c . ' ' . $this->getLanguageService()->getLL('stats_website_users_disabled'); } } @@ -1030,14 +1047,14 @@ protected function stats($row) if ($this->badHostCSV) { $emails = []; if (count($idLists['tt_address'])) { - $arr = DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'); + $arr = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists['tt_address'], 'tt_address'); foreach ($arr as $v) { $emails[] = $v['email']; } } if (count($idLists['fe_users'])) { - $arr = DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'); + $arr = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists['fe_users'], 'fe_users'); foreach ($arr as $v) { $emails[] = $v['email']; } @@ -1060,10 +1077,12 @@ protected function stats($row) if ($this->badHeaderList) { if (count($idLists['tt_address'])) { - $output .= '
' . $this->getLanguageService()->getLL('stats_emails') . '
' . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address', $this->id, 1, $this->sys_dmail_uid); + $tempRows = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists['tt_address'], 'tt_address'); + $output .= '
' . $this->getLanguageService()->getLL('stats_emails') . '
' . DirectMailUtility::getRecordList($tempRows, 'tt_address', $this->id, 1, $this->sys_dmail_uid); } if (count($idLists['fe_users'])) { - $output .= '
' . $this->getLanguageService()->getLL('stats_website_users') . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users', $this->id, 1, $this->sys_dmail_uid); + $tempRows = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists['fe_users'], 'fe_users'); + $output .= '
' . $this->getLanguageService()->getLL('stats_website_users') . DirectMailUtility::getRecordList($tempRows, 'fe_users', $this->id, 1, $this->sys_dmail_uid); } if (count($idLists['PLAINLIST'])) { $output .= '
' . $this->getLanguageService()->getLL('stats_plainlist'); @@ -1073,11 +1092,13 @@ protected function stats($row) if ($this->badHeaderDisable) { if (count($idLists['tt_address'])) { - $c = $this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address'); + $tempRows = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists['tt_address'], 'tt_address'); + $c = $this->disableRecipients($tempRows, 'tt_address'); $output .= '
' . $c . ' ' . $this->getLanguageService()->getLL('stats_emails_disabled'); } if (count($idLists['fe_users'])) { - $c = $this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users'); + $tempRows = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists['fe_users'], 'fe_users'); + $c = $this->disableRecipients($tempRows, 'fe_users'); $output .= '
' . $c . ' ' . $this->getLanguageService()->getLL('stats_website_users_disabled'); } } @@ -1085,13 +1106,13 @@ protected function stats($row) if ($this->badHeaderCSV) { $emails = []; if (count($idLists['tt_address'])) { - $arr = DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'); + $arr = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists['tt_address'], 'tt_address'); foreach ($arr as $v) { $emails[] = $v['email']; } } if (count($idLists['fe_users'])) { - $arr = DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'); + $arr = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists['fe_users'], 'fe_users'); foreach ($arr as $v) { $emails[] = $v['email']; } @@ -1113,10 +1134,12 @@ protected function stats($row) if ($this->reasonUnknownList) { if (count($idLists['tt_address'])) { - $output .= '
' . $this->getLanguageService()->getLL('stats_emails') . '
' . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address', $this->id, 1, $this->sys_dmail_uid); + $tempRows = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists['tt_address'], 'tt_address'); + $output .= '
' . $this->getLanguageService()->getLL('stats_emails') . '
' . DirectMailUtility::getRecordList($tempRows, 'tt_address', $this->id, 1, $this->sys_dmail_uid); } if (count($idLists['fe_users'])) { - $output .= '
' . $this->getLanguageService()->getLL('stats_website_users') . DirectMailUtility::getRecordList(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users', $this->id, 1, $this->sys_dmail_uid); + $tempRows = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists['fe_users'], 'fe_users'); + $output .= '
' . $this->getLanguageService()->getLL('stats_website_users') . DirectMailUtility::getRecordList($tempRows, 'fe_users', $this->id, 1, $this->sys_dmail_uid); } if (count($idLists['PLAINLIST'])) { $output .= '
' . $this->getLanguageService()->getLL('stats_plainlist'); @@ -1126,11 +1149,13 @@ protected function stats($row) if ($this->reasonUnknownDisable) { if (count($idLists['tt_address'])) { - $c = $this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'), 'tt_address'); + $tempRows = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists['tt_address'], 'tt_address'); + $c = $this->disableRecipients($tempRows, 'tt_address'); $output .= '
' . $c . ' ' . $this->getLanguageService()->getLL('stats_emails_disabled'); } if (count($idLists['fe_users'])) { - $c = $this->disableRecipients(DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'), 'fe_users'); + $tempRows = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists['fe_users'], 'fe_users'); + $c = $this->disableRecipients($tempRows, 'fe_users'); $output .= '
' . $c . ' ' . $this->getLanguageService()->getLL('stats_website_users_disabled'); } } @@ -1138,13 +1163,13 @@ protected function stats($row) if ($this->reasonUnknownCSV) { $emails = []; if (count($idLists['tt_address'])) { - $arr = DirectMailUtility::fetchRecordsListValues($idLists['tt_address'], 'tt_address'); + $arr = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists['tt_address'], 'tt_address'); foreach ($arr as $v) { $emails[] = $v['email']; } } if (count($idLists['fe_users'])) { - $arr = DirectMailUtility::fetchRecordsListValues($idLists['fe_users'], 'fe_users'); + $arr = GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists['fe_users'], 'fe_users'); foreach ($arr as $v) { $emails[] = $v['email']; } From f946f8ccc18aeacc0038193d8bb2cdd7cff22570 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Wed, 24 Aug 2022 20:38:25 +0200 Subject: [PATCH 298/342] remove old function 'fetchRecordsListValues' --- Classes/DirectMailUtility.php | 52 ----------------------------------- 1 file changed, 52 deletions(-) diff --git a/Classes/DirectMailUtility.php b/Classes/DirectMailUtility.php index fbce830b7..04cf9dc6d 100644 --- a/Classes/DirectMailUtility.php +++ b/Classes/DirectMailUtility.php @@ -54,58 +54,6 @@ */ class DirectMailUtility { - - /** - * Get recipient DB record given on the ID - * - * @param array $listArr List of recipient IDs - * @param string $table Table name - * @param string $fields Field to be selected - * - * @return array recipients' data - */ - public static function fetchRecordsListValues(array $listArr, $table, $fields = 'uid,name,email') - { - $outListArr = []; - if (is_array($listArr) && count($listArr)) { - $idlist = implode(',', $listArr); - - $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table); - $queryBuilder - ->getRestrictions() - ->removeAll() - ->add(GeneralUtility::makeInstance(DeletedRestriction::class)); - - $fieldArray = GeneralUtility::trimExplode(',', $fields); - - // handle selecting multiple fields - foreach ($fieldArray as $i => $field) { - if ($i) { - $queryBuilder->addSelect($field); - } else { - $queryBuilder->select($field); - } - } - - $res = $queryBuilder->from($table) - ->where( - $queryBuilder->expr()->in( - 'uid', - $queryBuilder->createNamedParameter( - GeneralUtility::intExplode(',', $idlist), - Connection::PARAM_INT_ARRAY - ) - ) - ) - ->execute(); - - while ($row = $res->fetch()) { - $outListArr[$row['uid']] = $row; - } - } - return $outListArr; - } - /** * Get the ID of page in a tree * From 95050405df965fb2f9c292203a1c4bf2a3da216c Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Wed, 24 Aug 2022 20:52:41 +0200 Subject: [PATCH 299/342] move function 'getIdList' to temp repository --- Classes/DirectMailUtility.php | 20 ++- Classes/Module/RecipientListController.php | 9 +- Classes/Repository/TempRepository.php | 145 +++++++++++++++++++++ 3 files changed, 159 insertions(+), 15 deletions(-) diff --git a/Classes/DirectMailUtility.php b/Classes/DirectMailUtility.php index 04cf9dc6d..0d5b6afdb 100644 --- a/Classes/DirectMailUtility.php +++ b/Classes/DirectMailUtility.php @@ -120,17 +120,12 @@ public static function getIdList($table, $pidList, $groupUid, $cat) { $addWhere = ''; - if ($table == 'fe_groups') { - $switchTable = 'fe_users'; - } else { - $switchTable = $table; - } + $switchTable = $table == 'fe_groups' ? 'fe_users' : $table; $pidArray = GeneralUtility::intExplode(',', $pidList); /** @var \TYPO3\CMS\Core\Database\Connection $connection */ - $connection = GeneralUtility::makeInstance(ConnectionPool::class) - ->getConnectionForTable($table); + $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($table); $queryBuilder = $connection->createQueryBuilder(); if ($switchTable == 'fe_users') { @@ -169,7 +164,8 @@ public static function getIdList($table, $pidList, $groupUid, $cat) ->orderBy($switchTable . '.uid') ->addOrderBy($switchTable . '.email') ->execute(); - } else { + } + else { $res = $queryBuilder ->selectLiteral('DISTINCT ' . $switchTable . '.uid', $switchTable . '.email') ->from($switchTable) @@ -185,7 +181,8 @@ public static function getIdList($table, $pidList, $groupUid, $cat) ->addOrderBy($switchTable . '.email') ->execute(); } - } else { + } + else { if ($table == 'fe_groups') { $res = $queryBuilder ->selectLiteral('DISTINCT ' . $switchTable . '.uid', $switchTable . '.email') @@ -214,7 +211,8 @@ public static function getIdList($table, $pidList, $groupUid, $cat) ->orderBy($switchTable . '.uid') ->addOrderBy($switchTable . '.email') ->execute(); - } else { + } + else { $res = $queryBuilder ->selectLiteral('DISTINCT ' . $switchTable . '.uid', $switchTable . '.email') ->from('sys_dmail_group', 'sys_dmail_group') @@ -243,7 +241,7 @@ public static function getIdList($table, $pidList, $groupUid, $cat) } } $outArr = []; - while (($row = $res->fetch())) { + while ($row = $res->fetch()) { $outArr[] = $row['uid']; } return $outArr; diff --git a/Classes/Module/RecipientListController.php b/Classes/Module/RecipientListController.php index 1536b8c14..478d27801 100644 --- a/Classes/Module/RecipientListController.php +++ b/Classes/Module/RecipientListController.php @@ -267,22 +267,23 @@ protected function cmd_compileMailGroup(int $groupUid) $whichTables = intval($mailGroup['whichtables']); // tt_address if ($whichTables&1) { - $idLists['tt_address'] = DirectMailUtility::getIdList('tt_address', $pidList, $groupUid, $mailGroup['select_categories']); + $idLists['tt_address'] = GeneralUtility::makeInstance(TempRepository::class)->getIdList('tt_address', $pidList, $groupUid, $mailGroup['select_categories']); } // fe_users if ($whichTables&2) { - $idLists['fe_users'] = DirectMailUtility::getIdList('fe_users', $pidList, $groupUid, $mailGroup['select_categories']); + $idLists['fe_users'] = GeneralUtility::makeInstance(TempRepository::class)->getIdList('fe_users', $pidList, $groupUid, $mailGroup['select_categories']); } // user table if ($this->userTable && ($whichTables&4)) { - $idLists[$this->userTable] = DirectMailUtility::getIdList($this->userTable, $pidList, $groupUid, $mailGroup['select_categories']); + $idLists[$this->userTable] = GeneralUtility::makeInstance(TempRepository::class)->getIdList($this->userTable, $pidList, $groupUid, $mailGroup['select_categories']); } // fe_groups if ($whichTables&8) { if (!is_array($idLists['fe_users'])) { $idLists['fe_users'] = []; } - $idLists['fe_users'] = array_unique(array_merge($idLists['fe_users'], DirectMailUtility::getIdList('fe_groups', $pidList, $groupUid, $mailGroup['select_categories']))); + $idLists['fe_users'] = GeneralUtility::makeInstance(TempRepository::class)->getIdList('fe_groups', $pidList, $groupUid, $mailGroup['select_categories']); + $idLists['fe_users'] = array_unique(array_merge($idLists['fe_users'], $idLists['fe_users'])); } } break; diff --git a/Classes/Repository/TempRepository.php b/Classes/Repository/TempRepository.php index ca33be98d..a657934e6 100644 --- a/Classes/Repository/TempRepository.php +++ b/Classes/Repository/TempRepository.php @@ -61,4 +61,149 @@ public static function fetchRecordsListValues(array $listArr, $table, $fields = } return $outListArr; } + + /** + * Return all uid's from $table where the $pid is in $pidList. + * If $cat is 0 or empty, then all entries (with pid $pid) is returned else only + * entires which are subscribing to the categories of the group with uid $group_uid is returned. + * The relation between the recipients in $table and sys_dmail_categories is a true MM relation + * (Must be correctly defined in TCA). + * + * @param string $table The table to select from + * @param string $pidList The pidList + * @param int $groupUid The groupUid. + * @param int $cat The number of relations from sys_dmail_group to sysmail_categories + * + * @return array The resulting array of uid's + */ + public static function getIdList($table, $pidList, $groupUid, $cat) + { + $addWhere = ''; + + $switchTable = $table == 'fe_groups' ? 'fe_users' : $table; + + $pidArray = GeneralUtility::intExplode(',', $pidList); + + /** @var \TYPO3\CMS\Core\Database\Connection $connection */ + $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($table); + $queryBuilder = $connection->createQueryBuilder(); + + if ($switchTable == 'fe_users') { + //$addWhere = ' AND fe_users.module_sys_dmail_newsletter = 1'; + $addWhere = $queryBuilder->expr()->eq( + 'fe_users.module_sys_dmail_newsletter', + 1 + ); + } + + // fe user group uid should be in list of fe users list of user groups + // $field = $switchTable.'.usergroup'; + // $command = $table.'.uid'; + // This approach, using standard SQL, does not work, + // even when fe_users.usergroup is defined as varchar(255) instead of tinyblob + // $usergroupInList = ' AND ('.$field.' LIKE \'%,\'||'.$command.'||\',%\' OR '.$field.' LIKE '.$command.'||\',%\' OR '.$field.' LIKE \'%,\'||'.$command.' OR '.$field.'='.$command.')'; + // The following will work but INSTR and CONCAT are available only in mySQL + + $mmTable = $GLOBALS['TCA'][$switchTable]['columns']['module_sys_dmail_category']['config']['MM']; + $cat = intval($cat); + if ($cat < 1) { + if ($table == 'fe_groups') { + $res = $queryBuilder + ->selectLiteral('DISTINCT ' . $switchTable . '.uid', $switchTable . '.email') + ->from($switchTable, $switchTable) + ->from($table, $table) + ->andWhere( + $queryBuilder->expr()->andX() + ->add($queryBuilder->expr()->in('fe_groups.pid', $queryBuilder->createNamedParameter($pidArray, Connection::PARAM_INT_ARRAY))) + ->add('INSTR( CONCAT(\',\',fe_users.usergroup,\',\'),CONCAT(\',\',fe_groups.uid ,\',\') )') + ->add( + $queryBuilder->expr()->neq($switchTable . '.email', $queryBuilder->createNamedParameter('')) + ) + ->add($addWhere) + ) + ->orderBy($switchTable . '.uid') + ->addOrderBy($switchTable . '.email') + ->execute(); + } + else { + $res = $queryBuilder + ->selectLiteral('DISTINCT ' . $switchTable . '.uid', $switchTable . '.email') + ->from($switchTable) + ->andWhere( + $queryBuilder->expr()->andX() + ->add($queryBuilder->expr()->in($switchTable . '.pid', $queryBuilder->createNamedParameter($pidArray, Connection::PARAM_INT_ARRAY))) + ->add( + $queryBuilder->expr()->neq($switchTable . '.email', $queryBuilder->createNamedParameter('')) + ) + ->add($addWhere) + ) + ->orderBy($switchTable . '.uid') + ->addOrderBy($switchTable . '.email') + ->execute(); + } + } + else { + if ($table == 'fe_groups') { + $res = $queryBuilder + ->selectLiteral('DISTINCT ' . $switchTable . '.uid', $switchTable . '.email') + ->from('sys_dmail_group', 'sys_dmail_group') + ->from('sys_dmail_group_category_mm', 'g_mm') + ->from('fe_groups', 'fe_groups') + ->from($mmTable, 'mm_1') + ->leftJoin( + 'mm_1', + $switchTable, + $switchTable, + $queryBuilder->expr()->eq($switchTable .'.uid', $queryBuilder->quoteIdentifier('mm_1.uid_local')) + ) + ->andWhere( + $queryBuilder->expr()->andX() + ->add($queryBuilder->expr()->in('fe_groups.pid', $queryBuilder->createNamedParameter($pidArray, Connection::PARAM_INT_ARRAY))) + ->add('INSTR( CONCAT(\',\',fe_users.usergroup,\',\'),CONCAT(\',\',fe_groups.uid ,\',\') )') + ->add($queryBuilder->expr()->eq('mm_1.uid_foreign', $queryBuilder->quoteIdentifier('g_mm.uid_foreign'))) + ->add($queryBuilder->expr()->eq('sys_dmail_group.uid', $queryBuilder->quoteIdentifier('g_mm.uid_local'))) + ->add($queryBuilder->expr()->eq('sys_dmail_group.uid', $queryBuilder->createNamedParameter($groupUid, \PDO::PARAM_INT))) + ->add( + $queryBuilder->expr()->neq($switchTable . '.email', $queryBuilder->createNamedParameter('')) + ) + ->add($addWhere) + ) + ->orderBy($switchTable . '.uid') + ->addOrderBy($switchTable . '.email') + ->execute(); + } + else { + $res = $queryBuilder + ->selectLiteral('DISTINCT ' . $switchTable . '.uid', $switchTable . '.email') + ->from('sys_dmail_group', 'sys_dmail_group') + ->from('sys_dmail_group_category_mm', 'g_mm') + ->from($mmTable, 'mm_1') + ->leftJoin( + 'mm_1', + $table, + $table, + $queryBuilder->expr()->eq($table .'.uid', $queryBuilder->quoteIdentifier('mm_1.uid_local')) + ) + ->andWhere( + $queryBuilder->expr()->andX() + ->add($queryBuilder->expr()->in($switchTable . '.pid', $queryBuilder->createNamedParameter($pidArray, Connection::PARAM_INT_ARRAY))) + ->add($queryBuilder->expr()->eq('mm_1.uid_foreign', $queryBuilder->quoteIdentifier('g_mm.uid_foreign'))) + ->add($queryBuilder->expr()->eq('sys_dmail_group.uid', $queryBuilder->quoteIdentifier('g_mm.uid_local'))) + ->add($queryBuilder->expr()->eq('sys_dmail_group.uid', $queryBuilder->createNamedParameter($groupUid, \PDO::PARAM_INT))) + ->add( + $queryBuilder->expr()->neq($switchTable . '.email', $queryBuilder->createNamedParameter('')) + ) + ->add($addWhere) + ) + ->orderBy($switchTable . '.uid') + ->addOrderBy($switchTable . '.email') + ->execute(); + } + } + $outArr = []; + while ($row = $res->fetch()) { + $outArr[] = $row['uid']; + } + return $outArr; + } } \ No newline at end of file From a2d3b368d6df9c935efc11eb767ab9370f5b0431 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Wed, 24 Aug 2022 21:12:21 +0200 Subject: [PATCH 300/342] use function from temp repository --- Classes/Module/DmailController.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Classes/Module/DmailController.php b/Classes/Module/DmailController.php index efa17675c..183f45424 100644 --- a/Classes/Module/DmailController.php +++ b/Classes/Module/DmailController.php @@ -1678,22 +1678,23 @@ protected function getSingleMailGroup($groupUid) $whichTables = intval($mailGroup['whichtables']); if ($whichTables&1) { // tt_address - $idLists['tt_address'] = DirectMailUtility::getIdList('tt_address', $pidList, $groupUid, $mailGroup['select_categories']); + $idLists['tt_address'] = GeneralUtility::makeInstance(TempRepository::class)->getIdList('tt_address', $pidList, $groupUid, $mailGroup['select_categories']); } if ($whichTables&2) { // fe_users - $idLists['fe_users'] = DirectMailUtility::getIdList('fe_users', $pidList, $groupUid, $mailGroup['select_categories']); + $idLists['fe_users'] = GeneralUtility::makeInstance(TempRepository::class)->getIdList('fe_users', $pidList, $groupUid, $mailGroup['select_categories']); } if ($this->userTable && ($whichTables&4)) { // user table - $idLists[$this->userTable] = DirectMailUtility::getIdList($this->userTable, $pidList, $groupUid, $mailGroup['select_categories']); + $idLists[$this->userTable] = GeneralUtility::makeInstance(TempRepository::class)->getIdList($this->userTable, $pidList, $groupUid, $mailGroup['select_categories']); } if ($whichTables&8) { // fe_groups if (!is_array($idLists['fe_users'])) { $idLists['fe_users'] = []; } - $idLists['fe_users'] = array_unique(array_merge($idLists['fe_users'], DirectMailUtility::getIdList('fe_groups', $pidList, $groupUid, $mailGroup['select_categories']))); + $idLists['fe_users'] = GeneralUtility::makeInstance(TempRepository::class)->getIdList('fe_groups', $pidList, $groupUid, $mailGroup['select_categories']); + $idLists['fe_users'] = array_unique(array_merge($idLists['fe_users'])); } } break; From 290b7be271613c7caea1204c4fe329f4c67aaa6e Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Wed, 24 Aug 2022 21:15:10 +0200 Subject: [PATCH 301/342] remove old function 'getIdList' --- Classes/DirectMailUtility.php | 145 ---------------------------------- 1 file changed, 145 deletions(-) diff --git a/Classes/DirectMailUtility.php b/Classes/DirectMailUtility.php index 0d5b6afdb..40a56a5b9 100644 --- a/Classes/DirectMailUtility.php +++ b/Classes/DirectMailUtility.php @@ -102,151 +102,6 @@ public static function cleanPlainList(array $plainlist) return $plainlist; } - /** - * Return all uid's from $table where the $pid is in $pidList. - * If $cat is 0 or empty, then all entries (with pid $pid) is returned else only - * entires which are subscribing to the categories of the group with uid $group_uid is returned. - * The relation between the recipients in $table and sys_dmail_categories is a true MM relation - * (Must be correctly defined in TCA). - * - * @param string $table The table to select from - * @param string $pidList The pidList - * @param int $groupUid The groupUid. - * @param int $cat The number of relations from sys_dmail_group to sysmail_categories - * - * @return array The resulting array of uid's - */ - public static function getIdList($table, $pidList, $groupUid, $cat) - { - $addWhere = ''; - - $switchTable = $table == 'fe_groups' ? 'fe_users' : $table; - - $pidArray = GeneralUtility::intExplode(',', $pidList); - - /** @var \TYPO3\CMS\Core\Database\Connection $connection */ - $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($table); - $queryBuilder = $connection->createQueryBuilder(); - - if ($switchTable == 'fe_users') { - //$addWhere = ' AND fe_users.module_sys_dmail_newsletter = 1'; - $addWhere = $queryBuilder->expr()->eq( - 'fe_users.module_sys_dmail_newsletter', - 1 - ); - } - - // fe user group uid should be in list of fe users list of user groups - // $field = $switchTable.'.usergroup'; - // $command = $table.'.uid'; - // This approach, using standard SQL, does not work, - // even when fe_users.usergroup is defined as varchar(255) instead of tinyblob - // $usergroupInList = ' AND ('.$field.' LIKE \'%,\'||'.$command.'||\',%\' OR '.$field.' LIKE '.$command.'||\',%\' OR '.$field.' LIKE \'%,\'||'.$command.' OR '.$field.'='.$command.')'; - // The following will work but INSTR and CONCAT are available only in mySQL - - $mmTable = $GLOBALS['TCA'][$switchTable]['columns']['module_sys_dmail_category']['config']['MM']; - $cat = intval($cat); - if ($cat < 1) { - if ($table == 'fe_groups') { - $res = $queryBuilder - ->selectLiteral('DISTINCT ' . $switchTable . '.uid', $switchTable . '.email') - ->from($switchTable, $switchTable) - ->from($table, $table) - ->andWhere( - $queryBuilder->expr()->andX() - ->add($queryBuilder->expr()->in('fe_groups.pid', $queryBuilder->createNamedParameter($pidArray, Connection::PARAM_INT_ARRAY))) - ->add('INSTR( CONCAT(\',\',fe_users.usergroup,\',\'),CONCAT(\',\',fe_groups.uid ,\',\') )') - ->add( - $queryBuilder->expr()->neq($switchTable . '.email', $queryBuilder->createNamedParameter('')) - ) - ->add($addWhere) - ) - ->orderBy($switchTable . '.uid') - ->addOrderBy($switchTable . '.email') - ->execute(); - } - else { - $res = $queryBuilder - ->selectLiteral('DISTINCT ' . $switchTable . '.uid', $switchTable . '.email') - ->from($switchTable) - ->andWhere( - $queryBuilder->expr()->andX() - ->add($queryBuilder->expr()->in($switchTable . '.pid', $queryBuilder->createNamedParameter($pidArray, Connection::PARAM_INT_ARRAY))) - ->add( - $queryBuilder->expr()->neq($switchTable . '.email', $queryBuilder->createNamedParameter('')) - ) - ->add($addWhere) - ) - ->orderBy($switchTable . '.uid') - ->addOrderBy($switchTable . '.email') - ->execute(); - } - } - else { - if ($table == 'fe_groups') { - $res = $queryBuilder - ->selectLiteral('DISTINCT ' . $switchTable . '.uid', $switchTable . '.email') - ->from('sys_dmail_group', 'sys_dmail_group') - ->from('sys_dmail_group_category_mm', 'g_mm') - ->from('fe_groups', 'fe_groups') - ->from($mmTable, 'mm_1') - ->leftJoin( - 'mm_1', - $switchTable, - $switchTable, - $queryBuilder->expr()->eq($switchTable .'.uid', $queryBuilder->quoteIdentifier('mm_1.uid_local')) - ) - ->andWhere( - $queryBuilder->expr()->andX() - ->add($queryBuilder->expr()->in('fe_groups.pid', $queryBuilder->createNamedParameter($pidArray, Connection::PARAM_INT_ARRAY))) - ->add('INSTR( CONCAT(\',\',fe_users.usergroup,\',\'),CONCAT(\',\',fe_groups.uid ,\',\') )') - ->add($queryBuilder->expr()->eq('mm_1.uid_foreign', $queryBuilder->quoteIdentifier('g_mm.uid_foreign'))) - ->add($queryBuilder->expr()->eq('sys_dmail_group.uid', $queryBuilder->quoteIdentifier('g_mm.uid_local'))) - ->add($queryBuilder->expr()->eq('sys_dmail_group.uid', $queryBuilder->createNamedParameter($groupUid, \PDO::PARAM_INT))) - ->add( - $queryBuilder->expr()->neq($switchTable . '.email', $queryBuilder->createNamedParameter('')) - ) - ->add($addWhere) - ) - ->orderBy($switchTable . '.uid') - ->addOrderBy($switchTable . '.email') - ->execute(); - } - else { - $res = $queryBuilder - ->selectLiteral('DISTINCT ' . $switchTable . '.uid', $switchTable . '.email') - ->from('sys_dmail_group', 'sys_dmail_group') - ->from('sys_dmail_group_category_mm', 'g_mm') - ->from($mmTable, 'mm_1') - ->leftJoin( - 'mm_1', - $table, - $table, - $queryBuilder->expr()->eq($table .'.uid', $queryBuilder->quoteIdentifier('mm_1.uid_local')) - ) - ->andWhere( - $queryBuilder->expr()->andX() - ->add($queryBuilder->expr()->in($switchTable . '.pid', $queryBuilder->createNamedParameter($pidArray, Connection::PARAM_INT_ARRAY))) - ->add($queryBuilder->expr()->eq('mm_1.uid_foreign', $queryBuilder->quoteIdentifier('g_mm.uid_foreign'))) - ->add($queryBuilder->expr()->eq('sys_dmail_group.uid', $queryBuilder->quoteIdentifier('g_mm.uid_local'))) - ->add($queryBuilder->expr()->eq('sys_dmail_group.uid', $queryBuilder->createNamedParameter($groupUid, \PDO::PARAM_INT))) - ->add( - $queryBuilder->expr()->neq($switchTable . '.email', $queryBuilder->createNamedParameter('')) - ) - ->add($addWhere) - ) - ->orderBy($switchTable . '.uid') - ->addOrderBy($switchTable . '.email') - ->execute(); - } - } - $outArr = []; - while ($row = $res->fetch()) { - $outArr[] = $row['uid']; - } - return $outArr; - } - /** * Return all uid's from $table for a static direct mail group. * From 13ca69935051c6ea394a3c015d41303b97840eaa Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Wed, 24 Aug 2022 21:37:15 +0200 Subject: [PATCH 302/342] move function 'getStaticIdList' to temp repository --- Classes/DirectMailUtility.php | 178 --------------------- Classes/Module/DmailController.php | 9 +- Classes/Module/RecipientListController.php | 9 +- Classes/Repository/TempRepository.php | 172 ++++++++++++++++++++ 4 files changed, 182 insertions(+), 186 deletions(-) diff --git a/Classes/DirectMailUtility.php b/Classes/DirectMailUtility.php index 40a56a5b9..361c06d73 100644 --- a/Classes/DirectMailUtility.php +++ b/Classes/DirectMailUtility.php @@ -102,184 +102,6 @@ public static function cleanPlainList(array $plainlist) return $plainlist; } - /** - * Return all uid's from $table for a static direct mail group. - * - * @param string $table The table to select from - * @param int $uid The uid of the direct_mail group - * - * @return array The resulting array of uid's - */ - public static function getStaticIdList($table, $uid) - { - if ($table == 'fe_groups') { - $switchTable = 'fe_users'; - } else { - $switchTable = $table; - } - - $connection = GeneralUtility::makeInstance(ConnectionPool::class) - ->getConnectionForTable($table); - $queryBuilder = $connection->createQueryBuilder(); - - // fe user group uid should be in list of fe users list of user groups - // $field = $switchTable.'.usergroup'; - // $command = $table.'.uid'; - - // See comment above - // $usergroupInList = ' AND ('.$field.' LIKE \'%,\'||'.$command.'||\',%\' OR '.$field.' LIKE '.$command.'||\',%\' OR '.$field.' LIKE \'%,\'||'.$command.' OR '.$field.'='.$command.')'; - - // for fe_users and fe_group, only activated modulde_sys_dmail_newsletter - if ($switchTable == 'fe_users') { - $addWhere = $queryBuilder->expr()->eq( - $switchTable . '.module_sys_dmail_newsletter', - 1 - ); - } - - if ($table == 'fe_groups') { - $res = $queryBuilder - ->selectLiteral('DISTINCT ' . $switchTable . '.uid', $switchTable . '.email') - ->from('sys_dmail_group_mm', 'sys_dmail_group_mm') - ->innerJoin( - 'sys_dmail_group_mm', - 'sys_dmail_group', - 'sys_dmail_group', - $queryBuilder->expr()->eq('sys_dmail_group_mm.uid_local', $queryBuilder->quoteIdentifier('sys_dmail_group.uid')) - ) - ->innerJoin( - 'sys_dmail_group_mm', - $table, - $table, - $queryBuilder->expr()->eq('sys_dmail_group_mm.uid_foreign', $queryBuilder->quoteIdentifier($table . '.uid')) - ) - ->innerJoin( - $table, - $switchTable, - $switchTable, - $queryBuilder->expr()->inSet($switchTable.'.usergroup', $queryBuilder->quoteIdentifier($table.'.uid')) - ) - ->andWhere( - $queryBuilder->expr()->andX() - ->add($queryBuilder->expr()->eq('sys_dmail_group_mm.uid_local', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT))) - ->add($queryBuilder->expr()->eq('sys_dmail_group_mm.tablenames', $queryBuilder->createNamedParameter($table))) - ->add($queryBuilder->expr()->neq($switchTable . '.email', $queryBuilder->createNamedParameter(''))) - ->add($queryBuilder->expr()->eq('sys_dmail_group.deleted', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT))) - ->add($addWhere) - ) - ->orderBy($switchTable . '.uid') - ->addOrderBy($switchTable . '.email') - ->execute(); - } else { - $res = $queryBuilder - ->selectLiteral('DISTINCT ' . $switchTable . '.uid', $switchTable . '.email') - ->from('sys_dmail_group_mm', 'sys_dmail_group_mm') - ->innerJoin( - 'sys_dmail_group_mm', - 'sys_dmail_group', - 'sys_dmail_group', - $queryBuilder->expr()->eq('sys_dmail_group_mm.uid_local', $queryBuilder->quoteIdentifier('sys_dmail_group.uid')) - ) - ->innerJoin( - 'sys_dmail_group_mm', - $switchTable, - $switchTable, - $queryBuilder->expr()->eq('sys_dmail_group_mm.uid_foreign', $queryBuilder->quoteIdentifier($switchTable . '.uid')) - ) - ->andWhere( - $queryBuilder->expr()->andX() - ->add($queryBuilder->expr()->eq('sys_dmail_group_mm.uid_local', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT))) - ->add($queryBuilder->expr()->eq('sys_dmail_group_mm.tablenames', $queryBuilder->createNamedParameter($switchTable))) - ->add($queryBuilder->expr()->neq($switchTable . '.email', $queryBuilder->createNamedParameter(''))) - ->add($queryBuilder->expr()->eq('sys_dmail_group.deleted', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT))) - ->add($addWhere) - ) - ->orderBy($switchTable . '.uid') - ->addOrderBy($switchTable . '.email') - ->execute(); - } - - $outArr = []; - - while (($row = $res->fetch())) { - $outArr[] = $row['uid']; - } - - if ($table == 'fe_groups') { - // get the uid of the current fe_group - $connection = GeneralUtility::makeInstance(ConnectionPool::class) - ->getConnectionForTable($table); - $queryBuilder = $connection->createQueryBuilder(); - - $res = $queryBuilder - ->selectLiteral('DISTINCT ' . $table . '.uid') - ->from($table, $table) - ->from('sys_dmail_group', 'sys_dmail_group') - ->leftJoin( - 'sys_dmail_group', - 'sys_dmail_group_mm', - 'sys_dmail_group_mm', - $queryBuilder->expr()->eq('sys_dmail_group_mm.uid_local', $queryBuilder->quoteIdentifier('sys_dmail_group.uid')) - ) - ->andWhere( - $queryBuilder->expr()->andX() - ->add($queryBuilder->expr()->eq('sys_dmail_group.uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT))) - ->add($queryBuilder->expr()->eq('fe_groups.uid', $queryBuilder->quoteIdentifier('sys_dmail_group_mm.uid_foreign'))) - ->add($queryBuilder->expr()->eq('sys_dmail_group_mm.tablenames', $queryBuilder->createNamedParameter($table))) - ) - ->execute(); - - list($groupId) = $res->fetchAll(); - - // recursively get all subgroups of this fe_group - $subgroups = self::getFEgroupSubgroups($groupId); - - if (!empty($subgroups)) { - $usergroupInList = null; - foreach ($subgroups as $subgroup) { - $usergroupInList .= (($usergroupInList == null) ? null : ' OR') . ' INSTR( CONCAT(\',\',fe_users.usergroup,\',\'),CONCAT(\',' . intval($subgroup) . ',\') )'; - } - $usergroupInList = '(' . $usergroupInList . ')'; - - // fetch all fe_users from these subgroups - $connection = GeneralUtility::makeInstance(ConnectionPool::class) - ->getConnectionForTable($table); - $queryBuilder = $connection->createQueryBuilder(); - // for fe_users and fe_group, only activated modulde_sys_dmail_newsletter - if ($switchTable == 'fe_users') { - $addWhere = $queryBuilder->expr()->eq( - $switchTable . '.module_sys_dmail_newsletter', - 1 - ); - } - - $res = $queryBuilder - ->selectLiteral('DISTINCT ' . $switchTable . '.uid', $switchTable . '.email') - ->from($table, $table) - ->innerJoin( - $table, - $switchTable, - $switchTable - ) - ->orWhere($usergroupInList) - ->andWhere( - $queryBuilder->expr()->andX() - ->add($queryBuilder->expr()->neq($switchTable . '.email', $queryBuilder->createNamedParameter(''))) - ->add($addWhere) - ) - ->orderBy($switchTable . '.uid') - ->addOrderBy($switchTable . '.email') - ->execute(); - - while ($row = $res->fetch()) { - $outArr[]=$row['uid']; - } - } - } - - return $outArr; - } - /** * Construct the array of uid's from $table selected * by special query of mail group of such type diff --git a/Classes/Module/DmailController.php b/Classes/Module/DmailController.php index 183f45424..b7dc80bb5 100644 --- a/Classes/Module/DmailController.php +++ b/Classes/Module/DmailController.php @@ -1709,11 +1709,12 @@ protected function getSingleMailGroup($groupUid) break; case 2: // Static MM list - $idLists['tt_address'] = DirectMailUtility::getStaticIdList('tt_address', $groupUid); - $idLists['fe_users'] = DirectMailUtility::getStaticIdList('fe_users', $groupUid); - $idLists['fe_users'] = array_unique(array_merge($idLists['fe_users'], DirectMailUtility::getStaticIdList('fe_groups', $groupUid))); + $idLists['tt_address'] = GeneralUtility::makeInstance(TempRepository::class)->getStaticIdList('tt_address', $groupUid); + $idLists['fe_users'] = GeneralUtility::makeInstance(TempRepository::class)->getStaticIdList('fe_users', $groupUid); + $tempGroups = GeneralUtility::makeInstance(TempRepository::class)->getStaticIdList('fe_groups', $groupUid); + $idLists['fe_users'] = array_unique(array_merge($idLists['fe_users'], $tempGroups)); if ($this->userTable) { - $idLists[$this->userTable] = DirectMailUtility::getStaticIdList($this->userTable, $groupUid); + $idLists[$this->userTable] = GeneralUtility::makeInstance(TempRepository::class)->getStaticIdList($this->userTable, $groupUid); } break; case 3: diff --git a/Classes/Module/RecipientListController.php b/Classes/Module/RecipientListController.php index 478d27801..a2f0cf8f7 100644 --- a/Classes/Module/RecipientListController.php +++ b/Classes/Module/RecipientListController.php @@ -298,11 +298,12 @@ protected function cmd_compileMailGroup(int $groupUid) break; case 2: // Static MM list - $idLists['tt_address'] = DirectMailUtility::getStaticIdList('tt_address', $groupUid); - $idLists['fe_users'] = DirectMailUtility::getStaticIdList('fe_users', $groupUid); - $idLists['fe_users'] = array_unique(array_merge($idLists['fe_users'], DirectMailUtility::getStaticIdList('fe_groups', $groupUid))); + $idLists['tt_address'] = GeneralUtility::makeInstance(TempRepository::class)->getStaticIdList('tt_address', $groupUid); + $idLists['fe_users'] = GeneralUtility::makeInstance(TempRepository::class)->getStaticIdList('fe_users', $groupUid); + $tempGroups = GeneralUtility::makeInstance(TempRepository::class)->getStaticIdList('fe_groups', $groupUid); + $idLists['fe_users'] = array_unique(array_merge($idLists['fe_users'], $tempGroups)); if ($this->userTable) { - $idLists[$this->userTable] = DirectMailUtility::getStaticIdList($this->userTable, $groupUid); + $idLists[$this->userTable] = GeneralUtility::makeInstance(TempRepository::class)->getStaticIdList($this->userTable, $groupUid); } break; case 3: diff --git a/Classes/Repository/TempRepository.php b/Classes/Repository/TempRepository.php index a657934e6..f89f5ad4a 100644 --- a/Classes/Repository/TempRepository.php +++ b/Classes/Repository/TempRepository.php @@ -206,4 +206,176 @@ public static function getIdList($table, $pidList, $groupUid, $cat) } return $outArr; } + + /** + * Return all uid's from $table for a static direct mail group. + * + * @param string $table The table to select from + * @param int $uid The uid of the direct_mail group + * + * @return array The resulting array of uid's + */ + public static function getStaticIdList($table, $uid) + { + $switchTable = $table == 'fe_groups' ? 'fe_users' : $table; + + $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($table); + $queryBuilder = $connection->createQueryBuilder(); + + // fe user group uid should be in list of fe users list of user groups + // $field = $switchTable.'.usergroup'; + // $command = $table.'.uid'; + + // See comment above + // $usergroupInList = ' AND ('.$field.' LIKE \'%,\'||'.$command.'||\',%\' OR '.$field.' LIKE '.$command.'||\',%\' OR '.$field.' LIKE \'%,\'||'.$command.' OR '.$field.'='.$command.')'; + + // for fe_users and fe_group, only activated modulde_sys_dmail_newsletter + if ($switchTable == 'fe_users') { + $addWhere = $queryBuilder->expr()->eq( + $switchTable . '.module_sys_dmail_newsletter', + 1 + ); + } + + if ($table == 'fe_groups') { + $res = $queryBuilder + ->selectLiteral('DISTINCT ' . $switchTable . '.uid', $switchTable . '.email') + ->from('sys_dmail_group_mm', 'sys_dmail_group_mm') + ->innerJoin( + 'sys_dmail_group_mm', + 'sys_dmail_group', + 'sys_dmail_group', + $queryBuilder->expr()->eq('sys_dmail_group_mm.uid_local', $queryBuilder->quoteIdentifier('sys_dmail_group.uid')) + ) + ->innerJoin( + 'sys_dmail_group_mm', + $table, + $table, + $queryBuilder->expr()->eq('sys_dmail_group_mm.uid_foreign', $queryBuilder->quoteIdentifier($table . '.uid')) + ) + ->innerJoin( + $table, + $switchTable, + $switchTable, + $queryBuilder->expr()->inSet($switchTable.'.usergroup', $queryBuilder->quoteIdentifier($table.'.uid')) + ) + ->andWhere( + $queryBuilder->expr()->andX() + ->add($queryBuilder->expr()->eq('sys_dmail_group_mm.uid_local', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT))) + ->add($queryBuilder->expr()->eq('sys_dmail_group_mm.tablenames', $queryBuilder->createNamedParameter($table))) + ->add($queryBuilder->expr()->neq($switchTable . '.email', $queryBuilder->createNamedParameter(''))) + ->add($queryBuilder->expr()->eq('sys_dmail_group.deleted', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT))) + ->add($addWhere) + ) + ->orderBy($switchTable . '.uid') + ->addOrderBy($switchTable . '.email') + ->execute(); + } + else { + $res = $queryBuilder + ->selectLiteral('DISTINCT ' . $switchTable . '.uid', $switchTable . '.email') + ->from('sys_dmail_group_mm', 'sys_dmail_group_mm') + ->innerJoin( + 'sys_dmail_group_mm', + 'sys_dmail_group', + 'sys_dmail_group', + $queryBuilder->expr()->eq('sys_dmail_group_mm.uid_local', $queryBuilder->quoteIdentifier('sys_dmail_group.uid')) + ) + ->innerJoin( + 'sys_dmail_group_mm', + $switchTable, + $switchTable, + $queryBuilder->expr()->eq('sys_dmail_group_mm.uid_foreign', $queryBuilder->quoteIdentifier($switchTable . '.uid')) + ) + ->andWhere( + $queryBuilder->expr()->andX() + ->add($queryBuilder->expr()->eq('sys_dmail_group_mm.uid_local', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT))) + ->add($queryBuilder->expr()->eq('sys_dmail_group_mm.tablenames', $queryBuilder->createNamedParameter($switchTable))) + ->add($queryBuilder->expr()->neq($switchTable . '.email', $queryBuilder->createNamedParameter(''))) + ->add($queryBuilder->expr()->eq('sys_dmail_group.deleted', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT))) + ->add($addWhere) + ) + ->orderBy($switchTable . '.uid') + ->addOrderBy($switchTable . '.email') + ->execute(); + } + + $outArr = []; + + while ($row = $res->fetch()) { + $outArr[] = $row['uid']; + } + + if ($table == 'fe_groups') { + // get the uid of the current fe_group + $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($table); + $queryBuilder = $connection->createQueryBuilder(); + + $res = $queryBuilder + ->selectLiteral('DISTINCT ' . $table . '.uid') + ->from($table, $table) + ->from('sys_dmail_group', 'sys_dmail_group') + ->leftJoin( + 'sys_dmail_group', + 'sys_dmail_group_mm', + 'sys_dmail_group_mm', + $queryBuilder->expr()->eq('sys_dmail_group_mm.uid_local', $queryBuilder->quoteIdentifier('sys_dmail_group.uid')) + ) + ->andWhere( + $queryBuilder->expr()->andX() + ->add($queryBuilder->expr()->eq('sys_dmail_group.uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT))) + ->add($queryBuilder->expr()->eq('fe_groups.uid', $queryBuilder->quoteIdentifier('sys_dmail_group_mm.uid_foreign'))) + ->add($queryBuilder->expr()->eq('sys_dmail_group_mm.tablenames', $queryBuilder->createNamedParameter($table))) + ) + ->execute(); + + list($groupId) = $res->fetchAll(); + + // recursively get all subgroups of this fe_group + $subgroups = self::getFEgroupSubgroups($groupId); + + if (!empty($subgroups)) { + $usergroupInList = null; + foreach ($subgroups as $subgroup) { + $usergroupInList .= (($usergroupInList == null) ? null : ' OR') . ' INSTR( CONCAT(\',\',fe_users.usergroup,\',\'),CONCAT(\',' . intval($subgroup) . ',\') )'; + } + $usergroupInList = '(' . $usergroupInList . ')'; + + // fetch all fe_users from these subgroups + $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($table); + $queryBuilder = $connection->createQueryBuilder(); + // for fe_users and fe_group, only activated modulde_sys_dmail_newsletter + if ($switchTable == 'fe_users') { + $addWhere = $queryBuilder->expr()->eq( + $switchTable . '.module_sys_dmail_newsletter', + 1 + ); + } + + $res = $queryBuilder + ->selectLiteral('DISTINCT ' . $switchTable . '.uid', $switchTable . '.email') + ->from($table, $table) + ->innerJoin( + $table, + $switchTable, + $switchTable + ) + ->orWhere($usergroupInList) + ->andWhere( + $queryBuilder->expr()->andX() + ->add($queryBuilder->expr()->neq($switchTable . '.email', $queryBuilder->createNamedParameter(''))) + ->add($addWhere) + ) + ->orderBy($switchTable . '.uid') + ->addOrderBy($switchTable . '.email') + ->execute(); + + while ($row = $res->fetch()) { + $outArr[] = $row['uid']; + } + } + } + + return $outArr; + } } \ No newline at end of file From 764f897c2b313d856c1b0f99d7e5416a6090f9ee Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Thu, 25 Aug 2022 11:40:42 +0200 Subject: [PATCH 303/342] move function 'getSpecialQueryIdList' to temp repository --- Classes/DirectMailUtility.php | 30 --------------------- Classes/Module/DmailController.php | 2 +- Classes/Module/RecipientListController.php | 2 +- Classes/Repository/TempRepository.php | 31 ++++++++++++++++++++++ 4 files changed, 33 insertions(+), 32 deletions(-) diff --git a/Classes/DirectMailUtility.php b/Classes/DirectMailUtility.php index 361c06d73..f54c7f4b8 100644 --- a/Classes/DirectMailUtility.php +++ b/Classes/DirectMailUtility.php @@ -102,36 +102,6 @@ public static function cleanPlainList(array $plainlist) return $plainlist; } - /** - * Construct the array of uid's from $table selected - * by special query of mail group of such type - * - * @param MailSelect $queryGenerator The query generator object - * @param string $table The table to select from - * @param array $group The direct_mail group record - * - * @return array The resulting query. - */ - public static function getSpecialQueryIdList(MailSelect &$queryGenerator, $table, array $group): array - { - $outArr = []; - if ($group['query']) { - $queryGenerator->init('dmail_queryConfig', $table); - $queryGenerator->queryConfig = $queryGenerator->cleanUpQueryConfig(unserialize($group['query'])); - - $queryGenerator->extFieldLists['queryFields'] = 'uid'; - $select = $queryGenerator->getSelectQuery(); - /** @var Connection $connection */ - $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($table); - $recipients = $connection->executeQuery($select)->fetchAll(); - - foreach ($recipients as $recipient) { - $outArr[] = $recipient['uid']; - } - } - return $outArr; - } - /** * Get all group IDs * diff --git a/Classes/Module/DmailController.php b/Classes/Module/DmailController.php index b7dc80bb5..e34c398e3 100644 --- a/Classes/Module/DmailController.php +++ b/Classes/Module/DmailController.php @@ -1732,7 +1732,7 @@ protected function getSingleMailGroup($groupUid) if ($table) { // initialize the query generator $queryGenerator = GeneralUtility::makeInstance(MailSelect::class); - $idLists[$table] = DirectMailUtility::getSpecialQueryIdList($queryGenerator, $table, $mailGroup); + $idLists[$table] = GeneralUtility::makeInstance(TempRepository::class)->getSpecialQueryIdList($queryGenerator, $table, $mailGroup); } break; case 4: diff --git a/Classes/Module/RecipientListController.php b/Classes/Module/RecipientListController.php index a2f0cf8f7..999a50e6f 100644 --- a/Classes/Module/RecipientListController.php +++ b/Classes/Module/RecipientListController.php @@ -319,7 +319,7 @@ protected function cmd_compileMailGroup(int $groupUid) $table = $this->userTable; } if ($table) { - $idLists[$table] = DirectMailUtility::getSpecialQueryIdList($this->queryGenerator, $table, $mailGroup); + $idLists[$table] = GeneralUtility::makeInstance(TempRepository::class)->getSpecialQueryIdList($this->queryGenerator, $table, $mailGroup); } break; case 4: diff --git a/Classes/Repository/TempRepository.php b/Classes/Repository/TempRepository.php index f89f5ad4a..8e6907dcc 100644 --- a/Classes/Repository/TempRepository.php +++ b/Classes/Repository/TempRepository.php @@ -3,6 +3,7 @@ namespace DirectMailTeam\DirectMail\Repository; +use DirectMailTeam\DirectMail\MailSelect; use TYPO3\CMS\Core\Database\Connection; use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction; @@ -378,4 +379,34 @@ public static function getStaticIdList($table, $uid) return $outArr; } + + /** + * Construct the array of uid's from $table selected + * by special query of mail group of such type + * + * @param MailSelect $queryGenerator The query generator object + * @param string $table The table to select from + * @param array $group The direct_mail group record + * + * @return array The resulting query. + */ + public static function getSpecialQueryIdList(MailSelect &$queryGenerator, $table, array $group): array + { + $outArr = []; + if ($group['query']) { + $queryGenerator->init('dmail_queryConfig', $table); + $queryGenerator->queryConfig = $queryGenerator->cleanUpQueryConfig(unserialize($group['query'])); + + $queryGenerator->extFieldLists['queryFields'] = 'uid'; + $select = $queryGenerator->getSelectQuery(); + /** @var Connection $connection */ + $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($table); + $recipients = $connection->executeQuery($select)->fetchAll(); + + foreach ($recipients as $recipient) { + $outArr[] = $recipient['uid']; + } + } + return $outArr; + } } \ No newline at end of file From 0f52ee43c6e1669c1ee049db5c407717f924fcfa Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Thu, 25 Aug 2022 13:24:32 +0200 Subject: [PATCH 304/342] move function 'getMailGroups' to temp repository --- Classes/DirectMailUtility.php | 46 ------------------ Classes/Module/DmailController.php | 2 +- Classes/Module/RecipientListController.php | 3 +- Classes/Repository/TempRepository.php | 55 ++++++++++++++++++++-- 4 files changed, 54 insertions(+), 52 deletions(-) diff --git a/Classes/DirectMailUtility.php b/Classes/DirectMailUtility.php index f54c7f4b8..8fb927b4e 100644 --- a/Classes/DirectMailUtility.php +++ b/Classes/DirectMailUtility.php @@ -102,52 +102,6 @@ public static function cleanPlainList(array $plainlist) return $plainlist; } - /** - * Get all group IDs - * - * @param string $list Comma-separated ID - * @param array $parsedGroups Groups ID, which is already parsed - * @param string $perms_clause Permission clause (Where) - * - * @return array the new Group IDs - */ - public static function getMailGroups($list, array $parsedGroups, $perms_clause) - { - $groupIdList = GeneralUtility::intExplode(',', $list); - $groups = []; - - $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_dmail_group'); - $queryBuilder - ->getRestrictions() - ->removeAll() - ->add(GeneralUtility::makeInstance(DeletedRestriction::class)); - $res = $queryBuilder->select('sys_dmail_group.*') - ->from('sys_dmail_group', 'sys_dmail_group') - ->leftJoin( - 'sys_dmail_group', - 'pages', - 'pages', - $queryBuilder->expr()->eq('pages.uid', $queryBuilder->quoteIdentifier('sys_dmail_group.pid')) - ) - ->add('where', 'sys_dmail_group.uid IN (' . implode(',', $groupIdList) . ')' . - ' AND ' . $perms_clause) - ->execute(); - - while (($row=$res->fetch())) { - if ($row['type'] == 4) { - // Other mail group... - if (!in_array($row['uid'], $parsedGroups)) { - $parsedGroups[] = $row['uid']; - $groups = array_merge($groups, self::getMailGroups($row['mail_groups'], $parsedGroups, $perms_clause)); - } - } else { - // Normal mail group, just add to list - $groups[] = $row['uid']; - } - } - return $groups; - } - /** * Parse CSV lines into array form * diff --git a/Classes/Module/DmailController.php b/Classes/Module/DmailController.php index e34c398e3..be39cab36 100644 --- a/Classes/Module/DmailController.php +++ b/Classes/Module/DmailController.php @@ -1736,7 +1736,7 @@ protected function getSingleMailGroup($groupUid) } break; case 4: - $groups = array_unique(DirectMailUtility::getMailGroups($mailGroup['mail_groups'], [$mailGroup['uid']], $this->perms_clause)); + $groups = array_unique(GeneralUtility::makeInstance(TempRepository::class)->getMailGroups($mailGroup['mail_groups'], [$mailGroup['uid']], $this->perms_clause)); foreach ($groups as $v) { $collect = $this->getSingleMailGroup($v); if (is_array($collect)) { diff --git a/Classes/Module/RecipientListController.php b/Classes/Module/RecipientListController.php index 999a50e6f..54bc755d5 100644 --- a/Classes/Module/RecipientListController.php +++ b/Classes/Module/RecipientListController.php @@ -323,7 +323,8 @@ protected function cmd_compileMailGroup(int $groupUid) } break; case 4: - $groups = array_unique(DirectMailUtility::getMailGroups($mailGroup['mail_groups'], [$mailGroup['uid']], $this->perms_clause)); + $groups = array_unique(GeneralUtility::makeInstance(TempRepository::class)->getMailGroups($mailGroup['mail_groups'], [$mailGroup['uid']], $this->perms_clause)); + foreach ($groups as $group) { $collect = $this->cmd_compileMailGroup($group); if (is_array($collect['queryInfo']['id_lists'])) { diff --git a/Classes/Repository/TempRepository.php b/Classes/Repository/TempRepository.php index 8e6907dcc..87b386cf5 100644 --- a/Classes/Repository/TempRepository.php +++ b/Classes/Repository/TempRepository.php @@ -20,7 +20,7 @@ class TempRepository extends MainRepository { * * @return array recipients' data */ - public static function fetchRecordsListValues(array $listArr, $table, $fields = 'uid,name,email') + public function fetchRecordsListValues(array $listArr, $table, $fields = 'uid,name,email') { $outListArr = []; if (is_array($listArr) && count($listArr)) { @@ -77,7 +77,7 @@ public static function fetchRecordsListValues(array $listArr, $table, $fields = * * @return array The resulting array of uid's */ - public static function getIdList($table, $pidList, $groupUid, $cat) + public function getIdList($table, $pidList, $groupUid, $cat) { $addWhere = ''; @@ -216,7 +216,7 @@ public static function getIdList($table, $pidList, $groupUid, $cat) * * @return array The resulting array of uid's */ - public static function getStaticIdList($table, $uid) + public function getStaticIdList($table, $uid) { $switchTable = $table == 'fe_groups' ? 'fe_users' : $table; @@ -390,7 +390,7 @@ public static function getStaticIdList($table, $uid) * * @return array The resulting query. */ - public static function getSpecialQueryIdList(MailSelect &$queryGenerator, $table, array $group): array + public function getSpecialQueryIdList(MailSelect &$queryGenerator, $table, array $group): array { $outArr = []; if ($group['query']) { @@ -409,4 +409,51 @@ public static function getSpecialQueryIdList(MailSelect &$queryGenerator, $table } return $outArr; } + + /** + * Get all group IDs + * + * @param string $list Comma-separated ID + * @param array $parsedGroups Groups ID, which is already parsed + * @param string $perms_clause Permission clause (Where) + * + * @return array the new Group IDs + */ + public function getMailGroups($list, array $parsedGroups, $permsClause) + { + $groupIdList = GeneralUtility::intExplode(',', $list); + $groups = []; + + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_dmail_group'); + $queryBuilder + ->getRestrictions() + ->removeAll() + ->add(GeneralUtility::makeInstance(DeletedRestriction::class)); + $res = $queryBuilder->select('sys_dmail_group.*') + ->from('sys_dmail_group', 'sys_dmail_group') + ->leftJoin( + 'sys_dmail_group', + 'pages', + 'pages', + $queryBuilder->expr()->eq('pages.uid', $queryBuilder->quoteIdentifier('sys_dmail_group.pid')) + ) + ->add('where', 'sys_dmail_group.uid IN (' . implode(',', $groupIdList) . ')' . + ' AND ' . $permsClause) + ->execute(); + + while ($row = $res->fetch()) { + if ($row['type'] == 4) { + // Other mail group... + if (!in_array($row['uid'], $parsedGroups)) { + $parsedGroups[] = $row['uid']; + $groups = array_merge($groups, $this->getMailGroups($row['mail_groups'], $parsedGroups, $permsClause)); + } + } + else { + // Normal mail group, just add to list + $groups[] = $row['uid']; + } + } + return $groups; + } } \ No newline at end of file From 5997f35c1b83fb940d56ccb4f96628484803a18d Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Thu, 25 Aug 2022 13:45:42 +0200 Subject: [PATCH 305/342] move function 'getFEgroupSubgroups' to temp repository --- Classes/DirectMailUtility.php | 75 ++--------- Classes/Repository/TempRepository.php | 186 ++++++++++++++++---------- 2 files changed, 133 insertions(+), 128 deletions(-) diff --git a/Classes/DirectMailUtility.php b/Classes/DirectMailUtility.php index 8fb927b4e..dc11a858f 100644 --- a/Classes/DirectMailUtility.php +++ b/Classes/DirectMailUtility.php @@ -233,8 +233,8 @@ public static function makeCategories($table, array $row, $sysLanguageUid) ->add('where', 'sys_dmail_category.pid IN (' . str_replace(',', "','", $queryBuilder->createNamedParameter($pidList)) . ')' . ' AND l18n_parent=0') ->execute(); - while (($rowCat = $res->fetch())) { - if (($localizedRowCat = self::getRecordOverlay('sys_dmail_category', $rowCat, $sysLanguageUid, ''))) { + while ($rowCat = $res->fetch()) { + if ($localizedRowCat = self::getRecordOverlay('sys_dmail_category', $rowCat, $sysLanguageUid, '')) { $categories[$localizedRowCat['uid']] = htmlspecialchars($localizedRowCat['category']); } } @@ -286,7 +286,8 @@ public static function getRecordOverlay($table, array $row, $sys_language_conten } } } - } elseif ($OLmode === 'hideNonTranslated' && $row[$GLOBALS['TCA'][$table]['ctrl']['languageField']] == 0) { + } + elseif ($OLmode === 'hideNonTranslated' && $row[$GLOBALS['TCA'][$table]['ctrl']['languageField']] == 0) { // Unset, if non-translated records should be hidden. // ONLY done if the source record really is default language and not [All] in which case it is allowed. unset($row); @@ -294,10 +295,12 @@ public static function getRecordOverlay($table, array $row, $sys_language_conten // Otherwise, check if sys_language_content is different from the value of the record // that means a japanese site might try to display french content. - } elseif ($sys_language_content!=$row[$GLOBALS['TCA'][$table]['ctrl']['languageField']]) { + } + elseif ($sys_language_content!=$row[$GLOBALS['TCA'][$table]['ctrl']['languageField']]) { unset($row); } - } else { + } + else { // When default language is displayed, // we never want to return a record carrying another language!: if ($row[$GLOBALS['TCA'][$table]['ctrl']['languageField']]>0) { @@ -522,58 +525,6 @@ public static function getRecordList(array $listArr, $table, $pageId, $editLinkF return $out; } - /** - * Get all subsgroups recursively. - * - * @param int $groupId Parent fe usergroup - * - * @return array The all id of fe_groups - */ - public static function getFEgroupSubgroups($groupId) - { - // get all subgroups of this fe_group - // fe_groups having this id in their subgroup field - - $table = 'fe_groups'; - $mmTable = 'sys_dmail_group_mm'; - $groupTable = 'sys_dmail_group'; - - $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table); - - $res = $queryBuilder->selectLiteral('DISTINCT fe_groups.uid') - ->from($table, $table) - ->join( - $table, - $mmTable, - $mmTable, - $queryBuilder->expr()->eq( - $mmTable . '.uid_local', - $queryBuilder->quoteIdentifier($table . '.uid') - ) - ) - ->join( - $mmTable, - $groupTable, - $groupTable, - $queryBuilder->expr()->eq( - $mmTable . '.uid_local', - $queryBuilder->quoteIdentifier($groupTable . '.uid') - ) - ) - ->andWhere('INSTR( CONCAT(\',\',fe_groups.subgroup,\',\'),\',' . intval($groupId) . ',\' )') - ->execute(); - $groupArr = []; - - while (($row = $res->fetch())) { - $groupArr[] = $row['uid']; - - // add all subgroups recursively too - $groupArr = array_merge($groupArr, self::getFEgroupSubgroups($row['uid'])); - } - - return $groupArr; - } - /** * Creates a directmail entry in th DB. * Used only for internal pages @@ -685,7 +636,8 @@ public static function getLanguageParam($sysLanguageUid, array $params) $param = $params['langParams.'][$sysLanguageUid]; // fallback: L == sys_language_uid - } else { + } + else { $param = '&L=' . $sysLanguageUid; } @@ -741,7 +693,7 @@ public static function createDirectMailRecordFromExternalURL($subject, $external // No plain text url if (!$externalUrlPlain || $urlParts === false || !$urlParts['host']) { $newRecord['plainParams'] = ''; - $newRecord['sendOptions']&=254; + $newRecord['sendOptions']&= 254; } else { $newRecord['plainParams'] = $externalUrlPlain; } @@ -749,7 +701,7 @@ public static function createDirectMailRecordFromExternalURL($subject, $external // No html url $urlParts = @parse_url($externalUrlHtml); if (!$externalUrlHtml || $urlParts === false || !$urlParts['host']) { - $newRecord['sendOptions']&=253; + $newRecord['sendOptions']&= 253; } else { $newRecord['HTMLParams'] = $externalUrlHtml; } @@ -1035,7 +987,8 @@ public static function getFullUrlsForDirectMailRecord(array $row) if ($result['htmlUrl']) { if (!($row['sendOptions'] & 2)) { $result['htmlUrl'] = ''; - } else { + } + else { $urlParts = @parse_url($result['htmlUrl']); if (!$urlParts['scheme']) { $result['htmlUrl'] = 'http://' . $result['htmlUrl']; diff --git a/Classes/Repository/TempRepository.php b/Classes/Repository/TempRepository.php index 87b386cf5..1893ed16d 100644 --- a/Classes/Repository/TempRepository.php +++ b/Classes/Repository/TempRepository.php @@ -282,23 +282,23 @@ public function getStaticIdList($table, $uid) 'sys_dmail_group', $queryBuilder->expr()->eq('sys_dmail_group_mm.uid_local', $queryBuilder->quoteIdentifier('sys_dmail_group.uid')) ) - ->innerJoin( - 'sys_dmail_group_mm', - $switchTable, - $switchTable, - $queryBuilder->expr()->eq('sys_dmail_group_mm.uid_foreign', $queryBuilder->quoteIdentifier($switchTable . '.uid')) - ) - ->andWhere( - $queryBuilder->expr()->andX() - ->add($queryBuilder->expr()->eq('sys_dmail_group_mm.uid_local', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT))) - ->add($queryBuilder->expr()->eq('sys_dmail_group_mm.tablenames', $queryBuilder->createNamedParameter($switchTable))) - ->add($queryBuilder->expr()->neq($switchTable . '.email', $queryBuilder->createNamedParameter(''))) - ->add($queryBuilder->expr()->eq('sys_dmail_group.deleted', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT))) - ->add($addWhere) - ) - ->orderBy($switchTable . '.uid') - ->addOrderBy($switchTable . '.email') - ->execute(); + ->innerJoin( + 'sys_dmail_group_mm', + $switchTable, + $switchTable, + $queryBuilder->expr()->eq('sys_dmail_group_mm.uid_foreign', $queryBuilder->quoteIdentifier($switchTable . '.uid')) + ) + ->andWhere( + $queryBuilder->expr()->andX() + ->add($queryBuilder->expr()->eq('sys_dmail_group_mm.uid_local', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT))) + ->add($queryBuilder->expr()->eq('sys_dmail_group_mm.tablenames', $queryBuilder->createNamedParameter($switchTable))) + ->add($queryBuilder->expr()->neq($switchTable . '.email', $queryBuilder->createNamedParameter(''))) + ->add($queryBuilder->expr()->eq('sys_dmail_group.deleted', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT))) + ->add($addWhere) + ) + ->orderBy($switchTable . '.uid') + ->addOrderBy($switchTable . '.email') + ->execute(); } $outArr = []; @@ -321,65 +321,117 @@ public function getStaticIdList($table, $uid) 'sys_dmail_group_mm', 'sys_dmail_group_mm', $queryBuilder->expr()->eq('sys_dmail_group_mm.uid_local', $queryBuilder->quoteIdentifier('sys_dmail_group.uid')) - ) - ->andWhere( - $queryBuilder->expr()->andX() - ->add($queryBuilder->expr()->eq('sys_dmail_group.uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT))) - ->add($queryBuilder->expr()->eq('fe_groups.uid', $queryBuilder->quoteIdentifier('sys_dmail_group_mm.uid_foreign'))) - ->add($queryBuilder->expr()->eq('sys_dmail_group_mm.tablenames', $queryBuilder->createNamedParameter($table))) - ) - ->execute(); + ) + ->andWhere( + $queryBuilder->expr()->andX() + ->add($queryBuilder->expr()->eq('sys_dmail_group.uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT))) + ->add($queryBuilder->expr()->eq('fe_groups.uid', $queryBuilder->quoteIdentifier('sys_dmail_group_mm.uid_foreign'))) + ->add($queryBuilder->expr()->eq('sys_dmail_group_mm.tablenames', $queryBuilder->createNamedParameter($table))) + ) + ->execute(); - list($groupId) = $res->fetchAll(); + list($groupId) = $res->fetchAll(); - // recursively get all subgroups of this fe_group - $subgroups = self::getFEgroupSubgroups($groupId); + // recursively get all subgroups of this fe_group + $subgroups = $this->getFEgroupSubgroups($groupId); - if (!empty($subgroups)) { - $usergroupInList = null; - foreach ($subgroups as $subgroup) { - $usergroupInList .= (($usergroupInList == null) ? null : ' OR') . ' INSTR( CONCAT(\',\',fe_users.usergroup,\',\'),CONCAT(\',' . intval($subgroup) . ',\') )'; - } - $usergroupInList = '(' . $usergroupInList . ')'; - - // fetch all fe_users from these subgroups - $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($table); - $queryBuilder = $connection->createQueryBuilder(); - // for fe_users and fe_group, only activated modulde_sys_dmail_newsletter - if ($switchTable == 'fe_users') { - $addWhere = $queryBuilder->expr()->eq( - $switchTable . '.module_sys_dmail_newsletter', - 1 - ); - } + if (!empty($subgroups)) { + $usergroupInList = null; + foreach ($subgroups as $subgroup) { + $usergroupInList .= (($usergroupInList == null) ? null : ' OR') . ' INSTR( CONCAT(\',\',fe_users.usergroup,\',\'),CONCAT(\',' . intval($subgroup) . ',\') )'; + } + $usergroupInList = '(' . $usergroupInList . ')'; + + // fetch all fe_users from these subgroups + $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($table); + $queryBuilder = $connection->createQueryBuilder(); + // for fe_users and fe_group, only activated modulde_sys_dmail_newsletter + if ($switchTable == 'fe_users') { + $addWhere = $queryBuilder->expr()->eq( + $switchTable . '.module_sys_dmail_newsletter', + 1 + ); + } + + $res = $queryBuilder + ->selectLiteral('DISTINCT ' . $switchTable . '.uid', $switchTable . '.email') + ->from($table, $table) + ->innerJoin( + $table, + $switchTable, + $switchTable + ) + ->orWhere($usergroupInList) + ->andWhere( + $queryBuilder->expr()->andX() + ->add($queryBuilder->expr()->neq($switchTable . '.email', $queryBuilder->createNamedParameter(''))) + ->add($addWhere) + ) + ->orderBy($switchTable . '.uid') + ->addOrderBy($switchTable . '.email') + ->execute(); - $res = $queryBuilder - ->selectLiteral('DISTINCT ' . $switchTable . '.uid', $switchTable . '.email') - ->from($table, $table) - ->innerJoin( - $table, - $switchTable, - $switchTable - ) - ->orWhere($usergroupInList) - ->andWhere( - $queryBuilder->expr()->andX() - ->add($queryBuilder->expr()->neq($switchTable . '.email', $queryBuilder->createNamedParameter(''))) - ->add($addWhere) - ) - ->orderBy($switchTable . '.uid') - ->addOrderBy($switchTable . '.email') - ->execute(); - - while ($row = $res->fetch()) { - $outArr[] = $row['uid']; - } - } + while ($row = $res->fetch()) { + $outArr[] = $row['uid']; + } + } } return $outArr; } + /** + * Get all subsgroups recursively. + * + * @param int $groupId Parent fe usergroup + * + * @return array The all id of fe_groups + */ + public function getFEgroupSubgroups($groupId) + { + // get all subgroups of this fe_group + // fe_groups having this id in their subgroup field + + $table = 'fe_groups'; + $mmTable = 'sys_dmail_group_mm'; + $groupTable = 'sys_dmail_group'; + + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table); + + $res = $queryBuilder->selectLiteral('DISTINCT fe_groups.uid') + ->from($table, $table) + ->join( + $table, + $mmTable, + $mmTable, + $queryBuilder->expr()->eq( + $mmTable . '.uid_local', + $queryBuilder->quoteIdentifier($table . '.uid') + ) + ) + ->join( + $mmTable, + $groupTable, + $groupTable, + $queryBuilder->expr()->eq( + $mmTable . '.uid_local', + $queryBuilder->quoteIdentifier($groupTable . '.uid') + ) + ) + ->andWhere('INSTR( CONCAT(\',\',fe_groups.subgroup,\',\'),\',' . intval($groupId) . ',\' )') + ->execute(); + $groupArr = []; + + while ($row = $res->fetch()) { + $groupArr[] = $row['uid']; + + // add all subgroups recursively too + $groupArr = array_merge($groupArr, $this->getFEgroupSubgroups($row['uid'])); + } + + return $groupArr; + } + /** * Construct the array of uid's from $table selected * by special query of mail group of such type From 7c620820d117e77c377fa86d4c1b88789bd9c708 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Thu, 25 Aug 2022 15:21:09 +0200 Subject: [PATCH 306/342] move functions 'makeCategories' and 'getRecordOverlay' to temp repository --- Classes/DirectMailUtility.php | 109 --------------------- Classes/Module/DmailController.php | 2 +- Classes/Module/RecipientListController.php | 3 +- Classes/Module/StatisticsController.php | 3 +- Classes/Repository/TempRepository.php | 106 ++++++++++++++++++++ 5 files changed, 109 insertions(+), 114 deletions(-) diff --git a/Classes/DirectMailUtility.php b/Classes/DirectMailUtility.php index dc11a858f..9b8269cf9 100644 --- a/Classes/DirectMailUtility.php +++ b/Classes/DirectMailUtility.php @@ -205,115 +205,6 @@ public static function rearrangePlainMails(array $plainMails) return $out; } - /** - * Compile the categories enables for this $row of this $table. - * - * @param string $table Table name - * @param array $row Row from table - * @param int $sysLanguageUid User language ID - * - * @return array the categories in an array with the cat id as keys - */ - public static function makeCategories($table, array $row, $sysLanguageUid) - { - $categories = []; - - $mmField = 'module_sys_dmail_category'; - if ($table == 'sys_dmail_group') { - $mmField = 'select_categories'; - } - - $pageTsConfig = BackendUtility::getTCEFORM_TSconfig($table, $row); - if (is_array($pageTsConfig[$mmField])) { - $pidList = $pageTsConfig[$mmField]['PAGE_TSCONFIG_IDLIST'] ?? []; - if ($pidList) { - $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_dmail_category'); - $res = $queryBuilder->select('*') - ->from('sys_dmail_category') - ->add('where', 'sys_dmail_category.pid IN (' . str_replace(',', "','", $queryBuilder->createNamedParameter($pidList)) . ')' . - ' AND l18n_parent=0') - ->execute(); - while ($rowCat = $res->fetch()) { - if ($localizedRowCat = self::getRecordOverlay('sys_dmail_category', $rowCat, $sysLanguageUid, '')) { - $categories[$localizedRowCat['uid']] = htmlspecialchars($localizedRowCat['category']); - } - } - } - } - return $categories; - } - - /** - * Import from t3lib_page in order to create backend version - * Creates language-overlay for records in general - * (where translation is found in records from the same table) - * - * @param string $table Table name - * @param array $row Record to overlay. Must contain uid, pid and languageField - * @param int $sys_language_content Language ID of the content - * @param string $OLmode Overlay mode. If "hideNonTranslated" then records without translation will not be returned un-translated but unset (and return value is false) - * - * @return mixed Returns the input record, possibly overlaid with a translation. But if $OLmode is "hideNonTranslated" then it will return false if no translation is found. - */ - public static function getRecordOverlay($table, array $row, $sys_language_content, $OLmode = '') - { - if ($row['uid']>0 && $row['pid']>0) { - if ($GLOBALS['TCA'][$table] && $GLOBALS['TCA'][$table]['ctrl']['languageField'] && $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']) { - if (!$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerTable']) { - // Will try to overlay a record only - // if the sys_language_content value is larger that zero. - if ($sys_language_content > 0) { - // Must be default language or [All], otherwise no overlaying: - if ($row[$GLOBALS['TCA'][$table]['ctrl']['languageField']]<=0) { - // Select overlay record: - $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table); - $res = $queryBuilder->select('*') - ->from($table) - ->add('where', 'pid=' . intval($row['pid']) . - ' AND ' . $GLOBALS['TCA'][$table]['ctrl']['languageField'] . '=' . intval($sys_language_content) . - ' AND ' . $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'] . '=' . intval($row['uid'])) - ->setMaxResults(1)/* LIMIT 1*/ - ->execute(); - - $olrow = $res->fetch(); - - // Merge record content by traversing all fields: - if (is_array($olrow)) { - foreach ($row as $fN => $fV) { - if ($fN!='uid' && $fN!='pid' && isset($olrow[$fN])) { - if ($GLOBALS['TCA'][$table]['l10n_mode'][$fN]!='exclude' && ($GLOBALS['TCA'][$table]['l10n_mode'][$fN]!='mergeIfNotBlank' || strcmp(trim($olrow[$fN]), ''))) { - $row[$fN] = $olrow[$fN]; - } - } - } - } - elseif ($OLmode === 'hideNonTranslated' && $row[$GLOBALS['TCA'][$table]['ctrl']['languageField']] == 0) { - // Unset, if non-translated records should be hidden. - // ONLY done if the source record really is default language and not [All] in which case it is allowed. - unset($row); - } - - // Otherwise, check if sys_language_content is different from the value of the record - // that means a japanese site might try to display french content. - } - elseif ($sys_language_content!=$row[$GLOBALS['TCA'][$table]['ctrl']['languageField']]) { - unset($row); - } - } - else { - // When default language is displayed, - // we never want to return a record carrying another language!: - if ($row[$GLOBALS['TCA'][$table]['ctrl']['languageField']]>0) { - unset($row); - } - } - } - } - } - - return $row; - } - /** * Print out an array as a table * diff --git a/Classes/Module/DmailController.php b/Classes/Module/DmailController.php index be39cab36..6ccb1e1a1 100644 --- a/Classes/Module/DmailController.php +++ b/Classes/Module/DmailController.php @@ -1888,7 +1888,7 @@ public function makeCategoriesForm(array $row, $indata) $colPosVal = $row['colPos']; } - $this->categories = DirectMailUtility::makeCategories('tt_content', $row, $this->sys_language_uid); + $this->categories = GeneralUtility::makeInstance(TempRepository::class)->makeCategories('tt_content', $row, $this->sys_language_uid); reset($this->categories); $cboxes = []; foreach ($this->categories as $pKey => $pVal) { diff --git a/Classes/Module/RecipientListController.php b/Classes/Module/RecipientListController.php index 54bc755d5..4f39a6c6f 100644 --- a/Classes/Module/RecipientListController.php +++ b/Classes/Module/RecipientListController.php @@ -788,8 +788,7 @@ protected function displayUserInfo() 'cmd' => $this->cmd, 'html' => $row['module_sys_dmail_html'] ? true : false ]; - - $this->categories = DirectMailUtility::makeCategories($this->table, $row, $this->sys_language_uid); + $this->categories = GeneralUtility::makeInstance(TempRepository::class)->makeCategories($this->table, $row, $this->sys_language_uid); reset($this->categories); foreach ($this->categories as $pKey => $pVal) { diff --git a/Classes/Module/StatisticsController.php b/Classes/Module/StatisticsController.php index 7f4dee2b2..911de8052 100644 --- a/Classes/Module/StatisticsController.php +++ b/Classes/Module/StatisticsController.php @@ -329,8 +329,7 @@ protected function displayUserInfo() 'returnUrl' => $this->requestUri, ]); - $this->categories = DirectMailUtility::makeCategories($this->table, $row, $this->sys_language_uid); - + $this->categories = GeneralUtility::makeInstance(TempRepository::class)->makeCategories($this->table, $row, $this->sys_language_uid); $data = [ 'icon' => $this->iconFactory->getIconForRecord($this->table, $row)->render(), 'iconActionsOpen' => $iconActionsOpen = $this->getIconActionsOpen(), diff --git a/Classes/Repository/TempRepository.php b/Classes/Repository/TempRepository.php index 1893ed16d..13d463d8a 100644 --- a/Classes/Repository/TempRepository.php +++ b/Classes/Repository/TempRepository.php @@ -4,6 +4,7 @@ namespace DirectMailTeam\DirectMail\Repository; use DirectMailTeam\DirectMail\MailSelect; +use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Core\Database\Connection; use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction; @@ -508,4 +509,109 @@ public function getMailGroups($list, array $parsedGroups, $permsClause) } return $groups; } + + /** + * Compile the categories enables for this $row of this $table. + * + * @param string $table Table name + * @param array $row Row from table + * @param int $sysLanguageUid User language ID + * + * @return array the categories in an array with the cat id as keys + */ + public static function makeCategories(string $table, array $row, int $sysLanguageUid) + { + $categories = []; + + $mmField = $table == 'sys_dmail_group' ? 'select_categories' : 'module_sys_dmail_category'; + + $pageTsConfig = BackendUtility::getTCEFORM_TSconfig($table, $row); + if (is_array($pageTsConfig[$mmField])) { + $pidList = $pageTsConfig[$mmField]['PAGE_TSCONFIG_IDLIST'] ?? []; + if ($pidList) { + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_dmail_category'); + $res = $queryBuilder->select('*') + ->from('sys_dmail_category') + ->add('where', 'sys_dmail_category.pid IN (' . str_replace(',', "','", $queryBuilder->createNamedParameter($pidList)) . ')' . + ' AND l18n_parent=0') + ->execute(); + while ($rowCat = $res->fetch()) { + if ($localizedRowCat = $this->getRecordOverlay('sys_dmail_category', $rowCat, $sysLanguageUid, '')) { + $categories[$localizedRowCat['uid']] = htmlspecialchars($localizedRowCat['category']); + } + } + } + } + return $categories; + } + + /** + * Import from t3lib_page in order to create backend version + * Creates language-overlay for records in general + * (where translation is found in records from the same table) + * + * @param string $table Table name + * @param array $row Record to overlay. Must contain uid, pid and languageField + * @param int $sys_language_content Language ID of the content + * @param string $OLmode Overlay mode. If "hideNonTranslated" then records without translation will not be returned un-translated but unset (and return value is false) + * + * @return mixed Returns the input record, possibly overlaid with a translation. But if $OLmode is "hideNonTranslated" then it will return false if no translation is found. + */ + public static function getRecordOverlay(string $table, array $row, int $sys_language_content, string $OLmode = '') + { + if ($row['uid'] > 0 && $row['pid'] > 0) { + if ($GLOBALS['TCA'][$table] && $GLOBALS['TCA'][$table]['ctrl']['languageField'] && $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']) { + if (!$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerTable']) { + // Will try to overlay a record only + // if the sys_language_content value is larger that zero. + if ($sys_language_content > 0) { + // Must be default language or [All], otherwise no overlaying: + if ($row[$GLOBALS['TCA'][$table]['ctrl']['languageField']] <= 0) { + // Select overlay record: + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table); + $olrow = $queryBuilder->select('*') + ->from($table) + ->add('where', 'pid=' . intval($row['pid']) . + ' AND ' . $GLOBALS['TCA'][$table]['ctrl']['languageField'] . '=' . intval($sys_language_content) . + ' AND ' . $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'] . '=' . intval($row['uid'])) + ->setMaxResults(1)/* LIMIT 1*/ + ->execute() + ->fetch(); + + // Merge record content by traversing all fields: + if (is_array($olrow)) { + foreach ($row as $fN => $fV) { + if ($fN != 'uid' && $fN != 'pid' && isset($olrow[$fN])) { + if ($GLOBALS['TCA'][$table]['l10n_mode'][$fN] != 'exclude' && ($GLOBALS['TCA'][$table]['l10n_mode'][$fN] != 'mergeIfNotBlank' || strcmp(trim($olrow[$fN]), ''))) { + $row[$fN] = $olrow[$fN]; + } + } + } + } + elseif ($OLmode === 'hideNonTranslated' && $row[$GLOBALS['TCA'][$table]['ctrl']['languageField']] == 0) { + // Unset, if non-translated records should be hidden. + // ONLY done if the source record really is default language and not [All] in which case it is allowed. + unset($row); + } + + // Otherwise, check if sys_language_content is different from the value of the record + // that means a japanese site might try to display french content. + } + elseif ($sys_language_content != $row[$GLOBALS['TCA'][$table]['ctrl']['languageField']]) { + unset($row); + } + } + else { + // When default language is displayed, + // we never want to return a record carrying another language!: + if ($row[$GLOBALS['TCA'][$table]['ctrl']['languageField']] > 0) { + unset($row); + } + } + } + } + } + + return $row; + } } \ No newline at end of file From 42e88b8ab45197c380a08461b052291a3a9cbf0e Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Thu, 25 Aug 2022 16:14:07 +0200 Subject: [PATCH 307/342] create function 'createDirectMailRecordFromPage' --- Classes/DirectMailUtility.php | 17 +++-------------- Classes/Repository/PagesRepository.php | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/Classes/DirectMailUtility.php b/Classes/DirectMailUtility.php index 9b8269cf9..bdf735fa8 100644 --- a/Classes/DirectMailUtility.php +++ b/Classes/DirectMailUtility.php @@ -14,6 +14,7 @@ * The TYPO3 project - inspiring people to share! */ +use DirectMailTeam\DirectMail\Repository\PagesRepository; use TYPO3\CMS\Backend\Routing\UriBuilder; use TYPO3\CMS\Backend\Tree\View\PageTreeView; use TYPO3\CMS\Backend\Utility\BackendUtility; @@ -426,7 +427,7 @@ public static function getRecordList(array $listArr, $table, $pageId, $editLinkF * @param int $sysLanguageUid * @return int|bool new record uid or FALSE if failed */ - public static function createDirectMailRecordFromPage($pageUid, array $parameters, $sysLanguageUid = 0) + public static function createDirectMailRecordFromPage(int $pageUid, array $parameters, int $sysLanguageUid = 0) { $result = false; @@ -470,19 +471,7 @@ public static function createDirectMailRecordFromPage($pageUid, array $parameter $pageRecord = BackendUtility::getRecord('pages', $pageUid); // Fetch page title from translated page if ($newRecord['sys_language_uid'] > 0) { - $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages'); - $queryBuilder - ->select('title') - ->from('pages') - ->where($queryBuilder->expr()->eq('l10n_parent', $queryBuilder->createNamedParameter($pageUid, \PDO::PARAM_INT))); - - $pageRecordOverlay = $queryBuilder->andWhere( - $queryBuilder->expr()->eq( - 'sys_language_uid', - $queryBuilder->createNamedParameter($newRecord['sys_language_uid'], \PDO::PARAM_INT) - ) - )->execute()->fetch(); - + $pageRecordOverlay = GeneralUtility::makeInstance(PagesRepository::class)->selectTitleTranslatedPage($pageUid, (int)$newRecord['sys_language_uid']); if (is_array($pageRecordOverlay)) { $pageRecord['title'] = $pageRecordOverlay['title']; } diff --git a/Classes/Repository/PagesRepository.php b/Classes/Repository/PagesRepository.php index 7ca6609d5..4ba7deb22 100644 --- a/Classes/Repository/PagesRepository.php +++ b/Classes/Repository/PagesRepository.php @@ -82,4 +82,20 @@ public function selectSubfolders(string $permsClause) //: array|bool ->execute() ->fetchAll(); } + + /** + * @return array|bool + */ + public function selectTitleTranslatedPage(int $pageUid, int $langUid) //: array|bool + { + $queryBuilder = $this->getQueryBuilder($this->table); + + return $queryBuilder + ->select('title') + ->from('pages') + ->where($queryBuilder->expr()->eq('l10n_parent', $queryBuilder->createNamedParameter($pageUid, \PDO::PARAM_INT))) + ->andWhere($queryBuilder->expr()->eq('sys_language_uid', $queryBuilder->createNamedParameter($langUid, \PDO::PARAM_INT))) + ->execute() + ->fetch(); + } } \ No newline at end of file From e27794738d44e6270a2a4a350fc4d079126e3735 Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Thu, 25 Aug 2022 16:40:37 +0200 Subject: [PATCH 308/342] create function 'updatePageTSconfig' --- Classes/DirectMailUtility.php | 9 +-------- Classes/Repository/PagesRepository.php | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Classes/DirectMailUtility.php b/Classes/DirectMailUtility.php index bdf735fa8..c9ff9dd4f 100644 --- a/Classes/DirectMailUtility.php +++ b/Classes/DirectMailUtility.php @@ -980,14 +980,7 @@ public static function updatePagesTSconfig($id, array $pageTs, $tsConfPrefix, $i // store those changes $tsConf = implode(LF, $tsLines); - - $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); - $connection = $connectionPool->getConnectionForTable('pages'); - $connection->update( - 'pages', // table - [ 'TSconfig' => $tsConf ], // value array - [ 'uid' => intval($id) ] // where - ); + $done = GeneralUtility::makeInstance(PagesRepository::class)->updatePageTSconfig((int)$id, $tsConf); } } } diff --git a/Classes/Repository/PagesRepository.php b/Classes/Repository/PagesRepository.php index 4ba7deb22..da9b4d817 100644 --- a/Classes/Repository/PagesRepository.php +++ b/Classes/Repository/PagesRepository.php @@ -98,4 +98,19 @@ public function selectTitleTranslatedPage(int $pageUid, int $langUid) //: array| ->execute() ->fetch(); } + + /** + * + * @param int $pageUid + * @param string $tsConf + * @return int + */ + public function updatePageTSconfig(int $pageUid, string $tsConf) { + $connection = $this->getConnection($this->table); + return $connection->update( + $this->table, + [ 'TSconfig' => $tsConf ], + [ 'uid' => $pageUid ] // where + ); + } } \ No newline at end of file From 529d2b66c580de44d6cd2bf805348a86fd2fcd2d Mon Sep 17 00:00:00 2001 From: Igor Neyman Date: Thu, 25 Aug 2022 17:09:28 +0200 Subject: [PATCH 309/342] create function 'updateSysDmailRecord' --- Classes/DirectMailUtility.php | 34 +++++++++++------------ Classes/Repository/SysDmailRepository.php | 16 +++++++++++ 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/Classes/DirectMailUtility.php b/Classes/DirectMailUtility.php index c9ff9dd4f..ebd934e0f 100644 --- a/Classes/DirectMailUtility.php +++ b/Classes/DirectMailUtility.php @@ -15,6 +15,7 @@ */ use DirectMailTeam\DirectMail\Repository\PagesRepository; +use DirectMailTeam\DirectMail\Repository\SysDmailRepository; use TYPO3\CMS\Backend\Routing\UriBuilder; use TYPO3\CMS\Backend\Tree\View\PageTreeView; use TYPO3\CMS\Backend\Utility\BackendUtility; @@ -34,10 +35,6 @@ use TYPO3\CMS\Core\Site\SiteFinder; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\MathUtility; -use TYPO3\CMS\Core\Database\ConnectionPool; -use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction; -use TYPO3\CMS\Core\Database\Connection; -use TYPO3\CMS\Core\Utility\VersionNumberUtility; use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; use TYPO3\CMS\Extbase\Object\ObjectManager; @@ -656,7 +653,8 @@ public static function fetchUrlContentsForDirectMailRecord(array $row, array $pa $htmlmail->addPlain($mailContent); if (!$mailContent || !$htmlmail->theParts['plain']['content']) { $errorMsg[] = $GLOBALS['LANG']->getLL('dmail_no_plain_content'); - } elseif (!strstr($htmlmail->theParts['plain']['content'], '
' . $this->iconFactory->getIconForRecord($table, $row, Icon::SIZE_SMALL) . '