/** * This event is triggered when a PROPPATCH method is executed * * @param array $mutations * @param array $result * @param DAV\INode $node * @return bool */ public function updateProperties(&$mutations, &$result, DAV\INode $node) { if (!$node instanceof UserAddressBooks) { return true; } $meCard = '{http://calendarserver.org/ns/}me-card'; // The only property we care about if (!isset($mutations[$meCard])) { return true; } $value = $mutations[$meCard]; unset($mutations[$meCard]); if ($value instanceof DAV\Property\IHref) { $value = $value->getHref(); $value = $this->server->calculateUri($value); } elseif (!is_null($value)) { $result[400][$meCard] = null; return false; } $innerResult = $this->server->updateProperties($node->getOwner(), array('{http://sabredav.org/ns}vcard-url' => $value)); $closureResult = false; foreach ($innerResult as $status => $props) { if (is_array($props) && array_key_exists('{http://sabredav.org/ns}vcard-url', $props)) { $result[$status][$meCard] = null; $closureResult = $status >= 200 && $status < 300; } } return $result; }
/** * This event is triggered when properties are requested for a certain * node. * * This allows us to inject any properties early. * * @param string $path * @param DAV\INode $node * @param array $requestedProperties * @param array $returnedProperties * @return void */ public function beforeGetProperties($path, DAV\INode $node, &$requestedProperties, &$returnedProperties) { if ($node instanceof IShareableCalendar) { if (($index = array_search('{' . Plugin::NS_CALENDARSERVER . '}invite', $requestedProperties)) !== false) { unset($requestedProperties[$index]); $returnedProperties[200]['{' . Plugin::NS_CALENDARSERVER . '}invite'] = new Property\Invite($node->getShares()); } } if ($node instanceof ISharedCalendar) { if (($index = array_search('{' . Plugin::NS_CALENDARSERVER . '}shared-url', $requestedProperties)) !== false) { unset($requestedProperties[$index]); $returnedProperties[200]['{' . Plugin::NS_CALENDARSERVER . '}shared-url'] = new DAV\Property\Href($node->getSharedUrl()); } // The 'invite' property is slightly different for the 'shared' // instance of the calendar, as it also contains the owner // information. if (($index = array_search('{' . Plugin::NS_CALENDARSERVER . '}invite', $requestedProperties)) !== false) { unset($requestedProperties[$index]); // Fetching owner information $props = $this->server->getPropertiesForPath($node->getOwner(), array('{http://sabredav.org/ns}email-address', '{DAV:}displayname'), 1); $ownerInfo = array('href' => $node->getOwner()); if (isset($props[0][200])) { // We're mapping the internal webdav properties to the // elements caldav-sharing expects. if (isset($props[0][200]['{http://sabredav.org/ns}email-address'])) { $ownerInfo['href'] = 'mailto:' . $props[0][200]['{http://sabredav.org/ns}email-address']; } if (isset($props[0][200]['{DAV:}displayname'])) { $ownerInfo['commonName'] = $props[0][200]['{DAV:}displayname']; } } $returnedProperties[200]['{' . Plugin::NS_CALENDARSERVER . '}invite'] = new Property\Invite($node->getShares(), $ownerInfo); } } }