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/
49 class UseradminpanelAction extends AdminPanelAction
52 * Returns the page title
54 * @return string page title
59 // TRANS: User admin panel title
60 return _m('TITLE', 'User');
64 * Instructions for using this form.
66 * @return string instructions
69 function getInstructions()
71 return _('User settings for this StatusNet site');
75 * Show the site admin panel form
82 $form = new UserAdminPanelForm($this);
88 * Save settings from the form
93 function saveSettings()
95 static $settings = array(
96 'profile' => array('biolimit'),
97 'newuser' => array('welcome', 'default')
100 static $booleans = array(
101 'invite' => array('enabled')
106 foreach ($settings as $section => $parts) {
107 foreach ($parts as $setting) {
108 $values[$section][$setting] = $this->trimmed("$section-$setting");
112 foreach ($booleans as $section => $parts) {
113 foreach ($parts as $setting) {
114 $values[$section][$setting] = ($this->boolean("$section-$setting")) ? 1 : 0;
118 // This throws an exception on validation errors
120 $this->validate($values);
122 // assert(all values are valid);
124 $config = new Config();
126 $config->query('BEGIN');
128 foreach ($settings as $section => $parts) {
129 foreach ($parts as $setting) {
130 Config::save($section, $setting, $values[$section][$setting]);
134 foreach ($booleans as $section => $parts) {
135 foreach ($parts as $setting) {
136 Config::save($section, $setting, $values[$section][$setting]);
140 $config->query('COMMIT');
145 function validate(&$values)
149 if (!Validate::number($values['profile']['biolimit'])) {
150 $this->clientError(_("Invalid bio limit. Must be numeric."));
153 // Validate welcome text
155 if (mb_strlen($values['newuser']['welcome']) > 255) {
156 $this->clientError(_("Invalid welcome text. Max length is 255 characters."));
159 // Validate default subscription
161 if (!empty($values['newuser']['default'])) {
162 $defuser = User::staticGet('nickname', trim($values['newuser']['default']));
163 if (empty($defuser)) {
166 _('Invalid default subscripton: \'%1$s\' is not user.'),
167 $values['newuser']['default']
175 class UserAdminPanelForm extends AdminForm
180 * @return int ID of the form
185 return 'useradminpanel';
191 * @return string class of the form
196 return 'form_settings';
202 * @return string URL of the action
207 return common_local_url('useradminpanel');
211 * Data elements of the form
218 $this->out->elementStart('fieldset', array('id' => 'settings_user-profile'));
219 $this->out->element('legend', null, _('Profile'));
220 $this->out->elementStart('ul', 'form_data');
223 $this->input('biolimit', _('Bio Limit'),
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 $this->out->element('legend', null, _('New users'));
233 $this->out->elementStart('ul', 'form_data');
236 $this->input('welcome', _('New user welcome'),
237 _('Welcome text for new users (Max 255 chars).'),
242 $this->input('default', _('Default subscription'),
243 _('Automatically subscribe new users to this user.'),
247 $this->out->elementEnd('ul');
249 $this->out->elementEnd('fieldset');
251 $this->out->elementStart('fieldset', array('id' => 'settings_user-invitations'));
252 $this->out->element('legend', null, _('Invitations'));
253 $this->out->elementStart('ul', 'form_data');
257 $this->out->checkbox('invite-enabled', _('Invitations enabled'),
258 (bool) $this->value('enabled', 'invite'),
259 _('Whether to allow users to invite new users.'));
262 $this->out->elementEnd('ul');
263 $this->out->elementEnd('fieldset');
270 * Utility to simplify some of the duplicated code around
271 * params and settings. Overrided from base class to be
272 * more specific about input ids.
274 * @param string $setting Name of the setting
275 * @param string $title Title to use for the input
276 * @param string $instructions Instructions for this field
277 * @param string $section config section, default = 'site'
282 function input($setting, $title, $instructions, $section='site')
284 $this->out->input("$section-$setting", $title, $this->value($setting, $section), $instructions);
293 function formActions()
295 $this->out->submit('submit', _('Save'), 'submit', null, _('Save user settings'));