<?php
// PukiWiki - Yet another WikiWikiWeb clone
-// $Id: pcomment.inc.php,v 1.48 2011/01/25 15:01:01 henoheno Exp $
+// pcomment.inc.php
+// Copyright 2002-2020 PukiWiki Development Team
+// License: GPL v2 or (at your option) any later version
//
// pcomment plugin - Show/Insert comments into specified (another) page
-//
+
// Usage: #pcomment([page][,max][,options])
//
// page -- An another page-name that holds comments
// reply -- Show radio buttons allow to specify where to reply
// Default recording page name (%s = $vars['page'] = original page name)
-switch (LANG) {
-case 'ja': define('PLUGIN_PCOMMENT_PAGE', '[[¥³¥á¥ó¥È/%s]]'); break;
-default: define('PLUGIN_PCOMMENT_PAGE', '[[Comments/%s]]'); break;
-}
+define('PLUGIN_PCOMMENT_PAGE', '[[Comments/%s]]');
+define('PLUGIN_PCOMMENT_PAGE_COMPATIBLE', '[[コメント/%s]]'); // for backword compatible of 'ja' pcomment
define('PLUGIN_PCOMMENT_NUM_COMMENTS', 10); // Default 'latest N posts'
define('PLUGIN_PCOMMENT_DIRECTION_DEFAULT', 1); // 1: above 0: below
}
pkwk_headers_sent();
- header('Location: ' . get_script_uri() . '?' . rawurlencode($refer));
+ header('Location: ' . get_page_uri($refer, PKWK_URI_ROOT));
exit;
}
plugin_pcomment_check_arg($arg, $params);
$vars_page = isset($vars['page']) ? $vars['page'] : '';
- $page = (isset($params['_args'][0]) && $params['_args'][0] != '') ? $params['_args'][0] :
- sprintf(PLUGIN_PCOMMENT_PAGE, strip_bracket($vars_page));
+ if (isset($params['_args'][0]) && $params['_args'][0] != '') {
+ $page = $params['_args'][0];
+ } else {
+ $raw_vars_page = strip_bracket($vars_page);
+ $page = sprintf(PLUGIN_PCOMMENT_PAGE, $raw_vars_page);
+ $raw_page = strip_bracket($page);
+ if (!is_page($raw_page)) {
+ // If the page doesn't exist, search backward-compatible page
+ // If only compatible page exists, set the page as comment target
+ $page_compat = sprintf(PLUGIN_PCOMMENT_PAGE_COMPATIBLE, $raw_vars_page);
+ if (is_page(strip_bracket($page_compat))) {
+ $page = $page_compat;
+ }
+ }
+ }
$count = isset($params['_args'][1]) ? intval($params['_args'][1]) : 0;
if ($count == 0) $count = PLUGIN_PCOMMENT_NUM_COMMENTS;
$radio = $params['reply'] ?
'<input type="radio" name="reply" value="0" tabindex="0" checked="checked" />' : '';
- $comment = '<input type="text" name="msg" size="' . PLUGIN_PCOMMENT_SIZE_MSG . '" />';
+ $comment = '<input type="text" name="msg" size="' .
+ PLUGIN_PCOMMENT_SIZE_MSG . '" required />';
$s_page = htmlsc($page);
$s_refer = htmlsc($vars_page);
$s_nodate = htmlsc($params['nodate']);
$s_count = htmlsc($count);
- $form_start = '<form action="' . get_script_uri() . '" method="post">' . "\n";
+ $form_start = '<form action="' . get_base_uri() .
+ '" method="post" class="_p_pcomment_form">' . "\n";
$form = <<<EOD
<div>
<input type="hidden" name="digest" value="$digest" />
$count = count($postdata);
$digest = isset($vars['digest']) ? $vars['digest'] : '';
- if (md5(join('', $postdata)) != $digest) {
+ if (md5(join('', $postdata)) !== $digest) {
$ret['msg'] = $_pcmt_messages['title_collided'];
$ret['body'] = $_pcmt_messages['msg_collided'];
}
while ($end_position < $count) {
$matches = array();
if (preg_match('/^(\-{1,2})(?!\-)(.*)$/', $postdata[$end_position++], $matches)
- && md5($matches[2]) == $reply_hash)
+ && md5($matches[2]) === $reply_hash)
{
$b_reply = TRUE;
$level = strlen($matches[1]) + 1;
return array($comments, $digest);
}
-?>