From 1cfec1523387ed85af2867fd20280c812c097cc6 Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Thu, 2 Sep 2010 22:19:49 +1200 Subject: [PATCH] Allow setting of the bound location of this resource. --- inc/DAVResource.php | 56 ++++++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 18 deletions(-) diff --git a/inc/DAVResource.php b/inc/DAVResource.php index 562dce08..cb419ba0 100644 --- a/inc/DAVResource.php +++ b/inc/DAVResource.php @@ -1028,6 +1028,19 @@ EOQRY; return $this->dav_name(); } + + /** + * Sets the dav_name of the resource we are bound as + */ + function set_bind_location( $new_dav_name ) { + if ( !isset($this->bound_from) && isset($this->dav_name) ) { + $this->bound_from = $this->dav_name; + } + $this->dav_name = $new_dav_name; + return $this->dav_name; + } + + /** * Returns the dav_name of the resource in our internal namespace */ @@ -1291,26 +1304,33 @@ EOQRY; break; case 'DAV::parent-set': - $parent_set = $reply->DAVElement( $prop, 'parent-set' ); - if ( preg_match( '{^(.*)/([^/]+)/?$}', $this->bound_from(), $matches ) ) { - $reply->DAVElement($parent_set, 'parent', array( - new XMLElement( 'href', ConstructURL($matches[1])), - new XMLElement( 'segment', $matches[2]) - )); - $sql = << $this->bound_from ) ); - if ( $qry->Exec('DAVResource',__LINE__,__FILE__) && $qry->rows() > 0 ) { - while( $row = $qry->Fetch() ) { - $reply->DAVElement($parent_set, 'parent', array( - new XMLElement( 'href', ConstructURL($row->parent)), - new XMLElement( 'segment', $row->segment) - )); - } + $qry = new AwlQuery($sql, array( ':bound_from' => $this->bound_from() ) ); + $parents = array(); + if ( $qry->Exec('DAVResource',__LINE__,__FILE__) && $qry->rows() > 0 ) { + while( $row = $qry->Fetch() ) { + $parents[$row->parent_container] = true; + } + } + $parents[preg_replace( '{(?<=/)[^/]+/?$}','',$this->bound_from())] = true; + $parents[preg_replace( '{(?<=/)[^/]+/?$}','',$this->dav_name())] = true; + + $parent_set = $reply->DAVElement( $prop, 'parent-set' ); + foreach( $parents AS $parent => $v ) { + if ( preg_match( '{^(.*)?/([^/]+)/?$}', $parent, $matches ) ) { + $reply->DAVElement($parent_set, 'parent', array( + new XMLElement( 'href', ConstructURL($matches[1])), + new XMLElement( 'segment', $matches[2]) + )); + } + else if ( $parent == '/' ) { + $reply->DAVElement($parent_set, 'parent', array( + new XMLElement( 'href', '/'), + new XMLElement( 'segment', ( ConstructURL('/') == '/caldav.php/' ? 'caldav.php' : '')) + )); } } break;