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
58 return _m('User admin panel title', 'User');
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 'invite' => array('enabled')
104 foreach ($settings as $section => $parts) {
105 foreach ($parts as $setting) {
106 $values[$section][$setting] = $this->trimmed("$section-$setting");
110 foreach ($booleans as $section => $parts) {
111 foreach ($parts as $setting) {
112 $values[$section][$setting] = ($this->boolean("$section-$setting")) ? 1 : 0;
116 // This throws an exception on validation errors
118 $this->validate($values);
120 // assert(all values are valid);
122 $config = new Config();
124 $config->query('BEGIN');
126 foreach ($settings as $section => $parts) {
127 foreach ($parts as $setting) {
128 Config::save($section, $setting, $values[$section][$setting]);
132 foreach ($booleans as $section => $parts) {
133 foreach ($parts as $setting) {
134 Config::save($section, $setting, $values[$section][$setting]);
138 $config->query('COMMIT');
143 function validate(&$values)
147 if (!Validate::number($values['profile']['biolimit'])) {
148 $this->clientError(_("Invalid bio limit. Must be numeric."));
151 // Validate welcome text
153 if (mb_strlen($values['newuser']['welcome']) > 255) {
154 $this->clientError(_("Invalid welcome text. Max 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 _('Invalid default subscripton: \'%1$s\' is not user.'),
165 $values['newuser']['default']
173 class UserAdminPanelForm extends AdminForm
178 * @return int ID of the form
183 return 'useradminpanel';
189 * @return string class of the form
194 return 'form_settings';
200 * @return string URL of the action
205 return common_local_url('useradminpanel');
209 * Data elements of the form
216 $this->out->elementStart('fieldset', array('id' => 'settings_user-profile'));
217 $this->out->element('legend', null, _('Profile'));
218 $this->out->elementStart('ul', 'form_data');
221 $this->input('biolimit', _('Bio Limit'),
222 _('Maximum length of a profile bio in characters.'),
226 $this->out->elementEnd('ul');
227 $this->out->elementEnd('fieldset');
229 $this->out->elementStart('fieldset', array('id' => 'settings_user-newusers'));
230 $this->out->element('legend', null, _('New users'));
231 $this->out->elementStart('ul', 'form_data');
234 $this->input('welcome', _('New user welcome'),
235 _('Welcome text for new users (Max 255 chars).'),
240 $this->input('default', _('Default subscription'),
241 _('Automatically subscribe new users to this user.'),
245 $this->out->elementEnd('ul');
247 $this->out->elementEnd('fieldset');
249 $this->out->elementStart('fieldset', array('id' => 'settings_user-invitations'));
250 $this->out->element('legend', null, _('Invitations'));
251 $this->out->elementStart('ul', 'form_data');
255 $this->out->checkbox('invite-enabled', _('Invitations enabled'),
256 (bool) $this->value('enabled', 'invite'),
257 _('Whether to allow users to invite new users.'));
260 $this->out->elementEnd('ul');
261 $this->out->elementEnd('fieldset');
268 * Utility to simplify some of the duplicated code around
269 * params and settings. Overrided from base class to be
270 * more specific about input ids.
272 * @param string $setting Name of the setting
273 * @param string $title Title to use for the input
274 * @param string $instructions Instructions for this field
275 * @param string $section config section, default = 'site'
280 function input($setting, $title, $instructions, $section='site')
282 $this->out->input("$section-$setting", $title, $this->value($setting, $section), $instructions);
291 function formActions()
293 $this->out->submit('submit', _('Save'), 'submit', null, _('Save site settings'));