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 !Validate::uri($values['site']['logo'], array('allowed_schemes' => array('http', 'https')))) {
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 !Validate::uri($values['site']['ssllogo'], array('allowed_schemes' => array('https')))) {
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.'));
181 if (!is_null($values['site']['language']) &&
182 !in_array($values['site']['language'], array_keys(get_nice_language_list()))) {
183 // TRANS: Client error displayed trying to save site settings with an invalid language code.
184 // TRANS: %s is the invalid language code.
185 $this->clientError(sprintf(_('Unknown language "%s".'), $values['site']['language']));
188 // Validate text limit
190 if (!Validate::number($values['site']['textlimit'], array('min' => 0))) {
191 // TRANS: Client error displayed trying to save site settings with a text limit below 0.
192 $this->clientError(_('Minimum text limit is 0 (unlimited).'));
195 // Validate dupe limit
197 if (!Validate::number($values['site']['dupelimit'], array('min' => 1))) {
198 // TRANS: Client error displayed trying to save site settings with a text limit below 1.
199 $this->clientError(_('Dupe limit must be one or more seconds.'));
204 // @todo FIXME: Class documentation missing.
205 class SiteAdminPanelForm extends AdminForm
210 * @return int ID of the form
214 return 'form_site_admin_panel';
220 * @return string class of the form
224 return 'form_settings';
230 * @return string URL of the action
234 return common_local_url('siteadminpanel');
238 * Data elements of the form
244 $this->out->elementStart('fieldset', array('id' => 'settings_admin_general'));
245 // TRANS: Fieldset legend on site settings panel.
246 $this->out->element('legend', null, _m('LEGEND','General'));
247 $this->out->elementStart('ul', 'form_data');
249 // TRANS: Field label on site settings panel.
250 $this->input('name', _m('LABEL','Site name'),
251 // TRANS: Field title on site settings panel.
252 _('The name of your site, like "Yourcompany Microblog".'));
256 // TRANS: Field label on site settings panel.
257 $this->input('broughtby', _('Brought by'),
258 // TRANS: Field title on site settings panel.
259 _('Text used for credits link in footer of each page.'));
263 // TRANS: Field label on site settings panel.
264 $this->input('broughtbyurl', _('Brought by URL'),
265 // TRANS: Field title on site settings panel.
266 _('URL used for credits link in footer of each page.'));
269 // TRANS: Field label on site settings panel.
270 $this->input('email', _('Email'),
271 // TRANS: Field title on site settings panel.
272 _('Contact email address for your site.'));
274 $this->out->elementEnd('ul');
275 $this->out->elementEnd('fieldset');
279 $this->out->elementStart('fieldset', array('id' => 'settings_admin_local'));
280 // TRANS: Fieldset legend on site settings panel.
281 $this->out->element('legend', null, _m('LEGEND','Local'));
282 $this->out->elementStart('ul', 'form_data');
283 $timezones = array();
285 foreach (DateTimeZone::listIdentifiers() as $k => $v) {
292 // TRANS: Dropdown label on site settings panel.
293 $this->out->dropdown('timezone', _('Default timezone'),
294 // TRANS: Dropdown title on site settings panel.
295 $timezones, _('Default timezone for the site; usually UTC.'),
296 true, $this->value('timezone'));
300 $this->out->dropdown('language',
301 // TRANS: Dropdown label on site settings panel.
302 _('Default language'),
303 get_nice_language_list(),
304 // TRANS: Dropdown title on site settings panel.
305 _('The site language when autodetection from browser settings is not available.'),
306 false, $this->value('language'));
309 $this->out->elementEnd('ul');
310 $this->out->elementEnd('fieldset');
312 $this->out->elementStart('fieldset', array('id' => 'settings_admin_limits'));
313 // TRANS: Fieldset legend on site settings panel.
314 $this->out->element('legend', null, _m('LEGEND','Limits'));
315 $this->out->elementStart('ul', 'form_data');
317 $this->input('textlimit',
318 // TRANS: Field label on site settings panel.
320 // TRANS: Field title on site settings panel.
321 _('Maximum number of characters for notices.'));
325 $this->input('dupelimit',
326 // TRANS: Field label on site settings panel.
328 // TRANS: Field title on site settings panel.
329 _('How long users must wait (in seconds) to post the same thing again.'));
331 $this->out->elementEnd('ul');
332 $this->out->elementEnd('fieldset');
337 $this->out->elementStart('fieldset', array('id' => 'settings_site_logo'));
338 // TRANS: Fieldset legend for form to change logo.
339 $this->out->element('legend', null, _('Logo'));
341 $this->out->elementStart('ul', 'form_data');
345 // TRANS: Field label for StatusNet site logo.
347 // TRANS: Title for field label for StatusNet site logo.
348 'Logo for the site (full URL).');
352 $this->input('ssllogo',
353 // TRANS: Field label for SSL StatusNet site logo.
355 // TRANS: Title for field label for SSL StatusNet site logo.
356 'Logo to show on SSL pages (full URL).');
359 $this->out->elementEnd('ul');
361 $this->out->elementEnd('fieldset');
369 function formActions()
371 $this->out->submit('submit',
372 // TRANS: Button text for saving site settings.
376 // TRANS: Button title for saving site settings.
377 _('Save the site settings.'));