Пример #1
0
 /**
  * Encodes the given data to a specific data format.
  *
  * @param array $data
  * @param \SimpleXMLElement $xml
  *
  * @return string
  */
 public function format(array $data, $xml = null)
 {
     if (!isset($xml)) {
         $xml = new \SimpleXMLElement('<Response/>');
     }
     foreach ($data as $key => $value) {
         if (is_numeric($key)) {
             if (!is_array($value)) {
                 $key = get_class($value);
             } else {
                 $key = 'Data';
             }
         }
         if (is_array($value)) {
             $this->format($value, $xml->addChild($key));
         } else {
             if ($value instanceof ArrayableInterface) {
                 $this->format($value->toArray(), $xml->addChild($key));
             } else {
                 $xml->addChild($key, $value);
             }
         }
     }
     return $xml->asXML();
 }
 /**
  * Constructor
  */
 public function __construct()
 {
     $this->_ci =& get_instance();
     $this->_ci->load->library(array("core/string/string_core", "cache"));
     $this->_kml = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" . "<kml xmlns=\"http://www.opengis.net/kml/2.2\">" . "</kml>");
     $this->_kml->addChild("Document");
 }
Пример #3
0
 public function indexAction()
 {
     $url = $this->getRequest()->getParam('url');
     $xmlString = '<?xml version="1.0" standalone="yes"?><response></response>';
     $xml = new SimpleXMLElement($xmlString);
     if (strlen($url) < 1) {
         $xml->addChild('status', 'failed no url passed');
     } else {
         $shortid = $this->db->fetchCol("select * from urls where url = ?", $url);
         $config = Zend_Registry::getInstance();
         $sh = $config->get('configuration');
         if ($shortid[0]) {
             $hex = dechex($shortid[0]);
             $short = $sh->siteroot . $hex;
         } else {
             //if not insert then return the id
             $data = array('url' => $url, 'createdate' => date("Y-m-d h:i:s"), 'remoteip' => Pandamp_Lib_Formater::getRealIpAddr());
             $insert = $this->db->insert('urls', $data);
             $id = $this->db->lastInsertId('urls', 'id');
             $hex = dechex($id);
             $short = $sh->siteroot . $hex;
         }
         $xml->addChild('holurl', $short);
         $xml->addChild('status', 'success');
     }
     $out = $xml->asXML();
     //This returns the XML xmlreponse should be key value pairs
     $this->getResponse()->setHeader('Content-Type', 'text/xml')->setBody($out);
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender();
 }
Пример #4
0
 /**
  * @param DecoderInterface $decoder
  *
  * @return string
  */
 public function transform(DecoderInterface $decoder)
 {
     $xml = new \SimpleXMLElement('<xml/>');
     foreach ($decoder->getData() as $key => $value) {
         if (is_array($value)) {
             if (is_numeric($key)) {
                 $items = $xml->addChild('items');
                 $item = $items->addChild('item');
             } else {
                 $item = $xml->addChild($key);
             }
             foreach ($value as $k => $v) {
                 if (is_array($v)) {
                     continue;
                 }
                 $item->addChild($k, $v);
             }
             continue;
         }
         $xml->addChild($key, $value);
     }
     $dom = new \DOMDocument('1.0', 'UTF-8');
     $dom->preserveWhiteSpace = false;
     $dom->formatOutput = true;
     $dom->loadXML($xml->asXML());
     return $dom->saveXML();
 }
Пример #5
0
 protected static function _recursiveXmlEncode($valueToEncode, $rootNodeName = 'data', &$xml = null)
 {
     if (null == $xml) {
         $xml = new SimpleXMLElement('<' . $rootNodeName . '/>');
     }
     foreach ($valueToEncode as $key => $value) {
         if (is_numeric($key)) {
             $key = $rootNodeName;
         }
         if ($key == self::XML_ATTRIBUTES) {
             foreach ($value as $attrName => $attrValue) {
                 $xml->addAttribute($attrName, $attrValue);
             }
         } else {
             // Filter non valid XML characters
             $key = preg_replace('/[^a-z0-9\\-\\_\\.\\:]/i', '', $key);
             if (is_array($value)) {
                 $node = self::_isAssoc($value) ? $xml->addChild($key) : $xml;
                 self::_recursiveXmlEncode($value, $key, $node);
             } else {
                 $value = htmlspecialchars($value, null, 'UTF-8');
                 //                    $value = htmlentities($value, null, 'UTF-8');
                 $xml->addChild($key, $value);
             }
         }
     }
     return $xml;
 }
