From a7fbb9d25e0d943b425fd3318d5aed54265ef939 Mon Sep 17 00:00:00 2001 From: Rimas Kudelis <rq@akl.lt> Date: Mon, 7 Mar 2016 08:20:38 +0200 Subject: [PATCH] Added support for Windows-125* character sets in CSV import. Excel still does not export CSV as UTF-8, using the 8-bit system character set instead, so support for these charsets comes in handy. This also updates the `convertCharacterEncoding()` function to be a bit smarter when choosing its backend. --- .../Import/modules/Import/helpers/Utils.php | 14 +++++++++++++- .../Import/modules/Import/readers/FileReader.php | 5 ++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/pkg/vtiger/modules/Import/modules/Import/helpers/Utils.php b/pkg/vtiger/modules/Import/modules/Import/helpers/Utils.php index 2da70b661..0b42706ea 100644 --- a/pkg/vtiger/modules/Import/modules/Import/helpers/Utils.php +++ b/pkg/vtiger/modules/Import/modules/Import/helpers/Utils.php @@ -16,7 +16,19 @@ class Import_Utils_Helper { static $AUTO_MERGE_OVERWRITE = 2; static $AUTO_MERGE_MERGEFIELDS = 3; - static $supportedFileEncoding = array('UTF-8'=>'UTF-8', 'ISO-8859-1'=>'ISO-8859-1'); + static $supportedFileEncoding = array( + 'UTF-8'=>'UTF-8', + 'ISO-8859-1'=>'ISO-8859-1', + 'Windows-1250'=>'Windows-1250', + 'Windows-1251'=>'Windows-1251', + 'Windows-1252'=>'Windows-1252', + 'Windows-1253'=>'Windows-1253', + 'Windows-1254'=>'Windows-1254', + 'Windows-1255'=>'Windows-1255', + 'Windows-1256'=>'Windows-1256', + 'Windows-1257'=>'Windows-1257', + 'Windows-1258'=>'Windows-1258', + ); static $supportedDelimiters = array(','=>'comma', ';'=>'semicolon'); static $supportedFileExtensions = array('csv','vcf'); diff --git a/pkg/vtiger/modules/Import/modules/Import/readers/FileReader.php b/pkg/vtiger/modules/Import/modules/Import/readers/FileReader.php index 8f55f64fa..dd77e669d 100644 --- a/pkg/vtiger/modules/Import/modules/Import/readers/FileReader.php +++ b/pkg/vtiger/modules/Import/modules/Import/readers/FileReader.php @@ -70,7 +70,10 @@ class Import_FileReader_Reader { } public function convertCharacterEncoding($value, $fromCharset, $toCharset) { - if (function_exists("mb_convert_encoding")) { + if (function_exists("mb_convert_encoding") + && function_exists("mb_list_encodings") + && in_array($fromCharset, mb_list_encodings()) + && in_array($toCharset, mb_list_encodings())) { $value = mb_convert_encoding($value, $toCharset, $fromCharset); } else { $value = iconv($fromCharset, $toCharset, $value); -- GitLab