[FEATURE] add formhandler support 58/32958/2
authortritum_rz <ralf.zimmermann@tritum.de>
Wed, 24 Sep 2014 21:05:32 +0000 (23:05 +0200)
committerRalf Zimmermann <ralf.zimmermann@tritum.de>
Wed, 24 Sep 2014 21:07:27 +0000 (23:07 +0200)
Resolves: #57513
Releases: 6.2
Change-Id: I01659f92e918120d01bae43f1221cf5d04356d75
Reviewed-on: http://review.typo3.org/32958
Reviewed-by: Ralf Zimmermann <ralf.zimmermann@tritum.de>
Tested-by: Ralf Zimmermann <ralf.zimmermann@tritum.de>
ChangeLog
Classes/Extensions/Tx_WtSpamshieldFormhandler_Interceptor_WtSpamshield.php [new file with mode: 0644]
Configuration/TypoScript/Extensions/formhandler/setup.txt [new file with mode: 0644]
Configuration/TypoScript/constants.txt
Configuration/TypoScript/setup.txt
ext_autoload.php
ext_emconf.php
ext_tables.php

index a6b2eca..e876716 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,12 @@
        2014-05-04
        Ralf Zimmermann <ralf.zimmermann@tritum.de>
 
+       * ADD feature #57513: add formhandler support 
+
+1.2.2
+       2014-05-04
+       Ralf Zimmermann <ralf.zimmermann@tritum.de>
+
        * ADD feature #58442: add hook for custom powermail error messages 
 
 1.2.1