Пример #6
0
 /**
  * Populate $xml with entries from $data array|DataObject.
  *
  * @param DataObject|array $data
  * @param \SimpleXMLElement $xml
  */
 private function _convertToXml($data, \SimpleXMLElement &$xml, $path = '')
 {
     if ($data instanceof DataObject) {
         $data = $data->getData();
     }
     foreach ($data as $key => $value) {
         if (is_int($key)) {
             /* this is array nodes with integer indexes */
             $name = $this->_namingStrategy->getNameForKey($key, $path);
             $newPath = $path . INamingStrategy::PS . $name;
             $arrayNode = $xml->addChild($name);
             if (is_array($value)) {
                 $this->_convertToXml($value, $arrayNode, $newPath);
             } elseif ($value instanceof \Flancer32\Lib\DataObject) {
                 $this->_convertToXml($value, $arrayNode, $newPath);
             } else {
                 throw new \Exception('Data in array nodes should not be simple, array or DataObject is expected.');
             }
         } else {
             /* this is XML node, not array subnode */
             $name = $this->_namingStrategy->getNameForKey($key, $path);
             $newPath = $path . INamingStrategy::PS . $name;
             if (is_array($value)) {
                 $subnode = $xml->addChild($name);
                 $this->_convertToXml($value, $subnode, $newPath);
             } elseif ($value instanceof \Flancer32\Lib\DataObject) {
                 $subnode = $xml->addChild($name);
                 $this->_convertToXml($value, $subnode, $newPath);
             } else {
                 $xml->addChild($name, htmlspecialchars($value));
             }
         }
     }
 }
    public function serializeToXml()
    {
        $strXml = <<<EOF
<?xml version="1.0" encoding="utf-8"?>
<LiveChannelConfiguration>
</LiveChannelConfiguration>
EOF;
        $xml = new \SimpleXMLElement($strXml);
        if (isset($this->description)) {
            $xml->addChild('Description', $this->description);
        }
        if (isset($this->status)) {
            $xml->addChild('Status', $this->status);
        }
        $node = $xml->addChild('Target');
        $node->addChild('Type', $this->type);
        if (isset($this->fragDuration)) {
            $node->addChild('FragDuration', $this->fragDuration);
        }
        if (isset($this->fragCount)) {
            $node->addChild('FragCount', $this->fragCount);
        }
        if (isset($this->playListName)) {
            $node->addChild('PlayListName', $this->playListName);
        }
        return $xml->asXML();
    }
Пример #8
0
 public function generate_xml($root, $tag_configuration)
 {
     $xml = new SimpleXMLElement('<oml:' . $root . ' xmlns:oml="http://openml.org/openml"/>');
     // first obtain the indices
     $indices = array();
     foreach ($tag_configuration as $key => $value) {
         $indices = array_merge($indices, array_keys($value));
     }
     sort($indices);
     foreach ($indices as $index) {
         foreach ($tag_configuration as $tag_type => $tags) {
             foreach ($tags as $tag_index => $tag_name) {
                 if ($tag_index == $index) {
                     if ($this->CI->input->post($tag_name)) {
                         if ($tag_type == 'csv') {
                             if (is_array($this->CI->input->post($tag_name))) {
                                 $values_exploded = $this->CI->input->post($tag_name);
                             } else {
                                 $values_exploded = explode(',', $this->CI->input->post($tag_name));
                             }
                             foreach ($values_exploded as $value) {
                                 $xml->addChild('oml:' . $tag_name, $value);
                             }
                         } else {
                             // TODO: add support for plain and array.
                             $value = $this->CI->input->post($tag_name);
                             $xml->addChild('oml:' . $tag_name, str_replace('&', '&amp;', htmlentities($value)));
                         }
                     }
                 }
             }
         }
     }
     return $xml->asXML();
 }
