From b8965ef0658c9ee9178dd2557f9f01d802ce4100 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Fri, 21 Dec 2007 03:14:22 +0000 Subject: [PATCH] Be more selective in what we make clickable. git-svn-id: https://develop.svn.wordpress.org/trunk@6449 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/formatting.php | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index e8c85832d3..7aa1533f9b 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -626,18 +626,36 @@ function antispambot($emailaddy, $mailto=0) { return $emailNOSPAMaddy; } +function _make_url_clickable_cb($matches) { + $url = $matches[2]; + $url = clean_url($url); + if ( empty($url) ) + return $matches[0]; + error_log($matches[0], 0); + return $matches[1] . "$url"; +} + +function _make_web_ftp_clickable_cb($matches) { + $dest = $matches[2]; + $dest = 'http://' . $dest; + $dest = clean_url($dest); + if ( empty($dest) ) + return $matches[0]; + + return $matches[1] . "$dest"; +} + +function _make_email_clickable_cb($matches) { + $email = $matches[2] . '@' . $matches[3]; + return $matches[1] . "$email"; +} + function make_clickable($ret) { $ret = ' ' . $ret; // in testing, using arrays here was found to be faster - $ret = preg_replace( - array( - '#([\s>])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is', - '#([\s>])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is', - '#([\s>])([a-z0-9\-_.]+)@([^,< \n\r]+)#i'), - array( - '$1$2', - '$1$2', - '$1$2@$3'),$ret); + $ret = preg_replace_callback('#([\s>])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is', '_make_url_clickable_cb', $ret); + $ret = preg_replace_callback('#([\s>])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is', '_make_web_ftp_clickable_cb', $ret); + $ret = preg_replace_callback('#([\s>])([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})#i', '_make_email_clickable_cb', $ret); // this one is not in an array because we need it to run last, for cleanup of accidental links within links $ret = preg_replace("#(]+?>|>))]+?>([^>]+?)#i", "$1$3", $ret); $ret = trim($ret);