From 6d3a0abd4ccae3f230ffbe91a23dd2484caed639 Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Sun, 25 Nov 2007 12:57:54 +1300 Subject: [PATCH] Write & use utility function for URL construction. --- inc/CalDAVRequest.php | 14 ++++++++++++++ inc/caldav-PROPFIND.php | 9 ++------- inc/caldav-REPORT.php | 4 +--- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/inc/CalDAVRequest.php b/inc/CalDAVRequest.php index 317f6109..0906ce57 100644 --- a/inc/CalDAVRequest.php +++ b/inc/CalDAVRequest.php @@ -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 diff --git a/inc/caldav-PROPFIND.php b/inc/caldav-PROPFIND.php index 94289283..d6ec5f23 100644 --- a/inc/caldav-PROPFIND.php +++ b/inc/caldav-PROPFIND.php @@ -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"); diff --git a/inc/caldav-REPORT.php b/inc/caldav-REPORT.php index 1f7f9bfe..4aee6056 100644 --- a/inc/caldav-REPORT.php +++ b/inc/caldav-REPORT.php @@ -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 ) {