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 'snapshot' => array('run', 'reporturl', 'frequency'));
97 static $booleans = array('site' => array('private'));
101 foreach ($settings as $section => $parts) {
102 foreach ($parts as $setting) {
103 $values[$section][$setting] = $this->trimmed($setting);
107 foreach ($booleans as $section => $parts) {
108 foreach ($parts as $setting) {
109 $values[$section][$setting] = ($this->boolean($setting)) ? 1 : 0;
113 // This throws an exception on validation errors
115 $this->validate($values);
117 // assert(all values are valid);
119 $config = new Config();
121 $config->query('BEGIN');
123 foreach ($settings as $section => $parts) {
124 foreach ($parts as $setting) {
125 Config::save($section, $setting, $values[$section][$setting]);
129 foreach ($booleans as $section => $parts) {
130 foreach ($parts as $setting) {
131 Config::save($section, $setting, $values[$section][$setting]);
135 $config->query('COMMIT');
140 function validate(&$values)
142 // Validate site name
144 if (empty($values['site']['name'])) {
145 $this->clientError(_("Site name must have non-zero length."));
150 $values['site']['email'] = common_canonical_email($values['site']['email']);
152 if (empty($values['site']['email'])) {
153 $this->clientError(_('You must have a valid contact email address'));
155 if (!Validate::email($values['site']['email'], common_config('email', 'check_domain'))) {
156 $this->clientError(_('Not a valid email address'));
161 if (is_null($values['site']['timezone']) ||
162 !in_array($values['site']['timezone'], DateTimeZone::listIdentifiers())) {
163 $this->clientError(_('Timezone not selected.'));
169 if (!is_null($values['site']['language']) &&
170 !in_array($values['site']['language'], array_keys(get_nice_language_list()))) {
171 $this->clientError(sprintf(_('Unknown language "%s"'), $values['site']['language']));
174 // Validate report URL
176 if (!is_null($values['snapshot']['reporturl']) &&
177 !Validate::uri($values['snapshot']['reporturl'], array('allowed_schemes' => array('http', 'https')))) {
178 $this->clientError(_("Invalid snapshot report URL."));
181 // Validate snapshot run value
183 if (!in_array($values['snapshot']['run'], array('web', 'cron', 'never'))) {
184 $this->clientError(_("Invalid snapshot run value."));
187 // Validate snapshot run value
189 if (!Validate::number($values['snapshot']['frequency'])) {
190 $this->clientError(_("Snapshot frequency must be a number."));
196 class SiteAdminPanelForm extends AdminForm
201 * @return int ID of the form
206 return 'form_site_admin_panel';
212 * @return string class of the form
217 return 'form_settings';
223 * @return string URL of the action
228 return common_local_url('siteadminpanel');
232 * Data elements of the form
239 $this->out->elementStart('ul', 'form_data');
241 $this->input('name', _('Site name'),
242 _('The name of your site, like "Yourcompany Microblog"'));
245 $this->input('broughtby', _('Brought by'),
246 _('Text used for credits link in footer of each page'));
249 $this->input('broughtbyurl', _('Brought by URL'),
250 _('URL used for credits link in footer of each page'));
253 $this->input('email', _('Email'),
254 _('contact email address for your site'));
258 $timezones = array();
260 foreach (DateTimeZone::listIdentifiers() as $k => $v) {
268 $this->out->dropdown('timezone', _('Default timezone'),
269 $timezones, _('Default timezone for the site; usually UTC.'),
270 true, $this->value('timezone'));
275 $this->out->dropdown('language', _('Language'),
276 get_nice_language_list(), _('Default site language'),
277 false, $this->value('language'));
282 $this->out->checkbox('private', _('Private'),
283 (bool) $this->value('private'),
284 _('Prohibit anonymous users (not logged in) from viewing site?'));
290 $snapshot = array('web' => _('Randomly during Web hit'),
291 'cron' => _('In a scheduled job'),
292 'never' => _('Never'));
294 $this->out->dropdown('run', _('Data snapshots'),
295 $snapshot, _('When to send statistical data to status.net servers'),
296 false, $this->value('run', 'snapshot'));
301 $this->input('frequency', _('Frequency'),
302 _('Snapshots will be sent once every N Web hits'),
309 $this->input('reporturl', _('Report URL'),
310 _('Snapshots will be sent to this URL'),
315 $this->out->elementEnd('ul');
324 function formActions()
326 $this->out->submit('submit', _('Save'), 'submit', null, _('Save site settings'));