3 * StatusNet, the distributed open-source microblogging tool
5 * Superclass for admin panel actions
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.
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.
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/>.
24 * @author Evan Prodromou <evan@status.net>
25 * @copyright 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/
30 if (!defined('STATUSNET')) {
35 * superclass for admin panel actions
37 * Common code for all admin panel actions.
41 * @author Evan Prodromou <evan@status.net>
42 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
43 * @link http://status.net/
45 * @todo Find some commonalities with SettingsAction and combine
48 class AdminPanelAction extends Action
54 * Prepare for the action
56 * We check to see that the user is logged in, has
57 * authenticated in this session, and has the right
58 * to configure the site.
60 * @param array $args Array of arguments from Web driver
62 * @return boolean success flag
65 function prepare($args)
67 parent::prepare($args);
69 // User must be logged in.
71 if (!common_logged_in()) {
72 $this->clientError(_('Not logged in.'));
76 $user = common_current_user();
78 // It must be a "real" login, not saved cookie login
80 if (!common_is_real_login()) {
81 // Cookie theft is too easy; we require automatic
82 // logins to re-authenticate before admining the site
83 common_set_returnto($this->selfUrl());
84 if (Event::handle('RedirectToLogin', array($this, $user))) {
85 common_redirect(common_local_url('login'), 303);
89 // User must have the right to change admin settings
91 $user = common_current_user();
93 if (!$user->hasRight(Right::CONFIGURESITE)) {
94 $this->clientError(_('You cannot make changes to this site.'));
104 * Check session token and try to save the settings if this is a
105 * POST. Otherwise, show the form.
107 * @param array $args unused.
112 function handle($args)
114 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
115 $this->checkSessionToken();
117 $this->saveSettings();
119 $this->success = true;
120 $this->msg = _('Settings saved.');
121 } catch (Exception $e) {
122 $this->success = false;
123 $this->msg = $e->getMessage();
130 * Show the content section of the page
132 * Here, we show the admin panel's form.
137 function showContent()
143 * show human-readable instructions for the page, or
144 * a success/failure on save.
149 function showPageNotice()
152 $this->element('div', ($this->success) ? 'success' : 'error',
155 $inst = $this->getInstructions();
156 $output = common_markup_to_html($inst);
158 $this->elementStart('div', 'instructions');
160 $this->elementEnd('div');
165 * Show the admin panel form
167 * Sub-classes should overload this.
174 $this->clientError(_('showForm() not implemented.'));
179 * Instructions for using this form.
181 * String with instructions for using the form.
183 * Subclasses should overload this.
188 function getInstructions()
194 * Save settings from the form
196 * Validate and save the settings from the user.
201 function saveSettings()
203 $this->clientError(_('saveSettings() not implemented.'));