3 * StatusNet, the distributed open-source microblogging tool
5 * Site 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 site 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 SiteadminpanelAction 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 _('Basic settings for this StatusNet site.');
73 * Show the site admin panel form
80 $form = new SiteAdminPanelForm($this);
86 * Save settings from the form
91 function saveSettings()
93 static $settings = array('name', 'broughtby', 'broughtbyurl',
94 'email', 'timezone', 'language');
98 foreach ($settings as $setting) {
99 $values[$setting] = $this->trimmed($setting);
102 // This throws an exception on validation errors
104 $this->validate($values);
106 // assert(all values are valid);
108 $config = new Config();
110 $config->query('BEGIN');
112 foreach ($settings as $setting) {
113 Config::save('site', $setting, $values[$setting]);
116 $config->query('COMMIT');
121 function validate(&$values)
123 // Validate site name
125 if (empty($values['name'])) {
126 $this->clientError(_("Site name must have non-zero length."));
131 $values['email'] = common_canonical_email($values['email']);
133 if (empty($values['email'])) {
134 $this->clientError(_('You must have a valid contact email address'));
136 if (!Validate::email($values['email'], common_config('email', 'check_domain'))) {
137 $this->clientError(_('Not a valid email address'));
142 if (is_null($values['timezone']) ||
143 !in_array($values['timezone'], DateTimeZone::listIdentifiers())) {
144 $this->clientError(_('Timezone not selected.'));
150 if (!is_null($language) && !in_array($language, array_keys(get_nice_language_list()))) {
151 $this->clientError(sprintf(_('Unknown language "%s"'), $language));
156 class SiteAdminPanelForm extends Form
161 * @return int ID of the form
166 return 'siteadminpanel';
172 * @return string class of the form
177 return 'form_site_admin_panel';
183 * @return string URL of the action
188 return common_local_url('siteadminpanel');
192 * Data elements of the form
199 $this->input('name', _('Site name'),
200 _('The name of your site, like "Yourcompany Microblog"'));
201 $this->input('broughtby', _('Brought by'),
202 _('Text used for credits link in footer of each page'));
203 $this->input('broughtbyurl', _('Brought by URL'),
204 _('URL used for credits link in footer of each page'));
205 $this->input('email', _('Email'),
206 _('contact email address for your site'));
208 $timezones = array();
210 foreach (DateTimeZone::listIdentifiers() as $k => $v) {
216 $this->out->dropdown('timezone', _('Default timezone'),
217 $timezones, _('Default timezone for the site; usually UTC.'),
218 true, $this->value('timezone'));
220 $this->out->dropdown('language', _('Language'),
221 get_nice_language_list(), _('Default site language'),
222 false, $this->value('language'));
226 * Utility to simplify some of the duplicated code around
227 * params and settings.
229 * @param string $setting Name of the setting
230 * @param string $title Title to use for the input
231 * @param string $instructions Instructions for this field
236 function input($setting, $title, $instructions)
238 $this->out->input($setting, $title, $this->value($setting), $instructions);
242 * Utility to simplify getting the posted-or-stored setting value
244 * @param string $setting Name of the setting
246 * @return string param value if posted, or current config value
249 function value($setting)
251 $value = $this->out->trimmed($setting);
253 $value = common_config('site', $setting);
264 function formActions()
266 $this->out->submit('submit', _('Save'), 'submit', null, _('Save site settings'));