Пример #9
0
		protected function _ConstructPostData($postData)
		{

			$billingDetails = $this->GetBillingDetails();

			$qbXML = new SimpleXMLElement('<?qbmsxml version="2.0"?><QBMSXML />');
			$signOnDesktop = $qbXML->addChild('SignonMsgsRq')->addChild('SignonDesktopRq');
			$signOnDesktop->addChild('ClientDateTime', date('Y-m-d\TH:i:s'));
			$signOnDesktop->addChild('ApplicationLogin', $this->GetValue('ApplicationLogin'));
			$signOnDesktop->addChild('ConnectionTicket', $this->GetValue('ConnectionTicket'));
			$signOnDesktop->addChild('Language', 'English');
			$signOnDesktop->addChild('AppID', $this->GetValue('AppID'));
			$signOnDesktop->addChild('AppVer', '1.0');

			$cardChargeRequest = $qbXML->addChild('QBMSXMLMsgsRq')->addChild('CustomerCreditCardChargeRq');
			$cardChargeRequest->addChild('TransRequestID', $this->GetCombinedOrderId());
			$cardChargeRequest->addChild('CreditCardNumber', $postData['ccno']);
			$cardChargeRequest->addChild('ExpirationMonth', $postData['ccexpm']);
			$cardChargeRequest->addChild('ExpirationYear', $postData['ccexpy']);
			$cardChargeRequest->addChild('IsECommerce', 'true');
			$cardChargeRequest->addChild('Amount', $this->GetGatewayAmount());
			$cardChargeRequest->addChild('NameOnCard', isc_substr($postData['name'], 0, 30));
			$cardChargeRequest->addChild('CreditCardAddress', isc_substr($billingDetails['ordbillstreet1'], 0, 30));
			$cardChargeRequest->addChild('CreditCardPostalCode', isc_substr($billingDetails['ordbillzip'], 0, 9));
			$cardChargeRequest->addChild('SalesTaxAmount', $this->GetTaxCost());
			$cardChargeRequest->addChild('CardSecurityCode', $postData['cccvd']);
			return $qbXML->asXML();
		}
Пример #10
0
 /**
  * Преобразовать PHP-массив в XML
  *
  * Метод также используется в PHPUnit тестах сервисов
  *
  * @param array $data
  * @param \SimpleXMLElement $xmlBlank
  * @param string $itemName
  */
 public function arrayToXml($data, \SimpleXMLElement &$xmlBlank, $itemName = 'item')
 {
     foreach ($data as $key => $value) {
         if (is_array($value) || is_object($value)) {
             if (!is_numeric($key)) {
                 $subnode = $xmlBlank->addChild((string) $key);
                 $this->arrayToXml($value, $subnode, $itemName);
             } else {
                 $subnode = $xmlBlank->addChild($itemName);
                 $this->arrayToXml($value, $subnode, $itemName);
             }
         } else {
             $val = $value;
             if (is_bool($value)) {
                 $val = $value ? 'true' : 'false';
             } else {
                 if (is_int($value)) {
                     $val = (int) $value;
                 } else {
                     $val = htmlspecialchars("{$value}");
                 }
             }
             if (!is_numeric($key)) {
                 $xmlBlank->addChild("{$key}", $val);
             } else {
                 $xmlBlank->addChild($itemName, $val);
             }
         }
     }
 }
 /**
  * Generate the sitemap file and replace any output with the valid XML of the sitemap
  * 
  * @param string $type Type of sitemap to be generated. Use 'urlset' for a normal sitemap. Use 'sitemapindex' for a sitemap index file.
  * @access public
  * @return void
  */
 public function output($type = 'urlset')
 {
     $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" ?><' . $type . '/>');
     $xml->addAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
     if ($type == 'urlset') {
         foreach ($this->urls as $url) {
             $child = $xml->addChild('url');
             $child->addChild('loc', strtolower($url->loc));
             if (isset($url->lastmod)) {
                 $child->addChild('lastmod', $url->lastmod);
             }
             if (isset($url->changefreq)) {
                 $child->addChild('changefreq', $url->changefreq);
             }
             if (isset($url->priority)) {
                 $child->addChild('priority', number_format($url->priority, 1));
             }
         }
     } elseif ($type == 'sitemapindex') {
         foreach ($this->urls as $url) {
             $child = $xml->addChild('sitemap');
             $child->addChild('loc', strtolower($url->loc));
             if (isset($url->lastmod)) {
                 $child->addChild('lastmod', $url->lastmod);
             }
         }
     }
     $this->output->set_content_type('application/xml')->set_output($xml->asXml());
 }
