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'),
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']));
167 class PathsAdminPanelForm extends AdminForm
173 * @return int ID of the form
178 return 'form_paths_admin_panel';
184 * @return string class of the form
189 return 'form_settings';
195 * @return string URL of the action
200 return common_local_url('pathsadminpanel');
204 * Data elements of the form
211 $this->out->elementStart('fieldset', array('id' => 'settings_paths_locale'));
212 $this->out->element('legend', null, _('Site'), 'site');
213 $this->out->elementStart('ul', 'form_data');
216 $this->input('path', _('Path'), _('Site path'));
220 $this->input('locale_path', _('Path to locales'), _('Directory path to locales'), 'site');
223 $this->out->elementEnd('ul');
224 $this->out->elementEnd('fieldset');
226 $this->out->elementStart('fieldset', array('id' => 'settings_paths_theme'));
227 $this->out->element('legend', null, _('Theme'));
229 $this->out->elementStart('ul', 'form_data');
232 $this->input('server', _('Theme server'), 'Server for themes', 'theme');
236 $this->input('path', _('Theme path'), 'Web path to themes', 'theme');
240 $this->input('dir', _('Theme directory'), 'Directory where themes are located', 'theme');
243 $this->out->elementEnd('ul');
245 $this->out->elementEnd('fieldset');
246 $this->out->elementStart('fieldset', array('id' => 'settings_avatar-paths'));
247 $this->out->element('legend', null, _('Avatars'));
249 $this->out->elementStart('ul', 'form_data');
252 $this->input('server', _('Avatar server'), 'Server for avatars', 'avatar');
256 $this->input('path', _('Avatar path'), 'Web path to avatars', 'avatar');
260 $this->input('dir', _('Avatar directory'), 'Directory where avatars are located', 'avatar');
263 $this->out->elementEnd('ul');
265 $this->out->elementEnd('fieldset');
267 $this->out->elementStart('fieldset', array('id' =>
268 'settings_design_background-paths'));
269 $this->out->element('legend', null, _('Backgrounds'));
270 $this->out->elementStart('ul', 'form_data');
273 $this->input('server', _('Background server'), 'Server for backgrounds', 'background');
277 $this->input('path', _('Background path'), 'Web path to backgrounds', 'background');
281 $this->input('dir', _('Background directory'), 'Directory where backgrounds are located', 'background');
284 $this->out->elementEnd('ul');
285 $this->out->elementEnd('fieldset');
294 function formActions()
296 $this->out->submit('save', _('Save'), 'submit',
297 'save', _('Save paths'));
302 * Utility to simplify some of the duplicated code around
303 * params and settings. Overriding the input() in the base class
304 * to handle a whole bunch of cases of settings with the same
305 * name under different sections.
307 * @param string $setting Name of the setting
308 * @param string $title Title to use for the input
309 * @param string $instructions Instructions for this field
310 * @param string $section config section, default = 'site'
315 function input($setting, $title, $instructions, $section='site')
317 $this->out->input("$section-$setting", $title, $this->value($setting, $section), $instructions);