### Eclipse Workspace Patch 1.0 #P drupal-cvs Index: modules/comment/comment.module =================================================================== RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v retrieving revision 1.541 diff -u -r1.541 comment.module --- modules/comment/comment.module 30 Apr 2007 17:03:24 -0000 1.541 +++ modules/comment/comment.module 4 May 2007 03:35:39 -0000 @@ -121,6 +121,11 @@ define('COMMENT_PREVIEW_REQUIRED', 1); /** + * Remember anonymous comment poster information. + */ +define('COMMENT_REMEMBER_ANONYMOUS', 1); + +/** * Implementation of hook_help(). */ function comment_help($section) { @@ -572,8 +577,14 @@ COMMENT_ANONYMOUS_MUST_CONTACT => t('Anonymous posters must leave their contact information')), '#description' => t('This option is enabled when anonymous users have permission to post comments on the permissions page.', array('@url' => url('admin/user/access', array('fragment' => 'module-comment')))), ); + $form['posting_settings']['comment_remember_anonymous'] = array( + '#type' => 'checkbox', + '#title' => t('Remember anonymous comment poster information.'), + '#default_value' => variable_get('comment_remember_anonymous', COMMENT_REMEMBER_ANONYMOUS), + ); if (!user_access('post comments', user_load(array('uid' => 0)))) { $form['posting_settings']['comment_anonymous']['#disabled'] = TRUE; + $form['posting_settings']['comment_remember_anonymous']['#disabled'] = TRUE; } $form['posting_settings']['comment_subject_field'] = array( @@ -1544,6 +1555,13 @@ } } else if (variable_get('comment_anonymous', COMMENT_ANONYMOUS_MAYNOT_CONTACT) == COMMENT_ANONYMOUS_MAY_CONTACT) { + if (variable_get('comment_remember_anonymous', COMMENT_REMEMBER_ANONYMOUS) == COMMENT_REMEMBER_ANONYMOUS && variable_get('cache', CACHE_DISABLED) == CACHE_DISABLED) { + foreach (array('name','homepage','mail') as $field) { + if (isset($_SESSION['comment'][$field])){ + $edit[$field] = $_SESSION['comment'][$field]; + } + } + } $form['name'] = array('#type' => 'textfield', '#title' => t('Your name'), '#maxlength' => 60, '#size' => 30, '#default_value' => $edit['name'] ? $edit['name'] : variable_get('anonymous', t('Anonymous')) ); @@ -1553,6 +1571,13 @@ $form['homepage'] = array('#type' => 'textfield', '#title' => t('Homepage'), '#maxlength' => 255, '#size' => 30, '#default_value' => $edit['homepage']); } else if (variable_get('comment_anonymous', COMMENT_ANONYMOUS_MAYNOT_CONTACT) == COMMENT_ANONYMOUS_MUST_CONTACT) { + if (variable_get('comment_remember_anonymous', COMMENT_REMEMBER_ANONYMOUS) == COMMENT_REMEMBER_ANONYMOUS && variable_get('cache', CACHE_DISABLED) == CACHE_DISABLED) { + foreach (array('name','homepage','mail') as $field) { + if (isset($_SESSION['comment'][$field])){ + $edit[$field] = $_SESSION['comment'][$field]; + } + } + } $form['name'] = array('#type' => 'textfield', '#title' => t('Your name'), '#maxlength' => 60, '#size' => 30, '#default_value' => $edit['name'] ? $edit['name'] : variable_get('anonymous', t('Anonymous')), '#required' => TRUE); $form['mail'] = array('#type' => 'textfield', '#title' => t('E-mail'), '#maxlength' => 64, '#size' => 30, '#default_value' => $edit['mail'], '#description' => t('The content of this field is kept private and will not be shown publicly.'), '#required' => TRUE); @@ -1582,7 +1607,21 @@ $edit['format'] = FILTER_FORMAT_DEFAULT; } $form['comment_filter']['format'] = filter_form($edit['format']); - + if (variable_get('comment_remember_anonymous', COMMENT_REMEMBER_ANONYMOUS) == COMMENT_REMEMBER_ANONYMOUS && empty($user->uid)) { + $form['comment_info_checkbox'] = array( + '#type' => 'checkbox', + '#title' => t('Save my comment information for next time.'), + ); + if (variable_get('cache', CACHE_DISABLED) == CACHE_DISABLED) { + $form['comment_info_checkbox']['#default_value'] = $_SESSION['comment']['comment_info_checkbox']; + } + else { + drupal_add_js('/misc/jquery.cookie.js'); + drupal_add_js(drupal_get_path('module', 'comment').'/comment.js'); + $form['comment_info_checkbox']['#prefix'] = ''; + $form['comment_info_checkbox']['#suffix'] = ''; + } + } $form['cid'] = array('#type' => 'value', '#value' => !empty($edit['cid']) ? $edit['cid'] : NULL); $form['pid'] = array('#type' => 'value', '#value' => $edit['pid']); $form['nid'] = array('#type' => 'value', '#value' => $edit['nid']); @@ -1711,6 +1750,17 @@ function comment_form_submit($form_id, $form_values) { $form_values = _comment_form_submit($form_values); + if (variable_get('comment_remember_anonymous', COMMENT_REMEMBER_ANONYMOUS) == COMMENT_REMEMBER_ANONYMOUS && variable_get('cache', CACHE_DISABLED) == CACHE_DISABLED) { + if ($form_values['comment_info_checkbox'] == 1) { + foreach (array('name','homepage','mail','comment_info_checkbox') as $field) { + $_SESSION['comment'][$field] = $form_values[$field]; + } + } else { + foreach (array('name','homepage','mail','comment_info_checkbox') as $field) { + unset($_SESSION['comment'][$field]); + } + } + } if ($cid = comment_save($form_values)) { return array('node/'. $form_values['nid'], NULL, "comment-$cid"); } Index: modules/system/system.css =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.css,v retrieving revision 1.25 diff -u -r1.25 system.css --- modules/system/system.css 1 May 2007 06:53:03 -0000 1.25 +++ modules/system/system.css 4 May 2007 03:35:40 -0000 @@ -431,3 +431,10 @@ thead div.sticky-header { background: #fff; } + +/* +** Hide comment remember checkbox with cache enabled. +*/ +#comment-info { + display:none; +} Index: misc/jquery.cookie.js =================================================================== RCS file: misc/jquery.cookie.js diff -N misc/jquery.cookie.js --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ misc/jquery.cookie.js 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,92 @@ +/** + * Cookie plugin + * + * Copyright (c) 2006 Klaus Hartl (stilbuero.de) + * Dual licensed under the MIT and GPL licenses: + * http://www.opensource.org/licenses/mit-license.php + * http://www.gnu.org/licenses/gpl.html + * + */ + +/** + * Create a cookie with the given name and value and other optional parameters. + * + * @example $.cookie('the_cookie', 'the_value'); + * @desc Set the value of a cookie. + * @example $.cookie('the_cookie', 'the_value', {expires: 7, path: '/', domain: 'jquery.com', secure: true}); + * @desc Create a cookie with all available options. + * @example $.cookie('the_cookie', 'the_value'); + * @desc Create a session cookie. + * @example $.cookie('the_cookie', null); + * @desc Delete a cookie by passing null as value. + * + * @param String name The name of the cookie. + * @param String value The value of the cookie. + * @param Object options An object literal containing key/value pairs to provide optional cookie attributes. + * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object. + * If a negative value is specified (e.g. a date in the past), the cookie will be deleted. + * If set to null or omitted, the cookie will be a session cookie and will not be retained + * when the the browser exits. + * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie). + * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie). + * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will + * require a secure protocol (like HTTPS). + * @type undefined + * + * @name $.cookie + * @cat Plugins/Cookie + * @author Klaus Hartl/klaus.hartl@stilbuero.de + */ + +/** + * Get the value of a cookie with the given name. + * + * @example $.cookie('the_cookie'); + * @desc Get the value of a cookie. + * + * @param String name The name of the cookie. + * @return The value of the cookie. + * @type String + * + * @name $.cookie + * @cat Plugins/Cookie + * @author Klaus Hartl/klaus.hartl@stilbuero.de + */ +jQuery.cookie = function(name, value, options) { + if (typeof value != 'undefined') { // name and value given, set cookie + options = options || {}; + if (value === null) { + value = ''; + options.expires = -1; + } + var expires = ''; + if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) { + var date; + if (typeof options.expires == 'number') { + date = new Date(); + date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000)); + } else { + date = options.expires; + } + expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE + } + var path = options.path ? '; path=' + options.path : ''; + var domain = options.domain ? '; domain=' + options.domain : ''; + var secure = options.secure ? '; secure' : ''; + document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join(''); + } else { // only name given, get cookie + var cookieValue = null; + if (document.cookie && document.cookie != '') { + var cookies = document.cookie.split(';'); + for (var i = 0; i < cookies.length; i++) { + var cookie = jQuery.trim(cookies[i]); + // Does this cookie string begin with the name we want? + if (cookie.substring(0, name.length + 1) == (name + '=')) { + cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); + break; + } + } + } + return cookieValue; + } +}; Index: modules/comment/comment.js =================================================================== RCS file: modules/comment/comment.js diff -N modules/comment/comment.js --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ modules/comment/comment.js 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,33 @@ +if (Drupal.jsEnabled) { + $(document).ready(function() { + var comment_x = false; + $("#comment-info").show(); + var comment_info_checkbox = jQuery.cookie('comment_info_checkbox'); + if (comment_info_checkbox=='true') { + $("#comment-form input[@name=name]").val(jQuery.cookie('comment_info_name')); + $("#comment-form input[@name=mail]").val(jQuery.cookie('comment_info_email')); + $("#comment-form input[@name=homepage]").val(jQuery.cookie('comment_info_homepage')); + $("#comment-form input[@name=comment_info_checkbox]").each( function() { + this.checked = true; + }); + }; + $("form#comment-form input[@type=submit]").each( function() { + $(this).click(function() { + $("#comment-form input[@name=comment_info_checkbox]").each( function() { + comment_info_x = this.checked; + }); + if(comment_info_x) { + jQuery.cookie('comment_info_checkbox', 'true', { expires: 120 }); + jQuery.cookie('comment_info_name', $("#comment-form input[@name=name]").val(), { expires: 120 }); + jQuery.cookie('comment_info_email', $("#comment-form input[@name=mail]").val(), { expires: 120 }); + jQuery.cookie('comment_info_homepage', $("#comment-form input[@name=homepage]").val(), { expires: 120 }); + } else { + jQuery.cookie('comment_info_checkbox', 'false', { expires: -1 }); + jQuery.cookie('comment_info_name', '', { expires: -1 }); + jQuery.cookie('comment_info_email', '', { expires: -1 }); + jQuery.cookie('comment_info_homepage', '', { expires: -1 }); + }; + }); + }); + }); +};