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-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')) {
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/
47 class SiteadminpanelAction extends AdminPanelAction
50 * Returns the page title
52 * @return string page title
56 // TRANS: Title for site administration panel.
57 return _m('TITLE','Site');
61 * Instructions for using this form.
63 * @return string instructions
65 function getInstructions()
67 // TRANS: Instructions for site administration panel.
68 return _('Basic settings for this StatusNet site');
72 * Show the site admin panel form
78 $form = new SiteAdminPanelForm($this);
84 * Save settings from the form
88 function saveSettings()
90 static $settings = array(
91 'site' => array('name', 'broughtby', 'broughtbyurl',
92 'email', 'timezone', 'language',
93 'site', 'textlimit', 'dupelimit'),
98 foreach ($settings as $section => $parts) {
99 foreach ($parts as $setting) {
100 $values[$section][$setting] = $this->trimmed($setting);
104 // This throws an exception on validation errors
106 $this->validate($values);
108 // assert(all values are valid);
110 $config = new Config();
112 $config->query('BEGIN');
114 foreach ($settings as $section => $parts) {
115 foreach ($parts as $setting) {
116 Config::save($section, $setting, $values[$section][$setting]);
120 $config->query('COMMIT');
125 function validate(&$values)
127 // Validate site name
129 if (empty($values['site']['name'])) {
130 // TRANS: Client error displayed trying to save an empty site name.
131 $this->clientError(_('Site name must have non-zero length.'));
136 $values['site']['email'] = common_canonical_email($values['site']['email']);
138 if (empty($values['site']['email'])) {
139 // TRANS: Client error displayed trying to save site settings without a contact address.
140 $this->clientError(_('You must have a valid contact email address.'));
142 if (!Validate::email($values['site']['email'], common_config('email', 'check_domain'))) {
143 // TRANS: Client error displayed trying to save site settings without a valid contact address.
144 $this->clientError(_('Not a valid email address.'));
149 if (is_null($values['site']['timezone']) ||
150 !in_array($values['site']['timezone'], DateTimeZone::listIdentifiers())) {
151 // TRANS: Client error displayed trying to save site settings without a timezone.
152 $this->clientError(_('Timezone not selected.'));
158 if (!is_null($values['site']['language']) &&
159 !in_array($values['site']['language'], array_keys(get_nice_language_list()))) {
160 // TRANS: Client error displayed trying to save site settings with an invalid language code.
161 // TRANS: %s is the invalid language code.
162 $this->clientError(sprintf(_('Unknown language "%s".'), $values['site']['language']));
165 // Validate text limit
167 if (!Validate::number($values['site']['textlimit'], array('min' => 0))) {
168 // TRANS: Client error displayed trying to save site settings with a text limit below 0.
169 $this->clientError(_('Minimum text limit is 0 (unlimited).'));
172 // Validate dupe limit
174 if (!Validate::number($values['site']['dupelimit'], array('min' => 1))) {
175 // TRANS: Client error displayed trying to save site settings with a text limit below 1.
176 $this->clientError(_("Dupe limit must be one or more seconds."));
181 // @todo FIXME: Class documentation missing.
182 class SiteAdminPanelForm extends AdminForm
187 * @return int ID of the form
191 return 'form_site_admin_panel';
197 * @return string class of the form
201 return 'form_settings';
207 * @return string URL of the action
211 return common_local_url('siteadminpanel');
215 * Data elements of the form
221 $this->out->elementStart('fieldset', array('id' => 'settings_admin_general'));
222 // TRANS: Fieldset legend on site settings panel.
223 $this->out->element('legend', null, _m('LEGEND','General'));
224 $this->out->elementStart('ul', 'form_data');
226 // TRANS: Field label on site settings panel.
227 $this->input('name', _m('LABEL','Site name'),
228 // TRANS: Field title on site settings panel.
229 _('The name of your site, like "Yourcompany Microblog".'));
233 // TRANS: Field label on site settings panel.
234 $this->input('broughtby', _('Brought by'),
235 // TRANS: Field title on site settings panel.
236 _('Text used for credits link in footer of each page.'));
240 // TRANS: Field label on site settings panel.
241 $this->input('broughtbyurl', _('Brought by URL'),
242 // TRANS: Field title on site settings panel.
243 _('URL used for credits link in footer of each page.'));
246 // TRANS: Field label on site settings panel.
247 $this->input('email', _('Email'),
248 // TRANS: Field title on site settings panel.
249 _('Contact email address for your site.'));
251 $this->out->elementEnd('ul');
252 $this->out->elementEnd('fieldset');
254 $this->out->elementStart('fieldset', array('id' => 'settings_admin_local'));
255 // TRANS: Fieldset legend on site settings panel.
256 $this->out->element('legend', null, _m('LEGEND','Local'));
257 $this->out->elementStart('ul', 'form_data');
258 $timezones = array();
260 foreach (DateTimeZone::listIdentifiers() as $k => $v) {
267 // TRANS: Dropdown label on site settings panel.
268 $this->out->dropdown('timezone', _('Default timezone'),
269 // TRANS: Dropdown title on site settings panel.
270 $timezones, _('Default timezone for the site; usually UTC.'),
271 true, $this->value('timezone'));
275 $this->out->dropdown('language',
276 // TRANS: Dropdown label on site settings panel.
277 _('Default language'),
278 get_nice_language_list(),
279 // TRANS: Dropdown title on site settings panel.
280 _('Site language when autodetection from browser settings is not available'),
281 false, $this->value('language'));
284 $this->out->elementEnd('ul');
285 $this->out->elementEnd('fieldset');
287 $this->out->elementStart('fieldset', array('id' => 'settings_admin_limits'));
288 // TRANS: Fieldset legend on site settings panel.
289 $this->out->element('legend', null, _m('LEGEND','Limits'));
290 $this->out->elementStart('ul', 'form_data');
292 $this->input('textlimit',
293 // TRANS: Field label on site settings panel.
295 // TRANS: Field title on site settings panel.
296 _('Maximum number of characters for notices.'));
300 $this->input('dupelimit',
301 // TRANS: Field label on site settings panel.
303 // TRANS: Field title on site settings panel.
304 _('How long users must wait (in seconds) to post the same thing again.'));
306 $this->out->elementEnd('ul');
307 $this->out->elementEnd('fieldset');
315 function formActions()
317 $this->out->submit('submit',
318 // TRANS: Button text for saving site settings.
322 // TRANS: Button title for saving site settings.
323 _('Save site settings'));