aboutsummaryrefslogtreecommitdiffhomepage
path: root/index.php
diff options
context:
space:
mode:
authorLionel Martin <renarddesmers@gmail.com>2013-05-20 19:00:28 +0200
committerLionel Martin <renarddesmers@gmail.com>2013-05-20 19:00:28 +0200
commit3385af123f6b4dfc59aeaa69f180381307b64368 (patch)
tree0b8d387c7b8b4899e9d4a6083ad4b182a5d215b8 /index.php
parent99954e12900401c5c725e65bce28cc1711653e45 (diff)
downloadShaarli-3385af123f6b4dfc59aeaa69f180381307b64368.tar.gz
Shaarli-3385af123f6b4dfc59aeaa69f180381307b64368.tar.zst
Shaarli-3385af123f6b4dfc59aeaa69f180381307b64368.zip
Added json_encode implementation for php<5.2
Diffstat (limited to 'index.php')
-rw-r--r--index.php39
1 files changed, 37 insertions, 2 deletions
diff --git a/index.php b/index.php
index 1d13e55c..eaa7c532 100644
--- a/index.php
+++ b/index.php
@@ -2122,7 +2122,42 @@ function isTZvalid($continent,$city)
2122 } 2122 }
2123 return false; 2123 return false;
2124} 2124}
2125 2125if (!function_exists('json_encode')) {
2126 function json_encode($data) {
2127 switch ($type = gettype($data)) {
2128 case 'NULL':
2129 return 'null';
2130 case 'boolean':
2131 return ($data ? 'true' : 'false');
2132 case 'integer':
2133 case 'double':
2134 case 'float':
2135 return $data;
2136 case 'string':
2137 return '"' . addslashes($data) . '"';
2138 case 'object':
2139 $data = get_object_vars($data);
2140 case 'array':
2141 $output_index_count = 0;
2142 $output_indexed = array();
2143 $output_associative = array();
2144 foreach ($data as $key => $value) {
2145 $output_indexed[] = json_encode($value);
2146 $output_associative[] = json_encode($key) . ':' . json_encode($value);
2147 if ($output_index_count !== NULL && $output_index_count++ !== $key) {
2148 $output_index_count = NULL;
2149 }
2150 }
2151 if ($output_index_count !== NULL) {
2152 return '[' . implode(',', $output_indexed) . ']';
2153 } else {
2154 return '{' . implode(',', $output_associative) . '}';
2155 }
2156 default:
2157 return ''; // Not supported
2158 }
2159 }
2160}
2126 2161
2127// Webservices (for use with jQuery/jQueryUI) 2162// Webservices (for use with jQuery/jQueryUI)
2128// eg. index.php?ws=tags&term=minecr 2163// eg. index.php?ws=tags&term=minecr
@@ -2419,4 +2454,4 @@ if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=d
2419if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'ws=')) { processWS(); exit; } // Webservices (for jQuery/jQueryUI) 2454if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'ws=')) { processWS(); exit; } // Webservices (for jQuery/jQueryUI)
2420if (!isset($_SESSION['LINKS_PER_PAGE'])) $_SESSION['LINKS_PER_PAGE']=$GLOBALS['config']['LINKS_PER_PAGE']; 2455if (!isset($_SESSION['LINKS_PER_PAGE'])) $_SESSION['LINKS_PER_PAGE']=$GLOBALS['config']['LINKS_PER_PAGE'];
2421renderPage(); 2456renderPage();
2422?> \ No newline at end of file 2457?>