/** * Convert JSON data to XML if it is in JSON * * @version 1.26.0 */ public static function json_to_xml($json, $options = array()) { //** An array of serializer options */ $options = wp_parse_args($options, array('indent' => " ", 'linebreak' => "\n", 'addDecl' => true, 'encoding' => 'ISO-8859-1', 'rootName' => 'objects', 'defaultTagName' => 'object', 'mode' => false)); if (empty($json)) { return false; } if (!class_exists('XML_Serializer')) { set_include_path(get_include_path() . PATH_SEPARATOR . WPP_Path . 'lib/third-party/XML/'); @(require_once 'Serializer.php'); } //** If class still doesn't exist, for whatever reason, we fail */ if (!class_exists('XML_Serializer')) { return false; } $encoding = function_exists('mb_detect_encoding') ? mb_detect_encoding($json) : 'UTF-8'; if ($encoding == 'UTF-8') { $json = preg_replace('/[^(\\x20-\\x7F)]*/', '', $json); } $json = WPP_F::strip_invalid_xml($json); $data = json_decode($json, true); //** If could not decode, return false so we presume with XML format */ if (!is_array($data)) { return false; } $Serializer = new XML_Serializer($options); $status = $Serializer->serialize($data); if (PEAR::isError($status)) { return false; } if ($Serializer->getSerializedData()) { return $Serializer->getSerializedData(); } return false; }