]> source.dussan.org Git - nextcloud-server.git/commitdiff
enable admin to turn off ZIP downloads
authorArthur Schiwon <blizzz@owncloud.com>
Mon, 19 Mar 2012 10:56:02 +0000 (11:56 +0100)
committerArthur Schiwon <blizzz@owncloud.com>
Mon, 19 Mar 2012 10:56:02 +0000 (11:56 +0100)
user interface offers multi-file/folder downloads only if available

make function name more clear

files/admin.php
files/js/admin.js
files/js/fileactions.js
files/templates/admin.php
files/templates/index.php
lib/files.php

index 7e410652cfb5f4f285fd2dfaff7c74ff6138342c..b9c26c465f3ebf84e314b9915b4328b51b8d8f70 100644 (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();
\ No newline at end of file
index 5cbb2b9f5ac5aa163ff3bad64eb3629ecd177574..bfa966706351e27b941e561b93c8a279f5c22e58 100644 (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');
+               }
+       });
 });
index b5dd3982803405ef8eadbde0fbcc7472a36922a0..b33be280ad53d77a1aed7536d64439611ad89a0a 100644 (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');
index 8c3ba56ad52fe98dae6c97bce5090f380c81ec22..fd86d02e1ed59adcdbf2193d3a8ce41a6059892d 100644 (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>
index 7fc51c288e1c7402c6edbb3df47281d71f9939f6..497a0f36c0d1ac7b8d11b8f47deacde1a7525366 100644 (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); ?>" />
\ No newline at end of file
index 50223df1d3693ba1e14a28d961e600a8c25eaca3..662f0b597241de8fe95fb7e97026a3854aa986d8 100644 (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;