From 6da7587e5d92d6e43a8e42470a273c946c258f2f Mon Sep 17 00:00:00 2001
From: Axel Rutz <axel.rutz@clever-systems.net>
Date: Fri, 16 Nov 2012 01:47:17 +0100
Subject: [PATCH] views_data_export Issue #1842108 by axel.rutz: Added Convert
 csv output to any encoding.

---
 .../views_data_export_plugin_style_export_csv.inc  |    9 ++---
 theme/views_data_export.theme.inc                  |   33 +++++++++++--------
 2 files changed, 22 insertions(+), 20 deletions(-)

diff --git a/plugins/views_data_export_plugin_style_export_csv.inc b/plugins/views_data_export_plugin_style_export_csv.inc
index 4aa900a..2083f2d 100644
--- a/plugins/views_data_export_plugin_style_export_csv.inc
+++ b/plugins/views_data_export_plugin_style_export_csv.inc
@@ -110,14 +110,11 @@ class views_data_export_plugin_style_export_csv extends views_data_export_plugin
       '#title' => t('Keep HTML tags.'),
     );
     $form['encoding'] = array(
-      '#type' => 'select',
+      '#type' => 'textfield',
       '#default_value' => !empty($this->options['encoding']) ? $this->options['encoding'] : '',
       '#title' => t('Character encoding conversion'),
-      '#options' => array (
-        '' => t('No conversion'),
-        'ASCII' => t('ASCII'),
-      ),
-      '#description' => t('Optionally specify a character conversion that some CSV file readers need. Note, using an external tool is always preferred and you should only use this option as a last resort. This feature requires the "iconv" PHP extension.'),
+      '#description' => t('Optionally specify a character conversion that some CSV file readers need. Use "utf8_decode" for ISO-8859-1 via said <a href="!utf8_decode">PHP function</a>, other values will be passed <a href="!url">iconv</a> (this requires the iconv PHP extension), empty or illegal values will leave the output as UTF-8.',
+        array('!iconv' => 'http://www.php.net/manual/en/function.iconv.php', '!utf8_decode' => 'http://www.php.net/manual/en/function.utf8-decode.php')),
     );
   }
 }
diff --git a/theme/views_data_export.theme.inc b/theme/views_data_export.theme.inc
index bc69cbd..7fc94c0 100644
--- a/theme/views_data_export.theme.inc
+++ b/theme/views_data_export.theme.inc
@@ -111,16 +111,18 @@ function template_preprocess_views_data_export_csv_header(&$vars) {
       $output = trim($output);
     }
     if (!empty($vars['options']['encoding']) && function_exists('iconv')) {
-        switch($vars['options']['encoding']) {
-          case 'ASCII':
-            $converted = iconv("UTF-8", "ASCII//TRANSLIT", $output);
-            if ($converted !== FALSE) {
-              $output = $converted;
-            }
-            break;
-        }
+      switch($vars['options']['encoding']) {
+        case 'utf8_decode':
+          $converted = utf8_decode($output);
+          break;
+        default:
+          $converted = iconv("UTF-8", $vars['options']['encoding'], $output);
+          break;
       }
-
+      if ($converted !== FALSE) {
+        $output = $converted;
+      }
+    }
     $vars['header'][$key] = $wrap . str_replace('"', $replace_value, $output) . $wrap;
   }
 }
@@ -157,12 +159,15 @@ function template_preprocess_views_data_export_csv_body(&$vars) {
 
       if (!empty($vars['options']['encoding']) && function_exists('iconv')) {
         switch($vars['options']['encoding']) {
-          case 'ASCII':
-            $converted = iconv("UTF-8", "ASCII//TRANSLIT", $output);
-            if ($converted !== FALSE) {
-              $output = $converted;
-            }
+          case 'utf8_decode':
+            $converted = utf8_decode($output);
             break;
+          default:
+            $converted = iconv("UTF-8", $vars['options']['encoding'], $output);
+            break;
+        }
+        if ($converted !== FALSE) {
+          $output = $converted;
         }
       }
       if (!empty($vars['options']['replace_newlines'])) {
-- 
1.7.5.4

