Selaa lähdekoodia

Fix captcha see #7688

Julio Montoya 9 vuotta sitten
vanhempi
commit
0a68d4952f

+ 59 - 1
main/inc/lib/pear/HTML/QuickForm/CAPTCHA/Image.php

@@ -83,14 +83,72 @@ class HTML_QuickForm_CAPTCHA_Image extends HTML_QuickForm_CAPTCHA
      */
     var $_CAPTCHA_driver = 'Image';
 
+    /**
+     * Code based in HTML_QuickForm_text::getTemplate()
+     * In order to render correctly the captcha in different layouts
+     * @param string $layout
+     *
+     * @return string
+     */
+    public static function getTemplate($layout)
+    {
+        $size = 8;
+        switch ($layout) {
+            case FormValidator::LAYOUT_INLINE:
+                return '
+                <div class="form-group {error_class}">
+                    <label {label-for} >
+                        <!-- BEGIN required --><span class="form_required">*</span><!-- END required -->
+                        {label}
+                    </label>
+                    {element}
+                </div>';
+                break;
+            case FormValidator::LAYOUT_HORIZONTAL:
+                return '
+                <div class="form-group {error_class}">
+                    <label {label-for} class="col-sm-2 control-label" >
+                        <!-- BEGIN required --><span class="form_required">*</span><!-- END required -->
+                        {label}
+                    </label>
+                    <div class="col-sm-'.$size.'">
+                        {icon}
+                        {element}
+
+                        <!-- BEGIN label_2 -->
+                            <p class="help-block">{label_2}</p>
+                        <!-- END label_2 -->
+
+                        <!-- BEGIN error -->
+                            <span class="help-inline">{error}</span>
+                        <!-- END error -->
+                    </div>
+                    <div class="col-sm-2">
+                        <!-- BEGIN label_3 -->
+                            {label_3}
+                        <!-- END label_3 -->
+                    </div>
+                </div>';
+                break;
+            case FormValidator::LAYOUT_BOX_NO_LABEL:
+                return '
+                        <div class="input-group">
+                            {icon}
+                            {element}
+                        </div>';
+                break;
+        }
+    }
+
     /**
      * Returns the HTML for the CAPTCHA image
      *
      * @return string
      * @access public
      */
-    function toHtml()
+    public function toHtml()
     {
+
         if ($this->_flagFrozen) {
             return '';
         }

+ 0 - 3
main/inc/lib/pear/HTML/QuickForm/text.php

@@ -71,9 +71,6 @@ class HTML_QuickForm_text extends HTML_QuickForm_input
         $this->_persistantFreeze = true;
 
         $this->setType('text');
-
-        $renderer = FormValidator::getDefaultRenderer();
-        //$renderer->setElementTemplate($this->getTemplate(), $elementName);
     }
 
     /**

+ 4 - 4
main/inc/lib/pear/Text/CAPTCHA.php

@@ -14,11 +14,11 @@
 /**
  * Require Exception class for error handling.
  */
-require_once 'Text/CAPTCHA/Exception.php';
+//require_once 'Text/CAPTCHA/Exception.php';
 /**
  * Require Text_Password class for generating the phrase.
  */
-require_once 'Text/Password.php';
+//require_once 'Text/Password.php';
 
 /**
  * Text_CAPTCHA - creates a CAPTCHA for Turing tests.
@@ -77,7 +77,7 @@ class Text_CAPTCHA
     {
         $driver = basename($driver);
         $class = 'Text_CAPTCHA_Driver_' . $driver;
-        $file = str_replace('_', '/', $class) . '.php';
+        /*$file = str_replace('_', '/', $class) . '.php';
         //check if it exists and can be loaded
         if (!@fclose(@fopen($file, 'r', true))) {
             throw new Text_CAPTCHA_Exception(
@@ -85,7 +85,7 @@ class Text_CAPTCHA
             );
         }
         //continue with including the driver
-        include_once $file;
+        include_once $file;*/
 
         $driver = new $class;
 

