From 5e4807cbf25415caf0dfeea82b221313eddd0bc8 Mon Sep 17 00:00:00 2001
From: Avi Goldberg <aviindub@gmail.com>
Date: Tue, 12 Nov 2013 16:09:08 -0800
Subject: [PATCH 1/3] help drupal preserve MIME type in metadata by adding the
 original file's extension to the temp file name.

---
 advagg.missing.inc | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/advagg.missing.inc b/advagg.missing.inc
index 352a580..7abf095 100644
--- a/advagg.missing.inc
+++ b/advagg.missing.inc
@@ -649,6 +649,9 @@ function advagg_save_data($uri, $data, $overwrite = FALSE) {
 
   // Get a temporary filename in the destination directory.
   $temporary_file = drupal_tempnam(drupal_dirname($uri), 'file');
+  // Get the extension of the original filename and append it to the temp
+  // file name. This preserves the mime type in different environments.
+  $temporary_file .= "." . pathinfo($uri, PATHINFO_EXTENSION);
   // Save to temporary filename in the destination directory.
   $filepath = file_unmanaged_save_data($data, $temporary_file, FILE_EXISTS_REPLACE);
 
-- 
1.8.4.msysgit.0


From 1a8fa87c411c11d6452f0e5947e2033721812483 Mon Sep 17 00:00:00 2001
From: Avi Goldberg <aviindub@gmail.com>
Date: Tue, 12 Nov 2013 16:10:09 -0800
Subject: [PATCH 2/3] adds an admin setting for the stream wrapper to use when
 storing aggregate files, and implements the use of that setting.

---
 advagg.admin.inc |  7 ++++++-
 advagg.module    | 12 ++++++++++--
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/advagg.admin.inc b/advagg.admin.inc
index 2899707..8b9a09a 100644
--- a/advagg.admin.inc
+++ b/advagg.admin.inc
@@ -107,7 +107,12 @@ function advagg_admin_settings_form($form, $form_state) {
     '#default_value' => variable_get('advagg_js_fix_type', ADVAGG_JS_FIX_TYPE),
     '#description' => t('If type is external but does not start with http, https, or // change it to be type file. If type is file but it starts with http, https, or // change type to be external.'),
   );
-
+  $form['global']['advagg_stream_wrapper'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Stream wrapper to use for storing aggregates'),
+    '#default_value' => variable_get('advagg_stream_wrapper', ADVAGG_DEFAULT_STREAM_WRAPPER),
+    '#description' => t('Change this to use a stream wrapper other than the default public wrapper. Use with caution. The value entered here should be just the stream wrapper prefix, without :// (for example, "public")'),
+  );
   // Clear the cache bins on submit.
   $form['#submit'][] = 'advagg_admin_settings_form_submit';
 
diff --git a/advagg.module b/advagg.module
index 3829c5d..cc2dccb 100644
--- a/advagg.module
+++ b/advagg.module
@@ -76,6 +76,11 @@ define('ADVAGG_CSS_FIX_TYPE', TRUE);
  */
 define('ADVAGG_HTACCESS_CHECK_GENERATE', TRUE);
 
+/**
+ * Default stream wrapper is the usual 'public'  
+ */
+define('ADVAGG_DEFAULT_STREAM_WRAPPER', 'public');
+
 // Core hook implementations.
 /**
  * Implements hook_hook_info().
@@ -1462,8 +1467,11 @@ function advagg_get_root_files_dir() {
 
   // Make sure directories are available and writable.
   if (empty($css_paths) || empty($js_paths)) {
-    $css_paths[0] = 'public://advagg_css';
-    $js_paths[0] = 'public://advagg_js';
+
+    // use the file stream wrapper specified in settings
+    $wrapper = variable_get('advagg_stream_wrapper', ADVAGG_DEFAULT_STREAM_WRAPPER);
+    $css_paths[0] = "$wrapper://advagg_css";
+    $js_paths[0] = "$wrapper://advagg_js";
 
     file_prepare_directory($css_paths[0], FILE_CREATE_DIRECTORY);
     file_prepare_directory($js_paths[0], FILE_CREATE_DIRECTORY);
-- 
1.8.4.msysgit.0


From 4e789b4fc06cb20a96e37d0d2133b02ffb8d94c2 Mon Sep 17 00:00:00 2001
From: Avi Goldberg <aviindub@gmail.com>
Date: Mon, 25 Nov 2013 11:20:34 -0800
Subject: [PATCH 3/3] textfield instead of checkbox for a text value.

---
 advagg.admin.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/advagg.admin.inc b/advagg.admin.inc
index 03972cc..72a352a 100644
--- a/advagg.admin.inc
+++ b/advagg.admin.inc
@@ -108,7 +108,7 @@ function advagg_admin_settings_form($form, $form_state) {
     '#description' => t('If type is external but does not start with http, https, or // change it to be type file. If type is file but it starts with http, https, or // change type to be external.'),
   );
   $form['global']['advagg_stream_wrapper'] = array(
-    '#type' => 'checkbox',
+    '#type' => 'textfield',
     '#title' => t('Stream wrapper to use for storing aggregates'),
     '#default_value' => variable_get('advagg_stream_wrapper', ADVAGG_DEFAULT_STREAM_WRAPPER),
     '#description' => t('Change this to use a stream wrapper other than the default public wrapper. Use with caution. The value entered here should be just the stream wrapper prefix, without :// (for example, "public")'),
-- 
1.8.4.msysgit.0

