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 // ...because they're logged in
80 assert(!empty($user));
82 // It must be a "real" login, not saved cookie login
84 if (!common_is_real_login()) {
85 // Cookie theft is too easy; we require automatic
86 // logins to re-authenticate before admining the site
87 common_set_returnto($this->selfUrl());
88 if (Event::handle('RedirectToLogin', array($this, $user))) {
89 common_redirect(common_local_url('login'), 303);
93 // User must have the right to change admin settings
95 if (!$user->hasRight(Right::CONFIGURESITE)) {
96 $this->clientError(_('You cannot make changes to this site.'));
106 * Check session token and try to save the settings if this is a
107 * POST. Otherwise, show the form.
109 * @param array $args unused.
114 function handle($args)
116 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
117 $this->checkSessionToken();
119 $this->saveSettings();
123 Config::loadSettings();
125 $this->success = true;
126 $this->msg = _('Settings saved.');
127 } catch (Exception $e) {
128 $this->success = false;
129 $this->msg = $e->getMessage();
136 * Show tabset for this page
138 * Uses the AdminPanelNav widget
144 function showLocalNav()
146 $nav = new AdminPanelNav($this);
151 * Show the content section of the page
153 * Here, we show the admin panel's form.
158 function showContent()
164 * show human-readable instructions for the page, or
165 * a success/failure on save.
170 function showPageNotice()
173 $this->element('div', ($this->success) ? 'success' : 'error',
176 $inst = $this->getInstructions();
177 $output = common_markup_to_html($inst);
179 $this->elementStart('div', 'instructions');
181 $this->elementEnd('div');
186 * Show the admin panel form
188 * Sub-classes should overload this.
195 $this->clientError(_('showForm() not implemented.'));
200 * Instructions for using this form.
202 * String with instructions for using the form.
204 * Subclasses should overload this.
209 function getInstructions()
215 * Save settings from the form
217 * Validate and save the settings from the user.
222 function saveSettings()
224 $this->clientError(_('saveSettings() not implemented.'));
229 * Delete a design setting
231 * // XXX: Maybe this should go in Design? --Z
233 * @return mixed $result false if something didn't work
236 function deleteSetting($section, $setting)
238 $config = new Config();
240 $config->section = $section;
241 $config->setting = $setting;
243 if ($config->find(true)) {
244 $result = $config->delete();
246 common_log_db_error($config, 'DELETE', __FILE__);
247 $this->clientError(_("Unable to delete design setting."));
257 * Menu for public group of actions
261 * @author Evan Prodromou <evan@status.net>
262 * @author Sarven Capadisli <csarven@status.net>
263 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
264 * @link http://status.net/
269 class AdminPanelNav extends Widget
276 * @param Action $action current action, used for output
279 function __construct($action=null)
281 parent::__construct($action);
282 $this->action = $action;
293 $action_name = $this->action->trimmed('action');
295 $this->action->elementStart('ul', array('class' => 'nav'));
297 if (Event::handle('StartAdminPanelNav', array($this))) {
299 $this->out->menuItem(common_local_url('siteadminpanel'), _('Site'),
300 _('Basic site configuration'), $action_name == 'siteadminpanel', 'nav_site_admin_panel');
302 $this->out->menuItem(common_local_url('designadminpanel'), _('Design'),
303 _('Design configuration'), $action_name == 'designadminpanel', 'nav_design_admin_panel');
305 $this->out->menuItem(common_local_url('useradminpanel'), _('User'),
306 _('Paths configuration'), $action_name == 'useradminpanel', 'nav_design_admin_panel');
308 $this->out->menuItem(common_local_url('pathsadminpanel'), _('Paths'),
309 _('Paths configuration'), $action_name == 'pathsadminpanel', 'nav_design_admin_panel');
311 Event::handle('EndAdminPanelNav', array($this));
313 $this->action->elementEnd('ul');