自作プラグイン 「comment3」

  • 公式プラグインに「#comment」というのがありますし、複数行投稿用のコメント欄作成プラグインとして「comment2」というのも自作しました
  • しかし、これらを使って書き込んだ事項を消す場合は、いちいち編集をしなければならず、面倒です。
  • そこで、複数行のコメントをテキストエリアに書き込んで「投稿」すると、そのままテキストエリアに記事を保持してくれて、次回はページ全体の編集を起動することなしに、そのテキストエリア内で投稿済みの書き込みを直接編集して再度「投稿」すればいい、というプラグインの作成に挑戦してみました

目次

プラグイン コード

  • comment3.inc.pl
 ##
 # 一時書き込みエリアを設置する。
 # :書式|
 #  #comment3 
  
 # PyukiWiki 一時コメント書き込みプラグイン
 # 書き込みはテキストエリア内に保持され、修正時は編集も該エリア内で編集して再度「投稿」すればok
 # 
 # 2007/01/15 スパム対策
 # 2004/06/12 Nekyo(c) http://nekyo.hp.infoseek.co.jp/
 # Based on OKAWARA,Satoshi's PukiWiki Plugin
 # 2013/9/16 koala
 use strict;
  
 $comment3::cols = 70;						# テキストエリアのカラム数
 $comment3::rows = 5;							# テキストエリアの行数
 $comment3::no = 0;
 my $mescom="";
  
 my $_no_name = "";
 my $_no_subject = "no subject";
  
 sub plugin_comment3_action
 {
 	return if ($::form{msg} =~ /^\s*$/); # msg なしで処理しない。
 	my $postdata = $::form{msg};
  
 	&::spam_filter($postdata, 1);
 	my $name = $_no_name;
 	 $mescom = $::form{msg};
 #	$mescom =~ s/\r?\n/\~\r\n/g;
 	$mescom =~ s/\r?\n/<br>/g;
 	$postdata = '';
 	my @postdata_old = split(/\r?\n/, $::database{$::form{'mypage'}});
 	my $_comment3_no = 0;
  
 	foreach (@postdata_old) {
 #		$postdata .= $_ . "\n" ;
 		if (/^#comment3/ && (++$_comment3_no == $::form{comment3_no})) {
 			$postdata .= "#comment3\(" . $mescom . "\)\n";
 		} else {
  
 		$postdata .= $_ . "\n" ;
  
 		}
 	}
 	$::form{mymsg} = $postdata;
 	$::form{mytouch} = 'on';
 	&do_write("FrozenWrite");
 	&close_db;
 	exit;
 }
  
 sub plugin_comment3_convert
 {
 ###
 #	my @argv = split(/,/, shift);
 	my $artic = shift;
  
 #	my $artic = $mescom;
 	$artic =~ s/&lt;br>/\r\n/g;
 ###
 	$comment3::no++;
 	my $conflictchecker = &get_info($::form{mypage}, $::info_ConflictChecker);
 	return <<"EOD";
 <form action="$::script" method="post">
  <div>
   <input type="hidden" name="comment3_no" value="$comment3::no" />
   <input type="hidden" name="cmd" value="comment3" />
   <input type="hidden" name="mypage" value="$::form{'mypage'}" />
   <input type="hidden" name="myConflictChecker" value="$conflictchecker" />
   <input type="hidden" name="mytouch" value="on" />
 <!--  <textarea name="msg" rows="$comment3::rows" cols="$comment3::cols">$artic</textarea><br /> -->
   <textarea name="msg" rows="$comment3::rows" cols="$comment3::cols">$artic</textarea>
   <input type="submit" value="$::resource{article_btn}" />
  </div>
 </form>
 EOD
 }
  
 1;
  

「comment」プラグインの修正

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

Counter: 2555, today: 2, yesterday: 1


Last-modified: 2014-11-09