|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Circles - Bring cloud-users closer together. |
|
4
|
|
|
* |
|
5
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
|
6
|
|
|
* later. See the COPYING file. |
|
7
|
|
|
* |
|
8
|
|
|
* @author Maxence Lange <[email protected]> |
|
9
|
|
|
* @copyright 2017 |
|
10
|
|
|
* @license GNU AGPL version 3 or any later version |
|
11
|
|
|
* |
|
12
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
13
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
14
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
15
|
|
|
* License, or (at your option) any later version. |
|
16
|
|
|
* |
|
17
|
|
|
* This program is distributed in the hope that it will be useful, |
|
18
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
19
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
20
|
|
|
* GNU Affero General Public License for more details. |
|
21
|
|
|
* |
|
22
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
23
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
24
|
|
|
* |
|
25
|
|
|
*/ |
|
26
|
|
|
|
|
27
|
|
|
namespace OCA\Circles\Model; |
|
28
|
|
|
|
|
29
|
|
|
use OC\L10N\L10N; |
|
30
|
|
|
|
|
31
|
|
|
class BaseCircle { |
|
32
|
|
|
|
|
33
|
|
|
const CIRCLES_SETTINGS_DEFAULT = [ |
|
34
|
|
|
'allow_links' => 'false', |
|
35
|
|
|
'allow_links_auto' => 'false', |
|
36
|
|
|
'allow_links_files' => 'false' |
|
37
|
|
|
]; |
|
38
|
|
|
|
|
39
|
|
|
const CIRCLES_PERSONAL = 1; |
|
40
|
|
|
const CIRCLES_HIDDEN = 2; |
|
41
|
|
|
const CIRCLES_PRIVATE = 4; |
|
42
|
|
|
const CIRCLES_PUBLIC = 8; |
|
43
|
|
|
|
|
44
|
|
|
const CIRCLES_ALL = 15; |
|
45
|
|
|
|
|
46
|
|
|
/** @var int */ |
|
47
|
|
|
private $id; |
|
48
|
|
|
|
|
49
|
|
|
/** @var L10N */ |
|
50
|
|
|
protected $l10n; |
|
51
|
|
|
|
|
52
|
|
|
/** @var string */ |
|
53
|
|
|
private $uniqueId; |
|
54
|
|
|
|
|
55
|
|
|
/** @var string */ |
|
56
|
|
|
private $name; |
|
57
|
|
|
|
|
58
|
|
|
/** @var Member */ |
|
59
|
|
|
private $owner; |
|
60
|
|
|
|
|
61
|
|
|
/** @var Member */ |
|
62
|
|
|
private $user; |
|
63
|
|
|
|
|
64
|
|
|
/** @var string */ |
|
65
|
|
|
private $description = ''; |
|
66
|
|
|
|
|
67
|
|
|
/** @var array */ |
|
68
|
|
|
private $settings = []; |
|
69
|
|
|
|
|
70
|
|
|
/** @var int */ |
|
71
|
|
|
private $type; |
|
72
|
|
|
|
|
73
|
|
|
/** @var string */ |
|
74
|
|
|
private $creation; |
|
75
|
|
|
|
|
76
|
|
|
/** @var Member[] */ |
|
77
|
|
|
private $members; |
|
78
|
|
|
|
|
79
|
|
|
/** @var FederatedLink[] */ |
|
80
|
|
|
private $links; |
|
81
|
|
|
|
|
82
|
|
|
/** @var FederatedLink[] */ |
|
83
|
|
|
private $remote; |
|
84
|
|
|
|
|
85
|
|
|
public function __construct($l10n, $type = -1, $name = '') { |
|
86
|
|
|
$this->l10n = $l10n; |
|
87
|
|
|
|
|
88
|
|
|
if ($type > -1) { |
|
89
|
|
|
$this->type = $type; |
|
90
|
|
|
} |
|
91
|
|
|
if ($name !== '') { |
|
92
|
|
|
$this->name = $name; |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
|
|
97
|
|
|
public function setId($id) { |
|
98
|
|
|
$this->id = $id; |
|
99
|
|
|
|
|
100
|
|
|
return $this; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function getId() { |
|
104
|
|
|
return $this->id; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @param string $uniqueId |
|
110
|
|
|
* |
|
111
|
|
|
* @return $this |
|
112
|
|
|
*/ |
|
113
|
|
|
public function setUniqueId($uniqueId) { |
|
114
|
|
|
$this->uniqueId = (string)$uniqueId; |
|
115
|
|
|
|
|
116
|
|
|
return $this; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @param bool $full |
|
121
|
|
|
* |
|
122
|
|
|
* @return string |
|
123
|
|
|
*/ |
|
124
|
|
|
public function getUniqueId($full = false) { |
|
125
|
|
|
if ($full) { |
|
126
|
|
|
return $this->uniqueId; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
return substr($this->uniqueId, 0, 14); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
|
|
133
|
|
|
public function generateUniqueId() { |
|
134
|
|
|
$uniqueId = bin2hex(openssl_random_pseudo_bytes(24)); |
|
135
|
|
|
$this->setUniqueId($uniqueId); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
public function setName($name) { |
|
139
|
|
|
$this->name = $name; |
|
140
|
|
|
|
|
141
|
|
|
return $this; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
public function getName() { |
|
145
|
|
|
return $this->name; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
|
|
149
|
|
|
public function getOwner() { |
|
150
|
|
|
return $this->owner; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
public function setOwner($owner) { |
|
154
|
|
|
$this->owner = $owner; |
|
155
|
|
|
|
|
156
|
|
|
return $this; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* @return Member |
|
162
|
|
|
*/ |
|
163
|
|
|
public function getUser() { |
|
164
|
|
|
return $this->user; |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
public function setUser($user) { |
|
168
|
|
|
$this->user = $user; |
|
169
|
|
|
|
|
170
|
|
|
return $this; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
|
|
174
|
|
|
public function setDescription($description) { |
|
175
|
|
|
$this->description = $description; |
|
176
|
|
|
|
|
177
|
|
|
return $this; |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
public function getDescription() { |
|
181
|
|
|
return $this->description; |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
|
|
185
|
|
|
public function setSettings($settings) { |
|
186
|
|
|
if (is_array($settings)) { |
|
187
|
|
|
$this->settings = $settings; |
|
188
|
|
|
} else if (is_string($settings)) { |
|
189
|
|
|
$this->settings = json_decode($settings, true); |
|
|
|
|
|
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
return $this; |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
public function getSettings($json = false) { |
|
196
|
|
|
|
|
197
|
|
|
if ($json) { |
|
198
|
|
|
return json_encode($this->settings); |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
$settings = $this->settings; |
|
202
|
|
|
if ($settings === null) { |
|
203
|
|
|
$settings = []; |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
$ak = array_keys(self::CIRCLES_SETTINGS_DEFAULT); |
|
207
|
|
|
foreach ($ak AS $k) { |
|
208
|
|
|
if (!key_exists($k, $settings)) { |
|
209
|
|
|
$settings[$k] = self::CIRCLES_SETTINGS_DEFAULT[$k]; |
|
210
|
|
|
} |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
return $settings; |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
|
|
217
|
|
|
public function setSetting($k, $v) { |
|
218
|
|
|
$this->settings[$k] = $v; |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
|
|
222
|
|
|
/** |
|
223
|
|
|
* @param string $k |
|
224
|
|
|
* |
|
225
|
|
|
* @return string|null |
|
226
|
|
|
*/ |
|
227
|
|
|
public function getSetting($k) { |
|
228
|
|
|
if (key_exists($k, $this->settings)) { |
|
229
|
|
|
return $this->settings[$k]; |
|
230
|
|
|
} |
|
231
|
|
|
if (key_exists($k, (array)self::CIRCLES_SETTINGS_DEFAULT)) { |
|
232
|
|
|
return self::CIRCLES_SETTINGS_DEFAULT[$k]; |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
return null; |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
|
|
239
|
|
|
public function setType($type) { |
|
240
|
|
|
$this->type = self::typeInt($type); |
|
241
|
|
|
|
|
242
|
|
|
return $this; |
|
243
|
|
|
} |
|
244
|
|
|
|
|
245
|
|
|
public function getType() { |
|
246
|
|
|
return $this->type; |
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
|
|
|
250
|
|
|
public function setCreation($creation) { |
|
251
|
|
|
$this->creation = $creation; |
|
252
|
|
|
|
|
253
|
|
|
return $this; |
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
public function getCreation() { |
|
257
|
|
|
return $this->creation; |
|
258
|
|
|
} |
|
259
|
|
|
|
|
260
|
|
|
|
|
261
|
|
|
public function setMembers($members) { |
|
262
|
|
|
$this->members = $members; |
|
263
|
|
|
|
|
264
|
|
|
return $this; |
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
|
|
public function getMembers() { |
|
268
|
|
|
return $this->members; |
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
|
|
|
272
|
|
|
public function setLinks($links) { |
|
273
|
|
|
$this->links = $links; |
|
274
|
|
|
|
|
275
|
|
|
return $this; |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
public function getLinks() { |
|
279
|
|
|
return $this->links; |
|
280
|
|
|
} |
|
281
|
|
|
|
|
282
|
|
|
|
|
283
|
|
|
// public function getRemote() { |
|
|
|
|
|
|
284
|
|
|
// return $this->remote; |
|
285
|
|
|
// } |
|
286
|
|
|
// |
|
287
|
|
|
// public function addRemote($link) { |
|
288
|
|
|
// array_push($this->remote, $link); |
|
289
|
|
|
// } |
|
290
|
|
|
// |
|
291
|
|
|
// public function getRemoteFromToken($token) { |
|
292
|
|
|
// foreach ($this->links AS $link) { |
|
293
|
|
|
// if ($link->getToken() === $token) { |
|
294
|
|
|
// return $link; |
|
295
|
|
|
// } |
|
296
|
|
|
// } |
|
297
|
|
|
// |
|
298
|
|
|
// return null; |
|
299
|
|
|
// } |
|
300
|
|
|
// |
|
301
|
|
|
// public function getRemoteFromAddressAndId($address, $id) { |
|
302
|
|
|
// foreach ($this->links AS $link) { |
|
303
|
|
|
// if ($link->getAddress() === $address && $link->getUniqueId() === $id) { |
|
304
|
|
|
// return $link; |
|
305
|
|
|
// } |
|
306
|
|
|
// } |
|
307
|
|
|
// |
|
308
|
|
|
// return null; |
|
309
|
|
|
// } |
|
310
|
|
|
|
|
311
|
|
|
|
|
312
|
|
|
public static function typeInt($type) { |
|
313
|
|
|
|
|
314
|
|
|
if (is_numeric($type)) { |
|
315
|
|
|
return (int)$type; |
|
316
|
|
|
} |
|
317
|
|
|
|
|
318
|
|
View Code Duplication |
switch ($type) { |
|
|
|
|
|
|
319
|
|
|
case 'Personal': |
|
320
|
|
|
return self::CIRCLES_PERSONAL; |
|
321
|
|
|
case 'Private': |
|
322
|
|
|
return self::CIRCLES_PRIVATE; |
|
323
|
|
|
case 'Hidden': |
|
324
|
|
|
return self::CIRCLES_HIDDEN; |
|
325
|
|
|
case 'Public': |
|
326
|
|
|
return self::CIRCLES_PUBLIC; |
|
327
|
|
|
} |
|
328
|
|
|
|
|
329
|
|
|
return 0; |
|
330
|
|
|
} |
|
331
|
|
|
} |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..