Beispiel #1
0
 /**
  * Obtiene y limpia el JSON final para insertar el ebook como documento
  * Limpia y agrega los campos de _id y lastUpdate
  */
 public static function getBookJSONFromXMLNode($node)
 {
     //Funcion de procesamiento del XMl a la cadena JSON
     $arr = xml2json::transformXmlStringToArray($node);
     //Agrega last update y limpia el inicio y fin para simplificar la jerarquia
     //De esta forma no funciona al pasar a json se pierde
     //$arr['book']['lastUpdate'] = new MongoDate();
     $date = new MongoDate();
     $arr['book']['lastUpdate'] = array('$date' => $date->sec * 1000 + $date->usec / 1000);
     $mongo_id = str_replace('-', '', $arr['book']['@attributes']['id']);
     $arr['book']['_id'] = $mongo_id;
     //concvert to json
     $jsonContents = json_encode($arr);
     //Eliminación de datos innecesarios en la cadena JSON
     $json_string = Utils::cleanJSON($jsonContents);
     return $json_string;
 }
Beispiel #2
0
 public static function convertSimpleXmlElementObjectIntoArray($simpleXmlElementObject, &$recursionDepth = 0)
 {
     if ($recursionDepth > MAX_RECURSION_DEPTH_ALLOWED) {
         return null;
     }
     if ($recursionDepth == 0) {
         if (get_class($simpleXmlElementObject) != SIMPLE_XML_ELEMENT_PHP_CLASS) {
             return null;
         } else {
             $callerProvidedSimpleXmlElementObject = $simpleXmlElementObject;
         }
     }
     if (@get_class($simpleXmlElementObject) == SIMPLE_XML_ELEMENT_PHP_CLASS) {
         $copyOfsimpleXmlElementObject = $simpleXmlElementObject;
         $simpleXmlElementObject = get_object_vars($simpleXmlElementObject);
     }
     if (is_array($simpleXmlElementObject)) {
         $resultArray = array();
         if (count($simpleXmlElementObject) <= 0) {
             return trim(strval($copyOfsimpleXmlElementObject));
         }
         foreach ($simpleXmlElementObject as $key => $value) {
             $recursionDepth++;
             $resultArray[$key] = xml2json::convertSimpleXmlElementObjectIntoArray($value, $recursionDepth);
             $recursionDepth--;
         }
         if ($recursionDepth == 0) {
             $tempArray = $resultArray;
             $resultArray = array();
             $resultArray[$callerProvidedSimpleXmlElementObject->getName()] = $tempArray;
         }
         return $resultArray;
     } else {
         return trim(strval($simpleXmlElementObject));
     }
 }
Beispiel #3
0
<?php

require_once "xml2json/xml2json.php";
$url = $_GET['url'];
// Open the Curl session
$session = curl_init($url);
$postvars = '';
foreach ($_POST as $key => $value) {
    $postvars .= $key . '=' . $value . '&';
}
if ($postvars != '') {
    curl_setopt($session, CURLOPT_POST, true);
    curl_setopt($session, CURLOPT_POSTFIELDS, $postvars);
}
// Don't return HTTP headers. Do return the contents of the call
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
// Make the call
$xml = curl_exec($session);
curl_close($session);
$json = xml2json::transformXmlStringToJson($xml);
echo $json;
Beispiel #4
0
<?php

