Esempio n. 1
0
 private function toXml($array, $xml = false)
 {
     $simxml = new simpleXMLElement('<!--?xml version="1.0" encoding="utf-8"?--><root></root>');
     foreach ($array as $k => $v) {
         $simxml->addChild($k, $v);
     }
     return $simxml->saveXML();
 }
Esempio n. 2
0
File: xml.php Progetto: swk/bluebox
 /**
  * Converts a simpleXML element into an array. Preserves attributes and everything.
  * You can choose to get your elements either flattened, or stored in a custom index that
  * you define.
  * For example, for a given element
  * <field name="someName" type="someType"/>
  * if you choose to flatten attributes, you would get:
  * $array['field']['name'] = 'someName';
  * $array['field']['type'] = 'someType';
  * If you choose not to flatten, you get:
  * $array['field']['@attributes']['name'] = 'someName';
  * _____________________________________
  * Repeating fields are stored in indexed arrays. so for a markup such as:
  * <parent>
  * <child>a</child>
  * <child>b</child>
  * <child>c</child>
  * </parent>
  * you array would be:
  * $array['parent']['child'][0] = 'a';
  * $array['parent']['child'][1] = 'b';
  * ...And so on.
  * _____________________________________
  * @param simpleXMLElement $xml the XML to convert
  * @param boolean $flattenValues    Choose wether to flatten values
  *                                    or to set them under a particular index.
  *                                    defaults to true;
  * @param boolean $flattenAttributes Choose wether to flatten attributes
  *                                    or to set them under a particular index.
  *                                    Defaults to true;
  * @param boolean $flattenChildren    Choose wether to flatten children
  *                                    or to set them under a particular index.
  *                                    Defaults to true;
  * @param string $valueKey            index for values, in case $flattenValues was set to
  *                            false. Defaults to "@value"
  * @param string $attributesKey        index for attributes, in case $flattenAttributes was set to
  *                            false. Defaults to "@attributes"
  * @param string $childrenKey        index for children, in case $flattenChildren was set to
  *                            false. Defaults to "@children"
  * @return array the resulting array.
  */
 public static function simpleXMLToArray($xml, $flattenValues = true, $flattenAttributes = true, $flattenChildren = true, $valueKey = '@value', $attributesKey = '@attributes', $childrenKey = '@children')
 {
     $return = array();
     if (!$xml instanceof SimpleXMLElement) {
         return $return;
     }
     $name = $xml->getName();
     $_value = trim((string) $xml);
     if (strlen($_value) == 0) {
         $_value = null;
     }
     if ($_value !== null) {
         if (!$flattenValues) {
             $return[$valueKey] = $_value;
         } else {
             $return = $_value;
         }
     }
     $children = array();
     $first = true;
     foreach ($xml->children() as $elementName => $child) {
         $value = self::simpleXMLToArray($child, $flattenValues, $flattenAttributes, $flattenChildren, $valueKey, $attributesKey, $childrenKey);
         if (isset($children[$elementName])) {
             if ($first) {
                 $temp = $children[$elementName];
                 unset($children[$elementName]);
                 $children[$elementName][] = $temp;
                 $first = false;
             }
             $children[$elementName][] = $value;
         } else {
             $children[$elementName] = $value;
         }
     }
     if (count($children) > 0) {
         if (!$flattenChildren) {
             $return[$childrenKey] = $children;
         } else {
             $return = array_merge($return, $children);
         }
     }
     $attributes = array();
     foreach ($xml->attributes() as $name => $value) {
         $attributes[$name] = trim($value);
     }
     if (count($attributes) > 0) {
         if (!$flattenAttributes) {
             $return[$attributesKey] = $attributes;
         } else {
             $return = array_merge($return, $attributes);
         }
     }
     if (count($return) == 0) {
         return '';
     }
     return $return;
 }
