示例#1
0
 /**
  * Triggered before properties are looked up in specific nodes. 
  * 
  * @param string $uri 
  * @param Sabre_DAV_INode $node 
  * @param array $requestedProperties 
  * @param array $returnedProperties
  * @TODO really should be broken into multiple methods, or even a class. 
  * @return void
  */
 public function beforeGetProperties($uri, Sabre_DAV_INode $node, &$requestedProperties, &$returnedProperties)
 {
     // Checking the read permission
     if (!$this->checkPrivileges($uri, '{DAV:}read', self::R_PARENT, false)) {
         // User is not allowed to read properties
         if ($this->hideNodesFromListings) {
             return false;
         }
         // Marking all requested properties as '403'.
         foreach ($requestedProperties as $key => $requestedProperty) {
             unset($requestedProperties[$key]);
             $returnedProperties[403][$requestedProperty] = null;
         }
         return;
     }
     /* Adding principal properties */
     if ($node instanceof Sabre_DAVACL_IPrincipal) {
         if (false !== ($index = array_search('{DAV:}alternate-URI-set', $requestedProperties))) {
             unset($requestedProperties[$index]);
             $returnedProperties[200]['{DAV:}alternate-URI-set'] = new Sabre_DAV_Property_HrefList($node->getAlternateUriSet());
         }
         if (false !== ($index = array_search('{DAV:}principal-URL', $requestedProperties))) {
             unset($requestedProperties[$index]);
             $returnedProperties[200]['{DAV:}principal-URL'] = new Sabre_DAV_Property_Href($node->getPrincipalUrl() . '/');
         }
         if (false !== ($index = array_search('{DAV:}group-member-set', $requestedProperties))) {
             unset($requestedProperties[$index]);
             $returnedProperties[200]['{DAV:}group-member-set'] = new Sabre_DAV_Property_HrefList($node->getGroupMemberSet());
         }
         if (false !== ($index = array_search('{DAV:}group-membership', $requestedProperties))) {
             unset($requestedProperties[$index]);
             $returnedProperties[200]['{DAV:}group-membership'] = new Sabre_DAV_Property_HrefList($node->getGroupMembership());
         }
         if (false !== ($index = array_search('{DAV:}displayname', $requestedProperties))) {
             $returnedProperties[200]['{DAV:}displayname'] = $node->getDisplayName();
         }
     }
     if (false !== ($index = array_search('{DAV:}principal-collection-set', $requestedProperties))) {
         unset($requestedProperties[$index]);
         $val = $this->principalCollectionSet;
         // Ensuring all collections end with a slash
         foreach ($val as $k => $v) {
             $val[$k] = $v . '/';
         }
         $returnedProperties[200]['{DAV:}principal-collection-set'] = new Sabre_DAV_Property_HrefList($val);
     }
     if (false !== ($index = array_search('{DAV:}current-user-principal', $requestedProperties))) {
         unset($requestedProperties[$index]);
         if ($url = $this->getCurrentUserPrincipal()) {
             $returnedProperties[200]['{DAV:}current-user-principal'] = new Sabre_DAVACL_Property_Principal(Sabre_DAVACL_Property_Principal::HREF, $url . '/');
         } else {
             $returnedProperties[200]['{DAV:}current-user-principal'] = new Sabre_DAVACL_Property_Principal(Sabre_DAVACL_Property_Principal::UNAUTHENTICATED);
         }
     }
     if (false !== ($index = array_search('{DAV:}supported-privilege-set', $requestedProperties))) {
         unset($requestedProperties[$index]);
         $returnedProperties[200]['{DAV:}supported-privilege-set'] = new Sabre_DAVACL_Property_SupportedPrivilegeSet($this->getSupportedPrivilegeSet());
     }
     if (false !== ($index = array_search('{DAV:}current-user-privilege-set', $requestedProperties))) {
         if (!$this->checkPrivileges($uri, '{DAV:}read-current-user-privilege-set', self::R_PARENT, false)) {
             $returnedProperties[403]['{DAV:}current-user-privilege-set'] = null;
             unset($requestedProperties[$index]);
         } else {
             $val = $this->getCurrentUserPrivilegeSet($node);
             if (!is_null($val)) {
                 unset($requestedProperties[$index]);
                 $returnedProperties[200]['{DAV:}current-user-privilege-set'] = new Sabre_DAVACL_Property_CurrentUserPrivilegeSet($val);
             }
         }
     }
     /* The ACL property contains all the permissions */
     if (false !== ($index = array_search('{DAV:}acl', $requestedProperties))) {
         if (!$this->checkPrivileges($uri, '{DAV:}read-acl', self::R_PARENT, false)) {
             unset($requestedProperties[$index]);
             $returnedProperties[403]['{DAV:}acl'] = null;
         } else {
             $acl = $this->getACL($node);
             if (!is_null($acl)) {
                 unset($requestedProperties[$index]);
                 $returnedProperties[200]['{DAV:}acl'] = new Sabre_DAVACL_Property_Acl($this->getACL($node));
             }
         }
     }
 }