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-2011 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 'attachments' => array('server', 'dir', 'path', 'sslserver', 'sslpath')
98 // XXX: If we're only going to have one boolean on thi page we
99 // can remove some of the boolean processing code --Z
101 static $booleans = array('site' => array('fancy'));
105 foreach ($settings as $section => $parts) {
106 foreach ($parts as $setting) {
107 $values[$section][$setting] = $this->trimmed("$section-$setting");
111 foreach ($booleans as $section => $parts) {
112 foreach ($parts as $setting) {
113 $values[$section][$setting] = ($this->boolean($setting)) ? 1 : 0;
117 $this->validate($values);
119 // assert(all values are valid);
121 $config = new Config();
123 $config->query('BEGIN');
125 foreach ($settings as $section => $parts) {
126 foreach ($parts as $setting) {
127 Config::save($section, $setting, $values[$section][$setting]);
131 foreach ($booleans as $section => $parts) {
132 foreach ($parts as $setting) {
133 Config::save($section, $setting, $values[$section][$setting]);
137 $config->query('COMMIT');
143 * Attempt to validate setting values
147 function validate(&$values)
149 // Validate theme dir
151 if (!empty($values['theme']['dir']) && !is_readable($values['theme']['dir'])) {
152 // TRANS: Client error in Paths admin panel.
153 // TRANS: %s is the directory that could not be read from.
154 $this->clientError(sprintf(_('Theme directory not readable: %s.'), $values['theme']['dir']));
157 // Validate avatar dir
159 if (empty($values['avatar']['dir']) || !is_writable($values['avatar']['dir'])) {
160 // TRANS: Client error in Paths admin panel.
161 // TRANS: %s is the avatar directory that could not be written to.
162 $this->clientError(sprintf(_('Avatar directory not writable: %s.'), $values['avatar']['dir']));
165 // Validate locales dir
167 // XXX: What else do we need to validate for lacales path here? --Z
169 if (!empty($values['site']['locale_path']) && !is_readable($values['site']['locale_path'])) {
170 // TRANS: Client error in Paths admin panel.
171 // TRANS: %s is the locales directory that could not be read from.
172 $this->clientError(sprintf(_('Locales directory not readable: %s.'), $values['site']['locale_path']));
175 // Validate SSL setup
177 if (mb_strlen($values['site']['sslserver']) > 255) {
178 // TRANS: Client error in Paths admin panel.
179 // TRANS: %s is the SSL server URL that is too long.
180 $this->clientError(_('Invalid SSL server. The maximum length is 255 characters.'));
185 class PathsAdminPanelForm extends AdminForm
190 * @return int ID of the form
194 return 'form_paths_admin_panel';
200 * @return string class of the form
204 return 'form_settings';
210 * @return string URL of the action
214 return common_local_url('pathsadminpanel');
218 * Data elements of the form
224 $this->out->elementStart('fieldset', array('id' => 'settings_paths_locale'));
225 // TRANS: Fieldset legend in Paths admin panel.
226 $this->out->element('legend', null, _('Site'), 'site');
227 $this->out->elementStart('ul', 'form_data');
230 $this->input('server',
231 // TRANS: Field label in Paths admin panel.
233 // TRANS: Field title in Paths admin panel.
234 _('Site\'s server hostname.'));
239 // TRANS: Field label in Paths admin panel.
241 // TRANS: Field title in Paths admin panel.
246 $this->input('locale_path',
247 // TRANS: Field label in Paths admin panel.
248 _('Locale directory'),
249 // TRANS: Field title in Paths admin panel.
250 _('Directory path to locales.'),
255 $this->out->checkbox('fancy',
256 // TRANS: Checkbox label in Paths admin panel.
258 (bool) $this->value('fancy'),
259 // TRANS: Field title in Paths admin panel.
260 _('Use fancy URLs (more readable and memorable)?'));
263 $this->out->elementEnd('ul');
264 $this->out->elementEnd('fieldset');
266 $this->out->elementStart('fieldset', array('id' => 'settings_paths_theme'));
267 // TRANS: Fieldset legend in Paths admin panel.
268 $this->out->element('legend', null, _m('LEGEND','Theme'));
270 $this->out->elementStart('ul', 'form_data');
273 $this->input('server',
274 // TRANS: Field label in Paths admin panel.
276 // TRANS: Tooltip for field label in Paths admin panel.
277 _('Server for themes.'),
283 // TRANS: Field label in Paths admin panel.
285 // TRANS: Tooltip for field label in Paths admin panel.
286 _('Web path to themes.'),
291 $this->input('sslserver',
292 // TRANS: Field label in Paths admin panel.
294 // TRANS: Tooltip for field label in Paths admin panel.
295 _('SSL server for themes (default: SSL server).'),
300 $this->input('sslpath',
301 // TRANS: Field label in Paths admin panel.
303 // TRANS: Tooltip for field label in Paths admin panel.
304 _('SSL path to themes (default: /theme/).'),
310 // TRANS: Field label in Paths admin panel.
312 // TRANS: Tooltip for field label in Paths admin panel.
313 _('Directory where themes are located.'),
317 $this->out->elementEnd('ul');
319 $this->out->elementEnd('fieldset');
320 $this->out->elementStart('fieldset', array('id' => 'settings_avatar-paths'));
321 // TRANS: Fieldset legend in Paths admin panel.
322 $this->out->element('legend', null, _('Avatars'));
324 $this->out->elementStart('ul', 'form_data');
327 $this->input('server',
328 // TRANS: Field label in Paths admin panel.
330 // TRANS: Tooltip for field label in Paths admin panel.
331 _('Server for avatars.'),
337 // TRANS: Field label in Paths admin panel.
339 // TRANS: Tooltip for field label in Paths admin panel.
340 _('Web path to avatars.'),
346 // TRANS: Field label in Paths admin panel.
347 _('Avatar directory'),
348 // TRANS: Tooltip for field label in Paths admin panel.
349 _('Directory where avatars are located.'),
353 $this->out->elementEnd('ul');
355 $this->out->elementEnd('fieldset');
357 $this->out->elementStart('fieldset', array('id' =>
358 'settings_attachments-paths'));
360 // TRANS: Fieldset legens in Paths admin panel.
361 $this->out->element('legend', null, _('Attachments'));
362 $this->out->elementStart('ul', 'form_data');
365 $this->input('server',
366 // TRANS: Field label in Paths admin panel.
368 // TRANS: Tooltip for field label in Paths admin panel.
369 _('Server for attachments.'),
375 // TRANS: Field label in Paths admin panel.
377 // TRANS: Tooltip for field label in Paths admin panel.
378 _('Web path to attachments.'),
383 $this->input('sslserver',
384 // TRANS: Field label in Paths admin panel.
386 // TRANS: Tooltip for field label in Paths admin panel.
387 _('Server for attachments on SSL pages.'),
392 $this->input('sslpath',
393 // TRANS: Field label in Paths admin panel.
395 // TRANS: Tooltip for field label in Paths admin panel.
396 _('Web path to attachments on SSL pages.'),
402 // TRANS: Field label in Paths admin panel.
404 // TRANS: Tooltip for field label in Paths admin panel.
405 _('Directory where attachments are located.'),
409 $this->out->elementEnd('ul');
410 $this->out->elementEnd('fieldset');
412 $this->out->elementStart('fieldset', array('id' => 'settings_admin_ssl'));
413 // TRANS: Fieldset legend in Paths admin panel.
414 $this->out->element('legend', null, _m('LEGEND','SSL'));
415 $this->out->elementStart('ul', 'form_data');
418 // TRANS: Drop down option in Paths admin panel (option for "When to use SSL").
419 $ssl = array('never' => _('Never'),
420 // TRANS: Drop down option in Paths admin panel (option for "When to use SSL").
421 'sometimes' => _('Sometimes'),
422 // TRANS: Drop down option in Paths admin panel (option for "When to use SSL").
423 'always' => _('Always'));
425 $this->out->dropdown('site-ssl',
426 // TRANS: Drop down label in Paths admin panel.
428 // TRANS: Tooltip for field label in Paths admin panel.
429 $ssl, _('When to use SSL.'),
431 $this->value('ssl', 'site'));
435 $this->input('sslserver',
436 // TRANS: Field label in Paths admin panel.
438 // TRANS: Tooltip for field label in Paths admin panel.
439 _('Server to direct SSL requests to.'),
442 $this->out->elementEnd('ul');
443 $this->out->elementEnd('fieldset');
451 function formActions()
453 // TRANS: Button text to store form data in the Paths admin panel.
454 $this->out->submit('save', _m('BUTTON','Save'), 'submit',
455 // TRANS: Button title text to store form data in the Paths admin panel.
456 'save', _('Save path settings.'));
460 * Utility to simplify some of the duplicated code around
461 * params and settings. Overriding the input() in the base class
462 * to handle a whole bunch of cases of settings with the same
463 * name under different sections.
465 * @param string $setting Name of the setting
466 * @param string $title Title to use for the input
467 * @param string $instructions Instructions for this field
468 * @param string $section config section, default = 'site'
472 function input($setting, $title, $instructions, $section='site')
474 $this->out->input("$section-$setting", $title, $this->value($setting, $section), $instructions);