* #29677: fix captcha checking
authorivankartolo <ivankartolo@735d13b6-9817-0410-8766-e36946ffe9aa>
Fri, 28 Oct 2011 12:08:32 +0000 (12:08 +0000)
committerivankartolo <ivankartolo@735d13b6-9817-0410-8766-e36946ffe9aa>
Fri, 28 Oct 2011 12:08:32 +0000 (12:08 +0000)
* compatibility to 4.6

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

ChangeLog
fe_adminLib.inc
pi/class.dmailsubscribe.php
pi/fe_admin_dmailsubscrip.tmpl
static/setup.txt

index 7cc8a6f..fad6680 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,8 @@
-2011-20-06 Ivan Kartolo <ivan.kartolo@dkd.de>
+2011-10-28 Ivan Kartolo <ivan.kartolo@dkd.de>
+       * #29677: fix captcha checking
+       * compatibility to 4.6
+
+2011-10-06 Ivan Kartolo <ivan.kartolo@dkd.de>
        * #29676: fixes unreplaced marker
        * #13264: moved typoscript to static template
        
index dce00f8..a04cb1c 100644 (file)
@@ -677,7 +677,7 @@ class user_feAdmin  {
                                                        }
                                                break;
                                                case 'email':
-                                                       if (!$this->cObj->checkEmail($this->dataArr[$theField]))        {
+                                                       if (!t3lib_div::validEmail($this->dataArr[$theField]))  {
                                                                $tempArr[]=$theField;
                                                                $this->failureMsg[$theField][] = $this->getFailure($theField, $theCmd, 'You must enter a valid email address');
                                                        }
@@ -729,12 +729,10 @@ class user_feAdmin        {
                                }
                                $this->markerArray['###EVAL_ERROR_FIELD_'.$theField.'###'] = is_array($this->failureMsg[$theField]) ? implode('<br />',$this->failureMsg[$theField]) : '';
                        }
-                       
-                       $this->checkCaptcha();
-                       
-                       
+                       $tempArr[] = $this->checkCaptcha();
                }
-               $this->failure=implode(',',$tempArr);    //$failure will show which fields were not OK
+               
+               $this->failure = implode(',',$tempArr);  //$failure will show which fields were not OK
        }
 
        /**
@@ -751,16 +749,18 @@ class user_feAdmin        {
                        $captchaStr = $_SESSION['tx_captcha_string'];
                        $_SESSION['tx_captcha_string'] = '';
 
-                       if ($captchaStr && $this->dataArr['captcha'] !== $captchaStr) {
+                       if (empty($captchaStr) || ($this->dataArr['captcha'] !== $captchaStr)) {
                                $captcha = FALSE;
                                $theField = 'captcha';
-                               $tempArr[] = $theField;
                                $this->failureMsg[$theField][] = $this->getFailure($theField, 'captcha', 'Wrong captcha!');
                                $errorMsg = is_array($this->failureMsg[$theField]) ? implode('<br />',$this->failureMsg[$theField]) : '';
                                $this->markerArray['###CAPTCHA###'] = $this->getCaptcha($errorMsg);
                        }
                }
-               return $captcha;
+               
+               if (isset($theField)) {
+                       return $theField;
+               }
        }
        
        
@@ -1363,7 +1363,7 @@ class user_feAdmin        {
        function getCaptcha($errorMsg='') {
                if (t3lib_extMgm::isLoaded('captcha')){
                        $templateCodeCaptcha = $this->cObj->getSubpart($this->templateCode, '###TEMPLATE_CAPTCHA###');
-                       $markerArrayCaptcha['###CAPTCHA_IMG###'] = '<img src="'.t3lib_extMgm::siteRelPath('captcha').'captcha/captcha.php" alt="" />';
+                       $markerArrayCaptcha['###CAPTCHA_IMG###'] = '<img src="/'.t3lib_extMgm::siteRelPath('captcha').'captcha/captcha.php" alt="" />';
                        
                        if (!empty($errorMsg)) {
                        $markerArrayCaptcha['###EVAL_ERROR_FIELD_captcha###'] = $errorMsg;
@@ -1411,6 +1411,10 @@ class user_feAdmin       {
                if ($this->conf['infomail'] && $this->conf['email.']['field'])  {
                        $fetch = t3lib_div::_GP('fetch');
                        
+                       if ($fetch) {
+                               $this->evalValues();
+                       }
+                       
                        //check the failureMsg array, since evalValues is called
                        $captcha = TRUE;
                        if (is_array($this->failureMsg['captcha'])) {
@@ -1453,6 +1457,7 @@ class user_feAdmin        {
 
                        } else {
                                $content = $this->getPlainTemplate('###TEMPLATE_INFOMAIL###');
+                               $content = $this->removeRequired($content ,$this->failure);
                        }
                } else $content='Error: infomail option is not available or emailField is not setup in TypoScript';
                return $content;
index 99187b4..3fc376f 100644 (file)
@@ -10,7 +10,9 @@ class user_dmailsubscribe {
        var $LLtestPrefix = '';                         // You can set this during development to some value that makes it easy for you to spot all labels that ARe delivered by the getLL function.
        var $LLtestPrefixAlt = '';                      // Save as LLtestPrefix, but additional prefix for the alternative value in getLL() function calls
 
-
+       var $scriptRelPath = 'pi/class.dmailsubscribe.php';
+       var $extKey = 'direct_mail_subscription';
+       
        /**
         * Constructor
         */
