|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Andreas Fischer <[email protected]> |
|
6
|
|
|
* @author Bart Visscher <[email protected]> |
|
7
|
|
|
* @author Björn Schießle <[email protected]> |
|
8
|
|
|
* @author Joas Schilling <[email protected]> |
|
9
|
|
|
* @author Jörn Friedrich Dreyer <[email protected]> |
|
10
|
|
|
* @author Michael Gapczynski <[email protected]> |
|
11
|
|
|
* @author Michael Kuhn <[email protected]> |
|
12
|
|
|
* @author Morris Jobke <[email protected]> |
|
13
|
|
|
* @author Robin McCorkell <[email protected]> |
|
14
|
|
|
* @author Roeland Jago Douma <[email protected]> |
|
15
|
|
|
* @author Sam Tuke <[email protected]> |
|
16
|
|
|
* @author Stefan Weil <[email protected]> |
|
17
|
|
|
* @author Thomas Müller <[email protected]> |
|
18
|
|
|
* |
|
19
|
|
|
* @license AGPL-3.0 |
|
20
|
|
|
* |
|
21
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
22
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
23
|
|
|
* as published by the Free Software Foundation. |
|
24
|
|
|
* |
|
25
|
|
|
* This program is distributed in the hope that it will be useful, |
|
26
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
27
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
28
|
|
|
* GNU Affero General Public License for more details. |
|
29
|
|
|
* |
|
30
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
31
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
32
|
|
|
* |
|
33
|
|
|
*/ |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Public interface of ownCloud for apps to use. |
|
37
|
|
|
* Share Class |
|
38
|
|
|
* |
|
39
|
|
|
*/ |
|
40
|
|
|
|
|
41
|
|
|
// use OCP namespace for all classes that are considered public. |
|
42
|
|
|
// This means that they should be used by apps instead of the internal ownCloud classes |
|
43
|
|
|
namespace OCP; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* This class provides the ability for apps to share their content between users. |
|
47
|
|
|
* Apps must create a backend class that implements OCP\Share_Backend and register it with this class. |
|
48
|
|
|
* |
|
49
|
|
|
* It provides the following hooks: |
|
50
|
|
|
* - post_shared |
|
51
|
|
|
* @since 5.0.0 |
|
52
|
|
|
*/ |
|
53
|
|
|
class Share extends \OC\Share\Constants { |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Register a sharing backend class that implements OCP\Share_Backend for an item type |
|
57
|
|
|
* @param string $itemType Item type |
|
58
|
|
|
* @param string $class Backend class |
|
59
|
|
|
* @param string $collectionOf (optional) Depends on item type |
|
60
|
|
|
* @param array $supportedFileExtensions (optional) List of supported file extensions if this item type depends on files |
|
61
|
|
|
* @return boolean true if backend is registered or false if error |
|
62
|
|
|
* @since 5.0.0 |
|
63
|
|
|
*/ |
|
64
|
|
|
public static function registerBackend($itemType, $class, $collectionOf = null, $supportedFileExtensions = null) { |
|
65
|
|
|
return \OC\Share\Share::registerBackend($itemType, $class, $collectionOf, $supportedFileExtensions); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Get the items of item type shared with the current user |
|
70
|
|
|
* @param string $itemType |
|
71
|
|
|
* @param int $format (optional) Format type must be defined by the backend |
|
72
|
|
|
* @param mixed $parameters (optional) |
|
73
|
|
|
* @param int $limit Number of items to return (optional) Returns all by default |
|
74
|
|
|
* @param bool $includeCollections (optional) |
|
75
|
|
|
* @return mixed Return depends on format |
|
76
|
|
|
* @since 5.0.0 |
|
77
|
|
|
*/ |
|
78
|
|
|
public static function getItemsSharedWith($itemType, $format = self::FORMAT_NONE, |
|
79
|
|
|
$parameters = null, $limit = -1, $includeCollections = false) { |
|
80
|
|
|
|
|
81
|
|
|
return \OC\Share\Share::getItemsSharedWith($itemType, $format, $parameters, $limit, $includeCollections); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Get the items of item type shared with a user |
|
86
|
|
|
* @param string $itemType |
|
87
|
|
|
* @param string $user for which user we want the shares |
|
88
|
|
|
* @param int $format (optional) Format type must be defined by the backend |
|
89
|
|
|
* @param mixed $parameters (optional) |
|
90
|
|
|
* @param int $limit Number of items to return (optional) Returns all by default |
|
91
|
|
|
* @param bool $includeCollections (optional) |
|
92
|
|
|
* @return mixed Return depends on format |
|
93
|
|
|
* @since 7.0.0 |
|
94
|
|
|
*/ |
|
95
|
|
|
public static function getItemsSharedWithUser($itemType, $user, $format = self::FORMAT_NONE, |
|
96
|
|
|
$parameters = null, $limit = -1, $includeCollections = false) { |
|
97
|
|
|
|
|
98
|
|
|
return \OC\Share\Share::getItemsSharedWithUser($itemType, $user, $format, $parameters, $limit, $includeCollections); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Get the item of item type shared with a given user by source |
|
103
|
|
|
* @param string $itemType |
|
104
|
|
|
* @param string $itemSource |
|
105
|
|
|
* @param string $user User to whom the item was shared |
|
106
|
|
|
* @param string $owner Owner of the share |
|
107
|
|
|
* @return array Return list of items with file_target, permissions and expiration |
|
108
|
|
|
* @since 6.0.0 - parameter $owner was added in 8.0.0 |
|
109
|
|
|
*/ |
|
110
|
|
|
public static function getItemSharedWithUser($itemType, $itemSource, $user, $owner = null) { |
|
111
|
|
|
return \OC\Share\Share::getItemSharedWithUser($itemType, $itemSource, $user, $owner); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Get the item of item type shared with the current user by source |
|
116
|
|
|
* @param string $itemType |
|
117
|
|
|
* @param string $itemSource |
|
118
|
|
|
* @param int $format (optional) Format type must be defined by the backend |
|
119
|
|
|
* @param mixed $parameters |
|
120
|
|
|
* @param bool $includeCollections |
|
121
|
|
|
* @return array |
|
122
|
|
|
* @since 5.0.0 |
|
123
|
|
|
*/ |
|
124
|
|
|
public static function getItemSharedWithBySource($itemType, $itemSource, $format = self::FORMAT_NONE, |
|
125
|
|
|
$parameters = null, $includeCollections = false) { |
|
126
|
|
|
return \OC\Share\Share::getItemSharedWithBySource($itemType, $itemSource, $format, $parameters, $includeCollections); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* Based on the given token the share information will be returned - password protected shares will be verified |
|
131
|
|
|
* @param string $token |
|
132
|
|
|
* @param bool $checkPasswordProtection |
|
133
|
|
|
* @return array|bool false will be returned in case the token is unknown or unauthorized |
|
134
|
|
|
* @since 5.0.0 - parameter $checkPasswordProtection was added in 7.0.0 |
|
135
|
|
|
*/ |
|
136
|
|
|
public static function getShareByToken($token, $checkPasswordProtection = true) { |
|
137
|
|
|
return \OC\Share\Share::getShareByToken($token, $checkPasswordProtection); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* resolves reshares down to the last real share |
|
142
|
|
|
* @param array $linkItem |
|
143
|
|
|
* @return array file owner |
|
144
|
|
|
* @since 6.0.0 |
|
145
|
|
|
*/ |
|
146
|
|
|
public static function resolveReShare($linkItem) { |
|
147
|
|
|
return \OC\Share\Share::resolveReShare($linkItem); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* Get the shared items of item type owned by the current user |
|
153
|
|
|
* @param string $itemType |
|
154
|
|
|
* @param int $format (optional) Format type must be defined by the backend |
|
155
|
|
|
* @param mixed $parameters |
|
156
|
|
|
* @param int $limit Number of items to return (optional) Returns all by default |
|
157
|
|
|
* @param bool $includeCollections |
|
158
|
|
|
* @return mixed Return depends on format |
|
159
|
|
|
* @since 5.0.0 |
|
160
|
|
|
*/ |
|
161
|
|
|
public static function getItemsShared($itemType, $format = self::FORMAT_NONE, $parameters = null, |
|
162
|
|
|
$limit = -1, $includeCollections = false) { |
|
163
|
|
|
|
|
164
|
|
|
return \OC\Share\Share::getItemsShared($itemType, $format, $parameters, $limit, $includeCollections); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* Get the shared item of item type owned by the current user |
|
169
|
|
|
* @param string $itemType |
|
170
|
|
|
* @param string $itemSource |
|
171
|
|
|
* @param int $format (optional) Format type must be defined by the backend |
|
172
|
|
|
* @param mixed $parameters |
|
173
|
|
|
* @param bool $includeCollections |
|
174
|
|
|
* @return mixed Return depends on format |
|
175
|
|
|
* @since 5.0.0 |
|
176
|
|
|
*/ |
|
177
|
|
|
public static function getItemShared($itemType, $itemSource, $format = self::FORMAT_NONE, |
|
178
|
|
|
$parameters = null, $includeCollections = false) { |
|
179
|
|
|
|
|
180
|
|
|
return \OC\Share\Share::getItemShared($itemType, $itemSource, $format, $parameters, $includeCollections); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* Share an item with a user, group, or via private link |
|
185
|
|
|
* @param string $itemType |
|
186
|
|
|
* @param string $itemSource |
|
187
|
|
|
* @param int $shareType SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK |
|
188
|
|
|
* @param string $shareWith User or group the item is being shared with |
|
189
|
|
|
* @param int $permissions CRUDS |
|
190
|
|
|
* @param string $itemSourceName |
|
191
|
|
|
* @param \DateTime|null $expirationDate |
|
192
|
|
|
* @param bool|null $passwordChanged |
|
193
|
|
|
* @return bool|string Returns true on success or false on failure, Returns token on success for links |
|
194
|
|
|
* @throws \OC\HintException when the share type is remote and the shareWith is invalid |
|
195
|
|
|
* @throws \Exception |
|
196
|
|
|
* @since 5.0.0 - parameter $itemSourceName was added in 6.0.0, parameter $expirationDate was added in 7.0.0, parameter $passwordChanged added in 9.0.0 |
|
197
|
|
|
*/ |
|
198
|
|
|
public static function shareItem($itemType, $itemSource, $shareType, $shareWith, $permissions, $itemSourceName = null, \DateTime $expirationDate = null, $passwordChanged = null) { |
|
199
|
|
|
return \OC\Share\Share::shareItem($itemType, $itemSource, $shareType, $shareWith, $permissions, $itemSourceName, $expirationDate, $passwordChanged); |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
/** |
|
203
|
|
|
* Unshare an item from a user, group, or delete a private link |
|
204
|
|
|
* @param string $itemType |
|
205
|
|
|
* @param string $itemSource |
|
206
|
|
|
* @param int $shareType SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK |
|
207
|
|
|
* @param string $shareWith User or group the item is being shared with |
|
208
|
|
|
* @param string $owner owner of the share, if null the current user is used |
|
209
|
|
|
* @return boolean true on success or false on failure |
|
210
|
|
|
* @since 5.0.0 - parameter $owner was added in 8.0.0 |
|
211
|
|
|
*/ |
|
212
|
|
|
public static function unshare($itemType, $itemSource, $shareType, $shareWith, $owner = null) { |
|
213
|
|
|
return \OC\Share\Share::unshare($itemType, $itemSource, $shareType, $shareWith, $owner); |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
/** |
|
217
|
|
|
* sent status if users got informed by mail about share |
|
218
|
|
|
* @param string $itemType |
|
219
|
|
|
* @param string $itemSource |
|
220
|
|
|
* @param int $shareType SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK |
|
221
|
|
|
* @param string $recipient with whom was the item shared |
|
222
|
|
|
* @param bool $status |
|
223
|
|
|
* @since 6.0.0 - parameter $originIsSource was added in 8.0.0 |
|
224
|
|
|
*/ |
|
225
|
|
|
public static function setSendMailStatus($itemType, $itemSource, $shareType, $recipient, $status) { |
|
226
|
|
|
return \OC\Share\Share::setSendMailStatus($itemType, $itemSource, $shareType, $recipient, $status); |
|
227
|
|
|
} |
|
228
|
|
|
|
|
229
|
|
|
/** |
|
230
|
|
|
* Get the backend class for the specified item type |
|
231
|
|
|
* @param string $itemType |
|
232
|
|
|
* @return Share_Backend |
|
233
|
|
|
* @since 5.0.0 |
|
234
|
|
|
*/ |
|
235
|
|
|
public static function getBackend($itemType) { |
|
236
|
|
|
return \OC\Share\Share::getBackend($itemType); |
|
237
|
|
|
} |
|
238
|
|
|
} |
|
239
|
|
|
|