--- filebrowser.module.orig	2006-12-05 16:41:06.000000000 -0500
+++ filebrowser.module	2006-12-08 00:14:45.500000000 -0500
@@ -56,7 +56,13 @@ function filebrowser_settings() {
       '#default_value' => variable_get('filebrowser_hide_description_files', 0),
       '#options' => array(t('Show'), t('Hide')),
       '#description' => t('Whether to show or hide description files from directory listings.'),
-    )
+    ),
+    'filebrowser_show_hidden_files' => array(
+      '#type' => 'checkbox',
+      '#title' => t('Display hidden files'),
+      '#default_value' => variable_get('filebrowser_show_hidden_files', 1),
+      '#description' => t('Whether to show or hide the "hidden" files (files that begin with a . such as .htaccess)'),
+    ),
   );
 }
 
@@ -64,7 +70,7 @@ function filebrowser_settings() {
  * Implementation of hook_perm().
  */
 function filebrowser_perm() {
-  return array('access filebrowser');
+  return array('access filebrowser', 'delete filebrowser');
 }
 
 /**
@@ -76,10 +82,56 @@ function filebrowser_menu($may_cache) {
     $items[] = array('path' => 'filebrowser', 'title' => t('filebrowser'),
       'access' => user_access('access filebrowser'), 'callback' => 'filebrowser_page',
       'type' => MENU_SUGGESTED_ITEM);
+    $items[] = array('path' => 'filebrowser/delete', 'title' => t('filebrowser delete'),
+      'access' => user_access('delete filebrowser'), 'callback' => 'filebrowser_delete_page',
+      'type' => MENU_CALLBACK);
   }
   return $items;
 }
 
+function filebrowser_delete_page() {
+  // get the requested path to delete
+  $path = $_GET['path'];
+  
+  // make sure this path is safe
+  // NOTE: it would be nicer to use the drupal functions in file.inc
+  $parts = explode('/', $path);
+  $file = array_pop($parts);
+  $subfolder = implode('/', $parts);
+  $folder = filebrowser_safe_folder($subfolder);
+  $root = variable_get('filebrowser_root', '');
+  $path = "$folder/$file";
+  $partialpath = substr("$path", strlen($root) + 1);
+
+  // save the t() arg array with %path because we're going to need it below
+  $path_placeholder = array('%path' => theme('placeholder', $partialpath));
+
+  if ($_POST['op'] && $_POST['edit']['confirm']) {
+    if (file_exists($path) && is_file($path)) {
+      if (file_delete($path)) {
+        // NOTE: it would be nice to delete the attachments even if the
+        // upload directory root is a subdirectory of the file_directory_path
+        if (file_directory_path() == $root) {
+          db_query("DELETE FROM {files} WHERE filepath='$root/$partialpath'");
+        }
+
+        drupal_set_message(t('File %path deleted', $path_placeholder));
+      } else {
+        drupal_set_message(t('File delete %path Failed', $path_placeholder));
+      }
+    } else {
+      drupal_set_message(t('Can not delete File %path', $path_placeholder));
+    }
+    drupal_goto("filebrowser/$subfolder");
+  }
+  return
+    confirm_form(
+      'filebrowser_confirm_delete',
+      array(),
+      t('Are you sure you want to delete the file %path?', $path_placeholder),
+      'filebrowser/delete');
+}
+
 /**
  * Prints a folder layout
  */
@@ -115,6 +167,7 @@ function filebrowser_page() {
       array('data' => t("Name"), 'field' => 1),
       array('data' => t("Size"), 'field' => 2),
       array('data' => t("Last modified"), 'field' => 3),
+      array('data' => '', 'field' => 4),
     ), filebrowser_get_fileinfo()
   );
   // Set sorting criteria eg. array(the 'field' key's associated value, asc/desc)
@@ -173,7 +226,8 @@ function filebrowser_get_list($subfolder
   global $base_path;
 
   $folder = filebrowser_safe_folder($subfolder);
-  $inroot = ($folder == variable_get('filebrowser_root', ''));
+  $root = variable_get('filebrowser_root', '');
+  $inroot = ($folder == $root);
   
   // Signal error in case of bogus directory name
   if (!(file_exists($folder) && is_dir($folder) && ($dir = opendir($folder)))) {
@@ -223,8 +277,10 @@ function filebrowser_get_list($subfolder
   }
     
   // Build detailed list of files
+  $show_hidden_files = variable_get('filebrowser_show_hidden_files', 1);
   $details = array();
   foreach ($files as $file) {
+    if (!$show_hidden_files && substr($file, 0, 1) == '.') continue;
     $extrainfo = (isset($info[$file]) ? $info[$file] : $emptyinfo);
     // Some real folder or file
     if (!in_array($file, array(".", ".."))) {
@@ -240,12 +296,19 @@ function filebrowser_get_list($subfolder
           $link = "<a href=\"{$base_path}{$completepath}\">$icon $file</a>";
           $size = format_size($stat['size']);
         }
-        $details[] = array_merge(
+        if (is_file($completepath) && user_access('delete filebrowser')) {
+          $path = substr("$folder/$file", strlen($root) + 1);
+          $dlink = l("delete", 'filebrowser/delete', array(), "path=$path");
+        } else {
+          $dlink = '';
+        }
+        $detail = 
           array(
             array('data' => $link, 'class' => 'filename', 'sv' => $file),
             array('data' => $size, 'sv' => ($size ? $stat['size'] : 0)),
-            array('data' => format_interval($age), 'sv' => $age)
-          ), $extrainfo);
+            array('data' => format_interval($age), 'sv' => $age),
+            array('data' => $dlink));
+        $details[] = array_merge($detail, $extrainfo);
       }
     }
     // The special one-up folder not in the root folder
@@ -259,7 +322,8 @@ function filebrowser_get_list($subfolder
       $details[] = array_merge(array(
         array('data' => $link, 'class' => 'filename', 'sv' => $file),
         array('data' => '', 'sv' => 0),
-        array('data' => '', 'sv' => 0)
+        array('data' => '', 'sv' => 0),
+        array('data' => '', 'sv' => 0),
       ), $extrainfo);
     }
   }
