]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/redirectingaction.php
Merge branch 'apinamespace' into 0.9.x
[quix0rs-gnu-social.git] / lib / redirectingaction.php
1 <?php
2 /**
3  * Superclass for actions that redirect to a given return-to page on completion.
4  *
5  * PHP version 5
6  *
7  * StatusNet - the distributed open-source microblogging tool
8  * Copyright (C) 2009-2010, StatusNet, Inc.
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Affero General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Affero General Public License for more details.
19  *
20  * You should have received a copy of the GNU Affero General Public License
21  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  * @category Action
24  * @package  StatusNet
25  * @author   Evan Prodromou <evan@status.net>
26  * @author   Brion Vibber <brion@status.net>
27  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
28  * @link     http://status.net/
29  */
30
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
32     exit(1);
33 }
34
35 /**
36  * Superclass for actions that redirect to a given return-to page on completion.
37  *
38  * @category Action
39  * @package  StatusNet
40  * @author   Evan Prodromou <evan@status.net>
41  * @author   Brion Vibber <brion@status.net>
42  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
43  * @link     http://status.net/
44  */
45
46
47 class RedirectingAction extends Action
48 {
49
50     /**
51      * Redirect browser to the page our hidden parameters requested,
52      * or if none given, to the url given by $this->defaultReturnTo().
53      * 
54      * To be called only after successful processing.
55      * 
56      * Note: this was named returnToArgs() up through 0.9.2, which
57      * caused problems because there's an Action::returnToArgs()
58      * already which does something different.
59      * 
60      * @return void
61      */
62     function returnToPrevious()
63     {
64         // Now, gotta figure where we go back to
65         $action = false;
66         $args = array();
67         $params = array();
68         foreach ($this->args as $k => $v) {
69             if ($k == 'returnto-action') {
70                 $action = $v;
71             } else if (substr($k, 0, 15) == 'returnto-param-') {
72                 $params[substr($k, 15)] = $v;
73             } elseif (substr($k, 0, 9) == 'returnto-') {
74                 $args[substr($k, 9)] = $v;
75             }
76         }
77
78         if ($action) {
79             common_redirect(common_local_url($action, $args, $params), 303);
80         } else {
81             $url = $this->defaultReturnTo();
82         }
83         common_redirect($url, 303);
84     }
85
86     /**
87      * If we reached this form without returnto arguments, where should
88      * we go? May be overridden by subclasses to a reasonable destination
89      * for that action; default implementation throws an exception.
90      * 
91      * @return string URL
92      */
93     function defaultReturnTo()
94     {
95         $this->clientError(_("No return-to arguments."));
96     }
97 }