[ Index ]

PHP Cross Reference of BackPress

title

Body

[close]

/includes/ -> functions.formatting.php (source)

   1  <?php
   2  // Last sync [WP20951]
   3  /**
   4   * Main BackPress Formatting API.based on wp-includes/formatting.php
   5   *
   6   * Handles many functions for formatting output.
   7   * Excluded functions are indicated in comments
   8   *
   9   * @package BackPress
  10   **/
  11  
  12  if ( !function_exists( 'wptexturize' ) ) :
  13  /**
  14   * Replaces common plain text characters into formatted entities
  15   *
  16   * As an example,
  17   * <code>
  18   * 'cause today's effort makes it worth tomorrow's "holiday"...
  19   * </code>
  20   * Becomes:
  21   * <code>
  22   * &#8217;cause today&#8217;s effort makes it worth tomorrow&#8217;s &#8220;holiday&#8221;&#8230;
  23   * </code>
  24   * Code within certain html blocks are skipped.
  25   *
  26   * @since 0.71
  27   * @uses $wp_cockneyreplace Array of formatted entities for certain common phrases
  28   *
  29   * @param string $text The text to be formatted
  30   * @return string The string replaced with html entities
  31   */
  32  function wptexturize($text) {
  33      global $wp_cockneyreplace;
  34      static $static_characters, $static_replacements, $dynamic_characters, $dynamic_replacements,
  35          $default_no_texturize_tags, $default_no_texturize_shortcodes;
  36  
  37      // No need to set up these static variables more than once
  38      if ( ! isset( $static_characters ) ) {
  39          /* translators: opening curly double quote */
  40          $opening_quote = _x( '&#8220;', 'opening curly double quote' );
  41          /* translators: closing curly double quote */
  42          $closing_quote = _x( '&#8221;', 'closing curly double quote' );
  43  
  44          /* translators: apostrophe, for example in 'cause or can't */
  45          $apos = _x( '&#8217;', 'apostrophe' );
  46  
  47          /* translators: prime, for example in 9' (nine feet) */
  48          $prime = _x( '&#8242;', 'prime' );
  49          /* translators: double prime, for example in 9" (nine inches) */
  50          $double_prime = _x( '&#8243;', 'double prime' );
  51  
  52          /* translators: opening curly single quote */
  53          $opening_single_quote = _x( '&#8216;', 'opening curly single quote' );
  54          /* translators: closing curly single quote */
  55          $closing_single_quote = _x( '&#8217;', 'closing curly single quote' );
  56  
  57          /* translators: en dash */
  58          $en_dash = _x( '&#8211;', 'en dash' );
  59          /* translators: em dash */
  60          $em_dash = _x( '&#8212;', 'em dash' );
  61  
  62          $default_no_texturize_tags = array('pre', 'code', 'kbd', 'style', 'script', 'tt');
  63          $default_no_texturize_shortcodes = array('code');
  64  
  65          // if a plugin has provided an autocorrect array, use it
  66          if ( isset($wp_cockneyreplace) ) {
  67              $cockney = array_keys($wp_cockneyreplace);
  68              $cockneyreplace = array_values($wp_cockneyreplace);
  69          } elseif ( "'" != $apos ) { // Only bother if we're doing a replacement.
  70              $cockney = array( "'tain't", "'twere", "'twas", "'tis", "'twill", "'til", "'bout", "'nuff", "'round", "'cause" );
  71              $cockneyreplace = array( $apos . "tain" . $apos . "t", $apos . "twere", $apos . "twas", $apos . "tis", $apos . "twill", $apos . "til", $apos . "bout", $apos . "nuff", $apos . "round", $apos . "cause" );
  72          } else {
  73              $cockney = $cockneyreplace = array();
  74          }
  75  
  76          $static_characters = array_merge( array( '---', ' -- ', '--', ' - ', 'xn&#8211;', '...', '``', '\'\'', ' (tm)' ), $cockney );
  77          $static_replacements = array_merge( array( $em_dash, ' ' . $em_dash . ' ', $en_dash, ' ' . $en_dash . ' ', 'xn--', '&#8230;', $opening_quote, $closing_quote, ' &#8482;' ), $cockneyreplace );
  78  
  79          $dynamic = array();
  80          if ( "'" != $apos ) {
  81              $dynamic[ '/\'(\d\d(?:&#8217;|\')?s)/' ] = $apos . '$1'; // '99's
  82              $dynamic[ '/\'(\d)/'                   ] = $apos . '$1'; // '99
  83          }
  84          if ( "'" != $opening_single_quote )
  85              $dynamic[ '/(\s|\A|[([{<]|")\'/'       ] = '$1' . $opening_single_quote; // opening single quote, even after (, {, <, [
  86          if ( '"' != $double_prime )
  87              $dynamic[ '/(\d)"/'                    ] = '$1' . $double_prime; // 9" (double prime)
  88          if ( "'" != $prime )
  89              $dynamic[ '/(\d)\'/'                   ] = '$1' . $prime; // 9' (prime)
  90          if ( "'" != $apos )
  91              $dynamic[ '/(\S)\'([^\'\s])/'          ] = '$1' . $apos . '$2'; // apostrophe in a word
  92          if ( '"' != $opening_quote )
  93              $dynamic[ '/(\s|\A|[([{<])"(?!\s)/'    ] = '$1' . $opening_quote . '$2'; // opening double quote, even after (, {, <, [
  94          if ( '"' != $closing_quote )
  95              $dynamic[ '/"(\s|\S|\Z)/'              ] = $closing_quote . '$1'; // closing double quote
  96          if ( "'" != $closing_single_quote )
  97              $dynamic[ '/\'([\s.]|\Z)/'             ] = $closing_single_quote . '$1'; // closing single quote
  98  
  99          $dynamic[ '/\b(\d+)x(\d+)\b/'              ] = '$1&#215;$2'; // 9x9 (times)
 100  
 101          $dynamic_characters = array_keys( $dynamic );
 102          $dynamic_replacements = array_values( $dynamic );
 103      }
 104  
 105      // Transform into regexp sub-expression used in _wptexturize_pushpop_element
 106      // Must do this everytime in case plugins use these filters in a context sensitive manner
 107      $no_texturize_tags = '(' . implode('|', apply_filters('no_texturize_tags', $default_no_texturize_tags) ) . ')';
 108      $no_texturize_shortcodes = '(' . implode('|', apply_filters('no_texturize_shortcodes', $default_no_texturize_shortcodes) ) . ')';
 109  
 110      $no_texturize_tags_stack = array();
 111      $no_texturize_shortcodes_stack = array();
 112  
 113      $textarr = preg_split('/(<.*>|\[.*\])/Us', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
 114  
 115      foreach ( $textarr as &$curl ) {
 116          if ( empty( $curl ) )
 117              continue;
 118  
 119          // Only call _wptexturize_pushpop_element if first char is correct tag opening
 120          $first = $curl[0];
 121          if ( '<' === $first ) {
 122              _wptexturize_pushpop_element($curl, $no_texturize_tags_stack, $no_texturize_tags, '<', '>');
 123          } elseif ( '[' === $first ) {
 124              _wptexturize_pushpop_element($curl, $no_texturize_shortcodes_stack, $no_texturize_shortcodes, '[', ']');
 125          } elseif ( empty($no_texturize_shortcodes_stack) && empty($no_texturize_tags_stack) ) {
 126              // This is not a tag, nor is the texturization disabled static strings
 127              $curl = str_replace($static_characters, $static_replacements, $curl);
 128              // regular expressions
 129              $curl = preg_replace($dynamic_characters, $dynamic_replacements, $curl);
 130          }
 131          $curl = preg_replace('/&([^#])(?![a-zA-Z1-4]{1,8};)/', '&#038;$1', $curl);
 132      }
 133      return implode( '', $textarr );
 134  }
 135  endif;
 136  
 137  if ( !function_exists( '_wptexturize_pushpop_element' ) ) :
 138  /**
 139   * Search for disabled element tags. Push element to stack on tag open and pop
 140   * on tag close. Assumes first character of $text is tag opening.
 141   *
 142   * @access private
 143   * @since 2.9.0
 144   *
 145   * @param string $text Text to check. First character is assumed to be $opening
 146   * @param array $stack Array used as stack of opened tag elements
 147   * @param string $disabled_elements Tags to match against formatted as regexp sub-expression
 148   * @param string $opening Tag opening character, assumed to be 1 character long
 149   * @param string $opening Tag closing  character
 150   * @return object
 151   */
 152  function _wptexturize_pushpop_element($text, &$stack, $disabled_elements, $opening = '<', $closing = '>') {
 153      // Check if it is a closing tag -- otherwise assume opening tag
 154      if (strncmp($opening . '/', $text, 2)) {
 155          // Opening? Check $text+1 against disabled elements
 156          if (preg_match('/^' . $disabled_elements . '\b/', substr($text, 1), $matches)) {
 157              /*
 158               * This disables texturize until we find a closing tag of our type
 159               * (e.g. <pre>) even if there was invalid nesting before that
 160               *
 161               * Example: in the case <pre>sadsadasd</code>"baba"</pre>
 162               *          "baba" won't be texturize
 163               */
 164  
 165              array_push($stack, $matches[1]);
 166          }
 167      } else {
 168          // Closing? Check $text+2 against disabled elements
 169          $c = preg_quote($closing, '/');
 170          if (preg_match('/^' . $disabled_elements . $c . '/', substr($text, 2), $matches)) {
 171              $last = array_pop($stack);
 172  
 173              // Make sure it matches the opening tag
 174              if ($last != $matches[1])
 175                  array_push($stack, $last);
 176          }
 177      }
 178  }
 179  endif;
 180  
 181  // @todo: Deprecated in WP 3.4 can probably remove as was only used by autop and we never had that [WP20307]
 182  if ( !function_exists( 'clean_pre' ) ) :
 183  /**
 184   * Accepts matches array from preg_replace_callback in wpautop() or a string.
 185   *
 186   * Ensures that the contents of a <<pre>>...<</pre>> HTML block are not
 187   * converted into paragraphs or line-breaks.
 188   *
 189   * @since 1.2.0
 190   *
 191   * @param array|string $matches The array or string
 192   * @return string The pre block without paragraph/line-break conversion.
 193   */
 194  function clean_pre($matches) {
 195      if ( is_array($matches) )
 196          $text = $matches[1] . $matches[2] . "</pre>";
 197      else
 198          $text = $matches;
 199  
 200      $text = str_replace('<br />', '', $text);
 201      $text = str_replace('<p>', "\n", $text);
 202      $text = str_replace('</p>', '', $text);
 203  
 204      return $text;
 205  }
 206  endif;
 207  
 208  // ! function wpautop()
 209  // ! function _autop_newline_preservation_helper()
 210  // ! function shortcode_unautop()
 211  
 212  if ( !function_exists('seems_utf8') ) :
 213  /**
 214   * Checks to see if a string is utf8 encoded.
 215   *
 216   * NOTE: This function checks for 5-Byte sequences, UTF8
 217   *       has Bytes Sequences with a maximum length of 4.
 218   *
 219   * @author bmorel at ssi dot fr (modified)
 220   * @since 1.2.1
 221   *
 222   * @param string $str The string to be checked
 223   * @return bool True if $str fits a UTF-8 model, false otherwise.
 224   */
 225  function seems_utf8($str) {
 226      $length = strlen($str);
 227      for ($i=0; $i < $length; $i++) {
 228          $c = ord($str[$i]);
 229          if ($c < 0x80) $n = 0; # 0bbbbbbb
 230          elseif (($c & 0xE0) == 0xC0) $n=1; # 110bbbbb
 231          elseif (($c & 0xF0) == 0xE0) $n=2; # 1110bbbb
 232          elseif (($c & 0xF8) == 0xF0) $n=3; # 11110bbb
 233          elseif (($c & 0xFC) == 0xF8) $n=4; # 111110bb
 234          elseif (($c & 0xFE) == 0xFC) $n=5; # 1111110b
 235          else return false; # Does not match any model
 236          for ($j=0; $j<$n; $j++) { # n bytes matching 10bbbbbb follow ?
 237              if ((++$i == $length) || ((ord($str[$i]) & 0xC0) != 0x80))
 238                  return false;
 239          }
 240      }
 241      return true;
 242  }
 243  endif;
 244  
 245  if ( !function_exists('_wp_specialchars') ) :
 246  /**
 247   * Converts a number of special characters into their HTML entities.
 248   *
 249   * Specifically deals with: &, <, >, ", and '.
 250   *
 251   * $quote_style can be set to ENT_COMPAT to encode " to
 252   * &quot;, or ENT_QUOTES to do both. Default is ENT_NOQUOTES where no quotes are encoded.
 253   *
 254   * @since 1.2.2
 255   *
 256   * @param string $string The text which is to be encoded.
 257   * @param mixed $quote_style Optional. Converts double quotes if set to ENT_COMPAT, both single and double if set to ENT_QUOTES or none if set to ENT_NOQUOTES. Also compatible with old values; converting single quotes if set to 'single', double if set to 'double' or both if otherwise set. Default is ENT_NOQUOTES.
 258   * @param string $charset Optional. The character encoding of the string. Default is false.
 259   * @param boolean $double_encode Optional. Whether to encode existing html entities. Default is false.
 260   * @return string The encoded text with HTML entities.
 261   */
 262  function _wp_specialchars( $string, $quote_style = ENT_NOQUOTES, $charset = false, $double_encode = false ) {
 263      $string = (string) $string;
 264  
 265      if ( 0 === strlen( $string ) )
 266          return '';
 267  
 268      // Don't bother if there are no specialchars - saves some processing
 269      if ( ! preg_match( '/[&<>"\']/', $string ) )
 270          return $string;
 271  
 272      // Account for the previous behaviour of the function when the $quote_style is not an accepted value
 273      if ( empty( $quote_style ) )
 274          $quote_style = ENT_NOQUOTES;
 275      elseif ( ! in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) )
 276          $quote_style = ENT_QUOTES;
 277  
 278      // Store the site charset as a static to avoid multiple calls to backpress_get_option()
 279      if ( !$charset ) {
 280          static $_charset;
 281          if ( !isset( $_charset ) ) {
 282              $_charset = backpress_get_option( 'charset' );
 283          }
 284          $charset = $_charset;
 285      }
 286  
 287      if ( in_array( $charset, array( 'utf8', 'utf-8', 'UTF8' ) ) )
 288          $charset = 'UTF-8';
 289  
 290      $_quote_style = $quote_style;
 291  
 292      if ( $quote_style === 'double' ) {
 293          $quote_style = ENT_COMPAT;
 294          $_quote_style = ENT_COMPAT;
 295      } elseif ( $quote_style === 'single' ) {
 296          $quote_style = ENT_NOQUOTES;
 297      }
 298  
 299      // Handle double encoding ourselves
 300      if ( $double_encode ) {
 301          $string = @htmlspecialchars( $string, $quote_style, $charset );
 302      } else {
 303          // Decode &amp; into &
 304          $string = wp_specialchars_decode( $string, $_quote_style );
 305  
 306          // Guarantee every &entity; is valid or re-encode the &
 307          $string = wp_kses_normalize_entities( $string );
 308  
 309          // Now re-encode everything except &entity;
 310          $string = preg_split( '/(&#?x?[0-9a-z]+;)/i', $string, -1, PREG_SPLIT_DELIM_CAPTURE );
 311  
 312          for ( $i = 0; $i < count( $string ); $i += 2 )
 313              $string[$i] = @htmlspecialchars( $string[$i], $quote_style, $charset );
 314  
 315          $string = implode( '', $string );
 316      }
 317  
 318      // Backwards compatibility
 319      if ( 'single' === $_quote_style )
 320          $string = str_replace( "'", '&#039;', $string );
 321  
 322      return $string;
 323  }
 324  endif;
 325  
 326  if ( !function_exists( 'wp_specialchars_decode' ) ) :
 327  /**
 328   * Converts a number of HTML entities into their special characters.
 329   *
 330   * Specifically deals with: &, <, >, ", and '.
 331   *
 332   * $quote_style can be set to ENT_COMPAT to decode " entities,
 333   * or ENT_QUOTES to do both " and '. Default is ENT_NOQUOTES where no quotes are decoded.
 334   *
 335   * @since 2.8
 336   *
 337   * @param string $string The text which is to be decoded.
 338   * @param mixed $quote_style Optional. Converts double quotes if set to ENT_COMPAT, both single and double if set to ENT_QUOTES or none if set to ENT_NOQUOTES. Also compatible with old _wp_specialchars() values; converting single quotes if set to 'single', double if set to 'double' or both if otherwise set. Default is ENT_NOQUOTES.
 339   * @return string The decoded text without HTML entities.
 340   */
 341  function wp_specialchars_decode( $string, $quote_style = ENT_NOQUOTES ) {
 342      $string = (string) $string;
 343  
 344      if ( 0 === strlen( $string ) ) {
 345          return '';
 346      }
 347  
 348      // Don't bother if there are no entities - saves a lot of processing
 349      if ( strpos( $string, '&' ) === false ) {
 350          return $string;
 351      }
 352  
 353      // Match the previous behaviour of _wp_specialchars() when the $quote_style is not an accepted value
 354      if ( empty( $quote_style ) ) {
 355          $quote_style = ENT_NOQUOTES;
 356      } elseif ( !in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) {
 357          $quote_style = ENT_QUOTES;
 358      }
 359  
 360      // More complete than get_html_translation_table( HTML_SPECIALCHARS )
 361      $single = array( '&#039;'  => '\'', '&#x27;' => '\'' );
 362      $single_preg = array( '/&#0*39;/'  => '&#039;', '/&#x0*27;/i' => '&#x27;' );
 363      $double = array( '&quot;' => '"', '&#034;'  => '"', '&#x22;' => '"' );
 364      $double_preg = array( '/&#0*34;/'  => '&#034;', '/&#x0*22;/i' => '&#x22;' );
 365      $others = array( '&lt;'   => '<', '&#060;'  => '<', '&gt;'   => '>', '&#062;'  => '>', '&amp;'  => '&', '&#038;'  => '&', '&#x26;' => '&' );
 366      $others_preg = array( '/&#0*60;/'  => '&#060;', '/&#0*62;/'  => '&#062;', '/&#0*38;/'  => '&#038;', '/&#x0*26;/i' => '&#x26;' );
 367  
 368      if ( $quote_style === ENT_QUOTES ) {
 369          $translation = array_merge( $single, $double, $others );
 370          $translation_preg = array_merge( $single_preg, $double_preg, $others_preg );
 371      } elseif ( $quote_style === ENT_COMPAT || $quote_style === 'double' ) {
 372          $translation = array_merge( $double, $others );
 373          $translation_preg = array_merge( $double_preg, $others_preg );
 374      } elseif ( $quote_style === 'single' ) {
 375          $translation = array_merge( $single, $others );
 376          $translation_preg = array_merge( $single_preg, $others_preg );
 377      } elseif ( $quote_style === ENT_NOQUOTES ) {
 378          $translation = $others;
 379          $translation_preg = $others_preg;
 380      }
 381  
 382      // Remove zero padding on numeric entities
 383      $string = preg_replace( array_keys( $translation_preg ), array_values( $translation_preg ), $string );
 384  
 385      // Replace characters according to translation table
 386      return strtr( $string, $translation );
 387  }
 388  endif;
 389  
 390  if ( !function_exists( 'wp_check_invalid_utf8' ) ) :
 391  /**
 392   * Checks for invalid UTF8 in a string.
 393   *
 394   * @since 2.8
 395   *
 396   * @param string $string The text which is to be checked.
 397   * @param boolean $strip Optional. Whether to attempt to strip out invalid UTF8. Default is false.
 398   * @return string The checked text.
 399   */
 400  function wp_check_invalid_utf8( $string, $strip = false ) {
 401      $string = (string) $string;
 402  
 403      if ( 0 === strlen( $string ) ) {
 404          return '';
 405      }
 406  
 407      // Store the site charset as a static to avoid multiple calls to backpress_get_option()
 408      static $is_utf8;
 409      if ( !isset( $is_utf8 ) ) {
 410          $is_utf8 = in_array( backpress_get_option( 'charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) );
 411      }
 412      if ( !$is_utf8 ) {
 413          return $string;
 414      }
 415  
 416      // Check for support for utf8 in the installed PCRE library once and store the result in a static
 417      static $utf8_pcre;
 418      if ( !isset( $utf8_pcre ) ) {
 419          $utf8_pcre = @preg_match( '/^./u', 'a' );
 420      }
 421      // We can't demand utf8 in the PCRE installation, so just return the string in those cases
 422      if ( !$utf8_pcre ) {
 423          return $string;
 424      }
 425  
 426      // preg_match fails when it encounters invalid UTF8 in $string
 427      if ( 1 === @preg_match( '/^./us', $string ) ) {
 428          return $string;
 429      }
 430  
 431      // Attempt to strip the bad chars if requested (not recommended)
 432      if ( $strip && function_exists( 'iconv' ) ) {
 433          return iconv( 'utf-8', 'utf-8', $string );
 434      }
 435  
 436      return '';
 437  }
 438  endif;
 439  
 440  if ( !function_exists('utf8_uri_encode') ) :
 441  /**
 442   * Encode the Unicode values to be used in the URI.
 443   *
 444   * @since 1.5.0
 445   *
 446   * @param string $utf8_string
 447   * @param int $length Max length of the string
 448   * @return string String with Unicode encoded for URI.
 449   */
 450  function utf8_uri_encode( $utf8_string, $length = 0 ) {
 451      $unicode = '';
 452      $values = array();
 453      $num_octets = 1;
 454      $unicode_length = 0;
 455  
 456      $string_length = strlen( $utf8_string );
 457      for ($i = 0; $i < $string_length; $i++ ) {
 458  
 459          $value = ord( $utf8_string[ $i ] );
 460  
 461          if ( $value < 128 ) {
 462              if ( $length && ( $unicode_length >= $length ) )
 463                  break;
 464              $unicode .= chr($value);
 465              $unicode_length++;
 466          } else {
 467              if ( count( $values ) == 0 ) $num_octets = ( $value < 224 ) ? 2 : 3;
 468  
 469              $values[] = $value;
 470  
 471              if ( $length && ( $unicode_length + ($num_octets * 3) ) > $length )
 472                  break;
 473              if ( count( $values ) == $num_octets ) {
 474                  if ($num_octets == 3) {
 475                      $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]) . '%' . dechex($values[2]);
 476                      $unicode_length += 9;
 477                  } else {
 478                      $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]);
 479                      $unicode_length += 6;
 480                  }
 481  
 482                  $values = array();
 483                  $num_octets = 1;
 484              }
 485          }
 486      }
 487  
 488      return $unicode;
 489  }
 490  endif;
 491  
 492  if ( !function_exists('remove_accents') ) :
 493  /**
 494   * Converts all accent characters to ASCII characters.
 495   *
 496   * If there are no accent characters, then the string given is just returned.
 497   *
 498   * @since 1.2.1
 499   *
 500   * @param string $string Text that might have accent characters
 501   * @return string Filtered string with replaced "nice" characters.
 502   */
 503  function remove_accents($string) {
 504      if ( !preg_match('/[\x80-\xff]/', $string) )
 505          return $string;
 506  
 507      if (seems_utf8($string)) {
 508          $chars = array(
 509          // Decompositions for Latin-1 Supplement
 510          chr(194).chr(170) => 'a', chr(194).chr(186) => 'o',
 511          chr(195).chr(128) => 'A', chr(195).chr(129) => 'A',
 512          chr(195).chr(130) => 'A', chr(195).chr(131) => 'A',
 513          chr(195).chr(132) => 'A', chr(195).chr(133) => 'A',
 514          chr(195).chr(134) => 'AE',chr(195).chr(135) => 'C',
 515          chr(195).chr(136) => 'E', chr(195).chr(137) => 'E',
 516          chr(195).chr(138) => 'E', chr(195).chr(139) => 'E',
 517          chr(195).chr(140) => 'I', chr(195).chr(141) => 'I',
 518          chr(195).chr(142) => 'I', chr(195).chr(143) => 'I',
 519          chr(195).chr(144) => 'D', chr(195).chr(145) => 'N',
 520          chr(195).chr(146) => 'O', chr(195).chr(147) => 'O',
 521          chr(195).chr(148) => 'O', chr(195).chr(149) => 'O',
 522          chr(195).chr(150) => 'O', chr(195).chr(153) => 'U',
 523          chr(195).chr(154) => 'U', chr(195).chr(155) => 'U',
 524          chr(195).chr(156) => 'U', chr(195).chr(157) => 'Y',
 525          chr(195).chr(158) => 'TH',chr(195).chr(159) => 's',
 526          chr(195).chr(160) => 'a', chr(195).chr(161) => 'a',
 527          chr(195).chr(162) => 'a', chr(195).chr(163) => 'a',
 528          chr(195).chr(164) => 'a', chr(195).chr(165) => 'a',
 529          chr(195).chr(166) => 'ae',chr(195).chr(167) => 'c',
 530          chr(195).chr(168) => 'e', chr(195).chr(169) => 'e',
 531          chr(195).chr(170) => 'e', chr(195).chr(171) => 'e',
 532          chr(195).chr(172) => 'i', chr(195).chr(173) => 'i',
 533          chr(195).chr(174) => 'i', chr(195).chr(175) => 'i',
 534          chr(195).chr(176) => 'd', chr(195).chr(177) => 'n',
 535          chr(195).chr(178) => 'o', chr(195).chr(179) => 'o',
 536          chr(195).chr(180) => 'o', chr(195).chr(181) => 'o',
 537          chr(195).chr(182) => 'o', chr(195).chr(184) => 'o',
 538          chr(195).chr(185) => 'u', chr(195).chr(186) => 'u',
 539          chr(195).chr(187) => 'u', chr(195).chr(188) => 'u',
 540          chr(195).chr(189) => 'y', chr(195).chr(190) => 'th',
 541          chr(195).chr(191) => 'y', chr(195).chr(152) => 'O',
 542          // Decompositions for Latin Extended-A
 543          chr(196).chr(128) => 'A', chr(196).chr(129) => 'a',
 544          chr(196).chr(130) => 'A', chr(196).chr(131) => 'a',
 545          chr(196).chr(132) => 'A', chr(196).chr(133) => 'a',
 546          chr(196).chr(134) => 'C', chr(196).chr(135) => 'c',
 547          chr(196).chr(136) => 'C', chr(196).chr(137) => 'c',
 548          chr(196).chr(138) => 'C', chr(196).chr(139) => 'c',
 549          chr(196).chr(140) => 'C', chr(196).chr(141) => 'c',
 550          chr(196).chr(142) => 'D', chr(196).chr(143) => 'd',
 551          chr(196).chr(144) => 'D', chr(196).chr(145) => 'd',
 552          chr(196).chr(146) => 'E', chr(196).chr(147) => 'e',
 553          chr(196).chr(148) => 'E', chr(196).chr(149) => 'e',
 554          chr(196).chr(150) => 'E', chr(196).chr(151) => 'e',
 555          chr(196).chr(152) => 'E', chr(196).chr(153) => 'e',
 556          chr(196).chr(154) => 'E', chr(196).chr(155) => 'e',
 557          chr(196).chr(156) => 'G', chr(196).chr(157) => 'g',
 558          chr(196).chr(158) => 'G', chr(196).chr(159) => 'g',
 559          chr(196).chr(160) => 'G', chr(196).chr(161) => 'g',
 560          chr(196).chr(162) => 'G', chr(196).chr(163) => 'g',
 561          chr(196).chr(164) => 'H', chr(196).chr(165) => 'h',
 562          chr(196).chr(166) => 'H', chr(196).chr(167) => 'h',
 563          chr(196).chr(168) => 'I', chr(196).chr(169) => 'i',
 564          chr(196).chr(170) => 'I', chr(196).chr(171) => 'i',
 565          chr(196).chr(172) => 'I', chr(196).chr(173) => 'i',
 566          chr(196).chr(174) => 'I', chr(196).chr(175) => 'i',
 567          chr(196).chr(176) => 'I', chr(196).chr(177) => 'i',
 568          chr(196).chr(178) => 'IJ',chr(196).chr(179) => 'ij',
 569          chr(196).chr(180) => 'J', chr(196).chr(181) => 'j',
 570          chr(196).chr(182) => 'K', chr(196).chr(183) => 'k',
 571          chr(196).chr(184) => 'k', chr(196).chr(185) => 'L',
 572          chr(196).chr(186) => 'l', chr(196).chr(187) => 'L',
 573          chr(196).chr(188) => 'l', chr(196).chr(189) => 'L',
 574          chr(196).chr(190) => 'l', chr(196).chr(191) => 'L',
 575          chr(197).chr(128) => 'l', chr(197).chr(129) => 'L',
 576          chr(197).chr(130) => 'l', chr(197).chr(131) => 'N',
 577          chr(197).chr(132) => 'n', chr(197).chr(133) => 'N',
 578          chr(197).chr(134) => 'n', chr(197).chr(135) => 'N',
 579          chr(197).chr(136) => 'n', chr(197).chr(137) => 'N',
 580          chr(197).chr(138) => 'n', chr(197).chr(139) => 'N',
 581          chr(197).chr(140) => 'O', chr(197).chr(141) => 'o',
 582          chr(197).chr(142) => 'O', chr(197).chr(143) => 'o',
 583          chr(197).chr(144) => 'O', chr(197).chr(145) => 'o',
 584          chr(197).chr(146) => 'OE',chr(197).chr(147) => 'oe',
 585          chr(197).chr(148) => 'R',chr(197).chr(149) => 'r',
 586          chr(197).chr(150) => 'R',chr(197).chr(151) => 'r',
 587          chr(197).chr(152) => 'R',chr(197).chr(153) => 'r',
 588          chr(197).chr(154) => 'S',chr(197).chr(155) => 's',
 589          chr(197).chr(156) => 'S',chr(197).chr(157) => 's',
 590          chr(197).chr(158) => 'S',chr(197).chr(159) => 's',
 591          chr(197).chr(160) => 'S', chr(197).chr(161) => 's',
 592          chr(197).chr(162) => 'T', chr(197).chr(163) => 't',
 593          chr(197).chr(164) => 'T', chr(197).chr(165) => 't',
 594          chr(197).chr(166) => 'T', chr(197).chr(167) => 't',
 595          chr(197).chr(168) => 'U', chr(197).chr(169) => 'u',
 596          chr(197).chr(170) => 'U', chr(197).chr(171) => 'u',
 597          chr(197).chr(172) => 'U', chr(197).chr(173) => 'u',
 598          chr(197).chr(174) => 'U', chr(197).chr(175) => 'u',
 599          chr(197).chr(176) => 'U', chr(197).chr(177) => 'u',
 600          chr(197).chr(178) => 'U', chr(197).chr(179) => 'u',
 601          chr(197).chr(180) => 'W', chr(197).chr(181) => 'w',
 602          chr(197).chr(182) => 'Y', chr(197).chr(183) => 'y',
 603          chr(197).chr(184) => 'Y', chr(197).chr(185) => 'Z',
 604          chr(197).chr(186) => 'z', chr(197).chr(187) => 'Z',
 605          chr(197).chr(188) => 'z', chr(197).chr(189) => 'Z',
 606          chr(197).chr(190) => 'z', chr(197).chr(191) => 's',
 607          // Decompositions for Latin Extended-B
 608          chr(200).chr(152) => 'S', chr(200).chr(153) => 's',
 609          chr(200).chr(154) => 'T', chr(200).chr(155) => 't',
 610          // Euro Sign
 611          chr(226).chr(130).chr(172) => 'E',
 612          // GBP (Pound) Sign
 613          chr(194).chr(163) => '',
 614          // Vowels with diacritic (Vietnamese)
 615          // unmarked
 616          chr(198).chr(160) => 'O', chr(198).chr(161) => 'o',
 617          chr(198).chr(175) => 'U', chr(198).chr(176) => 'u',
 618          // grave accent
 619          chr(225).chr(186).chr(166) => 'A', chr(225).chr(186).chr(167) => 'a',
 620          chr(225).chr(186).chr(176) => 'A', chr(225).chr(186).chr(177) => 'a',
 621          chr(225).chr(187).chr(128) => 'E', chr(225).chr(187).chr(129) => 'e',
 622          chr(225).chr(187).chr(146) => 'O', chr(225).chr(187).chr(147) => 'o',
 623          chr(225).chr(187).chr(156) => 'O', chr(225).chr(187).chr(157) => 'o',
 624          chr(225).chr(187).chr(170) => 'U', chr(225).chr(187).chr(171) => 'u',
 625          chr(225).chr(187).chr(178) => 'Y', chr(225).chr(187).chr(179) => 'y',
 626          // hook
 627          chr(225).chr(186).chr(162) => 'A', chr(225).chr(186).chr(163) => 'a',
 628          chr(225).chr(186).chr(168) => 'A', chr(225).chr(186).chr(169) => 'a',
 629          chr(225).chr(186).chr(178) => 'A', chr(225).chr(186).chr(179) => 'a',
 630          chr(225).chr(186).chr(186) => 'E', chr(225).chr(186).chr(187) => 'e',
 631          chr(225).chr(187).chr(130) => 'E', chr(225).chr(187).chr(131) => 'e',
 632          chr(225).chr(187).chr(136) => 'I', chr(225).chr(187).chr(137) => 'i',
 633          chr(225).chr(187).chr(142) => 'O', chr(225).chr(187).chr(143) => 'o',
 634          chr(225).chr(187).chr(148) => 'O', chr(225).chr(187).chr(149) => 'o',
 635          chr(225).chr(187).chr(158) => 'O', chr(225).chr(187).chr(159) => 'o',
 636          chr(225).chr(187).chr(166) => 'U', chr(225).chr(187).chr(167) => 'u',
 637          chr(225).chr(187).chr(172) => 'U', chr(225).chr(187).chr(173) => 'u',
 638          chr(225).chr(187).chr(182) => 'Y', chr(225).chr(187).chr(183) => 'y',
 639          // tilde
 640          chr(225).chr(186).chr(170) => 'A', chr(225).chr(186).chr(171) => 'a',
 641          chr(225).chr(186).chr(180) => 'A', chr(225).chr(186).chr(181) => 'a',
 642          chr(225).chr(186).chr(188) => 'E', chr(225).chr(186).chr(189) => 'e',
 643          chr(225).chr(187).chr(132) => 'E', chr(225).chr(187).chr(133) => 'e',
 644          chr(225).chr(187).chr(150) => 'O', chr(225).chr(187).chr(151) => 'o',
 645          chr(225).chr(187).chr(160) => 'O', chr(225).chr(187).chr(161) => 'o',
 646          chr(225).chr(187).chr(174) => 'U', chr(225).chr(187).chr(175) => 'u',
 647          chr(225).chr(187).chr(184) => 'Y', chr(225).chr(187).chr(185) => 'y',
 648          // acute accent
 649          chr(225).chr(186).chr(164) => 'A', chr(225).chr(186).chr(165) => 'a',
 650          chr(225).chr(186).chr(174) => 'A', chr(225).chr(186).chr(175) => 'a',
 651          chr(225).chr(186).chr(190) => 'E', chr(225).chr(186).chr(191) => 'e',
 652          chr(225).chr(187).chr(144) => 'O', chr(225).chr(187).chr(145) => 'o',
 653          chr(225).chr(187).chr(154) => 'O', chr(225).chr(187).chr(155) => 'o',
 654          chr(225).chr(187).chr(168) => 'U', chr(225).chr(187).chr(169) => 'u',
 655          // dot below
 656          chr(225).chr(186).chr(160) => 'A', chr(225).chr(186).chr(161) => 'a',
 657          chr(225).chr(186).chr(172) => 'A', chr(225).chr(186).chr(173) => 'a',
 658          chr(225).chr(186).chr(182) => 'A', chr(225).chr(186).chr(183) => 'a',
 659          chr(225).chr(186).chr(184) => 'E', chr(225).chr(186).chr(185) => 'e',
 660          chr(225).chr(187).chr(134) => 'E', chr(225).chr(187).chr(135) => 'e',
 661          chr(225).chr(187).chr(138) => 'I', chr(225).chr(187).chr(139) => 'i',
 662          chr(225).chr(187).chr(140) => 'O', chr(225).chr(187).chr(141) => 'o',
 663          chr(225).chr(187).chr(152) => 'O', chr(225).chr(187).chr(153) => 'o',
 664          chr(225).chr(187).chr(162) => 'O', chr(225).chr(187).chr(163) => 'o',
 665          chr(225).chr(187).chr(164) => 'U', chr(225).chr(187).chr(165) => 'u',
 666          chr(225).chr(187).chr(176) => 'U', chr(225).chr(187).chr(177) => 'u',
 667          chr(225).chr(187).chr(180) => 'Y', chr(225).chr(187).chr(181) => 'y',
 668          );
 669  
 670          $string = strtr($string, $chars);
 671      } else {
 672          // Assume ISO-8859-1 if not UTF-8
 673          $chars['in'] = chr(128).chr(131).chr(138).chr(142).chr(154).chr(158)
 674              .chr(159).chr(162).chr(165).chr(181).chr(192).chr(193).chr(194)
 675              .chr(195).chr(196).chr(197).chr(199).chr(200).chr(201).chr(202)
 676              .chr(203).chr(204).chr(205).chr(206).chr(207).chr(209).chr(210)
 677              .chr(211).chr(212).chr(213).chr(214).chr(216).chr(217).chr(218)
 678              .chr(219).chr(220).chr(221).chr(224).chr(225).chr(226).chr(227)
 679              .chr(228).chr(229).chr(231).chr(232).chr(233).chr(234).chr(235)
 680              .chr(236).chr(237).chr(238).chr(239).chr(241).chr(242).chr(243)
 681              .chr(244).chr(245).chr(246).chr(248).chr(249).chr(250).chr(251)
 682              .chr(252).chr(253).chr(255);
 683  
 684          $chars['out'] = "EfSZszYcYuAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy";
 685  
 686          $string = strtr($string, $chars['in'], $chars['out']);
 687          $double_chars['in'] = array(chr(140), chr(156), chr(198), chr(208), chr(222), chr(223), chr(230), chr(240), chr(254));
 688          $double_chars['out'] = array('OE', 'oe', 'AE', 'DH', 'TH', 'ss', 'ae', 'dh', 'th');
 689          $string = str_replace($double_chars['in'], $double_chars['out'], $string);
 690      }
 691  
 692      return $string;
 693  }
 694  endif;
 695  
 696  // ! function sanitize_file_name()
 697  
 698  if ( !function_exists('sanitize_user') ) :
 699  /**
 700   * Sanitize username stripping out unsafe characters.
 701   *
 702   * Removes tags, octets, entities, and if strict is enabled, will only keep
 703   * alphanumeric, _, space, ., -, @. After sanitizing, it passes the username,
 704   * raw username (the username in the parameter), and the value of $strict as
 705   * parameters for the 'sanitize_user' filter.
 706   *
 707   * @since 2.0.0
 708   * @uses apply_filters() Calls 'sanitize_user' hook on username, raw username,
 709   *        and $strict parameter.
 710   *
 711   * @param string $username The username to be sanitized.
 712   * @param bool $strict If set limits $username to specific characters. Default false.
 713   * @return string The sanitized username, after passing through filters.
 714   */
 715  function sanitize_user( $username, $strict = false ) {
 716      $raw_username = $username;
 717      $username = wp_strip_all_tags( $username );
 718      $username = remove_accents( $username );
 719      // Kill octets
 720      $username = preg_replace( '|%([a-fA-F0-9][a-fA-F0-9])|', '', $username );
 721      $username = preg_replace( '/&.+?;/', '', $username ); // Kill entities
 722  
 723      // If strict, reduce to ASCII for max portability.
 724      if ( $strict )
 725          $username = preg_replace( '|[^a-z0-9 _.\-@]|i', '', $username );
 726  
 727      $username = trim( $username );
 728      // Consolidate contiguous whitespace
 729      $username = preg_replace( '|\s+|', ' ', $username );
 730  
 731      return apply_filters( 'sanitize_user', $username, $raw_username, $strict );
 732  }
 733  endif;
 734  
 735  if ( !function_exists('sanitize_key') ) :
 736  /**
 737   * Sanitize a string key.
 738   *
 739   * Keys are used as internal identifiers. Lowercase alphanumeric characters, dashes and underscores are allowed.
 740   *
 741   * @since 3.0.0
 742   *
 743   * @param string $key String key
 744   * @return string Sanitized key
 745   */
 746  function sanitize_key( $key ) {
 747      $raw_key = $key;
 748      $key = strtolower( $key );
 749      $key = preg_replace( '/[^a-z0-9_\-]/', '', $key );
 750      return apply_filters( 'sanitize_key', $key, $raw_key );
 751  }
 752  endif;
 753  
 754  if ( !function_exists('sanitize_title') ) :
 755  /**
 756   * Sanitizes title or use fallback title.
 757   *
 758   * Specifically, HTML and PHP tags are stripped. Further actions can be added
 759   * via the plugin API. If $title is empty and $fallback_title is set, the latter
 760   * will be used.
 761   *
 762   * @since 1.0.0
 763   *
 764   * @param string $title The string to be sanitized.
 765   * @param string $fallback_title Optional. A title to use if $title is empty.
 766   * @param string $context Optional. The operation for which the string is sanitized
 767   * @return string The sanitized string.
 768   */
 769  function sanitize_title($title, $fallback_title = '', $context = 'save') {
 770      $raw_title = $title;
 771  
 772      if ( 'save' == $context )
 773          $title = remove_accents($title);
 774  
 775      $title = apply_filters('sanitize_title', $title, $raw_title, $context);
 776  
 777      if ( '' === $title || false === $title )
 778          $title = $fallback_title;
 779  
 780      return $title;
 781  }
 782  endif;
 783  
 784  //! function sanitize_title_for_query
 785  
 786  if ( !function_exists('sanitize_title_with_dashes') ) :
 787  /**
 788   * Sanitizes title, replacing whitespace and a few other characters with dashes.
 789   *
 790   * Limits the output to alphanumeric characters, underscore (_) and dash (-).
 791   * Whitespace becomes a dash.
 792   *
 793   * @since 1.2.0
 794   *
 795   * @param string $title The title to be sanitized.
 796   * @param string $raw_title Optional. Not used.
 797   * @param string $context Optional. The operation for which the string is sanitized.
 798   * @return string The sanitized title.
 799   */
 800  function sanitize_title_with_dashes($title, $raw_title = '', $context = 'display') {
 801      $title = strip_tags($title);
 802      // Preserve escaped octets.
 803      $title = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $title);
 804      // Remove percent signs that are not part of an octet.
 805      $title = str_replace('%', '', $title);
 806      // Restore octets.
 807      $title = preg_replace('|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $title);
 808  
 809      if (seems_utf8($title)) {
 810          if (function_exists('mb_strtolower')) {
 811              $title = mb_strtolower($title, 'UTF-8');
 812          }
 813          $title = utf8_uri_encode($title, 200);
 814      }
 815  
 816      $title = strtolower($title);
 817      $title = preg_replace('/&.+?;/', '', $title); // kill entities
 818      $title = str_replace('.', '-', $title);
 819  
 820      if ( 'save' == $context ) {
 821          // Convert nbsp, ndash and mdash to hyphens
 822          $title = str_replace( array( '%c2%a0', '%e2%80%93', '%e2%80%94' ), '-', $title );
 823  
 824          // Strip these characters entirely
 825          $title = str_replace( array(
 826              // iexcl and iquest
 827              '%c2%a1', '%c2%bf',
 828              // angle quotes
 829              '%c2%ab', '%c2%bb', '%e2%80%b9', '%e2%80%ba',
 830              // curly quotes
 831              '%e2%80%98', '%e2%80%99', '%e2%80%9c', '%e2%80%9d',
 832              '%e2%80%9a', '%e2%80%9b', '%e2%80%9e', '%e2%80%9f',
 833              // copy, reg, deg, hellip and trade
 834              '%c2%a9', '%c2%ae', '%c2%b0', '%e2%80%a6', '%e2%84%a2',
 835          ), '', $title );
 836  
 837          // Convert times to x
 838          $title = str_replace( '%c3%97', 'x', $title );
 839      }
 840  
 841      $title = preg_replace('/[^%a-z0-9 _-]/', '', $title);
 842      $title = preg_replace('/\s+/', '-', $title);
 843      $title = preg_replace('|-+|', '-', $title);
 844      $title = trim($title, '-');
 845  
 846      return $title;
 847  }
 848  endif;
 849  
 850  // ! function sanitize_sql_orderby()
 851  // ! function sanitize_html_class()
 852  // ! function convert_chars()
 853  // ! function balanceTags()
 854  
 855  if ( !function_exists( 'force_balance_tags' ) ) :
 856  /**
 857   * Balances tags of string using a modified stack.
 858   *
 859   * @since 2.0.4
 860   *
 861   * @author Leonard Lin <leonard@acm.org>
 862   * @license GPL
 863   * @copyright November 4, 2001
 864   * @version 1.1
 865   * @todo Make better - change loop condition to $text in 1.2
 866   * @internal Modified by Scott Reilly (coffee2code) 02 Aug 2004
 867   *        1.1  Fixed handling of append/stack pop order of end text
 868   *             Added Cleaning Hooks
 869   *        1.0  First Version
 870   *
 871   * @param string $text Text to be balanced.
 872   * @return string Balanced text.
 873   */
 874  function force_balance_tags( $text ) {
 875      $tagstack = array();
 876      $stacksize = 0;
 877      $tagqueue = '';
 878      $newtext = '';
 879      $single_tags = array( 'br', 'hr', 'img', 'input' ); // Known single-entity/self-closing tags
 880      $nestable_tags = array( 'blockquote', 'div', 'span', 'q' ); // Tags that can be immediately nested within themselves
 881  
 882      // WP bug fix for comments - in case you REALLY meant to type '< !--'
 883      $text = str_replace('< !--', '<    !--', $text);
 884      // WP bug fix for LOVE <3 (and other situations with '<' before a number)
 885      $text = preg_replace('#<([0-9]{1})#', '&lt;$1', $text);
 886  
 887      while ( preg_match("/<(\/?[\w:]*)\s*([^>]*)>/", $text, $regex) ) {
 888          $newtext .= $tagqueue;
 889  
 890          $i = strpos($text, $regex[0]);
 891          $l = strlen($regex[0]);
 892  
 893          // clear the shifter
 894          $tagqueue = '';
 895          // Pop or Push
 896          if ( isset($regex[1][0]) && '/' == $regex[1][0] ) { // End Tag
 897              $tag = strtolower(substr($regex[1],1));
 898              // if too many closing tags
 899              if( $stacksize <= 0 ) {
 900                  $tag = '';
 901                  // or close to be safe $tag = '/' . $tag;
 902              }
 903              // if stacktop value = tag close value then pop
 904              else if ( $tagstack[$stacksize - 1] == $tag ) { // found closing tag
 905                  $tag = '</' . $tag . '>'; // Close Tag
 906                  // Pop
 907                  array_pop( $tagstack );
 908                  $stacksize--;
 909              } else { // closing tag not at top, search for it
 910                  for ( $j = $stacksize-1; $j >= 0; $j-- ) {
 911                      if ( $tagstack[$j] == $tag ) {
 912                      // add tag to tagqueue
 913                          for ( $k = $stacksize-1; $k >= $j; $k--) {
 914                              $tagqueue .= '</' . array_pop( $tagstack ) . '>';
 915                              $stacksize--;
 916                          }
 917                          break;
 918                      }
 919                  }
 920                  $tag = '';
 921              }
 922          } else { // Begin Tag
 923              $tag = strtolower($regex[1]);
 924  
 925              // Tag Cleaning
 926  
 927              // If self-closing or '', don't do anything.
 928              if ( substr($regex[2],-1) == '/' || $tag == '' ) {
 929                  // do nothing
 930              }
 931              // ElseIf it's a known single-entity tag but it doesn't close itself, do so
 932              elseif ( in_array($tag, $single_tags) ) {
 933                  $regex[2] .= '/';
 934              } else {    // Push the tag onto the stack
 935                  // If the top of the stack is the same as the tag we want to push, close previous tag
 936                  if ( $stacksize > 0 && !in_array($tag, $nestable_tags) && $tagstack[$stacksize - 1] == $tag ) {
 937                      $tagqueue = '</' . array_pop ($tagstack) . '>';
 938                      $stacksize--;
 939                  }
 940                  $stacksize = array_push ($tagstack, $tag);
 941              }
 942  
 943              // Attributes
 944              $attributes = $regex[2];
 945              if( !empty($attributes) )
 946                  $attributes = ' '.$attributes;
 947  
 948              $tag = '<' . $tag . $attributes . '>';
 949              //If already queuing a close tag, then put this tag on, too
 950              if ( !empty($tagqueue) ) {
 951                  $tagqueue .= $tag;
 952                  $tag = '';
 953              }
 954          }
 955          $newtext .= substr($text, 0, $i) . $tag;
 956          $text = substr($text, $i + $l);
 957      }
 958  
 959      // Clear Tag Queue
 960      $newtext .= $tagqueue;
 961  
 962      // Add Remaining text
 963      $newtext .= $text;
 964  
 965      // Empty Stack
 966      while( $x = array_pop($tagstack) )
 967          $newtext .= '</' . $x . '>'; // Add remaining tags to close
 968  
 969      // WP fix for the bug with HTML comments
 970      $newtext = str_replace("< !--","<!--",$newtext);
 971      $newtext = str_replace("<    !--","< !--",$newtext);
 972  
 973      return $newtext;
 974  }
 975  endif;
 976  
 977  if ( !function_exists('format_to_edit') ) :
 978  /**
 979   * Acts on text which is about to be edited.
 980   *
 981   * The $content is run through esc_textarea(), which uses htmlspecialchars()
 982   * to convert special characters to HTML entities. If $richedit is set to true,
 983   * it is simply a holder for the 'format_to_edit' filter.
 984   *
 985   * @since 0.71
 986   *
 987   * @param string $content The text about to be edited.
 988   * @param bool $richedit Whether the $content should not pass through htmlspecialchars(). Default false (meaning it will be passed).
 989   * @return string The text after the filter (and possibly htmlspecialchars()) has been run.
 990   */
 991  function format_to_edit( $content, $richedit = false ) {
 992      $content = apply_filters( 'format_to_edit', $content );
 993      if ( ! $richedit )
 994          $content = esc_textarea( $content );
 995      return $content;
 996  }
 997  endif;
 998  
 999  // !format_to_post()
