]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/useradminpanel.php
Merge branch '0.9.x' of gitorious.org:statusnet/mainline into 0.9.x
[quix0rs-gnu-social.git] / actions / useradminpanel.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * User 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-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/
30  */
31
32 if (!defined('STATUSNET')) {
33     exit(1);
34 }
35
36 /**
37  * Administer user 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 UseradminpanelAction extends AdminPanelAction
49 {
50     /**
51      * Returns the page title
52      *
53      * @return string page title
54      */
55
56     function title()
57     {
58         return _('User');
59     }
60
61     /**
62      * Instructions for using this form.
63      *
64      * @return string instructions
65      */
66
67     function getInstructions()
68     {
69         return _('User 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 UserAdminPanelForm($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('theme');
94         static $booleans = array('closed', 'inviteonly', 'private');
95
96         $values = array();
97
98         foreach ($settings as $setting) {
99             $values[$setting] = $this->trimmed($setting);
100         }
101
102         // This throws an exception on validation errors
103
104         $this->validate($values);
105
106         // assert(all values are valid);
107
108         $config = new Config();
109
110         $config->query('BEGIN');
111
112         foreach ($settings as $setting) {
113             Config::save('site', $setting, $values[$setting]);
114         }
115
116         $config->query('COMMIT');
117
118         return;
119     }
120
121     function validate(&$values)
122     {
123     }
124 }
125
126 class UserAdminPanelForm extends Form
127 {
128     /**
129      * ID of the form
130      *
131      * @return int ID of the form
132      */
133
134     function id()
135     {
136         return 'useradminpanel';
137     }
138
139     /**
140      * class of the form
141      *
142      * @return string class of the form
143      */
144
145     function formClass()
146     {
147         return 'form_user_admin_panel';
148     }
149
150     /**
151      * Action of the form
152      *
153      * @return string URL of the action
154      */
155
156     function action()
157     {
158         return common_local_url('useradminpanel');
159     }
160
161     /**
162      * Data elements of the form
163      *
164      * @return void
165      */
166
167     function formData()
168     {
169         $this->li();
170
171         $this->out->checkbox('closed', _('Closed'),
172                              (bool) $this->value('closed'),
173                              _('Is registration on this site prohibited?'));
174
175         $this->unli();
176         $this->li();
177
178         $this->out->checkbox('inviteonly', _('Invite-only'),
179                              (bool) $this->value('inviteonly'),
180                              _('Is registration on this site only open to invited users?'));
181
182         $this->unli();
183     }
184
185     /**
186      * Utility to simplify some of the duplicated code around
187      * params and settings.
188      *
189      * @param string $setting      Name of the setting
190      * @param string $title        Title to use for the input
191      * @param string $instructions Instructions for this field
192      *
193      * @return void
194      */
195
196     function input($setting, $title, $instructions)
197     {
198         $this->out->input($setting, $title, $this->value($setting), $instructions);
199     }
200
201     /**
202      * Utility to simplify getting the posted-or-stored setting value
203      *
204      * @param string $setting Name of the setting
205      *
206      * @return string param value if posted, or current config value
207      */
208
209     function value($cat, $setting)
210     {
211         $value = $this->out->trimmed($setting);
212         if (empty($value)) {
213             $value = common_config($cat, $setting);
214         }
215         return $value;
216     }
217
218     /**
219      * Action elements
220      *
221      * @return void
222      */
223
224     function formActions()
225     {
226         $this->out->submit('submit', _('Save'), 'submit', null, _('Save site settings'));
227     }
228 }