|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* inetprocess/transformation |
|
4
|
|
|
* |
|
5
|
|
|
* PHP Version 5.3 |
|
6
|
|
|
* |
|
7
|
|
|
* @author Rémi Sauvat |
|
8
|
|
|
* @copyright 2005-2015 iNet Process |
|
9
|
|
|
* |
|
10
|
|
|
* @package inetprocess/transformation |
|
11
|
|
|
* |
|
12
|
|
|
* @license GNU General Public License v2.0 |
|
13
|
|
|
* |
|
14
|
|
|
* @link http://www.inetprocess.com |
|
15
|
|
|
*/ |
|
16
|
|
|
|
|
17
|
|
|
namespace Inet\Transformation\Rule; |
|
18
|
|
|
|
|
19
|
|
|
use Inet\Transformation\Exception\TransformationException; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Call a function and send back the result |
|
23
|
|
|
*/ |
|
24
|
|
|
class Htmlspecialchars extends AbstractRule |
|
25
|
|
|
{ |
|
26
|
6 |
|
public function transform($input, array $arguments) |
|
27
|
|
|
{ |
|
28
|
|
|
// I should have two arguments: old format / new format |
|
29
|
6 |
|
if (count($arguments) > 3) { |
|
30
|
1 |
|
throw new TransformationException( |
|
31
|
|
|
'Rule Htmlspecialchars expects at most 3 arguments' |
|
32
|
1 |
|
); |
|
33
|
|
|
} |
|
34
|
5 |
|
if (isset($arguments[0])) { |
|
35
|
3 |
|
$flags_array = $arguments[0]; |
|
36
|
3 |
|
$arguments[0] = 0; |
|
37
|
3 |
|
if (!is_array($flags_array)) { |
|
38
|
1 |
|
throw new TransformationException( |
|
39
|
|
|
'First argument of Htmlspecialchars should be an array' |
|
40
|
1 |
|
); |
|
41
|
|
|
} |
|
42
|
2 |
|
foreach ($flags_array as $constant) { |
|
43
|
2 |
|
if (!defined($constant)) { |
|
44
|
1 |
|
throw new TransformationException( |
|
45
|
|
|
'Flags should be valid PHP constants' |
|
46
|
1 |
|
); |
|
47
|
|
|
} |
|
48
|
1 |
|
$arguments[0] |= constant($constant); |
|
49
|
1 |
|
} |
|
50
|
1 |
|
} |
|
51
|
|
|
// Set defaults from php |
|
52
|
3 |
|
$arguments = array_replace(array( |
|
53
|
3 |
|
ENT_COMPAT | (defined('ENT_HTML401') ? ENT_HTML401 : 0), |
|
54
|
3 |
|
ini_get('default_charset'), |
|
55
|
|
|
true |
|
56
|
3 |
|
), $arguments); |
|
57
|
3 |
|
return htmlspecialchars($input, $arguments[0], $arguments[1], $arguments[2]); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|