1000  
1001  if ( !function_exists( 'zeroise' ) ) :
1002  /**
1003   * Add leading zeros when necessary.
1004   *
1005   * If you set the threshold to '4' and the number is '10', then you will get
1006   * back '0010'. If you set the threshold to '4' and the number is '5000', then you
1007   * will get back '5000'.
1008   *
1009   * Uses sprintf to append the amount of zeros based on the $threshold parameter
1010   * and the size of the number. If the number is large enough, then no zeros will
1011   * be appended.
1012   *
1013   * @since 0.71
1014   *
1015   * @param mixed $number Number to append zeros to if not greater than threshold.
1016   * @param int $threshold Digit places number needs to be to not have zeros added.
1017   * @return string Adds leading zeros to number if needed.
1018   */
1019  function zeroise($number, $threshold) {
1020      return sprintf('%0'.$threshold.'s', $number);
1021  }
1022  endif;
1023  
1024  if ( !function_exists( 'backslashit' ) ) :
1025  /**
1026   * Adds backslashes before letters and before a number at the start of a string.
1027   *
1028   * @since 0.71
1029   *
1030   * @param string $string Value to which backslashes will be added.
1031   * @return string String with backslashes inserted.
1032   */
1033  function backslashit($string) {
1034      $string = preg_replace('/^([0-9])/', '\\\\\\\\\1', $string);
1035      $string = preg_replace('/([a-z])/i', '\\\\\1', $string);
1036      return $string;
1037  }
1038  endif;
1039  
1040  if ( !function_exists( 'trailingslashit' ) ) :
1041  /**
1042   * Appends a trailing slash.
1043   *
1044   * Will remove trailing slash if it exists already before adding a trailing
1045   * slash. This prevents double slashing a string or path.
1046   *
1047   * The primary use of this is for paths and thus should be used for paths. It is
1048   * not restricted to paths and offers no specific path support.
1049   *
1050   * @since 1.2.0
1051   * @uses untrailingslashit() Unslashes string if it was slashed already.
1052   *
1053   * @param string $string What to add the trailing slash to.
1054   * @return string String with trailing slash added.
1055   */
1056  function trailingslashit($string) {
1057      return untrailingslashit($string) . '/';
1058  }
1059  endif;
1060  
1061  if ( !function_exists( 'untrailingslashit' ) ) :
1062  /**
1063   * Removes trailing slash if it exists.
1064   *
1065   * The primary use of this is for paths and thus should be used for paths. It is
1066   * not restricted to paths and offers no specific path support.
1067   *
1068   * @since 2.2.0
1069   *
1070   * @param string $string What to remove the trailing slash from.
1071   * @return string String without the trailing slash.
1072   */
1073  function untrailingslashit($string) {
1074      return rtrim($string, '/');
1075  }
1076  endif;
1077  
1078  // ! function addslashes_gpc()
1079  
1080  if ( !function_exists('stripslashes_deep') ) :
1081  /**
1082   * Navigates through an array and removes slashes from the values.
1083   *
1084   * If an array is passed, the array_map() function causes a callback to pass the
1085   * value back to the function. The slashes from this value will removed.
1086   *
1087   * @since 2.0.0
1088   *
1089   * @param array|string $value The array or string to be stripped.
1090   * @return array|string Stripped array (or string in the callback).
1091   */
1092  function stripslashes_deep($value) {
1093      if ( is_array($value) ) {
1094          $value = array_map('stripslashes_deep', $value);
1095      } elseif ( is_object($value) ) {
1096          $vars = get_object_vars( $value );
1097          foreach ($vars as $key=>$data) {
1098              $value->{$key} = stripslashes_deep( $data );
1099          }
1100      } else {
1101          $value = stripslashes($value);
1102      }
1103  
1104      return $value;
1105  }
1106  endif;
1107  
1108  if ( !function_exists( 'rawurlencode_deep' ) ) :
1109  /**
1110   * Navigates through an array and raw encodes the values to be used in a URL.
1111   *
1112   * @since 3.4.0
1113   *
1114   * @param array|string $value The array or string to be encoded.
1115   * @return array|string $value The encoded array (or string from the callback).
1116   */
1117  function rawurlencode_deep( $value ) {
1118      return is_array( $value ) ? array_map( 'rawurlencode_deep', $value ) : rawurlencode( $value );
1119  }
1120  endif;
1121      
1122  if ( !function_exists( 'urlencode_deep' ) ) :
1123  /**
1124   * Navigates through an array and encodes the values to be used in a URL.
1125   *
1126   * Uses a callback to pass the value of the array back to the function as a
1127   * string.
1128   *
1129   * @since 2.2.0
1130   *
1131   * @param array|string $value The array or string to be encoded.
1132   * @return array|string $value The encoded array (or string from the callback).
1133   */
1134  function urlencode_deep($value) {
1135      $value = is_array($value) ? array_map('urlencode_deep', $value) : urlencode($value);
1136      return $value;
1137  }
1138  endif;
1139  
1140  // ! function antispambot()
1141  
1142  if ( !function_exists( '_make_url_clickable_cb' ) ) :
1143  /**
1144   * Callback to convert URI match to HTML A element.
1145   *
1146   * This function was backported from 2.5.0 to 2.3.2. Regex callback for {@link
1147   * make_clickable()}.
1148   *
1149   * @since 2.3.2
1150   * @access private
1151   *
1152   * @param array $matches Single Regex Match.
1153   * @return string HTML A element with URI address.
1154   */
1155  function _make_url_clickable_cb($matches) {
1156      $url = $matches[2];
1157  
1158      if ( ')' == $matches[3] && strpos( $url, '(' ) ) {
1159          // If the trailing character is a closing parethesis, and the URL has an opening parenthesis in it, add the closing parenthesis to the URL.
1160          // Then we can let the parenthesis balancer do its thing below.
1161          $url .= $matches[3];
1162          $suffix = '';
1163      } else {
1164          $suffix = $matches[3];
1165      }
1166  
1167      // Include parentheses in the URL only if paired
1168      while ( substr_count( $url, '(' ) < substr_count( $url, ')' ) ) {
1169          $suffix = strrchr( $url, ')' ) . $suffix;
1170          $url = substr( $url, 0, strrpos( $url, ')' ) );
1171      }
1172  
1173      $url = esc_url($url);
1174      if ( empty($url) )
1175          return $matches[0];
1176  
1177      return $matches[1] . "<a href=\"$url\" rel=\"nofollow\">$url</a>" . $suffix;
1178  }
1179  endif;
1180  
1181  if ( !function_exists( '_make_web_ftp_clickable_cb' ) ) :
1182  /**
1183   * Callback to convert URL match to HTML A element.
1184   *
1185   * This function was backported from 2.5.0 to 2.3.2. Regex callback for {@link
1186   * make_clickable()}.
1187   *
1188   * @since 2.3.2
1189   * @access private
1190   *
1191   * @param array $matches Single Regex Match.
1192   * @return string HTML A element with URL address.
1193   */
1194  function _make_web_ftp_clickable_cb($matches) {
1195      $ret = '';
1196      $dest = $matches[2];
1197      $dest = 'http://' . $dest;
1198      $dest = esc_url($dest);
1199      if ( empty($dest) )
1200          return $matches[0];
1201  
1202      // removed trailing [.,;:)] from URL
1203      if ( in_array( substr($dest, -1), array('.', ',', ';', ':', ')') ) === true ) {
1204          $ret = substr($dest, -1);
1205          $dest = substr($dest, 0, strlen($dest)-1);
1206      }
1207      return $matches[1] . "<a href=\"$dest\" rel=\"nofollow\">$dest</a>$ret";
1208  }
1209  endif;
1210  
1211  if ( !function_exists( '_make_email_clickable_cb' ) ) :
1212  /**
1213   * Callback to convert email address match to HTML A element.
1214   *
1215   * This function was backported from 2.5.0 to 2.3.2. Regex callback for {@link
1216   * make_clickable()}.
1217   *
1218   * @since 2.3.2
1219   * @access private
1220   *
1221   * @param array $matches Single Regex Match.
1222   * @return string HTML A element with email address.
1223   */
1224  function _make_email_clickable_cb($matches) {
1225      $email = $matches[2] . '@' . $matches[3];
1226      return $matches[1] . "<a href=\"mailto:$email\">$email</a>";
1227  }
1228  endif;
1229  
1230  if ( !function_exists( 'make_clickable' ) ) :
1231  /**
1232   * Convert plaintext URI to HTML links.
1233   *
1234   * Converts URI, www and ftp, and email addresses. Finishes by fixing links
1235   * within links.
1236   *
1237   * @since 0.71
1238   *
1239   * @param string $text Content to convert URIs.
1240   * @return string Content with converted URIs.
1241   */
1242  function make_clickable( $text ) {
1243      $r = '';
1244      $textarr = preg_split( '/(<[^<>]+>)/', $text, -1, PREG_SPLIT_DELIM_CAPTURE ); // split out HTML tags
1245      foreach ( $textarr as $piece ) {
1246          if ( empty( $piece ) || ( $piece[0] == '<' && ! preg_match('|^<\s*[\w]{1,20}+://|', $piece) ) ) {
1247              $r .= $piece;
1248              continue;
1249          }
1250  
1251          // Long strings might contain expensive edge cases ...
1252          if ( 10000 < strlen( $piece ) ) {
1253              // ... break it up
1254              foreach ( _split_str_by_whitespace( $piece, 2100 ) as $chunk ) { // 2100: Extra room for scheme and leading and trailing paretheses
1255                  if ( 2101 < strlen( $chunk ) ) {
1256                      $r .= $chunk; // Too big, no whitespace: bail.
1257                  } else {
1258                      $r .= make_clickable( $chunk );
1259                  }
1260              }
1261          } else {
1262              $ret = " $piece "; // Pad with whitespace to simplify the regexes
1263  
1264              $url_clickable = '~
1265                  ([\\s(<.,;:!?])                                        # 1: Leading whitespace, or punctuation
1266                  (                                                      # 2: URL
1267                      [\\w]{1,20}+://                                # Scheme and hier-part prefix
1268                      (?=\S{1,2000}\s)                               # Limit to URLs less than about 2000 characters long
1269                      [\\w\\x80-\\xff#%\\~/@\\[\\]*(+=&$-]*+         # Non-punctuation URL character
1270                      (?:                                            # Unroll the Loop: Only allow puctuation URL character if followed by a non-punctuation URL character
1271                          [\'.,;:!?)]                            # Punctuation URL character
1272                          [\\w\\x80-\\xff#%\\~/@\\[\\]*(+=&$-]++ # Non-punctuation URL character
1273                      )*
1274                  )
1275                  (\)?)                                                  # 3: Trailing closing parenthesis (for parethesis balancing post processing)
1276              ~xS'; // The regex is a non-anchored pattern and does not have a single fixed starting character.
1277                    // Tell PCRE to spend more time optimizing since, when used on a page load, it will probably be used several times.
1278  
1279              $ret = preg_replace_callback( $url_clickable, '_make_url_clickable_cb', $ret );
1280  
1281              $ret = preg_replace_callback( '#([\s>])((www|ftp)\.[\w\\x80-\\xff\#$%&~/.\-;:=,?@\[\]+]+)#is', '_make_web_ftp_clickable_cb', $ret );
1282              $ret = preg_replace_callback( '#([\s>])([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})#i', '_make_email_clickable_cb', $ret );
1283  
1284              $ret = substr( $ret, 1, -1 ); // Remove our whitespace padding.
1285              $r .= $ret;
1286          }
1287      }
1288  
1289      // Cleanup of accidental links within links
1290      $r = preg_replace( '#(<a( [^>]+?>|>))<a [^>]+?>([^>]+?)</a></a>#i', "$1$3</a>", $r );
1291      return $r;
1292  }
1293  endif;
1294  
1295  if ( !function_exists('_split_str_by_whitespace') ) :
1296  /**
1297   * Breaks a string into chunks by splitting at whitespace characters.
1298   * The length of each returned chunk is as close to the specified length goal as possible,
1299   * with the caveat that each chunk includes its trailing delimiter.
1300   * Chunks longer than the goal are guaranteed to not have any inner whitespace.
1301   *
1302   * Joining the returned chunks with empty delimiters reconstructs the input string losslessly.
1303   *
1304   * Input string must have no null characters (or eventual transformations on output chunks must not care about null characters)
1305   *
1306   * <code>
1307   * _split_str_by_whitespace( "1234 67890 1234 67890a cd 1234   890 123456789 1234567890a    45678   1 3 5 7 90 ", 10 ) ==
1308   * array (
1309   *   0 => '1234 67890 ',  // 11 characters: Perfect split
1310   *   1 => '1234 ',        //  5 characters: '1234 67890a' was too long
1311   *   2 => '67890a cd ',   // 10 characters: '67890a cd 1234' was too long
1312   *   3 => '1234   890 ',  // 11 characters: Perfect split
1313   *   4 => '123456789 ',   // 10 characters: '123456789 1234567890a' was too long
1314   *   5 => '1234567890a ', // 12 characters: Too long, but no inner whitespace on which to split
1315   *   6 => '   45678   ',  // 11 characters: Perfect split
1316   *   7 => '1 3 5 7 9',    //  9 characters: End of $string
1317   * );
1318   * </code>
1319   *
1320   * @since 3.4.0
1321   * @access private
1322   *
1323   * @param string $string The string to split
1324   * @param    int $goal   The desired chunk length.
1325   * @return array Numeric array of chunks.
1326   */
1327  function _split_str_by_whitespace( $string, $goal ) {
1328      $chunks = array();
1329  
1330      $string_nullspace = strtr( $string, "\r\n\t\v\f ", "\000\000\000\000\000\000" );
1331  
1332      while ( $goal < strlen( $string_nullspace ) ) {
1333          $pos = strrpos( substr( $string_nullspace, 0, $goal + 1 ), "\000" );
1334  
1335          if ( false === $pos ) {
1336              $pos = strpos( $string_nullspace, "\000", $goal + 1 );
1337              if ( false === $pos ) {
1338                  break;
1339              }
1340          }
1341  
1342          $chunks[] = substr( $string, 0, $pos + 1 );
1343          $string = substr( $string, $pos + 1 );
1344          $string_nullspace = substr( $string_nullspace, $pos + 1 );
1345      }
1346  
1347      if ( $string ) {
1348          $chunks[] = $string;
1349      }
1350  
1351      return $chunks;
1352  }
1353  endif;
1354  
1355  // ! function wp_rel_nofollow()
1356  // ! function wp_rel_nofollow_callback()
1357  // ! function translate_smiley()
1358  // ! function convert_smilies()
1359  
1360  if ( !function_exists('is_email') ) :
1361  /**
1362   * Verifies that an email is valid.
1363   *
1364   * Does not grok i18n domains. Not RFC compliant.
1365   *
1366   * @since 0.71
1367   *
1368   * @param string $email Email address to verify.
1369   * @param boolean $deprecated Deprecated.
1370   * @return string|bool Either false or the valid email address.
1371   */
1372  function is_email( $email, $deprecated = false ) {
1373      // Test for the minimum length the email can be
1374      if ( strlen( $email ) < 3 ) {
1375          return apply_filters( 'is_email', false, $email, 'email_too_short' );
1376      }
1377  
1378      // Test for an @ character after the first position
1379      if ( strpos( $email, '@', 1 ) === false ) {
1380          return apply_filters( 'is_email', false, $email, 'email_no_at' );
1381      }
1382  
1383      // Split out the local and domain parts
1384      list( $local, $domain ) = explode( '@', $email, 2 );
1385  
1386      // LOCAL PART
1387      // Test for invalid characters
1388      if ( !preg_match( '/^[a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]+$/', $local ) ) {
1389          return apply_filters( 'is_email', false, $email, 'local_invalid_chars' );
1390      }
1391  
1392      // DOMAIN PART
1393      // Test for sequences of periods
1394      if ( preg_match( '/\.{2,}/', $domain ) ) {
1395          return apply_filters( 'is_email', false, $email, 'domain_period_sequence' );
1396      }
1397  
1398      // Test for leading and trailing periods and whitespace
1399      if ( trim( $domain, " \t\n\r\0\x0B." ) !== $domain ) {
1400          return apply_filters( 'is_email', false, $email, 'domain_period_limits' );
1401      }
1402  
1403      // Split the domain into subs
1404      $subs = explode( '.', $domain );
1405  
1406      // Assume the domain will have at least two subs
1407      if ( 2 > count( $subs ) ) {
1408          return apply_filters( 'is_email', false, $email, 'domain_no_periods' );
1409      }
1410  
1411      // Loop through each sub
1412      foreach ( $subs as $sub ) {
1413          // Test for leading and trailing hyphens and whitespace
1414          if ( trim( $sub, " \t\n\r\0\x0B-" ) !== $sub ) {
1415              return apply_filters( 'is_email', false, $email, 'sub_hyphen_limits' );
1416          }
1417  
1418          // Test for invalid characters
1419          if ( !preg_match('/^[a-z0-9-]+$/i', $sub ) ) {
1420              return apply_filters( 'is_email', false, $email, 'sub_invalid_chars' );
1421          }
1422      }
1423  
1424      // Congratulations your email made it!
1425      return apply_filters( 'is_email', $email, $email, null );
1426  }
1427  endif;
1428  
1429  // ! function wp_iso_descrambler()
1430  // ! function _wp_iso_convert()
1431  // ! function get_gmt_from_date()
1432  // ! function get_date_from_gmt()
1433  // ! function iso8601_timezone_to_offset()
1434  // ! function iso8601_to_datetime()
1435  // ! popuplinks()
1436  
1437  if ( !function_exists('sanitize_email') ) :
1438  /**
1439   * Strips out all characters that are not allowable in an email.
1440   *
1441   * @since 1.5.0
1442   *
1443   * @param string $email Email address to filter.
1444   * @return string Filtered email address.
1445   */
1446  function sanitize_email( $email ) {
1447      // Test for the minimum length the email can be
1448      if ( strlen( $email ) < 3 ) {
1449          return apply_filters( 'sanitize_email', '', $email, 'email_too_short' );
1450      }
1451  
1452      // Test for an @ character after the first position
1453      if ( strpos( $email, '@', 1 ) === false ) {
1454          return apply_filters( 'sanitize_email', '', $email, 'email_no_at' );
1455      }
1456  
1457      // Split out the local and domain parts
1458      list( $local, $domain ) = explode( '@', $email, 2 );
1459  
1460      // LOCAL PART
1461      // Test for invalid characters
1462      $local = preg_replace( '/[^a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]/', '', $local );
1463      if ( '' === $local ) {
1464          return apply_filters( 'sanitize_email', '', $email, 'local_invalid_chars' );
1465      }
1466  
1467      // DOMAIN PART
1468      // Test for sequences of periods
1469      $domain = preg_replace( '/\.{2,}/', '', $domain );
1470      if ( '' === $domain ) {
1471          return apply_filters( 'sanitize_email', '', $email, 'domain_period_sequence' );
1472      }
1473  
1474      // Test for leading and trailing periods and whitespace
1475      $domain = trim( $domain, " \t\n\r\0\x0B." );
1476      if ( '' === $domain ) {
1477          return apply_filters( 'sanitize_email', '', $email, 'domain_period_limits' );
1478      }
1479  
1480      // Split the domain into subs
1481      $subs = explode( '.', $domain );
1482  
1483      // Assume the domain will have at least two subs
1484      if ( 2 > count( $subs ) ) {
1485          return apply_filters( 'sanitize_email', '', $email, 'domain_no_periods' );
1486      }
1487  
1488      // Create an array that will contain valid subs
1489      $new_subs = array();
1490  
1491      // Loop through each sub
1492      foreach ( $subs as $sub ) {
1493          // Test for leading and trailing hyphens
1494          $sub = trim( $sub, " \t\n\r\0\x0B-" );
1495  
1496          // Test for invalid characters
1497          $sub = preg_replace( '/^[^a-z0-9-]+$/i', '', $sub );
1498  
1499          // If there's anything left, add it to the valid subs
1500          if ( '' !== $sub ) {
1501              $new_subs[] = $sub;
1502          }
1503      }
1504  
1505      // If there aren't 2 or more valid subs
1506      if ( 2 > count( $new_subs ) ) {
1507          return apply_filters( 'sanitize_email', '', $email, 'domain_no_valid_subs' );
1508      }
1509  
1510      // Join valid subs into the new domain
1511      $domain = join( '.', $new_subs );
1512  
1513      // Put the email back together
1514      $email = $local . '@' . $domain;
1515  
1516      // Congratulations your email made it!
1517      return apply_filters( 'sanitize_email', $email, $email, null );
1518  }
1519  endif;
1520  
1521  // ! function human_time_diff()
1522  // ! function wp_trim_excerpt()
1523  // ! function wp_trim_excerpt()
1524  
1525  if ( !function_exists( 'ent2ncr' ) ) : // Current at [WP9840]
1526  /**
1527   * Converts named entities into numbered entities.
1528   *
1529   * @since 1.5.1
1530   *
1531   * @param string $text The text within which entities will be converted.
1532   * @return string Text with converted entities.
1533   */
1534  function ent2ncr($text) {
1535  
1536      // Allow a plugin to short-circuit and override the mappings.
1537      $filtered = apply_filters( 'pre_ent2ncr', null, $text );
1538      if( null !== $filtered )
1539          return $filtered;
1540  
1541      $to_ncr = array(
1542          '&quot;' => '&#34;',
1543          '&amp;' => '&#38;',
1544          '&frasl;' => '&#47;',
1545          '&lt;' => '&#60;',
1546          '&gt;' => '&#62;',
1547          '|' => '&#124;',
1548          '&nbsp;' => '&#160;',
1549          '&iexcl;' => '&#161;',
1550          '&cent;' => '&#162;',
1551          '&pound;' => '&#163;',
1552          '&curren;' => '&#164;',
1553          '&yen;' => '&#165;',
1554          '&brvbar;' => '&#166;',
1555          '&brkbar;' => '&#166;',
1556          '&sect;' => '&#167;',
1557          '&uml;' => '&#168;',
1558          '&die;' => '&#168;',
1559          '&copy;' => '&#169;',
1560          '&ordf;' => '&#170;',
1561          '&laquo;' => '&#171;',
1562          '&not;' => '&#172;',
1563          '&shy;' => '&#173;',
1564          '&reg;' => '&#174;',
1565          '&macr;' => '&#175;',
1566          '&hibar;' => '&#175;',
1567          '&deg;' => '&#176;',
1568          '&plusmn;' => '&#177;',
1569          '&sup2;' => '&#178;',
1570          '&sup3;' => '&#179;',
1571          '&acute;' => '&#180;',
1572          '&micro;' => '&#181;',
1573          '&para;' => '&#182;',
1574          '&middot;' => '&#183;',
1575          '&cedil;' => '&#184;',
1576          '&sup1;' => '&#185;',
1577          '&ordm;' => '&#186;',
1578          '&raquo;' => '&#187;',
1579          '&frac14;' => '&#188;',
1580          '&frac12;' => '&#189;',
1581          '&frac34;' => '&#190;',
1582          '&iquest;' => '&#191;',
1583          '&Agrave;' => '&#192;',
1584          '&Aacute;' => '&#193;',
1585          '&Acirc;' => '&#194;',
1586          '&Atilde;' => '&#195;',
1587          '&Auml;' => '&#196;',
1588          '&Aring;' => '&#197;',
1589          '&AElig;' => '&#198;',
1590          '&Ccedil;' => '&#199;',
1591          '&Egrave;' => '&#200;',
1592          '&Eacute;' => '&#201;',
1593          '&Ecirc;' => '&#202;',
1594          '&Euml;' => '&#203;',
1595          '&Igrave;' => '&#204;',
1596          '&Iacute;' => '&#205;',
1597          '&Icirc;' => '&#206;',
1598          '&Iuml;' => '&#207;',
1599          '&ETH;' => '&#208;',
1600          '&Ntilde;' => '&#209;',
1601          '&Ograve;' => '&#210;',
1602          '&Oacute;' => '&#211;',
1603          '&Ocirc;' => '&#212;',
1604          '&Otilde;' => '&#213;',
1605          '&Ouml;' => '&#214;',
1606          '&times;' => '&#215;',
1607          '&Oslash;' => '&#216;',
1608          '&Ugrave;' => '&#217;',
1609          '&Uacute;' => '&#218;',
1610          '&Ucirc;' => '&#219;',
1611          '&Uuml;' => '&#220;',
1612          '&Yacute;' => '&#221;',
1613          '&THORN;' => '&#222;',
1614          '&szlig;' => '&#223;',
1615          '&agrave;' => '&#224;',
1616          '&aacute;' => '&#225;',
1617          '&acirc;' => '&#226;',
1618          '&atilde;' => '&#227;',
1619          '&auml;' => '&#228;',
1620          '&aring;' => '&#229;',
1621          '&aelig;' => '&#230;',
1622          '&ccedil;' => '&#231;',
1623          '&egrave;' => '&#232;',
1624          '&eacute;' => '&#233;',
1625          '&ecirc;' => '&#234;',
1626          '&euml;' => '&#235;',
1627          '&igrave;' => '&#236;',
1628          '&iacute;' => '&#237;',
1629          '&icirc;' => '&#238;',
1630          '&iuml;' => '&#239;',
1631          '&eth;' => '&#240;',
1632          '&ntilde;' => '&#241;',
1633          '&ograve;' => '&#242;',
1634          '&oacute;' => '&#243;',
1635          '&ocirc;' => '&#244;',
1636          '&otilde;' => '&#245;',
1637          '&ouml;' => '&#246;',
1638          '&divide;' => '&#247;',
1639          '&oslash;' => '&#248;',
1640          '&ugrave;' => '&#249;',
1641          '&uacute;' => '&#250;',
1642          '&ucirc;' => '&#251;',
1643          '&uuml;' => '&#252;',
1644          '&yacute;' => '&#253;',
1645          '&thorn;' => '&#254;',
1646          '&yuml;' => '&#255;',
1647          '&OElig;' => '&#338;',
1648          '&oelig;' => '&#339;',
1649          '&Scaron;' => '&#352;',
1650          '&scaron;' => '&#353;',
1651          '&Yuml;' => '&#376;',
1652          '&fnof;' => '&#402;',
1653          '&circ;' => '&#710;',
1654          '&tilde;' => '&#732;',
1655          '&Alpha;' => '&#913;',
1656          '&Beta;' => '&#914;',
1657          '&Gamma;' => '&#915;',
1658          '&Delta;' => '&#916;',
1659          '&Epsilon;' => '&#917;',
1660          '&Zeta;' => '&#918;',
1661          '&Eta;' => '&#919;',
1662          '&Theta;' => '&#920;',
1663          '&Iota;' => '&#921;',
1664          '&Kappa;' => '&#922;',
1665          '&Lambda;' => '&#923;',
1666          '&Mu;' => '&#924;',
1667          '&Nu;' => '&#925;',
1668          '&Xi;' => '&#926;',
1669          '&Omicron;' => '&#927;',
1670          '&Pi;' => '&#928;',
1671          '&Rho;' => '&#929;',
1672          '&Sigma;' => '&#931;',
1673          '&Tau;' => '&#932;',
1674          '&Upsilon;' => '&#933;',
1675          '&Phi;' => '&#934;',
1676          '&Chi;' => '&#935;',
1677          '&Psi;' => '&#936;',
1678          '&Omega;' => '&#937;',
1679          '&alpha;' => '&#945;',
1680          '&beta;' => '&#946;',
1681          '&gamma;' => '&#947;',
1682          '&delta;' => '&#948;',
1683          '&epsilon;' => '&#949;',
1684          '&zeta;' => '&#950;',
1685          '&eta;' => '&#951;',
1686          '&theta;' => '&#952;',
1687          '&iota;' => '&#953;',
1688          '&kappa;' => '&#954;',
1689          '&lambda;' => '&#955;',
1690          '&mu;' => '&#956;',
1691          '&nu;' => '&#957;',
1692          '&xi;' => '&#958;',
1693          '&omicron;' => '&#959;',
1694          '&pi;' => '&#960;',
1695          '&rho;' => '&#961;',
1696          '&sigmaf;' => '&#962;',
1697          '&sigma;' => '&#963;',
1698          '&tau;' => '&#964;',
1699          '&upsilon;' => '&#965;',
1700          '&phi;' => '&#966;',
1701          '&chi;' => '&#967;',
1702          '&psi;' => '&#968;',
1703          '&omega;' => '&#969;',
1704          '&thetasym;' => '&#977;',
1705          '&upsih;' => '&#978;',
1706          '&piv;' => '&#982;',
1707          '&ensp;' => '&#8194;',
1708          '&emsp;' => '&#8195;',
1709          '&thinsp;' => '&#8201;',
1710          '&zwnj;' => '&#8204;',
1711          '&zwj;' => '&#8205;',
1712          '&lrm;' => '&#8206;',
1713          '&rlm;' => '&#8207;',
1714          '&ndash;' => '&#8211;',
1715          '&mdash;' => '&#8212;',
1716          '&lsquo;' => '&#8216;',
1717          '&rsquo;' => '&#8217;',
1718          '&sbquo;' => '&#8218;',
1719          '&ldquo;' => '&#8220;',
1720          '&rdquo;' => '&#8221;',
1721          '&bdquo;' => '&#8222;',
1722          '&dagger;' => '&#8224;',
1723          '&Dagger;' => '&#8225;',
1724          '&bull;' => '&#8226;',
1725          '&hellip;' => '&#8230;',
1726          '&permil;' => '&#8240;',
1727          '&prime;' => '&#8242;',
1728          '&Prime;' => '&#8243;',
1729          '&lsaquo;' => '&#8249;',
1730          '&rsaquo;' => '&#8250;',
1731          '&oline;' => '&#8254;',
1732          '&frasl;' => '&#8260;',
1733          '&euro;' => '&#8364;',
1734          '&image;' => '&#8465;',
1735          '&weierp;' => '&#8472;',
1736          '&real;' => '&#8476;',
1737          '&trade;' => '&#8482;',
1738          '&alefsym;' => '&#8501;',
1739          '&crarr;' => '&#8629;',
1740          '&lArr;' => '&#8656;',
1741          '&uArr;' => '&#8657;',
1742          '&rArr;' => '&#8658;',
1743          '&dArr;' => '&#8659;',
1744          '&hArr;' => '&#8660;',
1745          '&forall;' => '&#8704;',
1746          '&part;' => '&#8706;',
1747          '&exist;' => '&#8707;',
1748          '&empty;' => '&#8709;',
1749          '&nabla;' => '&#8711;',
1750          '&isin;' => '&#8712;',
1751          '&notin;' => '&#8713;',
1752          '&ni;' => '&#8715;',
1753          '&prod;' => '&#8719;',
1754          '&sum;' => '&#8721;',
1755          '&minus;' => '&#8722;',
1756          '&lowast;' => '&#8727;',
1757          '&radic;' => '&#8730;',
1758          '&prop;' => '&#8733;',
1759          '&infin;' => '&#8734;',
1760          '&ang;' => '&#8736;',
1761          '&and;' => '&#8743;',
1762          '&or;' => '&#8744;',
1763          '&cap;' => '&#8745;',
1764          '&cup;' => '&#8746;',
1765          '&int;' => '&#8747;',
1766          '&there4;' => '&#8756;',
1767          '&sim;' => '&#8764;',
1768          '&cong;' => '&#8773;',
1769          '&asymp;' => '&#8776;',
1770          '&ne;' => '&#8800;',
1771          '&equiv;' => '&#8801;',
1772          '&le;' => '&#8804;',
1773          '&ge;' => '&#8805;',
1774          '&sub;' => '&#8834;',
1775          '&sup;' => '&#8835;',
1776          '&nsub;' => '&#8836;',
1777          '&sube;' => '&#8838;',
1778          '&supe;' => '&#8839;',
1779          '&oplus;' => '&#8853;',
1780          '&otimes;' => '&#8855;',
1781          '&perp;' => '&#8869;',
1782          '&sdot;' => '&#8901;',
1783          '&lceil;' => '&#8968;',
1784          '&rceil;' => '&#8969;',
1785          '&lfloor;' => '&#8970;',
1786          '&rfloor;' => '&#8971;',
1787          '&lang;' => '&#9001;',
1788          '&rang;' => '&#9002;',
1789          '&larr;' => '&#8592;',
1790          '&uarr;' => '&#8593;',
1791          '&rarr;' => '&#8594;',
1792          '&darr;' => '&#8595;',
1793          '&harr;' => '&#8596;',
1794          '&loz;' => '&#9674;',
1795          '&spades;' => '&#9824;',
1796          '&clubs;' => '&#9827;',
1797          '&hearts;' => '&#9829;',
1798          '&diams;' => '&#9830;'
1799      );
1800  
1801      return str_replace( array_keys($to_ncr), array_values($to_ncr), $text );
1802  }
1803  endif;
1804  
1805  // ! function wp_richedit_pre()
1806  // ! function wp_htmledit_pre()
1807  
1808  if ( !function_exists( '_deep_replace' ) ) :
1809  /**
1810   * Perform a deep string replace operation to ensure the values in $search are no longer present
1811   *
1812   * Repeats the replacement operation until it no longer replaces anything so as to remove "nested" values
1813   * e.g. $subject = '%0%0%0DDD', $search ='%0D', $result ='' rather than the '%0%0DD' that
1814   * str_replace would return
1815   *
1816   * @since 2.8.1
1817   * @access private
1818   *
1819   * @param string|array $search
1820   * @param string $subject
1821   * @return string The processed string
1822   */
1823  function _deep_replace($search, $subject){
1824      $found = true;
1825      while($found) {
1826          $found = false;
1827          foreach( (array) $search as $val ) {
1828              while(strpos($subject, $val) !== false) {
1829                  $found = true;
1830                  $subject = str_replace($val, '', $subject);
1831              }
1832          }
1833      }
1834  
1835      return $subject;
1836  }
1837  endif;
1838  
1839  if ( !function_exists( 'esc_sql' ) ) :
1840  /**
1841   * Escapes data for use in a MySQL query
1842   *
1843   * This is just a handy shortcut for $bpdb->escape(), for completeness' sake
1844   *
1845   * @since 2.8.0
1846   * @param string $sql Unescaped SQL data
1847   * @return string The cleaned $sql
1848   */
1849  function esc_sql( $sql ) {
1850      global $bpdb;
1851      return $bpdb->escape( $sql );
1852  }
1853  endif;
1854  
1855  // @todo: Deprecated function we should remove.
1856  if ( !function_exists( 'clean_url' ) ) :
1857  /**
1858   * Checks and cleans a URL.
1859   *
1860   * A number of characters are removed from the URL. If the URL is for displaying
1861   * (the default behaviour) ampersands are also replaced. The 'clean_url' filter
1862   * is applied to the returned cleaned URL.
1863   *
1864   * @since 1.2.0
1865   * @deprecated 3.0.0
1866   * @deprecated Use esc_url()
1867   * @see Alias for esc_url()
1868   *
1869   * @param string $url The URL to be cleaned.
1870   * @param array $protocols Optional. An array of acceptable protocols.
1871   * @param string $context Optional. How the URL will be used. Default is 'display'.
1872   * @return string The cleaned $url after the 'clean_url' filter is applied.
1873   */
1874  function clean_url( $url, $protocols = null, $context = 'display' ) {
1875      return esc_url( $url, $protocols, $context );
1876  }
1877  endif;
1878  
1879  if ( !function_exists( 'esc_url' ) ) :
1880  /**
1881   * Checks and cleans a URL.
1882   *
1883   * A number of characters are removed from the URL. If the URL is for displaying
1884   * (the default behaviour) ampersands are also replaced. The 'clean_url' filter
1885   * is applied to the returned cleaned URL.
1886   *
1887   * @since 2.8.0
1888   * @uses wp_kses_bad_protocol() To only permit protocols in the URL set
1889   *        via $protocols or the common ones set in the function.
1890   *
1891   * @param string $url The URL to be cleaned.
1892   * @param array $protocols Optional. An array of acceptable protocols.
1893   *        Defaults to 'http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet', 'mms', 'rtsp', 'svn' if not set.
1894   * @param string $_context Private. Use esc_url_raw() for database usage.
1895   * @return string The cleaned $url after the 'clean_url' filter is applied.
1896   */
1897  function esc_url( $url, $protocols = null, $_context = 'display' ) {
1898      $original_url = $url;
1899  
1900      if ( '' == $url )
1901          return $url;
1902      $url = preg_replace('|[^a-z0-9-~+_.?#=!&;,/:%@$\|*\'()\\x80-\\xff]|i', '', $url);
1903      $strip = array('%0d', '%0a', '%0D', '%0A');
1904      $url = _deep_replace($strip, $url);
1905      $url = str_replace(';//', '://', $url);
1906      /* If the URL doesn't appear to contain a scheme, we
1907       * presume it needs http:// appended (unless a relative
1908       * link starting with /, # or ? or a php file).
1909       */
1910      if ( strpos($url, ':') === false && ! in_array( $url[0], array( '/', '#', '?' ) ) &&
1911          ! preg_match('/^[a-z0-9-]+?\.php/i', $url) )
1912          $url = 'http://' . $url;
1913  
1914      // Replace ampersands and single quotes only when displaying.
1915      if ( 'display' == $_context ) {
1916          $url = wp_kses_normalize_entities( $url );
1917          $url = str_replace( '&amp;', '&#038;', $url );
1918          $url = str_replace( "'", '&#039;', $url );
1919      }
1920  
1921      // Todo: switch to wp_allowed_protocols() once it is merged to BackPress
1922      if ( ! is_array( $protocols ) )
1923          $protocols = array ('http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet', 'mms', 'rtsp', 'svn');
1924      if ( wp_kses_bad_protocol( $url, $protocols ) != $url )
1925          return '';
1926  
1927      return apply_filters('clean_url', $url, $original_url, $_context);
1928  }
1929  endif;
1930  
1931  if ( !function_exists( 'esc_url_raw' ) ) :
1932  /**
1933   * Performs esc_url() for database usage.
1934   *
1935   * @since 2.8.0
1936   * @uses esc_url()
1937   *
1938   * @param string $url The URL to be cleaned.
1939   * @param array $protocols An array of acceptable protocols.
1940   * @return string The cleaned URL.
1941   */
1942  function esc_url_raw( $url, $protocols = null ) {
1943      return esc_url( $url, $protocols, 'db' );
1944  }
1945  endif;
1946  
1947  // ! function htmlentities2()
1948  
1949  if ( !function_exists( 'esc_js' ) ) :
1950  /**
1951   * Escape single quotes, htmlspecialchar " < > &, and fix line endings.
1952   *
1953   * Escapes text strings for echoing in JS, both inline (for example in onclick="...")
1954   * and inside <script> tag. Note that the strings have to be in single quotes.
1955   * The filter 'js_escape' is also applied here.
1956   *
1957   * @since 2.8.0
1958   *
1959   * @param string $text The text to be escaped.
1960   * @return string Escaped text.
1961   */
1962  function esc_js( $text ) {
1963      $safe_text = wp_check_invalid_utf8( $text );
1964      $safe_text = _wp_specialchars( $safe_text, ENT_COMPAT );
1965      $safe_text = preg_replace( '/&#(x)?0*(?(1)27|39);?/i', "'", stripslashes( $safe_text ) );
1966      $safe_text = str_replace( "\r", '', $safe_text );
1967      $safe_text = str_replace( "\n", '\\n', addslashes( $safe_text ) );
1968      return apply_filters( 'js_escape', $safe_text, $text );
1969  }
1970  endif;
1971  
1972  // @todo: Deprecated function we should remove.
1973  if ( !function_exists( 'js_escape' ) ) :
1974  /**
1975   * Escape single quotes, specialchar double quotes, and fix line endings.
1976   *
1977   * The filter 'js_escape' is also applied by esc_js()
1978   *
1979   * @since 2.0.4
1980   *
1981   * @deprecated 2.8.0
1982   * @see esc_js()
1983   *
1984   * @param string $text The text to be escaped.
1985   * @return string Escaped text.
1986   */
1987  function js_escape( $text ) {
1988      return esc_js( $text );
1989  }
1990  endif;
1991  
1992  if ( !function_exists( 'esc_html' ) ) :
1993  /**
1994   * Escaping for HTML blocks.
1995   *
1996   * @since 2.8.0
1997   *
1998   * @param string $text
1999   * @return string
2000   */
2001  function esc_html( $text ) {
2002      $safe_text = wp_check_invalid_utf8( $text );
2003      $safe_text = _wp_specialchars( $safe_text, ENT_QUOTES );
2004      return apply_filters( 'esc_html', $safe_text, $text );
2005      return $text;
2006  }
2007  endif;
2008  
2009  // @todo: Deprecated function we should remove.
2010  if ( !function_exists( 'wp_specialchars' ) ) :
2011  /**
2012   * Escaping for HTML blocks
2013   * @deprecated 2.8.0
2014   * @see esc_html()
2015   */
2016  function wp_specialchars( $string, $quote_style = ENT_NOQUOTES, $charset = false, $double_encode = false ) {
2017      if ( func_num_args() > 1 ) { // Maintain backwards compat for people passing additional args
2018          $args = func_get_args();
2019          return call_user_func_array( '_wp_specialchars', $args );
2020      } else {
2021          return esc_html( $string );
2022      }
2023  }
2024  endif;
2025  
2026  if ( !function_exists( 'esc_attr' ) ) :
2027  /**
2028   * Escaping for HTML attributes.
2029   *
2030   * @since 2.8.0
2031   *
2032   * @param string $text
2033   * @return string
2034   */
2035  function esc_attr( $text ) {
2036      $safe_text = wp_check_invalid_utf8( $text );
2037      $safe_text = _wp_specialchars( $safe_text, ENT_QUOTES );
2038      return apply_filters( 'attribute_escape', $safe_text, $text );
2039  }
2040  endif;
2041  
2042  if ( !function_exists( 'esc_textarea' ) ) :
2043  /**
2044   * Escaping for textarea values.
2045   *
2046   * @since 3.1
2047   *
2048   * @param string $text
2049   * @return string
2050   */
2051  function esc_textarea( $text ) {
2052      $safe_text = htmlspecialchars( $text, ENT_QUOTES );
2053      return apply_filters( 'esc_textarea', $safe_text, $text );
2054  }
2055  endif;
2056  
2057  // @todo: Deprecated function we should remove.
2058  if ( !function_exists( 'attribute_escape' ) ) :
2059  /**
2060   * Escaping for HTML attributes.
2061   *
2062   * @since 2.0.6
2063   *
2064   * @deprecated 2.8.0
2065   * @see esc_attr()
2066   *
2067   * @param string $text
2068   * @return string
2069   */
2070  function attribute_escape( $text ) {
2071      return esc_attr( $text );
2072  }
2073  endif;
2074  
2075  // ! function tag_escape()
2076  
2077  if ( !function_exists('like_escape') ) :
2078  /**
2079   * Escapes text for SQL LIKE special characters % and _.
2080   *
2081   * @since 2.5.0
2082   *
2083   * @param string $text The text to be escaped.
2084   * @return string text, safe for inclusion in LIKE query.
2085   */
2086  function like_escape($text) {
2087      return str_replace(array("%", "_"), array("\\%", "\\_"), $text);
2088  }
2089  endif;
2090  
2091  // ! function wp_make_link_relative()
2092  // ! function sanitize_option()
2093  
2094  if ( !function_exists('wp_parse_str') ) :
2095  /**
2096   * Parses a string into variables to be stored in an array.
2097   *
2098   * Uses {@link http://www.php.net/parse_str parse_str()} and stripslashes if
2099   * {@link http://www.php.net/magic_quotes magic_quotes_gpc} is on.
2100   *
2101   * @since 2.2.1
2102   * @uses apply_filters() for the 'wp_parse_str' filter.
2103   *
2104   * @param string $string The string to be parsed.
2105   * @param array $array Variables will be stored in this array.
2106   */
2107  function wp_parse_str( $string, &$array ) {
2108      parse_str( $string, $array );
2109      if ( PHP_VERSION_ID < 50400 && get_magic_quotes_gpc() )
2110          $array = stripslashes_deep( $array );
2111      $array = apply_filters( 'wp_parse_str', $array );
2112  }
2113  endif;
2114  
2115  if ( !function_exists('wp_pre_kses_less_than') ) :
2116  /**
2117   * Convert lone less than signs.
2118   *
2119   * KSES already converts lone greater than signs.
2120   *
2121   * @uses wp_pre_kses_less_than_callback in the callback function.
2122   * @since 2.3.0
2123   *
2124   * @param string $text Text to be converted.
2125   * @return string Converted text.
2126   */
2127  function wp_pre_kses_less_than( $text ) {
2128      return preg_replace_callback('%<[^>]*?((?=<)|>|$)%', 'wp_pre_kses_less_than_callback', $text);
2129  }
2130  endif;
2131  if ( !function_exists('wp_pre_kses_less_than_callback') ) :
2132  /**
2133   * Callback function used by preg_replace.
2134   *
2135   * @uses esc_html to format the $matches text.
2136   * @since 2.3.0
2137   *
2138   * @param array $matches Populated by matches to preg_replace.
2139   * @return string The text returned after esc_html if needed.
2140   */
2141  function wp_pre_kses_less_than_callback( $matches ) {
2142      if ( false === strpos($matches[0], '>') )
2143          return esc_html($matches[0]);
2144      return $matches[0];
2145  }
2146  endif;
2147  // ! function wp_sprintf()
2148  // ! function wp_sprintf_l()
2149  
2150  if ( !function_exists('wp_html_excerpt') ) :
2151  /**
2152   * Safely extracts not more than the first $count characters from html string.
2153   *
2154   * UTF-8, tags and entities safe prefix extraction. Entities inside will *NOT*
2155   * be counted as one character. For example &amp; will be counted as 4, &lt; as
2156   * 3, etc.
2157   *
2158   * @since 2.5.0
2159   *
2160   * @param integer $str String to get the excerpt from.
2161   * @param integer $count Maximum number of characters to take.
2162   * @return string The excerpt.
2163   */
2164  function wp_html_excerpt( $str, $count ) {
2165      $str = wp_strip_all_tags( $str, true );
2166      $str = mb_substr( $str, 0, $count );
2167      // remove part of an entity at the end
2168      $str = preg_replace( '/&[^;\s]{0,6}$/', '', $str );
2169      return $str;
2170  }
2171  endif;
2172  
2173  // ! function links_add_base_url()
2174  // ! function _links_add_base()
2175  // ! function links_add_target()
2176  // ! function _links_add_target()
2177  // ! function normalize_whitespace()
2178  
2179  if ( !function_exists('wp_strip_all_tags') ) :
2180  /**
2181   * Properly strip all HTML tags including script and style
2182   *
2183   * @since 2.9.0
2184   *
2185   * @param string $string String containing HTML tags
2186   * @param bool $remove_breaks optional Whether to remove left over line breaks and white space chars
2187   * @return string The processed string.
2188   */
2189  function wp_strip_all_tags($string, $remove_breaks = false) {
2190      $string = preg_replace( '@<(script|style)[^>]*?>.*?</\\1>@si', '', $string );
2191      $string = strip_tags($string);
2192  
2193      if ( $remove_breaks )
2194          $string = preg_replace('/[\r\n\t ]+/', ' ', $string);
2195  
2196      return trim( $string );
2197  }
2198  endif;
2199  
2200  if ( !function_exists('sanitize_text_field') ) :
2201  /**
2202   * Sanitize a string from user input or from the db
2203   *
2204   * check for invalid UTF-8,
2205   * Convert single < characters to entity,
2206   * strip all tags,
2207   * remove line breaks, tabs and extra white space,
2208   * strip octets.
2209   *
2210   * @since 2.9.0
2211   *
2212   * @param string $str
2213   * @return string
2214   */
2215  function sanitize_text_field($str) {
2216      $filtered = wp_check_invalid_utf8( $str );
2217  
2218      if ( strpos($filtered, '<') !== false ) {
2219          $filtered = wp_pre_kses_less_than( $filtered );
2220          // This will strip extra whitespace for us.
2221          $filtered = wp_strip_all_tags( $filtered, true );
2222      } else {
2223          $filtered = trim( preg_replace('/[\r\n\t ]+/', ' ', $filtered) );
2224      }
2225  
2226      $match = array();
2227      $found = false;
2228      while ( preg_match('/%[a-f0-9]{2}/i', $filtered, $match) ) {
2229          $filtered = str_replace($match[0], '', $filtered);
2230          $found = true;
2231      }
2232  
2233      if ( $found ) {
2234          // Strip out the whitespace that may now exist after removing the octets.
2235          $filtered = trim( preg_replace('/ +/', ' ', $filtered) );
2236      }
2237  
2238      return apply_filters('sanitize_text_field', $filtered, $str);
2239  }
2240  endif;
2241  
2242  if ( !function_exists('wp_basename') ) :
2243  /**
2244   * i18n friendly version of basename()
2245   *
2246   * @since 3.1.0
2247   *
2248   * @param string $path A path.
2249   * @param string $suffix If the filename ends in suffix this will also be cut off.
2250   * @return string
2251   */
2252  function wp_basename( $path, $suffix = '' ) {
2253      return urldecode( basename( str_replace( '%2F', '/', urlencode( $path ) ), $suffix ) );
2254  }
2255  endif;
2256  
2257  // !function capital_P_dangit
2258  
2259  if ( !function_exists('sanitize_mime_type') ) :
2260  /**
2261   * Sanitize a mime type
2262   *
2263   * @since 3.1.3
2264   *
2265   * @param string $mime_type Mime type
2266   * @return string Sanitized mime type
2267   */
2268  function sanitize_mime_type( $mime_type ) {
2269      $sani_mime_type = preg_replace( '/[^-+*.a-zA-Z0-9\/]/', '', $mime_type );
2270      return apply_filters( 'sanitize_mime_type', $sani_mime_type, $mime_type );
2271  }
2272  endif;
2273  
2274  // !function sanitize_trackback_urls


Generated: Thu Dec 26 01:01:01 2024 Cross-referenced by PHPXref 0.7.1