Index: teaserthumbnail.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/teaserthumbnail/teaserthumbnail.module,v
retrieving revision 1.6
diff -u -p -r1.6 teaserthumbnail.module
--- teaserthumbnail.module	26 Dec 2009 05:46:00 -0000	1.6
+++ teaserthumbnail.module	11 Aug 2010 05:09:02 -0000
@@ -79,6 +79,34 @@ function teaserthumbnail_form_alter(&$fo
       '#default_value' => variable_get('teaserthumbnail_attachment_'. $form['#node_type']->type, 0),
       '#description' => t('If checked, the thumbnail may be built from file attachments as well for teasers and RSS feeds (not views fields).'),
     );
+    
+    $image_fields = fetch_image_fields($form['#node_type']->type);
+    if (count($image_fields) == 0) {
+      $form['teaserthumbnail']['teaserthumbnail_imagefield'] = array(
+         '#prefix' => '<div>',
+         '#title' => t('Use CCK Filed'),
+         '#value'=> t('It\' no image field in this content type. You can set after add image field for this content type'),
+         '#subfix' => '</div>',
+         '#attributes' => array('class' => 'no-field image-filed-setting'),
+         '#description' => t('It\'s no image field in this content type'),
+      );
+    } else {
+      $form['teaserthumbnail']['teaserthumbnail_imagefield'] = array(
+        '#type' => 'select',
+        '#title' => t('CCK Fileds'),
+        '#default_value'=> variable_get('teaserthumbnail_imagefield_'.$form['#node_type']->type, ''),
+        '#options' => $image_fields,
+        '#description' => t('If selected, the thumnail may be build from CCK Field (such as Image Field) as well from teasers adn RSS feeds(not views fields);If you let it affect, you should check the bottom checkbox'),
+      );
+  
+      $form['teaserthumbnail']['teaserthumbnail_imagefield_check'] = array(
+        '#type' => 'checkbox',
+        '#title' => t('Use CCK Field'),
+        '#default_value' => variable_get('teaserthumbnail_imagefield_check_'.$form['#node_type']->type, 0),
+        '#description' => t('If checked, the thumbnail may be build from image field that you selceted from the top selected'),
+      );
+    }
+    
 
     $form['teaserthumbnail']['teaserthumbnail_teaser'] = array(
       '#type' => 'radios',
@@ -216,6 +244,7 @@ function teaserthumbnail_nodeapi(&$node,
             if ($align) $attributes['align'] = ($align == 1) ? 'left' : 'right';
             // Build the thumbnail
             $thumbnail = theme('teaserthumbnail_thumbnail', $node, $attributes);
+            
             if (variable_get('teaserthumbnail_link_'. $node->type, 1)) $thumbnail = l($thumbnail, 'node/'. $node->nid, array('html' => TRUE));
             $node->content['teaserthumbnail'] = array(
               '#value' => $thumbnail,
@@ -265,11 +294,10 @@ function teaserthumbnail_theme() {
  */
 function theme_teaserthumbnail_thumbnail($node, $attributes = NULL) {
   $thumbnail = $node->teaserthumbnail;
-
   // We define if we prepend a thumbnail to the teaser
   if (!empty($thumbnail)) {
     $preset = variable_get('teaserthumbnail_preset_'. $node->type, '');
-    $preset = empty($preset) ? variable_get('teaserthumbnail_preset', '') : $preset ;
+    $preset = empty($preset) ? variable_get('teaserthumbnail_preset', '') : $preset;
     $thumbnail = theme('imagecache', $preset, $thumbnail, '', '', $attributes);
   }
   
@@ -315,7 +343,7 @@ function _teaserthumbnail_get_local_imag
  */
 function _teaserthumbnail_get_thumbnail_source($node) {
   $thumbnail = db_result(db_query("SELECT filepath FROM {teaserthumbnail} WHERE nid = %d", $node->nid));
-  
+
   // We look in the attachments if necessary and if possible
   if (variable_get('teaserthumbnail_attachment_'. $node->type, 0) && empty($thumbnail) && module_exists('upload')) {
     $files = upload_load($node);
@@ -343,6 +371,27 @@ function _teaserthumbnail_get_thumbnail_
     }
   }
   
+  // We look at the CCK Imagefields
+  if (variable_get('teaserthumbnail_imagefield_check_'. $node->type, 0) && empty($file) && module_exists('imagefield')) {
+    $imagefield = variable_get('teaserthumbnail_imagefield_'. $node->type, 0);
+    if ($node->$imagefield) {
+      $min_height = variable_get('teaserthumbnail_min_height_'.$node->type, '');
+      if (empty($min_height)) $min_height = variable_get('teaserthumbnail_min_height', '');
+      if (empty($min_height)) $min_height = 0;
+      $min_width = variable_get('teaserthumbnail_min_width_'.$node->type, '');
+      if (empty($min_width)) $min_width = variable_get('teaserthumbnail_min_width', '');
+      if (empty($min_width)) $min_width = 0;
+      foreach ($node->$imagefield as $field) {
+        $image_info = image_get_info($field['filepath']);
+        if ($image_info && isset($image_info['extension'])) {
+          // We check for minimum width and height        
+          if (($image_info['width'] >= $min_width) && ($image_info['height'] >= $min_height)) {
+            $thumbnail = $field['filepath'];
+          }
+        } if (!empty($thumbnail)) break;
+      }
+    }
+  }
   return $thumbnail;
 }
 
@@ -350,6 +399,7 @@ function _teaserthumbnail_get_thumbnail_
  * Process a node on submit: find if there is a valid picture for building a
  * thumbnail and stores a reference to it.
  */
+
 function _teaserthumbnail_process(&$node, $field) {
   $teaser_prefix = '';
   
@@ -420,4 +470,20 @@ function _teaserthumbnail_strip_media($s
   $text = preg_replace($object_pattern, '', $string);
   
   return $string;
-}
\ No newline at end of file
+}
+
+/**
+ * Retrieve the image fields in the node type
+ */
+function fetch_image_fields($node_type = NULL) {
+  $image_fields = array();
+  if ($node_type != NULL) {
+    $node = content_types($node_type);
+    foreach ($node['fields'] as $field) {
+      if ($field['type'] == 'filefield' && $field['widget']['module'] == 'imagefield') {
+        $image_fields [$field['field_name']] = $field['field_name'];
+      }
+    }
+  }
+  return $image_fields;
+}
