3 * Superclass for actions that redirect to a given return-to page on completion.
7 * StatusNet - the distributed open-source microblogging tool
8 * Copyright (C) 2009-2010, StatusNet, Inc.
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.
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.
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/>.
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/
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
36 * Superclass for actions that redirect to a given return-to page on completion.
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/
45 class RedirectingAction extends Action
48 * Redirect browser to the page our hidden parameters requested,
49 * or if none given, to the url given by $this->defaultReturnTo().
51 * To be called only after successful processing.
53 * Note: this was named returnToArgs() up through 0.9.2, which
54 * caused problems because there's an Action::returnToArgs()
55 * already which does something different.
59 function returnToPrevious()
61 // Now, gotta figure where we go back to
65 foreach ($this->args as $k => $v) {
66 if ($k == 'returnto-action') {
68 } else if (substr($k, 0, 15) == 'returnto-param-') {
69 $params[substr($k, 15)] = $v;
70 } elseif (substr($k, 0, 9) == 'returnto-') {
71 $args[substr($k, 9)] = $v;
76 common_redirect(common_local_url($action, $args, $params), 303);
78 $url = $this->defaultReturnTo();
80 common_redirect($url, 303);
84 * If we reached this form without returnto arguments, where should
85 * we go? May be overridden by subclasses to a reasonable destination
86 * for that action; default implementation throws an exception.
90 function defaultReturnTo()
92 // TRANS: Client error displayed when return-to was defined without a target.
93 $this->clientError(_('No return-to arguments.'));