Index: similar.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/similar/similar.module,v
retrieving revision 1.8.2.6
diff -u -r1.8.2.6 similar.module
--- similar.module	28 Mar 2010 03:49:46 -0000	1.8.2.6
+++ similar.module	25 May 2010 13:24:28 -0000
@@ -51,6 +51,42 @@
           '#default_value' => variable_get('similar_teaser_enabled', 0),
           '#options' => array(t('No'), t('Yes'))
         );
+		
+		$form['similar_image_fieldset'] = array(
+            '#type' => 'fieldset',
+            '#title' => t('Image Configuration'),
+            '#collapsible' => TRUE,
+            '#collapsed' => FALSE,
+			'#description' => t("Specific configurations to use similar entries with image. If node type choosed don't have image the display will revert to default list.")
+          );
+		  
+		$form['similar_image_fieldset']['similar_image_enabled'] = array(
+          '#type' => 'radios',
+          '#title' => t('Include Image'),
+          '#default_value' => variable_get('similar_image_enabled', 0),
+          '#options' => array(t('No'), t('Yes'))
+        );
+		  
+		$types = _similar_published_fields();
+        $form['similar_image_fieldset']['similar_node_fields'] = array(
+          '#type' => 'select',
+          '#multiple' => false,
+          '#title' => t('Choose Image Field that you want display'),
+          '#default_value' => variable_get('similar_node_fields', $types),
+          '#options' => $types
+        );
+
+		if (module_exists('imagecache')) {
+			$types = _similar_published_imagecache();
+			$form['similar_image_fieldset']['similar_imagecache'] = array(
+			  '#type' => 'select',
+			  '#multiple' => false,
+			  '#title' => t('Choose image preset that you want use'),
+			  '#default_value' => variable_get('similar_imagecache', $types),
+			  '#options' => $types
+			);
+		}
+		
         $form['similar_rel_nofollow'] = array(
           '#type' => 'radios',
           '#title' => t('Block search engines'),
@@ -65,6 +101,15 @@
           '#default_value' => variable_get('similar_num_display', 5),
           '#options' => $options
         );
