Index: contrib/image_attach/image_attach.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/image/contrib/image_attach/image_attach.module,v
retrieving revision 1.42
diff -u -r1.42 image_attach.module
--- contrib/image_attach/image_attach.module	17 Aug 2008 09:06:57 -0000	1.42
+++ contrib/image_attach/image_attach.module	11 Oct 2008 11:05:10 -0000
@@ -281,8 +281,10 @@
       break;
 
     case 'load':
-      $iid = db_result(db_query("SELECT iid FROM {image_attach} WHERE nid=%d", $node->nid));
-      return array('iid' => $iid);
+      if(_image_attach_checkcondition($node)) {
+        $iid = db_result(db_query("SELECT iid FROM {image_attach} WHERE nid=%d", $node->nid));
+        return array('iid' => $iid);
+      }
 
     // Pass the body and teaser objects to the theme again to add the images
     case 'view':
@@ -391,3 +393,44 @@
   }
 }
 
+/**
+ * Check for conditions to attach image.
+ * Condition files have to be placed in the actual themes directory.
+ * The files are loaded in the following order (first match wins):
+ * imageattach-nid.cond.php
+ * imageattach-type-nid.cond.php
+ * imageattach-type.cond.php
+ * imageattach.cond.php
+ *
+ * The condition file has to set the variable
+ * $returnvalue 
+ * either to true (attach image), or to false (do not attach)
+ *
+ */
+function _image_attach_checkcondition(&$node) {
+  $pathtocondition = path_to_theme() ."/imageattach";
+  /* all files which can include different conditions depending on the node loaded */
+  $conditiontests = array();
+  $conditiontests[0] = $pathtocondition ."-". $node->nid.".cond.php";
+  $conditiontests[1] = $pathtocondition ."-". $node->type ."-". $node->nid.".cond.php";
+  $conditiontests[2] = $pathtocondition ."-". $node->type .".cond.php";
+  $conditiontests[3] = $pathtocondition .".cond.php";
+  
+  foreach($conditiontests as $conditionfile){
+    /* only first match counts! */
+    if(file_exists($conditionfile)) {
+      /* conditionfile needs to return true if image should be attached */
+      if(_image_attach_checksinglecondition($conditionfile)) {
+        return true;
+      } else {
+        return false;
+      }
+    }
+  }
+  return true;
+}
+
+function _image_attach_checksinglecondition($conditionfile) {
+  require_once($conditionfile);
+  return $returnvalue;
+}
\ No newline at end of file
