diff --git a/inc/CalDAVPrincipal.php b/inc/CalDAVPrincipal.php index 1e9ac75f..39c6d153 100644 --- a/inc/CalDAVPrincipal.php +++ b/inc/CalDAVPrincipal.php @@ -98,11 +98,11 @@ class CalDAVPrincipal if ( $parameters == null ) return false; $this->by_email = false; if ( is_object($parameters) ) { - dbg_error_log( "principal", "Principal: record for %s", $parameters->username ); + dbg_error_log( 'principal', 'Principal: record for %s', $parameters->username ); $usr = $parameters; } else if ( is_int($parameters) ) { - dbg_error_log( "principal", "Principal: %d", $parameters ); + dbg_error_log( 'principal', 'Principal: %d', $parameters ); $usr = getUserByID($parameters); } else if ( is_array($parameters) ) { @@ -120,7 +120,7 @@ class CalDAVPrincipal } } else if ( isset($parameters['path']) ) { - dbg_error_log( "principal", "Finding Principal from path: '%s', options.allow_by_email: '%s'", $parameters['path'], $parameters['options']['allow_by_email'] ); + dbg_error_log( 'principal', 'Finding Principal from path: "%s", options.allow_by_email: "%s"', $parameters['path'], $parameters['options']['allow_by_email'] ); if ( $username = $this->UsernameFromPath($parameters['path'], $parameters['options']) ) { $usr = getUserByName($username); } @@ -153,34 +153,34 @@ class CalDAVPrincipal if ( !isset($this->created) ) $this->created = ISODateToHTTPDate($this->joined); $this->by_email = false; - $this->url = ConstructURL( "/".$this->username."/", true ); + $this->url = ConstructURL( '/'.$this->username.'/', true ); $this->calendar_home_set = array( $this->url ); $this->user_address_set = array( - "mailto:".$this->email, - ConstructURL( "/".$this->username."/", true ), -// ConstructURL( "/~".$this->username."/", true ), -// ConstructURL( "/__uuids__/".$this->username."/", true ), + rawurlencode('mailto:'.$this->email), + ConstructURL( '/'.$this->username.'/', true ), +// ConstructURL( '/~'.$this->username.'/', true ), +// ConstructURL( '/__uuids__/'.$this->username.'/', true ), ); - $this->schedule_inbox_url = sprintf( "%s.in/", $this->url); - $this->schedule_outbox_url = sprintf( "%s.out/", $this->url); - $this->dropbox_url = sprintf( "%s.drop/", $this->url); - $this->notifications_url = sprintf( "%s.notify/", $this->url); + $this->schedule_inbox_url = sprintf( '%s.in/', $this->url); + $this->schedule_outbox_url = sprintf( '%s.out/', $this->url); + $this->dropbox_url = sprintf( '%s.drop/', $this->url); + $this->notifications_url = sprintf( '%s.notify/', $this->url); $this->group_member_set = array(); - $qry = new PgQuery("SELECT * FROM relationship LEFT JOIN usr ON (from_user = usr.user_no) LEFT JOIN role_member ON (to_user = role_member.user_no) LEFT JOIN roles USING (role_no) WHERE to_user = ? AND role_name = 'Group';", $this->user_no ); - if ( $qry->Exec("CalDAVPrincipal") && $qry->rows > 0 ) { + $qry = new PgQuery('SELECT * FROM relationship LEFT JOIN usr ON (from_user = usr.user_no) LEFT JOIN role_member ON (to_user = role_member.user_no) LEFT JOIN roles USING (role_no) WHERE to_user = ? AND role_name = '."'Group'", $this->user_no ); + if ( $qry->Exec('CalDAVPrincipal') && $qry->rows > 0 ) { while( $membership = $qry->Fetch() ) { - $this->group_member_set[] = ConstructURL( "/". $membership->username . "/", true); + $this->group_member_set[] = ConstructURL( '/'. $membership->username . '/', true); } } $this->group_membership = array(); - $qry = new PgQuery("SELECT * FROM relationship LEFT JOIN usr ON (to_user = user_no) LEFT JOIN role_member USING (user_no) LEFT JOIN roles USING (role_no) WHERE from_user = ? AND role_name = 'Group';", $this->user_no ); - if ( $qry->Exec("CalDAVPrincipal") && $qry->rows > 0 ) { + $qry = new PgQuery('SELECT * FROM relationship LEFT JOIN usr ON (to_user = user_no) LEFT JOIN role_member USING (user_no) LEFT JOIN roles USING (role_no) WHERE from_user = ? AND role_name = '."'Group'", $this->user_no ); + if ( $qry->Exec('CalDAVPrincipal') && $qry->rows > 0 ) { while( $membership = $qry->Fetch() ) { - $this->group_membership[] = ConstructURL( "/". $membership->username . "/", true); + $this->group_membership[] = ConstructURL( '/'. $membership->username . '/', true); } } @@ -192,29 +192,29 @@ class CalDAVPrincipal if ( !isset($c->disable_caldav_proxy) || $c->disable_caldav_proxy === false ) { // whom are we a proxy for? who is a proxy for us? // (as per Caldav Proxy section 5.1 Paragraph 7 and 5) - $qry = new PgQuery("SELECT from_user.user_no AS from_user_no, from_user.username AS from_username,". - "get_permissions(from_user.user_no, to_user.user_no) AS confers,". - "to_user.user_no AS to_user_no, to_user.username AS to_username ". - "FROM usr from_user, usr to_user WHERE ". + $qry = new PgQuery('SELECT from_user.user_no AS from_user_no, from_user.username AS from_username,'. + 'get_permissions(from_user.user_no, to_user.user_no) AS confers,'. + 'to_user.user_no AS to_user_no, to_user.username AS to_username '. + 'FROM usr from_user, usr to_user WHERE '. "get_permissions(from_user.user_no, to_user.user_no) ~ '[AWR]' AND ". - "to_user.user_no != from_user.user_no AND (from_user.user_no = ? OR ". - "to_user.user_no = ?)", $this->user_no, $this->user_no ); - if ( $qry->Exec("CalDAVPrincipal") && $qry->rows > 0 ) { + 'to_user.user_no != from_user.user_no AND (from_user.user_no = ? OR '. + 'to_user.user_no = ?)', $this->user_no, $this->user_no ); + if ( $qry->Exec('CalDAVPrincipal') && $qry->rows > 0 ) { while( $relationship = $qry->Fetch() ) { - if ($relationship->confers == "R") { + if ($relationship->confers == 'R') { if ($relationship->from_user_no == $this->user_no) { // spec says without trailing slash, CalServ does it with slash, and so do we. - $this->group_membership[] = ConstructURL( "/". $relationship->to_username . "/calendar-proxy-read/", true); - $this->read_proxy_for[] = ConstructURL( "/". $relationship->to_username . "/", true); + $this->group_membership[] = ConstructURL( '/'. $relationship->to_username . '/calendar-proxy-read/', true); + $this->read_proxy_for[] = ConstructURL( '/'. $relationship->to_username . '/', true); } else /* ($relationship->to_user_no == $this->user_no) */ { - $this->read_proxy_group[] = ConstructURL( "/". $relationship->from_username . "/", true); + $this->read_proxy_group[] = ConstructURL( '/'. $relationship->from_username . '/', true); } - } else if (preg_match("/[WA]/", $relationship->confers)) { + } else if (preg_match('/[WA]/', $relationship->confers)) { if ($relationship->from_user_no == $this->user_no) { - $this->group_membership[] = ConstructURL( "/". $relationship->to_username . "/calendar-proxy-write/", true); - $this->write_proxy_for[] = ConstructURL( "/". $relationship->to_username . "/", true); + $this->group_membership[] = ConstructURL( '/'. $relationship->to_username . '/calendar-proxy-write/', true); + $this->write_proxy_for[] = ConstructURL( '/'. $relationship->to_username . '/', true); } else /* ($relationship->to_user_no == $this->user_no) */ { - $this->write_proxy_group[] = ConstructURL( "/". $relationship->from_username . "/", true); + $this->write_proxy_group[] = ConstructURL( '/'. $relationship->from_username . '/', true); } } } @@ -225,15 +225,15 @@ class CalDAVPrincipal * calendar-free-busy-set has been dropped from draft 5 of the scheduling extensions for CalDAV * but we'll keep replying to it for a while longer since iCal appears to want it... */ - $qry = new PgQuery("SELECT dav_name FROM collection WHERE user_no = ? AND is_calendar", $this->user_no); + $qry = new PgQuery('SELECT dav_name FROM collection WHERE user_no = ? AND is_calendar', $this->user_no); $this->calendar_free_busy_set = array(); - if( $qry->Exec("CalDAVPrincipal",__LINE__,__FILE__) && $qry->rows > 0 ) { + if( $qry->Exec('CalDAVPrincipal',__LINE__,__FILE__) && $qry->rows > 0 ) { while( $calendar = $qry->Fetch() ) { $this->calendar_free_busy_set[] = ConstructURL($calendar->dav_name, true); } } - dbg_error_log( "principal", "User: %s (%d) URL: %s, Home: %s, By Email: %d", $this->username, $this->user_no, $this->url, $this->calendar_home_set, $this->by_email ); + dbg_error_log( 'principal', 'User: %s (%d) URL: %s, Home: %s, By Email: %d', $this->username, $this->user_no, $this->url, $this->calendar_home_set, $this->by_email ); } @@ -246,12 +246,12 @@ class CalDAVPrincipal global $session, $c; if ( $path == '/' || $path == '' ) { - dbg_error_log( "principal", "No useful path split possible" ); + dbg_error_log( 'principal', 'No useful path split possible' ); return $session->username; } $path_split = explode('/', $path ); - @dbg_error_log( "principal", "Path split into at least /// %s /// %s /// %s", $path_split[1], $path_split[2], $path_split[3] ); + @dbg_error_log( 'principal', 'Path split into at least /// %s /// %s /// %s', $path_split[1], $path_split[2], $path_split[3] ); $username = $path_split[1]; if ( $path_split[1] == 'principals' ) $username = $path_split[3]; @@ -259,8 +259,8 @@ class CalDAVPrincipal if ( isset($options['allow_by_email']) && $options['allow_by_email'] && preg_match( '#/(\S+@\S+[.]\S+)$#', $path, $matches) ) { $email = $matches[1]; - $qry = new PgQuery("SELECT user_no, username FROM usr WHERE email = ?;", $email ); - if ( $qry->Exec("principal") && $user = $qry->Fetch() ) { + $qry = new PgQuery('SELECT user_no, username FROM usr WHERE email = ?;', $email ); + if ( $qry->Exec('principal') && $user = $qry->Fetch() ) { $user_no = $user->user_no; $username = $user->username; } @@ -277,8 +277,8 @@ class CalDAVPrincipal * @param string $email The email address to be used. */ function UsernameFromEMail( $email ) { - $qry = new PgQuery("SELECT user_no, username FROM usr WHERE email = ?;", $email ); - if ( $qry->Exec("principal") && $user = $qry->Fetch() ) { + $qry = new PgQuery('SELECT user_no, username FROM usr WHERE email = ?;', $email ); + if ( $qry->Exec('principal') && $user = $qry->Fetch() ) { $user_no = $user->user_no; $username = $user->username; } @@ -310,7 +310,7 @@ class CalDAVPrincipal /** * Returns the array of privilege names converted into XMLElements */ - function RenderPrivileges($privilege_names, $container="privilege") { + function RenderPrivileges($privilege_names, $container='privilege') { $privileges = array(); foreach( $privilege_names AS $k => $v ) { $privileges[] = new XMLElement($container, new XMLElement($k)); @@ -331,82 +331,92 @@ class CalDAVPrincipal function RenderAsXML( $properties, &$reply, $props_only = false ) { global $session, $c, $request; - dbg_error_log("principal",": RenderAsXML: Principal '%s'", $this->username ); + dbg_error_log('principal',': RenderAsXML: Principal "%s"', $this->username ); - $prop = new XMLElement("prop"); + $prop = new XMLElement('prop'); $denied = array(); $not_found = array(); foreach( $properties AS $k => $tag ) { - dbg_error_log("principal",": RenderAsXML: Principal Property '%s'", $tag ); + dbg_error_log('principal',': RenderAsXML: Principal Property "%s"', $tag ); switch( $tag ) { case 'DAV::getcontenttype': - $prop->NewElement("getcontenttype", "httpd/unix-directory" ); + $prop->NewElement('getcontenttype', 'httpd/unix-directory' ); break; case 'DAV::resourcetype': - $prop->NewElement("resourcetype", array( new XMLElement("principal"), new XMLElement("collection")) ); + $prop->NewElement('resourcetype', array( new XMLElement('principal'), new XMLElement('collection')) ); break; case 'DAV::displayname': - $prop->NewElement("displayname", $this->fullname ); + $prop->NewElement('displayname', $this->fullname ); break; case 'DAV::principal-URL': - $prop->NewElement("principal-URL", $reply->href($this->url) ); + $prop->NewElement('principal-URL', $reply->href($this->url) ); break; case 'DAV::getlastmodified': - $prop->NewElement("getlastmodified", $this->modified ); + $prop->NewElement('getlastmodified', $this->modified ); break; case 'DAV::creationdate': - $prop->NewElement("creationdate", $this->created ); + $prop->NewElement('creationdate', $this->created ); break; case 'DAV::group-member-set': - $prop->NewElement("group-member-set", $reply->href($this->group_member_set) ); + $prop->NewElement('group-member-set', $reply->href($this->group_member_set) ); break; case 'DAV::group-membership': - $prop->NewElement("group-membership", $reply->href($this->group_membership) ); + $prop->NewElement('group-membership', $reply->href($this->group_membership) ); break; case 'urn:ietf:params:xml:ns:caldav:schedule-inbox-URL': - $reply->CalDAVElement($prop, "schedule-inbox-URL", $reply->href($this->schedule_inbox_url) ); + $reply->CalDAVElement($prop, 'schedule-inbox-URL', $reply->href($this->schedule_inbox_url) ); break; case 'urn:ietf:params:xml:ns:caldav:schedule-outbox-URL': - $reply->CalDAVElement($prop, "schedule-outbox-URL", $reply->href($this->schedule_outbox_url) ); + $reply->CalDAVElement($prop, 'schedule-outbox-URL', $reply->href($this->schedule_outbox_url) ); break; -/* + case 'http://calendarserver.org/ns/:dropbox-home-URL': - $reply->CalendarserverElement($prop, "dropbox-home-URL", $reply->href($this->dropbox_url) ); + $reply->CalendarserverElement($prop, 'dropbox-home-URL', $reply->href($this->dropbox_url) ); break; case 'http://calendarserver.org/ns/:notifications-URL': - $reply->CalendarserverElement($prop, "notifications-URL", $reply->href($this->notifications_url) ); + $reply->CalendarserverElement($prop, 'notifications-URL', $reply->href($this->notifications_url) ); break; -*/ + case 'urn:ietf:params:xml:ns:caldav:calendar-home-set': - $reply->CalDAVElement($prop, "calendar-home-set", $reply->href( $this->calendar_home_set ) ); + $reply->CalDAVElement($prop, 'calendar-home-set', $reply->href( $this->calendar_home_set ) ); break; case 'urn:ietf:params:xml:ns:caldav:calendar-user-address-set': - $reply->CalDAVElement($prop, "calendar-user-address-set", $reply->href($this->user_address_set) ); + $reply->CalDAVElement($prop, 'calendar-user-address-set', $reply->href($this->user_address_set) ); break; +// case 'urn:ietf:params:xml:ns:caldav:supported-calendar-component-set': +// // Note that this won't appear on a PROPFIND against a Principal URL, since this routine is only called for a collection +// $components = array(); +// $set_of_components = array( 'VEVENT', 'VTODO', 'VJOURNAL', 'VTIMEZONE', 'VFREEBUSY' ); +// foreach( $set_of_components AS $v ) { +// $components[] = $reply->NewXMLElement( 'comp', '', array('name' => $v), 'urn:ietf:params:xml:ns:caldav'); +// } +// $reply->CalDAVElement($prop, 'supported-calendar-component-set', $components ); +// break; + case 'DAV::getcontentlanguage': - $locale = (isset($c->current_locale) ? $c->current_locale : ""); - if ( isset($this->locale) && $this->locale != "" ) $locale = $this->locale; - $prop->NewElement("getcontentlanguage", $locale ); + $locale = (isset($c->current_locale) ? $c->current_locale : ''); + if ( isset($this->locale) && $this->locale != '' ) $locale = $this->locale; + $prop->NewElement('getcontentlanguage', $locale ); break; case 'DAV::supportedlock': - $prop->NewElement("supportedlock", - new XMLElement( "lockentry", + $prop->NewElement('supportedlock', + new XMLElement( 'lockentry', array( - new XMLElement("lockscope", new XMLElement("exclusive")), - new XMLElement("locktype", new XMLElement("write")), + new XMLElement('lockscope', new XMLElement('exclusive')), + new XMLElement('locktype', new XMLElement('write')), ) ) ); @@ -416,18 +426,18 @@ class CalDAVPrincipal /** * @todo This information is semantically valid but presents an incorrect picture. */ - $principal = new XMLElement("principal"); - $principal->NewElement("authenticated"); - $grant = new XMLElement( "grant", array($this->RenderPrivileges($request->permissions)) ); - $prop->NewElement("acl", new XMLElement( "ace", array( $principal, $grant ) ) ); + $principal = new XMLElement('principal'); + $principal->NewElement('authenticated'); + $grant = new XMLElement( 'grant', array($this->RenderPrivileges($request->permissions)) ); + $prop->NewElement('acl', new XMLElement( 'ace', array( $principal, $grant ) ) ); break; case 'DAV::current-user-privilege-set': - $prop->NewElement("current-user-privilege-set", $this->RenderPrivileges($request->permissions) ); + $prop->NewElement('current-user-privilege-set', $this->RenderPrivileges($request->permissions) ); break; case 'DAV::supported-privilege-set': - $prop->NewElement("supported-privilege-set", $this->RenderPrivileges( $request->SupportedPrivileges(), "supported-privilege") ); + $prop->NewElement('supported-privilege-set', $this->RenderPrivileges( $request->SupportedPrivileges(), 'supported-privilege') ); break; // Empty tag responses. @@ -437,10 +447,10 @@ class CalDAVPrincipal break; case 'http://calendarserver.org/ns/:getctag': - $reply->CalendarServerElement( $prop, "getctag", '"'.md5($this->username . $this->updated).'"' ); + $reply->CalendarServerElement( $prop, 'getctag', '"'.md5($this->username . $this->updated).'"' ); break; case 'DAV::getetag': - $reply->DAVElement( $prop, "getetag", '"'.md5($this->username . $this->updated).'"' ); + $reply->DAVElement( $prop, 'getetag', '"'.md5($this->username . $this->updated).'"' ); break; case 'SOME-DENIED-PROPERTY': /** @todo indicating the style for future expansion */ @@ -448,7 +458,7 @@ class CalDAVPrincipal break; default: - dbg_error_log( 'principal', "Request for unsupported property '%s' of principal '%s'.", $tag, $this->username ); + dbg_error_log( 'principal', 'Request for unsupported property "%s" of principal "%s".', $tag, $this->username ); $not_found[] = $reply->Tag($tag); break; } @@ -456,32 +466,32 @@ class CalDAVPrincipal if ( $props_only ) return $prop; - $status = new XMLElement("status", "HTTP/1.1 200 OK" ); + $status = new XMLElement('status', 'HTTP/1.1 200 OK' ); - $propstat = new XMLElement( "propstat", array( $prop, $status) ); + $propstat = new XMLElement( 'propstat', array( $prop, $status) ); $href = $reply->href($this->url ); $elements = array($href,$propstat); if ( count($denied) > 0 ) { - $status = new XMLElement("status", "HTTP/1.1 403 Forbidden" ); - $noprop = new XMLElement("prop"); + $status = new XMLElement('status', 'HTTP/1.1 403 Forbidden' ); + $noprop = new XMLElement('prop'); foreach( $denied AS $k => $v ) { $noprop->NewElement( $v ); } - $elements[] = new XMLElement( "propstat", array( $noprop, $status) ); + $elements[] = new XMLElement( 'propstat', array( $noprop, $status) ); } if ( count($not_found) > 0 ) { - $status = new XMLElement("status", "HTTP/1.1 404 Not Found" ); - $noprop = new XMLElement("prop"); + $status = new XMLElement('status', 'HTTP/1.1 404 Not Found' ); + $noprop = new XMLElement('prop'); foreach( $not_found AS $k => $v ) { $noprop->NewElement( $v ); } - $elements[] = new XMLElement( "propstat", array( $noprop, $status) ); + $elements[] = new XMLElement( 'propstat', array( $noprop, $status) ); } - $response = new XMLElement( "response", $elements ); + $response = new XMLElement( 'response', $elements ); return $response; }