global $_W, $_GPC;
//check_shop_auth('http://120.26.212.219/api.php', $this -> pluginname);
ca('sale.enough.view');
$set = $this->getSet();
if (checksubmit('submit')) {
    ca('sale.enough.save');
    $data = is_array($_GPC['data']) ? $_GPC['data'] : array();
    $set['enoughfree'] = intval($data['enoughfree']);
    $set['enoughorder'] = round(floatval($data['enoughorder']), 2);
    $set['enoughareas'] = $data['enoughareas'];
    $set['enoughmoney'] = round(floatval($data['enoughmoney']), 2);
    $set['enoughdeduct'] = round(floatval($data['enoughdeduct']), 2);
    $this->updateSet($set);
    plog('sale.enough.save', '修改满额优惠');
    message('满额优惠设置成功!', referer(), 'success');
}
$areafile = IA_ROOT . "/addons/ewei_shop/data/areas";
$areas = json_decode(@file_get_contents($areafile), true);
if (!is_array($areas)) {
    require_once EWEI_SHOP_INC . 'json/xml2json.php';
    $file = IA_ROOT . "/addons/ewei_shop/static/js/dist/area/Area.xml";
    $content = file_get_contents($file);
    $json = xml2json::transformXmlStringToJson($content);
    $areas = json_decode($json, true);
    file_put_contents($areafile, $json);
}
load()->func('tpl');
include $this->template('enough');
 public static function convertSimpleXmlElementObjectIntoArray($simpleXmlElementObject, &$recursionDepth = 0)
 {
     // Keep an eye on how deeply we are involved in recursion.
     if ($recursionDepth > MAX_RECURSION_DEPTH_ALLOWED) {
         // Fatal error. Exit now.
         return null;
     }
     if ($recursionDepth == 0) {
         if (get_class($simpleXmlElementObject) != SIMPLE_XML_ELEMENT_PHP_CLASS) {
             // If the external caller doesn't call this function initially
             // with a SimpleXMLElement object, return now.
             return null;
         } else {
             // Store the original SimpleXmlElementObject sent by the caller.
             // We will need it at the very end when we return from here for good.
             $callerProvidedSimpleXmlElementObject = $simpleXmlElementObject;
         }
     }
     // End of if ($recursionDepth == 0) {
     if (is_object($simpleXmlElementObject) and get_class($simpleXmlElementObject) == SIMPLE_XML_ELEMENT_PHP_CLASS) {
         // Get a copy of the simpleXmlElementObject
         $copyOfsimpleXmlElementObject = $simpleXmlElementObject;
         // Get the object variables in the SimpleXmlElement object for us to iterate.
         $simpleXmlElementObject = get_object_vars($simpleXmlElementObject);
     }
     // It needs to be an array of object variables.
     if (is_array($simpleXmlElementObject)) {
         // Initialize the result array.
         $resultArray = array();
         // Is the input array size 0? Then, we reached the rare CDATA text if any.
         if (count($simpleXmlElementObject) <= 0) {
             // Let us return the lonely CDATA. It could even be whitespaces.
             return trim(strval($copyOfsimpleXmlElementObject));
         }
         // Let us walk through the child elements now.
         foreach ($simpleXmlElementObject as $key => $value) {
             // When this block of code is commented, XML attributes will be
             // added to the result array.
             // Uncomment the following block of code if XML attributes are
             // NOT required to be returned as part of the result array.
             /*
              if((is_string($key)) && ($key == SIMPLE_XML_ELEMENT_OBJECT_PROPERTY_FOR_ATTRIBUTES)) {
              continue;
              }
             */
             // Let us recursively process the current element we just visited.
             // Increase the recursion depth by one.
             $recursionDepth++;
             $resultArray[$key] = xml2json::convertSimpleXmlElementObjectIntoArray($value, $recursionDepth);
             // Decrease the recursion depth by one.
             $recursionDepth--;
         }
         // End of foreach($simpleXmlElementObject as $key=>$value) {
         if ($recursionDepth == 0) {
             // That is it. We are heading to the exit now.
             // Set the XML root element name as the root [top-level] key of
             // the associative array that we are going to return to the caller of this
             // recursive function.
             $tempArray = $resultArray;
             $resultArray = array();
             $resultArray[$callerProvidedSimpleXmlElementObject->getName()] = $tempArray;
         }
         return $resultArray;
     } else {
         // We are now looking at either the XML attribute text or
         // the text between the XML tags.
         return trim(strval($simpleXmlElementObject));
     }
     // End of else
 }
 function TransformXmlToJson()
 {
     $jsonContents = xml2json::transformXmlStringToJson($this->xml);
     return $jsonContents;
 }
Beispiel #7
0
merge, publish and distribute. This Software shall be used for Good, not Evil.

First Created on:
-----------------
Oct/04/2006

Last Modified on:
-----------------
Oct/07/2006
============================================================================================
*/
require_once "xml2json.php";
// Filename from where XML contents are to be read.
$testXmlFile = "";
// Read the filename from the command line.
if ($argc <= 1) {
    print "Please provide the XML filename as a command-line argument:\n";
    print "\tphp -f xml2json_test.php test1.xml\n";
    return;
} else {
    $testXmlFile = $argv[1];
}
//Read the XML contents from the input file.
file_exists($testXmlFile) or die('Could not find file ' . $testXmlFile);
$xmlStringContents = file_get_contents($testXmlFile);
$jsonContents = "";
// Convert it to JSON now.
// xml2json simply takes a String containing XML contents as input.
$jsonContents = xml2json::transformXmlStringToJson($xmlStringContents);
echo "JSON formatted output generated by xml2json:\n\n";
echo $jsonContents;
 function _throwError($error, $response_format)
 {
     Configure::write('debug', 0);
     $op = '<?xml version="1.0" encoding="UTF-8"?><response>' . $error . '</response>';
     if ($response_format == 'json') {
         App::import('vendor', 'xml2json', array('file' => 'xml2json/xml2json.php'));
         $jsonContents = xml2json::transformXmlStringToJson($op);
         echo $jsonContents;
     } else {
         //header("content-type: text/xml");
         echo $op;
     }
     exit;
 }
<?php

