]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/redirectingaction.php
Removed plugin Google-Analytics as this is free/libre and decentralized
[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 class RedirectingAction extends Action
46 {
47     /**
48      * Redirect browser to the page our hidden parameters requested,
49      * or if none given, to the url given by $this->defaultReturnTo().
50      *
51      * To be called only after successful processing.
52      *
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.
56      *
57      * @return void
58      */
59     function returnToPrevious()
60     {
61         // Now, gotta figure where we go back to
62         $action = false;
63         $args = array();
64         $params = array();
65         foreach ($this->args as $k => $v) {
66             if ($k == 'returnto-action') {
67                 $action = $v;
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;
72             }
73         }
74
75         if ($action) {
76             common_redirect(common_local_url($action, $args, $params), 303);
77         } else {
78             $url = $this->defaultReturnTo();
79         }
80         common_redirect($url, 303);
81     }
82
83     /**
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.
87      *
88      * @return string URL
89      */
90     function defaultReturnTo()
91     {
92         // TRANS: Client error displayed when return-to was defined without a target.
93         $this->clientError(_('No return-to arguments.'));
94     }
95 }