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

settingsaction.php 4.4 KB
Newer Older
Evan Prodromou's avatar
Evan Prodromou committed
1
<?php
2
/**
3
 * StatusNet, the distributed open-source microblogging tool
Evan Prodromou's avatar
Evan Prodromou committed
4
 *
5 6 7 8 9
 * Base class for settings actions
 *
 * PHP version 5
 *
 * LICENCE: This program is free software: you can redistribute it and/or modify
Evan Prodromou's avatar
Evan Prodromou committed
10 11 12
 * 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.
Evan Prodromou's avatar
Evan Prodromou committed
13
 *
Evan Prodromou's avatar
Evan Prodromou committed
14 15 16 17
 * 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.
Evan Prodromou's avatar
Evan Prodromou committed
18
 *
Evan Prodromou's avatar
Evan Prodromou committed
19 20
 * 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/>.
21 22
 *
 * @category  Settings
23
 * @package   StatusNet
24
 * @author    Evan Prodromou <evan@status.net>
25
 * @copyright 2008-2009 StatusNet, Inc.
26
 * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27
 * @link      http://status.net/
Evan Prodromou's avatar
Evan Prodromou committed
28
 */
Evan Prodromou's avatar
Evan Prodromou committed
29

30
if (!defined('STATUSNET') && !defined('LACONICA')) {
31 32 33 34 35 36 37
    exit(1);
}

/**
 * Base class for settings group of actions
 *
 * @category Settings
38
 * @package  StatusNet
39
 * @author   Evan Prodromou <evan@status.net>
40
 * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
41
 * @link     http://status.net/
42 43 44
 *
 * @see      Widget
 */
Evan Prodromou's avatar
Evan Prodromou committed
45

46
class SettingsAction extends Action
47
{
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
    /**
     * A message for the user.
     */

    var $msg = null;

    /**
     * Whether the message is a good one or a bad one.
     */

    var $success = false;

    /**
     * Handle input and output a page
     *
     * @param array $args $_REQUEST arguments
     *
     * @return void
     */
Evan Prodromou's avatar
Evan Prodromou committed
67

68 69
    function handle($args)
    {
Evan Prodromou's avatar
Evan Prodromou committed
70 71
        parent::handle($args);
        if (!common_logged_in()) {
72
            // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
73
            $this->clientError(_('Not logged in.'));
Evan Prodromou's avatar
Evan Prodromou committed
74
            return;
75
        } else if (!common_is_real_login()) {
76 77 78 79
            // Cookie theft means that automatic logins can't
            // change important settings or see private info, and
            // _all_ our settings are important
            common_set_returnto($this->selfUrl());
80
            $user = common_current_user();
81
            if (Event::handle('RedirectToLogin', array($this, $user))) {
82
                common_redirect(common_local_url('login'), 303);
83
            }
Evan Prodromou's avatar
Evan Prodromou committed
84
        } else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
85
            $this->handlePost();
Evan Prodromou's avatar
Evan Prodromou committed
86
        } else {
87
            $this->showForm();
Evan Prodromou's avatar
Evan Prodromou committed
88 89
        }
    }
Evan Prodromou's avatar
Evan Prodromou committed
90

91 92 93 94 95
    /**
     * Handle a POST request
     *
     * @return boolean success flag
     */
Evan Prodromou's avatar
Evan Prodromou committed
96

97
    function handlePost()
98
    {
Evan Prodromou's avatar
Evan Prodromou committed
99 100
        return false;
    }
Evan Prodromou's avatar
Evan Prodromou committed
101

102 103 104 105 106 107 108 109
    /**
     * show the settings form
     *
     * @param string $msg     an extra message for the user
     * @param string $success good message or bad message?
     *
     * @return void
     */
Evan Prodromou's avatar
Evan Prodromou committed
110

111
    function showForm($msg=null, $success=false)
112
    {
113 114
        $this->msg     = $msg;
        $this->success = $success;
115

116
        $this->showPage();
117
    }
118

119 120 121 122 123 124 125
    /**
     * show human-readable instructions for the page
     *
     * @return void
     */

    function showPageNotice()
126
    {
127 128 129
        if ($this->msg) {
            $this->element('div', ($this->success) ? 'success' : 'error',
                           $this->msg);
130
        } else {
131
            $inst   = $this->getInstructions();
132
            $output = common_markup_to_html($inst);
133 134 135

            $this->elementStart('div', 'instructions');
            $this->raw($output);
136
            $this->elementEnd('div');
137 138
        }
    }
139

140 141 142 143 144 145 146 147 148 149
    /**
     * instructions recipe for sub-classes
     *
     * Subclasses should override this to return readable instructions. They'll
     * be processed by common_markup_to_html().
     *
     * @return string instructions text
     */

    function getInstructions()
150
    {
151 152 153
        return '';
    }

154 155 156 157 158 159 160 161 162 163 164 165 166
    /**
     * Show the local navigation menu
     *
     * This is the same for all settings, so we show it here.
     *
     * @return void
     */

    function showLocalNav()
    {
        $menu = new SettingsNav($this);
        $menu->show();
    }
167 168 169 170 171 172 173 174 175 176 177

    /**
     * Show notice form.
     *
     * @return nothing
     */

    function showNoticeForm()
    {
        return;
    }
178 179 180 181

    function showProfileBlock()
    {
    }
Evan Prodromou's avatar
Evan Prodromou committed
182
}