diff options
Diffstat (limited to 'modules/comment')
-rw-r--r-- | modules/comment/comment.js | 23 | ||||
-rw-r--r-- | modules/comment/comment.module | 18 |
2 files changed, 8 insertions, 33 deletions
diff --git a/modules/comment/comment.js b/modules/comment/comment.js index 58f00dc6b..753e99252 100644 --- a/modules/comment/comment.js +++ b/modules/comment/comment.js @@ -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); diff --git a/modules/comment/comment.module b/modules/comment/comment.module index b9b7cd18c..d3facf4c6 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -1637,7 +1637,8 @@ function comment_form($form, &$form_state, $comment) { $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, &$form_state) { $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, &$form_state) { $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($format, $fallback) { ->condition('format', $format->format) ->execute(); } - |