Use short form array syntax everywhere
[friendica-addons.git] / dav / friendica / dav_friendica_principal.inc.php
1 <?php
2
3
4 class Sabre_DAVACL_PrincipalBackend_Std implements Sabre_DAVACL_IPrincipalBackend
5 {
6
7         /**
8          * Principals prefix
9          *
10          * @var string
11          */
12         public $prefix = 'principals/users';
13
14         /**
15          * @var Sabre_DAV_Auth_Backend_AbstractBasic $authBackend;
16          */
17         protected $authBackend;
18
19         public function __construct(&$authBackend)
20         {
21
22                 $this->authBackend = &$authBackend;
23
24         }
25
26
27         /**
28          * @var Sabre_DAVACL_IPrincipalBackend|null
29          */
30         private static $intstance = null;
31
32         /**
33          * @static
34          * @return Sabre_DAVACL_IPrincipalBackend
35          */
36         public static function &getInstance() {
37                 if (is_null(self::$intstance)) {
38                         $authBackend              = Sabre_DAV_Auth_Backend_Std::getInstance();
39                         self::$intstance = new Sabre_DAVACL_PrincipalBackend_Std($authBackend);
40                 }
41                 return self::$intstance;
42         }
43
44         /**
45          * Returns a list of principals based on a prefix.
46          *
47          * This prefix will often contain something like 'principals'. You are only
48          * expected to return principals that are in this base path.
49          *
50          * You are expected to return at least a 'uri' for every user, you can
51          * return any additional properties if you wish so. Common properties are:
52          *   {DAV:}displayname
53          *   {http://sabredav.org/ns}email-address - This is a custom SabreDAV
54          *     field that's actualy injected in a number of other properties. If
55          *     you have an email address, use this property.
56          *
57          * @param string $prefixPath
58          * @return array
59          */
60         public function getPrincipalsByPrefix($prefixPath)
61         {
62
63                 // This backend only support principals in one collection
64                 if ($prefixPath !== $this->prefix) return [];
65
66                 $users = [];
67
68                 $r = q("SELECT `nickname` FROM `user` WHERE `nickname` = '%s'", escape_tags($this->authBackend->getCurrentUser()) );
69                 foreach ($r as $t) {
70                         $users[] = [
71                                 'uri'               => $this->prefix . '/' . strtolower($t['nickname']),
72                                 '{DAV:}displayname' => $t['nickname'],
73                         ];
74                 }
75
76                 return $users;
77
78         }
79
80         /**
81          * Returns a specific principal, specified by it's path.
82          * The returned structure should be the exact same as from
83          * getPrincipalsByPrefix.
84          *
85          * @param string $path
86          * @return array
87          */
88         public function getPrincipalByPath($path)
89         {
90
91                 list($prefixPath, $userName) = Sabre_DAV_URLUtil::splitPath($path);
92
93                 // This backend only support principals in one collection
94                 if ($prefixPath !== $this->prefix) return null;
95
96                 $r = q("SELECT `nickname` FROM `user` WHERE `nickname` = '%s'", escape_tags($userName) );
97                 if (count($r) == 0) return [];
98
99                 return [
100                         'uri'               => $this->prefix . '/' . strtolower($r[0]['nickname']),
101                         '{DAV:}displayname' => $r[0]['nickname'],
102                 ];
103
104         }
105
106
107         function getGroupMemberSet($principal)
108         {
109                 return [];
110         }
111
112         function getGroupMembership($principal)
113         {
114                 return [];
115         }
116
117
118         /**
119          * Updates the list of group members for a group principal.
120          *
121          * The principals should be passed as a list of uri's.
122          *
123          * @param string $principal
124          * @param array $members
125          * @throws Sabre_DAV_Exception
126          * @return void
127          */
128         public function setGroupMemberSet($principal, array $members)
129         {
130                 throw new Sabre_DAV_Exception('Operation not supported');
131         }
132
133         /**
134          * Updates one ore more webdav properties on a principal.
135          *
136          * The list of mutations is supplied as an array. Each key in the array is
137          * a propertyname, such as {DAV:}displayname.
138          *
139          * Each value is the actual value to be updated. If a value is null, it
140          * must be deleted.
141          *
142          * This method should be atomic. It must either completely succeed, or
143          * completely fail. Success and failure can simply be returned as 'true' or
144          * 'false'.
145          *
146          * It is also possible to return detailed failure information. In that case
147          * an array such as this should be returned:
148          *
149          * array(
150          *   200 => array(
151          *      '{DAV:}prop1' => null,
152          *   ),
153          *   201 => array(
154          *      '{DAV:}prop2' => null,
155          *   ),
156          *   403 => array(
157          *      '{DAV:}prop3' => null,
158          *   ),
159          *   424 => array(
160          *      '{DAV:}prop4' => null,
161          *   ),
162          * );
163          *
164          * In this previous example prop1 was successfully updated or deleted, and
165          * prop2 was succesfully created.
166          *
167          * prop3 failed to update due to '403 Forbidden' and because of this prop4
168          * also could not be updated with '424 Failed dependency'.
169          *
170          * This last example was actually incorrect. While 200 and 201 could appear
171          * in 1 response, if there's any error (403) the other properties should
172          * always fail with 423 (failed dependency).
173          *
174          * But anyway, if you don't want to scratch your head over this, just
175          * return true or false.
176          *
177          * @param string $path
178          * @param array $mutations
179          * @return array|bool
180          */
181         function updatePrincipal($path, $mutations)
182         {
183                 // TODO: Implement updatePrincipal() method.
184         }
185
186         /**
187          * This method is used to search for principals matching a set of
188          * properties.
189          *
190          * This search is specifically used by RFC3744's principal-property-search
191          * REPORT. You should at least allow searching on
192          * http://sabredav.org/ns}email-address.
193          *
194          * The actual search should be a unicode-non-case-sensitive search. The
195          * keys in searchProperties are the WebDAV property names, while the values
196          * are the property values to search on.
197          *
198          * If multiple properties are being searched on, the search should be
199          * AND'ed.
200          *
201          * This method should simply return an array with full principal uri's.
202          *
203          * If somebody attempted to search on a property the backend does not
204          * support, you should simply return 0 results.
205          *
206          * You can also just return 0 results if you choose to not support
207          * searching at all, but keep in mind that this may stop certain features
208          * from working.
209          *
210          * @param string $prefixPath
211          * @param array $searchProperties
212          * @return array
213          */
214         function searchPrincipals($prefixPath, array $searchProperties)
215         {
216                 // TODO: Implement searchPrincipals() method.
217         }
218 }