27 #require_once 'Zend/Json/Expr.php'; 30 #require_once 'Zend/Xml/Security.php'; 76 $encodedValue = (string) $encodedValue;
77 if (
function_exists(
'json_decode') && self::$useBuiltinEncoderDecoder !==
true) {
78 $decode = json_decode($encodedValue, $objectDecodeType);
82 if (strtolower($encodedValue) ===
'null') {
84 }
elseif ($decode ===
null) {
85 #require_once 'Zend/Json/Exception.php'; 89 }
elseif (($jsonLastErr = json_last_error()) != JSON_ERROR_NONE) {
90 #require_once 'Zend/Json/Exception.php'; 91 switch ($jsonLastErr) {
92 case JSON_ERROR_DEPTH:
94 case JSON_ERROR_CTRL_CHAR:
96 case JSON_ERROR_SYNTAX:
106 #require_once 'Zend/Json/Decoder.php'; 130 public static function encode($valueToEncode, $cycleCheck =
false,
$options = array())
132 if (is_object($valueToEncode)) {
133 if (method_exists($valueToEncode,
'toJson')) {
134 return $valueToEncode->toJson();
135 }
elseif (method_exists($valueToEncode,
'toArray')) {
141 $javascriptExpressions = array();
142 if(isset(
$options[
'enableJsonExprFinder'])
143 && (
$options[
'enableJsonExprFinder'] ==
true)
148 #require_once "Zend/Json/Encoder.php"; 153 if (
function_exists(
'json_encode') && self::$useBuiltinEncoderDecoder !==
true) {
154 $encodedResult = json_encode($valueToEncode);
156 #require_once 'Zend/Json/Encoder.php'; 161 if (count($javascriptExpressions) > 0) {
162 $count = count($javascriptExpressions);
164 $magicKey = $javascriptExpressions[
$i][
'magicKey'];
165 $value = $javascriptExpressions[
$i][
'value'];
167 $encodedResult = str_replace(
169 '"' . $magicKey .
'"',
176 return $encodedResult;
201 $magicKey =
"____" . $currentKey .
"_" . (count($javascriptExpressions));
202 $javascriptExpressions[] = array(
206 "value" =>
$value->__toString(),
210 foreach (
$value as $k => $v) {
214 foreach (
$value as $k => $v) {
233 $pattern =
'/^[\s]*new Zend_Json_Expr[\s]*\([\s]*[\"\']{1}(.*)[\"\']{1}[\s]*\)[\s]*$/';
234 $matchings = array();
235 $match = preg_match (
$pattern, $simpleXmlElementObject, $matchings);
239 return (trim(strval($simpleXmlElementObject)));
263 protected static function _processXml($simpleXmlElementObject, $ignoreXmlAttributes, $recursionDepth=0)
266 if ($recursionDepth > self::$maxRecursionDepthAllowed) {
268 #require_once 'Zend/Json/Exception.php'; 270 "Function _processXml exceeded the allowed recursion depth of " .
271 self::$maxRecursionDepthAllowed);
274 $children = $simpleXmlElementObject->children();
275 $name = $simpleXmlElementObject->getName();
277 $attributes = (array) $simpleXmlElementObject->attributes();
280 if (!empty(
$attributes) && !$ignoreXmlAttributes) {
292 $childArray= array();
294 $childname = $child->getName();
296 if (array_key_exists($childname, $childArray)) {
297 if (empty($subChild[$childname])) {
298 $childArray[$childname] = array($childArray[$childname]);
299 $subChild[$childname] =
true;
301 $childArray[$childname][] =
$element[$childname];
303 $childArray[$childname] =
$element[$childname];
306 if (!empty(
$attributes) && !$ignoreXmlAttributes) {
310 $childArray[
'@attributes'] =
$attributes[
'@attributes'];
313 $childArray[
'@text'] =
$value;
315 return array(
$name => $childArray);
345 public static function fromXml($xmlStringContents, $ignoreXmlAttributes=
true)
351 if ($simpleXmlElementObject ==
null) {
352 #require_once 'Zend/Json/Exception.php'; 353 throw new Zend_Json_Exception(
'Function fromXml was called with an invalid XML formatted string.');
364 return($jsonStringOutput);
381 $tokens = preg_split(
'|([\{\}\]\[,])|', $json, -1, PREG_SPLIT_DELIM_CAPTURE);
395 $lineBreak =
'<br />';
396 $ind =
' ';
416 $prefix = str_repeat($ind, $indent);
425 $prefix = str_repeat($ind, $indent);
435 if ((substr_count(
$token,
"\"")-substr_count(
$token,
"\\\"")) % 2 != 0) {
436 $inLiteral = !$inLiteral;
static decode($encodedValue, $objectDecodeType=Zend_Json::TYPE_ARRAY)
elseif(isset( $params[ 'redirect_parent']))
static scan($xml, DOMDocument $dom=null)
static encodeUnicodeString($value)
static $useBuiltinEncoderDecoder
static prettyPrint($json, $options=array())
static _recursiveJsonExprFinder(&$value, array &$javascriptExpressions, $currentKey=null)
static fromXml($xmlStringContents, $ignoreXmlAttributes=true)
static _getXmlValue($simpleXmlElementObject)
static _processXml($simpleXmlElementObject, $ignoreXmlAttributes, $recursionDepth=0)
static encode($valueToEncode, $cycleCheck=false, $options=array())
static encode($value, $cycleCheck=false, $options=array())
static decode($source=null, $objectDecodeType=Zend_Json::TYPE_ARRAY)
static $maxRecursionDepthAllowed
if(!isset($_GET['name'])) $name