[Jaws-commits] r12421 - trunk/jaws/html/gadgets/Phoo

afz at jaws-project.com afz at jaws-project.com
Mon Jan 16 09:35:02 UTC 2012


Author: afz
Date: 2012-01-16 09:35:02 +0000 (Mon, 16 Jan 2012)
New Revision: 12421

Modified:
   trunk/jaws/html/gadgets/Phoo/Actions.php
   trunk/jaws/html/gadgets/Phoo/HTML.php
Log:
[Blog]: compatible using captcha with new changes in Policy gadget

Modified: trunk/jaws/html/gadgets/Phoo/Actions.php
===================================================================
--- trunk/jaws/html/gadgets/Phoo/Actions.php	2012-01-16 09:34:12 UTC (rev 12420)
+++ trunk/jaws/html/gadgets/Phoo/Actions.php	2012-01-16 09:35:02 UTC (rev 12421)
@@ -20,9 +20,6 @@
 $actions['Preview']           = array('NormalAction');
 $actions['SaveComment']       = array('NormalAction');
 
-/* StandaloneActions */
-$actions['Captcha']          = array('StandaloneAction');
-
 /* LayoutActions */
 $actions['Random']         = array('LayoutAction', _t('PHOO_RANDOM_IMAGE'), _t('PHOO_RANDOM_IMAGE_DESC'));
 $actions['Moblog']         = array('LayoutAction', _t('PHOO_MOBLOG'), _t('PHOO_MOBLOG_DESC'));

Modified: trunk/jaws/html/gadgets/Phoo/HTML.php
===================================================================
--- trunk/jaws/html/gadgets/Phoo/HTML.php	2012-01-16 09:34:12 UTC (rev 12420)
+++ trunk/jaws/html/gadgets/Phoo/HTML.php	2012-01-16 09:35:02 UTC (rev 12421)
@@ -657,22 +657,18 @@
             $tpl->SetVariable('url',  _t('GLOBAL_URL'));
             $tpl->SetVariable('url_value', $visitorUrl);
             $tpl->ParseBlock('commentform/unregistered');
+        }
 
-            $GLOBALS['app']->Registry->LoadFile('Policy');
-            $_captcha = $GLOBALS['app']->Registry->Get('/gadgets/Policy/captcha');
-            if ($_captcha != 'DISABLED') {
-                require_once JAWS_PATH . 'gadgets/Policy/captchas/' . $_captcha . '.php';
-                $captcha = new $_captcha();
-                $captchaRes = $captcha->Get();
-                $tpl->SetBlock('commentform/captcha');
-                $tpl->SetVariable('lbl_captcha', _t('GLOBAL_CAPTCHA_CODE'));
-                $tpl->SetVariable('captcha', $captchaRes['captcha']->Get());
-                if (!empty($captchaRes['entry'])) {
-                    $tpl->SetVariable('captchavalue', $captchaRes['entry']->Get());
-                }
-                $tpl->SetVariable('captcha_msg', _t('GLOBAL_CAPTCHA_CODE_DESC'));
-                $tpl->ParseBlock('commentform/captcha');
+        $mPolicy = $GLOBALS['app']->LoadGadget('Policy', 'Model');
+        if ($mPolicy->LoadCaptcha($captcha, $entry, $description)) {
+            $tpl->SetBlock('commentform/captcha');
+            $tpl->SetVariable('lbl_captcha', _t('GLOBAL_CAPTCHA_CODE'));
+            $tpl->SetVariable('captcha', $captcha);
+            if (!empty($entry)) {
+                $tpl->SetVariable('captchavalue', $entry);
             }
+            $tpl->SetVariable('captcha_msg', $description);
+            $tpl->ParseBlock('commentform/captcha');
         }
 
         if (!is_null($post['title'])) {
@@ -811,7 +807,7 @@
         $request =& Jaws_Request::getInstance();
         $names = array(
             'name', 'email', 'url', 'title', 'comments', 'createtime',
-            'ip_address', 'parent_id', 'parent', 'captcha', 'captchaKey', 'url2', 'albumid',
+            'ip_address', 'parent_id', 'parent', 'url2', 'albumid',
         );
         $post = $request->get($names, 'post');
         $post['parent_id'] = (int)$post['parent_id'];
@@ -851,18 +847,12 @@
             Jaws_Header::Location($url);
         }
 
-        if (!$GLOBALS['app']->Session->Logged()) {
-            $GLOBALS['app']->Registry->LoadFile('Policy');
-            $_captcha = $GLOBALS['app']->Registry->Get('/gadgets/Policy/captcha');
-            if ($_captcha != 'DISABLED') {
-                require_once JAWS_PATH . 'gadgets/Policy/captchas/' . $_captcha . '.php';
-                $captcha = new $_captcha();
-                if (!$captcha->Check()) {
-                    $GLOBALS['app']->Session->PushSimpleResponse(_t('GLOBAL_CAPTCHA_ERROR_DOES_NOT_MATCH'), 'Phoo');
-                    $GLOBALS['app']->Session->PushSimpleResponse($post, 'Phoo_Comment');
-                    Jaws_Header::Location($url);
-                }
-            }
+        $mPolicy = $GLOBALS['app']->LoadGadget('Policy', 'Model');
+        $resCheck = $mPolicy->CheckCaptcha();
+        if (Jaws_Error::IsError($resCheck)) {
+            $GLOBALS['app']->Session->PushSimpleResponse($resCheck->getMessage(), 'Phoo');
+            $GLOBALS['app']->Session->PushSimpleResponse($post, 'Phoo_Comment');
+            Jaws_Header::Location($url);
         }
 
         $result = $model->NewComment($post['name'], $post['title'], $post['url'],
@@ -889,32 +879,6 @@
     }
 
     /**
-     * Generate captcha image
-     *
-     * @access  public
-     * @return  binary  An image
-     */
-    function Captcha()
-    {
-        if (
-            $GLOBALS['app']->Registry->Get('/gadgets/Policy/allow_captchas') == 'yes' &&
-            $GLOBALS['app']->Registry->Get('/gadgets/Phoo/use_antispam') == 'true'
-        ) {
-            $request =& Jaws_Request::getInstance();
-            $key = $request->get('key', 'get');
-
-            require_once JAWS_PATH . 'include/Jaws/Captcha.php';
-            $md5 = !is_null($key) ? $key : '';
-            $jawsCaptchas =& JawsCaptcha::factory('Image');
-            $image = $jawsCaptchas->Build($md5);
-
-            return $image;
-        }
-
-        return '';
-    }
-
-    /**
      * Resize an image on the fly
      * FIXME: I don't know if is better to get it as a standalone function...
      * @returns binary Image resized
@@ -927,4 +891,5 @@
         include_once JAWS_PATH . 'include/Jaws/Image.php';
         Jaws_Image::get_exif_thumbnail(JAWS_DATA . 'phoo/import/' . $image, 'gadgets/Phoo/images/Phoo.png');
     }
-}
+
+}
\ No newline at end of file



More information about the Jaws-commits mailing list