Edit File by line
/home/barbar84/www/wp-inclu...
File: formatting.php
*
[2500] Fix | Delete
* @param string $text Text to be balanced.
[2501] Fix | Delete
* @return string Balanced text.
[2502] Fix | Delete
*/
[2503] Fix | Delete
function force_balance_tags( $text ) {
[2504] Fix | Delete
$tagstack = array();
[2505] Fix | Delete
$stacksize = 0;
[2506] Fix | Delete
$tagqueue = '';
[2507] Fix | Delete
$newtext = '';
[2508] Fix | Delete
// Known single-entity/self-closing tags.
[2509] Fix | Delete
$single_tags = array( 'area', 'base', 'basefont', 'br', 'col', 'command', 'embed', 'frame', 'hr', 'img', 'input', 'isindex', 'link', 'meta', 'param', 'source' );
[2510] Fix | Delete
// Tags that can be immediately nested within themselves.
[2511] Fix | Delete
$nestable_tags = array( 'blockquote', 'div', 'object', 'q', 'span' );
[2512] Fix | Delete
[2513] Fix | Delete
// WP bug fix for comments - in case you REALLY meant to type '< !--'.
[2514] Fix | Delete
$text = str_replace( '< !--', '< !--', $text );
[2515] Fix | Delete
// WP bug fix for LOVE <3 (and other situations with '<' before a number).
[2516] Fix | Delete
$text = preg_replace( '#<([0-9]{1})#', '&lt;$1', $text );
[2517] Fix | Delete
[2518] Fix | Delete
/**
[2519] Fix | Delete
* Matches supported tags.
[2520] Fix | Delete
*
[2521] Fix | Delete
* To get the pattern as a string without the comments paste into a PHP
[2522] Fix | Delete
* REPL like `php -a`.
[2523] Fix | Delete
*
[2524] Fix | Delete
* @see https://html.spec.whatwg.org/#elements-2
[2525] Fix | Delete
* @see https://w3c.github.io/webcomponents/spec/custom/#valid-custom-element-name
[2526] Fix | Delete
*
[2527] Fix | Delete
* @example
[2528] Fix | Delete
* ~# php -a
[2529] Fix | Delete
* php > $s = [paste copied contents of expression below including parentheses];
[2530] Fix | Delete
* php > echo $s;
[2531] Fix | Delete
*/
[2532] Fix | Delete
$tag_pattern = (
[2533] Fix | Delete
'#<' . // Start with an opening bracket.
[2534] Fix | Delete
'(/?)' . // Group 1 - If it's a closing tag it'll have a leading slash.
[2535] Fix | Delete
'(' . // Group 2 - Tag name.
[2536] Fix | Delete
// Custom element tags have more lenient rules than HTML tag names.
[2537] Fix | Delete
'(?:[a-z](?:[a-z0-9._]*)-(?:[a-z0-9._-]+)+)' .
[2538] Fix | Delete
'|' .
[2539] Fix | Delete
// Traditional tag rules approximate HTML tag names.
[2540] Fix | Delete
'(?:[\w:]+)' .
[2541] Fix | Delete
')' .
[2542] Fix | Delete
'(?:' .
[2543] Fix | Delete
// We either immediately close the tag with its '>' and have nothing here.
[2544] Fix | Delete
'\s*' .
[2545] Fix | Delete
'(/?)' . // Group 3 - "attributes" for empty tag.
[2546] Fix | Delete
'|' .
[2547] Fix | Delete
// Or we must start with space characters to separate the tag name from the attributes (or whitespace).
[2548] Fix | Delete
'(\s+)' . // Group 4 - Pre-attribute whitespace.
[2549] Fix | Delete
'([^>]*)' . // Group 5 - Attributes.
[2550] Fix | Delete
')' .
[2551] Fix | Delete
'>#' // End with a closing bracket.
[2552] Fix | Delete
);
[2553] Fix | Delete
[2554] Fix | Delete
while ( preg_match( $tag_pattern, $text, $regex ) ) {
[2555] Fix | Delete
$full_match = $regex[0];
[2556] Fix | Delete
$has_leading_slash = ! empty( $regex[1] );
[2557] Fix | Delete
$tag_name = $regex[2];
[2558] Fix | Delete
$tag = strtolower( $tag_name );
[2559] Fix | Delete
$is_single_tag = in_array( $tag, $single_tags, true );
[2560] Fix | Delete
$pre_attribute_ws = isset( $regex[4] ) ? $regex[4] : '';
[2561] Fix | Delete
$attributes = trim( isset( $regex[5] ) ? $regex[5] : $regex[3] );
[2562] Fix | Delete
$has_self_closer = '/' === substr( $attributes, -1 );
[2563] Fix | Delete
[2564] Fix | Delete
$newtext .= $tagqueue;
[2565] Fix | Delete
[2566] Fix | Delete
$i = strpos( $text, $full_match );
[2567] Fix | Delete
$l = strlen( $full_match );
[2568] Fix | Delete
[2569] Fix | Delete
// Clear the shifter.
[2570] Fix | Delete
$tagqueue = '';
[2571] Fix | Delete
if ( $has_leading_slash ) { // End tag.
[2572] Fix | Delete
// If too many closing tags.
[2573] Fix | Delete
if ( $stacksize <= 0 ) {
[2574] Fix | Delete
$tag = '';
[2575] Fix | Delete
// Or close to be safe $tag = '/' . $tag.
[2576] Fix | Delete
[2577] Fix | Delete
// If stacktop value = tag close value, then pop.
[2578] Fix | Delete
} elseif ( $tagstack[ $stacksize - 1 ] === $tag ) { // Found closing tag.
[2579] Fix | Delete
$tag = '</' . $tag . '>'; // Close tag.
[2580] Fix | Delete
array_pop( $tagstack );
[2581] Fix | Delete
$stacksize--;
[2582] Fix | Delete
} else { // Closing tag not at top, search for it.
[2583] Fix | Delete
for ( $j = $stacksize - 1; $j >= 0; $j-- ) {
[2584] Fix | Delete
if ( $tagstack[ $j ] === $tag ) {
[2585] Fix | Delete
// Add tag to tagqueue.
[2586] Fix | Delete
for ( $k = $stacksize - 1; $k >= $j; $k-- ) {
[2587] Fix | Delete
$tagqueue .= '</' . array_pop( $tagstack ) . '>';
[2588] Fix | Delete
$stacksize--;
[2589] Fix | Delete
}
[2590] Fix | Delete
break;
[2591] Fix | Delete
}
[2592] Fix | Delete
}
[2593] Fix | Delete
$tag = '';
[2594] Fix | Delete
}
[2595] Fix | Delete
} else { // Begin tag.
[2596] Fix | Delete
if ( $has_self_closer ) { // If it presents itself as a self-closing tag...
[2597] Fix | Delete
// ...but it isn't a known single-entity self-closing tag, then don't let it be treated as such
[2598] Fix | Delete
// and immediately close it with a closing tag (the tag will encapsulate no text as a result).
[2599] Fix | Delete
if ( ! $is_single_tag ) {
[2600] Fix | Delete
$attributes = trim( substr( $attributes, 0, -1 ) ) . "></$tag";
[2601] Fix | Delete
}
[2602] Fix | Delete
} elseif ( $is_single_tag ) { // Else if it's a known single-entity tag but it doesn't close itself, do so.
[2603] Fix | Delete
$pre_attribute_ws = ' ';
[2604] Fix | Delete
$attributes .= '/';
[2605] Fix | Delete
} else { // It's not a single-entity tag.
[2606] Fix | Delete
// If the top of the stack is the same as the tag we want to push, close previous tag.
[2607] Fix | Delete
if ( $stacksize > 0 && ! in_array( $tag, $nestable_tags, true ) && $tagstack[ $stacksize - 1 ] === $tag ) {
[2608] Fix | Delete
$tagqueue = '</' . array_pop( $tagstack ) . '>';
[2609] Fix | Delete
$stacksize--;
[2610] Fix | Delete
}
[2611] Fix | Delete
$stacksize = array_push( $tagstack, $tag );
[2612] Fix | Delete
}
[2613] Fix | Delete
[2614] Fix | Delete
// Attributes.
[2615] Fix | Delete
if ( $has_self_closer && $is_single_tag ) {
[2616] Fix | Delete
// We need some space - avoid <br/> and prefer <br />.
[2617] Fix | Delete
$pre_attribute_ws = ' ';
[2618] Fix | Delete
}
[2619] Fix | Delete
[2620] Fix | Delete
$tag = '<' . $tag . $pre_attribute_ws . $attributes . '>';
[2621] Fix | Delete
// If already queuing a close tag, then put this tag on too.
[2622] Fix | Delete
if ( ! empty( $tagqueue ) ) {
[2623] Fix | Delete
$tagqueue .= $tag;
[2624] Fix | Delete
$tag = '';
[2625] Fix | Delete
}
[2626] Fix | Delete
}
[2627] Fix | Delete
$newtext .= substr( $text, 0, $i ) . $tag;
[2628] Fix | Delete
$text = substr( $text, $i + $l );
[2629] Fix | Delete
}
[2630] Fix | Delete
[2631] Fix | Delete
// Clear tag queue.
[2632] Fix | Delete
$newtext .= $tagqueue;
[2633] Fix | Delete
[2634] Fix | Delete
// Add remaining text.
[2635] Fix | Delete
$newtext .= $text;
[2636] Fix | Delete
[2637] Fix | Delete
while ( $x = array_pop( $tagstack ) ) {
[2638] Fix | Delete
$newtext .= '</' . $x . '>'; // Add remaining tags to close.
[2639] Fix | Delete
}
[2640] Fix | Delete
[2641] Fix | Delete
// WP fix for the bug with HTML comments.
[2642] Fix | Delete
$newtext = str_replace( '< !--', '<!--', $newtext );
[2643] Fix | Delete
$newtext = str_replace( '< !--', '< !--', $newtext );
[2644] Fix | Delete
[2645] Fix | Delete
return $newtext;
[2646] Fix | Delete
}
[2647] Fix | Delete
[2648] Fix | Delete
/**
[2649] Fix | Delete
* Acts on text which is about to be edited.
[2650] Fix | Delete
*
[2651] Fix | Delete
* The $content is run through esc_textarea(), which uses htmlspecialchars()
[2652] Fix | Delete
* to convert special characters to HTML entities. If `$richedit` is set to true,
[2653] Fix | Delete
* it is simply a holder for the {@see 'format_to_edit'} filter.
[2654] Fix | Delete
*
[2655] Fix | Delete
* @since 0.71
[2656] Fix | Delete
* @since 4.4.0 The `$richedit` parameter was renamed to `$rich_text` for clarity.
[2657] Fix | Delete
*
[2658] Fix | Delete
* @param string $content The text about to be edited.
[2659] Fix | Delete
* @param bool $rich_text Optional. Whether `$content` should be considered rich text,
[2660] Fix | Delete
* in which case it would not be passed through esc_textarea().
[2661] Fix | Delete
* Default false.
[2662] Fix | Delete
* @return string The text after the filter (and possibly htmlspecialchars()) has been run.
[2663] Fix | Delete
*/
[2664] Fix | Delete
function format_to_edit( $content, $rich_text = false ) {
[2665] Fix | Delete
/**
[2666] Fix | Delete
* Filters the text to be formatted for editing.
[2667] Fix | Delete
*
[2668] Fix | Delete
* @since 1.2.0
[2669] Fix | Delete
*
[2670] Fix | Delete
* @param string $content The text, prior to formatting for editing.
[2671] Fix | Delete
*/
[2672] Fix | Delete
$content = apply_filters( 'format_to_edit', $content );
[2673] Fix | Delete
if ( ! $rich_text ) {
[2674] Fix | Delete
$content = esc_textarea( $content );
[2675] Fix | Delete
}
[2676] Fix | Delete
return $content;
[2677] Fix | Delete
}
[2678] Fix | Delete
[2679] Fix | Delete
/**
[2680] Fix | Delete
* Add leading zeros when necessary.
[2681] Fix | Delete
*
[2682] Fix | Delete
* If you set the threshold to '4' and the number is '10', then you will get
[2683] Fix | Delete
* back '0010'. If you set the threshold to '4' and the number is '5000', then you
[2684] Fix | Delete
* will get back '5000'.
[2685] Fix | Delete
*
[2686] Fix | Delete
* Uses sprintf to append the amount of zeros based on the $threshold parameter
[2687] Fix | Delete
* and the size of the number. If the number is large enough, then no zeros will
[2688] Fix | Delete
* be appended.
[2689] Fix | Delete
*
[2690] Fix | Delete
* @since 0.71
[2691] Fix | Delete
*
[2692] Fix | Delete
* @param int $number Number to append zeros to if not greater than threshold.
[2693] Fix | Delete
* @param int $threshold Digit places number needs to be to not have zeros added.
[2694] Fix | Delete
* @return string Adds leading zeros to number if needed.
[2695] Fix | Delete
*/
[2696] Fix | Delete
function zeroise( $number, $threshold ) {
[2697] Fix | Delete
return sprintf( '%0' . $threshold . 's', $number );
[2698] Fix | Delete
}
[2699] Fix | Delete
[2700] Fix | Delete
/**
[2701] Fix | Delete
* Adds backslashes before letters and before a number at the start of a string.
[2702] Fix | Delete
*
[2703] Fix | Delete
* @since 0.71
[2704] Fix | Delete
*
[2705] Fix | Delete
* @param string $string Value to which backslashes will be added.
[2706] Fix | Delete
* @return string String with backslashes inserted.
[2707] Fix | Delete
*/
[2708] Fix | Delete
function backslashit( $string ) {
[2709] Fix | Delete
if ( isset( $string[0] ) && $string[0] >= '0' && $string[0] <= '9' ) {
[2710] Fix | Delete
$string = '\\\\' . $string;
[2711] Fix | Delete
}
[2712] Fix | Delete
return addcslashes( $string, 'A..Za..z' );
[2713] Fix | Delete
}
[2714] Fix | Delete
[2715] Fix | Delete
/**
[2716] Fix | Delete
* Appends a trailing slash.
[2717] Fix | Delete
*
[2718] Fix | Delete
* Will remove trailing forward and backslashes if it exists already before adding
[2719] Fix | Delete
* a trailing forward slash. This prevents double slashing a string or path.
[2720] Fix | Delete
*
[2721] Fix | Delete
* The primary use of this is for paths and thus should be used for paths. It is
[2722] Fix | Delete
* not restricted to paths and offers no specific path support.
[2723] Fix | Delete
*
[2724] Fix | Delete
* @since 1.2.0
[2725] Fix | Delete
*
[2726] Fix | Delete
* @param string $string What to add the trailing slash to.
[2727] Fix | Delete
* @return string String with trailing slash added.
[2728] Fix | Delete
*/
[2729] Fix | Delete
function trailingslashit( $string ) {
[2730] Fix | Delete
return untrailingslashit( $string ) . '/';
[2731] Fix | Delete
}
[2732] Fix | Delete
[2733] Fix | Delete
/**
[2734] Fix | Delete
* Removes trailing forward slashes and backslashes if they exist.
[2735] Fix | Delete
*
[2736] Fix | Delete
* The primary use of this is for paths and thus should be used for paths. It is
[2737] Fix | Delete
* not restricted to paths and offers no specific path support.
[2738] Fix | Delete
*
[2739] Fix | Delete
* @since 2.2.0
[2740] Fix | Delete
*
[2741] Fix | Delete
* @param string $string What to remove the trailing slashes from.
[2742] Fix | Delete
* @return string String without the trailing slashes.
[2743] Fix | Delete
*/
[2744] Fix | Delete
function untrailingslashit( $string ) {
[2745] Fix | Delete
return rtrim( $string, '/\\' );
[2746] Fix | Delete
}
[2747] Fix | Delete
[2748] Fix | Delete
/**
[2749] Fix | Delete
* Adds slashes to escape strings.
[2750] Fix | Delete
*
[2751] Fix | Delete
* Slashes will first be removed if magic_quotes_gpc is set, see {@link
[2752] Fix | Delete
* https://www.php.net/magic_quotes} for more details.
[2753] Fix | Delete
*
[2754] Fix | Delete
* @since 0.71
[2755] Fix | Delete
*
[2756] Fix | Delete
* @param string $gpc The string returned from HTTP request data.
[2757] Fix | Delete
* @return string Returns a string escaped with slashes.
[2758] Fix | Delete
*/
[2759] Fix | Delete
function addslashes_gpc( $gpc ) {
[2760] Fix | Delete
return wp_slash( $gpc );
[2761] Fix | Delete
}
[2762] Fix | Delete
[2763] Fix | Delete
/**
[2764] Fix | Delete
* Navigates through an array, object, or scalar, and removes slashes from the values.
[2765] Fix | Delete
*
[2766] Fix | Delete
* @since 2.0.0
[2767] Fix | Delete
*
[2768] Fix | Delete
* @param mixed $value The value to be stripped.
[2769] Fix | Delete
* @return mixed Stripped value.
[2770] Fix | Delete
*/
[2771] Fix | Delete
function stripslashes_deep( $value ) {
[2772] Fix | Delete
return map_deep( $value, 'stripslashes_from_strings_only' );
[2773] Fix | Delete
}
[2774] Fix | Delete
[2775] Fix | Delete
/**
[2776] Fix | Delete
* Callback function for `stripslashes_deep()` which strips slashes from strings.
[2777] Fix | Delete
*
[2778] Fix | Delete
* @since 4.4.0
[2779] Fix | Delete
*
[2780] Fix | Delete
* @param mixed $value The array or string to be stripped.
[2781] Fix | Delete
* @return mixed The stripped value.
[2782] Fix | Delete
*/
[2783] Fix | Delete
function stripslashes_from_strings_only( $value ) {
[2784] Fix | Delete
return is_string( $value ) ? stripslashes( $value ) : $value;
[2785] Fix | Delete
}
[2786] Fix | Delete
[2787] Fix | Delete
/**
[2788] Fix | Delete
* Navigates through an array, object, or scalar, and encodes the values to be used in a URL.
[2789] Fix | Delete
*
[2790] Fix | Delete
* @since 2.2.0
[2791] Fix | Delete
*
[2792] Fix | Delete
* @param mixed $value The array or string to be encoded.
[2793] Fix | Delete
* @return mixed The encoded value.
[2794] Fix | Delete
*/
[2795] Fix | Delete
function urlencode_deep( $value ) {
[2796] Fix | Delete
return map_deep( $value, 'urlencode' );
[2797] Fix | Delete
}
[2798] Fix | Delete
[2799] Fix | Delete
/**
[2800] Fix | Delete
* Navigates through an array, object, or scalar, and raw-encodes the values to be used in a URL.
[2801] Fix | Delete
*
[2802] Fix | Delete
* @since 3.4.0
[2803] Fix | Delete
*
[2804] Fix | Delete
* @param mixed $value The array or string to be encoded.
[2805] Fix | Delete
* @return mixed The encoded value.
[2806] Fix | Delete
*/
[2807] Fix | Delete
function rawurlencode_deep( $value ) {
[2808] Fix | Delete
return map_deep( $value, 'rawurlencode' );
[2809] Fix | Delete
}
[2810] Fix | Delete
[2811] Fix | Delete
/**
[2812] Fix | Delete
* Navigates through an array, object, or scalar, and decodes URL-encoded values
[2813] Fix | Delete
*
[2814] Fix | Delete
* @since 4.4.0
[2815] Fix | Delete
*
[2816] Fix | Delete
* @param mixed $value The array or string to be decoded.
[2817] Fix | Delete
* @return mixed The decoded value.
[2818] Fix | Delete
*/
[2819] Fix | Delete
function urldecode_deep( $value ) {
[2820] Fix | Delete
return map_deep( $value, 'urldecode' );
[2821] Fix | Delete
}
[2822] Fix | Delete
[2823] Fix | Delete
/**
[2824] Fix | Delete
* Converts email addresses characters to HTML entities to block spam bots.
[2825] Fix | Delete
*
[2826] Fix | Delete
* @since 0.71
[2827] Fix | Delete
*
[2828] Fix | Delete
* @param string $email_address Email address.
[2829] Fix | Delete
* @param int $hex_encoding Optional. Set to 1 to enable hex encoding.
[2830] Fix | Delete
* @return string Converted email address.
[2831] Fix | Delete
*/
[2832] Fix | Delete
function antispambot( $email_address, $hex_encoding = 0 ) {
[2833] Fix | Delete
$email_no_spam_address = '';
[2834] Fix | Delete
for ( $i = 0, $len = strlen( $email_address ); $i < $len; $i++ ) {
[2835] Fix | Delete
$j = rand( 0, 1 + $hex_encoding );
[2836] Fix | Delete
if ( 0 == $j ) {
[2837] Fix | Delete
$email_no_spam_address .= '&#' . ord( $email_address[ $i ] ) . ';';
[2838] Fix | Delete
} elseif ( 1 == $j ) {
[2839] Fix | Delete
$email_no_spam_address .= $email_address[ $i ];
[2840] Fix | Delete
} elseif ( 2 == $j ) {
[2841] Fix | Delete
$email_no_spam_address .= '%' . zeroise( dechex( ord( $email_address[ $i ] ) ), 2 );
[2842] Fix | Delete
}
[2843] Fix | Delete
}
[2844] Fix | Delete
[2845] Fix | Delete
return str_replace( '@', '&#64;', $email_no_spam_address );
[2846] Fix | Delete
}
[2847] Fix | Delete
[2848] Fix | Delete
/**
[2849] Fix | Delete
* Callback to convert URI match to HTML A element.
[2850] Fix | Delete
*
[2851] Fix | Delete
* This function was backported from 2.5.0 to 2.3.2. Regex callback for make_clickable().
[2852] Fix | Delete
*
[2853] Fix | Delete
* @since 2.3.2
[2854] Fix | Delete
* @access private
[2855] Fix | Delete
*
[2856] Fix | Delete
* @param array $matches Single Regex Match.
[2857] Fix | Delete
* @return string HTML A element with URI address.
[2858] Fix | Delete
*/
[2859] Fix | Delete
function _make_url_clickable_cb( $matches ) {
[2860] Fix | Delete
$url = $matches[2];
[2861] Fix | Delete
[2862] Fix | Delete
if ( ')' === $matches[3] && strpos( $url, '(' ) ) {
[2863] Fix | Delete
// If the trailing character is a closing parethesis, and the URL has an opening parenthesis in it,
[2864] Fix | Delete
// add the closing parenthesis to the URL. Then we can let the parenthesis balancer do its thing below.
[2865] Fix | Delete
$url .= $matches[3];
[2866] Fix | Delete
$suffix = '';
[2867] Fix | Delete
} else {
[2868] Fix | Delete
$suffix = $matches[3];
[2869] Fix | Delete
}
[2870] Fix | Delete
[2871] Fix | Delete
// Include parentheses in the URL only if paired.
[2872] Fix | Delete
while ( substr_count( $url, '(' ) < substr_count( $url, ')' ) ) {
[2873] Fix | Delete
$suffix = strrchr( $url, ')' ) . $suffix;
[2874] Fix | Delete
$url = substr( $url, 0, strrpos( $url, ')' ) );
[2875] Fix | Delete
}
[2876] Fix | Delete
[2877] Fix | Delete
$url = esc_url( $url );
[2878] Fix | Delete
if ( empty( $url ) ) {
[2879] Fix | Delete
return $matches[0];
[2880] Fix | Delete
}
[2881] Fix | Delete
[2882] Fix | Delete
if ( 'comment_text' === current_filter() ) {
[2883] Fix | Delete
$rel = 'nofollow ugc';
[2884] Fix | Delete
} else {
[2885] Fix | Delete
$rel = 'nofollow';
[2886] Fix | Delete
}
[2887] Fix | Delete
[2888] Fix | Delete
/**
[2889] Fix | Delete
* Filters the rel value that is added to URL matches converted to links.
[2890] Fix | Delete
*
[2891] Fix | Delete
* @since 5.3.0
[2892] Fix | Delete
*
[2893] Fix | Delete
* @param string $rel The rel value.
[2894] Fix | Delete
* @param string $url The matched URL being converted to a link tag.
[2895] Fix | Delete
*/
[2896] Fix | Delete
$rel = apply_filters( 'make_clickable_rel', $rel, $url );
[2897] Fix | Delete
$rel = esc_attr( $rel );
[2898] Fix | Delete
[2899] Fix | Delete
return $matches[1] . "<a href=\"$url\" rel=\"$rel\">$url</a>" . $suffix;
[2900] Fix | Delete
}
[2901] Fix | Delete
[2902] Fix | Delete
/**
[2903] Fix | Delete
* Callback to convert URL match to HTML A element.
[2904] Fix | Delete
*
[2905] Fix | Delete
* This function was backported from 2.5.0 to 2.3.2. Regex callback for make_clickable().
[2906] Fix | Delete
*
[2907] Fix | Delete
* @since 2.3.2
[2908] Fix | Delete
* @access private
[2909] Fix | Delete
*
[2910] Fix | Delete
* @param array $matches Single Regex Match.
[2911] Fix | Delete
* @return string HTML A element with URL address.
[2912] Fix | Delete
*/
[2913] Fix | Delete
function _make_web_ftp_clickable_cb( $matches ) {
[2914] Fix | Delete
$ret = '';
[2915] Fix | Delete
$dest = $matches[2];
[2916] Fix | Delete
$dest = 'http://' . $dest;
[2917] Fix | Delete
[2918] Fix | Delete
// Removed trailing [.,;:)] from URL.
[2919] Fix | Delete
$last_char = substr( $dest, -1 );
[2920] Fix | Delete
if ( in_array( $last_char, array( '.', ',', ';', ':', ')' ), true ) === true ) {
[2921] Fix | Delete
$ret = $last_char;
[2922] Fix | Delete
$dest = substr( $dest, 0, strlen( $dest ) - 1 );
[2923] Fix | Delete
}
[2924] Fix | Delete
[2925] Fix | Delete
$dest = esc_url( $dest );
[2926] Fix | Delete
if ( empty( $dest ) ) {
[2927] Fix | Delete
return $matches[0];
[2928] Fix | Delete
}
[2929] Fix | Delete
[2930] Fix | Delete
if ( 'comment_text' === current_filter() ) {
[2931] Fix | Delete
$rel = 'nofollow ugc';
[2932] Fix | Delete
} else {
[2933] Fix | Delete
$rel = 'nofollow';
[2934] Fix | Delete
}
[2935] Fix | Delete
[2936] Fix | Delete
/** This filter is documented in wp-includes/formatting.php */
[2937] Fix | Delete
$rel = apply_filters( 'make_clickable_rel', $rel, $dest );
[2938] Fix | Delete
$rel = esc_attr( $rel );
[2939] Fix | Delete
[2940] Fix | Delete
return $matches[1] . "<a href=\"$dest\" rel=\"$rel\">$dest</a>$ret";
[2941] Fix | Delete
}
[2942] Fix | Delete
[2943] Fix | Delete
/**
[2944] Fix | Delete
* Callback to convert email address match to HTML A element.
[2945] Fix | Delete
*
[2946] Fix | Delete
* This function was backported from 2.5.0 to 2.3.2. Regex callback for make_clickable().
[2947] Fix | Delete
*
[2948] Fix | Delete
* @since 2.3.2
[2949] Fix | Delete
* @access private
[2950] Fix | Delete
*
[2951] Fix | Delete
* @param array $matches Single Regex Match.
[2952] Fix | Delete
* @return string HTML A element with email address.
[2953] Fix | Delete
*/
[2954] Fix | Delete
function _make_email_clickable_cb( $matches ) {
[2955] Fix | Delete
$email = $matches[2] . '@' . $matches[3];
[2956] Fix | Delete
return $matches[1] . "<a href=\"mailto:$email\">$email</a>";
[2957] Fix | Delete
}
[2958] Fix | Delete
[2959] Fix | Delete
/**
[2960] Fix | Delete
* Convert plaintext URI to HTML links.
[2961] Fix | Delete
*
[2962] Fix | Delete
* Converts URI, www and ftp, and email addresses. Finishes by fixing links
[2963] Fix | Delete
* within links.
[2964] Fix | Delete
*
[2965] Fix | Delete
* @since 0.71
[2966] Fix | Delete
*
[2967] Fix | Delete
* @param string $text Content to convert URIs.
[2968] Fix | Delete
* @return string Content with converted URIs.
[2969] Fix | Delete
*/
[2970] Fix | Delete
function make_clickable( $text ) {
[2971] Fix | Delete
$r = '';
[2972] Fix | Delete
$textarr = preg_split( '/(<[^<>]+>)/', $text, -1, PREG_SPLIT_DELIM_CAPTURE ); // Split out HTML tags.
[2973] Fix | Delete
$nested_code_pre = 0; // Keep track of how many levels link is nested inside <pre> or <code>.
[2974] Fix | Delete
foreach ( $textarr as $piece ) {
[2975] Fix | Delete
[2976] Fix | Delete
if ( preg_match( '|^<code[\s>]|i', $piece ) || preg_match( '|^<pre[\s>]|i', $piece ) || preg_match( '|^<script[\s>]|i', $piece ) || preg_match( '|^<style[\s>]|i', $piece ) ) {
[2977] Fix | Delete
$nested_code_pre++;
[2978] Fix | Delete
} elseif ( $nested_code_pre && ( '</code>' === strtolower( $piece ) || '</pre>' === strtolower( $piece ) || '</script>' === strtolower( $piece ) || '</style>' === strtolower( $piece ) ) ) {
[2979] Fix | Delete
$nested_code_pre--;
[2980] Fix | Delete
}
[2981] Fix | Delete
[2982] Fix | Delete
if ( $nested_code_pre || empty( $piece ) || ( '<' === $piece[0] && ! preg_match( '|^<\s*[\w]{1,20}+://|', $piece ) ) ) {
[2983] Fix | Delete
$r .= $piece;
[2984] Fix | Delete
continue;
[2985] Fix | Delete
}
[2986] Fix | Delete
[2987] Fix | Delete
// Long strings might contain expensive edge cases...
[2988] Fix | Delete
if ( 10000 < strlen( $piece ) ) {
[2989] Fix | Delete
// ...break it up.
[2990] Fix | Delete
foreach ( _split_str_by_whitespace( $piece, 2100 ) as $chunk ) { // 2100: Extra room for scheme and leading and trailing paretheses.
[2991] Fix | Delete
if ( 2101 < strlen( $chunk ) ) {
[2992] Fix | Delete
$r .= $chunk; // Too big, no whitespace: bail.
[2993] Fix | Delete
} else {
[2994] Fix | Delete
$r .= make_clickable( $chunk );
[2995] Fix | Delete
}
[2996] Fix | Delete
}
[2997] Fix | Delete
} else {
[2998] Fix | Delete
$ret = " $piece "; // Pad with whitespace to simplify the regexes.
[2999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function