+		
+		 $form['similar_node_types_option'] = array(
+		  '#type' => 'radios',
+          '#title' => t('Node Type Display Mode'),
+          '#description' => t('If Yes, yhe Block will only show content of the same type of the main content of page, usefull when you use this block in distinct pages.'),
+          '#default_value' => variable_get('similar_node_types_option', 0),
+          '#options' => array(t('No'), t('Yes'))
+        );
+		
         $types = _similar_published_node_types();
         $form['similar_node_types'] = array(
           '#type' => 'checkboxes',
@@ -109,13 +154,20 @@
     case 'save':
       if ($delta == 0) {
         variable_set('similar_teaser_enabled', $edit['similar_teaser_enabled']);
+		variable_set('similar_image_enabled', $edit['similar_image_enabled']);
         variable_set('similar_rel_nofollow', $edit['similar_rel_nofollow']);
         variable_set('similar_num_display', $edit['similar_num_display']);
         variable_set('similar_node_types', $edit['similar_node_types']);
+		variable_set('similar_node_fields', $edit['similar_node_fields']);
+		if (module_exists('imagecache')) {
+			variable_set('similar_imagecache', $edit['similar_imagecache']);
+		}
         if (module_exists('taxonomy')) {
           variable_set('similar_taxonomy_filter', $edit['similar_taxonomy_filter']);
           variable_set('similar_taxonomy_tids', $edit['similar_taxonomy_tids']);
         }
+		variable_set('similar_node_types_option', $edit['similar_node_types_option']);
+		
       }
       return;
 
@@ -219,28 +271,71 @@
 }
 
 /**
+ * Query for image fields
+ * @return array
+ */
+function _similar_published_fields() {
+  $types  = array();
+  $result = db_query('SELECT DISTINCT(n.field_name) FROM {content_node_field} n WHERE n.type="filefield" ORDER BY n.field_name ASC');
+  while ($fieldfile = db_fetch_object($result)) {
+    $types[$fieldfile->field_name] = $fieldfile->field_name;
+  }
+  return $types;
+}
+
+/**
+ * Query for imagecache presetname
+ * @return array
+ */
+function _similar_published_imagecache() {
+  $types  = array();
+  $types["No Preset"] = "No Preset";
+  $result = db_query('SELECT n.presetname FROM {imagecache_preset} n  ORDER BY n.presetname ASC');
+  while ($preset = db_fetch_object($result)) {
+    $types[$preset->presetname] = $preset->presetname;
+  }
+  return $types;
+}
+
+
+/**
  * Queries the database for similar entries and puts them in a HTML list
  *
  * @param object $node
  * @return string
  */
 function theme_similar_content($node) {
-  $items = array();
+	$items = array();
 
-  $text = "$node->title $node->body";
-  $teaser = variable_get('similar_teaser_enabled', 0);
-
-  $types = _similar_published_node_types();
-  $types = variable_get('similar_node_types', $types);
-  array_walk($types, '_similar_content_type_escape');
-
-  if (sizeof($types) > 1) {
-    $types = implode("','", $types);
+	$text = "$node->title $node->body";
+	$teaser = variable_get('similar_teaser_enabled', 0);
+	$image = variable_get('similar_image_enabled', 0);
+	$type_mode=variable_get('similar_node_types_option', 0);
+
+	if($image){
+		$field_imgcache = variable_get('similar_imagecache', 0);
+		$field_img = variable_get('similar_node_fields', 0);
+	}
+
+	if(isset($node->$field_img)){
+	}else{
+		$image='0';
+	}
+  
+  if($type_mode){
+		$types = "'$node->type'";
+  }else{
+	$types = _similar_published_node_types();
+	$types = variable_get('similar_node_types', $types);
+	array_walk($types, '_similar_content_type_escape');
+	if (sizeof($types) > 1) {
+	$types = implode("','", $types);
+	}
+	else {
+	list(, $types) = each($types);
+	}
+	$types = "'$types'";
   }
-  else {
-    list(, $types) = each($types);
-  }
-  $types = "'$types'";
   if (module_exists('taxonomy') && (variable_get('similar_taxonomy_filter', 0) == 2 && $taxonomy_tids = variable_get('similar_taxonomy_tids', array()))
     || (variable_get('similar_taxonomy_filter', 0) == 1 && $taxonomy_tids = _similar_taxonomy_membership($node->nid))) {
 
@@ -262,27 +357,57 @@
   $query = db_rewrite_sql($query, 'n', 'nid');
   $result = db_query_range($query, $text, $node->nid, 0, variable_get('similar_num_display', 5));
 
-  while ($node = db_fetch_object($result)) {
-    $content = node_load($node->nid);
-    if ($teaser) {
-      $items[] = '<div class="similar-title">'.
-        l($content->title,
-          'node/'. $node->nid,
-          array(
-            'attributes' => variable_get('similar_rel_nofollow', 0) ? array('rel' => 'nofollow') : NULL,
-            'absolute' => TRUE
-          )
-        ) .
-        '</div><div class="similar-teaser">'. check_markup($content->teaser, $content->format, FALSE) .'</div>';
-    }
-    else {
-      $items[] = l(
-        $content->title,
-        'node/'. $node->nid,
-        array('attributes' => variable_get('similar_rel_nofollow', 0) ? array('rel' => 'nofollow') : NULL)
-      );
-    }
-  }
-
-  return sizeof($items) > 0 ? theme('item_list', $items) : '';
+	while ($node = db_fetch_object($result)) {
+		$content = node_load($node->nid);
+		
+		if($image){
+			$x=$content->$field_img;
+			$path_node=base_path();
+			$path_node.=$content->path;
+			if($field_imgcache && $field_imgcache!="No Preset"){ //recurso imagecache
+				$items[] = '<div class="similar-teaser"><a href="'.$path_node.'">'.theme('imagecache', $field_imgcache, $x[0]['filepath']).'</a></div><div class="similar-title">'.
+					l($content->title,
+					  'node/'. $node->nid,
+					  array(
+						'attributes' => variable_get('similar_rel_nofollow', 0) ? array('rel' => 'nofollow') : NULL,
+						'absolute' => TRUE
+					  )
+					);
+			}else{
+				$items[] = '<div class="similar-teaser"><a href="'.$path_node.'"><img border="0" src='.base_path().$x[0]['filepath'].' height="60px" width="60px"></a></div><div class="similar-title">'.
+					l($content->title,
+					  'node/'. $node->nid,
+					  array(
+						'attributes' => variable_get('similar_rel_nofollow', 0) ? array('rel' => 'nofollow') : NULL,
+						'absolute' => TRUE
+					  )
+					);
+			}
+		}else{
+			if ($teaser) {
+			  $items[] = '<div class="similar-title">'.
+				l($content->title,
+				  'node/'. $node->nid,
+				  array(
+					'attributes' => variable_get('similar_rel_nofollow', 0) ? array('rel' => 'nofollow') : NULL,
+					'absolute' => TRUE
+				  )
+				) .
+				'</div><div class="similar-teaser">'. check_markup($content->teaser, $content->format, FALSE) .'</div>';
+			}else{
+			  $items[] = l(
+				$content->title,
+				'node/'. $node->nid,
+				array('attributes' => variable_get('similar_rel_nofollow', 0) ? array('rel' => 'nofollow') : NULL)
+			  );
+			}
+		}
+	}
+
+	if($image){
+		$table_attributes = array('id' => 'similar-image-table', 'align' => 'center' );
+		return sizeof($items) > 0 ? theme('table', $items, null, $table_attributes) : '';
+	}else{
+		return sizeof($items) > 0 ? theme('item_list', $items) : '';
+	}
 }

