]> git.mxchange.org Git - friendica.git/blob - library/HTMLPurifier/HTMLModule/Tidy/XHTMLAndHTML4.php
Merge branch 'master' of https://github.com/friendica/friendica
[friendica.git] / library / HTMLPurifier / HTMLModule / Tidy / XHTMLAndHTML4.php
1 <?php
2
3 class HTMLPurifier_HTMLModule_Tidy_XHTMLAndHTML4 extends HTMLPurifier_HTMLModule_Tidy
4 {
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     }
158
159 }
160
161 // vim: et sw=4 sts=4