]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/accessadminpanel.php
* i18n/L10n fixes.
[quix0rs-gnu-social.git] / actions / accessadminpanel.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Site access 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    Zach Copley <zach@status.net>
25  * @copyright 2010 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('STATUSNET')) {
31     exit(1);
32 }
33
34 /**
35  * Administer site access settings
36  *
37  * @category Admin
38  * @package  StatusNet
39  * @author   Zach Copley <zach@status.net>
40  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
41  * @link     http://status.net/
42  */
43 class AccessadminpanelAction extends AdminPanelAction
44 {
45     /**
46      * Returns the page title
47      *
48      * @return string page title
49      */
50     function title()
51     {
52         // TRANS: Page title for Access admin panel that allows configuring site access.
53         return _('Access');
54     }
55
56     /**
57      * Instructions for using this form.
58      *
59      * @return string instructions
60      */
61     function getInstructions()
62     {
63         // TRANS: Page notice.
64         return _('Site access settings');
65     }
66
67     /**
68      * Show the site admin panel form
69      *
70      * @return void
71      */
72     function showForm()
73     {
74         $form = new AccessAdminPanelForm($this);
75         $form->show();
76         return;
77     }
78
79     /**
80      * Save settings from the form
81      *
82      * @return void
83      */
84     function saveSettings()
85     {
86         static $booleans = array('site' => array('private', 'inviteonly', 'closed'));
87
88         foreach ($booleans as $section => $parts) {
89             foreach ($parts as $setting) {
90                 $values[$section][$setting] = ($this->boolean($setting)) ? 1 : 0;
91             }
92         }
93
94         $config = new Config();
95
96         $config->query('BEGIN');
97
98         foreach ($booleans as $section => $parts) {
99             foreach ($parts as $setting) {
100                 Config::save($section, $setting, $values[$section][$setting]);
101             }
102         }
103
104         $config->query('COMMIT');
105
106         return;
107     }
108 }
109
110 class AccessAdminPanelForm extends AdminForm
111 {
112     /**
113      * ID of the form
114      *
115      * @return int ID of the form
116      */
117     function id()
118     {
119         return 'form_site_admin_panel';
120     }
121
122     /**
123      * class of the form
124      *
125      * @return string class of the form
126      */
127     function formClass()
128     {
129         return 'form_settings';
130     }
131
132     /**
133      * Action of the form
134      *
135      * @return string URL of the action
136      */
137     function action()
138     {
139         return common_local_url('accessadminpanel');
140     }
141
142     /**
143      * Data elements of the form
144      *
145      * @return void
146      */
147     function formData()
148     {
149         $this->out->elementStart('fieldset', array('id' => 'settings_admin_access'));
150         // TRANS: Form legend for registration form.
151         $this->out->element('legend', null, _('Registration'));
152         $this->out->elementStart('ul', 'form_data');
153         $this->li();
154         // TRANS: Checkbox instructions for admin setting "Private".
155         $instructions = _('Prohibit anonymous users (not logged in) from viewing site?');
156         // TRANS: Checkbox label for prohibiting anonymous users from viewing site.
157         $this->out->checkbox('private', _m('LABEL', 'Private'),
158                              (bool) $this->value('private'),
159                              $instructions);
160         $this->unli();
161
162         $this->li();
163         // TRANS: Checkbox instructions for admin setting "Invite only".
164         $instructions = _('Make registration invitation only.');
165         // TRANS: Checkbox label for configuring site as invite only.
166         $this->out->checkbox('inviteonly', _('Invite only'),
167                              (bool) $this->value('inviteonly'),
168                              $instructions);
169         $this->unli();
170
171         $this->li();
172         // TRANS: Checkbox instructions for admin setting "Closed" (no new registrations).
173         $instructions = _('Disable new registrations.');
174         // TRANS: Checkbox label for disabling new user registrations.
175         $this->out->checkbox('closed', _('Closed'),
176                              (bool) $this->value('closed'),
177                              $instructions);
178         $this->unli();
179         $this->out->elementEnd('ul');
180         $this->out->elementEnd('fieldset');
181     }
182
183     /**
184      * Action elements
185      *
186      * @return void
187      */
188     function formActions()
189     {
190         // TRANS: Title for button to save access settings in site admin panel.
191         $title = _('Save access settings');
192         // TRANS: Tooltip for button to save access settings in site admin panel.
193         $this->out->submit('submit', _m('BUTTON', 'Save'), 'submit', null, $title);
194     }
195 }