primo commit
This commit is contained in:
319
libraries/f0f/input/input.php
Normal file
319
libraries/f0f/input/input.php
Normal file
@ -0,0 +1,319 @@
|
||||
<?php
|
||||
/**
|
||||
* @package FrameworkOnFramework
|
||||
* @subpackage input
|
||||
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
// Protect from unauthorized access
|
||||
defined('F0F_INCLUDED') or die;
|
||||
|
||||
if (version_compare(JVERSION, '1.7.0', 'lt'))
|
||||
{
|
||||
jimport('joomla.filter.input');
|
||||
jimport('joomla.filter.filterinput');
|
||||
jimport('joomla.base.object');
|
||||
|
||||
require_once __DIR__ . '/jinput/input.php';
|
||||
require_once __DIR__ . '/jinput/cli.php';
|
||||
require_once __DIR__ . '/jinput/cookie.php';
|
||||
require_once __DIR__ . '/jinput/files.php';
|
||||
require_once __DIR__ . '/jinput/json.php';
|
||||
}
|
||||
elseif (version_compare(JVERSION, '2.5.0', 'lt'))
|
||||
{
|
||||
jimport('joomla.application.input');
|
||||
jimport('joomla.input.input');
|
||||
}
|
||||
|
||||
/**
|
||||
* FrameworkOnFramework input handling class. Extends upon the JInput class.
|
||||
*
|
||||
* @package FrameworkOnFramework
|
||||
* @since 2.0
|
||||
*/
|
||||
class F0FInput extends JInput
|
||||
{
|
||||
/**
|
||||
* Public constructor. Overriden to allow specifying the global input array
|
||||
* to use as a string and instantiate from an objetc holding variables.
|
||||
*
|
||||
* @param array|string|object|null $source Source data; set null to use $_REQUEST
|
||||
* @param array $options Filter options
|
||||
*/
|
||||
public function __construct($source = null, array $options = array())
|
||||
{
|
||||
$hash = null;
|
||||
|
||||
if (is_string($source))
|
||||
{
|
||||
$hash = strtoupper($source);
|
||||
|
||||
switch ($hash)
|
||||
{
|
||||
case 'GET':
|
||||
$source = $_GET;
|
||||
break;
|
||||
case 'POST':
|
||||
$source = $_POST;
|
||||
break;
|
||||
case 'FILES':
|
||||
$source = $_FILES;
|
||||
break;
|
||||
case 'COOKIE':
|
||||
$source = $_COOKIE;
|
||||
break;
|
||||
case 'ENV':
|
||||
$source = $_ENV;
|
||||
break;
|
||||
case 'SERVER':
|
||||
$source = $_SERVER;
|
||||
break;
|
||||
default:
|
||||
$source = $_REQUEST;
|
||||
$hash = 'REQUEST';
|
||||
break;
|
||||
}
|
||||
}
|
||||
elseif (is_object($source))
|
||||
{
|
||||
try
|
||||
{
|
||||
$source = (array) $source;
|
||||
}
|
||||
catch (Exception $exc)
|
||||
{
|
||||
$source = null;
|
||||
}
|
||||
}
|
||||
elseif (is_array($source))
|
||||
{
|
||||
// Nothing, it's already an array
|
||||
}
|
||||
else
|
||||
{
|
||||
// Any other case
|
||||
$source = $_REQUEST;
|
||||
$hash = 'REQUEST';
|
||||
}
|
||||
|
||||
// Magic quotes GPC handling (something JInput simply can't handle at all)
|
||||
|
||||
if (($hash == 'REQUEST') && get_magic_quotes_gpc() && class_exists('JRequest', true))
|
||||
{
|
||||
$source = JRequest::get('REQUEST', 2);
|
||||
}
|
||||
|
||||
parent::__construct($source, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a value from the input data. Overriden to allow specifying a filter
|
||||
* mask.
|
||||
*
|
||||
* @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.
|
||||
* @param int $mask The filter mask
|
||||
*
|
||||
* @return mixed The filtered input value.
|
||||
*/
|
||||
public function get($name, $default = null, $filter = 'cmd', $mask = 0)
|
||||
{
|
||||
if (isset($this->data[$name]))
|
||||
{
|
||||
return $this->_cleanVar($this->data[$name], $mask, $filter);
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a copy of the raw data stored in the class
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getData()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Old static methods are now deprecated. This magic method makes sure there
|
||||
* is a continuity in our approach. The downside is that it's only compatible
|
||||
* with PHP 5.3.0. Sorry!
|
||||
*
|
||||
* @param string $name Name of the method we're calling
|
||||
* @param array $arguments The arguments passed to the method
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function __callStatic($name, $arguments)
|
||||
{
|
||||
F0FPlatform::getInstance()->logDeprecated('F0FInput: static getXXX() methods are deprecated. Use the input object\'s methods instead.');
|
||||
|
||||
if (substr($name, 0, 3) == 'get')
|
||||
{
|
||||
// Initialise arguments
|
||||
$key = array_shift($arguments);
|
||||
$default = array_shift($arguments);
|
||||
$input = array_shift($arguments);
|
||||
$type = 'none';
|
||||
$mask = 0;
|
||||
|
||||
$type = strtolower(substr($name, 3));
|
||||
|
||||
if ($type == 'var')
|
||||
{
|
||||
$type = array_shift($arguments);
|
||||
$mask = array_shift($arguments);
|
||||
}
|
||||
|
||||
if (is_null($type))
|
||||
{
|
||||
$type = 'none';
|
||||
}
|
||||
|
||||
if (is_null($mask))
|
||||
{
|
||||
$mask = 0;
|
||||
}
|
||||
|
||||
if (!($input instanceof F0FInput) && !($input instanceof JInput))
|
||||
{
|
||||
$input = new F0FInput($input);
|
||||
}
|
||||
|
||||
return $input->get($key, $default, $type, $mask);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic method to get filtered input data.
|
||||
*
|
||||
* @param mixed $name Name of the value to get.
|
||||
* @param string $arguments Default value to return if variable does not exist.
|
||||
*
|
||||
* @return boolean The filtered boolean input value.
|
||||
*/
|
||||
public function __call($name, $arguments)
|
||||
{
|
||||
if (substr($name, 0, 3) == 'get')
|
||||
{
|
||||
$filter = substr($name, 3);
|
||||
|
||||
$default = null;
|
||||
$mask = 0;
|
||||
|
||||
if (isset($arguments[1]))
|
||||
{
|
||||
$default = $arguments[1];
|
||||
}
|
||||
|
||||
if (isset($arguments[2]))
|
||||
{
|
||||
$mask = $arguments[2];
|
||||
}
|
||||
|
||||
return $this->get($arguments[0], $default, $filter, $mask);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an input variable. WARNING: IT SHOULD NO LONGER BE USED!
|
||||
*
|
||||
* @param string $name The name of the variable to set
|
||||
* @param mixed $value The value to set it to
|
||||
* @param array &$input The input array or F0FInput object
|
||||
* @param boolean $overwrite Should I overwrite existing values (default: true)
|
||||
*
|
||||
* @return string Previous value
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
public static function setVar($name, $value = null, &$input = array(), $overwrite = true)
|
||||
{
|
||||
F0FPlatform::getInstance()->logDeprecated('F0FInput::setVar() is deprecated. Use set() instead.');
|
||||
|
||||
if (empty($input))
|
||||
{
|
||||
return JRequest::setVar($name, $value, 'default', $overwrite);
|
||||
}
|
||||
elseif (is_string($input))
|
||||
{
|
||||
return JRequest::setVar($name, $value, $input, $overwrite);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!$overwrite && array_key_exists($name, $input))
|
||||
{
|
||||
return $input[$name];
|
||||
}
|
||||
|
||||
$previous = array_key_exists($name, $input) ? $input[$name] : null;
|
||||
|
||||
if (is_array($input))
|
||||
{
|
||||
$input[$name] = $value;
|
||||
}
|
||||
elseif ($input instanceof F0FInput)
|
||||
{
|
||||
$input->set($name, $value);
|
||||
}
|
||||
|
||||
return $previous;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom filter implementation. Works better with arrays and allows the use
|
||||
* of a filter mask.
|
||||
*
|
||||
* @param mixed $var The variable (value) to clean
|
||||
* @param integer $mask The clean mask
|
||||
* @param string $type The variable type
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function _cleanVar($var, $mask = 0, $type = null)
|
||||
{
|
||||
if (is_array($var))
|
||||
{
|
||||
$temp = array();
|
||||
|
||||
foreach ($var as $k => $v)
|
||||
{
|
||||
$temp[$k] = self::_cleanVar($v, $mask);
|
||||
}
|
||||
|
||||
return $temp;
|
||||
}
|
||||
|
||||
// If the no trim flag is not set, trim the variable
|
||||
if (!($mask & 1) && is_string($var))
|
||||
{
|
||||
$var = trim($var);
|
||||
}
|
||||
|
||||
// Now we handle input filtering
|
||||
if ($mask & 2)
|
||||
{
|
||||
// If the allow raw flag is set, do not modify the variable
|
||||
$var = $var;
|
||||
}
|
||||
elseif ($mask & 4)
|
||||
{
|
||||
// If the allow HTML flag is set, apply a safe HTML filter to the variable
|
||||
$safeHtmlFilter = JFilterInput::getInstance(null, null, 1, 1);
|
||||
$var = $safeHtmlFilter->clean($var, $type);
|
||||
}
|
||||
else
|
||||
{
|
||||
$var = $this->filter->clean($var, $type);
|
||||
}
|
||||
|
||||
return $var;
|
||||
}
|
||||
}
|
||||
200
libraries/f0f/input/jinput/cli.php
Normal file
200
libraries/f0f/input/jinput/cli.php
Normal file
@ -0,0 +1,200 @@
|
||||
<?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 CLI Class
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
class JInputCli extends JInput
|
||||
{
|
||||
/**
|
||||
* The executable that was called to run the CLI script.
|
||||
*
|
||||
* @var string
|
||||
* @since 11.1
|
||||
*/
|
||||
public $executable;
|
||||
|
||||
/**
|
||||
* The additional arguments passed to the script that are not associated
|
||||
* with a specific argument name.
|
||||
*
|
||||
* @var array
|
||||
* @since 11.1
|
||||
*/
|
||||
public $args = 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(array $source = null, array $options = array())
|
||||
{
|
||||
if (isset($options['filter']))
|
||||
{
|
||||
$this->filter = $options['filter'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->filter = JFilterInput::getInstance();
|
||||
}
|
||||
|
||||
// Get the command line options
|
||||
$this->parseArguments();
|
||||
|
||||
// Set the options for the class.
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 executable, args, options, data, and inputs.
|
||||
return serialize(array($this->executable, $this->args, $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 executable, args, options, data, and inputs.
|
||||
list($this->executable, $this->args, $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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise the options and arguments
|
||||
*
|
||||
* Not supported: -abc c-value
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
protected function parseArguments()
|
||||
{
|
||||
$argv = $_SERVER['argv'];
|
||||
|
||||
$this->executable = array_shift($argv);
|
||||
|
||||
$out = array();
|
||||
|
||||
for ($i = 0, $j = count($argv); $i < $j; $i++)
|
||||
{
|
||||
$arg = $argv[$i];
|
||||
|
||||
// --foo --bar=baz
|
||||
if (substr($arg, 0, 2) === '--')
|
||||
{
|
||||
$eqPos = strpos($arg, '=');
|
||||
|
||||
// --foo
|
||||
if ($eqPos === false)
|
||||
{
|
||||
$key = substr($arg, 2);
|
||||
|
||||
// --foo value
|
||||
if ($i + 1 < $j && $argv[$i + 1][0] !== '-')
|
||||
{
|
||||
$value = $argv[$i + 1];
|
||||
$i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
$value = isset($out[$key]) ? $out[$key] : true;
|
||||
}
|
||||
|
||||
$out[$key] = $value;
|
||||
}
|
||||
|
||||
// --bar=baz
|
||||
else
|
||||
{
|
||||
$key = substr($arg, 2, $eqPos - 2);
|
||||
$value = substr($arg, $eqPos + 1);
|
||||
$out[$key] = $value;
|
||||
}
|
||||
}
|
||||
elseif (substr($arg, 0, 1) === '-')
|
||||
// -k=value -abc
|
||||
{
|
||||
// -k=value
|
||||
if (substr($arg, 2, 1) === '=')
|
||||
{
|
||||
$key = substr($arg, 1, 1);
|
||||
$value = substr($arg, 3);
|
||||
$out[$key] = $value;
|
||||
}
|
||||
else
|
||||
// -abc
|
||||
{
|
||||
$chars = str_split(substr($arg, 1));
|
||||
|
||||
foreach ($chars as $char)
|
||||
{
|
||||
$key = $char;
|
||||
$value = isset($out[$key]) ? $out[$key] : true;
|
||||
$out[$key] = $value;
|
||||
}
|
||||
|
||||
// -a a-value
|
||||
if ((count($chars) === 1) && ($i + 1 < $j) && ($argv[$i + 1][0] !== '-'))
|
||||
{
|
||||
$out[$key] = $argv[$i + 1];
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Plain-arg
|
||||
$this->args[] = $arg;
|
||||
}
|
||||
}
|
||||
|
||||
$this->data = $out;
|
||||
}
|
||||
}
|
||||
89
libraries/f0f/input/jinput/cookie.php
Normal file
89
libraries/f0f/input/jinput/cookie.php
Normal file
@ -0,0 +1,89 @@
|
||||
<?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 Cookie Class
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
class JInputCookie extends JInput
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $source Ignored.
|
||||
* @param array $options Array of configuration parameters (Optional)
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function __construct(array $source = null, array $options = array())
|
||||
{
|
||||
if (isset($options['filter']))
|
||||
{
|
||||
$this->filter = $options['filter'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->filter = JFilterInput::getInstance();
|
||||
}
|
||||
|
||||
// Set the data source.
|
||||
$this->data = & $_COOKIE;
|
||||
|
||||
// Set the options for the class.
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a value
|
||||
*
|
||||
* @param string $name Name of the value to set.
|
||||
* @param mixed $value Value to assign to the input.
|
||||
* @param integer $expire The time the cookie expires. This is a Unix timestamp so is in number
|
||||
* of seconds since the epoch. In other words, you'll most likely set this
|
||||
* with the time() function plus the number of seconds before you want it
|
||||
* to expire. Or you might use mktime(). time()+60*60*24*30 will set the
|
||||
* cookie to expire in 30 days. If set to 0, or omitted, the cookie will
|
||||
* expire at the end of the session (when the browser closes).
|
||||
* @param string $path The path on the server in which the cookie will be available on. If set
|
||||
* to '/', the cookie will be available within the entire domain. If set to
|
||||
* '/foo/', the cookie will only be available within the /foo/ directory and
|
||||
* all sub-directories such as /foo/bar/ of domain. The default value is the
|
||||
* current directory that the cookie is being set in.
|
||||
* @param string $domain The domain that the cookie is available to. To make the cookie available
|
||||
* on all subdomains of example.com (including example.com itself) then you'd
|
||||
* set it to '.example.com'. Although some browsers will accept cookies without
|
||||
* the initial ., RFC 2109 requires it to be included. Setting the domain to
|
||||
* 'www.example.com' or '.www.example.com' will make the cookie only available
|
||||
* in the www subdomain.
|
||||
* @param boolean $secure Indicates that the cookie should only be transmitted over a secure HTTPS
|
||||
* connection from the client. When set to TRUE, the cookie will only be set
|
||||
* if a secure connection exists. On the server-side, it's on the programmer
|
||||
* to send this kind of cookie only on secure connection (e.g. with respect
|
||||
* to $_SERVER["HTTPS"]).
|
||||
* @param boolean $httpOnly When TRUE the cookie will be made accessible only through the HTTP protocol.
|
||||
* This means that the cookie won't be accessible by scripting languages, such
|
||||
* as JavaScript. This setting can effectively help to reduce identity theft
|
||||
* through XSS attacks (although it is not supported by all browsers).
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @link http://www.ietf.org/rfc/rfc2109.txt
|
||||
* @see setcookie()
|
||||
* @since 11.1
|
||||
*/
|
||||
public function set($name, $value, $expire = 0, $path = '', $domain = '', $secure = false, $httpOnly = false)
|
||||
{
|
||||
setcookie($name, $value, $expire, $path, $domain, $secure, $httpOnly);
|
||||
|
||||
$this->data[$name] = $value;
|
||||
}
|
||||
}
|
||||
136
libraries/f0f/input/jinput/files.php
Normal file
136
libraries/f0f/input/jinput/files.php
Normal file
@ -0,0 +1,136 @@
|
||||
<?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 Files Class
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
class JInputFiles extends JInput
|
||||
{
|
||||
/**
|
||||
* The pivoted data from a $_FILES or compatible array.
|
||||
*
|
||||
* @var array
|
||||
* @since 11.1
|
||||
*/
|
||||
protected $decodedData = array();
|
||||
|
||||
/**
|
||||
* The class constructor.
|
||||
*
|
||||
* @param array $source The source argument is ignored. $_FILES is always used.
|
||||
* @param array $options An optional array of configuration options:
|
||||
* filter : a custom JFilterInput object.
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
public function __construct(array $source = null, array $options = array())
|
||||
{
|
||||
if (isset($options['filter']))
|
||||
{
|
||||
$this->filter = $options['filter'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->filter = JFilterInput::getInstance();
|
||||
}
|
||||
|
||||
// Set the data source.
|
||||
$this->data = & $_FILES;
|
||||
|
||||
// Set the options for the class.
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a value from the input data.
|
||||
*
|
||||
* @param string $name The name of the input property (usually the name of the files INPUT tag) to get.
|
||||
* @param mixed $default The default value to return if the named property does not exist.
|
||||
* @param string $filter The filter to apply to the value.
|
||||
*
|
||||
* @return mixed The filtered input value.
|
||||
*
|
||||
* @see JFilterInput::clean()
|
||||
* @since 11.1
|
||||
*/
|
||||
public function get($name, $default = null, $filter = 'cmd')
|
||||
{
|
||||
if (isset($this->data[$name]))
|
||||
{
|
||||
$results = $this->decodeData(
|
||||
array(
|
||||
$this->data[$name]['name'],
|
||||
$this->data[$name]['type'],
|
||||
$this->data[$name]['tmp_name'],
|
||||
$this->data[$name]['error'],
|
||||
$this->data[$name]['size']
|
||||
)
|
||||
);
|
||||
|
||||
// Prevent returning an unsafe file unless speciffically requested
|
||||
if ($filter != 'raw')
|
||||
{
|
||||
$isSafe = JFilterInput::isSafeFile($results);
|
||||
|
||||
if (!$isSafe)
|
||||
{
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to decode a data array.
|
||||
*
|
||||
* @param array $data The data array to decode.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
protected function decodeData(array $data)
|
||||
{
|
||||
$result = array();
|
||||
|
||||
if (is_array($data[0]))
|
||||
{
|
||||
foreach ($data[0] as $k => $v)
|
||||
{
|
||||
$result[$k] = $this->decodeData(array($data[0][$k], $data[1][$k], $data[2][$k], $data[3][$k], $data[4][$k]));
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
return array('name' => $data[0], 'type' => $data[1], 'tmp_name' => $data[2], 'error' => $data[3], 'size' => $data[4]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a value.
|
||||
*
|
||||
* @param string $name The name of the input property to set.
|
||||
* @param mixed $value The value to assign to the input property.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function set($name, $value)
|
||||
{
|
||||
}
|
||||
}
|
||||
383
libraries/f0f/input/jinput/input.php
Normal file
383
libraries/f0f/input/jinput/input.php
Normal file
@ -0,0 +1,383 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
}
|
||||
72
libraries/f0f/input/jinput/json.php
Normal file
72
libraries/f0f/input/jinput/json.php
Normal file
@ -0,0 +1,72 @@
|
||||
<?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 JSON Class
|
||||
*
|
||||
* This class decodes a JSON string from the raw request data and makes it available via
|
||||
* the standard JInput interface.
|
||||
*
|
||||
* @since 12.2
|
||||
*/
|
||||
class JInputJSON extends JInput
|
||||
{
|
||||
/**
|
||||
* @var string The raw JSON string from the request.
|
||||
* @since 12.2
|
||||
*/
|
||||
private $_raw;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $source Source data (Optional, default is the raw HTTP input decoded from JSON)
|
||||
* @param array $options Array of configuration parameters (Optional)
|
||||
*
|
||||
* @since 12.2
|
||||
*/
|
||||
public function __construct(array $source = null, array $options = array())
|
||||
{
|
||||
if (isset($options['filter']))
|
||||
{
|
||||
$this->filter = $options['filter'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->filter = JFilterInput::getInstance();
|
||||
}
|
||||
|
||||
if (is_null($source))
|
||||
{
|
||||
$this->_raw = file_get_contents('php://input');
|
||||
$this->data = json_decode($this->_raw, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->data = & $source;
|
||||
}
|
||||
|
||||
// Set the options for the class.
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the raw JSON string from the request.
|
||||
*
|
||||
* @return string The raw JSON string from the request.
|
||||
*
|
||||
* @since 12.2
|
||||
*/
|
||||
public function getRaw()
|
||||
{
|
||||
return $this->_raw;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user