@@ -5,39 +5,39 @@ |
||
5 | 5 | */ |
6 | 6 | class HTMLPurifier_EntityLookup { |
7 | 7 | |
8 | - /** |
|
9 | - * Assoc array of entity name to character represented. |
|
10 | - */ |
|
11 | - public $table; |
|
8 | + /** |
|
9 | + * Assoc array of entity name to character represented. |
|
10 | + */ |
|
11 | + public $table; |
|
12 | 12 | |
13 | - /** |
|
14 | - * Sets up the entity lookup table from the serialized file contents. |
|
15 | - * @note The serialized contents are versioned, but were generated |
|
16 | - * using the maintenance script generate_entity_file.php |
|
17 | - * @warning This is not in constructor to help enforce the Singleton |
|
18 | - */ |
|
19 | - public function setup($file = false) { |
|
20 | - if (!$file) { |
|
21 | - $file = HTMLPURIFIER_PREFIX . '/HTMLPurifier/EntityLookup/entities.ser'; |
|
22 | - } |
|
23 | - $this->table = unserialize(file_get_contents($file)); |
|
24 | - } |
|
13 | + /** |
|
14 | + * Sets up the entity lookup table from the serialized file contents. |
|
15 | + * @note The serialized contents are versioned, but were generated |
|
16 | + * using the maintenance script generate_entity_file.php |
|
17 | + * @warning This is not in constructor to help enforce the Singleton |
|
18 | + */ |
|
19 | + public function setup($file = false) { |
|
20 | + if (!$file) { |
|
21 | + $file = HTMLPURIFIER_PREFIX . '/HTMLPurifier/EntityLookup/entities.ser'; |
|
22 | + } |
|
23 | + $this->table = unserialize(file_get_contents($file)); |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * Retrieves sole instance of the object. |
|
28 | - * @param Optional prototype of custom lookup table to overload with. |
|
29 | - */ |
|
30 | - public static function instance($prototype = false) { |
|
31 | - // no references, since PHP doesn't copy unless modified |
|
32 | - static $instance = null; |
|
33 | - if ($prototype) { |
|
34 | - $instance = $prototype; |
|
35 | - } elseif (!$instance) { |
|
36 | - $instance = new HTMLPurifier_EntityLookup(); |
|
37 | - $instance->setup(); |
|
38 | - } |
|
39 | - return $instance; |
|
40 | - } |
|
26 | + /** |
|
27 | + * Retrieves sole instance of the object. |
|
28 | + * @param Optional prototype of custom lookup table to overload with. |
|
29 | + */ |
|
30 | + public static function instance($prototype = false) { |
|
31 | + // no references, since PHP doesn't copy unless modified |
|
32 | + static $instance = null; |
|
33 | + if ($prototype) { |
|
34 | + $instance = $prototype; |
|
35 | + } elseif (!$instance) { |
|
36 | + $instance = new HTMLPurifier_EntityLookup(); |
|
37 | + $instance->setup(); |
|
38 | + } |
|
39 | + return $instance; |
|
40 | + } |
|
41 | 41 | |
42 | 42 | } |
43 | 43 |
@@ -18,7 +18,7 @@ |
||
18 | 18 | */ |
19 | 19 | public function setup($file = false) { |
20 | 20 | if (!$file) { |
21 | - $file = HTMLPURIFIER_PREFIX . '/HTMLPurifier/EntityLookup/entities.ser'; |
|
21 | + $file = HTMLPURIFIER_PREFIX.'/HTMLPurifier/EntityLookup/entities.ser'; |
|
22 | 22 | } |
23 | 23 | $this->table = unserialize(file_get_contents($file)); |
24 | 24 | } |
@@ -10,134 +10,134 @@ |
||
10 | 10 | class HTMLPurifier_EntityParser |
11 | 11 | { |
12 | 12 | |
13 | - /** |
|
14 | - * Reference to entity lookup table. |
|
15 | - */ |
|
16 | - protected $_entity_lookup; |
|
17 | - |
|
18 | - /** |
|
19 | - * Callback regex string for parsing entities. |
|
20 | - */ |
|
21 | - protected $_substituteEntitiesRegex = |
|
13 | + /** |
|
14 | + * Reference to entity lookup table. |
|
15 | + */ |
|
16 | + protected $_entity_lookup; |
|
17 | + |
|
18 | + /** |
|
19 | + * Callback regex string for parsing entities. |
|
20 | + */ |
|
21 | + protected $_substituteEntitiesRegex = |
|
22 | 22 | '/&(?:[#]x([a-fA-F0-9]+)|[#]0*(\d+)|([A-Za-z_:][A-Za-z0-9.\-_:]*));?/'; |
23 | 23 | // 1. hex 2. dec 3. string (XML style) |
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * Decimal to parsed string conversion table for special entities. |
|
28 | - */ |
|
29 | - protected $_special_dec2str = |
|
30 | - array( |
|
31 | - 34 => '"', |
|
32 | - 38 => '&', |
|
33 | - 39 => "'", |
|
34 | - 60 => '<', |
|
35 | - 62 => '>' |
|
36 | - ); |
|
37 | - |
|
38 | - /** |
|
39 | - * Stripped entity names to decimal conversion table for special entities. |
|
40 | - */ |
|
41 | - protected $_special_ent2dec = |
|
42 | - array( |
|
43 | - 'quot' => 34, |
|
44 | - 'amp' => 38, |
|
45 | - 'lt' => 60, |
|
46 | - 'gt' => 62 |
|
47 | - ); |
|
48 | - |
|
49 | - /** |
|
50 | - * Substitutes non-special entities with their parsed equivalents. Since |
|
51 | - * running this whenever you have parsed character is t3h 5uck, we run |
|
52 | - * it before everything else. |
|
53 | - * |
|
54 | - * @param $string String to have non-special entities parsed. |
|
55 | - * @returns Parsed string. |
|
56 | - */ |
|
57 | - public function substituteNonSpecialEntities($string) { |
|
58 | - // it will try to detect missing semicolons, but don't rely on it |
|
59 | - return preg_replace_callback( |
|
60 | - $this->_substituteEntitiesRegex, |
|
61 | - array($this, 'nonSpecialEntityCallback'), |
|
62 | - $string |
|
63 | - ); |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * Callback function for substituteNonSpecialEntities() that does the work. |
|
68 | - * |
|
69 | - * @param $matches PCRE matches array, with 0 the entire match, and |
|
70 | - * either index 1, 2 or 3 set with a hex value, dec value, |
|
71 | - * or string (respectively). |
|
72 | - * @returns Replacement string. |
|
73 | - */ |
|
74 | - |
|
75 | - protected function nonSpecialEntityCallback($matches) { |
|
76 | - // replaces all but big five |
|
77 | - $entity = $matches[0]; |
|
78 | - $is_num = (@$matches[0][1] === '#'); |
|
79 | - if ($is_num) { |
|
80 | - $is_hex = (@$entity[2] === 'x'); |
|
81 | - $code = $is_hex ? hexdec($matches[1]) : (int) $matches[2]; |
|
82 | - |
|
83 | - // abort for special characters |
|
84 | - if (isset($this->_special_dec2str[$code])) return $entity; |
|
85 | - |
|
86 | - return HTMLPurifier_Encoder::unichr($code); |
|
87 | - } else { |
|
88 | - if (isset($this->_special_ent2dec[$matches[3]])) return $entity; |
|
89 | - if (!$this->_entity_lookup) { |
|
90 | - $this->_entity_lookup = HTMLPurifier_EntityLookup::instance(); |
|
91 | - } |
|
92 | - if (isset($this->_entity_lookup->table[$matches[3]])) { |
|
93 | - return $this->_entity_lookup->table[$matches[3]]; |
|
94 | - } else { |
|
95 | - return $entity; |
|
96 | - } |
|
97 | - } |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Substitutes only special entities with their parsed equivalents. |
|
102 | - * |
|
103 | - * @notice We try to avoid calling this function because otherwise, it |
|
104 | - * would have to be called a lot (for every parsed section). |
|
105 | - * |
|
106 | - * @param $string String to have non-special entities parsed. |
|
107 | - * @returns Parsed string. |
|
108 | - */ |
|
109 | - public function substituteSpecialEntities($string) { |
|
110 | - return preg_replace_callback( |
|
111 | - $this->_substituteEntitiesRegex, |
|
112 | - array($this, 'specialEntityCallback'), |
|
113 | - $string); |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Callback function for substituteSpecialEntities() that does the work. |
|
118 | - * |
|
119 | - * This callback has same syntax as nonSpecialEntityCallback(). |
|
120 | - * |
|
121 | - * @param $matches PCRE-style matches array, with 0 the entire match, and |
|
122 | - * either index 1, 2 or 3 set with a hex value, dec value, |
|
123 | - * or string (respectively). |
|
124 | - * @returns Replacement string. |
|
125 | - */ |
|
126 | - protected function specialEntityCallback($matches) { |
|
127 | - $entity = $matches[0]; |
|
128 | - $is_num = (@$matches[0][1] === '#'); |
|
129 | - if ($is_num) { |
|
130 | - $is_hex = (@$entity[2] === 'x'); |
|
131 | - $int = $is_hex ? hexdec($matches[1]) : (int) $matches[2]; |
|
132 | - return isset($this->_special_dec2str[$int]) ? |
|
133 | - $this->_special_dec2str[$int] : |
|
134 | - $entity; |
|
135 | - } else { |
|
136 | - return isset($this->_special_ent2dec[$matches[3]]) ? |
|
137 | - $this->_special_ent2dec[$matches[3]] : |
|
138 | - $entity; |
|
139 | - } |
|
140 | - } |
|
26 | + /** |
|
27 | + * Decimal to parsed string conversion table for special entities. |
|
28 | + */ |
|
29 | + protected $_special_dec2str = |
|
30 | + array( |
|
31 | + 34 => '"', |
|
32 | + 38 => '&', |
|
33 | + 39 => "'", |
|
34 | + 60 => '<', |
|
35 | + 62 => '>' |
|
36 | + ); |
|
37 | + |
|
38 | + /** |
|
39 | + * Stripped entity names to decimal conversion table for special entities. |
|
40 | + */ |
|
41 | + protected $_special_ent2dec = |
|
42 | + array( |
|
43 | + 'quot' => 34, |
|
44 | + 'amp' => 38, |
|
45 | + 'lt' => 60, |
|
46 | + 'gt' => 62 |
|
47 | + ); |
|
48 | + |
|
49 | + /** |
|
50 | + * Substitutes non-special entities with their parsed equivalents. Since |
|
51 | + * running this whenever you have parsed character is t3h 5uck, we run |
|
52 | + * it before everything else. |
|
53 | + * |
|
54 | + * @param $string String to have non-special entities parsed. |
|
55 | + * @returns Parsed string. |
|
56 | + */ |
|
57 | + public function substituteNonSpecialEntities($string) { |
|
58 | + // it will try to detect missing semicolons, but don't rely on it |
|
59 | + return preg_replace_callback( |
|
60 | + $this->_substituteEntitiesRegex, |
|
61 | + array($this, 'nonSpecialEntityCallback'), |
|
62 | + $string |
|
63 | + ); |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * Callback function for substituteNonSpecialEntities() that does the work. |
|
68 | + * |
|
69 | + * @param $matches PCRE matches array, with 0 the entire match, and |
|
70 | + * either index 1, 2 or 3 set with a hex value, dec value, |
|
71 | + * or string (respectively). |
|
72 | + * @returns Replacement string. |
|
73 | + */ |
|
74 | + |
|
75 | + protected function nonSpecialEntityCallback($matches) { |
|
76 | + // replaces all but big five |
|
77 | + $entity = $matches[0]; |
|
78 | + $is_num = (@$matches[0][1] === '#'); |
|
79 | + if ($is_num) { |
|
80 | + $is_hex = (@$entity[2] === 'x'); |
|
81 | + $code = $is_hex ? hexdec($matches[1]) : (int) $matches[2]; |
|
82 | + |
|
83 | + // abort for special characters |
|
84 | + if (isset($this->_special_dec2str[$code])) return $entity; |
|
85 | + |
|
86 | + return HTMLPurifier_Encoder::unichr($code); |
|
87 | + } else { |
|
88 | + if (isset($this->_special_ent2dec[$matches[3]])) return $entity; |
|
89 | + if (!$this->_entity_lookup) { |
|
90 | + $this->_entity_lookup = HTMLPurifier_EntityLookup::instance(); |
|
91 | + } |
|
92 | + if (isset($this->_entity_lookup->table[$matches[3]])) { |
|
93 | + return $this->_entity_lookup->table[$matches[3]]; |
|
94 | + } else { |
|
95 | + return $entity; |
|
96 | + } |
|
97 | + } |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Substitutes only special entities with their parsed equivalents. |
|
102 | + * |
|
103 | + * @notice We try to avoid calling this function because otherwise, it |
|
104 | + * would have to be called a lot (for every parsed section). |
|
105 | + * |
|
106 | + * @param $string String to have non-special entities parsed. |
|
107 | + * @returns Parsed string. |
|
108 | + */ |
|
109 | + public function substituteSpecialEntities($string) { |
|
110 | + return preg_replace_callback( |
|
111 | + $this->_substituteEntitiesRegex, |
|
112 | + array($this, 'specialEntityCallback'), |
|
113 | + $string); |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Callback function for substituteSpecialEntities() that does the work. |
|
118 | + * |
|
119 | + * This callback has same syntax as nonSpecialEntityCallback(). |
|
120 | + * |
|
121 | + * @param $matches PCRE-style matches array, with 0 the entire match, and |
|
122 | + * either index 1, 2 or 3 set with a hex value, dec value, |
|
123 | + * or string (respectively). |
|
124 | + * @returns Replacement string. |
|
125 | + */ |
|
126 | + protected function specialEntityCallback($matches) { |
|
127 | + $entity = $matches[0]; |
|
128 | + $is_num = (@$matches[0][1] === '#'); |
|
129 | + if ($is_num) { |
|
130 | + $is_hex = (@$entity[2] === 'x'); |
|
131 | + $int = $is_hex ? hexdec($matches[1]) : (int) $matches[2]; |
|
132 | + return isset($this->_special_dec2str[$int]) ? |
|
133 | + $this->_special_dec2str[$int] : |
|
134 | + $entity; |
|
135 | + } else { |
|
136 | + return isset($this->_special_ent2dec[$matches[3]]) ? |
|
137 | + $this->_special_ent2dec[$matches[3]] : |
|
138 | + $entity; |
|
139 | + } |
|
140 | + } |
|
141 | 141 | |
142 | 142 | } |
143 | 143 |
@@ -130,12 +130,10 @@ |
||
130 | 130 | $is_hex = (@$entity[2] === 'x'); |
131 | 131 | $int = $is_hex ? hexdec($matches[1]) : (int) $matches[2]; |
132 | 132 | return isset($this->_special_dec2str[$int]) ? |
133 | - $this->_special_dec2str[$int] : |
|
134 | - $entity; |
|
133 | + $this->_special_dec2str[$int] : $entity; |
|
135 | 134 | } else { |
136 | 135 | return isset($this->_special_ent2dec[$matches[3]]) ? |
137 | - $this->_special_ent2dec[$matches[3]] : |
|
138 | - $entity; |
|
136 | + $this->_special_ent2dec[$matches[3]] : $entity; |
|
139 | 137 | } |
140 | 138 | } |
141 | 139 |
@@ -81,11 +81,15 @@ |
||
81 | 81 | $code = $is_hex ? hexdec($matches[1]) : (int) $matches[2]; |
82 | 82 | |
83 | 83 | // abort for special characters |
84 | - if (isset($this->_special_dec2str[$code])) return $entity; |
|
84 | + if (isset($this->_special_dec2str[$code])) { |
|
85 | + return $entity; |
|
86 | + } |
|
85 | 87 | |
86 | 88 | return HTMLPurifier_Encoder::unichr($code); |
87 | 89 | } else { |
88 | - if (isset($this->_special_ent2dec[$matches[3]])) return $entity; |
|
90 | + if (isset($this->_special_ent2dec[$matches[3]])) { |
|
91 | + return $entity; |
|
92 | + } |
|
89 | 93 | if (!$this->_entity_lookup) { |
90 | 94 | $this->_entity_lookup = HTMLPurifier_EntityLookup::instance(); |
91 | 95 | } |
@@ -9,51 +9,51 @@ |
||
9 | 9 | class HTMLPurifier_ErrorStruct |
10 | 10 | { |
11 | 11 | |
12 | - /** |
|
13 | - * Possible values for $children first-key. Note that top-level structures |
|
14 | - * are automatically token-level. |
|
15 | - */ |
|
16 | - const TOKEN = 0; |
|
17 | - const ATTR = 1; |
|
18 | - const CSSPROP = 2; |
|
19 | - |
|
20 | - /** |
|
21 | - * Type of this struct. |
|
22 | - */ |
|
23 | - public $type; |
|
24 | - |
|
25 | - /** |
|
26 | - * Value of the struct we are recording errors for. There are various |
|
27 | - * values for this: |
|
28 | - * - TOKEN: Instance of HTMLPurifier_Token |
|
29 | - * - ATTR: array('attr-name', 'value') |
|
30 | - * - CSSPROP: array('prop-name', 'value') |
|
31 | - */ |
|
32 | - public $value; |
|
33 | - |
|
34 | - /** |
|
35 | - * Errors registered for this structure. |
|
36 | - */ |
|
37 | - public $errors = array(); |
|
38 | - |
|
39 | - /** |
|
40 | - * Child ErrorStructs that are from this structure. For example, a TOKEN |
|
41 | - * ErrorStruct would contain ATTR ErrorStructs. This is a multi-dimensional |
|
42 | - * array in structure: [TYPE]['identifier'] |
|
43 | - */ |
|
44 | - public $children = array(); |
|
45 | - |
|
46 | - public function getChild($type, $id) { |
|
47 | - if (!isset($this->children[$type][$id])) { |
|
48 | - $this->children[$type][$id] = new HTMLPurifier_ErrorStruct(); |
|
49 | - $this->children[$type][$id]->type = $type; |
|
50 | - } |
|
51 | - return $this->children[$type][$id]; |
|
52 | - } |
|
53 | - |
|
54 | - public function addError($severity, $message) { |
|
55 | - $this->errors[] = array($severity, $message); |
|
56 | - } |
|
12 | + /** |
|
13 | + * Possible values for $children first-key. Note that top-level structures |
|
14 | + * are automatically token-level. |
|
15 | + */ |
|
16 | + const TOKEN = 0; |
|
17 | + const ATTR = 1; |
|
18 | + const CSSPROP = 2; |
|
19 | + |
|
20 | + /** |
|
21 | + * Type of this struct. |
|
22 | + */ |
|
23 | + public $type; |
|
24 | + |
|
25 | + /** |
|
26 | + * Value of the struct we are recording errors for. There are various |
|
27 | + * values for this: |
|
28 | + * - TOKEN: Instance of HTMLPurifier_Token |
|
29 | + * - ATTR: array('attr-name', 'value') |
|
30 | + * - CSSPROP: array('prop-name', 'value') |
|
31 | + */ |
|
32 | + public $value; |
|
33 | + |
|
34 | + /** |
|
35 | + * Errors registered for this structure. |
|
36 | + */ |
|
37 | + public $errors = array(); |
|
38 | + |
|
39 | + /** |
|
40 | + * Child ErrorStructs that are from this structure. For example, a TOKEN |
|
41 | + * ErrorStruct would contain ATTR ErrorStructs. This is a multi-dimensional |
|
42 | + * array in structure: [TYPE]['identifier'] |
|
43 | + */ |
|
44 | + public $children = array(); |
|
45 | + |
|
46 | + public function getChild($type, $id) { |
|
47 | + if (!isset($this->children[$type][$id])) { |
|
48 | + $this->children[$type][$id] = new HTMLPurifier_ErrorStruct(); |
|
49 | + $this->children[$type][$id]->type = $type; |
|
50 | + } |
|
51 | + return $this->children[$type][$id]; |
|
52 | + } |
|
53 | + |
|
54 | + public function addError($severity, $message) { |
|
55 | + $this->errors[] = array($severity, $message); |
|
56 | + } |
|
57 | 57 | |
58 | 58 | } |
59 | 59 |
@@ -22,24 +22,24 @@ |
||
22 | 22 | class HTMLPurifier_Filter |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * Name of the filter for identification purposes |
|
27 | - */ |
|
28 | - public $name; |
|
25 | + /** |
|
26 | + * Name of the filter for identification purposes |
|
27 | + */ |
|
28 | + public $name; |
|
29 | 29 | |
30 | - /** |
|
31 | - * Pre-processor function, handles HTML before HTML Purifier |
|
32 | - */ |
|
33 | - public function preFilter($html, $config, $context) { |
|
34 | - return $html; |
|
35 | - } |
|
30 | + /** |
|
31 | + * Pre-processor function, handles HTML before HTML Purifier |
|
32 | + */ |
|
33 | + public function preFilter($html, $config, $context) { |
|
34 | + return $html; |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * Post-processor function, handles HTML after HTML Purifier |
|
39 | - */ |
|
40 | - public function postFilter($html, $config, $context) { |
|
41 | - return $html; |
|
42 | - } |
|
37 | + /** |
|
38 | + * Post-processor function, handles HTML after HTML Purifier |
|
39 | + */ |
|
40 | + public function postFilter($html, $config, $context) { |
|
41 | + return $html; |
|
42 | + } |
|
43 | 43 | |
44 | 44 | } |
45 | 45 |
@@ -23,265 +23,265 @@ |
||
23 | 23 | class HTMLPurifier_Filter_ExtractStyleBlocks extends HTMLPurifier_Filter |
24 | 24 | { |
25 | 25 | |
26 | - public $name = 'ExtractStyleBlocks'; |
|
27 | - private $_styleMatches = array(); |
|
28 | - private $_tidy; |
|
26 | + public $name = 'ExtractStyleBlocks'; |
|
27 | + private $_styleMatches = array(); |
|
28 | + private $_tidy; |
|
29 | 29 | |
30 | - private $_id_attrdef; |
|
31 | - private $_class_attrdef; |
|
32 | - private $_enum_attrdef; |
|
30 | + private $_id_attrdef; |
|
31 | + private $_class_attrdef; |
|
32 | + private $_enum_attrdef; |
|
33 | 33 | |
34 | - public function __construct() { |
|
35 | - $this->_tidy = new csstidy(); |
|
36 | - $this->_id_attrdef = new HTMLPurifier_AttrDef_HTML_ID(true); |
|
37 | - $this->_class_attrdef = new HTMLPurifier_AttrDef_CSS_Ident(); |
|
38 | - $this->_enum_attrdef = new HTMLPurifier_AttrDef_Enum(array('first-child', 'link', 'visited', 'active', 'hover', 'focus')); |
|
39 | - } |
|
34 | + public function __construct() { |
|
35 | + $this->_tidy = new csstidy(); |
|
36 | + $this->_id_attrdef = new HTMLPurifier_AttrDef_HTML_ID(true); |
|
37 | + $this->_class_attrdef = new HTMLPurifier_AttrDef_CSS_Ident(); |
|
38 | + $this->_enum_attrdef = new HTMLPurifier_AttrDef_Enum(array('first-child', 'link', 'visited', 'active', 'hover', 'focus')); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * Save the contents of CSS blocks to style matches |
|
43 | - * @param $matches preg_replace style $matches array |
|
44 | - */ |
|
45 | - protected function styleCallback($matches) { |
|
46 | - $this->_styleMatches[] = $matches[1]; |
|
47 | - } |
|
41 | + /** |
|
42 | + * Save the contents of CSS blocks to style matches |
|
43 | + * @param $matches preg_replace style $matches array |
|
44 | + */ |
|
45 | + protected function styleCallback($matches) { |
|
46 | + $this->_styleMatches[] = $matches[1]; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Removes inline <style> tags from HTML, saves them for later use |
|
51 | - * @todo Extend to indicate non-text/css style blocks |
|
52 | - */ |
|
53 | - public function preFilter($html, $config, $context) { |
|
54 | - $tidy = $config->get('Filter.ExtractStyleBlocks.TidyImpl'); |
|
55 | - if ($tidy !== null) $this->_tidy = $tidy; |
|
56 | - $html = preg_replace_callback('#<style(?:\s.*)?>(.+)</style>#isU', array($this, 'styleCallback'), $html); |
|
57 | - $style_blocks = $this->_styleMatches; |
|
58 | - $this->_styleMatches = array(); // reset |
|
59 | - $context->register('StyleBlocks', $style_blocks); // $context must not be reused |
|
60 | - if ($this->_tidy) { |
|
61 | - foreach ($style_blocks as &$style) { |
|
62 | - $style = $this->cleanCSS($style, $config, $context); |
|
63 | - } |
|
64 | - } |
|
65 | - return $html; |
|
66 | - } |
|
49 | + /** |
|
50 | + * Removes inline <style> tags from HTML, saves them for later use |
|
51 | + * @todo Extend to indicate non-text/css style blocks |
|
52 | + */ |
|
53 | + public function preFilter($html, $config, $context) { |
|
54 | + $tidy = $config->get('Filter.ExtractStyleBlocks.TidyImpl'); |
|
55 | + if ($tidy !== null) $this->_tidy = $tidy; |
|
56 | + $html = preg_replace_callback('#<style(?:\s.*)?>(.+)</style>#isU', array($this, 'styleCallback'), $html); |
|
57 | + $style_blocks = $this->_styleMatches; |
|
58 | + $this->_styleMatches = array(); // reset |
|
59 | + $context->register('StyleBlocks', $style_blocks); // $context must not be reused |
|
60 | + if ($this->_tidy) { |
|
61 | + foreach ($style_blocks as &$style) { |
|
62 | + $style = $this->cleanCSS($style, $config, $context); |
|
63 | + } |
|
64 | + } |
|
65 | + return $html; |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * Takes CSS (the stuff found in <style>) and cleans it. |
|
70 | - * @warning Requires CSSTidy <http://csstidy.sourceforge.net/> |
|
71 | - * @param $css CSS styling to clean |
|
72 | - * @param $config Instance of HTMLPurifier_Config |
|
73 | - * @param $context Instance of HTMLPurifier_Context |
|
74 | - * @return Cleaned CSS |
|
75 | - */ |
|
76 | - public function cleanCSS($css, $config, $context) { |
|
77 | - // prepare scope |
|
78 | - $scope = $config->get('Filter.ExtractStyleBlocks.Scope'); |
|
79 | - if ($scope !== null) { |
|
80 | - $scopes = array_map('trim', explode(',', $scope)); |
|
81 | - } else { |
|
82 | - $scopes = array(); |
|
83 | - } |
|
84 | - // remove comments from CSS |
|
85 | - $css = trim($css); |
|
86 | - if (strncmp('<!--', $css, 4) === 0) { |
|
87 | - $css = substr($css, 4); |
|
88 | - } |
|
89 | - if (strlen($css) > 3 && substr($css, -3) == '-->') { |
|
90 | - $css = substr($css, 0, -3); |
|
91 | - } |
|
92 | - $css = trim($css); |
|
93 | - set_error_handler('htmlpurifier_filter_extractstyleblocks_muteerrorhandler'); |
|
94 | - $this->_tidy->parse($css); |
|
95 | - restore_error_handler(); |
|
96 | - $css_definition = $config->getDefinition('CSS'); |
|
97 | - $html_definition = $config->getDefinition('HTML'); |
|
98 | - $new_css = array(); |
|
99 | - foreach ($this->_tidy->css as $k => $decls) { |
|
100 | - // $decls are all CSS declarations inside an @ selector |
|
101 | - $new_decls = array(); |
|
102 | - foreach ($decls as $selector => $style) { |
|
103 | - $selector = trim($selector); |
|
104 | - if ($selector === '') continue; // should not happen |
|
105 | - // Parse the selector |
|
106 | - // Here is the relevant part of the CSS grammar: |
|
107 | - // |
|
108 | - // ruleset |
|
109 | - // : selector [ ',' S* selector ]* '{' ... |
|
110 | - // selector |
|
111 | - // : simple_selector [ combinator selector | S+ [ combinator? selector ]? ]? |
|
112 | - // combinator |
|
113 | - // : '+' S* |
|
114 | - // : '>' S* |
|
115 | - // simple_selector |
|
116 | - // : element_name [ HASH | class | attrib | pseudo ]* |
|
117 | - // | [ HASH | class | attrib | pseudo ]+ |
|
118 | - // element_name |
|
119 | - // : IDENT | '*' |
|
120 | - // ; |
|
121 | - // class |
|
122 | - // : '.' IDENT |
|
123 | - // ; |
|
124 | - // attrib |
|
125 | - // : '[' S* IDENT S* [ [ '=' | INCLUDES | DASHMATCH ] S* |
|
126 | - // [ IDENT | STRING ] S* ]? ']' |
|
127 | - // ; |
|
128 | - // pseudo |
|
129 | - // : ':' [ IDENT | FUNCTION S* [IDENT S*]? ')' ] |
|
130 | - // ; |
|
131 | - // |
|
132 | - // For reference, here are the relevant tokens: |
|
133 | - // |
|
134 | - // HASH #{name} |
|
135 | - // IDENT {ident} |
|
136 | - // INCLUDES == |
|
137 | - // DASHMATCH |= |
|
138 | - // STRING {string} |
|
139 | - // FUNCTION {ident}\( |
|
140 | - // |
|
141 | - // And the lexical scanner tokens |
|
142 | - // |
|
143 | - // name {nmchar}+ |
|
144 | - // nmchar [_a-z0-9-]|{nonascii}|{escape} |
|
145 | - // nonascii [\240-\377] |
|
146 | - // escape {unicode}|\\[^\r\n\f0-9a-f] |
|
147 | - // unicode \\{h}}{1,6}(\r\n|[ \t\r\n\f])? |
|
148 | - // ident -?{nmstart}{nmchar*} |
|
149 | - // nmstart [_a-z]|{nonascii}|{escape} |
|
150 | - // string {string1}|{string2} |
|
151 | - // string1 \"([^\n\r\f\\"]|\\{nl}|{escape})*\" |
|
152 | - // string2 \'([^\n\r\f\\"]|\\{nl}|{escape})*\' |
|
153 | - // |
|
154 | - // We'll implement a subset (in order to reduce attack |
|
155 | - // surface); in particular: |
|
156 | - // |
|
157 | - // - No Unicode support |
|
158 | - // - No escapes support |
|
159 | - // - No string support (by proxy no attrib support) |
|
160 | - // - element_name is matched against allowed |
|
161 | - // elements (some people might find this |
|
162 | - // annoying...) |
|
163 | - // - Pseudo-elements one of :first-child, :link, |
|
164 | - // :visited, :active, :hover, :focus |
|
68 | + /** |
|
69 | + * Takes CSS (the stuff found in <style>) and cleans it. |
|
70 | + * @warning Requires CSSTidy <http://csstidy.sourceforge.net/> |
|
71 | + * @param $css CSS styling to clean |
|
72 | + * @param $config Instance of HTMLPurifier_Config |
|
73 | + * @param $context Instance of HTMLPurifier_Context |
|
74 | + * @return Cleaned CSS |
|
75 | + */ |
|
76 | + public function cleanCSS($css, $config, $context) { |
|
77 | + // prepare scope |
|
78 | + $scope = $config->get('Filter.ExtractStyleBlocks.Scope'); |
|
79 | + if ($scope !== null) { |
|
80 | + $scopes = array_map('trim', explode(',', $scope)); |
|
81 | + } else { |
|
82 | + $scopes = array(); |
|
83 | + } |
|
84 | + // remove comments from CSS |
|
85 | + $css = trim($css); |
|
86 | + if (strncmp('<!--', $css, 4) === 0) { |
|
87 | + $css = substr($css, 4); |
|
88 | + } |
|
89 | + if (strlen($css) > 3 && substr($css, -3) == '-->') { |
|
90 | + $css = substr($css, 0, -3); |
|
91 | + } |
|
92 | + $css = trim($css); |
|
93 | + set_error_handler('htmlpurifier_filter_extractstyleblocks_muteerrorhandler'); |
|
94 | + $this->_tidy->parse($css); |
|
95 | + restore_error_handler(); |
|
96 | + $css_definition = $config->getDefinition('CSS'); |
|
97 | + $html_definition = $config->getDefinition('HTML'); |
|
98 | + $new_css = array(); |
|
99 | + foreach ($this->_tidy->css as $k => $decls) { |
|
100 | + // $decls are all CSS declarations inside an @ selector |
|
101 | + $new_decls = array(); |
|
102 | + foreach ($decls as $selector => $style) { |
|
103 | + $selector = trim($selector); |
|
104 | + if ($selector === '') continue; // should not happen |
|
105 | + // Parse the selector |
|
106 | + // Here is the relevant part of the CSS grammar: |
|
107 | + // |
|
108 | + // ruleset |
|
109 | + // : selector [ ',' S* selector ]* '{' ... |
|
110 | + // selector |
|
111 | + // : simple_selector [ combinator selector | S+ [ combinator? selector ]? ]? |
|
112 | + // combinator |
|
113 | + // : '+' S* |
|
114 | + // : '>' S* |
|
115 | + // simple_selector |
|
116 | + // : element_name [ HASH | class | attrib | pseudo ]* |
|
117 | + // | [ HASH | class | attrib | pseudo ]+ |
|
118 | + // element_name |
|
119 | + // : IDENT | '*' |
|
120 | + // ; |
|
121 | + // class |
|
122 | + // : '.' IDENT |
|
123 | + // ; |
|
124 | + // attrib |
|
125 | + // : '[' S* IDENT S* [ [ '=' | INCLUDES | DASHMATCH ] S* |
|
126 | + // [ IDENT | STRING ] S* ]? ']' |
|
127 | + // ; |
|
128 | + // pseudo |
|
129 | + // : ':' [ IDENT | FUNCTION S* [IDENT S*]? ')' ] |
|
130 | + // ; |
|
131 | + // |
|
132 | + // For reference, here are the relevant tokens: |
|
133 | + // |
|
134 | + // HASH #{name} |
|
135 | + // IDENT {ident} |
|
136 | + // INCLUDES == |
|
137 | + // DASHMATCH |= |
|
138 | + // STRING {string} |
|
139 | + // FUNCTION {ident}\( |
|
140 | + // |
|
141 | + // And the lexical scanner tokens |
|
142 | + // |
|
143 | + // name {nmchar}+ |
|
144 | + // nmchar [_a-z0-9-]|{nonascii}|{escape} |
|
145 | + // nonascii [\240-\377] |
|
146 | + // escape {unicode}|\\[^\r\n\f0-9a-f] |
|
147 | + // unicode \\{h}}{1,6}(\r\n|[ \t\r\n\f])? |
|
148 | + // ident -?{nmstart}{nmchar*} |
|
149 | + // nmstart [_a-z]|{nonascii}|{escape} |
|
150 | + // string {string1}|{string2} |
|
151 | + // string1 \"([^\n\r\f\\"]|\\{nl}|{escape})*\" |
|
152 | + // string2 \'([^\n\r\f\\"]|\\{nl}|{escape})*\' |
|
153 | + // |
|
154 | + // We'll implement a subset (in order to reduce attack |
|
155 | + // surface); in particular: |
|
156 | + // |
|
157 | + // - No Unicode support |
|
158 | + // - No escapes support |
|
159 | + // - No string support (by proxy no attrib support) |
|
160 | + // - element_name is matched against allowed |
|
161 | + // elements (some people might find this |
|
162 | + // annoying...) |
|
163 | + // - Pseudo-elements one of :first-child, :link, |
|
164 | + // :visited, :active, :hover, :focus |
|
165 | 165 | |
166 | - // handle ruleset |
|
167 | - $selectors = array_map('trim', explode(',', $selector)); |
|
168 | - $new_selectors = array(); |
|
169 | - foreach ($selectors as $sel) { |
|
170 | - // split on +, > and spaces |
|
171 | - $basic_selectors = preg_split('/\s*([+> ])\s*/', $sel, -1, PREG_SPLIT_DELIM_CAPTURE); |
|
172 | - // even indices are chunks, odd indices are |
|
173 | - // delimiters |
|
174 | - $nsel = null; |
|
175 | - $delim = null; // guaranteed to be non-null after |
|
176 | - // two loop iterations |
|
177 | - for ($i = 0, $c = count($basic_selectors); $i < $c; $i++) { |
|
178 | - $x = $basic_selectors[$i]; |
|
179 | - if ($i % 2) { |
|
180 | - // delimiter |
|
181 | - if ($x === ' ') { |
|
182 | - $delim = ' '; |
|
183 | - } else { |
|
184 | - $delim = ' ' . $x . ' '; |
|
185 | - } |
|
186 | - } else { |
|
187 | - // simple selector |
|
188 | - $components = preg_split('/([#.:])/', $x, -1, PREG_SPLIT_DELIM_CAPTURE); |
|
189 | - $sdelim = null; |
|
190 | - $nx = null; |
|
191 | - for ($j = 0, $cc = count($components); $j < $cc; $j ++) { |
|
192 | - $y = $components[$j]; |
|
193 | - if ($j === 0) { |
|
194 | - if ($y === '*' || isset($html_definition->info[$y = strtolower($y)])) { |
|
195 | - $nx = $y; |
|
196 | - } else { |
|
197 | - // $nx stays null; this matters |
|
198 | - // if we don't manage to find |
|
199 | - // any valid selector content, |
|
200 | - // in which case we ignore the |
|
201 | - // outer $delim |
|
202 | - } |
|
203 | - } elseif ($j % 2) { |
|
204 | - // set delimiter |
|
205 | - $sdelim = $y; |
|
206 | - } else { |
|
207 | - $attrdef = null; |
|
208 | - if ($sdelim === '#') { |
|
209 | - $attrdef = $this->_id_attrdef; |
|
210 | - } elseif ($sdelim === '.') { |
|
211 | - $attrdef = $this->_class_attrdef; |
|
212 | - } elseif ($sdelim === ':') { |
|
213 | - $attrdef = $this->_enum_attrdef; |
|
214 | - } else { |
|
215 | - throw new HTMLPurifier_Exception('broken invariant sdelim and preg_split'); |
|
216 | - } |
|
217 | - $r = $attrdef->validate($y, $config, $context); |
|
218 | - if ($r !== false) { |
|
219 | - if ($r !== true) { |
|
220 | - $y = $r; |
|
221 | - } |
|
222 | - if ($nx === null) { |
|
223 | - $nx = ''; |
|
224 | - } |
|
225 | - $nx .= $sdelim . $y; |
|
226 | - } |
|
227 | - } |
|
228 | - } |
|
229 | - if ($nx !== null) { |
|
230 | - if ($nsel === null) { |
|
231 | - $nsel = $nx; |
|
232 | - } else { |
|
233 | - $nsel .= $delim . $nx; |
|
234 | - } |
|
235 | - } else { |
|
236 | - // delimiters to the left of invalid |
|
237 | - // basic selector ignored |
|
238 | - } |
|
239 | - } |
|
240 | - } |
|
241 | - if ($nsel !== null) { |
|
242 | - if (!empty($scopes)) { |
|
243 | - foreach ($scopes as $s) { |
|
244 | - $new_selectors[] = "$s $nsel"; |
|
245 | - } |
|
246 | - } else { |
|
247 | - $new_selectors[] = $nsel; |
|
248 | - } |
|
249 | - } |
|
250 | - } |
|
251 | - if (empty($new_selectors)) continue; |
|
252 | - $selector = implode(', ', $new_selectors); |
|
253 | - foreach ($style as $name => $value) { |
|
254 | - if (!isset($css_definition->info[$name])) { |
|
255 | - unset($style[$name]); |
|
256 | - continue; |
|
257 | - } |
|
258 | - $def = $css_definition->info[$name]; |
|
259 | - $ret = $def->validate($value, $config, $context); |
|
260 | - if ($ret === false) unset($style[$name]); |
|
261 | - else $style[$name] = $ret; |
|
262 | - } |
|
263 | - $new_decls[$selector] = $style; |
|
264 | - } |
|
265 | - $new_css[$k] = $new_decls; |
|
266 | - } |
|
267 | - // remove stuff that shouldn't be used, could be reenabled |
|
268 | - // after security risks are analyzed |
|
269 | - $this->_tidy->css = $new_css; |
|
270 | - $this->_tidy->import = array(); |
|
271 | - $this->_tidy->charset = null; |
|
272 | - $this->_tidy->namespace = null; |
|
273 | - $css = $this->_tidy->print->plain(); |
|
274 | - // we are going to escape any special characters <>& to ensure |
|
275 | - // that no funny business occurs (i.e. </style> in a font-family prop). |
|
276 | - if ($config->get('Filter.ExtractStyleBlocks.Escaping')) { |
|
277 | - $css = str_replace( |
|
278 | - array('<', '>', '&'), |
|
279 | - array('\3C ', '\3E ', '\26 '), |
|
280 | - $css |
|
281 | - ); |
|
282 | - } |
|
283 | - return $css; |
|
284 | - } |
|
166 | + // handle ruleset |
|
167 | + $selectors = array_map('trim', explode(',', $selector)); |
|
168 | + $new_selectors = array(); |
|
169 | + foreach ($selectors as $sel) { |
|
170 | + // split on +, > and spaces |
|
171 | + $basic_selectors = preg_split('/\s*([+> ])\s*/', $sel, -1, PREG_SPLIT_DELIM_CAPTURE); |
|
172 | + // even indices are chunks, odd indices are |
|
173 | + // delimiters |
|
174 | + $nsel = null; |
|
175 | + $delim = null; // guaranteed to be non-null after |
|
176 | + // two loop iterations |
|
177 | + for ($i = 0, $c = count($basic_selectors); $i < $c; $i++) { |
|
178 | + $x = $basic_selectors[$i]; |
|
179 | + if ($i % 2) { |
|
180 | + // delimiter |
|
181 | + if ($x === ' ') { |
|
182 | + $delim = ' '; |
|
183 | + } else { |
|
184 | + $delim = ' ' . $x . ' '; |
|
185 | + } |
|
186 | + } else { |
|
187 | + // simple selector |
|
188 | + $components = preg_split('/([#.:])/', $x, -1, PREG_SPLIT_DELIM_CAPTURE); |
|
189 | + $sdelim = null; |
|
190 | + $nx = null; |
|
191 | + for ($j = 0, $cc = count($components); $j < $cc; $j ++) { |
|
192 | + $y = $components[$j]; |
|
193 | + if ($j === 0) { |
|
194 | + if ($y === '*' || isset($html_definition->info[$y = strtolower($y)])) { |
|
195 | + $nx = $y; |
|
196 | + } else { |
|
197 | + // $nx stays null; this matters |
|
198 | + // if we don't manage to find |
|
199 | + // any valid selector content, |
|
200 | + // in which case we ignore the |
|
201 | + // outer $delim |
|
202 | + } |
|
203 | + } elseif ($j % 2) { |
|
204 | + // set delimiter |
|
205 | + $sdelim = $y; |
|
206 | + } else { |
|
207 | + $attrdef = null; |
|
208 | + if ($sdelim === '#') { |
|
209 | + $attrdef = $this->_id_attrdef; |
|
210 | + } elseif ($sdelim === '.') { |
|
211 | + $attrdef = $this->_class_attrdef; |
|
212 | + } elseif ($sdelim === ':') { |
|
213 | + $attrdef = $this->_enum_attrdef; |
|
214 | + } else { |
|
215 | + throw new HTMLPurifier_Exception('broken invariant sdelim and preg_split'); |
|
216 | + } |
|
217 | + $r = $attrdef->validate($y, $config, $context); |
|
218 | + if ($r !== false) { |
|
219 | + if ($r !== true) { |
|
220 | + $y = $r; |
|
221 | + } |
|
222 | + if ($nx === null) { |
|
223 | + $nx = ''; |
|
224 | + } |
|
225 | + $nx .= $sdelim . $y; |
|
226 | + } |
|
227 | + } |
|
228 | + } |
|
229 | + if ($nx !== null) { |
|
230 | + if ($nsel === null) { |
|
231 | + $nsel = $nx; |
|
232 | + } else { |
|
233 | + $nsel .= $delim . $nx; |
|
234 | + } |
|
235 | + } else { |
|
236 | + // delimiters to the left of invalid |
|
237 | + // basic selector ignored |
|
238 | + } |
|
239 | + } |
|
240 | + } |
|
241 | + if ($nsel !== null) { |
|
242 | + if (!empty($scopes)) { |
|
243 | + foreach ($scopes as $s) { |
|
244 | + $new_selectors[] = "$s $nsel"; |
|
245 | + } |
|
246 | + } else { |
|
247 | + $new_selectors[] = $nsel; |
|
248 | + } |
|
249 | + } |
|
250 | + } |
|
251 | + if (empty($new_selectors)) continue; |
|
252 | + $selector = implode(', ', $new_selectors); |
|
253 | + foreach ($style as $name => $value) { |
|
254 | + if (!isset($css_definition->info[$name])) { |
|
255 | + unset($style[$name]); |
|
256 | + continue; |
|
257 | + } |
|
258 | + $def = $css_definition->info[$name]; |
|
259 | + $ret = $def->validate($value, $config, $context); |
|
260 | + if ($ret === false) unset($style[$name]); |
|
261 | + else $style[$name] = $ret; |
|
262 | + } |
|
263 | + $new_decls[$selector] = $style; |
|
264 | + } |
|
265 | + $new_css[$k] = $new_decls; |
|
266 | + } |
|
267 | + // remove stuff that shouldn't be used, could be reenabled |
|
268 | + // after security risks are analyzed |
|
269 | + $this->_tidy->css = $new_css; |
|
270 | + $this->_tidy->import = array(); |
|
271 | + $this->_tidy->charset = null; |
|
272 | + $this->_tidy->namespace = null; |
|
273 | + $css = $this->_tidy->print->plain(); |
|
274 | + // we are going to escape any special characters <>& to ensure |
|
275 | + // that no funny business occurs (i.e. </style> in a font-family prop). |
|
276 | + if ($config->get('Filter.ExtractStyleBlocks.Escaping')) { |
|
277 | + $css = str_replace( |
|
278 | + array('<', '>', '&'), |
|
279 | + array('\3C ', '\3E ', '\26 '), |
|
280 | + $css |
|
281 | + ); |
|
282 | + } |
|
283 | + return $css; |
|
284 | + } |
|
285 | 285 | |
286 | 286 | } |
287 | 287 |
@@ -52,7 +52,9 @@ discard block |
||
52 | 52 | */ |
53 | 53 | public function preFilter($html, $config, $context) { |
54 | 54 | $tidy = $config->get('Filter.ExtractStyleBlocks.TidyImpl'); |
55 | - if ($tidy !== null) $this->_tidy = $tidy; |
|
55 | + if ($tidy !== null) { |
|
56 | + $this->_tidy = $tidy; |
|
57 | + } |
|
56 | 58 | $html = preg_replace_callback('#<style(?:\s.*)?>(.+)</style>#isU', array($this, 'styleCallback'), $html); |
57 | 59 | $style_blocks = $this->_styleMatches; |
58 | 60 | $this->_styleMatches = array(); // reset |
@@ -101,7 +103,10 @@ discard block |
||
101 | 103 | $new_decls = array(); |
102 | 104 | foreach ($decls as $selector => $style) { |
103 | 105 | $selector = trim($selector); |
104 | - if ($selector === '') continue; // should not happen |
|
106 | + if ($selector === '') { |
|
107 | + continue; |
|
108 | + } |
|
109 | + // should not happen |
|
105 | 110 | // Parse the selector |
106 | 111 | // Here is the relevant part of the CSS grammar: |
107 | 112 | // |
@@ -248,7 +253,9 @@ discard block |
||
248 | 253 | } |
249 | 254 | } |
250 | 255 | } |
251 | - if (empty($new_selectors)) continue; |
|
256 | + if (empty($new_selectors)) { |
|
257 | + continue; |
|
258 | + } |
|
252 | 259 | $selector = implode(', ', $new_selectors); |
253 | 260 | foreach ($style as $name => $value) { |
254 | 261 | if (!isset($css_definition->info[$name])) { |
@@ -257,8 +264,11 @@ discard block |
||
257 | 264 | } |
258 | 265 | $def = $css_definition->info[$name]; |
259 | 266 | $ret = $def->validate($value, $config, $context); |
260 | - if ($ret === false) unset($style[$name]); |
|
261 | - else $style[$name] = $ret; |
|
267 | + if ($ret === false) { |
|
268 | + unset($style[$name]); |
|
269 | + } else { |
|
270 | + $style[$name] = $ret; |
|
271 | + } |
|
262 | 272 | } |
263 | 273 | $new_decls[$selector] = $style; |
264 | 274 | } |
@@ -181,14 +181,14 @@ discard block |
||
181 | 181 | if ($x === ' ') { |
182 | 182 | $delim = ' '; |
183 | 183 | } else { |
184 | - $delim = ' ' . $x . ' '; |
|
184 | + $delim = ' '.$x.' '; |
|
185 | 185 | } |
186 | 186 | } else { |
187 | 187 | // simple selector |
188 | 188 | $components = preg_split('/([#.:])/', $x, -1, PREG_SPLIT_DELIM_CAPTURE); |
189 | 189 | $sdelim = null; |
190 | 190 | $nx = null; |
191 | - for ($j = 0, $cc = count($components); $j < $cc; $j ++) { |
|
191 | + for ($j = 0, $cc = count($components); $j < $cc; $j++) { |
|
192 | 192 | $y = $components[$j]; |
193 | 193 | if ($j === 0) { |
194 | 194 | if ($y === '*' || isset($html_definition->info[$y = strtolower($y)])) { |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | if ($nx === null) { |
223 | 223 | $nx = ''; |
224 | 224 | } |
225 | - $nx .= $sdelim . $y; |
|
225 | + $nx .= $sdelim.$y; |
|
226 | 226 | } |
227 | 227 | } |
228 | 228 | } |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | if ($nsel === null) { |
231 | 231 | $nsel = $nx; |
232 | 232 | } else { |
233 | - $nsel .= $delim . $nx; |
|
233 | + $nsel .= $delim.$nx; |
|
234 | 234 | } |
235 | 235 | } else { |
236 | 236 | // delimiters to the left of invalid |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | // that no funny business occurs (i.e. </style> in a font-family prop). |
276 | 276 | if ($config->get('Filter.ExtractStyleBlocks.Escaping')) { |
277 | 277 | $css = str_replace( |
278 | - array('<', '>', '&'), |
|
278 | + array('<', '>', '&'), |
|
279 | 279 | array('\3C ', '\3E ', '\26 '), |
280 | 280 | $css |
281 | 281 | ); |
@@ -3,37 +3,37 @@ |
||
3 | 3 | class HTMLPurifier_Filter_YouTube extends HTMLPurifier_Filter |
4 | 4 | { |
5 | 5 | |
6 | - public $name = 'YouTube'; |
|
7 | - |
|
8 | - public function preFilter($html, $config, $context) { |
|
9 | - $pre_regex = '#<object[^>]+>.+?'. |
|
10 | - 'http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?</object>#s'; |
|
11 | - $pre_replace = '<span class="youtube-embed">\1</span>'; |
|
12 | - return preg_replace($pre_regex, $pre_replace, $html); |
|
13 | - } |
|
14 | - |
|
15 | - public function postFilter($html, $config, $context) { |
|
16 | - $post_regex = '#<span class="youtube-embed">((?:v|cp)/[A-Za-z0-9\-_=]+)</span>#'; |
|
17 | - return preg_replace_callback($post_regex, array($this, 'postFilterCallback'), $html); |
|
18 | - } |
|
19 | - |
|
20 | - protected function armorUrl($url) { |
|
21 | - return str_replace('--', '--', $url); |
|
22 | - } |
|
23 | - |
|
24 | - protected function postFilterCallback($matches) { |
|
25 | - $url = $this->armorUrl($matches[1]); |
|
26 | - return '<object width="425" height="350" type="application/x-shockwave-flash" '. |
|
27 | - 'data="http://www.youtube.com/'.$url.'">'. |
|
28 | - '<param name="movie" value="http://www.youtube.com/'.$url.'"></param>'. |
|
29 | - '<!--[if IE]>'. |
|
30 | - '<embed src="http://www.youtube.com/'.$url.'"'. |
|
31 | - 'type="application/x-shockwave-flash"'. |
|
32 | - 'wmode="transparent" width="425" height="350" />'. |
|
33 | - '<![endif]-->'. |
|
34 | - '</object>'; |
|
35 | - |
|
36 | - } |
|
6 | + public $name = 'YouTube'; |
|
7 | + |
|
8 | + public function preFilter($html, $config, $context) { |
|
9 | + $pre_regex = '#<object[^>]+>.+?'. |
|
10 | + 'http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?</object>#s'; |
|
11 | + $pre_replace = '<span class="youtube-embed">\1</span>'; |
|
12 | + return preg_replace($pre_regex, $pre_replace, $html); |
|
13 | + } |
|
14 | + |
|
15 | + public function postFilter($html, $config, $context) { |
|
16 | + $post_regex = '#<span class="youtube-embed">((?:v|cp)/[A-Za-z0-9\-_=]+)</span>#'; |
|
17 | + return preg_replace_callback($post_regex, array($this, 'postFilterCallback'), $html); |
|
18 | + } |
|
19 | + |
|
20 | + protected function armorUrl($url) { |
|
21 | + return str_replace('--', '--', $url); |
|
22 | + } |
|
23 | + |
|
24 | + protected function postFilterCallback($matches) { |
|
25 | + $url = $this->armorUrl($matches[1]); |
|
26 | + return '<object width="425" height="350" type="application/x-shockwave-flash" '. |
|
27 | + 'data="http://www.youtube.com/'.$url.'">'. |
|
28 | + '<param name="movie" value="http://www.youtube.com/'.$url.'"></param>'. |
|
29 | + '<!--[if IE]>'. |
|
30 | + '<embed src="http://www.youtube.com/'.$url.'"'. |
|
31 | + 'type="application/x-shockwave-flash"'. |
|
32 | + 'wmode="transparent" width="425" height="350" />'. |
|
33 | + '<![endif]-->'. |
|
34 | + '</object>'; |
|
35 | + |
|
36 | + } |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | // vim: et sw=4 sts=4 |
@@ -18,226 +18,226 @@ |
||
18 | 18 | class HTMLPurifier_HTMLModule |
19 | 19 | { |
20 | 20 | |
21 | - // -- Overloadable ---------------------------------------------------- |
|
22 | - |
|
23 | - /** |
|
24 | - * Short unique string identifier of the module |
|
25 | - */ |
|
26 | - public $name; |
|
27 | - |
|
28 | - /** |
|
29 | - * Informally, a list of elements this module changes. Not used in |
|
30 | - * any significant way. |
|
31 | - */ |
|
32 | - public $elements = array(); |
|
33 | - |
|
34 | - /** |
|
35 | - * Associative array of element names to element definitions. |
|
36 | - * Some definitions may be incomplete, to be merged in later |
|
37 | - * with the full definition. |
|
38 | - */ |
|
39 | - public $info = array(); |
|
40 | - |
|
41 | - /** |
|
42 | - * Associative array of content set names to content set additions. |
|
43 | - * This is commonly used to, say, add an A element to the Inline |
|
44 | - * content set. This corresponds to an internal variable $content_sets |
|
45 | - * and NOT info_content_sets member variable of HTMLDefinition. |
|
46 | - */ |
|
47 | - public $content_sets = array(); |
|
48 | - |
|
49 | - /** |
|
50 | - * Associative array of attribute collection names to attribute |
|
51 | - * collection additions. More rarely used for adding attributes to |
|
52 | - * the global collections. Example is the StyleAttribute module adding |
|
53 | - * the style attribute to the Core. Corresponds to HTMLDefinition's |
|
54 | - * attr_collections->info, since the object's data is only info, |
|
55 | - * with extra behavior associated with it. |
|
56 | - */ |
|
57 | - public $attr_collections = array(); |
|
58 | - |
|
59 | - /** |
|
60 | - * Associative array of deprecated tag name to HTMLPurifier_TagTransform |
|
61 | - */ |
|
62 | - public $info_tag_transform = array(); |
|
63 | - |
|
64 | - /** |
|
65 | - * List of HTMLPurifier_AttrTransform to be performed before validation. |
|
66 | - */ |
|
67 | - public $info_attr_transform_pre = array(); |
|
68 | - |
|
69 | - /** |
|
70 | - * List of HTMLPurifier_AttrTransform to be performed after validation. |
|
71 | - */ |
|
72 | - public $info_attr_transform_post = array(); |
|
73 | - |
|
74 | - /** |
|
75 | - * List of HTMLPurifier_Injector to be performed during well-formedness fixing. |
|
76 | - * An injector will only be invoked if all of it's pre-requisites are met; |
|
77 | - * if an injector fails setup, there will be no error; it will simply be |
|
78 | - * silently disabled. |
|
79 | - */ |
|
80 | - public $info_injector = array(); |
|
81 | - |
|
82 | - /** |
|
83 | - * Boolean flag that indicates whether or not getChildDef is implemented. |
|
84 | - * For optimization reasons: may save a call to a function. Be sure |
|
85 | - * to set it if you do implement getChildDef(), otherwise it will have |
|
86 | - * no effect! |
|
87 | - */ |
|
88 | - public $defines_child_def = false; |
|
89 | - |
|
90 | - /** |
|
91 | - * Boolean flag whether or not this module is safe. If it is not safe, all |
|
92 | - * of its members are unsafe. Modules are safe by default (this might be |
|
93 | - * slightly dangerous, but it doesn't make much sense to force HTML Purifier, |
|
94 | - * which is based off of safe HTML, to explicitly say, "This is safe," even |
|
95 | - * though there are modules which are "unsafe") |
|
96 | - * |
|
97 | - * @note Previously, safety could be applied at an element level granularity. |
|
98 | - * We've removed this ability, so in order to add "unsafe" elements |
|
99 | - * or attributes, a dedicated module with this property set to false |
|
100 | - * must be used. |
|
101 | - */ |
|
102 | - public $safe = true; |
|
103 | - |
|
104 | - /** |
|
105 | - * Retrieves a proper HTMLPurifier_ChildDef subclass based on |
|
106 | - * content_model and content_model_type member variables of |
|
107 | - * the HTMLPurifier_ElementDef class. There is a similar function |
|
108 | - * in HTMLPurifier_HTMLDefinition. |
|
109 | - * @param $def HTMLPurifier_ElementDef instance |
|
110 | - * @return HTMLPurifier_ChildDef subclass |
|
111 | - */ |
|
112 | - public function getChildDef($def) {return false;} |
|
113 | - |
|
114 | - // -- Convenience ----------------------------------------------------- |
|
115 | - |
|
116 | - /** |
|
117 | - * Convenience function that sets up a new element |
|
118 | - * @param $element Name of element to add |
|
119 | - * @param $type What content set should element be registered to? |
|
120 | - * Set as false to skip this step. |
|
121 | - * @param $contents Allowed children in form of: |
|
122 | - * "$content_model_type: $content_model" |
|
123 | - * @param $attr_includes What attribute collections to register to |
|
124 | - * element? |
|
125 | - * @param $attr What unique attributes does the element define? |
|
126 | - * @note See ElementDef for in-depth descriptions of these parameters. |
|
127 | - * @return Created element definition object, so you |
|
128 | - * can set advanced parameters |
|
129 | - */ |
|
130 | - public function addElement($element, $type, $contents, $attr_includes = array(), $attr = array()) { |
|
131 | - $this->elements[] = $element; |
|
132 | - // parse content_model |
|
133 | - list($content_model_type, $content_model) = $this->parseContents($contents); |
|
134 | - // merge in attribute inclusions |
|
135 | - $this->mergeInAttrIncludes($attr, $attr_includes); |
|
136 | - // add element to content sets |
|
137 | - if ($type) $this->addElementToContentSet($element, $type); |
|
138 | - // create element |
|
139 | - $this->info[$element] = HTMLPurifier_ElementDef::create( |
|
140 | - $content_model, $content_model_type, $attr |
|
141 | - ); |
|
142 | - // literal object $contents means direct child manipulation |
|
143 | - if (!is_string($contents)) $this->info[$element]->child = $contents; |
|
144 | - return $this->info[$element]; |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * Convenience function that creates a totally blank, non-standalone |
|
149 | - * element. |
|
150 | - * @param $element Name of element to create |
|
151 | - * @return Created element |
|
152 | - */ |
|
153 | - public function addBlankElement($element) { |
|
154 | - if (!isset($this->info[$element])) { |
|
155 | - $this->elements[] = $element; |
|
156 | - $this->info[$element] = new HTMLPurifier_ElementDef(); |
|
157 | - $this->info[$element]->standalone = false; |
|
158 | - } else { |
|
159 | - trigger_error("Definition for $element already exists in module, cannot redefine"); |
|
160 | - } |
|
161 | - return $this->info[$element]; |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * Convenience function that registers an element to a content set |
|
166 | - * @param Element to register |
|
167 | - * @param Name content set (warning: case sensitive, usually upper-case |
|
168 | - * first letter) |
|
169 | - */ |
|
170 | - public function addElementToContentSet($element, $type) { |
|
171 | - if (!isset($this->content_sets[$type])) $this->content_sets[$type] = ''; |
|
172 | - else $this->content_sets[$type] .= ' | '; |
|
173 | - $this->content_sets[$type] .= $element; |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * Convenience function that transforms single-string contents |
|
178 | - * into separate content model and content model type |
|
179 | - * @param $contents Allowed children in form of: |
|
180 | - * "$content_model_type: $content_model" |
|
181 | - * @note If contents is an object, an array of two nulls will be |
|
182 | - * returned, and the callee needs to take the original $contents |
|
183 | - * and use it directly. |
|
184 | - */ |
|
185 | - public function parseContents($contents) { |
|
186 | - if (!is_string($contents)) return array(null, null); // defer |
|
187 | - switch ($contents) { |
|
188 | - // check for shorthand content model forms |
|
189 | - case 'Empty': |
|
190 | - return array('empty', ''); |
|
191 | - case 'Inline': |
|
192 | - return array('optional', 'Inline | #PCDATA'); |
|
193 | - case 'Flow': |
|
194 | - return array('optional', 'Flow | #PCDATA'); |
|
195 | - } |
|
196 | - list($content_model_type, $content_model) = explode(':', $contents); |
|
197 | - $content_model_type = strtolower(trim($content_model_type)); |
|
198 | - $content_model = trim($content_model); |
|
199 | - return array($content_model_type, $content_model); |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * Convenience function that merges a list of attribute includes into |
|
204 | - * an attribute array. |
|
205 | - * @param $attr Reference to attr array to modify |
|
206 | - * @param $attr_includes Array of includes / string include to merge in |
|
207 | - */ |
|
208 | - public function mergeInAttrIncludes(&$attr, $attr_includes) { |
|
209 | - if (!is_array($attr_includes)) { |
|
210 | - if (empty($attr_includes)) $attr_includes = array(); |
|
211 | - else $attr_includes = array($attr_includes); |
|
212 | - } |
|
213 | - $attr[0] = $attr_includes; |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * Convenience function that generates a lookup table with boolean |
|
218 | - * true as value. |
|
219 | - * @param $list List of values to turn into a lookup |
|
220 | - * @note You can also pass an arbitrary number of arguments in |
|
221 | - * place of the regular argument |
|
222 | - * @return Lookup array equivalent of list |
|
223 | - */ |
|
224 | - public function makeLookup($list) { |
|
225 | - if (is_string($list)) $list = func_get_args(); |
|
226 | - $ret = array(); |
|
227 | - foreach ($list as $value) { |
|
228 | - if (is_null($value)) continue; |
|
229 | - $ret[$value] = true; |
|
230 | - } |
|
231 | - return $ret; |
|
232 | - } |
|
233 | - |
|
234 | - /** |
|
235 | - * Lazy load construction of the module after determining whether |
|
236 | - * or not it's needed, and also when a finalized configuration object |
|
237 | - * is available. |
|
238 | - * @param $config Instance of HTMLPurifier_Config |
|
239 | - */ |
|
240 | - public function setup($config) {} |
|
21 | + // -- Overloadable ---------------------------------------------------- |
|
22 | + |
|
23 | + /** |
|
24 | + * Short unique string identifier of the module |
|
25 | + */ |
|
26 | + public $name; |
|
27 | + |
|
28 | + /** |
|
29 | + * Informally, a list of elements this module changes. Not used in |
|
30 | + * any significant way. |
|
31 | + */ |
|
32 | + public $elements = array(); |
|
33 | + |
|
34 | + /** |
|
35 | + * Associative array of element names to element definitions. |
|
36 | + * Some definitions may be incomplete, to be merged in later |
|
37 | + * with the full definition. |
|
38 | + */ |
|
39 | + public $info = array(); |
|
40 | + |
|
41 | + /** |
|
42 | + * Associative array of content set names to content set additions. |
|
43 | + * This is commonly used to, say, add an A element to the Inline |
|
44 | + * content set. This corresponds to an internal variable $content_sets |
|
45 | + * and NOT info_content_sets member variable of HTMLDefinition. |
|
46 | + */ |
|
47 | + public $content_sets = array(); |
|
48 | + |
|
49 | + /** |
|
50 | + * Associative array of attribute collection names to attribute |
|
51 | + * collection additions. More rarely used for adding attributes to |
|
52 | + * the global collections. Example is the StyleAttribute module adding |
|
53 | + * the style attribute to the Core. Corresponds to HTMLDefinition's |
|
54 | + * attr_collections->info, since the object's data is only info, |
|
55 | + * with extra behavior associated with it. |
|
56 | + */ |
|
57 | + public $attr_collections = array(); |
|
58 | + |
|
59 | + /** |
|
60 | + * Associative array of deprecated tag name to HTMLPurifier_TagTransform |
|
61 | + */ |
|
62 | + public $info_tag_transform = array(); |
|
63 | + |
|
64 | + /** |
|
65 | + * List of HTMLPurifier_AttrTransform to be performed before validation. |
|
66 | + */ |
|
67 | + public $info_attr_transform_pre = array(); |
|
68 | + |
|
69 | + /** |
|
70 | + * List of HTMLPurifier_AttrTransform to be performed after validation. |
|
71 | + */ |
|
72 | + public $info_attr_transform_post = array(); |
|
73 | + |
|
74 | + /** |
|
75 | + * List of HTMLPurifier_Injector to be performed during well-formedness fixing. |
|
76 | + * An injector will only be invoked if all of it's pre-requisites are met; |
|
77 | + * if an injector fails setup, there will be no error; it will simply be |
|
78 | + * silently disabled. |
|
79 | + */ |
|
80 | + public $info_injector = array(); |
|
81 | + |
|
82 | + /** |
|
83 | + * Boolean flag that indicates whether or not getChildDef is implemented. |
|
84 | + * For optimization reasons: may save a call to a function. Be sure |
|
85 | + * to set it if you do implement getChildDef(), otherwise it will have |
|
86 | + * no effect! |
|
87 | + */ |
|
88 | + public $defines_child_def = false; |
|
89 | + |
|
90 | + /** |
|
91 | + * Boolean flag whether or not this module is safe. If it is not safe, all |
|
92 | + * of its members are unsafe. Modules are safe by default (this might be |
|
93 | + * slightly dangerous, but it doesn't make much sense to force HTML Purifier, |
|
94 | + * which is based off of safe HTML, to explicitly say, "This is safe," even |
|
95 | + * though there are modules which are "unsafe") |
|
96 | + * |
|
97 | + * @note Previously, safety could be applied at an element level granularity. |
|
98 | + * We've removed this ability, so in order to add "unsafe" elements |
|
99 | + * or attributes, a dedicated module with this property set to false |
|
100 | + * must be used. |
|
101 | + */ |
|
102 | + public $safe = true; |
|
103 | + |
|
104 | + /** |
|
105 | + * Retrieves a proper HTMLPurifier_ChildDef subclass based on |
|
106 | + * content_model and content_model_type member variables of |
|
107 | + * the HTMLPurifier_ElementDef class. There is a similar function |
|
108 | + * in HTMLPurifier_HTMLDefinition. |
|
109 | + * @param $def HTMLPurifier_ElementDef instance |
|
110 | + * @return HTMLPurifier_ChildDef subclass |
|
111 | + */ |
|
112 | + public function getChildDef($def) {return false;} |
|
113 | + |
|
114 | + // -- Convenience ----------------------------------------------------- |
|
115 | + |
|
116 | + /** |
|
117 | + * Convenience function that sets up a new element |
|
118 | + * @param $element Name of element to add |
|
119 | + * @param $type What content set should element be registered to? |
|
120 | + * Set as false to skip this step. |
|
121 | + * @param $contents Allowed children in form of: |
|
122 | + * "$content_model_type: $content_model" |
|
123 | + * @param $attr_includes What attribute collections to register to |
|
124 | + * element? |
|
125 | + * @param $attr What unique attributes does the element define? |
|
126 | + * @note See ElementDef for in-depth descriptions of these parameters. |
|
127 | + * @return Created element definition object, so you |
|
128 | + * can set advanced parameters |
|
129 | + */ |
|
130 | + public function addElement($element, $type, $contents, $attr_includes = array(), $attr = array()) { |
|
131 | + $this->elements[] = $element; |
|
132 | + // parse content_model |
|
133 | + list($content_model_type, $content_model) = $this->parseContents($contents); |
|
134 | + // merge in attribute inclusions |
|
135 | + $this->mergeInAttrIncludes($attr, $attr_includes); |
|
136 | + // add element to content sets |
|
137 | + if ($type) $this->addElementToContentSet($element, $type); |
|
138 | + // create element |
|
139 | + $this->info[$element] = HTMLPurifier_ElementDef::create( |
|
140 | + $content_model, $content_model_type, $attr |
|
141 | + ); |
|
142 | + // literal object $contents means direct child manipulation |
|
143 | + if (!is_string($contents)) $this->info[$element]->child = $contents; |
|
144 | + return $this->info[$element]; |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * Convenience function that creates a totally blank, non-standalone |
|
149 | + * element. |
|
150 | + * @param $element Name of element to create |
|
151 | + * @return Created element |
|
152 | + */ |
|
153 | + public function addBlankElement($element) { |
|
154 | + if (!isset($this->info[$element])) { |
|
155 | + $this->elements[] = $element; |
|
156 | + $this->info[$element] = new HTMLPurifier_ElementDef(); |
|
157 | + $this->info[$element]->standalone = false; |
|
158 | + } else { |
|
159 | + trigger_error("Definition for $element already exists in module, cannot redefine"); |
|
160 | + } |
|
161 | + return $this->info[$element]; |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * Convenience function that registers an element to a content set |
|
166 | + * @param Element to register |
|
167 | + * @param Name content set (warning: case sensitive, usually upper-case |
|
168 | + * first letter) |
|
169 | + */ |
|
170 | + public function addElementToContentSet($element, $type) { |
|
171 | + if (!isset($this->content_sets[$type])) $this->content_sets[$type] = ''; |
|
172 | + else $this->content_sets[$type] .= ' | '; |
|
173 | + $this->content_sets[$type] .= $element; |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * Convenience function that transforms single-string contents |
|
178 | + * into separate content model and content model type |
|
179 | + * @param $contents Allowed children in form of: |
|
180 | + * "$content_model_type: $content_model" |
|
181 | + * @note If contents is an object, an array of two nulls will be |
|
182 | + * returned, and the callee needs to take the original $contents |
|
183 | + * and use it directly. |
|
184 | + */ |
|
185 | + public function parseContents($contents) { |
|
186 | + if (!is_string($contents)) return array(null, null); // defer |
|
187 | + switch ($contents) { |
|
188 | + // check for shorthand content model forms |
|
189 | + case 'Empty': |
|
190 | + return array('empty', ''); |
|
191 | + case 'Inline': |
|
192 | + return array('optional', 'Inline | #PCDATA'); |
|
193 | + case 'Flow': |
|
194 | + return array('optional', 'Flow | #PCDATA'); |
|
195 | + } |
|
196 | + list($content_model_type, $content_model) = explode(':', $contents); |
|
197 | + $content_model_type = strtolower(trim($content_model_type)); |
|
198 | + $content_model = trim($content_model); |
|
199 | + return array($content_model_type, $content_model); |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * Convenience function that merges a list of attribute includes into |
|
204 | + * an attribute array. |
|
205 | + * @param $attr Reference to attr array to modify |
|
206 | + * @param $attr_includes Array of includes / string include to merge in |
|
207 | + */ |
|
208 | + public function mergeInAttrIncludes(&$attr, $attr_includes) { |
|
209 | + if (!is_array($attr_includes)) { |
|
210 | + if (empty($attr_includes)) $attr_includes = array(); |
|
211 | + else $attr_includes = array($attr_includes); |
|
212 | + } |
|
213 | + $attr[0] = $attr_includes; |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * Convenience function that generates a lookup table with boolean |
|
218 | + * true as value. |
|
219 | + * @param $list List of values to turn into a lookup |
|
220 | + * @note You can also pass an arbitrary number of arguments in |
|
221 | + * place of the regular argument |
|
222 | + * @return Lookup array equivalent of list |
|
223 | + */ |
|
224 | + public function makeLookup($list) { |
|
225 | + if (is_string($list)) $list = func_get_args(); |
|
226 | + $ret = array(); |
|
227 | + foreach ($list as $value) { |
|
228 | + if (is_null($value)) continue; |
|
229 | + $ret[$value] = true; |
|
230 | + } |
|
231 | + return $ret; |
|
232 | + } |
|
233 | + |
|
234 | + /** |
|
235 | + * Lazy load construction of the module after determining whether |
|
236 | + * or not it's needed, and also when a finalized configuration object |
|
237 | + * is available. |
|
238 | + * @param $config Instance of HTMLPurifier_Config |
|
239 | + */ |
|
240 | + public function setup($config) {} |
|
241 | 241 | |
242 | 242 | } |
243 | 243 |
@@ -109,7 +109,7 @@ |
||
109 | 109 | * @param $def HTMLPurifier_ElementDef instance |
110 | 110 | * @return HTMLPurifier_ChildDef subclass |
111 | 111 | */ |
112 | - public function getChildDef($def) {return false;} |
|
112 | + public function getChildDef($def) {return false; } |
|
113 | 113 | |
114 | 114 | // -- Convenience ----------------------------------------------------- |
115 | 115 |
@@ -134,13 +134,17 @@ discard block |
||
134 | 134 | // merge in attribute inclusions |
135 | 135 | $this->mergeInAttrIncludes($attr, $attr_includes); |
136 | 136 | // add element to content sets |
137 | - if ($type) $this->addElementToContentSet($element, $type); |
|
137 | + if ($type) { |
|
138 | + $this->addElementToContentSet($element, $type); |
|
139 | + } |
|
138 | 140 | // create element |
139 | 141 | $this->info[$element] = HTMLPurifier_ElementDef::create( |
140 | 142 | $content_model, $content_model_type, $attr |
141 | 143 | ); |
142 | 144 | // literal object $contents means direct child manipulation |
143 | - if (!is_string($contents)) $this->info[$element]->child = $contents; |
|
145 | + if (!is_string($contents)) { |
|
146 | + $this->info[$element]->child = $contents; |
|
147 | + } |
|
144 | 148 | return $this->info[$element]; |
145 | 149 | } |
146 | 150 | |
@@ -168,8 +172,11 @@ discard block |
||
168 | 172 | * first letter) |
169 | 173 | */ |
170 | 174 | public function addElementToContentSet($element, $type) { |
171 | - if (!isset($this->content_sets[$type])) $this->content_sets[$type] = ''; |
|
172 | - else $this->content_sets[$type] .= ' | '; |
|
175 | + if (!isset($this->content_sets[$type])) { |
|
176 | + $this->content_sets[$type] = ''; |
|
177 | + } else { |
|
178 | + $this->content_sets[$type] .= ' | '; |
|
179 | + } |
|
173 | 180 | $this->content_sets[$type] .= $element; |
174 | 181 | } |
175 | 182 | |
@@ -183,7 +190,10 @@ discard block |
||
183 | 190 | * and use it directly. |
184 | 191 | */ |
185 | 192 | public function parseContents($contents) { |
186 | - if (!is_string($contents)) return array(null, null); // defer |
|
193 | + if (!is_string($contents)) { |
|
194 | + return array(null, null); |
|
195 | + } |
|
196 | + // defer |
|
187 | 197 | switch ($contents) { |
188 | 198 | // check for shorthand content model forms |
189 | 199 | case 'Empty': |
@@ -207,8 +217,11 @@ discard block |
||
207 | 217 | */ |
208 | 218 | public function mergeInAttrIncludes(&$attr, $attr_includes) { |
209 | 219 | if (!is_array($attr_includes)) { |
210 | - if (empty($attr_includes)) $attr_includes = array(); |
|
211 | - else $attr_includes = array($attr_includes); |
|
220 | + if (empty($attr_includes)) { |
|
221 | + $attr_includes = array(); |
|
222 | + } else { |
|
223 | + $attr_includes = array($attr_includes); |
|
224 | + } |
|
212 | 225 | } |
213 | 226 | $attr[0] = $attr_includes; |
214 | 227 | } |
@@ -222,10 +235,14 @@ discard block |
||
222 | 235 | * @return Lookup array equivalent of list |
223 | 236 | */ |
224 | 237 | public function makeLookup($list) { |
225 | - if (is_string($list)) $list = func_get_args(); |
|
238 | + if (is_string($list)) { |
|
239 | + $list = func_get_args(); |
|
240 | + } |
|
226 | 241 | $ret = array(); |
227 | 242 | foreach ($list as $value) { |
228 | - if (is_null($value)) continue; |
|
243 | + if (is_null($value)) { |
|
244 | + continue; |
|
245 | + } |
|
229 | 246 | $ret[$value] = true; |
230 | 247 | } |
231 | 248 | return $ret; |
@@ -7,24 +7,24 @@ |
||
7 | 7 | class HTMLPurifier_HTMLModule_Bdo extends HTMLPurifier_HTMLModule |
8 | 8 | { |
9 | 9 | |
10 | - public $name = 'Bdo'; |
|
11 | - public $attr_collections = array( |
|
12 | - 'I18N' => array('dir' => false) |
|
13 | - ); |
|
10 | + public $name = 'Bdo'; |
|
11 | + public $attr_collections = array( |
|
12 | + 'I18N' => array('dir' => false) |
|
13 | + ); |
|
14 | 14 | |
15 | - public function setup($config) { |
|
16 | - $bdo = $this->addElement( |
|
17 | - 'bdo', 'Inline', 'Inline', array('Core', 'Lang'), |
|
18 | - array( |
|
19 | - 'dir' => 'Enum#ltr,rtl', // required |
|
20 | - // The Abstract Module specification has the attribute |
|
21 | - // inclusions wrong for bdo: bdo allows Lang |
|
22 | - ) |
|
23 | - ); |
|
24 | - $bdo->attr_transform_post['required-dir'] = new HTMLPurifier_AttrTransform_BdoDir(); |
|
15 | + public function setup($config) { |
|
16 | + $bdo = $this->addElement( |
|
17 | + 'bdo', 'Inline', 'Inline', array('Core', 'Lang'), |
|
18 | + array( |
|
19 | + 'dir' => 'Enum#ltr,rtl', // required |
|
20 | + // The Abstract Module specification has the attribute |
|
21 | + // inclusions wrong for bdo: bdo allows Lang |
|
22 | + ) |
|
23 | + ); |
|
24 | + $bdo->attr_transform_post['required-dir'] = new HTMLPurifier_AttrTransform_BdoDir(); |
|
25 | 25 | |
26 | - $this->attr_collections['I18N']['dir'] = 'Enum#ltr,rtl'; |
|
27 | - } |
|
26 | + $this->attr_collections['I18N']['dir'] = 'Enum#ltr,rtl'; |
|
27 | + } |
|
28 | 28 | |
29 | 29 | } |
30 | 30 |
@@ -2,24 +2,24 @@ |
||
2 | 2 | |
3 | 3 | class HTMLPurifier_HTMLModule_CommonAttributes extends HTMLPurifier_HTMLModule |
4 | 4 | { |
5 | - public $name = 'CommonAttributes'; |
|
5 | + public $name = 'CommonAttributes'; |
|
6 | 6 | |
7 | - public $attr_collections = array( |
|
8 | - 'Core' => array( |
|
9 | - 0 => array('Style'), |
|
10 | - // 'xml:space' => false, |
|
11 | - 'class' => 'Class', |
|
12 | - 'id' => 'ID', |
|
13 | - 'title' => 'CDATA', |
|
14 | - ), |
|
15 | - 'Lang' => array(), |
|
16 | - 'I18N' => array( |
|
17 | - 0 => array('Lang'), // proprietary, for xml:lang/lang |
|
18 | - ), |
|
19 | - 'Common' => array( |
|
20 | - 0 => array('Core', 'I18N') |
|
21 | - ) |
|
22 | - ); |
|
7 | + public $attr_collections = array( |
|
8 | + 'Core' => array( |
|
9 | + 0 => array('Style'), |
|
10 | + // 'xml:space' => false, |
|
11 | + 'class' => 'Class', |
|
12 | + 'id' => 'ID', |
|
13 | + 'title' => 'CDATA', |
|
14 | + ), |
|
15 | + 'Lang' => array(), |
|
16 | + 'I18N' => array( |
|
17 | + 0 => array('Lang'), // proprietary, for xml:lang/lang |
|
18 | + ), |
|
19 | + 'Common' => array( |
|
20 | + 0 => array('Core', 'I18N') |
|
21 | + ) |
|
22 | + ); |
|
23 | 23 | |
24 | 24 | } |
25 | 25 |