Skip to content

Commit d2f8838

Browse files
authored
[6.0] Add removed Input classes to the compat plugin (#44925)
* Revert "[6.0] Removing CMS Input package (#42890)" This reverts commit 1be1415. * Move input classes to compatibility plugin * Update Compat.php * cs * more cs * Move back to libraries * move to if * path only ---------
1 parent 835330b commit d2f8838

File tree

5 files changed

+621
-3
lines changed

5 files changed

+621
-3
lines changed
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
<?php
2+
3+
/**
4+
* Joomla! Content Management System
5+
*
6+
* @copyright (C) 2011 Open Source Matters, Inc. <https://www.joomla.org>
7+
* @license GNU General Public License version 2 or later; see LICENSE.txt
8+
*/
9+
10+
namespace Joomla\CMS\Input;
11+
12+
use Joomla\CMS\Filter\InputFilter;
13+
14+
// phpcs:disable PSR1.Files.SideEffects
15+
\defined('_JEXEC') or die;
16+
// phpcs:enable PSR1.Files.SideEffects
17+
18+
/**
19+
* Joomla! Input Cookie Class
20+
*
21+
* @since 1.7.0
22+
*
23+
* @deprecated 4.3 will be removed in 6.0.
24+
* Use Joomla\Input\Cookie instead
25+
*/
26+
class Cookie extends Input
27+
{
28+
/**
29+
* Constructor.
30+
*
31+
* @param array $source Ignored.
32+
* @param array $options Array of configuration parameters (Optional)
33+
*
34+
* @since 1.7.0
35+
*
36+
* @deprecated 4.3 will be removed in 6.0.
37+
* Use Joomla\Input\Cookie instead
38+
*/
39+
public function __construct(?array $source = null, array $options = [])
40+
{
41+
if (isset($options['filter'])) {
42+
$this->filter = $options['filter'];
43+
} else {
44+
$this->filter = InputFilter::getInstance();
45+
}
46+
47+
// Set the data source.
48+
$this->data = &$_COOKIE;
49+
50+
// Set the options for the class.
51+
$this->options = $options;
52+
}
53+
54+
/**
55+
* Sets a value
56+
*
57+
* @param string $name Name of the value to set.
58+
* @param mixed $value Value to assign to the input.
59+
* @param array $options An associative array which may have any of the keys expires, path, domain,
60+
* secure, httponly and samesite. The values have the same meaning as described
61+
* for the parameters with the same name. The value of the samesite element
62+
* should be either Lax or Strict. If any of the allowed options are not given,
63+
* their default values are the same as the default values of the explicit
64+
* parameters. If the samesite element is omitted, no SameSite cookie attribute
65+
* is set.
66+
*
67+
* @return void
68+
*
69+
* @link http://www.ietf.org/rfc/rfc2109.txt
70+
* @see setcookie()
71+
* @since 1.7.0
72+
*
73+
* @deprecated 4.3 will be removed in 6.0.
74+
* Use Joomla\Input\Cookie instead
75+
*/
76+
public function set($name, $value, $options = [])
77+
{
78+
// BC layer to convert old method parameters.
79+
if (\is_array($options) === false) {
80+
trigger_deprecation(
81+
'joomla/input',
82+
'1.4.0',
83+
'The %s($name, $value, $expire, $path, $domain, $secure, $httpOnly) signature is deprecated and'
84+
. ' will not be supported once support'
85+
. ' for PHP 7.2 and earlier is dropped, use the %s($name, $value, $options) signature instead',
86+
__METHOD__,
87+
__METHOD__
88+
);
89+
90+
$argList = \func_get_args();
91+
92+
$options = [
93+
'expires' => $argList[2] ?? 0,
94+
'path' => $argList[3] ?? '',
95+
'domain' => $argList[4] ?? '',
96+
'secure' => $argList[5] ?? false,
97+
'httponly' => $argList[6] ?? false,
98+
];
99+
}
100+
101+
// Set the cookie
102+
if (version_compare(PHP_VERSION, '7.3', '>=')) {
103+
if (\is_array($value)) {
104+
foreach ($value as $key => $val) {
105+
setcookie($name . "[$key]", $val, $options);
106+
}
107+
} else {
108+
setcookie($name, $value, $options);
109+
}
110+
} else {
111+
// Using the setcookie function before php 7.3, make sure we have default values.
112+
if (\array_key_exists('expires', $options) === false) {
113+
$options['expires'] = 0;
114+
}
115+
116+
if (\array_key_exists('path', $options) === false) {
117+
$options['path'] = '';
118+
}
119+
120+
if (\array_key_exists('domain', $options) === false) {
121+
$options['domain'] = '';
122+
}
123+
124+
if (\array_key_exists('secure', $options) === false) {
125+
$options['secure'] = false;
126+
}
127+
128+
if (\array_key_exists('httponly', $options) === false) {
129+
$options['httponly'] = false;
130+
}
131+
132+
if (\is_array($value)) {
133+
foreach ($value as $key => $val) {
134+
setcookie(
135+
$name . "[$key]",
136+
$val,
137+
$options['expires'],
138+
$options['path'],
139+
$options['domain'],
140+
$options['secure'],
141+
$options['httponly']
142+
);
143+
}
144+
} else {
145+
setcookie(
146+
$name,
147+
$value,
148+
$options['expires'],
149+
$options['path'],
150+
$options['domain'],
151+
$options['secure'],
152+
$options['httponly']
153+
);
154+
}
155+
}
156+
157+
$this->data[$name] = $value;
158+
}
159+
}
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
<?php
2+
3+
/**
4+
* Joomla! Content Management System
5+
*
6+
* @copyright (C) 2011 Open Source Matters, Inc. <https://www.joomla.org>
7+
* @license GNU General Public License version 2 or later; see LICENSE.txt
8+
*/
9+
10+
namespace Joomla\CMS\Input;
11+
12+
use Joomla\CMS\Filter\InputFilter;
13+
14+
// phpcs:disable PSR1.Files.SideEffects
15+
\defined('_JEXEC') or die;
16+
// phpcs:enable PSR1.Files.SideEffects
17+
18+
/**
19+
* Joomla! Input Files Class
20+
*
21+
* @since 1.7.0
22+
*
23+
* @deprecated 4.3 will be removed in 6.0.
24+
* Use Joomla\Input\Files instead
25+
*/
26+
class Files extends Input
27+
{
28+
/**
29+
* The pivoted data from a $_FILES or compatible array.
30+
*
31+
* @var array
32+
* @since 1.7.0
33+
*
34+
* @deprecated 4.3 will be removed in 6.0.
35+
* Use Joomla\Input\Files instead
36+
*/
37+
protected $decodedData = [];
38+
39+
/**
40+
* The class constructor.
41+
*
42+
* @param array $source The source argument is ignored. $_FILES is always used.
43+
* @param array $options An optional array of configuration options:
44+
* filter : a custom InputFilter object.
45+
*
46+
* @since 3.0.0
47+
*
48+
* @deprecated 4.3 will be removed in 6.0.
49+
* Use Joomla\Input\Files instead
50+
*/
51+
public function __construct(?array $source = null, array $options = [])
52+
{
53+
if (isset($options['filter'])) {
54+
$this->filter = $options['filter'];
55+
} else {
56+
$this->filter = InputFilter::getInstance();
57+
}
58+
59+
// Set the data source.
60+
$this->data = &$_FILES;
61+
62+
// Set the options for the class.
63+
$this->options = $options;
64+
}
65+
66+
/**
67+
* Gets a value from the input data.
68+
*
69+
* @param string $name The name of the input property (usually the name of the files INPUT tag) to get.
70+
* @param mixed $default The default value to return if the named property does not exist.
71+
* @param string $filter The filter to apply to the value.
72+
*
73+
* @return mixed The filtered input value.
74+
*
75+
* @see InputFilter::clean()
76+
* @since 1.7.0
77+
*
78+
* @deprecated 4.3 will be removed in 6.0.
79+
* Use Joomla\Input\Files instead
80+
*/
81+
public function get($name, $default = null, $filter = 'cmd')
82+
{
83+
if (isset($this->data[$name])) {
84+
$results = $this->decodeData(
85+
[
86+
$this->data[$name]['name'],
87+
$this->data[$name]['type'],
88+
$this->data[$name]['tmp_name'],
89+
$this->data[$name]['error'],
90+
$this->data[$name]['size'],
91+
]
92+
);
93+
94+
// Prevent returning an unsafe file unless specifically requested
95+
if (strtoupper($filter) !== 'RAW') {
96+
$isSafe = InputFilter::isSafeFile($results);
97+
98+
if (!$isSafe) {
99+
return $default;
100+
}
101+
}
102+
103+
return $results;
104+
}
105+
106+
return $default;
107+
}
108+
109+
/**
110+
* Method to decode a data array.
111+
*
112+
* @param array $data The data array to decode.
113+
*
114+
* @return array
115+
*
116+
* @since 1.7.0
117+
*
118+
* @deprecated 4.3 will be removed in 6.0.
119+
* Use Joomla\Input\Files instead
120+
*/
121+
protected function decodeData(array $data)
122+
{
123+
$result = [];
124+
125+
if (\is_array($data[0])) {
126+
foreach ($data[0] as $k => $v) {
127+
$result[$k] = $this->decodeData([$data[0][$k], $data[1][$k], $data[2][$k], $data[3][$k], $data[4][$k]]);
128+
}
129+
130+
return $result;
131+
}
132+
133+
return ['name' => $data[0], 'type' => $data[1], 'tmp_name' => $data[2], 'error' => $data[3], 'size' => $data[4]];
134+
}
135+
136+
/**
137+
* Sets a value.
138+
*
139+
* @param string $name The name of the input property to set.
140+
* @param mixed $value The value to assign to the input property.
141+
*
142+
* @return void
143+
*
144+
* @since 1.7.0
145+
*
146+
* @deprecated 4.3 will be removed in 6.0.
147+
* Use Joomla\Input\Files instead
148+
*/
149+
public function set($name, $value)
150+
{
151+
}
152+
}

0 commit comments

Comments
 (0)