2 // PukiWiki - Yet another WikiWikiWeb clone
3 // $Id: comment.inc.php,v 1.41 2011/01/25 15:01:01 henoheno Exp $
5 // 2002-2005 PukiWiki Developers Team
6 // 2001-2002 Originally written by yu-ji
7 // License: GPL v2 or (at your option) any later version
11 define('PLUGIN_COMMENT_DIRECTION_DEFAULT', '1'); // 1: above 0: below
12 define('PLUGIN_COMMENT_SIZE_MSG', 70);
13 define('PLUGIN_COMMENT_SIZE_NAME', 15);
16 define('PLUGIN_COMMENT_FORMAT_MSG', '$msg');
17 define('PLUGIN_COMMENT_FORMAT_NAME', '[[$name]]');
18 define('PLUGIN_COMMENT_FORMAT_NOW', '&new{$now};');
19 define('PLUGIN_COMMENT_FORMAT_STRING', "\x08MSG\x08 -- \x08NAME\x08 \x08NOW\x08");
21 function plugin_comment_action()
23 global $script, $vars, $now, $_title_updated, $_no_name;
24 global $_msg_comment_collided, $_title_comment_collided;
26 if (PKWK_READONLY) die_message('PKWK_READONLY prohibits editing');
28 if (! isset($vars['msg'])) return array('msg'=>'', 'body'=>''); // Do nothing
30 $vars['msg'] = str_replace("\n", '', $vars['msg']); // Cut LFs
33 if (preg_match('/^(-{1,2})-*\s*(.*)/', $vars['msg'], $match)) {
35 $vars['msg'] = & $match[2];
37 if ($vars['msg'] == '') return array('msg'=>'', 'body'=>''); // Do nothing
39 $comment = str_replace('$msg', $vars['msg'], PLUGIN_COMMENT_FORMAT_MSG);
40 if(isset($vars['name']) || ($vars['nodate'] != '1')) {
41 $_name = (! isset($vars['name']) || $vars['name'] == '') ? $_no_name : $vars['name'];
42 $_name = ($_name == '') ? '' : str_replace('$name', $_name, PLUGIN_COMMENT_FORMAT_NAME);
43 $_now = ($vars['nodate'] == '1') ? '' :
44 str_replace('$now', $now, PLUGIN_COMMENT_FORMAT_NOW);
45 $comment = str_replace("\x08MSG\x08", $comment, PLUGIN_COMMENT_FORMAT_STRING);
46 $comment = str_replace("\x08NAME\x08", $_name, $comment);
47 $comment = str_replace("\x08NOW\x08", $_now, $comment);
49 $comment = '-' . $head . ' ' . $comment;
53 $above = (isset($vars['above']) && $vars['above'] == '1');
54 foreach (get_source($vars['refer']) as $line) {
55 if (! $above) $postdata .= $line;
56 if (preg_match('/^#comment/i', $line) && $comment_no++ == $vars['comment_no']) {
58 $postdata = rtrim($postdata) . "\n" .
60 "\n"; // Insert one blank line above #commment, to avoid indentation
62 $postdata = rtrim($postdata) . "\n" .
66 if ($above) $postdata .= $line;
69 $title = $_title_updated;
71 if (md5(get_source($vars['refer'], TRUE, TRUE)) !== $vars['digest']) {
72 $title = $_title_comment_collided;
73 $body = $_msg_comment_collided . make_pagelink($vars['refer']);
76 page_write($vars['refer'], $postdata);
78 $retvars['msg'] = $title;
79 $retvars['body'] = $body;
81 $vars['page'] = $vars['refer'];
86 function plugin_comment_convert()
88 global $vars, $digest, $_btn_comment, $_btn_name, $_msg_comment;
89 static $numbers = array();
90 static $comment_cols = PLUGIN_COMMENT_SIZE_MSG;
92 if (PKWK_READONLY) return ''; // Show nothing
94 if (! isset($numbers[$vars['page']])) $numbers[$vars['page']] = 0;
95 $comment_no = $numbers[$vars['page']]++;
97 $options = func_num_args() ? func_get_args() : array();
98 if (in_array('noname', $options)) {
99 $nametags = '<label for="_p_comment_comment_' . $comment_no . '">' .
100 $_msg_comment . '</label>';
102 $nametags = '<label for="_p_comment_name_' . $comment_no . '">' .
103 $_btn_name . '</label>' .
104 '<input type="text" name="name" id="_p_comment_name_' .
105 $comment_no . '" size="' . PLUGIN_COMMENT_SIZE_NAME .
108 $nodate = in_array('nodate', $options) ? '1' : '0';
109 $above = in_array('above', $options) ? '1' :
110 (in_array('below', $options) ? '0' : PLUGIN_COMMENT_DIRECTION_DEFAULT);
112 $script = get_script_uri();
113 $s_page = htmlsc($vars['page']);
116 <form action="$script" method="post">
118 <input type="hidden" name="plugin" value="comment" />
119 <input type="hidden" name="refer" value="$s_page" />
120 <input type="hidden" name="comment_no" value="$comment_no" />
121 <input type="hidden" name="nodate" value="$nodate" />
122 <input type="hidden" name="above" value="$above" />
123 <input type="hidden" name="digest" value="$digest" />
125 <input type="text" name="msg" id="_p_comment_comment_{$comment_no}" size="$comment_cols" />
126 <input type="submit" name="comment" value="$_btn_comment" />