Source for file file.php

Documentation is available at file.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Platform
  4.  * @subpackage  Form
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. /**
  13.  * Form Field class for the Joomla Platform.
  14.  * Provides an input field for files
  15.  *
  16.  * @package     Joomla.Platform
  17.  * @subpackage  Form
  18.  * @link        http://www.w3.org/TR/html-markup/input.file.html#input.file
  19.  * @since       11.1
  20.  */
  21. class JFormFieldFile extends JFormField
  22. {
  23.     /**
  24.      * The form field type.
  25.      *
  26.      * @var    string 
  27.      * @since  11.1
  28.      */
  29.     protected $type = 'File';
  30.  
  31.     /**
  32.      * The accepted file type list.
  33.      *
  34.      * @var    mixed 
  35.      * @since  3.2
  36.      */
  37.     protected $accept;
  38.  
  39.     /**
  40.      * Method to get certain otherwise inaccessible properties from the form field object.
  41.      *
  42.      * @param   string  $name  The property name for which to the the value.
  43.      *
  44.      * @return  mixed  The property value or null.
  45.      *
  46.      * @since   3.2
  47.      */
  48.     public function __get($name)
  49.     {
  50.         switch ($name)
  51.         {
  52.             case 'accept':
  53.                 return $this->$name;
  54.         }
  55.  
  56.         return parent::__get($name);
  57.     }
  58.  
  59.     /**
  60.      * Method to set certain otherwise inaccessible properties of the form field object.
  61.      *
  62.      * @param   string  $name   The property name for which to the the value.
  63.      * @param   mixed   $value  The value of the property.
  64.      *
  65.      * @return  void 
  66.      *
  67.      * @since   3.2
  68.      */
  69.     public function __set($name$value)
  70.     {
  71.         switch ($name)
  72.         {
  73.             case 'accept':
  74.                 $this->$accept = (string) $value;
  75.                 break;
  76.  
  77.             default:
  78.                 parent::__set($name$value);
  79.         }
  80.     }
  81.  
  82.     /**
  83.      * Method to attach a JForm object to the field.
  84.      *
  85.      * @param   SimpleXMLElement  $element  The SimpleXMLElement object representing the <field /> tag for the form field object.
  86.      * @param   mixed             $value    The form field value to validate.
  87.      * @param   string            $group    The field name group control value. This acts as as an array container for the field.
  88.      *                                       For example if the field has name="foo" and the group value is set to "bar" then the
  89.      *                                       full field name would end up being "bar[foo]".
  90.      *
  91.      * @return  boolean  True on success.
  92.      *
  93.      * @see     JFormField::setup()
  94.      * @since   3.2
  95.      */
  96.     public function setup(SimpleXMLElement $element$value$group null)
  97.     {
  98.         $return parent::setup($element$value$group);
  99.  
  100.         if ($return)
  101.         {
  102.             $this->accept = (string) $this->element['accept'];
  103.         }
  104.  
  105.         return $return;
  106.     }
  107.  
  108.     /**
  109.      * Method to get the field input markup for the file field.
  110.      * Field attributes allow specification of a maximum file size and a string
  111.      * of accepted file extensions.
  112.      *
  113.      * @return  string  The field input markup.
  114.      *
  115.      * @note    The field does not include an upload mechanism.
  116.      * @see     JFormFieldMedia
  117.      * @since   11.1
  118.      */
  119.     protected function getInput()
  120.     {
  121.         // Initialize some field attributes.
  122.         $accept    !empty($this->accept' accept="' $this->accept . '"' '';
  123.         $size      !empty($this->size' size="' $this->size . '"' '';
  124.         $class     !empty($this->class' class="' $this->class . '"' '';
  125.         $disabled  $this->disabled ? ' disabled' '';
  126.         $required  $this->required ? ' required aria-required="true"' '';
  127.         $autofocus $this->autofocus ? ' autofocus' '';
  128.         $multiple  $this->multiple ? ' multiple' '';
  129.  
  130.         // Initialize JavaScript field attributes.
  131.         $onchange $this->onchange ? ' onchange="' $this->onchange . '"' '';
  132.  
  133.         // Including fallback code for HTML5 non supported browsers.
  134.         JHtml::_('jquery.framework');
  135.         JHtml::_('script''system/html5fallback.js'falsetrue);
  136.  
  137.         return '<input type="file" name="' $this->name . '" id="' $this->id . '" value=""' $accept
  138.             . $disabled $class $size $onchange $required $autofocus $multiple ' />';
  139.     }
  140. }

Documentation generated on Tue, 19 Nov 2013 15:03:09 +0100 by phpDocumentor 1.4.3