+ 2 - 2
main/inc/lib/pear/Text/CAPTCHA/Driver/Base.php

@@ -10,7 +10,7 @@
  * @license  http://www.opensource.org/licenses/bsd-license.php BSD License
  * @link     http://pear.php.net/package/Text_CAPTCHA
  */
-require_once 'Text/CAPTCHA/Driver.php';
+
 /**
  * Base class file for all Text_CAPTCHA drivers.
  *
@@ -94,4 +94,4 @@ abstract class Text_CAPTCHA_Driver_Base implements Text_CAPTCHA_Driver
         $this->setPhrase(null);
         $this->setCaptcha(null);
     }
-}
+}

+ 1 - 1
main/inc/lib/pear/Text/CAPTCHA/Driver/Equation.php

@@ -13,7 +13,7 @@
  * @license  http://www.opensource.org/licenses/bsd-license.php BSD License
  * @link     http://pear.php.net/package/Text_CAPTCHA
  */
-require_once 'Text/CAPTCHA/Driver/Base.php';
+
 /**
  * Equation driver for Text_CAPTCHA.
  * Returns simple equations as string, e.g. "9 - 2"

+ 0 - 2
main/inc/lib/pear/Text/CAPTCHA/Driver/Figlet.php

@@ -12,8 +12,6 @@
  * @license  http://www.opensource.org/licenses/bsd-license.php BSD License
  * @link     http://pear.php.net/package/Text_CAPTCHA
  */
-require_once 'Text/CAPTCHA/Driver/Base.php';
-require_once 'Text/Figlet.php';
 /**
  * Text_CAPTCHA_Driver_Figlet - Text_CAPTCHA driver Figlet based CAPTCHAs
  *

+ 2 - 3
main/inc/lib/pear/Text/CAPTCHA/Driver/Image.php

@@ -11,8 +11,6 @@
  * @license  http://www.opensource.org/licenses/bsd-license.php BSD License
  * @link     http://pear.php.net/package/Text_CAPTCHA
  */
-require_once 'Text/CAPTCHA/Driver/Base.php';
-require_once 'Image/Text.php';
 
 /**
  * Text_CAPTCHA_Driver_Image - Text_CAPTCHA driver graphical CAPTCHAs
@@ -69,7 +67,8 @@ class Text_CAPTCHA_Driver_Image extends Text_CAPTCHA_Driver_Base
         'text_color' => '#000000',
         'lines_color' => '#CACACA',
         'background_color' => '#555555',
-        'antialias' => false);
+        'antialias' => false
+    );
 
     /**
      * Init function

+ 1 - 1
main/inc/lib/pear/Text/CAPTCHA/Driver/Numeral.php

@@ -12,7 +12,7 @@
  * @license  http://www.opensource.org/licenses/bsd-license.php BSD License
  * @link     http://pear.php.net/package/Text_CAPTCHA
  */
-require_once 'Text/CAPTCHA/Driver/Base.php';
+
 /**
  * Class used for numeral captchas
  *

+ 2 - 3
main/inc/lib/pear/Text/CAPTCHA/Driver/Word.php

@@ -13,8 +13,7 @@
  * @license  http://www.opensource.org/licenses/bsd-license.php BSD License
  * @link     http://pear.php.net/package/Text_CAPTCHA
  */
-require_once 'Text/CAPTCHA/Driver/Base.php';
-require_once 'Numbers/Words.php';
+
 /**
  * Require Numbers_Words class for generating the text.
  *
@@ -124,4 +123,4 @@ class Text_CAPTCHA_Driver_Word extends Text_CAPTCHA_Driver_Base
         }
         $this->setCaptcha($res);
     }
-}
+}

+ 1 - 3
main/inc/lib/pear/Text/CAPTCHA/Exception.php

@@ -12,8 +12,6 @@
  * @license  http://www.opensource.org/licenses/bsd-license.php BSD License
  * @link     http://pear.php.net/package/Text_CAPTCHA
  */
