You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

share.php 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Bjoern Schiessle, Michael Gapczynski
  6. * @copyright 2012 Michael Gapczynski <mtgap@owncloud.com>
  7. * 2014 Bjoern Schiessle <schiessle@owncloud.com>
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  11. * License as published by the Free Software Foundation; either
  12. * version 3 of the License, or any later version.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public
  20. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * Public interface of ownCloud for apps to use.
  24. * Share Class
  25. *
  26. */
  27. // use OCP namespace for all classes that are considered public.
  28. // This means that they should be used by apps instead of the internal ownCloud classes
  29. namespace OCP;
  30. /**
  31. * This class provides the ability for apps to share their content between users.
  32. * Apps must create a backend class that implements OCP\Share_Backend and register it with this class.
  33. *
  34. * It provides the following hooks:
  35. * - post_shared
  36. */
  37. class Share extends \OC\Share\Constants {
  38. /**
  39. * Register a sharing backend class that implements OCP\Share_Backend for an item type
  40. * @param string $itemType Item type
  41. * @param string $class Backend class
  42. * @param string $collectionOf (optional) Depends on item type
  43. * @param array $supportedFileExtensions (optional) List of supported file extensions if this item type depends on files
  44. * @return boolean true if backend is registered or false if error
  45. */
  46. public static function registerBackend($itemType, $class, $collectionOf = null, $supportedFileExtensions = null) {
  47. return \OC\Share\Share::registerBackend($itemType, $class, $collectionOf, $supportedFileExtensions);
  48. }
  49. /**
  50. * Check if the Share API is enabled
  51. * @return boolean true if enabled or false
  52. *
  53. * The Share API is enabled by default if not configured
  54. */
  55. public static function isEnabled() {
  56. return \OC\Share\Share::isEnabled();
  57. }
  58. /**
  59. * Find which users can access a shared item
  60. * @param string $path to the file
  61. * @param string $ownerUser owner of the file
  62. * @param bool $includeOwner include owner to the list of users with access to the file
  63. * @param bool $returnUserPaths Return an array with the user => path map
  64. * @return array
  65. * @note $path needs to be relative to user data dir, e.g. 'file.txt'
  66. * not '/admin/data/file.txt'
  67. */
  68. public static function getUsersSharingFile($path, $ownerUser, $includeOwner = false, $returnUserPaths = false) {
  69. return \OC\Share\Share::getUsersSharingFile($path, $ownerUser, $includeOwner, $returnUserPaths);
  70. }
  71. /**
  72. * Get the items of item type shared with the current user
  73. * @param string $itemType
  74. * @param int $format (optional) Format type must be defined by the backend
  75. * @param mixed $parameters (optional)
  76. * @param int $limit Number of items to return (optional) Returns all by default
  77. * @param bool $includeCollections (optional)
  78. * @return mixed Return depends on format
  79. */
  80. public static function getItemsSharedWith($itemType, $format = self::FORMAT_NONE,
  81. $parameters = null, $limit = -1, $includeCollections = false) {
  82. return \OC\Share\Share::getItemsSharedWith($itemType, $format, $parameters, $limit, $includeCollections);
  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. */
  94. public static function getItemsSharedWithUser($itemType, $user, $format = self::FORMAT_NONE,
  95. $parameters = null, $limit = -1, $includeCollections = false) {
  96. return \OC\Share\Share::getItemsSharedWithUser($itemType, $user, $format, $parameters, $limit, $includeCollections);
  97. }
  98. /**
  99. * Get the item of item type shared with the current user
  100. * @param string $itemType
  101. * @param string $itemTarget
  102. * @param int $format (optional) Format type must be defined by the backend
  103. * @param mixed $parameters (optional)
  104. * @param bool $includeCollections (optional)
  105. * @return mixed Return depends on format
  106. */
  107. public static function getItemSharedWith($itemType, $itemTarget, $format = self::FORMAT_NONE,
  108. $parameters = null, $includeCollections = false) {
  109. return \OC\Share\Share::getItemSharedWith($itemType, $itemTarget, $format, $parameters, $includeCollections);
  110. }
  111. /**
  112. * Get the item of item type shared with a given user by source
  113. * @param string $itemType
  114. * @param string $itemSource
  115. * @param string $user User to whom the item was shared
  116. * @param string $owner Owner of the share
  117. * @return array Return list of items with file_target, permissions and expiration
  118. */
  119. public static function getItemSharedWithUser($itemType, $itemSource, $user, $owner = null) {
  120. return \OC\Share\Share::getItemSharedWithUser($itemType, $itemSource, $user, $owner);
  121. }
  122. /**
  123. * Get the item of item type shared with the current user by source
  124. * @param string $itemType
  125. * @param string $itemSource
  126. * @param int $format (optional) Format type must be defined by the backend
  127. * @param mixed $parameters
  128. * @param bool $includeCollections
  129. * @return array
  130. */
  131. public static function getItemSharedWithBySource($itemType, $itemSource, $format = self::FORMAT_NONE,
  132. $parameters = null, $includeCollections = false) {
  133. return \OC\Share\Share::getItemSharedWithBySource($itemType, $itemSource, $format, $parameters, $includeCollections);
  134. }
  135. /**
  136. * Get the item of item type shared by a link
  137. * @param string $itemType
  138. * @param string $itemSource
  139. * @param string $uidOwner Owner of link
  140. * @return Item
  141. */
  142. public static function getItemSharedWithByLink($itemType, $itemSource, $uidOwner) {
  143. return \OC\Share\Share::getItemSharedWithByLink($itemType, $itemSource, $uidOwner);
  144. }
  145. /**
  146. * Based on the given token the share information will be returned - password protected shares will be verified
  147. * @param string $token
  148. * @return array|bool false will be returned in case the token is unknown or unauthorized
  149. */
  150. public static function getShareByToken($token, $checkPasswordProtection = true) {
  151. return \OC\Share\Share::getShareByToken($token, $checkPasswordProtection);
  152. }
  153. /**
  154. * resolves reshares down to the last real share
  155. * @param array $linkItem
  156. * @return array file owner
  157. */
  158. public static function resolveReShare($linkItem) {
  159. return \OC\Share\Share::resolveReShare($linkItem);
  160. }
  161. /**
  162. * Get the shared items of item type owned by the current user
  163. * @param string $itemType
  164. * @param int $format (optional) Format type must be defined by the backend
  165. * @param mixed $parameters
  166. * @param int $limit Number of items to return (optional) Returns all by default
  167. * @param bool $includeCollections
  168. * @return mixed Return depends on format
  169. */
  170. public static function getItemsShared($itemType, $format = self::FORMAT_NONE, $parameters = null,
  171. $limit = -1, $includeCollections = false) {
  172. return \OC\Share\Share::getItemsShared($itemType, $format, $parameters, $limit, $includeCollections);
  173. }
  174. /**
  175. * Get the shared item of item type owned by the current user
  176. * @param string $itemType
  177. * @param string $itemSource
  178. * @param int $format (optional) Format type must be defined by the backend
  179. * @param mixed $parameters
  180. * @param bool $includeCollections
  181. * @return mixed Return depends on format
  182. */
  183. public static function getItemShared($itemType, $itemSource, $format = self::FORMAT_NONE,
  184. $parameters = null, $includeCollections = false) {
  185. return \OC\Share\Share::getItemShared($itemType, $itemSource, $format, $parameters, $includeCollections);
  186. }
  187. /**
  188. * Get all users an item is shared with
  189. * @param string $itemType
  190. * @param string $itemSource
  191. * @param string $uidOwner
  192. * @param bool $includeCollections
  193. * @param bool $checkExpireDate
  194. * @return array Return array of users
  195. */
  196. public static function getUsersItemShared($itemType, $itemSource, $uidOwner, $includeCollections = false, $checkExpireDate = true) {
  197. return \OC\Share\Share::getUsersItemShared($itemType, $itemSource, $uidOwner, $includeCollections, $checkExpireDate);
  198. }
  199. /**
  200. * Share an item with a user, group, or via private link
  201. * @param string $itemType
  202. * @param string $itemSource
  203. * @param int $shareType SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK
  204. * @param string $shareWith User or group the item is being shared with
  205. * @param int $permissions CRUDS
  206. * @param string $itemSourceName
  207. * @param \DateTime $expirationDate
  208. * @return bool|string Returns true on success or false on failure, Returns token on success for links
  209. * @throws \Exception
  210. */
  211. public static function shareItem($itemType, $itemSource, $shareType, $shareWith, $permissions, $itemSourceName = null, \DateTime $expirationDate = null) {
  212. return \OC\Share\Share::shareItem($itemType, $itemSource, $shareType, $shareWith, $permissions, $itemSourceName, $expirationDate);
  213. }
  214. /**
  215. * Unshare an item from a user, group, or delete a private link
  216. * @param string $itemType
  217. * @param string $itemSource
  218. * @param int $shareType SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK
  219. * @param string $shareWith User or group the item is being shared with
  220. * @return boolean true on success or false on failure
  221. */
  222. public static function unshare($itemType, $itemSource, $shareType, $shareWith) {
  223. return \OC\Share\Share::unshare($itemType, $itemSource, $shareType, $shareWith);
  224. }
  225. /**
  226. * Unshare an item from all users, groups, and remove all links
  227. * @param string $itemType
  228. * @param string $itemSource
  229. * @return boolean true on success or false on failure
  230. */
  231. public static function unshareAll($itemType, $itemSource) {
  232. return \OC\Share\Share::unshareAll($itemType, $itemSource);
  233. }
  234. /**
  235. * Unshare an item shared with the current user
  236. * @param string $itemType
  237. * @param string $itemTarget
  238. * @return boolean true on success or false on failure
  239. *
  240. * Unsharing from self is not allowed for items inside collections
  241. */
  242. public static function unshareFromSelf($itemType, $itemOrigin, $originIsSource = false) {
  243. return \OC\Share\Share::unshareFromSelf($itemType, $itemOrigin, $originIsSource);
  244. }
  245. /**
  246. * sent status if users got informed by mail about share
  247. * @param string $itemType
  248. * @param string $itemSource
  249. * @param int $shareType SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK
  250. * @param string $recipient with whom was the item shared
  251. * @param bool $status
  252. */
  253. public static function setSendMailStatus($itemType, $itemSource, $shareType, $recipient, $status) {
  254. return \OC\Share\Share::setSendMailStatus($itemType, $itemSource, $shareType, $recipient, $status);
  255. }
  256. /**
  257. * Set the permissions of an item for a specific user or group
  258. * @param string $itemType
  259. * @param string $itemSource
  260. * @param int $shareType SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK
  261. * @param string $shareWith User or group the item is being shared with
  262. * @param int $permissions CRUDS permissions
  263. * @return boolean true on success or false on failure
  264. */
  265. public static function setPermissions($itemType, $itemSource, $shareType, $shareWith, $permissions) {
  266. return \OC\Share\Share::setPermissions($itemType, $itemSource, $shareType, $shareWith, $permissions);
  267. }
  268. /**
  269. * Set expiration date for a share
  270. * @param string $itemType
  271. * @param string $itemSource
  272. * @param string $date expiration date
  273. * @param int $shareTime timestamp from when the file was shared
  274. * @return boolean
  275. */
  276. public static function setExpirationDate($itemType, $itemSource, $date, $shareTime = null) {
  277. return \OC\Share\Share::setExpirationDate($itemType, $itemSource, $date, $shareTime);
  278. }
  279. /**
  280. * Get the backend class for the specified item type
  281. * @param string $itemType
  282. * @return Share_Backend
  283. */
  284. public static function getBackend($itemType) {
  285. return \OC\Share\Share::getBackend($itemType);
  286. }
  287. /**
  288. * Delete all shares with type SHARE_TYPE_LINK
  289. */
  290. public static function removeAllLinkShares() {
  291. return \OC\Share\Share::removeAllLinkShares();
  292. }
  293. /**
  294. * In case a password protected link is not yet authenticated this function will return false
  295. *
  296. * @param array $linkItem
  297. * @return bool
  298. */
  299. public static function checkPasswordProtectedShare(array $linkItem) {
  300. return \OC\Share\Share::checkPasswordProtectedShare($linkItem);
  301. }
  302. /**
  303. * Check if resharing is allowed
  304. *
  305. * @return boolean true if allowed or false
  306. */
  307. public static function isResharingAllowed() {
  308. return \OC\Share\Share::isResharingAllowed();
  309. }
  310. }