\OCPShare

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

Summary

Methods
Properties
Constants
registerBackend()
isEnabled()
getUsersSharingFile()
getItemsSharedWith()
getItemsSharedWithUser()
getItemSharedWith()
getItemSharedWithUser()
getItemSharedWithBySource()
getItemSharedWithByLink()
getShareByToken()
resolveReShare()
getItemsShared()
getItemShared()
getUsersItemShared()
shareItem()
unshare()
unshareAll()
unshareFromSelf()
setSendMailStatus()
setPermissions()
setExpirationDate()
setPassword()
getBackend()
removeAllLinkShares()
checkPasswordProtectedShare()
isResharingAllowed()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

registerBackend()

registerBackend(string  $itemType, string  $class, string  $collectionOf = null, array  $supportedFileExtensions = null) : boolean

Register a sharing backend class that implements OCP\Share_Backend for an item type

Parameters

string $itemType

Item type

string $class

Backend class

string $collectionOf

(optional) Depends on item type

array $supportedFileExtensions

(optional) List of supported file extensions if this item type depends on files

Returns

boolean —

true if backend is registered or false if error

isEnabled()

isEnabled() : boolean

Check if the Share API is enabled

Returns

boolean —

true if enabled or false

The Share API is enabled by default if not configured

getUsersSharingFile()

getUsersSharingFile(string  $path, string  $ownerUser, boolean  $includeOwner = false, boolean  $returnUserPaths = false, boolean  $recursive = true) : array

Find which users can access a shared item

Parameters

string $path

to the file

string $ownerUser

owner of the file

boolean $includeOwner

include owner to the list of users with access to the file

boolean $returnUserPaths

Return an array with the user => path map

boolean $recursive

take parent folders into account

Returns

array

getItemsSharedWith()

getItemsSharedWith(string  $itemType, integer  $format = self::FORMAT_NONE, mixed  $parameters = null, integer  $limit = -1, boolean  $includeCollections = false) : mixed

Get the items of item type shared with the current user

Parameters

string $itemType
integer $format

(optional) Format type must be defined by the backend

mixed $parameters

(optional)

integer $limit

Number of items to return (optional) Returns all by default

boolean $includeCollections

(optional)

Returns

mixed —

Return depends on format

getItemsSharedWithUser()

getItemsSharedWithUser(string  $itemType, string  $user, integer  $format = self::FORMAT_NONE, mixed  $parameters = null, integer  $limit = -1, boolean  $includeCollections = false) : mixed

Get the items of item type shared with a user

Parameters

string $itemType
string $user

for which user we want the shares

integer $format

(optional) Format type must be defined by the backend

mixed $parameters

(optional)

integer $limit

Number of items to return (optional) Returns all by default

boolean $includeCollections

(optional)

Returns

mixed —

Return depends on format

getItemSharedWith()

getItemSharedWith(string  $itemType, string  $itemTarget, integer  $format = self::FORMAT_NONE, mixed  $parameters = null, boolean  $includeCollections = false) : mixed

Get the item of item type shared with the current user

Parameters

string $itemType
string $itemTarget
integer $format

(optional) Format type must be defined by the backend

mixed $parameters

(optional)

boolean $includeCollections

(optional)

Returns

mixed —

Return depends on format

getItemSharedWithUser()

getItemSharedWithUser(string  $itemType, string  $itemSource, string  $user, string  $owner = null) : array

Get the item of item type shared with a given user by source

Parameters

string $itemType
string $itemSource
string $user

User to whom the item was shared

string $owner

Owner of the share

Returns

array —

Return list of items with file_target, permissions and expiration

getItemSharedWithBySource()

getItemSharedWithBySource(string  $itemType, string  $itemSource, integer  $format = self::FORMAT_NONE, mixed  $parameters = null, boolean  $includeCollections = false) : array

Get the item of item type shared with the current user by source

Parameters

string $itemType
string $itemSource
integer $format

(optional) Format type must be defined by the backend

mixed $parameters
boolean $includeCollections

Returns

array

getItemSharedWithByLink()

getItemSharedWithByLink(string  $itemType, string  $itemSource, string  $uidOwner) : array

Get the item of item type shared by a link

Parameters

string $itemType
string $itemSource
string $uidOwner

Owner of link

Returns

array

getShareByToken()

getShareByToken(string  $token, boolean  $checkPasswordProtection = true) : array|boolean

Based on the given token the share information will be returned - password protected shares will be verified

Parameters

string $token
boolean $checkPasswordProtection

Returns

array|boolean —

false will be returned in case the token is unknown or unauthorized

resolveReShare()

resolveReShare(array  $linkItem) : array

resolves reshares down to the last real share

Parameters

array $linkItem

Returns

array —

file owner