-$lib_path = api_get_path(LIBRARY_PATH);
-require_once $lib_path.'/pear/Exception.php';
 /**
  * Exception for Text_CAPTCHA
  *
@@ -26,4 +24,4 @@ require_once $lib_path.'/pear/Exception.php';
 class Text_CAPTCHA_Exception extends PEAR_Exception
 {
 
-}
+}

+ 1 - 1
main/inc/lib/pear/Text/Diff.php

@@ -50,7 +50,7 @@ class Text_Diff
             $engine = basename($engine);
         }
 
-        require_once 'Text/Diff/Engine/' . $engine . '.php';
+        //require_once 'Text/Diff/Engine/' . $engine . '.php';
         $class = 'Text_Diff_Engine_' . $engine;
         $diff_engine = new $class();
 

+ 0 - 2
main/inc/lib/pear/Text/Diff/Renderer/context.php

@@ -14,8 +14,6 @@
  * @package Text_Diff
  */
 
-/** Text_Diff_Renderer */
-require_once 'Text/Diff/Renderer.php';
 
 /**
  * @package Text_Diff

+ 0 - 3
main/inc/lib/pear/Text/Diff/Renderer/inline.php

@@ -13,9 +13,6 @@
  * @package Text_Diff
  */
 
-/** Text_Diff_Renderer */
-require_once 'Text/Diff/Renderer.php';
-
 /**
  * "Inline" diff renderer.
  *

+ 0 - 2
main/inc/lib/pear/Text/Diff/Renderer/unified.php

@@ -15,8 +15,6 @@
  * @package Text_Diff
  */
 
-/** Text_Diff_Renderer */
-require_once 'Text/Diff/Renderer.php';
 
 /**
  * @package Text_Diff

+ 0 - 1
main/inc/lib/pear/Text/Diff/ThreeWay.php

@@ -14,7 +14,6 @@
  */
 
 /** Text_Diff */
-require_once 'Text/Diff.php';
 
 /**
  * A class for computing three way diffs.

+ 0 - 1
main/inc/lib/pear/Text/Diff3.php

@@ -14,7 +14,6 @@
  */
 
 /** Text_Diff */
-require_once 'Text/Diff.php';
 
 /**
  * A class for computing three way diffs.

+ 3 - 5
main/inc/lib/userportal.lib.php

@@ -747,8 +747,6 @@ class IndexManager
             array('id' => 'password', 'icon' => 'lock')
         );
 
-        global $_configuration;
-
         // Captcha
         $captcha = api_get_setting('allow_captcha');
         $allowCaptcha = $captcha == 'true';
@@ -758,8 +756,8 @@ class IndexManager
             if ($useCaptcha) {
                 $ajax = api_get_path(WEB_AJAX_PATH).'form.ajax.php?a=get_captcha';
                 $options = array(
-                    'width'        => 250,
-                    'height'       => 90,
+                    'width' => 250,
+                    'height' => 90,
                     'callback'     => $ajax.'&var='.basename(__FILE__, '.php'),
                     'sessionVar'   => basename(__FILE__, '.php'),
                     'imageOptions' => array(
@@ -774,7 +772,7 @@ class IndexManager
                 //$options = array('callback' => 'qfcaptcha_image.php');
 
                 $captcha_question = $form->addElement('CAPTCHA_Image', 'captcha_question', '', $options);
-                $form->addElement('static', null, null, get_lang('ClickOnTheImageForANewOne'));
+                $form->addHtml(get_lang('ClickOnTheImageForANewOne'));
 
                 $form->addElement('text', 'captcha', get_lang('EnterTheLettersYouSee'));
                 $form->addRule('captcha', get_lang('EnterTheCharactersYouReadInTheImage'), 'required', null, 'client');