Index: CHANGELOG.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/themekey/CHANGELOG.txt,v
retrieving revision 1.31.2.56
diff -u -r1.31.2.56 CHANGELOG.txt
--- CHANGELOG.txt	13 Jan 2010 14:19:35 -0000	1.31.2.56
+++ CHANGELOG.txt	15 Jan 2010 14:25:32 -0000
@@ -4,6 +4,7 @@
 ----------------------------------
 [#682626] mkalkbrenner: added setting to treat paths case sensitive or case insensitive
 [       ] mkalkbrenner: added possible value 'neutral' to property node:language
+[#684868] mkalkbrenner: Imagecache breaks, avoid node_load() in hook_init()
 
 
 ThemeKey 6.x-2.0-beta7, 2009-01-12
Index: themekey_ui.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/themekey/themekey_ui.module,v
retrieving revision 1.5.2.7
diff -u -r1.5.2.7 themekey_ui.module
--- themekey_ui.module	5 Jan 2010 21:35:33 -0000	1.5.2.7
+++ themekey_ui.module	15 Jan 2010 14:25:32 -0000
@@ -69,11 +69,18 @@
 function themekey_ui_nid2theme($nid) {
   global $custom_theme;
 
-  if ($node = node_load($nid)) {
-    if (!empty($node->themekey_ui_theme) && themekey_check_theme_enabled($node->themekey_ui_theme)) {
-      $custom_theme = $node->themekey_ui_theme;
-      return 'static';
-    }
+  // node_load() must not be called from hook_init().
+  // Therefor we have to execute SQL here using hook_nodeapi().
+  $node = new stdClass();
+  $node->nid = $nid;
+  $node->vid = themekey_node_get_simple_node_property($nid, 'vid');
+  $node->type = themekey_node_get_simple_node_property($nid, 'type');
+
+  themekey_ui_nodeapi($node, 'load');
+
+  if (!empty($node->themekey_ui_theme) && themekey_check_theme_enabled($node->themekey_ui_theme)) {
+    $custom_theme = $node->themekey_ui_theme;
+    return 'static';
   }
 
   return NULL;
Index: modules/themekey.node.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/themekey/modules/themekey.node.inc,v
retrieving revision 1.9.2.8
diff -u -r1.9.2.8 themekey.node.inc
--- modules/themekey.node.inc	13 Jan 2010 14:19:35 -0000	1.9.2.8
+++ modules/themekey.node.inc	15 Jan 2010 14:25:33 -0000
@@ -155,11 +155,19 @@
  *   the value of the property or NULL
  */
 function themekey_node_get_simple_node_property($nid, $property) {
-  // node should already be returned from cache at this point
-  if ($node = node_load($nid)) {
-    return $node->$property;
+  static $nodes = array();
+
+  if (!isset($nodes[$nid])) {
+    // node_load() must not be called from hook_init(). Therefor we have to execute SQL here
+    $nodes[$nid] = db_fetch_array(db_query('SELECT * FROM {node} WHERE nid = %d', $nid));
+  }
+
+  if (isset($nodes[$nid][$property])) {
+    return $nodes[$nid][$property];
+  }
+  else {
+    return NULL;
   }
-  return NULL;
 }
 
 
Index: modules/themekey.book.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/themekey/modules/themekey.book.inc,v
retrieving revision 1.5.2.4
diff -u -r1.5.2.4 themekey.book.inc
--- modules/themekey.book.inc	4 Jan 2010 15:00:42 -0000	1.5.2.4
+++ modules/themekey.book.inc	15 Jan 2010 14:25:32 -0000
@@ -57,13 +57,7 @@
  *   or NULL if no value could be mapped
  */
 function themekey_book_nid2bid($nid, $object = NULL) {
-  if ($node = node_load($nid)) {
-    if (!empty($node->book['bid'])) {
-      return $node->book['bid'];
-    }
-  }
-
-  return NULL;
+  return themekey_book_get_simple_book_property($nid, 'bid');
 }
 
 
@@ -83,11 +77,43 @@
  *   or NULL if no value could be mapped
  */
 function themekey_book_nid2has_children($nid, $object = NULL) {
-  if ($node = node_load($nid)) {
-    if (!empty($node->book['has_children'])) {
-      return $node->book['has_children'];
+  return themekey_book_get_simple_book_property($nid, 'has_children');
+}
+
+
+/**
+ * Helper function that loads a book and returns the
+ * value of a book's property.
+ *
+ * @param $nid
+ *   a node id
+ *
+ * @param $property
+ *   name of a nodes attribute as string
+ *
+ * @return
+ *   the value of the property or NULL
+ */
+function themekey_book_get_simple_book_property($nid, $property) {
+  static $books = array();
+
+  if (!isset($books[$nid])) {
+    $node = new stdClass();
+    $node->nid = $nid;
+
+    // node_load() must not be called from hook_init().
+    // Therefor we have to execute SQL here using book's hook_nodeapi().
+    $info = book_nodeapi($node, 'load', NULL, NULL);
+
+    if (!empty($info['book'])) {
+      $books[$nid] = $info['book'];
     }
   }
 
-  return NULL;
+  if (isset($books[$nid][$property])) {
+    return $books[$nid][$property];
+  }
+  else {
+    return NULL;
+  }
 }
