? filefield-split.patch
? filefield-tokens.patch
Index: filefield.inc
===================================================================
RCS file: filefield.inc
diff -N filefield.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ filefield.inc	28 Feb 2007 16:32:11 -0000
@@ -0,0 +1,105 @@
+<?php
+// $Id$
+
+/**
+ * insert a file into the database.
+ * @param $node
+ *    node object file will be associated with.
+ * @param $file
+ *    file to be inserted, passed by reference since fid should be attached.
+ *    
+ */
+function filefield_file_insert($node, &$file, $field) {
+  $fieldname = $field['field_name'];
+  if ($file = file_save_upload((object)$file, file_directory_path() . '/'.$file['filename'])) {
+    $file = (array)$file;
+    $file['fid'] = db_next_id('{files}_fid');
+    db_query('INSERT into {files} (fid, nid, filename, filepath, filemime, filesize)  
+             VALUES (%d, %d, "%s","%s","%s",%d)',
+            $file['fid'], $node->nid, $file['filename'], $file['filepath'], $file['filemime'], $file['filesize']);
+    return (array)$file;
+  }
+  else {
+    // Include file name in upload error.
+    form_set_error(NULL, t('file upload was unsuccessful.'));
+    return FALSE;
+  }
+}
+
+
+/**
+ * update the file record if necessary
+ * @param $node
+ * @param $file
+ * @param $field
+ */
+function filefield_file_update($node, &$file, $field) {
+  $file = (array)$file; 
+  if ($file['remove'] == TRUE) {
+     _filefield_file_delete($file, $field['field_name']);
+     // should I return an array here instead as imagefield does, or is that a bug in 
+     // in imagefield. I remember I was working on a content.module patch that would
+     // delete multivalue fields whose value was NULL. Maybe a leftover.
+     return NULL;
+  }
+  if ($file['fid'] == 'upload') {  
+    return filefield_file_insert($node, $file, $field);
+  }
+  else {
+    // if fid is not numeric here we should complain.
+    // else we update the file table.  
+  }
+  return $file;
+}
+
+function filefield_file_delete($file, $fieldname) {
+  if (is_numeric($file['fid'])) {
+    db_query('DELETE FROM {files} WHERE fid = %d', $file['fid']);
+  }
+  else {
+    unset($_SESSION['filefield'][$fieldname][$file['sessionid']]);
+  }
+  return file_delete($file['filepath']);
+}
+
+function filefield_file_load($fid = NULL) {
+  if (isset($fid)) { 
+    if (is_numeric($fid)) {
+      $result = db_query('SELECT * FROM {files} WHERE fid = %d', $fid);
+      $file = db_fetch_array($result);
+      return ($file) ? $file : array();
+    }
+  }
+  return array();
+}
+
+if (!function_exists('upload_file_download')) {
+  function filefield_file_download($file) {
+    $file = file_create_path($file);
+    $result = db_query("SELECT f.* FROM {files} f WHERE filepath = '%s'", $file);
+    if ($file = db_fetch_object($result)) {
+      if (user_access('view uploaded files')) {
+        $node = node_load($file->nid);
+        if (node_access('view', $node)) {
+          $name = mime_header_encode($file->filename);
+          $type = mime_header_encode($file->filemime);
+          // Serve images and text inline for the browser to display rather than download.
+          $disposition = ereg('^(text/|image/)', $file->filemime) ? 'inline' : 'attachment';
+          return array(
+            'Content-Type: '. $type .'; name='. $name,
+            'Content-Length: '. $file->filesize,
+            'Content-Disposition: '. $disposition .'; filename='. $name,
+            'Cache-Control: private'
+          );
+        }
+        else {
+          return -1; 
+        }
+      }   
+      else {
+        return -1; 
+      }   
+    }   
+  }
+
+}
Index: filefield.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/filefield/filefield.module,v
retrieving revision 1.16
diff -u -r1.16 filefield.module
--- filefield.module	1 Feb 2007 08:50:17 -0000	1.16
+++ filefield.module	28 Feb 2007 16:32:12 -0000
@@ -84,60 +84,10 @@
 }
 
 /**
- * insert a file into the database.
- * @param $node
- *    node object file will be associated with.
- * @param $file
- *    file to be inserted, passed by reference since fid should be attached.
- *    
- */
-function filefield_file_insert($node, &$file, $field) {
-  $fieldname = $field['field_name'];
-  if ($file = file_save_upload((object)$file, file_directory_path() . '/'.$file['filename'])) {
-    $file = (array)$file;
-    $file['fid'] = db_next_id('{files}_fid');
-    db_query('INSERT into {files} (fid, nid, filename, filepath, filemime, filesize)  
-             VALUES (%d, %d, "%s","%s","%s",%d)',
-            $file['fid'], $node->nid, $file['filename'], $file['filepath'], $file['filemime'], $file['filesize']);
-    return (array)$file;
-  }
-  else {
-    // Include file name in upload error.
-    form_set_error(NULL, t('file upload was unsuccessful.'));
-    return FALSE;
-  }
-}
-
-
-/**
- * update the file record if necessary
- * @param $node
- * @param $file
- * @param $field
- */
-function filefield_file_update($node, &$file, $field) {
-  $file = (array)$file; 
-  if ($file['remove'] == TRUE) {
-     _filefield_file_delete($file, $field['field_name']);
-     // should I return an array here instead as imagefield does, or is that a bug in 
-     // in imagefield. I remember I was working on a content.module patch that would
-     // delete multivalue fields whose value was NULL. Maybe a leftover.
-     return NULL;
-  }
-  if ($file['fid'] == 'upload') {  
-    return filefield_file_insert($node, $file, $field);
-  }
-  else {
-    // if fid is not numeric here we should complain.
-    // else we update the file table.  
-  }
-  return $file;
-}
-
-/**
  * Implementation of hook_field().
  */
 function filefield_field($op, $node, $field, &$node_field, $teaser, $page) {
+	require_once(drupal_get_path('module', 'filefield') . '/filefield.inc');
   $fieldname = $field['field_name'];
   switch ($op) {
     case 'load':
@@ -146,7 +96,7 @@
         $values = array();
         foreach ($node_field as $delta => $file) {
           if (!empty($file)) {
-            $node_field[$delta]  = array_merge($node_field[$delta], _filefield_file_load($file['fid']));
+            $node_field[$delta]  = array_merge($node_field[$delta], filefield_file_load($file['fid']));
           }
           $output = array($fieldname => $node_field);
         }
@@ -181,7 +131,7 @@
 
     case 'delete':
       foreach ($node_field as $delta => $item) {
-        _filefield_file_delete($item, $field['field_name']); 
+        filefield_file_delete($item, $field['field_name']); 
       }
       break;
   }
@@ -246,16 +196,6 @@
   }
 }
 
