OSDN Git Service

BugTrack/391: *.lngに$_no_subject,$_no_nameを追加
[pukiwiki/pukiwiki.git] / plugin / comment.inc.php
1 <?php
2 /////////////////////////////////////////////////
3 // PukiWiki - Yet another WikiWikiWeb clone.
4 //
5 // $Id: comment.inc.php,v 1.20 2003/07/10 03:21:12 arino 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','SIZE(10){$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,$post,$now;
32         global $_title_updated,$_no_name;
33         global $_msg_comment_collided,$_title_comment_collided;
34         
35         $post['msg'] = preg_replace("/\n/",'',$post['msg']);
36         
37         if ($post['msg'] == '')
38         {
39                 return array('msg'=>'','body'=>'');
40         }
41         
42         $head = '';
43         if (preg_match('/^(-{1,2})(.*)/',$post['msg'],$match))
44         {
45                 $head = $match[1];
46                 $post['msg'] = $match[2];
47         }
48         
49         $_msg  = str_replace('$msg',$post['msg'],COMMENT_MSG_FORMAT);
50         $_name = $post['name'] == '' ? $_no_name : $post['name'];
51         $_name = ($_name == '') ? '' : str_replace('$name',$_name,COMMENT_NAME_FORMAT);
52         $_now  = ($post['nodate'] == '1') ? '' : str_replace('$now',$now,COMMENT_NOW_FORMAT);
53         
54         $comment = str_replace("\x08MSG\x08", $_msg, COMMENT_FORMAT);
55         $comment = str_replace("\x08NAME\x08",$_name,$comment);
56         $comment = str_replace("\x08NOW\x08", $_now, $comment);
57         $comment = $head.$comment;
58         
59         $postdata = '';
60         $postdata_old  = get_source($post['refer']);
61         $comment_no = 0;
62         $comment_ins = ($post['above'] == '1');
63         
64         foreach ($postdata_old as $line)
65         {
66                 if (!$comment_ins)
67                 {
68                         $postdata .= $line;
69                 }
70                 if (preg_match('/^#comment/',$line) and $comment_no++ == $post['comment_no'])
71                 {
72                         $postdata = rtrim($postdata)."\n-$comment\n";
73                         if ($comment_ins)
74                         {
75                                 $postdata .= "\n";
76                         }
77                 }
78                 if ($comment_ins)
79                 {
80                         $postdata .= $line;
81                 }
82         }
83         
84         $title = $_title_updated;
85         $body = '';
86         if (md5(@join('',get_source($post['refer']))) != $post['digest'])
87         {
88                 $title = $_title_comment_collided;
89                 $body = $_msg_comment_collided . make_pagelink($post['refer']);
90         }
91         
92         page_write($post['refer'],$postdata);
93         
94         $retvars['msg'] = $title;
95         $retvars['body'] = $body;
96         
97         $post['page'] = $vars['page'] = $post['refer'];
98         
99         return $retvars;
100 }
101 function plugin_comment_convert()
102 {
103         global $script,$vars,$digest;
104         global $_btn_comment,$_btn_name,$_msg_comment;
105         static $numbers = array();
106         
107         if (!array_key_exists($vars['page'],$numbers))
108         {
109                 $numbers[$vars['page']] = 0;
110         }
111         $comment_no = $numbers[$vars['page']]++;
112         
113         $options = func_num_args() ? func_get_args() : array();
114         
115         if (in_array('noname',$options))
116         {
117                 $nametags = $_msg_comment;
118         }
119         else
120         {
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 ?>