Skip to content

Commit

Permalink
Add link target options to $g_html_make_links
Browse files Browse the repository at this point in the history
- Replace "magic numbers" with constants defined in constants_inc.php
- Update manual and config_defaults_inc.php with revised constants

Fixes #20694

Signed-off-by: Damien Regad <dregad@mantisbt.org>

Changes from original submission:
- commits squashed;
- reworded and reformatted the documentation for the new constants;
- referenced the equivalence between LINKS_SAME_WINDOW and ON;
- simplify the code in string_insert_hrefs().
  • Loading branch information
quayzar authored and dregad committed May 14, 2016
1 parent 9e532d6 commit aa91878
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 6 deletions.
12 changes: 8 additions & 4 deletions config_defaults_inc.php
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions core/constant_inc.php
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions core/string_api.php
Expand Up @@ -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 "<a ${t_url_href}>${p_match[1]}</a> [<a ${t_url_href} target=\"_blank\">^</a>]";
if( config_get( 'html_make_links' ) == LINKS_NEW_WINDOW ) {
$t_url_target = ' target="_blank"';
} else {
$t_url_target = '';
}
return "<a ${t_url_href}${t_url_target}>${p_match[1]}</a>";
},
$p_string
);
Expand Down
28 changes: 28 additions & 0 deletions docbook/Admin_Guide/en-US/config/html.xml
Expand Up @@ -6,6 +6,34 @@
<title>HTML</title>

<variablelist>
<varlistentry>
<term>$g_html_make_links</term>
<listitem>
<para>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:
<itemizedlist>
<listitem>
<para><emphasis>OFF</emphasis> - do not convert URLs or emails
</para>
</listitem>
<listitem>
<para><emphasis>LINKS_SAME_WINDOW</emphasis> -
convert to links that open in current tab/window.
NOTE: for backwards-compatibility, this is
equivalent to <emphasis>ON</emphasis>.
</para>
</listitem>
<listitem>
<para><emphasis>LINKS_NEW_WINDOW</emphasis> -
convert to links that open in a new tab/window
</para>
</listitem>
</itemizedlist>
Default is <emphasis>LINKS_SAME_WINDOW</emphasis>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>$g_html_valid_tags</term>
<listitem>
Expand Down

0 comments on commit aa91878

Please sign in to comment.