Make WordPress Core

Ticket #14993: make-clickable-ultimate.14993.diff

File make-clickable-ultimate.14993.diff, 1.6 KB (added by filosofo, 13 years ago)
  • wp-includes/formatting.php

     
    13121312 */
    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);
    13171324        if ( empty($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
    13231330/**
     
    13791386function make_clickable($ret) {
    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);
    13851392        // this one is not in an array because we need it to run last, for cleanup of accidental links within links