Index: taxonomy_image.module
===================================================================
--- taxonomy_image.module	(revision 615)
+++ taxonomy_image.module	(working copy)
@@ -749,6 +749,9 @@
       'views_handler_field_taxonomy_image' => array(
         'parent' => 'views_handler_field',
         ),
+      'views_handler_field_taxonomy_image_all' => array(
+        'parent' => 'views_handler_field',
+        ),
       ),
     );
 }
Index: taxonomy_image.views.inc
===================================================================
--- taxonomy_image.views.inc	(revision 615)
+++ taxonomy_image.views.inc	(working copy)
@@ -38,5 +38,13 @@
     ),
   );
 
+  $data['term_image']['all_tid'] = array(
+    'title' => t('All term images'),
+    'help' => t("All images associated with related taxonomy terms."),
+    'field' => array(
+      'handler' => 'views_handler_field_taxonomy_image_all',
+    ),
+  );
+
   return $data;
 }
Index: views_handler_field_taxonomy_image_all.inc
===================================================================
--- views_handler_field_taxonomy_image_all.inc	(revision 0)
+++ views_handler_field_taxonomy_image_all.inc	(revision 0)
@@ -0,0 +1,167 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Views integration for Taxonomy Image module.
+ */
+
+/**
+ * Field handler to provide all term images.
+ *
+ * @ingroup views_field_handlers
+ */
+class views_handler_field_taxonomy_image_all extends views_handler_field {
+
+  /**
+   * Define options available for this field.
+   */
+  function option_definition() {
+    $options = parent::option_definition();
+
+    $options['imagecache_preset'] = array('default' => '');
+    $options['link_to_taxonomy'] = array('default' => FALSE);
+    $options['only_one_image'] = array('default' => FALSE);
+    $options['limit'] = array('default' => FALSE);
+    $options['vids'] = array('default' => array());
+
+    return $options;
+  }
+
+  /**
+   * Build option configuration form.
+   */
+  function options_form(&$form, &$form_state) {
+    parent::options_form($form, $form_state);
+
+    $form['link_to_taxonomy'] = array(
+      '#title' => t('Link this image to its term page'),
+      '#type' => 'checkbox',
+      '#default_value' => !empty($this->options['link_to_taxonomy']),
+    );
+
+    $form['limit'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Limit term images by vocabulary'),
+      '#default_value'=> $this->options['limit'],
+    );
+
+    $voc_opts = array();
+    $vocs = taxonomy_get_vocabularies();
+    foreach ($vocs as $voc) {
+      $voc_opts[$voc->vid] = check_plain($voc->name);
+    }
+
+    $form['vids'] = array(
+      '#prefix' => '<div><div id="edit-options-vids">',
+      '#suffix' => '</div></div>',
+      '#type' => 'checkboxes',
+      '#title' => t('Vocabularies'),
+      '#options' => $voc_opts,
+      '#default_value' => $this->options['vids'],
+      '#process' => array('expand_checkboxes', 'views_process_dependency'),
+      '#dependency' => array('edit-options-limit' => array(TRUE)),
+    );
+
+    $form['only_one_image'] = array(
+      '#title' => t('If several images are available, show only one'),
+      '#type' => 'checkbox',
+      '#default_value' => !empty($this->options['only_one_image']),
+    );
+
+    // If ImageCache module is found, add its presets as available options
+    // for how to display the image.
+    if (module_exists('imagecache')) {
+      $raw_presets = imagecache_presets();
+      $presets[''] = t('Default');
+      foreach ($raw_presets as $preset_id => $preset_info) {
+        $preset = $preset_info['presetname'];
+        $presets[$preset] = $preset;
+      }
+      $form['imagecache_preset'] = array(
+        '#type' => 'select',
+        '#title' => t('ImageCache preset'),
+        '#options' => $presets,
+        '#default_value' => $this->options['imagecache_preset'],
+      );
+    }
+  }
+
+  /**
+   * Add node revision to the query
+   */
+  function query() {
+    $alias_tid_1 = $this->aliases['all_tid'];
+    $base_table = $this->view->base_table == 'node_revisions' ? 'node_revisions' : 'node';
+    $this->alias_revid = $this->query->add_field($base_table, 'vid');
+    $this->alias_all_tids = $this->query->add_field(NULL, 0, 'all_tid_all_tids');
+    $this->field_alias = $this->query->add_field(NULL, 0, 'all_tid');
+  }
+
+  /**
+   * Compute our virtual fields
+   */
+  function pre_render($values) {
+    $revids = array();
+    $all_tids = array();
+    foreach ($values as $val) {
+      $revid = $val->{$this->alias_revid};
+      if (!empty($revid)) {
+        $revids[] = $revid;
+        $all_tids[$revid] = array();
+      }
+    }
+
+
+    if ($revids) {
+      $voc_clause = "";
+      if (!empty($this->options['limit']) && !empty($this->options['vids']))
+        $voc_clause = " AND td.vid IN (" . implode(', ', array_keys(array_filter($this->options['vids']))) . ")";
+
+      if ($this->options['only_one_image'])
+        $order_clause = " ORDER BY tn.tid DESC LIMIT 1";
+      else
+        $order_clause = " ORDER BY tn.tid ASC";
+
+      $results = db_query("SELECT DISTINCT tn.vid as revid, ti.tid AS tid FROM {term_image} ti INNER JOIN {term_node} tn ON ti.tid = tn.tid INNER JOIN {term_data} td ON ti.tid = td.tid WHERE tn.vid IN (" . implode(', ', $revids) . ")" . $voc_clause . $order_clause);
+
+      while ($res = db_fetch_object($results))
+        $all_tids[$res->revid][] = $res->tid;
+    }
+
+    foreach ($values as &$val) {
+      $revid = $val->{$this->alias_revid};
+      if ($all_tids[$revid]) {
+        $tids = array_values($all_tids[$revid]);
+        $val->{$this->alias_all_tids} = $tids;
+        $val->{$this->field_alias} = $tids[0];
+      }
+      else {
+        $val->{$this->alias_all_tids} = array();
+        $val->{$this->field_alias} = NULL;
+      }
+    }
+  }
+
+  /**
+   * Render field output to the browser.
+   */
+  function render($value) {
+    $images = '';
+    foreach ($value->{$this->alias_all_tids} as $tid) {
+      // Render image using ImageCache preset, if any.
+      if ($this->options['imagecache_preset'])
+        $image = taxonomy_image_display($tid, NULL, $this->options['imagecache_preset']);
+      else
+        $image = taxonomy_image_display($tid);
+
+      // Output image as a link, if option is set.
+      if ($this->options['link_to_taxonomy'])
+        $image = l($image, drupal_get_path_alias(taxonomy_term_path(taxonomy_get_term($tid))), array('html' => TRUE));
+
+      $images .= $image;
+    }
+
+    return $images;
+  }
+}
