From d7de35376d7e068abdfb49e8336feab25e313662 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 9 May 2014 17:06:08 +0200 Subject: Add interface for accpeting external shares --- apps/files_sharing/js/external.js | 53 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 apps/files_sharing/js/external.js (limited to 'apps/files_sharing/js') diff --git a/apps/files_sharing/js/external.js b/apps/files_sharing/js/external.js new file mode 100644 index 00000000000..0fa99a1652b --- /dev/null +++ b/apps/files_sharing/js/external.js @@ -0,0 +1,53 @@ +$(document).ready(function () { + var getParameterByName = function (query, name) { + name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); + var regex = new RegExp("[\\#&]" + name + "=([^&#]*)"), + results = regex.exec(query); + return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); + }; + + var addExternalShare = function (remote, token, owner, name, password) { + return $.post(OC.generateUrl('apps/files_sharing/external'), { + remote : remote, + token : token, + owner : owner, + name : name, + password: password + }); + }; + + var showAddExternalDialog = function (remote, token, owner, name, passwordProtected) { + var remoteClean = (remote.substr(0, 8) === 'https://') ? remote.substr(8) : remote.substr(7); + var callback = function (add, password) { + password = password || ''; + if (add) { + addExternalShare(remote, token, owner, name, password).then(function (result) { + if (result) { + FileList.reload(); + } else { + OC.dialogs.alert('Error adding ' + name, 'Error adding share'); + } + }); + } + }; + if (!passwordProtected) { + OC.dialogs.confirm('Add ' + name + ' from ' + owner + '@' + remoteClean, 'Add Share', callback, true); + } else { + OC.dialogs.prompt('Add ' + name + ' from ' + owner + '@' + remoteClean, 'Add Share', callback, true, 'Password', true); + } + }; + + if (window.FileList) {// only run in the files app + var hash = location.hash; + location.hash = ''; + var remote = getParameterByName(hash, 'remote'); + var owner = getParameterByName(hash, 'owner'); + var name = getParameterByName(hash, 'name'); + var token = getParameterByName(hash, 'token'); + var passwordProtected = parseInt(getParameterByName(hash, 'protected'), 10); + + if (remote && token && owner && name) { + showAddExternalDialog(remote, token, owner, name, passwordProtected); + } + } +}); -- cgit v1.2.3 From cf5a72c10398bb18817cff8ca4dfba4429a97123 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 14 May 2014 13:29:03 +0200 Subject: Add interface for adding a public share to a different ownCloud instance --- apps/files_sharing/ajax/testremote.php | 17 ++++++++++++++++ apps/files_sharing/appinfo/routes.php | 1 + apps/files_sharing/css/public.css | 14 +++++++++++++ apps/files_sharing/js/external.js | 4 ++-- apps/files_sharing/js/public.js | 36 +++++++++++++++++++++++++++++++++ apps/files_sharing/templates/public.php | 18 +++++++++++++---- 6 files changed, 84 insertions(+), 6 deletions(-) create mode 100644 apps/files_sharing/ajax/testremote.php (limited to 'apps/files_sharing/js') diff --git a/apps/files_sharing/ajax/testremote.php b/apps/files_sharing/ajax/testremote.php new file mode 100644 index 00000000000..10ea3075ed3 --- /dev/null +++ b/apps/files_sharing/ajax/testremote.php @@ -0,0 +1,17 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +$remote = $_GET['remote']; + +if (file_get_contents('https://' . $remote . '/status.php')) { + echo 'https'; +} elseif (file_get_contents('http://' . $remote . '/status.php')) { + echo 'http'; +}else{ + echo 'false'; +} diff --git a/apps/files_sharing/appinfo/routes.php b/apps/files_sharing/appinfo/routes.php index 2d214c879c4..8ec4382180b 100644 --- a/apps/files_sharing/appinfo/routes.php +++ b/apps/files_sharing/appinfo/routes.php @@ -6,6 +6,7 @@ $this->create('core_ajax_public_preview', '/publicpreview')->action( }); $this->create('sharing_external_add', '/external')->actionInclude('files_sharing/ajax/external.php'); +$this->create('sharing_external_test_remote', '/testremote')->actionInclude('files_sharing/ajax/testremote.php'); // OCS API diff --git a/apps/files_sharing/css/public.css b/apps/files_sharing/css/public.css index 1bafb780744..52b8481140d 100644 --- a/apps/files_sharing/css/public.css +++ b/apps/files_sharing/css/public.css @@ -87,3 +87,17 @@ thead { width: 300px; max-width: 90%; } + +.header-right { + transition: opacity 500ms ease 0s; + -moz-transition: opacity 500ms ease 0s; + -ms-transition: opacity 500ms ease 0s; + -o-transition: opacity 500ms ease 0s; + -webkit-transition: opacity 500ms ease 0s; +} + +.header-right:hover, .header-right.active { + opacity: 1; + -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)"; + filter: alpha(opacity=100); +} diff --git a/apps/files_sharing/js/external.js b/apps/files_sharing/js/external.js index 0fa99a1652b..1e46b35c53b 100644 --- a/apps/files_sharing/js/external.js +++ b/apps/files_sharing/js/external.js @@ -22,7 +22,7 @@ $(document).ready(function () { password = password || ''; if (add) { addExternalShare(remote, token, owner, name, password).then(function (result) { - if (result) { + if (result && result !== 'false') { FileList.reload(); } else { OC.dialogs.alert('Error adding ' + name, 'Error adding share'); @@ -37,7 +37,7 @@ $(document).ready(function () { } }; - if (window.FileList) {// only run in the files app + if (window.FileList && window.FileList.appName === 'Files') {// only run in the files app var hash = location.hash; location.hash = ''; var remote = getParameterByName(hash, 'remote'); diff --git a/apps/files_sharing/js/public.js b/apps/files_sharing/js/public.js index a2248405d22..48db89532b4 100644 --- a/apps/files_sharing/js/public.js +++ b/apps/files_sharing/js/public.js @@ -186,5 +186,41 @@ $(document).ready(function() { }); }; } + + $('.save-form').submit(function (event) { + event.preventDefault(); + + var remote = $(this).find('input[type="text"]').val(); + var token = $('#sharingToken').val(); + var location = window.location.protocol + '//' + window.location.host + OC.webroot; + var owner = $('#save').data('owner'); + var name = $('#save').data('name'); + + var url = remote + '/index.php/apps/files#' + 'remote=' + encodeURIComponent(location) // our location is the remote for the other server + + "&token=" + encodeURIComponent(token) + "&owner=" + encodeURIComponent(owner) + "&name=" + encodeURIComponent(name); + + + if (remote.indexOf('://') > 0) { + window.location = url; + } else { + // if no protocol is specified, we automatically detect it by testing https and http + // this check needs to happen on the server due to the Content Security Policy directive + $.get(OC.generateUrl('apps/files_sharing/testremote'), {remote: remote}).then(function (protocol) { + if (protocol !== 'http' && protocol !== 'https') { + OC.dialogs.alert(t('files_sharing', 'No ownCloud installation found at {remote}', {remote: remote}), + t('files_sharing', 'Invalid ownCloud url')); + } else { + window.location = protocol + '://' + url; + } + }); + } + }); + + $('#save > button').click(function () { + $(this).hide(); + $('.header-right').addClass('active'); + $('.save-form').css('display', 'inline'); + $('#remote_address').focus(); + }); }); diff --git a/apps/files_sharing/templates/public.php b/apps/files_sharing/templates/public.php index 7b5f603a105..1c0570cb018 100644 --- a/apps/files_sharing/templates/public.php +++ b/apps/files_sharing/templates/public.php @@ -15,10 +15,20 @@ src="" alt="getName()); ?>" />
- - "/> - t('Download'))?> - + + + + + + + "/> + t('Download'))?> + + t('shared by %s', array($_['displayName']))) ?> +
-- cgit v1.2.3 From 30f5b2bd7cdb9dde211dd0d897f798190c8d3947 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 19 May 2014 15:39:14 +0200 Subject: Improve detection of whether we're in the files app --- apps/files_sharing/js/external.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apps/files_sharing/js') diff --git a/apps/files_sharing/js/external.js b/apps/files_sharing/js/external.js index 1e46b35c53b..5e133db2f57 100644 --- a/apps/files_sharing/js/external.js +++ b/apps/files_sharing/js/external.js @@ -37,7 +37,7 @@ $(document).ready(function () { } }; - if (window.FileList && window.FileList.appName === 'Files') {// only run in the files app + if (OCA.Files) {// only run in the files app var hash = location.hash; location.hash = ''; var remote = getParameterByName(hash, 'remote'); -- cgit v1.2.3 From 2005c162bdfbe70f2690697eee82bcbd28ff57f5 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 5 Jun 2014 11:29:01 +0200 Subject: Fix prompting for password --- apps/files_sharing/js/public.js | 31 ++++++++++++++++--------------- apps/files_sharing/public.php | 1 + apps/files_sharing/templates/public.php | 2 +- 3 files changed, 18 insertions(+), 16 deletions(-) (limited to 'apps/files_sharing/js') diff --git a/apps/files_sharing/js/public.js b/apps/files_sharing/js/public.js index 48db89532b4..359087c0f94 100644 --- a/apps/files_sharing/js/public.js +++ b/apps/files_sharing/js/public.js @@ -19,7 +19,7 @@ if (!OCA.Files) { OCA.Sharing.PublicApp = { _initialized: false, - initialize: function($el) { + initialize: function ($el) { var self = this; var fileActions; if (this._initialized) { @@ -65,7 +65,7 @@ OCA.Sharing.PublicApp = { } // dynamically load image previews - if (mimetype.substr(0, mimetype.indexOf('/')) === 'image' ) { + if (mimetype.substr(0, mimetype.indexOf('/')) === 'image') { var params = { x: $(document).width() * window.devicePixelRatio, @@ -82,7 +82,7 @@ OCA.Sharing.PublicApp = { if (this.fileList) { // TODO: move this to a separate PublicFileList class that extends OCA.Files.FileList (+ unit tests) - this.fileList.getDownloadUrl = function(filename, dir) { + this.fileList.getDownloadUrl = function (filename, dir) { if ($.isArray(filename)) { filename = JSON.stringify(filename); } @@ -97,13 +97,13 @@ OCA.Sharing.PublicApp = { return OC.filePath('', '', 'public.php') + '?' + OC.buildQueryString(params); }; - this.fileList.getAjaxUrl = function(action, params) { + this.fileList.getAjaxUrl = function (action, params) { params = params || {}; params.t = $('#sharingToken').val(); return OC.filePath('files_sharing', 'ajax', action + '.php') + '?' + OC.buildQueryString(params); }; - this.fileList.linkTo = function(dir) { + this.fileList.linkTo = function (dir) { var params = { service: 'files', t: $('#sharingToken').val(), @@ -112,15 +112,15 @@ OCA.Sharing.PublicApp = { return OC.filePath('', '', 'public.php') + '?' + OC.buildQueryString(params); }; - this.fileList.generatePreviewUrl = function(urlSpec) { + this.fileList.generatePreviewUrl = function (urlSpec) { urlSpec.t = $('#dirToken').val(); return OC.generateUrl('/apps/files_sharing/ajax/publicpreview.php?') + $.param(urlSpec); }; var file_upload_start = $('#file_upload_start'); - file_upload_start.on('fileuploadadd', function(e, data) { + file_upload_start.on('fileuploadadd', function (e, data) { var fileDirectory = ''; - if(typeof data.files[0].relativePath !== 'undefined') { + if (typeof data.files[0].relativePath !== 'undefined') { fileDirectory = data.files[0].relativePath; } @@ -143,7 +143,7 @@ OCA.Sharing.PublicApp = { OC.Util.History.addOnPopStateHandler(_.bind(this._onUrlChanged, this)); } - $(document).on('click', '#directLink', function() { + $(document).on('click', '#directLink', function () { $(this).focus(); $(this).select(); }); @@ -152,7 +152,7 @@ OCA.Sharing.PublicApp = { window.FileList = this.fileList; }, - _onDirectoryChanged: function(e) { + _onDirectoryChanged: function (e) { OC.Util.History.pushState({ service: 'files', t: $('#sharingToken').val(), @@ -161,21 +161,21 @@ OCA.Sharing.PublicApp = { }); }, - _onUrlChanged: function(params) { + _onUrlChanged: function (params) { this.fileList.changeDirectory(params.path || params.dir, false, true); } }; -$(document).ready(function() { +$(document).ready(function () { var App = OCA.Sharing.PublicApp; // defer app init, to give a chance to plugins to register file actions - _.defer(function() { + _.defer(function () { App.initialize($('#preview')); }); if (window.Files) { // HACK: for oc-dialogs previews that depends on Files: - Files.lazyLoadPreview = function(path, mime, ready, width, height, etag) { + Files.lazyLoadPreview = function (path, mime, ready, width, height, etag) { return App.fileList.lazyLoadPreview({ path: path, mime: mime, @@ -195,9 +195,10 @@ $(document).ready(function() { var location = window.location.protocol + '//' + window.location.host + OC.webroot; var owner = $('#save').data('owner'); var name = $('#save').data('name'); + var isProtected = $('#save').data('protected') ? 1 : 0; var url = remote + '/index.php/apps/files#' + 'remote=' + encodeURIComponent(location) // our location is the remote for the other server - + "&token=" + encodeURIComponent(token) + "&owner=" + encodeURIComponent(owner) + "&name=" + encodeURIComponent(name); + + "&token=" + encodeURIComponent(token) + "&owner=" + encodeURIComponent(owner) + "&name=" + encodeURIComponent(name) + "&protected=" + isProtected; if (remote.indexOf('://') > 0) { diff --git a/apps/files_sharing/public.php b/apps/files_sharing/public.php index 4782c4dbe32..ec7c80f3316 100644 --- a/apps/files_sharing/public.php +++ b/apps/files_sharing/public.php @@ -128,6 +128,7 @@ if (isset($path)) { $tmpl->assign('mimetype', \OC\Files\Filesystem::getMimeType($path)); $tmpl->assign('dirToken', $linkItem['token']); $tmpl->assign('sharingToken', $token); + $tmpl->assign('protected', isset($linkItem['share_with']) ? 'true' : 'false'); $urlLinkIdentifiers= (isset($token)?'&t='.$token:'') .(isset($_GET['dir'])?'&dir='.$_GET['dir']:'') diff --git a/apps/files_sharing/templates/public.php b/apps/files_sharing/templates/public.php index 92d561e18e1..c053aaabece 100644 --- a/apps/files_sharing/templates/public.php +++ b/apps/files_sharing/templates/public.php @@ -16,7 +16,7 @@
- +