3 * StatusNet, the distributed open-source microblogging tool
5 * User administration panel
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 * @author Zach Copley <zach@status.net>
26 * @author Sarven Capadisli <csarven@status.net>
27 * @copyright 2008-2009 StatusNet, Inc.
28 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
29 * @link http://status.net/
32 if (!defined('STATUSNET')) {
37 * Administer user settings
41 * @author Evan Prodromou <evan@status.net>
42 * @author Zach Copley <zach@status.net>
43 * @author Sarven Capadisli <csarven@status.net>
44 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45 * @link http://status.net/
48 class UseradminpanelAction extends AdminPanelAction
51 * Returns the page title
53 * @return string page title
62 * Instructions for using this form.
64 * @return string instructions
67 function getInstructions()
69 return _('User settings for this StatusNet site.');
73 * Show the site admin panel form
80 $form = new UserAdminPanelForm($this);
86 * Save settings from the form
91 function saveSettings()
93 static $settings = array(
94 'profile' => array('biolimit'),
95 'newuser' => array('welcome', 'default')
98 static $booleans = array(
99 'sessions' => array('handle', 'debug'),
100 'invite' => array('enabled')
105 foreach ($settings as $section => $parts) {
106 foreach ($parts as $setting) {
107 $values[$section][$setting] = $this->trimmed("$section-$setting");
111 foreach ($booleans as $section => $parts) {
112 foreach ($parts as $setting) {
113 $values[$section][$setting] = ($this->boolean("$section-$setting")) ? 1 : 0;
117 // This throws an exception on validation errors
119 $this->validate($values);
121 // assert(all values are valid);
123 $config = new Config();
125 $config->query('BEGIN');
127 foreach ($settings as $section => $parts) {
128 foreach ($parts as $setting) {
129 Config::save($section, $setting, $values[$section][$setting]);
133 foreach ($booleans as $section => $parts) {
134 foreach ($parts as $setting) {
135 Config::save($section, $setting, $values[$section][$setting]);
139 $config->query('COMMIT');
144 function validate(&$values)
148 if (!Validate::number($values['profile']['biolimit'])) {
149 $this->clientError(_("Invalid bio limit. Must be numeric."));
152 // Validate welcome text
154 if (mb_strlen($values['newuser']['welcome']) > 255) {
155 $this->clientError(_("Invalid welcome text. Max length is 255 characters."));
158 // Validate default subscription
160 if (!empty($values['newuser']['default'])) {
161 $defuser = User::staticGet('nickname', trim($values['newuser']['default']));
162 if (empty($defuser)) {
165 _('Invalid default subscripton: \'%1$s\' is not user.'),
166 $values['newuser']['default']
174 class UserAdminPanelForm extends AdminForm
179 * @return int ID of the form
184 return 'useradminpanel';
190 * @return string class of the form
195 return 'form_settings';
201 * @return string URL of the action
206 return common_local_url('useradminpanel');
210 * Data elements of the form
217 $this->out->elementStart('fieldset', array('id' => 'settings_user-profile'));
218 $this->out->element('legend', null, _('Profile'));
219 $this->out->elementStart('ul', 'form_data');
222 $this->input('biolimit', _('Bio Limit'),
223 _('Maximum length of a profile bio in characters.'),
227 $this->out->elementEnd('ul');
228 $this->out->elementEnd('fieldset');
230 $this->out->elementStart('fieldset', array('id' => 'settings_user-newusers'));
231 $this->out->element('legend', null, _('New users'));
232 $this->out->elementStart('ul', 'form_data');
235 $this->input('welcome', _('New user welcome'),
236 _('Welcome text for new users (Max 255 chars).'),
241 $this->input('default', _('Default subscription'),
242 _('Automatically subscribe new users to this user.'),
246 $this->out->elementEnd('ul');
248 $this->out->elementEnd('fieldset');
250 $this->out->elementStart('fieldset', array('id' => 'settings_user-invitations'));
251 $this->out->element('legend', null, _('Invitations'));
252 $this->out->elementStart('ul', 'form_data');
256 $this->out->checkbox('invite-enabled', _('Invitations enabled'),
257 (bool) $this->value('enabled', 'invite'),
258 _('Whether to allow users to invite new users.'));
261 $this->out->elementEnd('ul');
262 $this->out->elementEnd('fieldset');
264 $this->out->elementStart('fieldset', array('id' => 'settings_user_sessions'));
265 $this->out->element('legend', null, _('Sessions'));
267 $this->out->elementStart('ul');
270 $this->out->checkbox('sessions-handle', _('Handle sessions'),
271 (bool) $this->value('handle', 'sessions'),
272 _('Whether to handle sessions ourselves.'));
276 $this->out->checkbox('sessions-debug', _('Session debugging'),
277 (bool) $this->value('debug', 'sessions'),
278 _('Turn on debugging output for sessions.'));
281 $this->out->elementEnd('ul');
283 $this->out->elementEnd('fieldset');
288 * Utility to simplify some of the duplicated code around
289 * params and settings. Overrided from base class to be
290 * more specific about input ids.
292 * @param string $setting Name of the setting
293 * @param string $title Title to use for the input
294 * @param string $instructions Instructions for this field
295 * @param string $section config section, default = 'site'
300 function input($setting, $title, $instructions, $section='site')
302 $this->out->input("$section-$setting", $title, $this->value($setting, $section), $instructions);
311 function formActions()
313 $this->out->submit('submit', _('Save'), 'submit', null, _('Save site settings'));