mirror of
https://gitlab.com/davical-project/davical.git
synced 2026-05-25 02:34:17 +00:00
Use wrapper functions to construct tag namespaces.
This commit is contained in:
parent
4d3f233756
commit
ad17ee8a2b
@ -65,6 +65,7 @@ function ns_tag( $in_tag, $namespace=null, $prefix=null ) {
|
|||||||
$tag = $in_tag;
|
$tag = $in_tag;
|
||||||
}
|
}
|
||||||
$namespace = strtolower($namespace);
|
$namespace = strtolower($namespace);
|
||||||
|
$tag = strtolower($tag);
|
||||||
|
|
||||||
if ( $prefix == null ) {
|
if ( $prefix == null ) {
|
||||||
// Attempt to assign one
|
// Attempt to assign one
|
||||||
@ -72,9 +73,10 @@ function ns_tag( $in_tag, $namespace=null, $prefix=null ) {
|
|||||||
$prefix = $namespaces[$namespace];
|
$prefix = $namespaces[$namespace];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Try and build a prefix based on the first character of the last element of the namespace
|
// Try and build a prefix based on the first alphabetic character of the last element of the namespace
|
||||||
if ( preg_match('/^(.*):([^:]+)$/', $namespace, $matches) ) {
|
if ( preg_match('/^(.*):([^:]+)$/', $namespace, $matches) ) {
|
||||||
$prefix = strtoupper(substr($matches[2],0,1));
|
$alpha = preg_replace( '/[^a-z]/i', '', $matches[2] );
|
||||||
|
$prefix = strtoupper(substr($alpha,0,1));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$prefix = 'x';
|
$prefix = 'x';
|
||||||
@ -413,15 +415,7 @@ function collection_to_xml( $collection ) {
|
|||||||
|
|
||||||
if ( count($collection->properties) > 0 ) {
|
if ( count($collection->properties) > 0 ) {
|
||||||
foreach( $collection->properties AS $k => $v ) {
|
foreach( $collection->properties AS $k => $v ) {
|
||||||
if ( preg_match('/^(.*):([^:]+)$/', $k, $matches) ) {
|
$prop->NewElement(ns_tag($k), $v);
|
||||||
$namespace = $matches[1];
|
|
||||||
$tag = $matches[2];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$namespace = "";
|
|
||||||
$tag = $k;
|
|
||||||
}
|
|
||||||
$prop->NewElement(strtolower($tag), $v, array("xmlns" => strtolower($namespace)) );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -462,15 +456,7 @@ function collection_to_xml( $collection ) {
|
|||||||
|
|
||||||
if ( count($arbitrary_results->missing) > 0 ) {
|
if ( count($arbitrary_results->missing) > 0 ) {
|
||||||
foreach( $arbitrary_results->missing AS $k => $v ) {
|
foreach( $arbitrary_results->missing AS $k => $v ) {
|
||||||
if ( preg_match('/^(.*):([^:]+)$/', $k, $matches) ) {
|
$not_found->NewElement(ns_tag($k), '');
|
||||||
$namespace = $matches[1];
|
|
||||||
$tag = $matches[2];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$namespace = "";
|
|
||||||
$tag = $k;
|
|
||||||
}
|
|
||||||
$not_found->NewElement(strtolower($tag), '', array("xmlns" => strtolower($namespace)) );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user