X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/72836ec95a52eacbda4dc5aa296b7dd6de08bd3b..e08b42e8ad054ec67522d7ac1aaae5dc68cb3d01:/wp-includes/formatting.php?ds=sidebyside diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index 904c99b1..c56d8201 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -101,8 +101,22 @@ function wptexturize($text) { // Transform into regexp sub-expression used in _wptexturize_pushpop_element // Must do this every time in case plugins use these filters in a context sensitive manner - $no_texturize_tags = '(' . implode('|', apply_filters('no_texturize_tags', $default_no_texturize_tags) ) . ')'; - $no_texturize_shortcodes = '(' . implode('|', apply_filters('no_texturize_shortcodes', $default_no_texturize_shortcodes) ) . ')'; + /** + * Filter the list of HTML elements not to texturize. + * + * @since 2.8.0 + * + * @param array $default_no_texturize_tags An array of HTML element names. + */ + $no_texturize_tags = '(' . implode( '|', apply_filters( 'no_texturize_tags', $default_no_texturize_tags ) ) . ')'; + /** + * Filter the list of shortcodes not to texturize. + * + * @since 2.8.0 + * + * @param array $default_no_texturize_shortcodes An array of shortcode names. + */ + $no_texturize_shortcodes = '(' . implode( '|', apply_filters( 'no_texturize_shortcodes', $default_no_texturize_shortcodes ) ) . ')'; $no_texturize_tags_stack = array(); $no_texturize_shortcodes_stack = array(); @@ -798,6 +812,13 @@ function remove_accents($string) { $chars[ chr(195).chr(156) ] = 'Ue'; $chars[ chr(195).chr(188) ] = 'ue'; $chars[ chr(195).chr(159) ] = 'ss'; + } elseif ( 'da_DK' === $locale ) { + $chars[ chr(195).chr(134) ] = 'Ae'; + $chars[ chr(195).chr(166) ] = 'ae'; + $chars[ chr(195).chr(152) ] = 'Oe'; + $chars[ chr(195).chr(184) ] = 'oe'; + $chars[ chr(195).chr(133) ] = 'Aa'; + $chars[ chr(195).chr(165) ] = 'aa'; } $string = strtr($string, $chars); @@ -842,7 +863,15 @@ function remove_accents($string) { function sanitize_file_name( $filename ) { $filename_raw = $filename; $special_chars = array("?", "[", "]", "/", "\\", "=", "<", ">", ":", ";", ",", "'", "\"", "&", "$", "#", "*", "(", ")", "|", "~", "`", "!", "{", "}", chr(0)); - $special_chars = apply_filters('sanitize_file_name_chars', $special_chars, $filename_raw); + /** + * Filter the list of characters to remove from a filename. + * + * @since 2.8.0 + * + * @param array $special_chars Characters to remove. + * @param string $filename_raw Filename as it was passed into sanitize_file_name(). + */ + $special_chars = apply_filters( 'sanitize_file_name_chars', $special_chars, $filename_raw ); $filename = str_replace($special_chars, '', $filename); $filename = preg_replace('/[\s-]+/', '-', $filename); $filename = trim($filename, '.-_'); @@ -851,16 +880,27 @@ function sanitize_file_name( $filename ) { $parts = explode('.', $filename); // Return if only one extension - if ( count($parts) <= 2 ) - return apply_filters('sanitize_file_name', $filename, $filename_raw); + if ( count( $parts ) <= 2 ) { + /** + * Filter a sanitized filename string. + * + * @since 2.8.0 + * + * @param string $filename Sanitized filename. + * @param string $filename_raw The filename prior to sanitization. + */ + return apply_filters( 'sanitize_file_name', $filename, $filename_raw ); + } // Process multiple extensions $filename = array_shift($parts); $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 - // long alpha string not in the extension whitelist. + /* + * Loop over any intermediate extensions. Postfix 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; @@ -878,7 +918,7 @@ function sanitize_file_name( $filename ) { } } $filename .= '.' . $extension; - + /** This filter is documented in wp-includes/formatting.php */ return apply_filters('sanitize_file_name', $filename, $filename_raw); } @@ -891,8 +931,6 @@ function sanitize_file_name( $filename ) { * parameters for the 'sanitize_user' filter. * * @since 2.0.0 - * @uses apply_filters() Calls 'sanitize_user' hook on username, raw username, - * and $strict parameter. * * @param string $username The username to be sanitized. * @param bool $strict If set limits $username to specific characters. Default false. @@ -914,6 +952,15 @@ function sanitize_user( $username, $strict = false ) { // Consolidate contiguous whitespace $username = preg_replace( '|\s+|', ' ', $username ); + /** + * Filter a sanitized username string. + * + * @since 2.0.1 + * + * @param string $username Sanitized username. + * @param string $raw_username The username prior to sanitization. + * @param bool $strict Whether to limit the sanitization to specific characters. Default false. + */ return apply_filters( 'sanitize_user', $username, $raw_username, $strict ); } @@ -931,6 +978,15 @@ function sanitize_key( $key ) { $raw_key = $key; $key = strtolower( $key ); $key = preg_replace( '/[^a-z0-9_\-]/', '', $key ); + + /** + * Filter a sanitized key string. + * + * @since 3.0.0 + * + * @param string $key Sanitized key. + * @param string $raw_key The key prior to sanitization. + */ return apply_filters( 'sanitize_key', $key, $raw_key ); } @@ -954,7 +1010,16 @@ function sanitize_title( $title, $fallback_title = '', $context = 'save' ) { if ( 'save' == $context ) $title = remove_accents($title); - $title = apply_filters('sanitize_title', $title, $raw_title, $context); + /** + * Filter a sanitized title string. + * + * @since 1.2.0 + * + * @param string $title Sanitized title. + * @param string $raw_title The title prior to sanitization. + * @param string $context The context for which the title is being sanitized. + */ + $title = apply_filters( 'sanitize_title', $title, $raw_title, $context ); if ( '' === $title || false === $title ) $title = $fallback_title; @@ -1086,6 +1151,15 @@ function sanitize_html_class( $class, $fallback = '' ) { if ( '' == $sanitized ) $sanitized = $fallback; + /** + * Filter a sanitized HTML class string. + * + * @since 2.8.0 + * + * @param string $sanitized The sanitized HTML class. + * @param string $class HTML class before sanitization. + * @param string $fallback The fallback string. + */ return apply_filters( 'sanitize_html_class', $sanitized, $class, $fallback ); } @@ -1169,10 +1243,11 @@ function convert_chars($content, $deprecated = '') { * @return string Balanced text */ function balanceTags( $text, $force = false ) { - if ( $force || get_option('use_balanceTags') == 1 ) + if ( $force || get_option('use_balanceTags') == 1 ) { return force_balance_tags( $text ); - else + } else { return $text; + } } /** @@ -1320,6 +1395,13 @@ function force_balance_tags( $text ) { * @return string The text after the filter (and possibly htmlspecialchars()) has been run. */ function format_to_edit( $content, $richedit = false ) { + /** + * Filter the text to be formatted for editing. + * + * @since 1.2.0 + * + * @param string $content The text, prior to formatting for editing. + */ $content = apply_filters( 'format_to_edit', $content ); if ( ! $richedit ) $content = esc_textarea( $content ); @@ -1335,7 +1417,14 @@ function format_to_edit( $content, $richedit = false ) { * @return string Text returned from the 'format_to_post' filter. */ function format_to_post($content) { - $content = apply_filters('format_to_post', $content); + /** + * Filter the string returned by format_to_post(). + * + * @since 1.2.0 + * + * @param string $content The string to format. + */ + $content = apply_filters( 'format_to_post', $content ); return $content; } @@ -1601,8 +1690,15 @@ function _make_email_clickable_cb($matches) { function make_clickable( $text ) { $r = ''; $textarr = preg_split( '/(<[^<>]+>)/', $text, -1, PREG_SPLIT_DELIM_CAPTURE ); // split out HTML tags + $nested_code_pre = 0; // Keep track of how many levels link is nested inside
or
foreach ( $textarr as $piece ) {
- if ( empty( $piece ) || ( $piece[0] == '<' && ! preg_match('|^<\s*[\w]{1,20}+://|', $piece) ) ) {
+
+ if ( preg_match( '|^]|i', $piece ) || preg_match( '|^]|i', $piece ) )
+ $nested_code_pre++;
+ elseif ( ( '
' === strtolower( $piece ) || '
' === strtolower( $piece ) ) && $nested_code_pre )
+ $nested_code_pre--;
+
+ if ( $nested_code_pre || empty( $piece ) || ( $piece[0] === '<' && ! preg_match( '|^<\s*[\w]{1,20}+://|', $piece ) ) ) {
$r .= $piece;
continue;
}
@@ -1762,11 +1858,19 @@ function translate_smiley( $matches ) {
$smiley = trim( reset( $matches ) );
$img = $wpsmiliestrans[ $smiley ];
- $smiley_masked = esc_attr( $smiley );
+ /**
+ * Filter the Smiley image URL before it's used in the image element.
+ *
+ * @since 2.9.0
+ *
+ * @param string $smiley_url URL for the smiley image.
+ * @param string $img Filename for the smiley image.
+ * @param string $site_url Site URL, as returned by site_url().
+ */
$src_url = apply_filters( 'smilies_src', includes_url( "images/smilies/$img" ), $img, site_url() );
- return " ";
+ return sprintf( ' ', esc_url( $src_url ), esc_attr( $smiley ) );
}
/**
@@ -1781,18 +1885,36 @@ function translate_smiley( $matches ) {
* @param string $text Content to convert smilies from text.
* @return string Converted content with text smilies replaced with images.
*/
-function convert_smilies($text) {
+function convert_smilies( $text ) {
global $wp_smiliessearch;
$output = '';
- if ( get_option('use_smilies') && !empty($wp_smiliessearch) ) {
+ if ( get_option( 'use_smilies' ) && ! empty( $wp_smiliessearch ) ) {
// HTML loop taken from texturize function, could possible be consolidated
- $textarr = preg_split("/(<.*>)/U", $text, -1, PREG_SPLIT_DELIM_CAPTURE); // capture the tags as well as in between
- $stop = count($textarr);// loop stuff
- for ($i = 0; $i < $stop; $i++) {
+ $textarr = preg_split( '/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE ); // capture the tags as well as in between
+ $stop = count( $textarr );// loop stuff
+
+ // Ignore proessing of specific tags
+ $tags_to_ignore = 'code|pre|style|script|textarea';
+ $ignore_block_element = '';
+
+ for ( $i = 0; $i < $stop; $i++ ) {
$content = $textarr[$i];
- if ((strlen($content) > 0) && ('<' != $content[0])) { // If it's not a tag
- $content = preg_replace_callback($wp_smiliessearch, 'translate_smiley', $content);
+
+ // If we're in an ignore block, wait until we find its closing tag
+ if ( '' == $ignore_block_element && preg_match( '/^<(' . $tags_to_ignore . ')>/', $content, $matches ) ) {
+ $ignore_block_element = $matches[1];
+ }
+
+ // If it's not a tag and not in ignore block
+ if ( '' == $ignore_block_element && strlen( $content ) > 0 && '<' != $content[0] ) {
+ $content = preg_replace_callback( $wp_smiliessearch, 'translate_smiley', $content );
+ }
+
+ // did we exit ignore block
+ if ( '' != $ignore_block_element && '' . $ignore_block_element . '>' == $content ) {
+ $ignore_block_element = '';
}
+
$output .= $content;
}
} else {
@@ -1819,11 +1941,26 @@ function is_email( $email, $deprecated = false ) {
// Test for the minimum length the email can be
if ( strlen( $email ) < 3 ) {
+ /**
+ * Filter whether an email address is valid.
+ *
+ * This filter is evaluated under several different contexts, such as 'email_too_short',
+ * 'email_no_at', 'local_invalid_chars', 'domain_period_sequence', 'domain_period_limits',
+ * 'domain_no_periods', 'sub_hyphen_limits', 'sub_invalid_chars', or no specific context.
+ *
+ * @since 2.8.0
+ *
+ * @param bool $is_email Whether the email address has passed the is_email() checks. Default false.
+ * @param string $email The email address being checked.
+ * @param string $message An explanatory message to the user.
+ * @param string $context Context under which the email was tested.
+ */
return apply_filters( 'is_email', false, $email, 'email_too_short' );
}
// Test for an @ character after the first position
if ( strpos( $email, '@', 1 ) === false ) {
+ /** This filter is documented in wp-includes/formatting.php */
return apply_filters( 'is_email', false, $email, 'email_no_at' );
}
@@ -1833,17 +1970,20 @@ function is_email( $email, $deprecated = false ) {
// LOCAL PART
// Test for invalid characters
if ( !preg_match( '/^[a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]+$/', $local ) ) {
+ /** This filter is documented in wp-includes/formatting.php */
return apply_filters( 'is_email', false, $email, 'local_invalid_chars' );
}
// DOMAIN PART
// Test for sequences of periods
if ( preg_match( '/\.{2,}/', $domain ) ) {
+ /** This filter is documented in wp-includes/formatting.php */
return apply_filters( 'is_email', false, $email, 'domain_period_sequence' );
}
// Test for leading and trailing periods and whitespace
if ( trim( $domain, " \t\n\r\0\x0B." ) !== $domain ) {
+ /** This filter is documented in wp-includes/formatting.php */
return apply_filters( 'is_email', false, $email, 'domain_period_limits' );
}
@@ -1852,6 +1992,7 @@ function is_email( $email, $deprecated = false ) {
// Assume the domain will have at least two subs
if ( 2 > count( $subs ) ) {
+ /** This filter is documented in wp-includes/formatting.php */
return apply_filters( 'is_email', false, $email, 'domain_no_periods' );
}
@@ -1859,16 +2000,19 @@ function is_email( $email, $deprecated = false ) {
foreach ( $subs as $sub ) {
// Test for leading and trailing hyphens and whitespace
if ( trim( $sub, " \t\n\r\0\x0B-" ) !== $sub ) {
+ /** This filter is documented in wp-includes/formatting.php */
return apply_filters( 'is_email', false, $email, 'sub_hyphen_limits' );
}
// Test for invalid characters
if ( !preg_match('/^[a-z0-9-]+$/i', $sub ) ) {
+ /** This filter is documented in wp-includes/formatting.php */
return apply_filters( 'is_email', false, $email, 'sub_invalid_chars' );
}
}
// Congratulations your email made it!
+ /** This filter is documented in wp-includes/formatting.php */
return apply_filters( 'is_email', $email, $email, null );
}
@@ -2048,11 +2192,25 @@ function popuplinks($text) {
function sanitize_email( $email ) {
// Test for the minimum length the email can be
if ( strlen( $email ) < 3 ) {
+ /**
+ * Filter a sanitized email address.
+ *
+ * This filter is evaluated under several contexts, including 'email_too_short',
+ * 'email_no_at', 'local_invalid_chars', 'domain_period_sequence', 'domain_period_limits',
+ * 'domain_no_periods', 'domain_no_valid_subs', or no context.
+ *
+ * @since 2.8.0
+ *
+ * @param string $email The sanitized email address.
+ * @param string $email The email address, as provided to sanitize_email().
+ * @param string $message A message to pass to the user.
+ */
return apply_filters( 'sanitize_email', '', $email, 'email_too_short' );
}
// Test for an @ character after the first position
if ( strpos( $email, '@', 1 ) === false ) {
+ /** This filter is documented in wp-includes/formatting.php */
return apply_filters( 'sanitize_email', '', $email, 'email_no_at' );
}
@@ -2063,6 +2221,7 @@ function sanitize_email( $email ) {
// Test for invalid characters
$local = preg_replace( '/[^a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]/', '', $local );
if ( '' === $local ) {
+ /** This filter is documented in wp-includes/formatting.php */
return apply_filters( 'sanitize_email', '', $email, 'local_invalid_chars' );
}
@@ -2070,12 +2229,14 @@ function sanitize_email( $email ) {
// Test for sequences of periods
$domain = preg_replace( '/\.{2,}/', '', $domain );
if ( '' === $domain ) {
+ /** This filter is documented in wp-includes/formatting.php */
return apply_filters( 'sanitize_email', '', $email, 'domain_period_sequence' );
}
// Test for leading and trailing periods and whitespace
$domain = trim( $domain, " \t\n\r\0\x0B." );
if ( '' === $domain ) {
+ /** This filter is documented in wp-includes/formatting.php */
return apply_filters( 'sanitize_email', '', $email, 'domain_period_limits' );
}
@@ -2084,6 +2245,7 @@ function sanitize_email( $email ) {
// Assume the domain will have at least two subs
if ( 2 > count( $subs ) ) {
+ /** This filter is documented in wp-includes/formatting.php */
return apply_filters( 'sanitize_email', '', $email, 'domain_no_periods' );
}
@@ -2106,6 +2268,7 @@ function sanitize_email( $email ) {
// If there aren't 2 or more valid subs
if ( 2 > count( $new_subs ) ) {
+ /** This filter is documented in wp-includes/formatting.php */
return apply_filters( 'sanitize_email', '', $email, 'domain_no_valid_subs' );
}
@@ -2116,6 +2279,7 @@ function sanitize_email( $email ) {
$email = $local . '@' . $domain;
// Congratulations your email made it!
+ /** This filter is documented in wp-includes/formatting.php */
return apply_filters( 'sanitize_email', $email, $email, null );
}
@@ -2195,13 +2359,37 @@ function wp_trim_excerpt($text = '') {
$text = strip_shortcodes( $text );
- $text = apply_filters('the_content', $text);
+ /** This filter is documented in wp-includes/post-template.php */
+ $text = apply_filters( 'the_content', $text );
$text = str_replace(']]>', ']]>', $text);
- $excerpt_length = apply_filters('excerpt_length', 55);
- $excerpt_more = apply_filters('excerpt_more', ' ' . '[…]');
+
+ /**
+ * Filter the number of words in an excerpt.
+ *
+ * @since 2.7.0
+ *
+ * @param int $number The number of words. Default 55.
+ */
+ $excerpt_length = apply_filters( 'excerpt_length', 55 );
+ /**
+ * Filter the string in the "more" link displayed after a trimmed excerpt.
+ *
+ * @since 2.9.0
+ *
+ * @param string $more_string The string shown within the more link.
+ */
+ $excerpt_more = apply_filters( 'excerpt_more', ' ' . '[…]' );
$text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
}
- return apply_filters('wp_trim_excerpt', $text, $raw_excerpt);
+ /**
+ * Filter the trimmed excerpt string.
+ *
+ * @since 2.8.0
+ *
+ * @param string $text The trimmed text.
+ * @param string $raw_excerpt The text prior to trimming.
+ */
+ return apply_filters( 'wp_trim_excerpt', $text, $raw_excerpt );
}
/**
@@ -2241,6 +2429,16 @@ function wp_trim_words( $text, $num_words = 55, $more = null ) {
} else {
$text = implode( $sep, $words_array );
}
+ /**
+ * Filter the text content after words have been trimmed.
+ *
+ * @since 3.3.0
+ *
+ * @param string $text The trimmed text.
+ * @param int $num_words The number of words to trim the text to. Default 5.
+ * @param string $more An optional string to append to the end of the trimmed text, e.g. ….
+ * @param string $original_text The text before it was trimmed.
+ */
return apply_filters( 'wp_trim_words', $text, $num_words, $more, $original_text );
}
@@ -2254,7 +2452,16 @@ function wp_trim_words( $text, $num_words = 55, $more = null ) {
*/
function ent2ncr($text) {
- // Allow a plugin to short-circuit and override the mappings.
+ /**
+ * Filter text before named entities are converted into numbered entities.
+ *
+ * A non-null string must be returned for the filter to be evaluated.
+ *
+ * @since 3.3.0
+ *
+ * @param null $converted_text The text to be converted. Default null.
+ * @param string $text The text prior to entity conversion.
+ */
$filtered = apply_filters( 'pre_ent2ncr', null, $text );
if( null !== $filtered )
return $filtered;
@@ -2533,14 +2740,30 @@ function ent2ncr($text) {
* @return string The formatted text after filter is applied.
*/
function wp_richedit_pre($text) {
- // Filtering a blank results in an annoying