- md5
- ecdc2c6fcd7b42ddaffba024f5e331aa
- sha1
- 881121d4248b9dc94a1a84222c5bf8c9eac79d29
- sha256
- 7cbf4d76ef8a1f5670d0f5abe0fb79b90a13c05b1af20804e59cbbc960160f74
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
<?php
/**
* @package Joomla.Platform
* @subpackage Input
*
* @copyright Copyright (C) 2005-2016 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Joomla! Input Base Class
*
* This is an abstracted input class used to manage retrieving data from the application environment.
*
* @since 11.1
*
* @property-read JInput $get
* @property-read JInput $post
* @property-read JInput $request
* @property-read JInput $server
* @property-read JInputFiles $files
* @property-read JInputCookie $cookie
*
* @method integer getInt() getInt($name, $default = null) Get a signed integer.
* @method integer getUint() getUint($name, $default = null) Get an unsigned integer.
* @method float getFloat() getFloat($name, $default = null) Get a floating-point number.
* @method boolean getBool() getBool($name, $default = null) Get a boolean.
* @method string getWord() getWord($name, $default = null)
* @method string getAlnum() getAlnum($name, $default = null)
* @method string getCmd() getCmd($name, $default = null)
* @method string getBase64() getBase64($name, $default = null)
* @method string getString() getString($name, $default = null)
* @method string getHtml() getHtml($name, $default = null)
* @method string getPath() getPath($name, $default = null)
* @method string getUsername() getUsername($name, $default = null)
*/
class JInput implements Serializable, Countable
{
/**
* Options array for the JInput instance.
*
* @var array
* @since 11.1
*/
protected $options = array();
/**
* Filter object to use.
*
* @var JFilterInput
* @since 11.1
*/
protected $filter = null;
/**
* Input data.
*
* @var array
* @since 11.1
*/
protected $data = array();
/**
* Input objects
*
* @var array
* @since 11.1
*/
protected $inputs = array();
/**
* Constructor.
*
* @param array $source Source data (Optional, default is $_REQUEST)
* @param array $options Array of configuration parameters (Optional)
*
* @since 11.1
*/
public function __construct($source = null, array $options = array())
{
if (isset($options['filter']))
{
$this->filter = $options['filter'];
}
else
{
$this->filter = JFilterInput::getInstance();
}
if (is_null($source))
{
$this->data = &$_REQUEST;
}
else
{
$this->data = $source;
}
// Set the options for the class.
$this->options = $options;
}
/**
* Magic method to get an input object
*
* @param mixed $name Name of the input object to retrieve.
*
* @return JInput The request input object
*
* @since 11.1
*/
public function __get($name)
{
if (isset($this->inputs[$name]))
{
return $this->inputs[$name];
}
$className = 'JInput' . ucfirst($name);
if (class_exists($className))
{
$this->inputs[$name] = new $className(null, $this->options);
return $this->inputs[$name];
}
$superGlobal = '_' . strtoupper($name);
if (isset($GLOBALS[$superGlobal]))
{
$this->inputs[$name] = new JInput($GLOBALS[$superGlobal], $this->options);
return $this->inputs[$name];
}
// TODO throw an exception
}
/**
* Get the number of variables.
*
* @return integer The number of variables in the input.
*
* @since 12.2
* @see Countable::count()
*/
public function count()
{
return count($this->data);
}
/**
* Gets a value from the input data.
*
* @param string $name Name of the value to get.
* @param mixed $default Default value to return if variable does not exist.
* @param string $filter Filter to apply to the value.
*
* @return mixed The filtered input value.
*
* @since 11.1
*/
public function get($name, $default = null, $filter = 'cmd')
{
if (isset($this->data[$name]))
{
return $this->filter->clean($this->data[$name], $filter);
}
return $default;
}
/**
* Gets an array of values from the request.
*
* @param array $vars Associative array of keys and filter types to apply.
* If empty and datasource is null, all the input data will be returned
* but filtered using the default case in JFilterInput::clean.
* @param mixed $datasource Array to retrieve data from, or null
*
* @return mixed The filtered input data.
*
* @since 11.1
*/
public function getArray(array $vars = array(), $datasource = null)
{
if (empty($vars) && is_null($datasource))
{
$vars = $this->data;
}
$results = array();
foreach ($vars as $k => $v)
{
if (is_array($v))
{
if (is_null($datasource))
{
$results[$k] = $this->getArray($v, $this->get($k, null, 'array'));
}
else
{
$results[$k] = $this->getArray($v, $datasource[$k]);
}
}
else
{
if (is_null($datasource))
{
$results[$k] = $this->get($k, null, $v);
}
elseif (isset($datasource[$k]))
{
$results[$k] = $this->filter->clean($datasource[$k], $v);
}
else
{
$results[$k] = $this->filter->clean(null, $v);
}
}
}
return $results;
}
/**
* Sets a value
*
* @param string $name Name of the value to set.
* @param mixed $value Value to assign to the input.
*
* @return void
*
* @since 11.1
*/
public function set($name, $value)
{
$this->data[$name] = $value;
}
/**
* Define a value. The value will only be set if there's no value for the name or if it is null.
*
* @param string $name Name of the value to define.
* @param mixed $value Value to assign to the input.
*
* @return void
*
* @since 12.1
*/
public function def($name, $value)
{
if (isset($this->data[$name]))
{
return;
}
$this->data[$name] = $value;
}
/**
* Magic method to get filtered input data.
*
* @param string $name Name of the filter type prefixed with 'get'.
* @param array $arguments [0] The name of the variable [1] The default value.
*
* @return mixed The filtered input value.
*
* @since 11.1
*/
public function __call($name, $arguments)
{
if (substr($name, 0, 3) == 'get')
{
$filter = substr($name, 3);
$default = null;
if (isset($arguments[1]))
{
$default = $arguments[1];
}
return $this->get($arguments[0], $default, $filter);
}
}
/**
* Gets the request method.
*
* @return string The request method.
*
* @since 11.1
*/
public function getMethod()
{
$method = strtoupper($_SERVER['REQUEST_METHOD']);
return $method;
}
/**
* Method to serialize the input.
*
* @return string The serialized input.
*
* @since 12.1
*/
public function serialize()
{
// Load all of the inputs.
$this->loadAllInputs();
// Remove $_ENV and $_SERVER from the inputs.
$inputs = $this->inputs;
unset($inputs['env']);
unset($inputs['server']);
// Serialize the options, data, and inputs.
return serialize(array($this->options, $this->data, $inputs));
}
/**
* Method to unserialize the input.
*
* @param string $input The serialized input.
*
* @return JInput The input object.
*
* @since 12.1
*/
public function unserialize($input)
{
// Unserialize the options, data, and inputs.
list($this->options, $this->data, $this->inputs) = unserialize($input);
// Load the filter.
if (isset($this->options['filter']))
{
$this->filter = $this->options['filter'];
}
else
{
$this->filter = JFilterInput::getInstance();
}
}
/**
* Method to load all of the global inputs.
*
* @return void
*
* @since 12.1
*/
protected function loadAllInputs()
{
static $loaded = false;
if (!$loaded)
{
// Load up all the globals.
foreach ($GLOBALS as $global => $data)
{
// Check if the global starts with an underscore.
if (strpos($global, '_') === 0)
{
// Convert global name to input name.
$global = strtolower($global);
$global = substr($global, 1);
// Get the input.
$this->$global;
}
}
$loaded = true;
}
}
}
The same content is in 126 releases, Joomla 3.6.3-rc1 to 3.10.0-alpha1. See them all, or every version of this file.