OSDN Git Service

BugTrack/2213 Use get_base_uri() instead of get_script_uri()
[pukiwiki/pukiwiki.git] / plugin / pcomment.inc.php
index 6dadab0..f07871a 100644 (file)
@@ -1,9 +1,11 @@
 <?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-2017 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
@@ -58,7 +58,7 @@ function plugin_pcomment_action()
        }
 
        pkwk_headers_sent();
-       header('Location: ' . get_script_uri() . '?' . rawurlencode($refer));
+       header('Location: ' . get_page_uri($refer, PKWK_URI_ROOT));
        exit;
 }
 
@@ -80,8 +80,21 @@ function plugin_pcomment_convert()
                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;
 
@@ -120,7 +133,7 @@ function plugin_pcomment_convert()
                $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">' . "\n";
                $form = <<<EOD
   <div>
   <input type="hidden" name="digest" value="$digest" />
@@ -230,7 +243,7 @@ function plugin_pcomment_insert()
                        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;
@@ -368,4 +381,3 @@ function plugin_pcomment_get_comments($page, $count, $dir, $reply)
 
        return array($comments, $digest);
 }
-?>