From a5bf55de348530412615f55f28792b952de98765 Mon Sep 17 00:00:00 2001 From: Paul Richards Date: Tue, 16 Jun 2009 21:39:03 +0100 Subject: [PATCH] merge --- core/authentication_api.php | 6 +++--- core/file_api.php | 8 ++++---- core/filter_api.php | 18 +++++++++--------- core/graphviz_api.php | 2 +- core/html_api.php | 2 +- core/print_api.php | 14 +++++++------- core/relationship_api.php | 10 +++++----- core/string_api.php | 29 +++++------------------------ core/utility_api.php | 2 +- manage_proj_edit_page.php | 6 +++--- 10 files changed, 39 insertions(+), 58 deletions(-) diff --git a/core/authentication_api.php b/core/authentication_api.php index 180c659883..8a9aadf53b 100644 --- a/core/authentication_api.php +++ b/core/authentication_api.php @@ -357,7 +357,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 implemention of the CRYPT method - if(( $t_login_method != $t_configured_login_method ) || (( CRYPT == $t_configured_login_method ) && substr( $t_password, 0, 2 ) == substr( $p_test_password, 0, 2 ) ) ) { + 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 ) ) ) { user_set_password( $p_user_id, $p_test_password, true ); } @@ -407,7 +407,7 @@ function auth_process_plain_password( $p_password, $p_salt = null, $p_method = n } # cut this off to PASSLEN cahracters which the largest possible string in the database - return substr( $t_processed_password, 0, PASSLEN ); + return utf8_substr( $t_processed_password, 0, PASSLEN ); } /** @@ -421,7 +421,7 @@ function auth_generate_random_password( $p_email ) { $t_val = mt_rand( 0, mt_getrandmax() ) + mt_rand( 0, mt_getrandmax() ); $t_val = md5( $t_val ); - return substr( $t_val, 0, 12 ); + return utf8_substr( $t_val, 0, 12 ); } /** diff --git a/core/file_api.php b/core/file_api.php index c338a34599..4ad5c5f383 100644 --- a/core/file_api.php +++ b/core/file_api.php @@ -151,7 +151,7 @@ function file_can_delete_bug_attachments( $p_bug_id ) { function file_get_icon_url( $p_display_filename ) { $t_file_type_icons = config_get( 'file_type_icons' ); - $ext = strtolower( file_get_extension( $p_display_filename ) ); + $ext = utf8_strtolower( file_get_extension( $p_display_filename ) ); if( is_blank( $ext ) || !isset( $t_file_type_icons[$ext] ) ) { $ext = '?'; } @@ -170,7 +170,7 @@ function file_get_icon_url( $p_display_filename ) { */ function file_path_combine( $p_path, $p_filename ) { $t_path = $p_path; - if ( substr( $t_path, -1 ) != '/' && substr( $t_path, -1 ) != '\\' ) { + if ( utf8_substr( $t_path, -1 ) != '/' && utf8_substr( $t_path, -1 ) != '\\' ) { $t_path .= DIRECTORY_SEPARATOR; } @@ -310,7 +310,7 @@ function file_get_visible_attachments( $p_bug_id ) { $t_attachment['type'] = 'text'; } - if ( $t_can_download && ( $t_filesize != 0 ) && ( $t_filesize <= config_get( 'preview_attachments_inline_max_size' ) ) && ( in_array( strtolower( file_get_extension( $t_attachment['display_name'] ) ), $t_preview_image_ext, true ) ) ) { + if ( $t_can_download && ( $t_filesize != 0 ) && ( $t_filesize <= config_get( 'preview_attachments_inline_max_size' ) ) && ( in_array( utf8_strtolower( file_get_extension( $t_attachment['display_name'] ) ), $t_preview_image_ext, true ) ) ) { $t_attachment['preview'] = true; $t_attachment['type'] = 'image'; } @@ -840,7 +840,7 @@ function file_ensure_uploaded( $p_file ) { function file_get_extension( $p_filename ) { $ext = ''; $dot_found = false; - $i = strlen( $p_filename ) - 1; + $i = utf8_strlen( $p_filename ) - 1; while( $i >= 0 ) { if( '.' == $p_filename[$i] ) { $dot_found = true; diff --git a/core/filter_api.php b/core/filter_api.php index 20f1b4e64b..df97846657 100644 --- a/core/filter_api.php +++ b/core/filter_api.php @@ -406,8 +406,8 @@ function filter_ensure_valid_filter( $p_filter_arr ) { if( !isset( $p_filter_arr['_version'] ) ) { $p_filter_arr['_version'] = config_get( 'cookie_version' ); } - $t_cookie_vers = (int) substr( $p_filter_arr['_version'], 1 ); - if( substr( config_get( 'cookie_version' ), 1 ) > $t_cookie_vers ) { + $t_cookie_vers = (int) utf8_substr( $p_filter_arr['_version'], 1 ); + if( utf8_substr( config_get( 'cookie_version' ), 1 ) > $t_cookie_vers ) { # if the version is old, update it $p_filter_arr['_version'] = config_get( 'cookie_version' ); @@ -536,7 +536,7 @@ function filter_ensure_valid_filter( $p_filter_arr ) { $t_drop = false; $t_sort = $t_sort_fields[$i]; if( strpos( $t_sort, 'custom_' ) === 0 ) { - if( false === custom_field_get_id_from_name( substr( $t_sort, strlen( 'custom_' ) ) ) ) { + if( false === custom_field_get_id_from_name( utf8_substr( $t_sort, utf8_strlen( 'custom_' ) ) ) ) { $t_drop = true; } } else { @@ -840,7 +840,7 @@ function filter_get_query_sort_data( &$p_filter, $p_show_sticky, $p_query_clause # if sorting by a custom field if( strpos( $c_sort, 'custom_' ) === 0 ) { - $t_custom_field = substr( $c_sort, strlen( 'custom_' ) ); + $t_custom_field = utf8_substr( $c_sort, utf8_strlen( 'custom_' ) ); $t_custom_field_id = custom_field_get_id_from_name( $t_custom_field ); $c_cf_alias = str_replace( ' ', '_', $t_custom_field ); @@ -3052,12 +3052,12 @@ function () { } $t_sort = $t_sort_fields[$i]; if( strpos( $t_sort, 'custom_' ) === 0 ) { - $t_field_name = string_display( lang_get_defaulted( substr( $t_sort, strlen( 'custom_' ) ) ) ); + $t_field_name = string_display( lang_get_defaulted( utf8_substr( $t_sort, utf8_strlen( 'custom_' ) ) ) ); } else { $t_field_name = string_get_field_name( $t_sort ); } - echo $t_field_name . ' ' . lang_get( 'bugnote_order_' . strtolower( $t_dir_fields[$i] ) ); + echo $t_field_name . ' ' . lang_get( 'bugnote_order_' . utf8_strtolower( $t_dir_fields[$i] ) ); echo ''; echo ''; } @@ -3738,7 +3738,7 @@ function print_filter_custom_field( $p_field_id ) { if( is_array( $t_accessible_custom_fields_values[$j] ) ) { $t_max_length = config_get( 'max_dropdown_length' ); foreach( $t_accessible_custom_fields_values[$j] as $t_item ) { - if(( strtolower( $t_item ) !== META_FILTER_ANY ) && ( strtolower( $t_item ) !== META_FILTER_NONE ) ) { + if(( utf8_strtolower( $t_item ) !== META_FILTER_ANY ) && ( utf8_strtolower( $t_item ) !== META_FILTER_NONE ) ) { echo ''; } @@ -1059,10 +1059,10 @@ function print_project_user_list_option_list( $p_project_id = null ) { if(( isset( $row['realname'] ) ) && ( $row['realname'] <> '' ) && $t_show_realname ) { $t_user_name = string_attribute( $row['realname'] ); if( $t_sort_by_last_name ) { - $t_sort_name_bits = explode( ' ', strtolower( $t_user_name ), 2 ); + $t_sort_name_bits = explode( ' ', utf8_strtolower( $t_user_name ), 2 ); $t_sort_name = ( isset( $t_sort_name_bits[1] ) ? $t_sort_name_bits[1] . ', ' : '' ) . $t_sort_name_bits[0]; } else { - $t_sort_name = strtolower( $t_user_name ); + $t_sort_name = utf8_strtolower( $t_user_name ); } } $t_display[] = $t_user_name; @@ -1569,7 +1569,7 @@ function print_sql_error( $p_query ) { function print_file_icon( $p_filename ) { $t_file_type_icons = config_get( 'file_type_icons' ); - $ext = strtolower( file_get_extension( $p_filename ) ); + $ext = utf8_strtolower( file_get_extension( $p_filename ) ); if( !isset( $t_file_type_icons[$ext] ) ) { $ext = '?'; } diff --git a/core/relationship_api.php b/core/relationship_api.php index 375281bcff..5574fadb9b 100644 --- a/core/relationship_api.php +++ b/core/relationship_api.php @@ -590,7 +590,7 @@ function relationship_can_resolve_bug( $p_bug_id ) { * @return string */ function relationship_get_details( $p_bug_id, $p_relationship, $p_html = false, $p_html_preview = false, $p_show_project = false ) { - $t_summary_wrap_at = strlen( config_get( 'email_separator2' ) ) - 28; + $t_summary_wrap_at = utf8_strlen( config_get( 'email_separator2' ) ) - 28; $t_icon_path = config_get( 'icon_path' ); if( $p_bug_id == $p_relationship->src_bug_id ) { @@ -637,8 +637,8 @@ function relationship_get_details( $p_bug_id, $p_relationship, $p_html = false, $t_relationship_info_html .= $t_td . $t_status . ' '; } - $t_relationship_info_text = str_pad( $t_relationship_descr, 20 ); - $t_relationship_info_text .= str_pad( bug_format_id( $t_related_bug_id ), 8 ); + $t_relationship_info_text = utf8_str_pad( $t_relationship_descr, 20 ); + $t_relationship_info_text .= utf8_str_pad( bug_format_id( $t_related_bug_id ), 8 ); # get the handler name of the related bug $t_relationship_info_html .= $t_td; @@ -659,10 +659,10 @@ function relationship_get_details( $p_bug_id, $p_relationship, $p_html = false, $t_relationship_info_html .= sprintf( ' (%s)', $t_icon_path . 'protected.gif', lang_get( 'private' ), lang_get( 'private' ) ); } } else { - if( strlen( $t_bug->summary ) <= $t_summary_wrap_at ) { + if( utf8_strlen( $t_bug->summary ) <= $t_summary_wrap_at ) { $t_relationship_info_text .= string_email_links( $t_bug->summary ); } else { - $t_relationship_info_text .= mb_substr( string_email_links( $t_bug->summary ), 0, $t_summary_wrap_at - 3 ) . '...'; + $t_relationship_info_text .= utf8_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 6bf5eebc63..ed8ee99d1e 100644 --- a/core/string_api.php +++ b/core/string_api.php @@ -35,25 +35,6 @@ $g_cache_html_valid_tags = ''; $g_cache_html_valid_tags_single_line = ''; -if ( function_exists( 'mb_strtolower' ) ) { - /** - * Return a string with all alphabetical characters converted to lowercase, - * using an appropriate multibyte implementation as available to system. - * @param string Input string - * @return string Lower cased string - */ - function string_lower( $p_string ) { - return mb_strtolower( $p_string ); - } -} else { - /** - * @ignore - */ - function string_lower( $p_string ) { - return strtolower( $p_string ); - } -} - /** * Preserve spaces at beginning of lines. * Lines must be separated by \n rather than
@@ -67,7 +48,7 @@ function string_preserve_spaces_at_bol( $p_string ) { $count = 0; $prefix = ''; - $t_char = substr( $lines[$i], $count, 1 ); + $t_char = utf8_substr( $lines[$i], $count, 1 ); $spaces = 0; while(( $t_char == ' ' ) || ( $t_char == "\t" ) ) { if( $t_char == ' ' ) { @@ -79,14 +60,14 @@ function string_preserve_spaces_at_bol( $p_string ) { // 1 tab = 4 spaces, can be configurable. $count++; - $t_char = substr( $lines[$i], $count, 1 ); + $t_char = utf8_substr( $lines[$i], $count, 1 ); } for( $j = 0;$j < $spaces;$j++ ) { $prefix .= ' '; } - $lines[$i] = $prefix . substr( $lines[$i], $count ); + $lines[$i] = $prefix . utf8_substr( $lines[$i], $count ); } return implode( "\n", $lines ); } @@ -810,7 +791,7 @@ function string_shorten( $p_string, $p_max = null ) { $t_max = (int) $p_max; } - if( ( $t_max > 0 ) && ( strlen( $p_string ) > $t_max ) ) { + if( ( $t_max > 0 ) && ( utf8_strlen( $p_string ) > $t_max ) ) { $t_pattern = '/([\s|.|,|\-|_|\/|\?]+)/'; $t_bits = preg_split( $t_pattern, $p_string, -1, PREG_SPLIT_DELIM_CAPTURE ); @@ -819,7 +800,7 @@ function string_shorten( $p_string, $p_max = null ) { $t_last_len = strlen( $t_last ); foreach( $t_bits as $t_bit ) { - if(( strlen( $t_string ) + strlen( $t_bit ) + $t_last_len + 3 <= $t_max ) || ( strpos( $t_bit, '.,-/?' ) > 0 ) ) { + if(( utf8_strlen( $t_string ) + utf8_strlen( $t_bit ) + $t_last_len + 3 <= $t_max ) || ( strpos( $t_bit, '.,-/?' ) > 0 ) ) { $t_string .= $t_bit; } else { break; diff --git a/core/utility_api.php b/core/utility_api.php index 037f7dc90e..cd3f628039 100644 --- a/core/utility_api.php +++ b/core/utility_api.php @@ -64,7 +64,7 @@ function terminate_directory_path( $p_path ) { */ function is_blank( $p_var ) { $p_var = trim( $p_var ); - $str_len = strlen( $p_var ); + $str_len = utf8_strlen( $p_var ); if( 0 == $str_len ) { return true; } diff --git a/manage_proj_edit_page.php b/manage_proj_edit_page.php index 7962a40d28..876c2e6d7d 100644 --- a/manage_proj_edit_page.php +++ b/manage_proj_edit_page.php @@ -743,14 +743,14 @@ $t_sort = array(); foreach ( $t_users as $t_user ) { $t_user_name = string_attribute( $t_user['username'] ); - $t_sort_name = strtolower( $t_user_name ); + $t_sort_name = utf8_strtolower( $t_user_name ); if ( ( isset( $t_user['realname'] ) ) && ( $t_user['realname'] > "" ) && ( ON == config_get( 'show_realname' ) ) ){ $t_user_name = string_attribute( $t_user['realname'] ) . " (" . $t_user_name . ")"; if ( ON == config_get( 'sort_by_last_name') ) { - $t_sort_name_bits = explode( ' ', strtolower( $t_user_name ), 2 ); + $t_sort_name_bits = explode( ' ', utf8_strtolower( $t_user_name ), 2 ); $t_sort_name = $t_sort_name_bits[1] . ', ' . $t_sort_name_bits[1]; } else { - $t_sort_name = strtolower( $t_user_name ); + $t_sort_name = utf8_strtolower( $t_user_name ); } } $t_display[] = $t_user_name;