Пример #12
0
 static function buildBundlePackage($bundleName, $moduleList, $manifestData, $buildPath)
 {
     $fileName = $bundleName . '.zip';
     if (is_file($buildPath . '/' . $fileName)) {
         unlink($buildPath . '/' . $fileName);
     }
     $tmpPath = "build/{$bundleName}";
     @mkdir($tmpPath);
     foreach ($moduleList as $moduleName) {
         self::buildModulePackage($moduleName, $tmpPath);
     }
     $manifestDoc = new SimpleXMLElement("<?xml version='1.0'?><module/>");
     $manifestDoc->addChild('name', $bundleName);
     $manifestDoc->addChild('version', $manifestData['version']);
     $manifestDoc->addChild('modulebundle', 'true');
     $xmlDependencies = $manifestDoc->addChild('dependencies');
     $xmlDependencies->addChild('vtiger_version', $manifestData['vtiger_version']);
     $xmlDependencies->addChild('vtiger_max_version', $manifestData['vtiger_max_version']);
     $xmlModuleList = $manifestDoc->addChild('modulelist');
     $index = 1;
     foreach ($moduleList as $moduleName) {
         $xmlModule = $xmlModuleList->addChild('dependent_module');
         $xmlModule->addChild('name', $moduleName);
         $xmlModule->addChild('install_sequence', $index);
         $xmlModule->addChild('filepath', $moduleName . '.zip');
         $index++;
     }
     $manifestDoc->asXML($tmpPath . '/' . 'manifest.xml');
     $zip = new Vtiger_Zip($buildPath . '/' . $fileName);
     $zip->addFile($tmpPath . '/' . 'manifest.xml', 'manifest.xml');
     foreach ($moduleList as $module) {
         $zip->addFile($tmpPath . '/' . $module . '.zip', $module . '.zip');
     }
     $zip->save();
 }
Пример #13
0
 public static function arrayToXml(array $data, \SimpleXMLElement $xml, $parentKey = null, $keyFilterCallback = null)
 {
     foreach ($data as $k => $v) {
         if (!is_numeric($k) && is_callable($keyFilterCallback)) {
             $k = call_user_func($keyFilterCallback, $k);
         }
         if (is_array($v)) {
             if (!is_numeric($k)) {
                 self::arrayToXml($v, $xml->addChild($k), $k, $keyFilterCallback);
             } else {
                 self::arrayToXml($v, $xml->addChild(Inflector::singularize($parentKey)), null, $keyFilterCallback);
             }
         } else {
             if (!is_numeric($k)) {
                 $xml->addChildWithCDATA($k, $v);
             } else {
                 if (!is_null($parentKey)) {
                     $xml->addChildWithCDATA(Inflector::singularize($parentKey), $v);
                 } else {
                     throw new \Exception("Array To xml forma error: invalid element name {$k}");
                 }
             }
         }
     }
     return $xml;
 }
Пример #14
0
 /**
  * @param MessageInterface|Message $message
  * @return mixed|void
  * @throws RuntimeException
  */
 public function send(MessageInterface $message)
 {
     $config = $this->getSenderOptions();
     $serviceURL = "http://letsads.com/api";
     $body = new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><request></request>');
     $auth = $body->addChild('auth');
     $auth->addChild('login', $config->getUsername());
     $auth->addChild('password', $config->getPassword());
     $messageXML = $body->addChild('message');
     $messageXML->addChild('from', $config->getSender());
     $messageXML->addChild('text', $message->getMessage());
     $messageXML->addChild('recipient', $message->getRecipient());
     $client = new Client();
     $client->setMethod(Request::METHOD_POST);
     $client->setUri($serviceURL);
     $client->setRawBody($body->asXML());
     $client->setOptions(['sslverifypeer' => false, 'sslallowselfsigned' => true]);
     try {
         $response = $client->send();
     } catch (Client\Exception\RuntimeException $e) {
         throw new RuntimeException("Failed to send sms", null, $e);
     }
     try {
         $responseXML = new \SimpleXMLElement($response->getBody());
     } catch (\Exception $e) {
         throw new RuntimeException("Cannot parse response", null, $e);
     }
     if ($responseXML->name === 'error') {
         throw new RuntimeException("LetsAds return error (" . $responseXML->description . ')');
     }
 }
