]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/RedirectTo.php
LANG still broken, working on better locale handling.
[SourceForge/phpwiki.git] / lib / plugin / RedirectTo.php
1 <?php // -*-php-*-
2 rcs_id('$Id: RedirectTo.php,v 1.1 2002-08-27 21:51:31 rurban Exp $');
3 /*
4  Copyright 2002 $ThePhpWikiProgrammingTeam
5
6  This file is part of PhpWiki.
7
8  PhpWiki is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12
13  PhpWiki is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with PhpWiki; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 /**
24  * RedirectTo:
25  * Usage:   <?plugin-head RedirectTo href=http://www.internet-technology.de/fourwins_de.htm ?>
26  *      or  <?plugin-head RedirectTo page=AnotherPage ?>
27  *          at the VERY FIRST LINE in the content! Otherwise it will be ignored.
28  * Author:  Reini Urban <rurban@x-ray.at>
29  *
30  */
31
32 class WikiPlugin_RedirectTo
33 extends WikiPlugin
34 {
35     function getName() {
36         return _("RedirectTo");
37     }
38
39     function getDescription() {
40         return _("Redirects to another url or page.");
41     }
42
43     function getDefaultArguments() {
44         return array( 'href' => '',
45                       // 'type' => 'Temp' // or 'Permanent' // s far ignored
46                       'page' => false,
47                       'args' => false,  // pass more args to the page. TestMe!
48                       );
49     }
50
51     function run($dbi, $argstr, $request) {
52         $args = ($this->getArgs($argstr, $request));
53         $href = $args['href'];
54         $page = $args['page'];
55         if (!$href and !$page)
56             return $this->error(sprintf(_("href=%s parameter missing"), 'href'));
57         // FIXME: unmunged url hack
58         if ($href)
59             $url = preg_replace('/href=(.*)\Z/','$1',$argstr);
60         else {
61             $url = $request->getURLtoSelf(array_merge(array('pagename' => $page), $args['args']));
62         }
63         if ($page == $request->getArg($pagename)) {
64             return $this->error(sprintf(_("Recursive redirect to self %s"), $url));
65         }
66         return $request->redirect($url);
67     }
68 };
69
70 // For emacs users
71 // Local Variables:
72 // mode: php
73 // tab-width: 8
74 // c-basic-offset: 4
75 // c-hanging-comment-ender-p: nil
76 // indent-tabs-mode: nil
77 // End:
78 ?>