Index: image.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/image/image.module,v
retrieving revision 1.274
diff -u -r1.274 image.module
--- image.module  16 Jun 2008 18:45:58 -0000  1.274
+++ image.module  5 Jul 2008 13:28:14 -0000
@@ -30,37 +30,6 @@
 }
 
 /**
- * Implementation of hook_theme().
- */
-function image_theme() {
-  return array(
-    'image_settings_sizes_form' => array(
-      'arguments' => array('form' => NULL),
-    ),
-    'image_teaser' => array(
-      'arguments' => array('node' => NULL, 'size' => IMAGE_THUMBNAIL),
-    ),
-    'image_body' => array(
-      'arguments' => array('node' => NULL, 'size' => IMAGE_PREVIEW),
-    ),
-    'image_block_random' => array(
-      'arguments' => array('images' => NULL, 'size' => IMAGE_THUMBNAIL),
-    ),
-    'image_block_latest' => array(
-      'arguments' => array('images' => NULL, 'size' => IMAGE_THUMBNAIL),
-    ),
-    'image_display' => array(
-      'arguments' => array(
-        'node' => NULL,
-        'label' => NULL,
-        'url' => NULL,
-        'attributes' => NULL,
-      ),
-    ),
-  );
-}
-
-/**
  * Implementation of hook_node_info
  */
 function image_node_info() {
@@ -438,6 +407,7 @@
   }
 
   $node = node_prepare($node, $teaser);
+  $context[$teaser ? 'teaser' : 'node'] = array();
   $node->content['image'] = array(
     '#value' => theme($teaser ? 'image_teaser' : 'image_body', $node, $size),
     '#weight' => 0,
@@ -605,22 +575,6 @@
 }
 
 /**
- * Create an <img> tag for an image.
- */
-function image_display(&$node, $label = IMAGE_PREVIEW, $attributes = array()) {
-  if (empty($node->images[$label])) {
-    return;
-  }
-
-  $image_info = image_get_info(file_create_path($node->images[$label]));
-  $attributes['class'] = "image image-$label ". (isset($attributes['class']) ? $attributes['class'] : "");
-  $attributes['width'] = $image_info['width'];
-  $attributes['height'] = $image_info['height'];
-
-  return theme('image_display', $node, $label, file_create_url($node->images[$label]), $attributes);
-}
-
-/**
  * Fetches an image file, allows "shorthand" image urls such of the form:
  * image/view/$nid/$label
  * (e.g. image/view/25/thumbnail or image/view/14)
@@ -648,17 +602,85 @@
 }
 
 /**
- * Theme a teaser
+ * Implementation of hook_theme().
  */
-function theme_image_teaser($node, $size) {
-  return l(image_display($node, IMAGE_THUMBNAIL), 'node/'. $node->nid, array('html' => TRUE));
+function image_theme() {
+  return array(
+    'image_settings_sizes_form' => array(
+      'arguments' => array('form' => NULL),
+    ),
+    'image_teaser' => array(
+      'template' => 'image',
+      'arguments' => array('node' => NULL, 'size' => IMAGE_THUMBNAIL),
+    ),
+    'image_body' => array(
+      'template' => 'image',
+      'arguments' => array('node' => NULL, 'size' => IMAGE_PREVIEW),
+    ),
+    'image_block_random' => array(
+      'arguments' => array('images' => NULL, 'size' => IMAGE_THUMBNAIL),
+    ),
+    'image_block_latest' => array(
+      'arguments' => array('images' => NULL, 'size' => IMAGE_THUMBNAIL),
+    ),
+    'image_display' => array(
+      'arguments' => array(
+        'node' => NULL,
+        'label' => NULL,
+        'url' => NULL,
+        'attributes' => NULL,
+      ),
+    ),
+  );
+}
+
+/*
+ * Template preprocessor for image body
+ * Takes variables from theming call:
+ *  - node: the $node object
+ *  - size: the size of the image
+ */
+function template_preprocess_image_body(&$variables) {
+  if (empty($variables['node']->images[$variables['size']])) {
+    return;
+  }
+
+  $image_info = image_get_info(file_create_path($variables['node']->images[$variables['size']]));
+  $variables['attributes']['width'] = $image_info['width'];
+  $variables['attributes']['height']  = $image_info['height'];
+  $variables['attributes']['class'] = 'image image-'. $variables['size'];
+  $variables['img_src'] = file_create_url($variables['node']->images[$variables['size']]);
+
+  // call core theming function
+  $variables['image'] = theme('image', $variables['img_src'], $variables['node']->title, $variables['node']->title, $variables['attributes'], FALSE);
+
+}
+
+/*
+ * Template preprocessor for teasers
+ * Call the regular preprocessor and wrap the IMG tag in a link; keep it for theming access
+ */ 
+function template_preprocess_image_teaser(&$variables) {
+  template_preprocess_image_body($variables);
+  
+  $variables['img_tag'] = $variables['image'];
+  $variables['image'] = l($variables['img_tag'], 'node/'. $variables['node']->nid, array('html' => TRUE));
 }
 
 /**
- * Theme a body
+ * Create an <img> tag for an image.
  */
-function theme_image_body($node, $size) {
-  return image_display($node, $size);
+function image_display(&$node, $label = IMAGE_PREVIEW, $attributes = array()) {
+  if (empty($node->images[$label])) {
+    return;
+  }
+
+  $image_info = image_get_info(file_create_path($node->images[$label]));
+  $attributes['class'] = "image image-$label ". (isset($attributes['class']) ? $attributes['class'] : "");
+  $attributes['width'] = $image_info['width'];
+  $attributes['height'] = $image_info['height'];
+
+  return theme('image_display', $node, $label, file_create_url($node->images[$label]), $attributes);
 }
 
 /**
--- image.tpl.php
+++ image.tpl.php
@@ -0,0 +1,33 @@
+<?php+  /**+   * template file for images+   * stuff we need+   *  - node id+      - image URL+      - other attribs for the image+      - classes for the image div+      - label+      - size x+      - size y+      - size name+++     Notes:+     - there's now a DIV. This gives extra control in css+     - the classes are repeated: in the DIV and in the IMG.+       They could be removed from the image, but that would break existing theming+       that people have on their sites+       Not much mind you -- just replace 'img.CLASS' with 'div.CLASS img'+       Probably reasonable for a version upgrade. Up to you drewish.+  <?php print $img_tag ?>++   */++++?>+<div class="<?php print $attributes['class'] ?>">+  <?php +    print $image;+  ?>+</div>