getItemsShared()

getItemsShared(string  $itemType, integer  $format = self::FORMAT_NONE, mixed  $parameters = null, integer  $limit = -1, boolean  $includeCollections = false) : mixed

Get the shared items of item type owned by the current user

Parameters

string $itemType
integer $format

(optional) Format type must be defined by the backend

mixed $parameters
integer $limit

Number of items to return (optional) Returns all by default

boolean $includeCollections

Returns

mixed —

Return depends on format

getItemShared()

getItemShared(string  $itemType, string  $itemSource, integer  $format = self::FORMAT_NONE, mixed  $parameters = null, boolean  $includeCollections = false) : mixed

Get the shared item of item type owned by the current user

Parameters

string $itemType
string $itemSource
integer $format

(optional) Format type must be defined by the backend

mixed $parameters
boolean $includeCollections

Returns

mixed —

Return depends on format

getUsersItemShared()

getUsersItemShared(string  $itemType, string  $itemSource, string  $uidOwner, boolean  $includeCollections = false, boolean  $checkExpireDate = true) : array

Get all users an item is shared with

Parameters

string $itemType
string $itemSource
string $uidOwner
boolean $includeCollections
boolean $checkExpireDate

Returns

array —

Return array of users

shareItem()

shareItem(string  $itemType, string  $itemSource, integer  $shareType, string  $shareWith, integer  $permissions, string  $itemSourceName = null, \DateTime  $expirationDate = null, boolean  $passwordChanged = null) : boolean|string

Share an item with a user, group, or via private link

Parameters

string $itemType
string $itemSource
integer $shareType

SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK

string $shareWith

User or group the item is being shared with

integer $permissions

CRUDS

string $itemSourceName
\DateTime $expirationDate
boolean $passwordChanged

Throws

\OC\HintException

when the share type is remote and the shareWith is invalid

\Exception

Returns

boolean|string —

Returns true on success or false on failure, Returns token on success for links

unshare()

unshare(string  $itemType, string  $itemSource, integer  $shareType, string  $shareWith, string  $owner = null) : boolean

Unshare an item from a user, group, or delete a private link

Parameters

string $itemType
string $itemSource
integer $shareType

SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK

string $shareWith

User or group the item is being shared with

string $owner

owner of the share, if null the current user is used

Returns

boolean —

true on success or false on failure

unshareAll()

unshareAll(string  $itemType, string  $itemSource) : boolean

Unshare an item from all users, groups, and remove all links

Parameters

string $itemType
string $itemSource

Returns

boolean —

true on success or false on failure

unshareFromSelf()

unshareFromSelf(string  $itemType, string  $itemOrigin, boolean  $originIsSource = false) : boolean

Unshare an item shared with the current user

Parameters

string $itemType
string $itemOrigin

Item target or source

boolean $originIsSource

true if $itemOrigin is the source, false if $itemOrigin is the target (optional)

Returns

boolean —

true on success or false on failure

Unsharing from self is not allowed for items inside collections

setSendMailStatus()

setSendMailStatus(string  $itemType, string  $itemSource, integer  $shareType, string  $recipient, boolean  $status) 

sent status if users got informed by mail about share

Parameters

string $itemType
string $itemSource
integer $shareType

SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK

string $recipient

with whom was the item shared

boolean $status

setPermissions()

setPermissions(string  $itemType, string  $itemSource, integer  $shareType, string  $shareWith, integer  $permissions) : boolean

Set the permissions of an item for a specific user or group

Parameters

string $itemType
string $itemSource
integer $shareType

SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK

string $shareWith

User or group the item is being shared with

integer $permissions

CRUDS permissions

Returns

boolean —

true on success or false on failure

setExpirationDate()

setExpirationDate(string  $itemType, string  $itemSource, string  $date, integer  $shareTime = null) : boolean

Set expiration date for a share

Parameters

string $itemType
string $itemSource
string $date

expiration date

integer $shareTime

timestamp from when the file was shared

Returns

boolean

setPassword()

setPassword(integer  $shareId, string  $password) : boolean

Set password for a public link share

Parameters

integer $shareId
string $password

Returns

boolean

getBackend()

getBackend(string  $itemType) : \OCP\Share_Backend

Get the backend class for the specified item type

Parameters

string $itemType

Returns

\OCP\Share_Backend

removeAllLinkShares()

removeAllLinkShares() 

Delete all shares with type SHARE_TYPE_LINK

checkPasswordProtectedShare()

checkPasswordProtectedShare(array  $linkItem) : boolean

In case a password protected link is not yet authenticated this function will return false

Parameters

array $linkItem

Returns

boolean

isResharingAllowed()

isResharingAllowed() : boolean

Check if resharing is allowed

Returns

boolean —

true if allowed or false