From 0790011dfe3af1a4b378d81987776697fc4fac81 Mon Sep 17 00:00:00 2001 From: Franz Holzinger Date: Thu, 4 Apr 2024 14:10:47 +0200 Subject: [PATCH 1/3] fix bug to show the errors in the front end --- ChangeLog | 18 +++++++--- Classes/Controller/Submit.php | 34 ++++++++++--------- Classes/View/Form.php | 19 +++++++++-- .../TypoScript/Default/constants.typoscript | 14 ++++---- ext_emconf.php | 2 +- 5 files changed, 55 insertions(+), 32 deletions(-) diff --git a/ChangeLog b/ChangeLog index 52e009bf..1867a1af 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +TODO: +Replace $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$extensionKey] by +https://docs.typo3.org/m/typo3/reference-coreapi/11.5/en-us/ExtensionArchitecture/FileStructure/ExtConfTemplate.html#accessing-saved-options + + +2024-04-04 Franz Holzinger + * use checkMXRecord for each e-mail address before sending a notification e-mail + * fix bug to show the errors formerly shown in a flash error page message in the front end 2023-12-01 Franz Holzinger * add Documentation fixes @@ -44,7 +52,7 @@ 2020-07-31 Franz Holzinger * add the field tstamp to the TCA - * add the page browser header to the ###TEMPLATE_FORUM### subpart of the template file board_template2.html + * add the page browser header to the ###TEMPLATE_FORUM### subpart of the template file board_template2.html 2020-07-27 Franz Holzinger * add new field city @@ -65,7 +73,7 @@ 2019-12-18 Franz Holzinger * fix issue #5: tt_board 1.10.15 works under TYPO3 9.5 * compatibility for TYPO3 9 breaking 82803: $TYPO3_CONF_VARS['FE']['content_doktypes'] has been removed in TYPO3 9 - + 2019-11-02 Franz Holzinger * adapt composer.json to current needs * add alias files tt_board_list for JambageCom\TtBoard\Controller\ListPluginController and tt_board_tree for JambageCom\TtBoard\Controller\TreePluginController @@ -131,7 +139,7 @@ * readd the API to use a commenting system inside of external extensions. Only the method getDefaultConfig is needed. 2018-11-25 Franz Holzinger - * new: Replace the labels from the newReply and newThread processScript setup by language labels: + * new: Replace the labels from the newReply and newThread processScript setup by language labels: newReply.didWhat, newReply.subjectPrefix, newReply.followThisLink, newThread.didWhat, newThread.subjectPrefix * Add a new label for each text entry in the file template/board_notify.txt * fix in composer.json: require shall use the namespace typo3-ter instead of jambagecom @@ -165,7 +173,7 @@ * bugfix for TYPO3 9.x: replace deprecated method ContentObjectRenderer::substituteMarkerArrayCached by TYPO3\CMS\Core\Service\MarkerBasedTemplateService::substituteMarkerArrayCached 2018-07-30 Franz Holzinger - * bugfix for TYPO3 9.x: replace deprecated method ContentObjectRenderer::fileResource by $TSFE->tmpl->getFileName and file_get_contents. + * bugfix for TYPO3 9.x: replace deprecated method ContentObjectRenderer::fileResource by $TSFE->tmpl->getFileName and file_get_contents. 2018-06-28 Franz Holzinger * bugfix: because of the new base class \JambageCom\Div2007\Base\TranslationBase the new \JambageCom\Div2007\Utility\BrowserUtility must be used. @@ -189,7 +197,7 @@ * HTML templates: remove the font entries. Use CSS instead. 2018-04-02 Franz Holzinger - * new feature: disallow fields by exclude.tt_board. Set it to cr_ip for GDPR compliance + * new feature: disallow fields by exclude.tt_board. Set it to cr_ip for GDPR compliance 2018-03-19 Franz Holzinger * rename PostForm into Form diff --git a/Classes/Controller/Submit.php b/Classes/Controller/Submit.php index f6e7e51f..9a537a4e 100644 --- a/Classes/Controller/Submit.php +++ b/Classes/Controller/Submit.php @@ -5,7 +5,7 @@ /*************************************************************** * Copyright notice * -* (c) 2023 Kasper Skårhøj +* (c) 2024 Kasper Skårhøj * All rights reserved * * This script is part of the TYPO3 project. The TYPO3 project is @@ -97,7 +97,7 @@ public static function execute(TypoScriptFrontendDataController $pObj, $conf) false ); if (is_array($row)) { - $email = $row['email']; + $email = $row['email'] ?? ''; } } @@ -354,11 +354,7 @@ public static function execute(TypoScriptFrontendDataController $pObj, $conf) if ( $notify && $conf['notify'] && - trim($row['email']) && - ( - !$conf['emailCheck'] || - MailUtility::checkMXRecord($row['email']) - ) + !empty($row['email']) ) { $labelKeys = ['p_at', 'p_content', 'p_salutation', 'p_subject', 'p_text_snippet', 'p_url_title']; $markersArray = []; @@ -426,14 +422,19 @@ public static function execute(TypoScriptFrontendDataController $pObj, $conf) } $fromName = $senderArray[0]; foreach ($addresses as $email) { - MailUtility::send( - $email, - $msgParts[0], - $msgParts[1], - '', - $fromEmail, - $fromName - ); + if ( + empty($conf['emailCheck']) || + MailUtility::checkMXRecord($email) + ) { + MailUtility::send( + $email, + $msgParts[0], + $msgParts[1], + '', + $fromEmail, + $fromName + ); + } } } } @@ -461,7 +462,8 @@ public static function execute(TypoScriptFrontendDataController $pObj, $conf) $message ); $sessionData = []; - $sessionData['error'] = $content; + $sessionData['error-title'] = $title; + $sessionData['error-message'] = $message; $session->setSessionData($sessionData); } diff --git a/Classes/View/Form.php b/Classes/View/Form.php index 67fb7d36..923314a9 100644 --- a/Classes/View/Form.php +++ b/Classes/View/Form.php @@ -62,7 +62,7 @@ function enableSubmitButtonFunc() { document.getElementById("' . $buttonId . '").disabled = !this.checked; } } -window.onload = addListeners; +window.onload = addListeners; '; return $result; @@ -82,6 +82,18 @@ public function render( $content = ''; $session = GeneralUtility::makeInstance(SessionHandler::class); $currentSessionData = $session->getSessionData(); + + $errorOut = ''; + if ( + !empty($currentSessionData['error-title']) && + !empty($currentSessionData['error-message']) + ) { + $errorOut = +'
+

