コメント投稿承認制
提供: GeeklogJpWiki
Geeklog1.6より,実装されたのでハックは不要です。
Geeklog1.5に対して投稿されたコメントを表示するかどうかを承認制にするハックです。
<データベースのcommentsテーブルにフィールドを追加>
ALTER TABLE `gl_comments` ADD `active` TINYINT NOT NULL DEFAULT '0';
<phpファイルを一部書き換え>
system/lib-comment.php
539行目:
$q = "SELECT c.*, u.username, u.fullname, u.photo, u.email, "
. "UNIX_TIMESTAMP(c.date) AS nice_date "
. "FROM {$_TABLES['comments']} AS c, {$_TABLES['users']} AS u "
. "WHERE c.uid = u.uid AND c.cid = $pid AND type='{$type}';
->
$q = "SELECT c.*, u.username, u.fullname, u.photo, u.email, "
. "UNIX_TIMESTAMP(c.date) AS nice_date "
. "FROM {$_TABLES['comments']} AS c, {$_TABLES['users']} AS u "
. "WHERE c.uid = u.uid AND c.cid = $pid AND type='{$type}' and active>0";
547行目:
$q = "SELECT c.*, u.username, u.fullname, u.photo, u.email, "
. "UNIX_TIMESTAMP(c.date) AS nice_date "
. "FROM {$_TABLES['comments']} AS c, {$_TABLES['users']} AS u "
. "WHERE c.uid = u.uid AND c.sid = '$sid' AND type='{$type}' "
. "ORDER BY date $order LIMIT $start, $limit";
->
$q = "SELECT c.*, u.username, u.fullname, u.photo, u.email, "
. "UNIX_TIMESTAMP(c.date) AS nice_date "
. "FROM {$_TABLES['comments']} AS c, {$_TABLES['users']} AS u "
. "WHERE c.uid = u.uid AND c.sid = '$sid' AND type='{$type}' and active>0 "
. "ORDER BY date $order LIMIT $start, $limit";
568行目:
$q2 = "SELECT COUNT(*) "
. "FROM {$_TABLES['comments']} AS c, {$_TABLES['comments']} AS c2 "
. "WHERE c.sid = '$sid' AND (c.lft >= c2.lft AND c.lft <= c2.rht) "
. "AND c2.cid = $pid AND c.type='{$type}'";
->
$q2 = "SELECT COUNT(*) "
. "FROM {$_TABLES['comments']} AS c, {$_TABLES['comments']} AS c2 "
. "WHERE c.sid = '$sid' AND (c.lft >= c2.lft AND c.lft <= c2.rht) "
. "AND c2.cid = $pid AND c.type='{$type}' and c.active>0";
575行目:
$q = "SELECT c.*, u.username, u.fullname, u.photo, u.email, c2.indent AS pindent, "
. "UNIX_TIMESTAMP(c.date) AS nice_date "
. "FROM {$_TABLES['comments']} AS c, {$_TABLES['comments']} AS c2, "
. "{$_TABLES['users']} AS u "
. "WHERE c.sid = '$sid' AND (c.lft >= c2.lft AND c.lft <= c2.rht) "
. "AND c2.cid = $pid AND c.uid = u.uid AND c.type='{$type}' "
. "ORDER BY $cOrder LIMIT $start, $limit";
->
$q = "SELECT c.*, u.username, u.fullname, u.photo, u.email, c2.indent AS pindent, "
. "UNIX_TIMESTAMP(c.date) AS nice_date "
. "FROM {$_TABLES['comments']} AS c, {$_TABLES['comments']} AS c2, "
. "{$_TABLES['users']} AS u "
. "WHERE c.sid = '$sid' AND (c.lft >= c2.lft AND c.lft <= c2.rht) "
. "AND c2.cid = $pid AND c.uid = u.uid AND c.type='{$type}' and c.active>0 "
. "ORDER BY $cOrder LIMIT $start, $limit";
588行目:
$q = "SELECT c.*, u.username, u.fullname, u.photo, u.email, 0 AS pindent, "
. "UNIX_TIMESTAMP(c.date) AS nice_date "
. "FROM {$_TABLES['comments']} AS c, {$_TABLES['users']} AS u "
. "WHERE c.sid = '$sid' AND c.uid = u.uid AND type='{$type}' "
. "ORDER BY $cOrder LIMIT $start, $limit";
->
$q = "SELECT c.*, u.username, u.fullname, u.photo, u.email, 0 AS pindent, "
. "UNIX_TIMESTAMP(c.date) AS nice_date "
. "FROM {$_TABLES['comments']} AS c, {$_TABLES['users']} AS u "
. "WHERE c.sid = '$sid' AND c.uid = u.uid AND type='{$type}' and active>0 "
. "ORDER BY $cOrder LIMIT $start, $limit";
595行目:
$q2 = "SELECT COUNT(*) "
. "FROM {$_TABLES['comments']} AS c, {$_TABLES['comments']} AS c2 "
. "WHERE c.sid = '$sid' AND (c.lft > c2.lft AND c.lft < c2.rht) "
. "AND c2.cid = $pid AND c.type='{$type}'";
->
$q2 = "SELECT COUNT(*) "
. "FROM {$_TABLES['comments']} AS c, {$_TABLES['comments']} AS c2 "
. "WHERE c.sid = '$sid' AND (c.lft > c2.lft AND c.lft < c2.rht) "
. "AND c2.cid = $pid AND c.type='{$type}' and c.active>0";
602行目:
$q = "SELECT c.*, u.username, u.fullname, u.photo, u.email, c2.indent + 1 AS pindent, "
. "UNIX_TIMESTAMP(c.date) AS nice_date "
. "FROM {$_TABLES['comments']} AS c, {$_TABLES['comments']} AS c2, "
. "{$_TABLES['users']} AS u "
. "WHERE c.sid = '$sid' AND (c.lft > c2.lft AND c.lft < c2.rht) "
. "AND c2.cid = $pid AND c.uid = u.uid AND c.type='{$type}' "
. "ORDER BY $cOrder LIMIT $start, $limit";
->
$q = "SELECT c.*, u.username, u.fullname, u.photo, u.email, c2.indent + 1 AS pindent, "
. "UNIX_TIMESTAMP(c.date) AS nice_date "
. "FROM {$_TABLES['comments']} AS c, {$_TABLES['comments']} AS c2, "
. "{$_TABLES['users']} AS u "
. "WHERE c.sid = '$sid' AND (c.lft > c2.lft AND c.lft < c2.rht) "
. "AND c2.cid = $pid AND c.uid = u.uid AND c.type='{$type}' and c.active>0 "
. "ORDER BY $cOrder LIMIT $start, $limit";
admin/moderation.php
227行目に追記
$retval .= commentlist ($token);
482行目あたり:
if (!empty ($type) && ($type <> 'story') && ($type <> 'draft')) {
->
if(!empty($type) and $type=="comment"){
$sql="select * from gl_comments where cid='".$mid[$i]."'";
$rc=DB_fetchArray(DB_query($sql));
$sql="update gl_stories set comments=comments-1 where sid='".$rc["sid"]."'";
DB_query($sql);
$sql="delete from gl_comments where cid='".$mid[$i]."'";
DB_query($sql);
$retval .= commandcontrol(SEC_createToken());
return $retval;
}elseif (!empty ($type) && ($type <> 'story') && ($type <> 'draft')) {
525行目あたり:
}else{
->
}elseif($type=="comment"){
$sql="update gl_comments set active=1 where cid='".$mid[$i]."'";
DB_query($sql);
}else{
最終行に追記
function commentlist($token){
global $_TABLES;
$retval="<form action='moderation.php' method='post'>\n";
$retval.="<div class='block-center'>\n";
$retval.="<h2>コメントの投稿管理</h2>\n";
$retval.="<table class='admin-list'>\n";
$retval.="<tr><th class='admin-list-headfield'>日付</th><th class='admin-list-headfield'>記事</th>
<th class='admin-list-headfield'>コメント</th><th class='admin-list-headfield'>削除</th>
<th class='admin-list-headfield'>承認</th></tr>\n";
$n=0;
$sql="select * from ".$_TABLES["comments"]." where active=0";
$rs=DB_query($sql);
while($rc=DB_fetchArray($rs)){
$retval.="<tr class='admin-listitem1'>
<td class='admin-list-field'>".substr($rc["date"],0,10)."<input type='hidden' name='id[".$n."]' value='".$rc["cid"]."' /></td>
<td class='admin-list-field'>".$rc["title"]."</td>
<td class='admin-list-field'>".mb_strimwidth($rc["comment"],0,20,"...","UTF8")."</td>
<td class='admin-list-field'><input type='radio' name='action[".$n."]' value='delete'></td>
<td class='admin-list-field'><input type='radio' name='action[".$n."]' value='approve'></td>
</tr>\n";
$n++;
}
$retval.="</table>\n";
if(!empty($n)){
$retval.="<input type='hidden' name='type' value='comment'>
<input type='hidden' name='".CSRF_TOKEN."' value='".$token."' />
<input type='hidden' name='mode' value='moderation'>
<input type='hidden' name='count' value='".$n."'>
<p class='aligncenter'><input type='submit' value='実行'></p>\n";
}else{
$retval.="<p class='admin-list-message'>現在のところ申請はありません</p>";
}
$retval.="</div>\n";
$retval.="</form>\n";
return $retval;
}
system/lib-story.php 346行目あたり:
$comments_with_count = sprintf( $LANG01[121], COM_numberFormat( $story->DisplayElements('comments') ));
->
$sql="select count(*) as c from ".$_TABLES["comments"]." where sid='".$story->getSid()."' and active=1";
$rcn=DB_fetchArray(DB_query($sql));
$story->_comments=(int)$rcn["c"];
$comments_with_count = sprintf( $LANG01[121], COM_numberFormat( $story->DisplayElements('comments') ));
system/lib-comment.php 90行目あたりにある
$commentbar->set_var( 'num_comments', COM_numberFormat( $nrows ));
->
$sql="select count(*) as c from ".$_TABLES["comments"]." where sid='".$sid."' and active=1"; $rcn=DB_fetchArray(DB_query($sql)); $nrows=(int)$rcn["c"]; $commentbar->set_var( 'num_comments', COM_numberFormat( $nrows ));
lib-common.php 2788行目あたりにある
$adminmenu->set_var( 'option_count', COM_numberFormat( $modnum ));
->
$sql="select count(*) as c from ".$_TABLES["comments"]." where active=0"; $rcn=DB_fetchArray(DB_query($sql)); $modnum+=(int)$rcn["c"]; $adminmenu->set_var( 'option_count', COM_numberFormat( $modnum ));