Ejemplo n.º 1
0
 /**
  * create a tag from an array
  * this method awaits an array in the following format
  * <pre>
  * array(
  *  "qname"        => $qname         // qualified name of the tag
  *  "namespace"    => $namespace     // namespace prefix (optional, if qname is specified or no namespace)
  *  "localpart"    => $localpart,    // local part of the tagname (optional, if qname is specified)
  *  "attributes"   => array(),       // array containing all attributes (optional)
  *  "content"      => $content,      // tag content (optional)
  *  "namespaceUri" => $namespaceUri  // namespaceUri for the given namespace (optional)
  *   )
  * </pre>
  *
  * <code>
  * require_once 'XML/Util.php';
  * 
  * $tag = array(
  *           "qname"        => "foo:bar",
  *           "namespaceUri" => "http://foo.com",
  *           "attributes"   => array( "key" => "value", "argh" => "fruit&vegetable" ),
  *           "content"      => "I'm inside the tag",
  *            );
  * // creating a tag with qualified name and namespaceUri
  * $string = XML_Util::createTagFromArray($tag);
  * </code>
  *
  * @access   public
  * @static
  * @param    array   $tag               tag definition
  * @param    integer $replaceEntities   whether to replace XML special chars in content, embedd it in a CData section or none of both
  * @param    boolean $multiline         whether to create a multiline tag where each attribute gets written to a single line
  * @param    string  $indent            string used to indent attributes (_auto indents attributes so they start at the same column)
  * @param    string  $linebreak         string used for linebreaks
  * @return   string  $string            XML tag
  * @see      XML_Util::createTag()
  * @uses     XML_Util::attributesToString() to serialize the attributes of the tag
  * @uses     XML_Util::splitQualifiedName() to get local part and namespace of a qualified name
  */
 function createTagFromArray($tag, $replaceEntities = XML_UTIL_REPLACE_ENTITIES, $multiline = false, $indent = "_auto", $linebreak = "\n", $encoding = XML_UTIL_ENTITIES_XML)
 {
     if (isset($tag["content"]) && !is_scalar($tag["content"])) {
         return XML_Util::raiseError("Supplied non-scalar value as tag content", XML_UTIL_ERROR_NON_SCALAR_CONTENT);
     }
     if (!isset($tag['qname']) && !isset($tag['localPart'])) {
         return XML_Util::raiseError('You must either supply a qualified name (qname) or local tag name (localPart).', XML_UTIL_ERROR_NO_TAG_NAME);
     }
     // if no attributes hav been set, use empty attributes
     if (!isset($tag["attributes"]) || !is_array($tag["attributes"])) {
         $tag["attributes"] = array();
     }
     // qualified name is not given
     if (!isset($tag["qname"])) {
         // check for namespace
         if (isset($tag["namespace"]) && !empty($tag["namespace"])) {
             $tag["qname"] = $tag["namespace"] . ":" . $tag["localPart"];
         } else {
             $tag["qname"] = $tag["localPart"];
         }
         // namespace URI is set, but no namespace
     } elseif (isset($tag["namespaceUri"]) && !isset($tag["namespace"])) {
         $parts = XML_Util::splitQualifiedName($tag["qname"]);
         $tag["localPart"] = $parts["localPart"];
         if (isset($parts["namespace"])) {
             $tag["namespace"] = $parts["namespace"];
         }
     }
     if (isset($tag["namespaceUri"]) && !empty($tag["namespaceUri"])) {
         // is a namespace given
         if (isset($tag["namespace"]) && !empty($tag["namespace"])) {
             $tag["attributes"]["xmlns:" . $tag["namespace"]] = $tag["namespaceUri"];
         } else {
             // define this Uri as the default namespace
             $tag["attributes"]["xmlns"] = $tag["namespaceUri"];
         }
     }
     // check for multiline attributes
     if ($multiline === true) {
         if ($indent === "_auto") {
             $indent = str_repeat(" ", strlen($tag["qname"]) + 2);
         }
     }
     // create attribute list
     $attList = XML_Util::attributesToString($tag["attributes"], true, $multiline, $indent, $linebreak);
     if (!isset($tag["content"]) || (string) $tag["content"] == '') {
         $tag = sprintf("<%s%s />", $tag["qname"], $attList);
     } else {
         if ($replaceEntities == XML_UTIL_REPLACE_ENTITIES) {
             $tag["content"] = XML_Util::replaceEntities($tag["content"], $encoding);
         } elseif ($replaceEntities == XML_UTIL_CDATA_SECTION) {
             $tag["content"] = XML_Util::createCDataSection($tag["content"]);
         }
         $tag = sprintf("<%s%s>%s</%s>", $tag["qname"], $attList, $tag["content"], $tag["qname"]);
     }
     return $tag;
 }
