]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/accessadminpanel.php
Merge branch 'testing' of git@gitorious.org:statusnet/mainline into 0.9.x
[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
44 class AccessadminpanelAction extends AdminPanelAction
45 {
46     /**
47      * Returns the page title
48      *
49      * @return string page title
50      */
51
52     function title()
53     {
54         // TRANS: Page title
55         return _('Access');
56     }
57
58     /**
59      * Instructions for using this form.
60      *
61      * @return string instructions
62      */
63
64     function getInstructions()
65     {
66         // TRANS: Page notice
67         return _('Site access settings');
68     }
69
70     /**
71      * Show the site admin panel form
72      *
73      * @return void
74      */
75
76     function showForm()
77     {
78         $form = new AccessAdminPanelForm($this);
79         $form->show();
80         return;
81     }
82
83     /**
84      * Save settings from the form
85      *
86      * @return void
87      */
88
89     function saveSettings()
90     {
91         static $booleans = array('site' => array('private', 'inviteonly', 'closed'));
92
93         foreach ($booleans as $section => $parts) {
94             foreach ($parts as $setting) {
95                 $values[$section][$setting] = ($this->boolean($setting)) ? 1 : 0;
96             }
97         }
98
99         $config = new Config();
100
101         $config->query('BEGIN');
102
103         foreach ($booleans as $section => $parts) {
104             foreach ($parts as $setting) {
105                 Config::save($section, $setting, $values[$section][$setting]);
106             }
107         }
108
109         $config->query('COMMIT');
110
111         return;
112     }
113
114 }
115
116 class AccessAdminPanelForm extends AdminForm
117 {
118     /**
119      * ID of the form
120      *
121      * @return int ID of the form
122      */
123
124     function id()
125     {
126         return 'form_site_admin_panel';
127     }
128
129     /**
130      * class of the form
131      *
132      * @return string class of the form
133      */
134
135     function formClass()
136     {
137         return 'form_settings';
138     }
139
140     /**
141      * Action of the form
142      *
143      * @return string URL of the action
144      */
145
146     function action()
147     {
148         return common_local_url('accessadminpanel');
149     }
150
151     /**
152      * Data elements of the form
153      *
154      * @return void
155      */
156
157     function formData()
158     {
159         $this->out->elementStart('fieldset', array('id' => 'settings_admin_access'));
160         // TRANS: Form legend for registration form.
161         $this->out->element('legend', null, _('Registration'));
162         $this->out->elementStart('ul', 'form_data');
163         $this->li();
164         // TRANS: Checkbox instructions for admin setting "Private"
165         $instructions = _('Prohibit anonymous users (not logged in) from viewing site?');
166         // TRANS: Checkbox label for prohibiting anonymous users from viewing site.
167         $this->out->checkbox('private', _m('LABEL', 'Private'),
168                              (bool) $this->value('private'),
169                              $instructions);
170         $this->unli();
171
172         $this->li();
173         // TRANS: Checkbox instructions for admin setting "Invite only"
174         $instructions = _('Make registration invitation only.');
175         // TRANS: Checkbox label for configuring site as invite only.
176         $this->out->checkbox('inviteonly', _('Invite only'),
177                              (bool) $this->value('inviteonly'),
178                              $instructions);
179         $this->unli();
180
181         $this->li();
182         // TRANS: Checkbox instructions for admin setting "Closed" (no new registrations)
183         $instructions = _('Disable new registrations.');
184         // TRANS: Checkbox label for disabling new user registrations.
185         $this->out->checkbox('closed', _('Closed'),
186                              (bool) $this->value('closed'),
187                              $instructions);
188         $this->unli();
189         $this->out->elementEnd('ul');
190         $this->out->elementEnd('fieldset');
191     }
192
193     /**
194      * Action elements
195      *
196      * @return void
197      */
198
199     function formActions()
200     {
201         // TRANS: Title / tooltip for button to save access settings in site admin panel
202         $title = _('Save access settings');
203         $this->out->submit('submit', _m('BUTTON', 'Save'), 'submit', null, $title);
204     }
205
206 }