diff --git a/core/html_api.php b/core/html_api.php index 1fbf67a160..1a411427f9 100644 --- a/core/html_api.php +++ b/core/html_api.php @@ -1431,12 +1431,9 @@ function html_status_legend( $p_display_position, $p_restrict_by_filter = false $t_status_enum_string = config_get( 'status_enum_string' ); foreach( $t_status_array as $t_status => $t_name ) { $t_val = isset( $t_status_names[$t_status] ) ? $t_status_names[$t_status] : $t_status_array[$t_status]; - $t_status_css = html_get_css_identifier( - MantisEnum::getLabel( $t_status_enum_string, $t_status ), - 'color' - ); - echo '' . $t_val . ''; + echo '' + . $t_val . ''; } echo ''; @@ -1474,10 +1471,11 @@ function html_status_percentage_legend() { $t_percent = ( isset( $t_status_percents[$t_status] ) ? $t_status_percents[$t_status] : 0 ); if( $t_percent > 0 ) { - $t_status_css = html_get_css_identifier( - MantisEnum::getLabel( $t_status_enum_string, $t_status ) - ); - echo '' . $t_percent . '%'; + $t_class = html_get_status_css_class( $t_status ); + echo '' + . $t_percent . '%'; } } @@ -1911,28 +1909,10 @@ function html_buttons_view_bug_page( $p_bug_id ) { * Build CSS including project or even user-specific colors ? */ function html_get_status_css_class( $p_status, $p_user = null, $p_project = null ) { - $t_identifier = MantisEnum::getLabel( - config_get( 'status_enum_string', null, $p_user, $p_project ), - $p_status - ); - return html_get_css_identifier( $t_identifier, 'color' ); -} - -/** - * Get a CSS-friendly identifier for the given string - * Replace all invalid characters by a dash, remove multiple consecutive dashes - * and append the given suffix. - * This is useful e.g. for dynamic css class names used for status colors. - * @param string $p_string Identifier to convert - * @param string $p_string Suffix to append at end of string - * @return string - */ -function html_get_css_identifier( $p_string, $p_suffix = null ) { - $t_string = string_attribute( strtolower ( $p_string ) ); - $t_string = preg_replace( '/[^a-z0-9_-]/', '-', $t_string ); - if( $p_suffix ) { - $t_string .= '-' . $p_suffix; - } - $t_string = preg_replace( '/-+/', '-', trim( $t_string, '-' ) ); - return $t_string; + $t_status_enum = config_get( 'status_enum_string', null, $p_user, $p_project ); + if( MantisEnum::hasValue( $t_status_enum, $p_status ) ) { + return 'status-' . $p_status . '-color'; + } else { + return ''; + } } diff --git a/css/status_config.php b/css/status_config.php index 5c69bd3871..fcfb441aed 100644 --- a/css/status_config.php +++ b/css/status_config.php @@ -75,13 +75,14 @@ $t_color_width = ( $t_color_count > 0 ? ( round( 100/$t_color_count ) ) : 0 ); $t_status_percents = auth_is_user_authenticated() ? get_percentage_by_status() : array(); -foreach( $t_statuses AS $t_id=>$t_label ) { - if( array_key_exists( $t_label, $t_colors ) ) { - echo '.' . html_get_css_identifier( $t_label, 'color' ) - . " { background-color: {$t_colors[$t_label]}; width: $t_color_width%; }\n"; - } - if( array_key_exists( $t_id, $t_status_percents ) ) { - echo '.' . html_get_css_identifier( $t_label, 'percentage' ) - . " { width: {$t_status_percents[$t_id]}%; }\n"; - } +foreach( $t_statuses as $t_id => $t_label ) { + $t_css_class = html_get_status_css_class( $t_id ); + + # Status color class + echo '.' . $t_css_class + . " { background-color: {$t_colors[$t_label]}; width: $t_color_width%; }\n"; + + # Status percentage width class + echo '.' . str_replace( 'color', 'percentage', $t_css_class ) + . " { width: {$t_status_percents[$t_id]}%; }\n"; }