require_once "xml2json.php";
$file = utf16_to_utf8(file_get_contents($_FILES['file']['tmp_name']));
$log = fopen("log.txt", "a");
// fwrite($log, "starting\n");
// fwrite($log, "##" . $_FILES['file']['name'] . "##\n");
if (isPlist($_FILES['file']['name'])) {
    // fwrite($log, "is a plist\n");
    $postArgs = addFilenameAndType(xml2json::transformXmlStringToJson($file), $_FILES['file']['name'], "plist");
} else {
    if (isStrings($_FILES['file']['name'])) {
        // fwrite($log, "is a strings\n");
        $postArgs = transformStringsToJson($file, $_FILES['file']['name']);
    } else {
        if (isZip($_FILES['file']['name'])) {
            // fwrite($log, "is a zip\n");
            $postArgs = archiveToJson($file, $log);
        }
    }
}
fclose($log);
header("Content-Type: text/json");
// temporary fix
echo $postArgs;
function archiveToJson($zipFileContents, $log)
{
    $aFileName = "tmpArchive" . time() . ".zip";
    $theFile = fopen($aFileName, "w");
    // fwrite($log, "opened archive\n");
    fwrite($theFile, $zipFileContents);
Beispiel #10
0
 public static function json($xml)
 {
     return xml2json::transformXmlStringToJson($xml);
 }
Beispiel #11
0
function wfGetNetflixData($query = false, $callback = false, $count = 3)
{
    global $wgMemc;
    $query = urldecode($query);
    $netflix_api_key = WISE_netflix_api_key;
    $netflix_api_secret = WISE_netflix_api_secret;
    require_once '../common/OAuth.php';
    $test_consumer = new OAuthConsumer($netflix_api_key, $netflix_api_secret, NULL);
    $req_token = new OAuthConsumer("requestkey", "requestsecret", 1);
    $req_req = OAuthRequest::from_consumer_and_token($test_consumer, NULL, 'GET', 'http://api.netflix.com/catalog/titles', array("term" => $query, "expand" => "synopsis", "max_results" => $count));
    $req_req->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $test_consumer, NULL);
    $param_array = array();
    $params = preg_split("&", $req_req);
    foreach ($params as $key1) {
        $params2 = preg_split("=", $key1);
        $param_array[$params2[0]] = $params2[1];
    }
    $end_point_url = $req_req;
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $end_point_url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_TIMEOUT, 60);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    $xml = curl_exec($curl);
    $netflix_json = xml2json::transformXmlStringToJson($xml);
    return ($callback ? $callback . "(" : "") . $netflix_json . ($callback ? ");" : "");
}
 /**
  * getServiceResponse function.
  * 
  * @access public
  * @param mixed $param
  * @return void
  */
 function getServiceResponse($param)
 {
     $p = $this->getParameters($param);
     switch ($_REQUEST['bwsp_service']) {
         case 'getModelsIdByUniprotId':
             $this->rawResponse = $this->getModelsIdByUniprotId($p['uniprotId']);
             return true;
             break;
         case 'getModelByID':
             $this->rawResponse = $this->getModelByID($p['id']);
             return true;
             break;
     }
     $this->jsonResponse = xml2json::transformXmlStringToJson($this->rawResponse);
 }
Beispiel #13
0
<?php

