Custom fields url improved
This commit is contained in:
parent
9a24c90725
commit
f7f81f5344
|
@ -48,15 +48,18 @@ if (isset($config['homedir'])) {
|
|||
*/
|
||||
function ui_bbcode_to_html($text, $allowed_tags=['[url]'])
|
||||
{
|
||||
$return = $text;
|
||||
$return = io_safe_output($text);
|
||||
|
||||
if (array_search('[url]', $allowed_tags) !== false) {
|
||||
$return = preg_replace(
|
||||
'/\[url=([^\]]*)\]/',
|
||||
'<a target="_blank" rel="noopener noreferrer" href="$1">',
|
||||
$return
|
||||
);
|
||||
$return = str_replace('[/url]', '</a>', $return);
|
||||
// If link hasn't http, add it.
|
||||
if (preg_match('/https?:\/\//', $return)) {
|
||||
$html_bbcode = '<a target="_blank" rel="noopener noreferrer" href="$1">$2</a>';
|
||||
} else {
|
||||
$html_bbcode = '<a target="_blank" rel="noopener noreferrer" href="http://$1">$2</a>';
|
||||
}
|
||||
|
||||
// Replace bbcode format [url=www.example.org] String [/url] with or without http and slashes
|
||||
$return = preg_replace('/\[url(?|](((?:https?:\/\/)?[^[]+))|(?:=[\'"]?((?:https?:\/\/)?[^]]+?)[\'"]?)](.+?))\[\/url]/', $html_bbcode, $return);
|
||||
}
|
||||
|
||||
return $return;
|
||||
|
|
Loading…
Reference in New Issue