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-2011 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(
108 foreach ($settings as $section => $parts) {
109 foreach ($parts as $setting) {
110 $values[$section][$setting] = $this->trimmed($setting);
114 // This throws an exception on validation errors
116 $this->validate($values);
118 // assert(all values are valid);
120 $config = new Config();
122 $config->query('BEGIN');
124 foreach ($settings as $section => $parts) {
125 foreach ($parts as $setting) {
126 Config::save($section, $setting, $values[$section][$setting]);
130 $config->query('COMMIT');
135 function validate(&$values)
137 // Validate site name
139 if (empty($values['site']['name'])) {
140 // TRANS: Client error displayed trying to save an empty site name.
141 $this->clientError(_('Site name must have non-zero length.'));
146 $values['site']['email'] = common_canonical_email($values['site']['email']);
148 if (empty($values['site']['email'])) {
149 // TRANS: Client error displayed trying to save site settings without a contact address.
150 $this->clientError(_('You must have a valid contact email address.'));
152 if (!Validate::email($values['site']['email'], common_config('email', 'check_domain'))) {
153 // TRANS: Client error displayed trying to save site settings without a valid contact address.
154 $this->clientError(_('Not a valid email address.'));
158 if (!empty($values['site']['logo']) &&
159 !common_valid_http_url($values['site']['logo'])) {
160 // TRANS: Client error displayed when a logo URL is not valid.
161 $this->clientError(_('Invalid logo URL.'));
164 if (!empty($values['site']['ssllogo']) &&
165 !common_valid_http_url($values['site']['ssllogo'], true)) {
166 // TRANS: Client error displayed when a SSL logo URL is invalid.
167 $this->clientError(_('Invalid SSL logo URL.'));
172 if (is_null($values['site']['timezone']) ||
173 !in_array($values['site']['timezone'], DateTimeZone::listIdentifiers())) {
174 // TRANS: Client error displayed trying to save site settings without a timezone.
175 $this->clientError(_('Timezone not selected.'));
180 if (!is_null($values['site']['language']) &&
181 !in_array($values['site']['language'], array_keys(get_nice_language_list()))) {
182 // TRANS: Client error displayed trying to save site settings with an invalid language code.
183 // TRANS: %s is the invalid language code.
184 $this->clientError(sprintf(_('Unknown language "%s".'), $values['site']['language']));
187 // Validate text limit
189 if (!Validate::number($values['site']['textlimit'], array('min' => 0))) {
190 // TRANS: Client error displayed trying to save site settings with a text limit below 0.
191 $this->clientError(_('Minimum text limit is 0 (unlimited).'));
194 // Validate dupe limit
196 if (!Validate::number($values['site']['dupelimit'], array('min' => 1))) {
197 // TRANS: Client error displayed trying to save site settings with a text limit below 1.
198 $this->clientError(_('Dupe limit must be one or more seconds.'));
203 // @todo FIXME: Class documentation missing.
204 class SiteAdminPanelForm extends AdminForm
209 * @return int ID of the form
213 return 'form_site_admin_panel';
219 * @return string class of the form
223 return 'form_settings';
229 * @return string URL of the action
233 return common_local_url('siteadminpanel');
237 * Data elements of the form
243 $this->out->elementStart('fieldset', array('id' => 'settings_admin_general'));
244 // TRANS: Fieldset legend on site settings panel.
245 $this->out->element('legend', null, _m('LEGEND','General'));
246 $this->out->elementStart('ul', 'form_data');
248 // TRANS: Field label on site settings panel.
249 $this->input('name', _m('LABEL','Site name'),
250 // TRANS: Field title on site settings panel.
251 _('The name of your site, like "Yourcompany Microblog".'));
255 // TRANS: Field label on site settings panel.
256 $this->input('broughtby', _('Brought by'),
257 // TRANS: Field title on site settings panel.
258 _('Text used for credits link in footer of each page.'));
262 // TRANS: Field label on site settings panel.
263 $this->input('broughtbyurl', _('Brought by URL'),
264 // TRANS: Field title on site settings panel.
265 _('URL used for credits link in footer of each page.'));
268 // TRANS: Field label on site settings panel.
269 $this->input('email', _('Email'),
270 // TRANS: Field title on site settings panel.
271 _('Contact email address for your site.'));
273 $this->out->elementEnd('ul');
274 $this->out->elementEnd('fieldset');
278 $this->out->elementStart('fieldset', array('id' => 'settings_admin_local'));
279 // TRANS: Fieldset legend on site settings panel.
280 $this->out->element('legend', null, _m('LEGEND','Local'));
281 $this->out->elementStart('ul', 'form_data');
282 $timezones = array();
284 foreach (DateTimeZone::listIdentifiers() as $k => $v) {
291 // TRANS: Dropdown label on site settings panel.
292 $this->out->dropdown('timezone', _('Default timezone'),
293 // TRANS: Dropdown title on site settings panel.
294 $timezones, _('Default timezone for the site; usually UTC.'),
295 true, $this->value('timezone'));
299 $this->out->dropdown('language',
300 // TRANS: Dropdown label on site settings panel.
301 _('Default language'),
302 get_nice_language_list(),
303 // TRANS: Dropdown title on site settings panel.
304 _('The site language when autodetection from browser settings is not available.'),
305 false, $this->value('language'));
308 $this->out->elementEnd('ul');
309 $this->out->elementEnd('fieldset');
311 $this->out->elementStart('fieldset', array('id' => 'settings_admin_limits'));
312 // TRANS: Fieldset legend on site settings panel.
313 $this->out->element('legend', null, _m('LEGEND','Limits'));
314 $this->out->elementStart('ul', 'form_data');
316 $this->input('textlimit',
317 // TRANS: Field label on site settings panel.
319 // TRANS: Field title on site settings panel.
320 _('Maximum number of characters for notices.'));
324 $this->input('dupelimit',
325 // TRANS: Field label on site settings panel.
327 // TRANS: Field title on site settings panel.
328 _('How long users must wait (in seconds) to post the same thing again.'));
330 $this->out->elementEnd('ul');
331 $this->out->elementEnd('fieldset');
336 $this->out->elementStart('fieldset', array('id' => 'settings_site_logo'));
337 // TRANS: Fieldset legend for form to change logo.
338 $this->out->element('legend', null, _('Logo'));
340 $this->out->elementStart('ul', 'form_data');
344 // TRANS: Field label for StatusNet site logo.
346 // TRANS: Title for field label for StatusNet site logo.
347 'Logo for the site (full URL).');
351 $this->input('ssllogo',
352 // TRANS: Field label for SSL StatusNet site logo.
354 // TRANS: Title for field label for SSL StatusNet site logo.
355 'Logo to show on SSL pages (full URL).');
358 $this->out->elementEnd('ul');
360 $this->out->elementEnd('fieldset');
368 function formActions()
370 $this->out->submit('submit',
371 // TRANS: Button text for saving site settings.
375 // TRANS: Button title for saving site settings.
376 _('Save the site settings.'));