From 292c7049e22d643e37f65ea94e0e8c39b019f872 Mon Sep 17 00:00:00 2001 From: atrol Date: Sun, 16 Jul 2017 22:18:26 +0200 Subject: [PATCH] Replace utf8_substr by mb_substr Issue #23214 --- bug_actiongroup_ext_page.php | 2 +- bugnote_view_inc.php | 2 +- core/authentication_api.php | 4 ++-- core/cfdefs/cfdef_standard.php | 6 +++--- core/columns_api.php | 2 +- core/custom_field_api.php | 2 +- core/database_api.php | 6 +++--- core/form_api.php | 4 ++-- core/helper_api.php | 2 +- core/install_helper_functions_api.php | 2 +- core/php_api.php | 14 -------------- core/plugin_api.php | 6 +++--- core/relationship_api.php | 2 +- core/string_api.php | 8 ++++---- core/tag_api.php | 2 +- csv_export.php | 2 +- issues_rss.php | 2 +- news_rss.php | 2 +- .../pages/issues_trend_bystatus_table.php | 2 +- print_all_bug_page_word.php | 2 +- return_dynamic_filters.php | 6 +++--- search.php | 2 +- 22 files changed, 34 insertions(+), 48 deletions(-) diff --git a/bug_actiongroup_ext_page.php b/bug_actiongroup_ext_page.php index a7b7b3e1f9..39b47e0339 100644 --- a/bug_actiongroup_ext_page.php +++ b/bug_actiongroup_ext_page.php @@ -47,7 +47,7 @@ require_api( 'string_api.php' ); require_api( 'utility_api.php' ); -$t_external_action = utf8_strtolower( utf8_substr( $f_action, mb_strlen( $t_external_action_prefix ) ) ); +$t_external_action = utf8_strtolower( mb_substr( $f_action, mb_strlen( $t_external_action_prefix ) ) ); $t_form_fields_page = 'bug_actiongroup_' . $t_external_action . '_inc.php'; $t_form_name = 'bug_actiongroup_' . $t_external_action; diff --git a/bugnote_view_inc.php b/bugnote_view_inc.php index 4df37b62f1..e67f4224bf 100644 --- a/bugnote_view_inc.php +++ b/bugnote_view_inc.php @@ -280,7 +280,7 @@ echo lang_get( 'reminder_sent_none' ); } else { # If recipients list's last char is not a delimiter, it was truncated - $t_truncated = ( '|' != utf8_substr( $t_activity['note']->note_attr, mb_strlen( $t_activity['note']->note_attr ) - 1 ) ); + $t_truncated = ( '|' != mb_substr( $t_activity['note']->note_attr, mb_strlen( $t_activity['note']->note_attr ) - 1 ) ); # Build recipients list for display $t_to = array(); diff --git a/core/authentication_api.php b/core/authentication_api.php index e46d972d25..81741439e0 100644 --- a/core/authentication_api.php +++ b/core/authentication_api.php @@ -739,7 +739,7 @@ function auth_does_password_match( $p_user_id, $p_test_password ) { # Check for migration to another login method and test whether the password was encrypted # with our previously insecure implementation of the CRYPT method - if( ( $t_login_method != $t_configured_login_method ) || (( CRYPT == $t_configured_login_method ) && utf8_substr( $t_password, 0, 2 ) == utf8_substr( $p_test_password, 0, 2 ) ) ) { + if( ( $t_login_method != $t_configured_login_method ) || (( CRYPT == $t_configured_login_method ) && mb_substr( $t_password, 0, 2 ) == mb_substr( $p_test_password, 0, 2 ) ) ) { user_set_password( $p_user_id, $p_test_password, true ); } @@ -789,7 +789,7 @@ function auth_process_plain_password( $p_password, $p_salt = null, $p_method = n } # cut this off to DB_FIELD_SIZE_PASSWORD characters which the largest possible string in the database - return utf8_substr( $t_processed_password, 0, DB_FIELD_SIZE_PASSWORD ); + return mb_substr( $t_processed_password, 0, DB_FIELD_SIZE_PASSWORD ); } /** diff --git a/core/cfdefs/cfdef_standard.php b/core/cfdefs/cfdef_standard.php index 375f6d6878..2812d5d97a 100644 --- a/core/cfdefs/cfdef_standard.php +++ b/core/cfdefs/cfdef_standard.php @@ -257,7 +257,7 @@ function cfdef_prepare_string( $p_value ) { */ function cfdef_prepare_list_value_for_email( $p_value ) { # strip start and end markers before converting markers to commas - return str_replace( '|', ', ', utf8_substr( str_replace( '||', '|', '|' . $p_value . '|' ), 1, -1 ) ); + return str_replace( '|', ', ', mb_substr( str_replace( '||', '|', '|' . $p_value . '|' ), 1, -1 ) ); } /** @@ -307,7 +307,7 @@ function cfdef_prepare_date_default( $p_value ) { # We are expanding {tomorrow}, {yesterday}, {+3 days}, {-7 days}, {next week} # See strtotime() for more details about supported formats. if( $t_value_length >= 3 && $t_value[0] == '{' && $t_value[$t_value_length - 1] == '}' ) { - $t_value = utf8_substr( $t_value, 1, $t_value_length - 2 ); + $t_value = mb_substr( $t_value, 1, $t_value_length - 2 ); $t_value = @strtotime( $t_value ); # Different versions of PHP return different values in case of error. @@ -326,7 +326,7 @@ function cfdef_prepare_date_default( $p_value ) { */ function cfdef_prepare_list_value( $p_value ) { # strip start and end markers before converting markers to commas - return string_display_line( str_replace( '|', ', ', utf8_substr( str_replace( '||', '|', '|' . $p_value . '|' ), 1, -1 ) ) ); + return string_display_line( str_replace( '|', ', ', mb_substr( str_replace( '||', '|', '|' . $p_value . '|' ), 1, -1 ) ) ); } /** diff --git a/core/columns_api.php b/core/columns_api.php index 5a0951f6a7..7a83956060 100644 --- a/core/columns_api.php +++ b/core/columns_api.php @@ -343,7 +343,7 @@ function column_is_sortable( $p_column ) { */ function column_get_custom_field_name( $p_column ) { if( strncmp( $p_column, 'custom_', 7 ) === 0 ) { - return utf8_substr( $p_column, 7 ); + return mb_substr( $p_column, 7 ); } return null; diff --git a/core/custom_field_api.php b/core/custom_field_api.php index 11e4796407..9a3523d82d 100644 --- a/core/custom_field_api.php +++ b/core/custom_field_api.php @@ -1158,7 +1158,7 @@ function custom_field_validate( $p_field_id, $p_value ) { */ function custom_field_prepare_possible_values( $p_possible_values ) { if( !is_blank( $p_possible_values ) && ( $p_possible_values[0] == '=' ) ) { - return helper_call_custom_function( 'enum_' . utf8_substr( $p_possible_values, 1 ), array() ); + return helper_call_custom_function( 'enum_' . mb_substr( $p_possible_values, 1 ), array() ); } return $p_possible_values; diff --git a/core/database_api.php b/core/database_api.php index c7fddfcc72..98aff6404d 100644 --- a/core/database_api.php +++ b/core/database_api.php @@ -715,7 +715,7 @@ function db_prepare_string( $p_string ) { return addslashes( $p_string ); case 'mysqli': $t_escaped = $g_db->qstr( $p_string, false ); - return utf8_substr( $t_escaped, 1, mb_strlen( $t_escaped ) - 2 ); + return mb_substr( $t_escaped, 1, mb_strlen( $t_escaped ) - 2 ); case 'pgsql': return pg_escape_string( $p_string ); case 'oci8': @@ -1320,9 +1320,9 @@ function db_format_query_log_msg( $p_query, array $p_arr_parms ) { # Skip this token, so replacing it with itself. $t_replace = $t_match_param[0]; } - $p_query = utf8_substr( $p_query, 0, $t_utf8_offset ) + $p_query = mb_substr( $p_query, 0, $t_utf8_offset ) . $t_replace - . utf8_substr( $p_query, $t_utf8_offset + mb_strlen( $t_match_param[0] ) ); + . mb_substr( $p_query, $t_utf8_offset + mb_strlen( $t_match_param[0] ) ); $t_lastoffset = $t_match_param[1] + strlen( $t_replace ) + 1; } else { $t_lastoffset = $t_match_param[1] + 1; diff --git a/core/form_api.php b/core/form_api.php index 29ea3aec9f..b0492fe194 100644 --- a/core/form_api.php +++ b/core/form_api.php @@ -169,7 +169,7 @@ function form_security_validate( $p_form_name ) { } # Get the date claimed by the token - $t_date = utf8_substr( $t_input, 0, 8 ); + $t_date = mb_substr( $t_input, 0, 8 ); # Check if the token exists if( isset( $t_tokens[$p_form_name][$t_date][$t_input] ) ) { @@ -204,7 +204,7 @@ function form_security_purge( $p_form_name ) { $t_input = gpc_get_string( $t_form_token, '' ); # Get the date claimed by the token - $t_date = utf8_substr( $t_input, 0, 8 ); + $t_date = mb_substr( $t_input, 0, 8 ); # Generate a date string of three days ago $t_purge_date = date( 'Ymd', time() - ( 3 * 24 * 60 * 60 ) ); diff --git a/core/helper_api.php b/core/helper_api.php index f96de396c2..bc3c2e0517 100644 --- a/core/helper_api.php +++ b/core/helper_api.php @@ -710,7 +710,7 @@ function shutdown_functions_register() { function helper_filter_by_prefix( array $p_set, $p_prefix ) { $t_matches = array(); foreach ( $p_set as $p_item ) { - if( utf8_strtolower( utf8_substr( $p_item, 0, mb_strlen( $p_prefix ) ) ) === utf8_strtolower( $p_prefix ) ) { + if( utf8_strtolower( mb_substr( $p_item, 0, mb_strlen( $p_prefix ) ) ) === utf8_strtolower( $p_prefix ) ) { $t_matches[] = $p_item; } } diff --git a/core/install_helper_functions_api.php b/core/install_helper_functions_api.php index e4d988d521..e40c3edfaa 100644 --- a/core/install_helper_functions_api.php +++ b/core/install_helper_functions_api.php @@ -550,7 +550,7 @@ function install_update_history_long_custom_fields() { $t_result = db_query( $t_query ); while( $t_field = db_fetch_array( $t_result ) ) { if( mb_strlen( $t_field['name'] ) > 32 ) { - $t_custom_fields[utf8_substr( $t_field['name'], 0, 32 )] = $t_field['name']; + $t_custom_fields[mb_substr( $t_field['name'], 0, 32 )] = $t_field['name']; } } if( !isset( $t_custom_fields ) ) { diff --git a/core/php_api.php b/core/php_api.php index eaa5b724c8..031622d707 100644 --- a/core/php_api.php +++ b/core/php_api.php @@ -47,17 +47,3 @@ function php_mode() { return $s_mode; } - -# If mb_* not defined, define it to map to standard methods. -if( !function_exists( 'mb_substr' ) ) { - /** - * Map mb_substr to utf8_substr if mb extension is not found - * @param string $p_text Text string. - * @param integer $p_index Start position. - * @param integer $p_size Size. - * @return string - */ - function mb_substr( $p_text, $p_index, $p_size ) { - return utf8_substr( $p_text, $p_index, $p_size ); - } -} diff --git a/core/plugin_api.php b/core/plugin_api.php index 4c19f64ba9..0e6b3815b0 100644 --- a/core/plugin_api.php +++ b/core/plugin_api.php @@ -511,7 +511,7 @@ function plugin_dependency( $p_base_name, $p_required, $p_initialized = false ) # their code, adapt it if necessary, and release a new version of the # plugin with updated dependencies. if( $p_base_name == 'MantisCore' && strpos( $p_required, '<' ) === false ) { - $t_version_core = utf8_substr( $t_plugin_version, 0, strpos( $t_plugin_version, '.' ) ); + $t_version_core = mb_substr( $t_plugin_version, 0, strpos( $t_plugin_version, '.' ) ); $t_is_current_core_supported = false; foreach( $t_required_array as $t_version_required ) { $t_is_current_core_supported = $t_is_current_core_supported @@ -530,12 +530,12 @@ function plugin_dependency( $p_base_name, $p_required, $p_initialized = false ) # check for a less-than-or-equal version requirement $t_ltpos = strpos( $t_required, '<=' ); if( $t_ltpos !== false ) { - $t_required = trim( utf8_substr( $t_required, $t_ltpos + 2 ) ); + $t_required = trim( mb_substr( $t_required, $t_ltpos + 2 ) ); $t_maximum = true; } else { $t_ltpos = strpos( $t_required, '<' ); if( $t_ltpos !== false ) { - $t_required = trim( utf8_substr( $t_required, $t_ltpos + 1 ) ); + $t_required = trim( mb_substr( $t_required, $t_ltpos + 1 ) ); $t_maximum = true; } } diff --git a/core/relationship_api.php b/core/relationship_api.php index b79dd22f70..99403ac5d5 100644 --- a/core/relationship_api.php +++ b/core/relationship_api.php @@ -804,7 +804,7 @@ function relationship_get_details( $p_bug_id, BugRelationshipData $p_relationshi if( mb_strlen( $t_bug->summary ) <= $t_summary_wrap_at ) { $t_relationship_info_text .= string_email_links( $t_bug->summary ); } else { - $t_relationship_info_text .= utf8_substr( string_email_links( $t_bug->summary ), 0, $t_summary_wrap_at - 3 ) . '...'; + $t_relationship_info_text .= mb_substr( string_email_links( $t_bug->summary ), 0, $t_summary_wrap_at - 3 ) . '...'; } } diff --git a/core/string_api.php b/core/string_api.php index 157f4b8921..f8b4c4977e 100644 --- a/core/string_api.php +++ b/core/string_api.php @@ -66,7 +66,7 @@ function string_preserve_spaces_at_bol( $p_string ) { $t_count = 0; $t_prefix = ''; - $t_char = utf8_substr( $t_lines[$i], $t_count, 1 ); + $t_char = mb_substr( $t_lines[$i], $t_count, 1 ); $t_spaces = 0; while( ( $t_char == ' ' ) || ( $t_char == "\t" ) ) { if( $t_char == ' ' ) { @@ -78,14 +78,14 @@ function string_preserve_spaces_at_bol( $p_string ) { # 1 tab = 4 spaces, can be configurable. $t_count++; - $t_char = utf8_substr( $t_lines[$i], $t_count, 1 ); + $t_char = mb_substr( $t_lines[$i], $t_count, 1 ); } for( $j = 0;$j < $t_spaces;$j++ ) { $t_prefix .= ' '; } - $t_lines[$i] = $t_prefix . utf8_substr( $t_lines[$i], $t_count ); + $t_lines[$i] = $t_prefix . mb_substr( $t_lines[$i], $t_count ); } return implode( "\n", $t_lines ); } @@ -838,7 +838,7 @@ function string_shorten( $p_string, $p_max = null ) { $t_last_len = strlen( $t_last ); if( count( $t_bits ) == 1 ) { - $t_string .= utf8_substr( $t_last, 0, $t_max - 3 ); + $t_string .= mb_substr( $t_last, 0, $t_max - 3 ); $t_string .= '...'; } else { foreach( $t_bits as $t_bit ) { diff --git a/core/tag_api.php b/core/tag_api.php index 6a0f570a4b..67e105e681 100644 --- a/core/tag_api.php +++ b/core/tag_api.php @@ -393,7 +393,7 @@ function tag_parse_filters( $p_string ) { if( !is_blank( $t_name ) && tag_name_is_valid( $t_name, $t_matches, $t_prefix ) ) { $t_tag_row = tag_get_by_name( $t_matches[1] ); if( $t_tag_row !== false ) { - $t_filter = utf8_substr( $t_name, 0, 1 ); + $t_filter = mb_substr( $t_name, 0, 1 ); if( '+' == $t_filter ) { $t_tag_row['filter'] = 1; diff --git a/csv_export.php b/csv_export.php index 6501db626e..6e99309707 100644 --- a/csv_export.php +++ b/csv_export.php @@ -91,7 +91,7 @@ # Fixed for a problem in Excel where it prompts error message "SYLK: File Format Is Not Valid" # See Microsoft Knowledge Base Article - 323626 # http://support.microsoft.com/default.aspx?scid=kb;en-us;323626&Product=xlw -$t_first_three_chars = utf8_substr( $t_header, 0, 3 ); +$t_first_three_chars = mb_substr( $t_header, 0, 3 ); if( strcmp( $t_first_three_chars, 'ID' . $t_sep ) == 0 ) { $t_header = str_replace( 'ID' . $t_sep, 'Id' . $t_sep, $t_header ); } diff --git a/issues_rss.php b/issues_rss.php index 5c18353cac..e6e289d6c0 100644 --- a/issues_rss.php +++ b/issues_rss.php @@ -156,7 +156,7 @@ # add missing : in the O part of the date. PHP 5 supports a 'c' format which will output the format # exactly as we want it. # 2002-10-02T10:00:00-0500 -> 2002-10-02T10:00:00-05:00 -$t_base = utf8_substr( $t_base, 0, 22 ) . ':' . utf8_substr( $t_base, -2 ); +$t_base = mb_substr( $t_base, 0, 22 ) . ':' . mb_substr( $t_base, -2 ); $t_rssfile->addSYdata( $t_period, $t_frequency, $t_base ); diff --git a/news_rss.php b/news_rss.php index 6ee9f3c595..527b61be18 100644 --- a/news_rss.php +++ b/news_rss.php @@ -129,7 +129,7 @@ # add missing : in the O part of the date. @todo PHP 5 supports a 'c' format which will output the format # exactly as we want it. # 2002-10-02T10:00:00-0500 -> 2002-10-02T10:00:00-05:00 -$t_base = utf8_substr( $t_base, 0, 22 ) . ':' . utf8_substr( $t_base, -2 ); +$t_base = mb_substr( $t_base, 0, 22 ) . ':' . mb_substr( $t_base, -2 ); $t_rssfile->addSYdata( $t_period, $t_frequency, $t_base ); diff --git a/plugins/MantisGraph/pages/issues_trend_bystatus_table.php b/plugins/MantisGraph/pages/issues_trend_bystatus_table.php index 40b1c956c9..450753b8ee 100644 --- a/plugins/MantisGraph/pages/issues_trend_bystatus_table.php +++ b/plugins/MantisGraph/pages/issues_trend_bystatus_table.php @@ -148,7 +148,7 @@ # @todo - these should probably be separate strings, but in the summary page context, # the string is used as the title for all columns $t_label_string = lang_get( 'orct' ); # use the (open/resolved/closed/total) label -$t_label_strings = explode( '/', utf8_substr( $t_label_string, 1, strlen( $t_label_string ) - 2 ) ); +$t_label_strings = explode( '/', mb_substr( $t_label_string, 1, strlen( $t_label_string ) - 2 ) ); # add headers for table $t_date_format = config_get( 'short_date_format' ); diff --git a/print_all_bug_page_word.php b/print_all_bug_page_word.php index 4c771e2946..6582e44bc1 100644 --- a/print_all_bug_page_word.php +++ b/print_all_bug_page_word.php @@ -548,7 +548,7 @@ switch ( $t_bugnote->note_type ) { case REMINDER: echo lang_get( 'reminder_sent_to' ) . ': '; - $t_note_attr = utf8_substr( $t_bugnote->note_attr, 1, mb_strlen( $t_bugnote->note_attr ) - 2 ); + $t_note_attr = mb_substr( $t_bugnote->note_attr, 1, mb_strlen( $t_bugnote->note_attr ) - 2 ); $t_to = array(); foreach ( explode( '|', $t_note_attr ) as $t_recipient ) { $t_to[] = prepare_user_name( $t_recipient ); diff --git a/return_dynamic_filters.php b/return_dynamic_filters.php index c6775780a2..f63591bc60 100644 --- a/return_dynamic_filters.php +++ b/return_dynamic_filters.php @@ -90,16 +90,16 @@ function return_dynamic_filters_prepend_headers() { } $f_filter_target = gpc_get_string( 'filter_target' ); -$filter_target = utf8_substr( $f_filter_target, 0, -7 ); # -7 for '_filter' +$filter_target = mb_substr( $f_filter_target, 0, -7 ); # -7 for '_filter' $t_found = false; $t_content = @call_user_func_array( 'filter_form_get_input', array( $t_filter, $filter_target, true ) ); if( false !== $t_content ) { return_dynamic_filters_prepend_headers(); $t_found = true; echo $t_content; -} else if( 'custom_field' == utf8_substr( $f_filter_target, 0, 12 ) ) { +} else if( 'custom_field' == mb_substr( $f_filter_target, 0, 12 ) ) { # custom function - $t_custom_id = utf8_substr( $f_filter_target, 13, -7 ); + $t_custom_id = mb_substr( $f_filter_target, 13, -7 ); $t_cfdef = @custom_field_get_definition( $t_custom_id ); # Check existence of custom field id, and if the user have access to read and filter by if( $t_cfdef && access_has_any_project_level( $t_cfdef['access_level_r'] ) && $t_cfdef['filter_by'] ) { diff --git a/search.php b/search.php index 9796ec851b..3c6fbef5e4 100644 --- a/search.php +++ b/search.php @@ -135,7 +135,7 @@ $t_custom_fields = array(); foreach( $_GET as $t_var_name => $t_var_value ) { if( strpos( $t_var_name, 'custom_field_' ) === 0 ) { - $t_custom_field_id = utf8_substr( $t_var_name, 13 ); + $t_custom_field_id = mb_substr( $t_var_name, 13 ); $t_custom_fields[$t_custom_field_id] = $t_var_value; } }