2 // PukiWiki - Yet another WikiWikiWeb clone
3 // $Id: comment.inc.php,v 1.35 2005/05/06 04:44:20 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" .
63 "\n" . // Insert one blank line below #commment, too (only by design)
64 $comment; // "\n" is already there or EOF
67 if ($above) $postdata .= $line;
70 $title = $_title_updated;
72 if (md5(@join('', get_source($vars['refer']))) != $vars['digest']) {
73 $title = $_title_comment_collided;
74 $body = $_msg_comment_collided . make_pagelink($vars['refer']);
77 page_write($vars['refer'], $postdata);
79 $retvars['msg'] = $title;
80 $retvars['body'] = $body;
82 $vars['page'] = $vars['refer'];
87 function plugin_comment_convert()
89 global $vars, $digest, $_btn_comment, $_btn_name, $_msg_comment;
90 static $numbers = array();
91 static $comment_cols = PLUGIN_COMMENT_SIZE_MSG;
93 if (PKWK_READONLY) return ''; // Show nothing
95 if (! isset($numbers[$vars['page']])) $numbers[$vars['page']] = 0;
96 $comment_no = $numbers[$vars['page']]++;
98 $options = func_num_args() ? func_get_args() : array();
99 if (in_array('noname', $options)) {
100 $nametags = '<label for="_p_comment_comment_' . $comment_no . '">' .
101 $_msg_comment . '</label>';
103 $nametags = '<label for="_p_comment_name_' . $comment_no . '">' .
104 $_btn_name . '</label>' .
105 '<input type="text" name="name" id="_p_comment_name_' .
106 $comment_no . '" size="' . PLUGIN_COMMENT_SIZE_NAME .
109 $nodate = in_array('nodate', $options) ? '1' : '0';
110 $above = in_array('above', $options) ? '1' :
111 (in_array('below', $options) ? '0' : PLUGIN_COMMENT_DIRECTION_DEFAULT);
113 $script = get_script_uri();
114 $s_page = htmlspecialchars($vars['page']);
117 <form action="$script" method="post">
119 <input type="hidden" name="plugin" value="comment" />
120 <input type="hidden" name="refer" value="$s_page" />
121 <input type="hidden" name="comment_no" value="$comment_no" />
122 <input type="hidden" name="nodate" value="$nodate" />
123 <input type="hidden" name="above" value="$above" />
124 <input type="hidden" name="digest" value="$digest" />
126 <input type="text" name="msg" id="_p_comment_comment_{$comment_no}" size="$comment_cols" />
127 <input type="submit" name="comment" value="$_btn_comment" />