Пример #15
0
 /** Returns the group/key config as XML.
  * @return mixed
  */
 public static function export()
 {
     $xml = new \SimpleXMLElement('<xml/>');
     $groupConfigList = new Object\KeyValue\GroupConfig\Listing();
     $groupConfigList->load();
     $groupConfigItems = $groupConfigList->getList();
     $groups = $xml->addChild('groups');
     foreach ($groupConfigItems as $item) {
         $group = $groups->addChild('group');
         $group->addChild("id", $item->getId());
         $group->addChild("name", $item->getName());
         $group->addChild("description", $item->getDescription());
     }
     $keyConfigList = new Object\KeyValue\KeyConfig\Listing();
     $keyConfigList->load();
     $keyConfigItems = $keyConfigList->getList();
     $keys = $xml->addChild('keys');
     foreach ($keyConfigItems as $item) {
         $key = $keys->addChild('key');
         $id = $key->addChild('id', $item->getId());
         $name = $key->addChild('name', $item->getName());
         $description = $key->addChild('description', $item->getDescription());
         $type = $key->addChild('type', $item->getType());
         $unit = $key->addChild('unit', $item->getUnit());
         $group = $key->addChild('group', $item->getGroup());
         $possiblevalues = $key->addChild('possiblevalues', $item->getPossibleValues());
     }
     return $xml->asXML();
 }
Пример #16
0
 private static function setXml()
 {
     $xml = new \SimpleXMLElement("<?xml version='1.0' encoding='ISO-8859-1'?> <requisicao-transacao id='" . self::$pedido_id . "' versao='1.1.1'/>");
     $dados_ec = $xml->addChild('dados-ec');
     $dados_ec->addChild('numero', self::$cielo_numero);
     $dados_ec->addChild('chave', self::$cielo_chave);
     $dados_portador = $xml->addChild('dados-portador');
     $dados_portador->addChild('numero', self::$numero_cartao);
     $dados_portador->addChild('validade', self::$ano . self::$mes);
     $dados_portador->addChild('indicador', self::$indicador);
     $dados_portador->addChild('codigo-seguranca', self::$cvv);
     $dados_portador->addChild('nome-portador', 'teste');
     $dados_pedido = $xml->addChild('dados-pedido');
     $dados_pedido->addChild('numero', self::$pedido_id);
     $dados_pedido->addChild('valor', self::$valor);
     $dados_pedido->addChild('moeda', '986');
     $dados_pedido->addChild('data-hora', date('Y-m-d\\TH:i:s'));
     $dados_pedido->addChild('descricao', 'sd');
     $dados_pedido->addChild('idioma', 'PT');
     $forma_pagamento = $xml->addChild('forma-pagamento');
     $forma_pagamento->addChild('bandeira', self::$bandeira);
     $forma_pagamento->addChild('produto', self::$produto);
     $forma_pagamento->addChild('parcelas', self::$parcelas);
     $xml->addChild('url-retorno', 'http://webearte.com.br');
     $xml->addChild('autorizar', self::$autorizar);
     $xml->addChild('capturar', self::$captura);
     return $xml->asXml();
 }
Пример #17
0
 /**
  * Method to create a Picasa Album
  *
  * @param   string  $userID    ID of user
  * @param   string  $title     New album title
  * @param   string  $access    New album access settings
  * @param   string  $summary   New album summary
  * @param   string  $location  New album location
  * @param   int     $time      New album timestamp
  * @param   array   $keywords  New album keywords
  *
  * @return  mixed  Data from Google.
  *
  * @since   12.3
  */
 public function createAlbum($userID = 'default', $title = '', $access = 'private', $summary = '', $location = '', $time = false, $keywords = array())
 {
     if ($this->isAuthenticated()) {
         $time = $time ? $time : time();
         $title = $title != '' ? $title : date('F j, Y');
         $xml = new SimpleXMLElement('<entry></entry>');
         $xml->addAttribute('xmlns', 'http://www.w3.org/2005/Atom');
         $xml->addChild('title', $title);
         $xml->addChild('summary', $summary);
         $xml->addChild('gphoto:location', $location, 'http://schemas.google.com/photos/2007');
         $xml->addChild('gphoto:access', $access);
         $xml->addChild('gphoto:timestamp', $time);
         $media = $xml->addChild('media:group', '', 'http://search.yahoo.com/mrss/');
         $media->addChild('media:keywords', implode($keywords, ', '));
         $cat = $xml->addChild('category', '');
         $cat->addAttribute('scheme', 'http://schemas.google.com/g/2005#kind');
         $cat->addAttribute('term', 'http://schemas.google.com/photos/2007#album');
         $url = 'https://picasaweb.google.com/data/feed/api/user/' . urlencode($userID);
         $jdata = $this->query($url, $xml->asXML(), array('GData-Version' => 2, 'Content-type' => 'application/atom+xml'), 'post');
         $xml = $this->safeXML($jdata->body);
         return new JGoogleDataPicasaAlbum($xml, $this->options, $this->auth);
     } else {
         return false;
     }
 }
