From 60edcd04e52323050792252009512f7592f3b66c Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Sun, 3 Oct 2010 21:51:45 +0200 Subject: Make external links in comments clickable (FS#20137). Comments are now split at link boundaries and links are converted separately. I find this to be a much cleaner way than re-converting comments that have already been converted using htmlspecialchars(). This also doesn't require any callback procedure. Signed-off-by: Lukas Fleischer --- web/lib/aur.inc | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'web/lib') diff --git a/web/lib/aur.inc b/web/lib/aur.inc index bd69c4c..a6292ca 100644 --- a/web/lib/aur.inc +++ b/web/lib/aur.inc @@ -494,3 +494,27 @@ function salted_hash($passwd, $salt) } return md5($salt . $passwd); } + +function parse_comment($comment) +{ + $url_pattern = '/(\b(?:https?|ftp):\/\/[\w\/\#~:.?+=&%@!\-;,]+?' . + '(?=[.:?\-;,]*(?:[^\w\/\#~:.?+=&%@!\-;,]|$)))/iS'; + + $matches = preg_split($url_pattern, $comment, -1, + PREG_SPLIT_DELIM_CAPTURE); + + $html = ''; + for ($i = 0; $i < count($matches); $i++) { + if ($i % 2) { + # convert links + $html .= '' . htmlspecialchars($matches[$i]) . ''; + } + else { + # convert everything else + $html .= nl2br(htmlspecialchars($matches[$i])); + } + } + + return $html; +} -- cgit v1.2.3-54-g00ecf