Comment updating cleanup. Add get_comment(), edit_comment(), get_comment_to_edit(), and wp_update_comment().
git-svn-id: http://svn.automattic.com/wordpress/trunk@2662 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -63,13 +63,13 @@ function edit_post() {
|
||||
if ( !isset($blog_ID) )
|
||||
$blog_ID = 1;
|
||||
|
||||
$post_ID = $_POST['post_ID'];
|
||||
$post_ID = (int) $_POST['post_ID'];
|
||||
|
||||
if (!user_can_edit_post($user_ID, $post_ID, $blog_ID))
|
||||
die( __('You are not allowed to edit this post.') );
|
||||
|
||||
// Rename.
|
||||
$_POST['ID'] = $_POST['post_ID'];
|
||||
$_POST['ID'] = (int) $_POST['post_ID'];
|
||||
$_POST['post_content'] = $_POST['content'];
|
||||
$_POST['post_excerpt'] = $_POST['excerpt'];
|
||||
$_POST['post_parent'] = $_POST['parent_id'];
|
||||
@@ -119,6 +119,39 @@ function edit_post() {
|
||||
add_meta($post_ID);
|
||||
}
|
||||
|
||||
function edit_comment() {
|
||||
global $user_ID;
|
||||
|
||||
$comment_ID = (int) $_POST['comment_ID'];
|
||||
$comment_post_ID = (int) $_POST['comment_post_ID'];
|
||||
|
||||
if (!user_can_edit_post_comments($user_ID, $comment_post_ID))
|
||||
die( __('You are not allowed to edit comments on this post, so you cannot edit this comment.') );
|
||||
|
||||
$_POST['comment_author'] = $_POST['newcomment_author'];
|
||||
$_POST['comment_author_email'] = $_POST['newcomment_author_email'];
|
||||
$_POST['comment_author_url'] = $_POST['newcomment_author_url'];
|
||||
$_POST['comment_approved'] = $_POST['comment_status'];
|
||||
$_POST['comment_content'] = $_POST['content'];
|
||||
$_POST['comment_ID'] = (int) $_POST['comment_ID'];
|
||||
|
||||
if (user_can_edit_post_date($user_ID, $post_ID) && (!empty($_POST['edit_date']))) {
|
||||
$aa = $_POST['aa'];
|
||||
$mm = $_POST['mm'];
|
||||
$jj = $_POST['jj'];
|
||||
$hh = $_POST['hh'];
|
||||
$mn = $_POST['mn'];
|
||||
$ss = $_POST['ss'];
|
||||
$jj = ($jj > 31) ? 31 : $jj;
|
||||
$hh = ($hh > 23) ? $hh - 24 : $hh;
|
||||
$mn = ($mn > 59) ? $mn - 60 : $mn;
|
||||
$ss = ($ss > 59) ? $ss - 60 : $ss;
|
||||
$_POST['comment_date'] = "$aa-$mm-$jj $hh:$mn:$ss";
|
||||
}
|
||||
|
||||
wp_update_comment($_POST);
|
||||
}
|
||||
|
||||
// Get an existing post and format it for editing.
|
||||
function get_post_to_edit($id) {
|
||||
$post = get_post($id);
|
||||
@@ -158,6 +191,19 @@ function get_default_post_to_edit() {
|
||||
return $post;
|
||||
}
|
||||
|
||||
function get_comment_to_edit($id) {
|
||||
$comment = get_comment($id);
|
||||
|
||||
$comment->comment_content = format_to_edit($comment->comment_content);
|
||||
$comment->comment_content = apply_filters('comment_edit_pre', $comment->comment_content);
|
||||
|
||||
$comment->comment_author = format_to_edit($comment->comment_author);
|
||||
$comment->comment_author_email = format_to_edit($comment->comment_author_email);
|
||||
$comment->comment_author_url = format_to_edit($comment->comment_author_url);
|
||||
|
||||
return $comment;
|
||||
}
|
||||
|
||||
function url_shorten ($url) {
|
||||
$short_url = str_replace('http://', '', stripslashes($url));
|
||||
$short_url = str_replace('www.', '', $short_url);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
$submitbutton_text = __('Edit Comment »');
|
||||
$toprow_title = sprintf(__('Editing Comment # %s'), $commentdata['comment_ID']);
|
||||
$toprow_title = sprintf(__('Editing Comment # %s'), $comment->comment_ID);
|
||||
$form_action = 'editedcomment';
|
||||
$form_extra = "' />\n<input type='hidden' name='comment_ID' value='$comment' />\n<input type='hidden' name='comment_post_ID' value='".$commentdata["comment_post_ID"];
|
||||
$form_extra = "' />\n<input type='hidden' name='comment_ID' value='" . $comment->comment_ID . "' />\n<input type='hidden' name='comment_post_ID' value='".$comment->comment_post_ID;
|
||||
?>
|
||||
|
||||
<form name="post" action="post.php" method="post" id="post">
|
||||
@@ -20,19 +20,19 @@ window.onload = focusit;
|
||||
<fieldset id="namediv">
|
||||
<legend><?php _e('Name:') ?></legend>
|
||||
<div>
|
||||
<input type="text" name="newcomment_author" size="22" value="<?php echo format_to_edit($commentdata['comment_author']) ?>" tabindex="1" id="name" />
|
||||
<input type="text" name="newcomment_author" size="22" value="<?php echo $comment->comment_author ?>" tabindex="1" id="name" />
|
||||
</div>
|
||||
</fieldset>
|
||||
<fieldset id="emaildiv">
|
||||
<legend><?php _e('E-mail:') ?></legend>
|
||||
<div>
|
||||
<input type="text" name="newcomment_author_email" size="30" value="<?php echo format_to_edit($commentdata['comment_author_email']) ?>" tabindex="2" id="email" />
|
||||
<input type="text" name="newcomment_author_email" size="30" value="<?php echo $comment->comment_author_email ?>" tabindex="2" id="email" />
|
||||
</div>
|
||||
</fieldset>
|
||||
<fieldset id="uridiv">
|
||||
<legend><?php _e('URI:') ?></legend>
|
||||
<div>
|
||||
<input type="text" name="newcomment_author_url" size="35" value="<?php echo format_to_edit($commentdata['comment_author_url']) ?>" tabindex="3" id="URL" />
|
||||
<input type="text" name="newcomment_author_url" size="35" value="<?php echo $comment->comment_author_url ?>" tabindex="3" id="URL" />
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
@@ -45,7 +45,7 @@ window.onload = focusit;
|
||||
$rows = 10;
|
||||
}
|
||||
?>
|
||||
<div><textarea rows="<?php echo $rows; ?>" cols="40" name="content" tabindex="4" id="content" style="width: 99%"><?php echo $content ?></textarea></div>
|
||||
<div><textarea rows="<?php echo $rows; ?>" cols="40" name="content" tabindex="4" id="content" style="width: 99%"><?php echo $comment->comment_content ?></textarea></div>
|
||||
</fieldset>
|
||||
|
||||
<script type="text/javascript">
|
||||
@@ -66,9 +66,9 @@ edCanvas = document.getElementById('content');
|
||||
<table width="100%" cellspacing="2" cellpadding="5" class="editform">
|
||||
<tr>
|
||||
<th scope="row" valign="top"><?php _e('Comment Status') ?>:</th>
|
||||
<td><label for="comment_status_approved" class="selectit"><input id="comment_status_approved" name="comment_status" type="radio" value="1" <?php checked($comment_status, '1'); ?> /> <?php _e('Approved') ?></label><br />
|
||||
<label for="comment_status_moderated" class="selectit"><input id="comment_status_moderated" name="comment_status" type="radio" value="0" <?php checked($comment_status, '0'); ?> /> <?php _e('Moderated') ?></label><br />
|
||||
<label for="comment_status_spam" class="selectit"><input id="comment_status_spam" name="comment_status" type="radio" value="spam" <?php checked($comment_status, 'spam'); ?> /> <?php _e('Spam') ?></label></td>
|
||||
<td><label for="comment_status_approved" class="selectit"><input id="comment_status_approved" name="comment_status" type="radio" value="1" <?php checked($comment->comment_approved, '1'); ?> /> <?php _e('Approved') ?></label><br />
|
||||
<label for="comment_status_moderated" class="selectit"><input id="comment_status_moderated" name="comment_status" type="radio" value="0" <?php checked($comment->comment_approved, '0'); ?> /> <?php _e('Moderated') ?></label><br />
|
||||
<label for="comment_status_spam" class="selectit"><input id="comment_status_spam" name="comment_status" type="radio" value="spam" <?php checked($comment->comment_approved, 'spam'); ?> /> <?php _e('Spam') ?></label></td>
|
||||
</tr>
|
||||
|
||||
<?php if ($user_level > 4) : ?>
|
||||
@@ -80,7 +80,7 @@ edCanvas = document.getElementById('content');
|
||||
|
||||
<tr>
|
||||
<th scope="row"><?php _e('Delete'); ?>:</th>
|
||||
<td><p><a class="delete" href="post.php?action=confirmdeletecomment&noredir=true&comment=<?php echo $commentdata['comment_ID']; ?>&p=<?php echo $commentdata['comment_post_ID']; ?>"><?php _e('Delete comment') ?></a></p></td>
|
||||
<td><p><a class="delete" href="post.php?action=confirmdeletecomment&noredir=true&comment=<?php echo $comment->comment_ID; ?>&p=<?php echo $comment->comment_post_ID; ?>"><?php _e('Delete comment') ?></a></p></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
||||
@@ -140,18 +140,15 @@ case 'editcomment':
|
||||
|
||||
get_currentuserinfo();
|
||||
|
||||
$comment = $_GET['comment'];
|
||||
$commentdata = get_commentdata($comment, 1, true) or die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'javascript:history.go(-1)'));
|
||||
$comment = (int) $_GET['comment'];
|
||||
|
||||
if (!user_can_edit_post_comments($user_ID, $commentdata['comment_post_ID'])) {
|
||||
if ( ! $comment = get_comment($comment) )
|
||||
die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'javascript:history.go(-1)'));
|
||||
|
||||
if ( !user_can_edit_post_comments($user_ID, $comment->comment_post_ID) )
|
||||
die( __('You are not allowed to edit comments on this post.') );
|
||||
}
|
||||
|
||||
$content = $commentdata['comment_content'];
|
||||
$content = format_to_edit($content);
|
||||
$content = apply_filters('comment_edit_pre', $content);
|
||||
|
||||
$comment_status = $commentdata['comment_approved'];
|
||||
$comment = get_comment_to_edit($comment);
|
||||
|
||||
include('edit-form-comment.php');
|
||||
|
||||
@@ -161,21 +158,22 @@ case 'confirmdeletecomment':
|
||||
|
||||
require_once('./admin-header.php');
|
||||
|
||||
$comment = $_GET['comment'];
|
||||
$comment = (int) $_GET['comment'];
|
||||
$p = (int) $_GET['p'];
|
||||
$commentdata = get_commentdata($comment, 1, true) or die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
|
||||
|
||||
if (!user_can_delete_post_comments($user_ID, $commentdata['comment_post_ID'])) {
|
||||
if ( ! $comment = get_comment($comment) )
|
||||
die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
|
||||
|
||||
if ( !user_can_delete_post_comments($user_ID, $comment->comment_post_ID) )
|
||||
die( __('You are not allowed to delete comments on this post.') );
|
||||
}
|
||||
|
||||
echo "<div class=\"wrap\">\n";
|
||||
echo "<p>" . __('<strong>Caution:</strong> You are about to delete the following comment:') . "</p>\n";
|
||||
echo "<table border=\"0\">\n";
|
||||
echo "<tr><td>" . __('Author:') . "</td><td>" . $commentdata["comment_author"] . "</td></tr>\n";
|
||||
echo "<tr><td>" . __('E-mail:') . "</td><td>" . $commentdata["comment_author_email"] . "</td></tr>\n";
|
||||
echo "<tr><td>". __('URL:') . "</td><td>" . $commentdata["comment_author_url"] . "</td></tr>\n";
|
||||
echo "<tr><td>". __('Comment:') . "</td><td>" . stripslashes($commentdata["comment_content"]) . "</td></tr>\n";
|
||||
echo "<tr><td>" . __('Author:') . "</td><td>" . $comment->comment_author . "</td></tr>\n";
|
||||
echo "<tr><td>" . __('E-mail:') . "</td><td>" . $comment->comment_author_email . "</td></tr>\n";
|
||||
echo "<tr><td>". __('URL:') . "</td><td>" . $comment->comment_author_url . "</td></tr>\n";
|
||||
echo "<tr><td>". __('Comment:') . "</td><td>" . $comment->comment_content . "</td></tr>\n";
|
||||
echo "</table>\n";
|
||||
echo "<p>" . __('Are you sure you want to do that?') . "</p>\n";
|
||||
|
||||
@@ -196,8 +194,8 @@ case 'deletecomment':
|
||||
|
||||
check_admin_referer();
|
||||
|
||||
$comment = $_GET['comment'];
|
||||
$p = $_GET['p'];
|
||||
$comment = (int) $_GET['comment'];
|
||||
$p = (int) $_GET['p'];
|
||||
if (isset($_GET['noredir'])) {
|
||||
$noredir = true;
|
||||
} else {
|
||||
@@ -205,14 +203,15 @@ case 'deletecomment':
|
||||
}
|
||||
|
||||
$postdata = get_post($p) or die(sprintf(__('Oops, no post with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
|
||||
$commentdata = get_commentdata($comment, 1, true) or die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'post.php'));
|
||||
|
||||
if (!user_can_delete_post_comments($user_ID, $commentdata['comment_post_ID'])) {
|
||||
if ( ! $comment = get_comment($comment) )
|
||||
die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'post.php'));
|
||||
|
||||
if (!user_can_delete_post_comments($user_ID, $commentdata['comment_post_ID']))
|
||||
die( __('You are not allowed to edit comments on this post.') );
|
||||
}
|
||||
|
||||
wp_set_comment_status($comment, "delete");
|
||||
do_action('delete_comment', $comment);
|
||||
wp_set_comment_status($comment->comment_ID, "delete");
|
||||
do_action('delete_comment', $comment->comment_ID);
|
||||
|
||||
if (($_SERVER['HTTP_REFERER'] != "") && (false == $noredir)) {
|
||||
header('Location: ' . $_SERVER['HTTP_REFERER']);
|
||||
@@ -228,21 +227,21 @@ case 'unapprovecomment':
|
||||
|
||||
check_admin_referer();
|
||||
|
||||
$comment = $_GET['comment'];
|
||||
$p = $_GET['p'];
|
||||
$comment = (int) $_GET['comment'];
|
||||
$p = (int) $_GET['p'];
|
||||
if (isset($_GET['noredir'])) {
|
||||
$noredir = true;
|
||||
} else {
|
||||
$noredir = false;
|
||||
}
|
||||
|
||||
$commentdata = get_commentdata($comment) or die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
|
||||
if ( ! $comment = get_comment($comment) )
|
||||
die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
|
||||
|
||||
if (!user_can_edit_post_comments($user_ID, $commentdata['comment_post_ID'])) {
|
||||
if ( !user_can_edit_post_comments($user_ID, $comment->comment_post_ID) )
|
||||
die( __('You are not allowed to edit comments on this post, so you cannot disapprove this comment.') );
|
||||
}
|
||||
|
||||
wp_set_comment_status($comment, "hold");
|
||||
wp_set_comment_status($comment->comment_ID, "hold");
|
||||
|
||||
if (($_SERVER['HTTP_REFERER'] != "") && (false == $noredir)) {
|
||||
header('Location: ' . $_SERVER['HTTP_REFERER']);
|
||||
@@ -256,16 +255,16 @@ case 'mailapprovecomment':
|
||||
|
||||
$comment = (int) $_GET['comment'];
|
||||
|
||||
$commentdata = get_commentdata($comment, 1, true) or die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
|
||||
if ( ! $comment = get_comment($comment) )
|
||||
die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
|
||||
|
||||
if (!user_can_edit_post_comments($user_ID, $commentdata['comment_post_ID'])) {
|
||||
if ( !user_can_edit_post_comments($user_ID, $comment->comment_post_ID) )
|
||||
die( __('You are not allowed to edit comments on this post, so you cannot approve this comment.') );
|
||||
}
|
||||
|
||||
if ('1' != $commentdata['comment_approved']) {
|
||||
wp_set_comment_status($comment, 'approve');
|
||||
if ('1' != $comment->comment_approved) {
|
||||
wp_set_comment_status($comment->comment_ID, 'approve');
|
||||
if (true == get_option('comments_notify'))
|
||||
wp_notify_postauthor($comment);
|
||||
wp_notify_postauthor($comment->comment_ID);
|
||||
}
|
||||
|
||||
header('Location: ' . get_option('siteurl') . '/wp-admin/moderation.php?approved=1');
|
||||
@@ -274,22 +273,23 @@ case 'mailapprovecomment':
|
||||
|
||||
case 'approvecomment':
|
||||
|
||||
$comment = $_GET['comment'];
|
||||
$p = $_GET['p'];
|
||||
$comment = (int) $_GET['comment'];
|
||||
$p = (int) $_GET['p'];
|
||||
if (isset($_GET['noredir'])) {
|
||||
$noredir = true;
|
||||
} else {
|
||||
$noredir = false;
|
||||
}
|
||||
$commentdata = get_commentdata($comment) or die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
|
||||
|
||||
if (!user_can_edit_post_comments($user_ID, $commentdata['comment_post_ID'])) {
|
||||
if ( ! $comment = get_comment($comment) )
|
||||
die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
|
||||
|
||||
if ( !user_can_edit_post_comments($user_ID, $commentdata['comment_post_ID']))
|
||||
die( __('You are not allowed to edit comments on this post, so you cannot approve this comment.') );
|
||||
}
|
||||
|
||||
wp_set_comment_status($comment, "approve");
|
||||
wp_set_comment_status($comment->comment_ID, "approve");
|
||||
if (get_settings("comments_notify") == true) {
|
||||
wp_notify_postauthor($comment);
|
||||
wp_notify_postauthor($comment->comment_ID);
|
||||
}
|
||||
|
||||
|
||||
@@ -303,43 +303,7 @@ case 'approvecomment':
|
||||
|
||||
case 'editedcomment':
|
||||
|
||||
$comment_ID = $_POST['comment_ID'];
|
||||
$comment_post_ID = $_POST['comment_post_ID'];
|
||||
$newcomment_author = $_POST['newcomment_author'];
|
||||
$newcomment_author_email = $_POST['newcomment_author_email'];
|
||||
$newcomment_author_url = $_POST['newcomment_author_url'];
|
||||
$comment_status = $_POST['comment_status'];
|
||||
|
||||
if (!user_can_edit_post_comments($user_ID, $comment_post_ID)) {
|
||||
die( __('You are not allowed to edit comments on this post, so you cannot edit this comment.') );
|
||||
}
|
||||
|
||||
if (user_can_edit_post_date($user_ID, $post_ID) && (!empty($_POST['edit_date']))) {
|
||||
$aa = $_POST['aa'];
|
||||
$mm = $_POST['mm'];
|
||||
$jj = $_POST['jj'];
|
||||
$hh = $_POST['hh'];
|
||||
$mn = $_POST['mn'];
|
||||
$ss = $_POST['ss'];
|
||||
$jj = ($jj > 31) ? 31 : $jj;
|
||||
$hh = ($hh > 23) ? $hh - 24 : $hh;
|
||||
$mn = ($mn > 59) ? $mn - 60 : $mn;
|
||||
$ss = ($ss > 59) ? $ss - 60 : $ss;
|
||||
$datemodif = ", comment_date = '$aa-$mm-$jj $hh:$mn:$ss'";
|
||||
} else {
|
||||
$datemodif = '';
|
||||
}
|
||||
$content = apply_filters('comment_save_pre', $_POST['content']);
|
||||
|
||||
$result = $wpdb->query("
|
||||
UPDATE $wpdb->comments SET
|
||||
comment_content = '$content',
|
||||
comment_author = '$newcomment_author',
|
||||
comment_author_email = '$newcomment_author_email',
|
||||
comment_approved = '$comment_status',
|
||||
comment_author_url = '$newcomment_author_url'".$datemodif."
|
||||
WHERE comment_ID = $comment_ID"
|
||||
);
|
||||
edit_comment();
|
||||
|
||||
$referredby = $_POST['referredby'];
|
||||
if (!empty($referredby)) {
|
||||
@@ -347,7 +311,7 @@ case 'editedcomment':
|
||||
} else {
|
||||
header ("Location: edit.php?p=$comment_post_ID&c=1#comments");
|
||||
}
|
||||
do_action('edit_comment', $comment_ID);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user