diff --git a/config/func.inc.php b/config/func.inc.php index b09e04deb..9f0822f6b 100644 --- a/config/func.inc.php +++ b/config/func.inc.php @@ -1109,7 +1109,39 @@ function detectUTF8($string, $return_convert = false, $urldecode = true) */ function json_encode2($data) { - return json_encode($data); + switch (gettype($data)) + { + case 'boolean': + return $data?'true':'false'; + case 'integer': + case 'double': + return $data; + case 'string': + return '"'.strtr($data, array('\\'=>'\\\\','"'=>'\\"')).'"'; + case 'object': + $data = get_object_vars($data); + case 'array': + $rel = false; // relative array? + $key = array_keys($data); + foreach($key as $v) + { + if(!is_int($v)) + { + $rel = true; + break; + } + } + + $arr = array(); + foreach ($data as $k=>$v) + { + $arr[] = ($rel?'"'.strtr($k, array('\\'=>'\\\\','"'=>'\\"')).'":':'').json_encode2($v); + } + + return $rel?'{'.join(',', $arr).'}':'['.join(',', $arr).']'; + default: + return '""'; + } } /** diff --git a/modules/counter/counter.model.php b/modules/counter/counter.model.php index c1901a9d0..bfb6ec3e8 100644 --- a/modules/counter/counter.model.php +++ b/modules/counter/counter.model.php @@ -290,6 +290,13 @@ class counterModel extends counter $date = date('Ymd'); $output = $this->getHourlyStatus('week', $date); + $tmp = array(); + foreach($output->list AS $key=>$value) + { + $tmp["'".$key."'"] = $value; + } + $output->list = $tmp; + $this->add('data', $output); } @@ -298,6 +305,13 @@ class counterModel extends counter $date = date('Ymd'); $output = $this->getHourlyStatus('week', $date, 0, true); + $tmp = array(); + foreach($output->list AS $key=>$value) + { + $tmp["'".$key."'"] = $value; + } + $output->list = $tmp; + $this->add('data', $output); } }