3 * StatusNet, the distributed open-source microblogging tool
5 * Paths administration panel
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.
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.
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/>.
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/
32 if (!defined('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/
47 class PathsadminpanelAction extends AdminPanelAction
50 * Returns the page title
52 * @return string page title
57 // TRANS: Title for Paths admin panel.
62 * Instructions for using this form.
64 * @return string instructions
66 function getInstructions()
68 // TRANS: Form instructions for Path admin panel.
69 return _('Path and server settings for this StatusNet site');
73 * Show the paths admin panel form
79 $form = new PathsAdminPanelForm($this);
85 * Save settings from the form
89 function saveSettings()
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')
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
102 static $booleans = array('site' => array('fancy'));
106 foreach ($settings as $section => $parts) {
107 foreach ($parts as $setting) {
108 $values[$section][$setting] = $this->trimmed("$section-$setting");
112 foreach ($booleans as $section => $parts) {
113 foreach ($parts as $setting) {
114 $values[$section][$setting] = ($this->boolean($setting)) ? 1 : 0;
118 $this->validate($values);
120 // assert(all values are valid);
122 $config = new Config();
124 $config->query('BEGIN');
126 foreach ($settings as $section => $parts) {
127 foreach ($parts as $setting) {
128 Config::save($section, $setting, $values[$section][$setting]);
132 foreach ($booleans as $section => $parts) {
133 foreach ($parts as $setting) {
134 Config::save($section, $setting, $values[$section][$setting]);
138 $config->query('COMMIT');
144 * Attempt to validate setting values
148 function validate(&$values)
150 // Validate theme dir
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']));
158 // Validate avatar dir
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']));
166 // Validate background dir
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']));
174 // Validate locales dir
176 // XXX: What else do we need to validate for lacales path here? --Z
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']));
184 // Validate SSL setup
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.'));
194 class PathsAdminPanelForm extends AdminForm
199 * @return int ID of the form
203 return 'form_paths_admin_panel';
209 * @return string class of the form
213 return 'form_settings';
219 * @return string URL of the action
223 return common_local_url('pathsadminpanel');
227 * Data elements of the form
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');
239 $this->input('server',
240 // TRANS: Field label in Paths admin panel.
242 // TRANS: Field title in Paths admin panel.
243 _('Site\'s server hostname.'));
248 // TRANS: Field label in Paths admin panel.
250 // TRANS: Field title in Paths admin panel.
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.'),
264 $this->out->checkbox('fancy',
265 // TRANS: Checkbox label in Paths admin panel.
267 (bool) $this->value('fancy'),
268 // TRANS: Field title in Paths admin panel.
269 _('Use fancy URLs (more readable and memorable)?'));
272 $this->out->elementEnd('ul');
273 $this->out->elementEnd('fieldset');
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'));
279 $this->out->elementStart('ul', 'form_data');
282 $this->input('server',
283 // TRANS: Field label in Paths admin panel.
285 // TRANS: Tooltip for field label in Paths admin panel.
286 _('Server for themes.'),
292 // TRANS: Field label in Paths admin panel.
294 // TRANS: Tooltip for field label in Paths admin panel.
295 _('Web path to themes.'),
300 $this->input('sslserver',
301 // TRANS: Field label in Paths admin panel.
303 // TRANS: Tooltip for field label in Paths admin panel.
304 _('SSL server for themes (default: SSL server).'),
309 $this->input('sslpath',
310 // TRANS: Field label in Paths admin panel.
312 // TRANS: Tooltip for field label in Paths admin panel.
313 _('SSL path to themes (default: /theme/).'),
319 // TRANS: Field label in Paths admin panel.
321 // TRANS: Tooltip for field label in Paths admin panel.
322 _('Directory where themes are located.'),
326 $this->out->elementEnd('ul');
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'));
333 $this->out->elementStart('ul', 'form_data');
336 $this->input('server',
337 // TRANS: Field label in Paths admin panel.
339 // TRANS: Tooltip for field label in Paths admin panel.
340 _('Server for avatars.'),
346 // TRANS: Field label in Paths admin panel.
348 // TRANS: Tooltip for field label in Paths admin panel.
349 _('Web path to avatars.'),
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.'),
362 $this->out->elementEnd('ul');
364 $this->out->elementEnd('fieldset');
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');
373 $this->input('server',
374 // TRANS: Field label in Paths admin panel.
376 // TRANS: Tooltip for field label in Paths admin panel.
377 _('Server for backgrounds.'),
383 // TRANS: Field label in Paths admin panel.
385 // TRANS: Tooltip for field label in Paths admin panel.
386 _('Web path to backgrounds.'),
391 $this->input('sslserver',
392 // TRANS: Field label in Paths admin panel.
394 // TRANS: Tooltip for field label in Paths admin panel.
395 _('Server for backgrounds on SSL pages.'),
400 $this->input('sslpath',
401 // TRANS: Field label in Paths admin panel.
403 // TRANS: Tooltip for field label in Paths admin panel.
404 _('Web path to backgrounds on SSL pages.'),
410 // TRANS: Field label in Paths admin panel.
412 // TRANS: Tooltip for field label in Paths admin panel.
413 _('Directory where backgrounds are located.'),
417 $this->out->elementEnd('ul');
418 $this->out->elementEnd('fieldset');
420 $this->out->elementStart('fieldset', array('id' =>
421 'settings_design_attachments-paths'));
423 // TRANS: Fieldset legens in Paths admin panel.
424 $this->out->element('legend', null, _('Attachments'));
425 $this->out->elementStart('ul', 'form_data');
428 $this->input('server',
429 // TRANS: Field label in Paths admin panel.
431 // TRANS: Tooltip for field label in Paths admin panel.
432 _('Server for attachments.'),
438 // TRANS: Field label in Paths admin panel.
440 // TRANS: Tooltip for field label in Paths admin panel.
441 _('Web path to attachments.'),
446 $this->input('sslserver',
447 // TRANS: Field label in Paths admin panel.
449 // TRANS: Tooltip for field label in Paths admin panel.
450 _('Server for attachments on SSL pages.'),
455 $this->input('sslpath',
456 // TRANS: Field label in Paths admin panel.
458 // TRANS: Tooltip for field label in Paths admin panel.
459 _('Web path to attachments on SSL pages.'),
465 // TRANS: Field label in Paths admin panel.
467 // TRANS: Tooltip for field label in Paths admin panel.
468 _('Directory where attachments are located.'),
472 $this->out->elementEnd('ul');
473 $this->out->elementEnd('fieldset');
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');
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'));
488 $this->out->dropdown('site-ssl',
489 // TRANS: Drop down label in Paths admin panel.
491 // TRANS: Tooltip for field label in Paths admin panel.
492 $ssl, _('When to use SSL.'),
494 $this->value('ssl', 'site'));
498 $this->input('sslserver',
499 // TRANS: Field label in Paths admin panel.
501 // TRANS: Tooltip for field label in Paths admin panel.
502 _('Server to direct SSL requests to.'),
505 $this->out->elementEnd('ul');
506 $this->out->elementEnd('fieldset');
514 function formActions()
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'));
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.
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'
535 function input($setting, $title, $instructions, $section='site')
537 $this->out->input("$section-$setting", $title, $this->value($setting, $section), $instructions);