Index: modules/comment/comment.js =================================================================== RCS file: /cvs/drupal/drupal/modules/comment/comment.js,v retrieving revision 1.12 diff -u -p -r1.12 comment.js --- modules/comment/comment.js 31 Aug 2009 05:51:08 -0000 1.12 +++ modules/comment/comment.js 9 Oct 2009 14:50:24 -0000 @@ -4,7 +4,7 @@ Drupal.behaviors.comment = { attach: function (context, settings) { $.each(['name', 'homepage', 'mail'], function () { - var cookie = Drupal.comment.getCookie('comment_info_' + this); + var cookie = $.cookie('Drupal.visitor.' + this); if (cookie) { $('#comment-form input[name=' + this + ']', context).once('comment').val(cookie); } @@ -12,25 +12,4 @@ Drupal.behaviors.comment = { } }; -Drupal.comment = {}; - -Drupal.comment.getCookie = function (name) { - var search = name + '='; - var returnValue = ''; - - if (document.cookie.length > 0) { - offset = document.cookie.indexOf(search); - if (offset != -1) { - offset += search.length; - var end = document.cookie.indexOf(';', offset); - if (end == -1) { - end = document.cookie.length; - } - returnValue = decodeURIComponent(document.cookie.substring(offset, end).replace(/\+/g, '%20')); - } - } - - return returnValue; -}; - })(jQuery); Index: modules/comment/comment.module =================================================================== RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v retrieving revision 1.778 diff -u -p -r1.778 comment.module --- modules/comment/comment.module 9 Oct 2009 07:19:43 -0000 1.778 +++ modules/comment/comment.module 9 Oct 2009 14:50:25 -0000 @@ -1637,7 +1637,8 @@ function comment_form($form, &$form_stat $node = node_load($comment->nid); if (!$user->uid && variable_get('comment_anonymous_' . $node->type, COMMENT_ANONYMOUS_MAYNOT_CONTACT) != COMMENT_ANONYMOUS_MAYNOT_CONTACT) { - $form_state['#attached']['js'][] = drupal_get_path('module', 'comment') . '/comment.js'; + $form['#attached']['library'][] = array('system', 'cookie'); + $form['#attached']['js'][] = drupal_get_path('module', 'comment') . '/comment.js'; } $comment = (array) $comment; @@ -1957,15 +1958,6 @@ function comment_form_validate($form, &$ $comment = (object) $form_state['values']; field_attach_form_validate('comment', $comment, $form, $form_state); - if ($user->uid === 0) { - foreach (array('name', 'homepage', 'mail') as $field) { - // Set cookie for 365 days. - if (isset($form_state['values'][$field])) { - setcookie('comment_info_' . $field, $form_state['values'][$field], REQUEST_TIME + 31536000, '/'); - } - } - } - if (isset($form_state['values']['date'])) { if (strtotime($form_state['values']['date']) === FALSE) { form_set_error('date', t('You have to specify a valid date.')); @@ -2068,6 +2060,11 @@ function comment_form_submit($form, &$fo $node = node_load($form_state['values']['nid']); $comment = comment_form_submit_build_comment($form, $form_state); if (user_access('post comments') && (user_access('administer comments') || $node->comment == COMMENT_NODE_OPEN)) { + // Save the anonymous user information to a cookie for reuse. + if (!$comment->uid) { + user_cookie_save($form_state['values']); + } + comment_save($comment); // Explain the approval queue if necessary. if ($comment->status == COMMENT_NOT_PUBLISHED) { @@ -2425,4 +2422,3 @@ function comment_filter_format_delete($f ->condition('format', $format->format) ->execute(); } - Index: modules/contact/contact.js =================================================================== RCS file: modules/contact/contact.js diff -N modules/contact/contact.js --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ modules/contact/contact.js 9 Oct 2009 14:50:25 -0000 @@ -0,0 +1,15 @@ +// $Id$ +(function ($) { + +Drupal.behaviors.contact = { + attach: function(context) { + $.each(['name', 'mail'], function () { + var cookie = $.cookie('Drupal.user.' + this); + if (cookie) { + $('#contact-site-form input[name=' + this + ']', context).once('comment').val(cookie); + } + }); + } +}; + +})(jQuery); Index: modules/contact/contact.pages.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/contact/contact.pages.inc,v retrieving revision 1.29 diff -u -p -r1.29 contact.pages.inc --- modules/contact/contact.pages.inc 9 Oct 2009 02:34:07 -0000 1.29 +++ modules/contact/contact.pages.inc 9 Oct 2009 14:50:25 -0000 @@ -52,6 +52,11 @@ function contact_site_form($form, &$form } } + if (!$user->uid) { + $form['#attached']['library'][] = array('system', 'cookie'); + $form['#attached']['js'][] = drupal_get_path('module', 'contact') . '/contact.js'; + } + $form['#token'] = $user->uid ? $user->name . $user->mail : ''; $form['name'] = array( '#type' => 'textfield', @@ -117,10 +122,15 @@ function contact_site_form_validate($for * Form submission handler for contact_site_form(). */ function contact_site_form_submit($form, &$form_state) { - global $language; + global $user, $language; $values = $form_state['values']; + // Save the anonymous user information to a cookie for reuse. + if (!$user->uid) { + user_cookie_save($values); + } + // E-mail address of the sender: as the form field is a text field, // all instances of \r and \n have been automatically stripped from it. $from = $values['mail']; Index: modules/user/user.module =================================================================== RCS file: /cvs/drupal/drupal/modules/user/user.module,v retrieving revision 1.1058 diff -u -p -r1.1058 user.module --- modules/user/user.module 9 Oct 2009 08:13:17 -0000 1.1058 +++ modules/user/user.module 9 Oct 2009 14:50:25 -0000 @@ -3226,3 +3226,20 @@ function user_login_destination() { return $destination; } +/** + * Saves visitor information as a cookie so it can be reused. + * + * @param $values + * An array of submitted form values with identifying information about the + * current user, typically $form_state['values'] from a submit handler. + * @param $fields + * An array of key values from $values to be saved into a cookie. + */ +function user_cookie_save(array $values, array $fields = array('name', 'mail', 'homepage')) { + foreach ($fields as $field) { + if (isset($values[$field])) { + // Set cookie for 365 days. + setrawcookie('Drupal.visitor.' . $field, rawurlencode($values[$field]), REQUEST_TIME + 31536000, '/'); + } + } +}