\ No newline at end of file
diff --git a/apps/files_sharing/templates/public.php b/apps/files_sharing/templates/public.php
new file mode 100755
index 0000000000..065818c220
--- /dev/null
+++ b/apps/files_sharing/templates/public.php
@@ -0,0 +1,13 @@
+
+
+
+
+
+
shared the file with you
+
+
+
+
+
+
+Download
\ No newline at end of file
diff --git a/core/js/js.js b/core/js/js.js
index 86e802cd34..0c842f0559 100644
--- a/core/js/js.js
+++ b/core/js/js.js
@@ -29,6 +29,16 @@ function t(app,text){
}
t.cache={};
+/**
+* Get the path to download a file
+* @param file The filename
+* @param dir The directory the file is in - e.g. $('#dir').val()
+* @return string
+*/
+function fileDownloadPath(dir, file) {
+ return OC.filePath('files', 'ajax', 'download.php')+encodeURIComponent('?files='+encodeURIComponent(file)+'&dir='+encodeURIComponent(dir));
+}
+
OC={
webroot:oc_webroot,
appswebroots:oc_appswebroots,
diff --git a/lib/helper.php b/lib/helper.php
index 8c362747a2..3cf464dfa7 100644
--- a/lib/helper.php
+++ b/lib/helper.php
@@ -100,6 +100,17 @@ class OC_Helper {
return self::linkToAbsolute( '', 'remote.php') . '/' . $service . (($add_slash && $service[strlen($service)-1]!='/')?'/':'');
}
+ /**
+ * @brief Creates an absolute url for public use
+ * @param $service id
+ * @returns the url
+ *
+ * Returns a absolute url to the given service.
+ */
+ public static function linkToPublic($service, $add_slash = false) {
+ return self::linkToAbsolute( '', 'public.php') . '?service=' . $service . (($add_slash && $service[strlen($service)-1]!='/')?'/':'');
+ }
+
/**
* @brief Creates path to an image
* @param $app app
diff --git a/lib/public/share.php b/lib/public/share.php
index 9ee7ef0516..15fb73d8d8 100644
--- a/lib/public/share.php
+++ b/lib/public/share.php
@@ -32,7 +32,7 @@ class Share {
const SHARE_TYPE_USER = 0;
const SHARE_TYPE_GROUP = 1;
- const SHARE_TYPE_PRIVATE_LINK = 3;
+ const SHARE_TYPE_LINK = 3;
const SHARE_TYPE_EMAIL = 4;
const SHARE_TYPE_CONTACT = 5;
const SHARE_TYPE_REMOTE = 6;
@@ -112,6 +112,17 @@ class Share {
return self::getItems($itemType, $itemSource, self::$shareTypeUserAndGroups, \OC_User::getUser(), null, $format, $parameters, 1, $includeCollections, true);
}
+ /**
+ * @brief Get the item of item type shared by a link
+ * @param string Item type
+ * @param string Item source
+ * @param string Owner of link
+ * @return Item
+ */
+ public static function getItemSharedWithByLink($itemType, $itemSource, $uidOwner) {
+ return self::getItems($itemType, $itemSource, self::SHARE_TYPE_LINK, null, $uidOwner, self::FORMAT_NONE, null, 1);
+ }
+
/**
* @brief Get the shared items of item type owned by the current user
* @param string Item type
@@ -138,7 +149,7 @@ class Share {
* @brief Share an item with a user, group, or via private link
* @param string Item type
* @param string Item source
- * @param int SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_PRIVATE_LINK
+ * @param int SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK
* @param string User or group the item is being shared with
* @param int CRUDS permissions
* @return bool Returns true on success or false on failure
@@ -198,9 +209,14 @@ class Share {
$shareWith = array();
$shareWith['group'] = $group;
$shareWith['users'] = array_diff(\OC_Group::usersInGroup($group), array($uidOwner));
- } else if ($shareType === self::SHARE_TYPE_PRIVATE_LINK) {
- $shareWith = md5(uniqid($itemSource, true));
- return self::put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions);
+ } else if ($shareType === self::SHARE_TYPE_LINK) {
+ // Generate hash of password - same method as user passwords
+ if (isset($shareWith)) {
+ $forcePortable = (CRYPT_BLOWFISH != 1);
+ $hasher = new \PasswordHash(8, $forcePortable);
+ $shareWith = $hasher->HashPassword($shareWith.\OC_Config::getValue('passwordsalt', ''));
+ }
+ return self::put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions);
} else if ($shareType === self::SHARE_TYPE_CONTACT) {
if (!\OC_App::isEnabled('contacts')) {
$message = 'Sharing '.$itemSource.' failed, because the contacts app is not enabled';
@@ -262,7 +278,7 @@ class Share {
* @brief Unshare an item from a user, group, or delete a private link
* @param string Item type
* @param string Item source
- * @param int SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_PRIVATE_LINK
+ * @param int SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK
* @param string User or group the item is being shared with
* @return Returns true on success or false on failure
*/
@@ -298,7 +314,7 @@ class Share {
* @brief Set the permissions of an item for a specific user or group
* @param string Item type
* @param string Item source
- * @param int SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_PRIVATE_LINK
+ * @param int SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK
* @param string User or group the item is being shared with
* @param int CRUDS permissions
* @return Returns true on success or false on failure
@@ -407,7 +423,7 @@ class Share {
* @brief Get shared items from the database
* @param string Item type
* @param string Item source or target (optional)
- * @param int SHARE_TYPE_USER, SHARE_TYPE_GROUP, SHARE_TYPE_PRIVATE_LINK, $shareTypeUserAndGroups, or $shareTypeGroupUserUnique
+ * @param int SHARE_TYPE_USER, SHARE_TYPE_GROUP, SHARE_TYPE_LINK, $shareTypeUserAndGroups, or $shareTypeGroupUserUnique
* @param string User or group the item is being shared with
* @param string User that is the owner of shared items (optional)
* @param int Format to convert items to with formatItems()
@@ -444,9 +460,9 @@ class Share {
$queryArgs = array($itemType);
}
}
- if (isset($shareType) && isset($shareWith)) {
+ if (isset($shareType)) {
// Include all user and group items
- if ($shareType == self::$shareTypeUserAndGroups) {
+ if ($shareType == self::$shareTypeUserAndGroups && isset($shareWith)) {
$where .= ' AND `share_type` IN (?,?,?)';
$queryArgs[] = self::SHARE_TYPE_USER;
$queryArgs[] = self::SHARE_TYPE_GROUP;
@@ -459,9 +475,12 @@ class Share {
$where .= ' AND `uid_owner` != ?';
$queryArgs[] = $shareWith;
} else {
- $where .= ' AND `share_type` = ? AND `share_with` = ?';
+ $where .= ' AND `share_type` = ?';
$queryArgs[] = $shareType;
- $queryArgs[] = $shareWith;
+ if (isset($shareWith)) {
+ $where .= ' AND `share_with` = ?';
+ $queryArgs[] = $shareWith;
+ }
}
}
if (isset($uidOwner)) {
@@ -650,7 +669,7 @@ class Share {
$column = 'path';
}
foreach ($items as $item) {
- if ($item['share_type'] == self::SHARE_TYPE_PRIVATE_LINK) {
+ if ($item['share_type'] == self::SHARE_TYPE_LINK) {
$statuses[$item[$column]] = true;
} else if (!isset($statuses[$item[$column]])) {
$statuses[$item[$column]] = false;
@@ -670,7 +689,7 @@ class Share {
* @brief Put shared item into the database
* @param string Item type
* @param string Item source
- * @param int SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_PRIVATE_LINK
+ * @param int SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK
* @param string User or group the item is being shared with
* @param int CRUDS permissions
* @param bool|array Parent folder target (optional)
@@ -827,7 +846,7 @@ class Share {
* @brief Generate a unique target for the item
* @param string Item type
* @param string Item source
- * @param int SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_PRIVATE_LINK
+ * @param int SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK
* @param string User or group the item is being shared with
* @return string Item target
*
@@ -836,7 +855,7 @@ class Share {
*/
private static function generateTarget($itemType, $itemSource, $shareType, $shareWith, $uidOwner) {
$backend = self::getBackend($itemType);
- if ($shareType == self::SHARE_TYPE_PRIVATE_LINK) {
+ if ($shareType == self::SHARE_TYPE_LINK) {
return $backend->generateTarget($itemSource, false);
} else {
if ($itemType == 'file' || $itemType == 'folder') {
diff --git a/lib/public/util.php b/lib/public/util.php
index 9f6f6f32e1..8d7303bf7a 100644
--- a/lib/public/util.php
+++ b/lib/public/util.php
@@ -144,6 +144,17 @@ class Util {
return(\OC_Helper::linkToRemote( $service ));
}
+ /**
+ * @brief Creates an absolute url for public use
+ * @param $service id
+ * @returns the url
+ *
+ * Returns a absolute url to the given app and file.
+ */
+ public static function linkToPublic($service) {
+ return \OC_Helper::linkToPublic($service);
+ }
+
/**
* @brief Creates an url