-
Notifications
You must be signed in to change notification settings - Fork 58
/
ManageCoreFeatures.php
415 lines (372 loc) · 12.2 KB
/
ManageCoreFeatures.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
<?php
/**
* @name ElkArte Forum
* @copyright ElkArte Forum contributors
* @license BSD http://opensource.org/licenses/BSD-3-Clause
*
* This software is a derived product, based on:
*
* Simple Machines Forum (SMF)
* copyright: 2011 Simple Machines (http://www.simplemachines.org)
* license: BSD, See included LICENSE.TXT for terms and conditions.
*
* @version 1.0 Alpha
*
* This file is here to make it easier for installed mods to have
* settings and options.
*
*/
if (!defined('ELK'))
die('No access...');
/**
* This class takes care of the Core Features admin screen.
* It sets up the context, initializes the features info for display,
* updates the settings for enabled/disabled core features as requested.
*
*/
class ManageCoreFeatures_Controller extends Action_Controller
{
/**
* Default handler.
*
* @see Action_Controller::action_index()
*/
public function action_index()
{
// just delegate to our preferred default
$this->action_features();
}
/**
* This is an overall control panel enabling/disabling lots of the forums key features.
*
* Uses internally an array of all the features that can be enabled/disabled.
* $core_features, each option can have the following:
* title - Text title of this item (If standard string does not exist).
* desc - Description of this feature (If standard string does not exist).
* settings - Array of settings to change (For each name => value) on enable - reverse is done for disable. If > 1 will not change value if set.
* setting_callback- Function that returns an array of settings to save - takes one parameter which is value for this feature.
* save_callback - Function called on save, takes state as parameter.
*
*/
public function action_features()
{
global $txt, $scripturl, $context, $settings, $modSettings;
loadTemplate('ManageCoreFeatures');
$core_features = $this->settings();
$this->loadGeneralSettingParameters();
// Are we saving?
if (isset($_POST['save']))
{
checkSession();
if (isset($_GET['xml']))
{
$tokenValidation = validateToken('admin-core', 'post', false);
if (empty($tokenValidation))
return 'token_verify_fail';
}
else
validateToken('admin-core');
$setting_changes = array('admin_features' => array());
// Cycle each feature and change things as required!
foreach ($core_features as $id => $feature)
{
// Enabled?
if (!empty($_POST['feature_' . $id]))
$setting_changes['admin_features'][] = $id;
// Setting values to change?
if (isset($feature['settings']))
{
foreach ($feature['settings'] as $key => $value)
{
if (empty($_POST['feature_' . $id]) || (!empty($_POST['feature_' . $id]) && ($value < 2 || empty($modSettings[$key]))))
$setting_changes[$key] = !empty($_POST['feature_' . $id]) ? $value : !$value;
}
}
// Is there a call back for settings?
if (isset($feature['setting_callback']))
{
$returned_settings = $feature['setting_callback'](!empty($_POST['feature_' . $id]));
if (!empty($returned_settings))
$setting_changes = array_merge($setting_changes, $returned_settings);
}
// Standard save callback?
if (isset($feature['on_save']))
$feature['on_save']();
}
// Make sure this one setting is a string!
$setting_changes['admin_features'] = implode(',', $setting_changes['admin_features']);
// Make any setting changes!
updateSettings($setting_changes);
// This is needed to let menus appear if cache > 2
if ($modSettings['cache_enable'] > 2)
clean_cache('data');
// Any post save things?
foreach ($core_features as $id => $feature)
{
// Standard save callback?
if (isset($feature['save_callback']))
$feature['save_callback'](!empty($_POST['feature_' . $id]));
}
if (!isset($_REQUEST['xml']))
redirectexit('action=admin;area=corefeatures;' . $context['session_var'] . '=' . $context['session_id']);
}
// Put them in context.
$context['features'] = array();
foreach ($core_features as $id => $feature)
$context['features'][$id] = array(
'title' => isset($feature['title']) ? $feature['title'] : $txt['core_settings_item_' . $id],
'desc' => isset($feature['desc']) ? $feature['desc'] : $txt['core_settings_item_' . $id . '_desc'],
'enabled' => in_array($id, $context['admin_features']),
'state' => in_array($id, $context['admin_features']) ? 'on' : 'off',
'url' => !empty($feature['url']) ? $scripturl . '?' . $feature['url'] . ';' . $context['session_var'] . '=' . $context['session_id'] : '',
'image' => (file_exists($settings['theme_dir'] . '/images/admin/feature_' . $id . '.png') ? $settings['images_url'] : $settings['default_images_url']) . '/admin/feature_' . $id . '.png',
);
// Are they a new user?
$context['is_new_install'] = !isset($modSettings['admin_features']);
$context['force_disable_tabs'] = $context['is_new_install'];
// Don't show them this twice!
if ($context['is_new_install'])
updateSettings(array('admin_features' => ''));
// sub_template is already generic_xml and the token is created somewhere else
if (isset($_REQUEST['xml']))
return;
$context['sub_template'] = 'core_features';
$context['page_title'] = $txt['core_settings_title'];
$context[$context['admin_menu_name']]['tab_data'] = array(
'title' => $txt['core_settings_title'],
'help' => '',
'description' => $txt['core_settings_desc'],
);
// We love our tokens.
createToken('admin-core');
}
/**
* Return the configuration settings available for core features page.
*/
public function settings()
{
$core_features = array(
// cd = calendar.
'cd' => array(
'url' => 'action=admin;area=managecalendar',
'settings' => array(
'cal_enabled' => 1,
),
),
// cp = custom profile fields.
'cp' => array(
'url' => 'action=admin;area=featuresettings;sa=profile',
'save_callback' => create_function('$value', '
$db = database();
if (!$value)
{
$db->query(\'\', \'
UPDATE {db_prefix}custom_fields
SET active = 0\');
}
'),
'setting_callback' => create_function('$value', '
if (!$value)
return array(
\'disabled_profile_fields\' => \'\',
\'registration_fields\' => \'\',
\'displayFields\' => \'\',
);
else
return array();
'),
),
// dr = drafts
'dr' => array(
'url' => 'action=admin;area=managedrafts',
'settings' => array(
'drafts_enabled' => 1,
'drafts_post_enabled' => 2,
'drafts_pm_enabled' => 2,
'drafts_autosave_enabled' => 2,
'drafts_show_saved_enabled' => 2,
),
'setting_callback' => create_function('$value', '
$db = database();
// Set the correct disabled value for the scheduled task.
$db->query(\'\', \'
UPDATE {db_prefix}scheduled_tasks
SET disabled = {int:disabled}
WHERE task = {string:task}\',
array(
\'disabled\' => $value ? 0 : 1,
\'task\' => \'remove_old_drafts\',
)
);
'),
),
// ih = Integration Hooks Handling.
'ih' => array(
'url' => 'action=admin;area=modsettings;sa=hooks',
'settings' => array(
'handlinghooks_enabled' => 1,
),
),
// k = karma.
'k' => array(
'url' => 'action=admin;area=featuresettings;sa=karma',
'settings' => array(
'karmaMode' => 2,
),
),
// l = likes.
'l' => array(
'url' => 'action=admin;area=featuresettings;sa=likes',
'settings' => array(
'likes_enabled' => 1,
),
),
// ml = moderation log.
'ml' => array(
'url' => 'action=admin;area=logs;sa=modlog',
'settings' => array(
'modlog_enabled' => 1,
),
),
// pe = post email
'pe' => array(
'url' => 'action=admin;area=maillist',
'settings' => array(
'maillist_enabled' => 1,
'pbe_post_enabled' => 2,
'pbe_pm_enabled' => 2,
),
),
// pm = post moderation.
'pm' => array(
'url' => 'action=admin;area=permissions;sa=postmod',
'setting_callback' => create_function('$value', '
// Cant use warning post moderation if disabled!
if (!$value)
{
require_once(SUBSDIR . \'/Moderation.subs.php\');
approveAllUnapproved();
return array(\'warning_moderate\' => 0);
}
else
return array();
'),
),
// ps = Paid Subscriptions.
'ps' => array(
'url' => 'action=admin;area=paidsubscribe',
'settings' => array(
'paid_enabled' => 1,
),
'setting_callback' => create_function('$value', '
$db = database();
// Set the correct disabled value for scheduled task.
$db->query(\'\', \'
UPDATE {db_prefix}scheduled_tasks
SET disabled = {int:disabled}
WHERE task = {string:task}\',
array(
\'disabled\' => $value ? 0 : 1,
\'task\' => \'paid_subscriptions\',
)
);
// Should we calculate next trigger?
if ($value)
{
require_once(SUBSDIR . \'/ScheduledTasks.subs.php\');
calculateNextTrigger(\'paid_subscriptions\');
}
'),
),
// rg = report generator.
'rg' => array(
'url' => 'action=admin;area=reports',
),
// w = warning.
'w' => array(
'url' => 'action=admin;area=securitysettings;sa=moderation',
'setting_callback' => create_function('$value', '
global $modSettings;
list ($modSettings[\'warning_enable\'], $modSettings[\'user_limit\'], $modSettings[\'warning_decrement\']) = explode(\',\', $modSettings[\'warning_settings\']);
$warning_settings = ($value ? 1 : 0) . \',\' . $modSettings[\'user_limit\'] . \',\' . $modSettings[\'warning_decrement\'];
if (!$value)
{
$returnSettings = array(
\'warning_watch\' => 0,
\'warning_moderate\' => 0,
\'warning_mute\' => 0,
);
}
elseif (empty($modSettings[\'warning_enable\']) && $value)
{
$returnSettings = array(
\'warning_watch\' => 10,
\'warning_moderate\' => 35,
\'warning_mute\' => 60,
);
}
else
$returnSettings = array();
$returnSettings[\'warning_settings\'] = $warning_settings;
return $returnSettings;
'),
),
// Search engines
'sp' => array(
'url' => 'action=admin;area=sengines',
'settings' => array(
'spider_mode' => 1,
),
'setting_callback' => create_function('$value', '
// Turn off the spider group if disabling.
if (!$value)
return array(\'spider_group\' => 0, \'show_spider_online\' => 0);
'),
'on_save' => create_function('', '
global $modSettings;
require_once(SUBSDIR . \'/SearchEngines.subs.php\');
'),
),
);
// Anyone who would like to add a core feature?
call_integration_hook('integrate_core_features', array(&$core_features));
return $core_features;
}
/**
* Return the array of core features in the format expected by search.
* Callback for admin internal search.
* @todo quick method to return config in admin search format, during refactoring timez :P
* (might fix this method to be consistent with the rest of config_vars for search)
*
* @return array
*/
public function config_vars()
{
global $txt;
$core_features = $this->settings();
$return_data = array();
foreach ($core_features as $id => $data)
$return_data[] = array('switch', isset($data['title']) ? $data['title'] : $txt['core_settings_item_' . $id]);
return $return_data;
}
/**
* This function makes sure the requested subaction does exists, if it doesn't, it sets a default action or.
*
* @param array $subActions = array() An array containing all possible subactions.
* @param string $defaultAction = '' the default action to be called if no valid subaction was found.
*/
public function loadGeneralSettingParameters($subActions = array(), $defaultAction = '')
{
global $context;
// You need to be an admin to edit settings!
isAllowedTo('admin_forum');
loadLanguage('Help');
loadLanguage('ManageSettings');
// Will need the utility functions from here.
require_once(SUBSDIR . '/Settings.class.php');
$context['sub_template'] = 'show_settings';
// By default do the basic settings.
$_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : (!empty($defaultAction) ? $defaultAction : array_pop($temp = array_keys($subActions)));
$context['sub_action'] = $_REQUEST['sa'];
}
}