HTMLPurifier 4.4.0
|
00001 <?php 00002 00003 class HTMLPurifier_HTMLModule_Tidy_XHTMLAndHTML4 extends HTMLPurifier_HTMLModule_Tidy 00004 { 00005 00006 public function makeFixes() { 00007 00008 $r = array(); 00009 00010 // == deprecated tag transforms =================================== 00011 00012 $r['font'] = new HTMLPurifier_TagTransform_Font(); 00013 $r['menu'] = new HTMLPurifier_TagTransform_Simple('ul'); 00014 $r['dir'] = new HTMLPurifier_TagTransform_Simple('ul'); 00015 $r['center'] = new HTMLPurifier_TagTransform_Simple('div', 'text-align:center;'); 00016 $r['u'] = new HTMLPurifier_TagTransform_Simple('span', 'text-decoration:underline;'); 00017 $r['s'] = new HTMLPurifier_TagTransform_Simple('span', 'text-decoration:line-through;'); 00018 $r['strike'] = new HTMLPurifier_TagTransform_Simple('span', 'text-decoration:line-through;'); 00019 00020 // == deprecated attribute transforms ============================= 00021 00022 $r['caption@align'] = 00023 new HTMLPurifier_AttrTransform_EnumToCSS('align', array( 00024 // we're following IE's behavior, not Firefox's, due 00025 // to the fact that no one supports caption-side:right, 00026 // W3C included (with CSS 2.1). This is a slightly 00027 // unreasonable attribute! 00028 'left' => 'text-align:left;', 00029 'right' => 'text-align:right;', 00030 'top' => 'caption-side:top;', 00031 'bottom' => 'caption-side:bottom;' // not supported by IE 00032 )); 00033 00034 // @align for img ------------------------------------------------- 00035 $r['img@align'] = 00036 new HTMLPurifier_AttrTransform_EnumToCSS('align', array( 00037 'left' => 'float:left;', 00038 'right' => 'float:right;', 00039 'top' => 'vertical-align:top;', 00040 'middle' => 'vertical-align:middle;', 00041 'bottom' => 'vertical-align:baseline;', 00042 )); 00043 00044 // @align for table ----------------------------------------------- 00045 $r['table@align'] = 00046 new HTMLPurifier_AttrTransform_EnumToCSS('align', array( 00047 'left' => 'float:left;', 00048 'center' => 'margin-left:auto;margin-right:auto;', 00049 'right' => 'float:right;' 00050 )); 00051 00052 // @align for hr ----------------------------------------------- 00053 $r['hr@align'] = 00054 new HTMLPurifier_AttrTransform_EnumToCSS('align', array( 00055 // we use both text-align and margin because these work 00056 // for different browsers (IE and Firefox, respectively) 00057 // and the melange makes for a pretty cross-compatible 00058 // solution 00059 'left' => 'margin-left:0;margin-right:auto;text-align:left;', 00060 'center' => 'margin-left:auto;margin-right:auto;text-align:center;', 00061 'right' => 'margin-left:auto;margin-right:0;text-align:right;' 00062 )); 00063 00064 // @align for h1, h2, h3, h4, h5, h6, p, div ---------------------- 00065 // {{{ 00066 $align_lookup = array(); 00067 $align_values = array('left', 'right', 'center', 'justify'); 00068 foreach ($align_values as $v) $align_lookup[$v] = "text-align:$v;"; 00069 // }}} 00070 $r['h1@align'] = 00071 $r['h2@align'] = 00072 $r['h3@align'] = 00073 $r['h4@align'] = 00074 $r['h5@align'] = 00075 $r['h6@align'] = 00076 $r['p@align'] = 00077 $r['div@align'] = 00078 new HTMLPurifier_AttrTransform_EnumToCSS('align', $align_lookup); 00079 00080 // @bgcolor for table, tr, td, th --------------------------------- 00081 $r['table@bgcolor'] = 00082 $r['td@bgcolor'] = 00083 $r['th@bgcolor'] = 00084 new HTMLPurifier_AttrTransform_BgColor(); 00085 00086 // @border for img ------------------------------------------------ 00087 $r['img@border'] = new HTMLPurifier_AttrTransform_Border(); 00088 00089 // @clear for br -------------------------------------------------- 00090 $r['br@clear'] = 00091 new HTMLPurifier_AttrTransform_EnumToCSS('clear', array( 00092 'left' => 'clear:left;', 00093 'right' => 'clear:right;', 00094 'all' => 'clear:both;', 00095 'none' => 'clear:none;', 00096 )); 00097 00098 // @height for td, th --------------------------------------------- 00099 $r['td@height'] = 00100 $r['th@height'] = 00101 new HTMLPurifier_AttrTransform_Length('height'); 00102 00103 // @hspace for img ------------------------------------------------ 00104 $r['img@hspace'] = new HTMLPurifier_AttrTransform_ImgSpace('hspace'); 00105 00106 // @noshade for hr ------------------------------------------------ 00107 // this transformation is not precise but often good enough. 00108 // different browsers use different styles to designate noshade 00109 $r['hr@noshade'] = 00110 new HTMLPurifier_AttrTransform_BoolToCSS( 00111 'noshade', 00112 'color:#808080;background-color:#808080;border:0;' 00113 ); 00114 00115 // @nowrap for td, th --------------------------------------------- 00116 $r['td@nowrap'] = 00117 $r['th@nowrap'] = 00118 new HTMLPurifier_AttrTransform_BoolToCSS( 00119 'nowrap', 00120 'white-space:nowrap;' 00121 ); 00122 00123 // @size for hr -------------------------------------------------- 00124 $r['hr@size'] = new HTMLPurifier_AttrTransform_Length('size', 'height'); 00125 00126 // @type for li, ol, ul ------------------------------------------- 00127 // {{{ 00128 $ul_types = array( 00129 'disc' => 'list-style-type:disc;', 00130 'square' => 'list-style-type:square;', 00131 'circle' => 'list-style-type:circle;' 00132 ); 00133 $ol_types = array( 00134 '1' => 'list-style-type:decimal;', 00135 'i' => 'list-style-type:lower-roman;', 00136 'I' => 'list-style-type:upper-roman;', 00137 'a' => 'list-style-type:lower-alpha;', 00138 'A' => 'list-style-type:upper-alpha;' 00139 ); 00140 $li_types = $ul_types + $ol_types; 00141 // }}} 00142 00143 $r['ul@type'] = new HTMLPurifier_AttrTransform_EnumToCSS('type', $ul_types); 00144 $r['ol@type'] = new HTMLPurifier_AttrTransform_EnumToCSS('type', $ol_types, true); 00145 $r['li@type'] = new HTMLPurifier_AttrTransform_EnumToCSS('type', $li_types, true); 00146 00147 // @vspace for img ------------------------------------------------ 00148 $r['img@vspace'] = new HTMLPurifier_AttrTransform_ImgSpace('vspace'); 00149 00150 // @width for hr, td, th ------------------------------------------ 00151 $r['td@width'] = 00152 $r['th@width'] = 00153 $r['hr@width'] = new HTMLPurifier_AttrTransform_Length('width'); 00154 00155 return $r; 00156 00157 } 00158 00159 } 00160 00161 // vim: et sw=4 sts=4