Esempio n. 3
0
function parse_math_tag($convoArr, simpleXMLElement $element, $parentName, $level)
{
    $response = array();
    $children = $element->children();
    if (!empty($children)) {
        foreach ($children as $child) {
            $response[] = parseTemplateRecursive($convoArr, $child, $level + 1);
        }
    } else {
        $response[] = (string) $element;
    }
    $response_string = implode_recursive(' ', $response);
    // do something here
    runDebug(__FILE__, __FUNCTION__, __LINE__, "String to process: {$response_string}", 4);
    list($operator, $operand1, $operand2) = explode(' ', $response_string, 3);
    $operatorArray = array('ADD', 'SUBTRACT', 'MULTIPLY', 'DIVIDE');
    switch (true) {
        case !in_array(strtoupper($operator), $operatorArray):
            return 'Invalid math function!';
            break;
        case !is_numeric($operand1):
            return "{$operand1} is not a number!";
            break;
        case !is_numeric($operand2):
            return "{$operand2} is not a number!";
            break;
    }
    switch ($operator) {
        case 'ADD':
            $out = $operand1 + $operand2;
            break;
        case 'SUBTRACT':
            $out = $operand1 - $operand2;
            break;
        case 'MULTIPLY':
            $out = $operand1 * $operand2;
            break;
        case 'DIVIDE':
            $out = $operand1 / $operand2;
            break;
    }
    return $out;
}
Esempio n. 4
0
 /**
  * Return the contents of MARC data fields as an array
  *
  * @param simpleXMLElement $xml        MARC Record
  * @param string           $fieldspecs Fields and subfields (e.g. '100a:700a')
  * @param string           $glue       Delimiter used between subfields
  *
  * @return array
  */
 protected function getMultipleValues($xml, $fieldspecs, $glue = '')
 {
     $values = [];
     foreach (explode(':', $fieldspecs) as $fieldspec) {
         $field = substr($fieldspec, 0, 3);
         $subfields = substr($fieldspec, 3);
         $xpath = "./m:datafield[@tag='{$field}']";
         $res = $xml->xpath($xpath);
         foreach ($res as $datafield) {
             $strings = [];
             foreach ($datafield->subfield as $subfield) {
                 if (strstr($subfields, (string) $subfield['code'])) {
                     $strings[] .= (string) $subfield;
                 }
             }
             if ($strings) {
                 $values[] = implode($glue, $strings);
             }
         }
     }
     return $values;
 }
Esempio n. 5
0
 /**
  * Import email language
  *
  * @param string $source
  * @param string $path
  * @return bool
  */
 public function importEmail($source, $path = CC_LANGUAGE_DIR)
 {
     //Make sure the path is valid
     if (!$this->_checkPath($path)) {
         trigger_error('Invalid language path ' . $path, E_USER_ERROR);
     }
     //Check to see if the path is the current language directory
     if ($path !== CC_LANGUAGE_DIR) {
         $path = appendDS($path);
     }
     if (!empty($source) && preg_match(self::EMAIL_FILE, $source, $match)) {
         $file = $path . $source;
         if (file_exists($file)) {
             //Get the file data
             $data = file_get_contents($file);
             if (($gz = @gzuncompress($data)) !== false) {
                 $data = $gz;
                 unset($gz);
             }
             try {
                 $xml = new simpleXMLElement($data);
                 if ($xml->email) {
                     foreach ($xml->email as $email) {
                         if ($email->content) {
                             $record['content_type'] = (string) $email->attributes()->name;
                             $record['language'] = (string) $xml->attributes()->language;
                             $record['subject'] = (string) $email->subject;
                             foreach ($email->content as $content) {
                                 $record['content_' . (string) $content->attributes()->type] = trim((string) $content);
                             }
                             if ($GLOBALS['db']->count('CubeCart_email_content', 'content_id', array('language' => $record['language'], 'content_type' => $record['content_type']))) {
                                 $GLOBALS['db']->update('CubeCart_email_content', $record, array('language' => $record['language'], 'content_type' => $record['content_type']));
                             } else {
                                 $GLOBALS['db']->insert('CubeCart_email_content', $record);
                             }
                         }
                         unset($record);
                     }
                     return true;
                 }
             } catch (Exception $e) {
                 return false;
             }
         }
     }
     return false;
 }
