Update of /cvsroot/php-blog/serendipity
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15264
Modified Files:
NEWS comment.php index.php serendipity_admin_entries.inc.php
serendipity_config.inc.php serendipity_entries.php
serendipity_functions.inc.php
Added Files:
serendipity_admin_comments.inc.php
Log Message:
Allow moderation of comments through:
* E-mail
* Comment manager in Author Suite
Bumps version to 0.6.7-CVS, requires database changes
Index: serendipity_config.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_config.inc.php,v
retrieving revision 1.84
retrieving revision 1.85
diff -u -d -r1.84 -r1.85
--- serendipity_config.inc.php 14 Jul 2004 08:11:21 -0000 1.84
+++ serendipity_config.inc.php 16 Jul 2004 22:17:23 -0000 1.85
@@ -14,7 +14,7 @@
}
include_once(S9Y_INCLUDE_PATH . 'compat.php');
-$serendipity['version'] = '0.6.6-CVS';
+$serendipity['version'] = '0.6.7-CVS';
$serendipity['production'] = 1;
$serendipity['rewrite'] = 'none';
$serendipity['messagestack'] = array();
@@ -55,16 +55,21 @@
@define('PATH_ARCHIVES', 'archives');
@define('PATH_ARCHIVE', 'archive');
@define('PATH_UNSUBSCRIBE', 'unsubscribe');
+@define('PATH_DELETECOMMENT', 'deleteComment');
+@define('PATH_APPROVECOMMENT', 'approveComment');
@define('PATH_FEEDS', 'feeds');
@define('PATH_ADMIN', 'admin');
@define('PATH_ENTRIES', 'entries');
@define('PATH_CATEGORIES', 'categories');
@define('PATH_PLUGIN', 'plugin');
+
/* URI patterns
* Note that it's important to use @ as the pattern delimiter.
*/
@define('PAT_FILENAME', '0-9a-z\.\_!%;,\+-');
@define('PAT_UNSUBSCRIBE', '@/'.PATH_UNSUBSCRIBE.'/(.*)/([0-9]+)@');
+@define('PAT_APPROVECOMMENT', '@/'.PATH_APPROVECOMMENT.'/(.*)/([0-9]+)@');
+@define('PAT_DELETECOMMENT', '@/'.PATH_DELETECOMMENT.'/(.*)/([0-9]+)@');
@define('PAT_ARCHIVES', '@/'.PATH_ARCHIVES.'/(\d+)\.html@');
@define('PAT_ARCHIVES_SHORT', '@/'.PATH_ARCHIVES.'/(\d+)_short\.html@');
@define('PAT_COMMENTSUB', '@/(\d+)_[' . PAT_FILENAME . ']*\.html@i');
--- NEW FILE: serendipity_admin_comments.inc.php ---
<?php
if (IN_serendipity !== true) {
die ("Don't hack!");
}
/* We are asked to save the edited comment, and we are not in preview mode */
if ( isset($serendipity['GET']['adminAction']) && $serendipity['GET']['adminAction'] == 'doEdit' && !isset($serendipity['POST']['preview']) ) {
$sql = "UPDATE {$serendipity['dbPrefix']}comments
SET
author = '". $serendipity['POST']['name'] ."',
email = '". $serendipity['POST']['email'] ."',
url = '". $serendipity['POST']['url'] ."',
parent_id = '". $serendipity['POST']['replyTo']."',
body = '". $serendipity['POST']['comment']."'
WHERE id = ". $serendipity['GET']['id'] ." AND entry_id = ". $serendipity['POST']['entry_id'];
serendipity_db_query($sql);
echo COMMENT_EDITED;
return 1;
}
/* We approve a comment */
if ( isset($serendipity['GET']['adminAction']) && $serendipity['GET']['adminAction'] == 'approve' ) {
$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 = ". $serendipity['GET']['id'] ." AND status = 'pending'";
$rs = serendipity_db_query($sql, true);
if ( $rs === false ) {
echo ERROR .': '. sprintf(COMMENT_ALREADY_APPROVED, $serendipity['GET']['id']);
return 1;
}
serendipity_approveComment($serendipity['GET']['id'], serendipity_db_bool($rs['mail_comments']), $rs['entry_id'], $rs['authoremail'], $rs['email'], $rs['author'], $rs['url'], $rs['title'], $rs['body'], $rs['type']);
echo DONE .': '. sprintf(COMMENT_APPROVED, $serendipity['GET']['id']);
return 1;
}
/* We are asked to delete a comment */
if ( isset($serendipity['GET']['adminAction']) && $serendipity['GET']['adminAction'] == 'delete' ) {
serendipity_deleteComment($serendipity['GET']['id'], $serendipity['GET']['entry_id']);
echo DONE .': '. sprintf(COMMENT_DELETED, $serendipity['GET']['id']);;
return 1;
}
/* We are either in edit mode, or preview mode */
if ( isset($serendipity['GET']['adminAction']) && $serendipity['GET']['adminAction'] == 'edit' || isset($serendipity['POST']['preview'])) {
/* If we are not in preview, we need data from our database */
if (!isset($serendipity['POST']['preview']) ) {
$comment = serendipity_db_query("SELECT * FROM {$serendipity['dbPrefix']}comments WHERE id = ". $serendipity['GET']['id']);
$data['name'] = $comment[0]['author'];
$data['email'] = $comment[0]['email'];
$data['url'] = $comment[0]['url'];
$data['replyTo'] = $comment[0]['parent_id'];
$data['comment'] = $comment[0]['body'];
/* If we are in preview, we get data from our form */
} elseif ( isset($serendipity['POST']['preview']) ) {
$data['name'] = $serendipity['POST']['name'];
$data['email'] = $serendipity['POST']['email'];
$data['url'] = $serendipity['POST']['url'];
$data['replyTo'] = $serendipity['POST']['replyTo'];
$data['comment'] = $serendipity['POST']['comment'];
serendipity_printComments(
array(
array(
'email' => $serendipity['POST']['email'],
'author' => $serendipity['POST']['name'],
'body' => $serendipity['POST']['comment'],
'url' => $serendipity['POST']['url'],
'timestamp' => time()
)
),
false,
false
);
}
serendipity_displayCommentForm($serendipity['GET']['entry_id'], '?serendipity[action]=admin&serendipity[adminModule]=comments&serendipity[adminAction]=doEdit&serendipity[id]='. $serendipity['GET']['id'] .'&serendipity[entry_id]='. $serendipity['GET']['entry_id'], NULL, $data, false);
return 1;
}
$sql = serendipity_db_query("SELECT c.*, e.title FROM {$serendipity['dbPrefix']}comments c
LEFT JOIN {$serendipity['dbPrefix']}entries e ON (e.id = c.entry_id)
WHERE type = 'NORMAL'
". (($serendipity['serendipityUserlevel'] != USERLEVEL_ADMIN) ? 'AND e.authorid = '. $serendipity['authorId'] : '') ."
ORDER BY id DESC
LIMIT 10");
if ( !is_array($sql) ) {
echo NO_COMMENTS;
return;
}
?>
<script language="Javascript1.2" type="text/javascript">
function toggle(id) {
if ( document.getElementById(id +'_full').style.display == '' ) {
document.getElementById(id +'_full').style.display='none';
document.getElementById(id +'_summary').style.display='';
document.getElementById(id +'_link').innerHTML = '<?php echo VIEW ?>';
} else {
document.getElementById(id +'_full').style.display='';
document.getElementById(id +'_summary').style.display='none';
document.getElementById(id +'_link').innerHTML = '<?php echo HIDE ?>';
}
}
</script>
<table width="100%" cellspacing="5" cellpadding="0" border="0" class="serendipity_admin_list">
<?php
$i = 0;
foreach ( $sql as $rs ) {
if (empty($rs['author'])) {
$rs['author'] = ANONYMOUS;
}
if (empty($rs['ip'])) {
$rs['ip'] = '0.0.0.0';
}
if (empty($rs['email'])) {
$rs['email'] = 'N/A';
}
$class = 'serendipity_admin_list_item_'. (($i++ % 2 == 0 ) ? 'even' : 'uneven');
?>
<tr>
<td class="serendipity_admin_list_item <?php echo $class ?>" style="padding: 3px">
<a name="c<?php echo $rs['id'] ?>"></a>
<strong><?php echo $rs['title'] ?></strong>
<table width="100%" cellspacing="0" cellpadding="2" border="0">
<tr>
<td width="30">
<?php
// TODO; Multi-Delete
/* <input type="checkbox" name="delete[<?php echo $rs['id'] ?>]"> */
?> </td>
<td width="160"><?php echo $rs['author'] ?></td>
<td><?php echo $rs['email'] ?></td>
<td align="right">(<?php echo $rs['ip'] ?>)</td>
</tr>
<tr>
<td style="border-top: 1px solid #CCCCCC; border-bottom: 1px solid #CCCCCC" colspan="4"><div id="<?php echo $rs['id'] ?>_summary"><?php echo nl2br(substr(strip_tags($rs['body']), 0, 200)) ?> ...</div><div id="<?php echo $rs['id'] ?>_full" style="display: none"><?php echo nl2br(strip_tags($rs['body'])) ?></div></td>
</tr>
</table>
<?php if ( $rs['status'] == 'pending' ) { ?>
<strong>[<a href="?serendipity[action]=admin&serendipity[adminModule]=comments&serendipity[adminAction]=approve&serendipity[id]=<?php echo $rs['id'] ?>">Approve</a>]</strong> -
<?php } ?>
[<a href="?serendipity[action]=admin&serendipity[adminModule]=comments&serendipity[adminAction]=delete&serendipity[id]=<?php echo $rs['id'] ?>&serendipity[entry_id]=<?php echo $rs['entry_id'] ?>"><?php echo DELETE ?></a>] -
[<a href="?serendipity[action]=admin&serendipity[adminModule]=comments&serendipity[adminAction]=edit&serendipity[id]=<?php echo $rs['id'] ?>&serendipity[entry_id]=<?php echo $rs['entry_id'] ?>"><?php echo EDIT ?></a>] -
[<a href="#c<?php echo $rs['id'] ?>" onClick="toggle(<?php echo $rs['id'] ?>)" id="<?php echo $rs['id'] ?>_link"><?php echo VIEW ?></a>]
</td>
</tr>
<?php } ?>
</table>
Index: serendipity_entries.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_entries.php,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- serendipity_entries.php 13 Jul 2004 14:29:51 -0000 1.36
+++ serendipity_entries.php 16 Jul 2004 22:17:23 -0000 1.37
@@ -53,6 +53,7 @@
<div class="serendipitySideBarContent">
• <a href="?serendipity[adminModule]=entries&serendipity[adminAction]=new"><?php echo NEW_ENTRY; ?></a><br />
• <a href="?serendipity[adminModule]=entries&serendipity[adminAction]=editSelect"><?php echo EDIT_ENTRIES; ?></a><br />
+ • <a href="?serendipity[adminModule]=comments"><?php echo COMMENTS; ?></a><br />
<?php serendipity_plugin_api::hook_event('backend_sidebar_entries', $serendipity); ?>
</div>
</div>
@@ -104,6 +105,10 @@
include S9Y_INCLUDE_PATH . 'serendipity_admin_images.inc.php';
break;
+ case 'comments':
+ include S9Y_INCLUDE_PATH . 'serendipity_admin_comments.inc.php';
+ break;
+
case 'category':
include S9Y_INCLUDE_PATH . 'serendipity_admin_category.inc.php';
break;
Index: serendipity_admin_entries.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_admin_entries.inc.php,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- serendipity_admin_entries.inc.php 23 Jun 2004 17:26:44 -0000 1.28
+++ serendipity_admin_entries.inc.php 16 Jul 2004 22:17:23 -0000 1.29
@@ -222,7 +222,7 @@
?>
<tr>
- <td class="serendipity_admin_list_item">
+ <td class="serendipity_admin_list_item serendipity_admin_list_item_<?php echo (($rows+1) % 2 ? 'even' : 'uneven'); ?>">
<br />
<?php echo EDIT_ENTRY . ': #<input type="text" size="3" name="serendipity[id]" /> <input type="submit" name="serendipity[editSubmit]" value="' . GO . '" />'; ?>
</td>
@@ -253,14 +253,15 @@
switch($serendipity['GET']['adminAction']) {
case 'save':
$entry = array(
- 'id' => $serendipity['POST']['id'],
- 'title' => $serendipity['POST']['title'],
- 'timestamp' => $serendipity['POST']['timestamp'],
- 'body' => $serendipity['POST']['body'],
- 'extended' => $serendipity['POST']['extended'],
- 'categories' => $serendipity['POST']['categories'],
- 'isdraft' => $serendipity['POST']['isdraft'],
- 'allow_comments' => $serendipity['POST']['allow_comments']
+ 'id' => $serendipity['POST']['id'],
+ 'title' => $serendipity['POST']['title'],
+ 'timestamp' => $serendipity['POST']['timestamp'],
+ 'body' => $serendipity['POST']['body'],
+ 'extended' => $serendipity['POST']['extended'],
+ 'categories' => $serendipity['POST']['categories'],
+ 'isdraft' => $serendipity['POST']['isdraft'],
+ 'allow_comments' => $serendipity['POST']['allow_comments'],
+ 'moderate_comments' => $serendipity['POST']['moderate_comments']
);
if ($entry['allow_comments'] != 'true' && $entry['allow_comments'] !== true) {
Index: index.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/index.php,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- index.php 10 Jul 2004 13:30:33 -0000 1.42
+++ index.php 16 Jul 2004 22:17:23 -0000 1.43
@@ -15,10 +15,26 @@
$uri = $_SERVER['REQUEST_URI'];
if (preg_match(PAT_UNSUBSCRIBE, $uri, $res)) {
- serendipity_cancelSubscription(urldecode($res[1]), $res[2]);
+ if ( serendipity_cancelSubscription(urldecode($res[1]), $res[2]) ) {
+ define('DATA_UNSUBSCRIBED', urldecode($res[1]));
+ }
+
$uri = '/'.PATH_UNSUBSCRIBE.'/'. $res[2] .'_untitled.html';
}
+if (preg_match(PAT_DELETECOMMENT, $uri, $res) && $serendipity['serendipityAuthedUser'] === true) {
+ if ( serendipity_deleteComment($res[1], $res[2]) ) {
+ define('DATA_COMMENT_DELETED', $res[1]);
+ }
+}
+
+if (preg_match(PAT_APPROVECOMMENT, $uri, $res) && $serendipity['serendipityAuthedUser'] === true) {
+ if ( serendipity_approveComment($res[1], $res[2]) ) {
+ define('DATA_COMMENT_APPROVED', $res[1]);
+ }
+}
+
+
if (preg_match(PAT_ARCHIVES, $uri, $matches)) {
$range = $matches[1];
$_GET['serendipity']['action'] = 'read';
Index: NEWS
===================================================================
RCS file: /cvsroot/php-blog/serendipity/NEWS,v
retrieving revision 1.174
retrieving revision 1.175
diff -u -d -r1.174 -r1.175
--- NEWS 16 Jul 2004 10:04:35 -0000 1.174
+++ NEWS 16 Jul 2004 22:17:23 -0000 1.175
@@ -3,6 +3,14 @@
Version 0.7 ()
------------------------------------------------------------------------
+ * Better handling of unsubscriptions from entries, only show message
+ if the user was indeed unsubscribed (tomsommer)
+
+ * Added ability to moderate comments:
+ * Moderate from email
+ * Moderate and view comments from within Authoring Suite
+ (tomsommer)
+
* An entries' LastModified timestamp will get updated if a comment
is made to it, but only if the article is newer than 7 days.
Make the conditional Get RSS-feed a lot more usable because old
Index: serendipity_functions.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_functions.inc.php,v
retrieving revision 1.336
retrieving revision 1.337
diff -u -d -r1.336 -r1.337
--- serendipity_functions.inc.php 16 Jul 2004 04:22:01 -0000 1.336
+++ serendipity_functions.inc.php 16 Jul 2004 22:17:23 -0000 1.337
@@ -222,12 +222,13 @@
<?php
}
-function serendipity_displayCommentForm($id, $url = '', $comments = NULL) {
+function serendipity_displayCommentForm($id, $url = '', $comments = NULL, $data = NULL, $showToolbar = true, $moderate_comments = true) {
global $serendipity;
if ( $comments == NULL ) {
$comments = serendipity_fetchComments($id);
}
+
?>
<div class="serendipityCommentForm">
<a <?php echo ($serendipity['XHTML11'] ? 'id' : 'name'); ?>="serendipity_CommentForm"></a>
@@ -236,45 +237,56 @@
<table border="0" width="100%" cellpadding="3">
<tr>
<td class="serendipity_commentsLabel"><?php echo NAME; ?></td>
- <td class="serendipity_commentsValue"><input type="text" name="serendipity[name]" value="<?php echo (isset($serendipity['POST']['name']) ? $serendipity['POST']['name'] : (isset($serendipity['COOKIE']['name']) ? $serendipity['COOKIE']['name'] : '')); ?>" size="30" /></td>
+ <td class="serendipity_commentsValue"><input type="text" name="serendipity[name]" value="<?php echo (isset($data['name']) ? $data['name'] : (isset($serendipity['COOKIE']['name']) ? $serendipity['COOKIE']['name'] : '')); ?>" size="30" /></td>
</tr>
<tr>
<td class="serendipity_commentsLabel"><?php echo EMAIL; ?></td>
- <td class="serendipity_commentsValue"><input type="text" name="serendipity[email]" value="<?php echo (isset($serendipity['POST']['email']) ? $serendipity['POST']['email'] : (isset($serendipity['COOKIE']['email']) ? $serendipity['COOKIE']['email'] : '')); ?>" /></td>
+ <td class="serendipity_commentsValue"><input type="text" name="serendipity[email]" value="<?php echo (isset($data['email']) ? $data['email'] : (isset($serendipity['COOKIE']['email']) ? $serendipity['COOKIE']['email'] : '')); ?>" /></td>
</tr>
<tr>
<td class="serendipity_commentsLabel"><?php echo HOMEPAGE; ?></td>
- <td class="serendipity_commentsValue"><input type="text" name="serendipity[url]" value="<?php echo (isset($serendipity['POST']['url']) ? $serendipity['POST']['url'] : (isset($serendipity['COOKIE']['url']) ? $serendipity['COOKIE']['url'] : '')); ?>" /></td>
+ <td class="serendipity_commentsValue"><input type="text" name="serendipity[url]" value="<?php echo (isset($data['url']) ? $data['url'] : (isset($serendipity['COOKIE']['url']) ? $serendipity['COOKIE']['url'] : '')); ?>" /></td>
</tr>
<tr>
<td class="serendipity_commentsLabel"><?php echo IN_REPLY_TO; ?></td>
- <td class="serendipity_commentsValue"><?php echo serendipity_generateCommentList($id, $comments, ((isset($serendipity['POST']['serendipity']['replyTo']) && ($_POST['serendipity']['replyTo'])) ? $serendipity['POST']['serendipity']['replyTo'] : 0)); ?></td>
+ <td class="serendipity_commentsValue"><?php echo serendipity_generateCommentList($id, $comments, ((isset($data['replyTo']) && ($data['replyTo'])) ? $serendipity['POST']['serendipity']['replyTo'] : 0)); ?></td>
</tr>
<tr>
<td class="serendipity_commentsLabel"><?php echo COMMENT; ?></td>
<td class="serendipity_commentsValue">
- <textarea rows="10" cols="40" name="serendipity[comment]"><?php echo (isset($serendipity['POST']['comment']) ? $serendipity['POST']['comment'] : ''); ?></textarea><br />
+ <textarea rows="10" cols="40" name="serendipity[comment]"><?php echo (isset($data['comment']) ? $data['comment'] : ''); ?></textarea><br />
<?php serendipity_plugin_api::hook_event('frontend_comment', $nullParam); ?>
</td>
</tr>
+<?php if ( $showToolbar ) { ?>
<tr>
<td> </td>
<td class="serendipity_commentsLabel">
- <input id="checkbox_remember" type="checkbox" name="serendipity[remember]" <?php echo (isset($serendipity['POST']['remember']) ? 'checked="checked"' : isset($serendipity['COOKIE']['remember']) ? $serendipity['COOKIE']['remember'] : '') ; ?> /><label for="checkbox_remember"> <?php echo REMEMBER_INFO; ?></label>
+ <input id="checkbox_remember" type="checkbox" name="serendipity[remember]" <?php echo (isset($data['remember']) ? 'checked="checked"' : isset($serendipity['COOKIE']['remember']) ? $serendipity['COOKIE']['remember'] : '') ; ?> /><label for="checkbox_remember"> <?php echo REMEMBER_INFO; ?></label>
<?php
- if ($serendipity['allowSubscriptions']) {
+ if ($serendipity['allowSubscriptions']) {
?>
<br />
- <input id="checkbox_subscribe" type="checkbox" name="serendipity[subscribe]" <?php echo (isset($serendipity['POST']['subscribe']) ? 'checked="checked"' : ''); ?> /><label for="checkbox_subscribe"> <?php echo SUBSCRIBE_TO_THIS_ENTRY; ?></label>
+ <input id="checkbox_subscribe" type="checkbox" name="serendipity[subscribe]" <?php echo (isset($data['subscribe']) ? 'checked="checked"' : ''); ?> /><label for="checkbox_subscribe"> <?php echo SUBSCRIBE_TO_THIS_ENTRY; ?></label>
<?php
- }
+ }
?>
+<?php } ?>
</td>
</tr>
+<?php
+ if ($moderate_comments==true) {
+?>
+ <tr>
+ <td colspan="2"><div style="color: #FF0000; font-size: 8pt"><?php echo COMMENTS_WILL_BE_MODERATED ?></div></td>
+ </tr>
+<?php
+ }
+?>
<tr>
<td> </td>
<td><input type="submit" name="serendipity[submit]" value="<?php echo SUBMIT_COMMENT; ?>" /> <input type="submit" name="serendipity[preview]" value="<?php echo PREVIEW; ?>" /></td>
@@ -563,7 +575,7 @@
}
function serendipity_fetchCategoryInfo($categoryid, $categoryname = '') {
- global $serendipity;
+ global $serendipity;
if (!empty($categoryname)) {
$query = "SELECT
@@ -1087,7 +1099,6 @@
AND c.category_left BETWEEN " . implode(' AND ', serendipity_fetchCategoryRange($categoryid));
}
}
-
if (empty($querystring)) {
$querystring = "SELECT count(e.id)
FROM {$serendipity['dbPrefix']}entries e
@@ -1095,6 +1106,7 @@
}
$query = serendipity_db_query($querystring);
+
$totalEntries = $query[0][0];
$totalPages = ceil($totalEntries / (!empty($serendipity['fetchLimit']) ? $serendipity['fetchLimit'] : 15));
@@ -1262,10 +1274,19 @@
<br />
<div class="serendipity_commentsTitle"><?php echo COMMENTS; ?></div>
<?php
- if (preg_match('@/unsubscribe/(.*)/([0-9]+)@', $_SERVER['REQUEST_URI'], $res)) {
- echo '<div class="serendipity_center" style="color: #FF0000; font-weight: bold;">'. sprintf(UNSUBSCRIBE_OK, urldecode($res[1])) .'</div><br />';
+ if (defined('DATA_UNSUBSCRIBED')) {
+ echo '<div class="serendipity_center" style="color: red; font-weight: bold;">'. sprintf(UNSUBSCRIBE_OK, DATA_UNSUBSCRIBED) .'</div><br />';
+ }
+
+ if (defined('DATA_COMMENT_DELETED')) {
+ echo '<div class="serendipity_center" style="color: red; font-weight: bold;">'. sprintf(COMMENT_DELETED, DATA_COMMENT_DELETED) .'</div><br />';
+ }
+
+ if (defined('DATA_COMMENT_APPROVED')) {
+ echo '<div class="serendipity_center" style="color: green; font-weight: bold;">'. sprintf(COMMENT_APPROVED, DATA_COMMENT_APPROVED) .'</div><br />';
}
+
echo serendipity_printComments(serendipity_fetchComments($entry['id']), (isset($entry['allow_comments']) ? $entry['allow_comments'] : true));
if (!empty($serendipity['POST']['preview'])) {
@@ -1296,18 +1317,18 @@
if (isset($serendipity['GET']['csuccess']) && $serendipity['GET']['csuccess'] == 'true') {
?>
<br />
- <div class="serendipity_commentsTitle"><?php echo COMMENT_ADDED; ?></div>
+ <div class="serendipity_center" style="color: green"><?php echo COMMENT_ADDED; ?></div>
<?php
- } elseif (serendipity_db_bool($entry['allow_comments']) || !isset($entry['allow_comments'])) {
+ } elseif (!serendipity_db_bool($entry['allow_comments'])) {
?>
<br />
- <div class="serendipity_commentsTitle"><?php echo ADD_COMMENT; ?></div>
- <?php echo serendipity_displayCommentForm($entry['id'], $serendipity['serendipityHTTPPath'] . $serendipity['indexFile'] . '?url=' . str_replace('?', '&', serendipity_archiveURL($entry['id'], $entry['title']))); ?>
+ <div class="serendipity_center" style="color: #FF0000"><?php echo COMMENTS_CLOSED; ?></div>
<?php
- } else {
+ } else {
?>
<br />
- <div class="serendipity_center" style="color: #FF0000"><?php echo COMMENTS_CLOSED; ?></div>
+ <div class="serendipity_commentsTitle"><?php echo ADD_COMMENT; ?></div>
+ <?php echo serendipity_displayCommentForm($entry['id'], $serendipity['serendipityHTTPPath'] . $serendipity['indexFile'] . '?url=' . str_replace('?', '&', serendipity_archiveURL($entry['id'], $entry['title'])), true, $serendipity['POST'], true, serendipity_db_bool($entry['moderate_comments'])); ?>
<?php
}
?>
@@ -1359,11 +1380,13 @@
$query = "DELETE FROM {$serendipity['dbPrefix']}comments WHERE entry_id = $entry_id AND id = $id $admin";
serendipity_db_query($query);
+ $affected = serendipity_db_affected_rows();
$query = "UPDATE {$serendipity['dbPrefix']}entries SET $type = $type-1 WHERE id = $entry_id $admin";
serendipity_db_query($query);
+ return $affected;
} else {
- die('What are you up to? You need to be an admin to delete comments');
+ return false;
}
}
@@ -1384,9 +1407,10 @@
}
}
-function serendipity_fetchComments($id, $limit = null, $order = '')
+function serendipity_fetchComments($id, $limit = null, $order = '', $showAll = false)
{
global $serendipity;
+ $and = '';
if (!empty($limit)) {
$limit = serendipity_db_limit_sql($limit);
@@ -1395,7 +1419,11 @@
}
if (!empty($id)) {
- $and = 'AND co.entry_id=' . $id;
+ $and .= ' AND co.entry_id=' . $id;
+ }
+
+ if (!$showAll) {
+ $and .= ' AND co.status = \'approved\'';
}
if (strtolower($serendipity['dbType']) == 'postgres') {
@@ -1557,9 +1585,9 @@
}
if (serendipity_db_bool($allow_comments)) {
- echo '<div class="serendipity_comment_source">(<a href="' . $serendipity['baseURL'] . 'comment.php?serendipity[switch]=disable&serendipity[entry]=' . $comment['entry_id'] . '">' . COMMENTS_DISABLE . '</a>)</div>';
+ echo '<div class="serendipity_center">(<a href="' . $serendipity['baseURL'] . 'comment.php?serendipity[switch]=disable&serendipity[entry]=' . $comment['entry_id'] . '">' . COMMENTS_DISABLE . '</a>)</div>';
} else {
- echo '<div class="serendipity_comment_source">(<a href="' . $serendipity['baseURL'] . 'comment.php?serendipity[switch]=enable&serendipity[entry]=' . $comment['entry_id'] . '">' . COMMENTS_ENABLE . '</a>)</div>';
+ echo '<div class="serendipity_center">(<a href="' . $serendipity['baseURL'] . 'comment.php?serendipity[switch]=enable&serendipity[entry]=' . $comment['entry_id'] . '">' . COMMENTS_ENABLE . '</a>)</div>';
}
echo '<br />';
}
@@ -1610,10 +1638,52 @@
<?php
}
+
+function serendipity_approveComment($cid, $entry_id) {
+ global $serendipity;
+
+ /* Get data about the comment, we need this query because this function can be called from anywhere */
+ /* This also makes sure we are either the author of the comment, or a USERLEVEL_ADMIN */
+ $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 = ". $cid ."
+ ". (($serendipity['serendipityUserlevel'] != USERLEVEL_ADMIN) ? 'AND e.authorid = '. $serendipity['authorId'] : '') ."
+ AND status = 'pending'";
+ $rs = serendipity_db_query($sql, true);
+
+ /* It's already approved, don't spam people */
+ if ( $rs === false ) {
+ return false;
+ }
+
+ $sql = "UPDATE {$serendipity['dbPrefix']}comments SET status = 'approved' WHERE id = ". $cid;
+ serendipity_db_query($sql);
+
+ $field = ($rs['type'] == 'NORMAL' ? 'comments' : 'trackbacks');
+ // Check when the entry was published. If it is older than max_last_modified allows, the last_modified date of that entry
+ // will not be pushed. With this we make sure that an RSS feed will not be updated on a client's reader and marked as new
+ // only because someone made an comment to an old entry.
+ if ($ca['timestamp'] > time() - $serendipity['max_last_modified']) {
+ $lm = time();
+ } else {
+ $lm = $ca['last_modified'];
+ }
+
+ $query = "UPDATE {$serendipity['dbPrefix']}entries SET $field=$field+1, last_modified=". $lm ." WHERE id='$entry_id'";
+ serendipity_db_query($query);
+
+ if ($serendipity['allowSubscriptions']) {
+ serendipity_mailSubscribers($entry_id, $rs['name'], $rs['email'], $rs['title'], $rs['authoremail']);
+ }
+ return true;
+}
+
function serendipity_saveComment($id, $commentInfo, $type = 'NORMAL') {
global $serendipity;
- $query = "SELECT allow_comments, last_modified, timestamp FROM {$serendipity['dbPrefix']}entries WHERE id = '$id'";
+ $query = "SELECT allow_comments, moderate_comments, last_modified, timestamp FROM {$serendipity['dbPrefix']}entries WHERE id = '$id'";
$ca = serendipity_db_query($query, true);
if (serendipity_db_bool($ca['allow_comments']) || !is_array($ca)) {
@@ -1625,6 +1695,7 @@
$url = serendipity_db_escape_string($commentInfo['url']);
$email = serendipity_db_escape_string($commentInfo['email']);
$parentid = (isset($commentInfo['parent_id']) && is_numeric($commentInfo['parent_id'])) ? $commentInfo['parent_id'] : 0;
+ $status = (serendipity_db_bool($ca['moderate_comments']) && $type == 'NORMAL') ? 'pending' : 'approved';
if (isset($commentInfo['subscribe'])) {
$subscribe = 'true';
@@ -1633,39 +1704,23 @@
}
$t = time();
- $query = "INSERT INTO {$serendipity['dbPrefix']}comments (entry_id, parent_id, ip, author, email, url, body, type, timestamp, title, subscribed)";
- $query .= " VALUES ('$id', '$parentid', '$ip', '$name', '$email', '$url', '$commentsFixed', '$type', '$t', '$title', '$subscribe')";
-
- serendipity_db_query($query);
-
- $field = ($type == 'NORMAL' ? 'comments' : 'trackbacks');
-
- // Check when the entry was published. If it is older than max_last_modified allows, the last_modified date of that entry
- // will not be pushed. With this we make sure that an RSS feed will not be updated on a client's reader and marked as new
- // only because someone made an comment to an old entry.
- if ($ca['timestamp'] > time() - $serendipity['max_last_modified']) {
- $lm = time();
- } else {
- $lm = $ca['last_modified'];
- }
+ $query = "INSERT INTO {$serendipity['dbPrefix']}comments (entry_id, parent_id, ip, author, email, url, body, type, timestamp, title, subscribed, status)";
+ $query .= " VALUES ('$id', '$parentid', '$ip', '$name', '$email', '$url', '$commentsFixed', '$type', '$t', '$title', '$subscribe', '$status')";
- $query = "UPDATE {$serendipity['dbPrefix']}entries SET $field=$field+1, last_modified=$lm WHERE id='$id'";
serendipity_db_query($query);
+ $cid = serendipity_db_insert_id();
- $query = "SELECT email, title, mail_comments
- FROM {$serendipity['dbPrefix']}entries e, {$serendipity['dbPrefix']}authors a
- WHERE e.id = '$id'
- AND e.authorid = a.authorid";
- $row = serendipity_db_query($query, true);
+ $query = "SELECT email, title, mail_comments, e.moderate_comments
+ FROM {$serendipity['dbPrefix']}entries e, {$serendipity['dbPrefix']}authors a
+ WHERE e.id = '$id'
+ AND e.authorid = a.authorid";
+ $row = serendipity_db_query($query, true); // Get info on author/entry
- if ($row['mail_comments']) {
- serendipity_sendComment($row['email'], $name, $email, $url, $id, $row['title'], $comments, $type);
- }
+ serendipity_sendComment($cid, $row['email'], $name, $email, $url, $id, $row['title'], $comments, $type, serendipity_db_bool($row['moderate_comments']));
- if ($serendipity['allowSubscriptions']) {
- serendipity_mailSubscribers($id, $name, $email, $row['title'], $row['email']);
+ if (serendipity_db_bool($ca['moderate_comments']) == false) {
+ serendipity_approveComment($cid, serendipity_db_bool($row['mail_comments']), $id, $row['email'], $email, $name, $url, $row['title'], $comments, $type);
}
-
serendipity_purgeEntry($id, $t);
return true;
} else {
@@ -1738,7 +1793,7 @@
return serendipity_db_affected_rows();
}
-function serendipity_sendComment($to, $fromName, $fromEmail, $fromUrl, $id, $title, $comment, $type = 'NORMAL') {
+function serendipity_sendComment($comment_id, $to, $fromName, $fromEmail, $fromUrl, $id, $title, $comment, $type = 'NORMAL', $moderate_comment = false) {
global $serendipity;
if (empty($fromName)) {
@@ -1746,6 +1801,8 @@
}
$entryURI = serendipity_archiveURL($id, $title, 'baseURL', false);
+ $deleteURI = $serendipity['baseURL'] . ($serendipity['rewrite'] == 'none' ? $serendipity['indexFile'] . '?/' : '') . PATH_DELETECOMMENT . '/' . $comment_id . '/'. $id .'_' . serendipity_makeFilename($title) . '.html';
+ $approveURI = $serendipity['baseURL'] . ($serendipity['rewrite'] == 'none' ? $serendipity['indexFile'] . '?/' : '') . PATH_APPROVECOMMENT . '/' . $comment_id . '/'. $id .'_' . serendipity_makeFilename($title) . '.html';
if ($type == 'TRACKBACK') {
$subject = '[' . $serendipity['blogTitle'] . '] ' . NEW_TRACKBACK_TO . ' ' . $title;
@@ -1762,13 +1819,20 @@
$text = sprintf(A_NEW_COMMENT_BLAHBLAH, $serendipity['blogTitle'], $title)
. "\n" . LINK_TO_ENTRY . ': ' . $entryURI
. "\n"
+ . "\n" . REQUIRES_REVIEW . ': ' . (($moderate_comment) ? YES : NO)
. "\n" . USER . ' ' . IP_ADDRESS . ': ' . $_SERVER['REMOTE_ADDR']
. "\n" . USER . ' ' . NAME . ': ' . $fromName
. "\n" . USER . ' ' . EMAIL . ': ' . $fromEmail
. "\n" . USER . ' website: ' . $fromUrl
. "\n"
. "\n" . COMMENTS . ': '
- . "\n" . strip_tags($comment);
+ . "\n" . strip_tags($comment)
+ . "\n"
+ . "\n" . '----'
+ . "\n" . YOU_HAVE_THESE_OPTIONS
+ . (($moderate_comment) ? "\n" . str_repeat(' ', 2) . THIS_COMMENT_NEEDS_REVIEW : '')
+ . "\n" . str_repeat(' ', 3) . str_pad(DELETE_COMMENT, 15) . ' -- '. $deleteURI
+ . (($moderate_comment) ? "\n" . str_repeat(' ', 3) . str_pad(APPROVE_COMMENT, 15) . ' -- '. $approveURI : '');
}
return mail($to, $subject, $text . $serendipity['signature'], "From: {$serendipity['blogTitle']} - $fromName <$to>". (!empty($fromEmail) ? "\r\nReply-To: $fromEmail" : ''). "\r\n". $serendipity['mailheaders']);
@@ -2597,6 +2661,13 @@
$draftP = ' selected="selected"';
}
+ if (isset($entry['moderate_comments']) && (serendipity_db_bool($entry['moderate_comments']))) {
+ $moderate_comments = ' checked="checked"';
+ } else {
+ $moderate_comments = '';
+ }
+
+
if (isset($entry['allow_comments']) && (serendipity_db_bool($entry['allow_comments']))) {
$allow_comments = ' checked="checked"';
} elseif ((!isset($entry['allow_comments']) || $entry['allow_comments'] !== 'false') && ($serendipity['allowCommentsDefault'] == 'true' || $serendipity['allowCommentsDefault'] === true)) {
@@ -2808,8 +2879,12 @@
<td align="left">
<input id="checkbox_allow_comments" type="checkbox" name="serendipity[allow_comments]" value="true" <?php echo $allow_comments; ?> /><label for="checkbox_allow_comments"><?php echo COMMENTS_ENABLE; ?></label>
</td>
-
- <td align="right">
+ </tr>
+ <tr>
+ <td align="left">
+ <input id="checkbox_moderate_comments" type="checkbox" name="serendipity[moderate_comments]" value="true" <?php echo $moderate_comments; ?> /><label for="checkbox_moderate_comments"><?php echo COMMENTS_MODERATE; ?></label>
+ </td>
+ <td align="right" rowspan="2">
<input type="submit" value="- <?php echo PREVIEW; ?> -" style="font-weight: bold;" onclick="document.forms['serendipityEntry'].elements['serendipity[preview]'].value='true';" />
<input type="submit" value="- <?php echo SAVE; ?> -" style="font-weight: bold;" />
</td>
Index: comment.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/comment.php,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- comment.php 9 Jul 2004 22:55:25 -0000 1.39
+++ comment.php 16 Jul 2004 22:17:23 -0000 1.40
@@ -125,7 +125,7 @@
?>
<div class="serendipity_commentsTitle"><?php echo COMMENTS; ?></div>
<?php
- $query = "SELECT allow_comments FROM {$serendipity['dbPrefix']}entries WHERE id = '$id'";
+ $query = "SELECT allow_comments, moderate_comments FROM {$serendipity['dbPrefix']}entries WHERE id = '$id'";
$ca = serendipity_db_query($query, true);
serendipity_printComments(serendipity_fetchComments($id), (isset($ca['allow_comments']) ? $ca['allow_comments'] : true));
@@ -150,7 +150,10 @@
?>
<div class="serendipity_commentsTitle"><?php echo ADD_COMMENT; ?></div>
<?php
- serendipity_displayCommentForm($id, '?', $comments);
+ serendipity_displayCommentForm($id, '?', $comments, $serendipity['POST'], true, serendipity_db_bool($ca['moderate_comments']));
+ } elseif (!serendipity_db_bool($ca['allow_comments'])) { ?>
+ <div class="serendipity_center" style="color: #FF0000"><?php echo COMMENTS_CLOSED; ?></div>
+<?php
}
}
} else {
|