ちょっと便利に-タグ入力支援フォーム


改造法

@/lib/html.php - l.237

// jidaikobo start - tag input form
// edit.inc.php とセット
// confirm pukiwiki.ini.php
// 処理とiniでの規定値確認
global $taginput_edit;
$tag_ini_flag['edit'] = (isset($taginput_edit['form'])) ? $taginput_edit['form'] : '1';
$tag_ini_flag['position'] = (isset($taginput_edit['position'])) ? $taginput_edit['position'] : 'head';
$tag_ini_flag['ask'] = (isset($taginput_edit['ask'])) ? $taginput_edit['ask'] : '1';

// existent plugin in plugin folder - tag.inc.php
// プラグインの存在確認 - tag.inc.php
$tag_plugin     = PLUGIN_DIR . 'tag.inc.php';
$tag_tag_flag   = (file_exists($tag_plugin)) ? '1' : '';

if($tag_ini_flag['edit'] == 1 && $tag_tag_flag == 1){
	// existent plugin in plugin folder - enull.inc.php
	// プラグインの存在確認 - enull.inc.php
	$enull_plugin   = PLUGIN_DIR . 'enull.inc.php';
	$tag_enull_flag = (file_exists($enull_plugin)) ? '1' : '';

	// existent tags in CACHE_DIR
	// サイト内の既存タグの確認 - stolen from tag.inc.php by sonots
	$cache = CACHE_DIR . 'tagcloud.tag';
	if (file_exists($cache)){
		$lines = file($cache);
		if($lines != null){
			foreach ($lines as $k => $v) {
				list($tag_cache[], $count_cache[]) = explode("\t", $v);
			}
		}else{
			$tag_cache = array();
		}
	}else{
		$tag_cache = array();
	}
	
	// prepare html and items
	// HTML と選択肢の準備
	$tag_html = '';
	$tag_checked = ' checked="checked"';

	// prepare item
	// cache と既存入力値から選択肢を準備
	preg_match("/&tag\((.*?)\);[[:space:]]/",$s_postdata,$tags);
	$tag_each = explode(',',$tags[1]);
	$tag_each_temp = array_pop($tag_each);
	if($tag_each_temp != ''){
		$tag_each[] = $tag_each_temp;
	}
	$tag = $tag_cache + $tag_each;
	$tag = array_merge($tag_cache, $tag_each);
	$tag = array_unique($tag);

	// check tag position in page
	// タグの位置確認
	if(isset($tags)){
		$s_postdata_line = explode("\n",$s_postdata);
		// get line number
		// 行数取得
		foreach($s_postdata_line as $k => $v){
			if(strpos($v,'&tag(') === 0){
				$tag_position_strpos = $k;
				$tag_pos_prev_k = $k - 1;
				$tag_pos_prev = $s_postdata_line[$tag_pos_prev_k];
			}
			if(isset($tag_position_strpos) && $k > $tag_position_strpos && strpos($v,'}}') !== 0){
				if(preg_match("/.+/",$v)) $not_bottom = true;
			}
		}
		// head or bottom
		// 先頭か末尾のときだけ特別扱い
		$num_lines = count($s_postdata_line);
		if(isset($not_bottom) && $tag_position_strpos == 0 || $tag_pos_prev == '#enull{{' &&  $tag_position_strpos == 1){
			$tag_position = 'head';
			$tag_position_strpos = 0;
		}elseif( ! isset($not_bottom)){
			$tag_position = 'bottom';
		}
	}

	// generate html
	// タグ選択肢生成
	foreach($tag as $k => $v){
		$checked = '';
		foreach($tag_each as $kk => $vv){
			if($v == $vv){
				$checked = $tag_checked;
			}
		}
		$tag_html .= "\t".'<li style="display:inline;padding-right:15px;"><label><input type="checkbox" name="tag[]" value="'.$v.'"'.$checked.' />'.htmlspecialchars($v,ENT_QUOTES).'</label></li>'."\n";
	}
	$tag_html = "\n".'<ul style="list-style:none;margin:0;padding:0 0 5px;">'."\n".$tag_html;
	
	$tag_html = '<fieldset style="margin-bottom:10px;">'."\n".'<legend>Tags</legend>'.$tag_html;
	$tag_html .= "\t".'<li style="display:inline;padding-right:15px;white-space:nowrap;"><label>Add: <input name="tag_add" type="text" /></label></li>'."\n</ul>\n";

	// enull existent check
	// enull の存在確認
	if(preg_match("/#enull{{\n*&amp;tag/",$s_postdata)||$tag_ini_flag['position'] == 'hidden'){
		$check_enull = $tag_checked;
	}

	// deletion tag data from $s_postdata
	// 入力欄からタグ関連データを一旦削除
	$invisible_enul = "/\n*#enull{{\n*&amp;tag\((.*?)\);\n*}}\n*/";
	$invisible_tag = "/\n*&amp;tag\((.*?)\);\n*/";
	$s_postdata = preg_replace($invisible_enul,"\n",$s_postdata);
	$s_postdata = preg_replace($invisible_tag,"\n",$s_postdata);

	// positioning tag
	// tag の位置設定
	if($tag_position == 'head' && ! $tag_ini_flag['position'] == 'bottom'){
		$check_head = $tag_checked;
	}elseif($tag_position == 'bottom' || $tag_ini_flag['position'] == 'bottom'){
		$check_bottom = $tag_checked;
	}else{
		$check_line = $tag_checked;
	}

	if($tag_ini_flag['ask'] === 1){
		$tag_html .= <<<EOD
<hr />
<dl>
<dt style="display:inline;margin:0;padding-right:15px;">Position:</dt>
	<dd style="display:inline;margin:0;padding-right:15px;"><label><input type="radio" name="tag_position" value="head"$check_head /> head</label></dd>
	<dd style="display:inline;margin:0;padding-right:15px;"><label><input type="radio" name="tag_position" value="bottom"$check_bottom /> bottom</label></dd>
	<dd style="display:inline;margin:0;padding-right:15px;"><label><input type="radio" name="tag_position" value="line"$check_line />line: </label><input type="text" name="tag_pos_line" value="$tag_position_strpos" size="3" /></dd>
EOD;
		// enull plugin check
		// enull プラグインがあれば、チェックを表示
		if($tag_enull_flag == '1'){
			$tag_html .= "\n\t".'<dd style="display:inline;margin:0;padding-right:15px;"><label><input type="checkbox" name="tag_hidden" value="hidden"'.$check_enull.' /> hidden</label></dd>';
		}
	}else{
		// default value of hidden position control
		// タグ位置編集欄を非表示の際の規定値
		if($check_head){
			$tag_html .= '<input type="hidden" name="tag_position" value="head" />'."\n";
		}else{
			$tag_html .= '<input type="hidden" name="tag_position" value="bottom" />'."\n";
		}
		if($tag_enull_flag == '0' && $tag_ini_flag['position'] == 'hidden'){
			$tag_html .= '<p><strong>Cannot control visibility by pukiwiki.ini.php without enull.inc.php.</strong></p>'."\n";
		}elseif($check_enull){
			$tag_html .= '<input type="hidden" name="tag_hidden" value="hidden" />'."\n";
		}
	}
	$tag_html .= "\n</fieldset>";
}
// overwrite error message
// タグ入力支援許可しつつプラグインがない場合のエラー
if($tag_ini_flag['edit'] == 1 && $tag_tag_flag != 1){
	$tag_html = '<p><strong>install tag.inc.php into plugin folder.</strong></p>';
}

