Skip to:
Content

bbPress.org


Ignore:
Timestamp:
11/24/2009 11:56:40 PM (15 years ago)
Author:
mdawaffe
Message:

better clean_url and esc_url from WP for branches/0.9

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/0.9/bb-includes/wp-functions.php

    r2380 r2381  
    99/* Formatting */
    1010
    11 if ( !function_exists( 'clean_url' ) ) : // [WP6182]
     11if ( !function_exists( 'clean_url' ) ) : // [WP11615]
    1212function clean_url( $url, $protocols = null, $context = 'display' ) {
    1313    $original_url = $url;
    1414
    1515    if ('' == $url) return $url;
    16     $url = preg_replace('|[^a-z0-9-~+_.?#=!&;,/:%@]|i', '', $url);
    17     $strip = array('%0d', '%0a');
    18     $url = str_replace($strip, '', $url);
     16    $url = preg_replace('|[^a-z0-9-~+_.?#=!&;,/:%@$\|*\'()\\x80-\\xff]|i', '', $url);
     17    $strip = array('%0d', '%0a', '%0D', '%0A');
     18    $url = _deep_replace($strip, $url);
    1919    $url = str_replace(';//', '://', $url);
    2020    /* If the URL doesn't appear to contain a scheme, we
    2121     * presume it needs http:// appended (unless a relative
    2222     * link starting with / or a php file).
    23     */
     23     */
    2424    if ( strpos($url, ':') === false &&
    25         substr( $url, 0, 1 ) != '/' && !preg_match('/^[a-z0-9-]+?\.php/i', $url) )
     25        substr( $url, 0, 1 ) != '/' && substr( $url, 0, 1 ) != '#' && !preg_match('/^[a-z0-9-]+?\.php/i', $url) )
    2626        $url = 'http://' . $url;
    2727
    28     // Replace ampersands ony when displaying.
    29     if ( 'display' == $context )
     28    // Replace ampersands and single quotes only when displaying.
     29    if ( 'display' == $context ) {
    3030        $url = preg_replace('/&([^#])(?![a-z]{2,8};)/', '&$1', $url);
     31        $url = str_replace( "'", ''', $url );
     32    }
    3133
    3234    if ( !is_array($protocols) )
     
    3638
    3739    return apply_filters('clean_url', $url, $original_url, $context);
     40}
     41endif;
     42
     43if ( !function_exists( '_deep_replace' ) ) : // [WP11615]
     44function _deep_replace($search, $subject){
     45    $found = true;
     46    while($found) {
     47        $found = false;
     48        foreach( (array) $search as $val ) {
     49            while(strpos($subject, $val) !== false) {
     50                $found = true;
     51                $subject = str_replace($val, '', $subject);
     52            }
     53        }
     54    }
     55
     56    return $subject;
     57}
     58endif;
     59
     60if ( !function_exists( 'esc_url' ) ) : // [WP11383]
     61function esc_url( $url, $protocols = null ) {
     62    return clean_url( $url, $protocols, 'display' );
    3863}
    3964endif;
Note: See TracChangeset for help on using the changeset viewer.