]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/pathsadminpanel.php
Merge branch '0.9.x' of gitorious.org:statusnet/mainline into 0.9.x
[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                      _('Site\'s server hostname.'));
243         $this->unli();
244
245         $this->li();
246         $this->input('path',
247                      // TRANS: Field label in Paths admin panel.
248                      _('Path'),
249                      _('Site path.'));
250         $this->unli();
251
252         $this->li();
253         $this->input('locale_path',
254                      // TRANS: Field label in Paths admin panel.
255                      _('Locale directory'),
256                      _('Directory path to locales.'),
257                      'site');
258         $this->unli();
259
260         $this->li();
261         $this->out->checkbox('fancy',
262                              // TRANS: Checkbox label in Paths admin panel.
263                              _('Fancy URLs'),
264                              (bool) $this->value('fancy'),
265                              _('Use fancy (more readable and memorable) URLs?'));
266         $this->unli();
267
268         $this->out->elementEnd('ul');
269         $this->out->elementEnd('fieldset');
270
271         $this->out->elementStart('fieldset', array('id' => 'settings_paths_theme'));
272         $this->out->element('legend', null, _('Theme'));
273
274         $this->out->elementStart('ul', 'form_data');
275
276         $this->li();
277         $this->input('server',
278                      // TRANS: Field label in Paths admin panel.
279                      _('Server'),
280                      // TRANS: Tooltip for field label in Paths admin panel.
281                      _('Server for themes.'),
282                      'theme');
283         $this->unli();
284
285         $this->li();
286         $this->input('path',
287                      // TRANS: Field label in Paths admin panel.
288                      _('Path'),
289                      // TRANS: Tooltip for field label in Paths admin panel.
290                      _('Web path to themes.'),
291                      'theme');
292         $this->unli();
293
294         $this->li();
295         $this->input('sslserver',
296                      // TRANS: Field label in Paths admin panel.
297                      _('SSL server'),
298                      // TRANS: Tooltip for field label in Paths admin panel.
299                      _('SSL server for themes (default: SSL server).'),
300                      'theme');
301         $this->unli();
302
303         $this->li();
304         $this->input('sslpath',
305                      // TRANS: Field label in Paths admin panel.
306                      _('SSL path'),
307                      // TRANS: Tooltip for field label in Paths admin panel.
308                      _('SSL path to themes (default: /theme/).'),
309                      'theme');
310         $this->unli();
311
312         $this->li();
313         $this->input('dir',
314                      // TRANS: Field label in Paths admin panel.
315                      _('Directory'),
316                      // TRANS: Tooltip for field label in Paths admin panel.
317                      _('Directory where themes are located.'),
318                      'theme');
319         $this->unli();
320
321         $this->out->elementEnd('ul');
322
323         $this->out->elementEnd('fieldset');
324         $this->out->elementStart('fieldset', array('id' => 'settings_avatar-paths'));
325         // TRANS: Fieldset legend in Paths admin panel.
326         $this->out->element('legend', null, _('Avatars'));
327
328         $this->out->elementStart('ul', 'form_data');
329
330         $this->li();
331         $this->input('server',
332                      // TRANS: Field label in Paths admin panel.
333                      _('Avatar server'),
334                      // TRANS: Tooltip for field label in Paths admin panel.
335                      _('Server for avatars.'),
336                      'avatar');
337         $this->unli();
338
339         $this->li();
340         $this->input('path',
341                      // TRANS: Field label in Paths admin panel.
342                      _('Avatar path'),
343                      // TRANS: Tooltip for field label in Paths admin panel.
344                      _('Web path to avatars.'),
345                      'avatar');
346         $this->unli();
347
348         $this->li();
349         $this->input('dir',
350                      // TRANS: Field label in Paths admin panel.
351                      _('Avatar directory'),
352                      // TRANS: Tooltip for field label in Paths admin panel.
353                      _('Directory where avatars are located.'),
354                      'avatar');
355         $this->unli();
356
357         $this->out->elementEnd('ul');
358
359         $this->out->elementEnd('fieldset');
360
361         $this->out->elementStart('fieldset', array('id' =>
362                                                    'settings_design_background-paths'));
363         // TRANS: Fieldset legend in Paths admin panel.
364         $this->out->element('legend', null, _('Backgrounds'));
365         $this->out->elementStart('ul', 'form_data');
366
367         $this->li();
368         $this->input('server',
369                      // TRANS: Field label in Paths admin panel.
370                      _('Server'),
371                      // TRANS: Tooltip for field label in Paths admin panel.
372                      _('Server for backgrounds.'),
373                      'background');
374         $this->unli();
375
376         $this->li();
377         $this->input('path',
378                      // TRANS: Field label in Paths admin panel.
379                      _('Path'),
380                      // TRANS: Tooltip for field label in Paths admin panel.
381                      _('Web path to backgrounds.'),
382                      'background');
383         $this->unli();
384
385         $this->li();
386         $this->input('sslserver',
387                      // TRANS: Field label in Paths admin panel.
388                      _('SSL server'),
389                      // TRANS: Tooltip for field label in Paths admin panel.
390                      _('Server for backgrounds on SSL pages.'),
391                      'background');
392         $this->unli();
393
394         $this->li();
395         $this->input('sslpath',
396                      // TRANS: Field label in Paths admin panel.
397                      _('SSL path'),
398                      // TRANS: Tooltip for field label in Paths admin panel.
399                      _('Web path to backgrounds on SSL pages.'),
400                      'background');
401         $this->unli();
402
403         $this->li();
404         $this->input('dir',
405                      // TRANS: Field label in Paths admin panel.
406                      _('Directory'),
407                      // TRANS: Tooltip for field label in Paths admin panel.
408                      _('Directory where backgrounds are located.'),
409                      'background');
410         $this->unli();
411
412         $this->out->elementEnd('ul');
413         $this->out->elementEnd('fieldset');
414
415         $this->out->elementStart('fieldset', array('id' =>
416                                                    'settings_design_attachments-paths'));
417
418         // TRANS: Fieldset legens in Paths admin panel.
419         $this->out->element('legend', null, _('Attachments'));
420         $this->out->elementStart('ul', 'form_data');
421
422         $this->li();
423         $this->input('server',
424                      // TRANS: Field label in Paths admin panel.
425                      _('Server'),
426                      // TRANS: Tooltip for field label in Paths admin panel.
427                      _('Server for attachments.'),
428                      'attachments');
429         $this->unli();
430
431         $this->li();
432         $this->input('path',
433                      // TRANS: Field label in Paths admin panel.
434                      _('Path'),
435                      // TRANS: Tooltip for field label in Paths admin panel.
436                      _('Web path to attachments.'),
437                      'attachments');
438         $this->unli();
439
440         $this->li();
441         $this->input('sslserver',
442                      // TRANS: Field label in Paths admin panel.
443                      _('SSL server'),
444                      // TRANS: Tooltip for field label in Paths admin panel.
445                      _('Server for attachments on SSL pages.'),
446                      'attachments');
447         $this->unli();
448
449         $this->li();
450         $this->input('sslpath',
451                      // TRANS: Field label in Paths admin panel.
452                      _('SSL path'),
453                      // TRANS: Tooltip for field label in Paths admin panel.
454                      _('Web path to attachments on SSL pages.'),
455                      'attachments');
456         $this->unli();
457
458         $this->li();
459         $this->input('dir',
460                      // TRANS: Field label in Paths admin panel.
461                      _('Directory'),
462                      // TRANS: Tooltip for field label in Paths admin panel.
463                      _('Directory where attachments are located.'),
464                      'attachments');
465         $this->unli();
466
467         $this->out->elementEnd('ul');
468         $this->out->elementEnd('fieldset');
469
470         $this->out->elementStart('fieldset', array('id' => 'settings_admin_ssl'));
471         // TRANS: Fieldset legend in Paths admin panel.
472         $this->out->element('legend', null, _('SSL'));
473         $this->out->elementStart('ul', 'form_data');
474         $this->li();
475
476         // TRANS: Drop down option in Paths admin panel (option for "When to use SSL").
477         $ssl = array('never' => _('Never'),
478                      // TRANS: Drop down option in Paths admin panel (option for "When to use SSL").
479                      'sometimes' => _('Sometimes'),
480                       // TRANS: Drop down option in Paths admin panel (option for "When to use SSL").
481                      'always' => _('Always'));
482
483         // TRANS: Drop down label in Paths admin panel.
484         $this->out->dropdown('site-ssl',
485                              _('Use SSL'),
486                              // TRANS: Tooltip for field label in Paths admin panel.
487                              $ssl, _('When to use SSL.'),
488                              false,
489                              $this->value('ssl', 'site'));
490         $this->unli();
491
492         $this->li();
493         $this->input('sslserver',
494                      // TRANS: Field label in Paths admin panel.
495                      _('SSL server'),
496                      // TRANS: Tooltip for field label in Paths admin panel.
497                      _('Server to direct SSL requests to.'),
498                      'site');
499         $this->unli();
500         $this->out->elementEnd('ul');
501         $this->out->elementEnd('fieldset');
502     }
503
504     /**
505      * Action elements
506      *
507      * @return void
508      */
509     function formActions()
510     {
511         // TRANS: Button text to store form data in the Paths admin panel.
512         $this->out->submit('save', _m('BUTTON','Save'), 'submit',
513                            // TRANS: Button title text to store form data in the Paths admin panel.
514                            'save', _('Save paths'));
515     }
516
517     /**
518      * Utility to simplify some of the duplicated code around
519      * params and settings. Overriding the input() in the base class
520      * to handle a whole bunch of cases of settings with the same
521      * name under different sections.
522      *
523      * @param string $setting      Name of the setting
524      * @param string $title        Title to use for the input
525      * @param string $instructions Instructions for this field
526      * @param string $section      config section, default = 'site'
527      *
528      * @return void
529      */
530     function input($setting, $title, $instructions, $section='site')
531     {
532         $this->out->input("$section-$setting", $title, $this->value($setting, $section), $instructions);
533     }
534 }