Ejemplo n.º 2
0
print "creating a start element:<br>";
print "<pre>";
print htmlentities(XML_Util::createStartElement("myTag", array("foo" => "bar", "argh" => "tomato"), "http://www.w3c.org/myNs#", true));
print "</pre>";
print "\n<br><br>\n";
/**
 * creating an end element
 */
print "creating an end element:<br>";
print htmlentities(XML_Util::createEndElement("myNs:myTag"));
print "\n<br><br>\n";
/**
 * creating a CData section
 */
print "creating a CData section:<br>";
print htmlentities(XML_Util::createCDataSection("I am content."));
print "\n<br><br>\n";
/**
 * creating a comment
 */
print "creating a comment:<br>";
print htmlentities(XML_Util::createComment("I am a comment."));
print "\n<br><br>\n";
/**
 * creating an XML tag with multiline mode
 */
$tag = array("qname" => "foo:bar", "namespaceUri" => "http://foo.com", "attributes" => array("key" => "value", "argh" => "fruit&vegetable"), "content" => "I'm inside the tag & contain dangerous chars");
print "creating a tag with qualified name and namespaceUri:<br>\n";
print "<pre>";
print htmlentities(XML_Util::createTagFromArray($tag, XML_UTIL_REPLACE_ENTITIES, true));
print "</pre>";
Ejemplo n.º 3
0
 /**
  * create a tag from an array
  * this method awaits an array in the following format
  * <pre>
  * array(
  *     // qualified name of the tag
  *     'qname' => $qname        
  *
  *     // namespace prefix (optional, if qname is specified or no namespace)
  *     'namespace' => $namespace    
  *
  *     // local part of the tagname (optional, if qname is specified)
  *     'localpart' => $localpart,   
  *
  *     // array containing all attributes (optional)
  *     'attributes' => array(),      
  *
  *     // tag content (optional)
  *     'content' => $content,     
  *
  *     // namespaceUri for the given namespace (optional)
  *     'namespaceUri' => $namespaceUri 
  * )
  * </pre>
  *
  * <code>
  * require_once 'XML/Util.php';
  *
  * $tag = array(
  *     'qname'        => 'foo:bar',
  *     'namespaceUri' => 'http://foo.com',
  *     'attributes'   => array('key' => 'value', 'argh' => 'fruit&vegetable'),
  *     'content'      => 'I\'m inside the tag',
  * );
  * // creating a tag with qualified name and namespaceUri
  * $string = XML_Util::createTagFromArray($tag);
  * </code>
  *
  * @param array  $tag             tag definition
  * @param int    $replaceEntities whether to replace XML special chars in 
  *                                content, embedd it in a CData section 
  *                                or none of both
  * @param bool   $multiline       whether to create a multiline tag where each 
  *                                attribute gets written to a single line
  * @param string $indent          string used to indent attributes 
  *                                (_auto indents attributes so they start 
  *                                at the same column)
  * @param string $linebreak       string used for linebreaks
  * @param bool   $sortAttributes  Whether to sort the attributes or not
  *
  * @return string XML tag
  * @access public
  * @static
  * @see createTag()
  * @uses attributesToString() to serialize the attributes of the tag
  * @uses splitQualifiedName() to get local part and namespace of a qualified name
  * @uses createCDataSection()
  * @uses raiseError()
  */
 function createTagFromArray($tag, $replaceEntities = XML_UTIL_REPLACE_ENTITIES, $multiline = false, $indent = '_auto', $linebreak = "\n", $sortAttributes = true)
 {
     if (isset($tag['content']) && !is_scalar($tag['content'])) {
         return XML_Util::raiseError('Supplied non-scalar value as tag content', XML_UTIL_ERROR_NON_SCALAR_CONTENT);
     }
     if (!isset($tag['qname']) && !isset($tag['localPart'])) {
         return XML_Util::raiseError('You must either supply a qualified name ' . '(qname) or local tag name (localPart).', XML_UTIL_ERROR_NO_TAG_NAME);
     }
     // if no attributes hav been set, use empty attributes
     if (!isset($tag['attributes']) || !is_array($tag['attributes'])) {
         $tag['attributes'] = array();
     }
     if (isset($tag['namespaces'])) {
         foreach ($tag['namespaces'] as $ns => $uri) {
             $tag['attributes']['xmlns:' . $ns] = $uri;
         }
     }
     if (!isset($tag['qname'])) {
         // qualified name is not given
         // check for namespace
         if (isset($tag['namespace']) && !empty($tag['namespace'])) {
             $tag['qname'] = $tag['namespace'] . ':' . $tag['localPart'];
         } else {
             $tag['qname'] = $tag['localPart'];
         }
     } elseif (isset($tag['namespaceUri']) && !isset($tag['namespace'])) {
         // namespace URI is set, but no namespace
         $parts = XML_Util::splitQualifiedName($tag['qname']);
         $tag['localPart'] = $parts['localPart'];
         if (isset($parts['namespace'])) {
             $tag['namespace'] = $parts['namespace'];
         }
     }
     if (isset($tag['namespaceUri']) && !empty($tag['namespaceUri'])) {
         // is a namespace given
         if (isset($tag['namespace']) && !empty($tag['namespace'])) {
             $tag['attributes']['xmlns:' . $tag['namespace']] = $tag['namespaceUri'];
         } else {
             // define this Uri as the default namespace
             $tag['attributes']['xmlns'] = $tag['namespaceUri'];
         }
     }
     // check for multiline attributes
     if ($multiline === true) {
         if ($indent === '_auto') {
             $indent = str_repeat(' ', strlen($tag['qname']) + 2);
         }
     }
     // create attribute list
     $attList = XML_Util::attributesToString($tag['attributes'], $sortAttributes, $multiline, $indent, $linebreak, $replaceEntities);
     if (!isset($tag['content']) || (string) $tag['content'] == '') {
         $tag = sprintf('<%s%s />', $tag['qname'], $attList);
     } else {
         switch ($replaceEntities) {
             case XML_UTIL_ENTITIES_NONE:
                 break;
             case XML_UTIL_CDATA_SECTION:
                 $tag['content'] = XML_Util::createCDataSection($tag['content']);
                 break;
             default:
                 $tag['content'] = XML_Util::replaceEntities($tag['content'], $replaceEntities);
                 break;
         }
         $tag = sprintf('<%s%s>%s</%s>', $tag['qname'], $attList, $tag['content'], $tag['qname']);
     }
     return $tag;
 }
