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,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Affero General Public License for more details.
20 * You should have received a copy of the GNU Affero General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 * @author Evan Prodromou <evan@status.net>
26 * @author Zach Copley <zach@status.net>
27 * @author Sarven Capadisli <csarven@status.net>
28 * @copyright 2008-2010 StatusNet, Inc.
29 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
30 * @link http://status.net/
33 if (!defined('STATUSNET')) {
38 * Administer user settings
42 * @author Evan Prodromou <evan@status.net>
43 * @author Zach Copley <zach@status.net>
44 * @author Sarven Capadisli <csarven@status.net>
45 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
46 * @link http://status.net/
48 class UseradminpanelAction extends AdminPanelAction
51 * Returns the page title
53 * @return string page title
57 // TRANS: User admin panel title.
58 return _m('TITLE', 'User');
62 * Instructions for using this form.
64 * @return string instructions
66 function getInstructions()
68 // TRANS: Instruction for user admin panel.
69 return _('User settings for this StatusNet site');
73 * Show the site admin panel form
79 $form = new UserAdminPanelForm($this);
85 * Save settings from the form
89 function saveSettings()
91 static $settings = array(
92 'profile' => array('biolimit'),
93 'newuser' => array('welcome', 'default')
96 static $booleans = array(
97 'invite' => array('enabled')
102 foreach ($settings as $section => $parts) {
103 foreach ($parts as $setting) {
104 $values[$section][$setting] = $this->trimmed("$section-$setting");
108 foreach ($booleans as $section => $parts) {
109 foreach ($parts as $setting) {
110 $values[$section][$setting] = ($this->boolean("$section-$setting")) ? 1 : 0;
114 // This throws an exception on validation errors
116 $this->validate($values);
118 // assert(all values are valid);
120 $config = new Config();
122 $config->query('BEGIN');
124 foreach ($settings as $section => $parts) {
125 foreach ($parts as $setting) {
126 Config::save($section, $setting, $values[$section][$setting]);
130 foreach ($booleans as $section => $parts) {
131 foreach ($parts as $setting) {
132 Config::save($section, $setting, $values[$section][$setting]);
136 $config->query('COMMIT');
141 function validate(&$values)
145 if (!Validate::number($values['profile']['biolimit'])) {
146 // TRANS: Form validation error in user admin panel when a non-numeric character limit was set.
147 $this->clientError(_('Invalid bio limit. Must be numeric.'));
150 // Validate welcome text
152 if (mb_strlen($values['newuser']['welcome']) > 255) {
153 // TRANS: Form validation error in user admin panel when welcome text is too long.
154 $this->clientError(_('Invalid welcome text. Maximum length is 255 characters.'));
157 // Validate default subscription
159 if (!empty($values['newuser']['default'])) {
160 $defuser = User::staticGet('nickname', trim($values['newuser']['default']));
161 if (empty($defuser)) {
164 // TRANS: Client error displayed when trying to set a non-existing user as default subscription for new
165 // TRANS: users in user admin panel. %1$s is the invalid nickname.
166 _('Invalid default subscripton: "%1$s" is not a user.'),
167 $values['newuser']['default']
175 // @todo FIXME: Class documentation missing.
176 class UserAdminPanelForm extends AdminForm
181 * @return int ID of the form
185 return 'useradminpanel';
191 * @return string class of the form
195 return 'form_settings';
201 * @return string URL of the action
205 return common_local_url('useradminpanel');
209 * Data elements of the form
215 $this->out->elementStart('fieldset', array('id' => 'settings_user-profile'));
216 // TRANS: Fieldset legend in user administration panel.
217 $this->out->element('legend', null, _m('LEGEND','Profile'));
218 $this->out->elementStart('ul', 'form_data');
221 // TRANS: Field label in user admin panel for setting the character limit for the bio field.
222 $this->input('biolimit', _('Bio Limit'),
223 // TRANS: Tooltip in user admin panel for setting the character limit for the bio field.
224 _('Maximum length of a profile bio in characters.'),
228 $this->out->elementEnd('ul');
229 $this->out->elementEnd('fieldset');
231 $this->out->elementStart('fieldset', array('id' => 'settings_user-newusers'));
232 // TRANS: Form legend in user admin panel.
233 $this->out->element('legend', null, _('New users'));
234 $this->out->elementStart('ul', 'form_data');
237 // TRANS: Field label in user admin panel for setting new user welcome text.
238 $this->input('welcome', _('New user welcome'),
239 // TRANS: Tooltip in user admin panel for setting new user welcome text.
240 _('Welcome text for new users (maximum 255 characters).'),
245 // TRANS: Field label in user admin panel for setting default subscription for new users.
246 $this->input('default', _('Default subscription'),
247 // TRANS: Tooltip in user admin panel for setting default subscription for new users.
248 _('Automatically subscribe new users to this user.'),
252 $this->out->elementEnd('ul');
254 $this->out->elementEnd('fieldset');
256 $this->out->elementStart('fieldset', array('id' => 'settings_user-invitations'));
257 // TRANS: Form legend in user admin panel.
258 $this->out->element('legend', null, _('Invitations'));
259 $this->out->elementStart('ul', 'form_data');
263 // TRANS: Field label for checkbox in user admin panel for allowing users to invite friend using site e-mail.
264 $this->out->checkbox('invite-enabled', _('Invitations enabled'),
265 (bool) $this->value('enabled', 'invite'),
266 // TRANS: Tooltip for checkbox in user admin panel for allowing users to invite friend using site e-mail.
267 _('Whether to allow users to invite new users.'));
270 $this->out->elementEnd('ul');
271 $this->out->elementEnd('fieldset');
275 * Utility to simplify some of the duplicated code around
276 * params and settings. Overrided from base class to be
277 * more specific about input ids.
279 * @param string $setting Name of the setting
280 * @param string $title Title to use for the input
281 * @param string $instructions Instructions for this field
282 * @param string $section config section, default = 'site'
286 function input($setting, $title, $instructions, $section='site')
288 $this->out->input("$section-$setting", $title, $this->value($setting, $section), $instructions);
296 function formActions()
298 $this->out->submit('submit',
299 // TRANS: Button text to save user settings in user admin panel.
303 // TRANS: Button title to save user settings in user admin panel.
304 _('Save user settings.'));