OSDN Git Service

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