- added captcha in subscription form
authorivankartolo <ivankartolo@735d13b6-9817-0410-8766-e36946ffe9aa>
Wed, 9 Feb 2011 15:05:28 +0000 (15:05 +0000)
committerivankartolo <ivankartolo@735d13b6-9817-0410-8766-e36946ffe9aa>
Wed, 9 Feb 2011 15:05:28 +0000 (15:05 +0000)
- added the ability to search for user recursively
- if no subscription's not found, no mail will be sent.

git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/direct_mail_subscription/trunk@43331 735d13b6-9817-0410-8766-e36946ffe9aa

ext_typoscript_setup.txt
fe_adminLib.inc
pi/fe_admin_dmailsubscrip.tmpl

index 74c6313..72418af 100644 (file)
@@ -62,8 +62,8 @@ plugin.feadmin.dmailsubscription {
        create {
                userFunc_afterSave = user_dmailsubscribe->saveRecord
                preview = 0
-               fields = name, hidden, email, module_sys_dmail_category, module_sys_dmail_html
-               required = name, email
+               fields = name, hidden, email, module_sys_dmail_category, module_sys_dmail_html, captcha
+               required = name, email, captcha
                noSpecialLoginForm = 1
                # Initially hide the user until he approves!
                overrideValues.hidden = 1
@@ -76,10 +76,14 @@ plugin.feadmin.dmailsubscription {
 
        evalErrors.email.uniqueLocal = Apparently you're already registered with this email address!
        evalErrors.email.email = This is not a proper email address!
+       evalErrors.captcha.captcha = Captcha code is not right.
 
        parseValues.module_sys_dmail_category = checkArray,setEmptyIfAbsent 
        parseValues.module_sys_dmail_html = setEmptyIfAbsent 
+       
        pid = {$plugin.feadmin.dmailsubscription.pid}
+       //always search recursively
+       pidRecursive = 1
 
        email.from = {$plugin.feadmin.dmailsubscription.email}
        email.fromName = {$plugin.feadmin.dmailsubscription.emailName}
index a89c1f9..926d12e 100644 (file)
@@ -326,7 +326,7 @@ class user_feAdmin  {
                } else {
                                // Finally, if there has been no attempt to save. That is either preview or just displaying and empty or not correctly filled form:
                        if (!$this->cmd)        {
-                               $this->cmd=$this->conf['defaultCmd'];
+                               $this->cmd = $this->conf['defaultCmd'];
                        }
                        if ($this->conf['debug'])               debug('Display form: '.$this->cmd,1);
                        switch($this->cmd)      {
@@ -729,6 +729,27 @@ class user_feAdmin {
                                }
                                $this->markerArray['###EVAL_ERROR_FIELD_'.$theField.'###'] = is_array($this->failureMsg[$theField]) ? implode('<br />',$this->failureMsg[$theField]) : '';
                        }
+                       
+                       /* CAPTCHA */
+                       if (t3lib_extMgm::isLoaded('captcha')){
+                               session_start();
+                               $captchaStr = $_SESSION['tx_captcha_string'];
+                               $_SESSION['tx_captcha_string'] = '';
+                               
+                               if ($captchaStr && $this->dataArr['captcha'] !== $captchaStr) { 
+                                       $theField = 'captcha';
+                                       $tempArr[] = $theField;
+                                       $this->failureMsg[$theField][] = $this->getFailure($theField, 'captcha', 'Wrong captcha!');
+                                       $this->markerArray['###EVAL_ERROR_FIELD_'.$theField.'###'] = is_array($this->failureMsg[$theField]) ? implode('<br />',$this->failureMsg[$theField]) : '';
+                                       
+                                       $templateCodeCaptcha = $this->cObj->getSubpart($this->templateCode, '###TEMPLATE_CAPTCHA###');
+                                       $this->markerArray['###CAPTCHA_IMG###'] = '<img src="'.t3lib_extMgm::siteRelPath('captcha').'captcha/captcha.php" alt="" />';
+                                       $this->markerArray['###CAPTCHA###'] = $this->cObj->substituteMarkerArray($templateCodeCaptcha, $this->markerArray);
+                                       
+                               }
+                       } 
+                       
+                       
                }
                $this->failure=implode(',',$tempArr);    //$failure will show which fields were not OK
        }
@@ -987,8 +1008,20 @@ class user_feAdmin        {
 
                        $markerArray = $this->cObj->fillInMarkerArray($this->markerArray, $this->dataArr, '', TRUE, 'FIELD_', $this->recInMarkersHSC);
                        if ($this->conf['create.']['preview'] && !$this->previewLabel)  {$markerArray['###HIDDENFIELDS###'].= '<input type="hidden" name="preview" value="1" />';}
+                       
+                       /* CAPTCHA */
+                       if (t3lib_extMgm::isLoaded('captcha')){
+                               if (!$this->markerArray['###CAPTCHA###']) {
+                                       $templateCodeCaptcha = $this->cObj->getSubpart($this->templateCode, '###TEMPLATE_CAPTCHA###');
+                                       $markerArrayCaptcha['###CAPTCHA_IMG###'] = '<img src="'.t3lib_extMgm::siteRelPath('captcha').'captcha/captcha.php" alt="" />';
+                                       $templateCodeCaptcha = $this->cObj->substituteSubpart($templateCodeCaptcha, '###SUB_REQUIRED_FIELD_captcha###', '');
+                                       $markerArray['###CAPTCHA###'] = $this->cObj->substituteMarkerArray($templateCodeCaptcha, $markerArrayCaptcha);
+                               }
+                       } else {
+                               $markerArray['###CAPTCHA###'] = '';
+                       }
                        $content = $this->cObj->substituteMarkerArray($templateCode, $markerArray);
-                       $content.=$this->cObj->getUpdateJS($this->modifyDataArrForFormUpdate($this->dataArr), $this->theTable.'_form', 'FE['.$this->theTable.']', $this->fieldList.$this->additionalUpdateFields);
+                       $content.= $this->cObj->getUpdateJS($this->modifyDataArrForFormUpdate($this->dataArr), $this->theTable.'_form', 'FE['.$this->theTable.']', $this->fieldList.$this->additionalUpdateFields);
                }
                return $content;
        }
@@ -1343,23 +1376,28 @@ class user_feAdmin      {
                                if (!$config['dontLockPid'])    {
                                        $pidLock='AND pid IN ('.$this->thePid.') ';
                                }
-
+                               
+                               //get PID recursively
+                               if ($this->conf["pidRecursive"]) {
+                                       $pidLock = "AND pid IN (".tslib_cObj::getTreeList($this->thePid,100).$this->thePid.")";
+                               }
+                               
                                        // Getting records
                                if (t3lib_div::testInt($fetch)) {
                                        $DBrows = $GLOBALS['TSFE']->sys_page->getRecordsByField($this->theTable,'uid',$fetch,$pidLock,'','','1');
                                } elseif ($fetch) {     // $this->conf['email.']['field'] must be a valid field in the table!
                                        $DBrows = $GLOBALS['TSFE']->sys_page->getRecordsByField($this->theTable,$this->conf['email.']['field'],$fetch,$pidLock,'','','100');
                                }
-
+                               
                                        // Processing records
                                if (is_array($DBrows))  {
                                        $recipient = $DBrows[0][$this->conf['email.']['field']];
                                        $this->compileMail($config['label'], $DBrows, $recipient, $this->conf['setfixed.']);
-                               } elseif ($this->cObj->checkEmail($fetch)) {
-                                       $this->sendMail($fetch, '', trim($this->cObj->getSubpart($this->templateCode, '###'.$this->emailMarkPrefix.'NORECORD###')));
+                                       $content = $this->getPlainTemplate('###TEMPLATE_INFOMAIL_SENT###');
+                               } else {
+                                       $content = $this->getPlainTemplate('###TEMPLATE_INFOMAIL_NORECORD###');
                                }
 
-                               $content = $this->getPlainTemplate('###TEMPLATE_INFOMAIL_SENT###');
                        } else {
                                $content = $this->getPlainTemplate('###TEMPLATE_INFOMAIL###');
                        }
index 077e394..63b6575 100644 (file)
 
 <BR>
 <b>HTML emails?</b><BR>
-<input type="checkbox" name="FE[tt_address][module_sys_dmail_html]" value=1>
+<input type="checkbox" name="FE[tt_address][module_sys_dmail_html]" value=1 />
 <BR>
-
-
+###CAPTCHA###
+<br />
 
 <input type="submit" name="whatever" value="Subscribe">
 <input type="submit" name="whatever" value="Cancel" onClick="document.forms[0].action='###BACK_URL###';">
@@ -88,6 +88,18 @@ Are you subscribed already and wishes to <a href="###FORM_URL###&cmd=infomail&ba
 
 
 
+<!-- ###TEMPLATE_CAPTCHA### begin -->
+###CAPTCHA_IMG###
+<br />
+<!--###SUB_REQUIRED_FIELD_captcha### begin
+       Same as above...
+       EVAL_ERROR_FIELD_email is in addition an error message defined in TypoScript in case an email address does not verify to be of correct syntax.
+-->
+       <font color=red><strong>You must fill in this field!</strong></font><BR>
+       ###EVAL_ERROR_FIELD_captcha###<BR>
+<!--###SUB_REQUIRED_FIELD_captcha### end-->
+<input type="text" size=30 name="FE[tt_address][captcha]" value="" />
+<!-- ###TEMPLATE_CAPTCHA### begin -->
 
 
 
@@ -372,6 +384,23 @@ Enter the email address <em>by which you're registered</em> here, and a link to
 
 
 
+<BR><BR><BR><BR><HR><BR><BR><BR>
+<em>           This template is the response page when no email is found.</em>
+<br>
+<br>
+
+<!-- ###TEMPLATE_INFOMAIL_NORECORD### begin
+       This template is the response page when no email is found.
+-->
+###GW1B###The email is not registered.###GW1E###<br>
+<br>
+###GW2B###
+
+<a href="###BACK_URL###"><strong>Go back to register.</strong></a><BR>
+###GW2E###
+
+<!-- ###TEMPLATE_INFOMAIL_NORECORD### end-->
+