| 1 |
<?php |
<?php |
| 2 |
// $Id$ |
// $Id: xml.php,v 1.1 2008/09/25 06:45:42 t0talmeltd0wn Exp $ |
| 3 |
|
|
| 4 |
class XmlNode { |
class XmlNode { |
| 5 |
public $tag = ""; |
public $tag = ""; |
| 120 |
* Serialize an XML object. |
* Serialize an XML object. |
| 121 |
* |
* |
| 122 |
* @param $node |
* @param $node |
| 123 |
* The node to serialize. |
* The node to serialize, as an object or an array. |
| 124 |
* @param $op |
* @param $op |
| 125 |
* The serialization operation to perform. This should be 'open', 'body' or |
* The serialization operation to perform. This should be 'open', 'body' or |
| 126 |
* 'close'. |
* 'close'. |
| 127 |
*/ |
*/ |
| 128 |
function xmpp_server_xml_serialize($node, $op = NULL) { |
function xmpp_server_xml_serialize($node, $op = NULL) { |
| 129 |
$ret = ""; |
$ret = ""; |
| 130 |
|
|
| 131 |
|
if (!is_array($node)) { |
| 132 |
|
$node = (array)$node; |
| 133 |
|
} |
| 134 |
|
|
| 135 |
if ($op == NULL) { |
if ($op == NULL) { |
| 136 |
$op = $node->op; |
$op = $node['op']; |
| 137 |
} |
} |
| 138 |
|
|
| 139 |
//Serialize the opening tag. |
//Serialize the opening tag. |
| 140 |
if ($op == NULL || $op == 'open') { |
if ($op == NULL || $op == 'open') { |
| 141 |
$ret .= "<{$node->tag}"; |
$ret .= "<{$node['tag']}"; |
| 142 |
foreach ($node->options as $k => $v) { |
foreach ($node['options'] as $k => $v) { |
| 143 |
$ret .= " $k=\"". htmlentities($v) . "\""; |
$ret .= " $k=\"". htmlentities($v) . "\""; |
| 144 |
} |
} |
| 145 |
|
|
| 146 |
if ($op == NULL && empty($node->data) && !count($node->children)) { |
if ($op == NULL && empty($node['data']) && !count($node['children'])) { |
| 147 |
return $ret . "/>"; //Short tag support. |
return $ret . "/>"; //Short tag support. |
| 148 |
} |
} |
| 149 |
|
|
| 153 |
//Serialize our inner content. |
//Serialize our inner content. |
| 154 |
if ($op == NULL || $op == 'body') { |
if ($op == NULL || $op == 'body') { |
| 155 |
//Serialize children. |
//Serialize children. |
| 156 |
foreach ($node->children as $k => $v) { |
foreach ($node['children'] as $k => $v) { |
| 157 |
if (is_numeric($k)) { |
if (is_numeric($k)) { |
| 158 |
//Recursively serialize children. |
//Recursively serialize children. |
| 159 |
$ret .= xmpp_server_xml_serialize($v); |
$ret .= xmpp_server_xml_serialize($v); |
| 161 |
} |
} |
| 162 |
|
|
| 163 |
//Tack on our character data |
//Tack on our character data |
| 164 |
$ret .= $node->data; |
$ret .= $node['data']; |
| 165 |
} |
} |
| 166 |
|
|
| 167 |
//Serialize the closing tag. |
//Serialize the closing tag. |
| 168 |
if ($op == NULL || $op == 'close') { |
if ($op == NULL || $op == 'close') { |
| 169 |
$ret .= "</{$node->tag}>"; |
$ret .= "</{$node['tag']}>"; |
| 170 |
} |
} |
| 171 |
|
|
| 172 |
return $ret; |
return $ret; |