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/
48 class PathsadminpanelAction extends AdminPanelAction
52 * Returns the page title
54 * @return string page title
63 * Instructions for using this form.
65 * @return string instructions
68 function getInstructions()
70 return _('Path and server settings for this StatusNet site');
74 * Show the paths admin panel form
81 $form = new PathsAdminPanelForm($this);
87 * Save settings from the form
92 function saveSettings()
94 static $settings = array(
95 'site' => array('path', 'locale_path', 'ssl', 'sslserver'),
96 'theme' => array('server', 'dir', 'path', 'sslserver', 'sslpath'),
97 'avatar' => array('server', 'dir', 'path'),
98 'background' => array('server', 'dir', 'path', 'sslserver', 'sslpath'),
99 'attachments' => array('server', 'dir', 'path', 'sslserver', 'sslpath')
102 // XXX: If we're only going to have one boolean on thi page we
103 // can remove some of the boolean processing code --Z
105 static $booleans = array('site' => array('fancy'));
109 foreach ($settings as $section => $parts) {
110 foreach ($parts as $setting) {
111 $values[$section][$setting] = $this->trimmed("$section-$setting");
115 foreach ($booleans as $section => $parts) {
116 foreach ($parts as $setting) {
117 $values[$section][$setting] = ($this->boolean($setting)) ? 1 : 0;
121 $this->validate($values);
123 // assert(all values are valid);
125 $config = new Config();
127 $config->query('BEGIN');
129 foreach ($settings as $section => $parts) {
130 foreach ($parts as $setting) {
131 Config::save($section, $setting, $values[$section][$setting]);
135 foreach ($booleans as $section => $parts) {
136 foreach ($parts as $setting) {
137 Config::save($section, $setting, $values[$section][$setting]);
141 $config->query('COMMIT');
147 * Attempt to validate setting values
152 function validate(&$values)
155 // Validate theme dir
157 if (!empty($values['theme']['dir']) && !is_readable($values['theme']['dir'])) {
158 $this->clientError(sprintf(_("Theme directory not readable: %s."), $values['theme']['dir']));
161 // Validate avatar dir
163 if (empty($values['avatar']['dir']) || !is_writable($values['avatar']['dir'])) {
164 $this->clientError(sprintf(_("Avatar directory not writable: %s."), $values['avatar']['dir']));
167 // Validate background dir
169 if (empty($values['background']['dir']) || !is_writable($values['background']['dir'])) {
170 $this->clientError(sprintf(_("Background directory not writable: %s."), $values['background']['dir']));
173 // Validate locales dir
175 // XXX: What else do we need to validate for lacales path here? --Z
177 if (!empty($values['site']['locale_path']) && !is_readable($values['site']['locale_path'])) {
178 $this->clientError(sprintf(_("Locales directory not readable: %s."), $values['site']['locale_path']));
181 // Validate SSL setup
183 if (mb_strlen($values['site']['sslserver']) > 255) {
184 $this->clientError(_('Invalid SSL server. The maximum length is 255 characters.'));
190 class PathsAdminPanelForm extends AdminForm
196 * @return int ID of the form
201 return 'form_paths_admin_panel';
207 * @return string class of the form
212 return 'form_settings';
218 * @return string URL of the action
223 return common_local_url('pathsadminpanel');
227 * Data elements of the form
234 $this->out->elementStart('fieldset', array('id' => 'settings_paths_locale'));
235 $this->out->element('legend', null, _('Site'), 'site');
236 $this->out->elementStart('ul', 'form_data');
239 $this->input('server', _('Server'), _('Site\'s server hostname.'));
243 $this->input('path', _('Path'), _('Site path'));
247 $this->input('locale_path', _('Locale Directory'), _('Directory path to locales'), 'site');
251 $this->out->checkbox('fancy', _('Fancy URLs'),
252 (bool) $this->value('fancy'),
253 _('Use fancy (more readable and memorable) URLs?'));
256 $this->out->elementEnd('ul');
257 $this->out->elementEnd('fieldset');
259 $this->out->elementStart('fieldset', array('id' => 'settings_paths_theme'));
260 $this->out->element('legend', null, _('Theme'));
262 $this->out->elementStart('ul', 'form_data');
265 $this->input('server', _('Server'), _('Server for themes'), 'theme');
269 $this->input('path', _('Path'), _('Web path to themes'), 'theme');
273 $this->input('sslserver', _('SSL server'), _('SSL server for themes (default: SSL server)'), 'theme');
277 $this->input('sslpath', _('SSL path'), _('SSL path to themes (default: /theme/)'), 'theme');
281 $this->input('dir', _('Directory'), _('Directory where themes are located'), 'theme');
284 $this->out->elementEnd('ul');
286 $this->out->elementEnd('fieldset');
287 $this->out->elementStart('fieldset', array('id' => 'settings_avatar-paths'));
288 $this->out->element('legend', null, _('Avatars'));
290 $this->out->elementStart('ul', 'form_data');
293 $this->input('server', _('Avatar server'), 'Server for avatars', 'avatar');
297 $this->input('path', _('Avatar path'), 'Web path to avatars', 'avatar');
301 $this->input('dir', _('Avatar directory'), 'Directory where avatars are located', 'avatar');
304 $this->out->elementEnd('ul');
306 $this->out->elementEnd('fieldset');
308 $this->out->elementStart('fieldset', array('id' =>
309 'settings_design_background-paths'));
310 $this->out->element('legend', null, _('Backgrounds'));
311 $this->out->elementStart('ul', 'form_data');
314 $this->input('server', _('Server'), 'Server for backgrounds', 'background');
318 $this->input('path', _('Path'), 'Web path to backgrounds', 'background');
322 $this->input('sslserver', _('SSL server'), 'Server for backgrounds on SSL pages', 'background');
326 $this->input('sslpath', _('SSL path'), 'Web path to backgrounds on SSL pages', 'background');
330 $this->input('dir', _('Directory'), 'Directory where backgrounds are located', 'background');
333 $this->out->elementEnd('ul');
334 $this->out->elementEnd('fieldset');
336 $this->out->elementStart('fieldset', array('id' =>
337 'settings_design_attachments-paths'));
339 $this->out->element('legend', null, _('Attachments'));
340 $this->out->elementStart('ul', 'form_data');
343 $this->input('server', _('Server'), 'Server for attachments', 'attachments');
347 $this->input('path', _('Path'), 'Web path to attachments', 'attachments');
351 $this->input('sslserver', _('SSL server'), 'Server for attachments on SSL pages', 'attachments');
355 $this->input('sslpath', _('SSL path'), 'Web path to attachments on SSL pages', 'attachments');
359 $this->input('dir', _('Directory'), 'Directory where attachments are located', 'attachments');
362 $this->out->elementEnd('ul');
363 $this->out->elementEnd('fieldset');
365 $this->out->elementStart('fieldset', array('id' => 'settings_admin_ssl'));
366 $this->out->element('legend', null, _('SSL'));
367 $this->out->elementStart('ul', 'form_data');
370 $ssl = array('never' => _('Never'),
371 'sometimes' => _('Sometimes'),
372 'always' => _('Always'));
374 $this->out->dropdown('site-ssl', _('Use SSL'),
375 $ssl, _('When to use SSL'),
376 false, $this->value('ssl', 'site'));
380 $this->input('sslserver', _('SSL server'),
381 _('Server to direct SSL requests to'), 'site');
383 $this->out->elementEnd('ul');
384 $this->out->elementEnd('fieldset');
394 function formActions()
396 $this->out->submit('save', _('Save'), 'submit',
397 'save', _('Save paths'));
401 * Utility to simplify some of the duplicated code around
402 * params and settings. Overriding the input() in the base class
403 * to handle a whole bunch of cases of settings with the same
404 * name under different sections.
406 * @param string $setting Name of the setting
407 * @param string $title Title to use for the input
408 * @param string $instructions Instructions for this field
409 * @param string $section config section, default = 'site'
414 function input($setting, $title, $instructions, $section='site')
416 $this->out->input("$section-$setting", $title, $this->value($setting, $section), $instructions);