]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/pathsadminpanel.php
Merge branch '0.9.x' of gitorious.org:statusnet/mainline into 1.0.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
48 class PathsadminpanelAction extends AdminPanelAction
49 {
50
51     /**
52      * Returns the page title
53      *
54      * @return string page title
55      */
56
57     function title()
58     {
59         return _('Paths');
60     }
61
62     /**
63      * Instructions for using this form.
64      *
65      * @return string instructions
66      */
67
68     function getInstructions()
69     {
70         return _('Path and server settings for this StatusNet site');
71     }
72
73     /**
74      * Show the paths admin panel form
75      *
76      * @return void
77      */
78
79     function showForm()
80     {
81         $form = new PathsAdminPanelForm($this);
82         $form->show();
83         return;
84     }
85
86     /**
87      * Save settings from the form
88      *
89      * @return void
90      */
91
92     function saveSettings()
93     {
94         static $settings = array(
95             'site' => array('path', 'locale_path', 'ssl', 'sslserver'),
96             'theme' => array('server', 'dir', 'path'),
97             'avatar' => array('server', 'dir', 'path'),
98             'background' => array('server', 'dir', 'path')
99         );
100
101         // XXX: If we're only going to have one boolean on thi page we
102         // can remove some of the boolean processing code --Z
103
104         static $booleans = array('site' => array('fancy'));
105
106         $values = array();
107
108         foreach ($settings as $section => $parts) {
109             foreach ($parts as $setting) {
110                 $values[$section][$setting] = $this->trimmed("$section-$setting");
111             }
112         }
113
114         foreach ($booleans as $section => $parts) {
115             foreach ($parts as $setting) {
116                 $values[$section][$setting] = ($this->boolean($setting)) ? 1 : 0;
117             }
118         }
119
120         $this->validate($values);
121
122         // assert(all values are valid);
123
124         $config = new Config();
125
126         $config->query('BEGIN');
127
128         foreach ($settings as $section => $parts) {
129             foreach ($parts as $setting) {
130                 Config::save($section, $setting, $values[$section][$setting]);
131             }
132         }
133
134         foreach ($booleans as $section => $parts) {
135             foreach ($parts as $setting) {
136                 Config::save($section, $setting, $values[$section][$setting]);
137             }
138         }
139
140         $config->query('COMMIT');
141
142         return;
143     }
144
145     /**
146      * Attempt to validate setting values
147      *
148      * @return void
149      */
150
151     function validate(&$values)
152     {
153
154         // Validate theme dir
155
156         if (!empty($values['theme']['dir']) && !is_readable($values['theme']['dir'])) {
157             $this->clientError(sprintf(_("Theme directory not readable: %s."), $values['theme']['dir']));
158         }
159
160         // Validate avatar dir
161
162         if (empty($values['avatar']['dir']) || !is_writable($values['avatar']['dir'])) {
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             $this->clientError(sprintf(_("Background directory not writable: %s."), $values['background']['dir']));
170         }
171
172         // Validate locales dir
173
174         // XXX: What else do we need to validate for lacales path here? --Z
175
176         if (!empty($values['site']['locale_path']) && !is_readable($values['site']['locale_path'])) {
177             $this->clientError(sprintf(_("Locales directory not readable: %s."), $values['site']['locale_path']));
178         }
179
180         // Validate SSL setup
181
182         if (mb_strlen($values['site']['sslserver']) > 255) {
183             $this->clientError(_('Invalid SSL server. The maximum length is 255 characters.'));
184         }
185     }
186
187 }
188
189 class PathsAdminPanelForm extends AdminForm
190 {
191
192     /**
193      * ID of the form
194      *
195      * @return int ID of the form
196      */
197
198     function id()
199     {
200         return 'form_paths_admin_panel';
201     }
202
203     /**
204      * class of the form
205      *
206      * @return string class of the form
207      */
208
209     function formClass()
210     {
211         return 'form_settings';
212     }
213
214     /**
215      * Action of the form
216      *
217      * @return string URL of the action
218      */
219
220     function action()
221     {
222         return common_local_url('pathsadminpanel');
223     }
224
225     /**
226      * Data elements of the form
227      *
228      * @return void
229      */
230
231     function formData()
232     {
233         $this->out->elementStart('fieldset', array('id' => 'settings_paths_locale'));
234         $this->out->element('legend', null, _('Site'), 'site');
235         $this->out->elementStart('ul', 'form_data');
236
237         $this->li();
238         $this->input('server', _('Server'), _('Site\'s server hostname.'));
239         $this->unli();
240
241         $this->li();
242         $this->input('path', _('Path'), _('Site path'));
243         $this->unli();
244
245         $this->li();
246         $this->input('locale_path', _('Path to locales'), _('Directory path to locales'), 'site');
247         $this->unli();
248
249         $this->li();
250         $this->out->checkbox('fancy', _('Fancy URLs'),
251                              (bool) $this->value('fancy'),
252                              _('Use fancy (more readable and memorable) URLs?'));
253         $this->unli();
254
255         $this->out->elementEnd('ul');
256         $this->out->elementEnd('fieldset');
257
258         $this->out->elementStart('fieldset', array('id' => 'settings_paths_theme'));
259         $this->out->element('legend', null, _('Theme'));
260
261         $this->out->elementStart('ul', 'form_data');
262
263         $this->li();
264         $this->input('server', _('Theme server'), 'Server for themes', 'theme');
265         $this->unli();
266
267         $this->li();
268         $this->input('path', _('Theme path'), 'Web path to themes', 'theme');
269         $this->unli();
270
271         $this->li();
272         $this->input('dir', _('Theme directory'), 'Directory where themes are located', 'theme');
273         $this->unli();
274
275         $this->out->elementEnd('ul');
276
277         $this->out->elementEnd('fieldset');
278         $this->out->elementStart('fieldset', array('id' => 'settings_avatar-paths'));
279         $this->out->element('legend', null, _('Avatars'));
280
281         $this->out->elementStart('ul', 'form_data');
282
283         $this->li();
284         $this->input('server', _('Avatar server'), 'Server for avatars', 'avatar');
285         $this->unli();
286
287         $this->li();
288         $this->input('path', _('Avatar path'), 'Web path to avatars', 'avatar');
289         $this->unli();
290
291         $this->li();
292         $this->input('dir', _('Avatar directory'), 'Directory where avatars are located', 'avatar');
293         $this->unli();
294
295         $this->out->elementEnd('ul');
296
297         $this->out->elementEnd('fieldset');
298
299         $this->out->elementStart('fieldset', array('id' =>
300             'settings_design_background-paths'));
301         $this->out->element('legend', null, _('Backgrounds'));
302         $this->out->elementStart('ul', 'form_data');
303
304         $this->li();
305         $this->input('server', _('Background server'), 'Server for backgrounds', 'background');
306         $this->unli();
307
308         $this->li();
309         $this->input('path', _('Background path'), 'Web path to backgrounds', 'background');
310         $this->unli();
311
312         $this->li();
313         $this->input('dir', _('Background directory'), 'Directory where backgrounds are located', 'background');
314         $this->unli();
315
316         $this->out->elementEnd('ul');
317         $this->out->elementEnd('fieldset');
318
319         $this->out->elementStart('fieldset', array('id' => 'settings_admin_ssl'));
320         $this->out->element('legend', null, _('SSL'));
321         $this->out->elementStart('ul', 'form_data');
322         $this->li();
323         $ssl = array('never' => _('Never'),
324                      'sometimes' => _('Sometimes'),
325                      'always' => _('Always'));
326
327         common_debug("site ssl = " . $this->value('site', 'ssl'));
328
329         $this->out->dropdown('site-ssl', _('Use SSL'),
330                              $ssl, _('When to use SSL'),
331                              false, $this->value('ssl', 'site'));
332         $this->unli();
333
334         $this->li();
335         $this->input('sslserver', _('SSL server'),
336                      _('Server to direct SSL requests to'), 'site');
337         $this->unli();
338         $this->out->elementEnd('ul');
339         $this->out->elementEnd('fieldset');
340
341     }
342
343     /**
344      * Action elements
345      *
346      * @return void
347      */
348
349     function formActions()
350     {
351         $this->out->submit('save', _('Save'), 'submit',
352                 'save', _('Save paths'));
353     }
354
355     /**
356      * Utility to simplify some of the duplicated code around
357      * params and settings. Overriding the input() in the base class
358      * to handle a whole bunch of cases of settings with the same
359      * name under different sections.
360      *
361      * @param string $setting      Name of the setting
362      * @param string $title        Title to use for the input
363      * @param string $instructions Instructions for this field
364      * @param string $section      config section, default = 'site'
365      *
366      * @return void
367      */
368
369     function input($setting, $title, $instructions, $section='site')
370     {
371         $this->out->input("$section-$setting", $title, $this->value($setting, $section), $instructions);
372     }
373
374 }