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-2009 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'),
97 'avatar' => array('server', 'dir', 'path'),
98 'background' => array('server', 'dir', 'path')
103 foreach ($settings as $section => $parts) {
104 foreach ($parts as $setting) {
105 $values[$section][$setting] = $this->trimmed("$section-$setting");
109 $this->validate($values);
111 // assert(all values are valid);
113 $config = new Config();
115 $config->query('BEGIN');
117 foreach ($settings as $section => $parts) {
118 foreach ($parts as $setting) {
119 Config::save($section, $setting, $values[$section][$setting]);
123 $config->query('COMMIT');
129 * Attempt to validate setting values
134 function validate(&$values)
137 // Validate theme dir
139 if (!empty($values['theme']['dir']) && !is_readable($values['theme']['dir'])) {
140 $this->clientError(sprintf(_("Theme directory not readable: %s"), $values['theme']['dir']));
143 // Validate avatar dir
145 if (empty($values['avatar']['dir']) || !is_writable($values['avatar']['dir'])) {
146 $this->clientError(sprintf(_("Avatar directory not writable: %s"), $values['avatar']['dir']));
149 // Validate background dir
151 if (empty($values['background']['dir']) || !is_writable($values['background']['dir'])) {
152 $this->clientError(sprintf(_("Background directory not writable: %s"), $values['background']['dir']));
155 // Validate locales dir
157 // XXX: What else do we need to validate for lacales path here? --Z
159 if (!empty($values['site']['locale_path']) && !is_readable($values['site']['locale_path'])) {
160 $this->clientError(sprintf(_("Locales directory not readable: %s"), $values['site']['locale_path']));
163 // Validate SSL setup
165 if (in_array($values['site']['ssl'], array('sometimes', 'always'))) {
166 if (empty($values['site']['sslserver'])) {
167 $this->clientError(_("You must set an SSL server when enabling SSL."));
175 class PathsAdminPanelForm extends AdminForm
181 * @return int ID of the form
186 return 'form_paths_admin_panel';
192 * @return string class of the form
197 return 'form_settings';
203 * @return string URL of the action
208 return common_local_url('pathsadminpanel');
212 * Data elements of the form
219 $this->out->elementStart('fieldset', array('id' => 'settings_paths_locale'));
220 $this->out->element('legend', null, _('Site'), 'site');
221 $this->out->elementStart('ul', 'form_data');
224 $this->input('path', _('Path'), _('Site path'));
228 $this->input('locale_path', _('Path to locales'), _('Directory path to locales'), 'site');
231 $this->out->elementEnd('ul');
232 $this->out->elementEnd('fieldset');
234 $this->out->elementStart('fieldset', array('id' => 'settings_paths_theme'));
235 $this->out->element('legend', null, _('Theme'));
237 $this->out->elementStart('ul', 'form_data');
240 $this->input('server', _('Theme server'), 'Server for themes', 'theme');
244 $this->input('path', _('Theme path'), 'Web path to themes', 'theme');
248 $this->input('dir', _('Theme directory'), 'Directory where themes are located', 'theme');
251 $this->out->elementEnd('ul');
253 $this->out->elementEnd('fieldset');
254 $this->out->elementStart('fieldset', array('id' => 'settings_avatar-paths'));
255 $this->out->element('legend', null, _('Avatars'));
257 $this->out->elementStart('ul', 'form_data');
260 $this->input('server', _('Avatar server'), 'Server for avatars', 'avatar');
264 $this->input('path', _('Avatar path'), 'Web path to avatars', 'avatar');
268 $this->input('dir', _('Avatar directory'), 'Directory where avatars are located', 'avatar');
271 $this->out->elementEnd('ul');
273 $this->out->elementEnd('fieldset');
275 $this->out->elementStart('fieldset', array('id' =>
276 'settings_design_background-paths'));
277 $this->out->element('legend', null, _('Backgrounds'));
278 $this->out->elementStart('ul', 'form_data');
281 $this->input('server', _('Background server'), 'Server for backgrounds', 'background');
285 $this->input('path', _('Background path'), 'Web path to backgrounds', 'background');
289 $this->input('dir', _('Background directory'), 'Directory where backgrounds are located', 'background');
292 $this->out->elementEnd('ul');
293 $this->out->elementEnd('fieldset');
295 $this->out->elementStart('fieldset', array('id' => 'settings_admin_ssl'));
296 $this->out->element('legend', null, _('SSL'));
297 $this->out->elementStart('ul', 'form_data');
299 $ssl = array('never' => _('Never'),
300 'sometimes' => _('Sometimes'),
301 'always' => _('Always'));
303 common_debug("site ssl = " . $this->value('site', 'ssl'));
305 $this->out->dropdown('site-ssl', _('Use SSL'),
306 $ssl, _('When to use SSL'),
307 false, $this->value('ssl', 'site'));
311 $this->input('sslserver', _('SSL Server'),
312 _('Server to direct SSL requests to'), 'site');
314 $this->out->elementEnd('ul');
315 $this->out->elementEnd('fieldset');
325 function formActions()
327 $this->out->submit('save', _('Save'), 'submit',
328 'save', _('Save paths'));
332 * Utility to simplify some of the duplicated code around
333 * params and settings. Overriding the input() in the base class
334 * to handle a whole bunch of cases of settings with the same
335 * name under different sections.
337 * @param string $setting Name of the setting
338 * @param string $title Title to use for the input
339 * @param string $instructions Instructions for this field
340 * @param string $section config section, default = 'site'
345 function input($setting, $title, $instructions, $section='site')
347 $this->out->input("$section-$setting", $title, $this->value($setting, $section), $instructions);