| 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 | // @name for img, a ----------------------------------------------- |
|---|
| 107 | $r['img@name'] = |
|---|
| 108 | $r['a@name'] = new HTMLPurifier_AttrTransform_Name(); |
|---|
| 109 | |
|---|
| 110 | // @noshade for hr ------------------------------------------------ |
|---|
| 111 | // this transformation is not precise but often good enough. |
|---|
| 112 | // different browsers use different styles to designate noshade |
|---|
| 113 | $r['hr@noshade'] = |
|---|
| 114 | new HTMLPurifier_AttrTransform_BoolToCSS( |
|---|
| 115 | 'noshade', |
|---|
| 116 | 'color:#808080;background-color:#808080;border:0;' |
|---|
| 117 | ); |
|---|
| 118 | |
|---|
| 119 | // @nowrap for td, th --------------------------------------------- |
|---|
| 120 | $r['td@nowrap'] = |
|---|
| 121 | $r['th@nowrap'] = |
|---|
| 122 | new HTMLPurifier_AttrTransform_BoolToCSS( |
|---|
| 123 | 'nowrap', |
|---|
| 124 | 'white-space:nowrap;' |
|---|
| 125 | ); |
|---|
| 126 | |
|---|
| 127 | // @size for hr -------------------------------------------------- |
|---|
| 128 | $r['hr@size'] = new HTMLPurifier_AttrTransform_Length('size', 'height'); |
|---|
| 129 | |
|---|
| 130 | // @type for li, ol, ul ------------------------------------------- |
|---|
| 131 | // {{{ |
|---|
| 132 | $ul_types = array( |
|---|
| 133 | 'disc' => 'list-style-type:disc;', |
|---|
| 134 | 'square' => 'list-style-type:square;', |
|---|
| 135 | 'circle' => 'list-style-type:circle;' |
|---|
| 136 | ); |
|---|
| 137 | $ol_types = array( |
|---|
| 138 | '1' => 'list-style-type:decimal;', |
|---|
| 139 | 'i' => 'list-style-type:lower-roman;', |
|---|
| 140 | 'I' => 'list-style-type:upper-roman;', |
|---|
| 141 | 'a' => 'list-style-type:lower-alpha;', |
|---|
| 142 | 'A' => 'list-style-type:upper-alpha;' |
|---|
| 143 | ); |
|---|
| 144 | $li_types = $ul_types + $ol_types; |
|---|
| 145 | // }}} |
|---|
| 146 | |
|---|
| 147 | $r['ul@type'] = new HTMLPurifier_AttrTransform_EnumToCSS('type', $ul_types); |
|---|
| 148 | $r['ol@type'] = new HTMLPurifier_AttrTransform_EnumToCSS('type', $ol_types, true); |
|---|
| 149 | $r['li@type'] = new HTMLPurifier_AttrTransform_EnumToCSS('type', $li_types, true); |
|---|
| 150 | |
|---|
| 151 | // @vspace for img ------------------------------------------------ |
|---|
| 152 | $r['img@vspace'] = new HTMLPurifier_AttrTransform_ImgSpace('vspace'); |
|---|
| 153 | |
|---|
| 154 | // @width for hr, td, th ------------------------------------------ |
|---|
| 155 | $r['td@width'] = |
|---|
| 156 | $r['th@width'] = |
|---|
| 157 | $r['hr@width'] = new HTMLPurifier_AttrTransform_Length('width'); |
|---|
| 158 | |
|---|
| 159 | return $r; |
|---|
| 160 | |
|---|
| 161 | } |
|---|
| 162 | |
|---|
| 163 | } |
|---|
| 164 | |
|---|