Example #1
0
 public function canAccess($libraryID, $permission = 'library')
 {
     if ($this->super || $libraryID === 0) {
         return true;
     }
     if (!$libraryID) {
         throw new Exception('libraryID not provided');
     }
     // TEMP: necessary?
     $libraryID = (int) $libraryID;
     // If requested permission is explicitly set
     //
     // This assumes that permissions can't be incorrectly set
     // (e.g., are properly removed when a user loses group access)
     if (!empty($this->permissions[$libraryID][$permission])) {
         return true;
     }
     $libraryType = Zotero_Libraries::getType($libraryID);
     switch ($libraryType) {
         case 'user':
             $userID = Zotero_Users::getUserIDFromLibraryID($libraryID);
             $privacy = $this->getUserPrivacy($userID);
             break;
         case 'publications':
             return true;
         case 'group':
             $groupID = Zotero_Groups::getGroupIDFromLibraryID($libraryID);
             // If key has access to all groups, grant access if user
             // has read access to group
             if (!empty($this->permissions[0]['library'])) {
                 $group = Zotero_Groups::get($groupID);
                 // Only members have file access
                 if ($permission == 'files') {
                     return !!$group->getUserRole($this->userID);
                 }
                 if ($group->userCanRead($this->userID)) {
                     return true;
                 }
             }
             $privacy = $this->getGroupPrivacy($groupID);
             break;
         default:
             throw new Exception("Unsupported library type '{$libraryType}'");
     }
     switch ($permission) {
         case 'view':
             return $privacy['view'];
         case 'library':
             return $privacy['library'];
         case 'notes':
             return $privacy['notes'];
         default:
             return false;
     }
 }
Example #2
0
 public static function getLibraryURI($libraryID, $skipNames = false)
 {
     $libraryType = Zotero_Libraries::getType($libraryID);
     switch ($libraryType) {
         case 'user':
             $id = Zotero_Users::getUserIDFromLibraryID($libraryID);
             return self::getUserURI($id, $skipNames);
         case 'group':
             $id = Zotero_Groups::getGroupIDFromLibraryID($libraryID);
             $group = Zotero_Groups::get($id);
             return self::getGroupURI($group, $skipNames);
     }
 }
Example #3
0
 public static function getLibraryURI($libraryID, $www = false, $useSlug = false)
 {
     $libraryType = Zotero_Libraries::getType($libraryID);
     switch ($libraryType) {
         case 'user':
             $id = Zotero_Users::getUserIDFromLibraryID($libraryID);
             return self::getUserURI($id, $www, $useSlug);
         case 'publications':
             $id = Zotero_Users::getUserIDFromLibraryID($libraryID);
             return self::getUserURI($id, $www, $useSlug) . "/publications";
         case 'group':
             $id = Zotero_Groups::getGroupIDFromLibraryID($libraryID);
             $group = Zotero_Groups::get($id);
             return self::getGroupURI($group, $www, $useSlug);
         default:
             throw new Exception("Invalid library type '{$libraryType}'");
     }
 }
Example #4
0
 public static function getLibraryURI($libraryID)
 {
     $libraryType = Zotero_Libraries::getType($libraryID);
     switch ($libraryType) {
         case 'user':
             $id = Zotero_Users::getUserIDFromLibraryID($libraryID);
             return self::getBaseURI() . "users/{$id}";
         case 'publications':
             $id = Zotero_Users::getUserIDFromLibraryID($libraryID);
             return self::getBaseURI() . "users/{$id}/publications";
         case 'group':
             $id = Zotero_Groups::getGroupIDFromLibraryID($libraryID);
             return self::getBaseURI() . "groups/{$id}";
         default:
             throw new Exception("Invalid library type '{$libraryType}'");
     }
 }
Example #5
0
 public static function toJSON($libraryID)
 {
     // TODO: cache
     $libraryType = Zotero_Libraries::getType($libraryID);
     if ($libraryType == 'user') {
         $objectUserID = Zotero_Users::getUserIDFromLibraryID($libraryID);
         $json = ['type' => $libraryType, 'id' => $objectUserID, 'name' => self::getName($libraryID), 'links' => ['alternate' => ['href' => Zotero_URI::getUserURI($objectUserID, true), 'type' => 'text/html']]];
     } else {
         if ($libraryType == 'publications') {
             $objectUserID = Zotero_Users::getUserIDFromLibraryID($libraryID);
             $json = ['type' => $libraryType, 'id' => $objectUserID, 'name' => self::getName($libraryID), 'links' => ['alternate' => ['href' => Zotero_URI::getUserURI($objectUserID, true) . "/publications", 'type' => 'text/html']]];
         } else {
             if ($libraryType == 'group') {
                 $objectGroupID = Zotero_Groups::getGroupIDFromLibraryID($libraryID);
                 $group = Zotero_Groups::get($objectGroupID);
                 $json = ['type' => $libraryType, 'id' => $objectGroupID, 'name' => self::getName($libraryID), 'links' => ['alternate' => ['href' => Zotero_URI::getGroupURI($group, true), 'type' => 'text/html']]];
             } else {
                 throw new Exception("Invalid library type '{$libraryType}'");
             }
         }
     }
     return $json;
 }
Example #6
0
 public static function getLibraryURI($libraryID)
 {
     $libraryType = Zotero_Libraries::getType($libraryID);
     switch ($libraryType) {
         case 'user':
             $id = Zotero_Users::getUserIDFromLibraryID($libraryID);
             return self::getBaseURI() . "users/{$id}";
         case 'group':
             $id = Zotero_Groups::getGroupIDFromLibraryID($libraryID);
             return self::getBaseURI() . "groups/{$id}";
     }
 }
 public static function getOwner($libraryID)
 {
     $type = self::getType($libraryID);
     switch ($type) {
         case 'user':
             return Zotero_Users::getUserIDFromLibraryID($libraryID);
         case 'group':
             $groupID = Zotero_Groups::getGroupIDFromLibraryID($libraryID);
             $group = Zotero_Groups::get($groupID);
             return $group->ownerUserID;
     }
 }