Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge remote-tracking branch 'origin/master-2.4'
Conflicts:
	core/constant_inc.php
  • Loading branch information
dregad committed May 22, 2017
2 parents 6f7ea15 + 609e252 commit 13a7de4
Show file tree
Hide file tree
Showing 9 changed files with 194 additions and 23 deletions.
72 changes: 68 additions & 4 deletions core/cfdefs/cfdef_standard.php
Expand Up @@ -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,
);

Expand All @@ -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,
);

Expand All @@ -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,
);

Expand All @@ -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,
);

Expand All @@ -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',
);
Expand All @@ -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',
);
Expand All @@ -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',
);
Expand All @@ -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',
);
Expand All @@ -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',
);
Expand All @@ -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',
);
Expand All @@ -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',
);
Expand All @@ -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.
Expand Down
17 changes: 17 additions & 0 deletions core/classes/MantisColumn.class.php
Expand Up @@ -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();
}
}

42 changes: 42 additions & 0 deletions core/csv_api.php
Expand Up @@ -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.
Expand Down
16 changes: 14 additions & 2 deletions core/custom_field_api.php
Expand Up @@ -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;
}

/**
Expand All @@ -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 );
}

/**
Expand Down
16 changes: 8 additions & 8 deletions core/excel_api.php
Expand Up @@ -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
Expand All @@ -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 );
}

/**
Expand Down
19 changes: 11 additions & 8 deletions csv_export.php
Expand Up @@ -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 '';
}
}
}

Expand Down
14 changes: 14 additions & 0 deletions docbook/Admin_Guide/en-US/Revision_History.xml
Expand Up @@ -5,6 +5,20 @@
<title>Revision History</title>
<simpara>
<revhistory>
<revision>
<revnumber>2.4-1</revnumber>
<date>Sat May 20 2017</date>
<author>
<firstname>Victor</firstname>
<surname>Boctor</surname>
<email>vboctor@mantisbt.org</email>
</author>
<revdescription>
<simplelist>
<member>Release 2.4.1</member>
</simplelist>
</revdescription>
</revision>
<revision>
<revnumber>2.4-0</revnumber>
<date>Sun Apr 30 2017</date>
Expand Down
14 changes: 14 additions & 0 deletions docbook/Developers_Guide/en-US/Revision_History.xml
Expand Up @@ -7,6 +7,20 @@
<title>Revision History</title>
<simpara>
<revhistory>
<revision>
<revnumber>2.4-1</revnumber>
<date>Sat May 20 2017</date>
<author>
<firstname>Victor</firstname>
<surname>Boctor</surname>
<email>vboctor@mantisbt.org</email>
</author>
<revdescription>
<simplelist>
<member>Release 2.4.1</member>
</simplelist>
</revdescription>
</revision>
<revision>
<revnumber>2.4-0</revnumber>
<date>Sun Apr 30 2017</date>
Expand Down
7 changes: 6 additions & 1 deletion excel_xml_export.php
Expand Up @@ -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 '';
}
}
}

Expand Down

0 comments on commit 13a7de4

Please sign in to comment.