share.php 13 KB

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