diff --git a/Classes/Extensions/Tx_WtSpamshieldFormhandler_Interceptor_WtSpamshield.php b/Classes/Extensions/Tx_WtSpamshieldFormhandler_Interceptor_WtSpamshield.php
new file mode 100644 (file)
index 0000000..28b5090
--- /dev/null
@@ -0,0 +1,161 @@
+<?php
+/*                                                                        *
+ * This script is part of the TYPO3 project - inspiring people to share!  *
+ *                                                                        *
+ * TYPO3 is free software; you can redistribute it and/or modify it under *
+ * the terms of the GNU General Public License version 2 as published by  *
+ * the Free Software Foundation.                                          *
+ *                                                                        *
+ * This script is distributed in the hope that it will be useful, but     *
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *
+ * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General      *
+ * Public License for more details.                                       *
+ *                                                                        */
+
+/**
+ * Spam protection for the form withouth Captcha using wt_spamshield extension. 
+ *
+ * @author     Charles Brunet <charles@cbrunet.net>
+ */
+class Tx_WtSpamshieldFormhandler_Interceptor_WtSpamshield extends Tx_Formhandler_Interceptor_AntiSpamFormTime {
+
+
+       /**
+        * @var tx_wtspamshield_div
+        */
+       protected $div;
+
+       /**
+        * @var mixed
+        */
+       public $additionalValues = array();
+
+       /**
+        * @var string
+        */
+       public $tsKey = 'formhandler';
+
+       /**
+        * @var mixed
+        */
+       public $tsConf;
+
+       /**     
+        * Initialize the class variables
+        *
+        * @param array $gp GET and POST variable array
+        * @param array $settings Typoscript configuration for the component (component.1.config.*)
+        *
+        * @return void
+        */
+       public function init($gp, $settings) {
+               // $this->tsConf is config from wt_spamshield
+               // $settings is config from formhandler
+               $this->tsConf = $this->getDiv()->getTsConf();
+
+
+               if (isset($settings['validators.'])) {
+                       if (isset($settings['validators.']['enable'])) {
+                               $this->tsConf['validators.'][$this->tsKey . '.']['enable'] = $settings['validators.']['enable'];
+                       }
+                       if (isset($settings['validators.']['how_many_validators_can_fail'])) {
+                               $this->tsConf['validators.'][$this->tsKey . '.']['how_many_validators_can_fail'] = $settings['validators.']['how_many_validators_can_fail'];
+                       }
+               }
+
+               
+               if (isset($settings['httpCheck.'])) {
+                       if (isset($settings['httpCheck.']['maximumLinkAmount'])) {
+                               $this->tsConf['httpCheck.']['maximumLinkAmount'] = $settings['httpCheck.']['maximumLinkAmount'];
+                       }                        
+               }
+
+               if (isset($settings['uniqueCheck.'])) {
+                       if (isset($settings['uniqueCheck.']['fields'])) {
+                               $this->tsConf['uniqueCheck.']['fields'] = $settings['uniqueCheck.']['fields'];
+                       }
+               }
+
+               $honeypotInputName = $this->tsConf['honeypot.']['inputname.'][$this->tsKey];
+               if (isset($settings['honeypotCheck.'])) {
+                       if (isset($settings['honeypotCheck.']['inputname'])) {
+                               $honeypotInputName = $settings['honeypotCheck.']['inputname'];
+                       }
+               }
+               $this->additionalValues['honeypotCheck']['honeypotInputName'] = $honeypotInputName;
+
+               if (isset($settings['akismetCheck.'])) {
+                       if (isset($settings['akismetCheck.']['fields.'])) {
+                               foreach ($settings['akismetCheck.']['fields.'] as $key => $value) {
+                                       $this->tsConf['fields.'][$this->tsKey . '.'][$key] = $value;
+                               }
+                       }
+               }
+
+               // This is a little hack to pass config values to wt_spamshield.
+               // It could probably fail if there are more than one plugin on the same page.
+               $GLOBALS['TSFE']->tmpl->setup['plugin.']['wt_spamshield.'] = $this->tsConf;
+               
+
+               parent::init($gp, $settings);
+       }
+
+       /**
+        * 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;
+       }
+
+
+       /**
+        * Performs checks if the submitted form should be treated as Spam.
+        *
+        * @return boolean
+        */
+       protected function doCheck() {
+               if ( $this->getDiv()->isActivated($this->tsKey) ) {
+                       $error = $this->validate($this->gp);
+                       $this->gp['wtspamshield'] = strip_tags($error);
+                       if (strlen($error) > 0) {
+                               return TRUE;
+                       }
+               }
+               return FALSE;
+       }
+
+       /**
+        * validate
+        * 
+        * @param array $fieldValues
+        * @return string
+        */
+       protected function validate(array $fieldValues) {
+
+               $availableValidators =
+                       array(
+                               'blacklistCheck',
+                               'httpCheck',
+                               'uniqueCheck',
+                               'honeypotCheck',
+                               'akismetCheck',
+                       );
+
+               $tsValidators = $this->getDiv()->commaListToArray($this->tsConf['validators.'][$this->tsKey . '.']['enable']);
+
+               $processor = $this->getDiv()->getProcessor();
+               $processor->tsKey = $this->tsKey;
+               $processor->fieldValues = $fieldValues;
+               $processor->additionalValues = $this->additionalValues;
+               $processor->failureRate = intval($this->tsConf['validators.'][$this->tsKey . '.']['how_many_validators_can_fail']);
+               $processor->methodes = array_intersect($tsValidators, $availableValidators);
+
+               $error = $processor->validate();
+               return $error;
+       }
+}
\ No newline at end of file
diff --git a/Configuration/TypoScript/Extensions/formhandler/setup.txt b/Configuration/TypoScript/Extensions/formhandler/setup.txt
new file mode 100644 (file)
index 0000000..af9485f
--- /dev/null
@@ -0,0 +1,20 @@
+plugin.Tx_Formhandler.settings.markers.HONEYPOT = TEXT
+plugin.Tx_Formhandler.settings.markers.HONEYPOT {
+  value < plugin.wt_spamshield.honeypot.inputname.formhandler
+  value.wrap = [|]
+  value.prepend = TEXT
+  value.prepend.value < plugin.Tx_Formhandler.settings.formValuesPrefix
+
+  stdWrap {
+    outerWrap = <input type="text" autocomplete="off" | value="" />
+    noTrimWrap = | name="|" |
+    append = COA
+    append {
+      stdWrap.noTrimWrap = | | |
+      10 = TEXT
+      10.value < plugin.wt_spamshield.honeypot.css.inputStyle
+      20 = TEXT
+      20.value < plugin.wt_spamshield.honeypot.css.inputClass
+    }
+  }
+}
index c95d3ab..5cafa57 100644 (file)
@@ -36,6 +36,9 @@ plugin.wt_spamshield {
   # cat=wt_spamshield main//0110; type=boolean; label= Protect pbsurvey: Enable spamshield for pbsurvey
   pbsurvey = 0
 
+  # 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
 
@@ -96,6 +99,12 @@ plugin.wt_spamshield {
   # cat=wt_spamshield main//0310; type=int; label= failure rate for pbsurvey: how many validators can fail
   validators.pbsurvey.how_many_validators_can_fail = 0
 
+  # cat=wt_spamshield main//0315; type=text; label= validators for formhandler: available validators are blacklistCheck, httpCheck, uniqueCheck, honeypotCheck, akismetCheck
+  validators.formhandler.enable = blacklistCheck, httpCheck, uniqueCheck, honeypotCheck, akismetCheck
+
+  # cat=wt_spamshield main//0316; type=int; label= failure rate for formhandler: how many validators can fail
+  validators.formhandler.how_many_validators_can_fail = 0
+
   # cat=wt_spamshield main//0320; type=text; label= Mailform Redirect: Redirect URL for default mailform
   redirect_mailform =
 
@@ -149,4 +158,7 @@ plugin.wt_spamshield {
 
   # cat=wt_spamshield main//0490; type=text; label= Honeypot input name for pbsurvey
   honeypot.inputname.pbsurvey = uid987651
+
+  # cat=wt_spamshield main//0500; type=text; label= Honeyput input name for formhandler
+  honeypot.inputname.formhandler = uid987651
 }
index bbf4071..d58fe78 100644 (file)
@@ -46,6 +46,10 @@ plugin.wt_spamshield {
       enable = {$plugin.wt_spamshield.validators.pbsurvey.enable}
       how_many_validators_can_fail = {$plugin.wt_spamshield.validators.pbsurvey.how_many_validators_can_fail}
     }
+    formhandler {
+      enable = {$plugin.wt_spamshield.validators.formhandler.enable}
+      how_many_validators_can_fail = {$plugin.wt_spamshield.validators.formhandler.how_many_validators_can_fail}
+    }
   }
 
   enable {
@@ -58,6 +62,7 @@ plugin.wt_spamshield {
     direct_mail_subscription = {$plugin.wt_spamshield.direct_mail_subscription}
     ke_userregister = {$plugin.wt_spamshield.ke_userregister}
     pbsurvey = {$plugin.wt_spamshield.pbsurvey}
+    formhandler = {$plugin.wt_spamshield.formhandler}
   }
 
   redirect {
@@ -108,6 +113,7 @@ plugin.wt_spamshield {
       direct_mail_subscription = {$plugin.wt_spamshield.honeypot.inputname.direct_mail_subscription}
       ke_userregister = {$plugin.wt_spamshield.honeypot.inputname.ke_userregister}
       pbsurvey = {$plugin.wt_spamshield.honeypot.inputname.pbsurvey}
+      formhandler = {$plugin.wt_spamshield.honeypot.inputname.formhandler}
     }
   }
 
@@ -219,6 +225,13 @@ plugin.wt_spamshield {
       body = entry
       permalink = homepage
     }
+    formhandler {
+      author =
+      email =
+      homepage =
+      body =
+      permalink =
+    }
   }
 }
 
