@@ -15,56 +15,56 @@ |
||
15 | 15 | class HTMLPurifier_HTMLModule_Text extends HTMLPurifier_HTMLModule |
16 | 16 | { |
17 | 17 | |
18 | - public $name = 'Text'; |
|
19 | - public $content_sets = array( |
|
20 | - 'Flow' => 'Heading | Block | Inline' |
|
21 | - ); |
|
18 | + public $name = 'Text'; |
|
19 | + public $content_sets = array( |
|
20 | + 'Flow' => 'Heading | Block | Inline' |
|
21 | + ); |
|
22 | 22 | |
23 | - public function setup($config) { |
|
23 | + public function setup($config) { |
|
24 | 24 | |
25 | - // Inline Phrasal ------------------------------------------------- |
|
26 | - $this->addElement('abbr', 'Inline', 'Inline', 'Common'); |
|
27 | - $this->addElement('acronym', 'Inline', 'Inline', 'Common'); |
|
28 | - $this->addElement('cite', 'Inline', 'Inline', 'Common'); |
|
29 | - $this->addElement('dfn', 'Inline', 'Inline', 'Common'); |
|
30 | - $this->addElement('kbd', 'Inline', 'Inline', 'Common'); |
|
31 | - $this->addElement('q', 'Inline', 'Inline', 'Common', array('cite' => 'URI')); |
|
32 | - $this->addElement('samp', 'Inline', 'Inline', 'Common'); |
|
33 | - $this->addElement('var', 'Inline', 'Inline', 'Common'); |
|
25 | + // Inline Phrasal ------------------------------------------------- |
|
26 | + $this->addElement('abbr', 'Inline', 'Inline', 'Common'); |
|
27 | + $this->addElement('acronym', 'Inline', 'Inline', 'Common'); |
|
28 | + $this->addElement('cite', 'Inline', 'Inline', 'Common'); |
|
29 | + $this->addElement('dfn', 'Inline', 'Inline', 'Common'); |
|
30 | + $this->addElement('kbd', 'Inline', 'Inline', 'Common'); |
|
31 | + $this->addElement('q', 'Inline', 'Inline', 'Common', array('cite' => 'URI')); |
|
32 | + $this->addElement('samp', 'Inline', 'Inline', 'Common'); |
|
33 | + $this->addElement('var', 'Inline', 'Inline', 'Common'); |
|
34 | 34 | |
35 | - $em = $this->addElement('em', 'Inline', 'Inline', 'Common'); |
|
36 | - $em->formatting = true; |
|
35 | + $em = $this->addElement('em', 'Inline', 'Inline', 'Common'); |
|
36 | + $em->formatting = true; |
|
37 | 37 | |
38 | - $strong = $this->addElement('strong', 'Inline', 'Inline', 'Common'); |
|
39 | - $strong->formatting = true; |
|
38 | + $strong = $this->addElement('strong', 'Inline', 'Inline', 'Common'); |
|
39 | + $strong->formatting = true; |
|
40 | 40 | |
41 | - $code = $this->addElement('code', 'Inline', 'Inline', 'Common'); |
|
42 | - $code->formatting = true; |
|
41 | + $code = $this->addElement('code', 'Inline', 'Inline', 'Common'); |
|
42 | + $code->formatting = true; |
|
43 | 43 | |
44 | - // Inline Structural ---------------------------------------------- |
|
45 | - $this->addElement('span', 'Inline', 'Inline', 'Common'); |
|
46 | - $this->addElement('br', 'Inline', 'Empty', 'Core'); |
|
44 | + // Inline Structural ---------------------------------------------- |
|
45 | + $this->addElement('span', 'Inline', 'Inline', 'Common'); |
|
46 | + $this->addElement('br', 'Inline', 'Empty', 'Core'); |
|
47 | 47 | |
48 | - // Block Phrasal -------------------------------------------------- |
|
49 | - $this->addElement('address', 'Block', 'Inline', 'Common'); |
|
50 | - $this->addElement('blockquote', 'Block', 'Optional: Heading | Block | List', 'Common', array('cite' => 'URI') ); |
|
51 | - $pre = $this->addElement('pre', 'Block', 'Inline', 'Common'); |
|
52 | - $pre->excludes = $this->makeLookup( |
|
53 | - 'img', 'big', 'small', 'object', 'applet', 'font', 'basefont' ); |
|
54 | - $this->addElement('h1', 'Heading', 'Inline', 'Common'); |
|
55 | - $this->addElement('h2', 'Heading', 'Inline', 'Common'); |
|
56 | - $this->addElement('h3', 'Heading', 'Inline', 'Common'); |
|
57 | - $this->addElement('h4', 'Heading', 'Inline', 'Common'); |
|
58 | - $this->addElement('h5', 'Heading', 'Inline', 'Common'); |
|
59 | - $this->addElement('h6', 'Heading', 'Inline', 'Common'); |
|
48 | + // Block Phrasal -------------------------------------------------- |
|
49 | + $this->addElement('address', 'Block', 'Inline', 'Common'); |
|
50 | + $this->addElement('blockquote', 'Block', 'Optional: Heading | Block | List', 'Common', array('cite' => 'URI') ); |
|
51 | + $pre = $this->addElement('pre', 'Block', 'Inline', 'Common'); |
|
52 | + $pre->excludes = $this->makeLookup( |
|
53 | + 'img', 'big', 'small', 'object', 'applet', 'font', 'basefont' ); |
|
54 | + $this->addElement('h1', 'Heading', 'Inline', 'Common'); |
|
55 | + $this->addElement('h2', 'Heading', 'Inline', 'Common'); |
|
56 | + $this->addElement('h3', 'Heading', 'Inline', 'Common'); |
|
57 | + $this->addElement('h4', 'Heading', 'Inline', 'Common'); |
|
58 | + $this->addElement('h5', 'Heading', 'Inline', 'Common'); |
|
59 | + $this->addElement('h6', 'Heading', 'Inline', 'Common'); |
|
60 | 60 | |
61 | - // Block Structural ----------------------------------------------- |
|
62 | - $p = $this->addElement('p', 'Block', 'Inline', 'Common'); |
|
63 | - $p->autoclose = array_flip(array("address", "blockquote", "center", "dir", "div", "dl", "fieldset", "ol", "p", "ul")); |
|
61 | + // Block Structural ----------------------------------------------- |
|
62 | + $p = $this->addElement('p', 'Block', 'Inline', 'Common'); |
|
63 | + $p->autoclose = array_flip(array("address", "blockquote", "center", "dir", "div", "dl", "fieldset", "ol", "p", "ul")); |
|
64 | 64 | |
65 | - $this->addElement('div', 'Block', 'Flow', 'Common'); |
|
65 | + $this->addElement('div', 'Block', 'Flow', 'Common'); |
|
66 | 66 | |
67 | - } |
|
67 | + } |
|
68 | 68 | |
69 | 69 | } |
70 | 70 |
@@ -23,31 +23,31 @@ |
||
23 | 23 | public function setup($config) { |
24 | 24 | |
25 | 25 | // Inline Phrasal ------------------------------------------------- |
26 | - $this->addElement('abbr', 'Inline', 'Inline', 'Common'); |
|
26 | + $this->addElement('abbr', 'Inline', 'Inline', 'Common'); |
|
27 | 27 | $this->addElement('acronym', 'Inline', 'Inline', 'Common'); |
28 | - $this->addElement('cite', 'Inline', 'Inline', 'Common'); |
|
29 | - $this->addElement('dfn', 'Inline', 'Inline', 'Common'); |
|
30 | - $this->addElement('kbd', 'Inline', 'Inline', 'Common'); |
|
31 | - $this->addElement('q', 'Inline', 'Inline', 'Common', array('cite' => 'URI')); |
|
32 | - $this->addElement('samp', 'Inline', 'Inline', 'Common'); |
|
33 | - $this->addElement('var', 'Inline', 'Inline', 'Common'); |
|
28 | + $this->addElement('cite', 'Inline', 'Inline', 'Common'); |
|
29 | + $this->addElement('dfn', 'Inline', 'Inline', 'Common'); |
|
30 | + $this->addElement('kbd', 'Inline', 'Inline', 'Common'); |
|
31 | + $this->addElement('q', 'Inline', 'Inline', 'Common', array('cite' => 'URI')); |
|
32 | + $this->addElement('samp', 'Inline', 'Inline', 'Common'); |
|
33 | + $this->addElement('var', 'Inline', 'Inline', 'Common'); |
|
34 | 34 | |
35 | - $em = $this->addElement('em', 'Inline', 'Inline', 'Common'); |
|
35 | + $em = $this->addElement('em', 'Inline', 'Inline', 'Common'); |
|
36 | 36 | $em->formatting = true; |
37 | 37 | |
38 | - $strong = $this->addElement('strong', 'Inline', 'Inline', 'Common'); |
|
38 | + $strong = $this->addElement('strong', 'Inline', 'Inline', 'Common'); |
|
39 | 39 | $strong->formatting = true; |
40 | 40 | |
41 | - $code = $this->addElement('code', 'Inline', 'Inline', 'Common'); |
|
41 | + $code = $this->addElement('code', 'Inline', 'Inline', 'Common'); |
|
42 | 42 | $code->formatting = true; |
43 | 43 | |
44 | 44 | // Inline Structural ---------------------------------------------- |
45 | 45 | $this->addElement('span', 'Inline', 'Inline', 'Common'); |
46 | - $this->addElement('br', 'Inline', 'Empty', 'Core'); |
|
46 | + $this->addElement('br', 'Inline', 'Empty', 'Core'); |
|
47 | 47 | |
48 | 48 | // Block Phrasal -------------------------------------------------- |
49 | - $this->addElement('address', 'Block', 'Inline', 'Common'); |
|
50 | - $this->addElement('blockquote', 'Block', 'Optional: Heading | Block | List', 'Common', array('cite' => 'URI') ); |
|
49 | + $this->addElement('address', 'Block', 'Inline', 'Common'); |
|
50 | + $this->addElement('blockquote', 'Block', 'Optional: Heading | Block | List', 'Common', array('cite' => 'URI')); |
|
51 | 51 | $pre = $this->addElement('pre', 'Block', 'Inline', 'Common'); |
52 | 52 | $pre->excludes = $this->makeLookup( |
53 | 53 | 'img', 'big', 'small', 'object', 'applet', 'font', 'basefont' ); |
@@ -8,199 +8,199 @@ |
||
8 | 8 | class HTMLPurifier_HTMLModule_Tidy extends HTMLPurifier_HTMLModule |
9 | 9 | { |
10 | 10 | |
11 | - /** |
|
12 | - * List of supported levels. Index zero is a special case "no fixes" |
|
13 | - * level. |
|
14 | - */ |
|
15 | - public $levels = array(0 => 'none', 'light', 'medium', 'heavy'); |
|
16 | - |
|
17 | - /** |
|
18 | - * Default level to place all fixes in. Disabled by default |
|
19 | - */ |
|
20 | - public $defaultLevel = null; |
|
21 | - |
|
22 | - /** |
|
23 | - * Lists of fixes used by getFixesForLevel(). Format is: |
|
24 | - * HTMLModule_Tidy->fixesForLevel[$level] = array('fix-1', 'fix-2'); |
|
25 | - */ |
|
26 | - public $fixesForLevel = array( |
|
27 | - 'light' => array(), |
|
28 | - 'medium' => array(), |
|
29 | - 'heavy' => array() |
|
30 | - ); |
|
31 | - |
|
32 | - /** |
|
33 | - * Lazy load constructs the module by determining the necessary |
|
34 | - * fixes to create and then delegating to the populate() function. |
|
35 | - * @todo Wildcard matching and error reporting when an added or |
|
36 | - * subtracted fix has no effect. |
|
37 | - */ |
|
38 | - public function setup($config) { |
|
39 | - |
|
40 | - // create fixes, initialize fixesForLevel |
|
41 | - $fixes = $this->makeFixes(); |
|
42 | - $this->makeFixesForLevel($fixes); |
|
43 | - |
|
44 | - // figure out which fixes to use |
|
45 | - $level = $config->get('HTML.TidyLevel'); |
|
46 | - $fixes_lookup = $this->getFixesForLevel($level); |
|
47 | - |
|
48 | - // get custom fix declarations: these need namespace processing |
|
49 | - $add_fixes = $config->get('HTML.TidyAdd'); |
|
50 | - $remove_fixes = $config->get('HTML.TidyRemove'); |
|
51 | - |
|
52 | - foreach ($fixes as $name => $fix) { |
|
53 | - // needs to be refactored a little to implement globbing |
|
54 | - if ( |
|
55 | - isset($remove_fixes[$name]) || |
|
56 | - (!isset($add_fixes[$name]) && !isset($fixes_lookup[$name])) |
|
57 | - ) { |
|
58 | - unset($fixes[$name]); |
|
59 | - } |
|
60 | - } |
|
61 | - |
|
62 | - // populate this module with necessary fixes |
|
63 | - $this->populate($fixes); |
|
64 | - |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * Retrieves all fixes per a level, returning fixes for that specific |
|
69 | - * level as well as all levels below it. |
|
70 | - * @param $level String level identifier, see $levels for valid values |
|
71 | - * @return Lookup up table of fixes |
|
72 | - */ |
|
73 | - public function getFixesForLevel($level) { |
|
74 | - if ($level == $this->levels[0]) { |
|
75 | - return array(); |
|
76 | - } |
|
77 | - $activated_levels = array(); |
|
78 | - for ($i = 1, $c = count($this->levels); $i < $c; $i++) { |
|
79 | - $activated_levels[] = $this->levels[$i]; |
|
80 | - if ($this->levels[$i] == $level) break; |
|
81 | - } |
|
82 | - if ($i == $c) { |
|
83 | - trigger_error( |
|
84 | - 'Tidy level ' . htmlspecialchars($level) . ' not recognized', |
|
85 | - E_USER_WARNING |
|
86 | - ); |
|
87 | - return array(); |
|
88 | - } |
|
89 | - $ret = array(); |
|
90 | - foreach ($activated_levels as $level) { |
|
91 | - foreach ($this->fixesForLevel[$level] as $fix) { |
|
92 | - $ret[$fix] = true; |
|
93 | - } |
|
94 | - } |
|
95 | - return $ret; |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Dynamically populates the $fixesForLevel member variable using |
|
100 | - * the fixes array. It may be custom overloaded, used in conjunction |
|
101 | - * with $defaultLevel, or not used at all. |
|
102 | - */ |
|
103 | - public function makeFixesForLevel($fixes) { |
|
104 | - if (!isset($this->defaultLevel)) return; |
|
105 | - if (!isset($this->fixesForLevel[$this->defaultLevel])) { |
|
106 | - trigger_error( |
|
107 | - 'Default level ' . $this->defaultLevel . ' does not exist', |
|
108 | - E_USER_ERROR |
|
109 | - ); |
|
110 | - return; |
|
111 | - } |
|
112 | - $this->fixesForLevel[$this->defaultLevel] = array_keys($fixes); |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * Populates the module with transforms and other special-case code |
|
117 | - * based on a list of fixes passed to it |
|
118 | - * @param $lookup Lookup table of fixes to activate |
|
119 | - */ |
|
120 | - public function populate($fixes) { |
|
121 | - foreach ($fixes as $name => $fix) { |
|
122 | - // determine what the fix is for |
|
123 | - list($type, $params) = $this->getFixType($name); |
|
124 | - switch ($type) { |
|
125 | - case 'attr_transform_pre': |
|
126 | - case 'attr_transform_post': |
|
127 | - $attr = $params['attr']; |
|
128 | - if (isset($params['element'])) { |
|
129 | - $element = $params['element']; |
|
130 | - if (empty($this->info[$element])) { |
|
131 | - $e = $this->addBlankElement($element); |
|
132 | - } else { |
|
133 | - $e = $this->info[$element]; |
|
134 | - } |
|
135 | - } else { |
|
136 | - $type = "info_$type"; |
|
137 | - $e = $this; |
|
138 | - } |
|
139 | - // PHP does some weird parsing when I do |
|
140 | - // $e->$type[$attr], so I have to assign a ref. |
|
141 | - $f =& $e->$type; |
|
142 | - $f[$attr] = $fix; |
|
143 | - break; |
|
144 | - case 'tag_transform': |
|
145 | - $this->info_tag_transform[$params['element']] = $fix; |
|
146 | - break; |
|
147 | - case 'child': |
|
148 | - case 'content_model_type': |
|
149 | - $element = $params['element']; |
|
150 | - if (empty($this->info[$element])) { |
|
151 | - $e = $this->addBlankElement($element); |
|
152 | - } else { |
|
153 | - $e = $this->info[$element]; |
|
154 | - } |
|
155 | - $e->$type = $fix; |
|
156 | - break; |
|
157 | - default: |
|
158 | - trigger_error("Fix type $type not supported", E_USER_ERROR); |
|
159 | - break; |
|
160 | - } |
|
161 | - } |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * Parses a fix name and determines what kind of fix it is, as well |
|
166 | - * as other information defined by the fix |
|
167 | - * @param $name String name of fix |
|
168 | - * @return array(string $fix_type, array $fix_parameters) |
|
169 | - * @note $fix_parameters is type dependant, see populate() for usage |
|
170 | - * of these parameters |
|
171 | - */ |
|
172 | - public function getFixType($name) { |
|
173 | - // parse it |
|
174 | - $property = $attr = null; |
|
175 | - if (strpos($name, '#') !== false) list($name, $property) = explode('#', $name); |
|
176 | - if (strpos($name, '@') !== false) list($name, $attr) = explode('@', $name); |
|
177 | - |
|
178 | - // figure out the parameters |
|
179 | - $params = array(); |
|
180 | - if ($name !== '') $params['element'] = $name; |
|
181 | - if (!is_null($attr)) $params['attr'] = $attr; |
|
182 | - |
|
183 | - // special case: attribute transform |
|
184 | - if (!is_null($attr)) { |
|
185 | - if (is_null($property)) $property = 'pre'; |
|
186 | - $type = 'attr_transform_' . $property; |
|
187 | - return array($type, $params); |
|
188 | - } |
|
189 | - |
|
190 | - // special case: tag transform |
|
191 | - if (is_null($property)) { |
|
192 | - return array('tag_transform', $params); |
|
193 | - } |
|
194 | - |
|
195 | - return array($property, $params); |
|
196 | - |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * Defines all fixes the module will perform in a compact |
|
201 | - * associative array of fix name to fix implementation. |
|
202 | - */ |
|
203 | - public function makeFixes() {} |
|
11 | + /** |
|
12 | + * List of supported levels. Index zero is a special case "no fixes" |
|
13 | + * level. |
|
14 | + */ |
|
15 | + public $levels = array(0 => 'none', 'light', 'medium', 'heavy'); |
|
16 | + |
|
17 | + /** |
|
18 | + * Default level to place all fixes in. Disabled by default |
|
19 | + */ |
|
20 | + public $defaultLevel = null; |
|
21 | + |
|
22 | + /** |
|
23 | + * Lists of fixes used by getFixesForLevel(). Format is: |
|
24 | + * HTMLModule_Tidy->fixesForLevel[$level] = array('fix-1', 'fix-2'); |
|
25 | + */ |
|
26 | + public $fixesForLevel = array( |
|
27 | + 'light' => array(), |
|
28 | + 'medium' => array(), |
|
29 | + 'heavy' => array() |
|
30 | + ); |
|
31 | + |
|
32 | + /** |
|
33 | + * Lazy load constructs the module by determining the necessary |
|
34 | + * fixes to create and then delegating to the populate() function. |
|
35 | + * @todo Wildcard matching and error reporting when an added or |
|
36 | + * subtracted fix has no effect. |
|
37 | + */ |
|
38 | + public function setup($config) { |
|
39 | + |
|
40 | + // create fixes, initialize fixesForLevel |
|
41 | + $fixes = $this->makeFixes(); |
|
42 | + $this->makeFixesForLevel($fixes); |
|
43 | + |
|
44 | + // figure out which fixes to use |
|
45 | + $level = $config->get('HTML.TidyLevel'); |
|
46 | + $fixes_lookup = $this->getFixesForLevel($level); |
|
47 | + |
|
48 | + // get custom fix declarations: these need namespace processing |
|
49 | + $add_fixes = $config->get('HTML.TidyAdd'); |
|
50 | + $remove_fixes = $config->get('HTML.TidyRemove'); |
|
51 | + |
|
52 | + foreach ($fixes as $name => $fix) { |
|
53 | + // needs to be refactored a little to implement globbing |
|
54 | + if ( |
|
55 | + isset($remove_fixes[$name]) || |
|
56 | + (!isset($add_fixes[$name]) && !isset($fixes_lookup[$name])) |
|
57 | + ) { |
|
58 | + unset($fixes[$name]); |
|
59 | + } |
|
60 | + } |
|
61 | + |
|
62 | + // populate this module with necessary fixes |
|
63 | + $this->populate($fixes); |
|
64 | + |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * Retrieves all fixes per a level, returning fixes for that specific |
|
69 | + * level as well as all levels below it. |
|
70 | + * @param $level String level identifier, see $levels for valid values |
|
71 | + * @return Lookup up table of fixes |
|
72 | + */ |
|
73 | + public function getFixesForLevel($level) { |
|
74 | + if ($level == $this->levels[0]) { |
|
75 | + return array(); |
|
76 | + } |
|
77 | + $activated_levels = array(); |
|
78 | + for ($i = 1, $c = count($this->levels); $i < $c; $i++) { |
|
79 | + $activated_levels[] = $this->levels[$i]; |
|
80 | + if ($this->levels[$i] == $level) break; |
|
81 | + } |
|
82 | + if ($i == $c) { |
|
83 | + trigger_error( |
|
84 | + 'Tidy level ' . htmlspecialchars($level) . ' not recognized', |
|
85 | + E_USER_WARNING |
|
86 | + ); |
|
87 | + return array(); |
|
88 | + } |
|
89 | + $ret = array(); |
|
90 | + foreach ($activated_levels as $level) { |
|
91 | + foreach ($this->fixesForLevel[$level] as $fix) { |
|
92 | + $ret[$fix] = true; |
|
93 | + } |
|
94 | + } |
|
95 | + return $ret; |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Dynamically populates the $fixesForLevel member variable using |
|
100 | + * the fixes array. It may be custom overloaded, used in conjunction |
|
101 | + * with $defaultLevel, or not used at all. |
|
102 | + */ |
|
103 | + public function makeFixesForLevel($fixes) { |
|
104 | + if (!isset($this->defaultLevel)) return; |
|
105 | + if (!isset($this->fixesForLevel[$this->defaultLevel])) { |
|
106 | + trigger_error( |
|
107 | + 'Default level ' . $this->defaultLevel . ' does not exist', |
|
108 | + E_USER_ERROR |
|
109 | + ); |
|
110 | + return; |
|
111 | + } |
|
112 | + $this->fixesForLevel[$this->defaultLevel] = array_keys($fixes); |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * Populates the module with transforms and other special-case code |
|
117 | + * based on a list of fixes passed to it |
|
118 | + * @param $lookup Lookup table of fixes to activate |
|
119 | + */ |
|
120 | + public function populate($fixes) { |
|
121 | + foreach ($fixes as $name => $fix) { |
|
122 | + // determine what the fix is for |
|
123 | + list($type, $params) = $this->getFixType($name); |
|
124 | + switch ($type) { |
|
125 | + case 'attr_transform_pre': |
|
126 | + case 'attr_transform_post': |
|
127 | + $attr = $params['attr']; |
|
128 | + if (isset($params['element'])) { |
|
129 | + $element = $params['element']; |
|
130 | + if (empty($this->info[$element])) { |
|
131 | + $e = $this->addBlankElement($element); |
|
132 | + } else { |
|
133 | + $e = $this->info[$element]; |
|
134 | + } |
|
135 | + } else { |
|
136 | + $type = "info_$type"; |
|
137 | + $e = $this; |
|
138 | + } |
|
139 | + // PHP does some weird parsing when I do |
|
140 | + // $e->$type[$attr], so I have to assign a ref. |
|
141 | + $f =& $e->$type; |
|
142 | + $f[$attr] = $fix; |
|
143 | + break; |
|
144 | + case 'tag_transform': |
|
145 | + $this->info_tag_transform[$params['element']] = $fix; |
|
146 | + break; |
|
147 | + case 'child': |
|
148 | + case 'content_model_type': |
|
149 | + $element = $params['element']; |
|
150 | + if (empty($this->info[$element])) { |
|
151 | + $e = $this->addBlankElement($element); |
|
152 | + } else { |
|
153 | + $e = $this->info[$element]; |
|
154 | + } |
|
155 | + $e->$type = $fix; |
|
156 | + break; |
|
157 | + default: |
|
158 | + trigger_error("Fix type $type not supported", E_USER_ERROR); |
|
159 | + break; |
|
160 | + } |
|
161 | + } |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * Parses a fix name and determines what kind of fix it is, as well |
|
166 | + * as other information defined by the fix |
|
167 | + * @param $name String name of fix |
|
168 | + * @return array(string $fix_type, array $fix_parameters) |
|
169 | + * @note $fix_parameters is type dependant, see populate() for usage |
|
170 | + * of these parameters |
|
171 | + */ |
|
172 | + public function getFixType($name) { |
|
173 | + // parse it |
|
174 | + $property = $attr = null; |
|
175 | + if (strpos($name, '#') !== false) list($name, $property) = explode('#', $name); |
|
176 | + if (strpos($name, '@') !== false) list($name, $attr) = explode('@', $name); |
|
177 | + |
|
178 | + // figure out the parameters |
|
179 | + $params = array(); |
|
180 | + if ($name !== '') $params['element'] = $name; |
|
181 | + if (!is_null($attr)) $params['attr'] = $attr; |
|
182 | + |
|
183 | + // special case: attribute transform |
|
184 | + if (!is_null($attr)) { |
|
185 | + if (is_null($property)) $property = 'pre'; |
|
186 | + $type = 'attr_transform_' . $property; |
|
187 | + return array($type, $params); |
|
188 | + } |
|
189 | + |
|
190 | + // special case: tag transform |
|
191 | + if (is_null($property)) { |
|
192 | + return array('tag_transform', $params); |
|
193 | + } |
|
194 | + |
|
195 | + return array($property, $params); |
|
196 | + |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * Defines all fixes the module will perform in a compact |
|
201 | + * associative array of fix name to fix implementation. |
|
202 | + */ |
|
203 | + public function makeFixes() {} |
|
204 | 204 | |
205 | 205 | } |
206 | 206 |
@@ -77,7 +77,9 @@ discard block |
||
77 | 77 | $activated_levels = array(); |
78 | 78 | for ($i = 1, $c = count($this->levels); $i < $c; $i++) { |
79 | 79 | $activated_levels[] = $this->levels[$i]; |
80 | - if ($this->levels[$i] == $level) break; |
|
80 | + if ($this->levels[$i] == $level) { |
|
81 | + break; |
|
82 | + } |
|
81 | 83 | } |
82 | 84 | if ($i == $c) { |
83 | 85 | trigger_error( |
@@ -101,7 +103,9 @@ discard block |
||
101 | 103 | * with $defaultLevel, or not used at all. |
102 | 104 | */ |
103 | 105 | public function makeFixesForLevel($fixes) { |
104 | - if (!isset($this->defaultLevel)) return; |
|
106 | + if (!isset($this->defaultLevel)) { |
|
107 | + return; |
|
108 | + } |
|
105 | 109 | if (!isset($this->fixesForLevel[$this->defaultLevel])) { |
106 | 110 | trigger_error( |
107 | 111 | 'Default level ' . $this->defaultLevel . ' does not exist', |
@@ -172,17 +176,27 @@ discard block |
||
172 | 176 | public function getFixType($name) { |
173 | 177 | // parse it |
174 | 178 | $property = $attr = null; |
175 | - if (strpos($name, '#') !== false) list($name, $property) = explode('#', $name); |
|
176 | - if (strpos($name, '@') !== false) list($name, $attr) = explode('@', $name); |
|
179 | + if (strpos($name, '#') !== false) { |
|
180 | + list($name, $property) = explode('#', $name); |
|
181 | + } |
|
182 | + if (strpos($name, '@') !== false) { |
|
183 | + list($name, $attr) = explode('@', $name); |
|
184 | + } |
|
177 | 185 | |
178 | 186 | // figure out the parameters |
179 | 187 | $params = array(); |
180 | - if ($name !== '') $params['element'] = $name; |
|
181 | - if (!is_null($attr)) $params['attr'] = $attr; |
|
188 | + if ($name !== '') { |
|
189 | + $params['element'] = $name; |
|
190 | + } |
|
191 | + if (!is_null($attr)) { |
|
192 | + $params['attr'] = $attr; |
|
193 | + } |
|
182 | 194 | |
183 | 195 | // special case: attribute transform |
184 | 196 | if (!is_null($attr)) { |
185 | - if (is_null($property)) $property = 'pre'; |
|
197 | + if (is_null($property)) { |
|
198 | + $property = 'pre'; |
|
199 | + } |
|
186 | 200 | $type = 'attr_transform_' . $property; |
187 | 201 | return array($type, $params); |
188 | 202 | } |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | } |
82 | 82 | if ($i == $c) { |
83 | 83 | trigger_error( |
84 | - 'Tidy level ' . htmlspecialchars($level) . ' not recognized', |
|
84 | + 'Tidy level '.htmlspecialchars($level).' not recognized', |
|
85 | 85 | E_USER_WARNING |
86 | 86 | ); |
87 | 87 | return array(); |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | if (!isset($this->defaultLevel)) return; |
105 | 105 | if (!isset($this->fixesForLevel[$this->defaultLevel])) { |
106 | 106 | trigger_error( |
107 | - 'Default level ' . $this->defaultLevel . ' does not exist', |
|
107 | + 'Default level '.$this->defaultLevel.' does not exist', |
|
108 | 108 | E_USER_ERROR |
109 | 109 | ); |
110 | 110 | return; |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | } |
139 | 139 | // PHP does some weird parsing when I do |
140 | 140 | // $e->$type[$attr], so I have to assign a ref. |
141 | - $f =& $e->$type; |
|
141 | + $f = & $e->$type; |
|
142 | 142 | $f[$attr] = $fix; |
143 | 143 | break; |
144 | 144 | case 'tag_transform': |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | // special case: attribute transform |
184 | 184 | if (!is_null($attr)) { |
185 | 185 | if (is_null($property)) $property = 'pre'; |
186 | - $type = 'attr_transform_' . $property; |
|
186 | + $type = 'attr_transform_'.$property; |
|
187 | 187 | return array($type, $params); |
188 | 188 | } |
189 | 189 |
@@ -5,20 +5,20 @@ |
||
5 | 5 | */ |
6 | 6 | class HTMLPurifier_HTMLModule_Tidy_Name extends HTMLPurifier_HTMLModule_Tidy |
7 | 7 | { |
8 | - public $name = 'Tidy_Name'; |
|
9 | - public $defaultLevel = 'heavy'; |
|
10 | - public function makeFixes() { |
|
8 | + public $name = 'Tidy_Name'; |
|
9 | + public $defaultLevel = 'heavy'; |
|
10 | + public function makeFixes() { |
|
11 | 11 | |
12 | - $r = array(); |
|
12 | + $r = array(); |
|
13 | 13 | |
14 | - // @name for img, a ----------------------------------------------- |
|
15 | - // Technically, it's allowed even on strict, so we allow authors to use |
|
16 | - // it. However, it's deprecated in future versions of XHTML. |
|
17 | - $r['img@name'] = |
|
18 | - $r['a@name'] = new HTMLPurifier_AttrTransform_Name(); |
|
14 | + // @name for img, a ----------------------------------------------- |
|
15 | + // Technically, it's allowed even on strict, so we allow authors to use |
|
16 | + // it. However, it's deprecated in future versions of XHTML. |
|
17 | + $r['img@name'] = |
|
18 | + $r['a@name'] = new HTMLPurifier_AttrTransform_Name(); |
|
19 | 19 | |
20 | - return $r; |
|
21 | - } |
|
20 | + return $r; |
|
21 | + } |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | // vim: et sw=4 sts=4 |
@@ -3,21 +3,21 @@ |
||
3 | 3 | class HTMLPurifier_HTMLModule_Tidy_Proprietary extends HTMLPurifier_HTMLModule_Tidy |
4 | 4 | { |
5 | 5 | |
6 | - public $name = 'Tidy_Proprietary'; |
|
7 | - public $defaultLevel = 'light'; |
|
6 | + public $name = 'Tidy_Proprietary'; |
|
7 | + public $defaultLevel = 'light'; |
|
8 | 8 | |
9 | - public function makeFixes() { |
|
10 | - $r = array(); |
|
11 | - $r['table@background'] = new HTMLPurifier_AttrTransform_Background(); |
|
12 | - $r['td@background'] = new HTMLPurifier_AttrTransform_Background(); |
|
13 | - $r['th@background'] = new HTMLPurifier_AttrTransform_Background(); |
|
14 | - $r['tr@background'] = new HTMLPurifier_AttrTransform_Background(); |
|
15 | - $r['thead@background'] = new HTMLPurifier_AttrTransform_Background(); |
|
16 | - $r['tfoot@background'] = new HTMLPurifier_AttrTransform_Background(); |
|
17 | - $r['tbody@background'] = new HTMLPurifier_AttrTransform_Background(); |
|
18 | - $r['table@height'] = new HTMLPurifier_AttrTransform_Length('height'); |
|
19 | - return $r; |
|
20 | - } |
|
9 | + public function makeFixes() { |
|
10 | + $r = array(); |
|
11 | + $r['table@background'] = new HTMLPurifier_AttrTransform_Background(); |
|
12 | + $r['td@background'] = new HTMLPurifier_AttrTransform_Background(); |
|
13 | + $r['th@background'] = new HTMLPurifier_AttrTransform_Background(); |
|
14 | + $r['tr@background'] = new HTMLPurifier_AttrTransform_Background(); |
|
15 | + $r['thead@background'] = new HTMLPurifier_AttrTransform_Background(); |
|
16 | + $r['tfoot@background'] = new HTMLPurifier_AttrTransform_Background(); |
|
17 | + $r['tbody@background'] = new HTMLPurifier_AttrTransform_Background(); |
|
18 | + $r['table@height'] = new HTMLPurifier_AttrTransform_Length('height'); |
|
19 | + return $r; |
|
20 | + } |
|
21 | 21 | |
22 | 22 | } |
23 | 23 |
@@ -2,20 +2,20 @@ |
||
2 | 2 | |
3 | 3 | class HTMLPurifier_HTMLModule_Tidy_Strict extends HTMLPurifier_HTMLModule_Tidy_XHTMLAndHTML4 |
4 | 4 | { |
5 | - public $name = 'Tidy_Strict'; |
|
6 | - public $defaultLevel = 'light'; |
|
5 | + public $name = 'Tidy_Strict'; |
|
6 | + public $defaultLevel = 'light'; |
|
7 | 7 | |
8 | - public function makeFixes() { |
|
9 | - $r = parent::makeFixes(); |
|
10 | - $r['blockquote#content_model_type'] = 'strictblockquote'; |
|
11 | - return $r; |
|
12 | - } |
|
8 | + public function makeFixes() { |
|
9 | + $r = parent::makeFixes(); |
|
10 | + $r['blockquote#content_model_type'] = 'strictblockquote'; |
|
11 | + return $r; |
|
12 | + } |
|
13 | 13 | |
14 | - public $defines_child_def = true; |
|
15 | - public function getChildDef($def) { |
|
16 | - if ($def->content_model_type != 'strictblockquote') return parent::getChildDef($def); |
|
17 | - return new HTMLPurifier_ChildDef_StrictBlockquote($def->content_model); |
|
18 | - } |
|
14 | + public $defines_child_def = true; |
|
15 | + public function getChildDef($def) { |
|
16 | + if ($def->content_model_type != 'strictblockquote') return parent::getChildDef($def); |
|
17 | + return new HTMLPurifier_ChildDef_StrictBlockquote($def->content_model); |
|
18 | + } |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | // vim: et sw=4 sts=4 |
@@ -13,7 +13,9 @@ |
||
13 | 13 | |
14 | 14 | public $defines_child_def = true; |
15 | 15 | public function getChildDef($def) { |
16 | - if ($def->content_model_type != 'strictblockquote') return parent::getChildDef($def); |
|
16 | + if ($def->content_model_type != 'strictblockquote') { |
|
17 | + return parent::getChildDef($def); |
|
18 | + } |
|
17 | 19 | return new HTMLPurifier_ChildDef_StrictBlockquote($def->content_model); |
18 | 20 | } |
19 | 21 | } |
@@ -2,8 +2,8 @@ |
||
2 | 2 | |
3 | 3 | class HTMLPurifier_HTMLModule_Tidy_Transitional extends HTMLPurifier_HTMLModule_Tidy_XHTMLAndHTML4 |
4 | 4 | { |
5 | - public $name = 'Tidy_Transitional'; |
|
6 | - public $defaultLevel = 'heavy'; |
|
5 | + public $name = 'Tidy_Transitional'; |
|
6 | + public $defaultLevel = 'heavy'; |
|
7 | 7 | } |
8 | 8 | |
9 | 9 | // vim: et sw=4 sts=4 |
@@ -3,14 +3,14 @@ |
||
3 | 3 | class HTMLPurifier_HTMLModule_Tidy_XHTML extends HTMLPurifier_HTMLModule_Tidy |
4 | 4 | { |
5 | 5 | |
6 | - public $name = 'Tidy_XHTML'; |
|
7 | - public $defaultLevel = 'medium'; |
|
6 | + public $name = 'Tidy_XHTML'; |
|
7 | + public $defaultLevel = 'medium'; |
|
8 | 8 | |
9 | - public function makeFixes() { |
|
10 | - $r = array(); |
|
11 | - $r['@lang'] = new HTMLPurifier_AttrTransform_Lang(); |
|
12 | - return $r; |
|
13 | - } |
|
9 | + public function makeFixes() { |
|
10 | + $r = array(); |
|
11 | + $r['@lang'] = new HTMLPurifier_AttrTransform_Lang(); |
|
12 | + return $r; |
|
13 | + } |
|
14 | 14 | |
15 | 15 | } |
16 | 16 |
@@ -3,158 +3,158 @@ |
||
3 | 3 | class HTMLPurifier_HTMLModule_Tidy_XHTMLAndHTML4 extends HTMLPurifier_HTMLModule_Tidy |
4 | 4 | { |
5 | 5 | |
6 | - public function makeFixes() { |
|
7 | - |
|
8 | - $r = array(); |
|
9 | - |
|
10 | - // == deprecated tag transforms =================================== |
|
11 | - |
|
12 | - $r['font'] = new HTMLPurifier_TagTransform_Font(); |
|
13 | - $r['menu'] = new HTMLPurifier_TagTransform_Simple('ul'); |
|
14 | - $r['dir'] = new HTMLPurifier_TagTransform_Simple('ul'); |
|
15 | - $r['center'] = new HTMLPurifier_TagTransform_Simple('div', 'text-align:center;'); |
|
16 | - $r['u'] = new HTMLPurifier_TagTransform_Simple('span', 'text-decoration:underline;'); |
|
17 | - $r['s'] = new HTMLPurifier_TagTransform_Simple('span', 'text-decoration:line-through;'); |
|
18 | - $r['strike'] = new HTMLPurifier_TagTransform_Simple('span', 'text-decoration:line-through;'); |
|
19 | - |
|
20 | - // == deprecated attribute transforms ============================= |
|
21 | - |
|
22 | - $r['caption@align'] = |
|
23 | - new HTMLPurifier_AttrTransform_EnumToCSS('align', array( |
|
24 | - // we're following IE's behavior, not Firefox's, due |
|
25 | - // to the fact that no one supports caption-side:right, |
|
26 | - // W3C included (with CSS 2.1). This is a slightly |
|
27 | - // unreasonable attribute! |
|
28 | - 'left' => 'text-align:left;', |
|
29 | - 'right' => 'text-align:right;', |
|
30 | - 'top' => 'caption-side:top;', |
|
31 | - 'bottom' => 'caption-side:bottom;' // not supported by IE |
|
32 | - )); |
|
33 | - |
|
34 | - // @align for img ------------------------------------------------- |
|
35 | - $r['img@align'] = |
|
36 | - new HTMLPurifier_AttrTransform_EnumToCSS('align', array( |
|
37 | - 'left' => 'float:left;', |
|
38 | - 'right' => 'float:right;', |
|
39 | - 'top' => 'vertical-align:top;', |
|
40 | - 'middle' => 'vertical-align:middle;', |
|
41 | - 'bottom' => 'vertical-align:baseline;', |
|
42 | - )); |
|
43 | - |
|
44 | - // @align for table ----------------------------------------------- |
|
45 | - $r['table@align'] = |
|
46 | - new HTMLPurifier_AttrTransform_EnumToCSS('align', array( |
|
47 | - 'left' => 'float:left;', |
|
48 | - 'center' => 'margin-left:auto;margin-right:auto;', |
|
49 | - 'right' => 'float:right;' |
|
50 | - )); |
|
51 | - |
|
52 | - // @align for hr ----------------------------------------------- |
|
53 | - $r['hr@align'] = |
|
54 | - new HTMLPurifier_AttrTransform_EnumToCSS('align', array( |
|
55 | - // we use both text-align and margin because these work |
|
56 | - // for different browsers (IE and Firefox, respectively) |
|
57 | - // and the melange makes for a pretty cross-compatible |
|
58 | - // solution |
|
59 | - 'left' => 'margin-left:0;margin-right:auto;text-align:left;', |
|
60 | - 'center' => 'margin-left:auto;margin-right:auto;text-align:center;', |
|
61 | - 'right' => 'margin-left:auto;margin-right:0;text-align:right;' |
|
62 | - )); |
|
63 | - |
|
64 | - // @align for h1, h2, h3, h4, h5, h6, p, div ---------------------- |
|
65 | - // {{{ |
|
66 | - $align_lookup = array(); |
|
67 | - $align_values = array('left', 'right', 'center', 'justify'); |
|
68 | - foreach ($align_values as $v) $align_lookup[$v] = "text-align:$v;"; |
|
69 | - // }}} |
|
70 | - $r['h1@align'] = |
|
71 | - $r['h2@align'] = |
|
72 | - $r['h3@align'] = |
|
73 | - $r['h4@align'] = |
|
74 | - $r['h5@align'] = |
|
75 | - $r['h6@align'] = |
|
76 | - $r['p@align'] = |
|
77 | - $r['div@align'] = |
|
78 | - new HTMLPurifier_AttrTransform_EnumToCSS('align', $align_lookup); |
|
79 | - |
|
80 | - // @bgcolor for table, tr, td, th --------------------------------- |
|
81 | - $r['table@bgcolor'] = |
|
82 | - $r['td@bgcolor'] = |
|
83 | - $r['th@bgcolor'] = |
|
84 | - new HTMLPurifier_AttrTransform_BgColor(); |
|
85 | - |
|
86 | - // @border for img ------------------------------------------------ |
|
87 | - $r['img@border'] = new HTMLPurifier_AttrTransform_Border(); |
|
88 | - |
|
89 | - // @clear for br -------------------------------------------------- |
|
90 | - $r['br@clear'] = |
|
91 | - new HTMLPurifier_AttrTransform_EnumToCSS('clear', array( |
|
92 | - 'left' => 'clear:left;', |
|
93 | - 'right' => 'clear:right;', |
|
94 | - 'all' => 'clear:both;', |
|
95 | - 'none' => 'clear:none;', |
|
96 | - )); |
|
97 | - |
|
98 | - // @height for td, th --------------------------------------------- |
|
99 | - $r['td@height'] = |
|
100 | - $r['th@height'] = |
|
101 | - new HTMLPurifier_AttrTransform_Length('height'); |
|
102 | - |
|
103 | - // @hspace for img ------------------------------------------------ |
|
104 | - $r['img@hspace'] = new HTMLPurifier_AttrTransform_ImgSpace('hspace'); |
|
105 | - |
|
106 | - // @noshade for hr ------------------------------------------------ |
|
107 | - // this transformation is not precise but often good enough. |
|
108 | - // different browsers use different styles to designate noshade |
|
109 | - $r['hr@noshade'] = |
|
110 | - new HTMLPurifier_AttrTransform_BoolToCSS( |
|
111 | - 'noshade', |
|
112 | - 'color:#808080;background-color:#808080;border:0;' |
|
113 | - ); |
|
114 | - |
|
115 | - // @nowrap for td, th --------------------------------------------- |
|
116 | - $r['td@nowrap'] = |
|
117 | - $r['th@nowrap'] = |
|
118 | - new HTMLPurifier_AttrTransform_BoolToCSS( |
|
119 | - 'nowrap', |
|
120 | - 'white-space:nowrap;' |
|
121 | - ); |
|
122 | - |
|
123 | - // @size for hr -------------------------------------------------- |
|
124 | - $r['hr@size'] = new HTMLPurifier_AttrTransform_Length('size', 'height'); |
|
125 | - |
|
126 | - // @type for li, ol, ul ------------------------------------------- |
|
127 | - // {{{ |
|
128 | - $ul_types = array( |
|
129 | - 'disc' => 'list-style-type:disc;', |
|
130 | - 'square' => 'list-style-type:square;', |
|
131 | - 'circle' => 'list-style-type:circle;' |
|
132 | - ); |
|
133 | - $ol_types = array( |
|
134 | - '1' => 'list-style-type:decimal;', |
|
135 | - 'i' => 'list-style-type:lower-roman;', |
|
136 | - 'I' => 'list-style-type:upper-roman;', |
|
137 | - 'a' => 'list-style-type:lower-alpha;', |
|
138 | - 'A' => 'list-style-type:upper-alpha;' |
|
139 | - ); |
|
140 | - $li_types = $ul_types + $ol_types; |
|
141 | - // }}} |
|
142 | - |
|
143 | - $r['ul@type'] = new HTMLPurifier_AttrTransform_EnumToCSS('type', $ul_types); |
|
144 | - $r['ol@type'] = new HTMLPurifier_AttrTransform_EnumToCSS('type', $ol_types, true); |
|
145 | - $r['li@type'] = new HTMLPurifier_AttrTransform_EnumToCSS('type', $li_types, true); |
|
146 | - |
|
147 | - // @vspace for img ------------------------------------------------ |
|
148 | - $r['img@vspace'] = new HTMLPurifier_AttrTransform_ImgSpace('vspace'); |
|
149 | - |
|
150 | - // @width for hr, td, th ------------------------------------------ |
|
151 | - $r['td@width'] = |
|
152 | - $r['th@width'] = |
|
153 | - $r['hr@width'] = new HTMLPurifier_AttrTransform_Length('width'); |
|
154 | - |
|
155 | - return $r; |
|
156 | - |
|
157 | - } |
|
6 | + public function makeFixes() { |
|
7 | + |
|
8 | + $r = array(); |
|
9 | + |
|
10 | + // == deprecated tag transforms =================================== |
|
11 | + |
|
12 | + $r['font'] = new HTMLPurifier_TagTransform_Font(); |
|
13 | + $r['menu'] = new HTMLPurifier_TagTransform_Simple('ul'); |
|
14 | + $r['dir'] = new HTMLPurifier_TagTransform_Simple('ul'); |
|
15 | + $r['center'] = new HTMLPurifier_TagTransform_Simple('div', 'text-align:center;'); |
|
16 | + $r['u'] = new HTMLPurifier_TagTransform_Simple('span', 'text-decoration:underline;'); |
|
17 | + $r['s'] = new HTMLPurifier_TagTransform_Simple('span', 'text-decoration:line-through;'); |
|
18 | + $r['strike'] = new HTMLPurifier_TagTransform_Simple('span', 'text-decoration:line-through;'); |
|
19 | + |
|
20 | + // == deprecated attribute transforms ============================= |
|
21 | + |
|
22 | + $r['caption@align'] = |
|
23 | + new HTMLPurifier_AttrTransform_EnumToCSS('align', array( |
|
24 | + // we're following IE's behavior, not Firefox's, due |
|
25 | + // to the fact that no one supports caption-side:right, |
|
26 | + // W3C included (with CSS 2.1). This is a slightly |
|
27 | + // unreasonable attribute! |
|
28 | + 'left' => 'text-align:left;', |
|
29 | + 'right' => 'text-align:right;', |
|
30 | + 'top' => 'caption-side:top;', |
|
31 | + 'bottom' => 'caption-side:bottom;' // not supported by IE |
|
32 | + )); |
|
33 | + |
|
34 | + // @align for img ------------------------------------------------- |
|
35 | + $r['img@align'] = |
|
36 | + new HTMLPurifier_AttrTransform_EnumToCSS('align', array( |
|
37 | + 'left' => 'float:left;', |
|
38 | + 'right' => 'float:right;', |
|
39 | + 'top' => 'vertical-align:top;', |
|
40 | + 'middle' => 'vertical-align:middle;', |
|
41 | + 'bottom' => 'vertical-align:baseline;', |
|
42 | + )); |
|
43 | + |
|
44 | + // @align for table ----------------------------------------------- |
|
45 | + $r['table@align'] = |
|
46 | + new HTMLPurifier_AttrTransform_EnumToCSS('align', array( |
|
47 | + 'left' => 'float:left;', |
|
48 | + 'center' => 'margin-left:auto;margin-right:auto;', |
|
49 | + 'right' => 'float:right;' |
|
50 | + )); |
|
51 | + |
|
52 | + // @align for hr ----------------------------------------------- |
|
53 | + $r['hr@align'] = |
|
54 | + new HTMLPurifier_AttrTransform_EnumToCSS('align', array( |
|
55 | + // we use both text-align and margin because these work |
|
56 | + // for different browsers (IE and Firefox, respectively) |
|
57 | + // and the melange makes for a pretty cross-compatible |
|
58 | + // solution |
|
59 | + 'left' => 'margin-left:0;margin-right:auto;text-align:left;', |
|
60 | + 'center' => 'margin-left:auto;margin-right:auto;text-align:center;', |
|
61 | + 'right' => 'margin-left:auto;margin-right:0;text-align:right;' |
|
62 | + )); |
|
63 | + |
|
64 | + // @align for h1, h2, h3, h4, h5, h6, p, div ---------------------- |
|
65 | + // {{{ |
|
66 | + $align_lookup = array(); |
|
67 | + $align_values = array('left', 'right', 'center', 'justify'); |
|
68 | + foreach ($align_values as $v) $align_lookup[$v] = "text-align:$v;"; |
|
69 | + // }}} |
|
70 | + $r['h1@align'] = |
|
71 | + $r['h2@align'] = |
|
72 | + $r['h3@align'] = |
|
73 | + $r['h4@align'] = |
|
74 | + $r['h5@align'] = |
|
75 | + $r['h6@align'] = |
|
76 | + $r['p@align'] = |
|
77 | + $r['div@align'] = |
|
78 | + new HTMLPurifier_AttrTransform_EnumToCSS('align', $align_lookup); |
|
79 | + |
|
80 | + // @bgcolor for table, tr, td, th --------------------------------- |
|
81 | + $r['table@bgcolor'] = |
|
82 | + $r['td@bgcolor'] = |
|
83 | + $r['th@bgcolor'] = |
|
84 | + new HTMLPurifier_AttrTransform_BgColor(); |
|
85 | + |
|
86 | + // @border for img ------------------------------------------------ |
|
87 | + $r['img@border'] = new HTMLPurifier_AttrTransform_Border(); |
|
88 | + |
|
89 | + // @clear for br -------------------------------------------------- |
|
90 | + $r['br@clear'] = |
|
91 | + new HTMLPurifier_AttrTransform_EnumToCSS('clear', array( |
|
92 | + 'left' => 'clear:left;', |
|
93 | + 'right' => 'clear:right;', |
|
94 | + 'all' => 'clear:both;', |
|
95 | + 'none' => 'clear:none;', |
|
96 | + )); |
|
97 | + |
|
98 | + // @height for td, th --------------------------------------------- |
|
99 | + $r['td@height'] = |
|
100 | + $r['th@height'] = |
|
101 | + new HTMLPurifier_AttrTransform_Length('height'); |
|
102 | + |
|
103 | + // @hspace for img ------------------------------------------------ |
|
104 | + $r['img@hspace'] = new HTMLPurifier_AttrTransform_ImgSpace('hspace'); |
|
105 | + |
|
106 | + // @noshade for hr ------------------------------------------------ |
|
107 | + // this transformation is not precise but often good enough. |
|
108 | + // different browsers use different styles to designate noshade |
|
109 | + $r['hr@noshade'] = |
|
110 | + new HTMLPurifier_AttrTransform_BoolToCSS( |
|
111 | + 'noshade', |
|
112 | + 'color:#808080;background-color:#808080;border:0;' |
|
113 | + ); |
|
114 | + |
|
115 | + // @nowrap for td, th --------------------------------------------- |
|
116 | + $r['td@nowrap'] = |
|
117 | + $r['th@nowrap'] = |
|
118 | + new HTMLPurifier_AttrTransform_BoolToCSS( |
|
119 | + 'nowrap', |
|
120 | + 'white-space:nowrap;' |
|
121 | + ); |
|
122 | + |
|
123 | + // @size for hr -------------------------------------------------- |
|
124 | + $r['hr@size'] = new HTMLPurifier_AttrTransform_Length('size', 'height'); |
|
125 | + |
|
126 | + // @type for li, ol, ul ------------------------------------------- |
|
127 | + // {{{ |
|
128 | + $ul_types = array( |
|
129 | + 'disc' => 'list-style-type:disc;', |
|
130 | + 'square' => 'list-style-type:square;', |
|
131 | + 'circle' => 'list-style-type:circle;' |
|
132 | + ); |
|
133 | + $ol_types = array( |
|
134 | + '1' => 'list-style-type:decimal;', |
|
135 | + 'i' => 'list-style-type:lower-roman;', |
|
136 | + 'I' => 'list-style-type:upper-roman;', |
|
137 | + 'a' => 'list-style-type:lower-alpha;', |
|
138 | + 'A' => 'list-style-type:upper-alpha;' |
|
139 | + ); |
|
140 | + $li_types = $ul_types + $ol_types; |
|
141 | + // }}} |
|
142 | + |
|
143 | + $r['ul@type'] = new HTMLPurifier_AttrTransform_EnumToCSS('type', $ul_types); |
|
144 | + $r['ol@type'] = new HTMLPurifier_AttrTransform_EnumToCSS('type', $ol_types, true); |
|
145 | + $r['li@type'] = new HTMLPurifier_AttrTransform_EnumToCSS('type', $li_types, true); |
|
146 | + |
|
147 | + // @vspace for img ------------------------------------------------ |
|
148 | + $r['img@vspace'] = new HTMLPurifier_AttrTransform_ImgSpace('vspace'); |
|
149 | + |
|
150 | + // @width for hr, td, th ------------------------------------------ |
|
151 | + $r['td@width'] = |
|
152 | + $r['th@width'] = |
|
153 | + $r['hr@width'] = new HTMLPurifier_AttrTransform_Length('width'); |
|
154 | + |
|
155 | + return $r; |
|
156 | + |
|
157 | + } |
|
158 | 158 | |
159 | 159 | } |
160 | 160 |
@@ -12,7 +12,7 @@ |
||
12 | 12 | $r['font'] = new HTMLPurifier_TagTransform_Font(); |
13 | 13 | $r['menu'] = new HTMLPurifier_TagTransform_Simple('ul'); |
14 | 14 | $r['dir'] = new HTMLPurifier_TagTransform_Simple('ul'); |
15 | - $r['center'] = new HTMLPurifier_TagTransform_Simple('div', 'text-align:center;'); |
|
15 | + $r['center'] = new HTMLPurifier_TagTransform_Simple('div', 'text-align:center;'); |
|
16 | 16 | $r['u'] = new HTMLPurifier_TagTransform_Simple('span', 'text-decoration:underline;'); |
17 | 17 | $r['s'] = new HTMLPurifier_TagTransform_Simple('span', 'text-decoration:line-through;'); |
18 | 18 | $r['strike'] = new HTMLPurifier_TagTransform_Simple('span', 'text-decoration:line-through;'); |
@@ -65,7 +65,9 @@ |
||
65 | 65 | // {{{ |
66 | 66 | $align_lookup = array(); |
67 | 67 | $align_values = array('left', 'right', 'center', 'justify'); |
68 | - foreach ($align_values as $v) $align_lookup[$v] = "text-align:$v;"; |
|
68 | + foreach ($align_values as $v) { |
|
69 | + $align_lookup[$v] = "text-align:$v;"; |
|
70 | + } |
|
69 | 71 | // }}} |
70 | 72 | $r['h1@align'] = |
71 | 73 | $r['h2@align'] = |
@@ -2,13 +2,13 @@ |
||
2 | 2 | |
3 | 3 | class HTMLPurifier_HTMLModule_XMLCommonAttributes extends HTMLPurifier_HTMLModule |
4 | 4 | { |
5 | - public $name = 'XMLCommonAttributes'; |
|
5 | + public $name = 'XMLCommonAttributes'; |
|
6 | 6 | |
7 | - public $attr_collections = array( |
|
8 | - 'Lang' => array( |
|
9 | - 'xml:lang' => 'LanguageCode', |
|
10 | - ) |
|
11 | - ); |
|
7 | + public $attr_collections = array( |
|
8 | + 'Lang' => array( |
|
9 | + 'xml:lang' => 'LanguageCode', |
|
10 | + ) |
|
11 | + ); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | // vim: et sw=4 sts=4 |