WordPress.org

Make WordPress Core

Ticket #8300: leaner_make_url_clickable_cb.diff

File leaner_make_url_clickable_cb.diff, 1.5 KB (added by filosofo, 10 years ago)
  • wp-includes/formatting.php

     
    964964 * @return string HTML A element with URI address.
    965965 */
    966966function _make_url_clickable_cb($matches) {
    967         $ret = '';
    968967        $url = $matches[2];
    969968        $url = clean_url($url);
    970969        if ( empty($url) )
    971970                return $matches[0];
    972         // removed trailing [.,;:] from URL
    973         if ( in_array(substr($url, -1), array('.', ',', ';', ':')) === true ) {
    974                 $ret = substr($url, -1);
    975                 $url = substr($url, 0, strlen($url)-1);
    976         }
    977         return $matches[1] . "<a href=\"$url\" rel=\"nofollow\">$url</a>" . $ret;
     971        return $matches[1] . "<a href=\"$url\" rel=\"nofollow\">$url</a>";
    978972}
    979973
    980974/**
     
    10351029function make_clickable($ret) {
    10361030        $ret = ' ' . $ret;
    10371031        // in testing, using arrays here was found to be faster
    1038         $ret = preg_replace_callback('#([\s>])([\w]+?://[\w\\x80-\\xff\#$%&~/.\-;:=,?@\[\]+]*)#is', '_make_url_clickable_cb', $ret);
     1032        $ret = preg_replace_callback('#(?<=[\s>])(\()?([\w]+?://(?:[\w\\x80-\\xff\#$%&~/\-=?@\[\](+]|[.,;:](?![\s<])|(?(1)\)(?![\s<])|\)))*)#is', '_make_url_clickable_cb', $ret);
    10391033        $ret = preg_replace_callback('#([\s>])((www|ftp)\.[\w\\x80-\\xff\#$%&~/.\-;:=,?@\[\]+]*)#is', '_make_web_ftp_clickable_cb', $ret);
    10401034        $ret = preg_replace_callback('#([\s>])([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})#i', '_make_email_clickable_cb', $ret);
    10411035        // this one is not in an array because we need it to run last, for cleanup of accidental links within links