File indexing completed on 2024-05-26 06:02:32

0001 <?php
0002 
0003 class HTMLPurifier_HTMLModule_Tidy_XHTMLAndHTML4 extends HTMLPurifier_HTMLModule_Tidy
0004 {
0005 
0006     /**
0007      * @return array
0008      */
0009     public function makeFixes()
0010     {
0011         $r = array();
0012 
0013         // == deprecated tag transforms ===================================
0014 
0015         $r['font'] = new HTMLPurifier_TagTransform_Font();
0016         $r['menu'] = new HTMLPurifier_TagTransform_Simple('ul');
0017         $r['dir'] = new HTMLPurifier_TagTransform_Simple('ul');
0018         $r['center'] = new HTMLPurifier_TagTransform_Simple('div', 'text-align:center;');
0019         $r['u'] = new HTMLPurifier_TagTransform_Simple('span', 'text-decoration:underline;');
0020         $r['s'] = new HTMLPurifier_TagTransform_Simple('span', 'text-decoration:line-through;');
0021         $r['strike'] = new HTMLPurifier_TagTransform_Simple('span', 'text-decoration:line-through;');
0022 
0023         // == deprecated attribute transforms =============================
0024 
0025         $r['caption@align'] =
0026             new HTMLPurifier_AttrTransform_EnumToCSS(
0027                 'align',
0028                 array(
0029                     // we're following IE's behavior, not Firefox's, due
0030                     // to the fact that no one supports caption-side:right,
0031                     // W3C included (with CSS 2.1). This is a slightly
0032                     // unreasonable attribute!
0033                     'left' => 'text-align:left;',
0034                     'right' => 'text-align:right;',
0035                     'top' => 'caption-side:top;',
0036                     'bottom' => 'caption-side:bottom;' // not supported by IE
0037                 )
0038             );
0039 
0040         // @align for img -------------------------------------------------
0041         $r['img@align'] =
0042             new HTMLPurifier_AttrTransform_EnumToCSS(
0043                 'align',
0044                 array(
0045                     'left' => 'float:left;',
0046                     'right' => 'float:right;',
0047                     'top' => 'vertical-align:top;',
0048                     'middle' => 'vertical-align:middle;',
0049                     'bottom' => 'vertical-align:baseline;',
0050                 )
0051             );
0052 
0053         // @align for table -----------------------------------------------
0054         $r['table@align'] =
0055             new HTMLPurifier_AttrTransform_EnumToCSS(
0056                 'align',
0057                 array(
0058                     'left' => 'float:left;',
0059                     'center' => 'margin-left:auto;margin-right:auto;',
0060                     'right' => 'float:right;'
0061                 )
0062             );
0063 
0064         // @align for hr -----------------------------------------------
0065         $r['hr@align'] =
0066             new HTMLPurifier_AttrTransform_EnumToCSS(
0067                 'align',
0068                 array(
0069                     // we use both text-align and margin because these work
0070                     // for different browsers (IE and Firefox, respectively)
0071                     // and the melange makes for a pretty cross-compatible
0072                     // solution
0073                     'left' => 'margin-left:0;margin-right:auto;text-align:left;',
0074                     'center' => 'margin-left:auto;margin-right:auto;text-align:center;',
0075                     'right' => 'margin-left:auto;margin-right:0;text-align:right;'
0076                 )
0077             );
0078 
0079         // @align for h1, h2, h3, h4, h5, h6, p, div ----------------------
0080         // {{{
0081         $align_lookup = array();
0082         $align_values = array('left', 'right', 'center', 'justify');
0083         foreach ($align_values as $v) {
0084             $align_lookup[$v] = "text-align:$v;";
0085         }
0086         // }}}
0087         $r['h1@align'] =
0088         $r['h2@align'] =
0089         $r['h3@align'] =
0090         $r['h4@align'] =
0091         $r['h5@align'] =
0092         $r['h6@align'] =
0093         $r['p@align'] =
0094         $r['div@align'] =
0095             new HTMLPurifier_AttrTransform_EnumToCSS('align', $align_lookup);
0096 
0097         // @bgcolor for table, tr, td, th ---------------------------------
0098         $r['table@bgcolor'] =
0099         $r['td@bgcolor'] =
0100         $r['th@bgcolor'] =
0101             new HTMLPurifier_AttrTransform_BgColor();
0102 
0103         // @border for img ------------------------------------------------
0104         $r['img@border'] = new HTMLPurifier_AttrTransform_Border();
0105 
0106         // @clear for br --------------------------------------------------
0107         $r['br@clear'] =
0108             new HTMLPurifier_AttrTransform_EnumToCSS(
0109                 'clear',
0110                 array(
0111                     'left' => 'clear:left;',
0112                     'right' => 'clear:right;',
0113                     'all' => 'clear:both;',
0114                     'none' => 'clear:none;',
0115                 )
0116             );
0117 
0118         // @height for td, th ---------------------------------------------
0119         $r['td@height'] =
0120         $r['th@height'] =
0121             new HTMLPurifier_AttrTransform_Length('height');
0122 
0123         // @hspace for img ------------------------------------------------
0124         $r['img@hspace'] = new HTMLPurifier_AttrTransform_ImgSpace('hspace');
0125 
0126         // @noshade for hr ------------------------------------------------
0127         // this transformation is not precise but often good enough.
0128         // different browsers use different styles to designate noshade
0129         $r['hr@noshade'] =
0130             new HTMLPurifier_AttrTransform_BoolToCSS(
0131                 'noshade',
0132                 'color:#808080;background-color:#808080;border:0;'
0133             );
0134 
0135         // @nowrap for td, th ---------------------------------------------
0136         $r['td@nowrap'] =
0137         $r['th@nowrap'] =
0138             new HTMLPurifier_AttrTransform_BoolToCSS(
0139                 'nowrap',
0140                 'white-space:nowrap;'
0141             );
0142 
0143         // @size for hr  --------------------------------------------------
0144         $r['hr@size'] = new HTMLPurifier_AttrTransform_Length('size', 'height');
0145 
0146         // @type for li, ol, ul -------------------------------------------
0147         // {{{
0148         $ul_types = array(
0149             'disc' => 'list-style-type:disc;',
0150             'square' => 'list-style-type:square;',
0151             'circle' => 'list-style-type:circle;'
0152         );
0153         $ol_types = array(
0154             '1' => 'list-style-type:decimal;',
0155             'i' => 'list-style-type:lower-roman;',
0156             'I' => 'list-style-type:upper-roman;',
0157             'a' => 'list-style-type:lower-alpha;',
0158             'A' => 'list-style-type:upper-alpha;'
0159         );
0160         $li_types = $ul_types + $ol_types;
0161         // }}}
0162 
0163         $r['ul@type'] = new HTMLPurifier_AttrTransform_EnumToCSS('type', $ul_types);
0164         $r['ol@type'] = new HTMLPurifier_AttrTransform_EnumToCSS('type', $ol_types, true);
0165         $r['li@type'] = new HTMLPurifier_AttrTransform_EnumToCSS('type', $li_types, true);
0166 
0167         // @vspace for img ------------------------------------------------
0168         $r['img@vspace'] = new HTMLPurifier_AttrTransform_ImgSpace('vspace');
0169 
0170         // @width for hr, td, th ------------------------------------------
0171         $r['td@width'] =
0172         $r['th@width'] =
0173         $r['hr@width'] = new HTMLPurifier_AttrTransform_Length('width');
0174 
0175         return $r;
0176     }
0177 }
0178 
0179 // vim: et sw=4 sts=4