31 $dtk = array_keys( $data );
32 $root = array_shift( $dtk );
33 $xml =
new SimpleXMLElement(
'<?xml version="1.0" encoding="utf-8"?><' . $root .
'></' . $root .
'>' );
34 # $xml->registerXPathNamespace( 'xhtml', 'http://www.w3.org/1999/xhtml' ); 38 foreach( $data as $key => $value ) {
40 $key = str_replace(
':',
'|', $key );
42 if( is_array( $value ) ) {
44 $keys = array_keys( $value );
48 foreach( $value as $attrName => $attrVal ) {
49 # $xml[ $attrName ] = $attrVal; 50 # if( strpos( $attrName, ':' ) ) { 51 # $xml->addAttribute( $attrName, $attrVal, substr( $attrName, 0, strpos( $attrName, ':' ) ) ); 53 $attrName = str_replace(
':',
'|', $attrName );
54 $xml->addAttribute( $attrName, $attrVal );
58 }
elseif( array_shift( $keys ) ===
'#' ) {
60 $node =
$xml->addChild( $key, $value[
'#'] );
62 }
elseif( is_numeric( array_shift( $keys ) ) ) {
64 foreach( $value as $item ) {
66 if( strpos( $key,
':' ) ) {
67 $node =
$xml->addChild( $key, NULL, substr( $key, 0, strpos( $key,
':' ) ) );
68 # $node = $xml->addChild( $key, NULL, 'http://www.w3.org/1999/xhtml' ); 69 # $node = $xml->addChild( 'link', NULL, 'xhtml' ); 70 # $node = $xml->addChild( 'link', NULL, 'http://www.w3.org/1999/xhtml' ); 72 $node =
$xml->addChild( $key );
79 if( strpos( $key,
':' ) ) {
80 # $node = $xml->addChild( $key, NULL, 'http://www.w3.org/1999/xhtml' ); 82 $node =
$xml->addChild( $key );
84 # $node = $xml->addChild( $key ); 91 if( substr( $key, 0, 1 ) ==
'@' ) {
92 $xml[ substr( $key, 1 ) ] = $value;
93 }
elseif( strpos( $key,
':' ) ) {
94 # $xml->addChild( $key, htmlspecialchars( $value ), substr( $key, strpos( $key, ':' ) + 1 ) ); 96 $xml->addChild( $key, htmlspecialchars( $value ) );
103 if(
$file !== NULL ) {
107 $domxml =
new DOMDocument(
'1.0');
108 $domxml->preserveWhiteSpace =
false;
109 $domxml->formatOutput =
true;
110 $domxml->loadXML( str_replace(
'|',
':',
$xml->asXML()) );
112 if(
$file ===
false ) {
113 return $domxml->saveXML();
117 logWrite(
'impossibile scrivere il file xml, permessi insufficienti',
'filesystem', LOG_ERR );
130 function xml2array( $contents, $get_attributes =
true, $priority =
'tag' ) {
143 if( ! function_exists(
'xml_parser_create')) {
144 logWrite(
'la funzione xml_parser_create() non esiste',
'xml', LOG_FATAL );
148 $parser = xml_parser_create(
'' );
149 xml_parser_set_option( $parser, XML_OPTION_TARGET_ENCODING,
'UTF-8' );
150 xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING, 0 );
151 xml_parser_set_option( $parser, XML_OPTION_SKIP_WHITE, 1 );
152 xml_parse_into_struct( $parser, trim( $contents ), $xml_values );
153 xml_parser_free( $parser );
155 $err = xml_get_error_code( $parser );
157 if( ! empty( $err ) ) {
158 logWrite(
'errore #'.xml_get_error_code( $parser ).
' ('.xml_error_string( $err ).
')',
'xml', LOG_ERR );
161 if( ! $xml_values ) {
164 logWrite( print_r( $xml_values,
true ),
'xml', LOG_DEBUG );
167 $xml_array = array();
169 $opened_tags = array();
172 $current =& $xml_array;
174 $repeated_tag_index = array();
176 foreach( $xml_values as $data ) {
178 unset( $attributes, $value );
182 $attributes_data = array();
184 if( isset( $value ) ) {
185 if( $priority ==
'tag' ) {
192 if( isset( $attributes ) and $get_attributes ) {
193 foreach( $attributes as $attr =>
$val ) {
194 if( $priority ==
'tag' ) {
197 $attributes_data[$attr] =
$val;
203 if( $type ==
"open" ) {
207 if( ! is_array( $current ) || ( ! in_array( $tag, array_keys( $current ) ) ) ) {
211 if( $attributes_data ) {
212 $current[$tag.
'_attr'] = $attributes_data;
215 $repeated_tag_index[$tag.
'_'.$level] = 1;
216 $current =& $current[$tag];
220 if( isset( $current[$tag][0] ) ) {
222 $current[$tag][$repeated_tag_index[$tag.
'_'.$level]] =
$result;
224 if($attributes_data) {
225 $current[$tag][$repeated_tag_index[$tag.
'_'.$level].
'_attr'] = $attributes_data;
228 $repeated_tag_index[$tag.
'_'.$level]++;
232 $current[$tag] = array( $current[$tag],
$result );
233 $repeated_tag_index[$tag.
'_'.$level] = 2;
235 if( isset( $current[$tag.
'_attr'] ) ) {
236 $current[$tag][
'0_attr'] = $current[$tag.
'_attr'];
237 unset($current[$tag.
'_attr']);
240 if($attributes_data) {
241 $current[$tag][
'1_attr'] = $attributes_data;
246 $last_item_index = $repeated_tag_index[$tag.
'_'.$level]-1;
247 $current =& $current[$tag][$last_item_index];
251 }
elseif( $type ==
"complete" ) {
253 if( ! isset( $current[$tag] ) ) {
256 $repeated_tag_index[$tag.
'_'.$level] = 1;
258 if( $priority ==
'attribute' && $attributes_data ) {
259 $current[$tag.
'_attr'] = $attributes_data;
264 if( isset( $current[$tag][0] ) && is_array( $current[$tag] ) ) {
266 $current[$tag][$repeated_tag_index[$tag.
'_'.$level]] =
$result;
268 if( $priority ==
'tag' && $get_attributes && $attributes_data) {
269 $current[$tag][$repeated_tag_index[$tag.
'_'.$level] .
'_attr'] = $attributes_data;
272 $repeated_tag_index[$tag.
'_'.$level]++;
276 $current[$tag] = array( $current[$tag],
$result );
277 $repeated_tag_index[$tag.
'_'.$level] = 1;
279 if($priority ==
'tag' && $get_attributes) {
281 if( isset( $current[$tag.
'_attr'] ) ) {
282 $current[$tag][
'0_attr'] = $current[$tag.
'_attr'];
283 unset($current[$tag.
'_attr']);
286 if( $attributes_data ) {
287 $current[$tag][$repeated_tag_index[$tag.
'_'.$level] .
'_attr'] = $attributes_data;
292 $repeated_tag_index[$tag.
'_'.$level]++;
298 }
elseif( $type ==
'close' ) {
306 return( $xml_array );
315 if( ! function_exists(
'xmlEntities' ) ) {
316 function xmlEntities(
$t ) {
317 $t = iconv(
'UTF-8',
'ASCII//TRANSLIT//IGNORE',
$t );
318 $t = str_replace(
'€',
'EURO',
$t );
319 $t = str_replace(
',',
'.',
$t );
330 if( ! function_exists(
'xmlFloat' ) ) {
331 function xmlFloat(
$t ) {
332 $t = str_replace(
',',
'.', sprintf(
'%01.2f',
$t ) );
logWrite( $m, $f='site', $l=LOG_NOTICE, $d=DIRECTORY_LOG, $t=CURRENT_LOG_LEVEL, $s=SITE_STATUS)
scrive un messaggio nei log del sito
if(! isset( $_REQUEST['__view__'][ $ct['view']['id']]['__extra__']['assegnato'])|| $_REQUEST['__view__'][ $ct['view']['id']]['__extra__']['assegnato']=='__me__') elseif($_REQUEST[ '__view__'][$ct[ 'view'][ 'id']][ '__extra__'][ 'assegnato']=='__nessuno__')