Commit 60edcd04 authored by Lukas Fleischer's avatar Lukas Fleischer
Browse files

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: default avatarLukas Fleischer <archlinux@cryptocrack.de>
parent a4172249
......@@ -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 .= '<a href="' . htmlspecialchars($matches[$i]) .
'">' . htmlspecialchars($matches[$i]) . '</a>';
}
else {
# convert everything else
$html .= nl2br(htmlspecialchars($matches[$i]));
}
}
return $html;
}
......@@ -25,7 +25,7 @@ while (list($indx, $carr) = each($comments)) { ?>
?></div>
<blockquote class="comment-body">
<div>
<?php echo nl2br(htmlspecialchars($carr['Comments'])) ?>
<?php echo parse_comment($carr['Comments']) ?>
</div>
</blockquote>
<?php
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment