[FEATURE] default mailform: dont include honeypot field in email 59/32959/3
authortritum_rz <ralf.zimmermann@tritum.de>
Wed, 24 Sep 2014 21:14:18 +0000 (23:14 +0200)
committerRalf Zimmermann <ralf.zimmermann@tritum.de>
Wed, 24 Sep 2014 21:15:21 +0000 (23:15 +0200)
Resolves: #61854
Releases: 6.2
Change-Id: I6f702690ceca0425b4e3e0a5d6b4d1f98dfa6007
Reviewed-on: http://review.typo3.org/32959
Reviewed-by: Ralf Zimmermann <ralf.zimmermann@tritum.de>
Tested-by: Ralf Zimmermann <ralf.zimmermann@tritum.de>
ChangeLog
Classes/Extensions/Form/PostProcess/WtspamshieldmailPostProcessor.php [new file with mode: 0755]
Classes/Extensions/Form/View/Mail/Html/HtmlView.php [new file with mode: 0755]
Classes/Extensions/Form/View/Mail/Plain/PlainView.php [new file with mode: 0755]
ext_autoload.php

index e876716..6ca0267 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,10 @@
-1.2.2
+1.3.0-dev
+       2014-05-04
+       Ralf Zimmermann <ralf.zimmermann@tritum.de>
+
+       * ADD feature #61854: default mailform: dont include honeypot field in email
+
+1.3.0-dev
        2014-05-04
        Ralf Zimmermann <ralf.zimmermann@tritum.de>
 
