wp/wp-includes/formatting.php
author ymh <ymh.work@gmail.com>
Tue, 09 Jun 2015 03:35:32 +0200
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
permissions -rw-r--r--
upgrade wordpress + plugins
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * Main WordPress Formatting API.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * Handles many functions for formatting output.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
 * Replaces common plain text characters into formatted entities
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
 * As an example,
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    14
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    15
 *     'cause today's effort makes it worth tomorrow's "holiday" ...
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    16
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
 * Becomes:
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    18
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    19
 *     &#8217;cause today&#8217;s effort makes it worth tomorrow&#8217;s &#8220;holiday&#8221; &#8230;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    20
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
 * Code within certain html blocks are skipped.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
 * @uses $wp_cockneyreplace Array of formatted entities for certain common phrases
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
 * @param string $text The text to be formatted
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    27
 * @param bool $reset Set to true for unit testing. Translated patterns will reset.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
 * @return string The string replaced with html entities
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    30
function wptexturize($text, $reset = false) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    31
	global $wp_cockneyreplace, $shortcode_tags;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
	static $static_characters, $static_replacements, $dynamic_characters, $dynamic_replacements,
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    33
		$default_no_texturize_tags, $default_no_texturize_shortcodes, $run_texturize = true;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    34
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    35
	// If there's nothing to do, just stop.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    36
	if ( empty( $text ) || false === $run_texturize ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    37
		return $text;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    38
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    39
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    40
	// Set up static variables. Run once only.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    41
	if ( $reset || ! isset( $static_characters ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    42
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    43
		 * Filter whether to skip running wptexturize().
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    44
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    45
		 * Passing false to the filter will effectively short-circuit wptexturize().
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    46
		 * returning the original text passed to the function instead.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    47
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    48
		 * The filter runs only once, the first time wptexturize() is called.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    49
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    50
		 * @since 4.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    51
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    52
		 * @see wptexturize()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    53
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    54
		 * @param bool $run_texturize Whether to short-circuit wptexturize().
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    55
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    56
		$run_texturize = apply_filters( 'run_wptexturize', $run_texturize );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    57
		if ( false === $run_texturize ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    58
			return $text;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    59
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    60
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
		/* translators: opening curly double quote */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
		$opening_quote = _x( '&#8220;', 'opening curly double quote' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
		/* translators: closing curly double quote */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
		$closing_quote = _x( '&#8221;', 'closing curly double quote' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
		/* translators: apostrophe, for example in 'cause or can't */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
		$apos = _x( '&#8217;', 'apostrophe' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
		/* translators: prime, for example in 9' (nine feet) */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
		$prime = _x( '&#8242;', 'prime' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
		/* translators: double prime, for example in 9" (nine inches) */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
		$double_prime = _x( '&#8243;', 'double prime' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
		/* translators: opening curly single quote */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
		$opening_single_quote = _x( '&#8216;', 'opening curly single quote' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
		/* translators: closing curly single quote */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
		$closing_single_quote = _x( '&#8217;', 'closing curly single quote' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
		/* translators: en dash */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
		$en_dash = _x( '&#8211;', 'en dash' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
		/* translators: em dash */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
		$em_dash = _x( '&#8212;', 'em dash' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
		$default_no_texturize_tags = array('pre', 'code', 'kbd', 'style', 'script', 'tt');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
		$default_no_texturize_shortcodes = array('code');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
		// if a plugin has provided an autocorrect array, use it
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
		if ( isset($wp_cockneyreplace) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    89
			$cockney = array_keys( $wp_cockneyreplace );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    90
			$cockneyreplace = array_values( $wp_cockneyreplace );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
		} elseif ( "'" != $apos ) { // Only bother if we're doing a replacement.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    92
			$cockney = array( "'tain't", "'twere", "'twas", "'tis", "'twill", "'til", "'bout", "'nuff", "'round", "'cause", "'em" );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    93
			$cockneyreplace = array( $apos . "tain" . $apos . "t", $apos . "twere", $apos . "twas", $apos . "tis", $apos . "twill", $apos . "til", $apos . "bout", $apos . "nuff", $apos . "round", $apos . "cause", $apos . "em" );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
			$cockney = $cockneyreplace = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    98
		$static_characters = array_merge( array( '...', '``', '\'\'', ' (tm)' ), $cockney );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    99
		$static_replacements = array_merge( array( '&#8230;', $opening_quote, $closing_quote, ' &#8482;' ), $cockneyreplace );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   100
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   101
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   102
		// Pattern-based replacements of characters.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   103
		// Sort the remaining patterns into several arrays for performance tuning.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   104
		$dynamic_characters = array( 'apos' => array(), 'quote' => array(), 'dash' => array() );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   105
		$dynamic_replacements = array( 'apos' => array(), 'quote' => array(), 'dash' => array() );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
		$dynamic = array();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   107
		$spaces = wp_spaces_regexp();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   108
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   109
		// '99' and '99" are ambiguous among other patterns; assume it's an abbreviated year at the end of a quotation.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   110
		if ( "'" !== $apos || "'" !== $closing_single_quote ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   111
			$dynamic[ '/\'(\d\d)\'(?=\Z|[.,)}\-\]]|&gt;|' . $spaces . ')/' ] = $apos . '$1' . $closing_single_quote;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   112
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   113
		if ( "'" !== $apos || '"' !== $closing_quote ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   114
			$dynamic[ '/\'(\d\d)"(?=\Z|[.,)}\-\]]|&gt;|' . $spaces . ')/' ] = $apos . '$1' . $closing_quote;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   115
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   116
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   117
		// '99 '99s '99's (apostrophe)  But never '9 or '99% or '999 or '99.0.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   118
		if ( "'" !== $apos ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   119
			$dynamic[ '/\'(?=\d\d(?:\Z|(?![%\d]|[.,]\d)))/' ] = $apos;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   120
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   121
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   122
		// Quoted Numbers like '0.42'
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   123
		if ( "'" !== $opening_single_quote && "'" !== $closing_single_quote ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   124
			$dynamic[ '/(?<=\A|' . $spaces . ')\'(\d[.,\d]*)\'/' ] = $opening_single_quote . '$1' . $closing_single_quote;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   125
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   126
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   127
		// Single quote at start, or preceded by (, {, <, [, ", -, or spaces.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   128
		if ( "'" !== $opening_single_quote ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   129
			$dynamic[ '/(?<=\A|[([{"\-]|&lt;|' . $spaces . ')\'/' ] = $opening_single_quote;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   130
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   131
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   132
		// Apostrophe in a word.  No spaces, double apostrophes, or other punctuation.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   133
		if ( "'" !== $apos ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   134
			$dynamic[ '/(?<!' . $spaces . ')\'(?!\Z|[.,:;"\'(){}[\]\-]|&[lg]t;|' . $spaces . ')/' ] = $apos;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   135
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   136
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   137
		// 9' (prime)
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   138
		if ( "'" !== $prime ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   139
			$dynamic[ '/(?<=\d)\'/' ] = $prime;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   140
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   141
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   142
		// Single quotes followed by spaces or ending punctuation.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   143
		if ( "'" !== $closing_single_quote ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   144
			$dynamic[ '/\'(?=\Z|[.,)}\-\]]|&gt;|' . $spaces . ')/' ] = $closing_single_quote;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
		}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   146
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   147
		$dynamic_characters['apos'] = array_keys( $dynamic );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   148
		$dynamic_replacements['apos'] = array_values( $dynamic );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   149
		$dynamic = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   150
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   151
		// Quoted Numbers like "42"
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   152
		if ( '"' !== $opening_quote && '"' !== $closing_quote ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   153
			$dynamic[ '/(?<=\A|' . $spaces . ')"(\d[.,\d]*)"/' ] = $opening_quote . '$1' . $closing_quote;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   154
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   155
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   156
		// 9" (double prime)
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   157
		if ( '"' !== $double_prime ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   158
			$dynamic[ '/(?<=\d)"/' ] = $double_prime;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   159
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   160
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   161
		// Double quote at start, or preceded by (, {, <, [, -, or spaces, and not followed by spaces.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   162
		if ( '"' !== $opening_quote ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   163
			$dynamic[ '/(?<=\A|[([{\-]|&lt;|' . $spaces . ')"(?!' . $spaces . ')/' ] = $opening_quote;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   164
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   165
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   166
		// Any remaining double quotes.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   167
		if ( '"' !== $closing_quote ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   168
			$dynamic[ '/"/' ] = $closing_quote;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   169
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   170
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   171
		$dynamic_characters['quote'] = array_keys( $dynamic );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   172
		$dynamic_replacements['quote'] = array_values( $dynamic );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   173
		$dynamic = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   174
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   175
		// Dashes and spaces
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   176
		$dynamic[ '/---/' ] = $em_dash;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   177
		$dynamic[ '/(?<=^|' . $spaces . ')--(?=$|' . $spaces . ')/' ] = $em_dash;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   178
		$dynamic[ '/(?<!xn)--/' ] = $en_dash;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   179
		$dynamic[ '/(?<=^|' . $spaces . ')-(?=$|' . $spaces . ')/' ] = $en_dash;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   180
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   181
		$dynamic_characters['dash'] = array_keys( $dynamic );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   182
		$dynamic_replacements['dash'] = array_values( $dynamic );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
	// Must do this every time in case plugins use these filters in a context sensitive manner
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   186
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   187
	 * Filter the list of HTML elements not to texturize.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   188
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   189
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   190
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   191
	 * @param array $default_no_texturize_tags An array of HTML element names.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   192
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   193
	$no_texturize_tags = apply_filters( 'no_texturize_tags', $default_no_texturize_tags );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   194
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   195
	 * Filter the list of shortcodes not to texturize.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   196
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   197
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   198
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   199
	 * @param array $default_no_texturize_shortcodes An array of shortcode names.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   200
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   201
	$no_texturize_shortcodes = apply_filters( 'no_texturize_shortcodes', $default_no_texturize_shortcodes );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
	$no_texturize_tags_stack = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
	$no_texturize_shortcodes_stack = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   206
	// Look for shortcodes and HTML elements.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   207
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   208
	$tagnames = array_keys( $shortcode_tags );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   209
	$tagregexp = join( '|', array_map( 'preg_quote', $tagnames ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   210
	$tagregexp = "(?:$tagregexp)(?![\\w-])"; // Excerpt of get_shortcode_regex().
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   211
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   212
	$comment_regex =
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   213
		  '!'           // Start of comment, after the <.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   214
		. '(?:'         // Unroll the loop: Consume everything until --> is found.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   215
		.     '-(?!->)' // Dash not followed by end of comment.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   216
		.     '[^\-]*+' // Consume non-dashes.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   217
		. ')*+'         // Loop possessively.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   218
		. '(?:-->)?';   // End of comment. If not found, match all input.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   219
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   220
	$shortcode_regex =
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   221
		  '\['              // Find start of shortcode.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   222
		. '[\/\[]?'         // Shortcodes may begin with [/ or [[
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   223
		. $tagregexp        // Only match registered shortcodes, because performance.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   224
		. '(?:'
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   225
		.     '[^\[\]<>]+'  // Shortcodes do not contain other shortcodes. Quantifier critical.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   226
		. '|'
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   227
		.     '<[^\[\]>]*>' // HTML elements permitted. Prevents matching ] before >.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   228
		. ')*+'             // Possessive critical.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   229
		. '\]'              // Find end of shortcode.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   230
		. '\]?';            // Shortcodes may end with ]]
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   231
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   232
	$regex =
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   233
		  '/('                   // Capture the entire match.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   234
		.     '<'                // Find start of element.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   235
		.     '(?(?=!--)'        // Is this a comment?
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   236
		.         $comment_regex // Find end of comment.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   237
		.     '|'
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   238
		.         '[^>]*>'       // Find end of element.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   239
		.     ')'
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   240
		. '|'
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   241
		.     $shortcode_regex   // Find shortcodes.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   242
		. ')/s';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   243
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   244
	$textarr = preg_split( $regex, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
	foreach ( $textarr as &$curl ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   247
		// Only call _wptexturize_pushpop_element if $curl is a delimiter.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
		$first = $curl[0];
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   249
		if ( '<' === $first && '<!--' === substr( $curl, 0, 4 ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   250
			// This is an HTML comment delimeter.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   251
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   252
			continue;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   253
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   254
		} elseif ( '<' === $first && '>' === substr( $curl, -1 ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   255
			// This is an HTML element delimiter.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   256
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   257
			_wptexturize_pushpop_element( $curl, $no_texturize_tags_stack, $no_texturize_tags );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   258
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   259
		} elseif ( '' === trim( $curl ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   260
			// This is a newline between delimiters.  Performance improves when we check this.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   261
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   262
			continue;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   263
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   264
		} elseif ( '[' === $first && 1 === preg_match( '/^' . $shortcode_regex . '$/', $curl ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   265
			// This is a shortcode delimiter.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   266
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   267
			if ( '[[' !== substr( $curl, 0, 2 ) && ']]' !== substr( $curl, -2 ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   268
				// Looks like a normal shortcode.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   269
				_wptexturize_pushpop_element( $curl, $no_texturize_shortcodes_stack, $no_texturize_shortcodes );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   270
			} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   271
				// Looks like an escaped shortcode.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   272
				continue;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   273
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   274
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   275
		} elseif ( empty( $no_texturize_shortcodes_stack ) && empty( $no_texturize_tags_stack ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   276
			// This is neither a delimiter, nor is this content inside of no_texturize pairs.  Do texturize.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   277
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   278
			$curl = str_replace( $static_characters, $static_replacements, $curl );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   279
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   280
			if ( false !== strpos( $curl, "'" ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   281
				$curl = preg_replace( $dynamic_characters['apos'], $dynamic_replacements['apos'], $curl );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   282
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   283
			if ( false !== strpos( $curl, '"' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   284
				$curl = preg_replace( $dynamic_characters['quote'], $dynamic_replacements['quote'], $curl );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   285
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   286
			if ( false !== strpos( $curl, '-' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   287
				$curl = preg_replace( $dynamic_characters['dash'], $dynamic_replacements['dash'], $curl );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   288
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   289
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   290
			// 9x9 (times), but never 0x9999
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   291
			if ( 1 === preg_match( '/(?<=\d)x\d/', $curl ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   292
				// Searching for a digit is 10 times more expensive than for the x, so we avoid doing this one!
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   293
				$curl = preg_replace( '/\b(\d(?(?<=0)[\d\.,]+|[\d\.,]*))x(\d[\d\.,]*)\b/', '$1&#215;$2', $curl );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   294
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
	}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   297
	$text = implode( '', $textarr );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   298
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   299
	// Replace each & with &#038; unless it already looks like an entity.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   300
	$text = preg_replace('/&(?!#(?:\d+|x[a-f0-9]+);|[a-z1-4]{1,8};)/i', '&#038;', $text);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   301
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   302
	return $text;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
 * Search for disabled element tags. Push element to stack on tag open and pop
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   307
 * on tag close.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   308
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   309
 * Assumes first char of $text is tag opening and last char is tag closing.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   310
 * Assumes second char of $text is optionally '/' to indicate closing as in </html>.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
 * @since 2.9.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   315
 * @param string $text Text to check. Must be a tag like `<html>` or `[shortcode]`.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   316
 * @param array $stack List of open tag elements.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   317
 * @param array $disabled_elements The tag names to match against. Spaces are not allowed in tag names.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   319
function _wptexturize_pushpop_element($text, &$stack, $disabled_elements) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   320
	// Is it an opening tag or closing tag?
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   321
	if ( '/' !== $text[1] ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   322
		$opening_tag = true;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   323
		$name_offset = 1;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   324
	} elseif ( 0 == count( $stack ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   325
		// Stack is empty. Just stop.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   326
		return;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   327
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   328
		$opening_tag = false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   329
		$name_offset = 2;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   330
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   331
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   332
	// Parse out the tag name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   333
	$space = strpos( $text, ' ' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   334
	if ( false === $space ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   335
		$space = -1;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   336
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   337
		$space -= $name_offset;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   338
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   339
	$tag = substr( $text, $name_offset, $space );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   340
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   341
	// Handle disabled tags.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   342
	if ( in_array( $tag, $disabled_elements ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   343
		if ( $opening_tag ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
			/*
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
			 * This disables texturize until we find a closing tag of our type
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
			 * (e.g. <pre>) even if there was invalid nesting before that
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
			 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
			 * Example: in the case <pre>sadsadasd</code>"baba"</pre>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
			 *          "baba" won't be texturize
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
			 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   352
			array_push( $stack, $tag );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   353
		} elseif ( end( $stack ) == $tag ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   354
			array_pop( $stack );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
 * Replaces double line-breaks with paragraph elements.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
 * A group of regex replaces used to identify text formatted with newlines and
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   363
 * replace double line-breaks with HTML paragraph tags. The remaining line-breaks
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   364
 * after conversion become <<br />> tags, unless $br is set to '0' or 'false'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   368
 * @param string $pee The text which has to be formatted.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   369
 * @param bool   $br  Optional. If set, this will convert all remaining line-breaks
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   370
 *                    after paragraphing. Default true.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
 * @return string Text which has been converted into correct paragraph tags.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
function wpautop($pee, $br = true) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
	$pre_tags = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
	if ( trim($pee) === '' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
		return '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   379
	// Just to make things a little easier, pad the end.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   380
	$pee = $pee . "\n";
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   381
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   382
	/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   383
	 * Pre tags shouldn't be touched by autop.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   384
	 * Replace pre tags with placeholders and bring them back after autop.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   385
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
	if ( strpos($pee, '<pre') !== false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
		$pee_parts = explode( '</pre>', $pee );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
		$last_pee = array_pop($pee_parts);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
		$pee = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
		$i = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   391
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   392
		foreach ( $pee_parts as $pee_part ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   393
			$start = strpos($pee_part, '<pre');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   394
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   395
			// Malformed html?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   396
			if ( $start === false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
				$pee .= $pee_part;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
				continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   400
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
			$name = "<pre wp-pre-tag-$i></pre>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
			$pre_tags[$name] = substr( $pee_part, $start ) . '</pre>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   404
			$pee .= substr( $pee_part, 0, $start ) . $name;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   405
			$i++;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   406
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   407
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   408
		$pee .= $last_pee;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   409
	}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   410
	// Change multiple <br>s into two line breaks, which will turn into paragraphs.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   411
	$pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   412
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   413
	$allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   414
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   415
	// Add a single line break above block-level opening tags.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
	$pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   417
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   418
	// Add a double line break below block-level closing tags.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
	$pee = preg_replace('!(</' . $allblocks . '>)!', "$1\n\n", $pee);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   420
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   421
	// Standardize newline characters to "\n".
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   422
	$pee = str_replace(array("\r\n", "\r"), "\n", $pee); 
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   423
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   424
	// Collapse line breaks before and after <option> elements so they don't get autop'd.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   425
	if ( strpos( $pee, '<option' ) !== false ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   426
		$pee = preg_replace( '|\s*<option|', '<option', $pee );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   427
		$pee = preg_replace( '|</option>\s*|', '</option>', $pee );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   428
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   429
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   430
	/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   431
	 * Collapse line breaks inside <object> elements, before <param> and <embed> elements
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   432
	 * so they don't get autop'd.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   433
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   434
	if ( strpos( $pee, '</object>' ) !== false ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   435
		$pee = preg_replace( '|(<object[^>]*>)\s*|', '$1', $pee );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   436
		$pee = preg_replace( '|\s*</object>|', '</object>', $pee );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   437
		$pee = preg_replace( '%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   438
	}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   439
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   440
	/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   441
	 * Collapse line breaks inside <audio> and <video> elements,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   442
	 * before and after <source> and <track> elements.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   443
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   444
	if ( strpos( $pee, '<source' ) !== false || strpos( $pee, '<track' ) !== false ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   445
		$pee = preg_replace( '%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   446
		$pee = preg_replace( '%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   447
		$pee = preg_replace( '%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   448
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   449
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   450
	// Remove more than two contiguous line breaks.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   451
	$pee = preg_replace("/\n\n+/", "\n\n", $pee);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   452
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   453
	// Split up the contents into an array of strings, separated by double line breaks.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   454
	$pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   455
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   456
	// Reset $pee prior to rebuilding.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   457
	$pee = '';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   458
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   459
	// Rebuild the content as a string, wrapping every bit with a <p>.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   460
	foreach ( $pees as $tinkle ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   461
		$pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   462
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   463
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   464
	// Under certain strange conditions it could create a P of entirely whitespace.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   465
	$pee = preg_replace('|<p>\s*</p>|', '', $pee); 
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   466
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   467
	// Add a closing <p> inside <div>, <address>, or <form> tag if missing.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   468
	$pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>$1</p></$2>", $pee);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   469
	
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   470
	// If an opening or closing block element tag is wrapped in a <p>, unwrap it.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   471
	$pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee); 
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   472
	
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   473
	// In some cases <li> may get wrapped in <p>, fix them.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   474
	$pee = preg_replace("|<p>(<li.+?)</p>|", "$1", $pee); 
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   475
	
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   476
	// If a <blockquote> is wrapped with a <p>, move it inside the <blockquote>.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   477
	$pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote$1><p>", $pee);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   478
	$pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   479
	
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   480
	// If an opening or closing block element tag is preceded by an opening <p> tag, remove it.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   481
	$pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "$1", $pee);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   482
	
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   483
	// If an opening or closing block element tag is followed by a closing <p> tag, remove it.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   484
	$pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   485
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   486
	// Optionally insert line breaks.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   487
	if ( $br ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   488
		// Replace newlines that shouldn't be touched with a placeholder.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   489
		$pee = preg_replace_callback('/<(script|style).*?<\/\\1>/s', '_autop_newline_preservation_helper', $pee);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   490
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   491
		// Replace any new line characters that aren't preceded by a <br /> with a <br />.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   492
		$pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee); 
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   493
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   494
		// Replace newline placeholders with newlines.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   495
		$pee = str_replace('<WPPreserveNewline />', "\n", $pee);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   496
	}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   497
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   498
	// If a <br /> tag is after an opening or closing block tag, remove it.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   499
	$pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "$1", $pee);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   500
	
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   501
	// If a <br /> tag is before a subset of opening or closing block tags, remove it.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   502
	$pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   503
	$pee = preg_replace( "|\n</p>$|", '</p>', $pee );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   504
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   505
	// Replace placeholder <pre> tags with their original content.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   506
	if ( !empty($pre_tags) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   507
		$pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   508
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   509
	return $pee;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   510
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   511
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   512
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   513
 * Newline preservation help function for wpautop
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   514
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   515
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   516
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   517
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   518
 * @param array $matches preg_replace_callback matches array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   519
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   520
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   521
function _autop_newline_preservation_helper( $matches ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   522
	return str_replace("\n", "<WPPreserveNewline />", $matches[0]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   523
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   524
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   525
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   526
 * Don't auto-p wrap shortcodes that stand alone
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   527
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   528
 * Ensures that shortcodes are not wrapped in `<p>...</p>`.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   529
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   530
 * @since 2.9.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   531
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   532
 * @param string $pee The content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   533
 * @return string The filtered content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   534
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   535
function shortcode_unautop( $pee ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   536
	global $shortcode_tags;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   537
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   538
	if ( empty( $shortcode_tags ) || !is_array( $shortcode_tags ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   539
		return $pee;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   540
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   541
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   542
	$tagregexp = join( '|', array_map( 'preg_quote', array_keys( $shortcode_tags ) ) );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   543
	$spaces = wp_spaces_regexp();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   544
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   545
	$pattern =
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   546
		  '/'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   547
		. '<p>'                              // Opening paragraph
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   548
		. '(?:' . $spaces . ')*+'            // Optional leading whitespace
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   549
		. '('                                // 1: The shortcode
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   550
		.     '\\['                          // Opening bracket
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   551
		.     "($tagregexp)"                 // 2: Shortcode name
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   552
		.     '(?![\\w-])'                   // Not followed by word character or hyphen
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   553
		                                     // Unroll the loop: Inside the opening shortcode tag
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   554
		.     '[^\\]\\/]*'                   // Not a closing bracket or forward slash
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   555
		.     '(?:'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   556
		.         '\\/(?!\\])'               // A forward slash not followed by a closing bracket
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   557
		.         '[^\\]\\/]*'               // Not a closing bracket or forward slash
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   558
		.     ')*?'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   559
		.     '(?:'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   560
		.         '\\/\\]'                   // Self closing tag and closing bracket
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   561
		.     '|'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   562
		.         '\\]'                      // Closing bracket
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   563
		.         '(?:'                      // Unroll the loop: Optionally, anything between the opening and closing shortcode tags
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   564
		.             '[^\\[]*+'             // Not an opening bracket
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   565
		.             '(?:'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   566
		.                 '\\[(?!\\/\\2\\])' // An opening bracket not followed by the closing shortcode tag
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   567
		.                 '[^\\[]*+'         // Not an opening bracket
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   568
		.             ')*+'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   569
		.             '\\[\\/\\2\\]'         // Closing shortcode tag
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   570
		.         ')?'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   571
		.     ')'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   572
		. ')'
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   573
		. '(?:' . $spaces . ')*+'            // optional trailing whitespace
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   574
		. '<\\/p>'                           // closing paragraph
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   575
		. '/s';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   576
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   577
	return preg_replace( $pattern, '$1', $pee );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   578
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   579
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   580
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   581
 * Checks to see if a string is utf8 encoded.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   582
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   583
 * NOTE: This function checks for 5-Byte sequences, UTF8
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   584
 *       has Bytes Sequences with a maximum length of 4.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   585
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   586
 * @author bmorel at ssi dot fr (modified)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   587
 * @since 1.2.1
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   588
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   589
 * @param string $str The string to be checked
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   590
 * @return bool True if $str fits a UTF-8 model, false otherwise.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   591
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   592
function seems_utf8($str) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   593
	mbstring_binary_safe_encoding();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   594
	$length = strlen($str);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   595
	reset_mbstring_encoding();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   596
	for ($i=0; $i < $length; $i++) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   597
		$c = ord($str[$i]);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   598
		if ($c < 0x80) $n = 0; // 0bbbbbbb
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   599
		elseif (($c & 0xE0) == 0xC0) $n=1; // 110bbbbb
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   600
		elseif (($c & 0xF0) == 0xE0) $n=2; // 1110bbbb
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   601
		elseif (($c & 0xF8) == 0xF0) $n=3; // 11110bbb
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   602
		elseif (($c & 0xFC) == 0xF8) $n=4; // 111110bb
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   603
		elseif (($c & 0xFE) == 0xFC) $n=5; // 1111110b
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   604
		else return false; // Does not match any model
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   605
		for ($j=0; $j<$n; $j++) { // n bytes matching 10bbbbbb follow ?
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   606
			if ((++$i == $length) || ((ord($str[$i]) & 0xC0) != 0x80))
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   607
				return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   608
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   609
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   610
	return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   611
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   612
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   613
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   614
 * Converts a number of special characters into their HTML entities.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   615
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   616
 * Specifically deals with: &, <, >, ", and '.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   617
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   618
 * $quote_style can be set to ENT_COMPAT to encode " to
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   619
 * &quot;, or ENT_QUOTES to do both. Default is ENT_NOQUOTES where no quotes are encoded.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   620
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   621
 * @since 1.2.2
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   622
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   623
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   624
 * @param string $string The text which is to be encoded.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   625
 * @param int $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.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   626
 * @param string $charset Optional. The character encoding of the string. Default is false.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   627
 * @param boolean $double_encode Optional. Whether to encode existing html entities. Default is false.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   628
 * @return string The encoded text with HTML entities.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   629
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   630
function _wp_specialchars( $string, $quote_style = ENT_NOQUOTES, $charset = false, $double_encode = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   631
	$string = (string) $string;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   632
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   633
	if ( 0 === strlen( $string ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   634
		return '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   635
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   636
	// Don't bother if there are no specialchars - saves some processing
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   637
	if ( ! preg_match( '/[&<>"\']/', $string ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   638
		return $string;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   639
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   640
	// Account for the previous behaviour of the function when the $quote_style is not an accepted value
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   641
	if ( empty( $quote_style ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   642
		$quote_style = ENT_NOQUOTES;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   643
	elseif ( ! in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   644
		$quote_style = ENT_QUOTES;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   645
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   646
	// Store the site charset as a static to avoid multiple calls to wp_load_alloptions()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   647
	if ( ! $charset ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   648
		static $_charset;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   649
		if ( ! isset( $_charset ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   650
			$alloptions = wp_load_alloptions();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   651
			$_charset = isset( $alloptions['blog_charset'] ) ? $alloptions['blog_charset'] : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   652
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   653
		$charset = $_charset;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   654
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   655
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   656
	if ( in_array( $charset, array( 'utf8', 'utf-8', 'UTF8' ) ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   657
		$charset = 'UTF-8';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   658
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   659
	$_quote_style = $quote_style;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   660
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   661
	if ( $quote_style === 'double' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   662
		$quote_style = ENT_COMPAT;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   663
		$_quote_style = ENT_COMPAT;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   664
	} elseif ( $quote_style === 'single' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   665
		$quote_style = ENT_NOQUOTES;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   666
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   668
	// Handle double encoding ourselves
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   669
	if ( $double_encode ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   670
		$string = @htmlspecialchars( $string, $quote_style, $charset );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   671
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   672
		// Decode &amp; into &
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   673
		$string = wp_specialchars_decode( $string, $_quote_style );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   674
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   675
		// Guarantee every &entity; is valid or re-encode the &
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   676
		$string = wp_kses_normalize_entities( $string );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   677
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   678
		// Now re-encode everything except &entity;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   679
		$string = preg_split( '/(&#?x?[0-9a-z]+;)/i', $string, -1, PREG_SPLIT_DELIM_CAPTURE );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   680
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   681
		for ( $i = 0, $c = count( $string ); $i < $c; $i += 2 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   682
			$string[$i] = @htmlspecialchars( $string[$i], $quote_style, $charset );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   683
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   684
		$string = implode( '', $string );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   685
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   686
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   687
	// Backwards compatibility
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   688
	if ( 'single' === $_quote_style )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   689
		$string = str_replace( "'", '&#039;', $string );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   690
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   691
	return $string;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   692
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   693
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   694
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   695
 * Converts a number of HTML entities into their special characters.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   696
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   697
 * Specifically deals with: &, <, >, ", and '.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   698
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   699
 * $quote_style can be set to ENT_COMPAT to decode " entities,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   700
 * or ENT_QUOTES to do both " and '. Default is ENT_NOQUOTES where no quotes are decoded.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   701
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   702
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   703
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   704
 * @param string $string The text which is to be decoded.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   705
 * @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.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   706
 * @return string The decoded text without HTML entities.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   707
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   708
function wp_specialchars_decode( $string, $quote_style = ENT_NOQUOTES ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   709
	$string = (string) $string;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   710
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   711
	if ( 0 === strlen( $string ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   712
		return '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   713
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   714
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   715
	// Don't bother if there are no entities - saves a lot of processing
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   716
	if ( strpos( $string, '&' ) === false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   717
		return $string;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   718
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   719
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   720
	// Match the previous behaviour of _wp_specialchars() when the $quote_style is not an accepted value
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   721
	if ( empty( $quote_style ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   722
		$quote_style = ENT_NOQUOTES;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   723
	} elseif ( !in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   724
		$quote_style = ENT_QUOTES;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   725
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   726
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   727
	// More complete than get_html_translation_table( HTML_SPECIALCHARS )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   728
	$single = array( '&#039;'  => '\'', '&#x27;' => '\'' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   729
	$single_preg = array( '/&#0*39;/'  => '&#039;', '/&#x0*27;/i' => '&#x27;' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   730
	$double = array( '&quot;' => '"', '&#034;'  => '"', '&#x22;' => '"' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   731
	$double_preg = array( '/&#0*34;/'  => '&#034;', '/&#x0*22;/i' => '&#x22;' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   732
	$others = array( '&lt;'   => '<', '&#060;'  => '<', '&gt;'   => '>', '&#062;'  => '>', '&amp;'  => '&', '&#038;'  => '&', '&#x26;' => '&' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   733
	$others_preg = array( '/&#0*60;/'  => '&#060;', '/&#0*62;/'  => '&#062;', '/&#0*38;/'  => '&#038;', '/&#x0*26;/i' => '&#x26;' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   734
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   735
	if ( $quote_style === ENT_QUOTES ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   736
		$translation = array_merge( $single, $double, $others );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   737
		$translation_preg = array_merge( $single_preg, $double_preg, $others_preg );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   738
	} elseif ( $quote_style === ENT_COMPAT || $quote_style === 'double' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   739
		$translation = array_merge( $double, $others );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   740
		$translation_preg = array_merge( $double_preg, $others_preg );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   741
	} elseif ( $quote_style === 'single' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   742
		$translation = array_merge( $single, $others );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   743
		$translation_preg = array_merge( $single_preg, $others_preg );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   744
	} elseif ( $quote_style === ENT_NOQUOTES ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   745
		$translation = $others;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   746
		$translation_preg = $others_preg;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   747
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   748
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   749
	// Remove zero padding on numeric entities
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   750
	$string = preg_replace( array_keys( $translation_preg ), array_values( $translation_preg ), $string );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   751
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   752
	// Replace characters according to translation table
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   753
	return strtr( $string, $translation );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   754
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   755
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   756
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   757
 * Checks for invalid UTF8 in a string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   758
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   759
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   760
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   761
 * @param string $string The text which is to be checked.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   762
 * @param boolean $strip Optional. Whether to attempt to strip out invalid UTF8. Default is false.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   763
 * @return string The checked text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   764
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   765
function wp_check_invalid_utf8( $string, $strip = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   766
	$string = (string) $string;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   767
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   768
	if ( 0 === strlen( $string ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   769
		return '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   770
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   771
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   772
	// Store the site charset as a static to avoid multiple calls to get_option()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   773
	static $is_utf8;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   774
	if ( !isset( $is_utf8 ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   775
		$is_utf8 = in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   776
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   777
	if ( !$is_utf8 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   778
		return $string;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   779
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   780
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   781
	// Check for support for utf8 in the installed PCRE library once and store the result in a static
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   782
	static $utf8_pcre;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   783
	if ( !isset( $utf8_pcre ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   784
		$utf8_pcre = @preg_match( '/^./u', 'a' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   785
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   786
	// We can't demand utf8 in the PCRE installation, so just return the string in those cases
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   787
	if ( !$utf8_pcre ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   788
		return $string;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   789
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   790
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   791
	// preg_match fails when it encounters invalid UTF8 in $string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   792
	if ( 1 === @preg_match( '/^./us', $string ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   793
		return $string;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   794
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   795
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   796
	// Attempt to strip the bad chars if requested (not recommended)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   797
	if ( $strip && function_exists( 'iconv' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   798
		return iconv( 'utf-8', 'utf-8', $string );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   799
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   800
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   801
	return '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   802
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   803
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   804
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   805
 * Encode the Unicode values to be used in the URI.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   806
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   807
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   808
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   809
 * @param string $utf8_string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   810
 * @param int $length Max length of the string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   811
 * @return string String with Unicode encoded for URI.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   812
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   813
function utf8_uri_encode( $utf8_string, $length = 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   814
	$unicode = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   815
	$values = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   816
	$num_octets = 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   817
	$unicode_length = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   818
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   819
	mbstring_binary_safe_encoding();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   820
	$string_length = strlen( $utf8_string );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   821
	reset_mbstring_encoding();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   822
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   823
	for ($i = 0; $i < $string_length; $i++ ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   824
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   825
		$value = ord( $utf8_string[ $i ] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   826
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   827
		if ( $value < 128 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   828
			if ( $length && ( $unicode_length >= $length ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   829
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   830
			$unicode .= chr($value);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   831
			$unicode_length++;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   832
		} else {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   833
			if ( count( $values ) == 0 ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   834
				if ( $value < 224 ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   835
					$num_octets = 2;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   836
				} elseif ( $value < 240 ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   837
					$num_octets = 3;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   838
				} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   839
					$num_octets = 4;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   840
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   841
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   842
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   843
			$values[] = $value;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   844
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   845
			if ( $length && ( $unicode_length + ($num_octets * 3) ) > $length )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   846
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   847
			if ( count( $values ) == $num_octets ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   848
				for ( $j = 0; $j < $num_octets; $j++ ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   849
					$unicode .= '%' . dechex( $values[ $j ] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   850
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   851
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   852
				$unicode_length += $num_octets * 3;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   853
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   854
				$values = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   855
				$num_octets = 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   856
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   857
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   858
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   859
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   860
	return $unicode;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   861
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   862
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   863
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   864
 * Converts all accent characters to ASCII characters.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   865
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   866
 * If there are no accent characters, then the string given is just returned.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   867
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   868
 * @since 1.2.1
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   869
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   870
 * @param string $string Text that might have accent characters
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   871
 * @return string Filtered string with replaced "nice" characters.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   872
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   873
function remove_accents($string) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   874
	if ( !preg_match('/[\x80-\xff]/', $string) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   875
		return $string;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   876
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   877
	if (seems_utf8($string)) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   878
		$chars = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   879
		// Decompositions for Latin-1 Supplement
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   880
		chr(194).chr(170) => 'a', chr(194).chr(186) => 'o',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   881
		chr(195).chr(128) => 'A', chr(195).chr(129) => 'A',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   882
		chr(195).chr(130) => 'A', chr(195).chr(131) => 'A',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   883
		chr(195).chr(132) => 'A', chr(195).chr(133) => 'A',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   884
		chr(195).chr(134) => 'AE',chr(195).chr(135) => 'C',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   885
		chr(195).chr(136) => 'E', chr(195).chr(137) => 'E',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   886
		chr(195).chr(138) => 'E', chr(195).chr(139) => 'E',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   887
		chr(195).chr(140) => 'I', chr(195).chr(141) => 'I',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   888
		chr(195).chr(142) => 'I', chr(195).chr(143) => 'I',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   889
		chr(195).chr(144) => 'D', chr(195).chr(145) => 'N',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   890
		chr(195).chr(146) => 'O', chr(195).chr(147) => 'O',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   891
		chr(195).chr(148) => 'O', chr(195).chr(149) => 'O',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   892
		chr(195).chr(150) => 'O', chr(195).chr(153) => 'U',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   893
		chr(195).chr(154) => 'U', chr(195).chr(155) => 'U',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   894
		chr(195).chr(156) => 'U', chr(195).chr(157) => 'Y',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   895
		chr(195).chr(158) => 'TH',chr(195).chr(159) => 's',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   896
		chr(195).chr(160) => 'a', chr(195).chr(161) => 'a',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   897
		chr(195).chr(162) => 'a', chr(195).chr(163) => 'a',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   898
		chr(195).chr(164) => 'a', chr(195).chr(165) => 'a',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   899
		chr(195).chr(166) => 'ae',chr(195).chr(167) => 'c',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   900
		chr(195).chr(168) => 'e', chr(195).chr(169) => 'e',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   901
		chr(195).chr(170) => 'e', chr(195).chr(171) => 'e',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   902
		chr(195).chr(172) => 'i', chr(195).chr(173) => 'i',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   903
		chr(195).chr(174) => 'i', chr(195).chr(175) => 'i',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   904
		chr(195).chr(176) => 'd', chr(195).chr(177) => 'n',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   905
		chr(195).chr(178) => 'o', chr(195).chr(179) => 'o',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   906
		chr(195).chr(180) => 'o', chr(195).chr(181) => 'o',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   907
		chr(195).chr(182) => 'o', chr(195).chr(184) => 'o',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   908
		chr(195).chr(185) => 'u', chr(195).chr(186) => 'u',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   909
		chr(195).chr(187) => 'u', chr(195).chr(188) => 'u',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   910
		chr(195).chr(189) => 'y', chr(195).chr(190) => 'th',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   911
		chr(195).chr(191) => 'y', chr(195).chr(152) => 'O',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   912
		// Decompositions for Latin Extended-A
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   913
		chr(196).chr(128) => 'A', chr(196).chr(129) => 'a',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   914
		chr(196).chr(130) => 'A', chr(196).chr(131) => 'a',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   915
		chr(196).chr(132) => 'A', chr(196).chr(133) => 'a',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   916
		chr(196).chr(134) => 'C', chr(196).chr(135) => 'c',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   917
		chr(196).chr(136) => 'C', chr(196).chr(137) => 'c',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   918
		chr(196).chr(138) => 'C', chr(196).chr(139) => 'c',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   919
		chr(196).chr(140) => 'C', chr(196).chr(141) => 'c',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   920
		chr(196).chr(142) => 'D', chr(196).chr(143) => 'd',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   921
		chr(196).chr(144) => 'D', chr(196).chr(145) => 'd',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   922
		chr(196).chr(146) => 'E', chr(196).chr(147) => 'e',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   923
		chr(196).chr(148) => 'E', chr(196).chr(149) => 'e',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   924
		chr(196).chr(150) => 'E', chr(196).chr(151) => 'e',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   925
		chr(196).chr(152) => 'E', chr(196).chr(153) => 'e',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   926
		chr(196).chr(154) => 'E', chr(196).chr(155) => 'e',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   927
		chr(196).chr(156) => 'G', chr(196).chr(157) => 'g',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   928
		chr(196).chr(158) => 'G', chr(196).chr(159) => 'g',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   929
		chr(196).chr(160) => 'G', chr(196).chr(161) => 'g',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   930
		chr(196).chr(162) => 'G', chr(196).chr(163) => 'g',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   931
		chr(196).chr(164) => 'H', chr(196).chr(165) => 'h',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   932
		chr(196).chr(166) => 'H', chr(196).chr(167) => 'h',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   933
		chr(196).chr(168) => 'I', chr(196).chr(169) => 'i',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   934
		chr(196).chr(170) => 'I', chr(196).chr(171) => 'i',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   935
		chr(196).chr(172) => 'I', chr(196).chr(173) => 'i',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   936
		chr(196).chr(174) => 'I', chr(196).chr(175) => 'i',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   937
		chr(196).chr(176) => 'I', chr(196).chr(177) => 'i',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   938
		chr(196).chr(178) => 'IJ',chr(196).chr(179) => 'ij',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   939
		chr(196).chr(180) => 'J', chr(196).chr(181) => 'j',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   940
		chr(196).chr(182) => 'K', chr(196).chr(183) => 'k',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   941
		chr(196).chr(184) => 'k', chr(196).chr(185) => 'L',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   942
		chr(196).chr(186) => 'l', chr(196).chr(187) => 'L',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   943
		chr(196).chr(188) => 'l', chr(196).chr(189) => 'L',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   944
		chr(196).chr(190) => 'l', chr(196).chr(191) => 'L',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   945
		chr(197).chr(128) => 'l', chr(197).chr(129) => 'L',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   946
		chr(197).chr(130) => 'l', chr(197).chr(131) => 'N',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   947
		chr(197).chr(132) => 'n', chr(197).chr(133) => 'N',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   948
		chr(197).chr(134) => 'n', chr(197).chr(135) => 'N',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   949
		chr(197).chr(136) => 'n', chr(197).chr(137) => 'N',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   950
		chr(197).chr(138) => 'n', chr(197).chr(139) => 'N',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   951
		chr(197).chr(140) => 'O', chr(197).chr(141) => 'o',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   952
		chr(197).chr(142) => 'O', chr(197).chr(143) => 'o',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   953
		chr(197).chr(144) => 'O', chr(197).chr(145) => 'o',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   954
		chr(197).chr(146) => 'OE',chr(197).chr(147) => 'oe',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   955
		chr(197).chr(148) => 'R',chr(197).chr(149) => 'r',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   956
		chr(197).chr(150) => 'R',chr(197).chr(151) => 'r',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   957
		chr(197).chr(152) => 'R',chr(197).chr(153) => 'r',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   958
		chr(197).chr(154) => 'S',chr(197).chr(155) => 's',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   959
		chr(197).chr(156) => 'S',chr(197).chr(157) => 's',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   960
		chr(197).chr(158) => 'S',chr(197).chr(159) => 's',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   961
		chr(197).chr(160) => 'S', chr(197).chr(161) => 's',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   962
		chr(197).chr(162) => 'T', chr(197).chr(163) => 't',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   963
		chr(197).chr(164) => 'T', chr(197).chr(165) => 't',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   964
		chr(197).chr(166) => 'T', chr(197).chr(167) => 't',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   965
		chr(197).chr(168) => 'U', chr(197).chr(169) => 'u',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   966
		chr(197).chr(170) => 'U', chr(197).chr(171) => 'u',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   967
		chr(197).chr(172) => 'U', chr(197).chr(173) => 'u',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   968
		chr(197).chr(174) => 'U', chr(197).chr(175) => 'u',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   969
		chr(197).chr(176) => 'U', chr(197).chr(177) => 'u',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   970
		chr(197).chr(178) => 'U', chr(197).chr(179) => 'u',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   971
		chr(197).chr(180) => 'W', chr(197).chr(181) => 'w',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   972
		chr(197).chr(182) => 'Y', chr(197).chr(183) => 'y',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   973
		chr(197).chr(184) => 'Y', chr(197).chr(185) => 'Z',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   974
		chr(197).chr(186) => 'z', chr(197).chr(187) => 'Z',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   975
		chr(197).chr(188) => 'z', chr(197).chr(189) => 'Z',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   976
		chr(197).chr(190) => 'z', chr(197).chr(191) => 's',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   977
		// Decompositions for Latin Extended-B
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   978
		chr(200).chr(152) => 'S', chr(200).chr(153) => 's',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   979
		chr(200).chr(154) => 'T', chr(200).chr(155) => 't',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   980
		// Euro Sign
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   981
		chr(226).chr(130).chr(172) => 'E',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   982
		// GBP (Pound) Sign
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   983
		chr(194).chr(163) => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   984
		// Vowels with diacritic (Vietnamese)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   985
		// unmarked
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   986
		chr(198).chr(160) => 'O', chr(198).chr(161) => 'o',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   987
		chr(198).chr(175) => 'U', chr(198).chr(176) => 'u',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   988
		// grave accent
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   989
		chr(225).chr(186).chr(166) => 'A', chr(225).chr(186).chr(167) => 'a',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   990
		chr(225).chr(186).chr(176) => 'A', chr(225).chr(186).chr(177) => 'a',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   991
		chr(225).chr(187).chr(128) => 'E', chr(225).chr(187).chr(129) => 'e',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   992
		chr(225).chr(187).chr(146) => 'O', chr(225).chr(187).chr(147) => 'o',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   993
		chr(225).chr(187).chr(156) => 'O', chr(225).chr(187).chr(157) => 'o',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   994
		chr(225).chr(187).chr(170) => 'U', chr(225).chr(187).chr(171) => 'u',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   995
		chr(225).chr(187).chr(178) => 'Y', chr(225).chr(187).chr(179) => 'y',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   996
		// hook
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   997
		chr(225).chr(186).chr(162) => 'A', chr(225).chr(186).chr(163) => 'a',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   998
		chr(225).chr(186).chr(168) => 'A', chr(225).chr(186).chr(169) => 'a',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   999
		chr(225).chr(186).chr(178) => 'A', chr(225).chr(186).chr(179) => 'a',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1000
		chr(225).chr(186).chr(186) => 'E', chr(225).chr(186).chr(187) => 'e',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1001
		chr(225).chr(187).chr(130) => 'E', chr(225).chr(187).chr(131) => 'e',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1002
		chr(225).chr(187).chr(136) => 'I', chr(225).chr(187).chr(137) => 'i',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1003
		chr(225).chr(187).chr(142) => 'O', chr(225).chr(187).chr(143) => 'o',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1004
		chr(225).chr(187).chr(148) => 'O', chr(225).chr(187).chr(149) => 'o',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1005
		chr(225).chr(187).chr(158) => 'O', chr(225).chr(187).chr(159) => 'o',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1006
		chr(225).chr(187).chr(166) => 'U', chr(225).chr(187).chr(167) => 'u',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1007
		chr(225).chr(187).chr(172) => 'U', chr(225).chr(187).chr(173) => 'u',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1008
		chr(225).chr(187).chr(182) => 'Y', chr(225).chr(187).chr(183) => 'y',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1009
		// tilde
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1010
		chr(225).chr(186).chr(170) => 'A', chr(225).chr(186).chr(171) => 'a',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1011
		chr(225).chr(186).chr(180) => 'A', chr(225).chr(186).chr(181) => 'a',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1012
		chr(225).chr(186).chr(188) => 'E', chr(225).chr(186).chr(189) => 'e',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1013
		chr(225).chr(187).chr(132) => 'E', chr(225).chr(187).chr(133) => 'e',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1014
		chr(225).chr(187).chr(150) => 'O', chr(225).chr(187).chr(151) => 'o',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1015
		chr(225).chr(187).chr(160) => 'O', chr(225).chr(187).chr(161) => 'o',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1016
		chr(225).chr(187).chr(174) => 'U', chr(225).chr(187).chr(175) => 'u',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1017
		chr(225).chr(187).chr(184) => 'Y', chr(225).chr(187).chr(185) => 'y',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1018
		// acute accent
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1019
		chr(225).chr(186).chr(164) => 'A', chr(225).chr(186).chr(165) => 'a',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1020
		chr(225).chr(186).chr(174) => 'A', chr(225).chr(186).chr(175) => 'a',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1021
		chr(225).chr(186).chr(190) => 'E', chr(225).chr(186).chr(191) => 'e',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1022
		chr(225).chr(187).chr(144) => 'O', chr(225).chr(187).chr(145) => 'o',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1023
		chr(225).chr(187).chr(154) => 'O', chr(225).chr(187).chr(155) => 'o',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1024
		chr(225).chr(187).chr(168) => 'U', chr(225).chr(187).chr(169) => 'u',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1025
		// dot below
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1026
		chr(225).chr(186).chr(160) => 'A', chr(225).chr(186).chr(161) => 'a',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1027
		chr(225).chr(186).chr(172) => 'A', chr(225).chr(186).chr(173) => 'a',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1028
		chr(225).chr(186).chr(182) => 'A', chr(225).chr(186).chr(183) => 'a',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1029
		chr(225).chr(186).chr(184) => 'E', chr(225).chr(186).chr(185) => 'e',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1030
		chr(225).chr(187).chr(134) => 'E', chr(225).chr(187).chr(135) => 'e',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1031
		chr(225).chr(187).chr(138) => 'I', chr(225).chr(187).chr(139) => 'i',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1032
		chr(225).chr(187).chr(140) => 'O', chr(225).chr(187).chr(141) => 'o',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1033
		chr(225).chr(187).chr(152) => 'O', chr(225).chr(187).chr(153) => 'o',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1034
		chr(225).chr(187).chr(162) => 'O', chr(225).chr(187).chr(163) => 'o',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1035
		chr(225).chr(187).chr(164) => 'U', chr(225).chr(187).chr(165) => 'u',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1036
		chr(225).chr(187).chr(176) => 'U', chr(225).chr(187).chr(177) => 'u',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1037
		chr(225).chr(187).chr(180) => 'Y', chr(225).chr(187).chr(181) => 'y',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1038
		// Vowels with diacritic (Chinese, Hanyu Pinyin)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1039
		chr(201).chr(145) => 'a',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1040
		// macron
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1041
		chr(199).chr(149) => 'U', chr(199).chr(150) => 'u',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1042
		// acute accent
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1043
		chr(199).chr(151) => 'U', chr(199).chr(152) => 'u',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1044
		// caron
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1045
		chr(199).chr(141) => 'A', chr(199).chr(142) => 'a',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1046
		chr(199).chr(143) => 'I', chr(199).chr(144) => 'i',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1047
		chr(199).chr(145) => 'O', chr(199).chr(146) => 'o',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1048
		chr(199).chr(147) => 'U', chr(199).chr(148) => 'u',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1049
		chr(199).chr(153) => 'U', chr(199).chr(154) => 'u',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1050
		// grave accent
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1051
		chr(199).chr(155) => 'U', chr(199).chr(156) => 'u',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1052
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1053
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1054
		// Used for locale-specific rules
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1055
		$locale = get_locale();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1056
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1057
		if ( 'de_DE' == $locale ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1058
			$chars[ chr(195).chr(132) ] = 'Ae';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1059
			$chars[ chr(195).chr(164) ] = 'ae';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1060
			$chars[ chr(195).chr(150) ] = 'Oe';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1061
			$chars[ chr(195).chr(182) ] = 'oe';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1062
			$chars[ chr(195).chr(156) ] = 'Ue';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1063
			$chars[ chr(195).chr(188) ] = 'ue';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1064
			$chars[ chr(195).chr(159) ] = 'ss';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1065
		} elseif ( 'da_DK' === $locale ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1066
			$chars[ chr(195).chr(134) ] = 'Ae';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1067
 			$chars[ chr(195).chr(166) ] = 'ae';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1068
			$chars[ chr(195).chr(152) ] = 'Oe';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1069
			$chars[ chr(195).chr(184) ] = 'oe';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1070
			$chars[ chr(195).chr(133) ] = 'Aa';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1071
			$chars[ chr(195).chr(165) ] = 'aa';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1072
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1073
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1074
		$string = strtr($string, $chars);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1075
	} else {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1076
		$chars = array();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1077
		// Assume ISO-8859-1 if not UTF-8
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1078
		$chars['in'] = chr(128).chr(131).chr(138).chr(142).chr(154).chr(158)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1079
			.chr(159).chr(162).chr(165).chr(181).chr(192).chr(193).chr(194)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1080
			.chr(195).chr(196).chr(197).chr(199).chr(200).chr(201).chr(202)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1081
			.chr(203).chr(204).chr(205).chr(206).chr(207).chr(209).chr(210)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1082
			.chr(211).chr(212).chr(213).chr(214).chr(216).chr(217).chr(218)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1083
			.chr(219).chr(220).chr(221).chr(224).chr(225).chr(226).chr(227)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1084
			.chr(228).chr(229).chr(231).chr(232).chr(233).chr(234).chr(235)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1085
			.chr(236).chr(237).chr(238).chr(239).chr(241).chr(242).chr(243)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1086
			.chr(244).chr(245).chr(246).chr(248).chr(249).chr(250).chr(251)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1087
			.chr(252).chr(253).chr(255);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1088
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1089
		$chars['out'] = "EfSZszYcYuAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1090
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1091
		$string = strtr($string, $chars['in'], $chars['out']);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1092
		$double_chars = array();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1093
		$double_chars['in'] = array(chr(140), chr(156), chr(198), chr(208), chr(222), chr(223), chr(230), chr(240), chr(254));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1094
		$double_chars['out'] = array('OE', 'oe', 'AE', 'DH', 'TH', 'ss', 'ae', 'dh', 'th');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1095
		$string = str_replace($double_chars['in'], $double_chars['out'], $string);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1096
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1097
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1098
	return $string;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1099
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1100
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1101
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1102
 * Sanitizes a filename, replacing whitespace with dashes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1103
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1104
 * Removes special characters that are illegal in filenames on certain
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1105
 * operating systems and special characters requiring special escaping
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1106
 * to manipulate at the command line. Replaces spaces and consecutive
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1107
 * dashes with a single dash. Trims period, dash and underscore from beginning
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1108
 * and end of filename.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1109
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1110
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1111
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1112
 * @param string $filename The filename to be sanitized
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1113
 * @return string The sanitized filename
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1114
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1115
function sanitize_file_name( $filename ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1116
	$filename_raw = $filename;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1117
	$special_chars = array("?", "[", "]", "/", "\\", "=", "<", ">", ":", ";", ",", "'", "\"", "&", "$", "#", "*", "(", ")", "|", "~", "`", "!", "{", "}", chr(0));
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1118
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1119
	 * Filter the list of characters to remove from a filename.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1120
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1121
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1122
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1123
	 * @param array  $special_chars Characters to remove.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1124
	 * @param string $filename_raw  Filename as it was passed into sanitize_file_name().
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1125
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1126
	$special_chars = apply_filters( 'sanitize_file_name_chars', $special_chars, $filename_raw );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1127
	$filename = preg_replace( "#\x{00a0}#siu", ' ', $filename );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1128
	$filename = str_replace( $special_chars, '', $filename );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1129
	$filename = str_replace( array( '%20', '+' ), '-', $filename );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1130
	$filename = preg_replace( '/[\r\n\t -]+/', '-', $filename );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1131
	$filename = trim( $filename, '.-_' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1132
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1133
	// Split the filename into a base and extension[s]
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1134
	$parts = explode('.', $filename);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1135
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1136
	// Return if only one extension
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1137
	if ( count( $parts ) <= 2 ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1138
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1139
		 * Filter a sanitized filename string.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1140
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1141
		 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1142
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1143
		 * @param string $filename     Sanitized filename.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1144
		 * @param string $filename_raw The filename prior to sanitization.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1145
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1146
		return apply_filters( 'sanitize_file_name', $filename, $filename_raw );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1147
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1148
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1149
	// Process multiple extensions
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1150
	$filename = array_shift($parts);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1151
	$extension = array_pop($parts);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1152
	$mimes = get_allowed_mime_types();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1153
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1154
	/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1155
	 * Loop over any intermediate extensions. Postfix them with a trailing underscore
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1156
	 * if they are a 2 - 5 character long alpha string not in the extension whitelist.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1157
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1158
	foreach ( (array) $parts as $part) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1159
		$filename .= '.' . $part;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1160
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1161
		if ( preg_match("/^[a-zA-Z]{2,5}\d?$/", $part) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1162
			$allowed = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1163
			foreach ( $mimes as $ext_preg => $mime_match ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1164
				$ext_preg = '!^(' . $ext_preg . ')$!i';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1165
				if ( preg_match( $ext_preg, $part ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1166
					$allowed = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1167
					break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1168
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1169
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1170
			if ( !$allowed )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1171
				$filename .= '_';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1172
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1173
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1174
	$filename .= '.' . $extension;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1175
	/** This filter is documented in wp-includes/formatting.php */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1176
	return apply_filters('sanitize_file_name', $filename, $filename_raw);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1177
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1178
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1179
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1180
 * Sanitizes a username, stripping out unsafe characters.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1181
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1182
 * Removes tags, octets, entities, and if strict is enabled, will only keep
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1183
 * alphanumeric, _, space, ., -, @. After sanitizing, it passes the username,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1184
 * raw username (the username in the parameter), and the value of $strict as
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1185
 * parameters for the 'sanitize_user' filter.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1186
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1187
 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1188
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1189
 * @param string $username The username to be sanitized.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1190
 * @param bool $strict If set limits $username to specific characters. Default false.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1191
 * @return string The sanitized username, after passing through filters.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1192
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1193
function sanitize_user( $username, $strict = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1194
	$raw_username = $username;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1195
	$username = wp_strip_all_tags( $username );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1196
	$username = remove_accents( $username );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1197
	// Kill octets
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1198
	$username = preg_replace( '|%([a-fA-F0-9][a-fA-F0-9])|', '', $username );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1199
	$username = preg_replace( '/&.+?;/', '', $username ); // Kill entities
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1200
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1201
	// If strict, reduce to ASCII for max portability.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1202
	if ( $strict )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1203
		$username = preg_replace( '|[^a-z0-9 _.\-@]|i', '', $username );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1204
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1205
	$username = trim( $username );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1206
	// Consolidate contiguous whitespace
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1207
	$username = preg_replace( '|\s+|', ' ', $username );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1208
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1209
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1210
	 * Filter a sanitized username string.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1211
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1212
	 * @since 2.0.1
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1213
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1214
	 * @param string $username     Sanitized username.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1215
	 * @param string $raw_username The username prior to sanitization.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1216
	 * @param bool   $strict       Whether to limit the sanitization to specific characters. Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1217
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1218
	return apply_filters( 'sanitize_user', $username, $raw_username, $strict );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1219
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1220
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1221
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1222
 * Sanitizes a string key.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1223
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1224
 * Keys are used as internal identifiers. Lowercase alphanumeric characters, dashes and underscores are allowed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1225
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1226
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1227
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1228
 * @param string $key String key
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1229
 * @return string Sanitized key
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1230
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1231
function sanitize_key( $key ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1232
	$raw_key = $key;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1233
	$key = strtolower( $key );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1234
	$key = preg_replace( '/[^a-z0-9_\-]/', '', $key );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1235
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1236
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1237
	 * Filter a sanitized key string.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1238
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1239
	 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1240
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1241
	 * @param string $key     Sanitized key.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1242
	 * @param string $raw_key The key prior to sanitization.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1243
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1244
	return apply_filters( 'sanitize_key', $key, $raw_key );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1245
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1246
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1247
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1248
 * Sanitizes a title, or returns a fallback title.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1249
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1250
 * Specifically, HTML and PHP tags are stripped. Further actions can be added
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1251
 * via the plugin API. If $title is empty and $fallback_title is set, the latter
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1252
 * will be used.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1253
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1254
 * @since 1.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1255
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1256
 * @param string $title The string to be sanitized.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1257
 * @param string $fallback_title Optional. A title to use if $title is empty.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1258
 * @param string $context Optional. The operation for which the string is sanitized
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1259
 * @return string The sanitized string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1260
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1261
function sanitize_title( $title, $fallback_title = '', $context = 'save' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1262
	$raw_title = $title;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1263
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1264
	if ( 'save' == $context )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1265
		$title = remove_accents($title);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1266
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1267
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1268
	 * Filter a sanitized title string.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1269
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1270
	 * @since 1.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1271
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1272
	 * @param string $title     Sanitized title.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1273
	 * @param string $raw_title The title prior to sanitization.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1274
	 * @param string $context   The context for which the title is being sanitized.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1275
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1276
	$title = apply_filters( 'sanitize_title', $title, $raw_title, $context );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1277
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1278
	if ( '' === $title || false === $title )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1279
		$title = $fallback_title;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1280
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1281
	return $title;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1282
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1283
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1284
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1285
 * Sanitizes a title with the 'query' context.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1286
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1287
 * Used for querying the database for a value from URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1288
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1289
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1290
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1291
 * @param string $title The string to be sanitized.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1292
 * @return string The sanitized string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1293
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1294
function sanitize_title_for_query( $title ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1295
	return sanitize_title( $title, '', 'query' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1296
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1297
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1298
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1299
 * Sanitizes a title, replacing whitespace and a few other characters with dashes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1300
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1301
 * Limits the output to alphanumeric characters, underscore (_) and dash (-).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1302
 * Whitespace becomes a dash.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1303
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1304
 * @since 1.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1305
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1306
 * @param string $title The title to be sanitized.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1307
 * @param string $raw_title Optional. Not used.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1308
 * @param string $context Optional. The operation for which the string is sanitized.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1309
 * @return string The sanitized title.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1310
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1311
function sanitize_title_with_dashes( $title, $raw_title = '', $context = 'display' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1312
	$title = strip_tags($title);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1313
	// Preserve escaped octets.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1314
	$title = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $title);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1315
	// Remove percent signs that are not part of an octet.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1316
	$title = str_replace('%', '', $title);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1317
	// Restore octets.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1318
	$title = preg_replace('|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $title);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1319
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1320
	if (seems_utf8($title)) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1321
		if (function_exists('mb_strtolower')) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1322
			$title = mb_strtolower($title, 'UTF-8');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1323
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1324
		$title = utf8_uri_encode($title, 200);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1325
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1326
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1327
	$title = strtolower($title);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1328
	$title = preg_replace('/&.+?;/', '', $title); // kill entities
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1329
	$title = str_replace('.', '-', $title);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1330
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1331
	if ( 'save' == $context ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1332
		// Convert nbsp, ndash and mdash to hyphens
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1333
		$title = str_replace( array( '%c2%a0', '%e2%80%93', '%e2%80%94' ), '-', $title );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1334
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1335
		// Strip these characters entirely
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1336
		$title = str_replace( array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1337
			// iexcl and iquest
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1338
			'%c2%a1', '%c2%bf',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1339
			// angle quotes
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1340
			'%c2%ab', '%c2%bb', '%e2%80%b9', '%e2%80%ba',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1341
			// curly quotes
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1342
			'%e2%80%98', '%e2%80%99', '%e2%80%9c', '%e2%80%9d',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1343
			'%e2%80%9a', '%e2%80%9b', '%e2%80%9e', '%e2%80%9f',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1344
			// copy, reg, deg, hellip and trade
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1345
			'%c2%a9', '%c2%ae', '%c2%b0', '%e2%80%a6', '%e2%84%a2',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1346
			// acute accents
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1347
			'%c2%b4', '%cb%8a', '%cc%81', '%cd%81',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1348
			// grave accent, macron, caron
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1349
			'%cc%80', '%cc%84', '%cc%8c',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1350
		), '', $title );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1351
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1352
		// Convert times to x
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1353
		$title = str_replace( '%c3%97', 'x', $title );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1354
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1355
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1356
	$title = preg_replace('/[^%a-z0-9 _-]/', '', $title);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1357
	$title = preg_replace('/\s+/', '-', $title);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1358
	$title = preg_replace('|-+|', '-', $title);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1359
	$title = trim($title, '-');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1360
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1361
	return $title;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1362
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1363
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1364
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1365
 * Ensures a string is a valid SQL 'order by' clause.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1366
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1367
 * Accepts one or more columns, with or without a sort order (ASC / DESC).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1368
 * e.g. 'column_1', 'column_1, column_2', 'column_1 ASC, column_2 DESC' etc.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1369
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1370
 * Also accepts 'RAND()'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1371
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1372
 * @since 2.5.1
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1373
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1374
 * @param string $orderby Order by clause to be validated.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1375
 * @return string|bool Returns $orderby if valid, false otherwise.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1376
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1377
function sanitize_sql_orderby( $orderby ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1378
	if ( preg_match( '/^\s*(([a-z0-9_]+|`[a-z0-9_]+`)(\s+(ASC|DESC))?\s*(,\s*(?=[a-z0-9_`])|$))+$/i', $orderby ) || preg_match( '/^\s*RAND\(\s*\)\s*$/i', $orderby ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1379
		return $orderby;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1380
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1381
	return false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1382
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1383
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1384
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1385
 * Sanitizes an HTML classname to ensure it only contains valid characters.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1386
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1387
 * Strips the string down to A-Z,a-z,0-9,_,-. If this results in an empty
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1388
 * string then it will return the alternative value supplied.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1389
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1390
 * @todo Expand to support the full range of CDATA that a class attribute can contain.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1391
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1392
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1393
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1394
 * @param string $class The classname to be sanitized
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1395
 * @param string $fallback Optional. The value to return if the sanitization ends up as an empty string.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1396
 * 	Defaults to an empty string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1397
 * @return string The sanitized value
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1398
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1399
function sanitize_html_class( $class, $fallback = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1400
	//Strip out any % encoded octets
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1401
	$sanitized = preg_replace( '|%[a-fA-F0-9][a-fA-F0-9]|', '', $class );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1402
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1403
	//Limit to A-Z,a-z,0-9,_,-
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1404
	$sanitized = preg_replace( '/[^A-Za-z0-9_-]/', '', $sanitized );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1405
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1406
	if ( '' == $sanitized )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1407
		$sanitized = $fallback;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1408
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1409
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1410
	 * Filter a sanitized HTML class string.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1411
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1412
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1413
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1414
	 * @param string $sanitized The sanitized HTML class.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1415
	 * @param string $class     HTML class before sanitization.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1416
	 * @param string $fallback  The fallback string.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1417
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1418
	return apply_filters( 'sanitize_html_class', $sanitized, $class, $fallback );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1419
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1420
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1421
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1422
 * Converts a number of characters from a string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1423
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1424
 * Metadata tags `<title>` and `<category>` are removed, `<br>` and `<hr>` are
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1425
 * converted into correct XHTML and Unicode characters are converted to the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1426
 * valid range.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1427
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1428
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1429
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1430
 * @param string $content String of characters to be converted.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1431
 * @param string $deprecated Not used.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1432
 * @return string Converted string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1433
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1434
function convert_chars($content, $deprecated = '') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1435
	if ( !empty( $deprecated ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1436
		_deprecated_argument( __FUNCTION__, '0.71' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1437
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1438
	// Translation of invalid Unicode references range to valid range
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1439
	$wp_htmltranswinuni = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1440
	'&#128;' => '&#8364;', // the Euro sign
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1441
	'&#129;' => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1442
	'&#130;' => '&#8218;', // these are Windows CP1252 specific characters
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1443
	'&#131;' => '&#402;',  // they would look weird on non-Windows browsers
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1444
	'&#132;' => '&#8222;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1445
	'&#133;' => '&#8230;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1446
	'&#134;' => '&#8224;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1447
	'&#135;' => '&#8225;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1448
	'&#136;' => '&#710;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1449
	'&#137;' => '&#8240;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1450
	'&#138;' => '&#352;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1451
	'&#139;' => '&#8249;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1452
	'&#140;' => '&#338;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1453
	'&#141;' => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1454
	'&#142;' => '&#381;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1455
	'&#143;' => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1456
	'&#144;' => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1457
	'&#145;' => '&#8216;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1458
	'&#146;' => '&#8217;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1459
	'&#147;' => '&#8220;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1460
	'&#148;' => '&#8221;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1461
	'&#149;' => '&#8226;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1462
	'&#150;' => '&#8211;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1463
	'&#151;' => '&#8212;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1464
	'&#152;' => '&#732;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1465
	'&#153;' => '&#8482;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1466
	'&#154;' => '&#353;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1467
	'&#155;' => '&#8250;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1468
	'&#156;' => '&#339;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1469
	'&#157;' => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1470
	'&#158;' => '&#382;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1471
	'&#159;' => '&#376;'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1472
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1473
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1474
	// Remove metadata tags
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1475
	$content = preg_replace('/<title>(.+?)<\/title>/','',$content);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1476
	$content = preg_replace('/<category>(.+?)<\/category>/','',$content);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1477
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1478
	// Converts lone & characters into &#38; (a.k.a. &amp;)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1479
	$content = preg_replace('/&([^#])(?![a-z1-4]{1,8};)/i', '&#038;$1', $content);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1480
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1481
	// Fix Word pasting
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1482
	$content = strtr($content, $wp_htmltranswinuni);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1483
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1484
	// Just a little XHTML help
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1485
	$content = str_replace('<br>', '<br />', $content);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1486
	$content = str_replace('<hr>', '<hr />', $content);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1487
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1488
	return $content;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1489
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1490
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1491
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1492
 * Balances tags if forced to, or if the 'use_balanceTags' option is set to true.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1493
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1494
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1495
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1496
 * @param string $text Text to be balanced
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1497
 * @param bool $force If true, forces balancing, ignoring the value of the option. Default false.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1498
 * @return string Balanced text
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1499
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1500
function balanceTags( $text, $force = false ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1501
	if ( $force || get_option('use_balanceTags') == 1 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1502
		return force_balance_tags( $text );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1503
	} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1504
		return $text;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1505
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1506
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1507
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1508
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1509
 * Balances tags of string using a modified stack.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1510
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1511
 * @since 2.0.4
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1512
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1513
 * @author Leonard Lin <leonard@acm.org>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1514
 * @license GPL
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1515
 * @copyright November 4, 2001
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1516
 * @version 1.1
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1517
 * @todo Make better - change loop condition to $text in 1.2
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1518
 * @internal Modified by Scott Reilly (coffee2code) 02 Aug 2004
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1519
 *		1.1  Fixed handling of append/stack pop order of end text
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1520
 *			 Added Cleaning Hooks
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1521
 *		1.0  First Version
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1522
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1523
 * @param string $text Text to be balanced.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1524
 * @return string Balanced text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1525
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1526
function force_balance_tags( $text ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1527
	$tagstack = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1528
	$stacksize = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1529
	$tagqueue = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1530
	$newtext = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1531
	// Known single-entity/self-closing tags
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1532
	$single_tags = array( 'area', 'base', 'basefont', 'br', 'col', 'command', 'embed', 'frame', 'hr', 'img', 'input', 'isindex', 'link', 'meta', 'param', 'source' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1533
	// Tags that can be immediately nested within themselves
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1534
	$nestable_tags = array( 'blockquote', 'div', 'object', 'q', 'span' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1535
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1536
	// WP bug fix for comments - in case you REALLY meant to type '< !--'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1537
	$text = str_replace('< !--', '<    !--', $text);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1538
	// WP bug fix for LOVE <3 (and other situations with '<' before a number)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1539
	$text = preg_replace('#<([0-9]{1})#', '&lt;$1', $text);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1540
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1541
	while ( preg_match("/<(\/?[\w:]*)\s*([^>]*)>/", $text, $regex) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1542
		$newtext .= $tagqueue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1543
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1544
		$i = strpos($text, $regex[0]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1545
		$l = strlen($regex[0]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1546
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1547
		// clear the shifter
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1548
		$tagqueue = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1549
		// Pop or Push
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1550
		if ( isset($regex[1][0]) && '/' == $regex[1][0] ) { // End Tag
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1551
			$tag = strtolower(substr($regex[1],1));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1552
			// if too many closing tags
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1553
			if( $stacksize <= 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1554
				$tag = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1555
				// or close to be safe $tag = '/' . $tag;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1556
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1557
			// if stacktop value = tag close value then pop
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1558
			elseif ( $tagstack[$stacksize - 1] == $tag ) { // found closing tag
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1559
				$tag = '</' . $tag . '>'; // Close Tag
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1560
				// Pop
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1561
				array_pop( $tagstack );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1562
				$stacksize--;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1563
			} else { // closing tag not at top, search for it
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1564
				for ( $j = $stacksize-1; $j >= 0; $j-- ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1565
					if ( $tagstack[$j] == $tag ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1566
					// add tag to tagqueue
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1567
						for ( $k = $stacksize-1; $k >= $j; $k--) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1568
							$tagqueue .= '</' . array_pop( $tagstack ) . '>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1569
							$stacksize--;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1570
						}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1571
						break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1572
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1573
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1574
				$tag = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1575
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1576
		} else { // Begin Tag
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1577
			$tag = strtolower($regex[1]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1578
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1579
			// Tag Cleaning
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1580
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1581
			// If it's an empty tag "< >", do nothing
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1582
			if ( '' == $tag ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1583
				// do nothing
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1584
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1585
			// ElseIf it presents itself as a self-closing tag...
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1586
			elseif ( substr( $regex[2], -1 ) == '/' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1587
				// ...but it isn't a known single-entity self-closing tag, then don't let it be treated as such and
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1588
				// immediately close it with a closing tag (the tag will encapsulate no text as a result)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1589
				if ( ! in_array( $tag, $single_tags ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1590
					$regex[2] = trim( substr( $regex[2], 0, -1 ) ) . "></$tag";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1591
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1592
			// ElseIf it's a known single-entity tag but it doesn't close itself, do so
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1593
			elseif ( in_array($tag, $single_tags) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1594
				$regex[2] .= '/';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1595
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1596
			// Else it's not a single-entity tag
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1597
			else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1598
				// If the top of the stack is the same as the tag we want to push, close previous tag
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1599
				if ( $stacksize > 0 && !in_array($tag, $nestable_tags) && $tagstack[$stacksize - 1] == $tag ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1600
					$tagqueue = '</' . array_pop( $tagstack ) . '>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1601
					$stacksize--;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1602
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1603
				$stacksize = array_push( $tagstack, $tag );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1604
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1605
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1606
			// Attributes
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1607
			$attributes = $regex[2];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1608
			if( ! empty( $attributes ) && $attributes[0] != '>' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1609
				$attributes = ' ' . $attributes;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1610
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1611
			$tag = '<' . $tag . $attributes . '>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1612
			//If already queuing a close tag, then put this tag on, too
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1613
			if ( !empty($tagqueue) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1614
				$tagqueue .= $tag;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1615
				$tag = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1616
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1617
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1618
		$newtext .= substr($text, 0, $i) . $tag;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1619
		$text = substr($text, $i + $l);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1620
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1621
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1622
	// Clear Tag Queue
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1623
	$newtext .= $tagqueue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1624
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1625
	// Add Remaining text
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1626
	$newtext .= $text;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1627
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1628
	// Empty Stack
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1629
	while( $x = array_pop($tagstack) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1630
		$newtext .= '</' . $x . '>'; // Add remaining tags to close
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1631
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1632
	// WP fix for the bug with HTML comments
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1633
	$newtext = str_replace("< !--","<!--",$newtext);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1634
	$newtext = str_replace("<    !--","< !--",$newtext);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1635
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1636
	return $newtext;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1637
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1638
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1639
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1640
 * Acts on text which is about to be edited.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1641
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1642
 * The $content is run through esc_textarea(), which uses htmlspecialchars()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1643
 * to convert special characters to HTML entities. If $richedit is set to true,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1644
 * it is simply a holder for the 'format_to_edit' filter.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1645
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1646
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1647
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1648
 * @param string $content The text about to be edited.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1649
 * @param bool $richedit Whether the $content should not pass through htmlspecialchars(). Default false (meaning it will be passed).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1650
 * @return string The text after the filter (and possibly htmlspecialchars()) has been run.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1651
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1652
function format_to_edit( $content, $richedit = false ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1653
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1654
	 * Filter the text to be formatted for editing.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1655
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1656
	 * @since 1.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1657
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1658
	 * @param string $content The text, prior to formatting for editing.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1659
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1660
	$content = apply_filters( 'format_to_edit', $content );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1661
	if ( ! $richedit )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1662
		$content = esc_textarea( $content );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1663
	return $content;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1664
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1665
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1666
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1667
 * Add leading zeros when necessary.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1668
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1669
 * If you set the threshold to '4' and the number is '10', then you will get
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1670
 * back '0010'. If you set the threshold to '4' and the number is '5000', then you
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1671
 * will get back '5000'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1672
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1673
 * Uses sprintf to append the amount of zeros based on the $threshold parameter
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1674
 * and the size of the number. If the number is large enough, then no zeros will
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1675
 * be appended.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1676
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1677
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1678
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1679
 * @param mixed $number Number to append zeros to if not greater than threshold.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1680
 * @param int $threshold Digit places number needs to be to not have zeros added.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1681
 * @return string Adds leading zeros to number if needed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1682
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1683
function zeroise($number, $threshold) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1684
	return sprintf('%0'.$threshold.'s', $number);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1685
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1686
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1687
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1688
 * Adds backslashes before letters and before a number at the start of a string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1689
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1690
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1691
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1692
 * @param string $string Value to which backslashes will be added.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1693
 * @return string String with backslashes inserted.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1694
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1695
function backslashit($string) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1696
	if ( isset( $string[0] ) && $string[0] >= '0' && $string[0] <= '9' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1697
		$string = '\\\\' . $string;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1698
	return addcslashes( $string, 'A..Za..z' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1699
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1700
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1701
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1702
 * Appends a trailing slash.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1703
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1704
 * Will remove trailing forward and backslashes if it exists already before adding
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1705
 * a trailing forward slash. This prevents double slashing a string or path.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1706
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1707
 * The primary use of this is for paths and thus should be used for paths. It is
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1708
 * not restricted to paths and offers no specific path support.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1709
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1710
 * @since 1.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1711
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1712
 * @param string $string What to add the trailing slash to.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1713
 * @return string String with trailing slash added.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1714
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1715
function trailingslashit( $string ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1716
	return untrailingslashit( $string ) . '/';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1717
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1718
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1719
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1720
 * Removes trailing forward slashes and backslashes if they exist.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1721
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1722
 * The primary use of this is for paths and thus should be used for paths. It is
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1723
 * not restricted to paths and offers no specific path support.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1724
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1725
 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1726
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1727
 * @param string $string What to remove the trailing slashes from.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1728
 * @return string String without the trailing slashes.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1729
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1730
function untrailingslashit( $string ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1731
	return rtrim( $string, '/\\' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1732
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1733
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1734
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1735
 * Adds slashes to escape strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1736
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1737
 * Slashes will first be removed if magic_quotes_gpc is set, see {@link
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1738
 * http://www.php.net/magic_quotes} for more details.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1739
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1740
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1741
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1742
 * @param string $gpc The string returned from HTTP request data.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1743
 * @return string Returns a string escaped with slashes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1744
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1745
function addslashes_gpc($gpc) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1746
	if ( get_magic_quotes_gpc() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1747
		$gpc = stripslashes($gpc);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1748
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1749
	return wp_slash($gpc);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1750
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1751
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1752
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1753
 * Navigates through an array and removes slashes from the values.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1754
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1755
 * If an array is passed, the array_map() function causes a callback to pass the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1756
 * value back to the function. The slashes from this value will removed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1757
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1758
 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1759
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1760
 * @param mixed $value The value to be stripped.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1761
 * @return mixed Stripped value.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1762
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1763
function stripslashes_deep($value) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1764
	if ( is_array($value) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1765
		$value = array_map('stripslashes_deep', $value);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1766
	} elseif ( is_object($value) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1767
		$vars = get_object_vars( $value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1768
		foreach ($vars as $key=>$data) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1769
			$value->{$key} = stripslashes_deep( $data );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1770
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1771
	} elseif ( is_string( $value ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1772
		$value = stripslashes($value);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1773
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1774
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1775
	return $value;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1776
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1777
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1778
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1779
 * Navigates through an array and encodes the values to be used in a URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1780
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1781
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1782
 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1783
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1784
 * @param array|string $value The array or string to be encoded.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1785
 * @return array|string $value The encoded array (or string from the callback).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1786
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1787
function urlencode_deep($value) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1788
	$value = is_array($value) ? array_map('urlencode_deep', $value) : urlencode($value);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1789
	return $value;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1790
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1791
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1792
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1793
 * Navigates through an array and raw encodes the values to be used in a URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1794
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1795
 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1796
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1797
 * @param array|string $value The array or string to be encoded.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1798
 * @return array|string $value The encoded array (or string from the callback).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1799
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1800
function rawurlencode_deep( $value ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1801
	return is_array( $value ) ? array_map( 'rawurlencode_deep', $value ) : rawurlencode( $value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1802
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1803
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1804
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1805
 * Converts email addresses characters to HTML entities to block spam bots.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1806
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1807
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1808
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1809
 * @param string $email_address Email address.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1810
 * @param int $hex_encoding Optional. Set to 1 to enable hex encoding.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1811
 * @return string Converted email address.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1812
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1813
function antispambot( $email_address, $hex_encoding = 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1814
	$email_no_spam_address = '';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1815
	for ( $i = 0, $len = strlen( $email_address ); $i < $len; $i++ ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1816
		$j = rand( 0, 1 + $hex_encoding );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1817
		if ( $j == 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1818
			$email_no_spam_address .= '&#' . ord( $email_address[$i] ) . ';';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1819
		} elseif ( $j == 1 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1820
			$email_no_spam_address .= $email_address[$i];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1821
		} elseif ( $j == 2 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1822
			$email_no_spam_address .= '%' . zeroise( dechex( ord( $email_address[$i] ) ), 2 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1823
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1824
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1825
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1826
	$email_no_spam_address = str_replace( '@', '&#64;', $email_no_spam_address );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1827
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1828
	return $email_no_spam_address;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1829
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1830
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1831
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1832
 * Callback to convert URI match to HTML A element.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1833
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1834
 * This function was backported from 2.5.0 to 2.3.2. Regex callback for {@link
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1835
 * make_clickable()}.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1836
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1837
 * @since 2.3.2
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1838
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1839
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1840
 * @param array $matches Single Regex Match.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1841
 * @return string HTML A element with URI address.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1842
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1843
function _make_url_clickable_cb($matches) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1844
	$url = $matches[2];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1845
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1846
	if ( ')' == $matches[3] && strpos( $url, '(' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1847
		// If the trailing character is a closing parethesis, and the URL has an opening parenthesis in it, add the closing parenthesis to the URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1848
		// Then we can let the parenthesis balancer do its thing below.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1849
		$url .= $matches[3];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1850
		$suffix = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1851
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1852
		$suffix = $matches[3];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1853
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1854
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1855
	// Include parentheses in the URL only if paired
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1856
	while ( substr_count( $url, '(' ) < substr_count( $url, ')' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1857
		$suffix = strrchr( $url, ')' ) . $suffix;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1858
		$url = substr( $url, 0, strrpos( $url, ')' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1859
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1860
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1861
	$url = esc_url($url);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1862
	if ( empty($url) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1863
		return $matches[0];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1864
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1865
	return $matches[1] . "<a href=\"$url\" rel=\"nofollow\">$url</a>" . $suffix;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1866
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1867
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1868
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1869
 * Callback to convert URL match to HTML A element.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1870
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1871
 * This function was backported from 2.5.0 to 2.3.2. Regex callback for {@link
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1872
 * make_clickable()}.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1873
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1874
 * @since 2.3.2
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1875
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1876
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1877
 * @param array $matches Single Regex Match.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1878
 * @return string HTML A element with URL address.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1879
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1880
function _make_web_ftp_clickable_cb($matches) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1881
	$ret = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1882
	$dest = $matches[2];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1883
	$dest = 'http://' . $dest;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1884
	$dest = esc_url($dest);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1885
	if ( empty($dest) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1886
		return $matches[0];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1887
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1888
	// removed trailing [.,;:)] from URL
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1889
	if ( in_array( substr($dest, -1), array('.', ',', ';', ':', ')') ) === true ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1890
		$ret = substr($dest, -1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1891
		$dest = substr($dest, 0, strlen($dest)-1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1892
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1893
	return $matches[1] . "<a href=\"$dest\" rel=\"nofollow\">$dest</a>$ret";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1894
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1895
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1896
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1897
 * Callback to convert email address match to HTML A element.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1898
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1899
 * This function was backported from 2.5.0 to 2.3.2. Regex callback for {@link
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1900
 * make_clickable()}.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1901
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1902
 * @since 2.3.2
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1903
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1904
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1905
 * @param array $matches Single Regex Match.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1906
 * @return string HTML A element with email address.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1907
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1908
function _make_email_clickable_cb($matches) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1909
	$email = $matches[2] . '@' . $matches[3];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1910
	return $matches[1] . "<a href=\"mailto:$email\">$email</a>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1911
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1912
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1913
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1914
 * Convert plaintext URI to HTML links.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1915
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1916
 * Converts URI, www and ftp, and email addresses. Finishes by fixing links
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1917
 * within links.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1918
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1919
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1920
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1921
 * @param string $text Content to convert URIs.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1922
 * @return string Content with converted URIs.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1923
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1924
function make_clickable( $text ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1925
	$r = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1926
	$textarr = preg_split( '/(<[^<>]+>)/', $text, -1, PREG_SPLIT_DELIM_CAPTURE ); // split out HTML tags
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1927
	$nested_code_pre = 0; // Keep track of how many levels link is nested inside <pre> or <code>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1928
	foreach ( $textarr as $piece ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1929
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1930
		if ( preg_match( '|^<code[\s>]|i', $piece ) || preg_match( '|^<pre[\s>]|i', $piece ) )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1931
			$nested_code_pre++;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1932
		elseif ( ( '</code>' === strtolower( $piece ) || '</pre>' === strtolower( $piece ) ) && $nested_code_pre )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1933
			$nested_code_pre--;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1934
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1935
		if ( $nested_code_pre || empty( $piece ) || ( $piece[0] === '<' && ! preg_match( '|^<\s*[\w]{1,20}+://|', $piece ) ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1936
			$r .= $piece;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1937
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1938
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1939
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1940
		// Long strings might contain expensive edge cases ...
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1941
		if ( 10000 < strlen( $piece ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1942
			// ... break it up
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1943
			foreach ( _split_str_by_whitespace( $piece, 2100 ) as $chunk ) { // 2100: Extra room for scheme and leading and trailing paretheses
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1944
				if ( 2101 < strlen( $chunk ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1945
					$r .= $chunk; // Too big, no whitespace: bail.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1946
				} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1947
					$r .= make_clickable( $chunk );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1948
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1949
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1950
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1951
			$ret = " $piece "; // Pad with whitespace to simplify the regexes
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1952
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1953
			$url_clickable = '~
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1954
				([\\s(<.,;:!?])                                        # 1: Leading whitespace, or punctuation
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1955
				(                                                      # 2: URL
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1956
					[\\w]{1,20}+://                                # Scheme and hier-part prefix
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1957
					(?=\S{1,2000}\s)                               # Limit to URLs less than about 2000 characters long
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1958
					[\\w\\x80-\\xff#%\\~/@\\[\\]*(+=&$-]*+         # Non-punctuation URL character
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1959
					(?:                                            # Unroll the Loop: Only allow puctuation URL character if followed by a non-punctuation URL character
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1960
						[\'.,;:!?)]                            # Punctuation URL character
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1961
						[\\w\\x80-\\xff#%\\~/@\\[\\]*(+=&$-]++ # Non-punctuation URL character
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1962
					)*
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1963
				)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1964
				(\)?)                                                  # 3: Trailing closing parenthesis (for parethesis balancing post processing)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1965
			~xS'; // The regex is a non-anchored pattern and does not have a single fixed starting character.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1966
			      // Tell PCRE to spend more time optimizing since, when used on a page load, it will probably be used several times.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1967
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1968
			$ret = preg_replace_callback( $url_clickable, '_make_url_clickable_cb', $ret );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1969
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1970
			$ret = preg_replace_callback( '#([\s>])((www|ftp)\.[\w\\x80-\\xff\#$%&~/.\-;:=,?@\[\]+]+)#is', '_make_web_ftp_clickable_cb', $ret );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1971
			$ret = preg_replace_callback( '#([\s>])([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})#i', '_make_email_clickable_cb', $ret );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1972
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1973
			$ret = substr( $ret, 1, -1 ); // Remove our whitespace padding.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1974
			$r .= $ret;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1975
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1976
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1977
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1978
	// Cleanup of accidental links within links
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1979
	$r = preg_replace( '#(<a([ \r\n\t]+[^>]+?>|>))<a [^>]+?>([^>]+?)</a></a>#i', "$1$3</a>", $r );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1980
	return $r;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1981
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1982
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1983
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1984
 * Breaks a string into chunks by splitting at whitespace characters.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1985
 * The length of each returned chunk is as close to the specified length goal as possible,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1986
 * with the caveat that each chunk includes its trailing delimiter.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1987
 * Chunks longer than the goal are guaranteed to not have any inner whitespace.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1988
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1989
 * Joining the returned chunks with empty delimiters reconstructs the input string losslessly.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1990
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1991
 * Input string must have no null characters (or eventual transformations on output chunks must not care about null characters)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1992
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1993
 *     _split_str_by_whitespace( "1234 67890 1234 67890a cd 1234   890 123456789 1234567890a    45678   1 3 5 7 90 ", 10 ) ==
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1994
 *     array (
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1995
 *         0 => '1234 67890 ',  // 11 characters: Perfect split
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1996
 *         1 => '1234 ',        //  5 characters: '1234 67890a' was too long
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1997
 *         2 => '67890a cd ',   // 10 characters: '67890a cd 1234' was too long
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1998
 *         3 => '1234   890 ',  // 11 characters: Perfect split
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1999
 *         4 => '123456789 ',   // 10 characters: '123456789 1234567890a' was too long
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2000
 *         5 => '1234567890a ', // 12 characters: Too long, but no inner whitespace on which to split
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2001
 *         6 => '   45678   ',  // 11 characters: Perfect split
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2002
 *         7 => '1 3 5 7 90 ',  // 11 characters: End of $string
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2003
 *     );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2004
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2005
 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2006
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2007
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2008
 * @param string $string The string to split.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2009
 * @param int $goal The desired chunk length.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2010
 * @return array Numeric array of chunks.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2011
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2012
function _split_str_by_whitespace( $string, $goal ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2013
	$chunks = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2014
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2015
	$string_nullspace = strtr( $string, "\r\n\t\v\f ", "\000\000\000\000\000\000" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2016
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2017
	while ( $goal < strlen( $string_nullspace ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2018
		$pos = strrpos( substr( $string_nullspace, 0, $goal + 1 ), "\000" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2019
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2020
		if ( false === $pos ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2021
			$pos = strpos( $string_nullspace, "\000", $goal + 1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2022
			if ( false === $pos ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2023
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2024
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2025
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2026
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2027
		$chunks[] = substr( $string, 0, $pos + 1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2028
		$string = substr( $string, $pos + 1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2029
		$string_nullspace = substr( $string_nullspace, $pos + 1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2030
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2031
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2032
	if ( $string ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2033
		$chunks[] = $string;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2034
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2035
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2036
	return $chunks;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2037
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2038
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2039
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2040
 * Adds rel nofollow string to all HTML A elements in content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2041
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2042
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2043
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2044
 * @param string $text Content that may contain HTML A elements.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2045
 * @return string Converted content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2046
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2047
function wp_rel_nofollow( $text ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2048
	// This is a pre save filter, so text is already escaped.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2049
	$text = stripslashes($text);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2050
	$text = preg_replace_callback('|<a (.+?)>|i', 'wp_rel_nofollow_callback', $text);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2051
	$text = wp_slash($text);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2052
	return $text;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2053
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2054
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2055
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2056
 * Callback to add rel=nofollow string to HTML A element.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2057
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2058
 * Will remove already existing rel="nofollow" and rel='nofollow' from the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2059
 * string to prevent from invalidating (X)HTML.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2060
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2061
 * @since 2.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2062
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2063
 * @param array $matches Single Match
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2064
 * @return string HTML A Element with rel nofollow.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2065
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2066
function wp_rel_nofollow_callback( $matches ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2067
	$text = $matches[1];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2068
	$text = str_replace(array(' rel="nofollow"', " rel='nofollow'"), '', $text);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2069
	return "<a $text rel=\"nofollow\">";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2070
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2071
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2072
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2073
 * Convert one smiley code to the icon graphic file equivalent.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2074
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2075
 * Callback handler for {@link convert_smilies()}.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2076
 * Looks up one smiley code in the $wpsmiliestrans global array and returns an
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2077
 * `<img>` string for that smiley.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2078
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2079
 * @global array $wpsmiliestrans
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2080
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2081
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2082
 * @param array $matches Single match. Smiley code to convert to image.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2083
 * @return string Image string for smiley.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2084
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2085
function translate_smiley( $matches ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2086
	global $wpsmiliestrans;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2087
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2088
	if ( count( $matches ) == 0 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2089
		return '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2090
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2091
	$smiley = trim( reset( $matches ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2092
	$img = $wpsmiliestrans[ $smiley ];
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2093
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2094
	$matches = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2095
	$ext = preg_match( '/\.([^.]+)$/', $img, $matches ) ? strtolower( $matches[1] ) : false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2096
	$image_exts = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2097
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2098
	// Don't convert smilies that aren't images - they're probably emoji.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2099
	if ( ! in_array( $ext, $image_exts ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2100
		return $img;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2101
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2102
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2103
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2104
	 * Filter the Smiley image URL before it's used in the image element.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2105
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2106
	 * @since 2.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2107
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2108
	 * @param string $smiley_url URL for the smiley image.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2109
	 * @param string $img        Filename for the smiley image.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2110
	 * @param string $site_url   Site URL, as returned by site_url().
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2111
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2112
	$src_url = apply_filters( 'smilies_src', includes_url( "images/smilies/$img" ), $img, site_url() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2113
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2114
	return sprintf( '<img src="%s" alt="%s" class="wp-smiley" style="height: 1em; max-height: 1em;" />', esc_url( $src_url ), esc_attr( $smiley ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2115
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2116
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2117
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2118
 * Convert text equivalent of smilies to images.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2119
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2120
 * Will only convert smilies if the option 'use_smilies' is true and the global
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2121
 * used in the function isn't empty.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2122
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2123
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2124
 * @uses $wp_smiliessearch
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2125
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2126
 * @param string $text Content to convert smilies from text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2127
 * @return string Converted content with text smilies replaced with images.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2128
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2129
function convert_smilies( $text ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2130
	global $wp_smiliessearch;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2131
	$output = '';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2132
	if ( get_option( 'use_smilies' ) && ! empty( $wp_smiliessearch ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2133
		// HTML loop taken from texturize function, could possible be consolidated
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2134
		$textarr = preg_split( '/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE ); // capture the tags as well as in between
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2135
		$stop = count( $textarr );// loop stuff
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2136
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2137
		// Ignore proessing of specific tags
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2138
		$tags_to_ignore = 'code|pre|style|script|textarea';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2139
		$ignore_block_element = '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2140
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2141
		for ( $i = 0; $i < $stop; $i++ ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2142
			$content = $textarr[$i];
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2143
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2144
			// If we're in an ignore block, wait until we find its closing tag
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2145
			if ( '' == $ignore_block_element && preg_match( '/^<(' . $tags_to_ignore . ')>/', $content, $matches ) )  {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2146
				$ignore_block_element = $matches[1];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2147
			}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2148
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2149
			// If it's not a tag and not in ignore block
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2150
			if ( '' ==  $ignore_block_element && strlen( $content ) > 0 && '<' != $content[0] ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2151
				$content = preg_replace_callback( $wp_smiliessearch, 'translate_smiley', $content );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2152
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2153
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2154
			// did we exit ignore block
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2155
			if ( '' != $ignore_block_element && '</' . $ignore_block_element . '>' == $content )  {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2156
				$ignore_block_element = '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2157
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2158
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2159
			$output .= $content;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2160
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2161
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2162
		// return default text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2163
		$output = $text;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2164
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2165
	return $output;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2166
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2167
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2168
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2169
 * Verifies that an email is valid.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2170
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2171
 * Does not grok i18n domains. Not RFC compliant.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2172
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2173
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2174
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2175
 * @param string $email Email address to verify.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2176
 * @param boolean $deprecated Deprecated.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2177
 * @return string|bool Either false or the valid email address.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2178
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2179
function is_email( $email, $deprecated = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2180
	if ( ! empty( $deprecated ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2181
		_deprecated_argument( __FUNCTION__, '3.0' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2182
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2183
	// Test for the minimum length the email can be
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2184
	if ( strlen( $email ) < 3 ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2185
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2186
		 * Filter whether an email address is valid.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2187
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2188
		 * This filter is evaluated under several different contexts, such as 'email_too_short',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2189
		 * 'email_no_at', 'local_invalid_chars', 'domain_period_sequence', 'domain_period_limits',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2190
		 * 'domain_no_periods', 'sub_hyphen_limits', 'sub_invalid_chars', or no specific context.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2191
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2192
		 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2193
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2194
		 * @param bool   $is_email Whether the email address has passed the is_email() checks. Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2195
		 * @param string $email    The email address being checked.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2196
		 * @param string $message  An explanatory message to the user.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2197
		 * @param string $context  Context under which the email was tested.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2198
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2199
		return apply_filters( 'is_email', false, $email, 'email_too_short' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2200
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2201
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2202
	// Test for an @ character after the first position
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2203
	if ( strpos( $email, '@', 1 ) === false ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2204
		/** This filter is documented in wp-includes/formatting.php */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2205
		return apply_filters( 'is_email', false, $email, 'email_no_at' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2206
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2207
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2208
	// Split out the local and domain parts
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2209
	list( $local, $domain ) = explode( '@', $email, 2 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2210
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2211
	// LOCAL PART
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2212
	// Test for invalid characters
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2213
	if ( !preg_match( '/^[a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]+$/', $local ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2214
		/** This filter is documented in wp-includes/formatting.php */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2215
		return apply_filters( 'is_email', false, $email, 'local_invalid_chars' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2216
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2217
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2218
	// DOMAIN PART
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2219
	// Test for sequences of periods
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2220
	if ( preg_match( '/\.{2,}/', $domain ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2221
		/** This filter is documented in wp-includes/formatting.php */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2222
		return apply_filters( 'is_email', false, $email, 'domain_period_sequence' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2223
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2224
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2225
	// Test for leading and trailing periods and whitespace
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2226
	if ( trim( $domain, " \t\n\r\0\x0B." ) !== $domain ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2227
		/** This filter is documented in wp-includes/formatting.php */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2228
		return apply_filters( 'is_email', false, $email, 'domain_period_limits' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2229
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2230
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2231
	// Split the domain into subs
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2232
	$subs = explode( '.', $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2233
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2234
	// Assume the domain will have at least two subs
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2235
	if ( 2 > count( $subs ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2236
		/** This filter is documented in wp-includes/formatting.php */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2237
		return apply_filters( 'is_email', false, $email, 'domain_no_periods' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2238
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2239
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2240
	// Loop through each sub
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2241
	foreach ( $subs as $sub ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2242
		// Test for leading and trailing hyphens and whitespace
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2243
		if ( trim( $sub, " \t\n\r\0\x0B-" ) !== $sub ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2244
			/** This filter is documented in wp-includes/formatting.php */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2245
			return apply_filters( 'is_email', false, $email, 'sub_hyphen_limits' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2246
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2247
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2248
		// Test for invalid characters
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2249
		if ( !preg_match('/^[a-z0-9-]+$/i', $sub ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2250
			/** This filter is documented in wp-includes/formatting.php */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2251
			return apply_filters( 'is_email', false, $email, 'sub_invalid_chars' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2252
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2253
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2254
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2255
	// Congratulations your email made it!
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2256
	/** This filter is documented in wp-includes/formatting.php */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2257
	return apply_filters( 'is_email', $email, $email, null );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2258
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2259
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2260
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2261
 * Convert to ASCII from email subjects.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2262
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2263
 * @since 1.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2264
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2265
 * @param string $string Subject line
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2266
 * @return string Converted string to ASCII
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2267
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2268
function wp_iso_descrambler($string) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2269
	/* this may only work with iso-8859-1, I'm afraid */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2270
	if (!preg_match('#\=\?(.+)\?Q\?(.+)\?\=#i', $string, $matches)) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2271
		return $string;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2272
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2273
		$subject = str_replace('_', ' ', $matches[2]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2274
		$subject = preg_replace_callback('#\=([0-9a-f]{2})#i', '_wp_iso_convert', $subject);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2275
		return $subject;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2276
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2277
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2278
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2279
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2280
 * Helper function to convert hex encoded chars to ASCII
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2281
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2282
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2283
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2284
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2285
 * @param array $match The preg_replace_callback matches array
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2286
 * @return string Converted chars
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2287
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2288
function _wp_iso_convert( $match ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2289
	return chr( hexdec( strtolower( $match[1] ) ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2290
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2291
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2292
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2293
 * Returns a date in the GMT equivalent.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2294
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2295
 * Requires and returns a date in the Y-m-d H:i:s format. If there is a
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2296
 * timezone_string available, the date is assumed to be in that timezone,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2297
 * otherwise it simply subtracts the value of the 'gmt_offset' option. Return
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2298
 * format can be overridden using the $format parameter.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2299
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2300
 * @since 1.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2301
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2302
 * @param string $string The date to be converted.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2303
 * @param string $format The format string for the returned date (default is Y-m-d H:i:s)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2304
 * @return string GMT version of the date provided.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2305
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2306
function get_gmt_from_date( $string, $format = 'Y-m-d H:i:s' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2307
	$tz = get_option( 'timezone_string' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2308
	if ( $tz ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2309
		$datetime = date_create( $string, new DateTimeZone( $tz ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2310
		if ( ! $datetime )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2311
			return gmdate( $format, 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2312
		$datetime->setTimezone( new DateTimeZone( 'UTC' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2313
		$string_gmt = $datetime->format( $format );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2314
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2315
		if ( ! preg_match( '#([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $string, $matches ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2316
			return gmdate( $format, 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2317
		$string_time = gmmktime( $matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2318
		$string_gmt = gmdate( $format, $string_time - get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2319
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2320
	return $string_gmt;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2321
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2322
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2323
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2324
 * Converts a GMT date into the correct format for the blog.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2325
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2326
 * Requires and returns a date in the Y-m-d H:i:s format. If there is a
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2327
 * timezone_string available, the returned date is in that timezone, otherwise
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2328
 * it simply adds the value of gmt_offset. Return format can be overridden
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2329
 * using the $format parameter
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2330
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2331
 * @since 1.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2332
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2333
 * @param string $string The date to be converted.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2334
 * @param string $format The format string for the returned date (default is Y-m-d H:i:s)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2335
 * @return string Formatted date relative to the timezone / GMT offset.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2336
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2337
function get_date_from_gmt( $string, $format = 'Y-m-d H:i:s' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2338
	$tz = get_option( 'timezone_string' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2339
	if ( $tz ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2340
		$datetime = date_create( $string, new DateTimeZone( 'UTC' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2341
		if ( ! $datetime )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2342
			return date( $format, 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2343
		$datetime->setTimezone( new DateTimeZone( $tz ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2344
		$string_localtime = $datetime->format( $format );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2345
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2346
		if ( ! preg_match('#([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $string, $matches) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2347
			return date( $format, 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2348
		$string_time = gmmktime( $matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2349
		$string_localtime = gmdate( $format, $string_time + get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2350
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2351
	return $string_localtime;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2352
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2353
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2354
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2355
 * Computes an offset in seconds from an iso8601 timezone.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2356
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2357
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2358
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2359
 * @param string $timezone Either 'Z' for 0 offset or '±hhmm'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2360
 * @return int|float The offset in seconds.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2361
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2362
function iso8601_timezone_to_offset($timezone) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2363
	// $timezone is either 'Z' or '[+|-]hhmm'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2364
	if ($timezone == 'Z') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2365
		$offset = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2366
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2367
		$sign    = (substr($timezone, 0, 1) == '+') ? 1 : -1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2368
		$hours   = intval(substr($timezone, 1, 2));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2369
		$minutes = intval(substr($timezone, 3, 4)) / 60;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2370
		$offset  = $sign * HOUR_IN_SECONDS * ($hours + $minutes);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2371
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2372
	return $offset;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2373
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2374
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2375
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2376
 * Converts an iso8601 date to MySQL DateTime format used by post_date[_gmt].
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2377
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2378
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2379
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2380
 * @param string $date_string Date and time in ISO 8601 format {@link http://en.wikipedia.org/wiki/ISO_8601}.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2381
 * @param string $timezone Optional. If set to GMT returns the time minus gmt_offset. Default is 'user'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2382
 * @return string The date and time in MySQL DateTime format - Y-m-d H:i:s.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2383
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2384
function iso8601_to_datetime($date_string, $timezone = 'user') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2385
	$timezone = strtolower($timezone);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2386
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2387
	if ($timezone == 'gmt') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2388
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2389
		preg_match('#([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(Z|[\+|\-][0-9]{2,4}){0,1}#', $date_string, $date_bits);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2390
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2391
		if (!empty($date_bits[7])) { // we have a timezone, so let's compute an offset
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2392
			$offset = iso8601_timezone_to_offset($date_bits[7]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2393
		} else { // we don't have a timezone, so we assume user local timezone (not server's!)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2394
			$offset = HOUR_IN_SECONDS * get_option('gmt_offset');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2395
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2396
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2397
		$timestamp = gmmktime($date_bits[4], $date_bits[5], $date_bits[6], $date_bits[2], $date_bits[3], $date_bits[1]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2398
		$timestamp -= $offset;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2399
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2400
		return gmdate('Y-m-d H:i:s', $timestamp);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2401
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2402
	} elseif ($timezone == 'user') {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2403
		return preg_replace('#([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(Z|[\+|\-][0-9]{2,4}){0,1}#', '$1-$2-$3 $4:$5:$6', $date_string);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2404
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2405
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2406
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2407
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2408
 * Adds a element attributes to open links in new windows.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2409
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2410
 * Comment text in popup windows should be filtered through this. Right now it's
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2411
 * a moderately dumb function, ideally it would detect whether a target or rel
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2412
 * attribute was already there and adjust its actions accordingly.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2413
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2414
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2415
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2416
 * @param string $text Content to replace links to open in a new window.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2417
 * @return string Content that has filtered links.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2418
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2419
function popuplinks($text) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2420
	$text = preg_replace('/<a (.+?)>/i', "<a $1 target='_blank' rel='external'>", $text);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2421
	return $text;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2422
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2423
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2424
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2425
 * Strips out all characters that are not allowable in an email.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2426
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2427
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2428
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2429
 * @param string $email Email address to filter.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2430
 * @return string Filtered email address.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2431
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2432
function sanitize_email( $email ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2433
	// Test for the minimum length the email can be
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2434
	if ( strlen( $email ) < 3 ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2435
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2436
		 * Filter a sanitized email address.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2437
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2438
		 * This filter is evaluated under several contexts, including 'email_too_short',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2439
		 * 'email_no_at', 'local_invalid_chars', 'domain_period_sequence', 'domain_period_limits',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2440
		 * 'domain_no_periods', 'domain_no_valid_subs', or no context.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2441
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2442
		 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2443
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2444
		 * @param string $email   The sanitized email address.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2445
		 * @param string $email   The email address, as provided to sanitize_email().
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2446
		 * @param string $message A message to pass to the user.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2447
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2448
		return apply_filters( 'sanitize_email', '', $email, 'email_too_short' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2449
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2450
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2451
	// Test for an @ character after the first position
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2452
	if ( strpos( $email, '@', 1 ) === false ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2453
		/** This filter is documented in wp-includes/formatting.php */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2454
		return apply_filters( 'sanitize_email', '', $email, 'email_no_at' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2455
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2456
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2457
	// Split out the local and domain parts
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2458
	list( $local, $domain ) = explode( '@', $email, 2 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2459
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2460
	// LOCAL PART
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2461
	// Test for invalid characters
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2462
	$local = preg_replace( '/[^a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]/', '', $local );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2463
	if ( '' === $local ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2464
		/** This filter is documented in wp-includes/formatting.php */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2465
		return apply_filters( 'sanitize_email', '', $email, 'local_invalid_chars' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2466
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2467
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2468
	// DOMAIN PART
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2469
	// Test for sequences of periods
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2470
	$domain = preg_replace( '/\.{2,}/', '', $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2471
	if ( '' === $domain ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2472
		/** This filter is documented in wp-includes/formatting.php */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2473
		return apply_filters( 'sanitize_email', '', $email, 'domain_period_sequence' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2474
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2475
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2476
	// Test for leading and trailing periods and whitespace
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2477
	$domain = trim( $domain, " \t\n\r\0\x0B." );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2478
	if ( '' === $domain ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2479
		/** This filter is documented in wp-includes/formatting.php */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2480
		return apply_filters( 'sanitize_email', '', $email, 'domain_period_limits' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2481
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2482
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2483
	// Split the domain into subs
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2484
	$subs = explode( '.', $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2485
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2486
	// Assume the domain will have at least two subs
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2487
	if ( 2 > count( $subs ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2488
		/** This filter is documented in wp-includes/formatting.php */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2489
		return apply_filters( 'sanitize_email', '', $email, 'domain_no_periods' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2490
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2491
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2492
	// Create an array that will contain valid subs
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2493
	$new_subs = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2494
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2495
	// Loop through each sub
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2496
	foreach ( $subs as $sub ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2497
		// Test for leading and trailing hyphens
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2498
		$sub = trim( $sub, " \t\n\r\0\x0B-" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2499
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2500
		// Test for invalid characters
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2501
		$sub = preg_replace( '/[^a-z0-9-]+/i', '', $sub );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2502
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2503
		// If there's anything left, add it to the valid subs
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2504
		if ( '' !== $sub ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2505
			$new_subs[] = $sub;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2506
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2507
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2508
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2509
	// If there aren't 2 or more valid subs
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2510
	if ( 2 > count( $new_subs ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2511
		/** This filter is documented in wp-includes/formatting.php */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2512
		return apply_filters( 'sanitize_email', '', $email, 'domain_no_valid_subs' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2513
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2514
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2515
	// Join valid subs into the new domain
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2516
	$domain = join( '.', $new_subs );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2517
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2518
	// Put the email back together
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2519
	$email = $local . '@' . $domain;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2520
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2521
	// Congratulations your email made it!
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2522
	/** This filter is documented in wp-includes/formatting.php */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2523
	return apply_filters( 'sanitize_email', $email, $email, null );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2524
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2525
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2526
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2527
 * Determines the difference between two timestamps.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2528
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2529
 * The difference is returned in a human readable format such as "1 hour",
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2530
 * "5 mins", "2 days".
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2531
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2532
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2533
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2534
 * @param int $from Unix timestamp from which the difference begins.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2535
 * @param int $to Optional. Unix timestamp to end the time difference. Default becomes time() if not set.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2536
 * @return string Human readable time difference.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2537
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2538
function human_time_diff( $from, $to = '' ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2539
	if ( empty( $to ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2540
		$to = time();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2541
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2542
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2543
	$diff = (int) abs( $to - $from );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2544
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2545
	if ( $diff < HOUR_IN_SECONDS ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2546
		$mins = round( $diff / MINUTE_IN_SECONDS );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2547
		if ( $mins <= 1 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2548
			$mins = 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2549
		/* translators: min=minute */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2550
		$since = sprintf( _n( '%s min', '%s mins', $mins ), $mins );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2551
	} elseif ( $diff < DAY_IN_SECONDS && $diff >= HOUR_IN_SECONDS ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2552
		$hours = round( $diff / HOUR_IN_SECONDS );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2553
		if ( $hours <= 1 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2554
			$hours = 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2555
		$since = sprintf( _n( '%s hour', '%s hours', $hours ), $hours );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2556
	} elseif ( $diff < WEEK_IN_SECONDS && $diff >= DAY_IN_SECONDS ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2557
		$days = round( $diff / DAY_IN_SECONDS );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2558
		if ( $days <= 1 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2559
			$days = 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2560
		$since = sprintf( _n( '%s day', '%s days', $days ), $days );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2561
	} elseif ( $diff < 30 * DAY_IN_SECONDS && $diff >= WEEK_IN_SECONDS ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2562
		$weeks = round( $diff / WEEK_IN_SECONDS );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2563
		if ( $weeks <= 1 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2564
			$weeks = 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2565
		$since = sprintf( _n( '%s week', '%s weeks', $weeks ), $weeks );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2566
	} elseif ( $diff < YEAR_IN_SECONDS && $diff >= 30 * DAY_IN_SECONDS ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2567
		$months = round( $diff / ( 30 * DAY_IN_SECONDS ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2568
		if ( $months <= 1 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2569
			$months = 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2570
		$since = sprintf( _n( '%s month', '%s months', $months ), $months );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2571
	} elseif ( $diff >= YEAR_IN_SECONDS ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2572
		$years = round( $diff / YEAR_IN_SECONDS );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2573
		if ( $years <= 1 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2574
			$years = 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2575
		$since = sprintf( _n( '%s year', '%s years', $years ), $years );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2576
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2577
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2578
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2579
	 * Filter the human readable difference between two timestamps.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2580
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2581
	 * @since 4.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2582
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2583
	 * @param string $since The difference in human readable text.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2584
	 * @param int    $diff  The difference in seconds.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2585
	 * @param int    $from  Unix timestamp from which the difference begins.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2586
	 * @param int    $to    Unix timestamp to end the time difference.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2587
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2588
	return apply_filters( 'human_time_diff', $since, $diff, $from, $to );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2589
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2590
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2591
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2592
 * Generates an excerpt from the content, if needed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2593
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2594
 * The excerpt word amount will be 55 words and if the amount is greater than
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2595
 * that, then the string ' [&hellip;]' will be appended to the excerpt. If the string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2596
 * is less than 55 words, then the content will be returned as is.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2597
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2598
 * The 55 word limit can be modified by plugins/themes using the excerpt_length filter
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2599
 * The ' [&hellip;]' string can be modified by plugins/themes using the excerpt_more filter
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2600
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2601
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2602
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2603
 * @param string $text Optional. The excerpt. If set to empty, an excerpt is generated.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2604
 * @return string The excerpt.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2605
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2606
function wp_trim_excerpt($text = '') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2607
	$raw_excerpt = $text;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2608
	if ( '' == $text ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2609
		$text = get_the_content('');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2610
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2611
		$text = strip_shortcodes( $text );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2612
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2613
		/** This filter is documented in wp-includes/post-template.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2614
		$text = apply_filters( 'the_content', $text );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2615
		$text = str_replace(']]>', ']]&gt;', $text);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2616
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2617
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2618
		 * Filter the number of words in an excerpt.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2619
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2620
		 * @since 2.7.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2621
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2622
		 * @param int $number The number of words. Default 55.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2623
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2624
		$excerpt_length = apply_filters( 'excerpt_length', 55 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2625
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2626
		 * Filter the string in the "more" link displayed after a trimmed excerpt.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2627
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2628
		 * @since 2.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2629
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2630
		 * @param string $more_string The string shown within the more link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2631
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2632
		$excerpt_more = apply_filters( 'excerpt_more', ' ' . '[&hellip;]' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2633
		$text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2634
	}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2635
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2636
	 * Filter the trimmed excerpt string.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2637
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2638
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2639
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2640
	 * @param string $text        The trimmed text.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2641
	 * @param string $raw_excerpt The text prior to trimming.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2642
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2643
	return apply_filters( 'wp_trim_excerpt', $text, $raw_excerpt );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2644
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2645
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2646
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2647
 * Trims text to a certain number of words.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2648
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2649
 * This function is localized. For languages that count 'words' by the individual
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2650
 * character (such as East Asian languages), the $num_words argument will apply
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2651
 * to the number of individual characters.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2652
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2653
 * @since 3.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2654
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2655
 * @param string $text Text to trim.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2656
 * @param int $num_words Number of words. Default 55.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2657
 * @param string $more Optional. What to append if $text needs to be trimmed. Default '&hellip;'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2658
 * @return string Trimmed text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2659
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2660
function wp_trim_words( $text, $num_words = 55, $more = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2661
	if ( null === $more )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2662
		$more = __( '&hellip;' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2663
	$original_text = $text;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2664
	$text = wp_strip_all_tags( $text );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2665
	/* translators: If your word count is based on single characters (East Asian characters),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2666
	   enter 'characters'. Otherwise, enter 'words'. Do not translate into your own language. */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2667
	if ( 'characters' == _x( 'words', 'word count: words or characters?' ) && preg_match( '/^utf\-?8$/i', get_option( 'blog_charset' ) ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2668
		$text = trim( preg_replace( "/[\n\r\t ]+/", ' ', $text ), ' ' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2669
		preg_match_all( '/./u', $text, $words_array );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2670
		$words_array = array_slice( $words_array[0], 0, $num_words + 1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2671
		$sep = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2672
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2673
		$words_array = preg_split( "/[\n\r\t ]+/", $text, $num_words + 1, PREG_SPLIT_NO_EMPTY );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2674
		$sep = ' ';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2675
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2676
	if ( count( $words_array ) > $num_words ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2677
		array_pop( $words_array );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2678
		$text = implode( $sep, $words_array );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2679
		$text = $text . $more;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2680
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2681
		$text = implode( $sep, $words_array );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2682
	}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2683
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2684
	 * Filter the text content after words have been trimmed.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2685
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2686
	 * @since 3.3.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2687
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2688
	 * @param string $text          The trimmed text.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2689
	 * @param int    $num_words     The number of words to trim the text to. Default 5.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2690
	 * @param string $more          An optional string to append to the end of the trimmed text, e.g. &hellip;.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2691
	 * @param string $original_text The text before it was trimmed.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2692
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2693
	return apply_filters( 'wp_trim_words', $text, $num_words, $more, $original_text );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2694
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2695
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2696
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2697
 * Converts named entities into numbered entities.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2698
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2699
 * @since 1.5.1
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2700
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2701
 * @param string $text The text within which entities will be converted.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2702
 * @return string Text with converted entities.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2703
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2704
function ent2ncr($text) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2705
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2706
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2707
	 * Filter text before named entities are converted into numbered entities.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2708
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2709
	 * A non-null string must be returned for the filter to be evaluated.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2710
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2711
	 * @since 3.3.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2712
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2713
	 * @param null   $converted_text The text to be converted. Default null.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2714
	 * @param string $text           The text prior to entity conversion.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2715
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2716
	$filtered = apply_filters( 'pre_ent2ncr', null, $text );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2717
	if( null !== $filtered )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2718
		return $filtered;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2719
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2720
	$to_ncr = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2721
		'&quot;' => '&#34;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2722
		'&amp;' => '&#38;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2723
		'&lt;' => '&#60;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2724
		'&gt;' => '&#62;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2725
		'|' => '&#124;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2726
		'&nbsp;' => '&#160;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2727
		'&iexcl;' => '&#161;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2728
		'&cent;' => '&#162;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2729
		'&pound;' => '&#163;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2730
		'&curren;' => '&#164;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2731
		'&yen;' => '&#165;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2732
		'&brvbar;' => '&#166;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2733
		'&brkbar;' => '&#166;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2734
		'&sect;' => '&#167;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2735
		'&uml;' => '&#168;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2736
		'&die;' => '&#168;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2737
		'&copy;' => '&#169;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2738
		'&ordf;' => '&#170;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2739
		'&laquo;' => '&#171;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2740
		'&not;' => '&#172;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2741
		'&shy;' => '&#173;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2742
		'&reg;' => '&#174;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2743
		'&macr;' => '&#175;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2744
		'&hibar;' => '&#175;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2745
		'&deg;' => '&#176;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2746
		'&plusmn;' => '&#177;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2747
		'&sup2;' => '&#178;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2748
		'&sup3;' => '&#179;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2749
		'&acute;' => '&#180;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2750
		'&micro;' => '&#181;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2751
		'&para;' => '&#182;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2752
		'&middot;' => '&#183;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2753
		'&cedil;' => '&#184;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2754
		'&sup1;' => '&#185;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2755
		'&ordm;' => '&#186;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2756
		'&raquo;' => '&#187;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2757
		'&frac14;' => '&#188;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2758
		'&frac12;' => '&#189;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2759
		'&frac34;' => '&#190;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2760
		'&iquest;' => '&#191;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2761
		'&Agrave;' => '&#192;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2762
		'&Aacute;' => '&#193;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2763
		'&Acirc;' => '&#194;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2764
		'&Atilde;' => '&#195;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2765
		'&Auml;' => '&#196;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2766
		'&Aring;' => '&#197;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2767
		'&AElig;' => '&#198;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2768
		'&Ccedil;' => '&#199;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2769
		'&Egrave;' => '&#200;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2770
		'&Eacute;' => '&#201;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2771
		'&Ecirc;' => '&#202;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2772
		'&Euml;' => '&#203;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2773
		'&Igrave;' => '&#204;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2774
		'&Iacute;' => '&#205;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2775
		'&Icirc;' => '&#206;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2776
		'&Iuml;' => '&#207;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2777
		'&ETH;' => '&#208;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2778
		'&Ntilde;' => '&#209;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2779
		'&Ograve;' => '&#210;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2780
		'&Oacute;' => '&#211;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2781
		'&Ocirc;' => '&#212;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2782
		'&Otilde;' => '&#213;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2783
		'&Ouml;' => '&#214;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2784
		'&times;' => '&#215;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2785
		'&Oslash;' => '&#216;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2786
		'&Ugrave;' => '&#217;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2787
		'&Uacute;' => '&#218;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2788
		'&Ucirc;' => '&#219;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2789
		'&Uuml;' => '&#220;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2790
		'&Yacute;' => '&#221;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2791
		'&THORN;' => '&#222;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2792
		'&szlig;' => '&#223;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2793
		'&agrave;' => '&#224;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2794
		'&aacute;' => '&#225;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2795
		'&acirc;' => '&#226;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2796
		'&atilde;' => '&#227;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2797
		'&auml;' => '&#228;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2798
		'&aring;' => '&#229;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2799
		'&aelig;' => '&#230;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2800
		'&ccedil;' => '&#231;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2801
		'&egrave;' => '&#232;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2802
		'&eacute;' => '&#233;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2803
		'&ecirc;' => '&#234;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2804
		'&euml;' => '&#235;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2805
		'&igrave;' => '&#236;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2806
		'&iacute;' => '&#237;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2807
		'&icirc;' => '&#238;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2808
		'&iuml;' => '&#239;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2809
		'&eth;' => '&#240;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2810
		'&ntilde;' => '&#241;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2811
		'&ograve;' => '&#242;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2812
		'&oacute;' => '&#243;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2813
		'&ocirc;' => '&#244;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2814
		'&otilde;' => '&#245;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2815
		'&ouml;' => '&#246;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2816
		'&divide;' => '&#247;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2817
		'&oslash;' => '&#248;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2818
		'&ugrave;' => '&#249;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2819
		'&uacute;' => '&#250;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2820
		'&ucirc;' => '&#251;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2821
		'&uuml;' => '&#252;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2822
		'&yacute;' => '&#253;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2823
		'&thorn;' => '&#254;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2824
		'&yuml;' => '&#255;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2825
		'&OElig;' => '&#338;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2826
		'&oelig;' => '&#339;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2827
		'&Scaron;' => '&#352;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2828
		'&scaron;' => '&#353;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2829
		'&Yuml;' => '&#376;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2830
		'&fnof;' => '&#402;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2831
		'&circ;' => '&#710;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2832
		'&tilde;' => '&#732;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2833
		'&Alpha;' => '&#913;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2834
		'&Beta;' => '&#914;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2835
		'&Gamma;' => '&#915;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2836
		'&Delta;' => '&#916;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2837
		'&Epsilon;' => '&#917;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2838
		'&Zeta;' => '&#918;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2839
		'&Eta;' => '&#919;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2840
		'&Theta;' => '&#920;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2841
		'&Iota;' => '&#921;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2842
		'&Kappa;' => '&#922;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2843
		'&Lambda;' => '&#923;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2844
		'&Mu;' => '&#924;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2845
		'&Nu;' => '&#925;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2846
		'&Xi;' => '&#926;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2847
		'&Omicron;' => '&#927;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2848
		'&Pi;' => '&#928;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2849
		'&Rho;' => '&#929;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2850
		'&Sigma;' => '&#931;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2851
		'&Tau;' => '&#932;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2852
		'&Upsilon;' => '&#933;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2853
		'&Phi;' => '&#934;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2854
		'&Chi;' => '&#935;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2855
		'&Psi;' => '&#936;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2856
		'&Omega;' => '&#937;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2857
		'&alpha;' => '&#945;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2858
		'&beta;' => '&#946;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2859
		'&gamma;' => '&#947;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2860
		'&delta;' => '&#948;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2861
		'&epsilon;' => '&#949;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2862
		'&zeta;' => '&#950;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2863
		'&eta;' => '&#951;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2864
		'&theta;' => '&#952;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2865
		'&iota;' => '&#953;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2866
		'&kappa;' => '&#954;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2867
		'&lambda;' => '&#955;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2868
		'&mu;' => '&#956;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2869
		'&nu;' => '&#957;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2870
		'&xi;' => '&#958;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2871
		'&omicron;' => '&#959;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2872
		'&pi;' => '&#960;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2873
		'&rho;' => '&#961;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2874
		'&sigmaf;' => '&#962;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2875
		'&sigma;' => '&#963;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2876
		'&tau;' => '&#964;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2877
		'&upsilon;' => '&#965;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2878
		'&phi;' => '&#966;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2879
		'&chi;' => '&#967;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2880
		'&psi;' => '&#968;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2881
		'&omega;' => '&#969;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2882
		'&thetasym;' => '&#977;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2883
		'&upsih;' => '&#978;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2884
		'&piv;' => '&#982;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2885
		'&ensp;' => '&#8194;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2886
		'&emsp;' => '&#8195;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2887
		'&thinsp;' => '&#8201;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2888
		'&zwnj;' => '&#8204;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2889
		'&zwj;' => '&#8205;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2890
		'&lrm;' => '&#8206;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2891
		'&rlm;' => '&#8207;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2892
		'&ndash;' => '&#8211;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2893
		'&mdash;' => '&#8212;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2894
		'&lsquo;' => '&#8216;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2895
		'&rsquo;' => '&#8217;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2896
		'&sbquo;' => '&#8218;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2897
		'&ldquo;' => '&#8220;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2898
		'&rdquo;' => '&#8221;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2899
		'&bdquo;' => '&#8222;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2900
		'&dagger;' => '&#8224;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2901
		'&Dagger;' => '&#8225;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2902
		'&bull;' => '&#8226;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2903
		'&hellip;' => '&#8230;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2904
		'&permil;' => '&#8240;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2905
		'&prime;' => '&#8242;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2906
		'&Prime;' => '&#8243;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2907
		'&lsaquo;' => '&#8249;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2908
		'&rsaquo;' => '&#8250;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2909
		'&oline;' => '&#8254;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2910
		'&frasl;' => '&#8260;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2911
		'&euro;' => '&#8364;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2912
		'&image;' => '&#8465;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2913
		'&weierp;' => '&#8472;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2914
		'&real;' => '&#8476;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2915
		'&trade;' => '&#8482;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2916
		'&alefsym;' => '&#8501;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2917
		'&crarr;' => '&#8629;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2918
		'&lArr;' => '&#8656;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2919
		'&uArr;' => '&#8657;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2920
		'&rArr;' => '&#8658;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2921
		'&dArr;' => '&#8659;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2922
		'&hArr;' => '&#8660;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2923
		'&forall;' => '&#8704;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2924
		'&part;' => '&#8706;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2925
		'&exist;' => '&#8707;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2926
		'&empty;' => '&#8709;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2927
		'&nabla;' => '&#8711;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2928
		'&isin;' => '&#8712;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2929
		'&notin;' => '&#8713;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2930
		'&ni;' => '&#8715;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2931
		'&prod;' => '&#8719;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2932
		'&sum;' => '&#8721;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2933
		'&minus;' => '&#8722;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2934
		'&lowast;' => '&#8727;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2935
		'&radic;' => '&#8730;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2936
		'&prop;' => '&#8733;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2937
		'&infin;' => '&#8734;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2938
		'&ang;' => '&#8736;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2939
		'&and;' => '&#8743;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2940
		'&or;' => '&#8744;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2941
		'&cap;' => '&#8745;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2942
		'&cup;' => '&#8746;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2943
		'&int;' => '&#8747;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2944
		'&there4;' => '&#8756;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2945
		'&sim;' => '&#8764;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2946
		'&cong;' => '&#8773;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2947
		'&asymp;' => '&#8776;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2948
		'&ne;' => '&#8800;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2949
		'&equiv;' => '&#8801;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2950
		'&le;' => '&#8804;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2951
		'&ge;' => '&#8805;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2952
		'&sub;' => '&#8834;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2953
		'&sup;' => '&#8835;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2954
		'&nsub;' => '&#8836;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2955
		'&sube;' => '&#8838;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2956
		'&supe;' => '&#8839;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2957
		'&oplus;' => '&#8853;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2958
		'&otimes;' => '&#8855;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2959
		'&perp;' => '&#8869;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2960
		'&sdot;' => '&#8901;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2961
		'&lceil;' => '&#8968;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2962
		'&rceil;' => '&#8969;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2963
		'&lfloor;' => '&#8970;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2964
		'&rfloor;' => '&#8971;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2965
		'&lang;' => '&#9001;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2966
		'&rang;' => '&#9002;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2967
		'&larr;' => '&#8592;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2968
		'&uarr;' => '&#8593;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2969
		'&rarr;' => '&#8594;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2970
		'&darr;' => '&#8595;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2971
		'&harr;' => '&#8596;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2972
		'&loz;' => '&#9674;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2973
		'&spades;' => '&#9824;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2974
		'&clubs;' => '&#9827;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2975
		'&hearts;' => '&#9829;',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2976
		'&diams;' => '&#9830;'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2977
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2978
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2979
	return str_replace( array_keys($to_ncr), array_values($to_ncr), $text );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2980
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2981
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2982
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2983
 * Formats text for the rich text editor.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2984
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2985
 * The filter 'richedit_pre' is applied here. If $text is empty the filter will
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2986
 * be applied to an empty string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2987
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2988
 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2989
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2990
 * @param string $text The text to be formatted.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2991
 * @return string The formatted text after filter is applied.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2992
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2993
function wp_richedit_pre($text) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2994
	if ( empty( $text ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2995
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2996
		 * Filter text returned for the rich text editor.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2997
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2998
		 * This filter is first evaluated, and the value returned, if an empty string
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2999
		 * is passed to wp_richedit_pre(). If an empty string is passed, it results
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3000
		 * in a break tag and line feed.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3001
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3002
		 * If a non-empty string is passed, the filter is evaluated on the wp_richedit_pre()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3003
		 * return after being formatted.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3004
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3005
		 * @since 2.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3006
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3007
		 * @param string $output Text for the rich text editor.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3008
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3009
		return apply_filters( 'richedit_pre', '' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3010
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3011
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3012
	$output = convert_chars($text);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3013
	$output = wpautop($output);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3014
	$output = htmlspecialchars($output, ENT_NOQUOTES, get_option( 'blog_charset' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3015
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3016
	/** This filter is documented in wp-includes/formatting.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3017
	return apply_filters( 'richedit_pre', $output );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3018
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3019
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3020
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3021
 * Formats text for the HTML editor.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3022
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3023
 * Unless $output is empty it will pass through htmlspecialchars before the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3024
 * 'htmledit_pre' filter is applied.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3025
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3026
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3027
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3028
 * @param string $output The text to be formatted.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3029
 * @return string Formatted text after filter applied.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3030
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3031
function wp_htmledit_pre($output) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3032
	if ( !empty($output) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3033
		$output = htmlspecialchars($output, ENT_NOQUOTES, get_option( 'blog_charset' ) ); // convert only < > &
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3034
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3035
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3036
	 * Filter the text before it is formatted for the HTML editor.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3037
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3038
	 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3039
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3040
	 * @param string $output The HTML-formatted text.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3041
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3042
	return apply_filters( 'htmledit_pre', $output );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3043
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3044
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3045
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3046
 * Perform a deep string replace operation to ensure the values in $search are no longer present
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3047
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3048
 * Repeats the replacement operation until it no longer replaces anything so as to remove "nested" values
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3049
 * e.g. $subject = '%0%0%0DDD', $search ='%0D', $result ='' rather than the '%0%0DD' that
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3050
 * str_replace would return
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3051
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3052
 * @since 2.8.1
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3053
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3054
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3055
 * @param string|array $search The value being searched for, otherwise known as the needle. An array may be used to designate multiple needles.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3056
 * @param string $subject The string being searched and replaced on, otherwise known as the haystack.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3057
 * @return string The string with the replaced svalues.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3058
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3059
function _deep_replace( $search, $subject ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3060
	$subject = (string) $subject;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3061
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3062
	$count = 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3063
	while ( $count ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3064
		$subject = str_replace( $search, '', $subject, $count );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3065
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3066
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3067
	return $subject;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3068
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3069
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3070
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3071
 * Escapes data for use in a MySQL query.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3072
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3073
 * Usually you should prepare queries using wpdb::prepare().
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3074
 * Sometimes, spot-escaping is required or useful. One example
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3075
 * is preparing an array for use in an IN clause.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3076
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3077
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3078
 * @param string|array $data Unescaped data
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3079
 * @return string|array Escaped data
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3080
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3081
function esc_sql( $data ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3082
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3083
	return $wpdb->_escape( $data );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3084
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3085
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3086
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3087
 * Checks and cleans a URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3088
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3089
 * A number of characters are removed from the URL. If the URL is for displaying
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3090
 * (the default behaviour) ampersands are also replaced. The 'clean_url' filter
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3091
 * is applied to the returned cleaned URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3092
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3093
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3094
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3095
 * @param string $url The URL to be cleaned.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3096
 * @param array $protocols Optional. An array of acceptable protocols.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3097
 *		Defaults to 'http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet', 'mms', 'rtsp', 'svn' if not set.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3098
 * @param string $_context Private. Use esc_url_raw() for database usage.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3099
 * @return string The cleaned $url after the 'clean_url' filter is applied.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3100
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3101
function esc_url( $url, $protocols = null, $_context = 'display' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3102
	$original_url = $url;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3103
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3104
	if ( '' == $url )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3105
		return $url;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3106
	$url = preg_replace('|[^a-z0-9-~+_.?#=!&;,/:%@$\|*\'()\\x80-\\xff]|i', '', $url);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3107
	$strip = array('%0d', '%0a', '%0D', '%0A');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3108
	$url = _deep_replace($strip, $url);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3109
	$url = str_replace(';//', '://', $url);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3110
	/* If the URL doesn't appear to contain a scheme, we
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3111
	 * presume it needs http:// appended (unless a relative
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3112
	 * link starting with /, # or ? or a php file).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3113
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3114
	if ( strpos($url, ':') === false && ! in_array( $url[0], array( '/', '#', '?' ) ) &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3115
		! preg_match('/^[a-z0-9-]+?\.php/i', $url) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3116
		$url = 'http://' . $url;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3117
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3118
	// Replace ampersands and single quotes only when displaying.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3119
	if ( 'display' == $_context ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3120
		$url = wp_kses_normalize_entities( $url );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3121
		$url = str_replace( '&amp;', '&#038;', $url );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3122
		$url = str_replace( "'", '&#039;', $url );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3123
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3124
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3125
	if ( '/' === $url[0] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3126
		$good_protocol_url = $url;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3127
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3128
		if ( ! is_array( $protocols ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3129
			$protocols = wp_allowed_protocols();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3130
		$good_protocol_url = wp_kses_bad_protocol( $url, $protocols );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3131
		if ( strtolower( $good_protocol_url ) != strtolower( $url ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3132
			return '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3133
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3134
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3135
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3136
	 * Filter a string cleaned and escaped for output as a URL.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3137
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3138
	 * @since 2.3.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3139
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3140
	 * @param string $good_protocol_url The cleaned URL to be returned.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3141
	 * @param string $original_url      The URL prior to cleaning.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3142
	 * @param string $_context          If 'display', replace ampersands and single quotes only.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3143
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3144
	return apply_filters( 'clean_url', $good_protocol_url, $original_url, $_context );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3145
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3146
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3147
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3148
 * Performs esc_url() for database usage.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3149
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3150
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3151
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3152
 * @param string $url The URL to be cleaned.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3153
 * @param array $protocols An array of acceptable protocols.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3154
 * @return string The cleaned URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3155
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3156
function esc_url_raw( $url, $protocols = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3157
	return esc_url( $url, $protocols, 'db' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3158
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3159
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3160
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3161
 * Convert entities, while preserving already-encoded entities.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3162
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3163
 * @link http://www.php.net/htmlentities Borrowed from the PHP Manual user notes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3164
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3165
 * @since 1.2.2
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3166
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3167
 * @param string $myHTML The text to be converted.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3168
 * @return string Converted text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3169
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3170
function htmlentities2($myHTML) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3171
	$translation_table = get_html_translation_table( HTML_ENTITIES, ENT_QUOTES );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3172
	$translation_table[chr(38)] = '&';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3173
	return preg_replace( "/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,3};)/", "&amp;", strtr($myHTML, $translation_table) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3174
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3175
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3176
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3177
 * Escape single quotes, htmlspecialchar " < > &, and fix line endings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3178
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3179
 * Escapes text strings for echoing in JS. It is intended to be used for inline JS
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3180
 * (in a tag attribute, for example onclick="..."). Note that the strings have to
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3181
 * be in single quotes. The filter 'js_escape' is also applied here.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3182
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3183
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3184
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3185
 * @param string $text The text to be escaped.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3186
 * @return string Escaped text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3187
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3188
function esc_js( $text ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3189
	$safe_text = wp_check_invalid_utf8( $text );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3190
	$safe_text = _wp_specialchars( $safe_text, ENT_COMPAT );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3191
	$safe_text = preg_replace( '/&#(x)?0*(?(1)27|39);?/i', "'", stripslashes( $safe_text ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3192
	$safe_text = str_replace( "\r", '', $safe_text );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3193
	$safe_text = str_replace( "\n", '\\n', addslashes( $safe_text ) );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3194
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3195
	 * Filter a string cleaned and escaped for output in JavaScript.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3196
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3197
	 * Text passed to esc_js() is stripped of invalid or special characters,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3198
	 * and properly slashed for output.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3199
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3200
	 * @since 2.0.6
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3201
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3202
	 * @param string $safe_text The text after it has been escaped.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3203
 	 * @param string $text      The text prior to being escaped.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3204
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3205
	return apply_filters( 'js_escape', $safe_text, $text );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3206
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3207
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3208
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3209
 * Escaping for HTML blocks.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3210
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3211
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3212
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3213
 * @param string $text
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3214
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3215
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3216
function esc_html( $text ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3217
	$safe_text = wp_check_invalid_utf8( $text );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3218
	$safe_text = _wp_specialchars( $safe_text, ENT_QUOTES );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3219
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3220
	 * Filter a string cleaned and escaped for output in HTML.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3221
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3222
	 * Text passed to esc_html() is stripped of invalid or special characters
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3223
	 * before output.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3224
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3225
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3226
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3227
	 * @param string $safe_text The text after it has been escaped.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3228
 	 * @param string $text      The text prior to being escaped.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3229
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3230
	return apply_filters( 'esc_html', $safe_text, $text );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3231
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3232
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3233
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3234
 * Escaping for HTML attributes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3235
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3236
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3237
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3238
 * @param string $text
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3239
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3240
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3241
function esc_attr( $text ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3242
	$safe_text = wp_check_invalid_utf8( $text );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3243
	$safe_text = _wp_specialchars( $safe_text, ENT_QUOTES );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3244
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3245
	 * Filter a string cleaned and escaped for output in an HTML attribute.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3246
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3247
	 * Text passed to esc_attr() is stripped of invalid or special characters
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3248
	 * before output.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3249
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3250
	 * @since 2.0.6
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3251
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3252
	 * @param string $safe_text The text after it has been escaped.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3253
 	 * @param string $text      The text prior to being escaped.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3254
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3255
	return apply_filters( 'attribute_escape', $safe_text, $text );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3256
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3257
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3258
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3259
 * Escaping for textarea values.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3260
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3261
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3262
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3263
 * @param string $text
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3264
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3265
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3266
function esc_textarea( $text ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3267
	$safe_text = htmlspecialchars( $text, ENT_QUOTES, get_option( 'blog_charset' ) );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3268
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3269
	 * Filter a string cleaned and escaped for output in a textarea element.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3270
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3271
	 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3272
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3273
	 * @param string $safe_text The text after it has been escaped.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3274
 	 * @param string $text      The text prior to being escaped.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3275
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3276
	return apply_filters( 'esc_textarea', $safe_text, $text );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3277
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3278
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3279
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3280
 * Escape an HTML tag name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3281
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3282
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3283
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3284
 * @param string $tag_name
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3285
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3286
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3287
function tag_escape($tag_name) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3288
	$safe_tag = strtolower( preg_replace('/[^a-zA-Z0-9_:]/', '', $tag_name) );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3289
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3290
	 * Filter a string cleaned and escaped for output as an HTML tag.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3291
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3292
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3293
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3294
	 * @param string $safe_tag The tag name after it has been escaped.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3295
 	 * @param string $tag_name The text before it was escaped.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3296
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3297
	return apply_filters( 'tag_escape', $safe_tag, $tag_name );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3298
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3299
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3300
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3301
 * Convert full URL paths to absolute paths.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3302
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3303
 * Removes the http or https protocols and the domain. Keeps the path '/' at the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3304
 * beginning, so it isn't a true relative link, but from the web root base.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3305
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3306
 * @since 2.1.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3307
 * @since 4.1.0 Support was added for relative URLs.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3308
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3309
 * @param string $link Full URL path.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3310
 * @return string Absolute path.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3311
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3312
function wp_make_link_relative( $link ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3313
	return preg_replace( '|^(https?:)?//[^/]+(/.*)|i', '$2', $link );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3314
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3315
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3316
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3317
 * Sanitises various option values based on the nature of the option.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3318
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3319
 * This is basically a switch statement which will pass $value through a number
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3320
 * of functions depending on the $option.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3321
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3322
 * @since 2.0.5
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3323
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3324
 * @param string $option The name of the option.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3325
 * @param string $value The unsanitised value.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3326
 * @return string Sanitized value.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3327
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3328
function sanitize_option($option, $value) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3329
	global $wpdb;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3330
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3331
	switch ( $option ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3332
		case 'admin_email' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3333
		case 'new_admin_email' :
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3334
			$value = $wpdb->strip_invalid_text_for_column( $wpdb->options, 'option_value', $value );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3335
			$value = sanitize_email( $value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3336
			if ( ! is_email( $value ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3337
				$value = get_option( $option ); // Resets option to stored value in the case of failed sanitization
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3338
				if ( function_exists( 'add_settings_error' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3339
					add_settings_error( $option, 'invalid_admin_email', __( 'The email address entered did not appear to be a valid email address. Please enter a valid email address.' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3340
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3341
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3342
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3343
		case 'thumbnail_size_w':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3344
		case 'thumbnail_size_h':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3345
		case 'medium_size_w':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3346
		case 'medium_size_h':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3347
		case 'large_size_w':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3348
		case 'large_size_h':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3349
		case 'mailserver_port':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3350
		case 'comment_max_links':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3351
		case 'page_on_front':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3352
		case 'page_for_posts':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3353
		case 'rss_excerpt_length':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3354
		case 'default_category':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3355
		case 'default_email_category':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3356
		case 'default_link_category':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3357
		case 'close_comments_days_old':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3358
		case 'comments_per_page':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3359
		case 'thread_comments_depth':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3360
		case 'users_can_register':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3361
		case 'start_of_week':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3362
			$value = absint( $value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3363
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3364
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3365
		case 'posts_per_page':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3366
		case 'posts_per_rss':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3367
			$value = (int) $value;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3368
			if ( empty($value) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3369
				$value = 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3370
			if ( $value < -1 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3371
				$value = abs($value);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3372
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3373
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3374
		case 'default_ping_status':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3375
		case 'default_comment_status':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3376
			// Options that if not there have 0 value but need to be something like "closed"
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3377
			if ( $value == '0' || $value == '')
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3378
				$value = 'closed';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3379
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3380
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3381
		case 'blogdescription':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3382
		case 'blogname':
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3383
			$value = $wpdb->strip_invalid_text_for_column( $wpdb->options, 'option_value', $value );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3384
			$value = wp_kses_post( $value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3385
			$value = esc_html( $value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3386
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3387
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3388
		case 'blog_charset':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3389
			$value = preg_replace('/[^a-zA-Z0-9_-]/', '', $value); // strips slashes
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3390
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3391
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3392
		case 'blog_public':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3393
			// This is the value if the settings checkbox is not checked on POST. Don't rely on this.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3394
			if ( null === $value )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3395
				$value = 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3396
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3397
				$value = intval( $value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3398
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3399
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3400
		case 'date_format':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3401
		case 'time_format':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3402
		case 'mailserver_url':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3403
		case 'mailserver_login':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3404
		case 'mailserver_pass':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3405
		case 'upload_path':
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3406
			$value = $wpdb->strip_invalid_text_for_column( $wpdb->options, 'option_value', $value );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3407
			$value = strip_tags( $value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3408
			$value = wp_kses_data( $value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3409
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3410
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3411
		case 'ping_sites':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3412
			$value = explode( "\n", $value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3413
			$value = array_filter( array_map( 'trim', $value ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3414
			$value = array_filter( array_map( 'esc_url_raw', $value ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3415
			$value = implode( "\n", $value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3416
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3417
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3418
		case 'gmt_offset':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3419
			$value = preg_replace('/[^0-9:.-]/', '', $value); // strips slashes
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3420
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3421
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3422
		case 'siteurl':
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3423
			$value = $wpdb->strip_invalid_text_for_column( $wpdb->options, 'option_value', $value );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3424
			if ( (bool)preg_match( '#http(s?)://(.+)#i', $value) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3425
				$value = esc_url_raw($value);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3426
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3427
				$value = get_option( $option ); // Resets option to stored value in the case of failed sanitization
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3428
				if ( function_exists('add_settings_error') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3429
					add_settings_error('siteurl', 'invalid_siteurl', __('The WordPress address you entered did not appear to be a valid URL. Please enter a valid URL.'));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3430
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3431
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3432
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3433
		case 'home':
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3434
			$value = $wpdb->strip_invalid_text_for_column( $wpdb->options, 'option_value', $value );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3435
			if ( (bool)preg_match( '#http(s?)://(.+)#i', $value) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3436
				$value = esc_url_raw($value);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3437
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3438
				$value = get_option( $option ); // Resets option to stored value in the case of failed sanitization
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3439
				if ( function_exists('add_settings_error') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3440
					add_settings_error('home', 'invalid_home', __('The Site address you entered did not appear to be a valid URL. Please enter a valid URL.'));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3441
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3442
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3443
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3444
		case 'WPLANG':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3445
			$allowed = get_available_languages();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3446
			if ( ! is_multisite() && defined( 'WPLANG' ) && '' !== WPLANG && 'en_US' !== WPLANG ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3447
				$allowed[] = WPLANG;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3448
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3449
			if ( ! in_array( $value, $allowed ) && ! empty( $value ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3450
				$value = get_option( $option );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3451
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3452
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3453
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3454
		case 'illegal_names':
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3455
			$value = $wpdb->strip_invalid_text_for_column( $wpdb->options, 'option_value', $value );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3456
			if ( ! is_array( $value ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3457
				$value = explode( ' ', $value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3458
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3459
			$value = array_values( array_filter( array_map( 'trim', $value ) ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3460
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3461
			if ( ! $value )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3462
				$value = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3463
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3464
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3465
		case 'limited_email_domains':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3466
		case 'banned_email_domains':
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3467
			$value = $wpdb->strip_invalid_text_for_column( $wpdb->options, 'option_value', $value );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3468
			if ( ! is_array( $value ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3469
				$value = explode( "\n", $value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3470
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3471
			$domains = array_values( array_filter( array_map( 'trim', $value ) ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3472
			$value = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3473
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3474
			foreach ( $domains as $domain ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3475
				if ( ! preg_match( '/(--|\.\.)/', $domain ) && preg_match( '|^([a-zA-Z0-9-\.])+$|', $domain ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3476
					$value[] = $domain;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3477
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3478
			if ( ! $value )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3479
				$value = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3480
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3481
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3482
		case 'timezone_string':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3483
			$allowed_zones = timezone_identifiers_list();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3484
			if ( ! in_array( $value, $allowed_zones ) && ! empty( $value ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3485
				$value = get_option( $option ); // Resets option to stored value in the case of failed sanitization
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3486
				if ( function_exists('add_settings_error') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3487
					add_settings_error('timezone_string', 'invalid_timezone_string', __('The timezone you have entered is not valid. Please select a valid timezone.') );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3488
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3489
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3490
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3491
		case 'permalink_structure':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3492
		case 'category_base':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3493
		case 'tag_base':
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3494
			$value = $wpdb->strip_invalid_text_for_column( $wpdb->options, 'option_value', $value );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3495
			$value = esc_url_raw( $value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3496
			$value = str_replace( 'http://', '', $value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3497
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3498
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3499
		case 'default_role' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3500
			if ( ! get_role( $value ) && get_role( 'subscriber' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3501
				$value = 'subscriber';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3502
			break;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3503
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3504
		case 'moderation_keys':
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3505
		case 'blacklist_keys':
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3506
			$value = $wpdb->strip_invalid_text_for_column( $wpdb->options, 'option_value', $value );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3507
			$value = explode( "\n", $value );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3508
			$value = array_filter( array_map( 'trim', $value ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3509
			$value = array_unique( $value );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3510
			$value = implode( "\n", $value );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3511
			break;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3512
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3513
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3514
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3515
	 * Filter an option value following sanitization.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3516
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3517
	 * @since 2.3.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3518
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3519
	 * @param string $value  The sanitized option value.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3520
	 * @param string $option The option name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3521
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3522
	$value = apply_filters( "sanitize_option_{$option}", $value, $option );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3523
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3524
	return $value;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3525
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3526
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3527
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3528
 * Parses a string into variables to be stored in an array.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3529
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3530
 * Uses {@link http://www.php.net/parse_str parse_str()} and stripslashes if
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3531
 * {@link http://www.php.net/magic_quotes magic_quotes_gpc} is on.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3532
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3533
 * @since 2.2.1
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3534
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3535
 * @param string $string The string to be parsed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3536
 * @param array $array Variables will be stored in this array.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3537
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3538
function wp_parse_str( $string, &$array ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3539
	parse_str( $string, $array );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3540
	if ( get_magic_quotes_gpc() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3541
		$array = stripslashes_deep( $array );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3542
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3543
	 * Filter the array of variables derived from a parsed string.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3544
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3545
	 * @since 2.3.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3546
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3547
	 * @param array $array The array populated with variables.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3548
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3549
	$array = apply_filters( 'wp_parse_str', $array );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3550
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3551
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3552
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3553
 * Convert lone less than signs.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3554
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3555
 * KSES already converts lone greater than signs.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3556
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3557
 * @since 2.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3558
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3559
 * @param string $text Text to be converted.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3560
 * @return string Converted text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3561
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3562
function wp_pre_kses_less_than( $text ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3563
	return preg_replace_callback('%<[^>]*?((?=<)|>|$)%', 'wp_pre_kses_less_than_callback', $text);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3564
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3565
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3566
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3567
 * Callback function used by preg_replace.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3568
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3569
 * @since 2.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3570
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3571
 * @param array $matches Populated by matches to preg_replace.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3572
 * @return string The text returned after esc_html if needed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3573
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3574
function wp_pre_kses_less_than_callback( $matches ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3575
	if ( false === strpos($matches[0], '>') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3576
		return esc_html($matches[0]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3577
	return $matches[0];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3578
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3579
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3580
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3581
 * WordPress implementation of PHP sprintf() with filters.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3582
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3583
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3584
 * @link http://www.php.net/sprintf
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3585
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3586
 * @param string $pattern The string which formatted args are inserted.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3587
 * @param mixed  $args ,... Arguments to be formatted into the $pattern string.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3588
 * @return string The formatted string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3589
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3590
function wp_sprintf( $pattern ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3591
	$args = func_get_args();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3592
	$len = strlen($pattern);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3593
	$start = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3594
	$result = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3595
	$arg_index = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3596
	while ( $len > $start ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3597
		// Last character: append and break
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3598
		if ( strlen($pattern) - 1 == $start ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3599
			$result .= substr($pattern, -1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3600
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3601
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3602
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3603
		// Literal %: append and continue
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3604
		if ( substr($pattern, $start, 2) == '%%' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3605
			$start += 2;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3606
			$result .= '%';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3607
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3608
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3609
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3610
		// Get fragment before next %
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3611
		$end = strpos($pattern, '%', $start + 1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3612
		if ( false === $end )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3613
			$end = $len;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3614
		$fragment = substr($pattern, $start, $end - $start);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3615
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3616
		// Fragment has a specifier
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3617
		if ( $pattern[$start] == '%' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3618
			// Find numbered arguments or take the next one in order
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3619
			if ( preg_match('/^%(\d+)\$/', $fragment, $matches) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3620
				$arg = isset($args[$matches[1]]) ? $args[$matches[1]] : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3621
				$fragment = str_replace("%{$matches[1]}$", '%', $fragment);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3622
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3623
				++$arg_index;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3624
				$arg = isset($args[$arg_index]) ? $args[$arg_index] : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3625
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3626
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3627
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3628
			 * Filter a fragment from the pattern passed to wp_sprintf().
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3629
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3630
			 * If the fragment is unchanged, then sprintf() will be run on the fragment.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3631
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3632
			 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3633
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3634
			 * @param string $fragment A fragment from the pattern.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3635
			 * @param string $arg      The argument.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3636
			 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3637
			$_fragment = apply_filters( 'wp_sprintf', $fragment, $arg );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3638
			if ( $_fragment != $fragment )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3639
				$fragment = $_fragment;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3640
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3641
				$fragment = sprintf($fragment, strval($arg) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3642
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3643
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3644
		// Append to result and move to next fragment
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3645
		$result .= $fragment;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3646
		$start = $end;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3647
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3648
	return $result;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3649
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3650
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3651
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3652
 * Localize list items before the rest of the content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3653
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3654
 * The '%l' must be at the first characters can then contain the rest of the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3655
 * content. The list items will have ', ', ', and', and ' and ' added depending
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3656
 * on the amount of list items in the $args parameter.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3657
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3658
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3659
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3660
 * @param string $pattern Content containing '%l' at the beginning.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3661
 * @param array $args List items to prepend to the content and replace '%l'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3662
 * @return string Localized list items and rest of the content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3663
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3664
function wp_sprintf_l($pattern, $args) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3665
	// Not a match
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3666
	if ( substr($pattern, 0, 2) != '%l' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3667
		return $pattern;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3668
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3669
	// Nothing to work with
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3670
	if ( empty($args) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3671
		return '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3672
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3673
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3674
	 * Filter the translated delimiters used by wp_sprintf_l().
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3675
	 * Placeholders (%s) are included to assist translators and then
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3676
	 * removed before the array of strings reaches the filter.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3677
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3678
	 * Please note: Ampersands and entities should be avoided here.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3679
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3680
	 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3681
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3682
	 * @param array $delimiters An array of translated delimiters.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3683
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3684
	$l = apply_filters( 'wp_sprintf_l', array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3685
		/* translators: used to join items in a list with more than 2 items */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3686
		'between'          => sprintf( __('%s, %s'), '', '' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3687
		/* translators: used to join last two items in a list with more than 2 times */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3688
		'between_last_two' => sprintf( __('%s, and %s'), '', '' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3689
		/* translators: used to join items in a list with only 2 items */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3690
		'between_only_two' => sprintf( __('%s and %s'), '', '' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3691
	) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3692
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3693
	$args = (array) $args;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3694
	$result = array_shift($args);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3695
	if ( count($args) == 1 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3696
		$result .= $l['between_only_two'] . array_shift($args);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3697
	// Loop when more than two args
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3698
	$i = count($args);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3699
	while ( $i ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3700
		$arg = array_shift($args);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3701
		$i--;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3702
		if ( 0 == $i )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3703
			$result .= $l['between_last_two'] . $arg;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3704
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3705
			$result .= $l['between'] . $arg;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3706
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3707
	return $result . substr($pattern, 2);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3708
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3709
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3710
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3711
 * Safely extracts not more than the first $count characters from html string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3712
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3713
 * UTF-8, tags and entities safe prefix extraction. Entities inside will *NOT*
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3714
 * be counted as one character. For example &amp; will be counted as 4, &lt; as
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3715
 * 3, etc.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3716
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3717
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3718
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3719
 * @param string $str String to get the excerpt from.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3720
 * @param integer $count Maximum number of characters to take.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3721
 * @param string $more Optional. What to append if $str needs to be trimmed. Defaults to empty string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3722
 * @return string The excerpt.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3723
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3724
function wp_html_excerpt( $str, $count, $more = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3725
	if ( null === $more )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3726
		$more = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3727
	$str = wp_strip_all_tags( $str, true );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3728
	$excerpt = mb_substr( $str, 0, $count );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3729
	// remove part of an entity at the end
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3730
	$excerpt = preg_replace( '/&[^;\s]{0,6}$/', '', $excerpt );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3731
	if ( $str != $excerpt )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3732
		$excerpt = trim( $excerpt ) . $more;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3733
	return $excerpt;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3734
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3735
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3736
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3737
 * Add a Base url to relative links in passed content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3738
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3739
 * By default it supports the 'src' and 'href' attributes. However this can be
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3740
 * changed via the 3rd param.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3741
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3742
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3743
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3744
 * @param string $content String to search for links in.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3745
 * @param string $base The base URL to prefix to links.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3746
 * @param array $attrs The attributes which should be processed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3747
 * @return string The processed content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3748
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3749
function links_add_base_url( $content, $base, $attrs = array('src', 'href') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3750
	global $_links_add_base;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3751
	$_links_add_base = $base;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3752
	$attrs = implode('|', (array)$attrs);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3753
	return preg_replace_callback( "!($attrs)=(['\"])(.+?)\\2!i", '_links_add_base', $content );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3754
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3755
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3756
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3757
 * Callback to add a base url to relative links in passed content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3758
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3759
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3760
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3761
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3762
 * @param string $m The matched link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3763
 * @return string The processed link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3764
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3765
function _links_add_base($m) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3766
	global $_links_add_base;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3767
	//1 = attribute name  2 = quotation mark  3 = URL
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3768
	return $m[1] . '=' . $m[2] .
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3769
		( preg_match( '#^(\w{1,20}):#', $m[3], $protocol ) && in_array( $protocol[1], wp_allowed_protocols() ) ?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3770
			$m[3] :
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3771
			WP_HTTP::make_absolute_url( $m[3], $_links_add_base )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3772
		)
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3773
		. $m[2];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3774
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3775
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3776
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3777
 * Adds a Target attribute to all links in passed content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3778
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3779
 * This function by default only applies to `<a>` tags, however this can be
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3780
 * modified by the 3rd param.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3781
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3782
 * *NOTE:* Any current target attributed will be stripped and replaced.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3783
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3784
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3785
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3786
 * @param string $content String to search for links in.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3787
 * @param string $target The Target to add to the links.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3788
 * @param array $tags An array of tags to apply to.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3789
 * @return string The processed content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3790
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3791
function links_add_target( $content, $target = '_blank', $tags = array('a') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3792
	global $_links_add_target;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3793
	$_links_add_target = $target;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3794
	$tags = implode('|', (array)$tags);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3795
	return preg_replace_callback( "!<($tags)([^>]*)>!i", '_links_add_target', $content );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3796
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3797
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3798
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3799
 * Callback to add a target attribute to all links in passed content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3800
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3801
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3802
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3803
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3804
 * @param string $m The matched link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3805
 * @return string The processed link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3806
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3807
function _links_add_target( $m ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3808
	global $_links_add_target;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3809
	$tag = $m[1];
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3810
	$link = preg_replace('|( target=([\'"])(.*?)\2)|i', '', $m[2]);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3811
	return '<' . $tag . $link . ' target="' . esc_attr( $_links_add_target ) . '">';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3812
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3813
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3814
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3815
 * Normalize EOL characters and strip duplicate whitespace.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3816
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3817
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3818
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3819
 * @param string $str The string to normalize.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3820
 * @return string The normalized string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3821
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3822
function normalize_whitespace( $str ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3823
	$str  = trim( $str );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3824
	$str  = str_replace( "\r", "\n", $str );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3825
	$str  = preg_replace( array( '/\n+/', '/[ \t]+/' ), array( "\n", ' ' ), $str );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3826
	return $str;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3827
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3828
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3829
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3830
 * Properly strip all HTML tags including script and style
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3831
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3832
 * This differs from strip_tags() because it removes the contents of
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3833
 * the `<script>` and `<style>` tags. E.g. `strip_tags( '<script>something</script>' )`
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3834
 * will return 'something'. wp_strip_all_tags will return ''
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3835
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3836
 * @since 2.9.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3837
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3838
 * @param string $string String containing HTML tags
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3839
 * @param bool $remove_breaks optional Whether to remove left over line breaks and white space chars
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3840
 * @return string The processed string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3841
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3842
function wp_strip_all_tags($string, $remove_breaks = false) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3843
	$string = preg_replace( '@<(script|style)[^>]*?>.*?</\\1>@si', '', $string );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3844
	$string = strip_tags($string);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3845
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3846
	if ( $remove_breaks )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3847
		$string = preg_replace('/[\r\n\t ]+/', ' ', $string);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3848
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3849
	return trim( $string );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3850
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3851
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3852
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3853
 * Sanitize a string from user input or from the db
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3854
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3855
 * check for invalid UTF-8,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3856
 * Convert single < characters to entity,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3857
 * strip all tags,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3858
 * remove line breaks, tabs and extra white space,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3859
 * strip octets.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3860
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3861
 * @since 2.9.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3862
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3863
 * @param string $str
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3864
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3865
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3866
function sanitize_text_field($str) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3867
	$filtered = wp_check_invalid_utf8( $str );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3868
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3869
	if ( strpos($filtered, '<') !== false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3870
		$filtered = wp_pre_kses_less_than( $filtered );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3871
		// This will strip extra whitespace for us.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3872
		$filtered = wp_strip_all_tags( $filtered, true );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3873
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3874
		$filtered = trim( preg_replace('/[\r\n\t ]+/', ' ', $filtered) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3875
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3876
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3877
	$found = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3878
	while ( preg_match('/%[a-f0-9]{2}/i', $filtered, $match) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3879
		$filtered = str_replace($match[0], '', $filtered);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3880
		$found = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3881
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3882
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3883
	if ( $found ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3884
		// Strip out the whitespace that may now exist after removing the octets.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3885
		$filtered = trim( preg_replace('/ +/', ' ', $filtered) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3886
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3887
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3888
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3889
	 * Filter a sanitized text field string.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3890
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3891
	 * @since 2.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3892
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3893
	 * @param string $filtered The sanitized string.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3894
	 * @param string $str      The string prior to being sanitized.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3895
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3896
	return apply_filters( 'sanitize_text_field', $filtered, $str );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3897
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3898
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3899
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3900
 * i18n friendly version of basename()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3901
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3902
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3903
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3904
 * @param string $path A path.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3905
 * @param string $suffix If the filename ends in suffix this will also be cut off.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3906
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3907
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3908
function wp_basename( $path, $suffix = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3909
	return urldecode( basename( str_replace( array( '%2F', '%5C' ), '/', urlencode( $path ) ), $suffix ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3910
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3911
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3912
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3913
 * Forever eliminate "Wordpress" from the planet (or at least the little bit we can influence).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3914
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3915
 * Violating our coding standards for a good function name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3916
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3917
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3918
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3919
function capital_P_dangit( $text ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3920
	// Simple replacement for titles
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3921
	$current_filter = current_filter();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3922
	if ( 'the_title' === $current_filter || 'wp_title' === $current_filter )
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3923
		return str_replace( 'Wordpress', 'WordPress', $text );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3924
	// Still here? Use the more judicious replacement
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3925
	static $dblq = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3926
	if ( false === $dblq )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3927
		$dblq = _x( '&#8220;', 'opening curly double quote' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3928
	return str_replace(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3929
		array( ' Wordpress', '&#8216;Wordpress', $dblq . 'Wordpress', '>Wordpress', '(Wordpress' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3930
		array( ' WordPress', '&#8216;WordPress', $dblq . 'WordPress', '>WordPress', '(WordPress' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3931
	$text );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3932
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3933
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3934
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3935
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3936
 * Sanitize a mime type
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3937
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3938
 * @since 3.1.3
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3939
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3940
 * @param string $mime_type Mime type
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3941
 * @return string Sanitized mime type
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3942
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3943
function sanitize_mime_type( $mime_type ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3944
	$sani_mime_type = preg_replace( '/[^-+*.a-zA-Z0-9\/]/', '', $mime_type );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3945
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3946
	 * Filter a mime type following sanitization.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3947
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3948
	 * @since 3.1.3
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3949
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3950
	 * @param string $sani_mime_type The sanitized mime type.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3951
	 * @param string $mime_type      The mime type prior to sanitization.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3952
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3953
	return apply_filters( 'sanitize_mime_type', $sani_mime_type, $mime_type );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3954
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3955
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3956
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3957
 * Sanitize space or carriage return separated URLs that are used to send trackbacks.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3958
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3959
 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3960
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3961
 * @param string $to_ping Space or carriage return separated URLs
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3962
 * @return string URLs starting with the http or https protocol, separated by a carriage return.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3963
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3964
function sanitize_trackback_urls( $to_ping ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3965
	$urls_to_ping = preg_split( '/[\r\n\t ]/', trim( $to_ping ), -1, PREG_SPLIT_NO_EMPTY );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3966
	foreach ( $urls_to_ping as $k => $url ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3967
		if ( !preg_match( '#^https?://.#i', $url ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3968
			unset( $urls_to_ping[$k] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3969
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3970
	$urls_to_ping = array_map( 'esc_url_raw', $urls_to_ping );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3971
	$urls_to_ping = implode( "\n", $urls_to_ping );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3972
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3973
	 * Filter a list of trackback URLs following sanitization.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3974
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3975
	 * The string returned here consists of a space or carriage return-delimited list
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3976
	 * of trackback URLs.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3977
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3978
	 * @since 3.4.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3979
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3980
	 * @param string $urls_to_ping Sanitized space or carriage return separated URLs.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3981
	 * @param string $to_ping      Space or carriage return separated URLs before sanitization.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3982
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3983
	return apply_filters( 'sanitize_trackback_urls', $urls_to_ping, $to_ping );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3984
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3985
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3986
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3987
 * Add slashes to a string or array of strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3988
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3989
 * This should be used when preparing data for core API that expects slashed data.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3990
 * This should not be used to escape data going directly into an SQL query.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3991
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3992
 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3993
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3994
 * @param string|array $value String or array of strings to slash.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3995
 * @return string|array Slashed $value
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3996
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3997
function wp_slash( $value ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3998
	if ( is_array( $value ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3999
		foreach ( $value as $k => $v ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4000
			if ( is_array( $v ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4001
				$value[$k] = wp_slash( $v );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4002
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4003
				$value[$k] = addslashes( $v );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4004
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4005
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4006
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4007
		$value = addslashes( $value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4008
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4009
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4010
	return $value;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4011
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4012
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4013
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4014
 * Remove slashes from a string or array of strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4015
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4016
 * This should be used to remove slashes from data passed to core API that
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4017
 * expects data to be unslashed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4018
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4019
 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4020
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4021
 * @param string|array $value String or array of strings to unslash.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4022
 * @return string|array Unslashed $value
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4023
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4024
function wp_unslash( $value ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4025
	return stripslashes_deep( $value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4026
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4027
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4028
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4029
 * Extract and return the first URL from passed content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4030
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4031
 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4032
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4033
 * @param string $content A string which might contain a URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4034
 * @return string The found URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4035
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4036
function get_url_in_content( $content ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4037
	if ( empty( $content ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4038
		return false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4039
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4040
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4041
	if ( preg_match( '/<a\s[^>]*?href=([\'"])(.+?)\1/is', $content, $matches ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4042
		return esc_url_raw( $matches[2] );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4043
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4044
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4045
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4046
}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4047
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4048
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4049
 * Returns the regexp for common whitespace characters.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4050
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4051
 * By default, spaces include new lines, tabs, nbsp entities, and the UTF-8 nbsp.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4052
 * This is designed to replace the PCRE \s sequence.  In ticket #22692, that
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4053
 * sequence was found to be unreliable due to random inclusion of the A0 byte.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4054
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4055
 * @since 4.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4056
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4057
 * @return string The spaces regexp.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4058
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4059
function wp_spaces_regexp() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4060
	static $spaces;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4061
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4062
	if ( empty( $spaces ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4063
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4064
		 * Filter the regexp for common whitespace characters.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4065
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4066
		 * This string is substituted for the \s sequence as needed in regular
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4067
		 * expressions. For websites not written in English, different characters
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4068
		 * may represent whitespace. For websites not encoded in UTF-8, the 0xC2 0xA0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4069
		 * sequence may not be in use.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4070
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4071
		 * @since 4.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4072
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4073
		 * @param string $spaces Regexp pattern for matching common whitespace characters.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4074
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4075
		$spaces = apply_filters( 'wp_spaces_regexp', '[\r\n\t ]|\xC2\xA0|&nbsp;' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4076
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4077
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4078
	return $spaces;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4079
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4080
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4081
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4082
 * Print the important emoji-related styles.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4083
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4084
 * @since 4.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4085
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4086
function print_emoji_styles() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4087
	static $printed = false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4088
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4089
	if ( $printed ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4090
		return;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4091
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4092
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4093
	$printed = true;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4094
?>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4095
<style type="text/css">
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4096
img.wp-smiley,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4097
img.emoji {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4098
	display: inline !important;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4099
	border: none !important;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4100
	box-shadow: none !important;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4101
	height: 1em !important;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4102
	width: 1em !important;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4103
	margin: 0 .07em !important;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4104
	vertical-align: -0.1em !important;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4105
	background: none !important;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4106
	padding: 0 !important;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4107
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4108
</style>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4109
<?php
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4110
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4111
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4112
function print_emoji_detection_script() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4113
	global $wp_version;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4114
	static $printed = false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4115
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4116
	if ( $printed ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4117
		return;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4118
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4119
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4120
	$printed = true;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4121
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4122
	$settings = array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4123
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4124
		 * Filter the URL where emoji images are hosted.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4125
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4126
		 * @since 4.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4127
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4128
		 * @param string The emoji base URL.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4129
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4130
		'baseUrl' => apply_filters( 'emoji_url', set_url_scheme( '//s.w.org/images/core/emoji/72x72/' ) ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4131
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4132
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4133
		 * Filter the extension of the emoji files.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4134
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4135
		 * @since 4.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4136
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4137
		 * @param string The emoji extension. Default .png.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4138
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4139
		'ext' => apply_filters( 'emoji_ext', '.png' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4140
	);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4141
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4142
	$version = 'ver=' . $wp_version;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4143
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4144
	if ( SCRIPT_DEBUG ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4145
		$settings['source'] = array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4146
			/** This filter is documented in wp-includes/class.wp-scripts.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4147
			'wpemoji' => apply_filters( 'script_loader_src', includes_url( "js/wp-emoji.js?$version" ), 'wpemoji' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4148
			/** This filter is documented in wp-includes/class.wp-scripts.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4149
			'twemoji' => apply_filters( 'script_loader_src', includes_url( "js/twemoji.js?$version" ), 'twemoji' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4150
		);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4151
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4152
		?>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4153
		<script type="text/javascript">
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4154
			window._wpemojiSettings = <?php echo wp_json_encode( $settings ); ?>;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4155
			<?php readfile( ABSPATH . WPINC . "/js/wp-emoji-loader.js" ); ?>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4156
		</script>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4157
		<?php
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4158
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4159
		$settings['source'] = array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4160
			/** This filter is documented in wp-includes/class.wp-scripts.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4161
			'concatemoji' => apply_filters( 'script_loader_src', includes_url( "js/wp-emoji-release.min.js?$version" ), 'concatemoji' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4162
		);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4163
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4164
		/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4165
		 * If you're looking at a src version of this file, you'll see an "include"
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4166
		 * statement below. This is used by the `grunt build` process to directly
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4167
		 * include a minified version of wp-emoji-loader.js, instead of using the
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4168
		 * readfile() method from above.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4169
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4170
		 * If you're looking at a build version of this file, you'll see a string of
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4171
		 * minified JavaScript. If you need to debug it, please turn on SCRIPT_DEBUG
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4172
		 * and edit wp-emoji-loader.js directly.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4173
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4174
		?>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4175
		<script type="text/javascript">
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4176
			window._wpemojiSettings = <?php echo wp_json_encode( $settings ); ?>;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4177
			!function(a,b,c){function d(a){var c=b.createElement("canvas"),d=c.getContext&&c.getContext("2d");return d&&d.fillText?(d.textBaseline="top",d.font="600 32px Arial","flag"===a?(d.fillText(String.fromCharCode(55356,56812,55356,56807),0,0),c.toDataURL().length>3e3):(d.fillText(String.fromCharCode(55357,56835),0,0),0!==d.getImageData(16,16,1,1).data[0])):!1}function e(a){var c=b.createElement("script");c.src=a,c.type="text/javascript",b.getElementsByTagName("head")[0].appendChild(c)}var f,g;c.supports={simple:d("simple"),flag:d("flag")},c.DOMReady=!1,c.readyCallback=function(){c.DOMReady=!0},c.supports.simple&&c.supports.flag||(g=function(){c.readyCallback()},b.addEventListener?(b.addEventListener("DOMContentLoaded",g,!1),a.addEventListener("load",g,!1)):(a.attachEvent("onload",g),b.attachEvent("onreadystatechange",function(){"complete"===b.readyState&&c.readyCallback()})),f=c.source||{},f.concatemoji?e(f.concatemoji):f.wpemoji&&f.twemoji&&(e(f.twemoji),e(f.wpemoji)))}(window,document,window._wpemojiSettings);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4178
		</script>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4179
		<?php
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4180
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4181
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4182
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4183
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4184
 * Convert any 4 byte emoji in a string to their equivalent HTML entity.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4185
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4186
 * Currently, only Unicode 7 emoji are supported. Skin tone modifiers are allowed,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4187
 * all other Unicode 8 emoji will be added when the spec is finalised.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4188
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4189
 * This allows us to store emoji in a DB using the utf8 character set.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4190
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4191
 * @since 4.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4192
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4193
 * @param string $content The content to encode.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4194
 * @return string The encoded content.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4195
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4196
function wp_encode_emoji( $content ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4197
	if ( function_exists( 'mb_convert_encoding' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4198
		$regex = '/(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4199
		     \x23\xE2\x83\xA3               # Digits
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4200
		     [\x30-\x39]\xE2\x83\xA3
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4201
		   | \xF0\x9F[\x85-\x88][\xA6-\xBF] # Enclosed characters
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4202
		   | \xF0\x9F[\x8C-\x97][\x80-\xBF] # Misc
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4203
		   | \xF0\x9F\x98[\x80-\xBF]        # Smilies
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4204
		   | \xF0\x9F\x99[\x80-\x8F]
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4205
		   | \xF0\x9F\x9A[\x80-\xBF]        # Transport and map symbols
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4206
		)/x';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4207
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4208
		$matches = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4209
		if ( preg_match_all( $regex, $content, $matches ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4210
			if ( ! empty( $matches[1] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4211
				foreach( $matches[1] as $emoji ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4212
					/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4213
					 * UTF-32's hex encoding is the same as HTML's hex encoding.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4214
					 * So, by converting the emoji from UTF-8 to UTF-32, we magically
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4215
					 * get the correct hex encoding.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4216
					 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4217
					$unpacked = unpack( 'H*', mb_convert_encoding( $emoji, 'UTF-32', 'UTF-8' ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4218
					if ( isset( $unpacked[1] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4219
						$entity = '&#x' . ltrim( $unpacked[1], '0' ) . ';';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4220
						$content = str_replace( $emoji, $entity, $content );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4221
					}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4222
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4223
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4224
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4225
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4226
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4227
	return $content;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4228
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4229
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4230
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4231
 * Convert emoji to a static img element.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4232
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4233
 * @since 4.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4234
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4235
 * @param string $text The content to encode.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4236
 * @return string The encoded content.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4237
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4238
function wp_staticize_emoji( $text ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4239
	$text = wp_encode_emoji( $text );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4240
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4241
	/** This filter is documented in wp-includes/formatting.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4242
	$cdn_url = apply_filters( 'emoji_url', set_url_scheme( '//s.w.org/images/core/emoji/72x72/' ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4243
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4244
	/** This filter is documented in wp-includes/formatting.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4245
	$ext = apply_filters( 'emoji_ext', '.png' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4246
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4247
	$output = '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4248
	/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4249
	 * HTML loop taken from smiley function, which was taken from texturize function.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4250
	 * It'll never be consolidated.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4251
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4252
	 * First, capture the tags as well as in between.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4253
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4254
	$textarr = preg_split( '/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4255
	$stop = count( $textarr );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4256
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4257
	// Ignore processing of specific tags.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4258
	$tags_to_ignore = 'code|pre|style|script|textarea';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4259
	$ignore_block_element = '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4260
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4261
	for ( $i = 0; $i < $stop; $i++ ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4262
		$content = $textarr[$i];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4263
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4264
		// If we're in an ignore block, wait until we find its closing tag.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4265
		if ( '' == $ignore_block_element && preg_match( '/^<(' . $tags_to_ignore . ')>/', $content, $matches ) )  {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4266
			$ignore_block_element = $matches[1];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4267
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4268
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4269
		// If it's not a tag and not in ignore block.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4270
		if ( '' ==  $ignore_block_element && strlen( $content ) > 0 && '<' != $content[0] ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4271
			$matches = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4272
			if ( preg_match_all( '/(&#x1f1(e[6-9a-f]|f[0-9a-f]);){2}/', $content, $matches ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4273
				if ( ! empty( $matches[0] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4274
					foreach ( $matches[0] as $flag ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4275
						$chars = str_replace( array( '&#x', ';'), '', $flag );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4276
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4277
						list( $char1, $char2 ) = str_split( $chars, 5 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4278
						$entity = sprintf( '<img src="%s" alt="%s" class="wp-smiley" style="height: 1em; max-height: 1em;" />', $cdn_url . $char1 . '-' . $char2 . $ext, html_entity_decode( $flag ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4279
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4280
						$content = str_replace( $flag, $entity, $content );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4281
					}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4282
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4283
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4284
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4285
			// Loosely match the Emoji Unicode range.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4286
			$regex = '/(&#x[2-3][0-9a-f]{3};|&#x1f[1-6][0-9a-f]{2};)/';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4287
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4288
			$matches = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4289
			if ( preg_match_all( $regex, $content, $matches ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4290
				if ( ! empty( $matches[1] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4291
					foreach ( $matches[1] as $emoji ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4292
						$char = str_replace( array( '&#x', ';'), '', $emoji );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4293
						$entity = sprintf( '<img src="%s" alt="%s" class="wp-smiley" style="height: 1em; max-height: 1em;" />', $cdn_url . $char . $ext, html_entity_decode( $emoji ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4294
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4295
						$content = str_replace( $emoji, $entity, $content );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4296
					}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4297
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4298
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4299
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4300
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4301
		// Did we exit ignore block.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4302
		if ( '' != $ignore_block_element && '</' . $ignore_block_element . '>' == $content )  {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4303
			$ignore_block_element = '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4304
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4305
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4306
		$output .= $content;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4307
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4308
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4309
	return $output;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4310
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4311
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4312
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4313
 * Convert emoji in emails into static images.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4314
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4315
 * @since 4.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4316
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4317
 * @param array $mail The email data array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4318
 * @return array The email data array, with emoji in the message staticized.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4319
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4320
function wp_staticize_emoji_for_email( $mail ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4321
	if ( ! isset( $mail['message'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4322
		return $mail;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4323
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4324
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4325
	/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4326
	 * We can only transform the emoji into images if it's a text/html email.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4327
	 * To do that, here's a cut down version of the same process that happens
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4328
	 * in wp_mail() - get the Content-Type from the headers, if there is one,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4329
	 * then pass it through the wp_mail_content_type filter, in case a plugin
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4330
	 * is handling changing the Content-Type.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4331
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4332
	$headers = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4333
	if ( isset( $mail['headers'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4334
		if ( is_array( $mail['headers'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4335
			$headers = $mail['headers'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4336
		} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4337
			$headers = explode( "\n", str_replace( "\r\n", "\n", $mail['headers'] ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4338
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4339
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4340
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4341
	foreach ( $headers as $header ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4342
		if ( strpos($header, ':') === false ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4343
			continue;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4344
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4345
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4346
		// Explode them out.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4347
		list( $name, $content ) = explode( ':', trim( $header ), 2 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4348
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4349
		// Cleanup crew.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4350
		$name    = trim( $name    );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4351
		$content = trim( $content );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4352
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4353
		if ( 'content-type' === strtolower( $name ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4354
			if ( strpos( $content, ';' ) !== false ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4355
				list( $type, $charset ) = explode( ';', $content );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4356
				$content_type = trim( $type );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4357
			} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4358
				$content_type = trim( $content );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4359
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4360
			break;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4361
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4362
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4363
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4364
	// Set Content-Type if we don't have a content-type from the input headers.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4365
	if ( ! isset( $content_type ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4366
		$content_type = 'text/plain';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4367
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4368
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4369
	/** This filter is documented in wp-includes/pluggable.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4370
	$content_type = apply_filters( 'wp_mail_content_type', $content_type );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4371
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4372
	if ( 'text/html' === $content_type ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4373
		$mail['message'] = wp_staticize_emoji( $mail['message'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4374
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4375
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4376
	return $mail;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4377
}