3 * StatusNet, the distributed open-source microblogging tool
5 * Design 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')) {
37 * Administer design settings
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 DesignadminpanelAction extends AdminPanelAction
51 * Returns the page title
53 * @return string page title
62 * Instructions for using this form.
64 * @return string instructions
67 function getInstructions()
69 return _('Design settings for this StatusNet site.');
73 * Show the site admin panel form
80 $form = new DesignAdminPanelForm($this);
86 * Save settings from the form
91 function saveSettings()
93 static $settings = array('theme');
97 foreach ($settings as $setting) {
98 $values[$setting] = $this->trimmed($setting);
101 // This throws an exception on validation errors
103 $this->validate($values);
105 // assert(all values are valid);
107 $config = new Config();
109 $config->query('BEGIN');
111 foreach ($settings as $setting) {
112 Config::save('site', $setting, $values[$setting]);
115 $config->query('COMMIT');
120 function validate(&$values)
122 if (!in_array($values['theme'], Theme::listAvailable())) {
123 $this->clientError(sprintf(_("Theme not available: %s"), $values['theme']));
128 class DesignAdminPanelForm extends Form
133 * @return int ID of the form
138 return 'designadminpanel';
144 * @return string class of the form
149 return 'form_design_admin_panel';
155 * @return string URL of the action
160 return common_local_url('designadminpanel');
164 * Data elements of the form
171 $themes = Theme::listAvailable();
175 $themes = array_combine($themes, $themes);
177 $this->out->elementStart('ul');
178 $this->out->elementStart('li');
180 $this->out->dropdown('theme', _('Theme'),
181 $themes, _('Theme for the site.'),
182 true, $this->value('theme'));
184 $this->out->elementEnd('li');
185 $this->out->elementEnd('ul');
189 * Utility to simplify some of the duplicated code around
190 * params and settings.
192 * @param string $setting Name of the setting
193 * @param string $title Title to use for the input
194 * @param string $instructions Instructions for this field
199 function input($setting, $title, $instructions)
201 $this->out->input($setting, $title, $this->value($setting), $instructions);
205 * Utility to simplify getting the posted-or-stored setting value
207 * @param string $setting Name of the setting
209 * @return string param value if posted, or current config value
212 function value($setting)
214 $value = $this->out->trimmed($setting);
216 $value = common_config('site', $setting);
227 function formActions()
229 $this->out->submit('submit', _('Save'), 'submit', null, _('Save site settings'));