Index: trunk/phase3/includes/api/ApiFormatJson.php |
— | — | @@ -49,14 +49,35 @@ |
50 | 50 | } |
51 | 51 | |
52 | 52 | public function execute() { |
| 53 | + $prefix = $suffix = ""; |
| 54 | + |
| 55 | + $params = $this->extractRequestParams(); |
| 56 | + $callback = $params['callback']; |
| 57 | + if(!is_null($callback)) { |
| 58 | + $prefix = ereg_replace("[^_A-Za-z0-9]", "", $callback ) . "("; |
| 59 | + $suffix = ")"; |
| 60 | + } |
| 61 | + |
53 | 62 | if (!function_exists('json_encode') || $this->getIsHtml()) { |
54 | 63 | $json = new Services_JSON(); |
55 | | - $this->printText($json->encode($this->getResultData(), $this->getIsHtml())); |
| 64 | + $this->printText($prefix . $json->encode($this->getResultData(), $this->getIsHtml()) . $suffix); |
56 | 65 | } else { |
57 | | - $this->printText(json_encode($this->getResultData())); |
| 66 | + $this->printText($prefix . json_encode($this->getResultData()) . $suffix); |
58 | 67 | } |
59 | 68 | } |
60 | 69 | |
| 70 | + protected function getAllowedParams() { |
| 71 | + return array ( |
| 72 | + 'callback' => null |
| 73 | + ); |
| 74 | + } |
| 75 | + |
| 76 | + protected function getParamDescription() { |
| 77 | + return array ( |
| 78 | + 'callback' => 'If specified, wraps the output into a given function call', |
| 79 | + ); |
| 80 | + } |
| 81 | + |
61 | 82 | protected function getDescription() { |
62 | 83 | if ($this->mIsRaw) |
63 | 84 | return 'Output data with the debuging elements in JSON format' . parent :: getDescription(); |