Binary files nodeimageblock/.DS_Store and nodeimageblock.new/.DS_Store differ
diff -urpN nodeimageblock/README.txt nodeimageblock.new/README.txt
--- nodeimageblock/README.txt	2006-02-09 16:29:13.000000000 +0100
+++ nodeimageblock.new/README.txt	2007-12-01 14:11:51.000000000 +0100
@@ -4,30 +4,40 @@ Author: Mike Carter <mike@ixis.co.uk>
 
 Description
 ===========
+
 Displays all images that are attached to any node using the upload.module.
 
 
 Requirements
 ============
 
-* Drupal 4.5+ installation
-* upload.module to attach images to nodes
+Drupal 5.x installation with upload.module enabled. Optionally you can also use
+the Imagecache module.
 
 
 Installation
 ============
-* Copy the 'nodeimageblock' module directory in to your Drupal
-modules directory as usual.
 
+Copy the 'nodeimageblock' module directory to your Drupal modules directory as
+usual.
 
-Usage
-=====
-When editing a node, attach an image to it using the upload.module functionality.
 
-Untick the 'list' option to prevent the image(s) from being listed to
-the public at the end of the node.
+Configuration
+=============
+
+Go to Blocks administer page (admin/build/block) and click on the Node Image
+block's configuration link. In addition to the usual block settings, this
+module provides following settings:
 
-In the Blocks configuration page (?q=admin/block) enable the 'Node Image' block
-and assign it to a region on the page.
+  * Images to show: Select if the attached images must be listed or not listed
+    or if doesn't matter for it to be showed.
 
+  * Imagecache preset: Select the Imagecache preset to use for the images
+    shown. This settings is avaiable only if the Imagecache module is enabled.
+
+
+Usage
+=====
 
+When editing a node, attach an image to it using the upload.module
+functionality.
diff -urpN nodeimageblock/nodeimageblock.info nodeimageblock.new/nodeimageblock.info
--- nodeimageblock/nodeimageblock.info	1970-01-01 01:00:00.000000000 +0100
+++ nodeimageblock.new/nodeimageblock.info	2007-12-01 14:11:51.000000000 +0100
@@ -0,0 +1,4 @@
+; $Id$
+name = Node Image Block
+description = Provides a block to displays all images attached to a node.
+dependencies = upload
diff -urpN nodeimageblock/nodeimageblock.module nodeimageblock.new/nodeimageblock.module
--- nodeimageblock/nodeimageblock.module	2006-03-06 19:19:34.000000000 +0100
+++ nodeimageblock.new/nodeimageblock.module	2007-12-01 23:36:52.000000000 +0100
@@ -4,93 +4,123 @@
  *
  * @author: Mike Carter <mike@ixis.co.uk>
  */
-
+ 
+/**
+ * Bitwise flag for testing if an file that is listed should be viewed.
+ */
+define('INCLUDE_LISTED', 0x01);
 
 /**
- * Implementation of hook_help().
+ * Bitwise flag for testing if an file that is not listed should be viewed.
  */
-function nodeimageblock_help($section) {
-  switch ($section) {
-    case 'admin/modules#description':
-      return t('Provides a block to displays all images attached to a node.');
-  }
-}
+define('INCLUDE_NOT_LISTED', 0x02);
 
 /**
  * Implementation of hook_block().
  *
  * Displays all images that are attached to the current node
  */
