]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/siteadminpanel.php
Cosmetic changes to common_redirect, clientError, serverError
[quix0rs-gnu-social.git] / actions / siteadminpanel.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Site 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-2011 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 site 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 class SiteadminpanelAction extends AdminPanelAction
48 {
49     /**
50      * Returns the page title
51      *
52      * @return string page title
53      */
54     function title()
55     {
56         // TRANS: Title for site administration panel.
57         return _m('TITLE','Site');
58     }
59
60     /**
61      * Instructions for using this form.
62      *
63      * @return string instructions
64      */
65     function getInstructions()
66     {
67         // TRANS: Instructions for site administration panel.
68         return _('Basic settings for this StatusNet site');
69     }
70
71     /**
72      * Show the site admin panel form
73      *
74      * @return void
75      */
76     function showForm()
77     {
78         $form = new SiteAdminPanelForm($this);
79         $form->show();
80         return;
81     }
82
83     /**
84      * Save settings from the form
85      *
86      * @return void
87      */
88     function saveSettings()
89     {
90         static $settings = array(
91             'site' => array(
92                 'name',
93                 'broughtby',
94                 'broughtbyurl',
95                 'email',
96                 'timezone',
97                 'language',
98                 'site',
99                 'textlimit',
100                 'dupelimit',
101                 'logo',
102                 'ssllogo'
103             )
104         );
105
106         $values = array();
107
108         foreach ($settings as $section => $parts) {
109             foreach ($parts as $setting) {
110                 $values[$section][$setting] = $this->trimmed($setting);
111             }
112         }
113
114         // This throws an exception on validation errors
115
116         $this->validate($values);
117
118         // assert(all values are valid);
119
120         $config = new Config();
121
122         $config->query('BEGIN');
123
124         foreach ($settings as $section => $parts) {
125             foreach ($parts as $setting) {
126                 Config::save($section, $setting, $values[$section][$setting]);
127             }
128         }
129
130         $config->query('COMMIT');
131
132         return;
133     }
134
135     function validate(&$values)
136     {
137         // Validate site name
138
139         if (empty($values['site']['name'])) {
140             // TRANS: Client error displayed trying to save an empty site name.
141             $this->clientError(_('Site name must have non-zero length.'));
142         }
143
144         // Validate email
145
146         $values['site']['email'] = common_canonical_email($values['site']['email']);
147
148         if (empty($values['site']['email'])) {
149             // TRANS: Client error displayed trying to save site settings without a contact address.
150             $this->clientError(_('You must have a valid contact email address.'));
151         }
152         if (!Validate::email($values['site']['email'], common_config('email', 'check_domain'))) {
153             // TRANS: Client error displayed trying to save site settings without a valid contact address.
154             $this->clientError(_('Not a valid email address.'));
155         }
156
157         // Validate logos
158         if (!empty($values['site']['logo']) &&
159                 !common_valid_http_url($values['site']['logo'])) {
160             // TRANS: Client error displayed when a logo URL is not valid.
161             $this->clientError(_('Invalid logo URL.'));
162         }
163
164         if (!empty($values['site']['ssllogo']) &&
165                 !common_valid_http_url($values['site']['ssllogo'], true)) {
166             // TRANS: Client error displayed when a SSL logo URL is invalid.
167             $this->clientError(_('Invalid SSL logo URL.'));
168         }
169
170         // Validate timezone
171
172         if (is_null($values['site']['timezone']) ||
173             !in_array($values['site']['timezone'], DateTimeZone::listIdentifiers())) {
174             // TRANS: Client error displayed trying to save site settings without a timezone.
175             $this->clientError(_('Timezone not selected.'));
176         }
177
178         // Validate language
179
180         if (!is_null($values['site']['language']) &&
181             !in_array($values['site']['language'], array_keys(get_nice_language_list()))) {
182             // TRANS: Client error displayed trying to save site settings with an invalid language code.
183             // TRANS: %s is the invalid language code.
184             $this->clientError(sprintf(_('Unknown language "%s".'), $values['site']['language']));
185         }
186
187         // Validate text limit
188
189         if (!Validate::number($values['site']['textlimit'], array('min' => 0))) {
190             // TRANS: Client error displayed trying to save site settings with a text limit below 0.
191             $this->clientError(_('Minimum text limit is 0 (unlimited).'));
192         }
193
194         // Validate dupe limit
195
196         if (!Validate::number($values['site']['dupelimit'], array('min' => 1))) {
197             // TRANS: Client error displayed trying to save site settings with a text limit below 1.
198             $this->clientError(_('Dupe limit must be one or more seconds.'));
199         }
200     }
201 }
202
203 // @todo FIXME: Class documentation missing.
204 class SiteAdminPanelForm extends AdminForm
205 {
206     /**
207      * ID of the form
208      *
209      * @return int ID of the form
210      */
211     function id()
212     {
213         return 'form_site_admin_panel';
214     }
215
216     /**
217      * class of the form
218      *
219      * @return string class of the form
220      */
221     function formClass()
222     {
223         return 'form_settings';
224     }
225
226     /**
227      * Action of the form
228      *
229      * @return string URL of the action
230      */
231     function action()
232     {
233         return common_local_url('siteadminpanel');
234     }
235
236     /**
237      * Data elements of the form
238      *
239      * @return void
240      */
241     function formData()
242     {
243         $this->out->elementStart('fieldset', array('id' => 'settings_admin_general'));
244         // TRANS: Fieldset legend on site settings panel.
245         $this->out->element('legend', null, _m('LEGEND','General'));
246         $this->out->elementStart('ul', 'form_data');
247         $this->li();
248         // TRANS: Field label on site settings panel.
249         $this->input('name', _m('LABEL','Site name'),
250                      // TRANS: Field title on site settings panel.
251                      _('The name of your site, like "Yourcompany Microblog".'));
252         $this->unli();
253
254         $this->li();
255         // TRANS: Field label on site settings panel.
256         $this->input('broughtby', _('Brought by'),
257                      // TRANS: Field title on site settings panel.
258                      _('Text used for credits link in footer of each page.'));
259         $this->unli();
260
261         $this->li();
262         // TRANS: Field label on site settings panel.
263         $this->input('broughtbyurl', _('Brought by URL'),
264                      // TRANS: Field title on site settings panel.
265                      _('URL used for credits link in footer of each page.'));
266         $this->unli();
267         $this->li();
268         // TRANS: Field label on site settings panel.
269         $this->input('email', _('Email'),
270                      // TRANS: Field title on site settings panel.
271                      _('Contact email address for your site.'));
272         $this->unli();
273         $this->out->elementEnd('ul');
274         $this->out->elementEnd('fieldset');
275
276         $this->showLogo();
277
278         $this->out->elementStart('fieldset', array('id' => 'settings_admin_local'));
279         // TRANS: Fieldset legend on site settings panel.
280         $this->out->element('legend', null, _m('LEGEND','Local'));
281         $this->out->elementStart('ul', 'form_data');
282         $timezones = array();
283
284         foreach (DateTimeZone::listIdentifiers() as $k => $v) {
285             $timezones[$v] = $v;
286         }
287
288         asort($timezones);
289
290         $this->li();
291         // TRANS: Dropdown label on site settings panel.
292         $this->out->dropdown('timezone', _('Default timezone'),
293                              // TRANS: Dropdown title on site settings panel.
294                              $timezones, _('Default timezone for the site; usually UTC.'),
295                              true, $this->value('timezone'));
296         $this->unli();
297
298         $this->li();
299         $this->out->dropdown('language',
300                              // TRANS: Dropdown label on site settings panel.
301                              _('Default language'),
302                              get_nice_language_list(),
303                              // TRANS: Dropdown title on site settings panel.
304                              _('The site language when autodetection from browser settings is not available.'),
305                              false, $this->value('language'));
306         $this->unli();
307
308         $this->out->elementEnd('ul');
309         $this->out->elementEnd('fieldset');
310
311         $this->out->elementStart('fieldset', array('id' => 'settings_admin_limits'));
312         // TRANS: Fieldset legend on site settings panel.
313         $this->out->element('legend', null, _m('LEGEND','Limits'));
314         $this->out->elementStart('ul', 'form_data');
315         $this->li();
316         $this->input('textlimit',
317                      // TRANS: Field label on site settings panel.
318                      _('Text limit'),
319                      // TRANS: Field title on site settings panel.
320                      _('Maximum number of characters for notices.'));
321         $this->unli();
322
323         $this->li();
324         $this->input('dupelimit',
325                      // TRANS: Field label on site settings panel.
326                      _('Dupe limit'),
327                      // TRANS: Field title on site settings panel.
328                      _('How long users must wait (in seconds) to post the same thing again.'));
329         $this->unli();
330         $this->out->elementEnd('ul');
331         $this->out->elementEnd('fieldset');
332     }
333
334     function showLogo()
335     {
336         $this->out->elementStart('fieldset', array('id' => 'settings_site_logo'));
337         // TRANS: Fieldset legend for form to change logo.
338         $this->out->element('legend', null, _('Logo'));
339
340         $this->out->elementStart('ul', 'form_data');
341
342         $this->li();
343         $this->input('logo',
344                      // TRANS: Field label for StatusNet site logo.
345                      _('Site logo'),
346                      // TRANS: Title for field label for StatusNet site logo.
347                      'Logo for the site (full URL).');
348         $this->unli();
349
350         $this->li();
351         $this->input('ssllogo',
352                      // TRANS: Field label for SSL StatusNet site logo.
353                      _('SSL logo'),
354                      // TRANS: Title for field label for SSL StatusNet site logo.
355                      'Logo to show on SSL pages (full URL).');
356         $this->unli();
357
358         $this->out->elementEnd('ul');
359
360         $this->out->elementEnd('fieldset');
361     }
362
363     /**
364      * Action elements
365      *
366      * @return void
367      */
368     function formActions()
369     {
370         $this->out->submit('submit',
371                            // TRANS: Button text for saving site settings.
372                            _m('BUTTON','Save'),
373                            'submit',
374                            null,
375                            // TRANS: Button title for saving site settings.
376                            _('Save the site settings.'));
377     }
378 }