From: <pri...@us...> - 2008-04-22 23:24:42
|
Revision: 5195 http://mantisbt.svn.sourceforge.net/mantisbt/?rev=5195&view=rev Author: prichards Date: 2008-04-22 16:24:40 -0700 (Tue, 22 Apr 2008) Log Message: ----------- Fix memleak in string api, also path/short_path can be gather by config_get_global Modified Paths: -------------- trunk/mantisbt/core/string_api.php Modified: trunk/mantisbt/core/string_api.php =================================================================== --- trunk/mantisbt/core/string_api.php 2008-04-22 23:19:15 UTC (rev 5194) +++ trunk/mantisbt/core/string_api.php 2008-04-22 23:24:40 UTC (rev 5195) @@ -284,33 +284,39 @@ # preceeded by a character that is not a letter, a number or an underscore # # if $p_include_anchor = false, $p_fqdn is ignored and assumed to true. + $string_process_bug_link_callback = array(); + function string_process_bug_link( $p_string, $p_include_anchor = true, $p_detail_info = true, $p_fqdn = false ) { + global $string_process_bug_link_callback; + $t_tag = config_get( 'bug_link_tag' ); # bail if the link tag is blank if ( '' == $t_tag || $p_string == '' ) { return $p_string; } - if ($p_include_anchor) { - $callback = create_function('$p_array',' - if (bug_exists( (int)$p_array[2] ) ) { - return $p_array[1] . string_get_bug_view_link( (int)$p_array[2], null, ' . ($p_detail_info ? 'true' : 'false') . ', ' . ($p_fqdn ? 'true' : 'false') . '); - } else { + if ( !isset( $string_process_bug_link_callback[$p_include_anchor][$p_detail_info][$p_fqdn] ) ) { + if ($p_include_anchor) { + $string_process_bug_link_callback[$p_include_anchor][$p_detail_info][$p_fqdn] = create_function('$p_array',' + if (bug_exists( (int)$p_array[2] ) ) { + return $p_array[1] . string_get_bug_view_link( (int)$p_array[2], null, ' . ($p_detail_info ? 'true' : 'false') . ', ' . ($p_fqdn ? 'true' : 'false') . '); + } else { return $p_array[0]; } '); - } else { - $callback = create_function('$p_array',' + } else { + $string_process_bug_link_callback[$p_include_anchor][$p_detail_info][$p_fqdn] = create_function('$p_array',' # We might as well create the link here even if the bug # doesnt exist. In the case above we dont want to do # the summary lookup on a non-existant bug. But here, we # can create the link and by the time it is clicked on, the - # bug may exist. + # bug may exist. return $p_array[1] . string_get_bug_view_url_with_fqdn( (int)$p_array[2], null ); '); + } } - $p_string = preg_replace_callback( '/(^|[^\w&])' . preg_quote($t_tag, '/') . '(\d+)\b/', $callback, $p_string); + $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); return $p_string; } @@ -327,15 +333,20 @@ # preceeded by a character that is not a letter, a number or an underscore # # if $p_include_anchor = false, $p_fqdn is ignored and assumed to true. + $string_process_bugnote_link_callback = array(); + function string_process_bugnote_link( $p_string, $p_include_anchor = true, $p_detail_info = true, $p_fqdn = false ) { + global $string_process_bugnote_link_callback; $t_tag = config_get( 'bugnote_link_tag' ); # bail if the link tag is blank if ( '' == $t_tag || $p_string == '' ) { return $p_string; } - if ($p_include_anchor) { - $callback = create_function('$p_array',' + + if ( !isset ( $string_process_bugnote_link_callback[$p_include_anchor][$p_detail_info][$p_fqdn] ) ) { + if ($p_include_anchor) { + $string_process_bugnote_link_callback[$p_include_anchor][$p_detail_info][$p_fqdn] = create_function('$p_array',' if ( bugnote_exists( (int)$p_array[2] ) ) { $t_bug_id = bugnote_get_field( (int)$p_array[2], \'bug_id\' ); if ( bug_exists( $t_bug_id ) ) { @@ -347,13 +358,13 @@ return $p_array[0]; } '); - } else { - $callback = create_function('$p_array',' + } else { + $string_process_bugnote_link_callback[$p_include_anchor][$p_detail_info][$p_fqdn] = create_function('$p_array',' # We might as well create the link here even if the bug # doesnt exist. In the case above we dont want to do # the summary lookup on a non-existant bug. But here, we # can create the link and by the time it is clicked on, the - # bug may exist. + # bug may exist. $t_bug_id = bugnote_get_field( (int)$p_array[2], \'bug_id\' ); if ( bug_exists( $t_bug_id ) ) { return $p_array[1] . string_get_bugnote_view_url_with_fqdn( $t_bug_id, (int)$p_array[2], null ); @@ -361,8 +372,9 @@ return $p_array[0]; } '); + } } - $p_string = preg_replace_callback( '/(^|[^\w])' . preg_quote($t_tag, '/') .'(\d+)\b/', $callback, $p_string); + $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); return $p_string; } @@ -491,9 +503,9 @@ if ( bug_exists( $p_bug_id ) ) { $t_link = '<a href="'; if ( $p_fqdn ) { - $t_link .= config_get( 'path' ); + $t_link .= config_get_global( 'path' ); } else { - $t_link .= config_get( 'short_path' ); + $t_link .= config_get_global( 'short_path' ); } $t_link .= string_get_bug_view_url( $p_bug_id, $p_user_id ) . '"'; if ( $p_detail_info ) { @@ -516,9 +528,9 @@ if ( bug_exists( $p_bug_id ) && bugnote_exists( $p_bugnote_id ) ) { $t_link = '<a href="'; if ( $p_fqdn ) { - $t_link .= config_get( 'path' ); + $t_link .= config_get_global( 'path' ); } else { - $t_link .= config_get( 'short_path' ); + $t_link .= config_get_global( 'short_path' ); } $t_link .= string_get_bugnote_view_url( $p_bug_id, $p_bugnote_id, $p_user_id ) . '"'; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |