Firstly, can I say what a great module this is, I just have a couple of requests for features (I'll submit them seperately for tidiness though.

After using the module for a little while, I notice that the default file extension whitelist for fileshare is hard coded into the module itself rather than taking the setting from Drupal's built in extension whitelist.

Would it be possible to modify the module to use Drupal's built in whitelist as a default value?

Comments

deadman’s picture

oops, just realised this should probably be posted in feature requests - apologies.

JamieR’s picture

That's a good idea... don't know why I didn't do that in the first place... :)
I haven't had much time to work on the module... but there are a lot of great ideas and patches that I need to incorporate... hopefully soon!

Thanks, Jamie.

jonathan_hunt’s picture

I patched my instance of fileshare along the following lines:

  • Defined master list of accepted extensions as constant.
  • Use upload module's extension list if defined.
  • Display allowed extensions in upload form description.
  • Changed placeholder in t() to @ instead of % to save doubling of 'em' tags
Index: modules/fileshare/fileshare.module
===================================================================
--- modules/fileshare/fileshare.module  (revision 4048)
+++ modules/fileshare/fileshare.module  (working copy)
@@ -17,6 +17,8 @@
  *  Also be sure to check that your temp directory has enough space.
  */
 
+define(EXTENSIONS_DEFAULT, 'jpg jpeg gif png txt html htm doc xls pdf ppt pps ai psd');
+
 /**
  * Implementation of hook_node_info().
  *
@@ -211,10 +213,10 @@
   $form['file_filter']['_whitelist'] = array(
     '#type' => 'textfield',
     '#title' => t('File extension whitelist'),
-    '#default_value' => ($new) ? 'jpg jpeg gif png txt html htm doc xls pdf ppt pps ai psd' : $node->_whitelist,
+    '#default_value' => ($new) ? variable_get('upload_extensions_default', EXTENSIONS_DEFAULT) : $node->_whitelist,
     '#maxlength' => 255,
     '#description' => t("File extensions that are allowed to be uploaded. Separate extensions with a space and do not include the leading dot. 
-      If left blank the default 'jpg jpeg gif png txt html htm doc xls pdf ppt pps ai psd' will be applied.")
+      If left blank the default '@extensions' will be applied.", array('@extensions' => variable_get('upload_extensions_default', EXTENSIONS_DEFAULT) ))
   );
   $form['file_filter']['_private'] = array(
     '#type' => 'checkbox',
@@ -409,9 +411,12 @@
     '#title' => t('Upload a file to target directory'),
     '#size' => 30,
     '#description' => t('Click "Browse..." to select a file to upload into the target folder.
-      <em>%upload_max maximum file size.</em>', 
-      array('%upload_max' => ini_get('upload_max_filesize'))),
-      );
+      <em>@upload_max maximum file size.</em> Allowed file extensions: @extensions', 
+      array(
+        '@upload_max' => ini_get('upload_max_filesize'),
+        '@extensions' => variable_get('upload_extensions_default', EXTENSIONS_DEFAULT)
+      )),
+    );
   $form['file']['submit'] = array('#type' => 'submit', '#value' => t('Upload'));
   $form['file']['dirname'] = array(
     '#type' => 'textfield',
@@ -451,7 +456,9 @@
       } else {
         // Validate file against whitelist.
         $node = node_load($form_values['nid']);
-        if ($node->_whitelist == '') $node->_whitelist = 'jpg jpeg gif png txt html htm doc xls pdf ppt pps ai psd';
+        if ($node->_whitelist == '') {
+          $node->_whitelist = variable_get('upload_extensions_default', EXTENSIONS_DEFAULT);
+        }
         $regex = '/\.('. ereg_replace(' +', '|', preg_quote($node->_whitelist)) .')$/i';
         if (!preg_match($regex, $upload)) {
           form_set_error('upload', t('The selected file <em>%name</em> can not be attached to this post, because it is only possible to attach files with the following extensions: %files-allowed.',