enable admin to turn off ZIP downloads

user interface offers multi-file/folder downloads only if available

make function name more clear
This commit is contained in:
Arthur Schiwon 2012-03-19 11:56:02 +01:00
parent 194211500b
commit b13ab2b17e
6 changed files with 60 additions and 19 deletions

View File

@ -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();

View File

@ -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');
}
});
});

View File

@ -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');

View File

@ -6,7 +6,10 @@
<?php if($_['htaccessWorking']):?>
<label for="maxUploadSize"><?php echo $l->t( 'Maximum upload size' ); ?> </label><input name='maxUploadSize' id="maxUploadSize" value='<?php echo $_['uploadMaxFilesize'] ?>'/><br/>
<?php endif;?>
<label for="maxZipInputSize"><?php echo $l->t( 'Maximum input size for zip files (affects folder- and multi-file download)' ); ?> </label><input name="maxZipInputSize" id="maxZipInputSize" value='<?php echo $_['maxZipInputSize'] ?>'/><br/>
<input type="checkbox" name="allowZipDownload" id="allowZipDownload" value="1" title="<?php echo $l->t( 'Needed for multi-file and folder downloads.' ); ?>"<?php if ($_['allowZipDownload']) echo ' checked="checked"'; ?> /> <label for="allowZipDownload"><?php echo $l->t( 'Enable ZIP-download' ); ?></label> <br/>
<fieldset class="personalblock">
<label for="maxZipInputSize"><?php echo $l->t( 'Maximum input size for ZIP files:' ); ?> </label><input name="maxZipInputSize" id="maxZipInputSize" value='<?php echo $_['maxZipInputSize'] ?>' title="<?php echo $l->t( '0 is unlimited' ); ?>"<?php if (!$_['allowZipDownload']) echo ' disabled="disabled"'; ?> /><br/>
</fieldset>
<input type="submit" value="Save"/>
</fieldset>
</form>

View File

@ -40,7 +40,9 @@
<?php if(!isset($_['readonly']) || !$_['readonly']) { ?><input type="checkbox" id="select_all" /><?php } ?>
<span class='name'><?php echo $l->t( 'Name' ); ?></span>
<span class='selectedActions'>
<a href="" title="<?php echo $l->t('Download')?>" class="download"><img class='svg' alt="Download" src="<?php echo image_path("core", "actions/download.svg"); ?>" /></a>
<?php if(OC_Preferences::getValue('', 'files', 'allowZipDownload', 1)) : ?>
<a href="" title="<?php echo $l->t('Download')?>" class="download"><img class='svg' alt="Download" src="<?php echo image_path("core", "actions/download.svg"); ?>" /></a>
<?php endif; ?>
<a href="" title="Share" class="share"><img class='svg' alt="Share" src="<?php echo image_path("core", "actions/share.svg"); ?>" /></a>
</span>
</th>
@ -66,3 +68,6 @@
<?php echo $l->t('Current scanning');?> <span id='scan-current'></spann>
</p>
</div>
<!-- config hints for javascript -->
<input type="hidden" name="allowZipDownload" id="allowZipDownload" value="<?php echo OC_Preferences::getValue('', 'files', 'allowZipDownload', 1); ?>" />

View File

@ -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.') . '<br/><a href="javascript:history.back()">' . $l->t('Back to Files') . '</a>',
)
);
$tmpl->assign('errors', $errors);
$tmpl->printPage();
exit;
}
$zipLimit = OC_Preferences::getValue('', 'files', 'maxZipInputSize', OC_Helper::computerFileSize('800 MB'));
if($zipLimit > 0) {
$totalsize = 0;