Ejemplo n.º 4
0
 /**
  * Prepare the PUT query xml.
  *
  * @access private
  * @return string The query xml
  */
 function _prepareQueryString()
 {
     $data = array_merge($this->_options, $this->_data);
     $doc = XML_Util::getXMLDeclaration();
     $doc .= '<!DOCTYPE paymentService PUBLIC "-//Bibit//DTD Bibit PaymentService v1//EN" "http://dtd.bibit.com/paymentService_v1.dtd">';
     $doc .= XML_Util::createStartElement('paymentService', array('version' => $data['x_version'], 'merchantCode' => $data['x_login']));
     if ($data['x_action'] == PAYMENT_PROCESS_ACTION_BIBIT_CAPTURE || $data['x_action'] == PAYMENT_PROCESS_ACTION_BIBIT_REFUND) {
         $doc .= XML_Util::createStartElement('modify');
         $doc .= XML_Util::createStartElement('orderModification', array('orderCode' => $data['x_ordercode']));
         if ($data['x_action'] == PAYMENT_PROCESS_ACTION_BIBIT_CAPTURE) {
             $doc .= XML_Util::createStartElement('capture');
             $d = array();
             $t = time() - 86400;
             $d['dayOfMonth'] = date('d', $t);
             $d['month'] = date('m', $t);
             $d['year'] = date('Y', $t);
             $d['hour'] = date('H', $t);
             $d['minute'] = date('i', $t);
             $d['second'] = date('s', $t);
             $doc .= XML_Util::createTag('date', $d);
             $doc .= XML_Util::createTag('amount', array('value' => $data['x_amount'], 'currencyCode' => $data['x_currency'], 'exponent' => $data['x_exponent']));
             $doc .= XML_Util::createEndElement('capture');
         } else {
             if ($data['x_action'] == PAYMENT_PROCESS_ACTION_BIBIT_REFUND) {
                 $doc .= XML_Util::createStartElement('refund');
                 $doc .= XML_Util::createTag('amount', array('value' => $data['x_amount'], 'currencyCode' => $data['x_currency'], 'exponent' => $data['x_exponent']));
                 $doc .= XML_Util::createEndElement('refund');
             }
         }
         $doc .= XML_Util::createEndElement('orderModification');
         $doc .= XML_Util::createEndElement('modify');
     } else {
         $doc .= XML_Util::createStartElement('submit');
         $doc .= XML_Util::createStartElement('order', array('orderCode' => $data['x_ordercode']));
         $doc .= XML_Util::createTag('description', null, $data['x_descr']);
         $doc .= XML_Util::createTag('amount', array('value' => $data['x_amount'], 'currencyCode' => $data['x_currency'], 'exponent' => $data['x_exponent']));
         if (isset($data['x_ordercontent'])) {
             $doc .= XML_Util::createStartElement('orderContent');
             $doc .= XML_Util::createCDataSection($data['x_ordercontent']);
             $doc .= XML_Util::createEndElement('orderContent');
         }
         if ($data['x_action'] == PAYMENT_PROCESS_ACTION_BIBIT_REDIRECT) {
             if (is_array($data['paymentMethodMask']) && count($data['paymentMethodMask'] > 0)) {
                 $doc .= XML_Util::createStartElement('paymentMethodMask');
                 foreach ($data['paymentMethodMask']['include'] as $code) {
                     $doc .= XML_Util::createTag('include', array('code' => $code));
                 }
                 foreach ($data['paymentMethodMask']['exclude'] as $code) {
                     $doc .= XML_Util::createTag('exclude', array('code' => $code));
                 }
                 $doc .= XML_Util::createEndElement('paymentMethodMask');
             }
         } else {
             if ($data['x_action'] == PAYMENT_PROCESS_ACTION_BIBIT_AUTH) {
                 $doc .= XML_Util::createStartElement('paymentDetails');
                 switch ($this->_payment->type) {
                     case PAYMENT_PROCESS_CC_VISA:
                         $cc_type = 'VISA-SSL';
                         break;
                     case PAYMENT_PROCESS_CC_MASTERCARD:
                         $cc_type = 'ECMC-SSL';
                         break;
                     case PAYMENT_PROCESS_CC_AMEX:
                         $cc_type = 'AMEX-SSL';
                         break;
                 }
                 $doc .= XML_Util::createStartElement($cc_type);
                 if (isset($data['x_card_num'])) {
                     $doc .= XML_Util::createTag('cardNumber', null, $data['x_card_num']);
                 }
                 if (isset($data['x_exp_date'])) {
                     $doc .= XML_Util::createStartElement('expiryDate');
                     $doc .= XML_Util::createTag('date', array('month' => substr($data['x_exp_date'], 0, 2), 'year' => substr($data['x_exp_date'], 3, 4)));
                     $doc .= XML_Util::createEndElement('expiryDate');
                 }
                 if (isset($this->_payment->firstName) && isset($this->_payment->lastName)) {
                     $doc .= XML_Util::createTag('cardHolderName', null, $this->_payment->firstName . ' ' . $this->_payment->lastName);
                 }
                 if (isset($data['x_card_code'])) {
                     $doc .= XML_Util::createTag('cvc', null, $data['x_card_code']);
                 }
                 $doc .= XML_Util::createEndElement($cc_type);
                 if ((isset($data['shopperIPAddress']) || isset($data['sessionId'])) && ($data['shopperIPAddress'] != '' || $data['sessionId'] != '')) {
                     $t = array();
                     if ($data['shopperIPAddress'] != '') {
                         $t['shopperIPAddress'] = $data['shopperIPAddress'];
                     }
                     if ($data['sessionId'] != '') {
                         $t['id'] = $data['sessionId'];
                     }
                     $doc .= XML_Util::createTag('session', $t);
                     unset($t);
                 }
                 $doc .= XML_Util::createEndElement('paymentDetails');
             }
         }
         if (isset($data['shopperEmailAddress']) && $data['shopperEmailAddress'] != '' || isset($data['authenticatedShopperID']) && $data['authenticatedShopperID'] != '') {
             $doc .= XML_Util::createStartElement('shopper');
             if ($data['shopperEmailAddress'] != '') {
                 $doc .= XML_Util::createTag('shopperEmailAddress', null, $data['shopperEmailAddress']);
             }
             if ($data['authenticatedShopperID'] != '') {
                 $doc .= XML_Util::createTag('authenticatedShopperID', null, $data['authenticatedShopperID']);
             }
             $doc .= XML_Util::createEndElement('shopper');
         }
         if (is_array($data['shippingAddress']) && count($data['shippingAddress']) > 0) {
             $a = $data['shippingAddress'];
             $doc .= XML_Util::createStartElement('shippingAddress');
             $doc .= XML_Util::createStartElement('address');
             $fields = array('firstName', 'lastName', 'street', 'houseName', 'houseNumber', 'houseNumberExtension', 'postalCode', 'city', 'state', 'countryCode', 'telephoneNumber');
             foreach ($fields as $field) {
                 if (isset($a[$field])) {
                     $doc .= XML_Util::createTag($field, null, $a[$field]);
                 }
             }
             $doc .= XML_Util::createEndElement('address');
             $doc .= XML_Util::createEndElement('shippingAddress');
         }
         $doc .= XML_Util::createEndElement('order');
         $doc .= XML_Util::createEndElement('submit');
     }
     $doc .= XML_Util::createEndElement('paymentService');
     $doc1 = domxml_open_mem($doc);
     return $doc;
 }