' . $currentSessionData['error-title'] . '

+

' . $currentSessionData['error-message'] . '

+
'; + } $sessionData = []; $conf = $composite->getConf(); $modelObj = $composite->getModelObj(); @@ -96,15 +108,17 @@ public function render( $spamWord = ''; $cssPrefix = 'tx-ttboard-'; $notify = []; + $content .= $errorOut; if ( + empty($errorOut) && isset($GLOBALS['TSFE']->applicationData[$extensionKey]) && is_array($GLOBALS['TSFE']->applicationData[$extensionKey]) && !isset($GLOBALS['TSFE']->applicationData[$extensionKey]['error']) && isset($GLOBALS['TSFE']->applicationData[$extensionKey]['row']) && is_array($GLOBALS['TSFE']->applicationData[$extensionKey]['row']) ) { - $content = $languageObj->getLabel( + $content .= $languageObj->getLabel( 'post.thanks' ); } @@ -532,7 +546,6 @@ public function render( $sessionData['notify_me'] = $notify; } $session->setSessionData($sessionData); - return $content; } } diff --git a/Configuration/TypoScript/Default/constants.typoscript b/Configuration/TypoScript/Default/constants.typoscript index 3482bd9e..1224965e 100644 --- a/Configuration/TypoScript/Default/constants.typoscript +++ b/Configuration/TypoScript/Default/constants.typoscript @@ -24,7 +24,7 @@ plugin.tt_board { # cat=plugin.board; type=int+; label= Page Id of forum: Only set this if the BACKLINK does not work. PIDforum = - # cat=plugin.board/email; type=boolean; label= Email check: If you want to verify the validity of an entered email address + # cat=plugin.board/email; type=boolean; label= Email check: If you want to verify the validity of an entered email address by trying to connect to the mail gateway emailCheck = 0 # cat=plugin.board/captcha; type=string; label= Captcha check: If you want to display the captcha view and field. freecap or captcha are supported. @@ -46,11 +46,11 @@ plugin.tt_board_list { file.templateFile = EXT:tt_board/Resources/Private/Templates/board_template1.tmpl # cat=plugin.board/typo; type=wrap; label= List-style, Wrap 1: This wrap is used in the template-file. - wrap1 = + wrap1 = # cat=plugin.board/typo; type=wrap; label= List-style, Wrap 2: This wrap is used in the template-file. - wrap2 = + wrap2 = # cat=plugin.board/typo; type=wrap; label= List-style, Wrap 3: This wrap is used in the template-file. - wrap3 = + wrap3 = # cat=plugin.board/color; type=color; label= List-style, Color 1: This bgcolor is marker ###GC4### used in the template-file. color1 = #cae8f5 @@ -68,11 +68,11 @@ plugin.tt_board_tree { file.templateFile = EXT:tt_board/Resources/Private/Templates/board_template2.tmpl # cat=plugin.board/typo; type=wrap; label= Tree-style, Wrap 1: This wrap is used in the template-file. - wrap1 = + wrap1 = # cat=plugin.board/typo; type=wrap; label= Tree-style, Wrap 2: This wrap is used in the template-file. - wrap2 = + wrap2 = # cat=plugin.board/typo; type=wrap; label= Tree-style, Wrap 3: This wrap is used in the template-file. - wrap3 = + wrap3 = # cat=plugin.board/color; type=color; label= Tree-style, Color 1: This bgcolor is used in the template-file. color1 = #cae8f5 diff --git a/ext_emconf.php b/ext_emconf.php index fc3a1399..fbb2935c 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -8,7 +8,7 @@ 'title' => 'Message board, twin mode', 'description' => 'Simple threaded (tree) or list message board (forum).', 'category' => 'plugin', - 'version' => '1.14.0', + 'version' => '1.14.1', 'state' => 'stable', 'author' => 'Franz Holzinger', 'author_email' => 'franz@ttproducts.de', From d914b3c38d446d5be89ccf13a97b4119bc037382 Mon Sep 17 00:00:00 2001 From: Franz Holzinger Date: Thu, 4 Apr 2024 17:00:13 +0200 Subject: [PATCH 2/3] do not check for langkey = default --- Classes/View/Form.php | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/Classes/View/Form.php b/Classes/View/Form.php index 923314a9..72ce23e5 100644 --- a/Classes/View/Form.php +++ b/Classes/View/Form.php @@ -98,6 +98,7 @@ public function render( $conf = $composite->getConf(); $modelObj = $composite->getModelObj(); $languageObj = $composite->getLanguageObj(); + $langKey = $languageObj->getLocalLangKey(); $request = $cObj->getRequest(); $uid = $composite->getTtBoardUid(); $xhtmlFix = HtmlUtility::determineXhtmlFix(); @@ -454,9 +455,9 @@ public function render( ) { foreach ($lConf['dataArray.'] as $k => $dataRow) { if (strpos($dataRow['type'], '[author]') !== false) { - $lConf['dataArray.'][$k]['value'] = $GLOBALS['TSFE']->fe_user->user['name']; + $lConf['dataArray.'][$k]['value'] = $GLOBALS['TSFE']->fe_user->user['name'] ?? ''; } elseif (strpos($dataRow['type'], '[email]') !== false) { - $lConf['dataArray.'][$k]['value'] = $GLOBALS['TSFE']->fe_user->user['email']; + $lConf['dataArray.'][$k]['value'] = $GLOBALS['TSFE']->fe_user->user['email'] ?? ''; } } } @@ -473,21 +474,15 @@ public function render( is_array($lConf['dataArray.'][$k . '.']) ) { if ( + empty($lConf['dataArray.'][$k . '.'][$type]) || ( - !$languageObj->getLocalLangKey() || - $languageObj->getLocalLangKey() == 'default' - ) && - !$lConf['dataArray.'][$k . '.'][$type] || - - ( - $languageObj->getLocalLangKey() != 'default' && ( isset($lConf['dataArray.'][$k . '.'][$type . '.']) && !is_array($lConf['dataArray.'][$k . '.'][$type . '.']) || isset($lConf['dataArray.'][$k . '.'][$type . '.']['lang.']) && !is_array($lConf['dataArray.'][$k . '.'][$type . '.']['lang.']) || - isset($lConf['dataArray.'][$k . '.'][$type . '.']['lang.'][$languageObj->getLocalLangKey() . '.']) && - !is_array($lConf['dataArray.'][$k . '.'][$type . '.']['lang.'][$languageObj->getLocalLangKey() . '.']) + isset($lConf['dataArray.'][$k . '.'][$type . '.']['lang.'][$langKey . '.']) && + !is_array($lConf['dataArray.'][$k . '.'][$type . '.']['lang.'][$langKey . '.']) ) ) ) { @@ -503,14 +498,13 @@ public function render( $lConf['dataArray.'][$k . '.']['value'] = $origRow[$theField]; } elseif ( $theField == 'subject' && - $conf['fillSubject'] && - isset($row[$theField]) + !empty($conf['fillSubject']) && + !empty($row[$theField]) ) { $fillSubjectPrefix = $languageObj->getLabel( 'post.fillSubjectPrefix' ); - $lConf['dataArray.'][$k . '.']['value'] = $fillSubjectPrefix . $row[$theField]; } } From 83a21c62c5ea597098d4136cb2a9d7186a574a67 Mon Sep 17 00:00:00 2001 From: Franz Holzinger Date: Thu, 4 Apr 2024 18:03:04 +0200 Subject: [PATCH 3/3] fix error with search where clause --- Classes/Domain/TtBoard.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Classes/Domain/TtBoard.php b/Classes/Domain/TtBoard.php index 4e3dcf38..2aab7fa0 100644 --- a/Classes/Domain/TtBoard.php +++ b/Classes/Domain/TtBoard.php @@ -37,16 +37,18 @@ * @author Kasper Skårhøj * @author Franz Holzinger */ -use TYPO3\CMS\Core\SingletonInterface; -use JambageCom\Div2007\Utility\TableUtility; + use TYPO3\CMS\Core\Database\Query\Restriction\FrontendRestrictionContainer; -use JambageCom\Div2007\Database\QueryBuilderApi; use TYPO3\CMS\Core\Database\Connection; use TYPO3\CMS\Core\Database\ConnectionPool; +use TYPO3\CMS\Core\Database\Query\Expression\CompositeExpression; use TYPO3\CMS\Core\Database\Query\QueryBuilder; use TYPO3\CMS\Core\Information\Typo3Version; +use TYPO3\CMS\Core\SingletonInterface; use TYPO3\CMS\Core\Utility\GeneralUtility; +use JambageCom\Div2007\Utility\TableUtility; +use JambageCom\Div2007\Database\QueryBuilderApi; use JambageCom\TtBoard\Constants\TreeMark; use JambageCom\TtBoard\Domain\QueryParameter; @@ -247,9 +249,9 @@ public static function getPagesInPage($pid_list) * Returns number of post in a forum. * @param string ... $pidList comma separated list of page ids. * @param array ... $andWhereEqualsArray array of QueryParameter for equation comparisons - * @param where ... $where + * @param where ... $where */ - public function getNumPosts($pidList, array $queryParameters = [], QueryBuilder $where = null) + public function getNumPosts($pidList, array $queryParameters = [], CompositeExpression $where = null) { $pageIds = GeneralUtility::intExplode(',', (string) $pidList, true); $queryBuilder = $this->getQueryBuilder();