WordPress.org

Make WordPress Core


Ignore:
Timestamp:
12/15/2010 01:43:30 PM (9 years ago)
Author:
westi
Message:

Ultimate make_clickable. Fixes #14993 props filosofo

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/formatting.php

    r16692 r16948  
    13131313function _make_url_clickable_cb($matches) {
    13141314    $url = $matches[2];
     1315    $suffix = '';
     1316   
     1317    /** Include parentheses in the URL only if paired **/
     1318    while ( substr_count( $url, '(' ) < substr_count( $url, ')' ) ) {
     1319        $suffix = strrchr( $url, ')' ) . $suffix;
     1320        $url = substr( $url, 0, strrpos( $url, ')' ) );
     1321    }
    13151322
    13161323    $url = esc_url($url);
     
    13181325        return $matches[0];
    13191326
    1320     return $matches[1] . "<a href=\"$url\" rel=\"nofollow\">$url</a>";
     1327    return $matches[1] . "<a href=\"$url\" rel=\"nofollow\">$url</a>" . $suffix;
    13211328}
    13221329
     
    13801387    $ret = ' ' . $ret;
    13811388    // in testing, using arrays here was found to be faster
    1382     $ret = preg_replace_callback('#(?<=[\s>])(\()?([\w]+?://(?:[\w\\x80-\\xff\#$%&~/=?@\[\](!+-]|[.,;:](?![\s<]|(\))?([\s]|$))|(?(1)\)(?![\s<.,;:]|$)|\)))+)#is', '_make_url_clickable_cb', $ret);
     1389    $ret = preg_replace_callback('#(?<!=[\'"])(?<=[*\')+.,;:!&$\s>])(\()?([\w]+?://(?:[\w\\x80-\\xff\#%~/?@\[\]-]|[\'*(+.,;:!=&$](?![\b\)]|(\))?([\s]|$))|(?(1)\)(?![\s<.,;:]|$)|\)))+)#is', '_make_url_clickable_cb', $ret);
    13831390    $ret = preg_replace_callback('#([\s>])((www|ftp)\.[\w\\x80-\\xff\#$%&~/.\-;:=,?@\[\]+]+)#is', '_make_web_ftp_clickable_cb', $ret);
    13841391    $ret = preg_replace_callback('#([\s>])([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})#i', '_make_email_clickable_cb', $ret);
Note: See TracChangeset for help on using the changeset viewer.