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 04:38:04 -0000 @@ -342,6 +342,20 @@ } } +function comment_get_anon() { + $fields = array('name', 'mail', 'homepage', 'remember'); + $anon = unserialize($_COOKIE['comment_anon']); + foreach ($fields as $field) { + if ($val = $_POST['edit'][$field]) { + $values[$field] = $val; + } + elseif ($val = $anon[$field]) { + $values[$field] = $val; + } + } + return $values ? $values : array(); +} + function comment_reply($nid, $pid = NULL) { // set the breadcrumb trail $node = node_load(array('nid' => $nid)); @@ -384,7 +398,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('pid' => $pid, 'nid' => $nid)+comment_get_anon(), t('Reply')); } else { $output .= theme('box', t('Reply'), t('You are not authorized to post comments.')); @@ -468,7 +482,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', $edit+comment_get_anon(), 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 +658,27 @@ } } +/** + * 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'); + $values = array(); + foreach ($fields as $field) { + $values[$field] = $comment[$field]; + } + setcookie('comment_anon', serialize($values)); + } + elseif (isset($comment['remember'])) { + setcookie('comment_anon', ''); + } + } +} + function comment_links($comment, $return = 1) { global $user; @@ -881,7 +916,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('nid' => $nid)+comment_get_anon(), t('Post new comment')); } } return $output; @@ -1366,6 +1401,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);