]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/siteadminpanel.php
Merge branch 'master' into 1.0.x
[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             !Validate::uri($values['site']['logo'], array('allowed_schemes' => array('http', 'https')))) {
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             !Validate::uri($values['site']['ssllogo'], array('allowed_schemes' => array('https')))) {
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             return;
177         }
178
179         // Validate language
180
181         if (!is_null($values['site']['language']) &&
182             !in_array($values['site']['language'], array_keys(get_nice_language_list()))) {
183             // TRANS: Client error displayed trying to save site settings with an invalid language code.
184             // TRANS: %s is the invalid language code.
185             $this->clientError(sprintf(_('Unknown language "%s".'), $values['site']['language']));
186         }
187
188         // Validate text limit
189
190         if (!Validate::number($values['site']['textlimit'], array('min' => 0))) {
191             // TRANS: Client error displayed trying to save site settings with a text limit below 0.
192             $this->clientError(_('Minimum text limit is 0 (unlimited).'));
193         }
194
195         // Validate dupe limit
196
197         if (!Validate::number($values['site']['dupelimit'], array('min' => 1))) {
198             // TRANS: Client error displayed trying to save site settings with a text limit below 1.
199             $this->clientError(_('Dupe limit must be one or more seconds.'));
200         }
201     }
202 }
203
204 // @todo FIXME: Class documentation missing.
205 class SiteAdminPanelForm extends AdminForm
206 {
207     /**
208      * ID of the form
209      *
210      * @return int ID of the form
211      */
212     function id()
213     {
214         return 'form_site_admin_panel';
215     }
216
217     /**
218      * class of the form
219      *
220      * @return string class of the form
221      */
222     function formClass()
223     {
224         return 'form_settings';
225     }
226
227     /**
228      * Action of the form
229      *
230      * @return string URL of the action
231      */
232     function action()
233     {
234         return common_local_url('siteadminpanel');
235     }
236
237     /**
238      * Data elements of the form
239      *
240      * @return void
241      */
242     function formData()
243     {
244         $this->out->elementStart('fieldset', array('id' => 'settings_admin_general'));
245         // TRANS: Fieldset legend on site settings panel.
246         $this->out->element('legend', null, _m('LEGEND','General'));
247         $this->out->elementStart('ul', 'form_data');
248         $this->li();
249         // TRANS: Field label on site settings panel.
250         $this->input('name', _m('LABEL','Site name'),
251                      // TRANS: Field title on site settings panel.
252                      _('The name of your site, like "Yourcompany Microblog".'));
253         $this->unli();
254
255         $this->li();
256         // TRANS: Field label on site settings panel.
257         $this->input('broughtby', _('Brought by'),
258                      // TRANS: Field title on site settings panel.
259                      _('Text used for credits link in footer of each page.'));
260         $this->unli();
261
262         $this->li();
263         // TRANS: Field label on site settings panel.
264         $this->input('broughtbyurl', _('Brought by URL'),
265                      // TRANS: Field title on site settings panel.
266                      _('URL used for credits link in footer of each page.'));
267         $this->unli();
268         $this->li();
269         // TRANS: Field label on site settings panel.
270         $this->input('email', _('Email'),
271                      // TRANS: Field title on site settings panel.
272                      _('Contact email address for your site.'));
273         $this->unli();
274         $this->out->elementEnd('ul');
275         $this->out->elementEnd('fieldset');
276
277         $this->showLogo();
278
279         $this->out->elementStart('fieldset', array('id' => 'settings_admin_local'));
280         // TRANS: Fieldset legend on site settings panel.
281         $this->out->element('legend', null, _m('LEGEND','Local'));
282         $this->out->elementStart('ul', 'form_data');
283         $timezones = array();
284
285         foreach (DateTimeZone::listIdentifiers() as $k => $v) {
286             $timezones[$v] = $v;
287         }
288
289         asort($timezones);
290
291         $this->li();
292         // TRANS: Dropdown label on site settings panel.
293         $this->out->dropdown('timezone', _('Default timezone'),
294                              // TRANS: Dropdown title on site settings panel.
295                              $timezones, _('Default timezone for the site; usually UTC.'),
296                              true, $this->value('timezone'));
297         $this->unli();
298
299         $this->li();
300         $this->out->dropdown('language',
301                              // TRANS: Dropdown label on site settings panel.
302                              _('Default language'),
303                              get_nice_language_list(),
304                              // TRANS: Dropdown title on site settings panel.
305                              _('The site language when autodetection from browser settings is not available.'),
306                              false, $this->value('language'));
307         $this->unli();
308
309         $this->out->elementEnd('ul');
310         $this->out->elementEnd('fieldset');
311
312         $this->out->elementStart('fieldset', array('id' => 'settings_admin_limits'));
313         // TRANS: Fieldset legend on site settings panel.
314         $this->out->element('legend', null, _m('LEGEND','Limits'));
315         $this->out->elementStart('ul', 'form_data');
316         $this->li();
317         $this->input('textlimit',
318                      // TRANS: Field label on site settings panel.
319                      _('Text limit'),
320                      // TRANS: Field title on site settings panel.
321                      _('Maximum number of characters for notices.'));
322         $this->unli();
323
324         $this->li();
325         $this->input('dupelimit',
326                      // TRANS: Field label on site settings panel.
327                      _('Dupe limit'),
328                      // TRANS: Field title on site settings panel.
329                      _('How long users must wait (in seconds) to post the same thing again.'));
330         $this->unli();
331         $this->out->elementEnd('ul');
332         $this->out->elementEnd('fieldset');
333     }
334
335     function showLogo()
336     {
337         $this->out->elementStart('fieldset', array('id' => 'settings_site_logo'));
338         // TRANS: Fieldset legend for form to change logo.
339         $this->out->element('legend', null, _('Logo'));
340
341         $this->out->elementStart('ul', 'form_data');
342
343         $this->li();
344         $this->input('logo',
345                      // TRANS: Field label for StatusNet site logo.
346                      _('Site logo'),
347                      // TRANS: Title for field label for StatusNet site logo.
348                      'Logo for the site (full URL).');
349         $this->unli();
350
351         $this->li();
352         $this->input('ssllogo',
353                      // TRANS: Field label for SSL StatusNet site logo.
354                      _('SSL logo'),
355                      // TRANS: Title for field label for SSL StatusNet site logo.
356                      'Logo to show on SSL pages (full URL).');
357         $this->unli();
358
359         $this->out->elementEnd('ul');
360
361         $this->out->elementEnd('fieldset');
362     }
363
364     /**
365      * Action elements
366      *
367      * @return void
368      */
369     function formActions()
370     {
371         $this->out->submit('submit',
372                            // TRANS: Button text for saving site settings.
373                            _m('BUTTON','Save'),
374                            'submit',
375                            null,
376                            // TRANS: Button title for saving site settings.
377                            _('Save the site settings.'));
378     }
379 }