PageRenderTime 24ms CodeModel.GetById 13ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/libraries/joomla/form/fields/file.php

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