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('site' => array('name', 'broughtby', 'broughtbyurl',
94 'email', 'timezone', 'language',
95 'ssl', 'sslserver', 'site',
96 'textlimit', 'dupelimit'),
97 'snapshot' => array('run', 'reporturl', 'frequency'));
99 static $booleans = array('site' => array('private', 'inviteonly', 'closed', 'fancy'));
103 foreach ($settings as $section => $parts) {
104 foreach ($parts as $setting) {
105 $values[$section][$setting] = $this->trimmed($setting);
109 foreach ($booleans as $section => $parts) {
110 foreach ($parts as $setting) {
111 $values[$section][$setting] = ($this->boolean($setting)) ? 1 : 0;
115 // This throws an exception on validation errors
117 $this->validate($values);
119 // assert(all values are valid);
121 $config = new Config();
123 $config->query('BEGIN');
125 foreach ($settings as $section => $parts) {
126 foreach ($parts as $setting) {
127 Config::save($section, $setting, $values[$section][$setting]);
131 foreach ($booleans as $section => $parts) {
132 foreach ($parts as $setting) {
133 Config::save($section, $setting, $values[$section][$setting]);
137 $config->query('COMMIT');
142 function validate(&$values)
144 // Validate site name
146 if (empty($values['site']['name'])) {
147 $this->clientError(_("Site name must have non-zero length."));
152 $values['site']['email'] = common_canonical_email($values['site']['email']);
154 if (empty($values['site']['email'])) {
155 $this->clientError(_('You must have a valid contact email address'));
157 if (!Validate::email($values['site']['email'], common_config('email', 'check_domain'))) {
158 $this->clientError(_('Not a valid email address'));
163 if (is_null($values['site']['timezone']) ||
164 !in_array($values['site']['timezone'], DateTimeZone::listIdentifiers())) {
165 $this->clientError(_('Timezone not selected.'));
171 if (!is_null($values['site']['language']) &&
172 !in_array($values['site']['language'], array_keys(get_nice_language_list()))) {
173 $this->clientError(sprintf(_('Unknown language "%s"'), $values['site']['language']));
176 // Validate report URL
178 if (!is_null($values['snapshot']['reporturl']) &&
179 !Validate::uri($values['snapshot']['reporturl'], array('allowed_schemes' => array('http', 'https')))) {
180 $this->clientError(_("Invalid snapshot report URL."));
183 // Validate snapshot run value
185 if (!in_array($values['snapshot']['run'], array('web', 'cron', 'never'))) {
186 $this->clientError(_("Invalid snapshot run value."));
189 // Validate snapshot run value
191 if (!Validate::number($values['snapshot']['frequency'])) {
192 $this->clientError(_("Snapshot frequency must be a number."));
195 // Validate SSL setup
197 if (in_array($values['site']['ssl'], array('sometimes', 'always'))) {
198 if (empty($values['site']['sslserver'])) {
199 $this->clientError(_("You must set an SSL sever when enabling SSL."));
203 if (mb_strlen($values['site']['sslserver']) > 255) {
204 $this->clientError(_("Invalid SSL server. Max length is 255 characters."));
207 // Validate text limit
209 if (!Validate::number($values['site']['textlimit'], array('min' => 140))) {
210 $this->clientError(_("Minimum text limit is 140c."));
213 // Validate dupe limit
215 if (!Validate::number($values['site']['dupelimit'], array('min' => 1))) {
216 $this->clientError(_("Dupe limit must 1 or more seconds."));
222 class SiteAdminPanelForm extends AdminForm
227 * @return int ID of the form
232 return 'form_site_admin_panel';
238 * @return string class of the form
243 return 'form_settings';
249 * @return string URL of the action
254 return common_local_url('siteadminpanel');
258 * Data elements of the form
265 $this->out->elementStart('fieldset', array('id' => 'settings_admin_general'));
266 $this->out->element('legend', null, _('General'));
267 $this->out->elementStart('ul', 'form_data');
269 $this->input('name', _('Site name'),
270 _('The name of your site, like "Yourcompany Microblog"'));
274 $this->input('broughtby', _('Brought by'),
275 _('Text used for credits link in footer of each page'));
279 $this->input('broughtbyurl', _('Brought by URL'),
280 _('URL used for credits link in footer of each page'));
283 $this->input('email', _('Email'),
284 _('contact email address for your site'));
286 $this->out->elementEnd('ul');
287 $this->out->elementEnd('fieldset');
289 $this->out->elementStart('fieldset', array('id' => 'settings_admin_local'));
290 $this->out->element('legend', null, _('Local'));
291 $this->out->elementStart('ul', 'form_data');
292 $timezones = array();
294 foreach (DateTimeZone::listIdentifiers() as $k => $v) {
301 $this->out->dropdown('timezone', _('Default timezone'),
302 $timezones, _('Default timezone for the site; usually UTC.'),
303 true, $this->value('timezone'));
307 $this->out->dropdown('language', _('Language'),
308 get_nice_language_list(), _('Default site language'),
309 false, $this->value('language'));
312 $this->out->elementEnd('ul');
313 $this->out->elementEnd('fieldset');
315 $this->out->elementStart('fieldset', array('id' => 'settings_admin_urls'));
316 $this->out->element('legend', null, _('URLs'));
317 $this->out->elementStart('ul', 'form_data');
319 $this->input('server', _('Server'), _('Site\'s server hostname.'));
323 $this->out->checkbox('fancy', _('Fancy URLs'),
324 (bool) $this->value('fancy'),
325 _('Use fancy (more readable and memorable) URLs?'));
327 $this->out->elementEnd('ul');
328 $this->out->elementEnd('fieldset');
330 $this->out->elementStart('fieldset', array('id' => 'settings_admin_access'));
331 $this->out->element('legend', null, _('Access'));
332 $this->out->elementStart('ul', 'form_data');
334 $this->out->checkbox('private', _('Private'),
335 (bool) $this->value('private'),
336 _('Prohibit anonymous users (not logged in) from viewing site?'));
340 $this->out->checkbox('inviteonly', _('Invite only'),
341 (bool) $this->value('inviteonly'),
342 _('Make registration invitation only.'));
346 $this->out->checkbox('closed', _('Closed'),
347 (bool) $this->value('closed'),
348 _('Disable new registrations.'));
350 $this->out->elementEnd('ul');
351 $this->out->elementEnd('fieldset');
353 $this->out->elementStart('fieldset', array('id' => 'settings_admin_snapshots'));
354 $this->out->element('legend', null, _('Snapshots'));
355 $this->out->elementStart('ul', 'form_data');
357 $snapshot = array('web' => _('Randomly during Web hit'),
358 'cron' => _('In a scheduled job'),
359 'never' => _('Never'));
360 $this->out->dropdown('run', _('Data snapshots'),
361 $snapshot, _('When to send statistical data to status.net servers'),
362 false, $this->value('run', 'snapshot'));
366 $this->input('frequency', _('Frequency'),
367 _('Snapshots will be sent once every N Web hits'),
372 $this->input('reporturl', _('Report URL'),
373 _('Snapshots will be sent to this URL'),
376 $this->out->elementEnd('ul');
377 $this->out->elementEnd('fieldset');
379 $this->out->elementStart('fieldset', array('id' => 'settings_admin_ssl'));
380 $this->out->element('legend', null, _('SSL'));
381 $this->out->elementStart('ul', 'form_data');
383 $ssl = array('never' => _('Never'),
384 'sometimes' => _('Sometimes'),
385 'always' => _('Always'));
387 $this->out->dropdown('ssl', _('Use SSL'),
388 $ssl, _('When to use SSL'),
389 false, $this->value('ssl', 'site'));
393 $this->input('sslserver', _('SSL Server'),
394 _('Server to direct SSL requests to'));
396 $this->out->elementEnd('ul');
397 $this->out->elementEnd('fieldset');
399 $this->out->elementStart('fieldset', array('id' => 'settings_admin_limits'));
400 $this->out->element('legend', null, _('Limits'));
401 $this->out->elementStart('ul', 'form_data');
403 $this->input('textlimit', _('Text limit'), _('Maximum number of characters for notices.'));
407 $this->input('dupelimit', _('Dupe limit'), _('How long users must wait (in seconds) to post the same thing again.'));
409 $this->out->elementEnd('ul');
410 $this->out->elementEnd('fieldset');
419 function formActions()
421 $this->out->submit('submit', _('Save'), 'submit', null, _('Save site settings'));