11
11
* Replaces common plain text characters into formatted entities
15
* 'cause today's effort makes it worth tomorrow's "holiday"...
15
* 'cause today's effort makes it worth tomorrow's "holiday" ...
19
* ’cause today’s effort makes it worth tomorrow’s “holiday”…
19
* ’cause today’s effort makes it worth tomorrow’s “holiday” …
21
21
* Code within certain html blocks are skipped.
215
215
. '-(?!->)' // Dash not followed by end of comment.
216
216
. '[^\-]*+' // Consume non-dashes.
217
217
. ')*+' // Loop possessively.
218
. '-->'; // End of comment.
220
$regex = '/(' // Capture the entire match.
221
. '<' // Find start of element.
222
. '(?(?=!--)' // Is this a comment?
223
. $comment_regex // Find end of comment
225
. '[^>]+>' // Find end of element
228
. '\[' // Find start of shortcode.
229
. '[\/\[]?' // Shortcodes may begin with [/ or [[
230
. $tagregexp // Only match registered shortcodes, because performance.
232
. '[^\[\]<>]+' // Shortcodes do not contain other shortcodes. Quantifier critical.
234
. '<[^\[\]>]*>' // HTML elements permitted. Prevents matching ] before >.
235
. ')*+' // Possessive critical.
236
. '\]' // Find end of shortcode.
237
. '\]?' // Shortcodes may end with ]]
218
. '(?:-->)?'; // End of comment. If not found, match all input.
221
'\[' // Find start of shortcode.
222
. '[\/\[]?' // Shortcodes may begin with [/ or [[
223
. $tagregexp // Only match registered shortcodes, because performance.
225
. '[^\[\]<>]+' // Shortcodes do not contain other shortcodes. Quantifier critical.
227
. '<[^\[\]>]*>' // HTML elements permitted. Prevents matching ] before >.
228
. ')*+' // Possessive critical.
229
. '\]' // Find end of shortcode.
230
. '\]?'; // Shortcodes may end with ]]
233
'/(' // Capture the entire match.
234
. '<' // Find start of element.
235
. '(?(?=!--)' // Is this a comment?
236
. $comment_regex // Find end of comment.
238
. '[^>]+>' // Find end of element.
241
. $shortcode_regex // Find shortcodes.
240
244
$textarr = preg_split( $regex, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
242
246
foreach ( $textarr as &$curl ) {
243
247
// Only call _wptexturize_pushpop_element if $curl is a delimiter.
244
248
$first = $curl[0];
245
if ( '<' === $first && '>' === substr( $curl, -1 ) ) {
246
// This is an HTML delimiter.
248
if ( '<!--' !== substr( $curl, 0, 4 ) ) {
249
_wptexturize_pushpop_element( $curl, $no_texturize_tags_stack, $no_texturize_tags );
249
if ( '<' === $first && '<!--' === substr( $curl, 0, 4 ) ) {
250
// This is an HTML comment delimeter.
254
} elseif ( '<' === $first && '>' === substr( $curl, -1 ) ) {
255
// This is an HTML element delimiter.
257
_wptexturize_pushpop_element( $curl, $no_texturize_tags_stack, $no_texturize_tags );
252
259
} elseif ( '' === trim( $curl ) ) {
253
260
// This is a newline between delimiters. Performance improves when we check this.
257
} elseif ( '[' === $first && 1 === preg_match( '/^\[\/?' . $tagregexp . '(?:[^\[\]<>]+|<[^\[\]>]*>)*+\]$/', $curl ) ) {
264
} elseif ( '[' === $first && 1 === preg_match( '/^' . $shortcode_regex . '$/', $curl ) ) {
258
265
// This is a shortcode delimiter.
260
_wptexturize_pushpop_element( $curl, $no_texturize_shortcodes_stack, $no_texturize_shortcodes );
262
} elseif ( '[' === $first && 1 === preg_match( '/^\[[\/\[]?' . $tagregexp . '(?:[^\[\]<>]+|<[^\[\]>]*>)*+\]\]?$/', $curl ) ) {
263
// This is an escaped shortcode delimiter.
266
// Do not push to the shortcodes stack.
267
if ( '[[' !== substr( $curl, 0, 2 ) && ']]' !== substr( $curl, -2 ) ) {
268
// Looks like a normal shortcode.
269
_wptexturize_pushpop_element( $curl, $no_texturize_shortcodes_stack, $no_texturize_shortcodes );
271
// Looks like an escaped shortcode.
270
275
} elseif ( empty( $no_texturize_shortcodes_stack ) && empty( $no_texturize_tags_stack ) ) {
271
276
// This is neither a delimiter, nor is this content inside of no_texturize pairs. Do texturize.
285
290
// 9x9 (times), but never 0x9999
286
if ( 1 === preg_match( '/(?<=\d)x-?\d/', $curl ) ) {
291
if ( 1 === preg_match( '/(?<=\d)x\d/', $curl ) ) {
287
292
// Searching for a digit is 10 times more expensive than for the x, so we avoid doing this one!
288
$curl = preg_replace( '/\b(\d(?(?<=0)[\d\.,]+|[\d\.,]*))x(-?\d[\d\.,]*)\b/', '$1×$2', $curl );
293
$curl = preg_replace( '/\b(\d(?(?<=0)[\d\.,]+|[\d\.,]*))x(\d[\d\.,]*)\b/', '$1×$2', $curl );
308
313
* @access private
310
* @param string $text Text to check. Must be a tag like <html> or [shortcode].
315
* @param string $text Text to check. Must be a tag like `<html>` or `[shortcode]`.
311
316
* @param array $stack List of open tag elements.
312
317
* @param array $disabled_elements The tag names to match against. Spaces are not allowed in tag names.
327
332
// Parse out the tag name.
328
333
$space = strpos( $text, ' ' );
329
if ( FALSE === $space ) {
334
if ( false === $space ) {
332
337
$space -= $name_offset;
572
577
* @access private
574
579
* @param string $string The text which is to be encoded.
575
* @param mixed $quote_style Optional. Converts double quotes if set to ENT_COMPAT, both single and double if set to ENT_QUOTES or none if set to ENT_NOQUOTES. Also compatible with old values; converting single quotes if set to 'single', double if set to 'double' or both if otherwise set. Default is ENT_NOQUOTES.
580
* @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.
576
581
* @param string $charset Optional. The character encoding of the string. Default is false.
577
582
* @param boolean $double_encode Optional. Whether to encode existing html entities. Default is false.
578
583
* @return string The encoded text with HTML entities.
1068
1073
$special_chars = apply_filters( 'sanitize_file_name_chars', $special_chars, $filename_raw );
1069
1074
$filename = preg_replace( "#\x{00a0}#siu", ' ', $filename );
1070
$filename = str_replace($special_chars, '', $filename);
1075
$filename = str_replace( $special_chars, '', $filename );
1071
1076
$filename = str_replace( array( '%20', '+' ), '-', $filename );
1072
$filename = preg_replace('/[\s-]+/', '-', $filename);
1073
$filename = trim($filename, '.-_');
1077
$filename = preg_replace( '/[\r\n\t -]+/', '-', $filename );
1078
$filename = trim( $filename, '.-_' );
1075
1080
// Split the filename into a base and extension[s]
1076
1081
$parts = explode('.', $filename);
1315
1319
* @param string $orderby Order by string to be checked.
1316
* @return string|bool Returns the order by clause if it is a match, false otherwise.
1320
* @return false|string Returns the order by clause if it is a match, false otherwise.
1318
1322
function sanitize_sql_orderby( $orderby ){
1319
1323
preg_match('/^\s*([a-z0-9_]+(\s+(ASC|DESC))?(\s*,\s*|\s*$))+|^\s*RAND\(\s*\)\s*$/i', $orderby, $obmatches);
1363
1367
* Converts a number of characters from a string.
1365
* Metadata tags <<title>> and <<category>> are removed, <<br>> and <<hr>> are
1369
* Metadata tags `<title>` and `<category>` are removed, `<br>` and `<hr>` are
1366
1370
* converted into correct XHTML and Unicode characters are converted to the
1932
1936
* Input string must have no null characters (or eventual transformations on output chunks must not care about null characters)
1935
* _split_str_by_whitespace( "1234 67890 1234 67890a cd 1234 890 123456789 1234567890a 45678 1 3 5 7 90 ", 10 ) ==
1937
* 0 => '1234 67890 ', // 11 characters: Perfect split
1938
* 1 => '1234 ', // 5 characters: '1234 67890a' was too long
1939
* 2 => '67890a cd ', // 10 characters: '67890a cd 1234' was too long
1940
* 3 => '1234 890 ', // 11 characters: Perfect split
1941
* 4 => '123456789 ', // 10 characters: '123456789 1234567890a' was too long
1942
* 5 => '1234567890a ', // 12 characters: Too long, but no inner whitespace on which to split
1943
* 6 => ' 45678 ', // 11 characters: Perfect split
1944
* 7 => '1 3 5 7 9', // 9 characters: End of $string
1938
* _split_str_by_whitespace( "1234 67890 1234 67890a cd 1234 890 123456789 1234567890a 45678 1 3 5 7 90 ", 10 ) ==
1940
* 0 => '1234 67890 ', // 11 characters: Perfect split
1941
* 1 => '1234 ', // 5 characters: '1234 67890a' was too long
1942
* 2 => '67890a cd ', // 10 characters: '67890a cd 1234' was too long
1943
* 3 => '1234 890 ', // 11 characters: Perfect split
1944
* 4 => '123456789 ', // 10 characters: '123456789 1234567890a' was too long
1945
* 5 => '1234567890a ', // 12 characters: Too long, but no inner whitespace on which to split
1946
* 6 => ' 45678 ', // 11 characters: Perfect split
1947
* 7 => '1 3 5 7 90 ', // 11 characters: End of $string
1949
1951
* @access private
2018
2020
* Callback handler for {@link convert_smilies()}.
2019
2021
* Looks up one smiley code in the $wpsmiliestrans global array and returns an
2020
* <img> string for that smiley.
2022
* `<img>` string for that smiley.
2022
2024
* @global array $wpsmiliestrans
2217
2219
* @access private
2219
2221
* @param array $match The preg_replace_callback matches array
2220
* @return array Converted chars
2222
* @return string Converted chars
2222
2224
function _wp_iso_convert( $match ) {
2223
2225
return chr( hexdec( strtolower( $match[1] ) ) );
2236
* @uses get_option() to retrieve the value of 'gmt_offset'.
2237
2238
* @param string $string The date to be converted.
2238
2239
* @param string $format The format string for the returned date (default is Y-m-d H:i:s)
2239
2240
* @return string GMT version of the date provided.
3026
3027
* is applied to the returned cleaned URL.
3029
* @uses wp_kses_bad_protocol() To only permit protocols in the URL set
3030
* via $protocols or the common ones set in the function.
3032
3031
* @param string $url The URL to be cleaned.
3033
3032
* @param array $protocols Optional. An array of acceptable protocols.
3242
3240
* beginning, so it isn't a true relative link, but from the web root base.
3243
* @since 4.1.0 Support was added for relative URLs.
3246
3245
* @param string $link Full URL path.
3247
3246
* @return string Absolute path.
3249
3248
function wp_make_link_relative( $link ) {
3250
return preg_replace( '|https?://[^/]+(/.*)|i', '$1', $link );
3249
return preg_replace( '|^(https?:)?//[^/]+(/.*)|i', '$2', $link );
3697
3694
return $m[1] . '=' . $m[2] .
3698
3695
( preg_match( '#^(\w{1,20}):#', $m[3], $protocol ) && in_array( $protocol[1], wp_allowed_protocols() ) ?
3700
path_join( $_links_add_base, $m[3] ) )
3697
WP_HTTP::make_absolute_url( $m[3], $_links_add_base )
3705
3703
* Adds a Target attribute to all links in passed content.
3707
* This function by default only applies to <a> tags, however this can be
3705
* This function by default only applies to `<a>` tags, however this can be
3708
3706
* modified by the 3rd param.
3710
* <b>NOTE:</b> Any current target attributed will be stripped and replaced.
3708
* *NOTE:* Any current target attributed will be stripped and replaced.
3758
3756
* Properly strip all HTML tags including script and style
3760
3758
* This differs from strip_tags() because it removes the contents of
3761
* the <script> and <style> tags. E.g. strip_tags( '<script>something</script>' )
3759
* the `<script>` and `<style>` tags. E.g. `strip_tags( '<script>something</script>' )`
3762
3760
* will return 'something'. wp_strip_all_tags will return ''