linkify URLs

darcs-hash:20080529181244-84dde-6b51042c5c92581d8aecfbb83630646afc078793.gz
This commit is contained in:
Evan Prodromou 2008-05-29 14:12:44 -04:00
parent f4b8feec0a
commit 58219416ca
1 changed files with 3 additions and 0 deletions

View File

@ -349,10 +349,13 @@ function common_canonical_email($email) {
return $email;
}
define('URL_REGEX', '^|[ \t\r\n])((ftp|http|https|gopher|mailto|news|nntp|telnet|wais|file|prospero|aim|webcal):(([A-Za-z0-9$_.+!*(),;/?:@&~=-])|%[A-Fa-f0-9]{2}){2,}(#([a-zA-Z0-9][a-zA-Z0-9$_.+!*(),;/?:@&~=%-]*))?([A-Za-z0-9$_+!*();/?:~-]))');
function common_render_content($text, $notice) {
$r = htmlspecialchars($text);
$id = $notice->profile_id;
$r = preg_replace('/(^|\s)@([\w-]+)($|\s)/e', "'\\1@'.common_at_link($id, '\\2').'\\3'", $r);
$r = preg_replace('/'.URL_REGEX.'/', '<a href="\\0" class="extlink">\\0</a>', $r);
# XXX: # tags
# XXX: machine tags
return $r;