aboutsummaryrefslogtreecommitdiffhomepage
path: root/index.php
diff options
context:
space:
mode:
authorSébastien SAUVAGE <sebsauvage@sebsauvage.net>2013-09-24 02:20:06 -0700
committerSébastien SAUVAGE <sebsauvage@sebsauvage.net>2013-09-24 02:20:06 -0700
commiteea58b3d5a12ef6a75f482dfeecac2b8fa446170 (patch)
tree359f4c04e891914dc782440a8e9bfa805feedc3d /index.php
parent3fac0a52577ac0d1ac0a78fde5f5dba154a70e35 (diff)
parent3385af123f6b4dfc59aeaa69f180381307b64368 (diff)
downloadShaarli-eea58b3d5a12ef6a75f482dfeecac2b8fa446170.tar.gz
Shaarli-eea58b3d5a12ef6a75f482dfeecac2b8fa446170.tar.zst
Shaarli-eea58b3d5a12ef6a75f482dfeecac2b8fa446170.zip
Merge pull request #87 from LionelMartin/3385af123f6b4dfc59aeaa69f180381307b64368
Added a json_encode implementation for PHP < 5.2 (free.fr)
Diffstat (limited to 'index.php')
-rw-r--r--index.php37
1 files changed, 36 insertions, 1 deletions
diff --git a/index.php b/index.php
index 327109f0..d9181b65 100644
--- a/index.php
+++ b/index.php
@@ -2151,7 +2151,42 @@ function isTZvalid($continent,$city)
2151 } 2151 }
2152 return false; 2152 return false;
2153} 2153}
2154 2154if (!function_exists('json_encode')) {
2155 function json_encode($data) {
2156 switch ($type = gettype($data)) {
2157 case 'NULL':
2158 return 'null';
2159 case 'boolean':
2160 return ($data ? 'true' : 'false');
2161 case 'integer':
2162 case 'double':
2163 case 'float':
2164 return $data;
2165 case 'string':
2166 return '"' . addslashes($data) . '"';
2167 case 'object':
2168 $data = get_object_vars($data);
2169 case 'array':
2170 $output_index_count = 0;
2171 $output_indexed = array();
2172 $output_associative = array();
2173 foreach ($data as $key => $value) {
2174 $output_indexed[] = json_encode($value);
2175 $output_associative[] = json_encode($key) . ':' . json_encode($value);
2176 if ($output_index_count !== NULL && $output_index_count++ !== $key) {
2177 $output_index_count = NULL;
2178 }
2179 }
2180 if ($output_index_count !== NULL) {
2181 return '[' . implode(',', $output_indexed) . ']';
2182 } else {
2183 return '{' . implode(',', $output_associative) . '}';
2184 }
2185 default:
2186 return ''; // Not supported
2187 }
2188 }
2189}
2155 2190
2156// Webservices (for use with jQuery/jQueryUI) 2191// Webservices (for use with jQuery/jQueryUI)
2157// eg. index.php?ws=tags&term=minecr 2192// eg. index.php?ws=tags&term=minecr