|
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 $viewer; |
|
63
|
|
|
|
|
64
|
|
|
/** @var Member */ |
|
65
|
|
|
private $viewerGroup; |
|
66
|
|
|
|
|
67
|
|
|
/** @var string */ |
|
68
|
|
|
private $description = ''; |
|
69
|
|
|
|
|
70
|
|
|
/** @var array */ |
|
71
|
|
|
private $settings = []; |
|
72
|
|
|
|
|
73
|
|
|
/** @var int */ |
|
74
|
|
|
private $type; |
|
75
|
|
|
|
|
76
|
|
|
/** @var string */ |
|
77
|
|
|
private $creation; |
|
78
|
|
|
|
|
79
|
|
|
/** @var Member[] */ |
|
80
|
|
|
private $members; |
|
81
|
|
|
|
|
82
|
|
|
/** @var Member[] */ |
|
83
|
|
|
private $groups; |
|
84
|
|
|
|
|
85
|
|
|
/** @var FederatedLink[] */ |
|
86
|
|
|
private $links; |
|
87
|
|
|
|
|
88
|
|
|
public function __construct($l10n, $type = -1, $name = '') { |
|
89
|
|
|
$this->l10n = $l10n; |
|
90
|
|
|
|
|
91
|
|
|
if ($type > -1) { |
|
92
|
|
|
$this->type = $type; |
|
93
|
|
|
} |
|
94
|
|
|
if ($name !== '') { |
|
95
|
|
|
$this->name = $name; |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
|
|
100
|
|
|
public function setId($id) { |
|
101
|
|
|
$this->id = $id; |
|
102
|
|
|
|
|
103
|
|
|
return $this; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function getId() { |
|
107
|
|
|
return $this->id; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @param string $uniqueId |
|
113
|
|
|
* |
|
114
|
|
|
* @return $this |
|
115
|
|
|
*/ |
|
116
|
|
|
public function setUniqueId($uniqueId) { |
|
117
|
|
|
$this->uniqueId = (string)$uniqueId; |
|
118
|
|
|
|
|
119
|
|
|
return $this; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @param bool $full |
|
124
|
|
|
* |
|
125
|
|
|
* @return string |
|
126
|
|
|
*/ |
|
127
|
|
|
public function getUniqueId($full = false) { |
|
128
|
|
|
if ($full) { |
|
129
|
|
|
return $this->uniqueId; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
return substr($this->uniqueId, 0, 14); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
|
|
136
|
|
|
public function generateUniqueId() { |
|
137
|
|
|
$uniqueId = bin2hex(openssl_random_pseudo_bytes(24)); |
|
138
|
|
|
$this->setUniqueId($uniqueId); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
public function setName($name) { |
|
142
|
|
|
$this->name = $name; |
|
143
|
|
|
|
|
144
|
|
|
return $this; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
public function getName() { |
|
148
|
|
|
return $this->name; |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
|
|
152
|
|
|
public function getOwner() { |
|
153
|
|
|
return $this->owner; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
public function setOwner($owner) { |
|
157
|
|
|
$this->owner = $owner; |
|
158
|
|
|
|
|
159
|
|
|
return $this; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* @return Member |
|
165
|
|
|
*/ |
|
166
|
|
|
public function getViewer() { |
|
167
|
|
|
return $this->viewer; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
public function setViewer($user) { |
|
171
|
|
|
$this->viewer = $user; |
|
172
|
|
|
|
|
173
|
|
|
return $this; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* @return Member |
|
179
|
|
|
*/ |
|
180
|
|
|
public function getGroupViewer() { |
|
181
|
|
|
return $this->viewerGroup; |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
public function setGroupViewer($group) { |
|
185
|
|
|
$this->viewerGroup = $group; |
|
186
|
|
|
|
|
187
|
|
|
return $this; |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
|
|
191
|
|
|
/** |
|
192
|
|
|
* @return Member |
|
193
|
|
|
*/ |
|
194
|
|
|
public function getHigherViewer() { |
|
195
|
|
|
if ($this->getGroupViewer() === null) { |
|
196
|
|
|
return $this->getViewer(); |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
if ($this->getViewer() === null) { |
|
200
|
|
|
return $this->getGroupViewer(); |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
if ($this->getGroupViewer() |
|
204
|
|
|
->getLevel() > $this->getViewer() |
|
205
|
|
|
->getLevel() |
|
206
|
|
|
) { |
|
207
|
|
|
return $this->getGroupViewer(); |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
return $this->getViewer(); |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
|
|
214
|
|
|
public function setDescription($description) { |
|
215
|
|
|
$this->description = $description; |
|
216
|
|
|
|
|
217
|
|
|
return $this; |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
public function getDescription() { |
|
221
|
|
|
return $this->description; |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
|
|
225
|
|
|
public function setSettings($settings) { |
|
226
|
|
|
if (is_array($settings)) { |
|
227
|
|
|
$this->settings = $settings; |
|
228
|
|
|
} else if (is_string($settings)) { |
|
229
|
|
|
$this->settings = (array)json_decode($settings, true); |
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
|
|
return $this; |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
public function getSettings($json = false) { |
|
236
|
|
|
|
|
237
|
|
|
if ($json) { |
|
238
|
|
|
return json_encode($this->settings); |
|
239
|
|
|
} |
|
240
|
|
|
|
|
241
|
|
|
$settings = $this->settings; |
|
242
|
|
|
if ($settings === null) { |
|
243
|
|
|
$settings = []; |
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
|
|
$ak = array_keys(self::CIRCLES_SETTINGS_DEFAULT); |
|
247
|
|
|
foreach ($ak AS $k) { |
|
248
|
|
|
if (!key_exists($k, $settings)) { |
|
249
|
|
|
$settings[$k] = self::CIRCLES_SETTINGS_DEFAULT[$k]; |
|
250
|
|
|
} |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
return $settings; |
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
|
|
257
|
|
|
public function setSetting($k, $v) { |
|
258
|
|
|
switch ($k) { |
|
259
|
|
|
case 'circle_name': |
|
260
|
|
|
$this->setName($v); |
|
261
|
|
|
break; |
|
262
|
|
|
|
|
263
|
|
|
case 'circle_desc': |
|
264
|
|
|
$this->setDescription($v); |
|
265
|
|
|
break; |
|
266
|
|
|
|
|
267
|
|
|
default: |
|
268
|
|
|
$this->settings[$k] = $v; |
|
269
|
|
|
break; |
|
270
|
|
|
} |
|
271
|
|
|
} |
|
272
|
|
|
|
|
273
|
|
|
|
|
274
|
|
|
/** |
|
275
|
|
|
* @param string $k |
|
276
|
|
|
* |
|
277
|
|
|
* @return string|null |
|
278
|
|
|
*/ |
|
279
|
|
|
public function getSetting($k) { |
|
280
|
|
|
if (key_exists($k, $this->settings)) { |
|
281
|
|
|
return $this->settings[$k]; |
|
282
|
|
|
} |
|
283
|
|
|
if (key_exists($k, (array)self::CIRCLES_SETTINGS_DEFAULT)) { |
|
284
|
|
|
return self::CIRCLES_SETTINGS_DEFAULT[$k]; |
|
285
|
|
|
} |
|
286
|
|
|
|
|
287
|
|
|
return null; |
|
288
|
|
|
} |
|
289
|
|
|
|
|
290
|
|
|
|
|
291
|
|
|
public function setType($type) { |
|
292
|
|
|
$this->type = self::typeInt($type); |
|
293
|
|
|
|
|
294
|
|
|
return $this; |
|
295
|
|
|
} |
|
296
|
|
|
|
|
297
|
|
|
public function getType() { |
|
298
|
|
|
return $this->type; |
|
299
|
|
|
} |
|
300
|
|
|
|
|
301
|
|
|
|
|
302
|
|
|
public function setCreation($creation) { |
|
303
|
|
|
$this->creation = $creation; |
|
304
|
|
|
|
|
305
|
|
|
return $this; |
|
306
|
|
|
} |
|
307
|
|
|
|
|
308
|
|
|
public function getCreation() { |
|
309
|
|
|
return $this->creation; |
|
310
|
|
|
} |
|
311
|
|
|
|
|
312
|
|
|
|
|
313
|
|
|
public function setMembers($members) { |
|
314
|
|
|
$this->members = $members; |
|
315
|
|
|
|
|
316
|
|
|
return $this; |
|
317
|
|
|
} |
|
318
|
|
|
|
|
319
|
|
|
public function getMembers() { |
|
320
|
|
|
return $this->members; |
|
321
|
|
|
} |
|
322
|
|
|
|
|
323
|
|
|
|
|
324
|
|
|
public function setGroups($groups) { |
|
325
|
|
|
$this->groups = $groups; |
|
326
|
|
|
|
|
327
|
|
|
return $this; |
|
328
|
|
|
} |
|
329
|
|
|
|
|
330
|
|
|
public function getGroups() { |
|
331
|
|
|
return $this->groups; |
|
332
|
|
|
} |
|
333
|
|
|
|
|
334
|
|
|
|
|
335
|
|
|
public function setLinks($links) { |
|
336
|
|
|
$this->links = $links; |
|
337
|
|
|
|
|
338
|
|
|
return $this; |
|
339
|
|
|
} |
|
340
|
|
|
|
|
341
|
|
|
public function getLinks() { |
|
342
|
|
|
return $this->links; |
|
343
|
|
|
} |
|
344
|
|
|
|
|
345
|
|
|
|
|
346
|
|
|
// public function getRemote() { |
|
|
|
|
|
|
347
|
|
|
// return $this->remote; |
|
348
|
|
|
// } |
|
349
|
|
|
// |
|
350
|
|
|
// public function addRemote($link) { |
|
351
|
|
|
// array_push($this->remote, $link); |
|
352
|
|
|
// } |
|
353
|
|
|
// |
|
354
|
|
|
// public function getRemoteFromToken($token) { |
|
355
|
|
|
// foreach ($this->links AS $link) { |
|
356
|
|
|
// if ($link->getToken() === $token) { |
|
357
|
|
|
// return $link; |
|
358
|
|
|
// } |
|
359
|
|
|
// } |
|
360
|
|
|
// |
|
361
|
|
|
// return null; |
|
362
|
|
|
// } |
|
363
|
|
|
// |
|
364
|
|
|
// public function getRemoteFromAddressAndId($address, $id) { |
|
365
|
|
|
// foreach ($this->links AS $link) { |
|
366
|
|
|
// if ($link->getAddress() === $address && $link->getUniqueId() === $id) { |
|
367
|
|
|
// return $link; |
|
368
|
|
|
// } |
|
369
|
|
|
// } |
|
370
|
|
|
// |
|
371
|
|
|
// return null; |
|
372
|
|
|
// } |
|
373
|
|
|
|
|
374
|
|
|
|
|
375
|
|
|
public static function typeInt($type) { |
|
376
|
|
|
|
|
377
|
|
|
if (is_numeric($type)) { |
|
378
|
|
|
return (int)$type; |
|
379
|
|
|
} |
|
380
|
|
|
|
|
381
|
|
View Code Duplication |
switch ($type) { |
|
|
|
|
|
|
382
|
|
|
case 'Personal': |
|
383
|
|
|
return self::CIRCLES_PERSONAL; |
|
384
|
|
|
case 'Private': |
|
385
|
|
|
return self::CIRCLES_PRIVATE; |
|
386
|
|
|
case 'Hidden': |
|
387
|
|
|
return self::CIRCLES_HIDDEN; |
|
388
|
|
|
case 'Public': |
|
389
|
|
|
return self::CIRCLES_PUBLIC; |
|
390
|
|
|
} |
|
391
|
|
|
|
|
392
|
|
|
return 0; |
|
393
|
|
|
} |
|
394
|
|
|
} |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.