OSDN Git Service

Cleanup. true/false => TRUE/FALSE. Added spaces.
[pukiwiki/pukiwiki.git] / plugin / comment.inc.php
1 <?php
2 /////////////////////////////////////////////////
3 // PukiWiki - Yet another WikiWikiWeb clone.
4 //
5 // $Id: comment.inc.php,v 1.25 2004/11/23 01:19:59 henoheno Exp $
6 //
7 // Comment plugin
8
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);
12
13 // ----
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()
19 {
20         global $script, $vars, $now, $_title_updated, $_no_name;
21         global $_msg_comment_collided, $_title_comment_collided;
22
23         if (! isset($vars['msg']) || $vars['msg'] == '')
24                 return array('msg'=>'', 'body'=>'');
25
26         $vars['msg'] = preg_replace("/\n/", '', $vars['msg']);
27
28         $head = '';
29         $match = array();
30         if (preg_match('/^(-{1,2})(.*)/', $vars['msg'], $match)) {
31                 $head        = $match[1];
32                 $vars['msg'] = $match[2];
33         }
34         unset($match);
35
36         $_msg  = str_replace('$msg', $vars['msg'], PLUGIN_COMMENT_FORMAT_MSG);
37
38         $_name = (! isset($vars['name']) || $vars['name'] == '') ? $_no_name : $vars['name'];
39         $_name = ($_name == '') ? '' : str_replace('$name', $_name, PLUGIN_COMMENT_FORMAT_NAME);
40
41         $_now  = ($vars['nodate'] == '1') ? '' : str_replace('$now', $now, PLUGIN_COMMENT_FORMAT_NOW);
42
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;
47
48         $postdata = '';
49         $postdata_old  = get_source($vars['refer']);
50         $comment_no = 0;
51         $comment_ins = ($vars['above'] == '1');
52
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";
58                 }
59                 if ($comment_ins) $postdata .= $line;
60         }
61
62         $title = $_title_updated;
63         $body = '';
64         if (md5(@join('', get_source($vars['refer']))) != $vars['digest']) {
65                 $title = $_title_comment_collided;
66                 $body  = $_msg_comment_collided . make_pagelink($vars['refer']);
67         }
68
69         page_write($vars['refer'], $postdata);
70
71         $retvars['msg']  = $title;
72         $retvars['body'] = $body;
73
74         $vars['page'] = $vars['refer'];
75
76         return $retvars;
77 }
78
79 function plugin_comment_convert()
80 {
81         global $script, $vars, $digest;
82         global $_btn_comment, $_btn_name, $_msg_comment;
83         static $numbers = array();
84
85         if (! isset($numbers[$vars['page']])) $numbers[$vars['page']] = 0;
86         $comment_no = $numbers[$vars['page']]++;
87
88         $options = func_num_args() ? func_get_args() : array();
89
90         if (in_array('noname', $options)) {
91                 $nametags = $_msg_comment;
92         } else {
93                 $nametags = $_btn_name .
94                         '<input type="text" name="name" size="' . PLUGIN_COMMENT_SIZE_NAME . "\" />\n";
95         }
96
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);
100
101         $s_page = htmlspecialchars($vars['page']);
102         static $comment_cols = PLUGIN_COMMENT_SIZE_MSG;
103         $string = <<<EOD
104 <br />
105 <form action="$script" method="post">
106  <div>
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" />
113   $nametags
114   <input type="text"   name="msg" size="$comment_cols" />
115   <input type="submit" name="comment" value="$_btn_comment" />
116  </div>
117 </form>
118 EOD;
119
120         return $string;
121 }
122 ?>