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 _('Site\'s server hostname.'));
247 // TRANS: Field label in Paths admin panel.
253 $this->input('locale_path',
254 // TRANS: Field label in Paths admin panel.
255 _('Locale directory'),
256 _('Directory path to locales.'),
261 $this->out->checkbox('fancy',
262 // TRANS: Checkbox label in Paths admin panel.
264 (bool) $this->value('fancy'),
265 _('Use fancy (more readable and memorable) URLs?'));
268 $this->out->elementEnd('ul');
269 $this->out->elementEnd('fieldset');
271 $this->out->elementStart('fieldset', array('id' => 'settings_paths_theme'));
272 $this->out->element('legend', null, _('Theme'));
274 $this->out->elementStart('ul', 'form_data');
277 $this->input('server',
278 // TRANS: Field label in Paths admin panel.
280 // TRANS: Tooltip for field label in Paths admin panel.
281 _('Server for themes.'),
287 // TRANS: Field label in Paths admin panel.
289 // TRANS: Tooltip for field label in Paths admin panel.
290 _('Web path to themes.'),
295 $this->input('sslserver',
296 // TRANS: Field label in Paths admin panel.
298 // TRANS: Tooltip for field label in Paths admin panel.
299 _('SSL server for themes (default: SSL server).'),
304 $this->input('sslpath',
305 // TRANS: Field label in Paths admin panel.
307 // TRANS: Tooltip for field label in Paths admin panel.
308 _('SSL path to themes (default: /theme/).'),
314 // TRANS: Field label in Paths admin panel.
316 // TRANS: Tooltip for field label in Paths admin panel.
317 _('Directory where themes are located.'),
321 $this->out->elementEnd('ul');
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'));
328 $this->out->elementStart('ul', 'form_data');
331 $this->input('server',
332 // TRANS: Field label in Paths admin panel.
334 // TRANS: Tooltip for field label in Paths admin panel.
335 _('Server for avatars.'),
341 // TRANS: Field label in Paths admin panel.
343 // TRANS: Tooltip for field label in Paths admin panel.
344 _('Web path to avatars.'),
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.'),
357 $this->out->elementEnd('ul');
359 $this->out->elementEnd('fieldset');
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');
368 $this->input('server',
369 // TRANS: Field label in Paths admin panel.
371 // TRANS: Tooltip for field label in Paths admin panel.
372 _('Server for backgrounds.'),
378 // TRANS: Field label in Paths admin panel.
380 // TRANS: Tooltip for field label in Paths admin panel.
381 _('Web path to backgrounds.'),
386 $this->input('sslserver',
387 // TRANS: Field label in Paths admin panel.
389 // TRANS: Tooltip for field label in Paths admin panel.
390 _('Server for backgrounds on SSL pages.'),
395 $this->input('sslpath',
396 // TRANS: Field label in Paths admin panel.
398 // TRANS: Tooltip for field label in Paths admin panel.
399 _('Web path to backgrounds on SSL pages.'),
405 // TRANS: Field label in Paths admin panel.
407 // TRANS: Tooltip for field label in Paths admin panel.
408 _('Directory where backgrounds are located.'),
412 $this->out->elementEnd('ul');
413 $this->out->elementEnd('fieldset');
415 $this->out->elementStart('fieldset', array('id' =>
416 'settings_design_attachments-paths'));
418 // TRANS: Fieldset legens in Paths admin panel.
419 $this->out->element('legend', null, _('Attachments'));
420 $this->out->elementStart('ul', 'form_data');
423 $this->input('server',
424 // TRANS: Field label in Paths admin panel.
426 // TRANS: Tooltip for field label in Paths admin panel.
427 _('Server for attachments.'),
433 // TRANS: Field label in Paths admin panel.
435 // TRANS: Tooltip for field label in Paths admin panel.
436 _('Web path to attachments.'),
441 $this->input('sslserver',
442 // TRANS: Field label in Paths admin panel.
444 // TRANS: Tooltip for field label in Paths admin panel.
445 _('Server for attachments on SSL pages.'),
450 $this->input('sslpath',
451 // TRANS: Field label in Paths admin panel.
453 // TRANS: Tooltip for field label in Paths admin panel.
454 _('Web path to attachments on SSL pages.'),
460 // TRANS: Field label in Paths admin panel.
462 // TRANS: Tooltip for field label in Paths admin panel.
463 _('Directory where attachments are located.'),
467 $this->out->elementEnd('ul');
468 $this->out->elementEnd('fieldset');
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');
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'));
483 // TRANS: Drop down label in Paths admin panel.
484 $this->out->dropdown('site-ssl',
486 // TRANS: Tooltip for field label in Paths admin panel.
487 $ssl, _('When to use SSL.'),
489 $this->value('ssl', 'site'));
493 $this->input('sslserver',
494 // TRANS: Field label in Paths admin panel.
496 // TRANS: Tooltip for field label in Paths admin panel.
497 _('Server to direct SSL requests to.'),
500 $this->out->elementEnd('ul');
501 $this->out->elementEnd('fieldset');
509 function formActions()
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'));
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.
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'
530 function input($setting, $title, $instructions, $section='site')
532 $this->out->input("$section-$setting", $title, $this->value($setting, $section), $instructions);