]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/siteadminpanel.php
Merge branch 'testing' of gitorious.org:statusnet/mainline into testing
[quix0rs-gnu-social.git] / actions / siteadminpanel.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Site administration panel
6  *
7  * PHP version 5
8  *
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.
13  *
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.
18  *
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/>.
21  *
22  * @category  Settings
23  * @package   StatusNet
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/
30  */
31
32 if (!defined('STATUSNET')) {
33     exit(1);
34 }
35
36 /**
37  * Administer site settings
38  *
39  * @category Admin
40  * @package  StatusNet
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/
46  */
47
48 class SiteadminpanelAction extends AdminPanelAction
49 {
50     /**
51      * Returns the page title
52      *
53      * @return string page title
54      */
55
56     function title()
57     {
58         return _('Site');
59     }
60
61     /**
62      * Instructions for using this form.
63      *
64      * @return string instructions
65      */
66
67     function getInstructions()
68     {
69         return _('Basic settings for this StatusNet site');
70     }
71
72     /**
73      * Show the site admin panel form
74      *
75      * @return void
76      */
77
78     function showForm()
79     {
80         $form = new SiteAdminPanelForm($this);
81         $form->show();
82         return;
83     }
84
85     /**
86      * Save settings from the form
87      *
88      * @return void
89      */
90
91     function saveSettings()
92     {
93         static $settings = array(
94             'site' => array('name', 'broughtby', 'broughtbyurl',
95             'email', 'timezone', 'language',
96             'site', 'textlimit', 'dupelimit'),
97         );
98
99         $values = array();
100
101         foreach ($settings as $section => $parts) {
102             foreach ($parts as $setting) {
103                 $values[$section][$setting] = $this->trimmed($setting);
104             }
105         }
106
107         // This throws an exception on validation errors
108
109         $this->validate($values);
110
111         // assert(all values are valid);
112
113         $config = new Config();
114
115         $config->query('BEGIN');
116
117         foreach ($settings as $section => $parts) {
118             foreach ($parts as $setting) {
119                 Config::save($section, $setting, $values[$section][$setting]);
120             }
121         }
122
123         $config->query('COMMIT');
124
125         return;
126     }
127
128     function validate(&$values)
129     {
130         // Validate site name
131
132         if (empty($values['site']['name'])) {
133             $this->clientError(_("Site name must have non-zero length."));
134         }
135
136         // Validate email
137
138         $values['site']['email'] = common_canonical_email($values['site']['email']);
139
140         if (empty($values['site']['email'])) {
141             $this->clientError(_('You must have a valid contact email address.'));
142         }
143         if (!Validate::email($values['site']['email'], common_config('email', 'check_domain'))) {
144             $this->clientError(_('Not a valid email address.'));
145         }
146
147         // Validate timezone
148
149         if (is_null($values['site']['timezone']) ||
150             !in_array($values['site']['timezone'], DateTimeZone::listIdentifiers())) {
151             $this->clientError(_('Timezone not selected.'));
152             return;
153         }
154
155         // Validate language
156
157         if (!is_null($values['site']['language']) &&
158             !in_array($values['site']['language'], array_keys(get_nice_language_list()))) {
159             $this->clientError(sprintf(_('Unknown language "%s".'), $values['site']['language']));
160         }
161
162         // Validate text limit
163
164         if (!Validate::number($values['site']['textlimit'], array('min' => 0))) {
165             $this->clientError(_("Minimum text limit is 0 (unlimited)."));
166         }
167
168         // Validate dupe limit
169
170         if (!Validate::number($values['site']['dupelimit'], array('min' => 1))) {
171             $this->clientError(_("Dupe limit must 1 or more seconds."));
172         }
173
174     }
175 }
176
177 class SiteAdminPanelForm extends AdminForm
178 {
179     /**
180      * ID of the form
181      *
182      * @return int ID of the form
183      */
184
185     function id()
186     {
187         return 'form_site_admin_panel';
188     }
189
190     /**
191      * class of the form
192      *
193      * @return string class of the form
194      */
195
196     function formClass()
197     {
198         return 'form_settings';
199     }
200
201     /**
202      * Action of the form
203      *
204      * @return string URL of the action
205      */
206
207     function action()
208     {
209         return common_local_url('siteadminpanel');
210     }
211
212     /**
213      * Data elements of the form
214      *
215      * @return void
216      */
217
218     function formData()
219     {
220         $this->out->elementStart('fieldset', array('id' => 'settings_admin_general'));
221         $this->out->element('legend', null, _('General'));
222         $this->out->elementStart('ul', 'form_data');
223         $this->li();
224         $this->input('name', _('Site name'),
225                      _('The name of your site, like "Yourcompany Microblog"'));
226         $this->unli();
227
228         $this->li();
229         $this->input('broughtby', _('Brought by'),
230                      _('Text used for credits link in footer of each page'));
231         $this->unli();
232
233         $this->li();
234         $this->input('broughtbyurl', _('Brought by URL'),
235                      _('URL used for credits link in footer of each page'));
236         $this->unli();
237         $this->li();
238         $this->input('email', _('Email'),
239                      _('Contact email address for your site'));
240         $this->unli();
241         $this->out->elementEnd('ul');
242         $this->out->elementEnd('fieldset');
243
244         $this->out->elementStart('fieldset', array('id' => 'settings_admin_local'));
245         $this->out->element('legend', null, _('Local'));
246         $this->out->elementStart('ul', 'form_data');
247         $timezones = array();
248
249         foreach (DateTimeZone::listIdentifiers() as $k => $v) {
250             $timezones[$v] = $v;
251         }
252
253         asort($timezones);
254
255         $this->li();
256         $this->out->dropdown('timezone', _('Default timezone'),
257                              $timezones, _('Default timezone for the site; usually UTC.'),
258                              true, $this->value('timezone'));
259         $this->unli();
260
261         $this->li();
262         $this->out->dropdown('language', _('Default language'),
263                              get_nice_language_list(), _('Site language when autodetection from browser settings is not available'),
264                              false, $this->value('language'));
265         $this->unli();
266
267         $this->out->elementEnd('ul');
268         $this->out->elementEnd('fieldset');
269
270         $this->out->elementStart('fieldset', array('id' => 'settings_admin_limits'));
271         $this->out->element('legend', null, _('Limits'));
272         $this->out->elementStart('ul', 'form_data');
273         $this->li();
274         $this->input('textlimit', _('Text limit'), _('Maximum number of characters for notices.'));
275         $this->unli();
276
277         $this->li();
278         $this->input('dupelimit', _('Dupe limit'), _('How long users must wait (in seconds) to post the same thing again.'));
279         $this->unli();
280         $this->out->elementEnd('ul');
281         $this->out->elementEnd('fieldset');
282     }
283
284     /**
285      * Action elements
286      *
287      * @return void
288      */
289
290     function formActions()
291     {
292         $this->out->submit('submit', _('Save'), 'submit', null, _('Save site settings'));
293     }
294 }