-function _filefield_file_delete($file, $fieldname) {
-  if (is_numeric($file['fid'])) {
-    db_query('DELETE FROM {files} WHERE fid = %d', $file['fid']);
-  }
-  else {
-    unset($_SESSION['filefield'][$fieldname][$file['sessionid']]);
-  }
-  return file_delete($file['filepath']);
-}
-
 /**
  * Implementation of hook_widget().
  */
@@ -450,24 +390,14 @@
 }
 
 function filefield_field_formatter($field, $item, $formatter) {
+	require_once(drupal_get_path('module', 'filefield') .'/filefield.inc');
   if(!isset($item['fid'])) {
     return '';
   }
-  $file = _filefield_file_load($item['fid']);
+  $file = filefield_file_load($item['fid']);
   return theme('filefield', $file, $item);
 }
 
-function _filefield_file_load($fid = NULL) {
-  if (isset($fid)) { 
-    if (is_numeric($fid)) {
-      $result = db_query('SELECT * FROM {files} WHERE fid = %d', $fid);
-      $file = db_fetch_array($result);
-      return ($file) ? $file : array();
-    }
-  }
-  return array();
-}
-
 function theme_filefield_icon($file) {
   $ext = array_pop(explode('.',$file['filename']));
   $known_extensions = array('0','ace','aif','ai','ani','asf','asp','avi','bak','bat','bin','bmp','bz2','bz','cab','cdr','cfg','com','conf','cpt','css','cur','dat','db','dcr','dic','diff','dir','dll','dmg','doc','dwg','edir','eml','eps','exe','fla','flv','fon','gif','gz','hqx','html','htm','ico','inc','ini','iso','jpeg','jpg','js','lnk','log','m3u','mdb','midi','mid','mov','mp3','mpeg','mpg','nfo','odb','odc','odf','odg','odm','odp','ods','odt','ogg','otg','oth','otp','ots','ott','patch','pdf','php3','php','phtml','pl','png','pps','ppt','psd','pwl','qt','ram','ra','rar','reg','rpm','rtf','sh','shtml','sit','sql','svg','swf','sxc','sxi','sxw','sys','tar','tgz','tiff','tif','tmp','tpl','ttf','txt','wav','wma','wmv','wp','xls','xml','zip');
@@ -499,35 +429,3 @@
     return '<a href="'. check_url($url) .'">'.check_plain($name).'</a>';
   }
 }
-
-if (!function_exists('upload_file_download')) {
-  function filefield_file_download($file) {
-    $file = file_create_path($file);
-    $result = db_query("SELECT f.* FROM {files} f WHERE filepath = '%s'", $file);
-    if ($file = db_fetch_object($result)) {
-      if (user_access('view uploaded files')) {
-        $node = node_load($file->nid);
-        if (node_access('view', $node)) {
-          $name = mime_header_encode($file->filename);
-          $type = mime_header_encode($file->filemime);
-          // Serve images and text inline for the browser to display rather than download.
-          $disposition = ereg('^(text/|image/)', $file->filemime) ? 'inline' : 'attachment';
-          return array(
-            'Content-Type: '. $type .'; name='. $name,
-            'Content-Length: '. $file->filesize,
-            'Content-Disposition: '. $disposition .'; filename='. $name,
-            'Cache-Control: private'
-          );
-        }
-        else {
-          return -1; 
-        }
-      }   
-      else {
-        return -1; 
-      }   
-    }   
-  }
-
-}
-
