]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/settingsaction.php
Merge commit 'refs/merge-requests/165' of git://gitorious.org/statusnet/mainline...
[quix0rs-gnu-social.git] / lib / settingsaction.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Base class for settings actions
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * 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/
28  */
29
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
31     exit(1);
32 }
33
34 /**
35  * Base class for settings group of actions
36  *
37  * @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  * @see      Widget
44  */
45
46 class SettingsAction extends Action
47 {
48     /**
49      * A message for the user.
50      */
51
52     var $msg = null;
53
54     /**
55      * Whether the message is a good one or a bad one.
56      */
57
58     var $success = false;
59
60     /**
61      * Handle input and output a page
62      *
63      * @param array $args $_REQUEST arguments
64      *
65      * @return void
66      */
67
68     function handle($args)
69     {
70         parent::handle($args);
71         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.'));
74             return;
75         } else if (!common_is_real_login()) {
76             // Cookie theft means that automatic logins can't
77             // change important settings or see private info, and
78             // _all_ our settings are important
79             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             }
84         } else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
85             $this->handlePost();
86         } else {
87             $this->showForm();
88         }
89     }
90
91     /**
92      * Handle a POST request
93      *
94      * @return boolean success flag
95      */
96
97     function handlePost()
98     {
99         return false;
100     }
101
102     /**
103      * show the settings form
104      *
105      * @param string $msg     an extra message for the user
106      * @param string $success good message or bad message?
107      *
108      * @return void
109      */
110
111     function showForm($msg=null, $success=false)
112     {
113         $this->msg     = $msg;
114         $this->success = $success;
115
116         $this->showPage();
117     }
118
119     /**
120      * show human-readable instructions for the page
121      *
122      * @return void
123      */
124
125     function showPageNotice()
126     {
127         if ($this->msg) {
128             $this->element('div', ($this->success) ? 'success' : 'error',
129                            $this->msg);
130         } else {
131             $inst   = $this->getInstructions();
132             $output = common_markup_to_html($inst);
133
134             $this->elementStart('div', 'instructions');
135             $this->raw($output);
136             $this->elementEnd('div');
137         }
138     }
139
140     /**
141      * instructions recipe for sub-classes
142      *
143      * Subclasses should override this to return readable instructions. They'll
144      * be processed by common_markup_to_html().
145      *
146      * @return string instructions text
147      */
148
149     function getInstructions()
150     {
151         return '';
152     }
153
154     /**
155      * Show the local navigation menu
156      *
157      * This is the same for all settings, so we show it here.
158      *
159      * @return void
160      */
161
162     function showLocalNav()
163     {
164         $menu = new SettingsNav($this);
165         $menu->show();
166     }
167
168     /**
169      * Show notice form.
170      *
171      * @return nothing
172      */
173
174     function showNoticeForm()
175     {
176         return;
177     }
178
179     function showProfileBlock()
180     {
181     }
182 }