From b13ab2b17eb485aec13c7fb1e88e25e1c9901d72 Mon Sep 17 00:00:00 2001
From: Arthur Schiwon
Date: Mon, 19 Mar 2012 11:56:02 +0100
Subject: [PATCH] enable admin to turn off ZIP downloads
user interface offers multi-file/folder downloads only if available
make function name more clear
---
files/admin.php | 3 +++
files/js/admin.js | 28 ++++++++++++++++++----------
files/js/fileactions.js | 15 +++++++++++----
files/templates/admin.php | 5 ++++-
files/templates/index.php | 7 ++++++-
lib/files.php | 21 ++++++++++++++++++---
6 files changed, 60 insertions(+), 19 deletions(-)
diff --git a/files/admin.php b/files/admin.php
index 7e410652cfb..b9c26c465f3 100644
--- a/files/admin.php
+++ b/files/admin.php
@@ -37,10 +37,12 @@ if($_POST) {
$maxZipInputSize=$_POST['maxZipInputSize'];
OC_Preferences::setValue('', 'files', 'maxZipInputSize', OC_Helper::computerFileSize($maxZipInputSize));
}
+ OC_Preferences::setValue('', 'files', 'allowZipDownload', isset($_POST['allowZipDownload']));
}else{
$upload_max_filesize = OC_Helper::computerFileSize(ini_get('upload_max_filesize'));
$post_max_size = OC_Helper::computerFileSize(ini_get('post_max_size'));
$maxUploadFilesize = min($upload_max_filesize, $post_max_size);
+ $allowZipDownload = intval(OC_Preferences::getValue('', 'files', 'allowZipDownload', 1));
$maxZipInputSize = OC_Helper::humanfilesize(OC_Preferences::getValue('', 'files', 'maxZipInputSize', OC_Helper::computerFileSize('800 MB')));
}
@@ -49,5 +51,6 @@ OC_App::setActiveNavigationEntry( "files_administration" );
$tmpl = new OC_Template( 'files', 'admin' );
$tmpl->assign( 'htaccessWorking', $htaccessWorking );
$tmpl->assign( 'uploadMaxFilesize', $maxUploadFilesize);
+$tmpl->assign( 'allowZipDownload', $allowZipDownload);
$tmpl->assign( 'maxZipInputSize', $maxZipInputSize);
return $tmpl->fetchPage();
\ No newline at end of file
diff --git a/files/js/admin.js b/files/js/admin.js
index 5cbb2b9f5ac..bfa96670635 100644
--- a/files/js/admin.js
+++ b/files/js/admin.js
@@ -1,15 +1,23 @@
-function switchPublicFolder()
+function switchPublicFolder()
{
- var publicEnable = $('#publicEnable').is(':checked');
- var sharingaimGroup = $('input:radio[name=sharingaim]'); //find all radiobuttons of that group
- $.each(sharingaimGroup, function(index, sharingaimItem) {
- sharingaimItem.disabled = !publicEnable; //set all buttons to the correct state
- });
+ var publicEnable = $('#publicEnable').is(':checked');
+ var sharingaimGroup = $('input:radio[name=sharingaim]'); //find all radiobuttons of that group
+ $.each(sharingaimGroup, function(index, sharingaimItem) {
+ sharingaimItem.disabled = !publicEnable; //set all buttons to the correct state
+ });
}
$(document).ready(function(){
- switchPublicFolder(); // Execute the function after loading DOM tree
- $('#publicEnable').click(function(){
- switchPublicFolder(); // To get rid of onClick()
- });
+ switchPublicFolder(); // Execute the function after loading DOM tree
+ $('#publicEnable').click(function(){
+ switchPublicFolder(); // To get rid of onClick()
+ });
+
+ $('#allowZipDownload').bind('change', function() {
+ if($('#allowZipDownload').attr('checked')) {
+ $('#maxZipInputSize').removeAttr('disabled');
+ } else {
+ $('#maxZipInputSize').attr('disabled', 'disabled');
+ }
+ });
});
diff --git a/files/js/fileactions.js b/files/js/fileactions.js
index b5dd3982803..b33be280ad5 100644
--- a/files/js/fileactions.js
+++ b/files/js/fileactions.js
@@ -106,7 +106,7 @@ FileActions={
element.hide();
parent.parent().children().last().append(element);
}
- $('#fileList .action').css('-o-transition-property','none');//temporarly disable
+ $('#fileList .action').css('-o-transition-property','none');//temporarly disable
$('#fileList .action').fadeIn(200,function(){
$('#fileList .action').css('-o-transition-property','opacity');
});
@@ -128,8 +128,15 @@ FileActions={
}
}
-FileActions.register('all','Download',function(){return OC.imagePath('core','actions/download')},function(filename){
- window.location='ajax/download.php?files='+encodeURIComponent(filename)+'&dir='+encodeURIComponent($('#dir').val());
+$(document).ready(function(){
+ if($('#allowZipDownload').val() == 1){
+ var downloadScope = 'all';
+ } else {
+ var downloadScope = 'file';
+ }
+ FileActions.register(downloadScope,'Download',function(){return OC.imagePath('core','actions/download')},function(filename){
+ window.location='ajax/download.php?files='+encodeURIComponent(filename)+'&dir='+encodeURIComponent($('#dir').val());
+ });
});
FileActions.register('all','Delete',function(){return OC.imagePath('core','actions/delete')},function(filename){
@@ -144,4 +151,4 @@ FileActions.register('dir','Open','',function(filename){
window.location='index.php?dir='+encodeURIComponent($('#dir').val()).replace(/%2F/g, '/')+'/'+encodeURIComponent(filename);
});
-FileActions.setDefault('dir','Open');
+FileActions.setDefault('dir','Open');
diff --git a/files/templates/admin.php b/files/templates/admin.php
index 8c3ba56ad52..fd86d02e1ed 100644
--- a/files/templates/admin.php
+++ b/files/templates/admin.php
@@ -6,7 +6,10 @@
'/>
- '/>
+ />
+
diff --git a/files/templates/index.php b/files/templates/index.php
index 7fc51c288e1..497a0f36c0d 100644
--- a/files/templates/index.php
+++ b/files/templates/index.php
@@ -40,7 +40,9 @@
t( 'Name' ); ?>
- " />
+
+ " />
+
" />
@@ -66,3 +68,6 @@
t('Current scanning');?>
+
+
+
\ No newline at end of file
diff --git a/lib/files.php b/lib/files.php
index 50223df1d36..662f0b59724 100644
--- a/lib/files.php
+++ b/lib/files.php
@@ -59,7 +59,7 @@ class OC_Files {
}
if(is_array($files)){
- self::checkZipInputSize($dir,$files);
+ self::validateZipDownload($dir,$files);
$executionTime = intval(ini_get('max_execution_time'));
set_time_limit(0);
$zip = new ZipArchive();
@@ -80,7 +80,7 @@ class OC_Files {
$zip->close();
set_time_limit($executionTime);
}elseif(OC_Filesystem::is_dir($dir.'/'.$files)){
- self::checkZipInputSize($dir,$files);
+ self::validateZipDownload($dir,$files);
$executionTime = intval(ini_get('max_execution_time'));
set_time_limit(0);
$zip = new ZipArchive();
@@ -223,7 +223,22 @@ class OC_Files {
* @param dir $dir
* @param files $files
*/
- static function checkZipInputSize($dir, $files) {
+ static function validateZipDownload($dir, $files) {
+ if(!OC_Preferences::getValue('', 'files', 'allowZipDownload', 1)) {
+ $l = new OC_L10N('files');
+ header("HTTP/1.0 409 Conflict");
+ $tmpl = new OC_Template( '', 'error', 'user' );
+ $errors = array(
+ array(
+ 'error' => $l->t('ZIP download is turned off.'),
+ 'hint' => $l->t('Files need to be downloaded one by one.') . '
' . $l->t('Back to Files') . '',
+ )
+ );
+ $tmpl->assign('errors', $errors);
+ $tmpl->printPage();
+ exit;
+ }
+
$zipLimit = OC_Preferences::getValue('', 'files', 'maxZipInputSize', OC_Helper::computerFileSize('800 MB'));
if($zipLimit > 0) {
$totalsize = 0;
--
2.39.5