[Mapbender-commits] r4658 - in branches/2.6/http: classes php
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Fri Sep 18 06:57:30 EDT 2009
Author: tbaschetti
Date: 2009-09-18 06:57:29 -0400 (Fri, 18 Sep 2009)
New Revision: 4658
Modified:
branches/2.6/http/classes/class_json.php
branches/2.6/http/php/mod_addWMSfromfilteredList_server.php
Log:
added json->save_encode (converting to UTF-8 before encoding)
fixes http://trac.osgeo.org/mapbender/ticket/171
Modified: branches/2.6/http/classes/class_json.php
===================================================================
--- branches/2.6/http/classes/class_json.php 2009-09-18 10:44:35 UTC (rev 4657)
+++ branches/2.6/http/classes/class_json.php 2009-09-18 10:57:29 UTC (rev 4658)
@@ -59,6 +59,40 @@
}
}
+ /**
+ * Converts incoming object to UTF-8 for json_encode
+ *
+ */
+
+ private function json_fix_charset($var)
+ {
+ if (is_array($var)) {
+ $new = array();
+ foreach ($var as $k => $v) {
+ $new[$this->json_fix_charset($k)] = $this->json_fix_charset($v);
+ }
+ $var = $new;
+ } elseif (is_object($var)) {
+ $vars = get_object_vars(get_class($var));
+ foreach ($vars as $m => $v) {
+ $var->$m = $this->json_fix_charset($v);
+ }
+ } elseif (is_string($var)) {
+ $var = utf8_encode($var);
+ }
+ return $var;
+ }
+
+ /**
+ * savely encode object to JSON,
+ * converting to UTF-8
+ */
+ public function save_encode($anObject){
+ $e = new mb_notice("converting to UTF-8 before using native JSON");
+ return $this->encode($this->json_fix_charset($anObject));
+ }
+
+
/**
* Encodes an object to JSON
*/
Modified: branches/2.6/http/php/mod_addWMSfromfilteredList_server.php
===================================================================
--- branches/2.6/http/php/mod_addWMSfromfilteredList_server.php 2009-09-18 10:44:35 UTC (rev 4657)
+++ branches/2.6/http/php/mod_addWMSfromfilteredList_server.php 2009-09-18 10:57:29 UTC (rev 4658)
@@ -130,6 +130,6 @@
}
$json = new Mapbender_JSON();
-$output = $json->encode($resultObj);
+$output = $json->save_encode($resultObj);
echo $output;
-?>
\ No newline at end of file
+?>
More information about the Mapbender_commits
mailing list