2 /////////////////////////////////////////////////
3 // PukiWiki - Yet another WikiWikiWeb clone.
5 // $Id: comment.inc.php,v 1.25 2004/11/23 01:19:59 henoheno Exp $
9 define('PLUGIN_COMMENT_DIRECTION_DEFAULT', '1'); // 1: above 0: below
10 define('PLUGIN_COMMENT_SIZE_MSG', 70);
11 define('PLUGIN_COMMENT_SIZE_NAME', 15);
14 define('PLUGIN_COMMENT_FORMAT_MSG', '$msg');
15 define('PLUGIN_COMMENT_FORMAT_NAME', '[[$name]]');
16 define('PLUGIN_COMMENT_FORMAT_NOW', '&new{$now};');
17 define('PLUGIN_COMMENT_FORMAT_STRING', "\x08MSG\x08 -- \x08NAME\x08 \x08NOW\x08");
18 function plugin_comment_action()
20 global $script, $vars, $now, $_title_updated, $_no_name;
21 global $_msg_comment_collided, $_title_comment_collided;
23 if (! isset($vars['msg']) || $vars['msg'] == '')
24 return array('msg'=>'', 'body'=>'');
26 $vars['msg'] = preg_replace("/\n/", '', $vars['msg']);
30 if (preg_match('/^(-{1,2})(.*)/', $vars['msg'], $match)) {
32 $vars['msg'] = $match[2];
36 $_msg = str_replace('$msg', $vars['msg'], PLUGIN_COMMENT_FORMAT_MSG);
38 $_name = (! isset($vars['name']) || $vars['name'] == '') ? $_no_name : $vars['name'];
39 $_name = ($_name == '') ? '' : str_replace('$name', $_name, PLUGIN_COMMENT_FORMAT_NAME);
41 $_now = ($vars['nodate'] == '1') ? '' : str_replace('$now', $now, PLUGIN_COMMENT_FORMAT_NOW);
43 $comment = str_replace("\x08MSG\x08", $_msg, PLUGIN_COMMENT_FORMAT_STRING);
44 $comment = str_replace("\x08NAME\x08", $_name, $comment);
45 $comment = str_replace("\x08NOW\x08", $_now, $comment);
46 $comment = $head . $comment;
49 $postdata_old = get_source($vars['refer']);
51 $comment_ins = ($vars['above'] == '1');
53 foreach ($postdata_old as $line) {
54 if (! $comment_ins) $postdata .= $line;
55 if (preg_match('/^#comment/i', $line) && $comment_no++ == $vars['comment_no']) {
56 $postdata = rtrim($postdata) . "\n-$comment\n";
57 if ($comment_ins) $postdata .= "\n";
59 if ($comment_ins) $postdata .= $line;
62 $title = $_title_updated;
64 if (md5(@join('', get_source($vars['refer']))) != $vars['digest']) {
65 $title = $_title_comment_collided;
66 $body = $_msg_comment_collided . make_pagelink($vars['refer']);
69 page_write($vars['refer'], $postdata);
71 $retvars['msg'] = $title;
72 $retvars['body'] = $body;
74 $vars['page'] = $vars['refer'];
79 function plugin_comment_convert()
81 global $script, $vars, $digest;
82 global $_btn_comment, $_btn_name, $_msg_comment;
83 static $numbers = array();
85 if (! isset($numbers[$vars['page']])) $numbers[$vars['page']] = 0;
86 $comment_no = $numbers[$vars['page']]++;
88 $options = func_num_args() ? func_get_args() : array();
90 if (in_array('noname', $options)) {
91 $nametags = $_msg_comment;
93 $nametags = $_btn_name .
94 '<input type="text" name="name" size="' . PLUGIN_COMMENT_SIZE_NAME . "\" />\n";
97 $nodate = in_array('nodate', $options) ? '1' : '0';
98 $above = in_array('above', $options) ? '1' :
99 (in_array('below', $options) ? '0' : PLUGIN_COMMENT_DIRECTION_DEFAULT);
101 $s_page = htmlspecialchars($vars['page']);
102 static $comment_cols = PLUGIN_COMMENT_SIZE_MSG;
105 <form action="$script" method="post">
107 <input type="hidden" name="comment_no" value="$comment_no" />
108 <input type="hidden" name="refer" value="$s_page" />
109 <input type="hidden" name="plugin" value="comment" />
110 <input type="hidden" name="nodate" value="$nodate" />
111 <input type="hidden" name="above" value="$above" />
112 <input type="hidden" name="digest" value="$digest" />
114 <input type="text" name="msg" size="$comment_cols" />
115 <input type="submit" name="comment" value="$_btn_comment" />