Esempio n. 6
0
         $agent->callModifyDatastreamByValue($val, $dcID, 'A', $dcLabel, $dc);
     }
     $htmlFinal .= "<h1> Added </h1>Datafield '" . $datafieldtag . "'<h1>for Objects</h1>";
 } else {
     if ($_POST['function_type'] == "Delete") {
         // print_r($GLOBALS);
         $deleteDataField = $_POST['dataFieldtag'];
         foreach ($fields as $key => $val) {
             $xml_MARC = get_Datastream($val, $marcID);
             $xml_output_dc = get_Datastream($val, $dcID);
             $handle = retrieveHandle($xml_output_dc, $dictionary['HandleNamespace']);
             $marcxml = deleteNode($xml_MARC, $deleteDataField);
             $agent = new Agent();
             $dc_temp = $agent->transform2("./stylesheets/dc.xslt", $marcxml);
             //append identifiers information into DC i.e Handles (namespace:port and pid extracted from Val) and Pid = val
             $xmlDC = new simpleXMLElement($dc_temp);
             $namespace = $xmlDC->getNamespaces(true);
             $split = explode(":", $val);
             // $handle=$dictionary['HandleNamespace'].$split[1];
             $xmlDC->addChild('dc:identifier', $val, $namespace['dc']);
             $xmlDC->addChild('dc:identifier', $handle, $namespace['dc']);
             $dc = $xmlDC->saveXML();
             $marc = $marcxml->saveXML();
             $myFile1 = base64_encode(trim($marc));
             $myFile2 = base64_encode(trim($dc));
             $agent->callModifyDatastreamByValue($val, $marcID, 'I', $marcLabel, $marc);
             $agent->callModifyDatastreamByValue($val, $dcID, 'A', $dcLabel, $dc);
         }
         $htmlFinal .= "<h1> Deleted all Occurances of </h1>Datafield  '" . $deleteDataField . "' <h1> for Objects</h1>";
     } else {
         $htmlFinal .= "Please select a functionality before proceeding !";
 public function Save()
 {
     $this->xml->asXML($this->configurationFilePath);
 }
$STDIN = fopen('/dev/null', 'r');
$STDOUT = fopen(dirname(__FILE__) . "/application.log", 'a+');
$STDERR = fopen(dirname(__FILE__) . "/../error.log", 'a+');
$keys = new keys();
$yesterday = date("Y-m-d", strtotime("yesterday"));
$current_time = date("Y-m-d H:i:s", time());
printf("\n%s\n", $yesterday);
$dbconnection = new mysqlconnect();
$dbconnection->connect($dbName);
$mysqli = $dbconnection->connection;
$merchantid = $keys::almerchantid;
$authkey = $keys::alauthkey;
$module = 'MerchantReport';
$reportid = '12';
$report = get_report($authkey, $merchantid, $module, $reportid, $yesterday);
$xml = new simpleXMLElement($report);
$rowcount = count($xml->children());
//print_r($xml->Table1[2]->Sales);
$query = "insert into al_accountstats(accountdate, impressions, clicks, alsales, convertedsales, mobilesales, mobileconversions, commissions, incentives,\n\tnetworkcommissions, adj, newcustomers, newcustomersales, cpcfees, networkcpcfees, totalcommissions) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) on duplicate key update \n\taccountdate=values(accountdate), impressions=values(impressions), clicks=values(clicks), alsales=values(alsales), convertedsales=values(convertedsales), mobilesales=values(mobilesales),\n\tmobileconversions=values(mobileconversions), commissions=values(commissions), incentives=values(incentives), networkcommissions=values(networkcommissions), adj=values(adj),\n\tnewcustomers=values(newcustomers), newcustomersales=values(newcustomersales), cpcfees=values(cpcfees), networkcpcfees=values(networkcpcfees), totalcommissions=values(totalcommissions)";
$stmt = $mysqli->prepare($query);
$stmt->bind_param("siidididddiidddd", $accountdate, $impressions, $clicks, $alsales, $convertedsales, $mobilesales, $mobileconversions, $commissions, $incentives, $networkcommissions, $adj, $newcustomers, $newscustomersales, $cpcfees, $networkcpcfees, $totalcommissions);
$mysqli->query("start");
for ($i = 0; $i < $rowcount; ++$i) {
    $row = $xml->Table1[$i];
    $date = strtotime($row->Date);
    $accountdate = date('Y-m-d', $date);
    $impressions = (int) str_replace(',', '', $row->Ad_Impressions);
    $clicks = (int) str_replace(',', '', $row->Click_Throughs);
    $alsales = floatval(str_replace(array(',', '$'), '', $row->Sales));
    $convertedsales = $row->Number_of_Sales;
    $mobilesales = floatval(str_replace(array(',', '$'), '', $row->Mobile_Sales));
Esempio n. 9
0
 /**
  * Extends to allow chaining of add attribute
  *
  * e.g. $xml->addAttribute('size', 'large')->addAttribute('color', 'blue')
  */
 public function addAttribute($name, $value = NULL, $namespace = NULL)
 {
     parent::addAttribute($name, $value, $namespace);
     // switch (func_num_args()) {
     //   case 1:
     //     parent::addAttribute($name);
     //     break;
     //   case 2:
     //     parent::addAttribute($name, $value);
     //     break;
     //   case 3:
     //     parent::addAttribute($name, $value, $namespace);
     //     break;
     // }
     return $this;
 }
Esempio n. 10
0
 /**
  * Convert XML to array for bX recommendations
  *
  * @param \simpleXMLElement $xml XML to convert
  * @param string            $ns  Optional namespace for nodes
  *
  * @return array
  */
 protected function convertToArray($xml, $ns = '')
 {
     $result = [];
     foreach ($xml->children($ns) as $node) {
         $children = $node->children($ns);
         if (count($children) > 0) {
             $item = $this->convertToArray($node, $ns);
         } else {
             $item = (string) $node;
         }
         $key = $node->getName();
         if (isset($result[$key])) {
             if (!is_array($result[$key])) {
                 $result[$key] = [$result[$key]];
             }
             $result[$key][] = $item;
         } else {
             $result[$key] = $item;
         }
     }
     return $result;
 }
Esempio n. 11
0
function testPostNewSalesInvoiceXml()
{
    echo "Starting test: testPostNewSalesInvoiceXml" . "<br />";
    echo "-------------------------------------------------------------------------------------<br />";
    echo "POST new sales invoice in XML format:" . "<br />";
    $guid = NewGuid();
    echo "New GUID = {$guid}";
    echo "<br />";
    $date = date('Y-m-d');
    $taxRate = 0.15;
    $taxCode = "G.S.T.";
    // creating an xml object in PHP:
    $invoice = new simpleXMLElement('<SalesInvoice />');
    // set all the properties of the sales invoice
    // use simple xml, not stdClass
    $invoice->Guid = "{$guid}";
    $invoice->OrderNumber = substr($guid, 0, 15);
    $invoice->OrderDate = $date;
    $invoice->RequiredDate = $date;
    $invoice->OrderStatus = "Parked";
    $invoice->Customer->CustomerCode = "ACE001";
    $invoice->Currency->CurrencyCode = "NZD";
    $invoice->Warehouse->WarehouseCode = "W1";
    $invoice->Tax->TaxCode = $taxCode;
    $lines = $invoice->addChild('SalesOrderLines');
    addSalesInvoiceLineXml($lines, 1, 'ANIMAL', 5, 10, $taxRate);
    addSalesInvoiceLineXml($lines, 2, 'BISCUIT', 10, 2, $taxRate);
    addSalesInvoiceLineXml($lines, 3, 'CANDY', 1, 25, $taxRate);
    $invoice->SubTotal = 95.0;
    $invoice->TaxTotal = 14.25;
    $invoice->Total = 109.25;
    echo "Input data:" . "<br />";
    echo htmlentities($invoice->asXML());
    echo "<br />";
    echo "Input id:" . "<br />";
    echo $invoice->Guid;
    echo "<br />";
    echo "<br />";
    $xmlPost = postSalesInvoice($invoice, "xml", $invoice->Guid);
    echo "Output data:" . "<br />";
    echo htmlentities($xmlPost->asXML());
}
Esempio n. 12
0
<?php

$xml_element = new simpleXMLElement('<root></root>');
$xml_element->node1 = 'a &#38; b';
print $xml_element->node1 . "\n";
$xml_element->node1 = 'a &#38; b';
print $xml_element->node1 . "\n";
$xml_element->addChild('node2', 'a &#38; b');
print $xml_element->node2 . "\n";
$xml_element->node2 = 'a & b';
print $xml_element->node2 . "\n";
print $xml_element->asXML();
?>
===DONE===
Esempio n. 13
0
$moros = 0;
$phoenix = 0;
$revelation = 0;
$naglfar = 0;
// Fetch Stations
$conqStationIdArray = array();
$conqStationNameArray = array();
$conqstListURL = "https://api.eveonline.com/eve/ConquerableStationList.xml.aspx";
$conqstListXml = new simpleXMLElement($conqstListURL, NULL, TRUE);
foreach ($conqstListXml->result->rowset->row as $row) {
    array_push($conqStationIdArray, $row['stationID']);
    array_push($conqStationNameArray, $row['stationName']);
}
// Fetch Assets
$assetListURL = "http://api.eveonline.com/corp/AssetList.xml.aspx?keyID=" . $corpKeyID . "&vCode=" . $corpVcode;
$assetListXml = new simpleXMLElement($assetListURL, NULL, TRUE);
$doc = new DOMDocument('1.0');
$doc->preserveWhiteSpace = false;
$doc->formatOutput = true;
$doc->loadXML($assetListXml->asXML());
$doc->save("/xml/AssetList.xml");
echo "<h3>" . $assetListXml->currentTime . " ETC</h3>";
echo "<table cellspacing='5' cellpadding='5' border='1' align='center'>";
echo "<tr>";
echo "<td><b>Icon</b></td>";
echo "<td><b>Asset Name</b></td>";
echo "<td><b>Asset ID</b></td>";
echo "<td><b>Asset Location ID</b></td>";
echo "<td><b>Asset Location Name</b></td>";
echo "</tr>";
foreach ($assetListXml->result->rowset->row as $row) {
 *
 * @package   mod_collaborate
 * @copyright Copyright (c) 2015 Moodlerooms Inc. (http://www.moodlerooms.com)
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
define('CLI_SCRIPT', true);
require __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '../../../config.php';
$wsdl = 'http://testing.dev/apollo.xml?wsdl';
$outputdir = __DIR__ . '/classes/soap/generated';
// Pull complex types out of wsdl which contain 'html' (apollo api methods).
$wsdlcontents = file_get_contents($wsdl);
if (!$wsdlcontents) {
    die('Failed to load wsdl ' . $wsdl);
}
$wsdlxe = new simpleXMLElement($wsdlcontents);
// Remove doc elements (causing issues with wsdl parser).
$docels = $wsdlxe->xpath('//wsdl:documentation');
$docelsarr = [];
foreach ($docels as $docel) {
    $docelsarr[] = $docel;
}
foreach ($docelsarr as $docel) {
    unset($docel[0]);
}
// Create local wsdl.
$wsdlxe->asXML(__DIR__ . '/wsdl.xml');
$whitelist = ['Html', 'Apollo', 'UrlResponse', 'ServerConfiguration', 'Success'];
$htmlels = $wsdlxe->xpath('//xs:complexType | //xs:element');
$soapclasses = ['SASDefaultAdapter'];
foreach ($htmlels as $htmlel) {
Esempio n. 15
0
 /**
  * @param simpleXMLElement $xml_obj
  */
 private function _processXML($xml_obj)
 {
     $xml = $xml_obj->xpath('/datasets');
     $datasets = $xml;
     //process each layout
     foreach ($datasets as $dataset) {
         /**
          * @var SimpleXMLElement $dataset
          */
         $dataset = $dataset->dataset;
         /* Determine an action tag in all parent elements. 
          * Action can be insert, update and delete		       
          *   ->>> action = insert
          *		Mean that we will try create new dataset with column definitions and insert rows in it  
          *  ->>> action = update (default)
          *		Before loading the dataset, determine if same dataset exists with same name and key combination.
          *		If does exists, write new over existing
          *  ->>> action = delete
          *		Delete all that contains in dataset (values, definitions, properties and dataset)					
          *		NOTE: Parent level delete action is cascaded to all children elements
          */
         if (!$dataset->action) {
             $dataset->action = 'update';
         }
         if (in_array($dataset->action, array("update", "delete"))) {
             $this->__construct($dataset->dataset_name, $dataset->dataset_key);
             $this->dropDataset();
             if ($dataset->action == "delete") {
                 continue;
             }
         }
         if (in_array($dataset->action, array("insert", "update"))) {
             if ($dataset->dataset_name) {
                 $this->__construct($dataset->dataset_name, $dataset->dataset_key);
                 $this->createDataset($dataset->dataset_name, $dataset->dataset_key);
             }
         }
         // check creating
         if (!$this->dataset_id) {
             continue;
         }
         // set dataset definition if needed
         if ($dataset->dataset_definition && $dataset->dataset_definition->column_definition) {
             $definitions = array();
             $i = 0;
             foreach ($dataset->dataset_definition->column_definition as $column_definition) {
                 $definitions[$i]['name'] = (string) $column_definition->column_name;
                 $definitions[$i]['type'] = (string) $column_definition->column_type;
                 if ((int) $column_definition->column_sort_order) {
                     $definitions[$i]['sort_order'] = (int) $column_definition->column_sort_order;
                 }
                 $i++;
             }
             $this->defineColumns($definitions);
         }
         // set dataset properties if needed
         if ($dataset->dataset_properties && $dataset->dataset_properties->dataset_property) {
             $properties = array();
             foreach ($dataset->dataset_properties->dataset_property as $property) {
                 $properties[(string) $property->dataset_property_name] = (string) $property->dataset_property_value;
             }
             $this->setDatasetProperties($properties);
         }
         // set column properties if needed
         if ($dataset->column_properties && $dataset->column_properties->column_property) {
             $properties = array();
             foreach ($dataset->column_properties->column_property as $property) {
                 $properties[(string) $property->column_property_name] = (string) $property->column_property_value;
                 $this->setColumnProperties((string) $property->column_name, $properties);
             }
         }
         // operate with dataset rows
         if ($dataset->dataset_rows && $dataset->dataset_rows->dataset_row) {
             $row_values = array();
             foreach ($dataset->dataset_rows->dataset_row as $row) {
                 if ($row->cell) {
                     foreach ($row->cell as $cell) {
                         $row_values[][(string) $cell->column_name] = (string) $cell->value;
                     }
                 }
             }
             $this->addRows($row_values);
         }
     }
     // end of loop
 }