better handle urls
This commit is contained in:
@@ -50,7 +50,14 @@ class CollapsibleTextBoxWidget
|
||||
|
||||
$out = nl2br($out);
|
||||
|
||||
$out = preg_replace('|(https?://[^\s]+)|i', '<a href="\1">\1</a>', $out);
|
||||
$out = preg_replace_callback('#\b((https?://|ftp://|mailto:)[^\s]+)#i', function($m) {
|
||||
$href = $m[1];
|
||||
$text = $href;
|
||||
if (strpos($text, 'mailto:') === 0) {
|
||||
$text = str_replace('mailto:', '', $text);
|
||||
}
|
||||
return "<a href=\"".e($href)."\">".e($text)."</a>";
|
||||
}, $out);
|
||||
|
||||
return $out;
|
||||
}
|
||||
@@ -67,7 +74,9 @@ class CollapsibleTextBoxWidget
|
||||
}
|
||||
|
||||
if ($this->collapsing) {
|
||||
return '<div class="block-collapse" style="max-height:'.$this->maxHeight.'">' . $prefix . $content . '</div>';
|
||||
return '<div class="block-collapse"
|
||||
title="Click to expand / Double-click to collapse"
|
||||
style="max-height:'.$this->maxHeight.'">' . $prefix . $content . '</div>';
|
||||
} else {
|
||||
return $prefix.'<div>' . $prefix . $content . '</div>';
|
||||
}
|
||||
|
||||
@@ -31,6 +31,23 @@ class WidgetFactory
|
||||
"</div>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the given string to a-href if it is a link.
|
||||
*
|
||||
* @param $href
|
||||
* @return string
|
||||
*/
|
||||
public function tryLink($href)
|
||||
{
|
||||
$href = trim($href);
|
||||
if (starts_with($href, ['http://', 'https://', 'mailto:', 'ftp://'])) {
|
||||
$href_e = e($href);
|
||||
return "<a href=\"".$href_e."\">".$href_e."</a>";
|
||||
} else {
|
||||
return $href;
|
||||
}
|
||||
}
|
||||
|
||||
public function collapsible($text, $thrSize, $maxHeight)
|
||||
{
|
||||
return new CollapsibleTextBoxWidget($text, $thrSize, $maxHeight);
|
||||
|
||||
Reference in New Issue
Block a user