** plugin_comment.patch [#p14d088a]
** plugin_comment.patch [#AboutPlugin]
|RIGHT:100|LEFT:360|c
|~サマリ|comment.inc.phpの機能を拡張する|
|~リビジョン|1.0|
|~リビジョン|2.0|
|~対応バージョン|1.5 (branch_r1_5)|
|~投稿者|[[NoName]]|
|~投稿日|&new{2016-01-16 (土) 14:06:49};|
標準のcomment.inc.phpの機能を拡張します
diff形式なのでpatchコマンドもしくは手動で書き換えてください。

commentプラグインに名前の入力を強制する forcename オプションを追加します
ついでにコメント無しで投稿した場合にもエラー文を出すようにしました

従来の noname オプションと併用した場合は noname の方を優先して名前は必要ありません

 --- ./plugin.org/comment.inc.php	2016-01-11 01:22:46.000000000 +0900
 +++ ./plugin/comment.inc.php	2016-01-15 15:43:25.500895000 +0900
 @@ -23,6 +23,9 @@ function plugin_comment_action()
  	global $script, $vars, $now, $_title_updated, $_no_name;
  	global $_msg_comment_collided, $_title_comment_collided;
 +++ ./plugin/comment.inc.php	2016-01-20 16:35:39.744467900 +0900
 @@ -25,20 +25,37 @@ function plugin_comment_action()
  
  	if (PKWK_READONLY) die_message('PKWK_READONLY prohibits editing');
  
 -	if (! isset($vars['msg'])) return array('msg'=>'', 'body'=>''); // Do nothing
 +	$vars['page'] = $vars['refer'];
 +	$vars['_error'] = 'コメントがありません';
 +	$_num = '#'.$vars['comment_no'];
 +	$vars['_error'][$_num] = 'コメントがありません';
 +	$vars['_name'][$_num] = $vars['name'];
 +	$vars['_msg'][$_num] = $vars['msg'];
 +
  	if (PKWK_READONLY) die_message('PKWK_READONLY prohibits editing');
  
  	if (! isset($vars['msg'])) return array('msg'=>'', 'body'=>''); // Do nothing
 @@ -35,10 +38,20 @@ function plugin_comment_action()
  		$vars['msg'] = & $match[2];
 -	$vars['msg'] = str_replace("\n", '', $vars['msg']); // Cut LFs
 +	if (! isset($vars['_msg'][$_num])) return array('msg'=>'', 'body'=>''); // Do nothing
 +
 +	$vars['_msg'][$_num] = str_replace("\n", '', $vars['_msg'][$_num]); // Cut LFs
  	$head = '';
  	$match = array();
 -	if (preg_match('/^(-{1,2})-*\s*(.*)/', $vars['msg'], $match)) {
 +	if (preg_match('/^(-{1,2})-*\s*(.*)/', $vars['_msg'][$_num], $match)) {
  		$head        = & $match[1];
 -		$vars['msg'] = & $match[2];
 +		$vars['_msg'][$_num] = & $match[2];
  	}
  	if ($vars['msg'] == '') return array('msg'=>'', 'body'=>''); // Do nothing
 +	
 +	$vars['_error'] = '「お名前」の入力をおねがいします';
 -	if ($vars['msg'] == '') return array('msg'=>'', 'body'=>''); // Do nothing
 +	if ($vars['_msg'][$_num] == '') return array('msg'=>'', 'body'=>''); // Do nothing
 +
 +	$vars['_error'][$_num] = '「お名前」の入力をおねがいします';
  
  	$comment  = str_replace('$msg', $vars['msg'], PLUGIN_COMMENT_FORMAT_MSG);
  	if(isset($vars['name']) || ($vars['nodate'] != '1')) {
  		$_name = (! isset($vars['name']) || $vars['name'] == '') ? $_no_name : $vars['name'];
 -	$comment  = str_replace('$msg', $vars['msg'], PLUGIN_COMMENT_FORMAT_MSG);
 -	if(isset($vars['name']) || ($vars['nodate'] != '1')) {
 -		$_name = (! isset($vars['name']) || $vars['name'] == '') ? $_no_name : $vars['name'];
 +	$comment  = str_replace('$msg', $vars['_msg'][$_num], PLUGIN_COMMENT_FORMAT_MSG);
 +	if(isset($vars['_name'][$_num]) || ($vars['nodate'] != '1')) {
 +		$_name = (! isset($vars['_name'][$_num]) || $vars['_name'][$_num] == '') ? $_no_name : $vars['name'];
 +		if ($vars['forcename'] && $_name == $_no_name) {
 +			$vars['msg'] = htmlsc($vars['msg']);
 +			$vars['_msg'][$_num] = htmlsc($vars['_msg'][$_num]);
 +			return array('msg'=>'', 'body'=>'');
 +		} else {
 +			$vars['_error'] = '';
 +			$vars['msg'] = '';
 +			$vars['name'] = $vars['forcename'] ? htmlsc($_name) : '';
 +			$vars['_error'][$_num] = '';
 +			$vars['_msg'][$_num] = '';
 +			$vars['_name'][$_num] = $vars['forcename'] ? $_name : '';
 +		}
  		$_name = ($_name == '') ? '' : str_replace('$name', $_name, PLUGIN_COMMENT_FORMAT_NAME);
  		$_now  = ($vars['nodate'] == '1') ? '' :
  			str_replace('$now', $now, PLUGIN_COMMENT_FORMAT_NOW);
 @@ -78,8 +91,6 @@ function plugin_comment_action()
 @@ -78,8 +95,6 @@ function plugin_comment_action()
  	$retvars['msg']  = $title;
  	$retvars['body'] = $body;
  
 -	$vars['page'] = $vars['refer'];
 -
  	return $retvars;
  }
  
 @@ -103,26 +114,33 @@ function plugin_comment_convert()
 @@ -94,6 +109,10 @@ function plugin_comment_convert()
  	if (! isset($numbers[$vars['page']])) $numbers[$vars['page']] = 0;
  	$comment_no = $numbers[$vars['page']]++;
  
 +	$_name = $vars['_name']['#'.$comment_no];
 +	$_msg = $vars['_msg']['#'.$comment_no];
 +	$_error = $vars['_error']['#'.$comment_no];
 +
  	$options = func_num_args() ? func_get_args() : array();
  	if (in_array('noname', $options)) {
  		$nametags = '<label for="_p_comment_comment_' . $comment_no . '">' .
 @@ -103,31 +122,39 @@ function plugin_comment_convert()
  			$_btn_name . '</label>' .
  			'<input type="text" name="name" id="_p_comment_name_' .
  			$comment_no .  '" size="' . PLUGIN_COMMENT_SIZE_NAME .
 +			'" value="'.htmlsc($vars['name']).
 +			'" value="'.htmlsc($_name).
  			'" />' . "\n";
  	}
 +	$forcename = (in_array('forcename', $options) && !in_array('noname', $options))? '1' : '0';
  	$nodate = in_array('nodate', $options) ? '1' : '0';
  	$above  = in_array('above',  $options) ? '1' :
  		(in_array('below', $options) ? '0' : PLUGIN_COMMENT_DIRECTION_DEFAULT);
  
  	$script = get_script_uri();
  	$s_page = htmlsc($vars['page']);
 +	$vars['_error'] = $vars['_error'] ? "<p> ERROR: ".htmlsc($vars['_error'])."</p>" : "";
 +	$_error = $_error ? "<p> ERROR: ".htmlsc($_error)."</p>" : "";
  	$string = <<<EOD
  <br />
 -<form action="$script" method="post">
 +<form action="$script?cmd=comment&refer=$s_page" method="post">
   <div>
 +  <!--
    <input type="hidden" name="plugin" value="comment" />
    <input type="hidden" name="refer"  value="$s_page" />
 +  -->
    <input type="hidden" name="comment_no" value="$comment_no" />
 +  <input type="hidden" name="forcename"  value="$forcename" />
    <input type="hidden" name="nodate" value="$nodate" />
    <input type="hidden" name="above"  value="$above" />
    <input type="hidden" name="digest" value="$digest" />
 +  {$vars['_error']}
 +  $_error
    $nametags
 -  <input type="text"   name="msg" id="_p_comment_comment_{$comment_no}" size="$comment_cols" />
 +  <input type="text"   name="msg" id="_p_comment_comment_{$comment_no}" size="$comment_cols" value="{$vars['msg']}" />
 +  <input type="text"   name="msg" id="_p_comment_comment_{$comment_no}" size="$comment_cols" value="{$_msg}" />
    <input type="submit" name="comment" value="$_btn_comment" />
   </div>
  </form>
  EOD;
  
 +	$_name = $_msg = $_error = '';
  	return $string;
  }
  ?>

** バグなど [#BugReport]
- 複数実行したときにエラー文がおかしくなる問題を修正 --  &new{2016-01-20 (水) 16:40:21};

#comment(noname,above)


トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Site admin: PukiWiki Development Team

PukiWiki 1.5.3+ © 2001-2020 PukiWiki Development Team. Powered by PHP 5.6.40-0+deb8u12. HTML convert time: 0.039 sec.

OSDN