Last active
December 17, 2015 09:59
-
-
Save cosmomill/5590995 to your computer and use it in GitHub Desktop.
Add anonymous upload Feature as requested in https://github.com/owncloud/core/issues/740 to ownCloud 4.5.10
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git apps/files_sharing/ajax/upload.php apps/files_sharing/ajax/upload.php | |
new file mode 100644 | |
index 0000000..d5fc5f2 | |
--- /dev/null | |
+++ apps/files_sharing/ajax/upload.php | |
@@ -0,0 +1,125 @@ | |
+<?php | |
+ | |
+// Init owncloud | |
+ | |
+ | |
+// Firefox and Konqueror tries to download application/json for me. --Arthur | |
+OCP\JSON::setContentTypeHeader('text/plain'); | |
+ | |
+/** | |
+ * calculate the disc space | |
+ * needed because OC_Filesystem::free_space() (OC_FileProxy_Quota::getQuota()) | |
+ * uses data from session to fetch user quota | |
+ * @param string $user | |
+ * @return int | |
+ */ | |
+function getFreeSpace($user) { | |
+ $rootInfo = OC_FileCache_Cached::get(''); | |
+ if(OC_FileCache::inCache('/Shared')) { | |
+ $sharedInfo = OC_FileCache_Cached::get('/Shared'); | |
+ } else { | |
+ $sharedInfo = null; | |
+ } | |
+ $used = $rootInfo['size'] - $sharedInfo['size']; | |
+ $userQuota = OC_Preferences::getValue($user, 'files', 'quota', 'default'); | |
+ if($userQuota == 'default') { | |
+ $userQuota = OC_AppConfig::getValue('files', 'default_quota', 'none'); | |
+ } | |
+ if($userQuota == 'none') { | |
+ $userQuota = 0; | |
+ } else { | |
+ $userQuota = OC_Helper::computerFileSize($userQuota); | |
+ } | |
+ $usedSpace = isset($rootInfo['size']) ? $rootInfo['size'] : 0; | |
+ $usedSpace = isset($sharedInfo['size']) ? $usedSpace - $sharedInfo['size'] : $usedSpace; | |
+ $totalSpace = $userQuota; | |
+ if($totalSpace == 0) { | |
+ return 0; | |
+ } | |
+ return $totalSpace - $usedSpace; | |
+} | |
+ | |
+ | |
+// If a directory token is sent along check if public upload is permitted. | |
+// If not, check the login. | |
+// If no token is sent along, rely on login only | |
+if ($_POST['dirToken']) { | |
+ $linkItem = OCP\Share::getShareByToken($_POST['dirToken']); | |
+ | |
+ if (!($linkItem['permissions'] && OCP\Share::PERMISSION_CREATE && OCP\User::userExists($linkItem['uid_owner']) && $linkItem['file_source'] != -1)) { | |
+ OCP\JSON::checkLoggedIn(); | |
+ } else { | |
+ // The token defines the target directory (security reasons) | |
+ $dir = $linkItem['file_target']; | |
+ | |
+ // Setup FS with owner | |
+ // NOTE: this subject has been discussed in the IRC channel. So far however I didn't come to a conclusion | |
+ // about possible security issues on this line. Please take a closer look at this during evaluation. | |
+ OC_Util::setupFS($linkItem['uid_owner']); | |
+ } | |
+} else { | |
+ // The standard case, files are uploaded through logged in users :) | |
+ OCP\JSON::checkLoggedIn(); | |
+ $dir = $_POST['dir']; | |
+} | |
+ | |
+OCP\JSON::callCheck(); | |
+$l=OC_L10N::get('files'); | |
+ | |
+if (!isset($_FILES['files'])) { | |
+ OCP\JSON::error(array('data' => array( 'message' => $l->t( 'No file was uploaded. Unknown error' )))); | |
+ exit(); | |
+} | |
+foreach ($_FILES['files']['error'] as $error) { | |
+ if ($error != 0) { | |
+ $errors = array( | |
+ UPLOAD_ERR_OK=>$l->t('There is no error, the file uploaded with success'), | |
+ UPLOAD_ERR_INI_SIZE=>$l->t('The uploaded file exceeds the upload_max_filesize directive in php.ini: ') | |
+ .ini_get('upload_max_filesize'), | |
+ UPLOAD_ERR_FORM_SIZE=>$l->t('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified' | |
+ .' in the HTML form'), | |
+ UPLOAD_ERR_PARTIAL=>$l->t('The uploaded file was only partially uploaded'), | |
+ UPLOAD_ERR_NO_FILE=>$l->t('No file was uploaded'), | |
+ UPLOAD_ERR_NO_TMP_DIR=>$l->t('Missing a temporary folder'), | |
+ UPLOAD_ERR_CANT_WRITE=>$l->t('Failed to write to disk'), | |
+ ); | |
+ OCP\JSON::error(array('data' => array( 'message' => $errors[$error] ))); | |
+ exit(); | |
+ } | |
+} | |
+$files=$_FILES['files']; | |
+ | |
+$error=''; | |
+ | |
+$totalSize=0; | |
+foreach($files['size'] as $size) { | |
+ $totalSize+=$size; | |
+} | |
+if($totalSize>getFreeSpace($linkItem['uid_owner'])) { | |
+ OCP\JSON::error(array('data' => array( 'message' => $l->t( 'Not enough space available' )))); | |
+ exit(); | |
+} | |
+ | |
+$result=array(); | |
+if(strpos($dir, '..') === false) { | |
+ $fileCount=count($files['name']); | |
+ for($i=0;$i<$fileCount;$i++) { | |
+ $target = OCP\Files::buildNotExistingFileName(stripslashes($dir), $files['name'][$i]); | |
+ // $path needs to be normalized - this failed within drag'n'drop upload to a sub-folder | |
+ $target = OC_Filesystem::normalizePath($target); | |
+ if(is_uploaded_file($files['tmp_name'][$i]) and OC_Filesystem::fromTmpFile($files['tmp_name'][$i], $target)) { | |
+ $meta = OC_FileCache::get($target); | |
+ $id = OC_FileCache::getId($target); | |
+ $icon = OC_Helper::mimetypeIcon($meta['mimetype']); | |
+ // User cache must be cleared - because $_SESSION['user_id'] is empty, so the entries will never be cleared out. | |
+ OC_Cache::clear(); | |
+ $result[]=array( 'status' => 'success', 'mime'=>$meta['mimetype'], 'size'=>$meta['size'], 'id'=>$id, 'name'=>basename($target), 'icon'=>$icon); | |
+ } | |
+ } | |
+ OCP\JSON::encodedPrint($result); | |
+ exit(); | |
+} else { | |
+ $error=$l->t( 'Invalid directory.' ); | |
+} | |
+ | |
+OCP\JSON::error(array('data' => array('message' => $error ))); | |
diff --git apps/files_sharing/css/public.css apps/files_sharing/css/public.css | |
index fb4794e..d4ff7f4 100644 | |
--- apps/files_sharing/css/public.css | |
+++ apps/files_sharing/css/public.css | |
@@ -8,4 +8,43 @@ body { background:#ddd; } | |
p.info { width:22em; text-align: center; margin:2em auto; color:#777; text-shadow:#fff 0 1px 0; } | |
p.info a { font-weight:bold; color:#777; } | |
#imgframe { width:80%; height: 75%; margin: 0 auto; padding-bottom:2em; } | |
-#imgframe img { max-height:100%; max-width: 100%; } | |
\ No newline at end of file | |
+#imgframe img { max-height:100%; max-width: 100%; } | |
+ | |
+#public-upload-progressbar { | |
+ position: absolute; | |
+ right: 8px; | |
+ top: 44px; | |
+} | |
+ | |
+#public-upload-progressbar #uploadprogressbar { | |
+ display: inline-block; | |
+ height: 1.5em; | |
+ position: relative; | |
+ top: 0.4em; | |
+ width: 10em; | |
+} | |
+ | |
+.public_upload_button_wrapper { | |
+ display: inline-block; | |
+ cursor: pointer; | |
+} | |
+ | |
+.public_file_upload_form { | |
+ display: inline; | |
+ float: left; | |
+ margin-left: 0; | |
+} | |
+ | |
+.public_file_upload_start { | |
+ position: absolute; | |
+ opacity: 0; | |
+ font-size: 0; | |
+ margin: 15px; | |
+ z-index: -1; | |
+} | |
+ | |
+#header #file-upload-button img { | |
+ padding-left: 0.1em; | |
+ padding-right: 0.3em; | |
+ vertical-align: text-bottom; | |
+} | |
diff --git apps/files_sharing/js/public.js apps/files_sharing/js/public.js | |
index 916e354..d9e67eb 100644 | |
--- apps/files_sharing/js/public.js | |
+++ apps/files_sharing/js/public.js | |
@@ -46,4 +46,248 @@ $(document).ready(function() { | |
}); | |
} | |
-}); | |
\ No newline at end of file | |
+ // Triggers invisible file input | |
+ $('#file-upload-button').live('click', function() { | |
+ $(this).parent().children('.public_file_upload_start').trigger('click'); | |
+ return false; | |
+ }); | |
+ | |
+ // Tipsy stuff | |
+ $('#file-upload-button').tipsy({gravity:'ne', fade:true}); | |
+ | |
+ if(document.getElementById("public-data-upload-form") ) { | |
+ $(function() { | |
+ $('.public_file_upload_start').fileupload({ | |
+ dropZone: $('#preview'), // restrict dropZone to preview div | |
+ add: function(e, data) { | |
+ var files = data.files; | |
+ var totalSize=0; | |
+ if(files){ | |
+ for(var i=0;i<files.length;i++){ | |
+ if(files[i].size ==0 && files[i].type== '') | |
+ { | |
+ OC.dialogs.alert(t('files', 'Unable to upload your file as it is a directory or has 0 bytes'), t('files', 'Upload Error')); | |
+ return; | |
+ } | |
+ totalSize+=files[i].size; | |
+ } | |
+ } | |
+ if(totalSize>$('#max_upload').val()){ | |
+ $( '#uploadsize-message' ).dialog({ | |
+ modal: true, | |
+ buttons: { | |
+ Close: function() { | |
+ $( this ).dialog( 'close' ); | |
+ } | |
+ } | |
+ }); | |
+ }else{ | |
+ var dropTarget = $(e.originalEvent.target).closest('tr'); | |
+ if(dropTarget && dropTarget.attr('data-type') === 'dir') { // drag&drop upload to folder | |
+ var dirName = dropTarget.attr('data-file') | |
+ } | |
+ | |
+ var date=new Date(); | |
+ if(files){ | |
+ for(var i=0;i<files.length;i++){ | |
+ if(files[i].size>0){ | |
+ var size=files[i].size; | |
+ }else{ | |
+ var size=t('files','Pending'); | |
+ } | |
+ if(files && !dirName){ | |
+ var uniqueName = getUniqueName(files[i].name); | |
+ //FileList.addFile(uniqueName,size,date,true,hidden); | |
+ FileList.addFile(uniqueName,size,date,true,false); | |
+ } else if(dirName) { | |
+ var uploadtext = $('tr').filterAttr('data-type', 'dir').filterAttr('data-file', dirName).find('.uploadtext') | |
+ var currentUploads = parseInt(uploadtext.attr('currentUploads')); | |
+ currentUploads += 1; | |
+ uploadtext.attr('currentUploads', currentUploads); | |
+ if(currentUploads === 1) { | |
+ var img = OC.imagePath('core', 'loading.gif'); | |
+ var tr=$('tr').filterAttr('data-file',dirName); | |
+ tr.find('td.filename').attr('style','background-image:url('+img+')'); | |
+ uploadtext.text(t('files', '1 file uploading')); | |
+ uploadtext.show(); | |
+ } else { | |
+ uploadtext.text(currentUploads + ' ' + t('files', 'files uploading')); | |
+ } | |
+ } | |
+ } | |
+ }else{ | |
+ var filename=this.value.split('\\').pop(); //ie prepends C:\fakepath\ in front of the filename | |
+ var uniqueName = getUniqueName(filename); | |
+ if (uniqueName != filename) { | |
+ FileList.checkName(uniqueName, filename, true); | |
+ var hidden = true; | |
+ } else { | |
+ var hidden = false; | |
+ } | |
+ FileList.addFile(uniqueName,'Pending',date,true,hidden); | |
+ } | |
+ if($.support.xhrFileUpload) { | |
+ for(var i=0;i<files.length;i++){ | |
+ var fileName = files[i].name | |
+ var dropTarget = $(e.originalEvent.target).closest('tr'); | |
+ if(dropTarget && dropTarget.attr('data-type') === 'dir') { // drag&drop upload to folder | |
+ var dirName = dropTarget.attr('data-file') | |
+ var jqXHR = $('.public_file_upload_start').fileupload('send', {files: files[i], | |
+ formData: function(form) { | |
+ var formArray = form.serializeArray(); | |
+ // array index 0 contains the max files size | |
+ // array index 1 contains the request token | |
+ // array index 2 contains the directory | |
+ formArray[2]['value'] = dirName; | |
+ return formArray; | |
+ }}).success(function(result, textStatus, jqXHR) { | |
+ var response; | |
+ response=jQuery.parseJSON(result); | |
+ if(response[0] == undefined || response[0].status != 'success') { | |
+ $('#notification').text(t('files', response.data.message)); | |
+ $('#notification').fadeIn(); | |
+ } | |
+ var file=response[0]; | |
+ // TODO: this doesn't work if the file name has been changed server side | |
+ delete uploadingFiles[dirName][file.name]; | |
+ if ($.assocArraySize(uploadingFiles[dirName]) == 0) { | |
+ delete uploadingFiles[dirName]; | |
+ } | |
+ | |
+ var uploadtext = $('tr').filterAttr('data-type', 'dir').filterAttr('data-file', dirName).find('.uploadtext') | |
+ var currentUploads = parseInt(uploadtext.attr('currentUploads')); | |
+ currentUploads -= 1; | |
+ uploadtext.attr('currentUploads', currentUploads); | |
+ if(currentUploads === 0) { | |
+ var img = OC.imagePath('core', 'filetypes/folder.png'); | |
+ var tr=$('tr').filterAttr('data-file',dirName); | |
+ tr.find('td.filename').attr('style','background-image:url('+img+')'); | |
+ uploadtext.text(''); | |
+ uploadtext.hide(); | |
+ } else { | |
+ uploadtext.text(currentUploads + ' ' + t('files', 'files uploading')); | |
+ } | |
+ }) | |
+ .error(function(jqXHR, textStatus, errorThrown) { | |
+ if(errorThrown === 'abort') { | |
+ var currentUploads = parseInt(uploadtext.attr('currentUploads')); | |
+ currentUploads -= 1; | |
+ uploadtext.attr('currentUploads', currentUploads); | |
+ if(currentUploads === 0) { | |
+ var img = OC.imagePath('core', 'filetypes/folder.png'); | |
+ var tr=$('tr').filterAttr('data-file',dirName); | |
+ tr.find('td.filename').attr('style','background-image:url('+img+')'); | |
+ uploadtext.text(''); | |
+ uploadtext.hide(); | |
+ } else { | |
+ uploadtext.text(currentUploads + ' ' + t('files', 'files uploading')); | |
+ } | |
+ $('#notification').hide(); | |
+ $('#notification').text(t('files', 'Upload cancelled.')); | |
+ $('#notification').fadeIn(); | |
+ } | |
+ }); | |
+ //TODO test with filenames containing slashes | |
+ if(uploadingFiles[dirName] === undefined) { | |
+ uploadingFiles[dirName] = {}; | |
+ } | |
+ uploadingFiles[dirName][fileName] = jqXHR; | |
+ } else { | |
+ var jqXHR = $('.public_file_upload_start').fileupload('send', {files: files[i]}) | |
+ .success(function(result, textStatus, jqXHR) { | |
+ var response; | |
+ response=jQuery.parseJSON(result); | |
+ if(response[0] != undefined && response[0].status == 'success') { | |
+ var file=response[0]; | |
+ delete uploadingFiles[file.name]; | |
+ $('tr').filterAttr('data-file',file.name).data('mime',file.mime).data('id',file.id); | |
+ var size = $('tr').filterAttr('data-file',file.name).find('td.filesize').text(); | |
+ if(size==t('files','Pending')){ | |
+ $('tr').filterAttr('data-file',file.name).find('td.filesize').text(file.size); | |
+ } | |
+ $('tr').filterAttr('data-file',file.name).data('loading',false); | |
+ $('tr').filterAttr('data-file',file.name).attr('data-mime',file.mime); | |
+ if(file.id != null) { | |
+ $('tr').filterAttr('data-file',file.name).attr('data-id', file.id); | |
+ } | |
+ $('tr').filterAttr('data-file',file.name).find('td.filename').attr('style','background-image:url('+file.icon+')'); | |
+ $('tr').filterAttr('data-file',file.name).find('td.filename').draggable(dragOptions); | |
+ } else { | |
+ $('#notification').text(t('files', response.data.message)); | |
+ $('#notification').fadeIn(); | |
+ $('#fileList > tr').not('[data-mime]').fadeOut(); | |
+ $('#fileList > tr').not('[data-mime]').remove(); | |
+ } | |
+ }) | |
+ .error(function(jqXHR, textStatus, errorThrown) { | |
+ if(errorThrown === 'abort') { | |
+ $('#notification').hide(); | |
+ $('#notification').text(t('files', 'Upload cancelled.')); | |
+ $('#notification').fadeIn(); | |
+ } | |
+ }); | |
+ uploadingFiles[uniqueName] = jqXHR; | |
+ } | |
+ } | |
+ }else{ | |
+ data.submit().success(function(data, status) { | |
+ // in safari data is a string | |
+ response = jQuery.parseJSON(typeof data === 'string' ? data : data[0].body.innerText); | |
+ if(response[0] != undefined && response[0].status == 'success') { | |
+ var file=response[0]; | |
+ delete uploadingFiles[file.name]; | |
+ $('tr').filterAttr('data-file',file.name).data('mime',file.mime).data('id',file.id); | |
+ var size = $('tr').filterAttr('data-file',file.name).find('td.filesize').text(); | |
+ if(size==t('files','Pending')){ | |
+ $('tr').filterAttr('data-file',file.name).find('td.filesize').text(file.size); | |
+ } | |
+ $('tr').filterAttr('data-file',file.name).data('loading',false); | |
+ $('tr').filterAttr('data-file',file.name).attr('data-mime',file.mime); | |
+ if(file.id != null) { | |
+ $('tr').filterAttr('data-file',file.name).attr('data-id', file.id); | |
+ } | |
+ $('tr').filterAttr('data-file',file.name).find('td.filename').attr('style','background-image:url('+file.icon+')'); | |
+ $('tr').filterAttr('data-file',file.name).find('td.filename').draggable(dragOptions); | |
+ } else { | |
+ $('#notification').text(t('files', response.data.message)); | |
+ $('#notification').fadeIn(); | |
+ $('#fileList > tr').not('[data-mime]').fadeOut(); | |
+ $('#fileList > tr').not('[data-mime]').remove(); | |
+ } | |
+ }); | |
+ } | |
+ } | |
+ }, | |
+ fail: function(e, data) { | |
+ // TODO: cancel upload & display error notification | |
+ }, | |
+ progress: function(e, data) { | |
+ // TODO: show nice progress bar in file row | |
+ }, | |
+ progressall: function(e, data) { | |
+ var progress = (data.loaded/data.total)*100; | |
+ $('#uploadprogressbar').progressbar('value',progress); | |
+ }, | |
+ start: function(e, data) { | |
+ $('#uploadprogressbar').progressbar({value:0}); | |
+ $('#uploadprogressbar').fadeIn(); | |
+ if(data.dataType != 'iframe ') { | |
+ $('#public-upload-progressbar input.stop').show(); | |
+ } | |
+ }, | |
+ stop: function(e, data) { | |
+ if(data.dataType != 'iframe ') { | |
+ $('#public-upload-progressbar input.stop').hide(); | |
+ } | |
+ $('#uploadprogressbar').progressbar('value',100); | |
+ $('#uploadprogressbar').fadeOut(); | |
+ } | |
+ }) | |
+ }); | |
+ } | |
+ | |
+ //add multiply file upload attribute to all browsers except konqueror (which crashes when it's used) | |
+ if(navigator.userAgent.search(/konqueror/i)==-1){ | |
+ $('.public_file_upload_start').attr('multiple','multiple') | |
+ } | |
+}); | |
diff --git apps/files_sharing/public.php apps/files_sharing/public.php | |
index d376947..e806bd2 100644 | |
--- apps/files_sharing/public.php | |
+++ apps/files_sharing/public.php | |
@@ -52,6 +52,39 @@ function getPathAndUser($id) { | |
return $row; | |
} | |
+/** | |
+ * calculate the disc space | |
+ * needed because OC_Filesystem::free_space() (OC_FileProxy_Quota::getQuota()) | |
+ * uses data from session to fetch user quota | |
+ * @param string $user | |
+ * @return int | |
+ */ | |
+function getFreeSpace($user) { | |
+ $rootInfo = OC_FileCache_Cached::get(''); | |
+ if(OC_FileCache::inCache('/Shared')) { | |
+ $sharedInfo = OC_FileCache_Cached::get('/Shared'); | |
+ } else { | |
+ $sharedInfo = null; | |
+ } | |
+ $used = $rootInfo['size'] - $sharedInfo['size']; | |
+ $userQuota = OC_Preferences::getValue($user, 'files', 'quota', 'default'); | |
+ if($userQuota == 'default') { | |
+ $userQuota = OC_AppConfig::getValue('files', 'default_quota', 'none'); | |
+ } | |
+ if($userQuota == 'none') { | |
+ $userQuota = 0; | |
+ } else { | |
+ $userQuota = OC_Helper::computerFileSize($userQuota); | |
+ } | |
+ $usedSpace = isset($rootInfo['size']) ? $rootInfo['size'] : 0; | |
+ $usedSpace = isset($sharedInfo['size']) ? $usedSpace - $sharedInfo['size'] : $usedSpace; | |
+ $totalSpace = $userQuota; | |
+ if($totalSpace == 0) { | |
+ return 0; | |
+ } | |
+ return $totalSpace - $usedSpace; | |
+} | |
+ | |
if (isset($_GET['t'])) { | |
$token = $_GET['t']; | |
@@ -198,11 +231,27 @@ if ($linkItem) { | |
OCP\Util::addStyle('files_sharing', 'public'); | |
OCP\Util::addScript('files_sharing', 'public'); | |
OCP\Util::addScript('files', 'fileactions'); | |
+ OCP\Util::addScript('files', 'jquery.iframe-transport'); | |
+ OCP\Util::addScript('files', 'jquery.fileupload'); | |
$tmpl = new OCP\Template('files_sharing', 'public', 'base'); | |
$tmpl->assign('uidOwner', $shareOwner); | |
$tmpl->assign('dir', $dir); | |
$tmpl->assign('filename', $file); | |
$tmpl->assign('mimetype', OC_Filesystem::getMimeType($path)); | |
+ | |
+ $upload_max_filesize = OCP\Util::computerFileSize(ini_get('upload_max_filesize')); | |
+ $post_max_size = OCP\Util::computerFileSize(ini_get('post_max_size')); | |
+ $maxUploadFilesize = min($upload_max_filesize, $post_max_size); | |
+ | |
+ $freeSpace = getFreeSpace($shareOwner); | |
+ $freeSpace = max($freeSpace, 0); | |
+ $maxUploadFilesize = min($maxUploadFilesize, $freeSpace); | |
+ | |
+ $tmpl->assign('uploadMaxFilesize', $maxUploadFilesize); | |
+ $tmpl->assign('uploadMaxHumanFilesize', OCP\Util::humanFileSize($maxUploadFilesize)); | |
+ $tmpl->assign('dirToken', $linkItem['token']); | |
+ $tmpl->assign('allowPublicUpload', (($linkItem['permissions'] & OCP\Share::PERMISSION_CREATE) ? true : false )); | |
+ | |
if (isset($_GET['path'])) { | |
$getPath = $_GET['path']; | |
} else { | |
diff --git apps/files_sharing/templates/public.php apps/files_sharing/templates/public.php | |
index b8ee34e..75d283b 100644 | |
--- apps/files_sharing/templates/public.php | |
+++ apps/files_sharing/templates/public.php | |
@@ -21,6 +21,25 @@ | |
<?php if (!isset($_['folder']) || $_['allowZipDownload']): ?> | |
<a href="<?php echo $_['downloadURL']; ?>" class="button" id="download"><img class="svg" alt="Download" src="<?php echo OCP\image_path("core", "actions/download.svg"); ?>" /><?php echo $l->t('Download')?></a> | |
<?php endif; ?> | |
+ <?php if ($_['allowPublicUpload']):?> | |
+ <div class="public_upload_button_wrapper"> | |
+ <form data-upload-id='1' id="public-data-upload-form" class="file_upload_form" action="<?php echo OCP\Util::linkTo('files_sharing', 'ajax/upload.php'); ?>" method="post" enctype="multipart/form-data" target="file_upload_target_1"> | |
+ <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $_['uploadMaxFilesize'] ?>" id="max_upload"> | |
+ <!-- Send the requesttoken, this is needed for older IE versions because they don't send the CSRF token via HTTP header in this case --> | |
+ <input type="hidden" name="requesttoken" value="<?php echo $_['requesttoken'] ?>" id="requesttoken"> | |
+ <input type="hidden" class="max_human_file_size" value="(max <?php echo $_['uploadMaxHumanFilesize']; ?>)"> | |
+ <input type="hidden" name="dir" value="<?php echo $_['dir'] ?>" id="dir"> | |
+ <input type="hidden" name="dirToken" value="<?php echo $_['dirToken'] ?>" id="public-dir-token"> | |
+ <input class="public_file_upload_start" type="file" name='files[]'/> | |
+ <iframe name="file_upload_target_1" class='file_upload_target' src=""></iframe> | |
+ <a href="#" class="button" id="file-upload-button" onclick="return false;" title="<?php echo $l->t('Upload'); echo ' max. '.$_['uploadMaxHumanFilesize'] ?>"><img class="svg" alt="Upload" src="<?php echo OCP\image_path("core", "actions/upload.svg"); ?>" /><?php echo $l->t('Upload')?></a> | |
+ </form> | |
+ </div> | |
+ <div id="public-upload-progressbar"> | |
+ <div id="uploadprogressbar"></div> | |
+ <input type="button" class="stop" style="display:none" value="<?php echo $l->t('Cancel upload');?>" onclick="javascript:Files.cancelUploads();" /> | |
+ </div> | |
+ <?php endif; ?> | |
</div> | |
</div></header> | |
<div id="preview"> | |
diff --git core/js/share.js core/js/share.js | |
index 719baf7..f87f567 100644 | |
--- core/js/share.js | |
+++ core/js/share.js | |
@@ -134,6 +134,15 @@ OC.Share={ | |
html += '<br />'; | |
} | |
if (possiblePermissions & OC.PERMISSION_SHARE) { | |
+ // Determine the Allow Public Upload status. | |
+ // Used later on to determine if the | |
+ // respective checkbox should be checked or not. | |
+ var allowPublicUploadStatus = false; | |
+ $.each(data.shares, function(key, value) { | |
+ if (allowPublicUploadStatus) return true; | |
+ allowPublicUploadStatus = (value.permissions & OC.PERMISSION_CREATE) ? true : false; | |
+ }); | |
+ | |
html += '<input id="shareWith" type="text" placeholder="'+t('core', 'Share with')+'" />'; | |
html += '<ul id="shareWithList">'; | |
html += '</ul>'; | |
@@ -146,11 +155,14 @@ OC.Share={ | |
html += '<div id="linkPass">'; | |
html += '<input id="linkPassText" type="password" placeholder="'+t('core', 'Password')+'" />'; | |
html += '</div>'; | |
- html += '</div>'; | |
- html += '<form id="emailPrivateLink" >'; | |
- html += '<input id="email" style="display:none; width:65%;" value="" placeholder="' + t('core', 'Email link to person') + '" type="text" />'; | |
- html += '<input id="emailButton" style="display:none; float:right;" type="submit" value="' + t('core', 'Send') + '" />'; | |
- html += '</form>'; | |
+ html += '<div id="allowPublicUploadWrapper" style="display:none;">'; | |
+ html += '<input type="checkbox" value="1" name="allowPublicUpload" id="sharingDialogAllowPublicUpload"' + ((allowPublicUploadStatus) ? 'checked="checked"' : '') + ' />'; | |
+ html += '<label for="sharingDialogAllowPublicUpload">' + t('core', 'Allow Public Upload') + '</label>'; | |
+ html += '</div></div>'; | |
+ html += '<form id="emailPrivateLink" >'; | |
+ html += '<input id="email" style="display:none; width:65%;" value="" placeholder="' + t('core', 'Email link to person') + '" type="text" />'; | |
+ html += '<input id="emailButton" style="display:none; float:right;" type="submit" value="' + t('core', 'Send') + '" />'; | |
+ html += '</form>'; | |
} | |
html += '<div id="expiration">'; | |
html += '<input type="checkbox" name="expirationCheckbox" id="expirationCheckbox" value="1" /><label for="expirationCheckbox">'+t('core', 'Set expiration date')+'</label>'; | |
@@ -337,6 +349,7 @@ OC.Share={ | |
$('#expiration').show(); | |
$('#emailPrivateLink #email').show(); | |
$('#emailPrivateLink #emailButton').show(); | |
+ $('#allowPublicUploadWrapper').show(); | |
}, | |
hideLink:function() { | |
$('#linkText').hide('blind'); | |
@@ -345,6 +358,7 @@ OC.Share={ | |
$('#linkPass').hide(); | |
$('#emailPrivateLink #email').hide(); | |
$('#emailPrivateLink #emailButton').hide(); | |
+ $('#allowPublicUploadWrapper').hide(); | |
}, | |
dirname:function(path) { | |
return path.replace(/\\/g,'/').replace(/\/[^\/]*$/, ''); | |
@@ -488,6 +502,27 @@ $(document).ready(function() { | |
$(this).focus(); | |
$(this).select(); | |
}); | |
+ | |
+ // Handle the Allow Public Upload Checkbox | |
+ $('#sharingDialogAllowPublicUpload').live('click', function() { | |
+ // Gather data | |
+ var allowPublicUpload = $(this).is(':checked'); | |
+ var itemType = $('#dropdown').data('item-type'); | |
+ var itemSource = $('#dropdown').data('item-source'); | |
+ var permissions = 0; | |
+ | |
+ // Calculate permissions | |
+ if (allowPublicUpload) { | |
+ permissions = OC.PERMISSION_UPDATE + OC.PERMISSION_CREATE + OC.PERMISSION_READ; | |
+ } else { | |
+ permissions = OC.PERMISSION_READ; | |
+ } | |
+ | |
+ // Update the share information | |
+ OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', permissions, function(data) { | |
+ return; | |
+ }); | |
+ }); | |
$('#showPassword').live('click', function() { | |
$('#linkPass').toggle('blind'); | |
@@ -505,7 +540,7 @@ $(document).ready(function() { | |
var itemType = $('#dropdown').data('item-type'); | |
var itemSource = $('#dropdown').data('item-source'); | |
OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, $('#linkPassText').val(), OC.PERMISSION_READ, function() { | |
- console.log("password set to: '" + $('#linkPassText').val() +"' by event: " + event.type); | |
+ //console.log("password set to: '" + $('#linkPassText').val() +"' by event: " + event.type); | |
$('#linkPassText').val(''); | |
$('#linkPassText').attr('placeholder', t('core', 'Password protected')); | |
}); | |
diff --git core/l10n/de.php core/l10n/de.php | |
index 31cfa76..b91ab42 100644 | |
--- core/l10n/de.php | |
+++ core/l10n/de.php | |
@@ -87,5 +87,6 @@ | |
"Log in" => "Einloggen", | |
"You are logged out." => "Du wurdest abgemeldet.", | |
"prev" => "Zurück", | |
-"next" => "Weiter" | |
+"next" => "Weiter", | |
+"Allow Public Upload" => "Öffentlichen Upload erlauben" | |
); | |
diff --git lib/base.php lib/base.php | |
index 9f39e82..059f814 100644 | |
--- lib/base.php | |
+++ lib/base.php | |
@@ -488,6 +488,15 @@ class OC{ | |
} | |
} | |
return; | |
+ }else{ | |
+ $app = OC::$REQUESTEDAPP; | |
+ $file = OC::$REQUESTEDFILE; | |
+ if($app == 'files_sharing' && $file == 'ajax/upload.php' && isset($_POST['dirToken'])) { | |
+ $linkItem = OCP\Share::getShareByToken($_POST['dirToken']); | |
+ if($linkItem['permissions'] && OCP\Share::PERMISSION_CREATE && OCP\User::userExists($linkItem['uid_owner']) && $linkItem['file_source'] != -1) { | |
+ self::loadAppScriptFile($app, $file); | |
+ } | |
+ } | |
} | |
// Not handled and not logged in | |
self::handleLogin(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment