From: <pri...@us...> - 2008-02-21 14:25:36
|
Revision: 5024 http://mantisbt.svn.sourceforge.net/mantisbt/?rev=5024&view=rev Author: prichards Date: 2008-02-21 06:25:22 -0800 (Thu, 21 Feb 2008) Log Message: ----------- Allow string_sanitize_url to return either an absolute or relative link. This should allow us to simplify things elsewhere (I hope) Modified Paths: -------------- trunk/mantisbt/core/print_api.php trunk/mantisbt/core/string_api.php Modified: trunk/mantisbt/core/print_api.php =================================================================== --- trunk/mantisbt/core/print_api.php 2008-02-20 12:38:58 UTC (rev 5023) +++ trunk/mantisbt/core/print_api.php 2008-02-21 14:25:22 UTC (rev 5024) @@ -57,12 +57,19 @@ # validate the url as part of this site before continuing if ( $p_absolute ) { - $t_url = ''; + if ( $p_sanitize ) { + $t_url = string_sanitize_url( $p_url ); + } else { + $t_url = $p_url; + } } else { - $t_url = config_get( 'path' ); + if ( $p_sanitize ) { + $t_url = string_sanitize_url( $p_url, true ); + } else { + $t_url = config_get( 'path' ) . $p_url; + } } - $t_url .= $p_sanitize ? string_sanitize_url( $p_url ) : $p_url; - + # don't send more headers if they have already been sent (guideweb) if ( ! headers_sent() ) { header( 'Content-Type: text/html; charset=' . lang_get( 'charset' ) ); Modified: trunk/mantisbt/core/string_api.php =================================================================== --- trunk/mantisbt/core/string_api.php 2008-02-20 12:38:58 UTC (rev 5023) +++ trunk/mantisbt/core/string_api.php 2008-02-21 14:25:22 UTC (rev 5024) @@ -188,18 +188,40 @@ # -------------------- # validate the url as part of this site before continuing - function string_sanitize_url( $p_url ) { + function string_sanitize_url( $p_url, $return_absolute = false ) { $t_url = strip_tags( urldecode( $p_url ) ); if ( preg_match( '?http(s)*://?', $t_url ) > 0 ) { // no embedded addresses if ( preg_match( '?^' . config_get( 'path' ) . '?', $t_url ) == 0 ) { // url is ok if it begins with our path, if not, replace it - $t_url = 'index.php'; + if ( $return_absolute == true ) { + $t_url = config_get_global( 'path' ) . 'index.php'; + } else { + $t_url = 'index.php'; + } + } else { + if ( $return_absolute == false ) { + str_replace( config_get_global( 'path' ), '', $t_url ); + } } + } else { + // relative hyperlink + if ( $return_absolute == true ) { + if ( strpos( $p_url, config_get_global( 'short_path' ) ) === 0) { + $t_url = str_replace( config_get_global( 'short_path' ), '', config_get_global( 'path' ) ) . $t_url; + } else { + $t_url = config_get_global( 'path' ) . $t_url; + } + } } if ( $t_url == '' ) { - $t_url = 'index.php'; + if ( $return_absolute == true ) { + $t_url = config_get_global( 'path' ) . 'index.php'; + } else { + $t_url = 'index.php'; + } } + // split and encode parameters if ( strpos( $t_url, '?' ) !== FALSE ) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |