1
0

Allow to re-moderate comments

This commit is contained in:
Garvin Hicking
2008-01-03 15:02:22 +00:00
parent 7f8f873f87
commit c95f2dd9da
66 changed files with 190 additions and 27 deletions

View File

@ -78,6 +78,23 @@ if (isset($serendipity['GET']['adminAction']) && $serendipity['GET']['adminActio
}
}
if (isset($serendipity['GET']['adminAction']) && $serendipity['GET']['adminAction'] == 'pending' && serendipity_checkFormToken()) {
$sql = "SELECT c.*, e.title, a.email as authoremail, a.mail_comments
FROM {$serendipity['dbPrefix']}comments c
LEFT JOIN {$serendipity['dbPrefix']}entries e ON (e.id = c.entry_id)
LEFT JOIN {$serendipity['dbPrefix']}authors a ON (e.authorid = a.authorid)
WHERE c.id = " . (int)$serendipity['GET']['id'] ." AND status = 'approved'";
$rs = serendipity_db_query($sql, true);
if ($rs === false) {
echo ERROR .': '. sprintf(COMMENT_ALREADY_APPROVED, (int)$serendipity['GET']['id']);
} else {
serendipity_approveComment($serendipity['GET']['id'], $rs['entry_id'], true, true);
echo DONE . ': '. sprintf(COMMENT_MODERATED, (int)$serendipity['GET']['id']);
}
}
/* We are asked to delete a comment */
if (isset($serendipity['GET']['adminAction']) && $serendipity['GET']['adminAction'] == 'delete' && serendipity_checkFormToken()) {
serendipity_deleteComment($serendipity['GET']['id'], $serendipity['GET']['entry_id']);
@ -470,6 +487,9 @@ foreach ($sql as $rs) {
<?php if ($comment['status'] == 'pending') { ?>
<a href="?serendipity[action]=admin&amp;serendipity[adminModule]=comments&amp;serendipity[adminAction]=approve&amp;serendipity[id]=<?php echo $comment['id'] ?>&amp;<?php echo serendipity_setFormToken('url'); ?>" class="serendipityIconLink" title="<?php echo APPROVE; ?>"><img src="<?php echo serendipity_getTemplateFile('admin/img/accept.png'); ?>" alt="<?php echo APPROVE ?>" /><?php echo APPROVE ?></a>
<?php } ?>
<?php if ($comment['status'] == 'approved') { ?>
<a href="?serendipity[action]=admin&amp;serendipity[adminModule]=comments&amp;serendipity[adminAction]=pending&amp;serendipity[id]=<?php echo $comment['id'] ?>&amp;<?php echo serendipity_setFormToken('url'); ?>" class="serendipityIconLink" title="<?php echo SET_TO_MODERATED; ?>"><img src="<?php echo serendipity_getTemplateFile('admin/img/clock.png'); ?>" alt="<?php echo SET_TO_MODERATED ?>" /><?php echo SET_TO_MODERATED ?></a>
<?php } ?>
<?php if ($comment['excerpt']) { ?>
<a href="#c<?php echo $comment['id'] ?>" onclick="FT_toggle(<?php echo $comment['id'] ?>); return false;" title="<?php echo VIEW; ?>" class="serendipityIconLink"><img src="<?php echo serendipity_getTemplateFile('admin/img/zoom.png'); ?>" alt="<?php echo TOGGLE_ALL; ?>" /><span id="<?php echo $comment['id'] ?>_text"><?php echo TOGGLE_ALL ?></span></a>
<?php } ?>

View File

@ -497,9 +497,10 @@ function serendipity_allowCommentsToggle($entry_id, $switch = 'disable') {
* @param int The ID of the comment to approve
* @param int The ID of the entry a comment belongs to
* @param boolean Whether to force approving a comment despite of its current status
* @param boolean If set to true, a comment will be moderated instead of approved.
* @return boolean Success or failure
*/
function serendipity_approveComment($cid, $entry_id, $force = false) {
function serendipity_approveComment($cid, $entry_id, $force = false, $moderate = false) {
global $serendipity;
/* Get data about the comment, we need this query because this function can be called from anywhere */
@ -518,7 +519,11 @@ function serendipity_approveComment($cid, $entry_id, $force = false) {
return false;
}
$sql = "UPDATE {$serendipity['dbPrefix']}comments SET status = 'approved' WHERE id = ". (int)$cid;
if ($moderate) {
$sql = "UPDATE {$serendipity['dbPrefix']}comments SET status = 'pending' WHERE id = ". (int)$cid;
} else {
$sql = "UPDATE {$serendipity['dbPrefix']}comments SET status = 'approved' WHERE id = ". (int)$cid;
}
serendipity_db_query($sql);
$field = ($rs['type'] == 'NORMAL' ? 'comments' : 'trackbacks');
@ -531,14 +536,21 @@ function serendipity_approveComment($cid, $entry_id, $force = false) {
$lm = (int)$rs['entry_last_modified'];
}
$query = "UPDATE {$serendipity['dbPrefix']}entries SET $field=$field+1, last_modified=". $lm ." WHERE id='". (int)$entry_id ."'";
if ($moderate) {
$query = "UPDATE {$serendipity['dbPrefix']}entries SET $field=$field-1, last_modified=". $lm ." WHERE id='". (int)$entry_id ."'";
} else {
$query = "UPDATE {$serendipity['dbPrefix']}entries SET $field=$field+1, last_modified=". $lm ." WHERE id='". (int)$entry_id ."'";
}
serendipity_db_query($query);
if ($serendipity['allowSubscriptions']) {
serendipity_mailSubscribers($entry_id, $rs['author'], $rs['email'], $rs['title'], $rs['authoremail'], $cid);
if (!$moderate) {
if ($serendipity['allowSubscriptions']) {
serendipity_mailSubscribers($entry_id, $rs['author'], $rs['email'], $rs['title'], $rs['authoremail'], $cid);
}
serendipity_plugin_api::hook_event('backend_approvecomment', $rs);
}
serendipity_plugin_api::hook_event('backend_approvecomment', $rs);
return true;
}