リビジョン | fd549e4343007a525b7e68d5227842c84888f0b8 (tree) |
---|---|
日時 | 2016-11-15 02:40:00 |
作者 | umorigu <umorigu@gmai...> |
コミッター | 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 |
@@ -1,32 +1,12 @@ | ||
1 | 1 | <?php |
2 | 2 | // PukiWiki - Yet another WikiWikiWeb clone. |
3 | -// $Id: pukiwiki.php,v 1.23 2011/01/25 15:01:01 henoheno Exp $ | |
3 | +// pukiwiki.php | |
4 | +// Copyright | |
5 | +// 2002-2016 PukiWiki Development Team | |
6 | +// 2001-2002 Originally written by yu-ji | |
7 | +// License: GPL v2 or (at your option) any later version | |
4 | 8 | // |
5 | -// PukiWiki 1.4.* | |
6 | -// Copyright (C) 2002-2005 by PukiWiki Development Team | |
7 | -// http://pukiwiki.osdn.jp/ | |
8 | -// | |
9 | -// PukiWiki 1.3.* | |
10 | -// Copyright (C) 2002-2004 by PukiWiki Development Team | |
11 | -// http://pukiwiki.osdn.jp/ | |
12 | -// | |
13 | -// PukiWiki 1.3 (Base) | |
14 | -// Copyright (C) 2001-2002 by yu-ji <sng@factage.com> | |
15 | -// http://factage.com/sng/pukiwiki/ | |
16 | -// | |
17 | -// Special thanks | |
18 | -// YukiWiki by Hiroshi Yuki <hyuki@hyuki.com> | |
19 | -// http://www.hyuki.com/yukiwiki/ | |
20 | -// | |
21 | -// This program is free software; you can redistribute it and/or modify | |
22 | -// it under the terms of the GNU General Public License as published by | |
23 | -// the Free Software Foundation; either version 2 of the License, or | |
24 | -// (at your option) any later version. | |
25 | -// | |
26 | -// This program is distributed in the hope that it will be useful, | |
27 | -// but WITHOUT ANY WARRANTY; without even the implied warranty of | |
28 | -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
29 | -// GNU General Public License for more details. | |
9 | +// PukiWiki main script | |
30 | 10 | |
31 | 11 | if (! defined('DATA_HOME')) define('DATA_HOME', ''); |
32 | 12 |
@@ -65,7 +45,9 @@ if ($notify) { | ||
65 | 45 | |
66 | 46 | ///////////////////////////////////////////////// |
67 | 47 | // Main |
68 | - | |
48 | +if (manage_page_redirect()) { | |
49 | + exit; | |
50 | +} | |
69 | 51 | $retvars = array(); |
70 | 52 | $is_cmd = FALSE; |
71 | 53 | if (isset($vars['cmd'])) { |
@@ -121,4 +103,3 @@ if (isset($retvars['body']) && $retvars['body'] != '') { | ||
121 | 103 | |
122 | 104 | // Output |
123 | 105 | catbody($title, $page, $body); |
124 | -exit; |
@@ -419,6 +419,13 @@ $non_list = '^\:'; | ||
419 | 419 | // Search ignored pages |
420 | 420 | $search_non_list = 1; |
421 | 421 | |
422 | + | |
423 | +// Page redirect rules | |
424 | +$page_redirect_rules = array( | |
425 | + //'#^FromProject($|(/(.+)$))#' => 'ToProject$1', | |
426 | + //'#^FromProject($|(/(.+)$))#' => function($matches) { return 'ToProject' . $matches[1]; }, | |
427 | +); | |
428 | + | |
422 | 429 | ///////////////////////////////////////////////// |
423 | 430 | // Template setting |
424 | 431 |