diff --git a/Classes/Extensions/Form/PostProcess/WtspamshieldmailPostProcessor.php b/Classes/Extensions/Form/PostProcess/WtspamshieldmailPostProcessor.php
new file mode 100755 (executable)
index 0000000..60d0631
--- /dev/null
@@ -0,0 +1,71 @@
+<?php
+namespace TYPO3\CMS\Form\PostProcess;
+
+/***************************************************************
+ *
+ *  Copyright notice
+ *
+ *  (c) 2014 Ralf Zimmermann <ralf.zimmermann@tritum.de>, TRITUM GmbH
+ *
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * WtspamshieldmailPostProcessor
+ */
+class WtspamshieldmailPostProcessor extends \TYPO3\CMS\Form\PostProcess\MailPostProcessor {
+
+       /**
+        * Constructor
+        *
+        * @param \TYPO3\CMS\Form\Domain\Model\Form $form Form domain model
+        * @param array $typoScript Post processor TypoScript settings
+        */
+       public function __construct(\TYPO3\CMS\Form\Domain\Model\Form $form, array $typoScript) {
+               parent::__construct($form, $typoScript);
+       }
+
+       /**
+        * Add the HTML content
+        *
+        * Add a MimePart of the type text/html to the message.
+        *
+        * @return void
+        */
+       public function setHtmlContent() {
+               /** @var $view \TYPO3\CMS\Form\View\Mail\Html\HtmlView */
+               $view = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TRITUM\\WtSpamshield\\Form\\View\\Mail\\Html\\HtmlView', $this->form, $this->typoScript);
+               $htmlContent = $view->get();
+               $this->mailMessage->setBody($htmlContent, 'text/html');
+       }
+
+       /**
+        * Add the plain content
+        *
+        * Add a MimePart of the type text/plain to the message.
+        *
+        * @return void
+        */
+       public function setPlainContent() {
+               /** @var $view \TYPO3\CMS\Form\View\Mail\Plain\PlainView */
+               $view = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TRITUM\\WtSpamshield\\Form\\View\\Mail\\Plain\\PlainView', $this->form, 0, $this->typoScript);
+               $plainContent = $view->render();
+               $this->mailMessage->addPart($plainContent, 'text/plain');
+       }
+}
diff --git a/Classes/Extensions/Form/View/Mail/Html/HtmlView.php b/Classes/Extensions/Form/View/Mail/Html/HtmlView.php
new file mode 100755 (executable)
index 0000000..6719536
--- /dev/null
@@ -0,0 +1,74 @@
+<?php
+namespace TRITUM\WtSpamshield\Form\View\Mail\Html;
+
+/***************************************************************
+ *
+ *  Copyright notice
+ *
+ *  (c) 2014 Ralf Zimmermann <ralf.zimmermann@tritum.de>, TRITUM GmbH
+ *
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * HtmlView
+ */
+class HtmlView extends \TYPO3\CMS\Form\View\Mail\Html\HtmlView {
+
+       /**
+        * Constructor
+        */
+       public function __construct(\TYPO3\CMS\Form\Domain\Model\Form $model, array $typoscript) {
+               parent::__construct($model, $typoscript);
+       }
+
+       /**
+        * Start the main DOMdocument for the form
+        * Return it as a string using saveXML() to get a proper formatted output
+        * (when using formatOutput :-)
+        *
+        * @return string XHTML string containing the whole form
+        */
+       public function get() {
+               if (is_array($this->typoscript['excludeFieldsFromMail.'])) {
+                       $excludeFields = $this->typoscript['excludeFieldsFromMail.'];
+               } else {
+                       $excludeFields = array();
+               }
+
+               $elements = $this->model->getElements();
+               $newElements = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('\\TYPO3\\CMS\\Form\\Domain\\Model\\Form');
+
+               foreach ($elements as $element) {
+                       $_elements = $element->getElements();
+
+                       foreach ($_elements as $_element) {
+                               if (!in_array($_element->getName(), $excludeFields)) {
+                                       $newElements->addElement($_element);
+                               }
+                       }
+               }
+               $this->setData($newElements);
+
+               $node = $this->render('element', FALSE);
+               $content = chr(10) . html_entity_decode($node->saveXML($node->firstChild), ENT_QUOTES, 'UTF-8') . chr(10);
+               return $content;
+       }
+
+}
diff --git a/Classes/Extensions/Form/View/Mail/Plain/PlainView.php b/Classes/Extensions/Form/View/Mail/Plain/PlainView.php
new file mode 100755 (executable)
index 0000000..d5df9f8
--- /dev/null
@@ -0,0 +1,80 @@
+<?php
+namespace TRITUM\WtSpamshield\Form\View\Mail\Plain;
+
+/***************************************************************
+ *
+ *  Copyright notice
+ *
+ *  (c) 2014 Ralf Zimmermann <ralf.zimmermann@tritum.de>, TRITUM GmbH
+ *
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * PlainView
+ */
+class PlainView extends \TYPO3\CMS\Form\View\Mail\Plain\PlainView {
+
+       /**
+        * The TypoScript settings for the confirmation
+        *
+        * @var array
+        */
+       protected $typoscript = array();
+
+       /**
+        * Constructor
+        *
+        * @param \TYPO3\CMS\Form\Domain\Model\Form $model
+        * @param integer $spaces
+        * @param array $typoscript
+        */
+       public function __construct(\TYPO3\CMS\Form\Domain\Model\Form $model, $spaces = 0, array $typoscript) {
+               $this->typoscript = $typoscript;
+               parent::__construct($model, $spaces);
+       }
+
+       /**
+        * @return string Plain content containing the submitted values
+        */
+       public function render() {
+               if (is_array($this->typoscript['excludeFieldsFromMail.'])) {
+                       $excludeFields = $this->typoscript['excludeFieldsFromMail.'];
+               } else {
+                       $excludeFields = array();
+               }
+
+               $elements = $this->model->getElements();
+               $newElements = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('\\TYPO3\\CMS\\Form\\Domain\\Model\\Form');
+
+               foreach ($elements as $element) {
+                       $_elements = $element->getElements();
+
+                       foreach ($_elements as $_element) {
+                               if (!in_array($_element->getName(), $excludeFields)) {
+                                       $newElements->addElement($_element);
+                               }
+                       }
+               }
+
+               $content = $this->renderChildren($newElements->getElements());
+               return $content;
+       }
+
+}
index d0f8875..3c1ed12 100644 (file)
@@ -25,6 +25,10 @@ $return = array(
 
 'tx_wtspamshield_powermail2' => $extPath . 'Classes/Extensions/class.tx_wtspamshield_powermail2.php',
 'Tx_WtSpamshieldFormhandler_Interceptor_WtSpamshield' => $extPath . 'Classes/Extensions/Tx_WtSpamshieldFormhandler_Interceptor_WtSpamshield.php',
+
+'TYPO3\CMS\Form\PostProcess\WtspamshieldmailPostProcessor' => $extPath . 'Classes/Extensions/Form/PostProcess/WtspamshieldmailPostProcessor.php',
+'TRITUM\WtSpamshield\Form\View\Mail\Plain\PlainView' => $extPath . 'Classes/Extensions/Form/View/Mail/Plain/PlainView.php',
+'TRITUM\WtSpamshield\Form\View\Mail\Html\HtmlView' => $extPath . 'Classes/Extensions/Form/View/Mail/Html/HtmlView.php',
 );
 
 return $return;