]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/sessionsadminpanel.php
Type-hint is array here.
[quix0rs-gnu-social.git] / actions / sessionsadminpanel.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Sessions 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  * Admin site sessions
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 SessionsadminpanelAction extends AdminPanelAction
44 {
45     /**
46      * Returns the page title
47      *
48      * @return string page title
49      */
50     function title()
51     {
52         // TRANS: Title for the sessions administration panel.
53         return _m('TITLE','Sessions');
54     }
55
56     /**
57      * Instructions for using this form.
58      *
59      * @return string instructions
60      */
61     function getInstructions()
62     {
63         // TRANS: Instructions for the sessions administration panel.
64         return _('Session settings for this StatusNet site');
65     }
66
67     /**
68      * Show the site admin panel form
69      *
70      * @return void
71      */
72     function showForm()
73     {
74         $form = new SessionsAdminPanelForm($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('sessions' => array('handle', 'debug'));
87
88         $values = array();
89
90         foreach ($booleans as $section => $parts) {
91             foreach ($parts as $setting) {
92                 $values[$section][$setting] = ($this->boolean($setting)) ? 1 : 0;
93             }
94         }
95
96         // This throws an exception on validation errors
97
98         $this->validate($values);
99
100         // assert(all values are valid);
101
102         $config = new Config();
103
104         $config->query('BEGIN');
105
106         foreach ($booleans as $section => $parts) {
107             foreach ($parts as $setting) {
108                 Config::save($section, $setting, $values[$section][$setting]);
109             }
110         }
111
112         $config->query('COMMIT');
113
114         return;
115     }
116
117     function validate(&$values)
118     {
119         // stub
120     }
121 }
122
123 // @todo FIXME: Class documentation missing.
124 class SessionsAdminPanelForm extends AdminForm
125 {
126     /**
127      * ID of the form
128      *
129      * @return int ID of the form
130      */
131     function id()
132     {
133         return 'sessionsadminpanel';
134     }
135
136     /**
137      * class of the form
138      *
139      * @return string class of the form
140      */
141     function formClass()
142     {
143         return 'form_settings';
144     }
145
146     /**
147      * Action of the form
148      *
149      * @return string URL of the action
150      */
151     function action()
152     {
153         return common_local_url('sessionsadminpanel');
154     }
155
156     /**
157      * Data elements of the form
158      *
159      * @return void
160      */
161     function formData()
162     {
163         $this->out->elementStart('fieldset', array('id' => 'settings_user_sessions'));
164         // TRANS: Fieldset legend on the sessions administration panel.
165         $this->out->element('legend', null, _m('LEGEND','Sessions'));
166
167         $this->out->elementStart('ul', 'form_data');
168
169         $this->li();
170         // TRANS: Checkbox title on the sessions administration panel.
171         // TRANS: Indicates if StatusNet should handle session administration.
172         $this->out->checkbox('handle', _('Handle sessions'),
173                               (bool) $this->value('handle', 'sessions'),
174                               // TRANS: Checkbox title on the sessions administration panel.
175                               // TRANS: Indicates if StatusNet should handle session administration.
176                               _('Handle sessions ourselves.'));
177         $this->unli();
178
179         $this->li();
180         // TRANS: Checkbox label on the sessions administration panel.
181         // TRANS: Indicates if StatusNet should write session debugging output.
182         $this->out->checkbox('debug', _('Session debugging'),
183                               (bool) $this->value('debug', 'sessions'),
184                               // TRANS: Checkbox title on the sessions administration panel.
185                               _('Enable debugging output for sessions.'));
186         $this->unli();
187
188         $this->out->elementEnd('ul');
189
190         $this->out->elementEnd('fieldset');
191     }
192
193     /**
194      * Action elements
195      *
196      * @return void
197      */
198     function formActions()
199     {
200         $this->out->submit('submit',
201                            // TRANS: Submit button text on the sessions administration panel.
202                            _m('BUTTON','Save'),
203                            'submit',
204                            null,
205                            // TRANS: Title for submit button on the sessions administration panel.
206                            _('Save session settings'));
207     }
208 }