diff --git a/config_defaults_inc.php b/config_defaults_inc.php index 5be436dbcb..f80977c89e 100644 --- a/config_defaults_inc.php +++ b/config_defaults_inc.php @@ -1781,12 +1781,16 @@ ########################## /** - * html tags - * Set this flag to automatically convert www URLs and - * email addresses into clickable links + * Convert URLs and e-mail addresses to html links. + * This flag controls whether www URLs and email addresses are automatically + * converted to clickable links as well as where the www links open when + * clicked. Valid options are: + * - OFF Do not convert URLs or emails + * - LINKS_SAME_WINDOW Convert to links that open in the current window (DEFAULT) + * - LINKS_NEW_WINDOW Convert to links that open in a new window * @global integer $g_html_make_links */ -$g_html_make_links = ON; +$g_html_make_links = LINKS_SAME_WINDOW; /** * These are the valid html tags for multi-line fields (e.g. description) diff --git a/core/constant_inc.php b/core/constant_inc.php index f212f3ca55..95c5ccb0d2 100644 --- a/core/constant_inc.php +++ b/core/constant_inc.php @@ -593,6 +593,10 @@ define( 'SECONDS_PER_DAY', 86400 ); +# Auto-generated link targets +define( 'LINKS_SAME_WINDOW', 1 ); +define( 'LINKS_NEW_WINDOW', 2 ); + # Obsolete / deprecated constants # Defined below for backwards-compatibility purposes -- Do not use them # Constant # Replaced by diff --git a/core/string_api.php b/core/string_api.php index c113542b53..ca74c459df 100644 --- a/core/string_api.php +++ b/core/string_api.php @@ -503,12 +503,17 @@ function string_insert_hrefs( $p_string ) { $s_email_regex = substr_replace( email_regex_simple(), '(?:mailto:)?', 1, 0 ); } - # Find any URL in a string and replace it by a clickable link + # Find any URL in a string and replace it with a clickable link $p_string = preg_replace_callback( $s_url_regex, function ( $p_match ) { $t_url_href = 'href="' . rtrim( $p_match[1], '.' ) . '"'; - return "${p_match[1]} [^]"; + if( config_get( 'html_make_links' ) == LINKS_NEW_WINDOW ) { + $t_url_target = ' target="_blank"'; + } else { + $t_url_target = ''; + } + return "${p_match[1]}"; }, $p_string ); diff --git a/docbook/Admin_Guide/en-US/config/html.xml b/docbook/Admin_Guide/en-US/config/html.xml index eeb2de5521..4fc1847f09 100644 --- a/docbook/Admin_Guide/en-US/config/html.xml +++ b/docbook/Admin_Guide/en-US/config/html.xml @@ -6,6 +6,34 @@ HTML + + $g_html_make_links + + This flag controls whether www URLs and email addresses are + automatically converted into clickable links as well as where + the www links open when clicked. The options are: + + + OFF - do not convert URLs or emails + + + + LINKS_SAME_WINDOW - + convert to links that open in current tab/window. + NOTE: for backwards-compatibility, this is + equivalent to ON. + + + + LINKS_NEW_WINDOW - + convert to links that open in a new tab/window + + + + Default is LINKS_SAME_WINDOW. + + + $g_html_valid_tags