Index: modules/comment.module =================================================================== RCS file: /cvs/drupal/drupal/modules/comment.module,v retrieving revision 1.312 diff -u -r1.312 comment.module --- modules/comment.module 2 Dec 2004 20:24:53 -0000 1.312 +++ modules/comment.module 3 Dec 2004 22:53:00 -0000 @@ -384,7 +384,7 @@ $output .= theme('box', t('Reply'), t("This discussion is closed: you can't post new comments.")); } else if (user_access('post comments')) { - $output .= theme('comment_form', array('pid' => $pid, 'nid' => $nid), t('Reply')); + $output .= theme('comment_form', array_merge($_SESSION['comment_anon'], array('pid' => $pid, 'nid' => $nid)), t('Reply')); } else { $output .= theme('box', t('Reply'), t('You are not authorized to post comments.')); @@ -468,7 +468,7 @@ // Preview the comment. $output .= theme('comment_view', $comment, theme('links', module_invoke_all('link', 'comment', $comment, 1))); - $output .= theme('comment_form', $edit, t('Reply')); + $output .= theme('comment_form', array_merge($_SESSION['comment_anon'], $edit), t('Reply')); 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 = 0', $edit['pid'])); @@ -644,6 +644,25 @@ } } +/** + * Implementation of hook_comment + */ +function comment_comment($op, $comment) { + if (($op == 'insert' || $op == 'update')) { + // set or delete the anonymous comment cookie depending on the state + // of the 'remember me' checkbox (if applicable) + if ($comment['remember']) { + $fields = array('name', 'mail', 'homepage', 'remember'); + foreach ($fields as $field) { + $_SESSION['comment_anon'][$field] = $comment[$field]; + } + } + elseif (isset($comment['remember'])) { + unset($_SESSION['comment_anon']); + } + } +} + function comment_links($comment, $return = 1) { global $user; @@ -881,7 +900,7 @@ // If enabled, show new comment form. if (user_access('post comments') && node_comment_mode($nid) == 2 && variable_get('comment_form_location', 0)) { - $output .= theme('comment_form', array('nid' => $nid), t('Post new comment')); + $output .= theme('comment_form', array_merge($_SESSION['comment_anon'], array('nid' => $nid)), t('Post new comment')); } } return $output; @@ -1366,6 +1385,7 @@ $form .= form_textfield(t('Your name'), 'name', $edit['name'] ? $edit['name'] : variable_get('anonymous', 'Anonymous') , 20, 40); $form .= form_textfield(t('E-mail'), 'mail', $edit['mail'], 20, 40); $form .= form_textfield(t('Homepage'), 'homepage', $edit['homepage'], 20, 40); + $form .= form_checkbox('Remember me', 'remember', 1, $edit['remember']); } else if (variable_get('comment_anonymous', 0) == 2) { $form .= form_textfield(t('Your name'), 'name', $edit['name'] ? $edit['name'] : variable_get('anonymous', 'Anonymous') , 20, 40, NULL, NULL, TRUE);