diff --git a/api/src/Storage/Merge.php b/api/src/Storage/Merge.php index 9c4d056682..4b7618e2cc 100644 --- a/api/src/Storage/Merge.php +++ b/api/src/Storage/Merge.php @@ -1531,14 +1531,14 @@ abstract class Merge case 'application/vnd.oasis.opendocument.spreadsheet': // open office calc case 'application/vnd.oasis.opendocument.spreadsheet-template': $format = '/]+?)office:value-type="[^"]+"([^>]*?)(?:calcext:value-type="[^"]+")?>.?<([a-z].*?)[^>]*>(' . implode('|', $names) . ')<\/\3>.?<\/table:table-cell>/s'; - $replacement = '<$3>$4'; + $replacement = '<$3>$4'; break; case 'application/vnd.oasis.opendocument.text': // tables in open office writer case 'application/vnd.oasis.opendocument.presentation': case 'application/vnd.oasis.opendocument.text-template': case 'application/vnd.oasis.opendocument.presentation-template': $format = '/]+?)office:value-type="[^"]+"([^>]*?)>.?<([a-z].*?)[^>]*>(' . implode('|', $names) . ')<\/\3>.?<\/table:table-cell>/s'; - $replacement = '$4'; + $replacement = '$4'; break; case 'application/vnd.oasis.opendocument.text': // open office writer case 'application/xmlExcel.Sheet': // Excel 2003 @@ -1549,10 +1549,23 @@ abstract class Merge } if(!empty($format) && $names) { + // Use raw value instead of formatted value for spreadsheets (when present), but don't interfere otherwise + $callback = function ($matches) use ($replacement) + { + if($matches[4] && ($fieldname = substr($matches[4], 2, -2)) && in_array($this->prefix("", $fieldname, '$'), $this->numeric_fields)) + { + $matches[5] = $this->prefix("", $fieldname . '_-raw-', '$'); + } + else + { + $matches[5] = $matches[4]; + } + return str_replace(['$0', '$1', '$2', '$3', '$4', '$5'], $matches, $replacement); + }; // Dealing with backtrack limit per AmigoJack 10-Jul-2010 comment on php.net preg-replace docs do { - $result = preg_replace($format, $replacement, $content, -1); + $result = preg_replace_callback($format, $callback, $content, -1); } // try to increase/double pcre.backtrack_limit failure while(preg_last_error() == PREG_BACKTRACK_LIMIT_ERROR && self::increase_backtrack_limit()); @@ -1687,6 +1700,7 @@ abstract class Merge /** * Expand link_to custom fields with the merge replacements from the app * but only if the template uses them. + * We also do other custom field processing here */ public function cf_link_to_expand($values, $content, &$replacements, $app = null) { @@ -1696,6 +1710,21 @@ abstract class Merge } $cfs = Api\Storage\Customfields::get($app); + // Custom field processing + foreach($cfs as $fieldname => $field_data) + { + switch($field_data['type']) + { + case 'float': + case 'int': + $this->numeric_fields[] = "$$#{$fieldname}$$"; + break; + case 'date': + case 'datetime': + $this->date_fields[] = "$$#{$fieldname}$$"; + } + } + // Cache, in case more than one sub-placeholder is used $app_replacements = array(); diff --git a/importexport/inc/class.importexport_export_csv.inc.php b/importexport/inc/class.importexport_export_csv.inc.php index ad89472b10..96391e5a71 100644 --- a/importexport/inc/class.importexport_export_csv.inc.php +++ b/importexport/inc/class.importexport_export_csv.inc.php @@ -449,6 +449,8 @@ class importexport_export_csv implements importexport_iface_export_record } if($record->$name && (string)$record->$name != '') { + $raw = $name . '_-raw-'; + $record->$raw = $record->$name; if(!is_numeric($record->$name)) { $record->$name = (float)(str_replace($dec_separator, '.', preg_replace('/[^\d'.preg_quote($dec_separator, '/').']/', '', $record->$name)));