サイトにいただいた、コメント/トラックバックを集計して管理画面に表示するプラグイン wp-kumonosu を使用しているのだが、このプラグインではblog.livedoor.jp、d.hatena.ne.jp などのサブドメイン形式ではないサイトから頂いたコメントがすべてまとめて集計されてしまう。
ソースを追ってみたところ、WpKumonosuModel_V10 クラスの makeLinks() 関数を修正すれば良さそうだったので、ちょっと修正してみた。
ただし、修正が確認できたのは Analyze のところだけ、Akismet filter が正常に動作するかは確認していません。
とりあえず問題なさそうなので、このまま使ってみよう。
269行目からの sql 文を組み立てているところを、以下のように修正すればとりあえず対応できます。
$not_subdomain_site = "'blog.livedoor.jp'," . "'blog.goo.ne.jp'," . "'blog.drecom.jp'," . "'blog.so-net.ne.jp'," . "'d.hatena.ne.jp'," . "'ameblo.jp'," . "'yaplog.jp'"; $sql = '(SELECT' . ' comments.comment_author as author,' . ' comments.comment_author_url as author_url,' . ' count(comments.comment_author) as comment_count,' . ' \'00000\' as trackback_count,' . ' SUBSTRING_INDEX(REPLACE(comments.comment_author_url, \'http://\', \'\'), \'/\', 1) as hostname' . ' FROM' . " $wpdb->comments as comments" . ' WHERE' . ' comments.comment_approved = \'1\' AND' . ' REPLACE(comments.comment_author_url, \'http://\', \'\') <> \'\' AND' . ' SUBSTRING_INDEX(REPLACE(comments.comment_author_url, \'http://\', \'\'), \'/\', 1)' . ' not in ('.$not_subdomain_site.') AND' . ' comments.comment_type = \'\'' . ' GROUP BY' . ' hostname' . ' ORDER BY' . ' comment_date DESC' . ')' . ' UNION' . '(SELECT' . ' comments.comment_author as author,' . ' comments.comment_author_url as author_url,' . ' count(comments.comment_author) as comment_count,' . ' \'00000\' as trackback_count,' . ' SUBSTRING_INDEX(REPLACE(comments.comment_author_url, \'http://\', \'\'), \'/\', 2) as hostname' . ' FROM' . " $wpdb->comments as comments" . ' WHERE' . ' comments.comment_approved = \'1\' AND' . ' SUBSTRING_INDEX(REPLACE(comments.comment_author_url, \'http://\', \'\'), \'/\', 1)' . ' in ('.$not_subdomain_site.') AND' . ' comments.comment_type = \'\'' . ' GROUP BY' . ' hostname' . ' ORDER BY' . ' comment_date DESC' . ')' . ' UNION' . '(SELECT' . ' trackbacks.comment_author as author,' . ' trackbacks.comment_author_url as author_url,' . ' \'00000\' as comment_count,' . ' count(trackbacks.comment_author) as trackback_count,' . ' SUBSTRING_INDEX(REPLACE(trackbacks.comment_author_url, \'http://\', \'\'), \'/\', 1) as hostname' . ' FROM' . " $wpdb->comments as trackbacks" . ' WHERE' . ' trackbacks.comment_approved = \'1\' AND' . ' trackbacks.comment_author_url <> \'\' AND' . ' SUBSTRING_INDEX(REPLACE(trackbacks.comment_author_url, \'http://\', \'\'), \'/\', 1)' . ' not in ('.$not_subdomain_site.') AND' . ' trackbacks.comment_type = \'trackback\'' . ' GROUP BY' . ' hostname' . ' ORDER BY' . ' comment_date DESC' . ')' . ' UNION' . '(SELECT' . ' trackbacks.comment_author as author,' . ' trackbacks.comment_author_url as author_url,' . ' \'00000\' as comment_count,' . ' count(trackbacks.comment_author) as trackback_count,' . ' SUBSTRING_INDEX(REPLACE(trackbacks.comment_author_url, \'http://\', \'\'), \'/\', 2) as hostname' . ' FROM' . " $wpdb->comments as trackbacks" . ' WHERE' . ' trackbacks.comment_approved = \'1\' AND' . ' SUBSTRING_INDEX(REPLACE(trackbacks.comment_author_url, \'http://\', \'\'), \'/\', 1)' . ' in ('.$not_subdomain_site.') AND' . ' trackbacks.comment_type = \'trackback\'' . ' GROUP BY' . ' hostname' . ' ORDER BY' . ' comment_date DESC' . ')';
対応するブログサイトを増やすには $not_subdomain_site の内容を修正すればおっけ。
where 句の中で関数を使うという破廉恥なコードです。
気になる方は、like 文を使うように修正したほうがよろしいかと (^^;;