|
|
4c79b5 |
|
|
|
4c79b5 |
# Mantis - a php based bugtracking system
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
|
|
|
4c79b5 |
# Copyright (C) 2002 - 2007 Mantis Team - mantisbt-dev@lists.sourceforge.net
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# Mantis is free software: you can redistribute it and/or modify
|
|
|
4c79b5 |
# it under the terms of the GNU General Public License as published by
|
|
|
4c79b5 |
# the Free Software Foundation, either version 2 of the License, or
|
|
|
4c79b5 |
# (at your option) any later version.
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
# Mantis is distributed in the hope that it will be useful,
|
|
|
4c79b5 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
4c79b5 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
4c79b5 |
# GNU General Public License for more details.
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
# You should have received a copy of the GNU General Public License
|
|
|
4c79b5 |
# along with Mantis. If not, see <http://www.gnu.org/licenses/>.
|
|
|
4c79b5 |
|
|
|
4c79b5 |
#------------------------------
|
|
|
4c79b5 |
# $Revision: 2643 $
|
|
|
4c79b5 |
# $Author: al $
|
|
|
4c79b5 |
# $Date: 2009-06-18 19:06:27 -0400 (Thu, 18 Jun 2009) $
|
|
|
4c79b5 |
#------------------------------
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$t_core_dir = dirname( __FILE__ ).DIRECTORY_SEPARATOR;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
require_once( $t_core_dir . 'bug_api.php' );
|
|
|
4c79b5 |
require_once( $t_core_dir . 'user_pref_api.php' );
|
|
|
4c79b5 |
|
|
|
4c79b5 |
### String Processing API ###
|
|
|
4c79b5 |
|
|
|
4c79b5 |
### --------------------
|
|
|
4c79b5 |
# Preserve spaces at beginning of lines.
|
|
|
4c79b5 |
# Lines must be separated by \n rather than
|
|
|
4c79b5 |
function string_preserve_spaces_at_bol( $p_string ) {
|
|
|
4c79b5 |
$lines = explode( "\n", $p_string );
|
|
|
4c79b5 |
$line_count = count( $lines );
|
|
|
4c79b5 |
for ( $i = 0; $i < $line_count; $i++ ) {
|
|
|
4c79b5 |
$count = 0;
|
|
|
4c79b5 |
$prefix = '';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$t_char = substr( $lines[$i], $count, 1 );
|
|
|
4c79b5 |
$spaces = 0;
|
|
|
4c79b5 |
while ( ( $t_char == ' ' ) || ( $t_char == "\t" ) ) {
|
|
|
4c79b5 |
if ( $t_char == ' ' )
|
|
|
4c79b5 |
$spaces++;
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
$spaces += 4; // 1 tab = 4 spaces, can be configurable.
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$count++;
|
|
|
4c79b5 |
$t_char = substr( $lines[$i], $count, 1 );
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
for ( $j = 0; $j < $spaces; $j++ ) {
|
|
|
4c79b5 |
$prefix .= ' ';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$lines[$i] = $prefix . substr( $lines[$i], $count );
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
return implode( "\n", $lines );
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
# --------------------
|
|
|
4c79b5 |
# Prepare a string to be printed without being broken into multiple lines
|
|
|
4c79b5 |
function string_no_break( $p_string ) {
|
|
|
4c79b5 |
if ( strpos( $p_string, ' ' ) !== false ) {
|
|
|
4c79b5 |
return '' . $p_string . "";
|
|
|
4c79b5 |
} else {
|
|
|
4c79b5 |
return $p_string;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# --------------------
|
|
|
4c79b5 |
# Similar to nl2br, but fixes up a problem where new lines are doubled between
|
|
|
4c79b5 |
# tags.
|
|
|
4c79b5 |
# additionally, wrap the text an $p_wrap character intervals if the config is set
|
|
|
4c79b5 |
function string_nl2br( $p_string, $p_wrap = 100 ) {
|
|
|
4c79b5 |
$output = '';
|
|
|
4c79b5 |
$pieces = preg_split('/(<pre[^>]*>.*?<\/pre>)/is', $p_string, -1, PREG_SPLIT_DELIM_CAPTURE);
|
|
|
4c79b5 |
if(isset($pieces[1]))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
foreach($pieces as $piece)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if(preg_match('/(<pre[^>]*>.*?<\/pre>)/is', $piece))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$piece = preg_replace("/<br[^>]*?>/", "", $piece);
|
|
|
4c79b5 |
# @@@ thraxisp - this may want to be replaced by html_entity_decode (or equivalent)
|
|
|
4c79b5 |
# if other encoded characters are a problem
|
|
|
4c79b5 |
$piece = preg_replace("/ /", " ", $piece);
|
|
|
4c79b5 |
if ( ON == config_get( 'wrap_in_preformatted_text' ) ) {
|
|
|
4c79b5 |
$output .= preg_replace('/([^\n]{'.$p_wrap.'})(?!<\/pre>)/', "$1\n", $piece);
|
|
|
4c79b5 |
} else {
|
|
|
4c79b5 |
$output .= $piece;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
} else {
|
|
|
4c79b5 |
$output .= nl2br($piece);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
return $output;
|
|
|
4c79b5 |
} else {
|
|
|
4c79b5 |
return nl2br($p_string);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# --------------------
|
|
|
4c79b5 |
# Prepare a multiple line string for display to HTML
|
|
|
4c79b5 |
function string_display( $p_string ) {
|
|
|
4c79b5 |
$p_string = string_strip_hrefs( $p_string );
|
|
|
4c79b5 |
$p_string = string_html_specialchars( $p_string );
|
|
|
4c79b5 |
$p_string = string_restore_valid_html_tags( $p_string, /* multiline = */ true );
|
|
|
4c79b5 |
$p_string = string_preserve_spaces_at_bol( $p_string );
|
|
|
4c79b5 |
$p_string = string_nl2br( $p_string );
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $p_string;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# --------------------
|
|
|
4c79b5 |
# Prepare a single line string for display to HTML
|
|
|
4c79b5 |
function string_display_line( $p_string ) {
|
|
|
4c79b5 |
$p_string = string_strip_hrefs( $p_string );
|
|
|
4c79b5 |
$p_string = string_html_specialchars( $p_string );
|
|
|
4c79b5 |
$p_string = string_restore_valid_html_tags( $p_string, /* multiline = */ false );
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $p_string;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# --------------------
|
|
|
4c79b5 |
# Prepare a string for display to HTML and add href anchors for URLs, emails,
|
|
|
4c79b5 |
# bug references, and cvs references
|
|
|
4c79b5 |
function string_display_links( $p_string ) {
|
|
|
4c79b5 |
$p_string = string_display( $p_string );
|
|
|
4c79b5 |
$p_string = string_insert_hrefs( $p_string );
|
|
|
4c79b5 |
$p_string = string_process_bug_link( $p_string );
|
|
|
4c79b5 |
$p_string = string_process_bugnote_link( $p_string );
|
|
|
4c79b5 |
$p_string = string_process_cvs_link( $p_string );
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $p_string;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# --------------------
|
|
|
4c79b5 |
# Prepare a single line string for display to HTML and add href anchors for
|
|
|
4c79b5 |
# URLs, emails, bug references, and cvs references
|
|
|
4c79b5 |
function string_display_line_links( $p_string ) {
|
|
|
4c79b5 |
$p_string = string_display_line( $p_string );
|
|
|
4c79b5 |
$p_string = string_insert_hrefs( $p_string );
|
|
|
4c79b5 |
$p_string = string_process_bug_link( $p_string );
|
|
|
4c79b5 |
$p_string = string_process_bugnote_link( $p_string );
|
|
|
4c79b5 |
$p_string = string_process_cvs_link( $p_string );
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $p_string;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# --------------------
|
|
|
4c79b5 |
# Prepare a string for display in rss
|
|
|
4c79b5 |
function string_rss_links( $p_string ) {
|
|
|
4c79b5 |
# rss can not start with which spaces will be replaced into by string_display().
|
|
|
4c79b5 |
$t_string = trim( $p_string );
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# same steps as string_display_links() without the preservation of spaces since is undefined in XML.
|
|
|
4c79b5 |
$t_string = string_strip_hrefs( $t_string );
|
|
|
4c79b5 |
$t_string = string_html_specialchars( $t_string );
|
|
|
4c79b5 |
$t_string = string_restore_valid_html_tags( $t_string );
|
|
|
4c79b5 |
$t_string = string_nl2br( $t_string );
|
|
|
4c79b5 |
$t_string = string_insert_hrefs( $t_string );
|
|
|
4c79b5 |
$t_string = string_process_bug_link( $t_string, /* anchor */ true, /* detailInfo */ false, /* fqdn */ true );
|
|
|
4c79b5 |
$t_string = string_process_bugnote_link( $t_string, /* anchor */ true, /* detailInfo */ false, /* fqdn */ true );
|
|
|
4c79b5 |
$t_string = string_process_cvs_link( $t_string );
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# another escaping to escape the special characters created by the generated links
|
|
|
4c79b5 |
$t_string = string_html_specialchars( $t_string );
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $t_string;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# --------------------
|
|
|
4c79b5 |
# Prepare a string for plain text display in email
|
|
|
4c79b5 |
function string_email( $p_string ) {
|
|
|
4c79b5 |
$p_string = string_strip_hrefs( $p_string );
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $p_string;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# --------------------
|
|
|
4c79b5 |
# Prepare a string for plain text display in email and add URLs for bug
|
|
|
4c79b5 |
# links and cvs links
|
|
|
4c79b5 |
function string_email_links( $p_string ) {
|
|
|
4c79b5 |
$p_string = string_email( $p_string );
|
|
|
4c79b5 |
$p_string = string_process_bug_link( $p_string, false );
|
|
|
4c79b5 |
$p_string = string_process_bugnote_link( $p_string, false );
|
|
|
4c79b5 |
$p_string = string_process_cvs_link( $p_string, false );
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $p_string;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# --------------------
|
|
|
4c79b5 |
# Process a string for display in a textarea box
|
|
|
4c79b5 |
function string_textarea( $p_string ) {
|
|
|
4c79b5 |
$p_string = string_html_specialchars( $p_string );
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $p_string;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# --------------------
|
|
|
4c79b5 |
# Process a string for display in a text box
|
|
|
4c79b5 |
function string_attribute( $p_string ) {
|
|
|
4c79b5 |
$p_string = string_html_specialchars( $p_string );
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $p_string;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# --------------------
|
|
|
4c79b5 |
# Process a string for inclusion in a URL as a GET parameter
|
|
|
4c79b5 |
function string_url( $p_string ) {
|
|
|
4c79b5 |
$p_string = rawurlencode( $p_string );
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $p_string;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# --------------------
|
|
|
4c79b5 |
# validate the url as part of this site before continuing
|
|
|
4c79b5 |
function string_sanitize_url( $p_url ) {
|
|
|
4c79b5 |
$t_url = strip_tags( urldecode( $p_url ) );
|
|
|
4c79b5 |
if ( preg_match( '?http(s)*://?', $t_url ) > 0 ) {
|
|
|
4c79b5 |
// no embedded addresses
|
|
|
4c79b5 |
if ( preg_match( '?^' . config_get( 'path' ) . '?', $t_url ) == 0 ) {
|
|
|
4c79b5 |
// url is ok if it begins with our path, if not, replace it
|
|
|
4c79b5 |
$t_url = 'index.php';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
if ( $t_url == '' ) {
|
|
|
4c79b5 |
$t_url = 'index.php';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// split and encode parameters
|
|
|
4c79b5 |
if ( strpos( $t_url, '?' ) !== FALSE ) {
|
|
|
4c79b5 |
list( $t_path, $t_param ) = split( '\?', $t_url, 2 );
|
|
|
4c79b5 |
if ( !is_blank($t_param ) ) {
|
|
|
4c79b5 |
$t_vals = array();
|
|
|
4c79b5 |
parse_str( html_entity_decode( $t_param ), $t_vals );
|
|
|
4c79b5 |
$t_param = '';
|
|
|
4c79b5 |
foreach( $t_vals as $k => $v ) {
|
|
|
4c79b5 |
if ( $t_param != '' ) {
|
|
|
4c79b5 |
$t_param .= '&';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
if ( is_array( $v ) ) {
|
|
|
4c79b5 |
for ( $i = 0, $t_size = sizeof( $v ); $i < $t_size; $i++ ) {
|
|
|
4c79b5 |
$t_param .= $k . urlencode( '[]' ) . '=' . urlencode( strip_tags( urldecode( $v[$i] ) ) );
|
|
|
4c79b5 |
$t_param .= ( $i != $t_size - 1 ) ? '&' : '';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
} else {
|
|
|
4c79b5 |
$t_param .= "$k=" . urlencode( strip_tags( urldecode( $v ) ) );
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
return $t_path . '?' . $t_param;
|
|
|
4c79b5 |
} else {
|
|
|
4c79b5 |
return $t_path;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
} else {
|
|
|
4c79b5 |
return $t_url;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# --------------------
|
|
|
4c79b5 |
# process the $p_string and convert filenames in the format
|
|
|
4c79b5 |
# cvs:filename.ext or cvs:filename.ext:n.nn to a html link
|
|
|
4c79b5 |
# if $p_include_anchor is true, include an tag,
|
|
|
4c79b5 |
# otherwise, just insert the URL as text
|
|
|
4c79b5 |
function string_process_cvs_link( $p_string, $p_include_anchor=true ) {
|
|
|
4c79b5 |
$t_cvs_web = config_get( 'cvs_web' );
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ( $p_include_anchor ) {
|
|
|
4c79b5 |
$t_replace_with = '[CVS] \\1\\5';
|
|
|
4c79b5 |
} else {
|
|
|
4c79b5 |
$t_replace_with = '[CVS] '.$t_cvs_web.'\\1?rev=\\4\\5';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return preg_replace( '/cvs:([^\.\s:,\?!<]+(\.[^\.\s:,\?!<]+)*)(:)?(\d\.[\d\.]+)?([\W\s])?/i',
|
|
|
4c79b5 |
$t_replace_with,
|
|
|
4c79b5 |
$p_string );
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# --------------------
|
|
|
4c79b5 |
# Process $p_string, looking for bug ID references and creating bug view
|
|
|
4c79b5 |
# links for them.
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
# Returns the processed string.
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
# If $p_include_anchor is true, include the href tag, otherwise just insert
|
|
|
4c79b5 |
# the URL
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
# The bug tag ('#' by default) must be at the beginning of the string or
|
|
|
4c79b5 |
# preceeded by a character that is not a letter, a number or an underscore
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
# if $p_include_anchor = false, $p_fqdn is ignored and assumed to true.
|
|
|
4c79b5 |
$string_process_bug_link_callback = array();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
function string_process_bug_link( $p_string, $p_include_anchor = true, $p_detail_info = true, $p_fqdn = false ) {
|
|
|
4c79b5 |
global $string_process_bug_link_callback;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$t_tag = config_get( 'bug_link_tag' );
|
|
|
4c79b5 |
# bail if the link tag is blank
|
|
|
4c79b5 |
if ( '' == $t_tag || $p_string == '' ) {
|
|
|
4c79b5 |
return $p_string;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ( !isset( $string_process_bug_link_callback[$p_include_anchor][$p_detail_info][$p_fqdn] ) ) {
|
|
|
4c79b5 |
if ($p_include_anchor) {
|
|
|
4c79b5 |
$string_process_bug_link_callback[$p_include_anchor][$p_detail_info][$p_fqdn] = create_function('$p_array','
|
|
|
4c79b5 |
if (bug_exists( (int)$p_array[2] ) ) {
|
|
|
4c79b5 |
return $p_array[1] . string_get_bug_view_link( (int)$p_array[2], null, ' . ($p_detail_info ? 'true' : 'false') . ', ' . ($p_fqdn ? 'true' : 'false') . ');
|
|
|
4c79b5 |
} else {
|
|
|
4c79b5 |
return $p_array[0];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
');
|
|
|
4c79b5 |
} else {
|
|
|
4c79b5 |
$string_process_bug_link_callback[$p_include_anchor][$p_detail_info][$p_fqdn] = create_function('$p_array','
|
|
|
4c79b5 |
# We might as well create the link here even if the bug
|
|
|
4c79b5 |
# doesnt exist. In the case above we dont want to do
|
|
|
4c79b5 |
# the summary lookup on a non-existant bug. But here, we
|
|
|
4c79b5 |
# can create the link and by the time it is clicked on, the
|
|
|
4c79b5 |
# bug may exist.
|
|
|
4c79b5 |
return $p_array[1] . string_get_bug_view_url_with_fqdn( (int)$p_array[2], null );
|
|
|
4c79b5 |
');
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$p_string = preg_replace_callback( '/(^|[^\w&])' . preg_quote($t_tag, '/') . '(\d+)\b/', $string_process_bug_link_callback[$p_include_anchor][$p_detail_info][$p_fqdn], $p_string);
|
|
|
4c79b5 |
return $p_string;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# --------------------
|
|
|
4c79b5 |
# Process $p_string, looking for bugnote ID references and creating bug view
|
|
|
4c79b5 |
# links for them.
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
# Returns the processed string.
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
# If $p_include_anchor is true, include the href tag, otherwise just insert
|
|
|
4c79b5 |
# the URL
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
# The bugnote tag ('~' by default) must be at the beginning of the string or
|
|
|
4c79b5 |
# preceeded by a character that is not a letter, a number or an underscore
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
# if $p_include_anchor = false, $p_fqdn is ignored and assumed to true.
|
|
|
4c79b5 |
$string_process_bugnote_link_callback = array();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
function string_process_bugnote_link( $p_string, $p_include_anchor = true, $p_detail_info = true, $p_fqdn = false ) {
|
|
|
4c79b5 |
global $string_process_bugnote_link_callback;
|
|
|
4c79b5 |
$t_tag = config_get( 'bugnote_link_tag' );
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# bail if the link tag is blank
|
|
|
4c79b5 |
if ( '' == $t_tag || $p_string == '' ) {
|
|
|
4c79b5 |
return $p_string;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ( !isset ( $string_process_bugnote_link_callback[$p_include_anchor][$p_detail_info][$p_fqdn] ) ) {
|
|
|
4c79b5 |
if ($p_include_anchor) {
|
|
|
4c79b5 |
$string_process_bugnote_link_callback[$p_include_anchor][$p_detail_info][$p_fqdn] = create_function('$p_array','
|
|
|
4c79b5 |
if ( bugnote_exists( (int)$p_array[2] ) ) {
|
|
|
4c79b5 |
$t_bug_id = bugnote_get_field( (int)$p_array[2], \'bug_id\' );
|
|
|
4c79b5 |
if ( bug_exists( $t_bug_id ) ) {
|
|
|
4c79b5 |
return $p_array[1] . string_get_bugnote_view_link( $t_bug_id, (int)$p_array[2], null, ' . ($p_detail_info ? 'true' : 'false') . ', ' . ($p_fqdn ? 'true' : 'false') . ' );
|
|
|
4c79b5 |
} else {
|
|
|
4c79b5 |
return $p_array[0];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
} else {
|
|
|
4c79b5 |
return $p_array[0];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
');
|
|
|
4c79b5 |
} else {
|
|
|
4c79b5 |
$string_process_bugnote_link_callback[$p_include_anchor][$p_detail_info][$p_fqdn] = create_function('$p_array','
|
|
|
4c79b5 |
# We might as well create the link here even if the bug
|
|
|
4c79b5 |
# doesnt exist. In the case above we dont want to do
|
|
|
4c79b5 |
# the summary lookup on a non-existant bug. But here, we
|
|
|
4c79b5 |
# can create the link and by the time it is clicked on, the
|
|
|
4c79b5 |
# bug may exist.
|
|
|
4c79b5 |
$t_bug_id = bugnote_get_field( (int)$p_array[2], \'bug_id\' );
|
|
|
4c79b5 |
if ( bug_exists( $t_bug_id ) ) {
|
|
|
4c79b5 |
return $p_array[1] . string_get_bugnote_view_url_with_fqdn( $t_bug_id, (int)$p_array[2], null );
|
|
|
4c79b5 |
} else {
|
|
|
4c79b5 |
return $p_array[0];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
');
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$p_string = preg_replace_callback( '/(^|[^\w])' . preg_quote($t_tag, '/') .'(\d+)\b/', $string_process_bugnote_link_callback[$p_include_anchor][$p_detail_info][$p_fqdn], $p_string);
|
|
|
4c79b5 |
return $p_string;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
#===================================
|
|
|
4c79b5 |
# Tag Processing
|
|
|
4c79b5 |
#===================================
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# --------------------
|
|
|
4c79b5 |
# Detect URLs and email addresses in the string and replace them with href anchors
|
|
|
4c79b5 |
function string_insert_hrefs( $p_string ) {
|
|
|
4c79b5 |
if ( !config_get( 'html_make_links' ) ) {
|
|
|
4c79b5 |
return $p_string;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$t_change_quotes = false;
|
|
|
4c79b5 |
if( ini_get_bool( 'magic_quotes_sybase' ) ) {
|
|
|
4c79b5 |
$t_change_quotes = true;
|
|
|
4c79b5 |
ini_set( 'magic_quotes_sybase', false );
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# Find any URL in a string and replace it by a clickable link
|
|
|
4c79b5 |
$p_string = preg_replace( '/(([[:alpha:]][-+.[:alnum:]]*):\/\/(%[[:digit:]A-Fa-f]{2}|[-_.!~*\';\/?%^\\\\:@&={\|}+$#\(\),\[\][:alnum:]])+)/se',
|
|
|
4c79b5 |
"'\\1 [^]'",
|
|
|
4c79b5 |
$p_string);
|
|
|
4c79b5 |
if( $t_change_quotes ) {
|
|
|
4c79b5 |
ini_set( 'magic_quotes_sybase', true );
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$p_string = preg_replace( '/\b' . email_regex_simple() . '\b/i',
|
|
|
4c79b5 |
'\0',
|
|
|
4c79b5 |
$p_string);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $p_string;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# --------------------
|
|
|
4c79b5 |
# Detect href anchors in the string and replace them with URLs and email addresses
|
|
|
4c79b5 |
function string_strip_hrefs( $p_string ) {
|
|
|
4c79b5 |
# First grab mailto: hrefs. We don't care whether the URL is actually
|
|
|
4c79b5 |
# correct - just that it's inside an href attribute.
|
|
|
4c79b5 |
$p_string = preg_replace( '/<a\s[^\>]*href="mailto:([^\"]+)"[^\>]*>[^\<]*<\/a>/si',
|
|
|
4c79b5 |
'\1',
|
|
|
4c79b5 |
$p_string);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# Then grab any other href
|
|
|
4c79b5 |
$p_string = preg_replace( '/<a\s[^\>]*href="([^\"]+)"[^\>]*>[^\<]*<\/a>/si',
|
|
|
4c79b5 |
'\1',
|
|
|
4c79b5 |
$p_string);
|
|
|
4c79b5 |
return $p_string;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# --------------------
|
|
|
4c79b5 |
# This function looks for text with htmlentities
|
|
|
4c79b5 |
# like <b> and converts is into corresponding
|
|
|
4c79b5 |
# html based on the configuration presets
|
|
|
4c79b5 |
function string_restore_valid_html_tags( $p_string, $p_multiline = true ) {
|
|
|
4c79b5 |
$t_html_valid_tags = config_get( $p_multiline ? 'html_valid_tags' : 'html_valid_tags_single_line' );
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ( OFF === $t_html_valid_tags || is_blank( $t_html_valid_tags ) ) {
|
|
|
4c79b5 |
return $p_string;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$tags = explode( ',', $t_html_valid_tags );
|
|
|
4c79b5 |
foreach ($tags as $key => $value) {
|
|
|
4c79b5 |
if ( !is_blank( $value ) ) {
|
|
|
4c79b5 |
$tags[$key] = trim($value);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$tags = implode( '|', $tags);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$p_string = eregi_replace( '<(' . $tags . ')[[:space:]]*>', '<\\1>', $p_string );
|
|
|
4c79b5 |
$p_string = eregi_replace( '<\/(' .$tags . ')[[:space:]]*>', '</\\1>', $p_string );
|
|
|
4c79b5 |
$p_string = eregi_replace( '<(' . $tags . ')[[:space:]]*\/>', '<\\1 />', $p_string );
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $p_string;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
#===================================
|
|
|
4c79b5 |
# Advanced/Simple page selection
|
|
|
4c79b5 |
#===================================
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# --------------------
|
|
|
4c79b5 |
# return the name of a bug page for the user
|
|
|
4c79b5 |
# account for the user preference and site override
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
# $p_action should be something like 'view', 'update', or 'report'
|
|
|
4c79b5 |
# If $p_user_id is null or not specified, use the current user
|
|
|
4c79b5 |
function string_get_bug_page( $p_action, $p_user_id=null ) {
|
|
|
4c79b5 |
if ( null === $p_user_id ) {
|
|
|
4c79b5 |
if ( auth_is_user_authenticated() ) {
|
|
|
4c79b5 |
$p_user_id = auth_get_current_user_id();
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$g_show_action = config_get( 'show_' . $p_action );
|
|
|
4c79b5 |
switch ( $g_show_action ) {
|
|
|
4c79b5 |
case BOTH:
|
|
|
4c79b5 |
if ( ( null !== $p_user_id ) &&
|
|
|
4c79b5 |
( ON == user_pref_get_pref( $p_user_id, 'advanced_' . $p_action ) ) ) {
|
|
|
4c79b5 |
return 'bug_' . $p_action . '_advanced_page.php';
|
|
|
4c79b5 |
} else {
|
|
|
4c79b5 |
return 'bug_' . $p_action . '_page.php';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
case SIMPLE_ONLY:
|
|
|
4c79b5 |
return 'bug_' . $p_action . '_page.php';
|
|
|
4c79b5 |
case ADVANCED_ONLY:
|
|
|
4c79b5 |
return 'bug_' . $p_action . '_advanced_page.php';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# --------------------
|
|
|
4c79b5 |
# return an href anchor that links to a bug VIEW page for the given bug
|
|
|
4c79b5 |
# account for the user preference and site override
|
|
|
4c79b5 |
function string_get_bug_view_link( $p_bug_id, $p_user_id = null, $p_detail_info = true, $p_fqdn = false ) {
|
|
|
4c79b5 |
if ( bug_exists( $p_bug_id ) ) {
|
|
|
4c79b5 |
$t_link = '
|
|
|
4c79b5 |
if ( $p_fqdn ) {
|
|
|
4c79b5 |
$t_link .= config_get( 'path' );
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$t_link .= string_get_bug_view_url( $p_bug_id, $p_user_id ) . '"';
|
|
|
4c79b5 |
if ( $p_detail_info ) {
|
|
|
4c79b5 |
$t_summary = string_attribute( bug_get_field( $p_bug_id, 'summary' ) );
|
|
|
4c79b5 |
$t_status = string_attribute( get_enum_element( 'status', bug_get_field( $p_bug_id, 'status' ) ) );
|
|
|
4c79b5 |
$t_link .= ' title="[' . $t_status . '] ' . $t_summary . '"';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$t_link .= '>' . bug_format_id( $p_bug_id ) . '';
|
|
|
4c79b5 |
} else {
|
|
|
4c79b5 |
$t_link = bug_format_id( $p_bug_id );
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $t_link;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# --------------------
|
|
|
4c79b5 |
# return an href anchor that links to a bug VIEW page for the given bug
|
|
|
4c79b5 |
# account for the user preference and site override
|
|
|
4c79b5 |
function string_get_bugnote_view_link( $p_bug_id, $p_bugnote_id, $p_user_id = null, $p_detail_info = true, $p_fqdn = false ) {
|
|
|
4c79b5 |
if ( bug_exists( $p_bug_id ) && bugnote_exists( $p_bugnote_id ) ) {
|
|
|
4c79b5 |
$t_link = '
|
|
|
4c79b5 |
if ( $p_fqdn ) {
|
|
|
4c79b5 |
$t_link .= config_get( 'path' );
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$t_link .= string_get_bugnote_view_url( $p_bug_id, $p_bugnote_id, $p_user_id ) . '"';
|
|
|
4c79b5 |
if ( $p_detail_info ) {
|
|
|
4c79b5 |
$t_reporter = string_attribute( user_get_name ( bugnote_get_field( $p_bugnote_id, 'reporter_id' ) ) );
|
|
|
4c79b5 |
$t_update_date = string_attribute( date( config_get( 'normal_date_format' ), ( db_unixtimestamp( bugnote_get_field( $p_bugnote_id, 'last_modified' ) ) ) ) );
|
|
|
4c79b5 |
$t_link .= ' title="[' . $t_update_date . '] ' . $t_reporter . '"';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$t_link .= '>' . lang_get( 'bugnote' ) . ': ' . bugnote_format_id( $p_bugnote_id) . '';
|
|
|
4c79b5 |
} else {
|
|
|
4c79b5 |
$t_link = lang_get( 'bugnote' ) . ': ' . bugnote_format_id( $p_bugnote_id);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $t_link;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# --------------------
|
|
|
4c79b5 |
# return the name and GET parameters of a bug VIEW page for the given bug
|
|
|
4c79b5 |
# account for the user preference and site override
|
|
|
4c79b5 |
function string_get_bug_view_url( $p_bug_id, $p_user_id = null ) {
|
|
|
4c79b5 |
return 'view.php?id=' . $p_bug_id;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# --------------------
|
|
|
4c79b5 |
# return the name and GET parameters of a bug VIEW page for the given bug
|
|
|
4c79b5 |
# account for the user preference and site override
|
|
|
4c79b5 |
function string_get_bugnote_view_url( $p_bug_id, $p_bugnote_id, $p_user_id = null ) {
|
|
|
4c79b5 |
return 'view.php?id=' . $p_bug_id . '#c'. $p_bugnote_id;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# --------------------
|
|
|
4c79b5 |
# return the name and GET parameters of a bug VIEW page for the given bug
|
|
|
4c79b5 |
# account for the user preference and site override
|
|
|
4c79b5 |
# The returned url includes the fully qualified domain, hence it is suitable to be included
|
|
|
4c79b5 |
# in emails.
|
|
|
4c79b5 |
function string_get_bugnote_view_url_with_fqdn( $p_bug_id, $p_bugnote_id, $p_user_id = null ) {
|
|
|
4c79b5 |
return config_get( 'path' ) . string_get_bug_view_url( $p_bug_id, $p_user_id ).'#c'.$p_bugnote_id;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# --------------------
|
|
|
4c79b5 |
# return the name and GET parameters of a bug VIEW page for the given bug
|
|
|
4c79b5 |
# account for the user preference and site override
|
|
|
4c79b5 |
# The returned url includes the fully qualified domain, hence it is suitable to be included
|
|
|
4c79b5 |
# in emails.
|
|
|
4c79b5 |
function string_get_bug_view_url_with_fqdn( $p_bug_id, $p_user_id = null ) {
|
|
|
4c79b5 |
return config_get( 'path' ) . string_get_bug_view_url( $p_bug_id, $p_user_id );
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# --------------------
|
|
|
4c79b5 |
# return the name of a bug VIEW page for the user
|
|
|
4c79b5 |
# account for the user preference and site override
|
|
|
4c79b5 |
function string_get_bug_view_page( $p_user_id = null ) {
|
|
|
4c79b5 |
return string_get_bug_page( 'view', $p_user_id );
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# --------------------
|
|
|
4c79b5 |
# return an href anchor that links to a bug UPDATE page for the given bug
|
|
|
4c79b5 |
# account for the user preference and site override
|
|
|
4c79b5 |
function string_get_bug_update_link( $p_bug_id, $p_user_id = null ) {
|
|
|
4c79b5 |
$t_summary = string_attribute( bug_get_field( $p_bug_id, 'summary' ) );
|
|
|
4c79b5 |
return '' . bug_format_id( $p_bug_id ) . '';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# --------------------
|
|
|
4c79b5 |
# return the name and GET parameters of a bug UPDATE page for the given bug
|
|
|
4c79b5 |
# account for the user preference and site override
|
|
|
4c79b5 |
function string_get_bug_update_url( $p_bug_id, $p_user_id = null ) {
|
|
|
4c79b5 |
return string_get_bug_update_page( $p_user_id ) . '?bug_id=' . $p_bug_id;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# --------------------
|
|
|
4c79b5 |
# return the name of a bug UPDATE page for the user
|
|
|
4c79b5 |
# account for the user preference and site override
|
|
|
4c79b5 |
function string_get_bug_update_page( $p_user_id = null ) {
|
|
|
4c79b5 |
return string_get_bug_page( 'update', $p_user_id );
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# --------------------
|
|
|
4c79b5 |
# return an href anchor that links to a bug REPORT page for the given bug
|
|
|
4c79b5 |
# account for the user preference and site override
|
|
|
4c79b5 |
function string_get_bug_report_link( $p_user_id = null ) {
|
|
|
4c79b5 |
return '' . lang_get( 'report_bug_link' ) . '';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# --------------------
|
|
|
4c79b5 |
# return the name and GET parameters of a bug REPORT page for the given bug
|
|
|
4c79b5 |
# account for the user preference and site override
|
|
|
4c79b5 |
function string_get_bug_report_url( $p_user_id = null ) {
|
|
|
4c79b5 |
return string_get_bug_report_page( $p_user_id );
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# --------------------
|
|
|
4c79b5 |
# return the name of a bug REPORT page for the user
|
|
|
4c79b5 |
# account for the user preference and site override
|
|
|
4c79b5 |
function string_get_bug_report_page( $p_user_id = null ) {
|
|
|
4c79b5 |
return string_get_bug_page( 'report', $p_user_id );
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# --------------------
|
|
|
4c79b5 |
# return the complete url link to checkin using the confirm_hash
|
|
|
4c79b5 |
function string_get_confirm_hash_url( $p_user_id, $p_confirm_hash ) {
|
|
|
4c79b5 |
$t_path = config_get( 'path' );
|
|
|
4c79b5 |
return $t_path . "verify.php?id=" . string_url( $p_user_id ) . "&confirm_hash=" . string_url( $p_confirm_hash );
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# --------------------
|
|
|
4c79b5 |
# Return a string with the $p_character pattern repeated N times.
|
|
|
4c79b5 |
# $p_character - pattern to repeat
|
|
|
4c79b5 |
# $p_repeats - number of times to repeat.
|
|
|
4c79b5 |
function string_repeat_char( $p_character, $p_repeats ) {
|
|
|
4c79b5 |
return str_pad( '', $p_repeats, $p_character );
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# --------------------
|
|
|
4c79b5 |
# Format date for display
|
|
|
4c79b5 |
function string_format_complete_date( $p_date ) {
|
|
|
4c79b5 |
return date( config_get( 'complete_date_format' ), $p_date );
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# --------------------
|
|
|
4c79b5 |
# Shorten a string for display on a dropdown to prevent the page rendering too wide
|
|
|
4c79b5 |
# ref issues #4630, #5072, #5131
|
|
|
4c79b5 |
|
|
|
4c79b5 |
function string_shorten( $p_string ) {
|
|
|
4c79b5 |
$t_max = config_get( 'max_dropdown_length' );
|
|
|
4c79b5 |
if ( ( strlen( $p_string ) > $t_max ) && ( $t_max > 0 ) ){
|
|
|
4c79b5 |
$t_pattern = '/([\s|.|,|\-|_|\/|\?]+)/';
|
|
|
4c79b5 |
$t_bits = preg_split( $t_pattern, $p_string, -1, PREG_SPLIT_DELIM_CAPTURE );
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$t_string = '';
|
|
|
4c79b5 |
$t_last = $t_bits[ count( $t_bits ) - 1 ];
|
|
|
4c79b5 |
$t_last_len = strlen( $t_last );
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ( $t_bits as $t_bit ) {
|
|
|
4c79b5 |
if ( ( strlen( $t_string ) + strlen( $t_bit ) + $t_last_len + 3 <= $t_max )
|
|
|
4c79b5 |
|| ( strpos( $t_bit, '.,-/?' ) > 0 ) ) {
|
|
|
4c79b5 |
$t_string .= $t_bit;
|
|
|
4c79b5 |
} else {
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$t_string .= '...' . $t_last;
|
|
|
4c79b5 |
return $t_string;
|
|
|
4c79b5 |
} else {
|
|
|
4c79b5 |
return $p_string;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# --------------------
|
|
|
4c79b5 |
# remap a field name to a string name (for sort filter)
|
|
|
4c79b5 |
|
|
|
4c79b5 |
function string_get_field_name( $p_string ) {
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$t_map = array(
|
|
|
4c79b5 |
'last_updated' => 'last_update',
|
|
|
4c79b5 |
'id' => 'email_bug'
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$t_string = $p_string;
|
|
|
4c79b5 |
if ( isset( $t_map[ $p_string ] ) ) {
|
|
|
4c79b5 |
$t_string = $t_map[ $p_string ];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
return lang_get_defaulted( $t_string );
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# --------------------
|
|
|
4c79b5 |
# Calls htmlentities on the specified string, passing along
|
|
|
4c79b5 |
# the current charset.
|
|
|
4c79b5 |
function string_html_entities( $p_string ) {
|
|
|
4c79b5 |
return htmlentities( $p_string, ENT_COMPAT, lang_get( 'charset' ) );
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# --------------------
|
|
|
4c79b5 |
# Calls htmlspecialchars on the specified string, passing along
|
|
|
4c79b5 |
# the current charset, if the current PHP version supports it.
|
|
|
4c79b5 |
function string_html_specialchars( $p_string ) {
|
|
|
4c79b5 |
# achumakov: @ added to avoid warning output in unsupported codepages
|
|
|
4c79b5 |
# e.g. 8859-2, windows-1257, Korean, which are treated as 8859-1.
|
|
|
4c79b5 |
# This is VERY important for Eastern European, Baltic and Korean languages
|
|
|
4c79b5 |
return preg_replace("/&(#[0-9]+|[a-z]+);/i", "&$;;", @htmlspecialchars( $p_string, ENT_COMPAT, lang_get( 'charset' ) ) );
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# --------------------
|
|
|
4c79b5 |
# Prepares a string to be used as part of header().
|
|
|
4c79b5 |
function string_prepare_header( $p_string ) {
|
|
|
4c79b5 |
$t_string = $p_string;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$t_truncate_pos = strpos($p_string, "\n");
|
|
|
4c79b5 |
if ($t_truncate_pos !== false ) {
|
|
|
4c79b5 |
$t_string = substr($t_string, 0, $t_truncate_pos);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$t_truncate_pos = strpos($p_string, "\r");
|
|
|
4c79b5 |
if ($t_truncate_pos !== false ) {
|
|
|
4c79b5 |
$t_string = substr($t_string, 0, $t_truncate_pos);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $t_string;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# --------------------
|
|
|
4c79b5 |
# Checks the supplied string for scripting characters, if it contains any, then return true, otherwise return false.
|
|
|
4c79b5 |
function string_contains_scripting_chars( $p_string ) {
|
|
|
4c79b5 |
if ( ( strstr( $p_string, '<' ) !== false ) || ( strstr( $p_string, '>' ) !== false ) ) {
|
|
|
4c79b5 |
return true;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
?>
|