Changeset 21790
- Timestamp:
- 09/10/2012 04:19:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/kses.php
r21777 r21790 52 52 'address' => array(), 53 53 'a' => array( 54 'class' => true,55 54 'href' => true, 56 'id' => true,57 'title' => true,58 55 'rel' => true, 59 56 'rev' => true, … … 61 58 'target' => true, 62 59 ), 63 'abbr' => array( 64 'class' => true, 65 'title' => true, 66 ), 67 'acronym' => array( 68 'title' => true, 60 'abbr' => array(), 61 'acronym' => array(), 62 'area' => array( 63 'alt' => true, 64 'coords' => true, 65 'href' => true, 66 'nohref' => true, 67 'shape' => true, 68 'target' => true, 69 69 ), 70 70 'article' => array( 71 71 'align' => true, 72 'class' => true, 73 'dir' => true, 74 'lang' => true, 75 'style' => true, 72 'dir' => true, 73 'lang' => true, 76 74 'xml:lang' => true, 77 75 ), 78 76 'aside' => array( 79 77 'align' => true, 80 'class' => true, 81 'dir' => true, 82 'lang' => true, 83 'style' => true, 78 'dir' => true, 79 'lang' => true, 84 80 'xml:lang' => true, 85 81 ), … … 87 83 'big' => array(), 88 84 'blockquote' => array( 89 'id' => true,90 85 'cite' => true, 91 'class' => true,92 86 'lang' => true, 93 87 'xml:lang' => true, 94 88 ), 95 'br' => array ( 96 'class' => true, 97 ), 89 'br' => array(), 98 90 'button' => array( 99 91 'disabled' => true, … … 104 96 'caption' => array( 105 97 'align' => true, 106 'class' => true, 107 ), 108 'cite' => array ( 109 'class' => true, 110 'dir' => true, 111 'lang' => true, 112 'title' => true, 113 ), 114 'code' => array ( 115 'style' => true, 116 ), 98 ), 99 'cite' => array( 100 'dir' => true, 101 'lang' => true, 102 ), 103 'code' => array(), 117 104 'col' => array( 118 105 'align' => true, … … 121 108 'span' => true, 122 109 'dir' => true, 123 'style' => true,124 110 'valign' => true, 125 111 'width' => true, … … 131 117 'details' => array( 132 118 'align' => true, 133 'class' => true,134 119 'dir' => true, 135 120 'lang' => true, 136 121 'open' => true, 137 'style' => true,138 122 'xml:lang' => true, 139 123 ), 140 124 'div' => array( 141 125 'align' => true, 142 'class' => true, 143 'dir' => true, 144 'lang' => true, 145 'style' => true, 126 'dir' => true, 127 'lang' => true, 146 128 'xml:lang' => true, 147 129 ), … … 152 134 'figure' => array( 153 135 'align' => true, 154 'class' => true, 155 'dir' => true, 156 'lang' => true, 157 'style' => true, 136 'dir' => true, 137 'lang' => true, 158 138 'xml:lang' => true, 159 139 ), 160 140 'figcaption' => array( 161 141 'align' => true, 162 'class' => true, 163 'dir' => true, 164 'lang' => true, 165 'style' => true, 142 'dir' => true, 143 'lang' => true, 166 144 'xml:lang' => true, 167 145 ), … … 173 151 'footer' => array( 174 152 'align' => true, 175 'class' => true, 176 'dir' => true, 177 'lang' => true, 178 'style' => true, 153 'dir' => true, 154 'lang' => true, 179 155 'xml:lang' => true, 180 156 ), … … 190 166 'h1' => array( 191 167 'align' => true, 192 'class' => true, 193 'id' => true, 194 'style' => true, 195 ), 196 'h2' => array ( 197 'align' => true, 198 'class' => true, 199 'id' => true, 200 'style' => true, 201 ), 202 'h3' => array ( 203 'align' => true, 204 'class' => true, 205 'id' => true, 206 'style' => true, 207 ), 208 'h4' => array ( 209 'align' => true, 210 'class' => true, 211 'id' => true, 212 'style' => true, 213 ), 214 'h5' => array ( 215 'align' => true, 216 'class' => true, 217 'id' => true, 218 'style' => true, 219 ), 220 'h6' => array ( 221 'align' => true, 222 'class' => true, 223 'id' => true, 224 'style' => true, 168 ), 169 'h2' => array( 170 'align' => true, 171 ), 172 'h3' => array( 173 'align' => true, 174 ), 175 'h4' => array( 176 'align' => true, 177 ), 178 'h5' => array( 179 'align' => true, 180 ), 181 'h6' => array( 182 'align' => true, 225 183 ), 226 184 'header' => array( 227 185 'align' => true, 228 'class' => true, 229 'dir' => true, 230 'lang' => true, 231 'style' => true, 186 'dir' => true, 187 'lang' => true, 232 188 'xml:lang' => true, 233 189 ), 234 190 'hgroup' => array( 235 191 'align' => true, 236 'class' => true, 237 'dir' => true, 238 'lang' => true, 239 'style' => true, 192 'dir' => true, 193 'lang' => true, 240 194 'xml:lang' => true, 241 195 ), 242 'hr' => array ( 243 'align' => true, 244 'class' => true, 196 'hr' => array( 197 'align' => true, 245 198 'noshade' => true, 246 199 'size' => true, … … 252 205 'align' => true, 253 206 'border' => true, 254 'class' => true,255 207 'height' => true, 256 208 'hspace' => true, … … 258 210 'vspace' => true, 259 211 'src' => true, 260 ' style' => true,212 'usemap' => true, 261 213 'width' => true, 262 214 ), … … 272 224 'align' => true, 273 225 ), 274 'li' => array 275 'align' => true, 276 'class' => true,277 ),278 'menu' => array (279 'class' => true,280 'style' => true,226 'li' => array( 227 'align' => true, 228 ), 229 'map' => array( 230 'name' => true, 231 ), 232 'menu' => array( 281 233 'type' => true, 282 234 ), 283 235 'nav' => array( 284 236 'align' => true, 285 'class' => true, 286 'dir' => true, 287 'lang' => true, 288 'style' => true, 237 'dir' => true, 238 'lang' => true, 289 239 'xml:lang' => true, 290 240 ), 291 241 'p' => array( 292 'class' => true, 293 'align' => true, 294 'dir' => true, 295 'lang' => true, 296 'style' => true, 242 'align' => true, 243 'dir' => true, 244 'lang' => true, 297 245 'xml:lang' => true, 298 246 ), 299 247 'pre' => array( 300 'style' => true,301 248 'width' => true, 302 249 ), … … 305 252 ), 306 253 's' => array(), 307 'span' => array ( 308 'class' => true, 309 'dir' => true, 310 'align' => true, 311 'lang' => true, 312 'style' => true, 313 'title' => true, 254 'span' => array( 255 'dir' => true, 256 'align' => true, 257 'lang' => true, 314 258 'xml:lang' => true, 315 259 ), 316 260 'section' => array( 317 261 'align' => true, 318 'class' => true, 319 'dir' => true, 320 'lang' => true, 321 'style' => true, 262 'dir' => true, 263 'lang' => true, 322 264 'xml:lang' => true, 323 265 ), … … 328 270 'summary' => array( 329 271 'align' => true, 330 'class' => true, 331 'dir' => true, 332 'lang' => true, 333 'style' => true, 272 'dir' => true, 273 'lang' => true, 334 274 'xml:lang' => true, 335 275 ), … … 341 281 'cellpadding' => true, 342 282 'cellspacing' => true, 343 'class' => true, 344 'dir' => true, 345 'id' => true, 283 'dir' => true, 346 284 'rules' => true, 347 'style' => true,348 285 'summary' => true, 349 286 'width' => true, … … 362 299 'char' => true, 363 300 'charoff' => true, 364 'class' => true,365 301 'colspan' => true, 366 302 'dir' => true, … … 370 306 'rowspan' => true, 371 307 'scope' => true, 372 'style' => true,373 308 'valign' => true, 374 309 'width' => true, … … 384 319 'align' => true, 385 320 'char' => true, 386 'class' => true,387 321 'charoff' => true, 388 322 'valign' => true, … … 395 329 'char' => true, 396 330 'charoff' => true, 397 'class' => true,398 331 'colspan' => true, 399 332 'headers' => true, … … 409 342 'char' => true, 410 343 'charoff' => true, 411 'class' => true,412 344 'valign' => true, 413 345 ), … … 418 350 'char' => true, 419 351 'charoff' => true, 420 'class' => true,421 'style' => true,422 352 'valign' => true, 423 353 ), 424 354 'tt' => array(), 425 355 'u' => array(), 426 'ul' => array ( 427 'class' => true, 428 'style' => true, 356 'ul' => array( 429 357 'type' => true, 430 358 ), 431 'ol' => array ( 432 'class' => true, 359 'ol' => array( 433 360 'start' => true, 434 'style' => true,435 361 'type' => true, 436 362 ), … … 468 394 // 'dl' => array(), 469 395 // 'dt' => array(), 470 'em' => array (), 'i' => array (), 396 'em' => array(), 397 'i' => array(), 471 398 // 'ins' => array('datetime' => array(), 'cite' => array()), 472 399 // 'li' => array(), … … 527 454 'rang', 'loz', 'spades', 'clubs', 'hearts', 'diams', 528 455 ); 456 457 $allowedposttags = array_map( '_wp_add_global_attributes', $allowedposttags ); 458 } else { 459 $allowedtags = wp_kses_array_lc( $allowedtags ); 460 $allowedposttags = wp_kses_array_lc( $allowedposttags ); 529 461 } 530 462 … … 549 481 * @return string Filtered content with only allowed HTML elements 550 482 */ 551 function wp_kses( $string, $allowed_html, $allowed_protocols = array ()) {483 function wp_kses( $string, $allowed_html, $allowed_protocols = array() ) { 552 484 if ( empty( $allowed_protocols ) ) 553 485 $allowed_protocols = wp_allowed_protocols(); … … 555 487 $string = wp_kses_js_entities($string); 556 488 $string = wp_kses_normalize_entities($string); 557 $allowed_html_fixed = wp_kses_array_lc($allowed_html); 558 $string = wp_kses_hook($string, $allowed_html_fixed, $allowed_protocols); // WP changed the order of these funcs and added args to wp_kses_hook 559 return wp_kses_split($string, $allowed_html_fixed, $allowed_protocols); 489 $string = wp_kses_hook($string, $allowed_html, $allowed_protocols); // WP changed the order of these funcs and added args to wp_kses_hook 490 return wp_kses_split($string, $allowed_html, $allowed_protocols); 491 } 492 493 /** 494 * Return a list of allowed tags and attributes for a given context. 495 * 496 * @since 3.5.0 497 * 498 * @param string $context The context for which to retrieve tags. Allowed values are 499 * post | strip | data | entities or the name of a field filter such as pre_user_description. 500 * @return array List of allowed tags and their allowed attributes. 501 */ 502 function wp_kses_allowed_html( $context = '' ) { 503 global $allowedposttags, $allowedtags, $allowedentitynames; 504 505 if ( is_array( $context ) ) 506 return apply_filters( 'wp_kses_allowed_html', $context, 'explicit' ); 507 508 switch ( $context ) { 509 case 'post': 510 return apply_filters( 'wp_kses_allowed_html', $allowedposttags, $context ); 511 break; 512 case 'user_description': 513 case 'pre_user_description': 514 $tags = $allowedtags; 515 $tags['a']['rel'] = true; 516 return apply_filters( 'wp_kses_allowed_html', $tags, $context ); 517 break; 518 case 'strip': 519 return apply_filters( 'wp_kses_allowed_html', array(), $context ); 520 break; 521 case 'entities': 522 return apply_filters( 'wp_kses_allowed_html', $allowedentitynames, $context); 523 break; 524 case 'data': 525 default: 526 return apply_filters( 'wp_kses_allowed_html', $allowedtags, $context ); 527 } 560 528 } 561 529 … … 573 541 * @return string Filtered content through 'pre_kses' hook 574 542 */ 575 function wp_kses_hook( $string, $allowed_html, $allowed_protocols) {543 function wp_kses_hook( $string, $allowed_html, $allowed_protocols ) { 576 544 $string = apply_filters('pre_kses', $string, $allowed_html, $allowed_protocols); 577 545 return $string; … … 601 569 * @return string Content with fixed HTML tags 602 570 */ 603 function wp_kses_split( $string, $allowed_html, $allowed_protocols) {571 function wp_kses_split( $string, $allowed_html, $allowed_protocols ) { 604 572 global $pass_allowed_html, $pass_allowed_protocols; 605 573 $pass_allowed_html = $allowed_html; … … 669 637 $attrlist = $matches[3]; 670 638 639 if ( ! is_array( $allowed_html ) ) 640 $allowed_html = wp_kses_allowed_html( $allowed_html ); 641 671 642 if ( ! isset($allowed_html[strtolower($elem)]) ) 672 643 return ''; … … 699 670 function wp_kses_attr($element, $attr, $allowed_html, $allowed_protocols) { 700 671 # Is there a closing XHTML slash at the end of the attributes? 672 673 if ( ! is_array( $allowed_html ) ) 674 $allowed_html = wp_kses_allowed_html( $allowed_html ); 701 675 702 676 $xhtml_slash = ''; … … 778 752 */ 779 753 function wp_kses_hair($attr, $allowed_protocols) { 780 $attrarr = array 754 $attrarr = array(); 781 755 $mode = 0; 782 756 $attrname = ''; … … 1287 1261 * @return string Filtered content 1288 1262 */ 1289 function wp_filter_kses($data) { 1290 global $allowedtags; 1291 return addslashes( wp_kses(stripslashes( $data ), $allowedtags) ); 1263 function wp_filter_kses( $data ) { 1264 return addslashes( wp_kses( stripslashes( $data ), current_filter() ) ); 1292 1265 } 1293 1266 … … 1301 1274 * @return string Filtered content 1302 1275 */ 1303 function wp_kses_data($data) { 1304 global $allowedtags; 1305 return wp_kses( $data , $allowedtags ); 1276 function wp_kses_data( $data ) { 1277 return wp_kses( $data , current_filter() ); 1306 1278 } 1307 1279 … … 1313 1285 * 1314 1286 * @since 2.0.0 1315 * @uses $allowedposttags1316 1287 * 1317 1288 * @param string $data Post content to filter, expected to be escaped with slashes … … 1319 1290 */ 1320 1291 function wp_filter_post_kses($data) { 1321 global $allowedposttags; 1322 return addslashes ( wp_kses(stripslashes( $data ), $allowedposttags) ); 1292 return addslashes ( wp_kses( stripslashes( $data ), 'post' ) ); 1323 1293 } 1324 1294 … … 1330 1300 * 1331 1301 * @since 2.9.0 1332 * @uses $allowedposttags1333 1302 * 1334 1303 * @param string $data Post content to filter … … 1336 1305 */ 1337 1306 function wp_kses_post($data) { 1338 global $allowedposttags; 1339 return wp_kses( $data , $allowedposttags ); 1307 return wp_kses( $data , 'post' ); 1340 1308 } 1341 1309 … … 1348 1316 * @return string Filtered content without any HTML 1349 1317 */ 1350 function wp_filter_nohtml_kses( $data) {1351 return addslashes ( wp_kses( stripslashes( $data ), array()) );1318 function wp_filter_nohtml_kses( $data ) { 1319 return addslashes ( wp_kses( stripslashes( $data ), 'strip' ) ); 1352 1320 } 1353 1321 … … 1485 1453 return $css; 1486 1454 } 1455 1456 /** 1457 * Helper function to add global attributes to a tag in the allowed html list. 1458 * 1459 * @since 3.5.0 1460 * @access private 1461 * 1462 * @param array $value An array of attributes. 1463 * @return array The array of attributes with global attributes added. 1464 */ 1465 function _wp_add_global_attributes( $value ) { 1466 $global_attributes = array( 1467 'class' => true, 1468 'id' => true, 1469 'style' => true, 1470 'title' => true, 1471 ); 1472 1473 if ( true === $value ) 1474 $value = array(); 1475 1476 if ( is_array( $value ) ) 1477 return array_merge( $value, $global_attributes ); 1478 1479 return $value; 1480 }
Note: See TracChangeset
for help on using the changeset viewer.