--- C:/Users/neoguru/Desktop/masquerade.module	Thu Sep 25 14:09:34 2008
+++ D:/WebServers/home/dd/www/modules/masquerade/masquerade.module	Wed Nov 05 15:19:31 2008
@@ -132,6 +132,18 @@
     '#default_value' => check_plain($test_user->name),
     '#description' => t('Enter the username of an account you wish to switch easily between via a menu item. The name must be an exisiting user.'),
   );
+  
+  $form['post_nodes_as_test_user'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Post admins\' nodes on behalf of test user'),
+    '#default_value' => variable_get('post_nodes_as_test_user', FALSE),
+  );
+  $form['post_comments_as_test_user'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Post admins\' comments on behalf of test user'),
+    '#default_value' => variable_get('post_comments_as_test_user', FALSE),
+  );
+
   $form['masquerade_quick_switches'] = array(
     '#type' => 'select',
     '#title' => t('Quick switch users'),
@@ -376,4 +388,53 @@
 
 function masquerade_version() {
   return str_replace(array('$RCSf'.'ile:', ',v', '$Re'.'vision: ', '$Da'.'te: ', '$'), '', '<p style="font-size:x-small">$RCSfile: masquerade.module,v $ version: <b>$Revision: 1.15.2.12 $</b>, $Date: 2008/09/25 12:09:34 $</p>');
+}
+
+
+/**
+ * Implementation of hook_nodeapi().
+ */
+function masquerade_nodeapi(&$node, $op, $teaser, $page) {
+  switch ($op) {
+    case 'submit':
+      if (variable_get('post_nodes_as_test_user', FALSE)) {
+        $user = user_load(array('uid' => $node->uid));
+      
+        $roles = array_keys(array_filter(variable_get('masquerade_admin_roles', array())));
+        $perm = ($user->uid == 1) || (array_intersect(array_keys($user->roles), $roles));
+        
+        if ($perm) {
+          $default_test_user = user_load(array('name' => variable_get('masquerade_test_user', '')));
+          $node->uid = $default_test_user->uid;
+          $node->name = $default_test_user->name;
+        }
+      }
+    break;
+  }
+}
+
+/**
+ * Implementation of hook_comment().
+ */
+function masquerade_comment(&$a1, $op) {
+  switch ($op) {
+    case 'insert':
+    case 'update':
+    case 'publish':
+      if (variable_get('post_comments_as_test_user', FALSE)) {
+        $user = user_load(array('uid' => $a1['uid']));
+      
+        $roles = array_keys(array_filter(variable_get('masquerade_admin_roles', array())));
+        $perm = ($user->uid == 1) || (array_intersect(array_keys($user->roles), $roles));
+        
+        if ($perm) {
+          $default_test_user = user_load(array('name' => variable_get('masquerade_test_user', '')));
+          db_query("UPDATE {comments} SET uid = %d, name = '%s' WHERE cid = %d", $default_test_user->uid, $default_test_user->name, $a1['cid']);
+
+          $a1['uid'] = $default_test_user->uid;
+          $a1['name'] = $default_test_user->name;
+        }
+      }
+    break;
+  }
 }
