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 = [ $table->head = [
0 => __('Click to display').ui_print_help_tip( 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 true
), ),
]; ];

View File

@ -700,7 +700,7 @@ if ($fields === false) {
foreach ($fields as $field) { foreach ($fields as $field) {
$data[0] = '<b>'.$field['name'].'</b>'; $data[0] = '<b>'.$field['name'].'</b>';
$data[0] .= ui_print_help_tip( $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 true
); );
$combo = []; $combo = [];

View File

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

View File

@ -48,15 +48,16 @@ if (isset($config['homedir'])) {
*/ */
function ui_bbcode_to_html($text, $allowed_tags=['[url]']) function ui_bbcode_to_html($text, $allowed_tags=['[url]'])
{ {
$return = $text;
if (array_search('[url]', $allowed_tags) !== false) { if (array_search('[url]', $allowed_tags) !== false) {
$return = preg_replace( // If link hasn't http, add it.
'/\[url=([^\]]*)\]/', if (preg_match('/https?:\/\//', $text)) {
'<a target="_blank" rel="noopener noreferrer" href="$1">', $html_bbcode = '<a target="_blank" rel="noopener noreferrer" href="$1">$2</a>';
$return } else {
); $html_bbcode = '<a target="_blank" rel="noopener noreferrer" href="http://$1">$2</a>';
$return = str_replace('[/url]', '</a>', $return); }
// 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; return $return;