From d6bb04a74e7359fe00357d8e4613823ff570519e Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Sun, 26 Aug 2012 17:55:51 -0400 Subject: Move jquery.inview from contacts app to core --- core/js/jquery.inview.js | 134 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 core/js/jquery.inview.js (limited to 'core/js') diff --git a/core/js/jquery.inview.js b/core/js/jquery.inview.js new file mode 100644 index 00000000000..9687cd83368 --- /dev/null +++ b/core/js/jquery.inview.js @@ -0,0 +1,134 @@ +/** + * author Christopher Blum + * - based on the idea of Remy Sharp, http://remysharp.com/2009/01/26/element-in-view-event-plugin/ + * - forked from http://github.com/zuk/jquery.inview/ + */ +(function ($) { + var inviewObjects = {}, viewportSize, viewportOffset, + d = document, w = window, documentElement = d.documentElement, expando = $.expando, isFiring = false, $elements = {}; + + $.event.special.inview = { + add: function(data) { + var inviewObject = { data: data, $element: $(this) } + inviewObjects[data.guid + "-" + this[expando]] = inviewObject; + var selector = inviewObject.data.selector, + $element = inviewObject.$element; + var hash = parseInt(getHash( data.guid + this[expando])); + $elements[hash] = selector ? $element.find(selector) : $element; + }, + + remove: function(data) { + try { delete inviewObjects[data.guid + "-" + this[expando]]; } catch(e) {} + try { + var hash = parseInt(getHash(data.guid + this[expando])); + delete($elements[hash]); + } catch (e){} + } + }; + + + function getHash(str){ + str = str+''; + var hash = 0; + if (str.length == 0) return hash; + for (i = 0; i < str.length; i++) { + char = str.charCodeAt(i); + hash = ((hash<<5)-hash)+char; + hash = hash & hash; // Convert to 32bit integer + } + return Math.abs(hash); + } + + function getViewportSize() { + var mode, domObject, size = { height: w.innerHeight, width: w.innerWidth }; + + // if this is correct then return it. iPad has compat Mode, so will + // go into check clientHeight/clientWidth (which has the wrong value). + if (!size.height) { + mode = d.compatMode; + if (mode || !$.support.boxModel) { // IE, Gecko + domObject = mode === 'CSS1Compat' ? + documentElement : // Standards + d.body; // Quirks + size = { + height: domObject.clientHeight, + width: domObject.clientWidth + }; + } + } + + return size; + } + + function getViewportOffset() { + return { + top: w.pageYOffset || documentElement.scrollTop || (d.body?d.body.scrollTop:0), + left: w.pageXOffset || documentElement.scrollLeft || (d.body?d.body.scrollLeft:0) + }; + } + + function checkInView() { + if (isFiring){ + return; + } + isFiring = true; + viewportSize = viewportSize || getViewportSize(); + viewportOffset = viewportOffset || getViewportOffset(); + + for (var i in $elements) { + if (isNaN(parseInt(i))) { + continue; + } + + var $element = $($elements[i]), + elementSize = { height: $element.height(), width: $element.width() }, + elementOffset = $element.offset(), + inView = $element.data('inview'), + visiblePartX, + visiblePartY, + visiblePartsMerged; + + // Don't ask me why because I haven't figured out yet: + // viewportOffset and viewportSize are sometimes suddenly null in Firefox 5. + // Even though it sounds weird: + // It seems that the execution of this function is interferred by the onresize/onscroll event + // where viewportOffset and viewportSize are unset + if (!viewportOffset || !viewportSize) { + isFiring = false; + return; + } + + if (elementOffset.top + elementSize.height > viewportOffset.top && + elementOffset.top < viewportOffset.top + viewportSize.height && + elementOffset.left + elementSize.width > viewportOffset.left && + elementOffset.left < viewportOffset.left + viewportSize.width) { + visiblePartX = (viewportOffset.left > elementOffset.left ? + 'right' : (viewportOffset.left + viewportSize.width) < (elementOffset.left + elementSize.width) ? + 'left' : 'both'); + visiblePartY = (viewportOffset.top > elementOffset.top ? + 'bottom' : (viewportOffset.top + viewportSize.height) < (elementOffset.top + elementSize.height) ? + 'top' : 'both'); + visiblePartsMerged = visiblePartX + "-" + visiblePartY; + if (!inView || inView !== visiblePartsMerged) { + $element.data('inview', visiblePartsMerged).trigger('inview', [true, visiblePartX, visiblePartY]); + } + } else if (inView) { + $element.data('inview', false).trigger('inview', [false]); + } + } + isFiring = false; + } + + $(w).bind("scroll resize", function() { + viewportSize = viewportOffset = null; + }); + + // Use setInterval in order to also make sure this captures elements within + // "overflow:scroll" elements or elements that appeared in the dom tree due to + // dom manipulation and reflow + // old: $(window).scroll(checkInView); + // + // By the way, iOS (iPad, iPhone, ...) seems to not execute, or at least delays + // intervals while the user scrolls. Therefore the inview event might fire a bit late there + setInterval(checkInView, 250); +})(jQuery); \ No newline at end of file -- cgit v1.2.3 From 545812f5894707336022dc768915e6073578e419 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Sun, 26 Aug 2012 18:50:20 -0400 Subject: Move additional jquery.inview files --- core/js/LICENSE.jquery.inview | 41 +++++++++++++++++++++++++++++++++++++++++ core/js/jquery.inview.txt | 15 +++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 core/js/LICENSE.jquery.inview create mode 100644 core/js/jquery.inview.txt (limited to 'core/js') diff --git a/core/js/LICENSE.jquery.inview b/core/js/LICENSE.jquery.inview new file mode 100644 index 00000000000..1ed340edbe5 --- /dev/null +++ b/core/js/LICENSE.jquery.inview @@ -0,0 +1,41 @@ +Attribution-Non-Commercial-Share Alike 2.0 UK: England & Wales + +http://creativecommons.org/licenses/by-nc-sa/2.0/uk/ + +You are free: + + * to copy, distribute, display, and perform the work + * to make derivative works + + +Under the following conditions: + + * Attribution — You must give the original author credit. + Attribute this work: + Information + What does "Attribute this work" mean? + The page you came from contained embedded licensing metadata, + including how the creator wishes to be attributed for re-use. + You can use the HTML here to cite the work. Doing so will + also include metadata on your page so that others can find the + original work as well. + + * Non-Commercial — You may not use this work for commercial + purposes. + * Share Alike — If you alter, transform, or build upon this + work, you may distribute the resulting work only under a + licence identical to this one. + +With the understanding that: + + * Waiver — Any of the above conditions can be waived if you get + permission from the copyright holder. + * Other Rights — In no way are any of the following rights + affected by the license: + o Your fair dealing or fair use rights; + o The author's moral rights; + o Rights other persons may have either in the work itself + or in how the work is used, such as publicity or privacy rights. + * Notice — For any reuse or distribution, you must make clear to + others the licence terms of this work. + diff --git a/core/js/jquery.inview.txt b/core/js/jquery.inview.txt new file mode 100644 index 00000000000..c53dbd1d97c --- /dev/null +++ b/core/js/jquery.inview.txt @@ -0,0 +1,15 @@ +jQuery.inview is licensed Attribution-Non-Commercial-Share Alike 2.0 but the +conditions has been waived by the author in the following tweet: + +https://twitter.com/#!/ChristopherBlum/status/148382899887013888 + +Saying: + +Thomas Tanghus @tanghus 18 Dec. 2011 + +@ChristopherBlum Hi. Is it OK if I use https://github.com/protonet/jquery.inview in ownCloud? Preferably under an AGPL license ;-) owncloud.org + + +Christopher Blum Christopher Blum @ChristopherBlum 18 Dec. 2011 + +@tanghus Feel free to! :) -- cgit v1.2.3 From 0a9d1ed3a645efda56ae757f45aa7efb5a35ce4f Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Mon, 27 Aug 2012 15:46:05 -0400 Subject: Initial previewer for public links --- apps/files_sharing/css/public.css | 2 + apps/files_sharing/get.php | 88 --------------------------- apps/files_sharing/js/public.js | 18 ++++++ apps/files_sharing/public.php | 69 +++++++++++++++++++++ apps/files_sharing/templates/authenticate.php | 9 +++ apps/files_sharing/templates/get.php | 11 ---- apps/files_sharing/templates/public.php | 13 ++++ core/js/js.js | 10 +++ lib/helper.php | 11 ++++ lib/public/share.php | 51 +++++++++++----- lib/public/util.php | 11 ++++ 11 files changed, 178 insertions(+), 115 deletions(-) create mode 100644 apps/files_sharing/css/public.css delete mode 100644 apps/files_sharing/get.php create mode 100644 apps/files_sharing/js/public.js create mode 100644 apps/files_sharing/public.php create mode 100644 apps/files_sharing/templates/authenticate.php delete mode 100755 apps/files_sharing/templates/get.php create mode 100755 apps/files_sharing/templates/public.php (limited to 'core/js') diff --git a/apps/files_sharing/css/public.css b/apps/files_sharing/css/public.css new file mode 100644 index 00000000000..aa76c06175b --- /dev/null +++ b/apps/files_sharing/css/public.css @@ -0,0 +1,2 @@ +#content { position:relative; } +#preview p { text-align: center; } \ No newline at end of file diff --git a/apps/files_sharing/get.php b/apps/files_sharing/get.php deleted file mode 100644 index bcbe5985fb6..00000000000 --- a/apps/files_sharing/get.php +++ /dev/null @@ -1,88 +0,0 @@ -assign("file", $subPath); - $tmpl->printPage(); - exit; - } - if (OC_Filesystem::is_dir($source)) { - $files = array(); - $rootLength = strlen($root); - foreach (OC_Files::getdirectorycontent($source) as $i) { - $i['date'] = OCP\Util::formatDate($i['mtime'] ); - if ($i['type'] == 'file') { - $fileinfo = pathinfo($i['name']); - $i['basename'] = $fileinfo['filename']; - $i['extension'] = isset($fileinfo['extension']) ? ('.'.$fileinfo['extension']) : ''; - } - $i['directory'] = substr($i['directory'], $rootLength); - if ($i['directory'] == "/") { - $i['directory'] = ""; - } - $files[] = $i; - } - // Make breadcrumb - $breadcrumb = array(); - $pathtohere = ""; - foreach (explode("/", $subPath) as $i) { - if ($i != "") { - $pathtohere .= "/$i"; - $breadcrumb[] = array("dir" => $pathtohere, "name" => $i); - } - } - // Load the files we need - OCP\Util::addStyle("files", "files"); - $breadcrumbNav = new OCP\Template("files", "part.breadcrumb", ""); - $breadcrumbNav->assign("breadcrumb", $breadcrumb); - $breadcrumbNav->assign("baseURL", OCP\Util::linkTo("", "public.php")."?service=files&token=".$token."&path="); - $list = new OCP\Template("files", "part.list", ""); - $list->assign("files", $files); - $list->assign("baseURL", OCP\Util::linkTo("", "public.php")."?service=files&token=".$token."&path="); - $list->assign("downloadURL", OCP\Util::linkTo("", "public.php")."?service=files&token=".$token."&path="); - $list->assign("readonly", true); - $tmpl = new OCP\Template("files", "index", "user"); - $tmpl->assign("fileList", $list->fetchPage(), false); - $tmpl->assign("breadcrumb", $breadcrumbNav->fetchPage()); - $tmpl->assign("readonly", true); - $tmpl->assign("allowZipDownload", false); - $tmpl->assign("dir", 'shared dir'); - $tmpl->printPage(); - } else { - //get time mimetype and set the headers - $mimetype = OC_Filesystem::getMimeType($source); - header("Content-Transfer-Encoding: binary"); - OCP\Response::disableCaching(); - header('Content-Disposition: attachment; filename="'.basename($source).'"'); - header("Content-Type: " . $mimetype); - header("Content-Length: " . OC_Filesystem::filesize($source)); - //download the file - @ob_clean(); - //FIXME OC_Share no longer exists - OCP\Util::emitHook('OC_Share', 'public-download', array('source'=>$source, 'token'=>$token)); - OC_Filesystem::readfile($source); - } -} else { - header("HTTP/1.0 404 Not Found"); - $tmpl = new OCP\Template("", "404", "guest"); - $tmpl->printPage(); - die(); -} diff --git a/apps/files_sharing/js/public.js b/apps/files_sharing/js/public.js new file mode 100644 index 00000000000..755382e0736 --- /dev/null +++ b/apps/files_sharing/js/public.js @@ -0,0 +1,18 @@ +// Override download path to files_sharing/public.php +function fileDownloadPath(dir, file) { + return $('#downloadURL').val(); +} + +$(document).ready(function() { + + if (typeof FileActions !== 'undefined') { + var mimetype = $('#mimetype').val(); + // Show file preview if previewer is available, images are already handled by the template + if (mimetype.substr(0, mimetype.indexOf('/')) != 'image') { + // Trigger default action if not download TODO + var action = FileActions.getDefault(mimetype, 'file', FileActions.PERMISSION_READ); + action($('#filename').val()); + } + } + +}); \ No newline at end of file diff --git a/apps/files_sharing/public.php b/apps/files_sharing/public.php new file mode 100644 index 00000000000..15dac576d98 --- /dev/null +++ b/apps/files_sharing/public.php @@ -0,0 +1,69 @@ +CheckPassword($password.OC_Config::getValue('passwordsalt', ''), $storedHash))) { + $tmpl = new OCP\Template('files_sharing', 'authenticate', 'guest'); + $tmpl->assign('error', true); + $tmpl->printPage(); + exit(); + } + // Continue on if password is valid + } else { + // Prompt for password + $tmpl = new OCP\Template('files_sharing', 'authenticate', 'guest'); + $tmpl->printPage(); + exit(); + } + } + $path = $linkItem['path']; + // Download the file + if (isset($_GET['download'])) { + $mimetype = OC_Filesystem::getMimeType($path); + header('Content-Transfer-Encoding: binary'); + header('Content-Disposition: attachment; filename="'.basename($path).'"'); + header('Content-Type: '.$mimetype); + header('Content-Length: '.OC_Filesystem::filesize($path)); + OCP\Response::disableCaching(); + @ob_clean(); + OC_Filesystem::readfile($path); + } else { + OCP\Util::addStyle('files_sharing', 'public'); + OCP\Util::addScript('files_sharing', 'public'); + OCP\Util::addScript('files', 'fileactions'); + $tmpl = new OCP\Template('files_sharing', 'public', 'guest'); + $tmpl->assign('owner', $uidOwner); + $tmpl->assign('name', basename($path)); + // Show file list + if (OC_Filesystem::is_dir($path)) { + // TODO + } else { + // Show file preview if viewer is available + $tmpl->assign('dir', dirname($path)); + $tmpl->assign('filename', basename($path)); + $tmpl->assign('mimetype', OC_Filesystem::getMimeType($path)); + $tmpl->assign('downloadURL', OCP\Util::linkToPublic('files').'&file='.$_GET['file'].'&download'); + } + $tmpl->printPage(); + } + exit(); + } + } +} +header('HTTP/1.0 404 Not Found'); +$tmpl = new OCP\Template('', '404', 'guest'); +$tmpl->printPage(); \ No newline at end of file diff --git a/apps/files_sharing/templates/authenticate.php b/apps/files_sharing/templates/authenticate.php new file mode 100644 index 00000000000..41064d51464 --- /dev/null +++ b/apps/files_sharing/templates/authenticate.php @@ -0,0 +1,9 @@ +
+
+

+ + + +

+
+
\ No newline at end of file diff --git a/apps/files_sharing/templates/get.php b/apps/files_sharing/templates/get.php deleted file mode 100755 index 57275f07a3d..00000000000 --- a/apps/files_sharing/templates/get.php +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - -
t( 'Size' ); ?>t( 'Modified' ); ?>t('Delete all')?> <?php echo $l->t('Delete')?>" />
\ 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 00000000000..065818c2200 --- /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 86e802cd348..0c842f05593 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 8c362747a27..3cf464dfa7b 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 9ee7ef0516b..15fb73d8d88 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 9f6f6f32e1e..8d7303bf7a4 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 -- cgit v1.2.3 From 2aac6f02a0dd3da73db09e1b23aa14cb84d4d88e Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Mon, 27 Aug 2012 20:05:51 -0400 Subject: Reimplement links support for sharing and add password protection option --- core/ajax/share.php | 15 ++++++-- core/css/share.css | 2 +- core/js/share.js | 109 +++++++++++++++++++++++++--------------------------- 3 files changed, 66 insertions(+), 60 deletions(-) (limited to 'core/js') diff --git a/core/ajax/share.php b/core/ajax/share.php index 806ca9fb98f..debdf612c0e 100644 --- a/core/ajax/share.php +++ b/core/ajax/share.php @@ -26,8 +26,12 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo case 'share': if (isset($_POST['shareType']) && isset($_POST['shareWith']) && isset($_POST['permissions'])) { try { - OCP\Share::shareItem($_POST['itemType'], $_POST['itemSource'], (int)$_POST['shareType'], $_POST['shareWith'], $_POST['permissions']); - // TODO May need to return private link + if ((int)$_POST['shareType'] === OCP\Share::SHARE_TYPE_LINK && $_POST['shareWith'] == '') { + $shareWith = null; + } else { + $shareWith = $_POST['shareWith']; + } + OCP\Share::shareItem($_POST['itemType'], $_POST['itemSource'], (int)$_POST['shareType'], $shareWith, $_POST['permissions']); OC_JSON::success(); } catch (Exception $exception) { OC_JSON::error(array('data' => array('message' => $exception->getMessage()))); @@ -36,7 +40,12 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo break; case 'unshare': if (isset($_POST['shareType']) && isset($_POST['shareWith'])) { - $return = OCP\Share::unshare($_POST['itemType'], $_POST['itemSource'], $_POST['shareType'], $_POST['shareWith']); + if ((int)$_POST['shareType'] === OCP\Share::SHARE_TYPE_LINK && $_POST['shareWith'] == '') { + $shareWith = null; + } else { + $shareWith = $_POST['shareWith']; + } + $return = OCP\Share::unshare($_POST['itemType'], $_POST['itemSource'], $_POST['shareType'], $shareWith); ($return) ? OC_JSON::success() : OC_JSON::error(); } break; diff --git a/core/css/share.css b/core/css/share.css index e4b4870dd16..a8ffc8df42e 100644 --- a/core/css/share.css +++ b/core/css/share.css @@ -15,4 +15,4 @@ a.showCruds { display:inline; opacity:.5; } a.showCruds:hover { opacity:1; } a.unshare { float:right; display:inline; padding:.3em 0 0 .3em !important; opacity:.5; } a.unshare:hover { opacity:1; } -#privateLink { border-top:1px solid #ddd; padding-top:0.5em; } \ No newline at end of file +#link { border-top:1px solid #ddd; padding-top:0.5em; } \ No newline at end of file diff --git a/core/js/share.js b/core/js/share.js index 3db69dc6901..4c164f65b24 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -1,7 +1,7 @@ OC.Share={ SHARE_TYPE_USER:0, SHARE_TYPE_GROUP:1, - SHARE_TYPE_PRIVATE_LINK:3, + SHARE_TYPE_LINK:3, SHARE_TYPE_EMAIL:4, PERMISSION_CREATE:4, PERMISSION_READ:1, @@ -118,7 +118,7 @@ OC.Share={ } }); }, - showDropDown:function(itemType, itemSource, appendTo, privateLink, possiblePermissions) { + showDropDown:function(itemType, itemSource, appendTo, link, possiblePermissions) { var data = OC.Share.loadItem(itemType, itemSource); var html = ''; } html += ''; @@ -408,8 +410,7 @@ $(document).ready(function() { }); $('#showPassword').live('click', function() { - $('#linkText').after('
'); - $('#linkPassText').toggle('blind'); + $('#linkPass').toggle('blind'); }); $('#linkPassText').live('keyup', function(event) { -- cgit v1.2.3 From 26501a0bc8c7c4fa8343f5fa0c6e42bae1c7f298 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 29 Aug 2012 13:58:39 -0400 Subject: Delete old link if user sets a password --- core/js/share.js | 2 -- lib/public/share.php | 10 ++++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'core/js') diff --git a/core/js/share.js b/core/js/share.js index cc862b1c5f5..59ff25ee763 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -417,8 +417,6 @@ $(document).ready(function() { if (event.keyCode == 13) { var itemType = $('#dropdown').data('item-type'); var itemSource = $('#dropdown').data('item-source'); - // TODO Do this internally - OC.Share.unshare(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, ''); OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, $(this).val(), OC.Share.PERMISSION_READ); } }); diff --git a/lib/public/share.php b/lib/public/share.php index 165e3df452f..91b1bffc2d7 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -229,6 +229,16 @@ class Share { $shareWith['users'] = array_diff(\OC_Group::usersInGroup($group), array($uidOwner)); } else if ($shareType === self::SHARE_TYPE_LINK) { if (\OC_Appconfig::getValue('core', 'shareapi_allow_links', 'yes') == 'yes') { + if ($checkExists = self::getItems($itemType, $itemSource, self::SHARE_TYPE_LINK, null, $uidOwner, self::FORMAT_NONE, null, 1)) { + // If password is set delete the old link + if (isset($shareWith)) { + self::delete($checkExists['id']); + } else { + $message = 'Sharing '.$itemSource.' failed, because this item is already shared with a link'; + \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); + throw new \Exception($message); + } + } // Generate hash of password - same method as user passwords if (isset($shareWith)) { $forcePortable = (CRYPT_BLOWFISH != 1); -- cgit v1.2.3 From 0788c6e968f98647fe8bb8961cc2d250531ce283 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 29 Aug 2012 14:01:09 -0400 Subject: Hide link password controls if link is removed --- core/js/share.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'core/js') diff --git a/core/js/share.js b/core/js/share.js index 59ff25ee763..7d2daffb29d 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -285,6 +285,8 @@ OC.Share={ }, hideLink:function() { $('#linkText').hide('blind'); + $('#showPassword').hide(); + $('#linkPass').hide(); }, dirname:function(path) { return path.replace(/\\/g,'/').replace(/\/[^\/]*$/, ''); -- cgit v1.2.3 From 76bc4753e9bd2698415b067108806d82ac56b663 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 29 Aug 2012 14:06:33 -0400 Subject: Fix displaying if a link is password protected --- core/js/share.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'core/js') diff --git a/core/js/share.js b/core/js/share.js index 7d2daffb29d..fa412c7acc5 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -282,6 +282,10 @@ OC.Share={ $('#linkText').val(link); $('#linkText').show('blind'); $('#showPassword').show(); + if (password.length > 0) { + $('#linkPass').show('blind'); + $('#linkPassText').attr('placeholder', 'Password protected'); + } }, hideLink:function() { $('#linkText').hide('blind'); @@ -419,7 +423,10 @@ $(document).ready(function() { if (event.keyCode == 13) { var itemType = $('#dropdown').data('item-type'); var itemSource = $('#dropdown').data('item-source'); - OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, $(this).val(), OC.Share.PERMISSION_READ); + OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, $(this).val(), OC.Share.PERMISSION_READ, function() { + $('#linkPassText').val(''); + $('#linkPassText').attr('placeholder', 'Password protected'); + }); } }); -- cgit v1.2.3 From 3828d86191e7a0ecf8acbdddbb703352983178e1 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 29 Aug 2012 14:07:53 -0400 Subject: Remove old Javascript code --- core/js/share.js | 4 ---- 1 file changed, 4 deletions(-) (limited to 'core/js') diff --git a/core/js/share.js b/core/js/share.js index fa412c7acc5..8bfbdd36e19 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -429,8 +429,4 @@ $(document).ready(function() { }); } }); - - $('#emailPrivateLink').live('submit', function() { - OC.Share.emailPrivateLink(); - }); }); -- cgit v1.2.3