diff -r 950b3cbd8e19 filebrowser.module
--- a/filebrowser.module	Tue Mar 18 11:21:47 2008 +0300
+++ b/filebrowser.module	Tue Mar 18 11:52:23 2008 +0300
@@ -3,7 +3,7 @@
 
 function filebrowser_menu() {
   $items = array();
-  
+
   // TODO: Query below causes error on module uninstall
   $qry = db_query('SELECT path, location FROM {filebrowser} WHERE 1');
   while ($o = db_fetch_object($qry)) {
@@ -14,7 +14,7 @@ function filebrowser_menu() {
       'type' => MENU_CALLBACK
     );
   }
-  
+
   $items['admin/settings/filebrowser'] = array(
     'title' => 'Filebrowser',
     'page callback' => 'drupal_get_form',
@@ -22,30 +22,30 @@ function filebrowser_menu() {
     'description' => t('Expose file system directories to users'),
     'type' => MENU_NORMAL_ITEM
   );
-  
+
   return $items;
 }
 
 function filebrowser_page($path) {
-  
+
   // Grab info for the listing we're viewing
   $listing = db_fetch_object(db_query('SELECT location, can_explore FROM {filebrowser} WHERE path = "%s"', $path));
   $listing->can_explore = (bool)(int)$listing->can_explore;
   $listing->path = $path;
-  
+
   // Grab full Drupal path
   $curr_dir = substr($_GET['q'], strpos($full_path, $root_dir));
   $curr_dir = str_replace($listing->path, $listing->location, $curr_dir);
-  
+
   // Are we in a subdirectory?
   $is_subdir = ($listing->location != $curr_dir);
-  
+
   // If we shouldn't be in a subdir, redirect to root_dir
   if ($is_subdir && !$listing->can_explore) {
     drupal_set_message(t('You\'re not allowed to view subdirectories.'), 'error');
     drupal_goto($listing->path);
   }
-  
+
   // Reflect current directory in title
   drupal_set_title(t('Displaying contents of directory %dir', array('%dir' => $curr_dir)));
 
@@ -54,6 +54,10 @@ function filebrowser_page($path) {
   $total_size = 0;
   if (is_dir($dir) && $dh = opendir($dir)) {
     while (($file = readdir($dh)) !== false && is_readable($dir .'/'. $file)) {
+      // Skip .htaccess file from being displayed
+      if ($file == '.htaccess') {
+        continue;
+      }
       $full_path = $dir .'/'. $file;
       if (is_file($full_path)) {
         $f_size = filesize($full_path);
@@ -66,14 +70,15 @@ function filebrowser_page($path) {
           $dirs[] = $file;
         }
       }
-        
+
     }
     closedir($dh);
   }
-  
+
   if ($listing->can_explore) {
+    rsort($dirs);
     foreach ($dirs as $dir) {
-  
+
       // Always remove '.'
       if ($dir == '.') {
         continue;
@@ -83,31 +88,31 @@ function filebrowser_page($path) {
       if (!$is_subdir && $dir == '..') {
         continue;
       }
-      
+
       $dir_row = array(
         l($dir, $_GET['q'] .'/'. $dir),
         t('Directory')
       );
-      
+
       array_unshift($files, $dir_row);
     }
   }
-  
+
   $output = theme('table', array(t('Name'), t('Size')), $files);
-  
-  $output .= '<p>'. t('Contains @fc files totaling @ds in size', array('@fc' => count($files), '@ds' => format_size($total_size))) .'</p>';  
-  
+
+  $output .= '<p>'. t('Contains @fc files totaling @ds in size', array('@fc' => count($files), '@ds' => format_size($total_size))) .'</p>';
+
   return $output;
 }
 
 function filebrowser_admin_settings() {
   $form = array();
-  
+
   $form['listings'] = array(
     '#type' => 'fieldset',
     '#title' => t('Directory listings')
   );
-  
+
   // Insert listings table markup
   $qry = db_query('SELECT path, location, can_explore FROM {filebrowser} WHERE 1');
   while ($o = db_fetch_object($qry)) {
@@ -125,24 +130,24 @@ function filebrowser_admin_settings() {
     );
     $paths[$o->path] = '';
   }
-  
+
   $form['listing_checks'] = array(
     '#type' => 'checkboxes',
     '#options' => $paths
   );
-  
+
   $form['listings']['submit'] = array(
     '#type' => 'submit',
     '#value' => t('Update directory listings'),
     '#weight' => 10,
     '#submit' => array('filebrowser_admin_settings_submit_update')
   );
-  
+
   $form['new_listing'] = array(
     '#type' => 'fieldset',
     '#title' => t('Add listing')
   );
-  
+
   // Insert options to enter a new listing
   $form['new_listing']['path'] = array(
     '#type' => 'textfield',
@@ -150,28 +155,28 @@ function filebrowser_admin_settings() {
     '#description' => t('Path that users can view this directory listing at.'),
     '#required' => true
   );
-  
+
   $form['new_listing']['location'] = array(
     '#type' => 'textfield',
     '#title' => t('File system directory'),
     '#description' => t('File system path to a directory.'),
     '#required' => true
   );
-  
+
   $form['new_listing']['can_explore'] = array(
     '#type' => 'checkbox',
     '#title' => t('Do you want to allow exploring subdirectories?')
   );
-  
+
   $form['new_listing']['submit'] = array(
     '#type' => 'submit',
     '#value' => t('Add listing'),
     '#validate' => array('filebrowser_admin_settings_validate_add'),
     '#submit' => array('filebrowser_admin_settings_submit_add')
   );
-  
+
   $form['#after_build'] = array('filebrowser_strip_requirements');
-  
+
   return $form;
 }
 
@@ -186,14 +191,14 @@ function filebrowser_admin_settings_vali
 function filebrowser_admin_settings_validate_add($form, &$form_state) {
   $path = $form_state['values']['path'];
   $location = $form_state['values']['location'];
-  
+
   // Verify the Drupal path
   // Check that the path isn't already in use
   $path_exists = db_result(db_query('SELECT COUNT(1) FROM {menu_router} mr, {menu_links} ml WHERE mr.path = "%s" OR ml.link_path = "%s"', $path, $path));
   if ($path_exists) {
     form_set_error('path', t('You must specify an unused Drupal path'));
-  } 
-  
+  }
+
   // Verify the file system location
   // Check that it's a directory
   if (!is_dir($location)) {
@@ -208,12 +213,12 @@ function filebrowser_admin_settings_subm
 function filebrowser_admin_settings_submit_add($form, &$form_state) {
   db_query('INSERT INTO {filebrowser} (path, location, can_explore) VALUES ("%s", "%s", %d)',
     $form_state['values']['path'], $form_state['values']['location'], $form_state['values']['can_explore']);
-  
+
   // Make sure our entries are deleted from the menu system also
   // TODO: See if there's a lighter-weight function to update the menu
   // for just this module
   menu_rebuild();
-  
+
   drupal_set_message(t('Your directory listing has been added'));
 }
 
@@ -223,10 +228,10 @@ function filebrowser_admin_settings_subm
       db_query('DELETE FROM {filebrowser} WHERE path = "%s"', $check);
     }
   }
-  
+
   // Make sure our entries are deleted from the menu system also
   menu_rebuild();
-  
+
   drupal_set_message(t('Your directory listing has been updated'));
 }
 
@@ -244,7 +249,7 @@ function theme_filebrowser_admin_setting
     $row[] = drupal_render($form['listing_checks'][$key]);
     $rows[] = $row;
   }
-  
+
   $headers = array(
     t('Path'),
     t('Location'),
@@ -253,13 +258,13 @@ function theme_filebrowser_admin_setting
     t('Explorable'),
     t('Delete')
   );
-  
+
   $form['listings']['listings'] = array(
     '#value' => theme('table', $headers, $rows)
   );
-  
+
   $output .= drupal_render($form); // Process any other fields and display them
-  
+
   return $output;
 }
 
@@ -301,6 +306,6 @@ function _filebrowser_dir_stats($dir) {
     }
     closedir($dh);
   }
-  
+
   return array('file_count' => $file_count, 'total_size' => $total_size);
 }
