Show
Ignore:
Timestamp:
12/21/07 03:14:38 (1 year ago)
Author:
ryan
Message:

Be more selective in what we make clickable.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/2.3/wp-includes/formatting.php

    r6183 r6450  
    623623} 
    624624 
     625function _make_url_clickable_cb($matches) { 
     626    $url = $matches[2]; 
     627    $url = clean_url($url); 
     628    if ( empty($url) ) 
     629        return $matches[0]; 
     630        error_log($matches[0], 0); 
     631    return $matches[1] . "<a href=\"$url\" rel=\"nofollow\">$url</a>"; 
     632} 
     633 
     634function _make_web_ftp_clickable_cb($matches) { 
     635    $dest = $matches[2]; 
     636    $dest = 'http://' . $dest; 
     637    $dest = clean_url($dest); 
     638    if ( empty($dest) ) 
     639        return $matches[0]; 
     640 
     641    return $matches[1] . "<a href=\"$dest\" rel=\"nofollow\">$dest</a>"; 
     642} 
     643 
     644function _make_email_clickable_cb($matches) { 
     645    $email = $matches[2] . '@' . $matches[3]; 
     646    return $matches[1] . "<a href=\"mailto:$email\">$email</a>"; 
     647} 
     648 
    625649function make_clickable($ret) { 
    626650    $ret = ' ' . $ret; 
    627651    // in testing, using arrays here was found to be faster 
    628     $ret = preg_replace( 
    629         array( 
    630             '#([\s>])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is', 
    631             '#([\s>])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is', 
    632             '#([\s>])([a-z0-9\-_.]+)@([^,< \n\r]+)#i'), 
    633         array( 
    634             '$1<a href="$2" rel="nofollow">$2</a>', 
    635             '$1<a href="http://$2" rel="nofollow">$2</a>', 
    636             '$1<a href="mailto:$2@$3">$2@$3</a>'),$ret); 
     652    $ret = preg_replace_callback('#([\s>])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is', '_make_url_clickable_cb', $ret); 
     653    $ret = preg_replace_callback('#([\s>])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is', '_make_web_ftp_clickable_cb', $ret); 
     654    $ret = preg_replace_callback('#([\s>])([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})#i', '_make_email_clickable_cb', $ret); 
    637655    // this one is not in an array because we need it to run last, for cleanup of accidental links within links 
    638656    $ret = preg_replace("#(<a( [^>]+?>|>))<a [^>]+?>([^>]+?)</a></a>#i", "$1$3</a>", $ret);