protected function arrayToXML($fieldInfo, SimpleXMLElement $xmlFieldInfo) { foreach ($fieldInfo as $treeItemSID => $treeItemInfo) { $branch = $xmlFieldInfo->addChild('branch'); $branch->addChild('sid', $treeItemSID); $branch->addChild('caption', XML_Util::replaceEntities($treeItemInfo['caption'])); if (!empty($treeItemInfo['items'])) { $branchItems = $branch->addChild('items'); $this->arrayToXML($treeItemInfo['items'], $branchItems); } } }
/** * 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; }
/** * creating an XML tag with a CData Section */ $tag = array("qname" => "foo", "attributes" => array("key" => "value", "argh" => "tütü"), "content" => "Also XHTML-tags can be created and HTML entities can be replaced Ä ä Ü ö <>."); print "creating a tag with HTML entities:<br>\n"; print htmlentities(XML_Util::createTagFromArray($tag, XML_UTIL_ENTITIES_HTML)); print "\n<br><br>\n"; /** * creating an XML tag with createTag */ print "creating a tag with createTag:<br>"; print htmlentities(XML_Util::createTag("myNs:myTag", array("foo" => "bar"), "This is inside the tag", "http://www.w3c.org/myNs#")); print "\n<br><br>\n"; /** * trying to create an XML tag with an array as content */ $tag = array("qname" => "bar", "content" => array("foo" => "bar")); print "trying to create an XML tag with an array as content:<br>\n"; print "<pre>"; print_r(XML_Util::createTagFromArray($tag)); print "</pre>"; print "\n<br><br>\n"; /** * trying to create an XML tag without a name */ $tag = array("attributes" => array("foo" => "bar")); print "trying to create an XML tag without a name:<br>\n"; print "<pre>"; print_r(XML_Util::createTagFromArray($tag)); print "</pre>"; print "\n<br><br>\n";
/** * check, whether string is valid XML name * * <p>XML names are used for tagname, attribute names and various * other, lesser known entities.</p> * <p>An XML name may only consist of alphanumeric characters, * dashes, undescores and periods, and has to start with a letter * or an underscore. * </p> * * <code> * require_once 'XML/Util.php'; * * // verify tag name * $result = XML_Util::isValidName("invalidTag?"); * if (XML_Util::isError($result)) { * print "Invalid XML name: " . $result->getMessage(); * } * </code> * * @access public * @static * @param string $string string that should be checked * @return mixed $valid true, if string is a valid XML name, PEAR error otherwise * @todo support for other charsets */ function isValidName($string) { // check for invalid chars if (!preg_match("/^[[:alnum:]_\\-.]\$/", $string[0])) { return XML_Util::raiseError("XML names may only start with letter or underscore", XML_UTIL_ERROR_INVALID_START); } // check for invalid chars if (!preg_match("/^([a-zA-Z_]([a-zA-Z0-9_\\-\\.]*)?:)?[a-zA-Z_]([a-zA-Z0-9_\\-\\.]+)?\$/", $string)) { return XML_Util::raiseError("XML names may only contain alphanumeric chars, period, hyphen, colon and underscores", XML_UTIL_ERROR_INVALID_CHARS); } // XML name is valid return true; }
/** * create a tag from an array * this method awaits an array in the following format * array( * 'qname' => $tagName, * 'attributes' => array(), * 'content' => $content, // optional * 'namespace' => $namespace // optional * 'namespaceUri' => $namespaceUri // optional * ) * * @access private * @param array $tag tag definition * @param boolean $replaceEntities whether to replace XML entities in content or not * @return string $string XML tag */ function _createXMLTag($tag, $replaceEntities = true) { if ($this->options['indentAttributes'] !== false) { $multiline = true; $indent = str_repeat($this->options['indent'], $this->_tagDepth); if ($this->options['indentAttributes'] == '_auto') { $indent .= str_repeat(' ', strlen($tag['qname']) + 2); } else { $indent .= $this->options['indentAttributes']; } } else { $indent = $multiline = false; } if (is_array($tag['content'])) { if (empty($tag['content'])) { $tag['content'] = ''; } } elseif (is_scalar($tag['content']) && (string) $tag['content'] == '') { $tag['content'] = ''; } if (is_scalar($tag['content']) || is_null($tag['content'])) { if ($this->options['encoding'] == 'UTF-8' && version_compare(phpversion(), '5.0.0', 'lt')) { $tag['content'] = utf8_encode($tag['content']); } if ($replaceEntities === true) { $replaceEntities = XML_UTIL_ENTITIES_XML; } $tag = XML_Util::createTagFromArray($tag, $replaceEntities, $multiline, $indent, $this->options['linebreak']); } elseif (is_array($tag['content'])) { $tag = $this->_serializeArray($tag['content'], $tag['qname'], $tag['attributes']); } elseif (is_object($tag['content'])) { $tag = $this->_serializeObject($tag['content'], $tag['qname'], $tag['attributes']); } elseif (is_resource($tag['content'])) { settype($tag['content'], 'string'); $tag = XML_Util::createTagFromArray($tag, $replaceEntities); } return $tag; }
/** * create a tag from an array * this method awaits an array in the following format * array( * 'qname' => $tagName, * 'attributes' => array(), * 'content' => $content, // optional * 'namespace' => $namespace // optional * 'namespaceUri' => $namespaceUri // optional * ) * * @param array $tag tag definition * @param boolean $firstCall whether or not this is the first call * * @return string $string XML tag * @access private */ function _createXMLTag($tag, $firstCall = true) { // build fully qualified tag name if ($this->options[XML_SERIALIZER_OPTION_NAMESPACE] !== null) { if (is_array($this->options[XML_SERIALIZER_OPTION_NAMESPACE])) { $tag['qname'] = $this->options[XML_SERIALIZER_OPTION_NAMESPACE][0] . ':' . $tag['qname']; } else { $tag['qname'] = $this->options[XML_SERIALIZER_OPTION_NAMESPACE] . ':' . $tag['qname']; } } // attribute indentation if ($this->options[XML_SERIALIZER_OPTION_INDENT_ATTRIBUTES] !== false) { $multiline = true; $indent = str_repeat($this->options[XML_SERIALIZER_OPTION_INDENT], $this->_tagDepth); if ($this->options[XML_SERIALIZER_OPTION_INDENT_ATTRIBUTES] == '_auto') { $indent .= str_repeat(' ', strlen($tag['qname']) + 2); } else { $indent .= $this->options[XML_SERIALIZER_OPTION_INDENT_ATTRIBUTES]; } } else { $multiline = false; $indent = false; } if (is_array($tag['content'])) { if (empty($tag['content'])) { $tag['content'] = ''; } } elseif (XML_SERIALIZER_OPTION_FALSE_AS_STRING && $tag['content'] === false) { $tag['content'] = '0'; } elseif (is_scalar($tag['content']) && (string) $tag['content'] == '') { $tag['content'] = ''; } // replace XML entities if ($firstCall === true) { if ($this->options[XML_SERIALIZER_OPTION_CDATA_SECTIONS] === true) { $replaceEntities = XML_UTIL_CDATA_SECTION; } else { $replaceEntities = $this->options[XML_SERIALIZER_OPTION_ENTITIES]; } } else { // this is a nested call, so value is already encoded // and must not be encoded again $replaceEntities = XML_SERIALIZER_ENTITIES_NONE; // but attributes need to be encoded anyways // (done here because the rest of the code assumes the same encoding // can be used both for attributes and content) foreach ($tag['attributes'] as $k => $v) { $v = XML_Util::replaceEntities($v, $this->options[XML_SERIALIZER_OPTION_ENTITIES]); $tag['attributes'][$k] = $v; } } if (is_scalar($tag['content']) || is_null($tag['content'])) { if ($this->options[XML_SERIALIZER_OPTION_ENCODE_FUNC]) { if ($firstCall === true) { $tag['content'] = call_user_func($this->options[XML_SERIALIZER_OPTION_ENCODE_FUNC], $tag['content']); } $tag['attributes'] = array_map($this->options[XML_SERIALIZER_OPTION_ENCODE_FUNC], $tag['attributes']); } $tag = XML_Util::createTagFromArray($tag, $replaceEntities, $multiline, $indent, $this->options[XML_SERIALIZER_OPTION_LINEBREAKS]); } elseif (is_array($tag['content'])) { $tag = $this->_serializeArray($tag['content'], $tag['qname'], $tag['attributes']); } elseif (is_object($tag['content'])) { $tag = $this->_serializeObject($tag['content'], $tag['qname'], $tag['attributes']); } elseif (is_resource($tag['content'])) { settype($tag['content'], 'string'); if ($this->options[XML_SERIALIZER_OPTION_ENCODE_FUNC]) { if ($replaceEntities === true) { $tag['content'] = call_user_func($this->options[XML_SERIALIZER_OPTION_ENCODE_FUNC], $tag['content']); } $tag['attributes'] = array_map($this->options[XML_SERIALIZER_OPTION_ENCODE_FUNC], $tag['attributes']); } $tag = XML_Util::createTagFromArray($tag, $replaceEntities); } return $tag; }
/** * create a tag from an array * this method awaits an array in the following format * array( * 'qname' => $tagName, * 'attributes' => array(), * 'content' => $content, // optional * 'namespace' => $namespace // optional * 'namespaceUri' => $namespaceUri // optional * ) * * @access private * @param array $tag tag definition * @param boolean $replaceEntities whether to replace XML entities in content or not * @return string $string XML tag */ function _createXMLTag($tag, $firstCall = true) { // build fully qualified tag name if ($this->options[XML_SERIALIZER_OPTION_NAMESPACE] !== null) { if (is_array($this->options[XML_SERIALIZER_OPTION_NAMESPACE])) { $tag['qname'] = $this->options[XML_SERIALIZER_OPTION_NAMESPACE][0] . ':' . $tag['qname']; } else { $tag['qname'] = $this->options[XML_SERIALIZER_OPTION_NAMESPACE] . ':' . $tag['qname']; } } // attribute indentation if ($this->options[XML_SERIALIZER_OPTION_INDENT_ATTRIBUTES] !== false) { $multiline = true; $indent = str_repeat($this->options[XML_SERIALIZER_OPTION_INDENT], $this->_tagDepth); if ($this->options[XML_SERIALIZER_OPTION_INDENT_ATTRIBUTES] == '_auto') { $indent .= str_repeat(' ', strlen($tag['qname']) + 2); } else { $indent .= $this->options[XML_SERIALIZER_OPTION_INDENT_ATTRIBUTES]; } } else { $multiline = false; $indent = false; } if (is_array($tag['content'])) { if (empty($tag['content'])) { $tag['content'] = ''; } } elseif (is_scalar($tag['content']) && (string) $tag['content'] == '') { $tag['content'] = ''; } // replace XML entities (only needed, if this is not a nested call) if ($firstCall === true) { if ($this->options[XML_SERIALIZER_OPTION_CDATA_SECTIONS] === true) { $replaceEntities = XML_UTIL_CDATA_SECTION; } else { $replaceEntities = $this->options[XML_SERIALIZER_OPTION_ENTITIES]; } } else { $replaceEntities = XML_SERIALIZER_ENTITIES_NONE; } if (is_scalar($tag['content']) || is_null($tag['content'])) { if ($this->options[XML_SERIALIZER_OPTION_ENCODE_FUNC]) { if ($firstCall === true) { $tag['content'] = call_user_func($this->options[XML_SERIALIZER_OPTION_ENCODE_FUNC], $tag['content']); } $tag['attributes'] = array_map($this->options[XML_SERIALIZER_OPTION_ENCODE_FUNC], $tag['attributes']); } $tag = XML_Util::createTagFromArray($tag, $replaceEntities, $multiline, $indent, $this->options[XML_SERIALIZER_OPTION_LINEBREAKS]); } elseif (is_array($tag['content'])) { $tag = $this->_serializeArray($tag['content'], $tag['qname'], $tag['attributes']); } elseif (is_object($tag['content'])) { $tag = $this->_serializeObject($tag['content'], $tag['qname'], $tag['attributes']); } elseif (is_resource($tag['content'])) { settype($tag['content'], 'string'); if ($this->options[XML_SERIALIZER_OPTION_ENCODE_FUNC]) { if ($replaceEntities === true) { $tag['content'] = call_user_func($this->options[XML_SERIALIZER_OPTION_ENCODE_FUNC], $tag['content']); } $tag['attributes'] = array_map($this->options[XML_SERIALIZER_OPTION_ENCODE_FUNC], $tag['attributes']); } $tag = XML_Util::createTagFromArray($tag, $replaceEntities); } return $tag; }
/** * Serialize and save the updated tranlation data to the XML file * * @return boolean | PEAR_Error * @access private * @see Translation2_Admin_Container_xml::_scheduleSaving() */ function _saveData() { if ($this->options['save_on_shutdown']) { $data =& $this->_data; } else { $data = $this->_data; } $this->_convertEncodings('to_xml', $data); $this->_convertLangEncodings('to_xml', $data); // Serializing $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n" . "<!DOCTYPE translation2 [\n" . TRANSLATION2_DTD . "]>\n\n" . "<translation2>\n" . " <languages>\n"; foreach ($data['languages'] as $lang => $spec) { extract($spec); $xml .= " <lang id=\"{$lang}\">\n" . " <name>" . ($name ? ' ' . XML_Util::replaceEntities($name) . ' ' : '') . "</name>\n" . " <meta>" . ($meta ? ' ' . XML_Util::replaceEntities($meta) . ' ' : "") . "</meta>\n" . " <error_text>" . ($error_text ? ' ' . XML_Util::replaceEntities($error_text) . ' ' : "") . "</error_text>\n" . " <encoding>" . ($encoding ? " {$encoding} " : "") . "</encoding>\n" . " </lang>\n"; } $xml .= " </languages>\n" . " <pages>\n"; foreach ($data['pages'] as $page => $strings) { $xml .= " <page key=\"" . XML_Util::replaceEntities($page) . "\">\n"; foreach ($strings as $str_id => $translations) { $xml .= " <string key=\"" . XML_Util::replaceEntities($str_id) . "\">\n"; foreach ($translations as $lang => $str) { $xml .= " <tr lang=\"{$lang}\"> " . XML_Util::replaceEntities($str) . " </tr>\n"; } $xml .= " </string>\n"; } $xml .= " </page>\n"; } $xml .= " </pages>\n" . "</translation2>\n"; unset($data); // Saving if (!($f = fopen($this->_filename, 'w'))) { return $this->raiseError(sprintf('Unable to open the XML file ("%s") for writing', $this->_filename), TRANSLATION2_ERROR_CANNOT_WRITE_FILE, PEAR_ERROR_TRIGGER, E_USER_ERROR); } @flock($f, LOCK_EX); fwrite($f, $xml); //@flock($f, LOCK_UN); fclose($f); return true; }
function CreateNode($NodeName, $NodeValue) { require_once 'XML/Util.php'; $xml = new XML_Util(); $node = "<" . $NodeName . ">" . $xml->replaceEntities($NodeValue) . "</" . $NodeName . ">"; return $node; }
/** baz_affiche_flux_RSS() - affiche le flux rss ÃÂ partir de parametres * * * @return string Le flux RSS, avec les headers et tout et tout */ function baz_afficher_flux_RSS() { if (isset($_GET['id_typeannonce'])) { $id_typeannonce = $_GET['id_typeannonce']; } else { $id_typeannonce = $GLOBALS['_BAZAR_']['id_typeannonce']; } if (isset($_GET['categorie_fiche'])) { $categorie_fiche = $_GET['categorie_fiche']; } else { $categorie_fiche = $GLOBALS['_BAZAR_']['categorie_nature']; } if (isset($_GET['nbitem'])) { $nbitem = $_GET['nbitem']; } else { $nbitem = BAZ_NB_ENTREES_FLUX_RSS; } if (isset($_GET['utilisateur'])) { $utilisateur = $_GET['utilisateur']; } else { $utilisateur = ''; } if (isset($_GET['statut'])) { $statut = $_GET['statut']; } else { $statut = 1; } if (isset($_GET['query'])) { $query = $_GET['query']; } else { $query = ''; } $tableau_flux_rss = baz_requete_recherche_fiches($query, '', $id_typeannonce, $categorie_fiche, $statut, $utilisateur, 20); require_once 'XML/Util.php'; // setlocale() pour avoir les formats de date valides (w3c) --julien setlocale(LC_TIME, "C"); $xml = XML_Util::getXMLDeclaration('1.0', 'UTF-8', 'yes'); $xml .= "\r\n "; $xml .= XML_Util::createStartElement('rss', array('version' => '2.0', 'xmlns:atom' => "http://www.w3.org/2005/Atom")); $xml .= "\r\n "; $xml .= XML_Util::createStartElement('channel'); $xml .= "\r\n "; $xml .= XML_Util::createTag('title', null, utf8_encode(html_entity_decode(BAZ_DERNIERE_ACTU))); $xml .= "\r\n "; $xml .= XML_Util::createTag('link', null, utf8_encode(html_entity_decode(BAZ_RSS_ADRESSESITE))); $xml .= "\r\n "; $xml .= XML_Util::createTag('description', null, utf8_encode(html_entity_decode(BAZ_RSS_DESCRIPTIONSITE))); $xml .= "\r\n "; $xml .= XML_Util::createTag('language', null, 'fr-FR'); $xml .= "\r\n "; $xml .= XML_Util::createTag('copyright', null, 'Copyright (c) ' . date('Y') . ' ' . utf8_encode(html_entity_decode(BAZ_RSS_NOMSITE))); $xml .= "\r\n "; $xml .= XML_Util::createTag('lastBuildDate', null, strftime('%a, %d %b %Y %H:%M:%S GMT')); $xml .= "\r\n "; $xml .= XML_Util::createTag('docs', null, 'http://www.stervinou.com/projets/rss/'); $xml .= "\r\n "; $xml .= XML_Util::createTag('category', null, BAZ_RSS_CATEGORIE); $xml .= "\r\n "; $xml .= XML_Util::createTag('managingEditor', null, BAZ_RSS_MANAGINGEDITOR); $xml .= "\r\n "; $xml .= XML_Util::createTag('webMaster', null, BAZ_RSS_WEBMASTER); $xml .= "\r\n "; $xml .= XML_Util::createTag('ttl', null, '60'); $xml .= "\r\n "; $xml .= XML_Util::createStartElement('image'); $xml .= "\r\n "; $xml .= XML_Util::createTag('title', null, utf8_encode(html_entity_decode(BAZ_DERNIERE_ACTU))); $xml .= "\r\n "; $xml .= XML_Util::createTag('url', null, BAZ_RSS_LOGOSITE); $xml .= "\r\n "; $xml .= XML_Util::createTag('link', null, BAZ_RSS_ADRESSESITE); $xml .= "\r\n "; $xml .= XML_Util::createEndElement('image'); if (count($tableau_flux_rss) > 0) { // Creation des items : titre + lien + description + date de publication foreach ($tableau_flux_rss as $ligne) { $ligne = json_decode($ligne[0], true); $ligne = array_map('utf8_decode', $ligne); $xml .= "\r\n "; $xml .= XML_Util::createStartElement('item'); $xml .= "\r\n "; $xml .= XML_Util::createTag('title', null, encoder_en_utf8(html_entity_decode(stripslashes($ligne['bf_titre'])))); $xml .= "\r\n "; $lien = $GLOBALS['_BAZAR_']['url']; $lien->addQueryString(BAZ_VARIABLE_ACTION, BAZ_VOIR_FICHE); $lien->addQueryString(BAZ_VARIABLE_VOIR, BAZ_VOIR_CONSULTER); $lien->addQueryString('id_fiche', $ligne['id_fiche']); $xml .= XML_Util::createTag('link', null, '<![CDATA[' . $lien->getURL() . ']]>'); $xml .= "\r\n "; $xml .= XML_Util::createTag('guid', null, '<![CDATA[' . $lien->getURL() . ']]>'); $xml .= "\r\n "; $tab = explode("wakka.php?wiki=", $lien->getURL()); $xml .= XML_Util::createTag('description', null, '<![CDATA[' . encoder_en_utf8(html_entity_decode(baz_voir_fiche(0, $ligne))) . ']]>'); $xml .= "\r\n "; if ($ligne['date_debut_validite_fiche'] != '0000-00-00' && $ligne['date_debut_validite_fiche'] > $ligne['date_creation_fiche']) { $date_pub = $ligne['date_debut_validite_fiche']; } else { $date_pub = $ligne['date_creation_fiche']; } $xml .= XML_Util::createTag('pubDate', null, strftime('%a, %d %b %Y %H:%M:%S GMT', strtotime($date_pub))); $xml .= "\r\n "; $xml .= XML_Util::createEndElement('item'); } } else { //pas d'annonces $xml .= "\r\n "; $xml .= XML_Util::createStartElement('item'); $xml .= "\r\n "; $xml .= XML_Util::createTag('title', null, utf8_encode(html_entity_decode(BAZ_PAS_DE_FICHES))); $xml .= "\r\n "; $xml .= XML_Util::createTag('link', null, '<![CDATA[' . $GLOBALS['_BAZAR_']['url']->getUrl() . ']]>'); $xml .= "\r\n "; $xml .= XML_Util::createTag('guid', null, '<![CDATA[' . $GLOBALS['_BAZAR_']['url']->getUrl() . ']]>'); $xml .= "\r\n "; $xml .= XML_Util::createTag('description', null, utf8_encode(html_entity_decode(BAZ_PAS_DE_FICHES))); $xml .= "\r\n "; $xml .= XML_Util::createTag('pubDate', null, strftime('%a, %d %b %Y %H:%M:%S GMT', strtotime("01/01/%Y"))); $xml .= "\r\n "; $xml .= XML_Util::createEndElement('item'); } $xml .= "\r\n "; $GLOBALS['_BAZAR_']['url']->addQueryString(BAZ_VARIABLE_ACTION, BAZ_VOIR_FLUX_RSS); // $xml .= utf8_encode(html_entity_decode('<atom:link href="'.$GLOBALS['_BAZAR_']['url']->getUrl().'" rel="self" type="application/rss+xml" />'."\r\n ")); $xml .= XML_Util::createEndElement('channel'); $xml .= "\r\n "; $xml .= XML_Util::createEndElement('rss'); // Nettoyage de l'url $GLOBALS['_BAZAR_']['url']->removeQueryString(BAZ_VARIABLE_ACTION); $GLOBALS['_BAZAR_']['url']->removeQueryString('id_fiche'); echo html_entity_decode($xml); }
/** * create a tag from an array * this method awaits an array in the following format * array( * "qname" => $tagName, * "attributes" => array(), * "content" => $content, // optional * "namespace" => $namespace // optional * "namespaceUri" => $namespaceUri // optional * ) * * @access private * @param array $tag tag definition * @param boolean $replaceEntities whether to replace XML entities in content or not * @return string $string XML tag */ function _createXMLTag($tag, $replaceEntities = true) { if ($this->options["indentAttributes"] !== false) { $multiline = true; $indent = str_repeat($this->options["indent"], $this->_tagDepth); if ($this->options["indentAttributes"] == "_auto") { $indent .= str_repeat(" ", strlen($tag["qname"]) + 2); } else { $indent .= $this->options["indentAttributes"]; } } else { $multiline = false; $indent = false; } if (is_array($tag["content"])) { if (empty($tag["content"])) { $tag["content"] = ''; } } elseif (is_scalar($tag["content"]) && (string) $tag["content"] == '') { $tag["content"] = ''; } if (is_scalar($tag["content"]) || is_null($tag["content"])) { $tag = XML_Util::createTagFromArray($tag, $replaceEntities, $multiline, $indent, $this->options["linebreak"]); } elseif (is_array($tag["content"])) { $tag = $this->_serializeArray($tag["content"], $tag["qname"], $tag["attributes"]); } elseif (is_object($tag["content"])) { $tag = $this->_serializeObject($tag["content"], $tag["qname"], $tag["attributes"]); } elseif (is_resource($tag["content"])) { settype($tag["content"], "string"); $tag = XML_Util::createTagFromArray($tag, $replaceEntities); } return $tag; }
public static function generateExportData($parameters) { $exportProperties = $aliases = $sid = null; extract($parameters); $listingInfo = SJB_ListingManager::getListingInfoBySID($sid); $listingInfo = $aliases->changePropertiesInfo($listingInfo); $exportData = array(); $i18n = SJB_I18N::getInstance(); foreach ($exportProperties as $propertyId => $value) { if ('ApplicationSettings' == $propertyId) { $exportData[$sid][$propertyId] = isset($listingInfo[$propertyId]['value']) ? $listingInfo[$propertyId]['value'] : null; } else { $fieldInfo = SJB_ListingFieldDBManager::getListingFieldInfoByID($propertyId); if (!empty($fieldInfo['type']) && $fieldInfo['type'] == 'complex' && isset($listingInfo[$propertyId])) { $complexFields = $listingInfo[$propertyId]; if (is_string($listingInfo[$propertyId])) { $complexFields = unserialize($complexFields); } if (is_array($complexFields)) { $fieldsInfo = SJB_ListingComplexFieldManager::getListingFieldsInfoByParentSID($fieldInfo['sid']); foreach ($fieldsInfo as $key => $info) { $fieldsInfo[$info['id']] = $info; unset($fieldsInfo[$key]); } $domDocument = new DOMDocument(); $rootElement = $domDocument->createElement($propertyId . 's'); $domDocument->appendChild($rootElement); $propertyElements = array(); $createPropertyElements = true; foreach ($complexFields as $fieldName => $fieldValue) { $fieldInfo = isset($fieldsInfo[$fieldName]) ? $fieldsInfo[$fieldName] : array(); foreach ($fieldValue as $key => $value) { if (isset($fieldInfo['type']) && $fieldInfo['type'] == 'complexfile' && $value != '') { $fileName = SJB_UploadFileManager::getUploadedSavedFileName($value); $value = $fileName ? 'files/' . $fileName : ''; } elseif (isset($fieldInfo['type']) && $fieldInfo['type'] == 'date' && $value != '') { $value = $i18n->getDate($value); } if ($createPropertyElements) { $propertyElement = $domDocument->createElement($propertyId); $rootElement->appendChild($propertyElement); $propertyElements[$key] = $propertyElement; } $fieldElement = $domDocument->createElement($fieldName); $propertyElements[$key]->appendChild($fieldElement); $valElement = $domDocument->createTextNode(XML_Util::replaceEntities($value)); $fieldElement->appendChild($valElement); } $createPropertyElements = false; } $exportData[$sid][$propertyId] = $domDocument->saveXML(); } else { $exportData[$sid][$propertyId] = null; } } else { $exportData[$sid][$propertyId] = isset($listingInfo[$propertyId]) ? $listingInfo[$propertyId] : null; } } } self::changeTreeProperties($exportProperties, $exportData); self::changeMonetaryProperties($exportProperties, $exportData); self::changeListProperties($exportProperties, $exportData); self::changePicturesProperties($exportProperties, $exportData); self::changeFileProperties($exportProperties, $exportData, 'file'); self::changeFileProperties($exportProperties, $exportData, 'video'); self::changeComplexFileProperties($exportProperties, $exportData, 'complexfile'); self::changeLocationProperties($exportProperties, $exportData); return $exportData[$sid]; }
/** * Serialize the element. * * @access public * @return string string representation of the element and all of its childNodes */ public function serialize() { if (empty($this->_ns) || $this->knownElement === false) { $el = $this->elementName; } else { $el = sprintf('%s:%s', $this->_ns, $this->elementName); } if (!$this->hasChildren()) { if ($this->cdata !== null) { $content = $this->cdata; if ($this->replaceEntities) { $content = XML_Util::replaceEntities($content); } } } else { $content = ''; $rit = new RecursiveIteratorIterator($this, RIT_SELF_FIRST); while ($rit->getSubIterator()->valid()) { $content .= $rit->getSubIterator()->current()->serialize(); $rit->getSubIterator()->next(); } } if ($this->isRoot) { $nsUri = 'http://www.macromedia.com/2003/mxml'; } else { $nsUri = null; } return XML_Util::createTag($el, $this->attributes, $content, $nsUri, false); }
/** * 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 = PEAR_PackageFile_Generator_v2_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 PEAR_PackageFile_Generator_v2_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 = PEAR_PackageFile_Generator_v2_XML_Util_REPLACE_ENTITIES, $multiline = false, $indent = "_auto", $linebreak = "\n", $encoding = PEAR_PackageFile_Generator_v2_XML_Util_ENTITIES_XML) { if (isset($tag["content"]) && !is_scalar($tag["content"])) { return XML_Util::raiseError("Supplied non-scalar value as tag content", PEAR_PackageFile_Generator_v2_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).', PEAR_PackageFile_Generator_v2_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 == PEAR_PackageFile_Generator_v2_XML_Util_REPLACE_ENTITIES) { $tag["content"] = PEAR_PackageFile_Generator_v2_XML_Util::replaceEntities($tag["content"], $encoding); } elseif ($replaceEntities == PEAR_PackageFile_Generator_v2_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; }
echo 'assets url ' . $assets_url; echo PHP_EOL; $data = array('foo' => 'bar', 'baz' => 'boom', 'cow' => 'milk', 'php' => 'hypertext processor'); echo http_build_query($data) . "\n"; echo http_build_query($data, '', '&'); echo PHP_EOL; echo nl2br("Welcome\r\nThis is my HTML document", false); //lets look at some pear echo PHP_EOL; //C:\php\pear\docs\XML_Util\examples\example.php require_once 'XML/Util.php'; /** * building document type declaration */ print 'building DocType declaration:<br>'; print htmlspecialchars(XML_Util::getDocTypeDeclaration('package', 'http://pear.php.net/dtd/package-1.0')); print "\n<br><br>\n"; $modes = mcrypt_list_modes(); echo "mcrypt_list_modes <br>\n"; echo print_r_xml($modes); //F:\bit5411\php\PEAR\OS\Guess.php class OS_Guess require_once 'OS/Guess.php'; $phpwhat = new OS_Guess(); //$phpwhat = OS_Guess::getSignature(); //fatal this $tmp = $phpwhat->getSignature(); echo $tmp; echo PHP_EOL; $tmp = $phpwhat->getSysname(); echo $tmp; echo PHP_EOL; $tmp = $phpwhat->getNodename();
/** * Wrapper for startElement handler. * * @param string * @param array * @return string * @access public */ function startElement($element, $attributes) { $do = 'start_' . $element; if (method_exists($this, $do)) { return $this->{$do}($attributes); } return sprintf("<%s%s>", $element, XML_Util::attributesToString($attributes)); }
public function toString(__ConfigurationComponent &$configuration_component) { $indent = ''; if (!$configuration_component->isRoot()) { // no indent for root $this->_deep++; $indent = str_repeat($this->options['indent'], $this->_deep); } else { // Initialize string with xml declaration $string = ''; if ($this->options['addDecl']) { $string .= XML_Util::getXMLDeclaration($this->options['version'], $this->options['encoding']); $string .= $this->options['linebreak']; } if (!empty($this->options['name'])) { $string .= '<' . $this->options['name'] . '>' . $this->options['linebreak']; $this->_deep++; $indent = str_repeat($this->options['indent'], $this->_deep); } } if (!isset($string)) { $string = ''; } if ($configuration_component instanceof __ConfigurationProperty) { $attributes = $this->options['useAttr'] ? $configuration_component->attributes : array(); $string .= $indent . XML_Util::createTag($configuration_component->name, $attributes, $configuration_component->content, null, $this->options['useCData'] ? XML_UTIL_CDATA_SECTION : XML_UTIL_REPLACE_ENTITIES); $string .= $this->options['linebreak']; } else { if ($configuration_component instanceof __ConfigurationComment) { $string .= $indent . '<!-- ' . $configuration_component->content . ' -->'; $string .= $this->options['linebreak']; } else { if ($configuration_component instanceof __ConfigurationSection) { if (!$configuration_component->isRoot()) { $string = $indent . '<' . $configuration_component->name; $string .= $this->options['useAttr'] ? XML_Util::attributesToString($configuration_component->attributes) : ''; } if ($children = count($configuration_component->children)) { if (!$configuration_component->isRoot()) { $string .= '>' . $this->options['linebreak']; } for ($i = 0; $i < $children; $i++) { $string .= $this->toString($configuration_component->getChild($i)); } } if (!$configuration_component->isRoot()) { if ($children) { $string .= $indent . '</' . $configuration_component->name . '>' . $this->options['linebreak']; } else { $string .= '/>' . $this->options['linebreak']; } } else { if (!empty($this->options['name'])) { $string .= '</' . $this->options['name'] . '>' . $this->options['linebreak']; } } } else { $string = ''; } } } if (!$configuration_component->isRoot()) { $this->_deep--; } return $string; }
/** baz_affiche_flux_RSS() - affiche le flux rss a partir de parametres * @return string Le flux RSS, avec les headers et tout et tout */ function baz_afficher_flux_RSS() { $urlrss = $GLOBALS['wiki']->href('rss'); if (isset($_GET['id_typeannonce'])) { $id_typeannonce = $_GET['id_typeannonce']; $urlrss .= '&id_typeannonce=' . $id_typeannonce; } else { $id_typeannonce = ''; } if (isset($_GET['categorie_fiche'])) { $categorie_fiche = $_GET['categorie_fiche']; $urlrss .= '&categorie_fiche=' . $categorie_fiche; } else { $categorie_fiche = ''; } if (isset($_GET['nbitem'])) { $nbitem = $_GET['nbitem']; $urlrss .= '&nbitem=' . $nbitem; } else { $nbitem = BAZ_NB_ENTREES_FLUX_RSS; } if (isset($_GET['utilisateur'])) { $utilisateur = $_GET['utilisateur']; $urlrss .= '&utilisateur=' . $utilisateur; } else { $utilisateur = ''; } if (isset($_GET['statut'])) { $statut = $_GET['statut']; $urlrss .= '&statut=' . $statut; } else { $statut = 1; } if (isset($_GET['query'])) { $query = $_GET['query']; $urlrss .= '&query=' . $query; } else { $query = ''; } $tableau_flux_rss = baz_requete_recherche_fiches($query, '', $id_typeannonce, $categorie_fiche, $statut, $utilisateur, 20); require_once BAZ_CHEMIN . 'libs' . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'XML/Util.php'; // setlocale() pour avoir les formats de date valides (w3c) --julien setlocale(LC_TIME, 'C'); $xml = XML_Util::getXMLDeclaration('1.0', 'UTF-8', 'yes'); $xml .= "\r\n "; $xml .= XML_Util::createStartElement('rss', array('version' => '2.0', 'xmlns:atom' => 'http://www.w3.org/2005/Atom', 'xmlns:dc' => 'http://purl.org/dc/elements/1.1/')); $xml .= "\r\n "; $xml .= XML_Util::createStartElement('channel'); $xml .= "\r\n "; $xml .= XML_Util::createTag('title', null, html_entity_decode(_t('BAZ_DERNIERE_ACTU'), ENT_QUOTES, 'UTF-8')); $xml .= "\r\n "; $xml .= XML_Util::createTag('link', null, html_entity_decode(BAZ_RSS_ADRESSESITE, ENT_QUOTES, 'UTF-8')); $xml .= "\r\n "; $xml .= XML_Util::createTag('description', null, html_entity_decode(BAZ_RSS_DESCRIPTIONSITE, ENT_QUOTES, 'UTF-8')); $xml .= "\r\n "; $xml .= XML_Util::createTag('language', null, 'fr-FR'); $xml .= "\r\n "; $xml .= XML_Util::createTag('copyright', null, 'Copyright (c) ' . date('Y') . ' ' . html_entity_decode(BAZ_RSS_NOMSITE, ENT_QUOTES, 'UTF-8')); $xml .= "\r\n "; $xml .= XML_Util::createTag('lastBuildDate', null, strftime('%a, %d %b %Y %H:%M:%S GMT')); $xml .= "\r\n "; $xml .= XML_Util::createTag('docs', null, 'http://www.stervinou.com/projets/rss/'); $xml .= "\r\n "; $xml .= XML_Util::createTag('category', null, BAZ_RSS_CATEGORIE); $xml .= "\r\n "; $xml .= XML_Util::createTag('managingEditor', null, BAZ_RSS_MANAGINGEDITOR); $xml .= "\r\n "; $xml .= XML_Util::createTag('webMaster', null, BAZ_RSS_WEBMASTER); $xml .= "\r\n "; $xml .= XML_Util::createTag('ttl', null, '60'); $xml .= "\r\n "; $xml .= XML_Util::createStartElement('image'); $xml .= "\r\n "; $xml .= XML_Util::createTag('title', null, html_entity_decode(_t('BAZ_DERNIERE_ACTU'), ENT_QUOTES, 'UTF-8')); $xml .= "\r\n "; $xml .= XML_Util::createTag('url', null, BAZ_RSS_LOGOSITE); $xml .= "\r\n "; $xml .= XML_Util::createTag('link', null, BAZ_RSS_ADRESSESITE); $xml .= "\r\n "; $xml .= XML_Util::createEndElement('image'); if (count($tableau_flux_rss) > 0) { // Creation des items : titre + lien + description + date de publication foreach ($tableau_flux_rss as $ligne) { $ligne = json_decode($ligne['body'], true); $ligne = _convert($ligne, 'UTF-8'); $xml .= "\r\n "; $xml .= XML_Util::createStartElement('item'); $xml .= "\r\n "; $xml .= XML_Util::createTag('title', null, html_entity_decode(stripslashes($ligne['bf_titre']), ENT_QUOTES, 'UTF-8')); $xml .= "\r\n "; $lien = $GLOBALS['_BAZAR_']['url']; $lien->addQueryString(BAZ_VARIABLE_ACTION, BAZ_VOIR_FICHE); $lien->addQueryString(BAZ_VARIABLE_VOIR, BAZ_VOIR_CONSULTER); $lien->addQueryString('id_fiche', $ligne['id_fiche']); $xml .= XML_Util::createTag('link', null, '<![CDATA[' . $lien->getURL() . ']]>'); $xml .= "\r\n "; $xml .= XML_Util::createTag('guid', null, '<![CDATA[' . $lien->getURL() . ']]>'); $xml .= "\r\n "; $xml .= XML_Util::createTag('dc:creator', null, $ligne['createur']); $xml .= "\r\n "; $tab = explode('wakka.php?wiki=', $lien->getURL()); $xml .= XML_Util::createTag('description', null, '<![CDATA[' . preg_replace('/data-id=".*"/Ui', '', html_entity_decode(baz_voir_fiche(0, $ligne), ENT_QUOTES, 'UTF-8')) . ']]>'); $xml .= "\r\n "; $xml .= XML_Util::createTag('pubDate', null, strftime('%a, %d %b %Y %H:%M:%S GMT', strtotime($ligne['date_creation_fiche']))); $xml .= "\r\n "; $xml .= XML_Util::createEndElement('item'); } } else { //pas d'annonces $xml .= "\r\n "; $xml .= XML_Util::createStartElement('item'); $xml .= "\r\n "; $xml .= XML_Util::createTag('title', null, html_entity_decode(_t('BAZ_PAS_DE_FICHES'), ENT_QUOTES, 'UTF-8')); $xml .= "\r\n "; $xml .= XML_Util::createTag('link', null, '<![CDATA[' . $GLOBALS['_BAZAR_']['url']->getUrl() . ']]>'); $xml .= "\r\n "; $xml .= XML_Util::createTag('guid', null, '<![CDATA[' . $GLOBALS['_BAZAR_']['url']->getUrl() . ']]>'); $xml .= "\r\n "; $xml .= XML_Util::createTag('description', null, html_entity_decode(_t('BAZ_PAS_DE_FICHES'), ENT_QUOTES, 'UTF-8')); $xml .= "\r\n "; $xml .= XML_Util::createTag('pubDate', null, strftime('%a, %d %b %Y %H:%M:%S GMT', strtotime('01/01/%Y'))); $xml .= "\r\n "; $xml .= XML_Util::createEndElement('item'); } $xml .= "\r\n "; $xml .= XML_Util::createEndElement('channel'); $xml .= "\r\n "; $xml .= XML_Util::createEndElement('rss'); // Nettoyage de l'url $GLOBALS['_BAZAR_']['url']->removeQueryString(BAZ_VARIABLE_ACTION); $GLOBALS['_BAZAR_']['url']->removeQueryString('id_fiche'); echo str_replace('</image>', '</image>' . "\n" . '<atom:link href="' . $urlrss . '" rel="self" type="application/rss+xml" />', html_entity_decode($xml, ENT_QUOTES, 'UTF-8')); }
/** * @param string * @param integer * @return string * @access private */ function _createImage($word, $baseline) { $font = isset($this->_gtextAttributes['font']) ? $this->_gtextAttributes['font'] : 'arial.ttf'; $fh = isset($this->_gtextAttributes['fontsize']) ? $this->_gtextAttributes['fontsize'] : 12; $bgcolor = isset($this->_gtextAttributes['bgcolor']) ? $this->_gtextAttributes['bgcolor'] : '#ffffff'; $fgcolor = isset($this->_gtextAttributes['fgcolor']) ? $this->_gtextAttributes['fgcolor'] : '#ffffff'; $antialias = isset($this->_gtextAttributes['antialias']) ? $this->_gtextAttributes['antialias'] : 'yes'; $transparency = isset($this->_gtextAttributes['transparency']) ? $this->_gtextAttributes['transparency'] : 'yes'; $cacheable = isset($this->_gtextAttributes['cacheable']) ? $this->_gtextAttributes['cacheable'] : 'yes'; $spacing = isset($this->_gtextAttributes['spacing']) ? $this->_gtextAttributes['spacing'] : 2; $border = isset($this->_gtextAttributes['border']) ? $this->_gtextAttributes['border'] : 0; $bordercolor = isset($this->_gtextAttributes['bordercolor']) ? $this->_gtextAttributes['bordercolor'] : '#ff0000'; /* The cache name is derived from all attributes and cdata. * This is very conserative and may create to many cachefiles, * but better to err on the safe side. */ $cachefile = md5(XML_Util::attributesToString($this->_gtextAttributes) . ':' . $word) . '.png'; $cacheDir = $_SERVER['DOCUMENT_ROOT'] . PEAR_XML_TRANSFORMER_IMAGE_cacheDir; $cacheName = "{$cacheDir}/{$cachefile}"; $cacheURL = PEAR_XML_TRANSFORMER_IMAGE_cacheDir . "/{$cachefile}"; if (!is_dir($cacheDir)) { mkdir($cacheDir, 01777); } /* Don't do the same work twice. */ if (file_exists($cacheName) && $cacheable != 'no') { return $cacheURL; } $r = ImageTTFBBox($fh, 0, $font, $word); $w = max(1 / 10 * $fh, abs($r[2] - $r[0])); $h = max(1, abs($r[7] - $r[1])); $x = $r[0]; $y = $baseline; $www = $w + 2 * ($spacing + $border); $hhh = $fh + 2 * ($spacing + $border); $im = ImageCreate($www, $hhh); list($r, $g, $b) = $this->_colorString($bgcolor); $bg = ImageColorAllocate($im, $r, $g, $b); if ($transparency != 'no') { ImageColorTransparent($im, $bg); } list($r, $g, $b) = $this->_colorString($fgcolor); $fg = ImageColorAllocate($im, $r, $g, $b); if ($antialias == 'no') { $fg = -$fg; } list($r, $g, $b) = $this->_colorString($bordercolor); $bo = ImageColorAllocate($im, $r, $g, $b); ImageFilledRectangle($im, 0, 0, $www, $hhh, $bg); if ($border > 0) { for ($i = $border; $i >= 0; $i--) { $x1 = $y1 = $i; $x2 = $www - $i - 1; $y2 = $hhh - $i - 1; ImageRectangle($im, $x1, $y1, $x2, $y2, $bo); } } ImageTTFText($im, $fh, 0, -$x + $spacing + $border, $hhh - (2 + $y + $spacing + $border), $fg, $font, $word); ImagePNG($im, $cacheName); ImageDestroy($im); return $cacheURL; }
/** * @param array * @return string * @access public */ function start_xref($attributes) { if ($this->_secondPass) { return sprintf('<a href="#%s">%s</a>', isset($attributes['linkend']) ? $attributes['linkend'] : '', isset($this->_xref[$attributes['linkend']]) ? $this->_xref[$attributes['linkend']] : ''); } else { return sprintf('<xref%s>', XML_Util::attributesToString($attributes)); } }
/** * @param string * @return string * @access public */ function end_random($cdata) { srand((double) microtime() * 1000000); $keys = array_keys($this->_anchorDatabase); $pos = rand(0, count($keys) - 1); $name = $keys[$pos]; return sprintf('<a %s>%s</a>', XML_Util::attributesToString($this->_anchorDatabase[$name]), $cdata); }
/** * @param array $data * @return bool|PEAR_Error|void */ private function _saveDataPages($data) { $fileName = !empty($this->options['filename_pages']) ? $this->options['filename_pages'] : false; if (!$fileName) { return false; } $this->_convertEncodings('to_xml', $data); // Serializing $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n" . "<!DOCTYPE translation2 [\n" . TRANSLATION2_DTD_PAGES . "]>\n\n" . "<translation2>\n" . " <languages>\n"; foreach ($data['languages'] as $lang => $spec) { extract($spec); $xml .= " <lang id=\"{$lang}\"/>\n"; } $xml .= " </languages>\n" . " <pages>\n"; foreach ($data['pages'] as $page => $strings) { $xml .= " <page key=\"" . XML_Util::replaceEntities($page) . "\">\n"; foreach ($strings as $str_id => $translations) { $xml .= " <string key=\"" . XML_Util::replaceEntities($str_id) . "\">\n"; foreach ($translations as $lang => $str) { $xml .= " <tr lang=\"{$lang}\"> " . XML_Util::replaceEntities($str) . " </tr>\n"; } $xml .= " </string>\n"; } $xml .= " </page>\n"; } $xml .= " </pages>\n" . "</translation2>\n"; unset($data); // Saving if (!($f = fopen($fileName, 'w'))) { return $this->raiseError(sprintf('Unable to open the XML file ("%s") for writing', $fileName), TRANSLATION2_ERROR_CANNOT_WRITE_FILE, PEAR_ERROR_TRIGGER, E_USER_ERROR); } @flock($f, LOCK_EX); fwrite($f, $xml); //@flock($f, LOCK_UN); fclose($f); }
/** * Print a group of same tag in the XML report. * * Groups list are : extension(s), constant(s), token(s) * * @param array $dataSrc Data source * @param string $tagName Name of the XML tag * * @return string * @access private * @since version 1.7.0b4 (2008-04-03) */ function _printTagList($dataSrc, $tagName) { $msg = ''; if ($tagName == 'function') { $c = 0; foreach ($dataSrc as $version => $functions) { $c += count($functions); } $attributes = array('count' => $c); } elseif ($tagName == 'condition') { if ($this->_parser->options['debug'] === true) { $c = 0; foreach ($dataSrc[1] as $cond => $elements) { $c += count($elements); } $attributes = array('count' => $c, 'level' => $dataSrc[0]); } else { $attributes = array('level' => $dataSrc[0]); } } else { $attributes = array('count' => count($dataSrc)); } $msg .= XML_Util::createStartElement($tagName . 's', $attributes); $msg .= PHP_EOL; if ($tagName == 'function') { foreach ($dataSrc as $version => $functions) { foreach ($functions as $data) { $attr = array('version' => $version); if (!empty($data['extension'])) { $attr['extension'] = $data['extension']; $attr['pecl'] = $data['pecl'] === true ? 'true' : 'false'; } $tag = array('qname' => $tagName, 'attributes' => $attr, 'content' => $data['function']); $msg .= XML_Util::createTagFromArray($tag); $msg .= PHP_EOL; } } } elseif ($tagName == 'condition') { if ($this->_parser->options['debug'] == true) { foreach ($dataSrc[1] as $cond => $elements) { $cond = $cond == 0 ? 1 : $cond * 2; foreach ($elements as $data) { $tag = array('qname' => $tagName, 'attributes' => array('level' => $cond), 'content' => $data); $msg .= XML_Util::createTagFromArray($tag); $msg .= PHP_EOL; } } } } else { foreach ($dataSrc as $data) { $tag = array('qname' => $tagName, 'attributes' => array(), 'content' => $data); $msg .= XML_Util::createTagFromArray($tag); $msg .= PHP_EOL; } } $msg .= XML_Util::createEndElement($tagName . 's'); $msg .= PHP_EOL; return $msg; }
/** * @param array $data * @return string */ protected function generateXMLData($data) { $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n" . "<!DOCTYPE translation2 [\n" . TRANSLATION2_DTD . "]>\n\n" . "<translation2>\n" . " <languages>\n"; foreach ($data['languages'] as $lang => $spec) { extract($spec); $xml .= " <lang id=\"{$lang}\">\n" . " <name>" . ($name ? ' ' . XML_Util::replaceEntities($name) . ' ' : '') . "</name>\n" . " <meta>" . ($meta ? ' ' . str_replace('__quote__', '"', XML_Util::replaceEntities(str_replace('"', "__quote__", $meta))) . ' ' : "") . "</meta>\n" . " <error_text>" . ($error_text ? ' ' . XML_Util::replaceEntities($error_text) . ' ' : "") . "</error_text>\n" . " <encoding>" . ($encoding ? " {$encoding} " : "") . "</encoding>\n" . " </lang>\n"; } $xml .= " </languages>\n" . " <pages>\n"; foreach ($data['pages'] as $page => $strings) { $xml .= " <page key=\"" . XML_Util::replaceEntities($page) . "\">\n"; foreach ($strings as $str_id => $translations) { $xml .= " <string key=\"" . XML_Util::replaceEntities($str_id) . "\">\n"; foreach ($translations as $lang => $str) { $xml .= " <tr lang=\"{$lang}\"> " . XML_Util::replaceEntities($str) . " </tr>\n"; } $xml .= " </string>\n"; } $xml .= " </page>\n"; } $xml .= " </pages>\n" . "</translation2>\n"; return $xml; }
/** * check, whether string is valid XML name * * <p>XML names are used for tagname, attribute names and various * other, lesser known entities.</p> * <p>An XML name may only consist of alphanumeric characters, * dashes, undescores and periods, and has to start with a letter * or an underscore.</p> * * <code> * require_once 'XML/Util.php'; * * // verify tag name * $result = XML_Util::isValidName('invalidTag?'); * if (is_a($result, 'PEAR_Error')) { * print 'Invalid XML name: ' . $result->getMessage(); * } * </code> * * @param string $string string that should be checked * * @return mixed true, if string is a valid XML name, PEAR error otherwise * @access public * @static * @todo support for other charsets * @todo PEAR CS - unable to avoid 85-char limit on second preg_match */ function isValidName($string) { // check for invalid chars if (!preg_match('/^[[:alpha:]_]$/', $string[0])) { return XML_Util::raiseError('XML names may only start with letter ' . 'or underscore', XML_UTIL_ERROR_INVALID_START); } // check for invalid chars if (!preg_match('/^([[:alpha:]_]([[:alnum:]\\-\\.]*)?:)?[[:alpha:]_]([[:alnum:]\\_\\-\\.]+)?$/', $string)) { return XML_Util::raiseError('XML names may only contain alphanumeric ' . 'chars, period, hyphen, colon and underscores', XML_UTIL_ERROR_INVALID_CHARS); } // XML name is valid return true; }
/** * create a tag from an array * this method awaits an array in the following format * array( * 'qname' => $tagName, * 'attributes' => array(), * 'content' => $content, // optional * 'namespace' => $namespace // optional * 'namespaceUri' => $namespaceUri // optional * ) * * @access private * @param array $tag tag definition * @param boolean $replaceEntities whether to replace XML entities in content or not * @return string $string XML tag */ function _createXMLTag($tag, $replaceEntities = true) { if ($this->options['namespace'] !== null) { if (is_array($this->options['namespace'])) { $tag['qname'] = $this->options['namespace'][0] . ':' . $tag['qname']; } else { $tag['qname'] = $this->options['namespace'] . ':' . $tag['qname']; } } if ($this->options['indentAttributes'] !== false) { $multiline = true; $indent = str_repeat($this->options['indent'], $this->_tagDepth); if ($this->options['indentAttributes'] == '_auto') { $indent .= str_repeat(' ', strlen($tag['qname']) + 2); } else { $indent .= $this->options['indentAttributes']; } } else { $multiline = false; $indent = false; } if ($replaceEntities) { $replaceEntities = $this->options['replaceEntities']; } if (is_array($tag['content'])) { if (empty($tag['content'])) { $tag['content'] = ''; } } elseif (is_scalar($tag['content']) && (string) $tag['content'] == '') { $tag['content'] = ''; } if (is_scalar($tag['content']) || is_null($tag['content'])) { if ($this->options['encodeFunction']) { if ($replaceEntities === true) { $tag['content'] = call_user_func($this->options['encodeFunction'], $tag['content']); } $tag['attributes'] = array_map($this->options['encodeFunction'], $tag['attributes']); } $tag = XML_Util::createTagFromArray($tag, $replaceEntities, $multiline, $indent, $this->options['linebreak']); } elseif (is_array($tag['content'])) { $tag = $this->_serializeArray($tag['content'], $tag['qname'], $tag['attributes']); } elseif (is_object($tag['content'])) { $tag = $this->_serializeObject($tag['content'], $tag['qname'], $tag['attributes']); } elseif (is_resource($tag['content'])) { settype($tag['content'], 'string'); if ($this->options['encodeFunction']) { if ($replaceEntities === true) { $tag['content'] = call_user_func($this->options['encodeFunction'], $tag['content']); } $tag['attributes'] = array_map($this->options['encodeFunction'], $tag['attributes']); } $tag = XML_Util::createTagFromArray($tag, $replaceEntities); } return $tag; }
/** * serialize a token * * This method does the actual beautifying. * * @param array $token structure that should be serialized * * @return mixed * @access private * @todo split this method into smaller methods */ function _serializeToken($token) { switch ($token["type"]) { /* * serialize XML Element */ case XML_BEAUTIFIER_ELEMENT: $indent = $this->_getIndentString($token["depth"]); // adjust tag case if ($this->_options["caseFolding"] === true) { switch ($this->_options["caseFoldingTo"]) { case "uppercase": $token["tagname"] = strtoupper($token["tagname"]); $token["attribs"] = array_change_key_case($token["attribs"], CASE_UPPER); break; case "lowercase": $token["tagname"] = strtolower($token["tagname"]); $token["attribs"] = array_change_key_case($token["attribs"], CASE_LOWER); break; } } if ($this->_options["multilineTags"] == true) { $attIndent = $indent . str_repeat(" ", 2 + strlen($token["tagname"])); } else { $attIndent = null; } // check for children switch ($token["contains"]) { // contains only CData or is empty case XML_BEAUTIFIER_CDATA: case XML_BEAUTIFIER_EMPTY: if (sizeof($token["children"]) >= 1) { $data = $token["children"][0]["data"]; } else { $data = ''; } if (strstr($data, "\n")) { $data = "\n" . $this->_indentTextBlock($data, $token['depth'] + 1, true); } $xml = $indent . XML_Util::createTag($token["tagname"], $token["attribs"], $data, null, XML_UTIL_REPLACE_ENTITIES, $this->_options["multilineTags"], $attIndent) . $this->_options["linebreak"]; break; // contains mixed content // contains mixed content default: $xml = $indent . XML_Util::createStartElement($token["tagname"], $token["attribs"], null, $this->_options["multilineTags"], $attIndent) . $this->_options["linebreak"]; $cnt = count($token["children"]); for ($i = 0; $i < $cnt; $i++) { $xml .= $this->_serializeToken($token["children"][$i]); } $xml .= $indent . XML_Util::createEndElement($token["tagname"]) . $this->_options["linebreak"]; break; break; } break; /* * serialize CData */ /* * serialize CData */ case XML_BEAUTIFIER_CDATA: if ($token["depth"] > 0) { $xml = str_repeat($this->_options["indent"], $token["depth"]); } else { $xml = ""; } $xml .= XML_Util::replaceEntities($token["data"]) . $this->_options["linebreak"]; break; /* * serialize CData section */ /* * serialize CData section */ case XML_BEAUTIFIER_CDATA_SECTION: if ($token["depth"] > 0) { $xml = str_repeat($this->_options["indent"], $token["depth"]); } else { $xml = ""; } $xml .= '<![CDATA[' . $token["data"] . ']]>' . $this->_options["linebreak"]; break; /* * serialize entity */ /* * serialize entity */ case XML_BEAUTIFIER_ENTITY: if ($token["depth"] > 0) { $xml = str_repeat($this->_options["indent"], $token["depth"]); } else { $xml = ""; } $xml .= "&" . $token["name"] . ";" . $this->_options["linebreak"]; break; /* * serialize Processing instruction */ /* * serialize Processing instruction */ case XML_BEAUTIFIER_PI: $indent = $this->_getIndentString($token["depth"]); $xml = $indent . "<?" . $token["target"] . $this->_options["linebreak"] . $this->_indentTextBlock(rtrim($token["data"]), $token["depth"]) . $indent . "?>" . $this->_options["linebreak"]; break; /* * comments */ /* * comments */ case XML_BEAUTIFIER_COMMENT: $lines = count(explode("\n", $token["data"])); /* * normalize comment, i.e. combine it to one * line and remove whitespace */ if ($this->_options["normalizeComments"] && $lines > 1) { $comment = preg_replace("/\\s\\s+/s", " ", str_replace("\n", " ", $token["data"])); $lines = 1; } else { $comment = $token["data"]; } /* * check for the maximum length of one line */ if ($this->_options["maxCommentLine"] > 0) { if ($lines > 1) { $commentLines = explode("\n", $comment); } else { $commentLines = array($comment); } $comment = ""; for ($i = 0; $i < $lines; $i++) { if (strlen($commentLines[$i]) <= $this->_options["maxCommentLine"]) { $comment .= $commentLines[$i]; continue; } $comment .= wordwrap($commentLines[$i], $this->_options["maxCommentLine"]); if ($i != $lines - 1) { $comment .= "\n"; } } $lines = count(explode("\n", $comment)); } $indent = $this->_getIndentString($token["depth"]); if ($lines > 1) { $xml = $indent . "<!--" . $this->_options["linebreak"] . $this->_indentTextBlock($comment, $token["depth"] + 1, true) . $indent . "-->" . $this->_options["linebreak"]; } else { $xml = $indent . sprintf("<!-- %s -->", trim($comment)) . $this->_options["linebreak"]; } break; /* * xml declaration */ /* * xml declaration */ case XML_BEAUTIFIER_XML_DECLARATION: $indent = $this->_getIndentString($token["depth"]); $xml = $indent . XML_Util::getXMLDeclaration($token["version"], $token["encoding"], $token["standalone"]); break; /* * xml declaration */ /* * xml declaration */ case XML_BEAUTIFIER_DT_DECLARATION: $xml = $token["data"]; break; /* * all other elements */ /* * all other elements */ case XML_BEAUTIFIER_DEFAULT: default: $xml = XML_Util::replaceEntities($token["data"]); break; } return $xml; }
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>"; print "\n<br><br>\n"; /** * create an attribute string without replacing the entities */ $atts = array('series' => 'Starsky & Hutch', 'channel' => 'ABC'); print "creating a attribute string, entities in values already had been replaced:<br>"; print htmlentities(XML_Util::attributesToString($atts, true, false, false, false, XML_UTIL_ENTITIES_NONE)); print "\n<br><br>\n"; /** * using the array-syntax for attributesToString() */ $atts = array('series' => 'Starsky & Hutch', 'channel' => 'ABC'); print "using the array-syntax for attributesToString()<br>"; print htmlentities(XML_Util::attributesToString($atts, array('entities' => XML_UTIL_ENTITIES_NONE))); print "\n<br><br>\n";
/** * Returns a formatted string of the object * @param object $obj Container object to be output as string * @access public * @return string */ function toString(&$obj) { $indent = ''; if (!$obj->isRoot()) { // no indent for root $this->_deep++; $indent = str_repeat($this->options['indent'], $this->_deep); } else { // Initialize string with xml declaration $string = ''; if ($this->options['addDecl']) { $string .= XML_Util::getXMLDeclaration($this->options['version'], $this->options['encoding']); $string .= $this->options['linebreak']; } if (!empty($this->options['name'])) { $string .= '<' . $this->options['name'] . '>' . $this->options['linebreak']; $this->_deep++; $indent = str_repeat($this->options['indent'], $this->_deep); } } if (!isset($string)) { $string = ''; } switch ($obj->type) { case 'directive': $attributes = $this->options['useAttr'] ? $obj->attributes : array(); $string .= $indent . XML_Util::createTag($obj->name, $attributes, $obj->content, null, $this->options['useCData'] ? XML_UTIL_CDATA_SECTION : XML_UTIL_REPLACE_ENTITIES); $string .= $this->options['linebreak']; break; case 'comment': $string .= $indent . '<!-- ' . $obj->content . ' -->'; $string .= $this->options['linebreak']; break; case 'section': if (!$obj->isRoot()) { $string = $indent . '<' . $obj->name; $string .= $this->options['useAttr'] ? XML_Util::attributesToString($obj->attributes) : ''; } if ($children = count($obj->children)) { if (!$obj->isRoot()) { $string .= '>' . $this->options['linebreak']; } for ($i = 0; $i < $children; $i++) { $string .= $this->toString($obj->getChild($i)); } } if (!$obj->isRoot()) { if ($children) { $string .= $indent . '</' . $obj->name . '>' . $this->options['linebreak']; } else { $string .= '/>' . $this->options['linebreak']; } } else { if (!empty($this->options['name'])) { $string .= '</' . $this->options['name'] . '>' . $this->options['linebreak']; } } break; default: $string = ''; } if (!$obj->isRoot()) { $this->_deep--; } return $string; }
public function execute() { ini_set('max_execution_time', 0); $tp = SJB_System::getTemplateProcessor(); $file_info = isset($_FILES['import_file']) ? $_FILES['import_file'] : null; $encodingFromCharset = SJB_Request::getVar('encodingFromCharset', 'UTF-8'); $listingTypeID = SJB_Request::getVar('listing_type_id', null); $productSID = SJB_Request::getVar('product_sid', 0); $errors = array(); if ($listingTypeID && $productSID) { $acl = SJB_Acl::getInstance(); $resource = 'post_' . strtolower($listingTypeID); if (!$acl->isAllowed($resource, $productSID, 'product')) { $errors[] = 'You cannot import listings of this type under the selected product'; } } if (!empty($file_info)) { $extension = SJB_Request::getVar('file_type'); if (!SJB_ImportFile::isValidFileExtensionByFormat($extension, $file_info)) { $errors['DO_NOT_MATCH_SELECTED_FILE_FORMAT'] = true; } } if (empty($file_info) || $file_info['error'] || $errors) { if (isset($file_info['error']) && $file_info['error'] > 0) { $errors[SJB_UploadFileManager::getErrorId($file_info['error'])] = 1; } $listing_types = SJB_ListingTypeManager::getAllListingTypesInfo(); $products = SJB_ProductsManager::getProductsByProductType('post_listings'); $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize()); $tp->assign('listing_types', $listing_types); $tp->assign('products', $products); $tp->assign('errors', $errors); $tp->assign('charSets', SJB_HelperFunctions::getCharSets()); $tp->display('import_listings.tpl'); } else { $i18n = SJB_I18N::getInstance(); $csv_delimiter = SJB_Request::getVar('csv_delimiter', null); $activeStatus = SJB_Request::getVar('active', 0); $activationDate = SJB_Request::getVar('activation_date', date('Y-m-d')); $activationDate = $i18n->getInput('date', $activationDate); $non_existed_values_flag = SJB_Request::getVar('non_existed_values', null); $productInfo = SJB_ProductsManager::getProductInfoBySID($productSID); if (empty($productInfo['listing_duration'])) { $expirationDate = ''; } else { $timestamp = strtotime($activationDate . ' + ' . $productInfo['listing_duration'] . ' days'); $expirationDate = $i18n->getDate(date('Y-m-d', $timestamp)); } $extension = $_REQUEST['file_type']; if ($extension == 'xls') { $import_file = new SJB_ImportFileXLS($file_info); } elseif ($extension == 'csv') { $import_file = new SJB_ImportFileCSV($file_info, $csv_delimiter); } $import_file->parse($encodingFromCharset); $listing = $this->CreateListing(array(), $listingTypeID); $imported_data = $import_file->getData(); $isFileImported = true; $count = 0; $addedListingsSids = array(); $nonExistentUsers = array(); foreach ($imported_data as $key => $importedColumn) { if ($key == 1) { $imported_data_processor = new SJB_ImportedDataProcessor($importedColumn, $listing); continue; } if (!$importedColumn) { continue; } $count++; $listingInfo = $imported_data_processor->getData($non_existed_values_flag, $importedColumn); $doc = new DOMDocument(); foreach ($listing->getProperties() as $property) { if ($property->getType() == 'complex' && !empty($listingInfo[$property->id])) { $childFields = SJB_ListingComplexFieldManager::getListingFieldsInfoByParentSID($property->sid); $doc->loadXML($listingInfo[$property->id]); $results = $doc->getElementsByTagName($property->id . 's'); $listingInfo[$property->id] = array(); foreach ($results as $complexparent) { $i = 1; foreach ($complexparent->getElementsByTagName($property->id) as $result) { $resultXML = simplexml_import_dom($result); foreach ($childFields as $childField) { if (isset($resultXML->{$childField}['id'])) { $listingInfo[$property->id][$childField['id']][$i] = XML_Util::reverseEntities((string) $resultXML->{$childField}['id']); } } $i++; } } } elseif ($property->getType() == 'monetary' && !empty($listingInfo[$property->id])) { $value = $listingInfo[$property->id]; $listingInfo[$property->id] = array(); $listingInfo[$property->id]['value'] = $value; $defaultCurrency = SJB_CurrencyManager::getDefaultCurrency(); $currencyCode = !empty($listingInfo[$property->id . "Currency"]) ? $listingInfo[$property->id . "Currency"] : $defaultCurrency['currency_code']; $currency = SJB_CurrencyManager::getCurrencyByCurrCode($currencyCode); $listingInfo[$property->id]['add_parameter'] = !empty($currency['sid']) ? $currency['sid'] : ''; if (isset($listingInfo[$property->id . "Currency"])) { unset($listingInfo[$property->id . "Currency"]); } } elseif ($property->getType() == 'location') { $locationFields = array($property->id . '.Country', $property->id . '.State', $property->id . '.City', $property->id . '.ZipCode'); $locationFieldAdded = array(); foreach ($locationFields as $locationField) { if (array_key_exists($locationField, $listingInfo)) { switch ($locationField) { case $property->id . '.Country': $value = SJB_CountriesManager::getCountrySIDByCountryName($listingInfo[$locationField]); if (!$value) { $value = SJB_CountriesManager::getCountrySIDByCountryCode($listingInfo[$locationField]); } break; case $property->id . '.State': $value = SJB_StatesManager::getStateSIDByStateName($listingInfo[$locationField]); if (!$value) { $value = SJB_StatesManager::getStateSIDByStateCode($listingInfo[$locationField]); } break; default: $value = $listingInfo[$locationField]; break; } $listingInfo[$property->id][str_replace($property->id . '.', '', $locationField)] = $value; $locationFieldAdded[] = str_replace($property->id . '.', '', $locationField); } } if ($property->id == 'Location') { $locationFields = array('Country', 'State', 'City', 'ZipCode'); foreach ($locationFields as $locationField) { if (array_key_exists($locationField, $listingInfo) && !in_array($locationField, $locationFieldAdded) && !$listing->getProperty($locationField)) { switch ($locationField) { case 'Country': $value = SJB_CountriesManager::getCountrySIDByCountryName($listingInfo[$locationField]); if (!$value) { $value = SJB_CountriesManager::getCountrySIDByCountryCode($listingInfo[$locationField]); } break; case 'State': $value = SJB_StatesManager::getStateSIDByStateName($listingInfo[$locationField]); if (!$value) { $value = SJB_StatesManager::getStateSIDByStateCode($listingInfo[$locationField]); } break; default: $value = $listingInfo[$locationField]; break; } $listingInfo[$property->id][$locationField] = $value; } } } } } $listing = $this->CreateListing($listingInfo, $listingTypeID); $pictures = array(); if (isset($listingInfo['pictures'])) { $listing->addPicturesProperty(); $explodedPictures = explode(';', $listingInfo['pictures']); foreach ($explodedPictures as $picture) { if (!empty($picture)) { $pictures[] = $picture; } } $listing->setPropertyValue('pictures', count($pictures)); } $listing->addActiveProperty($activeStatus); $listing->addActivationDateProperty($activationDate); $listing->addExpirationDateProperty($expirationDate); SJB_ListingDBManager::setListingExpirationDateBySid($listing->sid); $listing->setProductInfo(SJB_ProductsManager::getProductExtraInfoBySID($productSID)); $listing->setPropertyValue('access_type', 'everyone'); $listing->setPropertyValue('status', 'approved'); foreach ($listing->getProperties() as $property) { if ($property->getType() == 'tree' && $property->value !== '') { try { $treeImportHelper = new SJB_FieldTreeImportHelper($property->value); $treeValues = $treeImportHelper->parseAndGetValues(); $listing->setPropertyValue($property->id, $treeValues); $listing->details->properties[$property->id]->type->property_info['value'] = $treeValues; } catch (Exception $e) { $listing->setPropertyValue($property->id, ''); $listing->details->properties[$property->id]->type->property_info['value'] = ''; SJB_Error::writeToLog('Listing Import. Tree Field Value Error: ' . $e->getMessage()); } } elseif ($property->id == 'ApplicationSettings' && !empty($listingInfo['ApplicationSettings'])) { if (preg_match("^[a-z0-9\\._-]+@[a-z0-9\\._-]+\\.[a-z]{2,}\$^iu", $listingInfo['ApplicationSettings'])) { $listingInfo['ApplicationSettings'] = array('value' => $listingInfo['ApplicationSettings'], 'add_parameter' => 1); } elseif (preg_match("^(https?:\\/\\/)^", $listingInfo['ApplicationSettings'])) { $listingInfo['ApplicationSettings'] = array('value' => $listingInfo['ApplicationSettings'], 'add_parameter' => 2); } else { $listingInfo['ApplicationSettings'] = array('value' => '', 'add_parameter' => ''); } //put empty if not valid email or url $listing->details->properties[$property->id]->type->property_info['value'] = $listingInfo['ApplicationSettings']; } elseif ($property->getType() == 'complex') { $childFields = SJB_ListingComplexFieldManager::getListingFieldsInfoByParentSID($property->sid); $complexChildValues = $property->value; foreach ($childFields as $childField) { if ($childField['type'] == 'complexfile' && !empty($complexChildValues[$childField['id']])) { $fieldInfo = SJB_ListingComplexFieldManager::getFieldInfoBySID($childField['sid']); if (!SJB_UploadFileManager::fileImport($listingInfo, $fieldInfo, $property->id)) { $isFileImported = false; } } if ($property->type->complex->details->properties[$childField['id']]->value == null) { $property->type->complex->details->properties[$childField['id']]->value = array(1 => ''); $property->type->complex->details->properties[$childField['id']]->type->property_info['value'] = array(1 => ''); } } } // The import of files at import of listings if (in_array($property->getType(), array('file', 'logo', 'video')) && $property->value !== '') { $fieldInfo = SJB_ListingFieldDBManager::getListingFieldInfoByID($property->id); if (!SJB_UploadFileManager::fileImport($listingInfo, $fieldInfo)) { $isFileImported = false; } } } if ($non_existed_values_flag == 'add') { $this->UpdateListValues($listing); } if ($listing->getUserSID()) { SJB_ListingManager::saveListing($listing); $listingSid = $listing->getSID(); SJB_Statistics::addStatistics('addListing', $listing->getListingTypeSID(), $listingSid); SJB_ListingManager::activateListingBySID($listingSid, false); if (!$this->fillGallery($listingSid, $pictures)) { $isFileImported = false; } $addedListingsSids[] = $listingSid; } else { $nonExistentUsers[] = $listingInfo['username']; $count--; } } SJB_BrowseDBManager::addListings($addedListingsSids); SJB_ProductsManager::incrementPostingsNumber($productSID, count($addedListingsSids)); if ($isFileImported && file_exists(SJB_System::getSystemSettings('IMPORT_FILES_DIRECTORY'))) { SJB_Filesystem::delete(SJB_System::getSystemSettings('IMPORT_FILES_DIRECTORY')); } $tp->assign('imported_listings_count', $count); $tp->assign('nonExistentUsers', $nonExistentUsers); $tp->display('import_listings_result.tpl'); } }