*/
function wptexturize($text) {
global $wp_cockneyreplace;
- static $opening_quote, $closing_quote, $en_dash, $em_dash, $default_no_texturize_tags, $default_no_texturize_shortcodes, $static_characters, $static_replacements, $dynamic_characters, $dynamic_replacements;
+ static $static_characters, $static_replacements, $dynamic_characters, $dynamic_replacements,
+ $default_no_texturize_tags, $default_no_texturize_shortcodes;
// No need to set up these static variables more than once
- if ( empty( $opening_quote ) ) {
- /* translators: opening curly quote */
- $opening_quote = _x('“', 'opening curly quote');
- /* translators: closing curly quote */
- $closing_quote = _x('”', 'closing curly quote');
+ if ( ! isset( $static_characters ) ) {
+ /* translators: opening curly double quote */
+ $opening_quote = _x( '“', 'opening curly double quote' );
+ /* translators: closing curly double quote */
+ $closing_quote = _x( '”', 'closing curly double quote' );
+
+ /* translators: apostrophe, for example in 'cause or can't */
+ $apos = _x( '’', 'apostrophe' );
+
+ /* translators: prime, for example in 9' (nine feet) */
+ $prime = _x( '′', 'prime' );
+ /* translators: double prime, for example in 9" (nine inches) */
+ $double_prime = _x( '″', 'double prime' );
+
+ /* translators: opening curly single quote */
+ $opening_single_quote = _x( '‘', 'opening curly single quote' );
+ /* translators: closing curly single quote */
+ $closing_single_quote = _x( '’', 'closing curly single quote' );
+
/* translators: en dash */
- $en_dash = _x('–', 'en dash');
+ $en_dash = _x( '–', 'en dash' );
/* translators: em dash */
- $em_dash = _x('—', 'em dash');
+ $em_dash = _x( '—', 'em dash' );
$default_no_texturize_tags = array('pre', 'code', 'kbd', 'style', 'script', 'tt');
$default_no_texturize_shortcodes = array('code');
if ( isset($wp_cockneyreplace) ) {
$cockney = array_keys($wp_cockneyreplace);
$cockneyreplace = array_values($wp_cockneyreplace);
+ } elseif ( "'" != $apos ) { // Only bother if we're doing a replacement.
+ $cockney = array( "'tain't", "'twere", "'twas", "'tis", "'twill", "'til", "'bout", "'nuff", "'round", "'cause" );
+ $cockneyreplace = array( $apos . "tain" . $apos . "t", $apos . "twere", $apos . "twas", $apos . "tis", $apos . "twill", $apos . "til", $apos . "bout", $apos . "nuff", $apos . "round", $apos . "cause" );
} else {
- $cockney = array("'tain't","'twere","'twas","'tis","'twill","'til","'bout","'nuff","'round","'cause");
- $cockneyreplace = array("’tain’t","’twere","’twas","’tis","’twill","’til","’bout","’nuff","’round","’cause");
+ $cockney = $cockneyreplace = array();
}
- $static_characters = array_merge( array('---', ' -- ', '--', ' - ', 'xn–', '...', '``', '\'\'', ' (tm)'), $cockney );
- $static_replacements = array_merge( array($em_dash, ' ' . $em_dash . ' ', $en_dash, ' ' . $en_dash . ' ', 'xn--', '…', $opening_quote, $closing_quote, ' ™'), $cockneyreplace );
+ $static_characters = array_merge( array( '---', ' -- ', '--', ' - ', 'xn–', '...', '``', '\'\'', ' (tm)' ), $cockney );
+ $static_replacements = array_merge( array( $em_dash, ' ' . $em_dash . ' ', $en_dash, ' ' . $en_dash . ' ', 'xn--', '…', $opening_quote, $closing_quote, ' ™' ), $cockneyreplace );
- $dynamic_characters = array('/\'(\d\d(?:’|\')?s)/', '/\'(\d)/', '/(\s|\A|[([{<]|")\'/', '/(\d)"/', '/(\d)\'/', '/(\S)\'([^\'\s])/', '/(\s|\A|[([{<])"(?!\s)/', '/"(\s|\S|\Z)/', '/\'([\s.]|\Z)/', '/\b(\d+)x(\d+)\b/');
- $dynamic_replacements = array('’$1','’$1', '$1‘', '$1″', '$1′', '$1’$2', '$1' . $opening_quote . '$2', $closing_quote . '$1', '’$1', '$1×$2');
+ $dynamic = array();
+ if ( "'" != $apos ) {
+ $dynamic[ '/\'(\d\d(?:’|\')?s)/' ] = $apos . '$1'; // '99's
+ $dynamic[ '/\'(\d)/' ] = $apos . '$1'; // '99
+ }
+ if ( "'" != $opening_single_quote )
+ $dynamic[ '/(\s|\A|[([{<]|")\'/' ] = '$1' . $opening_single_quote; // opening single quote, even after (, {, <, [
+ if ( '"' != $double_prime )
+ $dynamic[ '/(\d)"/' ] = '$1' . $double_prime; // 9" (double prime)
+ if ( "'" != $prime )
+ $dynamic[ '/(\d)\'/' ] = '$1' . $prime; // 9' (prime)
+ if ( "'" != $apos )
+ $dynamic[ '/(\S)\'([^\'\s])/' ] = '$1' . $apos . '$2'; // apostrophe in a word
+ if ( '"' != $opening_quote )
+ $dynamic[ '/(\s|\A|[([{<])"(?!\s)/' ] = '$1' . $opening_quote . '$2'; // opening double quote, even after (, {, <, [
+ if ( '"' != $closing_quote )
+ $dynamic[ '/"(\s|\S|\Z)/' ] = $closing_quote . '$1'; // closing double quote
+ if ( "'" != $closing_single_quote )
+ $dynamic[ '/\'([\s.]|\Z)/' ] = $closing_single_quote . '$1'; // closing single quote
+
+ $dynamic[ '/\b(\d+)x(\d+)\b/' ] = '$1×$2'; // 9x9 (times)
+
+ $dynamic_characters = array_keys( $dynamic );
+ $dynamic_replacements = array_values( $dynamic );
}
// Transform into regexp sub-expression used in _wptexturize_pushpop_element
}
}
-/**
- * Accepts matches array from preg_replace_callback in wpautop() or a string.
- *
- * Ensures that the contents of a <<pre>>...<</pre>> HTML block are not
- * converted into paragraphs or line-breaks.
- *
- * @since 1.2.0
- *
- * @param array|string $matches The array or string
- * @return string The pre block without paragraph/line-break conversion.
- */
-function clean_pre($matches) {
- if ( is_array($matches) )
- $text = $matches[1] . $matches[2] . "</pre>";
- else
- $text = $matches;
-
- $text = str_replace('<br />', '', $text);
- $text = str_replace('<p>', "\n", $text);
- $text = str_replace('</p>', '', $text);
-
- return $text;
-}
-
/**
* Replaces double line-breaks with paragraph elements.
*
* @since 0.71
*
* @param string $pee The text which has to be formatted.
- * @param int|bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
+ * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
* @return string Text which has been converted into correct paragraph tags.
*/
-function wpautop($pee, $br = 1) {
+function wpautop($pee, $br = true) {
+ $pre_tags = array();
if ( trim($pee) === '' )
return '';
+
$pee = $pee . "\n"; // just to make things a little easier, pad the end
+
+ if ( strpos($pee, '<pre') !== false ) {
+ $pee_parts = explode( '</pre>', $pee );
+ $last_pee = array_pop($pee_parts);
+ $pee = '';
+ $i = 0;
+
+ foreach ( $pee_parts as $pee_part ) {
+ $start = strpos($pee_part, '<pre');
+
+ // Malformed html?
+ if ( $start === false ) {
+ $pee .= $pee_part;
+ continue;
+ }
+
+ $name = "<pre wp-pre-tag-$i></pre>";
+ $pre_tags[$name] = substr( $pee_part, $start ) . '</pre>';
+
+ $pee .= substr( $pee_part, 0, $start ) . $name;
+ $i++;
+ }
+
+ $pee .= $last_pee;
+ }
+
$pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
// Space things out a little
- $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|option|form|map|area|blockquote|address|math|style|input|p|h[1-6]|hr|fieldset|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
+ $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|option|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)';
$pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee);
$pee = preg_replace('!(</' . $allblocks . '>)!', "$1\n\n", $pee);
$pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines
$pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
$pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "$1", $pee);
$pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee);
- if ($br) {
+ if ( $br ) {
$pee = preg_replace_callback('/<(script|style).*?<\/\\1>/s', '_autop_newline_preservation_helper', $pee);
$pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee); // optionally make line breaks
$pee = str_replace('<WPPreserveNewline />', "\n", $pee);
}
$pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "$1", $pee);
$pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
- if (strpos($pee, '<pre') !== false)
- $pee = preg_replace_callback('!(<pre[^>]*>)(.*?)</pre>!is', 'clean_pre', $pee );
$pee = preg_replace( "|\n</p>$|", '</p>', $pee );
+ if ( !empty($pre_tags) )
+ $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
+
return $pee;
}
// Euro Sign
chr(226).chr(130).chr(172) => 'E',
// GBP (Pound) Sign
- chr(194).chr(163) => '');
+ chr(194).chr(163) => '',
+ // Vowels with diacritic (Vietnamese)
+ // unmarked
+ chr(198).chr(160) => 'O', chr(198).chr(161) => 'o',
+ chr(198).chr(175) => 'U', chr(198).chr(176) => 'u',
+ // grave accent
+ chr(225).chr(186).chr(166) => 'A', chr(225).chr(186).chr(167) => 'a',
+ chr(225).chr(186).chr(176) => 'A', chr(225).chr(186).chr(177) => 'a',
+ chr(225).chr(187).chr(128) => 'E', chr(225).chr(187).chr(129) => 'e',
+ chr(225).chr(187).chr(146) => 'O', chr(225).chr(187).chr(147) => 'o',
+ chr(225).chr(187).chr(156) => 'O', chr(225).chr(187).chr(157) => 'o',
+ chr(225).chr(187).chr(170) => 'U', chr(225).chr(187).chr(171) => 'u',
+ chr(225).chr(187).chr(178) => 'Y', chr(225).chr(187).chr(179) => 'y',
+ // hook
+ chr(225).chr(186).chr(162) => 'A', chr(225).chr(186).chr(163) => 'a',
+ chr(225).chr(186).chr(168) => 'A', chr(225).chr(186).chr(169) => 'a',
+ chr(225).chr(186).chr(178) => 'A', chr(225).chr(186).chr(179) => 'a',
+ chr(225).chr(186).chr(186) => 'E', chr(225).chr(186).chr(187) => 'e',
+ chr(225).chr(187).chr(130) => 'E', chr(225).chr(187).chr(131) => 'e',
+ chr(225).chr(187).chr(136) => 'I', chr(225).chr(187).chr(137) => 'i',
+ chr(225).chr(187).chr(142) => 'O', chr(225).chr(187).chr(143) => 'o',
+ chr(225).chr(187).chr(148) => 'O', chr(225).chr(187).chr(149) => 'o',
+ chr(225).chr(187).chr(158) => 'O', chr(225).chr(187).chr(159) => 'o',
+ chr(225).chr(187).chr(166) => 'U', chr(225).chr(187).chr(167) => 'u',
+ chr(225).chr(187).chr(172) => 'U', chr(225).chr(187).chr(173) => 'u',
+ chr(225).chr(187).chr(182) => 'Y', chr(225).chr(187).chr(183) => 'y',
+ // tilde
+ chr(225).chr(186).chr(170) => 'A', chr(225).chr(186).chr(171) => 'a',
+ chr(225).chr(186).chr(180) => 'A', chr(225).chr(186).chr(181) => 'a',
+ chr(225).chr(186).chr(188) => 'E', chr(225).chr(186).chr(189) => 'e',
+ chr(225).chr(187).chr(132) => 'E', chr(225).chr(187).chr(133) => 'e',
+ chr(225).chr(187).chr(150) => 'O', chr(225).chr(187).chr(151) => 'o',
+ chr(225).chr(187).chr(160) => 'O', chr(225).chr(187).chr(161) => 'o',
+ chr(225).chr(187).chr(174) => 'U', chr(225).chr(187).chr(175) => 'u',
+ chr(225).chr(187).chr(184) => 'Y', chr(225).chr(187).chr(185) => 'y',
+ // acute accent
+ chr(225).chr(186).chr(164) => 'A', chr(225).chr(186).chr(165) => 'a',
+ chr(225).chr(186).chr(174) => 'A', chr(225).chr(186).chr(175) => 'a',
+ chr(225).chr(186).chr(190) => 'E', chr(225).chr(186).chr(191) => 'e',
+ chr(225).chr(187).chr(144) => 'O', chr(225).chr(187).chr(145) => 'o',
+ chr(225).chr(187).chr(154) => 'O', chr(225).chr(187).chr(155) => 'o',
+ chr(225).chr(187).chr(168) => 'U', chr(225).chr(187).chr(169) => 'u',
+ // dot below
+ chr(225).chr(186).chr(160) => 'A', chr(225).chr(186).chr(161) => 'a',
+ chr(225).chr(186).chr(172) => 'A', chr(225).chr(186).chr(173) => 'a',
+ chr(225).chr(186).chr(182) => 'A', chr(225).chr(186).chr(183) => 'a',
+ chr(225).chr(186).chr(184) => 'E', chr(225).chr(186).chr(185) => 'e',
+ chr(225).chr(187).chr(134) => 'E', chr(225).chr(187).chr(135) => 'e',
+ chr(225).chr(187).chr(138) => 'I', chr(225).chr(187).chr(139) => 'i',
+ chr(225).chr(187).chr(140) => 'O', chr(225).chr(187).chr(141) => 'o',
+ chr(225).chr(187).chr(152) => 'O', chr(225).chr(187).chr(153) => 'o',
+ chr(225).chr(187).chr(162) => 'O', chr(225).chr(187).chr(163) => 'o',
+ chr(225).chr(187).chr(164) => 'U', chr(225).chr(187).chr(165) => 'u',
+ chr(225).chr(187).chr(176) => 'U', chr(225).chr(187).chr(177) => 'u',
+ chr(225).chr(187).chr(180) => 'Y', chr(225).chr(187).chr(181) => 'y',
+ );
$string = strtr($string, $chars);
} else {
$extension = array_pop($parts);
$mimes = get_allowed_mime_types();
- // Loop over any intermediate extensions. Munge them with a trailing underscore if they are a 2 - 5 character
+ // Loop over any intermediate extensions. Munge them with a trailing underscore if they are a 2 - 5 character
// long alpha string not in the extension whitelist.
foreach ( (array) $parts as $part) {
$filename .= '.' . $part;
$title = str_replace('.', '-', $title);
if ( 'save' == $context ) {
- // nbsp, ndash and mdash
+ // Convert nbsp, ndash and mdash to hyphens
$title = str_replace( array( '%c2%a0', '%e2%80%93', '%e2%80%94' ), '-', $title );
- // iexcl and iquest
- $title = str_replace( array( '%c2%a1', '%c2%bf' ), '', $title );
- // angle quotes
- $title = str_replace( array( '%c2%ab', '%c2%bb', '%e2%80%b9', '%e2%80%ba' ), '', $title );
- // curly quotes
- $title = str_replace( array( '%e2%80%98', '%e2%80%99', '%e2%80%9c', '%e2%80%9d' ), '', $title );
- // copy, reg, deg, hellip and trade
- $title = str_replace( array( '%c2%a9', '%c2%ae', '%c2%b0', '%e2%80%a6', '%e2%84%a2' ), '', $title );
+
+ // Strip these characters entirely
+ $title = str_replace( array(
+ // iexcl and iquest
+ '%c2%a1', '%c2%bf',
+ // angle quotes
+ '%c2%ab', '%c2%bb', '%e2%80%b9', '%e2%80%ba',
+ // curly quotes
+ '%e2%80%98', '%e2%80%99', '%e2%80%9c', '%e2%80%9d',
+ '%e2%80%9a', '%e2%80%9b', '%e2%80%9e', '%e2%80%9f',
+ // copy, reg, deg, hellip and trade
+ '%c2%a9', '%c2%ae', '%c2%b0', '%e2%80%a6', '%e2%84%a2',
+ ), '', $title );
+
+ // Convert times to x
+ $title = str_replace( '%c3%97', 'x', $title );
}
$title = preg_replace('/[^%a-z0-9 _-]/', '', $title);
'‹' => '‹',
'Œ' => 'Œ',
'' => '',
- 'Ž' => 'ž',
+ 'Ž' => 'Ž',
'' => '',
'' => '',
'‘' => '‘',
'›' => '›',
'œ' => 'œ',
'' => '',
- 'ž' => '',
+ 'ž' => 'ž',
'Ÿ' => 'Ÿ'
);
/**
* Will only balance the tags if forced to and the option is set to balance tags.
*
- * The option 'use_balanceTags' is used for whether the tags will be balanced.
- * Both the $force parameter and 'use_balanceTags' option will have to be true
- * before the tags will be balanced.
+ * The option 'use_balanceTags' is used to determine whether the tags will be balanced.
*
* @since 0.71
*
* @param string $text Text to be balanced
- * @param bool $force Forces balancing, ignoring the value of the option. Default false.
+ * @param bool $force If true, forces balancing, ignoring the value of the option. Default false.
* @return string Balanced text
*/
function balanceTags( $text, $force = false ) {
/**
* Acts on text which is about to be edited.
*
- * Unless $richedit is set, it is simply a holder for the 'format_to_edit'
- * filter. If $richedit is set true htmlspecialchars(), through esc_textarea(),
- * will be run on the content, converting special characters to HTML entities.
+ * The $content is run through esc_textarea(), which uses htmlspecialchars()
+ * to convert special characters to HTML entities. If $richedit is set to true,
+ * it is simply a holder for the 'format_to_edit' filter.
*
* @since 0.71
*
* @param string $content The text about to be edited.
- * @param bool $richedit Whether the $content should pass through htmlspecialchars(). Default false.
+ * @param bool $richedit Whether the $content should not pass through htmlspecialchars(). Default false (meaning it will be passed).
* @return string The text after the filter (and possibly htmlspecialchars()) has been run.
*/
function format_to_edit( $content, $richedit = false ) {
/**
* Navigates through an array and encodes the values to be used in a URL.
*
- * Uses a callback to pass the value of the array back to the function as a
- * string.
*
* @since 2.2.0
*
return $value;
}
+/**
+ * Navigates through an array and raw encodes the values to be used in a URL.
+ *
+ * @since 3.4.0
+ *
+ * @param array|string $value The array or string to be encoded.
+ * @return array|string $value The encoded array (or string from the callback).
+ */
+function rawurlencode_deep( $value ) {
+ return is_array( $value ) ? array_map( 'rawurlencode_deep', $value ) : rawurlencode( $value );
+}
+
/**
* Converts email addresses characters to HTML entities to block spam bots.
*
/**
* Trims text to a certain number of words.
*
+ * This function is localized. For languages that count 'words' by the individual
+ * character (such as East Asian languages), the $num_words argument will apply
+ * to the number of individual characters.
+ *
* @since 3.3.0
*
* @param string $text Text to trim.
$more = __( '…' );
$original_text = $text;
$text = wp_strip_all_tags( $text );
- $words_array = preg_split( "/[\n\r\t ]+/", $text, $num_words + 1, PREG_SPLIT_NO_EMPTY );
+ /* translators: If your word count is based on single characters (East Asian characters),
+ enter 'characters'. Otherwise, enter 'words'. Do not translate into your own language. */
+ if ( 'characters' == _x( 'words', 'word count: words or characters?' ) && preg_match( '/^utf\-?8$/i', get_option( 'blog_charset' ) ) ) {
+ $text = trim( preg_replace( "/[\n\r\t ]+/", ' ', $text ), ' ' );
+ preg_match_all( '/./u', $text, $words_array );
+ $words_array = array_slice( $words_array[0], 0, $num_words + 1 );
+ $sep = '';
+ } else {
+ $words_array = preg_split( "/[\n\r\t ]+/", $text, $num_words + 1, PREG_SPLIT_NO_EMPTY );
+ $sep = ' ';
+ }
if ( count( $words_array ) > $num_words ) {
array_pop( $words_array );
- $text = implode( ' ', $words_array );
+ $text = implode( $sep, $words_array );
$text = $text . $more;
} else {
- $text = implode( ' ', $words_array );
+ $text = implode( $sep, $words_array );
}
return apply_filters( 'wp_trim_words', $text, $num_words, $more, $original_text );
}
function sanitize_option($option, $value) {
switch ( $option ) {
- case 'admin_email':
- $value = sanitize_email($value);
- if ( !is_email($value) ) {
+ case 'admin_email' :
+ case 'new_admin_email' :
+ $value = sanitize_email( $value );
+ if ( ! is_email( $value ) ) {
$value = get_option( $option ); // Resets option to stored value in the case of failed sanitization
- if ( function_exists('add_settings_error') )
- add_settings_error('admin_email', 'invalid_admin_email', __('The email address entered did not appear to be a valid email address. Please enter a valid email address.'));
- }
- break;
-
- case 'new_admin_email':
- $value = sanitize_email($value);
- if ( !is_email($value) ) {
- $value = get_option( $option ); // Resets option to stored value in the case of failed sanitization
- if ( function_exists('add_settings_error') )
- add_settings_error('new_admin_email', 'invalid_admin_email', __('The email address entered did not appear to be a valid email address. Please enter a valid email address.'));
+ if ( function_exists( 'add_settings_error' ) )
+ 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.' ) );
}
break;
global $_links_add_base;
//1 = attribute name 2 = quotation mark 3 = URL
return $m[1] . '=' . $m[2] .
- (strpos($m[3], 'http://') === false ?
- path_join($_links_add_base, $m[3]) :
- $m[3])
+ ( preg_match( '#^(\w{1,20}):#', $m[3], $protocol ) && in_array( $protocol[1], wp_allowed_protocols() ) ?
+ $m[3] :
+ path_join( $_links_add_base, $m[3] ) )
. $m[2];
}
if ( $remove_breaks )
$string = preg_replace('/[\r\n\t ]+/', ' ', $string);
- return trim($string);
+ return trim( $string );
}
/**
return apply_filters( 'sanitize_mime_type', $sani_mime_type, $mime_type );
}
-?>
+/**
+ * Sanitize space or carriage return separated URLs that are used to send trackbacks.
+ *
+ * @since 3.4.0
+ *
+ * @param string $to_ping Space or carriage return separated URLs
+ * @return string URLs starting with the http or https protocol, separated by a carriage return.
+ */
+function sanitize_trackback_urls( $to_ping ) {
+ $urls_to_ping = preg_split( '/\r\n\t /', trim( $to_ping ), -1, PREG_SPLIT_NO_EMPTY );
+ foreach ( $urls_to_ping as $k => $url ) {
+ if ( !preg_match( '#^https?://.#i', $url ) )
+ unset( $urls_to_ping[$k] );
+ }
+ $urls_to_ping = array_map( 'esc_url_raw', $urls_to_ping );
+ $urls_to_ping = implode( "\n", $urls_to_ping );
+ return apply_filters( 'sanitize_trackback_urls', $urls_to_ping, $to_ping );
+}