1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only |
4
|
|
|
* SPDX-FileCopyrightText: Copyright 2022 grommunio GmbH |
5
|
|
|
* |
6
|
|
|
* Cache shared public folder hierarchy information. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
class SharedFolders extends InterProcessData { |
10
|
|
|
public static $instance = false; |
11
|
|
|
|
12
|
|
|
public static function GetSharedFolders() { |
13
|
|
|
if (!self::$instance) { |
14
|
|
|
self::$instance = new SharedFolders(); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
return self::$instance->GetSharedFoldersRaw(); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Constructor. |
22
|
|
|
*/ |
23
|
|
|
public function __construct() { |
24
|
|
|
// initialize super parameters |
25
|
|
|
$this->allocate = 0; |
26
|
|
|
$this->localpart = "undefined"; |
|
|
|
|
27
|
|
|
$this->mainDomain = "undefined"; |
|
|
|
|
28
|
|
|
if (preg_match('/^([*+!.&#$|\'\\%\/0-9a-z^_`{}=?~:-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})$/i', nsp_getuserinfo(Request::GetUser())['primary_email'], $matches)) { |
29
|
|
|
$this->localpart = $matches[1]; |
30
|
|
|
$this->mainDomain = $matches[2]; |
31
|
|
|
} |
32
|
|
|
$this->type = "grommunio-sync:sharedfolders-" . $this->mainDomain; |
33
|
|
|
parent::__construct(); |
34
|
|
|
// initialize params |
35
|
|
|
$this->initializeParams(); |
36
|
|
|
|
37
|
|
|
// get cached data from redis |
38
|
|
|
$shared = $this->getDeviceUserData($this->type, $this->localpart, -1); |
39
|
|
|
|
40
|
|
|
// no shared folder in redis for this user, get them from the public folder |
41
|
|
|
if (empty($shared)) { |
42
|
|
|
$shared = GSync::GetBackend()->GetPublicSyncEnabledFolders(); |
43
|
|
|
$this->setDeviceUserData($this->type, $shared, $this->localpart, -1); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function GetSharedFoldersRaw() { |
48
|
|
|
// get cached data from redis |
49
|
|
|
$shared = $this->getDeviceUserData($this->type, $this->localpart, -1); |
50
|
|
|
if (!$shared) { |
51
|
|
|
return []; |
52
|
|
|
} |
53
|
|
|
return $shared; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|