]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/useradminpanel.php
Removed unused stub class
[quix0rs-gnu-social.git] / actions / useradminpanel.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * User administration panel
6  *
7  * PHP version 5
8  *
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.
13  *
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.
18  *
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/>.
21  *
22  * @category  Settings
23  * @package   StatusNet
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/
30  */
31
32 if (!defined('STATUSNET')) {
33     exit(1);
34 }
35
36 /**
37  * Administer user settings
38  *
39  * @category Admin
40  * @package  StatusNet
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/
46  */
47
48 class UseradminpanelAction extends AdminPanelAction
49 {
50     /**
51      * Returns the page title
52      *
53      * @return string page title
54      */
55
56     function title()
57     {
58         return _('User');
59     }
60
61     /**
62      * Instructions for using this form.
63      *
64      * @return string instructions
65      */
66
67     function getInstructions()
68     {
69         return _('User settings for this StatusNet site.');
70     }
71
72     /**
73      * Show the site admin panel form
74      *
75      * @return void
76      */
77
78     function showForm()
79     {
80         $form = new UserAdminPanelForm($this);
81         $form->show();
82         return;
83     }
84
85     /**
86      * Save settings from the form
87      *
88      * @return void
89      */
90
91     function saveSettings()
92     {
93         static $settings = array(
94                 'profile' => array('biolimit'),
95                 'newuser' => array('welcome', 'default')
96         );
97
98         static $booleans = array(
99             'invite' => array('enabled')
100         );
101
102         $values = array();
103
104         foreach ($settings as $section => $parts) {
105             foreach ($parts as $setting) {
106                 $values[$section][$setting] = $this->trimmed("$section-$setting");
107             }
108         }
109
110         foreach ($booleans as $section => $parts) {
111             foreach ($parts as $setting) {
112                 $values[$section][$setting] = ($this->boolean("$section-$setting")) ? 1 : 0;
113             }
114         }
115
116         // This throws an exception on validation errors
117
118         $this->validate($values);
119
120         // assert(all values are valid);
121
122         $config = new Config();
123
124         $config->query('BEGIN');
125
126         foreach ($settings as $section => $parts) {
127             foreach ($parts as $setting) {
128                 Config::save($section, $setting, $values[$section][$setting]);
129             }
130         }
131
132         foreach ($booleans as $section => $parts) {
133             foreach ($parts as $setting) {
134                 Config::save($section, $setting, $values[$section][$setting]);
135             }
136         }
137
138         $config->query('COMMIT');
139
140         return;
141     }
142
143     function validate(&$values)
144     {
145         // Validate biolimit
146
147         if (!Validate::number($values['profile']['biolimit'])) {
148             $this->clientError(_("Invalid bio limit. Must be numeric."));
149         }
150
151         // Validate welcome text
152
153         if (mb_strlen($values['newuser']['welcome']) > 255) {
154             $this->clientError(_("Invalid welcome text. Max length is 255 characters."));
155         }
156
157         // Validate default subscription
158
159         if (!empty($values['newuser']['default'])) {
160             $defuser = User::staticGet('nickname', trim($values['newuser']['default']));
161             if (empty($defuser)) {
162                 $this->clientError(
163                     sprintf(
164                         _('Invalid default subscripton: \'%1$s\' is not user.'),
165                         $values['newuser']['default']
166                     )
167                 );
168             }
169         }
170     }
171 }
172
173 class UserAdminPanelForm extends AdminForm
174 {
175     /**
176      * ID of the form
177      *
178      * @return int ID of the form
179      */
180
181     function id()
182     {
183         return 'useradminpanel';
184     }
185
186     /**
187      * class of the form
188      *
189      * @return string class of the form
190      */
191
192     function formClass()
193     {
194         return 'form_settings';
195     }
196
197     /**
198      * Action of the form
199      *
200      * @return string URL of the action
201      */
202
203     function action()
204     {
205         return common_local_url('useradminpanel');
206     }
207
208     /**
209      * Data elements of the form
210      *
211      * @return void
212      */
213
214     function formData()
215     {
216         $this->out->elementStart('fieldset', array('id' => 'settings_user-profile'));
217         $this->out->element('legend', null, _('Profile'));
218         $this->out->elementStart('ul', 'form_data');
219
220         $this->li();
221         $this->input('biolimit', _('Bio Limit'),
222                      _('Maximum length of a profile bio in characters.'),
223                      'profile');
224         $this->unli();
225
226         $this->out->elementEnd('ul');
227         $this->out->elementEnd('fieldset');
228
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');
232
233         $this->li();
234         $this->input('welcome', _('New user welcome'),
235                      _('Welcome text for new users (Max 255 chars).'),
236                      'newuser');
237         $this->unli();
238
239         $this->li();
240         $this->input('default', _('Default subscription'),
241                      _('Automatically subscribe new users to this user.'),
242                      'newuser');
243         $this->unli();
244
245         $this->out->elementEnd('ul');
246
247         $this->out->elementEnd('fieldset');
248
249         $this->out->elementStart('fieldset', array('id' => 'settings_user-invitations'));
250         $this->out->element('legend', null, _('Invitations'));
251         $this->out->elementStart('ul', 'form_data');
252
253         $this->li();
254
255         $this->out->checkbox('invite-enabled', _('Invitations enabled'),
256                               (bool) $this->value('enabled', 'invite'),
257                               _('Whether to allow users to invite new users.'));
258         $this->unli();
259
260         $this->out->elementEnd('ul');
261         $this->out->elementEnd('fieldset');
262
263
264
265     }
266
267     /**
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.
271      *
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'
276      *
277      * @return void
278      */
279
280     function input($setting, $title, $instructions, $section='site')
281     {
282         $this->out->input("$section-$setting", $title, $this->value($setting, $section), $instructions);
283     }
284
285     /**
286      * Action elements
287      *
288      * @return void
289      */
290
291     function formActions()
292     {
293         $this->out->submit('submit', _('Save'), 'submit', null, _('Save site settings'));
294     }
295 }