--- /opt/build/drupal-4.7.6/modules/comment.module 2007-01-30 05:39:27.000000000 +0800 +++ modules/comment.module 2007-04-03 16:20:19.000000000 +0800 @@ -314,26 +314,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); } @@ -491,7 +474,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.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', $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'); @@ -509,7 +492,7 @@ function comment_reply($nid, $pid = NULL else if (user_access('access content')) { $output .= node_view($node); } - + // should we show the reply box? if (node_comment_mode($nid) != COMMENT_NODE_READ_WRITE) { drupal_set_message(t("This discussion is closed: you can't post new comments."), 'error'); @@ -712,7 +695,7 @@ 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.signature, 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_args = array($cid); if (!user_access('administer comments')) { $query .= ' AND c.status = %d'; @@ -729,7 +712,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.signature, 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_args = array($nid); if (!user_access('administer comments')) { @@ -1324,7 +1307,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']); @@ -1386,6 +1369,9 @@ function comment_form_add_preview($form, $comment->uid = $account->uid; $comment->name = check_plain($account->name); } + else { + $comment->name = variable_get('anonymous', t('Anonymous')); + } $comment->timestamp = $edit['timestamp'] ? $edit['timestamp'] : time(); $output .= theme('comment_view', $comment); } @@ -1399,7 +1385,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, 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); @@ -1555,6 +1541,7 @@ function theme_comment($comment, $links $output .= '
'. l($comment->subject, $_GET['q'], NULL, NULL, "comment-$comment->cid") . ' ' . theme('mark', $comment->new) ."
\n"; $output .= '
'. t('by %a on %b', array('%a' => theme('username', $comment), '%b' => format_date($comment->timestamp))) ."
\n"; $output .= '
'. $comment->comment .'
'; + $output .= theme('user_signature', $comment->signature); $output .= ''; $output .= ''; return $output; --- /opt/build/drupal-4.7.6/modules/node.module 2007-01-30 05:39:28.000000000 +0800 +++ modules/node.module 2007-04-03 13:59:24.000000000 +0800 @@ -382,10 +382,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.moderate, 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.moderate, n.sticky, r.timestamp AS revision_timestamp, r.title, r.body, r.teaser, r.log, r.format, u.uid, u.name, u.signature, 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)); } 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.moderate, 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.moderate, n.sticky, r.timestamp AS revision_timestamp, r.title, r.body, r.teaser, r.log, r.format, u.uid, u.name, u.signature, 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)); } if ($node->nid) { --- /opt/build/drupal-4.7.6/modules/user.module 2007-01-30 03:37:48.000000000 +0800 +++ modules/user.module 2007-04-03 16:14:25.000000000 +0800 @@ -1,5 +1,5 @@ '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.'), + ); + } + // Picture/avatar: if (variable_get('user_pictures', 0)) { $form['picture'] = array('#type' => 'fieldset', '#title' => t('Picture'), '#weight' => 1); @@ -2156,8 +2171,41 @@ function user_autocomplete($string) { $result = db_query_range("SELECT name FROM {users} WHERE LOWER(name) LIKE LOWER('%s%%')", $string, 0, 10); while ($user = db_fetch_object($result)) { $matches[$user->name] = check_plain($user->name); - } + } } print drupal_to_js($matches); exit(); } + +/** + * Implementation of hook_comment(). + * + * Adds signatures to comments. + */ +function user_comment($comment, $op) { + if ($op == 'view') { + if ( (isset($comment->signature)) && (strlen($comment->signature)) ) { + $comment->signature = check_markup($comment->signature, $comment->format); + } + else { + $comment->signature = ''; + } + } +} + +/** + * Theme output of signature. + * + * @ingroup themeable + */ +function theme_user_signature($signature) { + $output = ''; + if ($signature) { + $output .= '
'; + $output .= '
'. '–' .'
'; + $output .= $signature; + $output .= '
'; + } + + return $output; +}