OSDN Git Service

Corrected 1.54
[pukiwiki/pukiwiki.git] / plugin / comment.inc.php
1 <?php
2 /////////////////////////////////////////////////
3 // PukiWiki - Yet another WikiWikiWeb clone.
4 //
5 // $Id: comment.inc.php,v 1.23 2004/07/31 03:09:20 henoheno Exp $
6 //
7
8 /////////////////////////////////////////////////
9 // ¥³¥á¥ó¥È¤Î̾Á°¥Æ¥­¥¹¥È¥¨¥ê¥¢¤Î¥«¥é¥à¿ô
10 define('COMMENT_NAME_COLS',15);
11 /////////////////////////////////////////////////
12 // ¥³¥á¥ó¥È¤Î¥Æ¥­¥¹¥È¥¨¥ê¥¢¤Î¥«¥é¥à¿ô
13 define('COMMENT_COLS',70);
14 /////////////////////////////////////////////////
15 // ¥³¥á¥ó¥È¤ÎÁÞÆþ¥Õ¥©¡¼¥Þ¥Ã¥È
16 define('COMMENT_NAME_FORMAT','[[$name]]');
17 define('COMMENT_MSG_FORMAT','$msg');
18 define('COMMENT_NOW_FORMAT','&new{$now};');
19 /////////////////////////////////////////////////
20 // ¥³¥á¥ó¥È¤ÎÁÞÆþ¥Õ¥©¡¼¥Þ¥Ã¥È(¥³¥á¥ó¥ÈÆâÍÆ)
21 define('COMMENT_FORMAT',"\x08MSG\x08 -- \x08NAME\x08 \x08NOW\x08");
22 /////////////////////////////////////////////////
23 // ¥³¥á¥ó¥È¤òÁÞÆþ¤¹¤ë°ÌÃÖ 1:Íó¤ÎÁ° 0:Íó¤Î¸å
24 define('COMMENT_INS','1');
25 /////////////////////////////////////////////////
26 // ¥³¥á¥ó¥È¤¬Åê¹Æ¤µ¤ì¤¿¾ì¹ç¡¢ÆâÍƤò¥á¡¼¥ë¤ÇÁ÷¤ëÀè
27 //define('COMMENT_MAIL',FALSE);
28
29 function plugin_comment_action()
30 {
31         global $script, $vars, $now;
32         global $_title_updated, $_no_name;
33         global $_msg_comment_collided, $_title_comment_collided;
34
35         if (! isset($vars['msg']) || $vars['msg'] == '') {
36                 return array('msg'=>'', 'body'=>'');
37         } else {
38                 $vars['msg'] = preg_replace("/\n/", '', $vars['msg']);
39         }
40
41         $head = '';
42         $match = array();
43         if (preg_match('/^(-{1,2})(.*)/', $vars['msg'], $match))
44         {
45                 $head = $match[1];
46                 $vars['msg'] = $match[2];
47         }
48         unset($match);
49
50         $_msg  = str_replace('$msg', $vars['msg'], COMMENT_MSG_FORMAT);
51
52         $_name = (! isset($vars['name']) || $vars['name'] == '') ? $_no_name : $vars['name'];
53         $_name = ($_name == '') ? '' : str_replace('$name', $_name, COMMENT_NAME_FORMAT);
54
55         $_now  = ($vars['nodate'] == '1') ? '' : str_replace('$now', $now, COMMENT_NOW_FORMAT);
56
57         $comment = str_replace("\x08MSG\x08", $_msg, COMMENT_FORMAT);
58         $comment = str_replace("\x08NAME\x08",$_name,$comment);
59         $comment = str_replace("\x08NOW\x08", $_now, $comment);
60         $comment = $head . $comment;
61
62         $postdata = '';
63         $postdata_old  = get_source($vars['refer']);
64         $comment_no = 0;
65         $comment_ins = ($vars['above'] == '1');
66
67         foreach ($postdata_old as $line)
68         {
69                 if (!$comment_ins)
70                 {
71                         $postdata .= $line;
72                 }
73                 if (preg_match('/^#comment/', $line) and $comment_no++ == $vars['comment_no'])
74                 {
75                         $postdata = rtrim($postdata)."\n-$comment\n";
76                         if ($comment_ins)
77                         {
78                                 $postdata .= "\n";
79                         }
80                 }
81                 if ($comment_ins)
82                 {
83                         $postdata .= $line;
84                 }
85         }
86
87         $title = $_title_updated;
88         $body = '';
89         if (md5(@join('',get_source($vars['refer']))) != $vars['digest'])
90         {
91                 $title = $_title_comment_collided;
92                 $body = $_msg_comment_collided . make_pagelink($vars['refer']);
93         }
94
95         page_write($vars['refer'], $postdata);
96
97         $retvars['msg'] = $title;
98         $retvars['body'] = $body;
99
100         $vars['page'] = $vars['refer'];
101
102         return $retvars;
103 }
104
105 function plugin_comment_convert()
106 {
107         global $script, $vars, $digest;
108         global $_btn_comment, $_btn_name, $_msg_comment;
109         static $numbers = array();
110
111         if (! isset($numbers[$vars['page']])) {
112                 $numbers[$vars['page']] = 0;
113         }
114         $comment_no = $numbers[$vars['page']]++;
115
116         $options = func_num_args() ? func_get_args() : array();
117
118         if (in_array('noname',$options)) {
119                 $nametags = $_msg_comment;
120         } else {
121                 $nametags = $_btn_name . '<input type="text" name="name" size="' . COMMENT_NAME_COLS . "\" />\n";
122         }
123
124         $nodate = in_array('nodate', $options) ? '1' : '0';
125         $above = in_array('above', $options) ? '1' : (in_array('below', $options) ? '0' : COMMENT_INS);
126
127         $s_page = htmlspecialchars($vars['page']);
128         $comment_cols = COMMENT_COLS;
129         $string = <<<EOD
130 <br />
131 <form action="$script" method="post">
132  <div>
133   <input type="hidden" name="comment_no" value="$comment_no" />
134   <input type="hidden" name="refer"  value="$s_page" />
135   <input type="hidden" name="plugin" value="comment" />
136   <input type="hidden" name="nodate" value="$nodate" />
137   <input type="hidden" name="above"  value="$above" />
138   <input type="hidden" name="digest" value="$digest" />
139   $nametags
140   <input type="text"   name="msg" size="$comment_cols" />
141   <input type="submit" name="comment" value="$_btn_comment" />
142  </div>
143 </form>
144 EOD;
145
146         return $string;
147 }
148 ?>