diff --git a/core/cfdefs/cfdef_standard.php b/core/cfdefs/cfdef_standard.php index b47905a06c..4b4274c80a 100644 --- a/core/cfdefs/cfdef_standard.php +++ b/core/cfdefs/cfdef_standard.php @@ -31,7 +31,8 @@ '#function_value_to_database' => 'db_mysql_fix_utf8', '#function_database_to_value' => null, '#function_print_input' => 'cfdef_input_textbox', - '#function_string_value' => null, + '#function_print_value' => null, + '#function_string_value' => 'cfdef_prepare_string', '#function_string_value_for_email' => null, ); @@ -46,7 +47,8 @@ '#function_value_to_database' => 'db_mysql_fix_utf8', '#function_database_to_value' => null, '#function_print_input' => 'cfdef_input_textarea', - '#function_string_value' => null, + '#function_print_value' => 'cfdef_print_textarea', + '#function_string_value' => 'cfdef_prepare_string', '#function_string_value_for_email' => null, ); @@ -60,7 +62,8 @@ '#function_value_to_database' => null, '#function_database_to_value' => null, '#function_print_input' => 'cfdef_input_textbox', - '#function_string_value' => null, + '#function_print_value' => 'cfdef_print_numeric', + '#function_string_value' => 'cfdef_prepare_numeric', '#function_string_value_for_email' => null, ); @@ -74,7 +77,8 @@ '#function_value_to_database' => null, '#function_database_to_value' => null, '#function_print_input' => 'cfdef_input_textbox', - '#function_string_value' => null, + '#function_print_value' => 'cfdef_print_float', + '#function_string_value' => 'cfdef_prepare_float', '#function_string_value_for_email' => null, ); @@ -88,6 +92,7 @@ '#function_value_to_database' => null, '#function_database_to_value' => null, '#function_print_input' => 'cfdef_input_list', + '#function_print_value' => null, '#function_string_value' => 'cfdef_prepare_list_value', '#function_string_value_for_email' => 'cfdef_prepare_list_value_for_email', ); @@ -102,6 +107,7 @@ '#function_value_to_database' => null, '#function_database_to_value' => null, '#function_print_input' => 'cfdef_input_textbox', + '#function_print_value' => null, '#function_string_value' => 'cfdef_prepare_email_value', '#function_string_value_for_email' => 'cfdef_prepare_email_value_for_email', ); @@ -116,6 +122,7 @@ '#function_value_to_database' => 'cfdef_prepare_list_value_to_database', '#function_database_to_value' => 'cfdef_prepare_list_database_to_value', '#function_print_input' => 'cfdef_input_checkbox', + '#function_print_value' => null, '#function_string_value' => 'cfdef_prepare_list_value', '#function_string_value_for_email' => 'cfdef_prepare_list_value_for_email', ); @@ -130,6 +137,7 @@ '#function_value_to_database' => null, '#function_database_to_value' => null, '#function_print_input' => 'cfdef_input_radio', + '#function_print_value' => null, '#function_string_value' => 'cfdef_prepare_list_value', '#function_string_value_for_email' => 'cfdef_prepare_list_value_for_email', ); @@ -144,6 +152,7 @@ '#function_value_to_database' => null, '#function_database_to_value' => null, '#function_print_input' => 'cfdef_input_list', + '#function_print_value' => null, '#function_string_value' => 'cfdef_prepare_list_value', '#function_string_value_for_email' => 'cfdef_prepare_list_value_for_email', ); @@ -158,6 +167,7 @@ '#function_value_to_database' => 'cfdef_prepare_list_value_to_database', '#function_database_to_value' => 'cfdef_prepare_list_database_to_value', '#function_print_input' => 'cfdef_input_list', + '#function_print_value' => null, '#function_string_value' => 'cfdef_prepare_list_value', '#function_string_value_for_email' => 'cfdef_prepare_list_value_for_email', ); @@ -173,6 +183,7 @@ '#function_database_to_value' => null, '#function_default_to_value' => 'cfdef_prepare_date_default', '#function_print_input' => 'cfdef_input_date', + '#function_print_value' => null, '#function_string_value' => 'cfdef_prepare_date_value', '#function_string_value_for_email' => 'cfdef_prepare_date_value_for_email', ); @@ -186,6 +197,59 @@ function cfdef_prepare_list_database_to_value( $p_value ) { return rtrim( ltrim( $p_value, '|' ), '|' ); } +/** + * Print value of text area custom field with sanitization and link processing. + * @param string $p_value The custom field value. + */ +function cfdef_print_textarea( $p_value ) { + echo string_display_links( $p_value ); +} + +/** + * Print value of numeric custom field with sanitization and link processing. + * @param string $p_value The custom field value. + */ +function cfdef_print_numeric( $p_value ) { + echo (int)$p_value; +} + +/** + * Print value of float custom field with sanitization and link processing. + * @param string $p_value The custom field value. + */ +function cfdef_print_float( $p_value ) { + echo (float)$p_value; +} + +/** + * Prepare value for custom fields of type numeric. + * @param string $p_value The string value. + * @return int The numeric value. + */ +function cfdef_prepare_numeric( $p_value ) { + $t_value = (int)$p_value; + return $t_value; +} + +/** + * Prepare value for custom fields of type float. + * @param string $p_value The string value. + * @return float The float value. + */ +function cfdef_prepare_float( $p_value ) { + $t_value = (float)$p_value; + return $t_value; +} + +/** + * Prepare value for custom fields of type string. + * @param string $p_value The string value. + * @return string The string value. + */ +function cfdef_prepare_string( $p_value ) { + return $p_value; +} + /** * Prepare List Value for email * @param string $p_value Value. diff --git a/core/classes/MantisColumn.class.php b/core/classes/MantisColumn.class.php index 6f4467e14f..e079ed10d1 100644 --- a/core/classes/MantisColumn.class.php +++ b/core/classes/MantisColumn.class.php @@ -79,5 +79,22 @@ public function clear_cache() {} * @return void */ abstract public function display( BugData $p_bug, $p_columns_target ); + + /** + * Function to return column value for a given bug row. This should be overridden + * to provide value without processing for html display or escaping for a specific target + * output. Default implementation is to capture display output for backward compatibility + * with target COLUMNS_TARGET_CSV_PAGE. The output will be escaped by calling code to the + * appropriate format. + * + * @param BugData $p_bug A BugData object. + * @param integer $p_columns_target Column display target. + * @return string The column value. + */ + public function value( BugData $p_bug, $p_columns_target ) { + ob_start(); + $this->display( $p_bug, COLUMNS_TARGET_CSV_PAGE ); + return ob_get_clean(); + } } diff --git a/core/csv_api.php b/core/csv_api.php index d2b6cae43a..aca8d2288d 100644 --- a/core/csv_api.php +++ b/core/csv_api.php @@ -133,6 +133,48 @@ function csv_get_columns() { return $t_columns; } +/** + * Gets the formatted value for the specified issue id, project and custom field. + * @param integer $p_issue_id The issue id. + * @param integer $p_project_id The project id. + * @param string $p_custom_field The custom field name (without 'custom_' prefix). + * @return string The custom field value. + */ +function csv_format_custom_field( $p_issue_id, $p_project_id, $p_custom_field ) { + $t_field_id = custom_field_get_id_from_name( $p_custom_field ); + + if( $t_field_id === false ) { + $t_value = '@' . $p_custom_field . '@'; + } else if( custom_field_is_linked( $t_field_id, $p_project_id ) ) { + $t_def = custom_field_get_definition( $t_field_id ); + $t_value = string_custom_field_value( $t_def, $t_field_id, $p_issue_id ); + } else { + # field is not linked to project + $t_value = ''; + } + + return csv_escape_string( $t_value ); +} + +/** + * Gets the formatted value for the specified plugin column value. + * @param string $p_column The plugin column name. + * @param BugData $p_bug A bug object to print the column for - needed for the display function of the plugin column. + * @return string The plugin column value. + */ +function csv_format_plugin_column_value( $p_column, BugData $p_bug ) { + $t_plugin_columns = columns_get_plugin_columns(); + + if( !isset( $t_plugin_columns[$p_column] ) ) { + $t_value = ''; + } else { + $t_column_object = $t_plugin_columns[$p_column]; + $t_value = $t_column_object->value( $p_bug ); + } + + return csv_escape_string( $t_value ); +} + /** * returns the formatted bug id * @param BugData $p_bug A BugData object. diff --git a/core/custom_field_api.php b/core/custom_field_api.php index b53fa69f2e..aac9cbd09c 100644 --- a/core/custom_field_api.php +++ b/core/custom_field_api.php @@ -1430,11 +1430,13 @@ function string_custom_field_value( array $p_def, $p_field_id, $p_bug_id ) { if( $t_custom_field_value === null ) { return ''; } + global $g_custom_field_type_definition; if( isset( $g_custom_field_type_definition[$p_def['type']]['#function_string_value'] ) ) { return call_user_func( $g_custom_field_type_definition[$p_def['type']]['#function_string_value'], $t_custom_field_value ); } - return string_display_links( $t_custom_field_value ); + + return $t_custom_field_value; } /** @@ -1447,7 +1449,17 @@ function string_custom_field_value( array $p_def, $p_field_id, $p_bug_id ) { * @access public */ function print_custom_field_value( array $p_def, $p_field_id, $p_bug_id ) { - echo string_custom_field_value( $p_def, $p_field_id, $p_bug_id ); + $t_custom_field_value = custom_field_get_value( $p_field_id, $p_bug_id ); + if( $t_custom_field_value === null ) { + return; + } + + global $g_custom_field_type_definition; + if( isset( $g_custom_field_type_definition[$p_def['type']]['#function_print_value'] ) ) { + return call_user_func( $g_custom_field_type_definition[$p_def['type']]['#function_print_value'], $t_custom_field_value ); + } + + echo string_display_line_links( $t_custom_field_value ); } /** diff --git a/core/excel_api.php b/core/excel_api.php index 108f131041..a05d9e6cd4 100644 --- a/core/excel_api.php +++ b/core/excel_api.php @@ -512,12 +512,13 @@ function excel_format_custom_field( $p_issue_id, $p_project_id, $p_custom_field if( custom_field_is_linked( $t_field_id, $p_project_id ) ) { $t_def = custom_field_get_definition( $t_field_id ); + $t_value = string_custom_field_value( $t_def, $t_field_id, $p_issue_id ); - if ( $t_def['type'] == CUSTOM_FIELD_TYPE_NUMERIC ) { - return excel_prepare_number( string_custom_field_value( $t_def, $t_field_id, $p_issue_id ) ); + if ( $t_def['type'] == CUSTOM_FIELD_TYPE_NUMERIC && is_numeric( $t_value ) ) { + return excel_prepare_number( $t_value ); } - return excel_prepare_string( string_custom_field_value( $t_def, $t_field_id, $p_issue_id ) ); + return excel_prepare_string( $t_value ); } # field is not linked to project @@ -534,14 +535,13 @@ function excel_format_plugin_column_value( $p_column, BugData $p_bug ) { $t_plugin_columns = columns_get_plugin_columns(); if( !isset( $t_plugin_columns[$p_column] ) ) { - return excel_prepare_string( '' ); + $t_value = ''; } else { $t_column_object = $t_plugin_columns[$p_column]; - ob_start(); - $t_column_object->display( $p_bug, COLUMNS_TARGET_EXCEL_PAGE ); - $t_value = ob_get_clean(); - return excel_prepare_string( $t_value ); + $t_value = $t_column_object->value( $p_bug ); } + + return excel_prepare_string( $t_value ); } /** diff --git a/csv_export.php b/csv_export.php index 402a17b6ed..6501db626e 100644 --- a/csv_export.php +++ b/csv_export.php @@ -148,16 +148,19 @@ $t_first_column = false; } - if( column_get_custom_field_name( $t_column ) !== null || column_is_plugin_column( $t_column ) ) { - ob_start(); - $t_column_value_function = 'print_column_value'; - helper_call_custom_function( $t_column_value_function, array( $t_column, $t_row, COLUMNS_TARGET_CSV_PAGE ) ); - $t_value = ob_get_clean(); - - echo csv_escape_string( $t_value ); + $t_custom_field = column_get_custom_field_name( $t_column ); + if( $t_custom_field !== null ) { + echo csv_format_custom_field( $t_row->id, $t_row->project_id, $t_custom_field ); + } else if( column_is_plugin_column( $t_column ) ) { + echo csv_format_plugin_column_value( $t_column, $t_row ); } else { $t_function = 'csv_format_' . $t_column; - echo $t_function( $t_row ); + if( function_exists( $t_function ) ) { + echo $t_function( $t_row ); + } else { + # Field is unknown + echo ''; + } } } diff --git a/docbook/Admin_Guide/en-US/Revision_History.xml b/docbook/Admin_Guide/en-US/Revision_History.xml index e5f7cf1c33..c0985958d9 100644 --- a/docbook/Admin_Guide/en-US/Revision_History.xml +++ b/docbook/Admin_Guide/en-US/Revision_History.xml @@ -5,6 +5,20 @@ Revision History + + 2.4-1 + Sat May 20 2017 + + Victor + Boctor + vboctor@mantisbt.org + + + + Release 2.4.1 + + + 2.4-0 Sun Apr 30 2017 diff --git a/docbook/Developers_Guide/en-US/Revision_History.xml b/docbook/Developers_Guide/en-US/Revision_History.xml index a8be04dde9..d94edce4d1 100644 --- a/docbook/Developers_Guide/en-US/Revision_History.xml +++ b/docbook/Developers_Guide/en-US/Revision_History.xml @@ -7,6 +7,20 @@ Revision History + + 2.4-1 + Sat May 20 2017 + + Victor + Boctor + vboctor@mantisbt.org + + + + Release 2.4.1 + + + 2.4-0 Sun Apr 30 2017 diff --git a/excel_xml_export.php b/excel_xml_export.php index 5d759d7ffb..d1c6ded56f 100644 --- a/excel_xml_export.php +++ b/excel_xml_export.php @@ -147,7 +147,12 @@ echo excel_format_plugin_column_value( $t_column, $t_row ); } else { $t_function = 'excel_format_' . $t_column; - echo $t_function( $t_row ); + if( function_exists( $t_function ) ) { + echo $t_function( $t_row ); + } else { + # field is unknown + echo ''; + } } }