]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/pathsadminpanel.php
0b4a5ff952615876320b6abcf7169fc7660695a3
[quix0rs-gnu-social.git] / actions / pathsadminpanel.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Paths 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-2010 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  * Paths 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 PathsadminpanelAction extends AdminPanelAction
48 {
49     /**
50      * Returns the page title
51      *
52      * @return string page title
53      */
54
55     function title()
56     {
57         // TRANS: Title for Paths admin panel.
58         return _('Paths');
59     }
60
61     /**
62      * Instructions for using this form.
63      *
64      * @return string instructions
65      */
66     function getInstructions()
67     {
68         // TRANS: Form instructions for Path admin panel.
69         return _('Path and server settings for this StatusNet site');
70     }
71
72     /**
73      * Show the paths admin panel form
74      *
75      * @return void
76      */
77     function showForm()
78     {
79         $form = new PathsAdminPanelForm($this);
80         $form->show();
81         return;
82     }
83
84     /**
85      * Save settings from the form
86      *
87      * @return void
88      */
89     function saveSettings()
90     {
91         static $settings = array(
92                                  'site' => array('path', 'locale_path', 'ssl', 'sslserver'),
93                                  'theme' => array('server', 'dir', 'path', 'sslserver', 'sslpath'),
94                                  'avatar' => array('server', 'dir', 'path'),
95                                  'background' => array('server', 'dir', 'path', 'sslserver', 'sslpath'),
96                                  'attachments' => array('server', 'dir', 'path', 'sslserver', 'sslpath')
97                                  );
98
99         // XXX: If we're only going to have one boolean on thi page we
100         // can remove some of the boolean processing code --Z
101
102         static $booleans = array('site' => array('fancy'));
103
104         $values = array();
105
106         foreach ($settings as $section => $parts) {
107             foreach ($parts as $setting) {
108                 $values[$section][$setting] = $this->trimmed("$section-$setting");
109             }
110         }
111
112         foreach ($booleans as $section => $parts) {
113             foreach ($parts as $setting) {
114                 $values[$section][$setting] = ($this->boolean($setting)) ? 1 : 0;
115             }
116         }
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     /**
144      * Attempt to validate setting values
145      *
146      * @return void
147      */
148     function validate(&$values)
149     {
150         // Validate theme dir
151
152         if (!empty($values['theme']['dir']) && !is_readable($values['theme']['dir'])) {
153             // TRANS: Client error in Paths admin panel.
154             // TRANS: %s is the directory that could not be read from.
155             $this->clientError(sprintf(_('Theme directory not readable: %s.'), $values['theme']['dir']));
156         }
157
158         // Validate avatar dir
159
160         if (empty($values['avatar']['dir']) || !is_writable($values['avatar']['dir'])) {
161             // TRANS: Client error in Paths admin panel.
162             // TRANS: %s is the avatar directory that could not be written to.
163             $this->clientError(sprintf(_('Avatar directory not writable: %s.'), $values['avatar']['dir']));
164         }
165
166         // Validate background dir
167
168         if (empty($values['background']['dir']) || !is_writable($values['background']['dir'])) {
169             // TRANS: Client error in Paths admin panel.
170             // TRANS: %s is the background directory that could not be written to.
171             $this->clientError(sprintf(_('Background directory not writable: %s.'), $values['background']['dir']));
172         }
173
174         // Validate locales dir
175
176         // XXX: What else do we need to validate for lacales path here? --Z
177
178         if (!empty($values['site']['locale_path']) && !is_readable($values['site']['locale_path'])) {
179             // TRANS: Client error in Paths admin panel.
180             // TRANS: %s is the locales directory that could not be read from.
181             $this->clientError(sprintf(_('Locales directory not readable: %s.'), $values['site']['locale_path']));
182         }
183
184         // Validate SSL setup
185
186         if (mb_strlen($values['site']['sslserver']) > 255) {
187             // TRANS: Client error in Paths admin panel.
188             // TRANS: %s is the SSL server URL that is too long.
189             $this->clientError(_('Invalid SSL server. The maximum length is 255 characters.'));
190         }
191     }
192 }
193
194 class PathsAdminPanelForm extends AdminForm
195 {
196     /**
197      * ID of the form
198      *
199      * @return int ID of the form
200      */
201     function id()
202     {
203         return 'form_paths_admin_panel';
204     }
205
206     /**
207      * class of the form
208      *
209      * @return string class of the form
210      */
211     function formClass()
212     {
213         return 'form_settings';
214     }
215
216     /**
217      * Action of the form
218      *
219      * @return string URL of the action
220      */
221     function action()
222     {
223         return common_local_url('pathsadminpanel');
224     }
225
226     /**
227      * Data elements of the form
228      *
229      * @return void
230      */
231     function formData()
232     {
233         $this->out->elementStart('fieldset', array('id' => 'settings_paths_locale'));
234         // TRANS: Fieldset legend in Paths admin panel.
235         $this->out->element('legend', null, _('Site'), 'site');
236         $this->out->elementStart('ul', 'form_data');
237
238         $this->li();
239         $this->input('server',
240                      // TRANS: Field label in Paths admin panel.
241                      _('Server'),
242                      // TRANS: Field title in Paths admin panel.
243                      _('Site\'s server hostname.'));
244         $this->unli();
245
246         $this->li();
247         $this->input('path',
248                      // TRANS: Field label in Paths admin panel.
249                      _('Path'),
250                      // TRANS: Field title in Paths admin panel.
251                      _('Site path.'));
252         $this->unli();
253
254         $this->li();
255         $this->input('locale_path',
256                      // TRANS: Field label in Paths admin panel.
257                      _('Locale directory'),
258                      // TRANS: Field title in Paths admin panel.
259                      _('Directory path to locales.'),
260                      'site');
261         $this->unli();
262
263         $this->li();
264         $this->out->checkbox('fancy',
265                              // TRANS: Checkbox label in Paths admin panel.
266                              _('Fancy URLs'),
267                              (bool) $this->value('fancy'),
268                              // TRANS: Field title in Paths admin panel.
269                              _('Use fancy URLs (more readable and memorable)?'));
270         $this->unli();
271
272         $this->out->elementEnd('ul');
273         $this->out->elementEnd('fieldset');
274
275         $this->out->elementStart('fieldset', array('id' => 'settings_paths_theme'));
276         // TRANS: Fieldset legend in Paths admin panel.
277         $this->out->element('legend', null, _m('LEGEND','Theme'));
278
279         $this->out->elementStart('ul', 'form_data');
280
281         $this->li();
282         $this->input('server',
283                      // TRANS: Field label in Paths admin panel.
284                      _('Server'),
285                      // TRANS: Tooltip for field label in Paths admin panel.
286                      _('Server for themes.'),
287                      'theme');
288         $this->unli();
289
290         $this->li();
291         $this->input('path',
292                      // TRANS: Field label in Paths admin panel.
293                      _('Path'),
294                      // TRANS: Tooltip for field label in Paths admin panel.
295                      _('Web path to themes.'),
296                      'theme');
297         $this->unli();
298
299         $this->li();
300         $this->input('sslserver',
301                      // TRANS: Field label in Paths admin panel.
302                      _('SSL server'),
303                      // TRANS: Tooltip for field label in Paths admin panel.
304                      _('SSL server for themes (default: SSL server).'),
305                      'theme');
306         $this->unli();
307
308         $this->li();
309         $this->input('sslpath',
310                      // TRANS: Field label in Paths admin panel.
311                      _('SSL path'),
312                      // TRANS: Tooltip for field label in Paths admin panel.
313                      _('SSL path to themes (default: /theme/).'),
314                      'theme');
315         $this->unli();
316
317         $this->li();
318         $this->input('dir',
319                      // TRANS: Field label in Paths admin panel.
320                      _('Directory'),
321                      // TRANS: Tooltip for field label in Paths admin panel.
322                      _('Directory where themes are located.'),
323                      'theme');
324         $this->unli();
325
326         $this->out->elementEnd('ul');
327
328         $this->out->elementEnd('fieldset');
329         $this->out->elementStart('fieldset', array('id' => 'settings_avatar-paths'));
330         // TRANS: Fieldset legend in Paths admin panel.
331         $this->out->element('legend', null, _('Avatars'));
332
333         $this->out->elementStart('ul', 'form_data');
334
335         $this->li();
336         $this->input('server',
337                      // TRANS: Field label in Paths admin panel.
338                      _('Avatar server'),
339                      // TRANS: Tooltip for field label in Paths admin panel.
340                      _('Server for avatars.'),
341                      'avatar');
342         $this->unli();
343
344         $this->li();
345         $this->input('path',
346                      // TRANS: Field label in Paths admin panel.
347                      _('Avatar path'),
348                      // TRANS: Tooltip for field label in Paths admin panel.
349                      _('Web path to avatars.'),
350                      'avatar');
351         $this->unli();
352
353         $this->li();
354         $this->input('dir',
355                      // TRANS: Field label in Paths admin panel.
356                      _('Avatar directory'),
357                      // TRANS: Tooltip for field label in Paths admin panel.
358                      _('Directory where avatars are located.'),
359                      'avatar');
360         $this->unli();
361
362         $this->out->elementEnd('ul');
363
364         $this->out->elementEnd('fieldset');
365
366         $this->out->elementStart('fieldset', array('id' =>
367                                                    'settings_design_background-paths'));
368         // TRANS: Fieldset legend in Paths admin panel.
369         $this->out->element('legend', null, _('Backgrounds'));
370         $this->out->elementStart('ul', 'form_data');
371
372         $this->li();
373         $this->input('server',
374                      // TRANS: Field label in Paths admin panel.
375                      _('Server'),
376                      // TRANS: Tooltip for field label in Paths admin panel.
377                      _('Server for backgrounds.'),
378                      'background');
379         $this->unli();
380
381         $this->li();
382         $this->input('path',
383                      // TRANS: Field label in Paths admin panel.
384                      _('Path'),
385                      // TRANS: Tooltip for field label in Paths admin panel.
386                      _('Web path to backgrounds.'),
387                      'background');
388         $this->unli();
389
390         $this->li();
391         $this->input('sslserver',
392                      // TRANS: Field label in Paths admin panel.
393                      _('SSL server'),
394                      // TRANS: Tooltip for field label in Paths admin panel.
395                      _('Server for backgrounds on SSL pages.'),
396                      'background');
397         $this->unli();
398
399         $this->li();
400         $this->input('sslpath',
401                      // TRANS: Field label in Paths admin panel.
402                      _('SSL path'),
403                      // TRANS: Tooltip for field label in Paths admin panel.
404                      _('Web path to backgrounds on SSL pages.'),
405                      'background');
406         $this->unli();
407
408         $this->li();
409         $this->input('dir',
410                      // TRANS: Field label in Paths admin panel.
411                      _('Directory'),
412                      // TRANS: Tooltip for field label in Paths admin panel.
413                      _('Directory where backgrounds are located.'),
414                      'background');
415         $this->unli();
416
417         $this->out->elementEnd('ul');
418         $this->out->elementEnd('fieldset');
419
420         $this->out->elementStart('fieldset', array('id' =>
421                                                    'settings_design_attachments-paths'));
422
423         // TRANS: Fieldset legens in Paths admin panel.
424         $this->out->element('legend', null, _('Attachments'));
425         $this->out->elementStart('ul', 'form_data');
426
427         $this->li();
428         $this->input('server',
429                      // TRANS: Field label in Paths admin panel.
430                      _('Server'),
431                      // TRANS: Tooltip for field label in Paths admin panel.
432                      _('Server for attachments.'),
433                      'attachments');
434         $this->unli();
435
436         $this->li();
437         $this->input('path',
438                      // TRANS: Field label in Paths admin panel.
439                      _('Path'),
440                      // TRANS: Tooltip for field label in Paths admin panel.
441                      _('Web path to attachments.'),
442                      'attachments');
443         $this->unli();
444
445         $this->li();
446         $this->input('sslserver',
447                      // TRANS: Field label in Paths admin panel.
448                      _('SSL server'),
449                      // TRANS: Tooltip for field label in Paths admin panel.
450                      _('Server for attachments on SSL pages.'),
451                      'attachments');
452         $this->unli();
453
454         $this->li();
455         $this->input('sslpath',
456                      // TRANS: Field label in Paths admin panel.
457                      _('SSL path'),
458                      // TRANS: Tooltip for field label in Paths admin panel.
459                      _('Web path to attachments on SSL pages.'),
460                      'attachments');
461         $this->unli();
462
463         $this->li();
464         $this->input('dir',
465                      // TRANS: Field label in Paths admin panel.
466                      _('Directory'),
467                      // TRANS: Tooltip for field label in Paths admin panel.
468                      _('Directory where attachments are located.'),
469                      'attachments');
470         $this->unli();
471
472         $this->out->elementEnd('ul');
473         $this->out->elementEnd('fieldset');
474
475         $this->out->elementStart('fieldset', array('id' => 'settings_admin_ssl'));
476         // TRANS: Fieldset legend in Paths admin panel.
477         $this->out->element('legend', null, _m('LEGEND','SSL'));
478         $this->out->elementStart('ul', 'form_data');
479         $this->li();
480
481         // TRANS: Drop down option in Paths admin panel (option for "When to use SSL").
482         $ssl = array('never' => _('Never'),
483                      // TRANS: Drop down option in Paths admin panel (option for "When to use SSL").
484                      'sometimes' => _('Sometimes'),
485                       // TRANS: Drop down option in Paths admin panel (option for "When to use SSL").
486                      'always' => _('Always'));
487
488         $this->out->dropdown('site-ssl',
489                              // TRANS: Drop down label in Paths admin panel.
490                              _('Use SSL'),
491                              // TRANS: Tooltip for field label in Paths admin panel.
492                              $ssl, _('When to use SSL.'),
493                              false,
494                              $this->value('ssl', 'site'));
495         $this->unli();
496
497         $this->li();
498         $this->input('sslserver',
499                      // TRANS: Field label in Paths admin panel.
500                      _('SSL server'),
501                      // TRANS: Tooltip for field label in Paths admin panel.
502                      _('Server to direct SSL requests to.'),
503                      'site');
504         $this->unli();
505         $this->out->elementEnd('ul');
506         $this->out->elementEnd('fieldset');
507     }
508
509     /**
510      * Action elements
511      *
512      * @return void
513      */
514     function formActions()
515     {
516         // TRANS: Button text to store form data in the Paths admin panel.
517         $this->out->submit('save', _m('BUTTON','Save'), 'submit',
518                            // TRANS: Button title text to store form data in the Paths admin panel.
519                            'save', _('Save paths'));
520     }
521
522     /**
523      * Utility to simplify some of the duplicated code around
524      * params and settings. Overriding the input() in the base class
525      * to handle a whole bunch of cases of settings with the same
526      * name under different sections.
527      *
528      * @param string $setting      Name of the setting
529      * @param string $title        Title to use for the input
530      * @param string $instructions Instructions for this field
531      * @param string $section      config section, default = 'site'
532      *
533      * @return void
534      */
535     function input($setting, $title, $instructions, $section='site')
536     {
537         $this->out->input("$section-$setting", $title, $this->value($setting, $section), $instructions);
538     }
539 }