]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/pathsadminpanel.php
Fix for massively slow friends timeline query due to indexing bug introduced with...
[quix0rs-gnu-social.git] / actions / pathsadminpanel.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Paths 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  * Paths 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 PathsadminpanelAction extends AdminPanelAction
49 {
50
51     /**
52      * Returns the page title
53      *
54      * @return string page title
55      */
56
57     function title()
58     {
59         return _('Paths');
60     }
61
62     /**
63      * Instructions for using this form.
64      *
65      * @return string instructions
66      */
67
68     function getInstructions()
69     {
70         return _('Path and server settings for this StatusNet site.');
71     }
72
73     /**
74      * Show the paths admin panel form
75      *
76      * @return void
77      */
78
79     function showForm()
80     {
81         $form = new PathsAdminPanelForm($this);
82         $form->show();
83         return;
84     }
85
86     /**
87      * Save settings from the form
88      *
89      * @return void
90      */
91
92     function saveSettings()
93     {
94         static $settings = array(
95             'site' => array('path', 'locale_path'),
96             'theme' => array('server', 'dir', 'path'),
97             'avatar' => array('server', 'dir', 'path'),
98             'background' => array('server', 'dir', 'path')
99         );
100
101         $values = array();
102
103         foreach ($settings as $section => $parts) {
104             foreach ($parts as $setting) {
105                 $values[$section][$setting] = $this->trimmed("$section-$setting");
106             }
107         }
108
109         $this->validate($values);
110
111         // assert(all values are valid);
112
113         $config = new Config();
114
115         $config->query('BEGIN');
116
117         foreach ($settings as $section => $parts) {
118             foreach ($parts as $setting) {
119                 Config::save($section, $setting, $values[$section][$setting]);
120             }
121         }
122
123         $config->query('COMMIT');
124
125         return;
126     }
127
128     /**
129      * Attempt to validate setting values
130      *
131      * @return void
132      */
133
134     function validate(&$values)
135     {
136
137         // Validate theme dir
138
139         if (!empty($values['theme']['dir']) && !is_readable($values['theme']['dir'])) {
140             $this->clientError(sprintf(_("Theme directory not readable: %s"), $values['theme']['dir']));
141         }
142
143         // Validate avatar dir
144
145         if (empty($values['avatar']['dir']) || !is_writable($values['avatar']['dir'])) {
146             $this->clientError(sprintf(_("Avatar directory not writable: %s"), $values['avatar']['dir']));
147         }
148
149         // Validate background dir
150
151         if (empty($values['background']['dir']) || !is_writable($values['background']['dir'])) {
152             $this->clientError(sprintf(_("Background directory not writable: %s"), $values['background']['dir']));
153         }
154
155         // Validate locales dir
156
157         // XXX: What else do we need to validate for lacales path here? --Z
158
159         if (!empty($values['site']['locale_path']) && !is_readable($values['site']['locale_path'])) {
160             $this->clientError(sprintf(_("Locales directory not readable: %s"), $values['site']['locale_path']));
161         }
162
163     }
164
165 }
166
167 class PathsAdminPanelForm extends AdminForm
168 {
169
170     /**
171      * ID of the form
172      *
173      * @return int ID of the form
174      */
175
176     function id()
177     {
178         return 'form_paths_admin_panel';
179     }
180
181     /**
182      * class of the form
183      *
184      * @return string class of the form
185      */
186
187     function formClass()
188     {
189         return 'form_settings';
190     }
191
192     /**
193      * Action of the form
194      *
195      * @return string URL of the action
196      */
197
198     function action()
199     {
200         return common_local_url('pathsadminpanel');
201     }
202
203     /**
204      * Data elements of the form
205      *
206      * @return void
207      */
208
209     function formData()
210     {
211         $this->out->elementStart('fieldset', array('id' => 'settings_paths_locale'));
212         $this->out->element('legend', null, _('Site'), 'site');
213         $this->out->elementStart('ul', 'form_data');
214
215         $this->li();
216         $this->input('path', _('Path'), _('Site path'));
217         $this->unli();
218
219         $this->li();
220         $this->input('locale_path', _('Path to locales'), _('Directory path to locales'), 'site');
221         $this->unli();
222
223         $this->out->elementEnd('ul');
224         $this->out->elementEnd('fieldset');
225
226         $this->out->elementStart('fieldset', array('id' => 'settings_paths_theme'));
227         $this->out->element('legend', null, _('Theme'));
228
229         $this->out->elementStart('ul', 'form_data');
230
231         $this->li();
232         $this->input('server', _('Theme server'), 'Server for themes', 'theme');
233         $this->unli();
234
235         $this->li();
236         $this->input('path', _('Theme path'), 'Web path to themes', 'theme');
237         $this->unli();
238
239         $this->li();
240         $this->input('dir', _('Theme directory'), 'Directory where themes are located', 'theme');
241         $this->unli();
242
243         $this->out->elementEnd('ul');
244
245         $this->out->elementEnd('fieldset');
246         $this->out->elementStart('fieldset', array('id' => 'settings_avatar-paths'));
247         $this->out->element('legend', null, _('Avatars'));
248
249         $this->out->elementStart('ul', 'form_data');
250
251         $this->li();
252         $this->input('server', _('Avatar server'), 'Server for avatars', 'avatar');
253         $this->unli();
254
255         $this->li();
256         $this->input('path', _('Avatar path'), 'Web path to avatars', 'avatar');
257         $this->unli();
258
259         $this->li();
260         $this->input('dir', _('Avatar directory'), 'Directory where avatars are located', 'avatar');
261         $this->unli();
262
263         $this->out->elementEnd('ul');
264
265         $this->out->elementEnd('fieldset');
266
267         $this->out->elementStart('fieldset', array('id' =>
268             'settings_design_background-paths'));
269         $this->out->element('legend', null, _('Backgrounds'));
270         $this->out->elementStart('ul', 'form_data');
271
272         $this->li();
273         $this->input('server', _('Background server'), 'Server for backgrounds', 'background');
274         $this->unli();
275
276         $this->li();
277         $this->input('path', _('Background path'), 'Web path to backgrounds', 'background');
278         $this->unli();
279
280         $this->li();
281         $this->input('dir', _('Background directory'), 'Directory where backgrounds are located', 'background');
282         $this->unli();
283
284         $this->out->elementEnd('ul');
285         $this->out->elementEnd('fieldset');
286     }
287
288     /**
289      * Action elements
290      *
291      * @return void
292      */
293
294     function formActions()
295     {
296         $this->out->submit('save', _('Save'), 'submit',
297                 'save', _('Save paths'));
298     }
299
300
301     /**
302      * Utility to simplify some of the duplicated code around
303      * params and settings. Overriding the input() in the base class
304      * to handle a whole bunch of cases of settings with the same
305      * name under different sections.
306      *
307      * @param string $setting      Name of the setting
308      * @param string $title        Title to use for the input
309      * @param string $instructions Instructions for this field
310      * @param string $section      config section, default = 'site'
311      *
312      * @return void
313      */
314
315     function input($setting, $title, $instructions, $section='site')
316     {
317         $this->out->input("$section-$setting", $title, $this->value($setting, $section), $instructions);
318     }
319
320 }