Comment registration goodness. Hat tip to Jason at noprequisite.com for user_identity code.

git-svn-id: http://svn.automattic.com/wordpress/trunk@2166 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
saxmatt 2005-01-31 06:38:12 +00:00
parent f95c9db9b7
commit c4649b9979
9 changed files with 98 additions and 50 deletions

View File

@ -60,8 +60,8 @@ if ($action == 'retrospam') {
</fieldset>
<fieldset class="options">
<legend><?php _e('Before a comment appears:') ?></legend>
<ul>
<li>
<ul>
<li>
<label for="comment_moderation">
<input name="comment_moderation" type="checkbox" id="comment_moderation" value="1" <?php checked('1', get_settings('comment_moderation')); ?> />
<?php _e('An administrator must approve the comment (regardless of any matches below)') ?> </label>

View File

@ -11,7 +11,7 @@ include('admin-header.php');
<h2><?php _e('General Options') ?></h2>
<form name="form1" method="post" action="options.php">
<input type="hidden" name="action" value="update" />
<input type="hidden" name="action" value="update" /> <input type="hidden" name="page_options" value="'blogname','blogdescription','siteurl','admin_email','users_can_register','gmt_offset','date_format','time_format','home','start_of_week'" />
<input type="hidden" name="action" value="update" /> <input type="hidden" name="page_options" value="'blogname','blogdescription','siteurl','admin_email','users_can_register','gmt_offset','date_format','time_format','home','start_of_week','comment_registration'" />
<table width="100%" cellspacing="2" cellpadding="5" class="editform">
<tr valign="top">
<th width="33%" scope="row"><?php _e('Weblog title:') ?></th>
@ -41,7 +41,11 @@ include('admin-header.php');
<th scope="row"><?php _e('Membership:') ?></th>
<td> <label for="users_can_register">
<input name="users_can_register" type="checkbox" id="users_can_register" value="1" <?php checked('1', get_settings('users_can_register')); ?> />
<?php _e('Anyone can register') ?></label>
<?php _e('Anyone can register') ?></label><br />
<label for="comment_registration">
<input name="comment_registration" type="checkbox" id="comment_registration" value="1" <?php checked('1', get_settings('comment_registration')); ?> />
<?php _e('Users must be registered and logged in to comment') ?>
</label>
</td>
</tr>
</table>

View File

@ -138,7 +138,7 @@ if (isset($updated)) { ?>
<input type="hidden" name="checkuser_id" value="<?php echo $user_ID ?>" />
</p>
<table width="99%" border="0" cellspacing="2" cellpadding="3">
<table width="99%" border="0" cellspacing="2" cellpadding="3" class="editform">
<tr>
<th width="33%" scope="row"><?php _e('Login:') ?></th>
<td width="67%"><?php echo $profiledata->user_login; ?></td>
@ -162,14 +162,41 @@ if (isset($updated)) { ?>
<th scope="row"><?php _e('Last name:') ?></th>
<td><input type="text" name="newuser_lastname" id="newuser_lastname2" value="<?php echo $profiledata->user_lastname ?>" /></td>
</tr>
<tr>
<th scope="row"><?php _e('Profile:') ?></th>
<td><textarea name="user_description" rows="5" id="textarea2" style="width: 99%; "><?php echo $profiledata->user_description ?></textarea></td>
</tr>
<tr>
<th scope="row"><?php _e('Nickname:') ?></th>
<td><input type="text" name="newuser_nickname" id="newuser_nickname2" value="<?php echo $profiledata->user_nickname ?>" /></td>
</tr>
<tr>
<th scope="row"><?php _e('How to display name:') ?> </th>
<td><select name="newuser_idmode">
<option value="nickname"<?php
if ($profiledata->user_idmode == 'nickname')
echo ' selected="selected"'; ?>><?php echo $profiledata->user_nickname ?></option>
<option value="login"<?php
if ($profiledata->user_idmode=="login")
echo ' selected="selected"'; ?>><?php echo $profiledata->user_login ?></option>
<?php if ( !empty( $profiledata->user_firstname ) ) : ?>
<option value="firstname"<?php
if ($profiledata->user_idmode=="firstname")
echo ' selected="selected"'; ?>><?php echo $profiledata->user_firstname ?></option>
<?php endif; ?>
<?php if ( !empty( $profiledata->user_lastname ) ) : ?>
<option value="lastname"<?php
if ($profiledata->user_idmode=="lastname")
echo ' selected="selected"'; ?>><?php echo $profiledata->user_lastname ?></option>
<?php endif; ?>
<?php if ( !empty( $profiledata->user_firstname ) && !empty( $profiledata->user_lastname ) ) : ?>
<option value="namefl"<?php
if ($profiledata->user_idmode=="namefl")
echo ' selected="selected"'; ?>><?php echo $profiledata->user_firstname." ".$profiledata->user_lastname ?></option>
<?php endif; ?>
<?php if ( !empty( $profiledata->user_firstname ) && !empty( $profiledata->user_lastname ) ) : ?>
<option value="namelf"<?php
if ($profiledata->user_idmode=="namelf")
echo ' selected="selected"'; ?>><?php echo $profiledata->user_lastname." ".$profiledata->user_firstname ?></option>
<?php endif; ?>
</select> </td>
</tr>
<tr>
<th scope="row"><?php _e('E-mail:') ?></th>
<td><input type="text" name="newuser_email" id="newuser_email2" value="<?php echo $profiledata->user_email ?>" /></td>
@ -195,27 +222,8 @@ if (isset($updated)) { ?>
<td> <input type="text" name="newuser_yim" id="newuser_yim2" value="<?php echo $profiledata->user_yim ?>" /> </td>
</tr>
<tr>
<th scope="row"><?php _e('Identity on blog:') ?> </th>
<td><select name="newuser_idmode">
<option value="nickname"<?php
if ($profiledata->user_idmode == 'nickname')
echo ' selected="selected"'; ?>><?php echo $profiledata->user_nickname ?></option>
<option value="login"<?php
if ($profiledata->user_idmode=="login")
echo ' selected="selected"'; ?>><?php echo $profiledata->user_login ?></option>
<option value="firstname"<?php
if ($profiledata->user_idmode=="firstname")
echo ' selected="selected"'; ?>><?php echo $profiledata->user_firstname ?></option>
<option value="lastname"<?php
if ($profiledata->user_idmode=="lastname")
echo ' selected="selected"'; ?>><?php echo $profiledata->user_lastname ?></option>
<option value="namefl"<?php
if ($profiledata->user_idmode=="namefl")
echo ' selected="selected"'; ?>><?php echo $profiledata->user_firstname." ".$profiledata->user_lastname ?></option>
<option value="namelf"<?php
if ($profiledata->user_idmode=="namelf")
echo ' selected="selected"'; ?>><?php echo $profiledata->user_lastname." ".$profiledata->user_firstname ?></option>
</select> </td>
<th scope="row"><?php _e('Profile:') ?></th>
<td><textarea name="user_description" rows="5" id="textarea2" style="width: 99%; "><?php echo $profiledata->user_description ?></textarea></td>
</tr>
<tr>
<th scope="row"><?php _e('New <strong>Password</strong> (Leave blank to stay the same.)') ?></th>

View File

@ -204,7 +204,7 @@ function populate_options() {
add_option('ping_sites', 'http://rpc.pingomatic.com/');
add_option('advanced_edit', 0);
add_option('comment_max_links', 2);
// 1.3
// 1.5
add_option('default_email_category', 1, 'Posts by email go to this category');
add_option('recently_edited');
add_option('use_linksupdate', 0);
@ -213,6 +213,7 @@ function populate_options() {
add_option('comment_whitelist', 1);
add_option('page_uris');
add_option('blacklist_keys');
add_option('comment_registration', 0);
// Delete unused options
$unusedoptions = array ('blodotgsping_url', 'bodyterminator', 'emailtestonly', 'phoneemail_separator', 'smilies_directory', 'subjectprefix', 'use_bbcode', 'use_blodotgsping', 'use_phoneemail', 'use_quicktags', 'use_weblogsping', 'weblogs_cache_file', 'use_preview', 'use_htmltrans', 'smilies_directory', 'rss_language', 'fileupload_allowedusers', 'use_phoneemail', 'default_post_status', 'default_post_category', 'archive_mode', 'time_difference', 'links_minadminlevel', 'links_use_adminlevels', 'links_rating_type', 'links_rating_char', 'links_rating_ignore_zero', 'links_rating_single_image', 'links_rating_image0', 'links_rating_image1', 'links_rating_image2', 'links_rating_image3', 'links_rating_image4', 'links_rating_image5', 'links_rating_image6', 'links_rating_image7', 'links_rating_image8', 'links_rating_image9', 'weblogs_cacheminutes', 'comment_allowed_tags', 'search_engine_friendly_urls', 'default_geourl_lat', 'default_geourl_lon', 'use_default_geourl');

View File

@ -18,9 +18,18 @@ $comment_author_email = $_POST['email'];
$comment_author_url = $_POST['url'];
$comment_content = $_POST['comment'];
$comment_type = '';
// If the user is logged in
get_currentuserinfo();
if ( $user_ID ) :
$comment_author = $user_login;
$comment_author_email = $user_email;
$comment_author_url = str_replace('http://', '', $user_url);
else :
if ( get_option('comment_registration') )
die( __('Sorry, you must be logged in to post a comment.') );
endif;
$user_ip = apply_filters('pre_comment_user_ip', $_SERVER['REMOTE_ADDR']);
$comment_type = '';
if ( get_settings('require_name_email') && ('' == $comment_author_email || '' == $comment_author) )
die( __('Error: please fill the required fields (name, email).') );
@ -28,7 +37,7 @@ if ( get_settings('require_name_email') && ('' == $comment_author_email || '' ==
if ( '' == $comment_content )
die( __('Error: please type a comment.') );
$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type');
$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'user_ID');
wp_new_comment($commentdata);

View File

@ -33,18 +33,16 @@
<?php endif; ?>
<br />
<small class="commentmetadata"><a href="#comment-<?php comment_ID() ?>" title=""><?php comment_date('F jS, Y') ?> at <?php comment_time() ?></a> <?php edit_comment_link('e','',''); ?></small>
<?php comment_text() ?>
</li>
<?php /* Changes every other comment to a different class */
if ('alt' == $oddcomment) $oddcomment = '';
else $oddcomment = 'alt';
?>
<?php /* Changes every other comment to a different class */
if ('alt' == $oddcomment) $oddcomment = '';
else $oddcomment = 'alt';
?>
<?php endforeach; /* end for each comment */ ?>
@ -66,10 +64,20 @@
<?php if ('open' == $post-> comment_status) : ?>
<h3 id="respond">Leave a Reply</h3>
<form action="<?php echo get_settings('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">
<?php if ( get_option('comment_registration') && !$user_ID ) : ?>
<p>You must be <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?redirect_to=<?php the_permalink(); ?>">logged in</a> to post a comment.</p>
<?php else : ?>
<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">
<?php if ( $user_ID ) : ?>
<p>Logged in as <a href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php"><?php echo $user_identity; ?></a>. <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?action=logout" title="<?php _e('Log out of this account') ?>">Logout &raquo;</a></p>
<?php else : ?>
<p><input type="text" name="author" id="author" value="<?php echo $comment_author; ?>" size="22" tabindex="1" />
<input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" />
<label for="author"><small>Name <?php if ($req) _e('(required)'); ?></small></label></p>
<p><input type="text" name="email" id="email" value="<?php echo $comment_author_email; ?>" size="22" tabindex="2" />
@ -78,13 +86,19 @@
<p><input type="text" name="url" id="url" value="<?php echo $comment_author_url; ?>" size="22" tabindex="3" />
<label for="url"><small>Website</small></label></p>
<?php endif; ?>
<!--<p><small><strong>XHTML:</strong> You can use these tags: <?php echo allowed_tags(); ?></small></p>-->
<p><textarea name="comment" id="comment" cols="100%" rows="10" tabindex="4"></textarea></p>
<p><input name="submit" type="submit" id="submit" tabindex="5" value="Submit Comment" /></p>
<p><input name="submit" type="submit" id="submit" tabindex="5" value="Submit Comment" />
<input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" />
</p>
<?php do_action('comment_form', $post->ID); ?>
</form>
<?php endif; // If registration required and not logged in ?>
<?php endif; // if you delete this the sky will fall on your head ?>

View File

@ -3,7 +3,7 @@
// Template functions
function comments_template() {
global $wp_query, $withcomments, $post, $wpdb, $id, $comment;
global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity;
if ( is_single() || is_page() || $withcomments ) :
$req = get_settings('require_name_email');
@ -18,6 +18,8 @@ function comments_template() {
$comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND ( comment_approved = '1' OR ( comment_author = '$author_db' AND comment_author_email = '$email_db' AND comment_approved = '0' ) ) ORDER BY comment_date");
}
get_currentuserinfo();
if ( file_exists( TEMPLATEPATH . '/comments.php') )
require( TEMPLATEPATH . '/comments.php');
else

View File

@ -429,6 +429,7 @@ function wp_new_comment( $commentdata, $spam = false ) {
$comment_post_ID = (int) $comment_post_ID;
$user_id = apply_filters('pre_user_id', $user_ID);
$author = apply_filters('pre_comment_author_name', $comment_author);
$email = apply_filters('pre_comment_author_email', $comment_author_email);
$url = apply_filters('pre_comment_author_url', $comment_author_url);
@ -463,9 +464,9 @@ function wp_new_comment( $commentdata, $spam = false ) {
$approved = apply_filters('pre_comment_approved', $approved);
$result = $wpdb->query("INSERT INTO $wpdb->comments
(comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_author_IP, comment_date, comment_date_gmt, comment_content, comment_approved, comment_agent, comment_type)
(comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_author_IP, comment_date, comment_date_gmt, comment_content, comment_approved, comment_agent, comment_type, user_id)
VALUES
('$comment_post_ID', '$author', '$email', '$url', '$user_ip', '$now', '$now_gmt', '$comment', '$approved', '$user_agent', '$comment_type')
('$comment_post_ID', '$author', '$email', '$url', '$user_ip', '$now', '$now_gmt', '$comment', '$approved', '$user_agent', '$comment_type', '$user_id')
");
$comment_id = $wpdb->insert_id;

View File

@ -155,7 +155,7 @@ function user_pass_ok($user_login,$user_pass) {
}
function get_currentuserinfo() { // a bit like get_userdata(), on steroids
global $user_login, $userdata, $user_level, $user_ID, $user_nickname, $user_email, $user_url, $user_pass_md5;
global $user_login, $userdata, $user_level, $user_ID, $user_nickname, $user_email, $user_url, $user_pass_md5, $user_identity;
// *** retrieving user's data from cookies and db - no spoofing
if (isset($_COOKIE['wordpressuser_' . COOKIEHASH]))
@ -167,6 +167,15 @@ function get_currentuserinfo() { // a bit like get_userdata(), on steroids
$user_email = $userdata->user_email;
$user_url = $userdata->user_url;
$user_pass_md5 = md5($userdata->user_pass);
$idmode = $userdata->user_idmode;
if ($idmode == 'nickname') $user_identity = $userdata->user_nickname;
if ($idmode == 'login') $user_identity = $userdata->user_login;
if ($idmode == 'firstname') $user_identity = $userdata->user_firstname;
if ($idmode == 'lastname') $user_identity = $userdata->user_lastname;
if ($idmode == 'namefl') $user_identity = $userdata->user_firstname.' '.$userdata->user_lastname;
if ($idmode == 'namelf') $user_identity = $userdata->user_lastname.' '.$userdata->user_firstname;
if (!$idmode) $user_identity = $userdata->user_nickname;
}
function get_userdata($userid) {