? amazontools.txt
Index: amazon.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/amazontools/amazon.module,v
retrieving revision 1.63
diff -u -p -r1.63 amazon.module
--- amazon.module	25 Jan 2007 00:13:16 -0000	1.63
+++ amazon.module	25 Jun 2007 20:21:00 -0000
@@ -710,6 +710,12 @@ function amazon_settings() {
     '#width' => 60,
     '#height' => 5,
   );
+  $form['amazon_link_functionality'] = array(
+    '#title' => t('Link Functionality'),
+    '#type' => 'radios',
+    '#options' => array(t('Images link back to Amazon'),t('Disable image links'),t('Images link to product node')),
+    '#default_value' => variable_get('amazon_link_functionality', 0),
+  );
   return system_settings_form($form);
 }
 
@@ -1375,7 +1381,7 @@ function theme_amazon_block($selected_bo
   $book_image = $selected_book->mediumimageurl ? $selected_book->mediumimageurl : "$module_dir/images/missingm.gif";
   $blockcontent = '<div class="amazontools_block">';
   if ($is_review) {
-    $blockcontent .= "<a href=\"$review_url\">";
+    $blockcontent .= "review<a href=\"$review_url\">";
     $blockcontent .= "<img src=\"$book_image\" height=\"$selected_book->mediumimageheight\" width=\"$selected_book->mediumimagewidth\" alt=\"cover of $selected_book->title\" /><br />";
     $blockcontent .= '</a>';
     $blockcontent .= "<span class=\"amazontools_detailpage_link\"> <a href=\"$selected_book->detailpageurl\" target=\"_blank\">";
@@ -1386,12 +1392,8 @@ function theme_amazon_block($selected_bo
     $blockcontent .= '</a></span>';
   }
   else {
-    $blockcontent .= "<a href=\"$selected_book->detailpageurl\" target=\"_blank\">";
-    $blockcontent .= "<img src=\"$book_image\" height=\"$selected_book->mediumimageheight\" width=\"$selected_book->mediumimagewidth\" alt=\"cover of $selected_book->title\" /><br />";
-    $blockcontent .= '</a>';
-    $blockcontent .= "<a href=\"$selected_book->detailpageurl\" target=\"_blank\">";
-    $blockcontent .= $selected_book->title;
-    $blockcontent .= '</a>';
+    $blockcontent .= amazon_paint_image($node,$book_image,$selected_book);
+    $blockcontent .= amazon_paint_link($selected_book);
 
   }
   if ($selected_book->rating) {
@@ -1400,20 +1402,14 @@ function theme_amazon_block($selected_bo
   $blockcontent .= '</div>';
   return $blockcontent;
 }
-
 function theme_amazon_node($node) {
   $module_dir = drupal_get_path('module', 'amazon');
   $output = '';
   $output .= '<table class="amazontools_table">';
   $output .= '<tr>';
-  $output .= "<td><a href=\"$node->detailpageurl\" target=\"_blank\">";
-  if ($node->mediumimageurl) {
-    $output .= "<img src=\"$node->mediumimageurl\" height=\"$node->mediumimageheight\" width=\"$node->mediumimagewidth\" alt=\"cover of $node->title\" />";
-  }
-  else {
-    $output .= "<img src=\"$module_dir/images/missingm.gif\" height=\"150\" width=\"100\" alt=\"no image\" />";
-  }
-  $output .= "</a></td><td>";
+  $output .= "<td>";
+  $output .= amazon_paint_image($node);
+  $output .= "</td><td>";
   if ($node->type == 'amazon') {
     if ($node->detailpageurl) {
       $output .= "<a href=\"$node->detailpageurl\" target=\"_blank\">";
@@ -1477,3 +1473,51 @@ function theme_amazon_related_link($node
   $output .= '</tr></table>';
   return $output;
 }
+function amazon_paint_image($node,$book_image=null,$selected_book=null) {
+  $src = $book_image;
+  $height = $selected_book->mediumimageheight;
+  $width = $selected_book->mediumimagewidth;
+  if(!$src) {
+  	$src = $node->mediumimageurl;
+  	$height = $node->mediumimageheight;
+  	$width = $node->width;
+  }
+  if ($src) {
+    $image .= "<img src=\"$src\" height=\"$height\" width=\"$width\" alt=\"cover of $node->title\" />";
+  }
+  else {
+    $image .= "<img src=\"".drupal_get_path('module', 'amazon')."/images/missingm.gif\" height=\"150\" width=\"100\" alt=\"no image\" />";
+  }
+  switch(variable_get('amazon_link_functionality',0)) {
+  	case 0:
+  		$output .= l($image,$node->detailpageurl,array('target'=>'_blank'),null,null,false,true);
+  		break;
+  	case 1:
+  		$output .= $image;
+  		break;
+  	case 2:
+  		if(!$node->nid) {
+  			$node = db_fetch_object(db_query("SELECT nid,asin from {amazonnode} where asin = '%s'",$selected_book->asin));
+  		}
+  		$output .= l($image,'node/'.$node->nid,null,null,null,false,true);
+  		break;
+  }
+  return $output;
+}
+function amazon_paint_link($selected_book) {
+  $href = $selected_book->detailpageurl;
+  $title = $selected_book->title;
+  switch(variable_get('amazon_link_functionality',0)) {
+  	case 0:
+  		$output .= "<h4>".l($title,$href,array('target'=>'_blank'),null,null,false,false)."</h4>";
+  		break;
+  	case 1:
+  		$output .= "<h4>$title</h4>";
+  		break;
+  	case 2:
+  		$node = db_fetch_object(db_query("SELECT nid,asin from {amazonnode} where asin = '%s'",$selected_book->asin));
+  		$output .= "<h4>".l($title,'node/'.$node->nid,null,null,null,false,false)."</h4>";
+  		break;
+  }
+  return $output;
+}
\ No newline at end of file
