Index: html2book.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/html2book/html2book.module,v
retrieving revision 1.2
diff -u -r1.2 html2book.module
--- html2book.module	5 Apr 2009 13:35:56 -0000	1.2
+++ html2book.module	25 Apr 2010 15:26:29 -0000
@@ -89,7 +89,7 @@
  * Implementation of hook_nodeapi().
  */
 function html2book_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
-  if ($node->type == 'book' && $node->html2book && user_access('use html2book')) {
+  if ($node->type == 'book' && isset($node->html2book) && user_access('use html2book')) {
     switch ($op) {
     case 'presave':
       $items = preg_split('/<h(.*)>/U', $node->body, -1, PREG_SPLIT_DELIM_CAPTURE );
@@ -97,8 +97,9 @@
       $node->body = $items[0];
       $node->teaser = node_teaser($node->body);
       break;
-      case 'insert':
-        html2book_split($node);
+    case 'update':  
+    case 'insert':
+        html2book_split($node, $op);
         unset($node->temp);
       break;
     }
@@ -108,7 +109,7 @@
 /**
  * html2book operation.
  */
-function html2book_split(&$node) {
+function html2book_split(&$node, $op) {
   // This may take some time since new nodes are created.
   $original_time = ini_get('max_execution_time');
   ini_set('max_execution_time', 0);
@@ -143,6 +144,26 @@
           // and adjust the parent body and teaser.
           $parent = array(0 => $node->nid);
           $book = array(0 => $node);
+          //Update hack. save_node spirals into a infinite loop, so 
+          //check if the initial page is part of a book. If not -
+          //create a new book (:-)
+          if($op == 'update'){
+			  if($node->book['bid'] == 0){
+					module_load_include('inc', 'book', 'book.pages');
+					$formvals = array();
+					$formvals['values']['book']['bid'] = $node->nid;
+					$formvals['values']['book']['weight'] = 0;
+					drupal_execute('book_outline_form', $formvals, (object)$node);
+				  }
+			  }
+          if($op == 'insert'){
+			  if($node->book['bid'] == 0 || !isset($node->book['bid'])){
+						$node->book['bid'] = $node->nid;
+						node_save($node);
+				  }
+			
+			}
+			//node_save($node);
           $page = 1;
         }
         else {
@@ -192,4 +213,4 @@
   $node->html2book = 0;
   // Reset max_execution_time
   ini_set('max_execution_time', $original_time);
-}
\ No newline at end of file
+}
