| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: | class HTMLPurifier_ChildDef_Table extends HTMLPurifier_ChildDef |
| 33: | { |
| 34: | |
| 35: | |
| 36: | |
| 37: | public $allow_empty = false; |
| 38: | |
| 39: | |
| 40: | |
| 41: | |
| 42: | public $type = 'table'; |
| 43: | |
| 44: | |
| 45: | |
| 46: | |
| 47: | public $elements = array( |
| 48: | 'tr' => true, |
| 49: | 'tbody' => true, |
| 50: | 'thead' => true, |
| 51: | 'tfoot' => true, |
| 52: | 'caption' => true, |
| 53: | 'colgroup' => true, |
| 54: | 'col' => true |
| 55: | ); |
| 56: | |
| 57: | public function __construct() |
| 58: | { |
| 59: | } |
| 60: | |
| 61: | |
| 62: | |
| 63: | |
| 64: | |
| 65: | |
| 66: | |
| 67: | public function validateChildren($children, $config, $context) |
| 68: | { |
| 69: | if (empty($children)) { |
| 70: | return false; |
| 71: | } |
| 72: | |
| 73: | |
| 74: | $caption = false; |
| 75: | $thead = false; |
| 76: | $tfoot = false; |
| 77: | |
| 78: | |
| 79: | $initial_ws = array(); |
| 80: | $after_caption_ws = array(); |
| 81: | $after_thead_ws = array(); |
| 82: | $after_tfoot_ws = array(); |
| 83: | |
| 84: | |
| 85: | $cols = array(); |
| 86: | $content = array(); |
| 87: | |
| 88: | $tbody_mode = false; |
| 89: | |
| 90: | |
| 91: | $ws_accum =& $initial_ws; |
| 92: | |
| 93: | foreach ($children as $node) { |
| 94: | if ($node instanceof HTMLPurifier_Node_Comment) { |
| 95: | $ws_accum[] = $node; |
| 96: | continue; |
| 97: | } |
| 98: | switch ($node->name) { |
| 99: | case 'tbody': |
| 100: | $tbody_mode = true; |
| 101: | |
| 102: | case 'tr': |
| 103: | $content[] = $node; |
| 104: | $ws_accum =& $content; |
| 105: | break; |
| 106: | case 'caption': |
| 107: | |
| 108: | if ($caption !== false) break; |
| 109: | $caption = $node; |
| 110: | $ws_accum =& $after_caption_ws; |
| 111: | break; |
| 112: | case 'thead': |
| 113: | $tbody_mode = true; |
| 114: | |
| 115: | |
| 116: | |
| 117: | |
| 118: | |
| 119: | |
| 120: | if ($thead === false) { |
| 121: | $thead = $node; |
| 122: | $ws_accum =& $after_thead_ws; |
| 123: | } else { |
| 124: | |
| 125: | |
| 126: | |
| 127: | |
| 128: | |
| 129: | |
| 130: | |
| 131: | |
| 132: | |
| 133: | $node->name = 'tbody'; |
| 134: | $content[] = $node; |
| 135: | $ws_accum =& $content; |
| 136: | } |
| 137: | break; |
| 138: | case 'tfoot': |
| 139: | |
| 140: | $tbody_mode = true; |
| 141: | if ($tfoot === false) { |
| 142: | $tfoot = $node; |
| 143: | $ws_accum =& $after_tfoot_ws; |
| 144: | } else { |
| 145: | $node->name = 'tbody'; |
| 146: | $content[] = $node; |
| 147: | $ws_accum =& $content; |
| 148: | } |
| 149: | break; |
| 150: | case 'colgroup': |
| 151: | case 'col': |
| 152: | $cols[] = $node; |
| 153: | $ws_accum =& $cols; |
| 154: | break; |
| 155: | case '#PCDATA': |
| 156: | |
| 157: | |
| 158: | |
| 159: | |
| 160: | if (!empty($node->is_whitespace)) { |
| 161: | $ws_accum[] = $node; |
| 162: | } |
| 163: | break; |
| 164: | } |
| 165: | } |
| 166: | |
| 167: | if (empty($content) && $thead === false && $tfoot === false) { |
| 168: | return false; |
| 169: | } |
| 170: | |
| 171: | $ret = $initial_ws; |
| 172: | if ($caption !== false) { |
| 173: | $ret[] = $caption; |
| 174: | $ret = array_merge($ret, $after_caption_ws); |
| 175: | } |
| 176: | if ($cols !== false) { |
| 177: | $ret = array_merge($ret, $cols); |
| 178: | } |
| 179: | if ($thead !== false) { |
| 180: | $ret[] = $thead; |
| 181: | $ret = array_merge($ret, $after_thead_ws); |
| 182: | } |
| 183: | if ($tfoot !== false) { |
| 184: | $ret[] = $tfoot; |
| 185: | $ret = array_merge($ret, $after_tfoot_ws); |
| 186: | } |
| 187: | |
| 188: | if ($tbody_mode) { |
| 189: | |
| 190: | $current_tr_tbody = null; |
| 191: | |
| 192: | foreach($content as $node) { |
| 193: | switch ($node->name) { |
| 194: | case 'tbody': |
| 195: | $current_tr_tbody = null; |
| 196: | $ret[] = $node; |
| 197: | break; |
| 198: | case 'tr': |
| 199: | if ($current_tr_tbody === null) { |
| 200: | $current_tr_tbody = new HTMLPurifier_Node_Element('tbody'); |
| 201: | $ret[] = $current_tr_tbody; |
| 202: | } |
| 203: | $current_tr_tbody->children[] = $node; |
| 204: | break; |
| 205: | case '#PCDATA': |
| 206: | |
| 207: | if ($current_tr_tbody === null) { |
| 208: | $ret[] = $node; |
| 209: | } else { |
| 210: | $current_tr_tbody->children[] = $node; |
| 211: | } |
| 212: | break; |
| 213: | } |
| 214: | } |
| 215: | } else { |
| 216: | $ret = array_merge($ret, $content); |
| 217: | } |
| 218: | |
| 219: | return $ret; |
| 220: | |
| 221: | } |
| 222: | } |
| 223: | |
| 224: | |
| 225: | |