自作プラグイン 「comment2」

  • 公式プラグインに「#comment」というのがありますが、一行コメントしか投稿できず、タグも使えません。
  • 複数行コメントを投稿するには「article」プラグインがありますが、これは章立てを伴う大掛かりな掲示板風のコードを生成するプラグインで、単に改行や「-」を用いた箇条書きを含む程度の複数行コメントを、レイアウトを縛られることなく投稿するのには向いていません
  • 少なくとも自作版は、セキュリティ面の対策もしていないので、イントラネットなど安全な環境での利用をお勧めします

目次

プラグイン コード

  • ファイル名:comment2.inc.pl
 ##
 # 簡易掲示板を設置する。
 # :書式|
 #  #comment2 
  
 # PyukiWiki 複数行コメント書き込みプラグイン
 # 「-」などの箇条書きタグが使えます
 # 改行も反映
 # 2007/01/15 スパム対策
 # 2004/06/12 Nekyo(c) http://nekyo.hp.infoseek.co.jp/
 # Based on OKAWARA,Satoshi's PukiWiki Plugin
 # 2013/09/13 koala 
 use strict;
  
 $comment2::cols = 70;						# テキストエリアのカラム数
 $comment2::rows = 5;							# テキストエリアの行数
 $comment2::ins = ($::form{above} == 1) ? 1 : 0;		# 挿入する位置 1:欄の前 0:欄の後
 $comment2::no = 0;
  
 my $_no_name = "";
 my $_no_subject = "no subject";
  
 sub plugin_comment2_action
 {
 	return if ($::form{msg} =~ /^\s*$/); # msg なしで処理しない。
 	my $postdata = $::form{msg};
  
 	&::spam_filter($postdata, 1);
 	my $name = $_no_name;
 	my $mescom = $::form{msg};
 	$mescom =~ s/\r?\n/\~\r\n/g;
 	my $artic = ($::form{nodate} == 1) ? "\n\n$mescom\n"  : "\n(@{[&get_now]})~\n$mescom\n";
 	$postdata = '';
 	my @postdata_old = split(/\r?\n/, $::database{$::form{'mypage'}});
 	my $_comment2_no = 0;
  
 	foreach (@postdata_old) {
 		$postdata .= $_ . "\n" if (!$comment2::ins);
 		if (/^#comment2/ && (++$_comment2_no == $::form{comment2_no})) {
 			$postdata .= "$artic\n";
 		}
 		$postdata .= $_ . "\n" if ($comment2::ins);
 	}
 	$::form{mymsg} = $postdata;
 	$::form{mytouch} = 'on';
 	&do_write("FrozenWrite");
 	&close_db;
 	exit;
 }
  
 sub plugin_comment2_convert
 {
 ###
 	my @argv = split(/,/, shift);
  
 	my $above = 0;
 	my $nodate = '';
  
 	foreach (@argv) {
 		chomp;
 		if (/above/) {
 			$above = 1;
 		} elsif (/nodate/) {
 			$nodate = 1;
 		}
 	}
  
 ###
 	$comment2::no++;
 	my $conflictchecker = &get_info($::form{mypage}, $::info_ConflictChecker);
 	return <<"EOD";
 <form action="$::script" method="post">
  <div>
   <input type="hidden" name="comment2_no" value="$comment2::no" />
   <input type="hidden" name="cmd" value="comment2" />
   <input type="hidden" name="mypage" value="$::form{'mypage'}" />
   <input type="hidden" name="myConflictChecker" value="$conflictchecker" />
   <input type="hidden" name="mytouch" value="on" />
    <input type="hidden" name="nodate" value="$nodate" />
    <input type="hidden" name="above" value="$above" />
   <textarea name="msg" rows="$comment2::rows" cols="$comment2::cols"></textarea>
   <input type="submit" value="$::resource{article_btn}" />
  </div>
 </form>
 EOD
 }
  
 1;

「comment」プラグインの修正

  • 上記「comment2」を「comment」プラグインと同じページで使用すると干渉してしまいます。プラグイン名が「comment」プラグインと同じく「comment」で始まるので、「comment」プラグインのほうで「comment2」プラグインを「comment」プラグインと誤認してしまうのが原因です。
  • 対策としては、下記2とおり。
    1. 「comment2」プラグインの名称を「comment」で始まらない別の名称にする(例:「multicomment」)
    2. 「comment」プラグインのコードを書き換える
  • iの場合は、ファイル名のほか、上記コード中の「comment2」をことごとく、上記「別の名称」に書き換える
  • iiの場合は、「comment」プラグインを下記のとおり書き換える
 sub plugin_comment_action { 
 内の
 		if (/^#comment/ && (++$_comment_no == $::form{comment_no})) {
 を
                   if (/^#comment(\(.*\))?$/ && (++$_comment_no == $::form{comment_no})) { 
 と書き換える

Counter: 2819, today: 2, yesterday: 1


Last-modified: 2014-11-09