Skip to:
Content

bbPress.org


Ignore:
Timestamp:
12/12/2016 02:06:38 PM (8 years ago)
Author:
xknown
Message:

Branch 0.9: Remove all the expressions that use the preg_replace function with the e modifier.

The e(val) modifier is not longer supported in PHP7, use preg_replace_callback instead.
See #3033

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/0.9/bb-includes/kses.php

    r516 r6162  
    4646###############################################################################
    4747{
    48   return preg_replace('%(<'.   # EITHER: <
     48  global $pass_allowed_html, $pass_allowed_protocols;
     49  $pass_allowed_html = $allowed_html;
     50  $pass_allowed_protocols = $allowed_protocols;
     51  return preg_replace_callback('%(<'.   # EITHER: <
    4952                      '[^>]*'. # things that aren't >
    5053                      '(>|$)'. # > or end of string
    51                       '|>)%e', # OR: just a >
    52                       "wp_kses_split2('\\1', \$allowed_html, ".
    53                       '$allowed_protocols)',
     54                      '|>)%', # OR: just a >
     55                      '_wp_kses_split_callback',
    5456                      $string);
    5557} # function wp_kses_split
    5658
     59function _wp_kses_split_callback( $match )
     60{
     61    global $pass_allowed_html, $pass_allowed_protocols;
     62    return wp_kses_split2( $match[1], $pass_allowed_html, $pass_allowed_protocols );
     63}
    5764
    5865function wp_kses_split2($string, $allowed_html, $allowed_protocols)
     
    435442###############################################################################
    436443{
    437   return preg_replace('/^((&[^;]*;|[\sA-Za-z0-9])*)'.
    438                       '(:|&#58;|&#[Xx]3[Aa];)\s*/e',
    439                       'wp_kses_bad_protocol_once2("\\1", $allowed_protocols)',
    440                       $string);
     444  $string2 = preg_split( '/:|&#0*58;|&#x0*3a;/i', $string, 2 );
     445  if ( isset($string2[1]) && ! preg_match('%/\?%', $string2[0]) )
     446    $string = wp_kses_bad_protocol_once2( $string2[0], $allowed_protocols ) . trim( $string2[1] );
     447  return $string;
    441448} # function wp_kses_bad_protocol_once
    442 
    443449
    444450function wp_kses_bad_protocol_once2($string, $allowed_protocols)
     
    482488  $string = preg_replace('/&amp;([A-Za-z][A-Za-z0-9]{0,19});/',
    483489                         '&\\1;', $string);
    484   $string = preg_replace('/&amp;#0*([0-9]{1,5});/e',
    485                          'wp_kses_normalize_entities2("\\1")', $string);
     490  $string = preg_replace_callback('/&amp;#0*([0-9]{1,5});/',
     491                         '_wp_kses_normalize_entities_callback', $string);
    486492  $string = preg_replace('/&amp;#([Xx])0*(([0-9A-Fa-f]{2}){1,2});/',
    487493                         '&#\\1\\2;', $string);
     
    490496} # function wp_kses_normalize_entities
    491497
     498function _wp_kses_normalize_entities_callback($match) {
     499  return wp_kses_normalize_entities2($match[1]);
     500}
    492501
    493502function wp_kses_normalize_entities2($i)
     
    508517###############################################################################
    509518{
    510   $string = preg_replace('/&#([0-9]+);/e', 'chr("\\1")', $string);
    511   $string = preg_replace('/&#[Xx]([0-9A-Fa-f]+);/e', 'chr(hexdec("\\1"))',
     519  $string = preg_replace_callback('/&#([0-9]+);/', '_wp_kses_decode_entities_chr', $string);
     520  $string = preg_replace_callback('/&#[Xx]([0-9A-Fa-f]+);/', '_wp_kses_decode_entities_chr_hexdec',
    512521                         $string);
    513522
     
    515524} # function wp_kses_decode_entities
    516525
     526# Regex callback for wp_kses_decode_entities()
     527function _wp_kses_decode_entities_chr( $match ) {
     528  return chr( $match[1] );
     529}
     530
     531##
     532function _wp_kses_decode_entities_chr_hexdec( $match ) {
     533  return chr( hexdec( $match[1] ) );
     534}
    517535?>
Note: See TracChangeset for help on using the changeset viewer.