]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/lib/Sabre/DAVACL/Principal.php
51c6658afd64ce3c626682208389965a1ddce361
[friendica-addons.git] / dav / SabreDAV / lib / Sabre / DAVACL / Principal.php
1 <?php
2
3 /**
4  * Principal class
5  *
6  * This class is a representation of a simple principal
7  *
8  * Many WebDAV specs require a user to show up in the directory
9  * structure.
10  *
11  * This principal also has basic ACL settings, only allowing the principal
12  * access it's own principal.
13  *
14  * @package Sabre
15  * @subpackage DAVACL
16  * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
17  * @author Evert Pot (http://www.rooftopsolutions.nl/)
18  * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
19  */
20 class Sabre_DAVACL_Principal extends Sabre_DAV_Node implements Sabre_DAVACL_IPrincipal, Sabre_DAV_IProperties, Sabre_DAVACL_IACL {
21
22     /**
23      * Struct with principal information.
24      *
25      * @var array
26      */
27     protected $principalProperties;
28
29     /**
30      * Principal backend
31      *
32      * @var Sabre_DAVACL_IPrincipalBackend
33      */
34     protected $principalBackend;
35
36     /**
37      * Creates the principal object
38      *
39      * @param Sabre_DAVACL_IPrincipalBackend $principalBackend
40      * @param array $principalProperties
41      */
42     public function __construct(Sabre_DAVACL_IPrincipalBackend $principalBackend, array $principalProperties = array()) {
43
44         if (!isset($principalProperties['uri'])) {
45             throw new Sabre_DAV_Exception('The principal properties must at least contain the \'uri\' key');
46         }
47         $this->principalBackend = $principalBackend;
48         $this->principalProperties = $principalProperties;
49
50     }
51
52     /**
53      * Returns the full principal url
54      *
55      * @return string
56      */
57     public function getPrincipalUrl() {
58
59         return $this->principalProperties['uri'];
60
61     }
62
63     /**
64      * Returns a list of alternative urls for a principal
65      *
66      * This can for example be an email address, or ldap url.
67      *
68      * @return array
69      */
70     public function getAlternateUriSet() {
71
72         $uris = array();
73         if (isset($this->principalProperties['{DAV:}alternate-URI-set'])) {
74
75             $uris = $this->principalProperties['{DAV:}alternate-URI-set'];
76
77         }
78
79         if (isset($this->principalProperties['{http://sabredav.org/ns}email-address'])) {
80             $uris[] = 'mailto:' . $this->principalProperties['{http://sabredav.org/ns}email-address'];
81         }
82
83         return array_unique($uris);
84
85     }
86
87     /**
88      * Returns the list of group members
89      *
90      * If this principal is a group, this function should return
91      * all member principal uri's for the group.
92      *
93      * @return array
94      */
95     public function getGroupMemberSet() {
96
97         return $this->principalBackend->getGroupMemberSet($this->principalProperties['uri']);
98
99     }
100
101     /**
102      * Returns the list of groups this principal is member of
103      *
104      * If this principal is a member of a (list of) groups, this function
105      * should return a list of principal uri's for it's members.
106      *
107      * @return array
108      */
109     public function getGroupMembership() {
110
111         return $this->principalBackend->getGroupMemberShip($this->principalProperties['uri']);
112
113     }
114
115
116     /**
117      * Sets a list of group members
118      *
119      * If this principal is a group, this method sets all the group members.
120      * The list of members is always overwritten, never appended to.
121      *
122      * This method should throw an exception if the members could not be set.
123      *
124      * @param array $groupMembers
125      * @return void
126      */
127     public function setGroupMemberSet(array $groupMembers) {
128
129         $this->principalBackend->setGroupMemberSet($this->principalProperties['uri'], $groupMembers);
130
131     }
132
133
134     /**
135      * Returns this principals name.
136      *
137      * @return string
138      */
139     public function getName() {
140
141         $uri = $this->principalProperties['uri'];
142         list(, $name) = Sabre_DAV_URLUtil::splitPath($uri);
143         return $name;
144
145     }
146
147     /**
148      * Returns the name of the user
149      *
150      * @return string
151      */
152     public function getDisplayName() {
153
154         if (isset($this->principalProperties['{DAV:}displayname'])) {
155             return $this->principalProperties['{DAV:}displayname'];
156         } else {
157             return $this->getName();
158         }
159
160     }
161
162     /**
163      * Returns a list of properties
164      *
165      * @param array $requestedProperties
166      * @return array
167      */
168     public function getProperties($requestedProperties) {
169
170         $newProperties = array();
171         foreach($requestedProperties as $propName) {
172
173             if (isset($this->principalProperties[$propName])) {
174                 $newProperties[$propName] = $this->principalProperties[$propName];
175             }
176
177         }
178
179         return $newProperties;
180
181     }
182
183     /**
184      * Updates this principals properties.
185      * 
186      * @param array $mutations
187      * @see Sabre_DAV_IProperties::updateProperties
188      * @return bool|array
189      */
190     public function updateProperties($mutations) {
191
192         return $this->principalBackend->updatePrincipal($this->principalProperties['uri'], $mutations);
193
194     }
195
196     /**
197      * Returns the owner principal
198      *
199      * This must be a url to a principal, or null if there's no owner
200      *
201      * @return string|null
202      */
203     public function getOwner() {
204
205         return $this->principalProperties['uri'];
206
207
208     }
209
210     /**
211      * Returns a group principal
212      *
213      * This must be a url to a principal, or null if there's no owner
214      *
215      * @return string|null
216      */
217     public function getGroup() {
218
219         return null;
220
221     }
222
223     /**
224      * Returns a list of ACE's for this node.
225      *
226      * Each ACE has the following properties:
227      *   * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
228      *     currently the only supported privileges
229      *   * 'principal', a url to the principal who owns the node
230      *   * 'protected' (optional), indicating that this ACE is not allowed to
231      *      be updated.
232      *
233      * @return array
234      */
235     public function getACL() {
236
237         return array(
238             array(
239                 'privilege' => '{DAV:}read',
240                 'principal' => $this->getPrincipalUrl(),
241                 'protected' => true,
242             ),
243         );
244
245     }
246
247     /**
248      * Updates the ACL
249      *
250      * This method will receive a list of new ACE's.
251      *
252      * @param array $acl
253      * @return void
254      */
255     public function setACL(array $acl) {
256
257         throw new Sabre_DAV_Exception_MethodNotAllowed('Updating ACLs is not allowed here');
258
259     }
260
261     /**
262      * Returns the list of supported privileges for this node.
263      *
264      * The returned data structure is a list of nested privileges.
265      * See Sabre_DAVACL_Plugin::getDefaultSupportedPrivilegeSet for a simple
266      * standard structure.
267      *
268      * If null is returned from this method, the default privilege set is used,
269      * which is fine for most common usecases.
270      *
271      * @return array|null
272      */
273     public function getSupportedPrivilegeSet() {
274
275         return null;
276
277     }
278
279 }