-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.php
48 lines (45 loc) · 1.18 KB
/
helper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
/**
* @package midgardmvc_helper_xsspreventer
* @author The Midgard Project, http://www.midgard-project.org
* @copyright The Midgard Project, http://www.midgard-project.org
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
*/
/**
* Static helper functions for the Cross-Site Scripting (XSS) preventer.
*
* @package midgardmvc_helper_xsspreventer
*/
class midgardmvc_helper_xsspreventer_helper
{
/**
* Escape value of an XML attribute
*
* @param string $input Attribute value to escape
*/
static public function escape_attribute($input)
{
$output = str_replace('"', '"', $input);
return '"' . $output . '"';
}
/**
* Escape contents of an XML element
*
* @param string $element XML element to close
* @param string $input Element content to escape
*/
static public function escape_element($element, $input)
{
return preg_replace_callback
(
"%(<\s*)+(/\s*)+{$element}%i",
create_function
(
'$matches',
'return htmlentities($matches[0]);'
),
$input
);
}
}
?>