Merge branch 'ent-4132-custom-fields-url' into 'develop'

Custom fields url improved

See merge request artica/pandorafms!2525
This commit is contained in:
Daniel Rodriguez 2019-08-27 10:32:01 +02:00
commit cb8278030a
4 changed files with 12 additions and 11 deletions

View File

@ -825,7 +825,7 @@ $table->class = 'custom_fields_table';
$table->head = [
0 => __('Click to display').ui_print_help_tip(
__('This field allows url insertion using the BBCode\'s url tag').'.<br />'.__('The format is: [url=\'url to navigate\']\'text to show\'[/url]').'.<br /><br />'.__('e.g.: [url=google.com]Google web search[/url]'),
__('This field allows url insertion using the BBCode\'s url tag').'.<br />'.__('The format is: [url=\'url to navigate\']\'text to show\'[/url] or [url]\'url to navigate\'[/url] ').'.<br /><br />'.__('e.g.: [url=google.com]Google web search[/url] or [url]www.goole.com[/url]'),
true
),
];

View File

@ -700,7 +700,7 @@ if ($fields === false) {
foreach ($fields as $field) {
$data[0] = '<b>'.$field['name'].'</b>';
$data[0] .= ui_print_help_tip(
__('This field allows url insertion using the BBCode\'s url tag').'.<br />'.__('The format is: [url=\'url to navigate\']\'text to show\'[/url]').'.<br /><br />'.__('e.g.: [url=google.com]Google web search[/url]'),
__('This field allows url insertion using the BBCode\'s url tag').'.<br />'.__('The format is: [url=\'url to navigate\']\'text to show\'[/url] or [url]\'url to navigate\'[/url] ').'.<br /><br />'.__('e.g.: [url=google.com]Google web search[/url] or [url]www.goole.com[/url]'),
true
);
$combo = [];

View File

@ -292,7 +292,7 @@ if (check_login()) {
$data[] = [
'ref' => $referencia,
'data_custom_field' => $values['name_custom_fields'],
'data_custom_field' => ui_bbcode_to_html($values['name_custom_fields']),
'server' => $values['server_name'],
'agent' => $agent,
'IP' => $values['direccion'],

View File

@ -48,15 +48,16 @@ if (isset($config['homedir'])) {
*/
function ui_bbcode_to_html($text, $allowed_tags=['[url]'])
{
$return = $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?:\/\//', $text)) {
$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, $text);
}
return $return;