index 9ddeef1..d0f8875 100644 (file)
@@ -24,6 +24,7 @@ $return = array(
 'tx_wtspamshield_method_unique' => $extPath . 'Classes/Methodes/class.tx_wtspamshield_method_unique.php',
 
 'tx_wtspamshield_powermail2' => $extPath . 'Classes/Extensions/class.tx_wtspamshield_powermail2.php',
+'Tx_WtSpamshieldFormhandler_Interceptor_WtSpamshield' => $extPath . 'Classes/Extensions/Tx_WtSpamshieldFormhandler_Interceptor_WtSpamshield.php',
 );
 
 return $return;
index 48e0b43..09bc516 100644 (file)
@@ -15,7 +15,7 @@ $EM_CONF[$_EXTKEY] = array(
        'description' => 'Spam shield without captcha to avoid spam in powermail, ve_guestbook, comments, t3_blog, direct_mail_subscription and standard TYPO3 mailforms. Session check, Link check, Time check, Akismet check, Name check, Honeypot check (see manual for details)',
        'category' => 'services',
        'shy' => 0,
-       'version' => '1.2.2',
+       'version' => '1.3.0-dev',
        'dependencies' => '',
        'conflicts' => 'mf_akismet,wt_calculating_captcha',
        'priority' => '',
index 9463c63..5b4caf1 100644 (file)
@@ -5,6 +5,7 @@ if (!defined ('TYPO3_MODE')) {
 
 t3lib_extMgm::addStaticFile($_EXTKEY, 'Configuration/TypoScript', 'Main Settings');
 t3lib_extMgm::addStaticFile($_EXTKEY, 'Configuration/TypoScript/Extensions/direct_mail_subscription', 'direct_mail_subscription');
+t3lib_extMgm::addStaticFile($_EXTKEY, 'Configuration/TypoScript/Extensions/formhandler', 'formhandler');
 
        // only add static template for default mailform
        // if new form extension is not loaded