From: Yuri Astrakhan Date: Tue, 15 May 2007 18:45:20 +0000 (+0000) Subject: * API: JSON format now allows callback parameter X-Git-Tag: 1.31.0-rc.0~52904 X-Git-Url: http://git.cyclocoop.org//%22%22.str_replace%28%27%22%27%2C?a=commitdiff_plain;h=6e1226c640fae22495a374fdc827ebdd03e711ee;p=lhc%2Fweb%2Fwiklou.git * API: JSON format now allows callback parameter --- diff --git a/includes/api/ApiFormatJson.php b/includes/api/ApiFormatJson.php index 99979d207d..8184c8c74b 100644 --- a/includes/api/ApiFormatJson.php +++ b/includes/api/ApiFormatJson.php @@ -49,14 +49,35 @@ class ApiFormatJson extends ApiFormatBase { } public function execute() { + $prefix = $suffix = ""; + + $params = $this->extractRequestParams(); + $callback = $params['callback']; + if(!is_null($callback)) { + $prefix = ereg_replace("[^_A-Za-z0-9]", "", $callback ) . "("; + $suffix = ")"; + } + if (!function_exists('json_encode') || $this->getIsHtml()) { $json = new Services_JSON(); - $this->printText($json->encode($this->getResultData(), $this->getIsHtml())); + $this->printText($prefix . $json->encode($this->getResultData(), $this->getIsHtml()) . $suffix); } else { - $this->printText(json_encode($this->getResultData())); + $this->printText($prefix . json_encode($this->getResultData()) . $suffix); } } + protected function getAllowedParams() { + return array ( + 'callback' => null + ); + } + + protected function getParamDescription() { + return array ( + 'callback' => 'If specified, wraps the output into a given function call', + ); + } + protected function getDescription() { if ($this->mIsRaw) return 'Output data with the debuging elements in JSON format' . parent :: getDescription();