OSDN Git Service

BugTrack2/370 Set same pcomment default target page for en/ja
authorumorigu <umorigu@gmail.com>
Sun, 17 Jan 2016 16:49:12 +0000 (01:49 +0900)
committerumorigu <umorigu@gmail.com>
Sun, 17 Jan 2016 16:49:12 +0000 (01:49 +0900)
* Default page: Comments/%s
* Compatible default page: コメント/%s

If only compatible page exist, use compatible page as a default comment
target.

plugin/pcomment.inc.php

index 036a14f..ac6931c 100644 (file)
 //   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
@@ -80,8 +78,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;