Allow URIs in frame comments

This commit is contained in:
filp
2013-04-17 15:10:08 +01:00
parent 5b40a9e535
commit 56f94f4ee3
2 changed files with 15 additions and 3 deletions
+14 -2
View File
@@ -101,8 +101,20 @@ class PrettyPageHandler extends Handler
$v->tables = array_merge($this->getDataTables(), $v->tables);
call_user_func(function() use($templateFile, $v) {
// $e -> cleanup output
$e = function($_) { return htmlspecialchars($_, ENT_QUOTES, 'UTF-8'); };
// $e -> cleanup output, optionally preserving URIs as anchors:
$e = function($_, $allowLinks = false) {
$escaped = htmlspecialchars($_, ENT_QUOTES, 'UTF-8');
// convert URIs to clickable anchor elements:
if($allowLinks) {
$escaped = preg_replace(
'@([A-z]+?://([-\w\.]+[-\w])+(:\d+)?(/([\w/_\.#-]*(\?\S+)?[^\.\s])?)?)@',
"<a href=\"$1\" target=\"_blank\">$1</a>", $escaped
);
}
return $escaped;
};
// $slug -> sluggify string (i.e: Hello world! -> hello-world)
$slug = function($_) {
+1 -1
View File
@@ -98,7 +98,7 @@
<?php extract($comment) ?>
<div class="frame-comment" id="comment-<?php echo $i . '-' . $commentNo ?>">
<span class="frame-comment-context"><?php echo $e($context) ?></span>
<?php echo $e($comment) ?>
<?php echo $e($comment, true) ?>
</div>
<?php endforeach ?>
</div>