-function nodeimageblock_block($op = 'list', $delta = 0) {
+function nodeimageblock_block($op = 'list', $delta = 0, $edit = array()) {
   if ($op == 'list') {
-	  $block[0]['info'] = 'Node Image';
+    $block[0]['info'] = 'Node Image';
+  }
+  elseif ($op == 'configure') {
+
+    // Which images to include
+    $options = array(
+      INCLUDE_LISTED | INCLUDE_NOT_LISTED  => 'All attached images',
+      INCLUDE_LISTED                       => 'Only attached images that are listed',
+      INCLUDE_NOT_LISTED                   => 'Only attached images that are not listed',
+    );
+    $form['nodeimageblock_images_to_include'] = array(
+      '#type' => 'select',
+      '#title' => 'Images to show',
+      '#description' => 'Select which attached images to show.',
+      '#options' => $options,
+      '#default_value' => variable_get('nodeimageblock_images_to_include', INCLUDE_LISTED | INCLUDE_NOT_LISTED),
+    );
+
+    // Select imagecache preset to use
+    if (module_exists('imagecache')) {
+      $options = _imagecache_get_presets();
+      $options[0] = t('<none>');
+      ksort($options);
+      $form['nodeimageblock_imagecache_preset'] = array(
+        '#type' => 'select',
+        '#title' => 'Imagecache preset',
+        '#description' => 'Select the Imagecache preset to use for the images in the Node Image Block.',
+        '#options' => $options,
+        '#default_value' => variable_get('nodeimageblock_imagecache_preset', 0),
+      );
+    }
+
+    return $form;
+  }
+  elseif ($op == 'save') {
+    variable_set('nodeimageblock_images_to_include', $edit['nodeimageblock_images_to_include']);
+    variable_set('nodeimageblock_imagecache_preset', $edit['nodeimageblock_imagecache_preset']);
   }
-  elseif($op = 'view') {
-	  if($nid = _nodeimageblock_getnid()) {
-  		if ($node = node_load(array('nid' => $nid))) {
-
-  		  // Get all images associated with this node
-  			$imagesrc = _nodeimageblock_get_node_images($node);
-
-  			if(count($imagesrc) > 0) {
-  			  $output = '';
-    			foreach($imagesrc as $img) {
-      			$output .= theme('nodeimageblock_block_item', $node, $img);
+  elseif ($op == 'view') {
+    if (arg(0) == 'node') {
+      $nid = arg(1);
+      if ($node = node_load(array('nid' => $nid))) {
+
+        // Get all images associated with this node
+        $images = _nodeimageblock_get_node_images($node);
+
+        if (count($images) > 0) {
+          $output = '';
+          if (($imagecache_preset = variable_get('nodeimageblock_imagecache_preset', 0)) && module_exists('imagecache')) {
+            $imagecache_preset = _imagecache_preset_load($imagecache_preset);
+            foreach($images as $img) {
+              $html = theme('imagecache', $imagecache_preset, $img->filepath, $img->description, $img->description);
+              $output .= theme('nodeimageblock_block_item', $html, $img);
+            }
+          }
+          else {
+            foreach($images as $img) {
+              $html = theme('image', $img->filepath, $img->description, $img->description);
+              $output .= theme('nodeimageblock_block_item', $html, $img);
+            }
           }
 
-    			$block['subject'] = '';
-    			$block['content'] = theme('nodeimageblock_block', $output);
-  			}
-  		}
-	  }
+          $block['subject'] = '';
+          $block['content'] = theme('nodeimageblock_block', $output);
+        }
+      }
+    }
   }
 
   return $block;
 }
 
-function _nodeimageblock_getnid(){
-    $path = drupal_lookup_path('source', $_GET['q']);
-    if($path == false){
-        $path = $_GET['q'];
-    }
-    $pathvars = explode('/', $path);
-    if ($pathvars[0] == 'node'){
-        $nid = $pathvars[1];
-    }
-    return $nid;
-}
-
 function theme_nodeimageblock_block($items) {
-	$output  = '<div id="nodeimageblock">';
-	$output .= $items;
-	$output .= '</div>';
-	return $output;
+  $output  = '<div id="nodeimageblock">';
+  $output .= $items;
+  $output .= '</div>';
+  return $output;
 }
 
-function theme_nodeimageblock_block_item($node, $imagesrc) {
-	$output = '
-	<div class="nodeimage">
-	    <img src="' . $imagesrc . '" alt="" />
-	</div>';
+function theme_nodeimageblock_block_item($html, $img) {
+  $output = '
+  <div class="nodeimage">
+    '. $html .'
+		<p>'. $img->description .'</p>
+  </div>';
 
-	return $output;
+  return $output;
 }
 
 function _nodeimageblock_get_node_images($node) {
-	$filepath = '';
-
-	// -- if upload.module is enabled
-	if($files = module_invoke('upload', 'load', $node)) {
-		$image_mime = array("image/gif", "image/png", "image/jpeg", "image/pjpeg");
-		$images = array();
-
-		foreach($files as $key => $file){
-
-			// --- Is the file an image?
-			if(in_array($file->filemime, $image_mime)) {
-				$images[] = file_create_url($file->filepath);
-			}
-		}
-	}
-	return $images;
+  static $image_mime = array("image/gif", "image/png", "image/jpeg", "image/pjpeg");
+  $flags = variable_get('nodeimageblock_images_to_include', INCLUDE_LISTED | INCLUDE_NOT_LISTED);
+  if ($files = module_invoke('upload', 'load', $node)) {
+    $images = array();
+    foreach ($files as $file) {
+      if(in_array($file->filemime, $image_mime) && ($flags & INCLUDE_LISTED && $file->list || $flags & INCLUDE_NOT_LISTED && !$file->list)) {
+        $images[] = $file;
+      }
+    }
+  }
+  return $images;
 }