Пример #18
0
 /**
  * @return \SimpleXMLElement|String
  */
 public function xmlNode()
 {
     $rootNode = new \SimpleXMLElement('<' . $this->feedName() . '></' . $this->feedName() . '>');
     $rootNode->addChild('SKU', $this->sku());
     $rootNode->addChild('Quantity', $this->stock());
     return $rootNode;
 }
Пример #19
0
 private function array_to_xml(array $arr, SimpleXMLElement $xml)
 {
     foreach ($arr as $k => $v) {
         is_array($v) ? $this->array_to_xml($v, $xml->addChild($k)) : $xml->addChild($k, $v);
     }
     return $xml;
 }
Пример #20
0
 /**
  * simple example without groups:
  *
  * $data = array(
  *     "option1" => "description",
  *     "option2" => "description"
  * )
  *
  * example with groups:
  *
  * $data = array(
  *     "label1" => array(
  *         "option1" => "description",
  *         "option2" => "description"
  *     ),
  *     "label2" => array(
  *         "option3" => "description",
  *         "option4" => "description"
  *     )
  * )
  *
  * @param mixed[] $data
  * @return SimpleXMLElement
  */
 public function __construct($data)
 {
     $select = new SimpleXMLElement("<select />");
     if (is_array($data) && count($data)) {
         // only proceed if $data is a non-empty array
         foreach ($data as $label => $group) {
             if (is_array($group)) {
                 // groups are used
                 $optgroup = $select->addChild("optgroup");
                 $optgroup->addAttribute("label", $label);
                 foreach ($group as $value => $item) {
                     $option = $optgroup->addChild("option", $item);
                     if (is_int($value)) {
                         $value = $item;
                     }
                     $option->addAttribute("value", $value);
                 }
             } else {
                 // no groups are used
                 $option = $select->addChild("option", $group);
                 if (is_int($label)) {
                     $label = $group;
                 }
                 $option->addAttribute("value", $label);
             }
         }
     }
     return $select;
 }
Пример #21
0
 protected function buildMessageXml($recipient, $message)
 {
     if (strpos($recipient, '+') !== 0) {
         $recipient = '+' . $recipient;
     }
     $xml = new \SimpleXMLElement('<MESSAGES/>');
     $authentication = $xml->addChild('AUTHENTICATION');
     $authentication->addChild('PRODUCTTOKEN', $this->product_token);
     $msg = $xml->addChild('MSG');
     $msg->addChild('FROM', $this->from);
     $msg->addChild('TO', $recipient);
     if ($this->unicode_msg) {
         $msg->addChild('DCS', 8);
     }
     $len = mb_strlen($message);
     if (!$this->unicode_msg && $len >= 160) {
         $msg->addChild('MINIMUMNUMBEROFMESSAGEPARTS', 1);
         $msg->addChild('MAXIMUMNUMBEROFMESSAGEPARTS', ceil($len / 153));
     } else {
         if ($this->unicode_msg && $len >= 70) {
             $msg->addChild('MINIMUMNUMBEROFMESSAGEPARTS', 1);
             $msg->addChild('MAXIMUMNUMBEROFMESSAGEPARTS', ceil($len / 70));
         }
     }
     $msg->addChild('BODY', $message);
     return $xml->asXML();
 }
Пример #22
0
 public function asElement()
 {
     $element = new \SimpleXMLElement('<credential/>');
     $element->addChild('profile-id', $this->_profileId);
     $element->addChild('securitycode', $this->_securityCode);
     return $element;
 }
Пример #23
0
 /**
  * @param string $url
  * @param int $lastmod Timestamp
  * @param string $changefreq
  * @param real $priority
  */
 private function addUrlToSitemap($url, $lastmod = 0, $changefreq = self::NODE_CHANGEFREQ_MONTHLY, $priority = 0.5)
 {
     if (empty($url)) {
         throw new \InvalidArgumentException('Параметр $url не может быть пустым!');
     }
     if (substr($url, 0, 1) == '/') {
         $url = $this->getProtocol() . '://' . $_SERVER['HTTP_HOST'] . $url;
     }
     $ue = $this->sxe->addChild('url');
     $ue->addChild('loc', htmlspecialchars($url));
     if (!empty($lastmod)) {
         $ue->addChild('lastmod', date_format(new \DateTime("@" . (int) $lastmod), 'Y-m-d'));
     }
     if (!empty($changefreq)) {
         $ue->addChild('changefreq', (string) $changefreq);
     }
     if (!empty($priority)) {
         $ue->addChild('priority', (double) $priority);
     }
     /*
      *  <url>
      *      <loc>http://www.example.com/</loc>
      *      <lastmod>2005-01-01</lastmod>
      *      <changefreq>monthly</changefreq>
      *      <priority>0.8</priority>
      *  </url>   
      */
 }