@@ -74,6 +76,12 @@ class user_dmailsubscribe {
        function saveRecord($conf)    {
                //print "TEST";
                //t3lib_div::print_array($conf);
+               
+               //check loaded LL
+               if (!$this->LOCAL_LANG_loaded){
+                       $this->user_dmailsubscribe();
+               }
+
                if(intval($conf['rec']['uid'])) {
                        $fe = t3lib_div::_GP('FE');
                        $newFieldsArr = $fe['tt_address']['module_sys_dmail_category'];
@@ -113,33 +121,59 @@ class user_dmailsubscribe {
        /**
         * LOCALLANG copied from pibase
         */
-
-
+       
        /**
-        * Returns the localized label of the LOCAL_LANG key, $key
-        * Notice that for debugging purposes prefixes for the output values can be set with the internal vars ->LLtestPrefixAlt and ->LLtestPrefix
-        *
-        * @param       string          The key from the LOCAL_LANG array for which to return the value.
-        * @param       string          Alternative string to return IF no value is found set for the key, neither for the local language nor the default.
-        * @param       boolean         If true, the output label is passed through htmlspecialchars()
-        * @return      string          The value from LOCAL_LANG.
-        */
-       function pi_getLL($key,$alt='',$hsc=FALSE)      {
-               if (isset($this->LOCAL_LANG[$this->LLkey][$key]))       {
-                       $word = $GLOBALS['TSFE']->csConv($this->LOCAL_LANG[$this->LLkey][$key], $this->LOCAL_LANG_charset[$this->LLkey][$key]); // The "from" charset is normally empty and thus it will convert from the charset of the system language, but if it is set (see ->pi_loadLL()) it will be used.
-               } elseif ($this->altLLkey && isset($this->LOCAL_LANG[$this->altLLkey][$key]))   {
-                       $word = $GLOBALS['TSFE']->csConv($this->LOCAL_LANG[$this->altLLkey][$key], $this->LOCAL_LANG_charset[$this->altLLkey][$key]);   // The "from" charset is normally empty and thus it will convert from the charset of the system language, but if it is set (see ->pi_loadLL()) it will be used.
-               } elseif (isset($this->LOCAL_LANG['default'][$key]))    {
-                       $word = $this->LOCAL_LANG['default'][$key];     // No charset conversion because default is english and thereby ASCII
+       * Returns the localized label of the LOCAL_LANG key, $key
+       * Notice that for debugging purposes prefixes for the output values can be set with the internal vars ->LLtestPrefixAlt and ->LLtestPrefix
+       *
+       * @param        string          The key from the LOCAL_LANG array for which to return the value.
+       * @param        string          Alternative string to return IF no value is found set for the key, neither for the local language nor the default.
+       * @param        boolean         If TRUE, the output label is passed through htmlspecialchars()
+       * @return       string          The value from LOCAL_LANG.
+       */
+       public function pi_getLL($key, $alternativeLabel = '', $hsc = FALSE) {
+               if (isset($this->LOCAL_LANG[$this->LLkey][$key][0]['target'])) {
+       
+                       // The "from" charset of csConv() is only set for strings from TypoScript via _LOCAL_LANG
+                       if (isset($this->LOCAL_LANG_charset[$this->LLkey][$key])) {
+                               $word = $GLOBALS['TSFE']->csConv(
+                               $this->LOCAL_LANG[$this->LLkey][$key][0]['target'],
+                               $this->LOCAL_LANG_charset[$this->LLkey][$key]
+                               );
+                       } else {
+                               $word = $this->LOCAL_LANG[$this->LLkey][$key][0]['target'];
+                       }
+               } elseif ($this->altLLkey && isset($this->LOCAL_LANG[$this->altLLkey][$key][0]['target'])) {
+       
+                       // The "from" charset of csConv() is only set for strings from TypoScript via _LOCAL_LANG
+                       if (isset($this->LOCAL_LANG_charset[$this->altLLkey][$key])) {
+                               $word = $GLOBALS['TSFE']->csConv(
+                               $this->LOCAL_LANG[$this->altLLkey][$key][0]['target'],
+                               $this->LOCAL_LANG_charset[$this->altLLkey][$key]
+                               );
+                       } else {
+                               $word = $this->LOCAL_LANG[$this->altLLkey][$key][0]['target'];
+                       }
+               } elseif (isset($this->LOCAL_LANG['default'][$key][0]['target'])) {
+       
+                       // Get default translation (without charset conversion, english)
+                       $word = $this->LOCAL_LANG['default'][$key][0]['target'];
                } else {
-                       $word = $this->LLtestPrefixAlt.$alt;
+       
+                       // Return alternative string or empty
+                       $word = (isset($this->LLtestPrefixAlt)) ? $this->LLtestPrefixAlt . $alternativeLabel : $alternativeLabel;
                }
-
-               $output = $this->LLtestPrefix.$word;
-               if ($hsc)       $output = htmlspecialchars($output);
-
+       
+               $output = (isset($this->LLtestPrefix)) ? $this->LLtestPrefix . $word : $word;
+       
+               if ($hsc) {
+                       $output = htmlspecialchars($output);
+               }
+       
                return $output;
        }
+       
+       
 
        /**
         * Loads local-language values by looking for a "locallang.php" file in the plugin class directory ($this->scriptRelPath) and if found includes it.
@@ -147,29 +181,34 @@ class user_dmailsubscribe {
         *
         * @return      void
         */
-       function pi_loadLL()    {
-               if (!$this->LOCAL_LANG_loaded)  {
-                       $basePath = t3lib_extMgm::extPath('direct_mail_subscription').'pi/locallang.xml';
-
-                               // php or xml as source: In any case the charset will be that of the system language.
-                               // However, this function guarantees only return output for default language plus the specified language (which is different from how 3.7.0 dealt with it)
-                       $this->LOCAL_LANG = t3lib_div::readLLfile($basePath,$this->LLkey);
-                       if ($this->altLLkey)    {
-                               $tempLOCAL_LANG = t3lib_div::readLLfile($basePath,$this->altLLkey);
-                               $this->LOCAL_LANG = array_merge(is_array($this->LOCAL_LANG) ? $this->LOCAL_LANG : array(),$tempLOCAL_LANG);
+       public function pi_loadLL() {
+               if (!$this->LOCAL_LANG_loaded && $this->scriptRelPath) {
+                       $basePath = 'EXT:' . $this->extKey . '/' . dirname($this->scriptRelPath) . '/locallang.xml';
+
+                               // Read the strings in the required charset (since TYPO3 4.2)
+                       $this->LOCAL_LANG = t3lib_div::readLLfile($basePath,$this->LLkey, $GLOBALS['TSFE']->renderCharset);
+                       if ($this->altLLkey) {
+                               $this->LOCAL_LANG = t3lib_div::readLLfile($basePath,$this->altLLkey);
                        }
 
                                // Overlaying labels from TypoScript (including fictitious language keys for non-system languages!):
-                       if (is_array($this->conf['_LOCAL_LANG.']))      {
-                               reset($this->conf['_LOCAL_LANG.']);
-                               while(list($k,$lA)=each($this->conf['_LOCAL_LANG.']))   {
-                                       if (is_array($lA))      {
-                                               $k = substr($k,0,-1);
-                                               foreach($lA as $llK => $llV)    {
-                                                       if (!is_array($llV))    {
-                                                               $this->LOCAL_LANG[$k][$llK] = $llV;
-                                                               if ($k != 'default')    {
-                                                                       $this->LOCAL_LANG_charset[$k][$llK] = $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'];        // For labels coming from the TypoScript (database) the charset is assumed to be "forceCharset" and if that is not set, assumed to be that of the individual system languages (thus no conversion)
+                       $confLL = $this->conf['_LOCAL_LANG.'];
+                       if (is_array($confLL)) {
+                               foreach ($confLL as $languageKey => $languageArray) {
+                                               // Don't process label if the langue is not loaded
+                                       $languageKey = substr($languageKey,0,-1);
+                                       if (is_array($languageArray) && is_array($this->LOCAL_LANG[$languageKey])) {
+                                                       // Remove the dot after the language key
+                                               foreach ($languageArray as $labelKey => $labelValue) {
+                                                       if (!is_array($labelValue))     {
+                                                               $this->LOCAL_LANG[$languageKey][$labelKey][0]['target'] = $labelValue;
+
+                                                                       // For labels coming from the TypoScript (database) the charset is assumed to be "forceCharset"
+                                                                       // and if that is not set, assumed to be that of the individual system languages
+                                                               if ($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset']) {
+                                                                       $this->LOCAL_LANG_charset[$languageKey][$labelKey] = $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'];
+                                                               } else {
+                                                                       $this->LOCAL_LANG_charset[$languageKey][$labelKey] = $GLOBALS['TSFE']->csConvObj->charSetArray[$languageKey];
                                                                }
                                                        }
                                                }
index a62bf2a..dc75e50 100644 (file)
@@ -248,7 +248,7 @@ You're now subscribed to our newsletter. An email has been sent to your email ad
 <br />
 
 ###CAPTCHA###
-
+<br />
 
        ###HIDDENFIELDS###
        <input type="Submit" name="whatever" value="Update">
@@ -600,13 +600,13 @@ You're now subscribed to a TYPO3 Testsite newsletter.
 IMPORTANT:
 
 Before your subscriptions is fully enabled, you must click this link:
-###THIS_URL######FORM_URL###?1=1###SYS_SETFIXED_approve###
+###THIS_URL######FORM_URL###1=1###SYS_SETFIXED_approve###
 
 If you cannot accept the subscription (eg. if somebody else subscribed you!) just click this link and you're deleted from the database:
-###THIS_URL######FORM_URL######SYS_SETFIXED_DELETE###
+###THIS_URL######FORM_URL###1=1###SYS_SETFIXED_DELETE###
 
 If you wish to edit your personal data, click this link:
-###THIS_URL######FORM_URL###?cmd=edit&aC=###SYS_AUTHCODE###&rU=###FIELD_uid###
+###THIS_URL######FORM_URL###cmd=edit&aC=###SYS_AUTHCODE###&rU=###FIELD_uid###
 
 <!--###SUB_RECORD###-->
 <!-- ###EMAIL_TEMPLATE_CREATE_SAVED### end-->
index edec145..dcf8d22 100644 (file)
@@ -44,15 +44,19 @@ plugin.feadmin.dmailsubscription {
 
        // Info-mail setup
        infomail = 1
-       infomail.default {
-               label = FORGOTPASSWORD
+       infomail {
+               default {
+                       label = FORGOTPASSWORD
+               }
+               required = captcha, email 
+               fields = captcha, email
        }
-
+       
        // Edit setup
        edit = 1
        edit {
-               fields = gender, name, email, module_sys_dmail_category, module_sys_dmail_html
-               required = gender, name, email
+               fields = gender, name, email, module_sys_dmail_category, module_sys_dmail_html, captcha
+               required = gender, name, email, captcha
                evalValues.email = uniqueLocal, email
                userFunc_afterSave = user_dmailsubscribe->saveRecord            
        }
@@ -89,4 +93,10 @@ plugin.feadmin.dmailsubscription {
        email.fromName = {$plugin.feadmin.dmailsubscription.emailName}
        email.admin = {$plugin.feadmin.dmailsubscription.email}
        email.field = email
+}
+
+tt_content.list.20 {
+       21 = CASE
+       21.key.field = layout
+       21.0 = < plugin.feadmin.dmailsubscription
 }
\ No newline at end of file