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 - 2009 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_BASE'or die;
  11.  
  12. /**
  13.  * Form Field class for the Joomla Framework.
  14.  *
  15.  * @package     Joomla.Libraries
  16.  * @subpackage  Form
  17.  * @since       2.5
  18.  */
  19. class JFormFieldCaptcha extends JFormField
  20. {
  21.     /**
  22.      * The field type.
  23.      *
  24.      * @var        string 
  25.      */
  26.     protected $type = 'Captcha';
  27.  
  28.     /**
  29.      * Method to get certain otherwise inaccessible properties from the form field object.
  30.      *
  31.      * @param   string  $name  The property name for which to the the value.
  32.      *
  33.      * @return  mixed  The property value or null.
  34.      *
  35.      * @since   3.2
  36.      */
  37.     public function __get($name)
  38.     {
  39.         switch ($name)
  40.         {
  41.             case 'plugin':
  42.             case 'namespace':
  43.                 return $this->$name;
  44.         }
  45.  
  46.         return parent::__get($name);
  47.     }
  48.  
  49.     /**
  50.      * Method to set certain otherwise inaccessible properties of the form field object.
  51.      *
  52.      * @param   string  $name   The property name for which to the the value.
  53.      * @param   mixed   $value  The value of the property.
  54.      *
  55.      * @return  void 
  56.      *
  57.      * @since   3.2
  58.      */
  59.     public function __set($name$value)
  60.     {
  61.         switch ($name)
  62.         {
  63.             case 'plugin':
  64.             case 'namespace':
  65.                 $this->$name = (string) $value;
  66.                 break;
  67.  
  68.             default:
  69.                 parent::__set($name$value);
  70.         }
  71.     }
  72.  
  73.     /**
  74.      * Method to attach a JForm object to the field.
  75.      *
  76.      * @param   SimpleXMLElement  $element  The SimpleXMLElement object representing the <field /> tag for the form field object.
  77.      * @param   mixed             $value    The form field value to validate.
  78.      * @param   string            $group    The field name group control value. This acts as as an array container for the field.
  79.      *                                       For example if the field has name="foo" and the group value is set to "bar" then the
  80.      *                                       full field name would end up being "bar[foo]".
  81.      *
  82.      * @return  boolean  True on success.
  83.      *
  84.      * @since   2.5
  85.      */
  86.     public function setup(SimpleXMLElement $element$value$group null)
  87.     {
  88.         $result parent::setup($element$value$group);
  89.  
  90.         $plugin $this->element['plugin'?
  91.             (string) $this->element['plugin':
  92.             JFactory::getApplication()->getParams()->get('captcha'JFactory::getConfig()->get('captcha'));
  93.  
  94.         $this->plugin $plugin;
  95.  
  96.         if ($plugin === || $plugin === '0' || $plugin === '' || $plugin === null)
  97.         {
  98.             $this->hidden = true;
  99.         }
  100.         else
  101.         {
  102.             // Force field to be required. There's no reason to have a captcha if it is not required.
  103.             // Obs: Don't put required="required" in the xml file, you just need to have validate="captcha"
  104.             $this->required = true;
  105.  
  106.             if (strpos($this->class'required'=== false)
  107.             {
  108.                 $this->class = $this->class . ' required';
  109.             }
  110.         }
  111.  
  112.         $this->namespace $this->element['namespace'? (string) $this->element['namespace'$this->form->getName();
  113.  
  114.         return $result;
  115.     }
  116.  
  117.     /**
  118.      * Method to get the field input.
  119.      *
  120.      * @return  string  The field input.
  121.      *
  122.      * @since   2.5
  123.      */
  124.     protected function getInput()
  125.     {
  126.         if ($this->hidden)
  127.         {
  128.             return '';
  129.         }
  130.         else
  131.         {
  132.             if (($captcha JCaptcha::getInstance($this->pluginarray('namespace' => $this->namespace))) == null)
  133.             {
  134.                 return '';
  135.             }
  136.         }
  137.  
  138.         return $captcha->display($this->name$this->id$this->class);
  139.     }
  140. }

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