/////////////////////////////////////////////////
// PukiWiki - Yet another WikiWikiWeb clone.
//
-// $Id: pcomment.inc.php,v 1.18 2003/06/22 06:37:18 arino Exp $
+// $Id: pcomment.inc.php,v 1.27 2004/07/10 03:38:06 henoheno Exp $
//
/*
define('PCMT_INSERT_INS',1);
//
//¥³¥á¥ó¥È¤ÎÁÞÆþ¥Õ¥©¡¼¥Þ¥Ã¥È
-define('PCMT_FORMAT_NAME','[[%s]]');
-define('PCMT_FORMAT_MSG','%s');
-define('PCMT_FORMAT_DATE','SIZE(10){%s}');
+define('PCMT_NAME_FORMAT','[[$name]]');
+define('PCMT_MSG_FORMAT','$msg');
+define('PCMT_NOW_FORMAT','&new{$now};');
// \x08¤Ï¡¢Åê¹Æ¤µ¤ì¤¿Ê¸»úÎóÃæ¤Ë¸½¤ì¤Ê¤¤Ê¸»ú¤Ç¤¢¤ì¤Ð¤Ê¤ó¤Ç¤â¤¤¤¤¡£
define('PCMT_FORMAT',"\x08MSG\x08 -- \x08NAME\x08 \x08DATE\x08");
//
// ¼«Æ°²áµî¥í¥°²½ 1¥Ú¡¼¥¸¤¢¤¿¤ê¤Î·ï¿ô¤ò»ØÄê 0¤Ç̵¸ú
define('PCMT_AUTO_LOG',0);
+// ¥³¥á¥ó¥È¥Ú¡¼¥¸¤Î¥¿¥¤¥à¥¹¥¿¥ó¥×¤ò¹¹¿·¤»¤º¡¢ÀßÃÖ¥Ú¡¼¥¸¤Î¥¿¥¤¥à¥¹¥¿¥ó¥×¤ò¹¹¿·¤¹¤ë
+define('PCMT_TIMESTAMP',0);
-function plugin_pcomment_init()
-{
- $messages = array(
- '_pcmt_messages'=>array(
- 'btn_name' => '¤ªÌ¾Á°: ',
- 'btn_comment' => '¥³¥á¥ó¥È¤ÎÁÞÆþ',
- 'msg_comment' => '¥³¥á¥ó¥È: ',
- 'msg_recent' => 'ºÇ¿·¤Î%d·ï¤òɽ¼¨¤·¤Æ¤¤¤Þ¤¹¡£',
- 'msg_all' => '¥³¥á¥ó¥È¥Ú¡¼¥¸¤ò»²¾È',
- 'msg_none' => '¥³¥á¥ó¥È¤Ï¤¢¤ê¤Þ¤»¤ó¡£',
- 'title_collided' => '$1 ¤Ç¡Ú¹¹¿·¤Î¾×ÆÍ¡Û¤¬µ¯¤¤Þ¤·¤¿',
- 'msg_collided' => '¤¢¤Ê¤¿¤¬¤³¤Î¥Ú¡¼¥¸¤òÊÔ½¸¤·¤Æ¤¤¤ë´Ö¤Ë¡¢Â¾¤Î¿Í¤¬Æ±¤¸¥Ú¡¼¥¸¤ò¹¹¿·¤·¤Æ¤·¤Þ¤Ã¤¿¤è¤¦¤Ç¤¹¡£<br />
-¥³¥á¥ó¥È¤òÄɲä·¤Þ¤·¤¿¤¬¡¢°ã¤¦°ÌÃÖ¤ËÁÞÆþ¤µ¤ì¤Æ¤¤¤ë¤«¤â¤·¤ì¤Þ¤»¤ó¡£<br />',
- 'err_pagename' => basename(__FILE__).' : ¥Ú¡¼¥¸Ì¾ [[%s]] ¤Ï»ÈÍѤǤ¤Þ¤»¤ó¡£ Àµ¤·¤¤¥Ú¡¼¥¸Ì¾¤ò»ØÄꤷ¤Æ¤¯¤À¤µ¤¤¡£',
- )
- );
- set_plugin_messages($messages);
-}
function plugin_pcomment_action()
{
- global $script,$post,$vars;
+ global $script, $vars;
- if ($post['msg'] == '')
- {
- return array();
- }
+ if (! isset($vars['msg']) || $vars['msg'] == '') return array();
+ $refer = isset($vars['refer']) ? $vars['refer'] : '';
$retval = pcmt_insert();
-
- if ($retval['collided'])
- {
- $vars['page'] = $post['page'] = $post['refer'];
+ if ($retval['collided']) {
+ $vars['page'] = $refer;
return $retval;
}
- header("Location: $script?".rawurlencode($post['refer']));
+ header("Location: $script?" . rawurlencode($refer));
exit;
}
function plugin_pcomment_convert()
{
- global $script,$vars;
+ global $script, $vars;
global $_pcmt_messages;
//Ìá¤êÃÍ
'below' =>FALSE,
'above' =>FALSE,
'reply' =>FALSE,
- '_args' =>array(),
- '_done' =>FALSE
+ '_args' =>array()
);
array_walk(func_get_args(), 'pcmt_check_arg', &$params);
//ʸ»úÎó¤ò¼èÆÀ
- $page = array_key_exists(0,$params['_args']) ? $params['_args'][0] : '';
- $count = array_key_exists(1,$params['_args']) ? $params['_args'][1] : 0;
-
- if ($page == '')
- {
- $page = sprintf(PCMT_PAGE,strip_bracket($vars['page']));
- }
-
- $_page = get_fullname(strip_bracket($page),$vars['page']);
- if (!is_pagename($_page))
- {
- return sprintf($_pcmt_messages['err_pagename'],htmlspecialchars($_page));
- }
- if ($count == 0 and $count !== '0')
- {
+ $vars_page = isset($vars['page']) ? $vars['page'] : '';
+ $page = isset($params['_args'][0]) ? $params['_args'][0] : sprintf(PCMT_PAGE, strip_bracket($vars_page));
+ $count = isset($params['_args'][1]) ? $params['_args'][1] : 0;
+ if ($count == 0 and $count !== '0') {
$count = PCMT_NUM_COMMENTS;
}
- //¸þ¤¤ò·èÄê
+ $_page = get_fullname(strip_bracket($page), $vars_page);
+ if (!is_pagename($_page))
+ return sprintf($_pcmt_messages['err_pagename'], htmlspecialchars($_page));
+
+ //¿·¤·¤¤¥³¥á¥ó¥È¤òÄɲ乤ëÊý¸þ¤ò·èÄê
$dir = PCMT_INSERT_INS;
- if ($params['above'])
- {
+ if ($params['below']) {
+ $dir = 0; // ξÊý»ØÄꤵ¤ì¤¿¤é¡¢form¤Î²¼¤Ë (^^;
+ } elseif ($params['above']) {
$dir = 1;
}
- if ($params['below']) //ξÊý»ØÄꤵ¤ì¤¿¤é²¼¤Ë (^^;
- {
- $dir = 0;
- }
-
+
//¥³¥á¥ó¥È¤ò¼èÆÀ
- list($comments, $digest) = pcmt_get_comments($_page,$count,$dir,$params['reply']);
-
+ list($comments, $digest) = pcmt_get_comments($_page, $count, $dir, $params['reply']);
+
//¥Õ¥©¡¼¥à¤òɽ¼¨
if ($params['noname'])
{
$radio = $params['reply'] ? '<input type="radio" name="reply" value="0" tabindex="0" checked="checked" />' : '';
$comment = '<input type="text" name="msg" size="'.PCMT_COLS_COMMENT.'" />';
- //XSSÀȼåÀÌäÂê - ³°Éô¤«¤éÍ褿ÊÑ¿ô¤ò¥¨¥¹¥±¡¼¥×
- $s_page = htmlspecialchars($page);
- $s_refer = htmlspecialchars($vars['page']);
+ //XSSÀȼåÀÂкö - ³°Éô¤«¤éÍ褿ÊÑ¿ô¤ò¥¨¥¹¥±¡¼¥×
+ $s_page = htmlspecialchars($page);
+ $s_refer = htmlspecialchars($vars_page);
$s_nodate = htmlspecialchars($params['nodate']);
- $s_count = htmlspecialchars($count);
+ $s_count = htmlspecialchars($count);
$form = <<<EOD
<div>
<input type="hidden" name="digest" value="$digest" />
<input type="hidden" name="plugin" value="pcomment" />
- <input type="hidden" name="refer" value="$s_refer" />
- <input type="hidden" name="page" value="$s_page" />
+ <input type="hidden" name="refer" value="$s_refer" />
+ <input type="hidden" name="page" value="$s_page" />
<input type="hidden" name="nodate" value="$s_nodate" />
- <input type="hidden" name="dir" value="$dir" />
- <input type="hidden" name="count" value="$count" />
+ <input type="hidden" name="dir" value="$dir" />
+ <input type="hidden" name="count" value="$count" />
$radio $title $name $comment
<input type="submit" value="{$_pcmt_messages['btn_comment']}" />
</div>
function pcmt_insert()
{
- global $script,$vars,$post,$now;
- global $_title_updated,$_pcmt_messages;
+ global $script, $vars, $now;
+ global $_title_updated, $_no_name, $_pcmt_messages;
- $page = $post['page'];
+ $page = isset($vars['page']) ? $vars['page'] : '';
if (!is_pagename($page))
- {
- return array('msg'=>'invalid page name.','body'=>'cannot add comment.','collided'=>TRUE);
- }
+ return array('msg'=>'invalid page name.', 'body'=>'cannot add comment.' , 'collided'=>TRUE);
check_editable($page, true, true);
);
//¥³¥á¥ó¥È¥Õ¥©¡¼¥Þ¥Ã¥È¤òŬÍÑ
- $msg = sprintf(PCMT_FORMAT_MSG, rtrim($post['msg']));
- $name = ($post['name'] == '') ? '' : sprintf(PCMT_FORMAT_NAME, $post['name']);
- $date = ($post['nodate'] == '1') ? '' : sprintf(PCMT_FORMAT_DATE, $now);
+ $msg = str_replace('$msg', rtrim($vars['msg']), PCMT_MSG_FORMAT);
+
+ $name = (! isset($vars['name']) || $vars['name'] == '') ? $_no_name : $vars['name'];
+ $name = ($name == '') ? '' : str_replace('$name', $name, PCMT_NAME_FORMAT);
+
+ $date = (! isset($vars['nodate']) || $vars['nodate'] != '1') ? str_replace('$now', $now, PCMT_NOW_FORMAT) : '';
if ($date != '' or $name != '')
{
$msg = str_replace("\x08MSG\x08", $msg, PCMT_FORMAT);
$msg = str_replace("\x08NAME\x08",$name, $msg);
$msg = str_replace("\x08DATE\x08",$date, $msg);
}
- $reply_hash = array_key_exists('reply',$post) ? $post['reply'] : '';
+
+ $reply_hash = isset($vars['reply']) ? $vars['reply'] : '';
if ($reply_hash or !is_page($page))
{
$msg = preg_replace('/^\-+/','',$msg);
}
$msg = rtrim($msg);
-
- if (!is_page($page))
- {
- $postdata = '[['.htmlspecialchars(strip_bracket($post['refer']))."]]\n\n-$msg\n";
- }
- else
- {
+
+ $refer = isset($vars['refer']) ? $vars['refer'] : '';
+ if (! is_page($page)) {
+ $postdata = '[[' . htmlspecialchars(strip_bracket($refer)) . "]]\n\n-$msg\n";
+ } else {
//¥Ú¡¼¥¸¤òÆɤ߽Ф¹
$postdata = get_source($page);
// ¹¹¿·¤Î¾×Æͤò¸¡½Ð
- if (md5(join('',$postdata)) != $post['digest'])
+ $digest = isset($vars['digest']) ? $vars['digest'] : '';
+ if (md5(join('', $postdata)) != $digest)
{
- $ret['msg'] = $_pcmt_messages['title_collided'];
+ $ret['msg'] = $_pcmt_messages['title_collided'];
$ret['body'] = $_pcmt_messages['msg_collided'];
}
$pos++;
}
$start_pos = $pos;
+
+ $dir = isset($vars['dir']) ? $vars['dir'] : '';
//¥ê¥×¥é¥¤Àè¤Î¥³¥á¥ó¥È¤ò¸¡º÷
if ($reply_hash != '')
{
while ($pos < count($postdata))
{
- if (preg_match('/^(\-{1,2})(?!\-)(.*)$/',$postdata[$pos++],$matches)
+ $matches = array();
+ if (preg_match('/^(\-{1,2})(?!\-)(.*)$/', $postdata[$pos++], $matches)
and md5($matches[2]) == $reply_hash)
{
$level = strlen($matches[1]) + 1; //ÁÞÆþ¤¹¤ë¥ì¥Ù¥ë
}
else
{
- $pos = ($post['dir'] == 0) ? $start_pos : count($postdata);
+ $pos = ($dir == 0) ? $start_pos : count($postdata);
}
- if ($post['dir'] == '0')
+ if ($dir == '0')
{
if ($pos == count($postdata))
{
}
//¥³¥á¥ó¥È¤òÁÞÆþ
- array_splice($postdata,$pos,0,str_repeat('-',$level)."$msg\n");
+ array_splice($postdata, $pos, 0, str_repeat('-', $level) . "$msg\n");
// ²áµî¥í¥°½èÍý
- pcmt_auto_log($page,$post['dir'],$post['count'],$postdata);
+ $count = isset($vars['count']) ? $vars['count'] : '';
+ pcmt_auto_log($page, $dir, $count, $postdata);
- $postdata = join('',$postdata);
+ $postdata = join('', $postdata);
+ }
+ page_write($page,$postdata,PCMT_TIMESTAMP);
+
+ if (PCMT_TIMESTAMP)
+ {
+ // ¿Æ¥Ú¡¼¥¸¤Î¥¿¥¤¥à¥¹¥¿¥ó¥×¤ò¹¹¿·¤¹¤ë
+ if ($refer != '') touch(get_filename($refer));
+ put_lastmodified();
}
- // ¥Õ¥¡¥¤¥ë¤Î½ñ¤¹þ¤ß
- page_write($page,$postdata);
-
return $ret;
}
+
// ²áµî¥í¥°½èÍý
-function pcmt_auto_log($page,$dir,$count,&$postdata)
+function pcmt_auto_log($page, $dir, $count, &$postdata)
{
if (!PCMT_AUTO_LOG)
- {
return;
- }
- $keys = array_keys(preg_grep('/(?:^-(?!-).*$)/m',$postdata));
+
+ $keys = array_keys(preg_grep('/(?:^-(?!-).*$)/m', $postdata));
if (count($keys) < (PCMT_AUTO_LOG + $count))
- {
return;
+
+ if ($dir) { //Á°¤«¤éPCMT_AUTO_LOG·ï
+ $old = array_splice($postdata, $keys[0], $keys[PCMT_AUTO_LOG] - $keys[0]);
+ } else { //¸å¤í¤«¤éPCMT_AUTO_LOG·ï
+ $old = array_splice($postdata, $keys[count($keys) - PCMT_AUTO_LOG]);
}
- if ($dir) //Á°¤«¤éPCMT_AUTO_LOG·ï
- {
- $old = array_splice($postdata,$keys[0],$keys[PCMT_AUTO_LOG] - $keys[0]);
- }
- else //¸å¤í¤«¤éPCMT_AUTO_LOG·ï
- {
- $old = array_splice($postdata,$keys[count($keys) - PCMT_AUTO_LOG]);
- }
+
// ¥Ú¡¼¥¸Ì¾¤ò·èÄê
$i = 0;
do {
- $i++;
+ ++$i;
$_page = "$page/$i";
} while (is_page($_page));
- page_write($_page,"[[$page]]\n\n".join('',$old));
+ page_write($_page, "[[$page]]\n\n" . join('', $old));
// ·«¤êÊÖ¤¹ :)
- pcmt_auto_log($page,$dir,$count,$postdata);
+ pcmt_auto_log($page, $dir, $count, $postdata);
}
+
//¥ª¥×¥·¥ç¥ó¤ò²òÀϤ¹¤ë
function pcmt_check_arg($val, $key, &$params)
{
$params['_args'][] = $val;
}
-function pcmt_get_comments($page,$count,$dir,$reply)
+function pcmt_get_comments($page, $count, $dir, $reply)
{
+ global $_msg_pcomment_restrict;
+
if (!check_readable($page, false, false))
- {
- return array("±ÜÍ÷À©¸Â¤¬¤«¤«¤Ã¤Æ¤¤¤ë¤¿¤á¡¢".$page."¤«¤é¤Ï¥³¥á¥ó¥È¤òÆɤߤ³¤à¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡£");
- }
+ return array(str_replace('$1', $page, $_msg_pcomment_restrict));
$data = get_source($page);
-
if (!is_array($data))
- {
return array('',0);
- }
- $digest = md5(join('',$data));
+ $digest = md5(join('', $data));
//¥³¥á¥ó¥È¤ò»ØÄꤵ¤ì¤¿·ï¿ô¤À¤±ÀÚ¤ê¼è¤ë
if ($dir)
$data = array_reverse($data);
}
$num = $cnt = 0;
- $cmts = array();
+ $cmts = $matches = array();
foreach ($data as $line)
{
if ($count > 0 and $dir and $cnt == $count)
- {
break;
- }
- if (preg_match('/^(\-{1,2})(?!\-)(.*)$/', $line, $matches))
+
+ if (preg_match('/^(\-{1,2})(?!\-)(.+)$/', $line, $matches))
{
if ($count > 0 and strlen($matches[1]) == 1 and ++$cnt > $count)
- {
break;
- }
+
if ($reply)
{
++$num;
- $cmts[] = "$matches[1]\x01$num\x02".md5($matches[2])."\x03$matches[2]\n";
+ $cmts[] = "$matches[1]\x01$num\x02" . md5($matches[2]) . "\x03$matches[2]\n";
continue;
}
}
$cmts[] = $line;
}
$data = $cmts;
- if ($dir)
- {
+ if ($dir) {
$data = array_reverse($data);
}
- unset($cmts);
+ unset($cmts, $matches);
//¥³¥á¥ó¥È¤è¤êÁ°¤Î¥Ç¡¼¥¿¤ò¼è¤ê½ü¤¯¡£
- while (count($data) > 0 and substr($data[0],0,1) != '-')
- {
+ while (count($data) > 0 and substr($data[0], 0, 1) != '-') {
array_shift($data);
}
//¥³¥á¥ó¥È¤Ë¥é¥¸¥ª¥Ü¥¿¥ó¤Î°õ¤ò¤Ä¤±¤ë
if ($reply)
{
- $comments = preg_replace("/<li>\x01(\d+)\x02(.*)\x03/",'<li class="pcmt"><input class="pcmt" type="radio" name="reply" value="$2" tabindex="$1" />', $comments);
+ $comments = preg_replace("/<li>\x01(\d+)\x02(.*)\x03/", '<li class="pcmt"><input class="pcmt" type="radio" name="reply" value="$2" tabindex="$1" />', $comments);
}
- return array($comments,$digest);
+ return array($comments, $digest);
}
?>