Index: modules/filemanager/filemanager.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/filemanager/filemanager.module,v
retrieving revision 1.4
diff -u -r1.4 filemanager.module
--- modules/filemanager/filemanager.module	17 Sep 2004 02:21:59 -0000	1.4
+++ modules/filemanager/filemanager.module	19 Dec 2004 03:57:29 -0000
@@ -3,7 +3,7 @@
 
 /**
  * @defgroup filemanager File Upload/Download Manager
- *   Functions for modules to use the managed file repository.  Modules using 
+ *   Functions for modules to use the managed file repository.  Modules using
  *   this repository don't have to deal with filenames, directory, size limits,
  *   or creating download URLs.
  *
@@ -22,48 +22,48 @@
  *   Filestore file to create the url for
  * @param $working
  *   If this is true and there is a working copy of the file then a url
- *   to the working copy will be returned, otherwise the url will point to 
+ *   to the working copy will be returned, otherwise the url will point to
  *   the active copy.
  * @param $absolute
  *   Whether to force the output to be an absolute url (beginning with http:).
  *   Useful for urls that will be displayed outside the site, such as in an RSS feed.
  * @return
- *   a string containing the url to the given path. 
+ *   a string containing the url to the given path.
  */
 function filemanager_url($file, $working = FALSE, $absolute = FALSE) {
   global $base_url;
-  
+
   // Load file info if we only got a $fid
   $file = filemanager_get_file_info($file);
-  
+
   $subdir = ($file->working && $working) ? 'working' : 'active';
-  
+
   if ($file->private) {
     return url('filemanager/' . $subdir, 'fid=' . $file->fid, NULL, $absolute);
-  } 
+  }
   else {
-    return variable_get('filemanager_public_url', $base_url . '/' . variable_get('filemanger_public_path','files')) . "/$subdir/$file->directory/$file->filename";
-  }  
+    return variable_get('filemanager_public_url', $base_url . '/' . variable_get('filemanager_public_path','files')) . "/$subdir/$file->directory/$file->filename";
+  }
 }
 
 /**
  * Create a link to download a file in the filestore.
  *
  * @param $text
- *   The text to be enclosed with the anchor tag. 
+ *   The text to be enclosed with the anchor tag.
  * @param $file
  *   Filestore file to create the url for
  * @param $working
  *   If this is true and there is a working copy of the file then a link
- *   to the working copy will be returned, otherwise the link will point to 
+ *   to the working copy will be returned, otherwise the link will point to
  *   the active copy.
  * @param $attributes
- *   An associative array of HTML attributes to apply to the anchor tag. 
+ *   An associative array of HTML attributes to apply to the anchor tag.
  * @param $absolute
  *   Whether to force the output to be an absolute link (beginning with http:).
  *   Useful for links that will be displayed outside the site, such as in an RSS feed.
  * @return
- *   an HTML string containing a link to the given path. 
+ *   an HTML string containing a link to the given path.
  */
 function filemanager_l($text, $file, $working = FALSE, $attributes = array(), $absolute = FALSE) {
   return '<a href="' . filemanager_url($file, $working, $absolute) . '"' . drupal_attributes($attributes) . '>' . $text . '</a>';
@@ -124,7 +124,7 @@
  * Adds a file into the repository as a working copy
  *
  * @param $path
- *   Path to the file to be added to the 
+ *   Path to the file to be added to the
  * @param $area
  *   Name of the area where the file resides which will usually be the name of the module
  *   managing the file. Ignored if over if you supply a file to overwrite
@@ -140,25 +140,25 @@
  *   Filestore file which this upload should replace
  */
 function filemanager_add_file($area, $path, $filename, $mimetype = 'application/unknown', $remove = TRUE, $private = FALSE, $file = FALSE) {
-   
+
   $lock_file = variable_get('filemanager_private_path', 'private') . '/' . 'filemanager.lck';
   $size = filesize($path);
 
-  if ($file === FALSE) {  
-    
+  if ($file === FALSE) {
+
     if ($area == '') {
       $area = 'general';
     }
-  
+
     // This is a net new file find a directory for it and setup the object
     $file->fid = db_next_id('file_fid');
     $file->area = $area;
     $file->filename = $filename;
     $file->active = FALSE;
-    $file->working = FALSE;    
+    $file->working = FALSE;
     $file->private = $private;
-    $file->size = size;
-    
+    $file->size = $size;
+
     // Find a directory that is not already full and does not contain our files
     $file->directory = 0;
     $directories = db_query("SELECT directory, count(1) filecount FROM file WHERE private = '%s' GROUP BY directory ORDER BY directory ASC", $private);
@@ -205,34 +205,34 @@
     drupal_set_message(t('Filestore add failed: Working space limit has been reached.'), 'error');
     return FALSE;
   }
-  
-  // Verify working directory exists  
+
+  // Verify working directory exists
   filemanager_create_directory(filemanager_create_directory_path($file->private, TRUE));
   filemanager_create_directory(filemanager_create_directory_path($file->private, TRUE, $file->directory));
-  
+
   // Move upload file to new location and name
   if (file_move($path, filemanager_create_path($file, TRUE), FILE_EXISTS_ERROR)) {
-    
+
     $file->working = TRUE;
     $file->mimetype = $mimetype;
-    
+
     // Save database record
     if ($update) {
       db_query("UPDATE {file} SET working='%s' WHERE fid=%d", $file->working, $file->fid);
-    } 
+    }
     else {
       db_query("INSERT INTO {file} (fid, area, directory, filename, mimetype, size, active, working, private) VALUES (%d,'%s',%d,'%s','%s',%d,'%s','%s','%s')",
-               $file->fid, $file->area, $file->directory, $file->filename, $file->mimetype, $file->size, $file->active, $file->working, $file->private);  
+               $file->fid, $file->area, $file->directory, $file->filename, $file->mimetype, $file->size, $file->active, $file->working, $file->private);
     }
-    
+
     if ($remove) {
       file_delete($path);
     }
-    
+
     return $file;
-    
+
   }
-  
+
   return FALSE;
 }
 
