/** * JSON response generator. * will perform character transformation according to parameters. * * @access public * @param object $node a cpaint_node object * @return string */ function toJSON($node) { $return_value = ''; $JSON_node = new stdClass(); // handle attributes $JSON_node->attributes = $node->attributes; // handle subnodes foreach ($node->composites as $composite) { if (!is_array($JSON_node->{$composite->nodename})) { $JSON_node->{$composite->nodename} = array(); } // end: if // we need to parse the JSON object again to avoid multiple encoding $JSON_node->{$composite->nodename}[] = $GLOBALS['__cpaint_json']->parse(cpaint_transformer::toJSON($composite)); } // handle data $JSON_node->data = $node->data; return $GLOBALS['__cpaint_json']->stringify($JSON_node); }