Index: image.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/image/image.module,v
retrieving revision 1.196
diff -u -r1.196 image.module
--- image.module	20 Apr 2006 07:20:54 -0000	1.196
+++ image.module	25 Apr 2006 11:04:06 -0000
@@ -186,13 +186,42 @@
 }
 
 /**
- * implement hook_file_download
+ * Implementation of hook_file_download().
  */
 function image_file_download($file) {
-  $size = image_get_info(file_create_path($file));
-  if ($size) {
-    $headers = array('Content-Type: ' . $size['mime_type']);
-    return $headers;
+  // Check if an image is downloaded from our temp directory
+  $temp_path = file_create_path(rtrim(variable_get('image_default_path', 'images'), '/') .'/temp');
+  if (strpos(file_create_path($file), $temp_path) === 0) {
+    // Only allow when the user has permissions to create images
+    if (user_access('create images')) {
+      $info = image_get_info(file_create_path($file));
+      $name = mime_header_encode(basename($file));
+      $type = mime_header_encode($info['mime_type']);
+      return array(
+        'Content-Type: '. $type .'; name='. $name,
+        'Content-Length: '. $info['file_size'],
+        'Content-Disposition: inline; filename='. $name
+      );
+    }
+    else {
+      return -1;
+    }
+  }
+  // Check if an image is downloaded from a node
+  else if ($file = db_fetch_object(db_query("SELECT f.* FROM {files} f INNER JOIN {node} n ON f.nid = n.nid WHERE f.filepath = '%s' AND n.type = 'image'", $file))) {
+    $node = node_load($file->nid);
+    if (node_access('view', $node)) {
+      $name = mime_header_encode($file->filename);
+      $type = mime_header_encode($file->filemime);
+      return array(
+        'Content-Type: '. $type .'; name='. $name,
+        'Content-Length: '. $file->filesize,
+        'Content-Disposition: inline; filename='. $name
+      );
+    }
+    else {
+      return -1;
+    }
   }
 }
 
@@ -377,6 +406,31 @@
 }
 
 /**
+ * Implementation of hook_form_alter().
+ */
+function image_form_alter($form_id, &$form) {
+  if (module_exist('upload') && $form_id == 'image_node_settings') {
+    // Allow ourselves to alter the Workflow fieldset
+    $form['workflow']['#process']['image_node_settings'] = array();
+  }
+}
+
+/**
+ * Alters the Workflow fieldset in the node settings form.
+ */
+function image_node_settings($form) {
+  // Change the Attachments field into a dummy field
+  $form['upload_image']['#type'] = 'value';
+  $form['upload_image']['#value'] = false;
+  
+  // Add a notice
+  $form['upload_image_notice'] = array('#type' => 'item', '#title' => t('Attachments'), 
+    '#value' => "<p>". t("Attachments cannot be enabled for images because of incompatibility issues."). "</p>");
+
+  return $form;
+}
+
+/**
  * Create an <img> tag for an image.
  */
 function image_display(&$node, $label = 'preview', $attributes = array()) {
@@ -718,6 +772,12 @@
     drupal_set_message(t('Make sure you have a working image toolkit installed and enabled, for more information see: %settings', array('%settings' => l(t('the settings page'), 'admin/settings'))), 'error');
     return false;
   }
+
+  // Make sure upload module doesn't interfere with image files
+  if (module_exist('upload') && variable_get('upload_image', TRUE)) {
+    variable_set('upload_image', FALSE);
+  }
+
   return true;
 }
 
@@ -827,15 +887,15 @@
   $dest = _image_filename(basename($image));
   if (file_copy($image, $dest)) {
     $info = image_get_info(file_create_path($dest));
+
     $file->filename = $label;
     $file->filepath = _image_filename(basename($image));
     $file->filemime = $info['mime_type'];
     $file->filesize = filesize(file_create_path($dest));
+
     $fid = db_next_id('{files}_fid');
-    db_query("INSERT INTO {files} (fid, nid, filename, filepath, filemime, filesize) VALUES (%d, %d, '%s', '%s', '%s', '%s')",
-             $fid, $node->nid, $file->filename, $file->filepath, $file->filemime, $file->filesize);
-    db_query("INSERT INTO {file_revisions} (fid, vid, description, list) VALUES (%d, %d, '%s', %d)",
-             $fid, $node->vid, '', 0);
+    db_query("INSERT INTO {files} (fid, nid, filename, filepath, filemime, filesize) VALUES (%d, %d, '%s', '%s', '%s', %d)",
+      $fid, $node->nid, $file->filename, $file->filepath, $file->filemime, $file->filesize);
   }
 }
 
