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