- 2009-05-04 (月) 19:16
- WordPress
[追記]
この内容に関して2009年5月7日付で提供元の cougar さんに対応していただけました!
wp.vicuna.CMS.Ext.Customなんですが、ダウンロードしたまま適応するとスパムコメントやスパムピンバック・トラックバックが表示されることが判明しました。その件について、入れ子方式に改変に際してこの記事のひとつ前の記事で追加したんですが、「コメントの入れ子なんて使わねーよ」って人もいると思うんで改めてこれについてだけ記事にすることにしました。緊急を要すると思うので適応していただけたらと思います。
変更するのはwp.vicuna.excフォルダ直下のcomments.phpとfunction.phpのみです。ちなみに消去するコードには『erase』を、追加するコードには『add』を行単位の場合は行頭または行末に付けてます。また大幅に追加した箇所は『add start』から『add end』の範囲としてます。
まずはcomments.phpから。wp.vicuna.CMS.Ext.Customでは個々の記事においてコメントとトラックバック/ピンバックの数をそれぞれカウントして、その数からそれぞれを表示するかどうかを判定しています。ので、まずはカウントしているコードに『smap』フラグが付いたコメントをカウントから除くように改編します。
/* to split comment and pings */
$trackpingCount = 0;
$commentCount = 0;
/* -- whisper add s -- */
global $wpdb;
$comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d ORDER BY comment_date", $post->ID));
/* -- whisper add e -- */
if ($comments) :
foreach ($comments as $comment) {
$type = get_comment_type();
$approved = $comments->comment_approved;
switch( $type ) {
case 'trackback' :
case 'pingback' :
//erase $trackpingArray[$trackpingCount++] = $comment;
if ( $approved != 'spam') : $trackpingArray[$trackpingCount++] = $comment; endif; //add
break;
default :
//erase $commentArray[$commentCount++] = $comment;
if ( $approved != 'spam') : $commentArray[$commentCount++] = $comment; endif; //add
}
}
endif;
これでスパム判定されたものを除いた数が取得できます。次にスパムと判定されたものを表示しないようにコードを改変します。コード内では承認されている場合とそうでない場合に分けて表示されるようになっています。この判定にそうでない場合を承認されていない場合としてしまいます。具体的にコメントに関するコードについて次のように改変します。
if ($commentCount > 0) :
vicuna_edit_comments_link(__('Edit this comments.', 'vicuna'), '<p class="admin">', '</p>'); ?>
<dl class="log">
<?php foreach ($commentArray as $comment) : ?>
<?php
/* -- whisper add s -- */
if('1' == $comment->comment_approved){
/* -- whisper add e -- */
?>
<dt id="comment<?php comment_ID() ?>"><span class="name"><?php comment_author_link() ?></span> <span class="date"><?php comment_date(__('y-m-d (D) G:i', 'vicuna')) ?></span> <?php edit_comment_link(__('Edit', 'vicuna'), '<span class="admin">', '</span>'); ?></dt>
<dd>
<?php comment_text() ?>
<?php
/* -- whisper add s -- */
//} else { // erase
} else if('0' == $comment->comment_approved){ // add
?>
<dt id="comment<?php comment_ID() ?>"><span class="name">******</span> <span class="date"><?php comment_date(__('y-m-d (D) G:i', 'vicuna')) ?></span> </dt>
<dd>
<?php
_e('This comment is awaiting the approval of the author','vicuna');
}
/* -- whisper add e -- */
?>
</dd>
<?php endforeach; ?>
ついでにトラックバック・ピンバックについて。こちらは承認していない場合のコードがなかったので、承認してない場合のコードを大きく付加してます。
if ($trackpingCount > 0 || 'open' == $post->ping_status) : ?>
<div class="section" id="trackback">
<h2><?php if ('open' == $post->ping_status) : _e('Trackbacks', 'vicuna'); else : _e('Trackbacks (Close)', 'vicuna'); endif; ?>:<span class="count"><?php echo $trackpingCount; ?></span></h2>
<?php if ('open' == $post->ping_status) : ?>
<dl class="info">
<dt><?php _e('Trackback URL for this entry', 'vicuna'); ?></dt>
<dd class="URL"><?php trackback_url(); ?></dd>
<dt><?php _e('Listed below are links to weblogs that reference', 'vicuna'); ?></dt>
<dd><?php printf(__('%s from %s', 'vicuna'), '<a href="'. get_permalink() .'">'. get_the_title() .'</a>', '<a href="'.get_bloginfo('home'). '">'. get_bloginfo('name') .'</a>'); ?></dd>
</dl>
<?php endif;
if ($trackpingCount > 0) :
vicuna_edit_comments_link(__('Edit this comments.', 'vicuna'), '<p class="admin">', '</p>'); ?>
<dl class="log">
<?php foreach ($trackpingArray as $comment) : ?>
<?php
if('1' == $comment->comment_approved){ //add
?>
<dt id="ping<?php comment_ID() ?>"><span class="name"><?php printf(__("%s from %s", 'vicuna'), get_comment_type(), get_comment_author_link()); ?></span> <span class="date"><?php comment_date(__('y-m-d (D) G:i', 'vicuna')); ?></span></dt>
<dd>
<?php comment_text() ?>
<?php
// add start
} else if('0' == $comment->comment_approved){
?>
<dt id="ping<?php comment_ID() ?>"><span class="name">******</span> <span class="date"><?php comment_date(__('y-m-d (D) G:i', 'vicuna')); ?></span></dt>
<dd>
<?php
_e('This comment is awaiting the approval of the author','vicuna');
}
// add end
?>
</dd>
<?php endforeach; ?>
</dl>
<?php endif; ?>
これで個々の記事に関する改変は終了です。
function.phpのほうはコメントの表示には直接影響せず、コメントとトラックバック/ピンバックの数をカウントしているだけです。が、表示されていないコメントがカウントされて表示されるのはいささか気持ち悪いので次のように改変します。
/**
* Return the total amount of pings.
*/
function get_vicuna_pings_count() {
global $post, $wpdb, $id;
/* -- whisper cng s --
$comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND comment_approved = '1' AND comment_type != '' ORDER BY comment_date");
-- */
// $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND (comment_type = 'trackback' OR comment_type = 'pingback') ORDER BY comment_date"); // erase
$comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND comment_approved = '1' AND (comment_type = 'trackback' OR comment_type = 'pingback') ORDER BY comment_date"); // add
/* -- whisper cng e -- */
// $comments = apply_filters( 'comments_array', $comments, $post->ID );
return count($comments);
}
/* -- whisper add s -- */
function get_vicuna_comment_count() {
global $post, $wpdb, $id, $comments;
// $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND (comment_approved = '1' or comment_type = 'whisper')");
// $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' order by comment_date"); // erase
$comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND comment_approved = '1' order by comment_date"); // add
return count($comments);
}
/* -- whisper add e -- */
これでスパムも表示されず、カウントもされないはずです。
#hiromasa さん、後押ししてくださってありがとうございますm(_ _)m
- 関連記事:
関連記事は今のところありません
- Newer: コンタクトフォームを設置しました
- Older: コメントの入れ子方式について(vicuna CMS Ext. Customに対して)
Comments:0
Trackbacks:1
- Trackback URL for this entry
- http://shinonon-web.net/2009/05/04/753/trackback/
- Listed below are links to weblogs that reference
- wp.vicuna.CMS.Ext.Customでスパムコメント・トラックバックが公開される件(対策法) from ある日の小さなつぶやき
- trackback from the Fang of Sky 09-05-07 (木) 0:09
-
wp.Vicuna Ext. Custom バージョンアップ
バージョンアップ、と言うか、主にバグ修正です。
wp.Vicuna Ext. Custom で以下の点を修正しました。コンフィグでスキンを選択しても反映されないバグを修正。
スパムコメ…











