Source for file captcha.php

Documentation is available at captcha.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Libraries
  4.  * @subpackage  Form
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. /**
  13.  * Form Rule class for the Joomla Framework.
  14.  *
  15.  * @package     Joomla.Libraries
  16.  * @subpackage  Form
  17.  * @since       2.5
  18.  */
  19. class JFormRuleCaptcha extends JFormRule
  20. {
  21.     /**
  22.      * Method to test if the Captcha is correct.
  23.      *
  24.      * @param   SimpleXMLElement  $element  The SimpleXMLElement object representing the <field /> tag for the form field object.
  25.      * @param   mixed             $value    The form field value to validate.
  26.      * @param   string            $group    The field name group control value. This acts as as an array container for the field.
  27.      *                                       For example if the field has name="foo" and the group value is set to "bar" then the
  28.      *                                       full field name would end up being "bar[foo]".
  29.      * @param   JRegistry         $input    An optional JRegistry object with the entire data set to validate against the entire form.
  30.      * @param   JForm             $form     The form object for which the field is being tested.
  31.      *
  32.      * @return  boolean  True if the value is valid, false otherwise.
  33.      *
  34.      * @since   2.5
  35.      */
  36.     public function test(SimpleXMLElement $element$value$group nullJRegistry $input nullJForm $form null)
  37.     {
  38.         $plugin    $element['plugin'?: JFactory::getApplication()->getParams()->get('captcha'JFactory::getConfig()->get('captcha'0));
  39.         $namespace $element['namespace'?: $form->getName();
  40.  
  41.         // Use 0 for none
  42.         if ($plugin === || $plugin === '0')
  43.         {
  44.             return true;
  45.         }
  46.         else
  47.         {
  48.             $captcha JCaptcha::getInstance($pluginarray('namespace' => (string) $namespace));
  49.         }
  50.  
  51.         // Test the value.
  52.         if (!$captcha->checkAnswer($value))
  53.         {
  54.             $error $captcha->getError();
  55.             if ($error instanceof Exception)
  56.             {
  57.                 return $error;
  58.             }
  59.             else
  60.             {
  61.                 return new JException($error);
  62.             }
  63.         }
  64.  
  65.         return true;
  66.     }
  67. }

Documentation generated on Tue, 19 Nov 2013 14:55:03 +0100 by phpDocumentor 1.4.3