修訂 | c7a32f7e9d6b9ec074fe0faa7de8241f9db5cff4 (tree) |
---|---|
時間 | 2016-11-15 01:57:41 |
作者 | umorigu <umorigu@gmai...> |
Commiter | umorigu |
BugTrack/2396 Redirect pages by Site Administrator
Add new property - $page_redirect_rules in pukiwiki.ini.php
@@ -730,6 +730,29 @@ function htmlsc($string = '', $flags = ENT_COMPAT, $charset = CONTENT_CHARSET) | ||
730 | 730 | return htmlspecialchars($string, $flags, $charset); // htmlsc() |
731 | 731 | } |
732 | 732 | |
733 | +// Redirect from an old page to new page | |
734 | +function manage_page_redirect() { | |
735 | + global $page_redirect_rules, $vars; | |
736 | + if (isset($vars['page'])) { | |
737 | + $page = $vars['page']; | |
738 | + foreach ($page_redirect_rules as $rule => $replace) { | |
739 | + if (preg_match($rule, $page)) { | |
740 | + if (is_string($replace)) { | |
741 | + $new_page = preg_replace($rule, $replace, $page); | |
742 | + } elseif (is_object($replace) && is_callable($replace)) { | |
743 | + $new_page = preg_replace_callback($rule, $replace, $page); | |
744 | + } else { | |
745 | + die_message('Invalid redirect rule: ' . $rule . '=>' . $replace); | |
746 | + } | |
747 | + header('Location: ' . get_script_uri() . '?' . | |
748 | + pagename_urlencode($new_page)); | |
749 | + return TRUE; | |
750 | + } | |
751 | + } | |
752 | + } | |
753 | + return FALSE; | |
754 | +} | |
755 | + | |
733 | 756 | |
734 | 757 | //// Compat //// |
735 | 758 |
@@ -65,19 +65,9 @@ if ($notify) { | ||
65 | 65 | |
66 | 66 | ///////////////////////////////////////////////// |
67 | 67 | // Main |
68 | - | |
69 | -if (isset($vars['page'])) { | |
70 | - $page = $vars['page']; | |
71 | - foreach ($redirect_rules as $rule => $replace) { | |
72 | - if (preg_match($rule, $page)) { | |
73 | - $new_page = preg_replace($rule, $replace, $page); | |
74 | - header('Location: ' . get_script_uri() . '?' . | |
75 | - pagename_urlencode($new_page)); | |
76 | - exit; | |
77 | - } | |
78 | - } | |
68 | +if (manage_page_redirect()) { | |
69 | + exit; | |
79 | 70 | } |
80 | - | |
81 | 71 | $retvars = array(); |
82 | 72 | $is_cmd = FALSE; |
83 | 73 | if (isset($vars['cmd'])) { |
@@ -421,8 +421,9 @@ $search_non_list = 1; | ||
421 | 421 | |
422 | 422 | |
423 | 423 | // Page redirect rules |
424 | -$redirect_rules = array( | |
425 | - //'#^RenamedOldProject($|(/(.+)$))#' => 'NewProject$1', | |
424 | +$page_redirect_rules = array( | |
425 | + //'#^FromProject($|(/(.+)$))#' => 'ToProject$1', | |
426 | + //'#^FromProject($|(/(.+)$))#' => function($matches) { return 'ToProject' . $matches[1]; }, | |
426 | 427 | ); |
427 | 428 | |
428 | 429 | ///////////////////////////////////////////////// |