Write & use utility function for URL construction.

This commit is contained in:
Andrew McMillan 2007-11-25 12:57:54 +13:00
parent 89c7a33694
commit 6d3a0abd4c
3 changed files with 17 additions and 10 deletions

View File

@ -254,6 +254,20 @@ class CalDAVRequest
}
/**
* Construct a URL from the supplied dav_name
* @param string $partial_path The part of the path after the script name
*/
function ConstructURL( $partial_path ) {
global $c;
$url = $c->protocol_server_port_script . $partial_path;
$url = preg_replace( '#^(https?://.+)//#', '$1/', $url ); // Ensure we don't double any '/'
$url = preg_replace('#^https?://[^/]+#', '', $url );
return $url;
}
/**
* Permissions are controlled as follows:
* 1. if the path is '/', the request has read privileges

View File

@ -320,10 +320,7 @@ function collection_to_xml( $collection ) {
$arbitrary_results = get_arbitrary_properties($collection->dav_name);
$collection->properties = $arbitrary_results->found;
$url = $c->protocol_server_port_script . $collection->dav_name;
$url = preg_replace( '#^(https?://.+)//#', '$1/', $url ); // Ensure we don't double any '/'
$url = preg_replace('#^https?://[^/]+#', '', $url );
$url = $request->ConstructURL($collection->dav_name);
$resourcetypes = array( new XMLElement("collection") );
$contentlength = false;
@ -479,9 +476,7 @@ function item_to_xml( $item ) {
$item->properties = get_arbitrary_properties($item->dav_name);
$url = $c->protocol_server_port_script . $item->dav_name;
$url = preg_replace( '#^(https?://.+)//#', '$1/', $url ); // Ensure we don't double any '/'
$url = preg_replace('#^https?://[^/]+#', '', $url );
$url = $request->ConstructURL($item->dav_name);
$prop = new XMLElement("prop");
$not_found = new XMLElement("prop");

View File

@ -96,9 +96,7 @@ function calendar_to_xml( $properties, $item ) {
}
}
$url = $c->protocol_server_port_script . $item->dav_name;
$url = preg_replace( '#^(https?://.+)//#', '$1/', $url ); // Ensure we don't double any '/'
$url = preg_replace('#^https?://[^/]+#', '', $url );
$url = $request->ConstructURL($item->dav_name);
$prop = new XMLElement("prop");
foreach( $properties AS $k => $v ) {