? taxonomy_image-views2-integration-267427-11.patch
? taxonomy_image-views2-integration-267427-13.patch
? taxonomy_image-views2-integration-267427-8.patch
Index: taxonomy_image.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/taxonomy_image/taxonomy_image.module,v
retrieving revision 1.12.4.13.2.16
diff -u -p -r1.12.4.13.2.16 taxonomy_image.module
--- taxonomy_image.module	8 Jun 2008 16:19:48 -0000	1.12.4.13.2.16
+++ taxonomy_image.module	12 Jun 2008 04:23:20 -0000
@@ -384,89 +384,6 @@ function taxonomy_image_user($type, $edi
   }
 }
 
-function taxonomy_image_views_tables() {
-//  $tables['term_node'] = array(
-//    'name' => 'term_node',
-//    'join' => array(
-//      'left' => array(
-//        'table' => 'node',
-//        'field' => 'nid'
-//      ),
-//      'right' => array(
-//        'field' => 'nid'
-//      )
-//    ),
-//  );
-  $tables['term_image'] = array(
-    'name' => 'term_image',
-    'join' => array(
-      'left' => array(
-        'table' => 'term_node',
-        'field' => 'tid',
-      ),
-      'right' => array(
-        'field' => 'tid'
-      )
-    ),
-    'fields' => array(
-      'tid' => array(
-        'name' => t('Taxonomy Image: Image'),
-        'help' => t('The image associated with the node\'s taxonomy term.'),
-        'handler' => array(
-          'views_handler_image_path' => t('Image'),
-        )
-      )
-    ),
-  );
-
-  if (module_exists('imagecache')) {
-    if (function_exists('_imagecache_get_presets')) {
-      $raw_presets = _imagecache_get_presets();
-      $presets = array();
-      foreach ($raw_presets as $preset) {
-        $presets[$preset] = $preset;
-        $presets["{$preset}_link"] = "{$preset} as link";
-      }
-    }
-    elseif (function_exists('imagecache_presets')) {
-      $raw_presets = imagecache_presets();
-      $presets = array();
-      foreach ($raw_presets as $preset_id => $preset_info) {
-        $preset = $preset_info['presetname'];
-        $presets[$preset] = $preset;
-        $presets["{$preset}_link"] = "{$preset} as link";
-      }
-    }
-
-    $presets[''] = 'Default';
-    $tables['term_image']['fields']['tid']['option'] = array(
-      '#type' => 'select',
-      '#options' => $presets,
-      );
-  }
-
-  return $tables;
-}
-
-function views_handler_image_path($fieldinfo, $fielddata, $value, $data) {
-  if (empty($fielddata['options'])) {
-    return taxonomy_image_display($value);
-  }
-  else{
-    if (drupal_substr($fielddata['options'], -5, 5) == '_link') {
-      $profile=drupal_substr($fielddata['options'], 0, -5);
-      $img = taxonomy_image_display($value, $data->name, $profile);
-      $img = l($img, taxonomy_term_path(taxonomy_get_term($value)), array('html' => TRUE));
-      return $img;
-    }
-    else{
-      $profile = $fielddata['options'];
-      $img = taxonomy_image_display($value, $data->name, $profile);
-      return $img;
-    }
-  }
-}
-
 function taxonomy_image_file_download($file) {
   if (user_access('access taxonomy images')) {
     $path = file_create_path($file);
Index: taxonomy_image.views.inc
===================================================================
RCS file: taxonomy_image.views.inc
diff -N taxonomy_image.views.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ taxonomy_image.views.inc	12 Jun 2008 04:23:20 -0000
@@ -0,0 +1,109 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Views integration for Taxonomy Image module.
+ */
+
+/**
+ * Implementation of hook_views_data().
+ */
+function taxonomy_image_views_data() {
+  // Table definition.
+  $data['term_image']['table']['group'] = t('Taxonomy');
+
+  // Joins.
+  $data['term_image']['table']['join'] = array(
+    'term_data' => array(
+      // Links directly to term_data via tid.
+      'left_field' => 'tid',
+      'field' => 'tid',
+    ),
+  );
+
+  // Fields.
+  $data['term_image']['path'] = array(
+    'title' => t('Term image'),
+    'help' => t("The image associated with a taxonomy term."),
+    'field' => array(
+      'handler' => 'views_handler_field_taxonomy_image',
+    ),
+  );
+
+  return $data;
+}
+
+/**
+ * Field handler to provide an embedded image.
+ *
+ * @ingroup views_field_handlers
+ */
+class views_handler_field_taxonomy_image 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);
+
+    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']),
+    );
+
+    // 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'],
+      );
+    }
+  }
+
+  /**
+   * Render field output to the browser.
+   */
+  function render($values) {
+    $image = '';
+
+    // Render image. If ImageCache preset is specified, use it.
+    if ($this->options['imagecache_preset']) {
+      $image = taxonomy_image_display($values->tid, NULL, $this->options['imagecache_preset']);
+    }
+    else {
+      $image = taxonomy_image_display($values->tid);
+    }
+
+    // Output image as a link, if option is set.
+    if ($this->options['link_to_taxonomy']) {
+      $image = l($image, taxonomy_term_path(taxonomy_get_term($values->tid)), array('html' => TRUE));
+    }
+
+    return $image;
+  }
+
+}
+
