summaryrefslogtreecommitdiff
path: root/modules/gallery/helpers
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2011-06-05 17:16:07 -0700
committerBharat Mediratta <bharat@menalto.com>2011-06-05 17:16:07 -0700
commit61691fdf713950f704427640bc30776990768d98 (patch)
treeb189d04d583cc06fb25e7e260219388826d89242 /modules/gallery/helpers
parent4a208226edbd3aeb8352b068f6f774ce410a3b3d (diff)
Use the strict form of mb_detect_encoding for best results.
Thanks to guthy in https://github.com/gallery/gallery3/commit/fa6f233603267505c216abc4f12663d245cd23e7#commitcomment-403145 Fixes #1745.
Diffstat (limited to 'modules/gallery/helpers')
-rw-r--r--modules/gallery/helpers/encoding.php17
1 files changed, 10 insertions, 7 deletions
diff --git a/modules/gallery/helpers/encoding.php b/modules/gallery/helpers/encoding.php
index c5928634..7d5add34 100644
--- a/modules/gallery/helpers/encoding.php
+++ b/modules/gallery/helpers/encoding.php
@@ -19,13 +19,16 @@
*/
class encoding_Core {
static function convert_to_utf8($value) {
- if (function_exists("mb_detect_encoding") &&
- function_exists("mb_convert_encoding") &&
- mb_detect_encoding($value, "ISO-8859-1, UTF-8") != "UTF-8") {
- $value = mb_convert_encoding($value, "UTF-8", mb_detect_encoding($value));
- } else if (function_exists("mb_detect_encoding") &&
- mb_detect_encoding($value, "ISO-8859-1, UTF-8") != "UTF-8") {
- $value = utf8_encode($value);
+ if (function_exists("mb_detect_encoding")) {
+ // Rely on mb_detect_encoding()'s strict mode
+ $src_encoding = mb_detect_encoding($value, mb_detect_order(), true);
+ if ($src_encoding != "UTF-8") {
+ if (function_exists("mb_convert_encoding") && $src_encoding) {
+ $value = mb_convert_encoding($value, "UTF-8", $src_encoding);
+ } else {
+ $value = utf8_encode($value);
+ }
+ }
}
return $value;
}