Index: modules/comment/comment.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v
retrieving revision 1.476
diff -u -F^f -r1.476 comment.module
--- modules/comment/comment.module	18 Aug 2006 18:58:45 -0000	1.476
+++ modules/comment/comment.module	19 Aug 2006 21:30:13 -0000
@@ -355,26 +355,9 @@ function comment_nodeapi(&$node, $op, $a
 
 /**
  * Implementation of hook_user().
- *
- * Provides signature customization for the user's comments.
  */
 function comment_user($type, $edit, &$user, $category = NULL) {
-  if ($type == 'form' && $category == 'account') {
-    // when user tries to edit his own data
-    $form['comment_settings'] = array(
-      '#type' => 'fieldset',
-      '#title' => t('Comment settings'),
-      '#collapsible' => TRUE,
-      '#weight' => 4);
-    $form['comment_settings']['signature'] = array(
-      '#type' => 'textarea',
-      '#title' => t('Signature'),
-      '#default_value' => $edit['signature'],
-      '#description' => t('Your signature will be publicly displayed at the end of your comments.'));
-
-    return $form;
-  }
-  elseif ($type == 'delete') {
+  if ($type == 'delete') {
     db_query('UPDATE {comments} SET uid = 0 WHERE uid = %d', $user->uid);
     db_query('UPDATE {node_comment_statistics} SET last_comment_uid = 0 WHERE last_comment_uid = %d', $user->uid);
   }
@@ -532,7 +515,7 @@ function comment_reply($nid, $pid = NULL
       // if this is a reply to another comment, show that comment first
       // else, we'll just show the user the node they're commenting on.
       if ($pid) {
-        if ($comment = db_fetch_object(db_query('SELECT c.*, u.uid, u.name AS registered_name, u.picture, u.data FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d AND c.status = %d', $pid, COMMENT_PUBLISHED))) {
+        if ($comment = db_fetch_object(db_query('SELECT c.*, u.uid, u.name AS registered_name, u.picture, u.signature AS user_signature, u.data FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d AND c.status = %d', $pid, COMMENT_PUBLISHED))) {
           if ($comment->nid != $nid) {
             // Attempting to reply to a comment not belonging to the current nid.
             drupal_set_message(t('The comment you are replying to does not exist.'), 'error');
@@ -770,13 +753,13 @@ function comment_render($node, $cid = 0)
 
     if ($cid) {
       // Single comment view.
-      $query = 'SELECT c.cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, c.homepage, u.uid, u.name AS registered_name, u.picture, u.data, c.score, c.users, c.status FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d';
+      $query = 'SELECT c.cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, c.homepage, u.uid, u.name AS registered_name, u.picture, u.signature AS user_signature, u.data, c.score, c.users, c.status FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d';
       $query_args = array($cid);
       if (!user_access('administer comments')) {
         $query .= ' AND c.status = %d';
         $query_args[] = COMMENT_PUBLISHED;
       }
-      $query .= ' GROUP BY c.cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, u.picture, c.homepage, u.uid, u.name, u.picture, u.data, c.score, c.users, c.status';
+      $query .= ' GROUP BY c.cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, c.homepage, u.uid, u.name, u.picture, u.signature, u.data, c.score, c.users, c.status';
       $result = db_query($query, $query_args);
 
       if ($comment = db_fetch_object($result)) {
@@ -794,7 +777,7 @@ function comment_render($node, $cid = 0)
     else {
       // Multiple comment view
       $query_count = 'SELECT COUNT(*) FROM {comments} WHERE nid = %d';
-      $query = 'SELECT c.cid as cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, c.homepage, u.uid, u.name AS registered_name, u.picture, u.data, c.score, c.users, c.thread, c.status FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.nid = %d';
+      $query = 'SELECT c.cid as cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, c.homepage, u.uid, u.name AS registered_name, u.picture, u.signature AS user_signature, u.data, c.score, c.users, c.thread, c.status FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.nid = %d';
 
       $query_args = array($nid);
       if (!user_access('administer comments')) {
@@ -803,7 +786,7 @@ function comment_render($node, $cid = 0)
         $query_args[] = COMMENT_PUBLISHED;
       }
 
-      $query .= ' GROUP BY c.cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, u.picture, c.homepage, u.uid, u.name, u.picture, u.data, c.score, c.users, c.thread, c.status';
+      $query .= ' GROUP BY c.cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, c.homepage, u.uid, u.name, u.picture, u.signature, u.data, c.score, c.users, c.thread, c.status';
 
       /*
       ** We want to use the standard pager, but threads would need every
@@ -1397,7 +1380,7 @@ function comment_form($edit, $title = NU
     $form['subject'] = array('#type' => 'textfield', '#title' => t('Subject'), '#maxlength' => 64, '#default_value' => $edit['subject']);
   }
 
-  $form['comment_filter']['comment'] = array('#type' => 'textarea', '#title' => t('Comment'), '#rows' => 15, '#default_value' => $edit['comment'] ? $edit['comment'] : $user->signature, '#required' => TRUE);
+  $form['comment_filter']['comment'] = array('#type' => 'textarea', '#title' => t('Comment'), '#rows' => 15, '#default_value' => $edit['comment'], '#required' => TRUE);
   $form['comment_filter']['format'] = filter_form($edit['format']);
 
   $form['cid'] = array('#type' => 'value', '#value' => $edit['cid']);
@@ -1473,7 +1456,7 @@ function comment_form_add_preview($form,
   $output = '';
 
   if ($edit['pid']) {
-    $comment = db_fetch_object(db_query('SELECT c.*, u.uid, u.name AS registered_name, u.picture, u.data FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d AND c.status = %d', $edit['pid'], COMMENT_PUBLISHED));
+    $comment = db_fetch_object(db_query('SELECT c.*, u.uid, u.name AS registered_name, u.signature AS user_signature, u.picture, u.data FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d AND c.status = %d', $edit['pid'], COMMENT_PUBLISHED));
     $comment = drupal_unpack($comment);
     $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
     $output .= theme('comment_view', $comment);
Index: modules/node/node.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/node/node.module,v
retrieving revision 1.676
diff -u -F^f -r1.676 node.module
--- modules/node/node.module	18 Aug 2006 18:58:46 -0000	1.676
+++ modules/node/node.module	19 Aug 2006 21:30:19 -0000
@@ -485,10 +485,10 @@ function node_load($param = array(), $re
   // No db_rewrite_sql is applied so as to get complete indexing for search.
   if ($revision) {
     array_unshift($arguments, $revision);
-    $node = db_fetch_object(db_query('SELECT n.nid, r.vid, n.type, n.status, n.created, n.changed, n.comment, n.promote, n.sticky, r.timestamp AS revision_timestamp, r.title, r.body, r.teaser, r.log, r.format, u.uid, u.name, u.picture, u.data FROM {node} n INNER JOIN {users} u ON u.uid = n.uid INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = %d WHERE '. $cond, $arguments));
+    $node = db_fetch_object(db_query('SELECT n.nid, r.vid, n.type, n.status, n.created, n.changed, n.comment, n.promote, n.sticky, r.timestamp AS revision_timestamp, r.title, r.body, r.teaser, r.log, r.format, u.uid, u.name, u.picture, u.signature AS user_signature, u.data FROM {node} n INNER JOIN {users} u ON u.uid = n.uid INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = %d WHERE '. $cond, $arguments));
   }
   else {
-    $node = db_fetch_object(db_query('SELECT n.nid, n.vid, n.type, n.status, n.created, n.changed, n.comment, n.promote, n.sticky, r.timestamp AS revision_timestamp, r.title, r.body, r.teaser, r.log, r.format, u.uid, u.name, u.picture, u.data FROM {node} n INNER JOIN {users} u ON u.uid = n.uid INNER JOIN {node_revisions} r ON r.vid = n.vid WHERE '. $cond, $arguments));
+    $node = db_fetch_object(db_query('SELECT n.nid, n.vid, n.type, n.status, n.created, n.changed, n.comment, n.promote, n.sticky, r.timestamp AS revision_timestamp, r.title, r.body, r.teaser, r.log, r.format, u.uid, u.name, u.picture, u.signature AS user_signature, u.data FROM {node} n INNER JOIN {users} u ON u.uid = n.uid INNER JOIN {node_revisions} r ON r.vid = n.vid WHERE '. $cond, $arguments));
   }
 
   if ($node->nid) {
Index: modules/user/user.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.module,v
retrieving revision 1.656
diff -u -F^f -r1.656 user.module
--- modules/user/user.module	18 Aug 2006 18:58:47 -0000	1.656
+++ modules/user/user.module	19 Aug 2006 21:30:24 -0000
@@ -1314,6 +1314,25 @@ function user_edit_form($uid, $edit, $re
     }
   }
 
+  // Signature:
+  foreach (node_get_types() as $type => $details) {
+    // Only show signature textarea if at least one node type is signature-enabled.
+    if (variable_get('user_signatures_'. $type, 0)) {
+      $form['signature_settings'] = array(
+        '#type' => 'fieldset',
+        '#title' => t('Signature settings'),
+        '#weight' => 1,
+      );
+      $form['signature_settings']['signature'] = array(
+        '#type' => 'textarea',
+        '#title' => t('Signature'),
+        '#default_value' => $edit['signature'],
+        '#description' => t('Your signature will be publicly displayed at the end of your comments.'),
+      );
+      break;
+    }
+  }
+
   // Picture/avatar:
   if (variable_get('user_pictures', 0)) {
     $form['picture'] = array('#type' => 'fieldset', '#title' => t('Picture'), '#weight' => 1);
@@ -2201,6 +2220,28 @@ function user_admin_settings() {
   $form['registration']['user_email_verification'] = array('#type' => 'checkbox', '#title' => t('Require e-mail verification when a visitor creates an account'), '#default_value' => variable_get('user_email_verification', TRUE), '#description' => t('If this box is checked, new users will be required to validate their e-mail address prior to logging into to the site, and will be assigned a system-generated password. With it unchecked, users will be logged in immediately upon registering, and may select their own passwords during registration.'));
   $form['registration']['user_registration_help'] = array('#type' => 'textarea', '#title' => t('User registration guidelines'), '#default_value' => variable_get('user_registration_help', ''), '#description' => t("This text is displayed at the top of the user registration form. It's useful for helping or instructing your users."));
 
+  // Signature settings.
+  $form['signatures'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Signature settings'),
+  );
+  $form['signatures']['user_signatures_add'] = array(
+    '#type' => 'radios',
+    '#title' => t('When to add signatures'),
+    '#options' => array(
+      0 => t('As posts and comments are created'),
+      1 => t('As posts and comments are viewed'),
+    ),
+    '#default_value' => variable_get('user_signatures_add', 0),
+    '#description' => t("Adding during create means posts will reflect user signatures at the time they were posted. Adding during view means that when a user's signature is updated, it will instantly be shown on all of that user's posts and comments."),
+  );  
+  $form['signatures']['user_signatures_format_description'] = array(
+    '#type' => 'item',
+    '#title' => t('Input format'),
+    '#value' => '<p>'. t("Select which input format should be allowed on users' signatures:") .'</p>',
+  );
+  $form['signatures']['user_signatures_format'] = filter_form(variable_get('user_signature_format', 1));
+
   // User e-mail settings.
   $form['email'] = array('#type' => 'fieldset', '#title' => t('User e-mail settings'));
   $form['email']['user_mail_welcome_subject'] = array('#type' => 'textfield', '#title' => t('Subject of welcome e-mail'), '#default_value' => _user_mail_text('welcome_subject'), '#maxlength' => 180, '#description' => t('Customize the subject of your welcome e-mail, which is sent to new members upon registering.') .' '. t('Available variables are:') .' !username, !site, !password, !uri, !uri_brief, !mailto, !date, !login_uri, !edit_uri, !login_url.');
@@ -2561,3 +2602,102 @@ function user_forms() {
   return $forms;
 }
 
+/**
+ * Implementation of hook_form_alter().
+ *
+ * Add user signature option to content type settings forms.
+ */
+function user_form_alter($form_id, &$form) {
+  if ($form_id == 'node_type_form') {
+    $type = $form['orig_type']['#value'];
+    $form['signature'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('User signatures'),
+      '#collapsible' => TRUE,
+      '#collapsed' => TRUE,
+      '#weight' => -1,
+    );
+    $form['signature']["user_signatures_$type"] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Show user signatures on this node type.'),
+      '#default_value' => variable_get("user_signatures_$type", 0),
+      '#description' => t("If enabled, users' signatures will be appended to the end of all posts and comments for this type."),
+    );
+    $form['#submit'] = array_merge($form['#submit'], array('user_signature_submit' => array($type)));
+  }
+}
+
+/**
+ * Submit callback; sets variable to track whether user signatures are enabled
+ * for the given node type.
+ */
+function user_signature_submit($form_id, $form_values, $type) {
+  if ($form_values["user_signatures_$type"]) {
+    variable_set("user_signatures_$type", 1);
+  }
+  else {
+    variable_set("user_signatures_$type", 0);
+  }
+}
+
+/**
+ * Implementation of hook_nodeapi().
+ *
+ * Append signatures to signature-enabled node types.
+ */
+function user_nodeapi(&$node, $op, $arg = 0) {
+  if (variable_get('user_signatures_'. $node->type, 0)) {
+    if ($op == 'view' && variable_get('user_signatures_add', 0)) {
+      $node->content['signature'] = array(
+        '#value' => theme('user_signature', $node->user_signature),
+        '#weight' => 1,
+      );
+    }
+    elseif ($op == 'insert' && !variable_get('user_signatures_add', 0)) {
+      $author = user_load(array('uid' => $node->uid));
+      db_query("UPDATE {node_revisions} SET body = '%s' WHERE nid = %d AND vid = %d", $node->body ."\n". theme('user_signature', $author->signature), $node->nid, $node->nid);
+    }
+  }
+}
+
+/**
+ * Implementation of hook_comment().
+ *
+ * Append signatures to comments, if the parent node type is signature-enabled.
+ */
+function user_comment(&$comment, $op) {
+  if ($op == 'view' && variable_get('user_signatures_add', 0)) {
+    // Display signatures on view
+    $node = node_load($comment->nid);
+    if (variable_get('user_signatures_'. $node->type, 0)) {
+      if (!empty($comment->user_signature)) {
+        $comment->comment .= theme('user_signature', $comment->user_signature);
+      }
+    }
+  }
+  elseif ($op == 'insert' && !variable_get('user_signatures_add', 0)) {
+    // Display signatures on insert
+    $node = node_load($comment['nid']);
+    $author = user_load(array('name' => $comment['author']));
+    if (variable_get('user_signatures_'. $node->type, 0)) {
+      db_query("UPDATE {comments} SET comment = '%s' WHERE cid = %d", $comment['comment'] ."\n". theme('user_signature', $author->signature), $comment['cid']);
+    }
+  }
+}
+
+/**
+ * Output a user's signature.
+ * 
+ * @ingroup themeable
+ */
+function theme_user_signature($signature) {
+  $output = '<div class="user_signature">';
+  // Note: check_markup is important, as without it people could enter potentially dangerous stuff like PHP.
+  $output .= check_markup("
+-- 
+$signature
+", variable_get('user_signatures_format', 1));
+  $output .= '</div>';
+
+  return $output;
+}