Пример #24
0
 protected function arrayToXML($data_array, \SimpleXMLElement $XML)
 {
     $consecutive_counter = 0;
     foreach ($data_array as $key => $value) {
         if (is_array($value)) {
             if (!is_numeric($key)) {
                 $subnode = $XML->addChild($key);
                 $this->arrayToXML($value, $subnode);
             } else {
                 $subnode = $XML->addChild($XML->getName() . '_' . $this->array_item_name);
                 if ($key != $consecutive_counter) {
                     $subnode->addAttribute($this->array_item_attribute, $key);
                 }
                 $this->arrayToXML($value, $subnode);
             }
         } else {
             if (!is_numeric($key)) {
                 $XML->addAttribute($key, $value);
             } else {
                 $subnode = $XML->addChild($this->array_item_name, str_replace('&', '&amp;', $value));
                 if ($key != $consecutive_counter) {
                     $subnode->addAttribute($this->array_item_attribute, $key);
                 }
             }
         }
         if (is_numeric($key)) {
             $consecutive_counter++;
         }
     }
 }
Пример #25
0
 /**
  * Build the XML for an issue
  * @param  array             $params for the new/updated issue data
  * @return \SimpleXMLElement
  */
 private function buildXML(array $params = array())
 {
     $xml = new \SimpleXMLElement('<?xml version="1.0"?><issue></issue>');
     foreach ($params as $k => $v) {
         if ('custom_fields' === $k && is_array($v)) {
             $custom_fields_item = $xml->addChild('custom_fields', '');
             $custom_fields_item->addAttribute('type', 'array');
             foreach ($v as $field) {
                 $item = $custom_fields_item->addChild('custom_field', '');
                 $item->addAttribute('id', (int) $field['id']);
                 $item->addChild('value', $field['value']);
             }
         } elseif ('watcher_user_ids' === $k && is_array($v)) {
             $watcher_user_ids = $xml->addChild('watcher_user_ids', '');
             $watcher_user_ids->addAttribute('type', 'array');
             foreach ($v as $watcher) {
                 $watcher_user_ids->addChild('watcher_user_id', (int) $watcher);
             }
         } elseif ('uploads' === $k && is_array($v)) {
             $uploads_item = $xml->addChild('uploads', '');
             $uploads_item->addAttribute('type', 'array');
             foreach ($v as $upload) {
                 $upload_item = $uploads_item->addChild('upload', '');
                 foreach ($upload as $upload_k => $upload_v) {
                     $upload_item->addChild($upload_k, $upload_v);
                 }
             }
         } else {
             $xml->addChild($k, $v);
         }
     }
     return $xml;
 }
Пример #26
0
/**
 * @param array $data
 * @param SimpleXMLElement $xml
 * @return SimpleXMLElement
 */
function array2xml(array $data, SimpleXMLElement $xml)
{
    foreach ($data as $k => $v) {
        is_array($v) ? array2xml($v, $xml->addChild($k)) : $xml->addChild($k, $v);
    }
    return $xml;
}
Пример #27
0
 /**
  * Function, that actually recursively transforms array to xml
  *
  * @param array $array
  * @param string $rootName
  * @param \SimpleXMLElement $xml
  * @return \SimpleXMLElement
  * @throws Exception
  */
 private function _assocToXml(array $array, $rootName, \SimpleXMLElement $xml)
 {
     $hasNumericKey = false;
     $hasStringKey = false;
     foreach ($array as $key => $value) {
         if (!is_array($value)) {
             if (is_string($key)) {
                 if ($key === $rootName) {
                     throw new Exception('Associative key must not be the same as its parent associative key.');
                 }
                 $hasStringKey = true;
                 $xml->addChild($key, $value);
             } elseif (is_int($key)) {
                 $hasNumericKey = true;
                 $xml->addChild($key, $value);
             }
         } else {
             $xml->addChild($key);
             self::_assocToXml($value, $key, $xml->{$key});
         }
     }
     if ($hasNumericKey && $hasStringKey) {
         throw new Exception('Associative and numeric keys must not be mixed at one level.');
     }
     return $xml;
 }
