2 // PukiWiki - Yet another WikiWikiWeb clone
5 // 2002-2017 PukiWiki Development 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 $vars, $now, $_title_updated, $_no_name;
24 global $_msg_comment_collided, $_title_comment_collided;
25 global $_comment_plugin_fail_msg;
27 if (PKWK_READONLY) die_message('PKWK_READONLY prohibits editing');
29 if (! isset($vars['msg'])) return array('msg'=>'', 'body'=>''); // Do nothing
31 $vars['msg'] = str_replace("\n", '', $vars['msg']); // Cut LFs
34 if (preg_match('/^(-{1,2})-*\s*(.*)/', $vars['msg'], $match)) {
36 $vars['msg'] = & $match[2];
38 if ($vars['msg'] == '') return array('msg'=>'', 'body'=>''); // Do nothing
40 $comment = str_replace('$msg', $vars['msg'], PLUGIN_COMMENT_FORMAT_MSG);
41 if(isset($vars['name']) || ($vars['nodate'] != '1')) {
42 $_name = (! isset($vars['name']) || $vars['name'] == '') ? $_no_name : $vars['name'];
43 $_name = ($_name == '') ? '' : str_replace('$name', $_name, PLUGIN_COMMENT_FORMAT_NAME);
44 $_now = ($vars['nodate'] == '1') ? '' :
45 str_replace('$now', $now, PLUGIN_COMMENT_FORMAT_NOW);
46 $comment = str_replace("\x08MSG\x08", $comment, PLUGIN_COMMENT_FORMAT_STRING);
47 $comment = str_replace("\x08NAME\x08", $_name, $comment);
48 $comment = str_replace("\x08NOW\x08", $_now, $comment);
50 $comment = '-' . $head . ' ' . $comment;
54 $above = (isset($vars['above']) && $vars['above'] == '1');
55 $comment_added = FALSE;
56 foreach (get_source($vars['refer']) as $line) {
57 if (! $above) $postdata .= $line;
58 if (preg_match('/^#comment/i', $line) && $comment_no++ == $vars['comment_no']) {
59 $comment_added = TRUE;
61 $postdata = rtrim($postdata) . "\n" .
63 "\n"; // Insert one blank line above #commment, to avoid indentation
65 $postdata = rtrim($postdata) . "\n" .
69 if ($above) $postdata .= $line;
71 $title = $_title_updated;
75 if (md5(get_source($vars['refer'], TRUE, TRUE)) !== $vars['digest']) {
76 $title = $_title_comment_collided;
77 $body = $_msg_comment_collided . make_pagelink($vars['refer']);
79 page_write($vars['refer'], $postdata);
81 // failed to add the comment
82 $title = $_title_comment_collided;
83 $body = $_comment_plugin_fail_msg . make_pagelink($vars['refer']);
85 $retvars['msg'] = $title;
86 $retvars['body'] = $body;
87 $vars['page'] = $vars['refer'];
91 function plugin_comment_convert()
93 global $vars, $digest, $_btn_comment, $_btn_name, $_msg_comment;
94 static $numbers = array();
95 static $comment_cols = PLUGIN_COMMENT_SIZE_MSG;
97 if (PKWK_READONLY) return ''; // Show nothing
99 if (! isset($numbers[$vars['page']])) $numbers[$vars['page']] = 0;
100 $comment_no = $numbers[$vars['page']]++;
102 $options = func_num_args() ? func_get_args() : array();
103 if (in_array('noname', $options)) {
104 $nametags = '<label for="_p_comment_comment_' . $comment_no . '">' .
105 $_msg_comment . '</label>';
107 $nametags = '<label for="_p_comment_name_' . $comment_no . '">' .
108 $_btn_name . '</label>' .
109 '<input type="text" name="name" id="_p_comment_name_' .
110 $comment_no . '" size="' . PLUGIN_COMMENT_SIZE_NAME .
113 $nodate = in_array('nodate', $options) ? '1' : '0';
114 $above = in_array('above', $options) ? '1' :
115 (in_array('below', $options) ? '0' : PLUGIN_COMMENT_DIRECTION_DEFAULT);
117 $script = get_base_uri();
118 $s_page = htmlsc($vars['page']);
121 <form action="$script" method="post">
123 <input type="hidden" name="plugin" value="comment" />
124 <input type="hidden" name="refer" value="$s_page" />
125 <input type="hidden" name="comment_no" value="$comment_no" />
126 <input type="hidden" name="nodate" value="$nodate" />
127 <input type="hidden" name="above" value="$above" />
128 <input type="hidden" name="digest" value="$digest" />
130 <input type="text" name="msg" id="_p_comment_comment_{$comment_no}" size="$comment_cols" />
131 <input type="submit" name="comment" value="$_btn_comment" />