[FEATURE] Akismet check for tx_form 13/33313/3
authortritum_rz <ralf.zimmermann@tritum.de>
Tue, 14 Oct 2014 21:02:04 +0000 (23:02 +0200)
committerRalf Zimmermann <ralf.zimmermann@tritum.de>
Tue, 14 Oct 2014 21:02:34 +0000 (23:02 +0200)
Resolves: #57516
Releases: 6.2
Change-Id: I549e76b0e719a2a1a2b96eb2830055bb75d8f4ad
Reviewed-on: http://review.typo3.org/33313
Reviewed-by: Ralf Zimmermann <ralf.zimmermann@tritum.de>
Tested-by: Ralf Zimmermann <ralf.zimmermann@tritum.de>
ChangeLog
Classes/Extensions/Form/PostProcess/WtspamshieldvalidatorPostProcessor.php [new file with mode: 0755]
Configuration/TypoScript/constants.txt
Configuration/TypoScript/setup.txt
ext_autoload.php

index da82a0f..71dfb7f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,7 @@
 
        * FIX feature #62238: Akismet check takes a lot of time
        * ADD feature #59247: Test field for Akismet
+       * ADD feature #57516: Akismet check for tx_form
 
        2014-09-24
        Ralf Zimmermann <ralf.zimmermann@tritum.de>
diff --git a/Classes/Extensions/Form/PostProcess/WtspamshieldvalidatorPostProcessor.php b/Classes/Extensions/Form/PostProcess/WtspamshieldvalidatorPostProcessor.php
new file mode 100755 (executable)
index 0000000..f0a693a
--- /dev/null
@@ -0,0 +1,159 @@
+<?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!
+ ***************************************************************/
+
+/**
+ * WtspamshieldvalidatorPostProcessor
+ */
+class WtspamshieldvalidatorPostProcessor implements \TYPO3\CMS\Form\PostProcess\PostProcessorInterface {
+
+       /**
+        * @var tx_wtspamshield_div
+        */
+       protected $div;
+
+       /**
+        * @var mixed
+        */
+       public $additionalValues = array();
+
+       /**
+        * @var string
+        */
+       public $tsKey = 'standardMailform';
+
+       /**
+        * @var mixed
+        */
+       public $tsConf;
+
+       /**
+        * @var \TYPO3\CMS\Form\Domain\Model\Form
+        */
+       public $form;
+
+       /**
+        * @var array
+        */
+       public $typoScript;
+
+       /**
+        * @var \TYPO3\CMS\Form\Request
+        */
+       public $requestHandler;
+
+       /**
+        * 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) {
+               $this->form = $form;
+               $this->typoScript = $typoScript;
+               $this->requestHandler = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Form\\Request');
+
+               $this->tsConf = $this->getDiv()->getTsConf();
+               $honeypotInputName = $this->tsConf['honeypot.']['inputname.'][$this->tsKey];
+               $this->additionalValues['honeypotCheck']['prefixInputName'] = 'tx_form';
+               $this->additionalValues['honeypotCheck']['honeypotInputName'] = $honeypotInputName;
+
+       }
+
+       /**
+        *
+        * @return void
+        */
+       public function process() {
+               if ( $this->getDiv()->isActivated($this->tsKey) ) {
+                       $error = '';
+
+                       $this->requestHandler->setMethod('session');
+                       if ($this->requestHandler->hasRequest()) {
+                               $session = $this->requestHandler->getSession();
+
+                               $validateArray = $session;
+                               $error = $this->validate($validateArray);
+                       } else {
+                               $error = 'no session data';
+                       }
+
+                       $urlConf = array('parameter' => 0);
+
+                       if (strlen($error) > 0) {
+                               if ($this->typoScript['errorDestination']) {
+                                       $urlConf = array('parameter' => $this->typoScript['errorDestination']);
+                               }
+
+                               $this->requestHandler->destroySession();
+                               $destination = $GLOBALS['TSFE']->cObj->typoLink_URL($urlConf);
+                               \TYPO3\CMS\Core\Utility\HttpUtility::redirect($destination);
+                       }
+               }
+       }
+
+       /**
+        * getDiv
+        * 
+        * @return tx_wtspamshield_div
+        */
+       protected function getDiv() {
+               if (!isset($this->div)) {
+                       $this->div = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_wtspamshield_div');
+               }
+               return $this->div;
+       }
+
+       /**
+        * validate
+        * 
+        * @param array $fieldValues
+        * @return string
+        */
+       protected function validate(array $fieldValues) {
+
+               $availableValidators =
+                       array(
+                               'blacklistCheck',
+                               'httpCheck',
+                               'honeypotCheck',
+                               'akismetCheck'
+                       );
+
+               $tsValidators = $this->getDiv()->commaListToArray($this->tsConf['validators.'][$this->tsKey . '_new.']['enable']);
+
+               $processor = $this->getDiv()->getProcessor();
+               $processor->tsKey = $this->tsKey;
+               $processor->fieldValues = $fieldValues;
+               $processor->additionalValues = $this->additionalValues;
+               $processor->failureRate = intval($this->tsConf['validators.'][$this->tsKey . '_new.']['how_many_validators_can_fail']);
+               $processor->methodes = array_intersect($tsValidators, $availableValidators);
+
+               $error = $processor->validate();
+               return $error;
+       }
+}
index d30aabb..920375a 100644 (file)
@@ -39,8 +39,8 @@ plugin.wt_spamshield {
   # cat=wt_spamshield main//0115; type=boolean; label= Protect formhandler: Enable spamshield for formhandler
   formhandler = 0
 
-  # cat=wt_spamshield main//0120; type=text; label= validators for standardMailform >= TYPO3 4.6: available validators are blacklistCheck, httpCheck, honeypotCheck
-  validators.standardMailform_new.enable = blacklistCheck, httpCheck, honeypotCheck
+  # cat=wt_spamshield main//0120; type=text; label= validators for standardMailform >= TYPO3 4.6: available validators are blacklistCheck, httpCheck, honeypotCheck, akismetCheck (only with wtspamshieldvalidator postProcessor)
+  validators.standardMailform_new.enable = blacklistCheck, httpCheck, honeypotCheck, akismetCheck
 
   # cat=wt_spamshield main//0130; type=int; label= failure rate for standardMailform >= TYPO3 4.6: how many validators can fail
   validators.standardMailform_new.how_many_validators_can_fail = 0
index 87ecb4c..721cd50 100644 (file)
@@ -233,6 +233,13 @@ plugin.wt_spamshield {
       body =
       permalink =
     }
+    standardMailform {
+      author = name
+      email = email
+      homepage = homepage
+      body = msg
+      permalink = homepage
+    }
   }
 }
 
index 3c1ed12..3ed1b61 100644 (file)
@@ -27,6 +27,7 @@ $return = array(
 'Tx_WtSpamshieldFormhandler_Interceptor_WtSpamshield' => $extPath . 'Classes/Extensions/Tx_WtSpamshieldFormhandler_Interceptor_WtSpamshield.php',
 
 'TYPO3\CMS\Form\PostProcess\WtspamshieldmailPostProcessor' => $extPath . 'Classes/Extensions/Form/PostProcess/WtspamshieldmailPostProcessor.php',
+'TYPO3\CMS\Form\PostProcess\WtspamshieldvalidatorPostProcessor' => $extPath . 'Classes/Extensions/Form/PostProcess/WtspamshieldvalidatorPostProcessor.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',
 );