From 206c2a734e2a0d100af6d772d90b01c5cb8fe870 Mon Sep 17 00:00:00 2001 From: Eric Fredj Date: Tue, 5 Apr 2016 16:30:08 +0200 Subject: Fix UTF-8 encoding before JSON export --- inc/poche/Poche.class.php | 2 +- inc/poche/Tools.class.php | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 400857b4..1476d158 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -908,7 +908,7 @@ class Poche $entries = $this->store->retrieveAllWithTags($this->user->getId()); if ($entries) { echo $this->tpl->render('export.twig', array( - 'export' => Tools::renderJson($entries), + 'export' => Tools::renderJson(Tools::utf8ize($entries)), )); Tools::logm('export view'); } else { diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php index e5e150cd..d84850cf 100755 --- a/inc/poche/Tools.class.php +++ b/inc/poche/Tools.class.php @@ -232,6 +232,27 @@ final class Tools exit(); } + /** + * UTF-8 encode array of string + * + * @param $data + */ + public static function utf8ize($data) + { + if (is_array($data)) + { + foreach ($data as $k => $v) + { + $data[$k] = self::utf8ize($v); + } + } + else if (is_string ($data)) + { + return utf8_encode($data); + } + return $data; + } + /** * Create new line in log file * -- cgit v1.2.3