1+ <?php
2+ define ('PLUGIN_COMMENTplus_DIRECTION_DEFAULT ' , '1 ' ); // 1: above 0: below
3+ define ('PLUGIN_COMMENTplus_SIZE_MSG ' , 70 );
4+ define ('PLUGIN_COMMENTplus_SIZE_NAME ' , 15 );
5+ // ----
6+ define ('PLUGIN_COMMENTplus_FORMAT_MSG ' , '$msg ' );
7+ define ('PLUGIN_COMMENTplus_FORMAT_NAME ' , '[[$name]] ' );
8+ define ('PLUGIN_COMMENTplus_FORMAT_NOW ' , '&new{$now}; ' );
9+ define ('PLUGIN_COMMENTplus_FORMAT_STRING ' , "\x08MSG \x08 -- \x08NAME \x08 \x08NOW \x08" );
10+
11+ function plugin_commentplus_action ()
12+ {
13+ global $ vars , $ now , $ _title_updated , $ _no_name ;
14+ global $ _msg_commentplus_collided , $ _title_commentplus_collided ;
15+ global $ _commentplus_plugin_fail_msg ;
16+
17+ if (PKWK_READONLY ) die_message ('PKWK_READONLY prohibits editing ' );
18+
19+ if (! isset ($ vars ['msg ' ])) return array ('msg ' =>'' , 'body ' =>'' ); // Do nothing
20+
21+ $ vars ['msg ' ] = str_replace ("\n" , '' , $ vars ['msg ' ]); // Cut LFs
22+ $ head = '' ;
23+ $ match = array ();
24+ if (preg_match ('/^(-{1,2})-*\s*(.*)/ ' , $ vars ['msg ' ], $ match )) {
25+ $ head = & $ match [1 ];
26+ $ vars ['msg ' ] = & $ match [2 ];
27+ }
28+ if ($ vars ['msg ' ] == '' ) return array ('msg ' =>'' , 'body ' =>'' ); // Do nothing
29+
30+ $ commentplus = str_replace ('$msg ' , $ vars ['msg ' ], PLUGIN_COMMENTplus_FORMAT_MSG);
31+ if (isset ($ vars ['name ' ]) || ($ vars ['nodate ' ] != '1 ' )) {
32+ $ _name = (! isset ($ vars ['name ' ]) || $ vars ['name ' ] == '' ) ? $ _no_name : $ vars ['name ' ];
33+ if ($ _name == null ){
34+ $ _name = 'Anonymous ' ;
35+ }
36+ $ _name = ($ _name == '' ) ? '' : str_replace ('$name ' , $ _name , PLUGIN_COMMENTplus_FORMAT_NAME);
37+ $ _now = ($ vars ['nodate ' ] == '1 ' ) ? '' :
38+ str_replace ('$now ' , $ now , PLUGIN_COMMENTplus_FORMAT_NOW);
39+ $ commentplus = str_replace ("\x08MSG \x08" , $ commentplus , PLUGIN_COMMENTplus_FORMAT_STRING);
40+ $ commentplus = str_replace ("\x08NAME \x08" , $ _name , $ commentplus );
41+ $ commentplus = str_replace ("\x08NOW \x08" , $ _now , $ commentplus );
42+ }
43+ $ commentplus = '- ' . $ head . ' ' . $ commentplus ;
44+
45+ $ postdata = '' ;
46+ $ commentplus_no = 0 ;
47+ $ above = (isset ($ vars ['above ' ]) && $ vars ['above ' ] == '1 ' );
48+ $ commentplus_added = FALSE ;
49+ foreach (get_source ($ vars ['refer ' ]) as $ line ) {
50+ if (! $ above ) $ postdata .= $ line ;
51+ if (preg_match ('/^#commentplus/i ' , $ line ) && $ commentplus_no ++ == $ vars ['commentplus_no ' ]) {
52+ $ commentplus_added = TRUE ;
53+
54+ if ($ above ) {
55+ $ postdata = rtrim ($ postdata ) . "\n" .
56+ $ commentplus . "\n" .
57+ "\n" ; // Insert one blank line above #commment, to avoid indentation
58+ } else {
59+ $ postdata = rtrim ($ postdata ) . "\n" .
60+ $ commentplus . "\n" ;
61+ }
62+ }
63+ if ($ above ) $ postdata .= $ line ;
64+ }
65+ $ title = $ _title_updated ;
66+ $ body = '' ;
67+ if ($ commentplus_added ) {
68+ // new commentplus added
69+ if (md5 (get_source ($ vars ['refer ' ], TRUE , TRUE )) !== $ vars ['digest ' ]) {
70+ $ title = $ _title_commentplus_collided ;
71+ $ body = $ _msg_commentplus_collided . make_pagelink ($ vars ['refer ' ]);
72+ }
73+ // require "iplog.php";//IPLOGを入れてる場合のみ可能
74+ // addLog($commentplus,'コメント+');
75+ page_write ($ vars ['refer ' ], $ postdata );
76+ } else {
77+ // failed to add the commentplus
78+ $ title = $ _title_commentplus_collided ;
79+ $ body = $ _commentplus_plugin_fail_msg . make_pagelink ($ vars ['refer ' ]);
80+ }
81+ $ retvars ['msg ' ] = $ title ;
82+ $ retvars ['body ' ] = $ body ;
83+ $ vars ['page ' ] = $ vars ['refer ' ];
84+ return $ retvars ;
85+ }
86+
87+ function plugin_commentplus_convert ()
88+ {
89+ global $ vars , $ digest , $ _btn_comment , $ _btn_name , $ _msg_commentplus ;
90+ static $ numbers = array ();
91+ static $ commentplus_cols = PLUGIN_COMMENTplus_SIZE_MSG;
92+
93+ if (PKWK_READONLY ) return '' ; // Show nothing
94+
95+ $ page = $ vars ['page ' ];
96+ if (! isset ($ numbers [$ page ])) $ numbers [$ page ] = 0 ;
97+ $ commentplus_no = $ numbers [$ page ]++;
98+
99+ $ options = func_num_args () ? func_get_args () : array ();
100+ if (in_array ('noname ' , $ options )) {
101+ $ nametags = '<label for="_p_commentplus_commentplus_ ' . $ commentplus_no . '"> ' .
102+ $ _msg_commentplus . '</label> ' ;
103+ } else {
104+ $ nametags = '<label for="_p_commentplus_name_ ' . $ commentplus_no . '"> ' .
105+ $ _btn_name . '</label> ' .
106+ '<input type="text" name="name" id="_p_commentplus_name_ ' .
107+ $ commentplus_no . '" size=" ' . PLUGIN_COMMENTplus_SIZE_NAME .
108+ '" /> ' . "\n" ;
109+ }
110+ $ nodate = in_array ('nodate ' , $ options ) ? '1 ' : '0 ' ;
111+ $ above = in_array ('above ' , $ options ) ? '1 ' :
112+ (in_array ('below ' , $ options ) ? '0 ' : PLUGIN_COMMENTplus_DIRECTION_DEFAULT);
113+
114+ $ script = get_page_uri ($ page );
115+ $ s_page = htmlsc ($ page );
116+ $ string = <<<EOD
117+ <br />
118+ <form action=" $ script" method="post" class="_p_commentplus_form">
119+ <div>
120+ <input type="hidden" name="plugin" value="commentplus" />
121+ <input type="hidden" name="refer" value=" $ s_page" />
122+ <input type="hidden" name="commentplus_no" value=" $ commentplus_no" />
123+ <input type="hidden" name="nodate" value=" $ nodate" />
124+ <input type="hidden" name="above" value=" $ above" />
125+ <input type="hidden" name="digest" value=" $ digest" />
126+ $ nametags
127+ <input type="text" name="msg" id="_p_commentplus_commentplus_ {$ commentplus_no }"
128+ size=" $ commentplus_cols" required />
129+ <input type="submit" name="commentplus" value=" $ _btn_comment" />
130+ </div>
131+ </form>
132+ <script>
133+ function inputToCommentplusArea(input_text) {
134+ document.getElementById('_p_commentplus_commentplus_ {$ commentplus_no }').value += input_text;
135+ }
136+ function inputToCommentplusArea2(input_text1,input_text2,input_text3) {
137+ size = window.prompt("サイズ:", "10");
138+ text1 = window.prompt("テキスト:", "");
139+ document.getElementById('_p_commentplus_commentplus_ {$ commentplus_no }').value += input_text1 + size + input_text2 + text1 + input_text3;
140+ }
141+ function inputToCommentplusAreaURL(input_text1,input_text2,input_text3) {
142+ text1 = window.prompt("テキスト:", "");
143+ url1 = window.prompt("URL:", "http://");
144+ document.getElementById('_p_commentplus_commentplus_ {$ commentplus_no }').value += "[["+text1+">"+url1+"]]";
145+ }
146+
147+ </script>
148+ <a href="javascript:inputToCommentplusArea('&br;')">[改行]</a>
149+ <a href="javascript:inputToCommentplusArea('&attachref();')">[添付]</a>
150+ <a href="javascript:inputToCommentplusArea2('&size(','){','};')">[サイズ]</a>
151+ <a href="javascript:inputToCommentplusAreaURL()">[URL]</a>
152+
153+ <a href="javascript:inputToCommentplusArea('&smile;')"><img src="./image/face/smile.png"/></a>
154+ <a href="javascript:inputToCommentplusArea('&bigsmile;')"><img src="./image/face/bigsmile.png"/></a>
155+ <a href="javascript:inputToCommentplusArea('&huh;')"><img src="./image/face/huh.png"/></a>
156+ <a href="javascript:inputToCommentplusArea('&oh;')"><img src="./image/face/oh.png"/></a>
157+ <a href="javascript:inputToCommentplusArea('&wink;')"><img src="./image/face/wink.png"/></a>
158+ <a href="javascript:inputToCommentplusArea('&sad;')"><img src="./image/face/sad.png"/></a>
159+ <a href="javascript:inputToCommentplusArea('&heart;')"><img src="./image/face/heart.png"/></a>
160+ EOD ;
161+ //顔文字↑
162+ return $ string ;
163+ }
0 commit comments