Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.0] Add removed Input classes to the compat plugin #44925

Open
wants to merge 9 commits into
base: 6.0-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 159 additions & 0 deletions plugins/behaviour/compat/classes/Input/Cookie.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
<?php

/**
* Joomla! Content Management System
*
* @copyright (C) 2011 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\CMS\Input;

use Joomla\CMS\Filter\InputFilter;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
* Joomla! Input Cookie Class
*
* @since 1.7.0
*
* @deprecated 4.3 will be removed in 6.0.
* Use Joomla\Input\Cookie instead
*/
class Cookie extends Input
{
/**
* Constructor.
*
* @param array $source Ignored.
* @param array $options Array of configuration parameters (Optional)
*
* @since 1.7.0
*
* @deprecated 4.3 will be removed in 6.0.
* Use Joomla\Input\Cookie instead
*/
public function __construct(?array $source = null, array $options = [])
{
if (isset($options['filter'])) {
$this->filter = $options['filter'];
} else {
$this->filter = InputFilter::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 array $options An associative array which may have any of the keys expires, path, domain,
* secure, httponly and samesite. The values have the same meaning as described
* for the parameters with the same name. The value of the samesite element
* should be either Lax or Strict. If any of the allowed options are not given,
* their default values are the same as the default values of the explicit
* parameters. If the samesite element is omitted, no SameSite cookie attribute
* is set.
*
* @return void
*
* @link http://www.ietf.org/rfc/rfc2109.txt
* @see setcookie()
* @since 1.7.0
*
* @deprecated 4.3 will be removed in 6.0.
* Use Joomla\Input\Cookie instead
*/
public function set($name, $value, $options = [])
{
// BC layer to convert old method parameters.
if (\is_array($options) === false) {
trigger_deprecation(
'joomla/input',
'1.4.0',
'The %s($name, $value, $expire, $path, $domain, $secure, $httpOnly) signature is deprecated and'
. ' will not be supported once support'
. ' for PHP 7.2 and earlier is dropped, use the %s($name, $value, $options) signature instead',
__METHOD__,
__METHOD__
);

$argList = \func_get_args();

$options = [
'expires' => $argList[2] ?? 0,
'path' => $argList[3] ?? '',
'domain' => $argList[4] ?? '',
'secure' => $argList[5] ?? false,
'httponly' => $argList[6] ?? false,
];
}

// Set the cookie
if (version_compare(PHP_VERSION, '7.3', '>=')) {
if (\is_array($value)) {
foreach ($value as $key => $val) {
setcookie($name . "[$key]", $val, $options);
}
} else {
setcookie($name, $value, $options);
}
} else {
// Using the setcookie function before php 7.3, make sure we have default values.
if (\array_key_exists('expires', $options) === false) {
$options['expires'] = 0;
}

if (\array_key_exists('path', $options) === false) {
$options['path'] = '';
}

if (\array_key_exists('domain', $options) === false) {
$options['domain'] = '';
}

if (\array_key_exists('secure', $options) === false) {
$options['secure'] = false;
}

if (\array_key_exists('httponly', $options) === false) {
$options['httponly'] = false;
}

if (\is_array($value)) {
foreach ($value as $key => $val) {
setcookie(
$name . "[$key]",
$val,
$options['expires'],
$options['path'],
$options['domain'],
$options['secure'],
$options['httponly']
);
}
} else {
setcookie(
$name,
$value,
$options['expires'],
$options['path'],
$options['domain'],
$options['secure'],
$options['httponly']
);
}
}

$this->data[$name] = $value;
}
}
152 changes: 152 additions & 0 deletions plugins/behaviour/compat/classes/Input/Files.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<?php

/**
* Joomla! Content Management System
*
* @copyright (C) 2011 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\CMS\Input;

use Joomla\CMS\Filter\InputFilter;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
* Joomla! Input Files Class
*
* @since 1.7.0
*
* @deprecated 4.3 will be removed in 6.0.
* Use Joomla\Input\Files instead
*/
class Files extends Input
{
/**
* The pivoted data from a $_FILES or compatible array.
*
* @var array
* @since 1.7.0
*
* @deprecated 4.3 will be removed in 6.0.
* Use Joomla\Input\Files instead
*/
protected $decodedData = [];

/**
* 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 InputFilter object.
*
* @since 3.0.0
*
* @deprecated 4.3 will be removed in 6.0.
* Use Joomla\Input\Files instead
*/
public function __construct(?array $source = null, array $options = [])
{
if (isset($options['filter'])) {
$this->filter = $options['filter'];
} else {
$this->filter = InputFilter::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 InputFilter::clean()
* @since 1.7.0
*
* @deprecated 4.3 will be removed in 6.0.
* Use Joomla\Input\Files instead
*/
public function get($name, $default = null, $filter = 'cmd')
{
if (isset($this->data[$name])) {
$results = $this->decodeData(
[
$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 specifically requested
if (strtoupper($filter) !== 'RAW') {
$isSafe = InputFilter::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 1.7.0
*
* @deprecated 4.3 will be removed in 6.0.
* Use Joomla\Input\Files instead
*/
protected function decodeData(array $data)
{
$result = [];

if (\is_array($data[0])) {
foreach ($data[0] as $k => $v) {
$result[$k] = $this->decodeData([$data[0][$k], $data[1][$k], $data[2][$k], $data[3][$k], $data[4][$k]]);
}

return $result;
}

return ['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 1.7.0
*
* @deprecated 4.3 will be removed in 6.0.
* Use Joomla\Input\Files instead
*/
public function set($name, $value)
{
}
}
Loading