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