[Jaws-commits] r12411 - trunk/jaws/html/gadgets/Policy

afz at jaws-project.com afz at jaws-project.com
Mon Jan 16 07:38:46 UTC 2012


Author: afz
Date: 2012-01-16 07:38:46 +0000 (Mon, 16 Jan 2012)
New Revision: 12411

Modified:
   trunk/jaws/html/gadgets/Policy/HTML.php
   trunk/jaws/html/gadgets/Policy/Model.php
Log:
Added methods to Policy to load and check captcha

Modified: trunk/jaws/html/gadgets/Policy/HTML.php
===================================================================
--- trunk/jaws/html/gadgets/Policy/HTML.php	2012-01-16 07:38:11 UTC (rev 12410)
+++ trunk/jaws/html/gadgets/Policy/HTML.php	2012-01-16 07:38:46 UTC (rev 12411)
@@ -38,13 +38,24 @@
      */
     function Captcha()
     {
-        $GLOBALS['app']->Registry->LoadFile('Policy');
-        $_captcha = $GLOBALS['app']->Registry->Get('/gadgets/Policy/captcha');
-        if ($_captcha == 'DISABLED') {
-            return '';
+        $status = $GLOBALS['app']->Registry->Get('/gadgets/Policy/captcha');
+        if (($status == 'DISABLED') ||
+            ($status == 'ANONYMOUS' && $GLOBALS['app']->Session->Logged())) {
+            return false;
         }
-        require_once JAWS_PATH . 'gadgets/Policy/captchas/' . $_captcha . '.php';
-        $captcha = new $_captcha();
-        $captcha->Image();
+
+        static $objCaptcha;
+        if (!isset($objCaptcha)) {
+            $objCaptcha = array();
+        }
+
+        $dCaptcha = $GLOBALS['app']->Registry->Get('/gadgets/Policy/captcha_driver');
+        if (!isset($objCaptcha[$dCaptcha])) {
+            require_once JAWS_PATH . 'gadgets/Policy/captchas/' . $dCaptcha . '.php';
+            $objCaptcha[$dCaptcha] = new $dCaptcha();
+        }
+
+        $objCaptcha[$dCaptcha]->Image();
     }
-}
+
+}
\ No newline at end of file

Modified: trunk/jaws/html/gadgets/Policy/Model.php
===================================================================
--- trunk/jaws/html/gadgets/Policy/Model.php	2012-01-16 07:38:11 UTC (rev 12410)
+++ trunk/jaws/html/gadgets/Policy/Model.php	2012-01-16 07:38:46 UTC (rev 12411)
@@ -56,5 +56,74 @@
         return false;
     }
 
-}
-?>
+   /**
+     * Load and get captcha
+     *
+     * @access  public
+     * @param   string  $captcha
+     * @param   string  $entry
+     * @param   string  $description
+     * @return  boolean True if captcha loaded successfully
+     */
+    function LoadCaptcha(&$captcha, &$entry, &$description)
+    {
+        $status = $GLOBALS['app']->Registry->Get('/gadgets/Policy/captcha');
+        if (($status == 'DISABLED') ||
+            ($status == 'ANONYMOUS' && $GLOBALS['app']->Session->Logged())) {
+            return false;
+        }
+
+        static $objCaptcha;
+        if (!isset($objCaptcha)) {
+            $objCaptcha = array();
+        }
+
+        $dCaptcha = $GLOBALS['app']->Registry->Get('/gadgets/Policy/captcha_driver');
+        if (!isset($objCaptcha[$dCaptcha])) {
+            require_once JAWS_PATH . 'gadgets/Policy/captchas/' . $dCaptcha . '.php';
+            $objCaptcha[$dCaptcha] = new $dCaptcha();
+        }
+
+        $resCaptcha = $objCaptcha[$dCaptcha]->Get();
+        $captcha = $resCaptcha['captcha']->Get();
+        $entry   = $resCaptcha['entry']->Get();
+        $description = $resCaptcha['description'];
+
+        return true;
+    }
+
+   /**
+     * Load and get captcha
+     *
+     * @access  public
+     * @return  boolean True if captcha loaded successfully
+     */
+    function CheckCaptcha()
+    {
+        $status = $GLOBALS['app']->Registry->Get('/gadgets/Policy/captcha');
+        if (($status == 'DISABLED') ||
+            ($status == 'ANONYMOUS' && $GLOBALS['app']->Session->Logged())) {
+            return true;
+        }
+
+        static $objCaptcha;
+        if (!isset($objCaptcha)) {
+            $objCaptcha = array();
+        }
+
+        $dCaptcha = $GLOBALS['app']->Registry->Get('/gadgets/Policy/captcha_driver');
+        if (!isset($objCaptcha[$dCaptcha])) {
+            require_once JAWS_PATH . 'gadgets/Policy/captchas/' . $dCaptcha . '.php';
+            $objCaptcha[$dCaptcha] = new $dCaptcha();
+        }
+
+        if (!$objCaptcha[$dCaptcha]->Check()) {
+            return Jaws_Error::raiseError(_t('GLOBAL_CAPTCHA_ERROR_DOES_NOT_MATCH'),
+                                          'Jaws_Captcha',
+                                          JAWS_ERROR_ERROR);
+        }
+
+        return true;
+    }
+
+}
\ No newline at end of file



More information about the Jaws-commits mailing list