OSDN Git Service

Do nothing with content body '--------------'
[pukiwiki/pukiwiki.git] / plugin / comment.inc.php
1 <?php
2 // PukiWiki - Yet another WikiWikiWeb clone
3 // $Id: comment.inc.php,v 1.31 2005/05/06 01:59:34 henoheno Exp $
4 //
5 // Comment plugin
6
7 define('PLUGIN_COMMENT_DIRECTION_DEFAULT', '1'); // 1: above 0: below
8 define('PLUGIN_COMMENT_SIZE_MSG',  70);
9 define('PLUGIN_COMMENT_SIZE_NAME', 15);
10
11 // ----
12 define('PLUGIN_COMMENT_FORMAT_MSG',  '$msg');
13 define('PLUGIN_COMMENT_FORMAT_NAME', '[[$name]]');
14 define('PLUGIN_COMMENT_FORMAT_NOW',  '&new{$now};');
15 define('PLUGIN_COMMENT_FORMAT_STRING', "\x08MSG\x08 -- \x08NAME\x08 \x08NOW\x08");
16
17 function plugin_comment_action()
18 {
19         global $script, $vars, $now, $_title_updated, $_no_name;
20         global $_msg_comment_collided, $_title_comment_collided;
21
22         if (PKWK_READONLY) die_message('PKWK_READONLY prohibits editing');
23
24         if (! isset($vars['msg'])) return array('msg'=>'', 'body'=>''); // Do nothing
25
26         $vars['msg'] = preg_replace("/\n/", '', $vars['msg']); // Cut LFs
27         $head = '';
28         $match = array();
29         if (preg_match('/^(-{1,2})-*\s*(.*)/', $vars['msg'], $match)) {
30                 $head        = & $match[1];
31                 $vars['msg'] = & $match[2];
32         }
33         if ($vars['msg'] == '') return array('msg'=>'', 'body'=>''); // Do nothing
34
35         $comment  = str_replace('$msg', $vars['msg'], PLUGIN_COMMENT_FORMAT_MSG);
36         if(isset($vars['name']) || ($vars['nodate'] != '1')) {
37                 $_name = (! isset($vars['name']) || $vars['name'] == '') ? $_no_name : $vars['name'];
38                 $_name = ($_name == '') ? '' : str_replace('$name', $_name, PLUGIN_COMMENT_FORMAT_NAME);
39
40                 $_now  = ($vars['nodate'] == '1') ? '' :
41                         str_replace('$now', $now, PLUGIN_COMMENT_FORMAT_NOW);
42
43                 $comment = str_replace("\x08MSG\x08",  $comment, PLUGIN_COMMENT_FORMAT_STRING);
44                 $comment = str_replace("\x08NAME\x08", $_name, $comment);
45                 $comment = str_replace("\x08NOW\x08",  $_now,  $comment);
46         }
47         $comment = $head . ' ' . $comment;
48
49         $postdata      = '';
50         $postdata_old  = get_source($vars['refer']);
51         $comment_no    = 0;
52         $comment_ins   = ($vars['above'] == '1');
53
54         foreach ($postdata_old as $line) {
55                 if (! $comment_ins) $postdata .= $line;
56                 if (preg_match('/^#comment/i', $line) && $comment_no++ == $vars['comment_no']) {
57                         $postdata = rtrim($postdata) . "\n" .
58                                 '-' . $comment . "\n";
59                         if ($comment_ins) $postdata .= "\n";
60                 }
61                 if ($comment_ins) $postdata .= $line;
62         }
63
64         $title = $_title_updated;
65         $body = '';
66         if (md5(@join('', get_source($vars['refer']))) != $vars['digest']) {
67                 $title = $_title_comment_collided;
68                 $body  = $_msg_comment_collided . make_pagelink($vars['refer']);
69         }
70
71         page_write($vars['refer'], $postdata);
72
73         $retvars['msg']  = $title;
74         $retvars['body'] = $body;
75
76         $vars['page'] = $vars['refer'];
77
78         return $retvars;
79 }
80
81 function plugin_comment_convert()
82 {
83         global $vars, $digest, $_btn_comment, $_btn_name, $_msg_comment;
84         static $numbers = array();
85         static $comment_cols = PLUGIN_COMMENT_SIZE_MSG;
86
87         if (PKWK_READONLY) return ''; // Show nothing
88
89         if (! isset($numbers[$vars['page']])) $numbers[$vars['page']] = 0;
90         $comment_no = $numbers[$vars['page']]++;
91
92         $options = func_num_args() ? func_get_args() : array();
93         if (in_array('noname', $options)) {
94                 $nametags = '<label for="_p_comment_comment_' . $comment_no . '">' .
95                         $_msg_comment . '</label>';
96         } else {
97                 $nametags = '<label for="_p_comment_name_' . $comment_no . '">' .
98                         $_btn_name . '</label>' .
99                         '<input type="text" name="name" id="_p_comment_name_' .
100                         $comment_no .  '" size="' . PLUGIN_COMMENT_SIZE_NAME .
101                         '" />' . "\n";
102         }
103         $nodate = in_array('nodate', $options) ? '1' : '0';
104         $above  = in_array('above',  $options) ? '1' :
105                 (in_array('below', $options) ? '0' : PLUGIN_COMMENT_DIRECTION_DEFAULT);
106
107         $script = get_script_uri();
108         $s_page = htmlspecialchars($vars['page']);
109         $string = <<<EOD
110 <br />
111 <form action="$script" method="post">
112  <div>
113   <input type="hidden" name="plugin" value="comment" />
114   <input type="hidden" name="refer"  value="$s_page" />
115   <input type="hidden" name="comment_no" value="$comment_no" />
116   <input type="hidden" name="nodate" value="$nodate" />
117   <input type="hidden" name="above"  value="$above" />
118   <input type="hidden" name="digest" value="$digest" />
119   $nametags
120   <input type="text"   name="msg" id="_p_comment_comment_{$comment_no}" size="$comment_cols" />
121   <input type="submit" name="comment" value="$_btn_comment" />
122  </div>
123 </form>
124 EOD;
125
126         return $string;
127 }
128 ?>