filter = $options['filter']; } else { $this->filter = new JInputFilter; } if (is_null($source)) { $this->data = &$_REQUEST; } else { $this->data = &$source; } $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. */ public function __get($name) { // always use UPPERCASE notation $name = strtoupper($name); // check if the input has been already loaded if (isset($this->inputs[$name])) { return $this->inputs[$name]; } $className = 'JInput' . ucfirst($name); // otherwise try to load the file and check if the class handler exists if (JLoader::import('adapter.input.classes.' . strtolower($name)) && class_exists($className)) { $this->inputs[$name] = new $className(null, $this->options); return $this->inputs[$name]; } // otherwise check for an existing superglobal $superGlobal = '_' . $name; /** * Make sure the superglobal is allowed before accessing it. * * @since 10.1.24 */ if (in_array($name, static::$allowedGlobals, true) && isset($GLOBALS[$superGlobal])) { $this->inputs[$name] = new JInput($GLOBALS[$superGlobal], $this->options); return $this->inputs[$name]; } throw new Exception('The input handler [' . $name . '] does not exist', 404); } /** * 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. * * @uses get() */ public function __call($name, $arguments) { if (substr($name, 0, 3) == 'get') { $filter = substr($name, 3); return $this->get($arguments[0], isset($arguments[1]) ? $arguments[1] : null, $filter); } throw new Exception('Call to undefined method ' . __CLASS__ . '::' . $name . '()', 404); } /** * Get the number of variables. * * @return integer The number of variables in the input. */ 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. */ public function get($name, $default = null, $filter = 'cmd') { if (isset($this->data[$name])) { return $this->filter->clean($this->data[$name], $filter); } else if ($name == 'Itemid') { return (int) url_to_postid(JUri::current()); } return $default; } /** * Gets the original array of values from the request. * * @return array The values array. */ public function getArray() { return $this->data; } /** * Sets a value into the input data. * * @param string $name Name of the value to set. * @param mixed $value Value to assign to the input. * * @return void */ public function set($name, $value) { if ($value !== null) { $this->data[$name] = $value; } else { /** * Delete argument directly when value is NULL. * * @since 10.1.24 */ $this->delete($name); } } /** * Defines 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 * * @uses exists() * @uses set() */ public function def($name, $value) { if (!$this->exists($name)) { $this->set($name, $value); } } /** * Deletes a value from the input data, if any. * * NOTE: this method is not available in Joomla! * * @param string $name Name of the value to unset. * * @return void * * @uses exists() * * @since 10.1.24 */ public function delete($name) { if ($this->exists($name)) { unset($this->data[$name]); } } /** * Checks if a value name exists. * * @param string $name The value name. * * @return boolean */ public function exists($name) { return isset($this->data[$name]); } }