@@ -256,13 +256,13 @@
   foreach($files as $file) {
     $size += filesize($file->$filename);
   }
-  
+
   $files = file_scan_directory(filemanager_create_directory_path(FALSE, TRUE), '.*');
   foreach($files as $file) {
     $size += filesize($file->$filename);
   }
-  
-  return $size;  
+
+  return $size;
 }
 
 /**
@@ -290,7 +290,7 @@
  * Returns a filestore object containing information about a given file.
  * Passing in a filestore object will just pass the same object back out.
  *
- * @param $file 
+ * @param $file
  *   File id which you want information about.
  */
 function filemanager_get_file_info($file) {
@@ -304,30 +304,30 @@
 /**
  * Promotes a working copy of a file to the active copy
  *
- * @param $file 
+ * @param $file
  *   File object or file id you want to promote
  * @return
  *    Updated $file object for promoted file
  */
 function filemanager_promote_working($file) {
   $file = filemanager_get_file_info($file);
-  
+
   if ($file->working) {
     $size = filesize(filemanager_create_path($file, TRUE));
-    
+
     $area = filemanager_get_area_info($file->area);
     if ($area->sizelimit > -1 && ($size + $area->size) > ($area->sizelimit * 1024 * 1024)) {
       drupal_set_message(t('File promotion failed: area out of space'), 'error');
       return FALSE;
-    }  
-    
+    }
+
     $maxsize = variable_get('filemanager_max_size', '400');
-    if ($maxsize > -1 && ($size + filemanger_get_size()) > ($maxsize * 1024 * 1024)) {
+    if ($maxsize > -1 && ($size + filemanager_get_size()) > ($maxsize * 1024 * 1024)) {
       drupal_set_message(t('File promotion failed: out of space'), 'error');
       return FALSE;
     }
 
-    // Verify working directory exists  
+    // Verify working directory exists
     $activedir = filemanager_create_directory_path($file->private, FALSE);
     if (!file_exists($activedir)) {
       mkdir($activedir);
@@ -336,7 +336,7 @@
     if (!file_exists($filedir)) {
       mkdir($filedir);
     }
-  
+
     if (file_move(filemanager_create_path($file, TRUE), filemanager_create_path($file, FALSE), FILE_EXISTS_ERROR)) {
       $file->working = FALSE;
       $file->active = TRUE;
@@ -351,12 +351,12 @@
 /**
  * Purge a working file from the repository
  *
- * @param $file 
+ * @param $file
  *   File object or file id you want to purge the working file for
  */
 function filemanager_purge_working($file) {
   $file = filemanager_get_file_info($file);
-  
+
   file_delete(filemanager_create_path($file, TRUE));
   if ($file->active) {
     db_query("UPDATE {file} SET working = '%s' WHERE fid = %d", FALSE, $file->fid);
@@ -369,7 +369,7 @@
 /**
  * Removes a file from a repository
  *
- * @param $file 
+ * @param $file
  *   File object or file id you want to promote
  */
 function filemanager_delete($file) {
@@ -412,70 +412,77 @@
 }
 
 /**
- * Transfers a file to the client after calling modules to find out 
+ * Transfers a file to the client after calling modules to find out
  * if a file is accessible for a given user.  This function
  * is here to support legacy private downloads
  *
- * @param $file 
+ * @param $file
  *   File object or file id you want to promote
  */
 function filemanager_transfer($file, $working) {
-  
-  $file = filemanager_get_file_info($file);  
+
+  $file = filemanager_get_file_info($file);
   $filepath = filemanager_create_path($file, $working);
-  
+
   if ($file->private) {
-  
+
     if (file_check_location($filepath, variable_get('filemanager_private_path','private')) && file_exists($filepath)) {
-      
+
       $list = module_list();
       foreach ($list as $module) {
         $headers = module_invoke($module, 'filemanager_download', $file);
-        
+
         if ($headers === FALSE) {
           drupal_access_denied();
         }
-      
+
         elseif ($headers === TRUE) {
           file_transfer($filepath, array('Content-Type: '. $file->mimetype, 'Content-Length: '. filesize($filepath), 'Content-Disposition: filename=' . $file->filename));
         }
-  
+
         elseif (is_array($headers)) {
           file_transfer($filepath, $headers);
-        }      
+        }
       }
-      
+
       // Since no modules responded check to see if this is a general area file
       // and allow download if so.
       if ($file->area == 'general') {
-        file_transfer($filepath, array('Content-Type: '. $file->mimetype, 'Content-Length: '. filesize($filepath), 'Content-Disposition: filename=' . $file->filename));      
+        file_transfer($filepath, array('Content-Type: '. $file->mimetype, 'Content-Length: '. filesize($filepath), 'Content-Disposition: filename=' . $file->filename));
       }
-    }  
-    
+    }
+
     drupal_not_found();
   }
   else {
     // It's a public file so no auth check is required.
-    file_transfer($filepath, array('Content-Type: '. $file->mimetype, 'Content-Length: '. filesize($filepath), 'Content-Disposition: filename=' . $file->filename));      
+    file_transfer($filepath, array('Content-Type: '. $file->mimetype, 'Content-Length: '. filesize($filepath), 'Content-Disposition: filename=' . $file->filename));
   }
 }
 
 /**
  * @}
  */
- 
-function filemanager_menu() {
+
+function filemanager_menu($may_cache) {
   $items = array();
-  $items[] = array('path' => 'filemanager/active', 'title' => t('file download'),
-    'callback' => 'filemanager_download_active',
-    'access' => TRUE,
-    'type' => MENU_CALLBACK);
-  $items[] = array('path' => 'filemanager/working', 'title' => t('file download'),
-    'callback' => 'filemanager_download_working',
-    'access' => TRUE,
-    'type' => MENU_CALLBACK);
+
+  if ($may_cache) {
+    $items[] = array('path' => 'filemanager/active', 'title' => t('file download'),
+      'callback' => 'filemanager_download_active',
+      'access' => TRUE,
+      'type' => MENU_CALLBACK
+    );
+    $items[] = array('path' => 'filemanager/working', 'title' => t('file download'),
+      'callback' => 'filemanager_download_working',
+      'access' => TRUE,
+      'type' => MENU_CALLBACK
+    );
+  }
+
+  return $items;
 }
- 
+
 /**
  * Menu callback to download the latest active file
  */
@@ -512,31 +519,31 @@
 
 /**
  * Displays filemanager admin screen
- */ 
+ */
 function filemanager_settings() {
   global $base_url;
-  
+
   $public_directory_path = variable_get('filemanager_public_path', 'files');
   if (!file_check_directory($public_directory_path)) {
     form_set_error('filemanager_public_path', t( "the directory '%name' does not exist, or is not writable.", array('%name' => $public_directory_path)));
-  }  
-  
-  $output = form_textfield(t('Public file system path'), 'filemanager_public_path', $public_directory_path, 70, 255, t('A file system path where public files will be stored. This directory has to exist and be writable by Drupal. This directory has to be accessible over the web. Changing this location after the site has been in use will cause problems so only change this setting on an existing site if you know what you are doing.')); 
+  }
+
+  $output = form_textfield(t('Public file system path'), 'filemanager_public_path', $public_directory_path, 70, 255, t('A file system path where public files will be stored. This directory has to exist and be writable by Drupal. This directory has to be accessible over the web. Changing this location after the site has been in use will cause problems so only change this setting on an existing site if you know what you are doing.'));
 
   $output .= form_textfield(t('Public file system url'), 'filemanager_public_url', $base_url . '/' . $public_directory_path, 70, 255, t('Base url that points to the public files directory.'));
 
   $private_directory_path = variable_get('filemanager_private_path', 'private');
   if (!file_check_directory($private_directory_path)) {
     form_set_error('filemanager_private_path', t( "the directory '%name' does not exist, or is not writable.", array('%name' => $private_directory_path)));
-  }  
+  }
 
-  $output .= form_textfield(t('Private file system path'), 'filemanager_private_path', $private_directory_path, 70, 255, t('A file system path where private access controlled files will be stored. This directory has to exist and be writable by Drupal. This directory should not be accessible over the web. Changing this location after the site has been in use will cause problems so only change this setting on an existing site if you know what you are doing.')); 
+  $output .= form_textfield(t('Private file system path'), 'filemanager_private_path', $private_directory_path, 70, 255, t('A file system path where private access controlled files will be stored. This directory has to exist and be writable by Drupal. This directory should not be accessible over the web. Changing this location after the site has been in use will cause problems so only change this setting on an existing site if you know what you are doing.'));
 
    $output .= form_textfield(t('Maximum files per directory'), 'filemanager_max_filecount', variable_get('filemanager_max_filecount', '200'), 6, 10, t('Maximum number of files to put in each directory.'));
 
   $output .= form_textfield(t('Working size limit'), 'filemanager_working_sizelimit', variable_get('filemanager_working_sizelimit', '10'), 6, 10, t('Maximum total size in megabytes for the working storage directory. Enter -1 for unlimited.'));
 
-  $output .= form_textfield(t('Maximum working age'), 'filemanager_working_maxage', variable_get('filemanager_working_maxage', '120'), 6, 10, t('Maximum amoung of time in minutes that an attachment is allowed to live in working storage. Enter -1 for unlimited.'));  
+  $output .= form_textfield(t('Maximum working age'), 'filemanager_working_maxage', variable_get('filemanager_working_maxage', '120'), 6, 10, t('Maximum amoung of time in minutes that an attachment is allowed to live in working storage. Enter -1 for unlimited.'));
 
   $output .= form_textfield(t('Maximum size limit'), 'filemanager_max_size', variable_get('filemnager_max_size', '400'), 6, 10, t('Maximum amount of disk space that can be consumed by all files. Enter in megabytes.'));
 
@@ -547,7 +554,7 @@
   $output .= form_item(t('File areas'),  theme_table($header, $rows));
   return $output;
 }
- 
+
 /**
  * Creates a directory if it does not already exist.
  */
@@ -569,5 +576,5 @@
     rmdir($directory);
   }
 }
- 
+
 ?>
Index: modules/filemanager/filemanager.mysql
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/filemanager/filemanager.mysql,v
retrieving revision 1.1
diff -u -r1.1 filemanager.mysql
--- modules/filemanager/filemanager.mysql	21 Aug 2004 15:21:23 -0000	1.1
+++ modules/filemanager/filemanager.mysql	19 Dec 2004 04:14:17 -0000
@@ -1,5 +1,5 @@
 --
--- Structure for table 'files'
+-- Structure for table 'file'
 --
 
 CREATE TABLE file (
