自作プラグイン/commentplus.inc.php
の編集
Top
/
自作プラグイン
/
commentplus.inc.php
[
トップ
] [
編集
|
差分
|
履歴
|
添付
|
リロード
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
|
ログイン
]
Wikiを試したい方へ:
「この」Wikiは、
PukiWiki
のための公式Wikiです。
テスト書き込みなどは
お試しサイト
https://pukiwiki.osdn.jp/_trial/
をご利用ください
** commentplus.inc.php [#e468904c] |RIGHT:100|LEFT:360|c |~サマリ|機能追加版コメントプラグイン| |~リビジョン|1.0.2| |~対応バージョン|1.5.x| |~投稿者|[[K]]| |~投稿日|&new{2020-08-05 (水) 22:16:23};| #contents **概要 [#o5c7ac0a] コメントに絵文字などの機能を加えたプラグインです。 //**ダウンロード [#e183570a] // k0.22web.org/commentplus.inc.php-1.0.dl **ソース [#r574e65a] <?php define('applyNoname', ''); //名前が入力されていない時に適用する名前 define('PLUGIN_COMMENTplus_DIRECTION_DEFAULT', '1'); // 1: above 0: below define('PLUGIN_COMMENTplus_SIZE_MSG', 70); define('PLUGIN_COMMENTplus_SIZE_NAME', 15); // ---- define('PLUGIN_COMMENTplus_FORMAT_MSG', '$msg'); define('PLUGIN_COMMENTplus_FORMAT_NAME', '[[$name]]'); define('PLUGIN_COMMENTplus_FORMAT_NOW', '&new{$now};'); define('PLUGIN_COMMENTplus_FORMAT_STRING', "\x08MSG\x08 -- \x08NAME\x08 \x08NOW\x08"); function plugin_commentplus_action() { global $vars, $now, $_title_updated, $_no_name; global $_msg_commentplus_collided, $_title_commentplus_collided; global $_commentplus_plugin_fail_msg; if (PKWK_READONLY) die_message('PKWK_READONLY prohibits editing'); if (! isset($vars['msg'])) return array('msg'=>'', 'body'=>''); // Do nothing $vars['msg'] = str_replace("\n", '', $vars['msg']); // Cut LFs $head = ''; $match = array(); if (preg_match('/^(-{1,2})-*\s*(.*)/', $vars['msg'], $match)) { $head = & $match[1]; $vars['msg'] = & $match[2]; } if ($vars['msg'] == '') return array('msg'=>'', 'body'=>''); // Do nothing $commentplus = str_replace('$msg', $vars['msg'], PLUGIN_COMMENTplus_FORMAT_MSG); if(isset($vars['name']) || ($vars['nodate'] != '1')) { $_name = (! isset($vars['name']) || $vars['name'] == '') ? $_no_name : $vars['name']; if ($_name == null){ $_name = applyNoname; } $_name = ($_name == '') ? '' : str_replace('$name', $_name, PLUGIN_COMMENTplus_FORMAT_NAME); $_now = ($vars['nodate'] == '1') ? '' : str_replace('$now', $now, PLUGIN_COMMENTplus_FORMAT_NOW); $commentplus = str_replace("\x08MSG\x08", $commentplus, PLUGIN_COMMENTplus_FORMAT_STRING); $commentplus = str_replace("\x08NAME\x08", $_name, $commentplus); $commentplus = str_replace("\x08NOW\x08", $_now, $commentplus); } $commentplus = '-' . $head . ' ' . $commentplus; $postdata = ''; $commentplus_no = 0; $above = (isset($vars['above']) && $vars['above'] == '1'); $commentplus_added = FALSE; foreach (get_source($vars['refer']) as $line) { if (! $above) $postdata .= $line; if (preg_match('/^#commentplus/i', $line) && $commentplus_no++ == $vars['commentplus_no']) { $commentplus_added = TRUE; if ($above) { $postdata = rtrim($postdata) . "\n" . $commentplus . "\n" . "\n"; // Insert one blank line above #commment, to avoid indentation } else { $postdata = rtrim($postdata) . "\n" . $commentplus . "\n"; } } if ($above) $postdata .= $line; } $title = $_title_updated; $body = ''; if ($commentplus_added) { // new commentplus added if (md5(get_source($vars['refer'], TRUE, TRUE)) !== $vars['digest']) { $title = $_title_commentplus_collided; $body = $_msg_commentplus_collided . make_pagelink($vars['refer']); } //require "iplog.php";//IPLOGを入れてる場合のみ可能 //addLog($commentplus,'コメント+'); page_write($vars['refer'], $postdata); } else { // failed to add the commentplus $title = $_title_commentplus_collided; $body = $_commentplus_plugin_fail_msg . make_pagelink($vars['refer']); } $retvars['msg'] = $title; $retvars['body'] = $body; $vars['page'] = $vars['refer']; return $retvars; } function plugin_commentplus_convert() { global $vars, $digest, $_btn_comment, $_btn_name, $_msg_commentplus; static $numbers = array(); static $commentplus_cols = PLUGIN_COMMENTplus_SIZE_MSG; if (PKWK_READONLY) return ''; // Show nothing $page = $vars['page']; if (! isset($numbers[$page])) $numbers[$page] = 0; $commentplus_no = $numbers[$page]++; $options = func_num_args() ? func_get_args() : array(); if (in_array('noname', $options)) { $nametags = '<label for="_p_commentplus_commentplus_' . $commentplus_no . '">' . $_msg_commentplus . '</label>'; } else { $nametags = '<label for="_p_commentplus_name_' . $commentplus_no . '">' . $_btn_name . '</label>' . '<input type="text" name="name" id="_p_commentplus_name_' . $commentplus_no . '" size="' . PLUGIN_COMMENTplus_SIZE_NAME . '" />' . "\n"; } $nodate = in_array('nodate', $options) ? '1' : '0'; $above = in_array('above', $options) ? '1' : (in_array('below', $options) ? '0' : PLUGIN_COMMENTplus_DIRECTION_DEFAULT); $script = get_page_uri($page); $s_page = htmlsc($page); $string = <<<EOD <br /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <form action="$script" method="post" class="_p_commentplus_form"> <div> <input type="hidden" name="plugin" value="commentplus" /> <input type="hidden" name="refer" value="$s_page" /> <input type="hidden" name="commentplus_no" value="$commentplus_no" /> <input type="hidden" name="nodate" value="$nodate" /> <input type="hidden" name="above" value="$above" /> <input type="hidden" name="digest" value="$digest" /> $nametags <input type="text" name="msg" id="_p_commentplus_commentplus_{$commentplus_no}" size="$commentplus_cols" required /> <input type="submit" name="commentplus" value="$_btn_comment" /> </div> </form> <script> document.activeElement.onInput = function() { if (document.activeElement.type == "text"){ dae = document.activeElement; text_len = dae.value.length; text_pos = dae.selectionStart; text_bf = dae.value.substr(0, text_pos); text_af = dae.value.substr(text_pos, text_len); } }; document.activeElement.onclick = function() { if (document.activeElement.type == "text"){ dae = document.activeElement; text_len = dae.value.length; text_pos = dae.selectionStart; text_bf = dae.value.substr(0, text_pos); text_af = dae.value.substr(text_pos, text_len); } }; function inputToCommentplusArea(input_text) { dae.value = text_bf + input_text + text_af; text_len = dae.value.length; text_pos = text_pos + input_text.length; text_bf = dae.value.substr(0, text_pos); text_af = dae.value.substr(text_pos, text_len); }; function inputToCommentplusArea2(input_text1,input_text2,input_text3) { size = window.prompt("サイズ:", "10"); text1 = window.prompt("テキスト:", dae.value.substring(dae.selectionStart,dae.selectionEnd)); text_af = dae.value.substr(text_pos + dae.value.substring(dae.selectionStart,dae.selectionEnd).length, text_len); dae.value = text_bf + input_text1 + size + input_text2 + text1 + input_text3 + text_af; text_len = dae.value.length; text_pos = text_pos + input_text.length; text_bf = dae.value.substr(0, text_pos); text_af = dae.value.substr(text_pos, text_len); }; function inputToCommentplusAreaURL(input_text1,input_text2,input_text3) { text1 = window.prompt("テキスト:", ""); url1 = window.prompt("URL:", "http://"); dae.value = text_bf + "[["+text1+">"+url1+"]]" + text_af; text_len = dae.value.length; text_pos = text_pos + input_text.length; text_bf = dae.value.substr(0, text_pos); text_af = dae.value.substr(text_pos, text_len); }; function inputToCommentplusArea3(input_text) { text_af = dae.value.substr(text_pos + dae.value.substring(dae.selectionStart,dae.selectionEnd).length, text_len); dae.value = text_bf + input_text + dae.value.substring(dae.selectionStart,dae.selectionEnd) + input_text + text_af; text_se_1 = dae.selectionEnd; text_len = dae.value.length; text_pos = text_pos + input_text.length; text_bf = dae.value.substr(0, text_pos); text_af = dae.value.substr(text_pos, text_len); }; </script> <a href="javascript:inputToCommentplusAreaURL()">[URL]</a> <a href="javascript:inputToCommentplusArea3('\'\'')">[B]</a> <a href="javascript:inputToCommentplusArea3('\'\'\'')">[I]</a> <a href="javascript:inputToCommentplusArea3('%%%')">[U]</a> <a href="javascript:inputToCommentplusArea3('%%')">[S]</a> <a href="javascript:inputToCommentplusArea2('&size(','){','};')">[サイズ]</a> <a href="javascript:inputToCommentplusArea('&attachref();')">[添付]</a> <a href="javascript:inputToCommentplusArea('&br;')">[改行]</a> <a href="javascript:inputToCommentplusArea('&smile;')"><img src="./image/face/smile.png"/></a> <a href="javascript:inputToCommentplusArea('&bigsmile;')"><img src="./image/face/bigsmile.png"/></a> <a href="javascript:inputToCommentplusArea('&huh;')"><img src="./image/face/huh.png"/></a> <a href="javascript:inputToCommentplusArea('&oh;')"><img src="./image/face/oh.png"/></a> <a href="javascript:inputToCommentplusArea('&wink;')"><img src="./image/face/wink.png"/></a> <a href="javascript:inputToCommentplusArea('&sad;')"><img src="./image/face/sad.png"/></a> <a href="javascript:inputToCommentplusArea('&heart;')"><img src="./image/face/heart.png"/></a> EOD; //顔文字↑ return $string; } **使い方 [#j6d6dc69] "plugin/commentplus.inc.php"で保存してください。 #commentplus で使うことができます。 **注意 [#sab23c3e] -%%#commentplusを同じページに複数設置するとボタンのバグが発生する。%%(修正済み) **ライセンス [#i1e4a42f] GPL
** commentplus.inc.php [#e468904c] |RIGHT:100|LEFT:360|c |~サマリ|機能追加版コメントプラグイン| |~リビジョン|1.0.2| |~対応バージョン|1.5.x| |~投稿者|[[K]]| |~投稿日|&new{2020-08-05 (水) 22:16:23};| #contents **概要 [#o5c7ac0a] コメントに絵文字などの機能を加えたプラグインです。 //**ダウンロード [#e183570a] // k0.22web.org/commentplus.inc.php-1.0.dl **ソース [#r574e65a] <?php define('applyNoname', ''); //名前が入力されていない時に適用する名前 define('PLUGIN_COMMENTplus_DIRECTION_DEFAULT', '1'); // 1: above 0: below define('PLUGIN_COMMENTplus_SIZE_MSG', 70); define('PLUGIN_COMMENTplus_SIZE_NAME', 15); // ---- define('PLUGIN_COMMENTplus_FORMAT_MSG', '$msg'); define('PLUGIN_COMMENTplus_FORMAT_NAME', '[[$name]]'); define('PLUGIN_COMMENTplus_FORMAT_NOW', '&new{$now};'); define('PLUGIN_COMMENTplus_FORMAT_STRING', "\x08MSG\x08 -- \x08NAME\x08 \x08NOW\x08"); function plugin_commentplus_action() { global $vars, $now, $_title_updated, $_no_name; global $_msg_commentplus_collided, $_title_commentplus_collided; global $_commentplus_plugin_fail_msg; if (PKWK_READONLY) die_message('PKWK_READONLY prohibits editing'); if (! isset($vars['msg'])) return array('msg'=>'', 'body'=>''); // Do nothing $vars['msg'] = str_replace("\n", '', $vars['msg']); // Cut LFs $head = ''; $match = array(); if (preg_match('/^(-{1,2})-*\s*(.*)/', $vars['msg'], $match)) { $head = & $match[1]; $vars['msg'] = & $match[2]; } if ($vars['msg'] == '') return array('msg'=>'', 'body'=>''); // Do nothing $commentplus = str_replace('$msg', $vars['msg'], PLUGIN_COMMENTplus_FORMAT_MSG); if(isset($vars['name']) || ($vars['nodate'] != '1')) { $_name = (! isset($vars['name']) || $vars['name'] == '') ? $_no_name : $vars['name']; if ($_name == null){ $_name = applyNoname; } $_name = ($_name == '') ? '' : str_replace('$name', $_name, PLUGIN_COMMENTplus_FORMAT_NAME); $_now = ($vars['nodate'] == '1') ? '' : str_replace('$now', $now, PLUGIN_COMMENTplus_FORMAT_NOW); $commentplus = str_replace("\x08MSG\x08", $commentplus, PLUGIN_COMMENTplus_FORMAT_STRING); $commentplus = str_replace("\x08NAME\x08", $_name, $commentplus); $commentplus = str_replace("\x08NOW\x08", $_now, $commentplus); } $commentplus = '-' . $head . ' ' . $commentplus; $postdata = ''; $commentplus_no = 0; $above = (isset($vars['above']) && $vars['above'] == '1'); $commentplus_added = FALSE; foreach (get_source($vars['refer']) as $line) { if (! $above) $postdata .= $line; if (preg_match('/^#commentplus/i', $line) && $commentplus_no++ == $vars['commentplus_no']) { $commentplus_added = TRUE; if ($above) { $postdata = rtrim($postdata) . "\n" . $commentplus . "\n" . "\n"; // Insert one blank line above #commment, to avoid indentation } else { $postdata = rtrim($postdata) . "\n" . $commentplus . "\n"; } } if ($above) $postdata .= $line; } $title = $_title_updated; $body = ''; if ($commentplus_added) { // new commentplus added if (md5(get_source($vars['refer'], TRUE, TRUE)) !== $vars['digest']) { $title = $_title_commentplus_collided; $body = $_msg_commentplus_collided . make_pagelink($vars['refer']); } //require "iplog.php";//IPLOGを入れてる場合のみ可能 //addLog($commentplus,'コメント+'); page_write($vars['refer'], $postdata); } else { // failed to add the commentplus $title = $_title_commentplus_collided; $body = $_commentplus_plugin_fail_msg . make_pagelink($vars['refer']); } $retvars['msg'] = $title; $retvars['body'] = $body; $vars['page'] = $vars['refer']; return $retvars; } function plugin_commentplus_convert() { global $vars, $digest, $_btn_comment, $_btn_name, $_msg_commentplus; static $numbers = array(); static $commentplus_cols = PLUGIN_COMMENTplus_SIZE_MSG; if (PKWK_READONLY) return ''; // Show nothing $page = $vars['page']; if (! isset($numbers[$page])) $numbers[$page] = 0; $commentplus_no = $numbers[$page]++; $options = func_num_args() ? func_get_args() : array(); if (in_array('noname', $options)) { $nametags = '<label for="_p_commentplus_commentplus_' . $commentplus_no . '">' . $_msg_commentplus . '</label>'; } else { $nametags = '<label for="_p_commentplus_name_' . $commentplus_no . '">' . $_btn_name . '</label>' . '<input type="text" name="name" id="_p_commentplus_name_' . $commentplus_no . '" size="' . PLUGIN_COMMENTplus_SIZE_NAME . '" />' . "\n"; } $nodate = in_array('nodate', $options) ? '1' : '0'; $above = in_array('above', $options) ? '1' : (in_array('below', $options) ? '0' : PLUGIN_COMMENTplus_DIRECTION_DEFAULT); $script = get_page_uri($page); $s_page = htmlsc($page); $string = <<<EOD <br /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <form action="$script" method="post" class="_p_commentplus_form"> <div> <input type="hidden" name="plugin" value="commentplus" /> <input type="hidden" name="refer" value="$s_page" /> <input type="hidden" name="commentplus_no" value="$commentplus_no" /> <input type="hidden" name="nodate" value="$nodate" /> <input type="hidden" name="above" value="$above" /> <input type="hidden" name="digest" value="$digest" /> $nametags <input type="text" name="msg" id="_p_commentplus_commentplus_{$commentplus_no}" size="$commentplus_cols" required /> <input type="submit" name="commentplus" value="$_btn_comment" /> </div> </form> <script> document.activeElement.onInput = function() { if (document.activeElement.type == "text"){ dae = document.activeElement; text_len = dae.value.length; text_pos = dae.selectionStart; text_bf = dae.value.substr(0, text_pos); text_af = dae.value.substr(text_pos, text_len); } }; document.activeElement.onclick = function() { if (document.activeElement.type == "text"){ dae = document.activeElement; text_len = dae.value.length; text_pos = dae.selectionStart; text_bf = dae.value.substr(0, text_pos); text_af = dae.value.substr(text_pos, text_len); } }; function inputToCommentplusArea(input_text) { dae.value = text_bf + input_text + text_af; text_len = dae.value.length; text_pos = text_pos + input_text.length; text_bf = dae.value.substr(0, text_pos); text_af = dae.value.substr(text_pos, text_len); }; function inputToCommentplusArea2(input_text1,input_text2,input_text3) { size = window.prompt("サイズ:", "10"); text1 = window.prompt("テキスト:", dae.value.substring(dae.selectionStart,dae.selectionEnd)); text_af = dae.value.substr(text_pos + dae.value.substring(dae.selectionStart,dae.selectionEnd).length, text_len); dae.value = text_bf + input_text1 + size + input_text2 + text1 + input_text3 + text_af; text_len = dae.value.length; text_pos = text_pos + input_text.length; text_bf = dae.value.substr(0, text_pos); text_af = dae.value.substr(text_pos, text_len); }; function inputToCommentplusAreaURL(input_text1,input_text2,input_text3) { text1 = window.prompt("テキスト:", ""); url1 = window.prompt("URL:", "http://"); dae.value = text_bf + "[["+text1+">"+url1+"]]" + text_af; text_len = dae.value.length; text_pos = text_pos + input_text.length; text_bf = dae.value.substr(0, text_pos); text_af = dae.value.substr(text_pos, text_len); }; function inputToCommentplusArea3(input_text) { text_af = dae.value.substr(text_pos + dae.value.substring(dae.selectionStart,dae.selectionEnd).length, text_len); dae.value = text_bf + input_text + dae.value.substring(dae.selectionStart,dae.selectionEnd) + input_text + text_af; text_se_1 = dae.selectionEnd; text_len = dae.value.length; text_pos = text_pos + input_text.length; text_bf = dae.value.substr(0, text_pos); text_af = dae.value.substr(text_pos, text_len); }; </script> <a href="javascript:inputToCommentplusAreaURL()">[URL]</a> <a href="javascript:inputToCommentplusArea3('\'\'')">[B]</a> <a href="javascript:inputToCommentplusArea3('\'\'\'')">[I]</a> <a href="javascript:inputToCommentplusArea3('%%%')">[U]</a> <a href="javascript:inputToCommentplusArea3('%%')">[S]</a> <a href="javascript:inputToCommentplusArea2('&size(','){','};')">[サイズ]</a> <a href="javascript:inputToCommentplusArea('&attachref();')">[添付]</a> <a href="javascript:inputToCommentplusArea('&br;')">[改行]</a> <a href="javascript:inputToCommentplusArea('&smile;')"><img src="./image/face/smile.png"/></a> <a href="javascript:inputToCommentplusArea('&bigsmile;')"><img src="./image/face/bigsmile.png"/></a> <a href="javascript:inputToCommentplusArea('&huh;')"><img src="./image/face/huh.png"/></a> <a href="javascript:inputToCommentplusArea('&oh;')"><img src="./image/face/oh.png"/></a> <a href="javascript:inputToCommentplusArea('&wink;')"><img src="./image/face/wink.png"/></a> <a href="javascript:inputToCommentplusArea('&sad;')"><img src="./image/face/sad.png"/></a> <a href="javascript:inputToCommentplusArea('&heart;')"><img src="./image/face/heart.png"/></a> EOD; //顔文字↑ return $string; } **使い方 [#j6d6dc69] "plugin/commentplus.inc.php"で保存してください。 #commentplus で使うことができます。 **注意 [#sab23c3e] -%%#commentplusを同じページに複数設置するとボタンのバグが発生する。%%(修正済み) **ライセンス [#i1e4a42f] GPL
テキスト整形のルールを表示する