Blame view
sources/lib/public/share.php
15.1 KB
|
03e52840d
|
1 2 |
<?php /** |
|
31b7f2792
|
3 4 |
* ownCloud * |
|
6d9380f96
|
5 6 7 |
* @author Bjoern Schiessle, Michael Gapczynski * @copyright 2012 Michael Gapczynski <mtgap@owncloud.com> * 2014 Bjoern Schiessle <schiessle@owncloud.com> |
|
31b7f2792
|
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
* * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE * License as published by the Free Software Foundation; either * version 3 of the License, or any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU AFFERO GENERAL PUBLIC LICENSE for more details. * * You should have received a copy of the GNU Affero General Public * License along with this library. If not, see <http://www.gnu.org/licenses/>. */ /** * Public interface of ownCloud for apps to use. * Share Class * */ // use OCP namespace for all classes that are considered public. // This means that they should be used by apps instead of the internal ownCloud classes |
|
03e52840d
|
31 32 33 |
namespace OCP; /** |
|
31b7f2792
|
34 35 36 37 38 39 |
* This class provides the ability for apps to share their content between users. * Apps must create a backend class that implements OCP\Share_Backend and register it with this class. * * It provides the following hooks: * - post_shared */ |
|
6d9380f96
|
40 |
class Share extends \OC\Share\Constants {
|
|
03e52840d
|
41 42 |
/** |
|
31b7f2792
|
43 |
* Register a sharing backend class that implements OCP\Share_Backend for an item type |
|
6d9380f96
|
44 45 46 47 48 |
* @param string $itemType Item type * @param string $class Backend class * @param string $collectionOf (optional) Depends on item type * @param array $supportedFileExtensions (optional) List of supported file extensions if this item type depends on files * @return boolean true if backend is registered or false if error |
|
31b7f2792
|
49 |
*/ |
|
03e52840d
|
50 |
public static function registerBackend($itemType, $class, $collectionOf = null, $supportedFileExtensions = null) {
|
|
6d9380f96
|
51 |
return \OC\Share\Share::registerBackend($itemType, $class, $collectionOf, $supportedFileExtensions); |
|
03e52840d
|
52 53 54 |
} /** |
|
31b7f2792
|
55 |
* Check if the Share API is enabled |
|
6d9380f96
|
56 |
* @return boolean true if enabled or false |
|
31b7f2792
|
57 58 59 |
* * The Share API is enabled by default if not configured */ |
|
03e52840d
|
60 |
public static function isEnabled() {
|
|
6d9380f96
|
61 |
return \OC\Share\Share::isEnabled(); |
|
03e52840d
|
62 63 64 |
} /** |
|
31b7f2792
|
65 |
* Find which users can access a shared item |
|
6d9380f96
|
66 67 68 69 |
* @param string $path to the file * @param string $ownerUser owner of the file * @param bool $includeOwner include owner to the list of users with access to the file * @param bool $returnUserPaths Return an array with the user => path map |
|
31b7f2792
|
70 71 72 73 |
* @return array * @note $path needs to be relative to user data dir, e.g. 'file.txt' * not '/admin/data/file.txt' */ |
|
6d9380f96
|
74 75 |
public static function getUsersSharingFile($path, $ownerUser, $includeOwner = false, $returnUserPaths = false) {
return \OC\Share\Share::getUsersSharingFile($path, $ownerUser, $includeOwner, $returnUserPaths);
|
|
03e52840d
|
76 77 78 |
} /** |
|
31b7f2792
|
79 |
* Get the items of item type shared with the current user |
|
6d9380f96
|
80 81 82 83 84 85 |
* @param string $itemType * @param int $format (optional) Format type must be defined by the backend * @param mixed $parameters (optional) * @param int $limit Number of items to return (optional) Returns all by default * @param bool $includeCollections (optional) * @return mixed Return depends on format |
|
31b7f2792
|
86 |
*/ |
|
03e52840d
|
87 88 |
public static function getItemsSharedWith($itemType, $format = self::FORMAT_NONE,
$parameters = null, $limit = -1, $includeCollections = false) {
|
|
6d9380f96
|
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
return \OC\Share\Share::getItemsSharedWith($itemType, $format, $parameters, $limit, $includeCollections);
}
/**
* Get the items of item type shared with a user
* @param string $itemType
* @param string $user for which user we want the shares
* @param int $format (optional) Format type must be defined by the backend
* @param mixed $parameters (optional)
* @param int $limit Number of items to return (optional) Returns all by default
* @param bool $includeCollections (optional)
* @return mixed Return depends on format
*/
public static function getItemsSharedWithUser($itemType, $user, $format = self::FORMAT_NONE,
$parameters = null, $limit = -1, $includeCollections = false) {
return \OC\Share\Share::getItemsSharedWithUser($itemType, $user, $format, $parameters, $limit, $includeCollections);
|
|
03e52840d
|
107 108 109 |
} /** |
|
31b7f2792
|
110 111 112 113 |
* Get the item of item type shared with the current user * @param string $itemType * @param string $itemTarget * @param int $format (optional) Format type must be defined by the backend |
|
6d9380f96
|
114 115 116 |
* @param mixed $parameters (optional) * @param bool $includeCollections (optional) * @return mixed Return depends on format |
|
31b7f2792
|
117 |
*/ |
|
03e52840d
|
118 119 |
public static function getItemSharedWith($itemType, $itemTarget, $format = self::FORMAT_NONE,
$parameters = null, $includeCollections = false) {
|
|
6d9380f96
|
120 121 |
return \OC\Share\Share::getItemSharedWith($itemType, $itemTarget, $format, $parameters, $includeCollections); |
|
03e52840d
|
122 123 124 |
} /** |
|
31b7f2792
|
125 126 127 128 129 130 131 |
* Get the item of item type shared with a given user by source
* @param string $itemType
* @param string $itemSource
* @param string $user User user to whom the item was shared
* @return array Return list of items with file_target, permissions and expiration
*/
public static function getItemSharedWithUser($itemType, $itemSource, $user) {
|
|
6d9380f96
|
132 |
return \OC\Share\Share::getItemSharedWithUser($itemType, $itemSource, $user); |
|
31b7f2792
|
133 134 135 136 |
} /** * Get the item of item type shared with the current user by source |
|
6d9380f96
|
137 138 139 140 141 142 |
* @param string $itemType * @param string $itemSource * @param int $format (optional) Format type must be defined by the backend * @param mixed $parameters * @param bool $includeCollections * @return mixed Return depends on format |
|
31b7f2792
|
143 |
*/ |
|
03e52840d
|
144 145 |
public static function getItemSharedWithBySource($itemType, $itemSource, $format = self::FORMAT_NONE,
$parameters = null, $includeCollections = false) {
|
|
6d9380f96
|
146 |
return \OC\Share\Share::getItemSharedWithBySource($itemType, $itemSource, $format, $parameters, $includeCollections); |
|
03e52840d
|
147 148 149 |
} /** |
|
31b7f2792
|
150 |
* Get the item of item type shared by a link |
|
6d9380f96
|
151 152 153 |
* @param string $itemType * @param string $itemSource * @param string $uidOwner Owner of link |
|
31b7f2792
|
154 155 |
* @return Item */ |
|
03e52840d
|
156 |
public static function getItemSharedWithByLink($itemType, $itemSource, $uidOwner) {
|
|
6d9380f96
|
157 |
return \OC\Share\Share::getItemSharedWithByLink($itemType, $itemSource, $uidOwner); |
|
03e52840d
|
158 159 160 |
} /** |
|
a293d369c
|
161 162 |
* Based on the given token the share information will be returned - password protected shares will be verified * @param string $token |
|
6d9380f96
|
163 |
* @return array|bool false will be returned in case the token is unknown or unauthorized |
|
03e52840d
|
164 |
*/ |
|
a293d369c
|
165 |
public static function getShareByToken($token, $checkPasswordProtection = true) {
|
|
6d9380f96
|
166 |
return \OC\Share\Share::getShareByToken($token, $checkPasswordProtection); |
|
03e52840d
|
167 168 169 |
} /** |
|
31b7f2792
|
170 |
* resolves reshares down to the last real share |
|
6d9380f96
|
171 172 |
* @param array $linkItem * @return array file owner |
|
03e52840d
|
173 |
*/ |
|
6d9380f96
|
174 175 |
public static function resolveReShare($linkItem) {
return \OC\Share\Share::resolveReShare($linkItem);
|
|
03e52840d
|
176 177 178 179 |
} /** |
|
31b7f2792
|
180 |
* Get the shared items of item type owned by the current user |
|
6d9380f96
|
181 182 183 184 185 186 |
* @param string $itemType * @param int $format (optional) Format type must be defined by the backend * @param mixed $parameters * @param int $limit Number of items to return (optional) Returns all by default * @param bool $includeCollections * @return mixed Return depends on format |
|
31b7f2792
|
187 |
*/ |
|
03e52840d
|
188 189 |
public static function getItemsShared($itemType, $format = self::FORMAT_NONE, $parameters = null,
$limit = -1, $includeCollections = false) {
|
|
6d9380f96
|
190 191 |
return \OC\Share\Share::getItemsShared($itemType, $format, $parameters, $limit, $includeCollections); |
|
03e52840d
|
192 193 194 |
} /** |
|
31b7f2792
|
195 |
* Get the shared item of item type owned by the current user |
|
6d9380f96
|
196 197 198 199 200 201 |
* @param string $itemType * @param string $itemSource * @param int $format (optional) Format type must be defined by the backend * @param mixed $parameters * @param bool $includeCollections * @return mixed Return depends on format |
|
31b7f2792
|
202 |
*/ |
|
03e52840d
|
203 204 |
public static function getItemShared($itemType, $itemSource, $format = self::FORMAT_NONE,
$parameters = null, $includeCollections = false) {
|
|
6d9380f96
|
205 206 |
return \OC\Share\Share::getItemShared($itemType, $itemSource, $format, $parameters, $includeCollections); |
|
03e52840d
|
207 208 209 |
} /** |
|
31b7f2792
|
210 |
* Get all users an item is shared with |
|
6d9380f96
|
211 212 213 214 215 216 |
* @param string $itemType * @param string $itemSource * @param string $uidOwner * @param bool $includeCollections * @param bool $checkExpireDate * @return array Return array of users |
|
31b7f2792
|
217 218 |
*/
public static function getUsersItemShared($itemType, $itemSource, $uidOwner, $includeCollections = false, $checkExpireDate = true) {
|
|
6d9380f96
|
219 |
return \OC\Share\Share::getUsersItemShared($itemType, $itemSource, $uidOwner, $includeCollections, $checkExpireDate); |
|
03e52840d
|
220 221 222 |
} /** |
|
31b7f2792
|
223 224 225 226 227 228 |
* Share an item with a user, group, or via private link * @param string $itemType * @param string $itemSource * @param int $shareType SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK * @param string $shareWith User or group the item is being shared with * @param int $permissions CRUDS |
|
6d9380f96
|
229 230 |
* @param string $itemSourceName * @param \DateTime $expirationDate |
|
31b7f2792
|
231 |
* @return bool|string Returns true on success or false on failure, Returns token on success for links |
|
6d9380f96
|
232 |
* @throws \Exception |
|
31b7f2792
|
233 |
*/ |
|
6d9380f96
|
234 235 |
public static function shareItem($itemType, $itemSource, $shareType, $shareWith, $permissions, $itemSourceName = null, \DateTime $expirationDate = null) {
return \OC\Share\Share::shareItem($itemType, $itemSource, $shareType, $shareWith, $permissions, $itemSourceName, $expirationDate);
|
|
03e52840d
|
236 237 238 |
} /** |
|
31b7f2792
|
239 |
* Unshare an item from a user, group, or delete a private link |
|
6d9380f96
|
240 241 242 243 244 |
* @param string $itemType * @param string $itemSource * @param int $shareType SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK * @param string $shareWith User or group the item is being shared with * @return boolean true on success or false on failure |
|
31b7f2792
|
245 |
*/ |
|
03e52840d
|
246 |
public static function unshare($itemType, $itemSource, $shareType, $shareWith) {
|
|
6d9380f96
|
247 |
return \OC\Share\Share::unshare($itemType, $itemSource, $shareType, $shareWith); |
|
03e52840d
|
248 249 250 |
} /** |
|
31b7f2792
|
251 |
* Unshare an item from all users, groups, and remove all links |
|
6d9380f96
|
252 253 254 |
* @param string $itemType * @param string $itemSource * @return boolean true on success or false on failure |
|
31b7f2792
|
255 |
*/ |
|
03e52840d
|
256 |
public static function unshareAll($itemType, $itemSource) {
|
|
6d9380f96
|
257 |
return \OC\Share\Share::unshareAll($itemType, $itemSource); |
|
03e52840d
|
258 259 260 |
} /** |
|
31b7f2792
|
261 |
* Unshare an item shared with the current user |
|
6d9380f96
|
262 263 264 |
* @param string $itemType * @param string $itemTarget * @return boolean true on success or false on failure |
|
31b7f2792
|
265 266 267 |
* * Unsharing from self is not allowed for items inside collections */ |
|
03e52840d
|
268 |
public static function unshareFromSelf($itemType, $itemTarget) {
|
|
6d9380f96
|
269 |
return \OC\Share\Share::unshareFromSelf($itemType, $itemTarget); |
|
03e52840d
|
270 |
} |
|
6d9380f96
|
271 |
|
|
31b7f2792
|
272 273 274 275 276 277 278 279 |
/**
* sent status if users got informed by mail about share
* @param string $itemType
* @param string $itemSource
* @param int $shareType SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK
* @param bool $status
*/
public static function setSendMailStatus($itemType, $itemSource, $shareType, $status) {
|
|
6d9380f96
|
280 |
return \OC\Share\Share::setSendMailStatus($itemType, $itemSource, $shareType, $status); |
|
31b7f2792
|
281 |
} |
|
03e52840d
|
282 283 |
/** |
|
31b7f2792
|
284 |
* Set the permissions of an item for a specific user or group |
|
6d9380f96
|
285 286 287 288 289 290 |
* @param string $itemType * @param string $itemSource * @param int $shareType SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK * @param string $shareWith User or group the item is being shared with * @param int $permissions CRUDS permissions * @return boolean true on success or false on failure |
|
31b7f2792
|
291 |
*/ |
|
03e52840d
|
292 |
public static function setPermissions($itemType, $itemSource, $shareType, $shareWith, $permissions) {
|
|
6d9380f96
|
293 |
return \OC\Share\Share::setPermissions($itemType, $itemSource, $shareType, $shareWith, $permissions); |
|
03e52840d
|
294 |
} |
|
31b7f2792
|
295 296 297 298 299 |
/** * Set expiration date for a share * @param string $itemType * @param string $itemSource * @param string $date expiration date |
|
6d9380f96
|
300 301 |
* @param int $shareTime timestamp from when the file was shared * @return boolean |
|
31b7f2792
|
302 |
*/ |
|
6d9380f96
|
303 304 |
public static function setExpirationDate($itemType, $itemSource, $date, $shareTime = null) {
return \OC\Share\Share::setExpirationDate($itemType, $itemSource, $date, $shareTime);
|
|
31b7f2792
|
305 306 307 308 309 310 311 |
} /** * Get the backend class for the specified item type * @param string $itemType * @return Share_Backend */ |
|
03e52840d
|
312 |
public static function getBackend($itemType) {
|
|
6d9380f96
|
313 |
return \OC\Share\Share::getBackend($itemType); |
|
03e52840d
|
314 315 316 |
} /** |
|
31b7f2792
|
317 318 319 |
* Delete all shares with type SHARE_TYPE_LINK
*/
public static function removeAllLinkShares() {
|
|
6d9380f96
|
320 |
return \OC\Share\Share::removeAllLinkShares(); |
|
03e52840d
|
321 |
} |
|
a293d369c
|
322 323 324 325 326 327 328 |
/**
* In case a password protected link is not yet authenticated this function will return false
*
* @param array $linkItem
* @return bool
*/
public static function checkPasswordProtectedShare(array $linkItem) {
|
|
6d9380f96
|
329 |
return \OC\Share\Share::checkPasswordProtectedShare($linkItem); |
|
a293d369c
|
330 |
} |
|
03e52840d
|
331 332 333 |
} /** |
|
31b7f2792
|
334 335 |
* Interface that apps must implement to share content. */ |
|
03e52840d
|
336 337 338 |
interface Share_Backend {
/**
|
|
6d9380f96
|
339 340 341 342 |
* Check if this $itemSource exist for the user * @param string $itemSource * @param string $uidOwner Owner of the item * @return boolean|null Source |
|
31b7f2792
|
343 |
* |
|
31b7f2792
|
344 |
* Return false if the item does not exist for the user |
|
31b7f2792
|
345 |
*/ |
|
03e52840d
|
346 347 348 |
public function isValidSource($itemSource, $uidOwner); /** |
|
31b7f2792
|
349 |
* Get a unique name of the item for the specified user |
|
6d9380f96
|
350 351 352 |
* @param string $itemSource * @param string|false $shareWith User the item is being shared with * @param array|null $exclude List of similar item names already existing as shared items |
|
31b7f2792
|
353 354 355 356 357 |
* @return string Target name * * This function needs to verify that the user does not already have an item with this name. * If it does generate a new name e.g. name_# */ |
|
03e52840d
|
358 359 360 |
public function generateTarget($itemSource, $shareWith, $exclude = null); /** |
|
31b7f2792
|
361 |
* Converts the shared item sources back into the item in the specified format |
|
6d9380f96
|
362 363 |
* @param array $items Shared items * @param int $format |
|
31b7f2792
|
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 |
* @return TODO * * The items array is a 3-dimensional array with the item_source as the * first key and the share id as the second key to an array with the share * info. * * The key/value pairs included in the share info depend on the function originally called: * If called by getItem(s)Shared: id, item_type, item, item_source, * share_type, share_with, permissions, stime, file_source * * If called by getItem(s)SharedWith: id, item_type, item, item_source, * item_target, share_type, share_with, permissions, stime, file_source, * file_target * * This function allows the backend to control the output of shared items with custom formats. * It is only called through calls to the public getItem(s)Shared(With) functions. */ |
|
03e52840d
|
381 382 383 384 385 |
public function formatItems($items, $format, $parameters = null); } /** |
|
31b7f2792
|
386 387 388 |
* Interface for share backends that share content that is dependent on files. * Extends the Share_Backend interface. */ |
|
03e52840d
|
389 390 391 |
interface Share_Backend_File_Dependent extends Share_Backend {
/**
|
|
31b7f2792
|
392 |
* Get the file path of the item |
|
6d9380f96
|
393 394 395 |
* @param string $itemSource * @param string $uidOwner User that is the owner of shared item * @return string|false |
|
31b7f2792
|
396 |
*/ |
|
03e52840d
|
397 398 399 400 401 |
public function getFilePath($itemSource, $uidOwner); } /** |
|
31b7f2792
|
402 403 404 |
* Interface for collections of of items implemented by another share backend. * Extends the Share_Backend interface. */ |
|
03e52840d
|
405 406 407 |
interface Share_Backend_Collection extends Share_Backend {
/**
|
|
31b7f2792
|
408 |
* Get the sources of the children of the item |
|
6d9380f96
|
409 |
* @param string $itemSource |
|
31b7f2792
|
410 411 |
* @return array Returns an array of children each inside an array with the keys: source, target, and file_path if applicable */ |
|
03e52840d
|
412 413 414 |
public function getChildren($itemSource); } |