// jidaikobo end - tag input form
// attention: put $body into $tag_html after textarea
// $body のヒヤドキュメントに $tag_html を入れること

@/plugin/edit.inc.php - l.64

	$postdata = $vars['msg'] = plugin_edit_tag($postdata); //jidaikobo

@/plugin/edit.inc.php - l.189

	$msg = plugin_edit_tag($msg); //jidaikobo

@/plugin/edit.inc.php - さいご

function plugin_edit_tag($msg){
// tags include values
	global $vars;

if($msg != ''){
	$tag_hidden   = isset($vars['tag_hidden']) ? '1' : '';
	$tag_add      = ($vars['tag_add'] != '') ? $vars['tag_add'] : NULL;
	$tag_position = isset($vars['tag_position']) ? $vars['tag_position'] : '';
	$tag_line     = isset($vars['tag_pos_line']) ? $vars['tag_pos_line'] : '';
	$tags         = isset($vars['tag']) ? implode(',',$vars['tag']) : NULL;
}

// tags include
	if(isset($vars['tag'])||isset($vars['tag_add']) && $vars['tag_add']!=''){
		$tags = (isset($tags)) ? $tags.','.$tag_add : $tag_add ;
		$tags = '&tag('.htmlspecialchars($tags,ENT_QUOTES).');';
		if(isset($vars['tag_hidden'])){
			$tags = "#enull{{\n".$tags."\n}}\n";
		}
		if($tag_position == 'head'){
			$msg = $tags."\n\n".$msg;
		}elseif($tag_position == 'bottom'){
			$msg = $msg."\n\n".$tags;
		}elseif($tag_position == 'line'){
			$msg_temp = explode("\n",$msg);
			array_splice($msg_temp, $tag_line, 0,"\n".$tags."\n");
			$msg = implode("\n",$msg_temp);
		}
	}

	return $msg;
}

@pukiwiki.ini.php - どこでも

////////////////////////////////////////jidaikobo
// タグ用編集窓の追加(1:add or 0:remove)
$taginput_edit['form'] = 1;
// タグ位置の規定値(head, bottom, hidden)
$taginput_edit['position'] = 'hidden';
// タグ編集の可視設定(1:ask or 0:don't ask)
$taginput_edit['ask'] = 0;

オマケ - タグの一覧

@skinのてきとうなところ

//prepare tag
$cache = CACHE_DIR . 'tagcloud.tag';
if (file_exists($cache)){
	$lines = file($cache);
	if($lines != null){
		foreach ($lines as $k => $v) {
			list($tag_cache[], $count_cache[]) = explode("\t", $v);
		}
	}else{
		$tag_cache = array();
		$count_cache = array();
	}
}else{
	$tag_cache = array();
	$count_cache = array();
}
$tag_cache=str_replace("%22",'',$tag_cache);
$count_cache=str_replace("\n",'',$count_cache);

//html - change heading level as you like
$tag_skin = "<h3>tag categories</h3>\n";
$tag_skin.= "<ul>\n";
foreach($tag_cache as $k => $v){
	$tag_skin.= "\t".'<li><a href="'.$script.'?cmd=lsx&amp;tag='.urlencode($v).'">'.$v.'</a> ('.$count_cache[$k].")</li>\n";
}
$tag_skin.= "</ul>\n";

コメント


トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2008-10-15 (水) 13:36:45
Site admin: PukiWiki Development Team

PukiWiki 1.5.4+ © 2001-2022 PukiWiki Development Team. Powered by PHP 8.2.12. HTML convert time: 0.258 sec.

SourceForge