We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

redirectingaction.php 3.11 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
<?php
/**
 * Superclass for actions that redirect to a given return-to page on completion.
 *
 * PHP version 5
 *
 * StatusNet - the distributed open-source microblogging tool
 * Copyright (C) 2009-2010, StatusNet, Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @category Action
 * @package  StatusNet
 * @author   Evan Prodromou <evan@status.net>
 * @author   Brion Vibber <brion@status.net>
 * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
 * @link     http://status.net/
 */

if (!defined('STATUSNET') && !defined('LACONICA')) {
    exit(1);
}

/**
 * Superclass for actions that redirect to a given return-to page on completion.
 *
 * @category Action
 * @package  StatusNet
 * @author   Evan Prodromou <evan@status.net>
 * @author   Brion Vibber <brion@status.net>
 * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
 * @link     http://status.net/
 */
class RedirectingAction extends Action
{
    /**
     * Redirect browser to the page our hidden parameters requested,
     * or if none given, to the url given by $this->defaultReturnTo().
50
     *
51
     * To be called only after successful processing.
52
     *
53 54 55
     * Note: this was named returnToArgs() up through 0.9.2, which
     * caused problems because there's an Action::returnToArgs()
     * already which does something different.
56
     *
57 58
     * @return void
     */
59
    function returnToPrevious()
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
    {
        // Now, gotta figure where we go back to
        $action = false;
        $args = array();
        $params = array();
        foreach ($this->args as $k => $v) {
            if ($k == 'returnto-action') {
                $action = $v;
            } else if (substr($k, 0, 15) == 'returnto-param-') {
                $params[substr($k, 15)] = $v;
            } elseif (substr($k, 0, 9) == 'returnto-') {
                $args[substr($k, 9)] = $v;
            }
        }

        if ($action) {
            common_redirect(common_local_url($action, $args, $params), 303);
        } else {
78
            $url = $this->defaultReturnTo();
79 80 81 82 83 84 85 86
        }
        common_redirect($url, 303);
    }

    /**
     * If we reached this form without returnto arguments, where should
     * we go? May be overridden by subclasses to a reasonable destination
     * for that action; default implementation throws an exception.
87
     *
88 89 90 91
     * @return string URL
     */
    function defaultReturnTo()
    {
92 93
        // TRANS: Client error displayed when return-to was defined without a target.
        $this->clientError(_('No return-to arguments.'));
94 95
    }
}