Пример #28
0
 /**
  * Add track to xml 
  */
 protected function setTrack()
 {
     if (!$this->Context->hasTrackdata()) {
         return;
     }
     $Starttime = $this->Context->activity()->timestamp();
     $Trackdata = new Trackdata\Loop($this->Context->trackdata());
     $Route = $this->Context->hasRoute() && $this->Context->route()->hasPositionData() ? new Route\Loop($this->Context->route()) : null;
     $hasHeartrate = $this->Context->trackdata()->has(Trackdata\Object::HEARTRATE);
     $Track = $this->Activity->addChild('Track');
     $Track->addAttribute('StartTime', $this->timeToString($Starttime));
     while ($Trackdata->nextStep()) {
         $Point = $Track->addChild('pt');
         $Point->addAttribute('tm', $Trackdata->time());
         if (NULL !== $Route) {
             $Route->nextStep();
             $Point->addAttribute('lat', $Route->latitude());
             $Point->addAttribute('lon', $Route->longitude());
             $Point->addAttribute('ele', $Route->current(Route\Object::ELEVATIONS_ORIGINAL));
         }
         if ($hasHeartrate) {
             $Point->addAttribute('hr', $Trackdata->current(Trackdata\Object::HEARTRATE));
         }
     }
 }
Пример #29
0
 public function asXML()
 {
     $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" ?><item></item>', LIBXML_NOERROR | LIBXML_ERR_NONE | LIBXML_ERR_FATAL);
     $xml->addChild('title', $this->title);
     $xml->addChild('link', $this->url);
     $xml->addChild('description', $this->description);
     foreach ($this->categories as $category) {
         $element = $xml->addChild('category', $category[0]);
         if (isset($category[1])) {
             $element->addAttribute('domain', $category[1]);
         }
     }
     if ($this->guid) {
         $guid = $xml->addChild('guid', $this->guid);
         if ($this->isPermalink) {
             $guid->addAttribute('isPermaLink', 'true');
         }
     }
     if ($this->pubDate !== null) {
         $xml->addChild('pubDate', date(DATE_RSS, $this->pubDate));
     }
     if (is_array($this->enclosure) && count($this->enclosure) == 3) {
         $element = $xml->addChild('enclosure');
         $element->addAttribute('url', $this->enclosure['url']);
         $element->addAttribute('type', $this->enclosure['type']);
         if ($this->enclosure['length']) {
             $element->addAttribute('length', $this->enclosure['length']);
         }
     }
     if (!empty($this->author)) {
         $xml->addChild('author', $this->author);
     }
     return $xml;
 }
Пример #30
0
 /**
  *
  * @param \SimpleXmlElement $xml
  * @param object $obj
  *
  * @throws \Exception
  */
 private function appendObjectProperties(\SimpleXMLElement $xml, $obj)
 {
     $clsMeta = new ClassMetadata($obj, $this->configuration);
     foreach ($clsMeta->getProperties() as $prop) {
         $propName = $prop->getName();
         $nodeName = "xmlns:" . $prop->getXmlNodeName();
         $value = $obj->{$propName};
         if (is_object($value)) {
             $this->appendObjectProperties($xml->addChild($nodeName), $value);
         } elseif (is_string($value) && $prop->isScalarValue()) {
             $xml[0] = $value;
         } elseif (is_string($value) && $prop->isAttribute()) {
             $xml->addAttribute($prop->getName(), $value);
         } elseif (is_string($value)) {
             $xml->addChild($nodeName, $value);
         } elseif ((is_int($value) || is_float($value)) && $prop->isScalarValue()) {
             $xml[0] = (string) $value;
         } elseif (is_null($value)) {
             continue;
         } elseif (is_array($value)) {
             if (count($value) == 0) {
                 continue;
             }
             foreach ($value as $itemValue) {
                 if (is_object($itemValue)) {
                     $this->appendObjectProperties($xml->addChild($nodeName), $itemValue);
                 } else {
                     throw new \Exception("Failed to serialize. Only object node arrays supported");
                 }
             }
         } else {
             throw new \Exception("Not implemented yet. Prop: {$propName} cannot be converted to xml node");
         }
     }
 }