moved download code to class, module only for drupal hooks
moved download code to class, module only for drupal hooks

--- a/vcaching.class.php
+++ b/vcaching.class.php
@@ -211,6 +211,45 @@
         }
     }
 
+    public function downloadConf($version)
+    {
+        $tmpfile = tempnam("tmp", "zip");
+        $zip = new ZipArchive();
+        $zip->open($tmpfile, ZipArchive::OVERWRITE);
+        $files = array(
+            'default.vcl' => true,
+            'LICENSE' => false,
+            'README.rst' => false,
+            'conf/acl.vcl' => true,
+            'conf/backend.vcl' => true,
+            'lib/bigfiles.vcl' => false,
+            'lib/bigfiles_pipe.vcl' => false,
+            'lib/cloudflare.vcl' => false,
+            'lib/mobile_cache.vcl' => false,
+            'lib/mobile_pass.vcl' => false,
+            'lib/purge.vcl' => true,
+            'lib/static.vcl' => false,
+            'lib/xforward.vcl' => false,
+        );
+        $vcaching = new VCaching('vcaching_');
+        foreach ($files as $file => $parse) {
+            $filepath = __DIR__ . '/varnish-conf/v' . $version . '/' . $file;
+            if ($parse) {
+                $content = $vcaching->_parse_conf_file($version, $file, file_get_contents($filepath));
+            } else {
+                $content = file_get_contents($filepath);
+            }
+            $zip->addFromString($file, $content);
+        }
+        $zip->close();
+        header('Content-Type: application/zip');
+        header('Content-Length: ' . filesize($tmpfile));
+        header('Content-Disposition: attachment; filename="varnish_v' . $version . '_conf.zip"');
+        readfile($tmpfile);
+        unlink($tmpfile);
+        exit();
+    }
+
     public function _parse_conf_file($version, $file, $content)
     {
         if ($file == 'default.vcl') {

--- a/vcaching.module
+++ b/vcaching.module
@@ -137,7 +137,7 @@
         'title' => 'Purge Varnish cache',
         'description' => 'Clear all cache',
         'page callback' => 'vcaching_purge_all_cache_callback',
-        'access arguments' => array('varnish caching console access'),
+        'access arguments' => array('varnish caching purge all'),
         'menu_name' => 'shortcut-set-1',
         'type' => MENU_NORMAL_ITEM,
         'weight' => 10
@@ -152,7 +152,7 @@
 function vcaching_permission() {
     return array(
         'varnish caching purge all' => array(
-            'title' => t('Purge all Varnish cache from \'Flush all caches\' shortcut'),
+            'title' => t('Purge all Varnish cache from shortcut'),
         ),
         'varnish caching settings access' => array(
             'title' => t('Change settings'),
@@ -402,41 +402,10 @@
 function vcaching_conf_form_submit($form, &$form_state)
 {
     $version = in_array($_POST['vcaching_conf_version'], array(3,4)) ? $_POST['vcaching_conf_version'] : 3;
-    $tmpfile = tempnam("tmp", "zip");
-    $zip = new ZipArchive();
-    $zip->open($tmpfile, ZipArchive::OVERWRITE);
-    $files = array(
-        'default.vcl' => true,
-        'LICENSE' => false,
-        'README.rst' => false,
-        'conf/acl.vcl' => true,
-        'conf/backend.vcl' => true,
-        'lib/bigfiles.vcl' => false,
-        'lib/bigfiles_pipe.vcl' => false,
-        'lib/cloudflare.vcl' => false,
-        'lib/mobile_cache.vcl' => false,
-        'lib/mobile_pass.vcl' => false,
-        'lib/purge.vcl' => true,
-        'lib/static.vcl' => false,
-        'lib/xforward.vcl' => false,
-    );
-    $vcaching = new VCaching('vcaching_');
-    foreach ($files as $file => $parse) {
-        $filepath = __DIR__ . '/varnish-conf/v' . $version . '/' . $file;
-        if ($parse) {
-            $content = $vcaching->_parse_conf_file($version, $file, file_get_contents($filepath));
-        } else {
-            $content = file_get_contents($filepath);
-        }
-        $zip->addFromString($file, $content);
-    }
-    $zip->close();
-    header('Content-Type: application/zip');
-    header('Content-Length: ' . filesize($tmpfile));
-    header('Content-Disposition: attachment; filename="varnish_v' . $version . '_conf.zip"');
-    readfile($tmpfile);
-    unlink($tmpfile);
-    exit();
+    if (variable_get('vcaching_enable')) {
+        $vcaching = new VCaching('vcaching_');
+        $vcaching->downloadConf($version);
+    }
 }
 
 /**

comments