Passed
Push — release-2.1 ( 0c2197...207d2d )
by Jeremy
05:47
created

ModifyAntispamSettings()   F

Complexity

Conditions 52
Paths > 20000

Size

Total Lines 309
Code Lines 157

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 52
eloc 157
c 0
b 0
f 0
nop 1
dl 0
loc 309
rs 0
nc 149762

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * This file is here to make it easier for installed mods to have
5
 * settings and options.
6
 *
7
 * Simple Machines Forum (SMF)
8
 *
9
 * @package SMF
10
 * @author Simple Machines http://www.simplemachines.org
11
 * @copyright 2018 Simple Machines and individual contributors
12
 * @license http://www.simplemachines.org/about/smf/license.php BSD
13
 *
14
 * @version 2.1 Beta 4
15
 */
16
17
if (!defined('SMF'))
18
	die('No direct access...');
19
20
/**
21
 * This function makes sure the requested subaction does exists, if it doesn't, it sets a default action or.
22
 *
23
 * @param array $subActions An array containing all possible subactions.
24
 * @param string $defaultAction The default action to be called if no valid subaction was found.
25
 */
26
function loadGeneralSettingParameters($subActions = array(), $defaultAction = null)
27
{
28
	global $context, $sourcedir;
29
30
	// You need to be an admin to edit settings!
31
	isAllowedTo('admin_forum');
32
33
	// Will need the utility functions from here.
34
	require_once($sourcedir . '/ManageServer.php');
35
36
	$context['sub_template'] = 'show_settings';
37
38
	// If no fallback was specified, use the first subaction.
39
	$defaultAction = $defaultAction ?: key($subActions);
40
41
	// I want...
42
	$_REQUEST['sa'] = isset($_REQUEST['sa'], $subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : $defaultAction;
43
	$context['sub_action'] = $_REQUEST['sa'];
44
}
45
46
/**
47
 * This function passes control through to the relevant tab.
48
 */
49
function ModifyFeatureSettings()
50
{
51
	global $context, $txt, $settings;
52
53
	loadLanguage('Help');
54
	loadLanguage('ManageSettings');
55
56
	$context['page_title'] = $txt['modSettings_title'];
57
58
	$subActions = array(
59
		'basic' => 'ModifyBasicSettings',
60
		'bbc' => 'ModifyBBCSettings',
61
		'layout' => 'ModifyLayoutSettings',
62
		'sig' => 'ModifySignatureSettings',
63
		'profile' => 'ShowCustomProfiles',
64
		'profileedit' => 'EditCustomProfiles',
65
		'likes' => 'ModifyLikesSettings',
66
		'mentions' => 'ModifyMentionsSettings',
67
		'alerts' => 'ModifyAlertsSettings',
68
	);
69
70
	// Load up all the tabs...
71
	$context[$context['admin_menu_name']]['tab_data'] = array(
72
		'title' => $txt['modSettings_title'],
73
		'help' => 'featuresettings',
74
		'description' => sprintf($txt['modSettings_desc'], $settings['theme_id'], $context['session_id'], $context['session_var']),
75
		'tabs' => array(
76
			'basic' => array(
77
			),
78
			'bbc' => array(
79
				'description' => $txt['manageposts_bbc_settings_description'],
80
			),
81
			'layout' => array(
82
			),
83
			'sig' => array(
84
				'description' => $txt['signature_settings_desc'],
85
			),
86
			'profile' => array(
87
				'description' => $txt['custom_profile_desc'],
88
			),
89
			'likes' => array(
90
			),
91
			'mentions' => array(
92
			),
93
			'alerts' => array(
94
				'description' => $txt['notifications_desc'],
95
			),
96
		),
97
	);
98
99
	call_integration_hook('integrate_modify_features', array(&$subActions));
100
101
	loadGeneralSettingParameters($subActions, 'basic');
102
103
	// Call the right function for this sub-action.
104
	call_helper($subActions[$_REQUEST['sa']]);
105
}
106
107
/**
108
 * This my friend, is for all the mod authors out there.
109
 */
110
function ModifyModSettings()
111
{
112
	global $context, $txt;
113
114
	loadLanguage('Help');
115
	loadLanguage('ManageSettings');
116
117
	$context['page_title'] = $txt['admin_modifications'];
118
119
	$subActions = array(
120
		'general' => 'ModifyGeneralModSettings',
121
		// Mod authors, once again, if you have a whole section to add do it AFTER this line, and keep a comma at the end.
122
	);
123
124
	// Load up all the tabs...
125
	$context[$context['admin_menu_name']]['tab_data'] = array(
126
		'title' => $txt['admin_modifications'],
127
		'help' => 'modsettings',
128
		'description' => $txt['modification_settings_desc'],
129
		'tabs' => array(
130
			'general' => array(
131
			),
132
		),
133
	);
134
135
	// Make it easier for mods to add new areas.
136
	call_integration_hook('integrate_modify_modifications', array(&$subActions));
137
138
	loadGeneralSettingParameters($subActions, 'general');
139
140
	// Call the right function for this sub-action.
141
	call_helper($subActions[$_REQUEST['sa']]);
142
}
143
144
/**
145
 * Config array for changing the basic forum settings
146
 * Accessed  from ?action=admin;area=featuresettings;sa=basic;
147
 *
148
 * @param bool $return_config Whether or not to return the config_vars array (used for admin search)
149
 * @return void|array Returns nothing or returns the $config_vars array if $return_config is true
150
 */
151
function ModifyBasicSettings($return_config = false)
152
{
153
	global $txt, $scripturl, $context, $modSettings;
154
155
	// We need to know if personal text is enabled, and if it's in the registration fields option.
156
	// If admins have set it up as an on-registration thing, they can't set a default value (because it'll never be used)
157
	$disabled_fields = isset($modSettings['disabled_profile_fields']) ? explode(',', $modSettings['disabled_profile_fields']) : array();
158
	$reg_fields = isset($modSettings['registration_fields']) ? explode(',', $modSettings['registration_fields']) : array();
159
	$can_personal_text = !in_array('personal_text', $disabled_fields) && !in_array('personal_text', $reg_fields);
160
161
	$config_vars = array(
162
			// Big Options... polls, sticky, bbc....
163
			array('select', 'pollMode', array($txt['disable_polls'], $txt['enable_polls'], $txt['polls_as_topics'])),
164
		'',
165
			// Basic stuff, titles, flash, permissions...
166
			array('check', 'allow_guestAccess'),
167
			array('check', 'enable_buddylist'),
168
			array('check', 'allow_hideOnline'),
169
			array('check', 'titlesEnable'),
170
			array('text', 'default_personal_text', 'subtext' => $txt['default_personal_text_note'], 'disabled' => !$can_personal_text),
171
			array('check', 'topic_move_any'),
172
			array('int', 'defaultMaxListItems', 'step' => 1, 'min' => 1, 'max' => 999),
173
		'',
174
			// Jquery source
175
			array('select', 'jquery_source', array('auto' => $txt['jquery_auto'], 'local' => $txt['jquery_local'], 'cdn' => $txt['jquery_cdn'], 'custom' => $txt['jquery_custom']), 'onchange' => 'if (this.value == \'custom\'){document.getElementById(\'jquery_custom\').disabled = false; } else {document.getElementById(\'jquery_custom\').disabled = true;}'),
176
			array('text', 'jquery_custom', 'disabled' => isset($modSettings['jquery_source']) && $modSettings['jquery_source'] != 'custom', 'size' => 75),
177
		'',
178
			// css and js minification.
179
			array('check', 'minimize_files'),
180
		'',
181
			// SEO stuff
182
			array('check', 'queryless_urls', 'subtext' => '<strong>' . $txt['queryless_urls_note'] . '</strong>'),
183
			array('text', 'meta_keywords', 'subtext' => $txt['meta_keywords_note'], 'size' => 50),
184
		'',
185
			// Number formatting, timezones.
186
			array('text', 'time_format'),
187
			array('float', 'time_offset', 'subtext' => $txt['setting_time_offset_note'], 6, 'postinput' => $txt['hours'], 'step' => 0.25, 'min' => -23.5, 'max' => 23.5),
188
			'default_timezone' => array('select', 'default_timezone', array()),
189
			array('text', 'timezone_priority_countries', 'subtext' => $txt['setting_timezone_priority_countries_note']),
190
		'',
191
			// Who's online?
192
			array('check', 'who_enabled'),
193
			array('int', 'lastActive', 6, 'postinput' => $txt['minutes']),
194
		'',
195
			// Statistics.
196
			array('check', 'trackStats'),
197
			array('check', 'hitStats'),
198
		'',
199
			// Option-ish things... miscellaneous sorta.
200
			array('check', 'allow_disableAnnounce'),
201
			array('check', 'disallow_sendBody'),
202
		'',
203
			// Alerts stuff
204
			array('check', 'enable_ajax_alerts'),
205
	);
206
207
	// Get all the time zones.
208
	if (function_exists('timezone_identifiers_list') && function_exists('date_default_timezone_set'))
209
	{
210
		$all_zones = timezone_identifiers_list();
211
		// Make sure we set the value to the same as the printed value.
212
		foreach ($all_zones as $zone)
213
			$config_vars['default_timezone'][2][$zone] = $zone;
214
	}
215
	else
216
		unset($config_vars['default_timezone']);
217
218
	call_integration_hook('integrate_modify_basic_settings', array(&$config_vars));
219
220
	if ($return_config)
221
		return $config_vars;
222
223
	// Saving?
224
	if (isset($_GET['save']))
225
	{
226
		checkSession();
227
228
		// Prevent absurd boundaries here - make it a day tops.
229
		if (isset($_POST['lastActive']))
230
			$_POST['lastActive'] = min((int) $_POST['lastActive'], 1440);
231
232
		call_integration_hook('integrate_save_basic_settings');
233
234
		saveDBSettings($config_vars);
235
		$_SESSION['adm-save'] = true;
236
237
		// Do a bit of housekeeping
238
		if (empty($_POST['minimize_files']))
239
			deleteAllMinified();
240
241
		writeLog();
242
		redirectexit('action=admin;area=featuresettings;sa=basic');
243
	}
244
245
	$context['post_url'] = $scripturl . '?action=admin;area=featuresettings;save;sa=basic';
246
	$context['settings_title'] = $txt['mods_cat_features'];
247
248
	prepareDBSettingContext($config_vars);
249
}
250
251
/**
252
 * Set a few Bulletin Board Code settings. It loads a list of Bulletin Board Code tags to allow disabling tags.
253
 * Requires the admin_forum permission.
254
 * Accessed from ?action=admin;area=featuresettings;sa=bbc.
255
 *
256
 * @param bool $return_config Whether or not to return the config_vars array (used for admin search)
257
 * @return void|array Returns nothing or returns the $config_vars array if $return_config is true
258
 * @uses Admin template, edit_bbc_settings sub-template.
259
 */
260
function ModifyBBCSettings($return_config = false)
261
{
262
	global $context, $txt, $modSettings, $scripturl, $sourcedir;
263
264
	$config_vars = array(
265
			// Main tweaks
266
			array('check', 'enableBBC'),
267
			array('check', 'enableBBC', 0, 'onchange' => 'toggleBBCDisabled(\'disabledBBC\', !this.checked);'),
268
			array('check', 'enablePostHTML'),
269
			array('check', 'autoLinkUrls'),
270
		'',
271
			array('bbc', 'disabledBBC'),
272
	);
273
274
	$context['settings_post_javascript'] = '
275
		toggleBBCDisabled(\'disabledBBC\', ' . (empty($modSettings['enableBBC']) ? 'true' : 'false') . ');';
276
277
	call_integration_hook('integrate_modify_bbc_settings', array(&$config_vars));
278
279
	if ($return_config)
280
		return $config_vars;
281
282
	// Setup the template.
283
	require_once($sourcedir . '/ManageServer.php');
284
	$context['sub_template'] = 'show_settings';
285
	$context['page_title'] = $txt['manageposts_bbc_settings_title'];
286
287
	// Make sure we check the right tags!
288
	$modSettings['bbc_disabled_disabledBBC'] = empty($modSettings['disabledBBC']) ? array() : explode(',', $modSettings['disabledBBC']);
289
290
	// Saving?
291
	if (isset($_GET['save']))
292
	{
293
		checkSession();
294
295
		// Clean up the tags.
296
		$bbcTags = array();
297
		foreach (parse_bbc(false) as $tag)
298
			$bbcTags[] = $tag['tag'];
299
300
		if (!isset($_POST['disabledBBC_enabledTags']))
301
			$_POST['disabledBBC_enabledTags'] = array();
302
		elseif (!is_array($_POST['disabledBBC_enabledTags']))
303
			$_POST['disabledBBC_enabledTags'] = array($_POST['disabledBBC_enabledTags']);
304
		// Work out what is actually disabled!
305
		$_POST['disabledBBC'] = implode(',', array_diff($bbcTags, $_POST['disabledBBC_enabledTags']));
306
307
		call_integration_hook('integrate_save_bbc_settings', array($bbcTags));
308
309
		saveDBSettings($config_vars);
310
		$_SESSION['adm-save'] = true;
311
		redirectexit('action=admin;area=featuresettings;sa=bbc');
312
	}
313
314
	$context['post_url'] = $scripturl . '?action=admin;area=featuresettings;save;sa=bbc';
315
	$context['settings_title'] = $txt['manageposts_bbc_settings_title'];
316
317
	prepareDBSettingContext($config_vars);
318
}
319
320
/**
321
 * Allows modifying the global layout settings in the forum
322
 * Accessed through ?action=admin;area=featuresettings;sa=layout;
323
 *
324
 * @param bool $return_config Whether or not to return the config_vars array (used for admin search)
325
 * @return void|array Returns nothing or returns the $config_vars array if $return_config is true
326
 */
327
function ModifyLayoutSettings($return_config = false)
328
{
329
	global $txt, $scripturl, $context;
330
331
	$config_vars = array(
332
			// Pagination stuff.
333
			array('check', 'compactTopicPagesEnable'),
334
			array('int', 'compactTopicPagesContiguous', null, $txt['contiguous_page_display'] . '<div class="smalltext">' . str_replace(' ', '&nbsp;', '"3" ' . $txt['to_display'] . ': <strong>1 ... 4 [5] 6 ... 9</strong>') . '<br>' . str_replace(' ', '&nbsp;', '"5" ' . $txt['to_display'] . ': <strong>1 ... 3 4 [5] 6 7 ... 9</strong>') . '</div>'),
335
			array('int', 'defaultMaxMembers'),
336
		'',
337
			// Stuff that just is everywhere - today, search, online, etc.
338
			array('select', 'todayMod', array($txt['today_disabled'], $txt['today_only'], $txt['yesterday_today'])),
339
			array('check', 'onlineEnable'),
340
		'',
341
			// This is like debugging sorta.
342
			array('check', 'timeLoadPageEnable'),
343
	);
344
345
	call_integration_hook('integrate_layout_settings', array(&$config_vars));
346
347
	if ($return_config)
348
		return $config_vars;
349
350
	// Saving?
351
	if (isset($_GET['save']))
352
	{
353
		checkSession();
354
355
		call_integration_hook('integrate_save_layout_settings');
356
357
		saveDBSettings($config_vars);
358
		$_SESSION['adm-save'] = true;
359
		writeLog();
360
361
		redirectexit('action=admin;area=featuresettings;sa=layout');
362
	}
363
364
	$context['post_url'] = $scripturl . '?action=admin;area=featuresettings;save;sa=layout';
365
	$context['settings_title'] = $txt['mods_cat_layout'];
366
367
	prepareDBSettingContext($config_vars);
368
}
369
370
/**
371
 * Config array for changing like settings
372
 * Accessed  from ?action=admin;area=featuresettings;sa=likes;
373
 *
374
 * @param bool $return_config Whether or not to return the config_vars array
375
 * @return void|array Returns nothing or returns the $config_vars array if $return_config is true
376
 */
377
function ModifyLikesSettings($return_config = false)
378
{
379
	global $txt, $scripturl, $context;
380
381
	$config_vars = array(
382
		array('check', 'enable_likes'),
383
		array('permissions', 'likes_like'),
384
	);
385
386
	call_integration_hook('integrate_likes_settings', array(&$config_vars));
387
388
	if ($return_config)
389
		return $config_vars;
390
391
	// Saving?
392
	if (isset($_GET['save']))
393
	{
394
		checkSession();
395
396
		call_integration_hook('integrate_save_likes_settings');
397
398
		saveDBSettings($config_vars);
399
		$_SESSION['adm-save'] = true;
400
		redirectexit('action=admin;area=featuresettings;sa=likes');
401
	}
402
403
	$context['post_url'] = $scripturl . '?action=admin;area=featuresettings;save;sa=likes';
404
	$context['settings_title'] = $txt['likes'];
405
406
	prepareDBSettingContext($config_vars);
407
}
408
409
/**
410
 * Config array for changing like settings
411
 * Accessed  from ?action=admin;area=featuresettings;sa=mentions;
412
 *
413
 * @param bool $return_config Whether or not to return the config_vars array (used for admin search)
414
 * @return void|array Returns nothing or returns the $config_vars array if $return_config is true
415
 */
416
function ModifyMentionsSettings($return_config = false)
417
{
418
	global $txt, $scripturl, $context;
419
420
	$config_vars = array(
421
		array('check', 'enable_mentions'),
422
		array('permissions', 'mention'),
423
	);
424
425
	call_integration_hook('integrate_mentions_settings', array(&$config_vars));
426
427
	if ($return_config)
428
		return $config_vars;
429
430
	// Saving?
431
	if (isset($_GET['save']))
432
	{
433
		checkSession();
434
435
		call_integration_hook('integrate_save_mentions_settings');
436
437
		saveDBSettings($config_vars);
438
		$_SESSION['adm-save'] = true;
439
		redirectexit('action=admin;area=featuresettings;sa=mentions');
440
	}
441
442
	$context['post_url'] = $scripturl . '?action=admin;area=featuresettings;save;sa=mentions';
443
	$context['settings_title'] = $txt['mentions'];
444
445
	prepareDBSettingContext($config_vars);
446
}
447
448
/**
449
 * Moderation type settings - although there are fewer than we have you believe ;)
450
 *
451
 * @param bool $return_config Whether or not to return the config_vars array (used for admin search)
452
 * @return void|array Returns nothing or returns the $config_vars array if $return_config is true
453
 */
454
function ModifyWarningSettings($return_config = false)
455
{
456
	global $txt, $scripturl, $context, $modSettings, $sourcedir;
457
458
	// You need to be an admin to edit settings!
459
	isAllowedTo('admin_forum');
460
461
	loadLanguage('Help');
462
	loadLanguage('ManageSettings');
463
464
	// We need the existing ones for this
465
	list ($currently_enabled, $modSettings['user_limit'], $modSettings['warning_decrement']) = explode(',', $modSettings['warning_settings']);
466
467
	$config_vars = array(
468
			// Warning system?
469
			'enable' => array('check', 'warning_enable'),
470
	);
471
472
	if (!empty($modSettings['warning_settings']) && $currently_enabled)
473
		$config_vars += array(
474
			'',
475
				array('int', 'warning_watch', 'subtext' => $txt['setting_warning_watch_note'] . ' ' . $txt['zero_to_disable']),
476
				'moderate' => array('int', 'warning_moderate', 'subtext' => $txt['setting_warning_moderate_note'] . ' ' . $txt['zero_to_disable']),
477
				array('int', 'warning_mute', 'subtext' => $txt['setting_warning_mute_note'] . ' ' . $txt['zero_to_disable']),
478
				'rem1' => array('int', 'user_limit', 'subtext' => $txt['setting_user_limit_note']),
479
				'rem2' => array('int', 'warning_decrement', 'subtext' => $txt['setting_warning_decrement_note'] . ' ' . $txt['zero_to_disable']),
480
				array('permissions', 'view_warning'),
481
		);
482
483
	call_integration_hook('integrate_warning_settings', array(&$config_vars));
484
485
	if ($return_config)
486
		return $config_vars;
487
488
	// Cannot use moderation if post moderation is not enabled.
489
	if (!$modSettings['postmod_active'])
490
		unset($config_vars['moderate']);
491
492
	// Will need the utility functions from here.
493
	require_once($sourcedir . '/ManageServer.php');
494
495
	// Saving?
496
	if (isset($_GET['save']))
497
	{
498
		checkSession();
499
500
		// Make sure these don't have an effect.
501
		if (!$currently_enabled && empty($_POST['warning_enable']))
502
		{
503
			$_POST['warning_watch'] = 0;
504
			$_POST['warning_moderate'] = 0;
505
			$_POST['warning_mute'] = 0;
506
		}
507
		// If it was disabled and we're enabling it now, set some sane defaults.
508
		elseif (!$currently_enabled && !empty($_POST['warning_enable']))
509
		{
510
			// Need to add these, these weren't there before...
511
			$vars = array(
512
				'warning_watch' => 10,
513
				'warning_mute' => 60,
514
			);
515
			if ($modSettings['postmod_active'])
516
				$vars['warning_moderate'] = 35;
517
518
			foreach ($vars as $var => $value)
519
			{
520
				$config_vars[] = array('int', $var);
521
				$_POST[$var] = $value;
522
			}
523
		}
524
		else
525
		{
526
			$_POST['warning_watch'] = min($_POST['warning_watch'], 100);
527
			$_POST['warning_moderate'] = $modSettings['postmod_active'] ? min($_POST['warning_moderate'], 100) : 0;
528
			$_POST['warning_mute'] = min($_POST['warning_mute'], 100);
529
		}
530
531
		// We might not have these already depending on how we got here.
532
		$_POST['user_limit'] = isset($_POST['user_limit']) ? (int) $_POST['user_limit'] : $modSettings['user_limit'];
533
		$_POST['warning_decrement'] = isset($_POST['warning_decrement']) ? (int) $_POST['warning_decrement'] : $modSettings['warning_decrement'];
534
535
		// Fix the warning setting array!
536
		$_POST['warning_settings'] = (!empty($_POST['warning_enable']) ? 1 : 0) . ',' . min(100, $_POST['user_limit']) . ',' . min(100, $_POST['warning_decrement']);
537
		$save_vars = $config_vars;
538
		$save_vars[] = array('text', 'warning_settings');
539
		unset($save_vars['enable'], $save_vars['rem1'], $save_vars['rem2']);
540
541
		call_integration_hook('integrate_save_warning_settings', array(&$save_vars));
542
543
		saveDBSettings($save_vars);
544
		$_SESSION['adm-save'] = true;
545
		redirectexit('action=admin;area=warnings');
546
	}
547
548
	// We actually store lots of these together - for efficiency.
549
	list ($modSettings['warning_enable'], $modSettings['user_limit'], $modSettings['warning_decrement']) = explode(',', $modSettings['warning_settings']);
550
551
	$context['sub_template'] = 'show_settings';
552
	$context['post_url'] = $scripturl . '?action=admin;area=warnings;save';
553
	$context['settings_title'] = $txt['warnings'];
554
	$context['page_title'] = $txt['warnings'];
555
556
	$context[$context['admin_menu_name']]['tab_data'] = array(
557
		'title' => $txt['warnings'],
558
		'help' => '',
559
		'description' => $txt['warnings_desc'],
560
	);
561
562
	prepareDBSettingContext($config_vars);
563
}
564
565
/**
566
 * Let's try keep the spam to a minimum ah Thantos?
567
 * @param bool $return_config Whether or not to return the config_vars array (used for admin search)
568
 * @return void|array Returns nothing or returns the $config_vars array if $return_config is true
569
 */
570
function ModifyAntispamSettings($return_config = false)
571
{
572
	global $txt, $scripturl, $context, $modSettings, $smcFunc, $language, $sourcedir;
573
574
	loadLanguage('Help');
575
	loadLanguage('ManageSettings');
576
577
	// Generate a sample registration image.
578
	$context['use_graphic_library'] = in_array('gd', get_loaded_extensions());
579
	$context['verification_image_href'] = $scripturl . '?action=verificationcode;rand=' . md5(mt_rand());
580
581
	$config_vars = array(
582
				array('check', 'reg_verification'),
583
				array('check', 'search_enable_captcha'),
584
				// This, my friend, is a cheat :p
585
				'guest_verify' => array('check', 'guests_require_captcha', 'subtext' => $txt['setting_guests_require_captcha_desc']),
586
				array('int', 'posts_require_captcha', 'subtext' => $txt['posts_require_captcha_desc'], 'onchange' => 'if (this.value > 0){ document.getElementById(\'guests_require_captcha\').checked = true; document.getElementById(\'guests_require_captcha\').disabled = true;} else {document.getElementById(\'guests_require_captcha\').disabled = false;}'),
587
			'',
588
			// PM Settings
589
				'pm1' => array('int', 'max_pm_recipients', 'subtext' => $txt['max_pm_recipients_note']),
590
				'pm2' => array('int', 'pm_posts_verification', 'subtext' => $txt['pm_posts_verification_note']),
591
				'pm3' => array('int', 'pm_posts_per_hour', 'subtext' => $txt['pm_posts_per_hour_note']),
592
			// Visual verification.
593
			array('title', 'configure_verification_means'),
594
			array('desc', 'configure_verification_means_desc'),
595
				'vv' => array('select', 'visual_verification_type', array($txt['setting_image_verification_off'], $txt['setting_image_verification_vsimple'], $txt['setting_image_verification_simple'], $txt['setting_image_verification_medium'], $txt['setting_image_verification_high'], $txt['setting_image_verification_extreme']), 'subtext' => $txt['setting_visual_verification_type_desc'], 'onchange' => $context['use_graphic_library'] ? 'refreshImages();' : ''),
596
			// reCAPTCHA
597
			array('title', 'recaptcha_configure'),
598
			array('desc', 'recaptcha_configure_desc', 'class' => 'windowbg'),
599
				array('check', 'recaptcha_enabled', 'subtext' => $txt['recaptcha_enable_desc']),
600
				array('text', 'recaptcha_site_key', 'subtext' => $txt['recaptcha_site_key_desc']),
601
				array('text', 'recaptcha_secret_key', 'subtext' => $txt['recaptcha_secret_key_desc']),
602
				array('select', 'recaptcha_theme', array('light' => $txt['recaptcha_theme_light'], 'dark' => $txt['recaptcha_theme_dark'])),
603
			// Clever Thomas, who is looking sheepy now? Not I, the mighty sword swinger did say.
604
			array('title', 'setup_verification_questions'),
605
			array('desc', 'setup_verification_questions_desc'),
606
				array('int', 'qa_verification_number', 'subtext' => $txt['setting_qa_verification_number_desc']),
607
				array('callback', 'question_answer_list'),
608
	);
609
610
	call_integration_hook('integrate_spam_settings', array(&$config_vars));
611
612
	if ($return_config)
613
		return $config_vars;
614
615
	// You need to be an admin to edit settings!
616
	isAllowedTo('admin_forum');
617
618
	// Firstly, figure out what languages we're dealing with, and do a little processing for the form's benefit.
619
	getLanguages();
620
	$context['qa_languages'] = array();
621
	foreach ($context['languages'] as $lang_id => $lang)
622
	{
623
		$lang_id = strtr($lang_id, array('-utf8' => ''));
624
		$lang['name'] = strtr($lang['name'], array('-utf8' => ''));
625
		$context['qa_languages'][$lang_id] = $lang;
626
	}
627
628
	// Secondly, load any questions we currently have.
629
	$context['question_answers'] = array();
630
	$request = $smcFunc['db_query']('', '
631
		SELECT id_question, lngfile, question, answers
632
		FROM {db_prefix}qanda'
633
	);
634
	while ($row = $smcFunc['db_fetch_assoc']($request))
635
	{
636
		$lang = strtr($row['lngfile'], array('-utf8' => ''));
637
		$context['question_answers'][$row['id_question']] = array(
638
			'lngfile' => $lang,
639
			'question' => $row['question'],
640
			'answers' => $smcFunc['json_decode']($row['answers'], true),
641
		);
642
		$context['qa_by_lang'][$lang][] = $row['id_question'];
643
	}
644
645
	if (empty($context['qa_by_lang'][strtr($language, array('-utf8' => ''))]) && !empty($context['question_answers']))
646
	{
647
		if (empty($context['settings_insert_above']))
648
			$context['settings_insert_above'] = '';
649
650
		$context['settings_insert_above'] .= '<div class="noticebox">' . sprintf($txt['question_not_defined'], $context['languages'][$language]['name']) . '</div>';
651
	}
652
653
	// Thirdly, push some JavaScript for the form to make it work.
654
	addInlineJavaScript('
655
	var nextrow = ' . (!empty($context['question_answers']) ? max(array_keys($context['question_answers'])) + 1 : 1) . ';
656
	$(".qa_link a").click(function() {
657
		var id = $(this).parent().attr("id").substring(6);
658
		$("#qa_fs_" + id).show();
659
		$(this).parent().hide();
660
	});
661
	$(".qa_fieldset legend a").click(function() {
662
		var id = $(this).closest("fieldset").attr("id").substring(6);
663
		$("#qa_dt_" + id).show();
664
		$(this).closest("fieldset").hide();
665
	});
666
	$(".qa_add_question a").click(function() {
667
		var id = $(this).closest("fieldset").attr("id").substring(6);
668
		$(\'<dt><input type="text" name="question[\' + id + \'][\' + nextrow + \']" value="" size="50" class="verification_question"></dt><dd><input type="text" name="answer[\' + id + \'][\' + nextrow + \'][]" value="" size="50" class="verification_answer" / ><div class="qa_add_answer"><a href="javascript:void(0);">[ \' + ' . JavaScriptEscape($txt['setup_verification_add_answer']) . ' + \' ]</a></div></dd>\').insertBefore($(this).parent());
669
		nextrow++;
670
	});
671
	$(".qa_add_answer a").click(function() {
672
		var attr = $(this).closest("dd").find(".verification_answer:last").attr("name");
673
		$(\'<input type="text" name="\' + attr + \'" value="" size="50" class="verification_answer">\').insertBefore($(this).closest("div"));
674
		return false;
675
	});
676
	$("#qa_dt_' . strtr($language, array('-utf8' => '')) . ' a").click();', true);
677
678
	// Will need the utility functions from here.
679
	require_once($sourcedir . '/ManageServer.php');
680
681
	// Saving?
682
	if (isset($_GET['save']))
683
	{
684
		checkSession();
685
686
		// Fix PM settings.
687
		$_POST['pm_spam_settings'] = (int) $_POST['max_pm_recipients'] . ',' . (int) $_POST['pm_posts_verification'] . ',' . (int) $_POST['pm_posts_per_hour'];
688
689
		// Hack in guest requiring verification!
690
		if (empty($_POST['posts_require_captcha']) && !empty($_POST['guests_require_captcha']))
691
			$_POST['posts_require_captcha'] = -1;
692
693
		$save_vars = $config_vars;
694
		unset($save_vars['pm1'], $save_vars['pm2'], $save_vars['pm3'], $save_vars['guest_verify']);
695
696
		$save_vars[] = array('text', 'pm_spam_settings');
697
698
		// Handle verification questions.
699
		$changes = array(
700
			'insert' => array(),
701
			'replace' => array(),
702
			'delete' => array(),
703
		);
704
		$qs_per_lang = array();
705
		foreach ($context['qa_languages'] as $lang_id => $dummy)
706
		{
707
			// If we had some questions for this language before, but don't now, delete everything from that language.
708
			if ((!isset($_POST['question'][$lang_id]) || !is_array($_POST['question'][$lang_id])) && !empty($context['qa_by_lang'][$lang_id]))
709
				$changes['delete'] = array_merge($questions['delete'], $context['qa_by_lang'][$lang_id]);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $questions does not exist. Did you maybe mean $question?
Loading history...
710
711
			// Now step through and see if any existing questions no longer exist.
712
			if (!empty($context['qa_by_lang'][$lang_id]))
713
				foreach ($context['qa_by_lang'][$lang_id] as $q_id)
714
					if (empty($_POST['question'][$lang_id][$q_id]))
715
						$changes['delete'][] = $q_id;
716
717
			// Now let's see if there are new questions or ones that need updating.
718
			if (isset($_POST['question'][$lang_id]))
719
			{
720
				foreach ($_POST['question'][$lang_id] as $q_id => $question)
721
				{
722
					// Ignore junky ids.
723
					$q_id = (int) $q_id;
724
					if ($q_id <= 0)
725
						continue;
726
727
					// Check the question isn't empty (because they want to delete it?)
728
					if (empty($question) || trim($question) == '')
729
					{
730
						if (isset($context['question_answers'][$q_id]))
731
							$changes['delete'][] = $q_id;
732
						continue;
733
					}
734
					$question = $smcFunc['htmlspecialchars'](trim($question));
735
736
					// Get the answers. Firstly check there actually might be some.
737
					if (!isset($_POST['answer'][$lang_id][$q_id]) || !is_array($_POST['answer'][$lang_id][$q_id]))
738
					{
739
						if (isset($context['question_answers'][$q_id]))
740
							$changes['delete'][] = $q_id;
741
						continue;
742
					}
743
					// Now get them and check that they might be viable.
744
					$answers = array();
745
					foreach ($_POST['answer'][$lang_id][$q_id] as $answer)
746
						if (!empty($answer) && trim($answer) !== '')
747
							$answers[] = $smcFunc['htmlspecialchars'](trim($answer));
748
					if (empty($answers))
749
					{
750
						if (isset($context['question_answers'][$q_id]))
751
							$changes['delete'][] = $q_id;
752
						continue;
753
					}
754
					$answers = $smcFunc['json_encode']($answers);
755
756
					// At this point we know we have a question and some answers. What are we doing with it?
757
					if (!isset($context['question_answers'][$q_id]))
758
					{
759
						// New question. Now, we don't want to randomly consume ids, so we'll set those, rather than trusting the browser's supplied ids.
760
						$changes['insert'][] = array($lang_id, $question, $answers);
761
					}
762
					else
763
					{
764
						// It's an existing question. Let's see what's changed, if anything.
765
						if ($lang_id != $context['question_answers'][$q_id]['lngfile'] || $question != $context['question_answers'][$q_id]['question'] || $answers != $context['question_answers'][$q_id]['answers'])
766
							$changes['replace'][$q_id] = array('lngfile' => $lang_id, 'question' => $question, 'answers' => $answers);
767
					}
768
769
					if (!isset($qs_per_lang[$lang_id]))
770
						$qs_per_lang[$lang_id] = 0;
771
					$qs_per_lang[$lang_id]++;
772
				}
773
			}
774
		}
775
776
		// OK, so changes?
777
		if (!empty($changes['delete']))
778
		{
779
			$smcFunc['db_query']('', '
780
				DELETE FROM {db_prefix}qanda
781
				WHERE id_question IN ({array_int:questions})',
782
				array(
783
					'questions' => $changes['delete'],
784
				)
785
			);
786
		}
787
788
		if (!empty($changes['replace']))
789
		{
790
			foreach ($changes['replace'] as $q_id => $question)
791
			{
792
				$smcFunc['db_query']('', '
793
					UPDATE {db_prefix}qanda
794
					SET lngfile = {string:lngfile},
795
						question = {string:question},
796
						answers = {string:answers}
797
					WHERE id_question = {int:id_question}',
798
					array(
799
						'id_question' => $q_id,
800
						'lngfile' => $question['lngfile'],
801
						'question' => $question['question'],
802
						'answers' => $question['answers'],
803
					)
804
				);
805
			}
806
		}
807
808
		if (!empty($changes['insert']))
809
		{
810
			$smcFunc['db_insert']('insert',
811
				'{db_prefix}qanda',
812
				array('lngfile' => 'string-50', 'question' => 'string-255', 'answers' => 'string-65534'),
813
				$changes['insert'],
814
				array('id_question')
815
			);
816
		}
817
818
		// Lastly, the count of messages needs to be no more than the lowest number of questions for any one language.
819
		$count_questions = empty($qs_per_lang) ? 0 : min($qs_per_lang);
820
		if (empty($count_questions) || $_POST['qa_verification_number'] > $count_questions)
821
			$_POST['qa_verification_number'] = $count_questions;
822
823
		call_integration_hook('integrate_save_spam_settings', array(&$save_vars));
824
825
		// Now save.
826
		saveDBSettings($save_vars);
827
		$_SESSION['adm-save'] = true;
828
829
		cache_put_data('verificationQuestions', null, 300);
830
831
		redirectexit('action=admin;area=antispam');
832
	}
833
834
	$character_range = array_merge(range('A', 'H'), array('K', 'M', 'N', 'P', 'R'), range('T', 'Y'));
835
	$_SESSION['visual_verification_code'] = '';
836
	for ($i = 0; $i < 6; $i++)
837
		$_SESSION['visual_verification_code'] .= $character_range[array_rand($character_range)];
838
839
	// Some javascript for CAPTCHA.
840
	$context['settings_post_javascript'] = '';
841
	if ($context['use_graphic_library'])
842
		$context['settings_post_javascript'] .= '
843
		function refreshImages()
844
		{
845
			var imageType = document.getElementById(\'visual_verification_type\').value;
846
			document.getElementById(\'verification_image\').src = \'' . $context['verification_image_href'] . ';type=\' + imageType;
847
		}';
848
849
	// Show the image itself, or text saying we can't.
850
	if ($context['use_graphic_library'])
851
		$config_vars['vv']['postinput'] = '<br><img src="' . $context['verification_image_href'] . ';type=' . (empty($modSettings['visual_verification_type']) ? 0 : $modSettings['visual_verification_type']) . '" alt="' . $txt['setting_image_verification_sample'] . '" id="verification_image"><br>';
852
	else
853
		$config_vars['vv']['postinput'] = '<br><span class="smalltext">' . $txt['setting_image_verification_nogd'] . '</span>';
854
855
	// Hack for PM spam settings.
856
	list ($modSettings['max_pm_recipients'], $modSettings['pm_posts_verification'], $modSettings['pm_posts_per_hour']) = explode(',', $modSettings['pm_spam_settings']);
857
858
	// Hack for guests requiring verification.
859
	$modSettings['guests_require_captcha'] = !empty($modSettings['posts_require_captcha']);
860
	$modSettings['posts_require_captcha'] = !isset($modSettings['posts_require_captcha']) || $modSettings['posts_require_captcha'] == -1 ? 0 : $modSettings['posts_require_captcha'];
861
862
	// Some minor javascript for the guest post setting.
863
	if ($modSettings['posts_require_captcha'])
864
		$context['settings_post_javascript'] .= '
865
		document.getElementById(\'guests_require_captcha\').disabled = true;';
866
867
	// And everything else.
868
	$context['post_url'] = $scripturl . '?action=admin;area=antispam;save';
869
	$context['settings_title'] = $txt['antispam_Settings'];
870
	$context['page_title'] = $txt['antispam_title'];
871
	$context['sub_template'] = 'show_settings';
872
873
	$context[$context['admin_menu_name']]['tab_data'] = array(
874
		'title' => $txt['antispam_title'],
875
		'description' => $txt['antispam_Settings_desc'],
876
	);
877
878
	prepareDBSettingContext($config_vars);
879
}
880
881
/**
882
 * You'll never guess what this function does...
883
 *
884
 * @param bool $return_config Whether or not to return the config_vars array (used for admin search)
885
 * @return void|array Returns nothing or returns the $config_vars array if $return_config is true
886
 */
887
function ModifySignatureSettings($return_config = false)
888
{
889
	global $context, $txt, $modSettings, $sig_start, $smcFunc, $scripturl;
890
891
	$config_vars = array(
892
			// Are signatures even enabled?
893
			array('check', 'signature_enable'),
894
		'',
895
			// Tweaking settings!
896
			array('int', 'signature_max_length', 'subtext' => $txt['zero_for_no_limit']),
897
			array('int', 'signature_max_lines', 'subtext' => $txt['zero_for_no_limit']),
898
			array('int', 'signature_max_font_size', 'subtext' => $txt['zero_for_no_limit']),
899
			array('check', 'signature_allow_smileys', 'onclick' => 'document.getElementById(\'signature_max_smileys\').disabled = !this.checked;'),
900
			array('int', 'signature_max_smileys', 'subtext' => $txt['zero_for_no_limit']),
901
		'',
902
			// Image settings.
903
			array('int', 'signature_max_images', 'subtext' => $txt['signature_max_images_note']),
904
			array('int', 'signature_max_image_width', 'subtext' => $txt['zero_for_no_limit']),
905
			array('int', 'signature_max_image_height', 'subtext' => $txt['zero_for_no_limit']),
906
		'',
907
			array('bbc', 'signature_bbc'),
908
	);
909
910
	call_integration_hook('integrate_signature_settings', array(&$config_vars));
911
912
	if ($return_config)
913
		return $config_vars;
914
915
	// Setup the template.
916
	$context['page_title'] = $txt['signature_settings'];
917
	$context['sub_template'] = 'show_settings';
918
919
	// Disable the max smileys option if we don't allow smileys at all!
920
	$context['settings_post_javascript'] = 'document.getElementById(\'signature_max_smileys\').disabled = !document.getElementById(\'signature_allow_smileys\').checked;';
921
922
	// Load all the signature settings.
923
	list ($sig_limits, $sig_bbc) = explode(':', $modSettings['signature_settings']);
924
	$sig_limits = explode(',', $sig_limits);
925
	$disabledTags = !empty($sig_bbc) ? explode(',', $sig_bbc) : array();
926
927
	// Applying to ALL signatures?!!
928
	if (isset($_GET['apply']))
929
	{
930
		// Security!
931
		checkSession('get');
932
933
		$sig_start = time();
934
		// This is horrid - but I suppose some people will want the option to do it.
935
		$_GET['step'] = isset($_GET['step']) ? (int) $_GET['step'] : 0;
936
		$done = false;
937
938
		$request = $smcFunc['db_query']('', '
939
			SELECT MAX(id_member)
940
			FROM {db_prefix}members',
941
			array(
942
			)
943
		);
944
		list ($context['max_member']) = $smcFunc['db_fetch_row']($request);
945
		$smcFunc['db_free_result']($request);
946
947
		while (!$done)
948
		{
949
			$changes = array();
950
951
			$request = $smcFunc['db_query']('', '
952
				SELECT id_member, signature
953
				FROM {db_prefix}members
954
				WHERE id_member BETWEEN {int:step} AND {int:step} + 49
955
					AND id_group != {int:admin_group}
956
					AND FIND_IN_SET({int:admin_group}, additional_groups) = 0',
957
				array(
958
					'admin_group' => 1,
959
					'step' => $_GET['step'],
960
				)
961
			);
962
			while ($row = $smcFunc['db_fetch_assoc']($request))
963
			{
964
				// Apply all the rules we can realistically do.
965
				$sig = strtr($row['signature'], array('<br>' => "\n"));
966
967
				// Max characters...
968
				if (!empty($sig_limits[1]))
969
					$sig = $smcFunc['substr']($sig, 0, $sig_limits[1]);
970
				// Max lines...
971
				if (!empty($sig_limits[2]))
972
				{
973
					$count = 0;
974
					for ($i = 0; $i < strlen($sig); $i++)
975
					{
976
						if ($sig[$i] == "\n")
977
						{
978
							$count++;
979
							if ($count >= $sig_limits[2])
980
								$sig = substr($sig, 0, $i) . strtr(substr($sig, $i), array("\n" => ' '));
981
						}
982
					}
983
				}
984
985
				if (!empty($sig_limits[7]) && preg_match_all('~\[size=([\d\.]+)?(px|pt|em|x-large|larger)~i', $sig, $matches) !== false && isset($matches[2]))
986
				{
987
					foreach ($matches[1] as $ind => $size)
988
					{
989
						$limit_broke = 0;
990
						// Attempt to allow all sizes of abuse, so to speak.
991
						if ($matches[2][$ind] == 'px' && $size > $sig_limits[7])
992
							$limit_broke = $sig_limits[7] . 'px';
993
						elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75))
994
							$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
995
						elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16))
996
							$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
997
						elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18)
998
							$limit_broke = 'large';
999
1000
						if ($limit_broke)
1001
							$sig = str_replace($matches[0][$ind], '[size=' . $sig_limits[7] . 'px', $sig);
1002
					}
1003
				}
1004
1005
				// Stupid images - this is stupidly, stupidly challenging.
1006
				if ((!empty($sig_limits[3]) || !empty($sig_limits[5]) || !empty($sig_limits[6])))
1007
				{
1008
					$replaces = array();
1009
					$img_count = 0;
1010
					// Get all BBC tags...
1011
					preg_match_all('~\[img(\s+width=([\d]+))?(\s+height=([\d]+))?(\s+width=([\d]+))?\s*\](?:<br>)*([^<">]+?)(?:<br>)*\[/img\]~i', $sig, $matches);
1012
					// ... and all HTML ones.
1013
					preg_match_all('~&lt;img\s+src=(?:&quot;)?((?:http://|ftp://|https://|ftps://).+?)(?:&quot;)?(?:\s+alt=(?:&quot;)?(.*?)(?:&quot;)?)?(?:\s?/)?&gt;~i', $sig, $matches2, PREG_PATTERN_ORDER);
1014
					// And stick the HTML in the BBC.
1015
					if (!empty($matches2))
1016
					{
1017
						foreach ($matches2[0] as $ind => $dummy)
1018
						{
1019
							$matches[0][] = $matches2[0][$ind];
1020
							$matches[1][] = '';
1021
							$matches[2][] = '';
1022
							$matches[3][] = '';
1023
							$matches[4][] = '';
1024
							$matches[5][] = '';
1025
							$matches[6][] = '';
1026
							$matches[7][] = $matches2[1][$ind];
1027
						}
1028
					}
1029
					// Try to find all the images!
1030
					if (!empty($matches))
1031
					{
1032
						$image_count_holder = array();
1033
						foreach ($matches[0] as $key => $image)
1034
						{
1035
							$width = -1; $height = -1;
1036
							$img_count++;
1037
							// Too many images?
1038
							if (!empty($sig_limits[3]) && $img_count > $sig_limits[3])
1039
							{
1040
								// If we've already had this before we only want to remove the excess.
1041
								if (isset($image_count_holder[$image]))
1042
								{
1043
									$img_offset = -1;
1044
									$rep_img_count = 0;
1045
									while ($img_offset !== false)
1046
									{
1047
										$img_offset = strpos($sig, $image, $img_offset + 1);
1048
										$rep_img_count++;
1049
										if ($rep_img_count > $image_count_holder[$image])
1050
										{
1051
											// Only replace the excess.
1052
											$sig = substr($sig, 0, $img_offset) . str_replace($image, '', substr($sig, $img_offset));
1053
											// Stop looping.
1054
											$img_offset = false;
1055
										}
1056
									}
1057
								}
1058
								else
1059
									$replaces[$image] = '';
1060
1061
								continue;
1062
							}
1063
1064
							// Does it have predefined restraints? Width first.
1065
							if ($matches[6][$key])
1066
								$matches[2][$key] = $matches[6][$key];
1067
							if ($matches[2][$key] && $sig_limits[5] && $matches[2][$key] > $sig_limits[5])
1068
							{
1069
								$width = $sig_limits[5];
1070
								$matches[4][$key] = $matches[4][$key] * ($width / $matches[2][$key]);
1071
							}
1072
							elseif ($matches[2][$key])
1073
								$width = $matches[2][$key];
1074
							// ... and height.
1075
							if ($matches[4][$key] && $sig_limits[6] && $matches[4][$key] > $sig_limits[6])
1076
							{
1077
								$height = $sig_limits[6];
1078
								if ($width != -1)
1079
									$width = $width * ($height / $matches[4][$key]);
1080
							}
1081
							elseif ($matches[4][$key])
1082
								$height = $matches[4][$key];
1083
1084
							// If the dimensions are still not fixed - we need to check the actual image.
1085
							if (($width == -1 && $sig_limits[5]) || ($height == -1 && $sig_limits[6]))
1086
							{
1087
								$sizes = url_image_size($matches[7][$key]);
1088
								if (is_array($sizes))
1089
								{
1090
									// Too wide?
1091
									if ($sizes[0] > $sig_limits[5] && $sig_limits[5])
1092
									{
1093
										$width = $sig_limits[5];
1094
										$sizes[1] = $sizes[1] * ($width / $sizes[0]);
1095
									}
1096
									// Too high?
1097
									if ($sizes[1] > $sig_limits[6] && $sig_limits[6])
1098
									{
1099
										$height = $sig_limits[6];
1100
										if ($width == -1)
1101
											$width = $sizes[0];
1102
										$width = $width * ($height / $sizes[1]);
1103
									}
1104
									elseif ($width != -1)
1105
										$height = $sizes[1];
1106
								}
1107
							}
1108
1109
							// Did we come up with some changes? If so remake the string.
1110
							if ($width != -1 || $height != -1)
1111
							{
1112
								$replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]';
1113
							}
1114
1115
							// Record that we got one.
1116
							$image_count_holder[$image] = isset($image_count_holder[$image]) ? $image_count_holder[$image] + 1 : 1;
1117
						}
1118
						if (!empty($replaces))
1119
							$sig = str_replace(array_keys($replaces), array_values($replaces), $sig);
1120
					}
1121
				}
1122
				// Try to fix disabled tags.
1123
				if (!empty($disabledTags))
1124
				{
1125
					$sig = preg_replace('~\[(?:' . implode('|', $disabledTags) . ').+?\]~i', '', $sig);
1126
					$sig = preg_replace('~\[/(?:' . implode('|', $disabledTags) . ')\]~i', '', $sig);
1127
				}
1128
1129
				$sig = strtr($sig, array("\n" => '<br>'));
1130
				call_integration_hook('integrate_apply_signature_settings', array(&$sig, $sig_limits, $disabledTags));
1131
				if ($sig != $row['signature'])
1132
					$changes[$row['id_member']] = $sig;
1133
			}
1134
			if ($smcFunc['db_num_rows']($request) == 0)
1135
				$done = true;
1136
			$smcFunc['db_free_result']($request);
1137
1138
			// Do we need to delete what we have?
1139
			if (!empty($changes))
1140
			{
1141
				foreach ($changes as $id => $sig)
1142
					$smcFunc['db_query']('', '
1143
						UPDATE {db_prefix}members
1144
						SET signature = {string:signature}
1145
						WHERE id_member = {int:id_member}',
1146
						array(
1147
							'id_member' => $id,
1148
							'signature' => $sig,
1149
						)
1150
					);
1151
			}
1152
1153
			$_GET['step'] += 50;
1154
			if (!$done)
1155
				pauseSignatureApplySettings();
1156
		}
1157
		$settings_applied = true;
1158
	}
1159
1160
	$context['signature_settings'] = array(
1161
		'enable' => isset($sig_limits[0]) ? $sig_limits[0] : 0,
1162
		'max_length' => isset($sig_limits[1]) ? $sig_limits[1] : 0,
1163
		'max_lines' => isset($sig_limits[2]) ? $sig_limits[2] : 0,
1164
		'max_images' => isset($sig_limits[3]) ? $sig_limits[3] : 0,
1165
		'allow_smileys' => isset($sig_limits[4]) && $sig_limits[4] == -1 ? 0 : 1,
1166
		'max_smileys' => isset($sig_limits[4]) && $sig_limits[4] != -1 ? $sig_limits[4] : 0,
1167
		'max_image_width' => isset($sig_limits[5]) ? $sig_limits[5] : 0,
1168
		'max_image_height' => isset($sig_limits[6]) ? $sig_limits[6] : 0,
1169
		'max_font_size' => isset($sig_limits[7]) ? $sig_limits[7] : 0,
1170
	);
1171
1172
	// Temporarily make each setting a modSetting!
1173
	foreach ($context['signature_settings'] as $key => $value)
1174
		$modSettings['signature_' . $key] = $value;
1175
1176
	// Make sure we check the right tags!
1177
	$modSettings['bbc_disabled_signature_bbc'] = $disabledTags;
1178
1179
	// Saving?
1180
	if (isset($_GET['save']))
1181
	{
1182
		checkSession();
1183
1184
		// Clean up the tag stuff!
1185
		$bbcTags = array();
1186
		foreach (parse_bbc(false) as $tag)
1187
			$bbcTags[] = $tag['tag'];
1188
1189
		if (!isset($_POST['signature_bbc_enabledTags']))
1190
			$_POST['signature_bbc_enabledTags'] = array();
1191
		elseif (!is_array($_POST['signature_bbc_enabledTags']))
1192
			$_POST['signature_bbc_enabledTags'] = array($_POST['signature_bbc_enabledTags']);
1193
1194
		$sig_limits = array();
1195
		foreach ($context['signature_settings'] as $key => $value)
1196
		{
1197
			if ($key == 'allow_smileys')
1198
				continue;
1199
			elseif ($key == 'max_smileys' && empty($_POST['signature_allow_smileys']))
1200
				$sig_limits[] = -1;
1201
			else
1202
				$sig_limits[] = !empty($_POST['signature_' . $key]) ? max(1, (int) $_POST['signature_' . $key]) : 0;
1203
		}
1204
1205
		call_integration_hook('integrate_save_signature_settings', array(&$sig_limits, &$bbcTags));
1206
1207
		$_POST['signature_settings'] = implode(',', $sig_limits) . ':' . implode(',', array_diff($bbcTags, $_POST['signature_bbc_enabledTags']));
1208
1209
		// Even though we have practically no settings let's keep the convention going!
1210
		$save_vars = array();
1211
		$save_vars[] = array('text', 'signature_settings');
1212
1213
		saveDBSettings($save_vars);
1214
		$_SESSION['adm-save'] = true;
1215
		redirectexit('action=admin;area=featuresettings;sa=sig');
1216
	}
1217
1218
	$context['post_url'] = $scripturl . '?action=admin;area=featuresettings;save;sa=sig';
1219
	$context['settings_title'] = $txt['signature_settings'];
1220
1221
	$context['settings_message'] = !empty($settings_applied) ? '<div class="infobox">' . $txt['signature_settings_applied'] . '</div>' : '<p class="centertext">' . sprintf($txt['signature_settings_warning'], $context['session_id'], $context['session_var']) . '</p>';
1222
1223
	prepareDBSettingContext($config_vars);
1224
}
1225
1226
/**
1227
 * Just pause the signature applying thing.
1228
 */
1229
function pauseSignatureApplySettings()
1230
{
1231
	global $context, $txt, $sig_start;
1232
1233
	// Try get more time...
1234
	@set_time_limit(600);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for set_time_limit(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

1234
	/** @scrutinizer ignore-unhandled */ @set_time_limit(600);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
1235
	if (function_exists('apache_reset_timeout'))
1236
		@apache_reset_timeout();
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for apache_reset_timeout(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

1236
		/** @scrutinizer ignore-unhandled */ @apache_reset_timeout();

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
1237
1238
	// Have we exhausted all the time we allowed?
1239
	if (time() - array_sum(explode(' ', $sig_start)) < 3)
1240
		return;
1241
1242
	$context['continue_get_data'] = '?action=admin;area=featuresettings;sa=sig;apply;step=' . $_GET['step'] . ';' . $context['session_var'] . '=' . $context['session_id'];
1243
	$context['page_title'] = $txt['not_done_title'];
1244
	$context['continue_post_data'] = '';
1245
	$context['continue_countdown'] = '2';
1246
	$context['sub_template'] = 'not_done';
1247
1248
	// Specific stuff to not break this template!
1249
	$context[$context['admin_menu_name']]['current_subsection'] = 'sig';
1250
1251
	// Get the right percent.
1252
	$context['continue_percent'] = round(($_GET['step'] / $context['max_member']) * 100);
1253
1254
	// Never more than 100%!
1255
	$context['continue_percent'] = min($context['continue_percent'], 100);
1256
1257
	obExit();
1258
}
1259
1260
/**
1261
 * Show all the custom profile fields available to the user.
1262
 */
1263
function ShowCustomProfiles()
1264
{
1265
	global $txt, $scripturl, $context;
1266
	global $sourcedir;
1267
1268
	$context['page_title'] = $txt['custom_profile_title'];
1269
	$context['sub_template'] = 'show_custom_profile';
1270
1271
	// What about standard fields they can tweak?
1272
	$standard_fields = array('website', 'personal_text', 'timezone', 'posts', 'warning_status');
1273
	// What fields can't you put on the registration page?
1274
	$context['fields_no_registration'] = array('posts', 'warning_status');
1275
1276
	// Are we saving any standard field changes?
1277
	if (isset($_POST['save']))
1278
	{
1279
		checkSession();
1280
		validateToken('admin-scp');
1281
1282
		// Do the active ones first.
1283
		$disable_fields = array_flip($standard_fields);
1284
		if (!empty($_POST['active']))
1285
		{
1286
			foreach ($_POST['active'] as $value)
1287
				if (isset($disable_fields[$value]))
1288
					unset($disable_fields[$value]);
1289
		}
1290
		// What we have left!
1291
		$changes['disabled_profile_fields'] = empty($disable_fields) ? '' : implode(',', array_keys($disable_fields));
0 ignored issues
show
Comprehensibility Best Practice introduced by
$changes was never initialized. Although not strictly required by PHP, it is generally a good practice to add $changes = array(); before regardless.
Loading history...
1292
1293
		// Things we want to show on registration?
1294
		$reg_fields = array();
1295
		if (!empty($_POST['reg']))
1296
		{
1297
			foreach ($_POST['reg'] as $value)
1298
				if (in_array($value, $standard_fields) && !isset($disable_fields[$value]))
1299
					$reg_fields[] = $value;
1300
		}
1301
		// What we have left!
1302
		$changes['registration_fields'] = empty($reg_fields) ? '' : implode(',', $reg_fields);
1303
1304
		$_SESSION['adm-save'] = true;
1305
		if (!empty($changes))
1306
			updateSettings($changes);
1307
	}
1308
1309
	createToken('admin-scp');
1310
1311
	// Need to know the max order for custom fields
1312
	$context['custFieldsMaxOrder'] = custFieldsMaxOrder();
1313
1314
	require_once($sourcedir . '/Subs-List.php');
1315
1316
	$listOptions = array(
1317
		'id' => 'standard_profile_fields',
1318
		'title' => $txt['standard_profile_title'],
1319
		'base_href' => $scripturl . '?action=admin;area=featuresettings;sa=profile',
1320
		'get_items' => array(
1321
			'function' => 'list_getProfileFields',
1322
			'params' => array(
1323
				true,
1324
			),
1325
		),
1326
		'columns' => array(
1327
			'field' => array(
1328
				'header' => array(
1329
					'value' => $txt['standard_profile_field'],
1330
				),
1331
				'data' => array(
1332
					'db' => 'label',
1333
					'style' => 'width: 60%;',
1334
				),
1335
			),
1336
			'active' => array(
1337
				'header' => array(
1338
					'value' => $txt['custom_edit_active'],
1339
					'class' => 'centercol',
1340
				),
1341
				'data' => array(
1342
					'function' => function ($rowData)
1343
					{
1344
						$isChecked = $rowData['disabled'] ? '' : ' checked';
1345
						$onClickHandler = $rowData['can_show_register'] ? sprintf(' onclick="document.getElementById(\'reg_%1$s\').disabled = !this.checked;"', $rowData['id']) : '';
1346
						return sprintf('<input type="checkbox" name="active[]" id="active_%1$s" value="%1$s" %2$s%3$s>', $rowData['id'], $isChecked, $onClickHandler);
1347
					},
1348
					'style' => 'width: 20%;',
1349
					'class' => 'centercol',
1350
				),
1351
			),
1352
			'show_on_registration' => array(
1353
				'header' => array(
1354
					'value' => $txt['custom_edit_registration'],
1355
					'class' => 'centercol',
1356
				),
1357
				'data' => array(
1358
					'function' => function ($rowData)
1359
					{
1360
						$isChecked = $rowData['on_register'] && !$rowData['disabled'] ? ' checked' : '';
1361
						$isDisabled = $rowData['can_show_register'] ? '' : ' disabled';
1362
						return sprintf('<input type="checkbox" name="reg[]" id="reg_%1$s" value="%1$s" %2$s%3$s>', $rowData['id'], $isChecked, $isDisabled);
1363
					},
1364
					'style' => 'width: 20%;',
1365
					'class' => 'centercol',
1366
				),
1367
			),
1368
		),
1369
		'form' => array(
1370
			'href' => $scripturl . '?action=admin;area=featuresettings;sa=profile',
1371
			'name' => 'standardProfileFields',
1372
			'token' => 'admin-scp',
1373
		),
1374
		'additional_rows' => array(
1375
			array(
1376
				'position' => 'below_table_data',
1377
				'value' => '<input type="submit" name="save" value="' . $txt['save'] . '" class="button">',
1378
			),
1379
		),
1380
	);
1381
	createList($listOptions);
1382
1383
	$listOptions = array(
1384
		'id' => 'custom_profile_fields',
1385
		'title' => $txt['custom_profile_title'],
1386
		'base_href' => $scripturl . '?action=admin;area=featuresettings;sa=profile',
1387
		'default_sort_col' => 'field_order',
1388
		'no_items_label' => $txt['custom_profile_none'],
1389
		'items_per_page' => 25,
1390
		'get_items' => array(
1391
			'function' => 'list_getProfileFields',
1392
			'params' => array(
1393
				false,
1394
			),
1395
		),
1396
		'get_count' => array(
1397
			'function' => 'list_getProfileFieldSize',
1398
		),
1399
		'columns' => array(
1400
			'field_order' => array(
1401
				'header' => array(
1402
					'value' => $txt['custom_profile_fieldorder'],
1403
				),
1404
				'data' => array(
1405
					'function' => function ($rowData) use ($context, $txt, $scripturl)
1406
					{
1407
						$return = '<p class="centertext bold_text">'. $rowData['field_order'] .'<br>';
1408
1409
						if ($rowData['field_order'] > 1)
1410
							$return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=up"><span class="toggle_up" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_up'] .'"></span></a>';
1411
1412
						if ($rowData['field_order'] < $context['custFieldsMaxOrder'])
1413
							$return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=down"><span class="toggle_down" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_down'] .'"></span></a>';
1414
1415
						$return .= '</p>';
1416
1417
						return $return;
1418
					},
1419
					'style' => 'width: 12%;',
1420
				),
1421
				'sort' => array(
1422
					'default' => 'field_order',
1423
					'reverse' => 'field_order DESC',
1424
				),
1425
			),
1426
			'field_name' => array(
1427
				'header' => array(
1428
					'value' => $txt['custom_profile_fieldname'],
1429
				),
1430
				'data' => array(
1431
					'function' => function ($rowData) use ($scripturl)
1432
					{
1433
						return sprintf('<a href="%1$s?action=admin;area=featuresettings;sa=profileedit;fid=%2$d">%3$s</a><div class="smalltext">%4$s</div>', $scripturl, $rowData['id_field'], $rowData['field_name'], $rowData['field_desc']);
1434
					},
1435
					'style' => 'width: 62%;',
1436
				),
1437
				'sort' => array(
1438
					'default' => 'field_name',
1439
					'reverse' => 'field_name DESC',
1440
				),
1441
			),
1442
			'field_type' => array(
1443
				'header' => array(
1444
					'value' => $txt['custom_profile_fieldtype'],
1445
				),
1446
				'data' => array(
1447
					'function' => function ($rowData) use ($txt)
1448
					{
1449
						$textKey = sprintf('custom_profile_type_%1$s', $rowData['field_type']);
1450
						return isset($txt[$textKey]) ? $txt[$textKey] : $textKey;
1451
					},
1452
					'style' => 'width: 15%;',
1453
					'class' => 'hidden',
1454
				),
1455
				'sort' => array(
1456
					'default' => 'field_type',
1457
					'reverse' => 'field_type DESC',
1458
				),
1459
			),
1460
			'active' => array(
1461
				'header' => array(
1462
					'value' => $txt['custom_profile_active'],
1463
				),
1464
				'data' => array(
1465
					'function' => function ($rowData) use ($txt)
1466
					{
1467
						return $rowData['active'] ? $txt['yes'] : $txt['no'];
1468
					},
1469
					'style' => 'width: 8%;',
1470
					'class' => 'hidden',
1471
				),
1472
				'sort' => array(
1473
					'default' => 'active DESC',
1474
					'reverse' => 'active',
1475
				),
1476
			),
1477
			'placement' => array(
1478
				'header' => array(
1479
					'value' => $txt['custom_profile_placement'],
1480
				),
1481
				'data' => array(
1482
					'function' => function ($rowData)
1483
					{
1484
						global $txt, $context;
1485
1486
						return $txt['custom_profile_placement_' . (empty($rowData['placement']) ? 'standard' : $context['cust_profile_fields_placement'][$rowData['placement']])];
1487
					},
1488
					'style' => 'width: 8%;',
1489
					'class' => 'hidden',
1490
				),
1491
				'sort' => array(
1492
					'default' => 'placement DESC',
1493
					'reverse' => 'placement',
1494
				),
1495
			),
1496
			'show_on_registration' => array(
1497
				'data' => array(
1498
					'sprintf' => array(
1499
						'format' => '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=%1$s">' . $txt['modify'] . '</a>',
1500
						'params' => array(
1501
							'id_field' => false,
1502
						),
1503
					),
1504
					'style' => 'width: 15%;',
1505
				),
1506
			),
1507
		),
1508
		'form' => array(
1509
			'href' => $scripturl . '?action=admin;area=featuresettings;sa=profileedit',
1510
			'name' => 'customProfileFields',
1511
		),
1512
		'additional_rows' => array(
1513
			array(
1514
				'position' => 'below_table_data',
1515
				'value' => '<input type="submit" name="new" value="' . $txt['custom_profile_make_new'] . '" class="button">',
1516
			),
1517
		),
1518
	);
1519
	createList($listOptions);
1520
1521
	// There are two different ways we could get to this point. To keep it simple, they both do
1522
	// the same basic thing.
1523
	if (isset($_SESSION['adm-save']))
1524
	{
1525
		$context['saved_successful'] = true;
1526
		unset ($_SESSION['adm-save']);
1527
	}
1528
}
1529
1530
/**
1531
 * Callback for createList().
1532
 * @param int $start The item to start with (used for pagination purposes)
1533
 * @param int $items_per_page The number of items to display per page
1534
 * @param string $sort A string indicating how to sort the results
1535
 * @param bool $standardFields Whether or not to include standard fields as well
1536
 * @return array An array of info about the various profile fields
1537
 */
1538
function list_getProfileFields($start, $items_per_page, $sort, $standardFields)
1539
{
1540
	global $txt, $modSettings, $smcFunc;
1541
1542
	$list = array();
1543
1544
	if ($standardFields)
1545
	{
1546
		$standard_fields = array('website', 'personal_text', 'timezone', 'posts', 'warning_status');
1547
		$fields_no_registration = array('posts', 'warning_status');
1548
		$disabled_fields = isset($modSettings['disabled_profile_fields']) ? explode(',', $modSettings['disabled_profile_fields']) : array();
1549
		$registration_fields = isset($modSettings['registration_fields']) ? explode(',', $modSettings['registration_fields']) : array();
1550
1551
		foreach ($standard_fields as $field)
1552
			$list[] = array(
1553
				'id' => $field,
1554
				'label' => isset($txt['standard_profile_field_' . $field]) ? $txt['standard_profile_field_' . $field] : (isset($txt[$field]) ? $txt[$field] : $field),
1555
				'disabled' => in_array($field, $disabled_fields),
1556
				'on_register' => in_array($field, $registration_fields) && !in_array($field, $fields_no_registration),
1557
				'can_show_register' => !in_array($field, $fields_no_registration),
1558
			);
1559
	}
1560
	else
1561
	{
1562
		// Load all the fields.
1563
		$request = $smcFunc['db_query']('', '
1564
			SELECT id_field, col_name, field_name, field_desc, field_type, field_order, active, placement
1565
			FROM {db_prefix}custom_fields
1566
			ORDER BY {raw:sort}
1567
			LIMIT {int:start}, {int:items_per_page}',
1568
			array(
1569
				'sort' => $sort,
1570
				'start' => $start,
1571
				'items_per_page' => $items_per_page,
1572
			)
1573
		);
1574
		while ($row = $smcFunc['db_fetch_assoc']($request))
1575
			$list[] = $row;
1576
		$smcFunc['db_free_result']($request);
1577
	}
1578
1579
	return $list;
1580
}
1581
1582
/**
1583
 * Callback for createList().
1584
 * @return int The total number of custom profile fields
1585
 */
1586
function list_getProfileFieldSize()
1587
{
1588
	global $smcFunc;
1589
1590
	$request = $smcFunc['db_query']('', '
1591
		SELECT COUNT(*)
1592
		FROM {db_prefix}custom_fields',
1593
		array(
1594
		)
1595
	);
1596
1597
	list ($numProfileFields) = $smcFunc['db_fetch_row']($request);
1598
	$smcFunc['db_free_result']($request);
1599
1600
	return $numProfileFields;
1601
}
1602
1603
/**
1604
 * Edit some profile fields?
1605
 */
1606
function EditCustomProfiles()
1607
{
1608
	global $txt, $scripturl, $context, $smcFunc;
1609
1610
	// Sort out the context!
1611
	$context['fid'] = isset($_GET['fid']) ? (int) $_GET['fid'] : 0;
1612
	$context[$context['admin_menu_name']]['current_subsection'] = 'profile';
1613
	$context['page_title'] = $context['fid'] ? $txt['custom_edit_title'] : $txt['custom_add_title'];
1614
	$context['sub_template'] = 'edit_profile_field';
1615
1616
	// Load the profile language for section names.
1617
	loadLanguage('Profile');
1618
1619
	// There's really only a few places we can go...
1620
	$move_to = array('up', 'down');
1621
1622
	// We need this for both moving and saving so put it right here.
1623
	$order_count = custFieldsMaxOrder();
1624
1625
	if ($context['fid'])
1626
	{
1627
		$request = $smcFunc['db_query']('', '
1628
			SELECT
1629
				id_field, col_name, field_name, field_desc, field_type, field_order, field_length, field_options,
1630
				show_reg, show_display, show_mlist, show_profile, private, active, default_value, can_search,
1631
				bbc, mask, enclose, placement
1632
			FROM {db_prefix}custom_fields
1633
			WHERE id_field = {int:current_field}',
1634
			array(
1635
				'current_field' => $context['fid'],
1636
			)
1637
		);
1638
		$context['field'] = array();
1639
		while ($row = $smcFunc['db_fetch_assoc']($request))
1640
		{
1641
			if ($row['field_type'] == 'textarea')
1642
				@list ($rows, $cols) = @explode(',', $row['default_value']);
1643
			else
1644
			{
1645
				$rows = 3;
1646
				$cols = 30;
1647
			}
1648
1649
			$context['field'] = array(
1650
				'name' => $row['field_name'],
1651
				'desc' => $row['field_desc'],
1652
				'col_name' => $row['col_name'],
1653
				'profile_area' => $row['show_profile'],
1654
				'reg' => $row['show_reg'],
1655
				'display' => $row['show_display'],
1656
				'mlist' => $row['show_mlist'],
1657
				'type' => $row['field_type'],
1658
				'order' => $row['field_order'],
1659
				'max_length' => $row['field_length'],
1660
				'rows' => $rows,
1661
				'cols' => $cols,
1662
				'bbc' => $row['bbc'] ? true : false,
1663
				'default_check' => $row['field_type'] == 'check' && $row['default_value'] ? true : false,
1664
				'default_select' => $row['field_type'] == 'select' || $row['field_type'] == 'radio' ? $row['default_value'] : '',
1665
				'options' => strlen($row['field_options']) > 1 ? explode(',', $row['field_options']) : array('', '', ''),
1666
				'active' => $row['active'],
1667
				'private' => $row['private'],
1668
				'can_search' => $row['can_search'],
1669
				'mask' => $row['mask'],
1670
				'regex' => substr($row['mask'], 0, 5) == 'regex' ? substr($row['mask'], 5) : '',
1671
				'enclose' => $row['enclose'],
1672
				'placement' => $row['placement'],
1673
			);
1674
		}
1675
		$smcFunc['db_free_result']($request);
1676
	}
1677
1678
	// Setup the default values as needed.
1679
	if (empty($context['field']))
1680
		$context['field'] = array(
1681
			'name' => '',
1682
			'col_name' => '???',
1683
			'desc' => '',
1684
			'profile_area' => 'forumprofile',
1685
			'reg' => false,
1686
			'display' => false,
1687
			'mlist' => false,
1688
			'type' => 'text',
1689
			'order' => 0,
1690
			'max_length' => 255,
1691
			'rows' => 4,
1692
			'cols' => 30,
1693
			'bbc' => false,
1694
			'default_check' => false,
1695
			'default_select' => '',
1696
			'options' => array('', '', ''),
1697
			'active' => true,
1698
			'private' => false,
1699
			'can_search' => false,
1700
			'mask' => 'nohtml',
1701
			'regex' => '',
1702
			'enclose' => '',
1703
			'placement' => 0,
1704
		);
1705
1706
	// Are we moving it?
1707
	if (isset($_GET['move']) && in_array($smcFunc['htmlspecialchars']($_GET['move']), $move_to))
1708
	{
1709
		// Down is the new up.
1710
		$new_order = ($_GET['move'] == 'up' ? ($context['field']['order'] - 1) : ($context['field']['order'] + 1));
1711
1712
		// Is this a valid position?
1713
		if ($new_order <= 0 || $new_order > $order_count)
1714
			redirectexit('action=admin;area=featuresettings;sa=profile'); // @todo implement an error handler
1715
1716
		// All good, proceed.
1717
		$smcFunc['db_query']('','
1718
			UPDATE {db_prefix}custom_fields
1719
			SET field_order = {int:old_order}
1720
			WHERE field_order = {int:new_order}',
1721
			array(
1722
				'new_order' => $new_order,
1723
				'old_order' => $context['field']['order'],
1724
			)
1725
		);
1726
		$smcFunc['db_query']('','
1727
			UPDATE {db_prefix}custom_fields
1728
			SET field_order = {int:new_order}
1729
			WHERE id_field = {int:id_field}',
1730
			array(
1731
				'new_order' => $new_order,
1732
				'id_field' => $context['fid'],
1733
			)
1734
		);
1735
		redirectexit('action=admin;area=featuresettings;sa=profile'); // @todo perhaps a nice confirmation message, dunno.
1736
	}
1737
1738
	// Are we saving?
1739
	if (isset($_POST['save']))
1740
	{
1741
		checkSession();
1742
		validateToken('admin-ecp');
1743
1744
		// Everyone needs a name - even the (bracket) unknown...
1745
		if (trim($_POST['field_name']) == '')
1746
			redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=need_name');
1747
1748
		// Regex you say?  Do a very basic test to see if the pattern is valid
1749
		if (!empty($_POST['regex']) && @preg_match($_POST['regex'], 'dummy') === false)
1750
			redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=regex_error');
1751
1752
		$_POST['field_name'] = $smcFunc['htmlspecialchars']($_POST['field_name']);
1753
		$_POST['field_desc'] = $smcFunc['htmlspecialchars']($_POST['field_desc']);
1754
1755
		// Checkboxes...
1756
		$show_reg = isset($_POST['reg']) ? (int) $_POST['reg'] : 0;
1757
		$show_display = isset($_POST['display']) ? 1 : 0;
1758
		$show_mlist = isset($_POST['mlist']) ? 1 : 0;
1759
		$bbc = isset($_POST['bbc']) ? 1 : 0;
1760
		$show_profile = $_POST['profile_area'];
1761
		$active = isset($_POST['active']) ? 1 : 0;
1762
		$private = isset($_POST['private']) ? (int) $_POST['private'] : 0;
1763
		$can_search = isset($_POST['can_search']) ? 1 : 0;
1764
1765
		// Some masking stuff...
1766
		$mask = isset($_POST['mask']) ? $_POST['mask'] : '';
1767
		if ($mask == 'regex' && isset($_POST['regex']))
1768
			$mask .= $_POST['regex'];
1769
1770
		$field_length = isset($_POST['max_length']) ? (int) $_POST['max_length'] : 255;
1771
		$enclose = isset($_POST['enclose']) ? $_POST['enclose'] : '';
1772
		$placement = isset($_POST['placement']) ? (int) $_POST['placement'] : 0;
1773
1774
		// Select options?
1775
		$field_options = '';
1776
		$newOptions = array();
1777
		$default = isset($_POST['default_check']) && $_POST['field_type'] == 'check' ? 1 : '';
1778
		if (!empty($_POST['select_option']) && ($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio'))
1779
		{
1780
			foreach ($_POST['select_option'] as $k => $v)
1781
			{
1782
				// Clean, clean, clean...
1783
				$v = $smcFunc['htmlspecialchars']($v);
1784
				$v = strtr($v, array(',' => ''));
1785
1786
				// Nada, zip, etc...
1787
				if (trim($v) == '')
1788
					continue;
1789
1790
				// Otherwise, save it boy.
1791
				$field_options .= $v . ',';
1792
				// This is just for working out what happened with old options...
1793
				$newOptions[$k] = $v;
1794
1795
				// Is it default?
1796
				if (isset($_POST['default_select']) && $_POST['default_select'] == $k)
1797
					$default = $v;
1798
			}
1799
			$field_options = substr($field_options, 0, -1);
1800
		}
1801
1802
		// Text area has default has dimensions
1803
		if ($_POST['field_type'] == 'textarea')
1804
			$default = (int) $_POST['rows'] . ',' . (int) $_POST['cols'];
1805
1806
		// Come up with the unique name?
1807
		if (empty($context['fid']))
1808
		{
1809
			$col_name = $smcFunc['substr'](strtr($_POST['field_name'], array(' ' => '')), 0, 6);
1810
			preg_match('~([\w\d_-]+)~', $col_name, $matches);
1811
1812
			// If there is nothing to the name, then let's start out own - for foreign languages etc.
1813
			if (isset($matches[1]))
1814
				$col_name = $initial_col_name = 'cust_' . strtolower($matches[1]);
1815
			else
1816
				$col_name = $initial_col_name = 'cust_' . mt_rand(1, 9999);
1817
1818
			// Make sure this is unique.
1819
			$current_fields = array();
1820
			$request = $smcFunc['db_query']('', '
1821
				SELECT id_field, col_name
1822
				FROM {db_prefix}custom_fields');
1823
			while ($row = $smcFunc['db_fetch_assoc']($request))
1824
				$current_fields[$row['id_field']] = $row['col_name'];
1825
			$smcFunc['db_free_result']($request);
1826
1827
			$unique = false;
1828
			for ($i = 0; !$unique && $i < 9; $i ++)
1829
			{
1830
				if (!in_array($col_name, $current_fields))
1831
					$unique = true;
1832
				else
1833
					$col_name = $initial_col_name . $i;
1834
			}
1835
1836
			// Still not a unique column name? Leave it up to the user, then.
1837
			if (!$unique)
1838
				fatal_lang_error('custom_option_not_unique');
1839
		}
1840
		// Work out what to do with the user data otherwise...
1841
		else
1842
		{
1843
			// Anything going to check or select is pointless keeping - as is anything coming from check!
1844
			if (($_POST['field_type'] == 'check' && $context['field']['type'] != 'check')
1845
				|| (($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio') && $context['field']['type'] != 'select' && $context['field']['type'] != 'radio')
1846
				|| ($context['field']['type'] == 'check' && $_POST['field_type'] != 'check'))
1847
			{
1848
				$smcFunc['db_query']('', '
1849
					DELETE FROM {db_prefix}themes
1850
					WHERE variable = {string:current_column}
1851
						AND id_member > {int:no_member}',
1852
					array(
1853
						'no_member' => 0,
1854
						'current_column' => $context['field']['col_name'],
1855
					)
1856
				);
1857
			}
1858
			// Otherwise - if the select is edited may need to adjust!
1859
			elseif ($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio')
1860
			{
1861
				$optionChanges = array();
1862
				$takenKeys = array();
1863
				// Work out what's changed!
1864
				foreach ($context['field']['options'] as $k => $option)
1865
				{
1866
					if (trim($option) == '')
1867
						continue;
1868
1869
					// Still exists?
1870
					if (in_array($option, $newOptions))
1871
					{
1872
						$takenKeys[] = $k;
1873
						continue;
1874
					}
1875
				}
1876
1877
				// Finally - have we renamed it - or is it really gone?
1878
				foreach ($optionChanges as $k => $option)
1879
				{
1880
					// Just been renamed?
1881
					if (!in_array($k, $takenKeys) && !empty($newOptions[$k]))
1882
						$smcFunc['db_query']('', '
1883
							UPDATE {db_prefix}themes
1884
							SET value = {string:new_value}
1885
							WHERE variable = {string:current_column}
1886
								AND value = {string:old_value}
1887
								AND id_member > {int:no_member}',
1888
							array(
1889
								'no_member' => 0,
1890
								'new_value' => $newOptions[$k],
1891
								'current_column' => $context['field']['col_name'],
1892
								'old_value' => $option,
1893
							)
1894
						);
1895
				}
1896
			}
1897
			// @todo Maybe we should adjust based on new text length limits?
1898
		}
1899
1900
		// Do the insertion/updates.
1901
		if ($context['fid'])
1902
		{
1903
			$smcFunc['db_query']('', '
1904
				UPDATE {db_prefix}custom_fields
1905
				SET
1906
					field_name = {string:field_name}, field_desc = {string:field_desc},
1907
					field_type = {string:field_type}, field_length = {int:field_length},
1908
					field_options = {string:field_options}, show_reg = {int:show_reg},
1909
					show_display = {int:show_display}, show_mlist = {int:show_mlist}, show_profile = {string:show_profile},
1910
					private = {int:private}, active = {int:active}, default_value = {string:default_value},
1911
					can_search = {int:can_search}, bbc = {int:bbc}, mask = {string:mask},
1912
					enclose = {string:enclose}, placement = {int:placement}
1913
				WHERE id_field = {int:current_field}',
1914
				array(
1915
					'field_length' => $field_length,
1916
					'show_reg' => $show_reg,
1917
					'show_display' => $show_display,
1918
					'show_mlist' => $show_mlist,
1919
					'private' => $private,
1920
					'active' => $active,
1921
					'can_search' => $can_search,
1922
					'bbc' => $bbc,
1923
					'current_field' => $context['fid'],
1924
					'field_name' => $_POST['field_name'],
1925
					'field_desc' => $_POST['field_desc'],
1926
					'field_type' => $_POST['field_type'],
1927
					'field_options' => $field_options,
1928
					'show_profile' => $show_profile,
1929
					'default_value' => $default,
1930
					'mask' => $mask,
1931
					'enclose' => $enclose,
1932
					'placement' => $placement,
1933
				)
1934
			);
1935
1936
			// Just clean up any old selects - these are a pain!
1937
			if (($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio') && !empty($newOptions))
1938
				$smcFunc['db_query']('', '
1939
					DELETE FROM {db_prefix}themes
1940
					WHERE variable = {string:current_column}
1941
						AND value NOT IN ({array_string:new_option_values})
1942
						AND id_member > {int:no_member}',
1943
					array(
1944
						'no_member' => 0,
1945
						'new_option_values' => $newOptions,
1946
						'current_column' => $context['field']['col_name'],
1947
					)
1948
				);
1949
		}
1950
		else
1951
		{
1952
			// Gotta figure it out the order.
1953
			$new_order = $order_count > 1 ? ($order_count + 1) : 1;
1954
1955
			$smcFunc['db_insert']('',
1956
				'{db_prefix}custom_fields',
1957
				array(
1958
					'col_name' => 'string', 'field_name' => 'string', 'field_desc' => 'string',
1959
					'field_type' => 'string', 'field_length' => 'string', 'field_options' => 'string', 'field_order' => 'int',
1960
					'show_reg' => 'int', 'show_display' => 'int', 'show_mlist' => 'int', 'show_profile' => 'string',
1961
					'private' => 'int', 'active' => 'int', 'default_value' => 'string', 'can_search' => 'int',
1962
					'bbc' => 'int', 'mask' => 'string', 'enclose' => 'string', 'placement' => 'int',
1963
				),
1964
				array(
1965
					$col_name, $_POST['field_name'], $_POST['field_desc'],
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $col_name does not seem to be defined for all execution paths leading up to this point.
Loading history...
1966
					$_POST['field_type'], $field_length, $field_options, $new_order,
1967
					$show_reg, $show_display, $show_mlist, $show_profile,
1968
					$private, $active, $default, $can_search,
1969
					$bbc, $mask, $enclose, $placement,
1970
				),
1971
				array('id_field')
1972
			);
1973
		}
1974
	}
1975
	// Deleting?
1976
	elseif (isset($_POST['delete']) && $context['field']['col_name'])
1977
	{
1978
		checkSession();
1979
		validateToken('admin-ecp');
1980
1981
		// Delete the user data first.
1982
		$smcFunc['db_query']('', '
1983
			DELETE FROM {db_prefix}themes
1984
			WHERE variable = {string:current_column}
1985
				AND id_member > {int:no_member}',
1986
			array(
1987
				'no_member' => 0,
1988
				'current_column' => $context['field']['col_name'],
1989
			)
1990
		);
1991
		// Finally - the field itself is gone!
1992
		$smcFunc['db_query']('', '
1993
			DELETE FROM {db_prefix}custom_fields
1994
			WHERE id_field = {int:current_field}',
1995
			array(
1996
				'current_field' => $context['fid'],
1997
			)
1998
		);
1999
2000
		// Re-arrange the order.
2001
		$smcFunc['db_query']('','
2002
			UPDATE {db_prefix}custom_fields
2003
			SET field_order = field_order - 1
2004
			WHERE field_order > {int:current_order}',
2005
			array(
2006
				'current_order' => $context['field']['order'],
2007
			)
2008
		);
2009
	}
2010
2011
	// Rebuild display cache etc.
2012
	if (isset($_POST['delete']) || isset($_POST['save']))
2013
	{
2014
		checkSession();
2015
2016
		$request = $smcFunc['db_query']('', '
2017
			SELECT col_name, field_name, field_type, field_order, bbc, enclose, placement, show_mlist, field_options
2018
			FROM {db_prefix}custom_fields
2019
			WHERE show_display = {int:is_displayed}
2020
				AND active = {int:active}
2021
				AND private != {int:not_owner_only}
2022
				AND private != {int:not_admin_only}
2023
			ORDER BY field_order',
2024
			array(
2025
				'is_displayed' => 1,
2026
				'active' => 1,
2027
				'not_owner_only' => 2,
2028
				'not_admin_only' => 3,
2029
			)
2030
		);
2031
2032
		$fields = array();
2033
		while ($row = $smcFunc['db_fetch_assoc']($request))
2034
		{
2035
			$fields[] = array(
2036
				'col_name' => strtr($row['col_name'], array('|' => '', ';' => '')),
2037
				'title' => strtr($row['field_name'], array('|' => '', ';' => '')),
2038
				'type' => $row['field_type'],
2039
				'order' => $row['field_order'],
2040
				'bbc' => $row['bbc'] ? '1' : '0',
2041
				'placement' => !empty($row['placement']) ? $row['placement'] : '0',
2042
				'enclose' => !empty($row['enclose']) ? $row['enclose'] : '',
2043
				'mlist' => $row['show_mlist'],
2044
				'options' => (!empty($row['field_options']) ? explode(',', $row['field_options']) : array()),
2045
			);
2046
		}
2047
		$smcFunc['db_free_result']($request);
2048
2049
		updateSettings(array('displayFields' => $smcFunc['json_encode']($fields)));
2050
		$_SESSION['adm-save'] = true;
2051
		redirectexit('action=admin;area=featuresettings;sa=profile');
2052
	}
2053
2054
	createToken('admin-ecp');
2055
}
2056
2057
/**
2058
 * Returns the maximum field_order value for the custom fields
2059
 * @return int The maximum value of field_order from the custom_fields table
2060
 */
2061
function custFieldsMaxOrder()
2062
{
2063
	global $smcFunc;
2064
2065
	// Gotta know the order limit
2066
	$result = $smcFunc['db_query']('', '
2067
			SELECT MAX(field_order)
2068
			FROM {db_prefix}custom_fields',
2069
			array()
2070
		);
2071
2072
	list ($order_count) = $smcFunc['db_fetch_row']($result);
2073
	$smcFunc['db_free_result']($result);
2074
2075
	return (int) $order_count;
2076
}
2077
2078
/**
2079
 * Allow to edit the settings on the pruning screen.
2080
 * @param bool $return_config Whether or not to return the config_vars array (used for admin search)
2081
 * @return void|array Returns nothing or returns the $config_vars array if $return_config is true
2082
 */
2083
function ModifyLogSettings($return_config = false)
2084
{
2085
	global $txt, $scripturl, $sourcedir, $context, $modSettings;
2086
2087
	// Make sure we understand what's going on.
2088
	loadLanguage('ManageSettings');
2089
2090
	$context['page_title'] = $txt['log_settings'];
2091
2092
	$config_vars = array(
2093
			array('check', 'modlog_enabled', 'help' => 'modlog'),
2094
			array('check', 'adminlog_enabled', 'help' => 'adminlog'),
2095
			array('check', 'userlog_enabled', 'help' => 'userlog'),
2096
			// The error log is a wonderful thing.
2097
			array('title', 'errlog'),
2098
			array('desc', 'error_log_desc'),
2099
			array('check', 'enableErrorLogging'),
2100
			array('check', 'enableErrorQueryLogging'),
2101
			array('check', 'log_ban_hits'),
2102
			// Even do the pruning?
2103
			array('title', 'pruning_title'),
2104
			array('desc', 'pruning_desc'),
2105
			// The array indexes are there so we can remove/change them before saving.
2106
			'pruningOptions' => array('check', 'pruningOptions'),
2107
		'',
2108
			// Various logs that could be pruned.
2109
			array('int', 'pruneErrorLog', 'postinput' => $txt['days_word'], 'subtext' => $txt['zero_to_disable']), // Error log.
2110
			array('int', 'pruneModLog', 'postinput' => $txt['days_word'], 'subtext' => $txt['zero_to_disable']), // Moderation log.
2111
			array('int', 'pruneBanLog', 'postinput' => $txt['days_word'], 'subtext' => $txt['zero_to_disable']), // Ban hit log.
2112
			array('int', 'pruneReportLog', 'postinput' => $txt['days_word'], 'subtext' => $txt['zero_to_disable']), // Report to moderator log.
2113
			array('int', 'pruneScheduledTaskLog', 'postinput' => $txt['days_word'], 'subtext' => $txt['zero_to_disable']), // Log of the scheduled tasks and how long they ran.
2114
			array('int', 'pruneSpiderHitLog', 'postinput' => $txt['days_word'], 'subtext' => $txt['zero_to_disable']), // Log of the scheduled tasks and how long they ran.
2115
			// If you add any additional logs make sure to add them after this point.  Additionally, make sure you add them to the weekly scheduled task.
2116
			// Mod Developers: Do NOT use the pruningOptions master variable for this as SMF Core may overwrite your setting in the future!
2117
	);
2118
2119
	// We want to be toggling some of these for a nice user experience. If you want to add yours to the list of those magically hidden when the 'pruning' option is off, add to this.
2120
	$prune_toggle = array('pruneErrorLog', 'pruneModLog', 'pruneBanLog', 'pruneReportLog', 'pruneScheduledTaskLog', 'pruneSpiderHitLog');
2121
2122
	call_integration_hook('integrate_prune_settings', array(&$config_vars, &$prune_toggle, false));
2123
2124
	$prune_toggle_dt = array();
2125
	foreach ($prune_toggle as $item)
2126
		$prune_toggle_dt[] = 'setting_' . $item;
2127
2128
	if ($return_config)
2129
		return $config_vars;
2130
2131
	addInlineJavaScript('
2132
	function togglePruned()
2133
	{
2134
		var newval = $("#pruningOptions").prop("checked");
2135
		$("#' . implode(', #', $prune_toggle) . '").closest("dd").toggle(newval);
2136
		$("#' . implode(', #', $prune_toggle_dt) . '").closest("dt").toggle(newval);
2137
	};
2138
	togglePruned();
2139
	$("#pruningOptions").click(function() { togglePruned(); });', true);
2140
2141
	// We'll need this in a bit.
2142
	require_once($sourcedir . '/ManageServer.php');
2143
2144
	// Saving?
2145
	if (isset($_GET['save']))
2146
	{
2147
		checkSession();
2148
2149
		// Because of the excitement attached to combining pruning log items, we need to duplicate everything here.
2150
		$savevar = array(
2151
			array('check', 'modlog_enabled'),
2152
			array('check', 'adminlog_enabled'),
2153
			array('check', 'userlog_enabled'),
2154
			array('check', 'enableErrorLogging'),
2155
			array('check', 'enableErrorQueryLogging'),
2156
			array('check', 'log_ban_hits'),
2157
			array('text', 'pruningOptions')
2158
		);
2159
2160
		call_integration_hook('integrate_prune_settings', array(&$savevar, &$prune_toggle, true));
2161
2162
		if (!empty($_POST['pruningOptions']))
2163
		{
2164
			$vals = array();
2165
			foreach ($config_vars as $index => $dummy)
2166
			{
2167
				if (!is_array($dummy) || $index == 'pruningOptions' || !in_array($dummy[1], $prune_toggle))
2168
					continue;
2169
2170
				$vals[] = empty($_POST[$dummy[1]]) || $_POST[$dummy[1]] < 0 ? 0 : (int) $_POST[$dummy[1]];
2171
			}
2172
			$_POST['pruningOptions'] = implode(',', $vals);
2173
		}
2174
		else
2175
			$_POST['pruningOptions'] = '';
2176
2177
		saveDBSettings($savevar);
2178
		$_SESSION['adm-save'] = true;
2179
		redirectexit('action=admin;area=logs;sa=settings');
2180
	}
2181
2182
	$context['post_url'] = $scripturl . '?action=admin;area=logs;save;sa=settings';
2183
	$context['settings_title'] = $txt['log_settings'];
2184
	$context['sub_template'] = 'show_settings';
2185
2186
	// Get the actual values
2187
	if (!empty($modSettings['pruningOptions']))
2188
		@list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
2189
	else
2190
		$modSettings['pruneErrorLog'] = $modSettings['pruneModLog'] = $modSettings['pruneBanLog'] = $modSettings['pruneReportLog'] = $modSettings['pruneScheduledTaskLog'] = $modSettings['pruneSpiderHitLog'] = 0;
2191
2192
	prepareDBSettingContext($config_vars);
2193
}
2194
2195
/**
2196
 * If you have a general mod setting to add stick it here.
2197
 *
2198
 * @param bool $return_config Whether or not to return the config_vars array (used for admin search)
2199
 * @return void|array Returns nothing or returns the $config_vars array if $return_config is true
2200
 */
2201
function ModifyGeneralModSettings($return_config = false)
2202
{
2203
	global $txt, $scripturl, $context;
2204
2205
	$config_vars = array(
2206
		// Mod authors, add any settings UNDER this line. Include a comma at the end of the line and don't remove this statement!!
2207
	);
2208
2209
	// Make it even easier to add new settings.
2210
	call_integration_hook('integrate_general_mod_settings', array(&$config_vars));
2211
2212
	if ($return_config)
2213
		return $config_vars;
2214
2215
	$context['post_url'] = $scripturl . '?action=admin;area=modsettings;save;sa=general';
2216
	$context['settings_title'] = $txt['mods_cat_modifications_misc'];
2217
2218
	// No removing this line you, dirty unwashed mod authors. :p
2219
	if (empty($config_vars))
2220
	{
2221
		$context['settings_save_dont_show'] = true;
2222
		$context['settings_message'] = '<div class="centertext">' . $txt['modification_no_misc_settings'] . '</div>';
2223
2224
		return prepareDBSettingContext($config_vars);
0 ignored issues
show
Bug introduced by
Are you sure the usage of prepareDBSettingContext($config_vars) is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
2225
	}
2226
2227
	// Saving?
2228
	if (isset($_GET['save']))
2229
	{
2230
		checkSession();
2231
2232
		$save_vars = $config_vars;
2233
2234
		call_integration_hook('integrate_save_general_mod_settings', array(&$save_vars));
2235
2236
		// This line is to help mod authors do a search/add after if you want to add something here. Keyword: FOOT TAPPING SUCKS!
2237
		saveDBSettings($save_vars);
2238
2239
		// This line is to remind mod authors that it's nice to let the users know when something has been saved.
2240
		$_SESSION['adm-save'] = true;
2241
2242
		// This line is to help mod authors do a search/add after if you want to add something here. Keyword: I LOVE TEA!
2243
		redirectexit('action=admin;area=modsettings;sa=general');
2244
	}
2245
2246
	// This line is to help mod authors do a search/add after if you want to add something here. Keyword: RED INK IS FOR TEACHERS AND THOSE WHO LIKE PAIN!
2247
	prepareDBSettingContext($config_vars);
2248
}
2249
2250
/**
2251
 * Handles modifying the alerts settings
2252
 */
2253
function ModifyAlertsSettings()
2254
{
2255
	global $context, $modSettings, $sourcedir, $txt;
2256
2257
	// Dummy settings for the template...
2258
	$modSettings['allow_disableAnnounce'] = false;
2259
	$context['user']['is_owner'] = false;
2260
	$context['member'] = array();
2261
	$context['id_member'] = 0;
2262
	$context['menu_item_selected'] = 'alerts';
2263
	$context['token_check'] = 'noti-admin';
2264
2265
	// Specify our action since we'll want to post back here instead of the profile
2266
	$context['action'] = 'action=admin;area=featuresettings;sa=alerts;'. $context['session_var'] .'='. $context['session_id'];
2267
2268
	loadTemplate('Profile');
2269
	loadLanguage('Profile');
2270
2271
	include_once($sourcedir . '/Profile-Modify.php');
2272
	alert_configuration(0);
2273
2274
	$context['page_title'] = $txt['notify_settings'];
2275
2276
	// Override the description
2277
	$context['description'] = $txt['notifications_desc'];
2278
	$context['sub_template'] = 'alert_configuration';
2279
}
2280
2281
?>