3 require_once 'HTMLPurifier/ChildDef/StrictBlockquote.php';
5 require_once 'HTMLPurifier/TagTransform/Simple.php';
6 require_once 'HTMLPurifier/TagTransform/Center.php';
7 require_once 'HTMLPurifier/TagTransform/Font.php';
9 require_once 'HTMLPurifier/AttrTransform/Lang.php';
10 require_once 'HTMLPurifier/AttrTransform/BgColor.php';
11 require_once 'HTMLPurifier/AttrTransform/BoolToCSS.php';
12 require_once 'HTMLPurifier/AttrTransform/Border.php';
13 require_once 'HTMLPurifier/AttrTransform/Name.php';
14 require_once 'HTMLPurifier/AttrTransform/Length.php';
15 require_once 'HTMLPurifier/AttrTransform/ImgSpace.php';
16 require_once 'HTMLPurifier/AttrTransform/EnumToCSS.php';
19 * Proprietary module that transforms deprecated elements into Strict
20 * HTML (see HTML 4.01 and XHTML 1.0) when possible.
23 class HTMLPurifier_HTMLModule_TransformToStrict
extends HTMLPurifier_HTMLModule
26 var $name = 'TransformToStrict';
28 // we're actually modifying these elements, not defining them
29 var $elements = array('h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p',
30 'blockquote', 'table', 'td', 'th', 'tr', 'img', 'a', 'hr', 'br',
31 'caption', 'ul', 'ol', 'li');
33 var $info_tag_transform = array(
34 // placeholders, see constructor for definitions
41 var $attr_collections = array(
43 'lang' => false // placeholder
47 var $info_attr_transform_post = array(
48 'lang' => false // placeholder
51 function HTMLPurifier_HTMLModule_TransformToStrict() {
53 // behavior with transformations when there's another CSS property
54 // working on it is interesting: the CSS will *always* override
55 // the deprecated attribute, whereas an inline CSS declaration will
56 // override the corresponding declaration in, say, an external
57 // stylesheet. This behavior won't affect most people, but it
58 // does represent an operational difference we CANNOT fix.
60 // deprecated tag transforms
61 $this->info_tag_transform
['font'] = new HTMLPurifier_TagTransform_Font();
62 $this->info_tag_transform
['menu'] = new HTMLPurifier_TagTransform_Simple('ul');
63 $this->info_tag_transform
['dir'] = new HTMLPurifier_TagTransform_Simple('ul');
64 $this->info_tag_transform
['center'] = new HTMLPurifier_TagTransform_Center();
66 foreach ($this->elements
as $name) {
67 $this->info
[$name] = new HTMLPurifier_ElementDef();
68 $this->info
[$name]->standalone
= false;
71 // deprecated attribute transforms
74 $align_lookup = array();
75 $align_values = array('left', 'right', 'center', 'justify');
76 foreach ($align_values as $v) $align_lookup[$v] = "text-align:$v;";
77 $this->info
['h1']->attr_transform_pre
['align'] =
78 $this->info
['h2']->attr_transform_pre
['align'] =
79 $this->info
['h3']->attr_transform_pre
['align'] =
80 $this->info
['h4']->attr_transform_pre
['align'] =
81 $this->info
['h5']->attr_transform_pre
['align'] =
82 $this->info
['h6']->attr_transform_pre
['align'] =
83 $this->info
['p'] ->attr_transform_pre
['align'] =
84 new HTMLPurifier_AttrTransform_EnumToCSS('align', $align_lookup);
86 // xml:lang <=> lang mirroring, implement in TransformToStrict,
87 // this is overridden in TransformToXHTML11
88 $this->info_attr_transform_post
['lang'] = new HTMLPurifier_AttrTransform_Lang();
89 $this->attr_collections
['Lang']['lang'] = new HTMLPurifier_AttrDef_Lang();
91 // this should not be applied to XHTML 1.0 Transitional, ONLY
92 // XHTML 1.0 Strict. We may need three classes
93 $this->info
['blockquote']->content_model_type
= 'strictblockquote';
94 $this->info
['blockquote']->child
= false; // recalculate please!
96 $this->info
['table']->attr_transform_pre
['bgcolor'] =
97 $this->info
['tr']->attr_transform_pre
['bgcolor'] =
98 $this->info
['td']->attr_transform_pre
['bgcolor'] =
99 $this->info
['th']->attr_transform_pre
['bgcolor'] = new HTMLPurifier_AttrTransform_BgColor();
101 $this->info
['img']->attr_transform_pre
['border'] = new HTMLPurifier_AttrTransform_Border();
103 $this->info
['img']->attr_transform_pre
['name'] =
104 $this->info
['a']->attr_transform_pre
['name'] = new HTMLPurifier_AttrTransform_Name();
106 $this->info
['td']->attr_transform_pre
['width'] =
107 $this->info
['th']->attr_transform_pre
['width'] =
108 $this->info
['hr']->attr_transform_pre
['width'] = new HTMLPurifier_AttrTransform_Length('width');
110 $this->info
['td']->attr_transform_pre
['nowrap'] =
111 $this->info
['th']->attr_transform_pre
['nowrap'] = new HTMLPurifier_AttrTransform_BoolToCSS('nowrap', 'white-space:nowrap;');
113 $this->info
['td']->attr_transform_pre
['height'] =
114 $this->info
['th']->attr_transform_pre
['height'] = new HTMLPurifier_AttrTransform_Length('height');
116 $this->info
['img']->attr_transform_pre
['hspace'] = new HTMLPurifier_AttrTransform_ImgSpace('hspace');
117 $this->info
['img']->attr_transform_pre
['vspace'] = new HTMLPurifier_AttrTransform_ImgSpace('vspace');
119 $this->info
['hr']->attr_transform_pre
['size'] = new HTMLPurifier_AttrTransform_Length('size', 'height');
121 // this transformation is not precise but often good enough.
122 // different browsers use different styles to designate noshade
123 $this->info
['hr']->attr_transform_pre
['noshade'] = new HTMLPurifier_AttrTransform_BoolToCSS('noshade', 'color:#808080;background-color:#808080;border: 0;');
125 $this->info
['br']->attr_transform_pre
['clear'] =
126 new HTMLPurifier_AttrTransform_EnumToCSS('clear', array(
127 'left' => 'clear:left;',
128 'right' => 'clear:right;',
129 'all' => 'clear:both;',
130 'none' => 'clear:none;',
133 // this is a slightly unreasonable attribute
134 $this->info
['caption']->attr_transform_pre
['align'] =
135 new HTMLPurifier_AttrTransform_EnumToCSS('align', array(
136 // we're following IE's behavior, not Firefox's, due
137 // to the fact that no one supports caption-side:right,
138 // W3C included (with CSS 2.1)
139 'left' => 'text-align:left;',
140 'right' => 'text-align:right;',
141 'top' => 'caption-side:top;',
142 'bottom' => 'caption-side:bottom;' // not supported by IE
145 $this->info
['table']->attr_transform_pre
['align'] =
146 new HTMLPurifier_AttrTransform_EnumToCSS('align', array(
147 'left' => 'float:left;',
148 'center' => 'margin-left:auto;margin-right:auto;',
149 'right' => 'float:right;'
152 $this->info
['img']->attr_transform_pre
['align'] =
153 new HTMLPurifier_AttrTransform_EnumToCSS('align', array(
154 'left' => 'float:left;',
155 'right' => 'float:right;',
156 'top' => 'vertical-align:top;',
157 'middle' => 'vertical-align:middle;',
158 'bottom' => 'vertical-align:baseline;',
161 $this->info
['hr']->attr_transform_pre
['align'] =
162 new HTMLPurifier_AttrTransform_EnumToCSS('align', array(
163 'left' => 'margin-left:0;margin-right:auto;text-align:left;',
164 'center' => 'margin-left:auto;margin-right:auto;text-align:center;',
165 'right' => 'margin-left:auto;margin-right:0;text-align:right;'
169 'disc' => 'list-style-type:disc;',
170 'square' => 'list-style-type:square;',
171 'circle' => 'list-style-type:circle;'
174 '1' => 'list-style-type:decimal;',
175 'i' => 'list-style-type:lower-roman;',
176 'I' => 'list-style-type:upper-roman;',
177 'a' => 'list-style-type:lower-alpha;',
178 'A' => 'list-style-type:upper-alpha;'
180 $li_types = $ul_types +
$ol_types;
182 $this->info
['ul']->attr_transform_pre
['type'] =
183 new HTMLPurifier_AttrTransform_EnumToCSS('type', $ul_types);
184 $this->info
['ol']->attr_transform_pre
['type'] =
185 new HTMLPurifier_AttrTransform_EnumToCSS('type', $ol_types, true);
186 $this->info
['li']->attr_transform_pre
['type'] =
187 new HTMLPurifier_AttrTransform_EnumToCSS('type', $li_types, true);
192 var $defines_child_def = true;
193 function getChildDef($def) {
194 if ($def->content_model_type
!= 'strictblockquote') return false;
195 return new HTMLPurifier_ChildDef_StrictBlockquote($def->content_model
);