$xml_file_path = 'vnstat.xml';
if (file_exists($xml_file_path)) {
    $xml = simplexml_load_file($xml_file_path);
    require_once 'lib/xml2json.php';
    if ($xml_as_array = xml2json::convertSimpleXmlElementObjectIntoArray($xml)) {
        if ($json = json_encode($xml_as_array)) {
            header('Content-type: application/json');
            echo $json;
        } else {
            exit("Could not convert array to JSON.");
        }
    } else {
        exit("Could not convert XML to array for conversion to JSON.");
    }
} else {
    exit("Failed to load {$xml_file_path}.");
}
    $url .= "&Operation=ItemSearch";
    $url .= "&AWSAccessKeyId=" . $amazonAWSAccessKeyId;
    $url .= "&AssociateTag=" . $amazonAssociateTag;
    $url .= "&ResponseGroup=Medium";
    $url .= "&SearchIndex=" . $q_search;
    if ($q_type) {
        $url .= "&IdType=" . $q_type;
        $url .= "&ItemId=" . $q_item;
        $url .= "&Keywords=" . urlencode($q_item);
    } else {
        $url .= "&Keywords=" . urlencode($q_item);
    }
    // sign
    $url = amazonSign($url, $amazonSecretAccessKey);
    // fetch the response and parse the results
    $curl_handle = curl_init();
    curl_setopt($curl_handle, CURLOPT_URL, $url);
    curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
    curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
    $data = curl_exec($curl_handle);
    if ($q_output == "raw" || $q_output == null) {
        header("Content-Type:text/xml");
        echo $data;
    } elseif ($q_output == "xml") {
        header("Content-Type:text/xml");
        echo amazonItemPrint($data, $q_num);
    } elseif ($q_output == "json") {
        header("Content-Type:application/json");
        echo xml2json::transformXmlStringToJson(amazonItemPrint($data, $q_num));
    }
}
 public static function convertSimpleXmlElementObjectIntoArray($simpleXmlElementObject, &$recursionDepth = 0)
 {
     // Keep an eye on how deeply we are involved in recursion.
     if ($recursionDepth > MAX_RECURSION_DEPTH_ALLOWED) {
         // Fatal error. Exit now.
         return null;
     }
     if ($recursionDepth == 0) {
         if (get_class($simpleXmlElementObject) != SIMPLE_XML_ELEMENT_PHP_CLASS) {
             // If the external caller doesn't call this function initially
             // with a SimpleXMLElement object, return now.
             return null;
         } else {
             // Store the original SimpleXmlElementObject sent by the caller.
             // We will need it at the very end when we return from here for good.
             $callerProvidedSimpleXmlElementObject = $simpleXmlElementObject;
         }
     }
     // End of if ($recursionDepth == 0) {
     if (is_object($simpleXmlElementObject) && get_class($simpleXmlElementObject) == SIMPLE_XML_ELEMENT_PHP_CLASS) {
         // Get a copy of the simpleXmlElementObject
         $copyOfsimpleXmlElementObject = $simpleXmlElementObject;
     }
     // It needs to be an array of object variables.
     if ($simpleXmlElementObject->count() > 0) {
         // Initialize the result array.
         $resultArray = array();
         //Add the attributes if any
         //Now add the attributes
         foreach ($simpleXmlElementObject->attributes() as $key => $value) {
             $resultArray[SIMPLE_XML_ELEMENT_OBJECT_PROPERTY_FOR_ATTRIBUTES][$key] = trim(strval($value));
         }
         // Let us walk through the child elements now.
         foreach ($simpleXmlElementObject->children() as $child) {
             // When this block of code is commented, XML attributes will be
             // added to the result array.
             // Uncomment the following block of code if XML attributes are
             // NOT required to be returned as part of the result array.
             /*
             if((is_string($key)) && ($key == SIMPLE_XML_ELEMENT_OBJECT_PROPERTY_FOR_ATTRIBUTES)) {
                 continue;
             }
             */
             // Let us recursively process the current element we just visited.
             // Increase the recursion depth by one.
             $recursionDepth++;
             //Group children with the same name
             if (isset($resultArray[$child->getName()])) {
                 //If it is array apppend
                 if (is_array($resultArray[$child->getName()]) && !isset($resultArray[$child->getName()][SIMPLE_XML_ELEMENT_OBJECT_PROPERTY_FOR_TXT_VALUE])) {
                     //If it contains @value then is not really an array
                     $resultArray[$child->getName()][] = xml2json::convertSimpleXmlElementObjectIntoArray($child, $recursionDepth);
                 } else {
                     //else convert and append
                     $resultArray[$child->getName()] = array(0 => $resultArray[$child->getName()]);
                     $resultArray[$child->getName()][] = xml2json::convertSimpleXmlElementObjectIntoArray($child, $recursionDepth);
                 }
             } else {
                 $resultArray[$child->getName()] = xml2json::convertSimpleXmlElementObjectIntoArray($child, $recursionDepth);
             }
             // Decrease the recursion depth by one.
             $recursionDepth--;
         }
         // End of foreach($simpleXmlElementObject as $key=>$value) {
         if ($recursionDepth == 0) {
             // That is it. We are heading to the exit now.
             // Set the XML root element name as the root [top-level] key of
             // the associative array that we are going to return to the caller of this
             // recursive function.
             $tempArray = $resultArray;
             $resultArray = array();
             $resultArray[$callerProvidedSimpleXmlElementObject->getName()] = $tempArray;
         }
         return $resultArray;
     } else {
         // We are now looking at either the XML attribute text or
         // the text between the XML tags.
         //Check for attributes, it it has attritubes return an @array containing @atrtibutes and @value
         if (count($simpleXmlElementObject->attributes()) > 0) {
             $r_array = array();
             foreach ($simpleXmlElementObject->attributes() as $key => $value) {
                 $r_array[SIMPLE_XML_ELEMENT_OBJECT_PROPERTY_FOR_ATTRIBUTES][$key] = trim(strval($value));
             }
             $r_array[SIMPLE_XML_ELEMENT_OBJECT_PROPERTY_FOR_TXT_VALUE] = trim(strval($simpleXmlElementObject));
             return $r_array;
         } else {
             //Else return the value
             return trim(strval($simpleXmlElementObject));
         }
     }
     // End of else
 }