Issues (1027)

Sources/ManageSettings.php (3 issues)

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 2019 Simple Machines and individual contributors
12
 * @license http://www.simplemachines.org/about/smf/license.php BSD
13
 *
14
 * @version 2.1 RC2
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
166
		// Basic stuff, titles, flash, permissions...
167
		array('check', 'allow_guestAccess'),
168
		array('check', 'enable_buddylist'),
169
		array('check', 'allow_hideOnline'),
170
		array('check', 'titlesEnable'),
171
		array('text', 'default_personal_text', 'subtext' => $txt['default_personal_text_note'], 'disabled' => !$can_personal_text),
172
		array('check', 'topic_move_any'),
173
		array('int', 'defaultMaxListItems', 'step' => 1, 'min' => 1, 'max' => 999),
174
		'',
175
176
		// Jquery source
177
		array(
178
			'select',
179
			'jquery_source',
180
			array(
181
				'auto' => $txt['jquery_auto'],
182
				'local' => $txt['jquery_local'],
183
				'cdn' => $txt['jquery_cdn'],
184
				'custom' => $txt['jquery_custom']
185
			),
186
			'onchange' => 'if (this.value == \'custom\'){document.getElementById(\'jquery_custom\').disabled = false; } else {document.getElementById(\'jquery_custom\').disabled = true;}'
187
		),
188
		array(
189
			'text',
190
			'jquery_custom',
191
			'disabled' => isset($modSettings['jquery_source']) && $modSettings['jquery_source'] != 'custom', 'size' => 75
192
		),
193
		'',
194
195
		// css and js minification.
196
		array('check', 'minimize_files'),
197
		'',
198
199
		// SEO stuff
200
		array('check', 'queryless_urls', 'subtext' => '<strong>' . $txt['queryless_urls_note'] . '</strong>'),
201
		array('text', 'meta_keywords', 'subtext' => $txt['meta_keywords_note'], 'size' => 50),
202
		'',
203
204
		// Number formatting, timezones.
205
		array('text', 'time_format'),
206
		array(
207
			'float',
208
			'time_offset',
209
			'subtext' => $txt['setting_time_offset_note'],
210
			6,
211
			'postinput' => $txt['hours'],
212
			'step' => 0.25,
213
			'min' => -23.5,
214
			'max' => 23.5
215
		),
216
		'default_timezone' => array('select', 'default_timezone', array()),
217
		array('text', 'timezone_priority_countries', 'subtext' => $txt['setting_timezone_priority_countries_note']),
218
		'',
219
220
		// Who's online?
221
		array('check', 'who_enabled'),
222
		array('int', 'lastActive', 6, 'postinput' => $txt['minutes']),
223
		'',
224
225
		// Statistics.
226
		array('check', 'trackStats'),
227
		array('check', 'hitStats'),
228
		'',
229
230
		// Option-ish things... miscellaneous sorta.
231
		array('check', 'allow_disableAnnounce'),
232
		array('check', 'disallow_sendBody'),
233
		'',
234
235
		// Alerts stuff
236
		array('check', 'enable_ajax_alerts'),
237
	);
238
239
	// Get all the time zones.
240
	if (function_exists('timezone_identifiers_list') && function_exists('date_default_timezone_set'))
241
	{
242
		$all_zones = timezone_identifiers_list();
243
		// Make sure we set the value to the same as the printed value.
244
		foreach ($all_zones as $zone)
245
			$config_vars['default_timezone'][2][$zone] = $zone;
246
	}
247
	else
248
		unset($config_vars['default_timezone']);
249
250
	call_integration_hook('integrate_modify_basic_settings', array(&$config_vars));
251
252
	if ($return_config)
253
		return $config_vars;
254
255
	// Saving?
256
	if (isset($_GET['save']))
257
	{
258
		checkSession();
259
260
		// Prevent absurd boundaries here - make it a day tops.
261
		if (isset($_POST['lastActive']))
262
			$_POST['lastActive'] = min((int) $_POST['lastActive'], 1440);
263
264
		call_integration_hook('integrate_save_basic_settings');
265
266
		saveDBSettings($config_vars);
267
		$_SESSION['adm-save'] = true;
268
269
		// Do a bit of housekeeping
270
		if (empty($_POST['minimize_files']) || $_POST['minimize_files'] != $modSettings['minimize_files'])
271
			deleteAllMinified();
272
273
		writeLog();
274
		redirectexit('action=admin;area=featuresettings;sa=basic');
275
	}
276
277
	$context['post_url'] = $scripturl . '?action=admin;area=featuresettings;save;sa=basic';
278
	$context['settings_title'] = $txt['mods_cat_features'];
279
280
	prepareDBSettingContext($config_vars);
281
}
282
283
/**
284
 * Set a few Bulletin Board Code settings. It loads a list of Bulletin Board Code tags to allow disabling tags.
285
 * Requires the admin_forum permission.
286
 * Accessed from ?action=admin;area=featuresettings;sa=bbc.
287
 *
288
 * @param bool $return_config Whether or not to return the config_vars array (used for admin search)
289
 * @return void|array Returns nothing or returns the $config_vars array if $return_config is true
290
 * @uses Admin template, edit_bbc_settings sub-template.
291
 */
292
function ModifyBBCSettings($return_config = false)
293
{
294
	global $context, $txt, $modSettings, $scripturl, $sourcedir;
295
296
	$config_vars = array(
297
		// Main tweaks
298
		array('check', 'enableBBC'),
299
		array('check', 'enableBBC', 0, 'onchange' => 'toggleBBCDisabled(\'disabledBBC\', !this.checked); toggleBBCDisabled(\'legacyBBC\', !this.checked);'),
300
		array('check', 'enablePostHTML'),
301
		array('check', 'autoLinkUrls'),
302
		'',
303
304
		array('bbc', 'disabledBBC'),
305
306
		// This one is actually pretend...
307
		array('bbc', 'legacyBBC', 'help' => 'legacy_bbc'),
308
	);
309
310
	// Permissions for restricted BBC
311
	if (!empty($context['restricted_bbc']))
312
		$config_vars[] = '';
313
314
	foreach ($context['restricted_bbc'] as $bbc)
315
		$config_vars[] = array('permissions', 'bbc_' . $bbc, 'text_label' => sprintf($txt['groups_can_use'], '[' . $bbc . ']'));
316
317
	$context['settings_post_javascript'] = '
318
		toggleBBCDisabled(\'disabledBBC\', ' . (empty($modSettings['enableBBC']) ? 'true' : 'false') . ');
319
		toggleBBCDisabled(\'legacyBBC\', ' . (empty($modSettings['enableBBC']) ? 'true' : 'false') . ');';
320
321
	call_integration_hook('integrate_modify_bbc_settings', array(&$config_vars));
322
323
	if ($return_config)
324
		return $config_vars;
325
326
	// Setup the template.
327
	require_once($sourcedir . '/ManageServer.php');
328
	$context['sub_template'] = 'show_settings';
329
	$context['page_title'] = $txt['manageposts_bbc_settings_title'];
330
331
	// Make sure we check the right tags!
332
	$modSettings['bbc_disabled_disabledBBC'] = empty($modSettings['disabledBBC']) ? array() : explode(',', $modSettings['disabledBBC']);
333
334
	// Legacy BBC are listed separately, but we use the same info in both cases
335
	$modSettings['bbc_disabled_legacyBBC'] = $modSettings['bbc_disabled_disabledBBC'];
336
337
	$extra = '';
338
	if (isset($_REQUEST['cowsay']))
339
	{
340
		$config_vars[] = array('permissions', 'bbc_cowsay', 'text_label' => sprintf($txt['groups_can_use'], 'cowsay'));
341
		$extra = ';cowsay';
342
	}
343
344
	// Saving?
345
	if (isset($_GET['save']))
346
	{
347
		checkSession();
348
349
		// Clean up the tags.
350
		$bbcTags = array();
351
		foreach (parse_bbc(false) as $tag)
352
			$bbcTags[] = $tag['tag'];
353
354
		if (!isset($_POST['disabledBBC_enabledTags']))
355
			$_POST['disabledBBC_enabledTags'] = array();
356
		elseif (!is_array($_POST['disabledBBC_enabledTags']))
357
			$_POST['disabledBBC_enabledTags'] = array($_POST['disabledBBC_enabledTags']);
358
359
		if (!isset($_POST['legacyBBC_enabledTags']))
360
			$_POST['legacyBBC_enabledTags'] = array();
361
		elseif (!is_array($_POST['legacyBBC_enabledTags']))
362
			$_POST['legacyBBC_enabledTags'] = array($_POST['legacyBBC_enabledTags']);
363
364
		$_POST['disabledBBC_enabledTags'] = array_unique(array_merge($_POST['disabledBBC_enabledTags'], $_POST['legacyBBC_enabledTags']));
365
366
		// Work out what is actually disabled!
367
		$_POST['disabledBBC'] = implode(',', array_diff($bbcTags, $_POST['disabledBBC_enabledTags']));
368
369
		// $modSettings['legacyBBC'] isn't really a thing...
370
		unset($_POST['legacyBBC_enabledTags']);
371
		$config_vars = array_filter($config_vars, function($config_var)
372
		{
373
			return !isset($config_var[1]) || $config_var[1] != 'legacyBBC';
374
		});
375
376
		call_integration_hook('integrate_save_bbc_settings', array($bbcTags));
377
378
		saveDBSettings($config_vars);
379
		$_SESSION['adm-save'] = true;
380
		redirectexit('action=admin;area=featuresettings;sa=bbc' . $extra);
381
	}
382
383
	$context['post_url'] = $scripturl . '?action=admin;area=featuresettings;save;sa=bbc' . $extra;
384
	$context['settings_title'] = $txt['manageposts_bbc_settings_title'];
385
386
	prepareDBSettingContext($config_vars);
387
}
388
389
/**
390
 * Allows modifying the global layout settings in the forum
391
 * Accessed through ?action=admin;area=featuresettings;sa=layout;
392
 *
393
 * @param bool $return_config Whether or not to return the config_vars array (used for admin search)
394
 * @return void|array Returns nothing or returns the $config_vars array if $return_config is true
395
 */
396
function ModifyLayoutSettings($return_config = false)
397
{
398
	global $txt, $scripturl, $context;
399
400
	$config_vars = array(
401
		// Pagination stuff.
402
		array('check', 'compactTopicPagesEnable'),
403
		array(
404
			'int',
405
			'compactTopicPagesContiguous',
406
			null,
407
			$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>'
408
		),
409
		array('int', 'defaultMaxMembers'),
410
		'',
411
412
		// Stuff that just is everywhere - today, search, online, etc.
413
		array('select', 'todayMod', array($txt['today_disabled'], $txt['today_only'], $txt['yesterday_today'])),
414
		array('check', 'onlineEnable'),
415
		'',
416
417
		// This is like debugging sorta.
418
		array('check', 'timeLoadPageEnable'),
419
	);
420
421
	call_integration_hook('integrate_layout_settings', array(&$config_vars));
422
423
	if ($return_config)
424
		return $config_vars;
425
426
	// Saving?
427
	if (isset($_GET['save']))
428
	{
429
		checkSession();
430
431
		call_integration_hook('integrate_save_layout_settings');
432
433
		saveDBSettings($config_vars);
434
		$_SESSION['adm-save'] = true;
435
		writeLog();
436
437
		redirectexit('action=admin;area=featuresettings;sa=layout');
438
	}
439
440
	$context['post_url'] = $scripturl . '?action=admin;area=featuresettings;save;sa=layout';
441
	$context['settings_title'] = $txt['mods_cat_layout'];
442
443
	prepareDBSettingContext($config_vars);
444
}
445
446
/**
447
 * Config array for changing like settings
448
 * Accessed  from ?action=admin;area=featuresettings;sa=likes;
449
 *
450
 * @param bool $return_config Whether or not to return the config_vars array
451
 * @return void|array Returns nothing or returns the $config_vars array if $return_config is true
452
 */
453
function ModifyLikesSettings($return_config = false)
454
{
455
	global $txt, $scripturl, $context;
456
457
	$config_vars = array(
458
		array('check', 'enable_likes'),
459
		array('permissions', 'likes_like'),
460
	);
461
462
	call_integration_hook('integrate_likes_settings', array(&$config_vars));
463
464
	if ($return_config)
465
		return $config_vars;
466
467
	// Saving?
468
	if (isset($_GET['save']))
469
	{
470
		checkSession();
471
472
		call_integration_hook('integrate_save_likes_settings');
473
474
		saveDBSettings($config_vars);
475
		$_SESSION['adm-save'] = true;
476
		redirectexit('action=admin;area=featuresettings;sa=likes');
477
	}
478
479
	$context['post_url'] = $scripturl . '?action=admin;area=featuresettings;save;sa=likes';
480
	$context['settings_title'] = $txt['likes'];
481
482
	prepareDBSettingContext($config_vars);
483
}
484
485
/**
486
 * Config array for changing like settings
487
 * Accessed  from ?action=admin;area=featuresettings;sa=mentions;
488
 *
489
 * @param bool $return_config Whether or not to return the config_vars array (used for admin search)
490
 * @return void|array Returns nothing or returns the $config_vars array if $return_config is true
491
 */
492
function ModifyMentionsSettings($return_config = false)
493
{
494
	global $txt, $scripturl, $context;
495
496
	$config_vars = array(
497
		array('check', 'enable_mentions'),
498
		array('permissions', 'mention'),
499
	);
500
501
	call_integration_hook('integrate_mentions_settings', array(&$config_vars));
502
503
	if ($return_config)
504
		return $config_vars;
505
506
	// Saving?
507
	if (isset($_GET['save']))
508
	{
509
		checkSession();
510
511
		call_integration_hook('integrate_save_mentions_settings');
512
513
		saveDBSettings($config_vars);
514
		$_SESSION['adm-save'] = true;
515
		redirectexit('action=admin;area=featuresettings;sa=mentions');
516
	}
517
518
	$context['post_url'] = $scripturl . '?action=admin;area=featuresettings;save;sa=mentions';
519
	$context['settings_title'] = $txt['mentions'];
520
521
	prepareDBSettingContext($config_vars);
522
}
523
524
/**
525
 * Moderation type settings - although there are fewer than we have you believe ;)
526
 *
527
 * @param bool $return_config Whether or not to return the config_vars array (used for admin search)
528
 * @return void|array Returns nothing or returns the $config_vars array if $return_config is true
529
 */
530
function ModifyWarningSettings($return_config = false)
531
{
532
	global $txt, $scripturl, $context, $modSettings, $sourcedir;
533
534
	// You need to be an admin to edit settings!
535
	isAllowedTo('admin_forum');
536
537
	loadLanguage('Help');
538
	loadLanguage('ManageSettings');
539
540
	// We need the existing ones for this
541
	list ($currently_enabled, $modSettings['user_limit'], $modSettings['warning_decrement']) = explode(',', $modSettings['warning_settings']);
542
543
	$config_vars = array(
544
		// Warning system?
545
		'enable' => array('check', 'warning_enable'),
546
	);
547
548
	if (!empty($modSettings['warning_settings']) && $currently_enabled)
549
		$config_vars += array(
550
			'',
551
552
			array(
553
				'int',
554
				'warning_watch',
555
				'subtext' => $txt['setting_warning_watch_note'] . ' ' . $txt['zero_to_disable']
556
			),
557
			'moderate' => array(
558
				'int',
559
				'warning_moderate',
560
				'subtext' => $txt['setting_warning_moderate_note'] . ' ' . $txt['zero_to_disable']
561
			),
562
			array(
563
				'int',
564
				'warning_mute',
565
				'subtext' => $txt['setting_warning_mute_note'] . ' ' . $txt['zero_to_disable']
566
			),
567
			'rem1' => array(
568
				'int',
569
				'user_limit',
570
				'subtext' => $txt['setting_user_limit_note']
571
			),
572
			'rem2' => array(
573
				'int',
574
				'warning_decrement',
575
				'subtext' => $txt['setting_warning_decrement_note'] . ' ' . $txt['zero_to_disable']
576
			),
577
			array('permissions', 'view_warning_any'),
578
			array('permissions', 'view_warning_own'),
579
		);
580
581
	call_integration_hook('integrate_warning_settings', array(&$config_vars));
582
583
	if ($return_config)
584
		return $config_vars;
585
586
	// Cannot use moderation if post moderation is not enabled.
587
	if (!$modSettings['postmod_active'])
588
		unset($config_vars['moderate']);
589
590
	// Will need the utility functions from here.
591
	require_once($sourcedir . '/ManageServer.php');
592
593
	// Saving?
594
	if (isset($_GET['save']))
595
	{
596
		checkSession();
597
598
		// Make sure these don't have an effect.
599
		if (!$currently_enabled && empty($_POST['warning_enable']))
600
		{
601
			$_POST['warning_watch'] = 0;
602
			$_POST['warning_moderate'] = 0;
603
			$_POST['warning_mute'] = 0;
604
		}
605
		// If it was disabled and we're enabling it now, set some sane defaults.
606
		elseif (!$currently_enabled && !empty($_POST['warning_enable']))
607
		{
608
			// Need to add these, these weren't there before...
609
			$vars = array(
610
				'warning_watch' => 10,
611
				'warning_mute' => 60,
612
			);
613
			if ($modSettings['postmod_active'])
614
				$vars['warning_moderate'] = 35;
615
616
			foreach ($vars as $var => $value)
617
			{
618
				$config_vars[] = array('int', $var);
619
				$_POST[$var] = $value;
620
			}
621
		}
622
		else
623
		{
624
			$_POST['warning_watch'] = min($_POST['warning_watch'], 100);
625
			$_POST['warning_moderate'] = $modSettings['postmod_active'] ? min($_POST['warning_moderate'], 100) : 0;
626
			$_POST['warning_mute'] = min($_POST['warning_mute'], 100);
627
		}
628
629
		// We might not have these already depending on how we got here.
630
		$_POST['user_limit'] = isset($_POST['user_limit']) ? (int) $_POST['user_limit'] : $modSettings['user_limit'];
631
		$_POST['warning_decrement'] = isset($_POST['warning_decrement']) ? (int) $_POST['warning_decrement'] : $modSettings['warning_decrement'];
632
633
		// Fix the warning setting array!
634
		$_POST['warning_settings'] = (!empty($_POST['warning_enable']) ? 1 : 0) . ',' . min(100, $_POST['user_limit']) . ',' . min(100, $_POST['warning_decrement']);
635
		$save_vars = $config_vars;
636
		$save_vars[] = array('text', 'warning_settings');
637
		unset($save_vars['enable'], $save_vars['rem1'], $save_vars['rem2']);
638
639
		call_integration_hook('integrate_save_warning_settings', array(&$save_vars));
640
641
		saveDBSettings($save_vars);
642
		$_SESSION['adm-save'] = true;
643
		redirectexit('action=admin;area=warnings');
644
	}
645
646
	// We actually store lots of these together - for efficiency.
647
	list ($modSettings['warning_enable'], $modSettings['user_limit'], $modSettings['warning_decrement']) = explode(',', $modSettings['warning_settings']);
648
649
	$context['sub_template'] = 'show_settings';
650
	$context['post_url'] = $scripturl . '?action=admin;area=warnings;save';
651
	$context['settings_title'] = $txt['warnings'];
652
	$context['page_title'] = $txt['warnings'];
653
654
	$context[$context['admin_menu_name']]['tab_data'] = array(
655
		'title' => $txt['warnings'],
656
		'help' => '',
657
		'description' => $txt['warnings_desc'],
658
	);
659
660
	prepareDBSettingContext($config_vars);
661
}
662
663
/**
664
 * Let's try keep the spam to a minimum ah Thantos?
665
 *
666
 * @param bool $return_config Whether or not to return the config_vars array (used for admin search)
667
 * @return void|array Returns nothing or returns the $config_vars array if $return_config is true
668
 */
669
function ModifyAntispamSettings($return_config = false)
670
{
671
	global $txt, $scripturl, $context, $modSettings, $smcFunc, $language, $sourcedir;
672
673
	loadLanguage('Help');
674
	loadLanguage('ManageSettings');
675
676
	// Generate a sample registration image.
677
	$context['use_graphic_library'] = in_array('gd', get_loaded_extensions());
678
	$context['verification_image_href'] = $scripturl . '?action=verificationcode;rand=' . md5(mt_rand());
679
680
	$config_vars = array(
681
		array('check', 'reg_verification'),
682
		array('check', 'search_enable_captcha'),
683
		// This, my friend, is a cheat :p
684
		'guest_verify' => array(
685
			'check',
686
			'guests_require_captcha',
687
			'subtext' => $txt['setting_guests_require_captcha_desc']
688
		),
689
		array(
690
			'int',
691
			'posts_require_captcha',
692
			'subtext' => $txt['posts_require_captcha_desc'],
693
			'min' => -1,
694
			'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;}'
695
		),
696
		'',
697
698
		// PM Settings
699
		'pm1' => array('int', 'max_pm_recipients', 'subtext' => $txt['max_pm_recipients_note']),
700
		'pm2' => array('int', 'pm_posts_verification', 'subtext' => $txt['pm_posts_verification_note']),
701
		'pm3' => array('int', 'pm_posts_per_hour', 'subtext' => $txt['pm_posts_per_hour_note']),
702
		// Visual verification.
703
		array('title', 'configure_verification_means'),
704
		array('desc', 'configure_verification_means_desc'),
705
		'vv' => array(
706
			'select',
707
			'visual_verification_type',
708
			array(
709
				$txt['setting_image_verification_off'],
710
				$txt['setting_image_verification_vsimple'],
711
				$txt['setting_image_verification_simple'],
712
				$txt['setting_image_verification_medium'],
713
				$txt['setting_image_verification_high'],
714
				$txt['setting_image_verification_extreme']
715
			),
716
			'subtext' => $txt['setting_visual_verification_type_desc'],
717
			'onchange' => $context['use_graphic_library'] ? 'refreshImages();' : ''
718
		),
719
		// reCAPTCHA
720
		array('title', 'recaptcha_configure'),
721
		array('desc', 'recaptcha_configure_desc', 'class' => 'windowbg'),
722
		array('check', 'recaptcha_enabled', 'subtext' => $txt['recaptcha_enable_desc']),
723
		array('text', 'recaptcha_site_key', 'subtext' => $txt['recaptcha_site_key_desc']),
724
		array('text', 'recaptcha_secret_key', 'subtext' => $txt['recaptcha_secret_key_desc']),
725
		array('select', 'recaptcha_theme', array('light' => $txt['recaptcha_theme_light'], 'dark' => $txt['recaptcha_theme_dark'])),
726
		// Clever Thomas, who is looking sheepy now? Not I, the mighty sword swinger did say.
727
		array('title', 'setup_verification_questions'),
728
		array('desc', 'setup_verification_questions_desc'),
729
		array('int', 'qa_verification_number', 'subtext' => $txt['setting_qa_verification_number_desc']),
730
		array('callback', 'question_answer_list'),
731
	);
732
733
	call_integration_hook('integrate_spam_settings', array(&$config_vars));
734
735
	if ($return_config)
736
		return $config_vars;
737
738
	// You need to be an admin to edit settings!
739
	isAllowedTo('admin_forum');
740
741
	// Firstly, figure out what languages we're dealing with, and do a little processing for the form's benefit.
742
	getLanguages();
743
	$context['qa_languages'] = array();
744
	foreach ($context['languages'] as $lang_id => $lang)
745
	{
746
		$lang_id = strtr($lang_id, array('-utf8' => ''));
747
		$lang['name'] = strtr($lang['name'], array('-utf8' => ''));
748
		$context['qa_languages'][$lang_id] = $lang;
749
	}
750
751
	// Secondly, load any questions we currently have.
752
	$context['question_answers'] = array();
753
	$request = $smcFunc['db_query']('', '
754
		SELECT id_question, lngfile, question, answers
755
		FROM {db_prefix}qanda'
756
	);
757
	while ($row = $smcFunc['db_fetch_assoc']($request))
758
	{
759
		$lang = strtr($row['lngfile'], array('-utf8' => ''));
760
		$context['question_answers'][$row['id_question']] = array(
761
			'lngfile' => $lang,
762
			'question' => $row['question'],
763
			'answers' => $smcFunc['json_decode']($row['answers'], true),
764
		);
765
		$context['qa_by_lang'][$lang][] = $row['id_question'];
766
	}
767
768
	if (empty($context['qa_by_lang'][strtr($language, array('-utf8' => ''))]) && !empty($context['question_answers']))
769
	{
770
		if (empty($context['settings_insert_above']))
771
			$context['settings_insert_above'] = '';
772
773
		$context['settings_insert_above'] .= '<div class="noticebox">' . sprintf($txt['question_not_defined'], $context['languages'][$language]['name']) . '</div>';
774
	}
775
776
	// Thirdly, push some JavaScript for the form to make it work.
777
	addInlineJavaScript('
778
	var nextrow = ' . (!empty($context['question_answers']) ? max(array_keys($context['question_answers'])) + 1 : 1) . ';
779
	$(".qa_link a").click(function() {
780
		var id = $(this).parent().attr("id").substring(6);
781
		$("#qa_fs_" + id).show();
782
		$(this).parent().hide();
783
	});
784
	$(".qa_fieldset legend a").click(function() {
785
		var id = $(this).closest("fieldset").attr("id").substring(6);
786
		$("#qa_dt_" + id).show();
787
		$(this).closest("fieldset").hide();
788
	});
789
	$(".qa_add_question a").click(function() {
790
		var id = $(this).closest("fieldset").attr("id").substring(6);
791
		$(\'<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());
792
		nextrow++;
793
	});
794
	$(".qa_fieldset ").on("click", ".qa_add_answer a", function() {
795
		var attr = $(this).closest("dd").find(".verification_answer:last").attr("name");
796
		$(\'<input type="text" name="\' + attr + \'" value="" size="50" class="verification_answer">\').insertBefore($(this).closest("div"));
797
		return false;
798
	});
799
	$("#qa_dt_' . strtr($language, array('-utf8' => '')) . ' a").click();', true);
800
801
	// Will need the utility functions from here.
802
	require_once($sourcedir . '/ManageServer.php');
803
804
	// Saving?
805
	if (isset($_GET['save']))
806
	{
807
		checkSession();
808
809
		// Fix PM settings.
810
		$_POST['pm_spam_settings'] = (int) $_POST['max_pm_recipients'] . ',' . (int) $_POST['pm_posts_verification'] . ',' . (int) $_POST['pm_posts_per_hour'];
811
812
		// Hack in guest requiring verification!
813
		if (empty($_POST['posts_require_captcha']) && !empty($_POST['guests_require_captcha']))
814
			$_POST['posts_require_captcha'] = -1;
815
816
		$save_vars = $config_vars;
817
		unset($save_vars['pm1'], $save_vars['pm2'], $save_vars['pm3'], $save_vars['guest_verify']);
818
819
		$save_vars[] = array('text', 'pm_spam_settings');
820
821
		// Handle verification questions.
822
		$changes = array(
823
			'insert' => array(),
824
			'replace' => array(),
825
			'delete' => array(),
826
		);
827
		$qs_per_lang = array();
828
		foreach ($context['qa_languages'] as $lang_id => $dummy)
829
		{
830
			// If we had some questions for this language before, but don't now, delete everything from that language.
831
			if ((!isset($_POST['question'][$lang_id]) || !is_array($_POST['question'][$lang_id])) && !empty($context['qa_by_lang'][$lang_id]))
832
				$changes['delete'] = array_merge($changes['delete'], $context['qa_by_lang'][$lang_id]);
833
834
			// Now step through and see if any existing questions no longer exist.
835
			if (!empty($context['qa_by_lang'][$lang_id]))
836
				foreach ($context['qa_by_lang'][$lang_id] as $q_id)
837
					if (empty($_POST['question'][$lang_id][$q_id]))
838
						$changes['delete'][] = $q_id;
839
840
			// Now let's see if there are new questions or ones that need updating.
841
			if (isset($_POST['question'][$lang_id]))
842
			{
843
				foreach ($_POST['question'][$lang_id] as $q_id => $question)
844
				{
845
					// Ignore junky ids.
846
					$q_id = (int) $q_id;
847
					if ($q_id <= 0)
848
						continue;
849
850
					// Check the question isn't empty (because they want to delete it?)
851
					if (empty($question) || trim($question) == '')
852
					{
853
						if (isset($context['question_answers'][$q_id]))
854
							$changes['delete'][] = $q_id;
855
						continue;
856
					}
857
					$question = $smcFunc['htmlspecialchars'](trim($question));
858
859
					// Get the answers. Firstly check there actually might be some.
860
					if (!isset($_POST['answer'][$lang_id][$q_id]) || !is_array($_POST['answer'][$lang_id][$q_id]))
861
					{
862
						if (isset($context['question_answers'][$q_id]))
863
							$changes['delete'][] = $q_id;
864
						continue;
865
					}
866
					// Now get them and check that they might be viable.
867
					$answers = array();
868
					foreach ($_POST['answer'][$lang_id][$q_id] as $answer)
869
						if (!empty($answer) && trim($answer) !== '')
870
							$answers[] = $smcFunc['htmlspecialchars'](trim($answer));
871
					if (empty($answers))
872
					{
873
						if (isset($context['question_answers'][$q_id]))
874
							$changes['delete'][] = $q_id;
875
						continue;
876
					}
877
					$answers = $smcFunc['json_encode']($answers);
878
879
					// At this point we know we have a question and some answers. What are we doing with it?
880
					if (!isset($context['question_answers'][$q_id]))
881
					{
882
						// New question. Now, we don't want to randomly consume ids, so we'll set those, rather than trusting the browser's supplied ids.
883
						$changes['insert'][] = array($lang_id, $question, $answers);
884
					}
885
					else
886
					{
887
						// It's an existing question. Let's see what's changed, if anything.
888
						if ($lang_id != $context['question_answers'][$q_id]['lngfile'] || $question != $context['question_answers'][$q_id]['question'] || $answers != $context['question_answers'][$q_id]['answers'])
889
							$changes['replace'][$q_id] = array('lngfile' => $lang_id, 'question' => $question, 'answers' => $answers);
890
					}
891
892
					if (!isset($qs_per_lang[$lang_id]))
893
						$qs_per_lang[$lang_id] = 0;
894
					$qs_per_lang[$lang_id]++;
895
				}
896
			}
897
		}
898
899
		// OK, so changes?
900
		if (!empty($changes['delete']))
901
		{
902
			$smcFunc['db_query']('', '
903
				DELETE FROM {db_prefix}qanda
904
				WHERE id_question IN ({array_int:questions})',
905
				array(
906
					'questions' => $changes['delete'],
907
				)
908
			);
909
		}
910
911
		if (!empty($changes['replace']))
912
		{
913
			foreach ($changes['replace'] as $q_id => $question)
914
			{
915
				$smcFunc['db_query']('', '
916
					UPDATE {db_prefix}qanda
917
					SET lngfile = {string:lngfile},
918
						question = {string:question},
919
						answers = {string:answers}
920
					WHERE id_question = {int:id_question}',
921
					array(
922
						'id_question' => $q_id,
923
						'lngfile' => $question['lngfile'],
924
						'question' => $question['question'],
925
						'answers' => $question['answers'],
926
					)
927
				);
928
			}
929
		}
930
931
		if (!empty($changes['insert']))
932
		{
933
			$smcFunc['db_insert']('insert',
934
				'{db_prefix}qanda',
935
				array('lngfile' => 'string-50', 'question' => 'string-255', 'answers' => 'string-65534'),
936
				$changes['insert'],
937
				array('id_question')
938
			);
939
		}
940
941
		// Lastly, the count of messages needs to be no more than the lowest number of questions for any one language.
942
		$count_questions = empty($qs_per_lang) ? 0 : min($qs_per_lang);
943
		if (empty($count_questions) || $_POST['qa_verification_number'] > $count_questions)
944
			$_POST['qa_verification_number'] = $count_questions;
945
946
		call_integration_hook('integrate_save_spam_settings', array(&$save_vars));
947
948
		// Now save.
949
		saveDBSettings($save_vars);
950
		$_SESSION['adm-save'] = true;
951
952
		cache_put_data('verificationQuestions', null, 300);
953
954
		redirectexit('action=admin;area=antispam');
955
	}
956
957
	$character_range = array_merge(range('A', 'H'), array('K', 'M', 'N', 'P', 'R'), range('T', 'Y'));
958
	$_SESSION['visual_verification_code'] = '';
959
	for ($i = 0; $i < 6; $i++)
960
		$_SESSION['visual_verification_code'] .= $character_range[array_rand($character_range)];
961
962
	// Some javascript for CAPTCHA.
963
	$context['settings_post_javascript'] = '';
964
	if ($context['use_graphic_library'])
965
		$context['settings_post_javascript'] .= '
966
		function refreshImages()
967
		{
968
			var imageType = document.getElementById(\'visual_verification_type\').value;
969
			document.getElementById(\'verification_image\').src = \'' . $context['verification_image_href'] . ';type=\' + imageType;
970
		}';
971
972
	// Show the image itself, or text saying we can't.
973
	if ($context['use_graphic_library'])
974
		$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>';
975
	else
976
		$config_vars['vv']['postinput'] = '<br><span class="smalltext">' . $txt['setting_image_verification_nogd'] . '</span>';
977
978
	// Hack for PM spam settings.
979
	list ($modSettings['max_pm_recipients'], $modSettings['pm_posts_verification'], $modSettings['pm_posts_per_hour']) = explode(',', $modSettings['pm_spam_settings']);
980
981
	// Hack for guests requiring verification.
982
	$modSettings['guests_require_captcha'] = !empty($modSettings['posts_require_captcha']);
983
	$modSettings['posts_require_captcha'] = !isset($modSettings['posts_require_captcha']) || $modSettings['posts_require_captcha'] == -1 ? 0 : $modSettings['posts_require_captcha'];
984
985
	// Some minor javascript for the guest post setting.
986
	if ($modSettings['posts_require_captcha'])
987
		$context['settings_post_javascript'] .= '
988
		document.getElementById(\'guests_require_captcha\').disabled = true;';
989
990
	// And everything else.
991
	$context['post_url'] = $scripturl . '?action=admin;area=antispam;save';
992
	$context['settings_title'] = $txt['antispam_Settings'];
993
	$context['page_title'] = $txt['antispam_title'];
994
	$context['sub_template'] = 'show_settings';
995
996
	$context[$context['admin_menu_name']]['tab_data'] = array(
997
		'title' => $txt['antispam_title'],
998
		'description' => $txt['antispam_Settings_desc'],
999
	);
1000
1001
	prepareDBSettingContext($config_vars);
1002
}
1003
1004
/**
1005
 * You'll never guess what this function does...
1006
 *
1007
 * @param bool $return_config Whether or not to return the config_vars array (used for admin search)
1008
 * @return void|array Returns nothing or returns the $config_vars array if $return_config is true
1009
 */
1010
function ModifySignatureSettings($return_config = false)
1011
{
1012
	global $context, $txt, $modSettings, $sig_start, $smcFunc, $scripturl;
1013
1014
	$config_vars = array(
1015
		// Are signatures even enabled?
1016
		array('check', 'signature_enable'),
1017
		'',
1018
1019
		// Tweaking settings!
1020
		array('int', 'signature_max_length', 'subtext' => $txt['zero_for_no_limit']),
1021
		array('int', 'signature_max_lines', 'subtext' => $txt['zero_for_no_limit']),
1022
		array('int', 'signature_max_font_size', 'subtext' => $txt['zero_for_no_limit']),
1023
		array('check', 'signature_allow_smileys', 'onclick' => 'document.getElementById(\'signature_max_smileys\').disabled = !this.checked;'),
1024
		array('int', 'signature_max_smileys', 'subtext' => $txt['zero_for_no_limit']),
1025
		'',
1026
1027
		// Image settings.
1028
		array('int', 'signature_max_images', 'subtext' => $txt['signature_max_images_note']),
1029
		array('int', 'signature_max_image_width', 'subtext' => $txt['zero_for_no_limit']),
1030
		array('int', 'signature_max_image_height', 'subtext' => $txt['zero_for_no_limit']),
1031
		'',
1032
1033
		array('bbc', 'signature_bbc'),
1034
	);
1035
1036
	call_integration_hook('integrate_signature_settings', array(&$config_vars));
1037
1038
	if ($return_config)
1039
		return $config_vars;
1040
1041
	// Setup the template.
1042
	$context['page_title'] = $txt['signature_settings'];
1043
	$context['sub_template'] = 'show_settings';
1044
1045
	// Disable the max smileys option if we don't allow smileys at all!
1046
	$context['settings_post_javascript'] = 'document.getElementById(\'signature_max_smileys\').disabled = !document.getElementById(\'signature_allow_smileys\').checked;';
1047
1048
	// Load all the signature settings.
1049
	list ($sig_limits, $sig_bbc) = explode(':', $modSettings['signature_settings']);
1050
	$sig_limits = explode(',', $sig_limits);
1051
	$disabledTags = !empty($sig_bbc) ? explode(',', $sig_bbc) : array();
1052
1053
	// Applying to ALL signatures?!!
1054
	if (isset($_GET['apply']))
1055
	{
1056
		// Security!
1057
		checkSession('get');
1058
1059
		$sig_start = time();
1060
		// This is horrid - but I suppose some people will want the option to do it.
1061
		$_GET['step'] = isset($_GET['step']) ? (int) $_GET['step'] : 0;
1062
		$done = false;
1063
1064
		$request = $smcFunc['db_query']('', '
1065
			SELECT MAX(id_member)
1066
			FROM {db_prefix}members',
1067
			array(
1068
			)
1069
		);
1070
		list ($context['max_member']) = $smcFunc['db_fetch_row']($request);
1071
		$smcFunc['db_free_result']($request);
1072
1073
		while (!$done)
1074
		{
1075
			$changes = array();
1076
1077
			$request = $smcFunc['db_query']('', '
1078
				SELECT id_member, signature
1079
				FROM {db_prefix}members
1080
				WHERE id_member BETWEEN {int:step} AND {int:step} + 49
1081
					AND id_group != {int:admin_group}
1082
					AND FIND_IN_SET({int:admin_group}, additional_groups) = 0',
1083
				array(
1084
					'admin_group' => 1,
1085
					'step' => $_GET['step'],
1086
				)
1087
			);
1088
			while ($row = $smcFunc['db_fetch_assoc']($request))
1089
			{
1090
				// Apply all the rules we can realistically do.
1091
				$sig = strtr($row['signature'], array('<br>' => "\n"));
1092
1093
				// Max characters...
1094
				if (!empty($sig_limits[1]))
1095
					$sig = $smcFunc['substr']($sig, 0, $sig_limits[1]);
1096
				// Max lines...
1097
				if (!empty($sig_limits[2]))
1098
				{
1099
					$count = 0;
1100
					for ($i = 0; $i < strlen($sig); $i++)
1101
					{
1102
						if ($sig[$i] == "\n")
1103
						{
1104
							$count++;
1105
							if ($count >= $sig_limits[2])
1106
								$sig = substr($sig, 0, $i) . strtr(substr($sig, $i), array("\n" => ' '));
1107
						}
1108
					}
1109
				}
1110
1111
				if (!empty($sig_limits[7]) && preg_match_all('~\[size=([\d\.]+)?(px|pt|em|x-large|larger)~i', $sig, $matches) !== false && isset($matches[2]))
1112
				{
1113
					foreach ($matches[1] as $ind => $size)
1114
					{
1115
						$limit_broke = 0;
1116
						// Attempt to allow all sizes of abuse, so to speak.
1117
						if ($matches[2][$ind] == 'px' && $size > $sig_limits[7])
1118
							$limit_broke = $sig_limits[7] . 'px';
1119
						elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75))
1120
							$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
1121
						elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16))
1122
							$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
1123
						elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18)
1124
							$limit_broke = 'large';
1125
1126
						if ($limit_broke)
1127
							$sig = str_replace($matches[0][$ind], '[size=' . $sig_limits[7] . 'px', $sig);
1128
					}
1129
				}
1130
1131
				// Stupid images - this is stupidly, stupidly challenging.
1132
				if ((!empty($sig_limits[3]) || !empty($sig_limits[5]) || !empty($sig_limits[6])))
1133
				{
1134
					$replaces = array();
1135
					$img_count = 0;
1136
					// Get all BBC tags...
1137
					preg_match_all('~\[img(\s+width=([\d]+))?(\s+height=([\d]+))?(\s+width=([\d]+))?\s*\](?:<br>)*([^<">]+?)(?:<br>)*\[/img\]~i', $sig, $matches);
1138
					// ... and all HTML ones.
1139
					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);
1140
					// And stick the HTML in the BBC.
1141
					if (!empty($matches2))
1142
					{
1143
						foreach ($matches2[0] as $ind => $dummy)
1144
						{
1145
							$matches[0][] = $matches2[0][$ind];
1146
							$matches[1][] = '';
1147
							$matches[2][] = '';
1148
							$matches[3][] = '';
1149
							$matches[4][] = '';
1150
							$matches[5][] = '';
1151
							$matches[6][] = '';
1152
							$matches[7][] = $matches2[1][$ind];
1153
						}
1154
					}
1155
					// Try to find all the images!
1156
					if (!empty($matches))
1157
					{
1158
						$image_count_holder = array();
1159
						foreach ($matches[0] as $key => $image)
1160
						{
1161
							$width = -1;
1162
							$height = -1;
1163
							$img_count++;
1164
							// Too many images?
1165
							if (!empty($sig_limits[3]) && $img_count > $sig_limits[3])
1166
							{
1167
								// If we've already had this before we only want to remove the excess.
1168
								if (isset($image_count_holder[$image]))
1169
								{
1170
									$img_offset = -1;
1171
									$rep_img_count = 0;
1172
									while ($img_offset !== false)
1173
									{
1174
										$img_offset = strpos($sig, $image, $img_offset + 1);
1175
										$rep_img_count++;
1176
										if ($rep_img_count > $image_count_holder[$image])
1177
										{
1178
											// Only replace the excess.
1179
											$sig = substr($sig, 0, $img_offset) . str_replace($image, '', substr($sig, $img_offset));
1180
											// Stop looping.
1181
											$img_offset = false;
1182
										}
1183
									}
1184
								}
1185
								else
1186
									$replaces[$image] = '';
1187
1188
								continue;
1189
							}
1190
1191
							// Does it have predefined restraints? Width first.
1192
							if ($matches[6][$key])
1193
								$matches[2][$key] = $matches[6][$key];
1194
							if ($matches[2][$key] && $sig_limits[5] && $matches[2][$key] > $sig_limits[5])
1195
							{
1196
								$width = $sig_limits[5];
1197
								$matches[4][$key] = $matches[4][$key] * ($width / $matches[2][$key]);
1198
							}
1199
							elseif ($matches[2][$key])
1200
								$width = $matches[2][$key];
1201
							// ... and height.
1202
							if ($matches[4][$key] && $sig_limits[6] && $matches[4][$key] > $sig_limits[6])
1203
							{
1204
								$height = $sig_limits[6];
1205
								if ($width != -1)
1206
									$width = $width * ($height / $matches[4][$key]);
1207
							}
1208
							elseif ($matches[4][$key])
1209
								$height = $matches[4][$key];
1210
1211
							// If the dimensions are still not fixed - we need to check the actual image.
1212
							if (($width == -1 && $sig_limits[5]) || ($height == -1 && $sig_limits[6]))
1213
							{
1214
								$sizes = url_image_size($matches[7][$key]);
1215
								if (is_array($sizes))
1216
								{
1217
									// Too wide?
1218
									if ($sizes[0] > $sig_limits[5] && $sig_limits[5])
1219
									{
1220
										$width = $sig_limits[5];
1221
										$sizes[1] = $sizes[1] * ($width / $sizes[0]);
1222
									}
1223
									// Too high?
1224
									if ($sizes[1] > $sig_limits[6] && $sig_limits[6])
1225
									{
1226
										$height = $sig_limits[6];
1227
										if ($width == -1)
1228
											$width = $sizes[0];
1229
										$width = $width * ($height / $sizes[1]);
1230
									}
1231
									elseif ($width != -1)
1232
										$height = $sizes[1];
1233
								}
1234
							}
1235
1236
							// Did we come up with some changes? If so remake the string.
1237
							if ($width != -1 || $height != -1)
1238
							{
1239
								$replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]';
1240
							}
1241
1242
							// Record that we got one.
1243
							$image_count_holder[$image] = isset($image_count_holder[$image]) ? $image_count_holder[$image] + 1 : 1;
1244
						}
1245
						if (!empty($replaces))
1246
							$sig = str_replace(array_keys($replaces), array_values($replaces), $sig);
1247
					}
1248
				}
1249
				// Try to fix disabled tags.
1250
				if (!empty($disabledTags))
1251
				{
1252
					$sig = preg_replace('~\[(?:' . implode('|', $disabledTags) . ').+?\]~i', '', $sig);
1253
					$sig = preg_replace('~\[/(?:' . implode('|', $disabledTags) . ')\]~i', '', $sig);
1254
				}
1255
1256
				$sig = strtr($sig, array("\n" => '<br>'));
1257
				call_integration_hook('integrate_apply_signature_settings', array(&$sig, $sig_limits, $disabledTags));
1258
				if ($sig != $row['signature'])
1259
					$changes[$row['id_member']] = $sig;
1260
			}
1261
			if ($smcFunc['db_num_rows']($request) == 0)
1262
				$done = true;
1263
			$smcFunc['db_free_result']($request);
1264
1265
			// Do we need to delete what we have?
1266
			if (!empty($changes))
1267
			{
1268
				foreach ($changes as $id => $sig)
1269
					$smcFunc['db_query']('', '
1270
						UPDATE {db_prefix}members
1271
						SET signature = {string:signature}
1272
						WHERE id_member = {int:id_member}',
1273
						array(
1274
							'id_member' => $id,
1275
							'signature' => $sig,
1276
						)
1277
					);
1278
			}
1279
1280
			$_GET['step'] += 50;
1281
			if (!$done)
1282
				pauseSignatureApplySettings();
1283
		}
1284
		$settings_applied = true;
1285
	}
1286
1287
	$context['signature_settings'] = array(
1288
		'enable' => isset($sig_limits[0]) ? $sig_limits[0] : 0,
1289
		'max_length' => isset($sig_limits[1]) ? $sig_limits[1] : 0,
1290
		'max_lines' => isset($sig_limits[2]) ? $sig_limits[2] : 0,
1291
		'max_images' => isset($sig_limits[3]) ? $sig_limits[3] : 0,
1292
		'allow_smileys' => isset($sig_limits[4]) && $sig_limits[4] == -1 ? 0 : 1,
1293
		'max_smileys' => isset($sig_limits[4]) && $sig_limits[4] != -1 ? $sig_limits[4] : 0,
1294
		'max_image_width' => isset($sig_limits[5]) ? $sig_limits[5] : 0,
1295
		'max_image_height' => isset($sig_limits[6]) ? $sig_limits[6] : 0,
1296
		'max_font_size' => isset($sig_limits[7]) ? $sig_limits[7] : 0,
1297
	);
1298
1299
	// Temporarily make each setting a modSetting!
1300
	foreach ($context['signature_settings'] as $key => $value)
1301
		$modSettings['signature_' . $key] = $value;
1302
1303
	// Make sure we check the right tags!
1304
	$modSettings['bbc_disabled_signature_bbc'] = $disabledTags;
1305
1306
	// Saving?
1307
	if (isset($_GET['save']))
1308
	{
1309
		checkSession();
1310
1311
		// Clean up the tag stuff!
1312
		$bbcTags = array();
1313
		foreach (parse_bbc(false) as $tag)
1314
			$bbcTags[] = $tag['tag'];
1315
1316
		if (!isset($_POST['signature_bbc_enabledTags']))
1317
			$_POST['signature_bbc_enabledTags'] = array();
1318
		elseif (!is_array($_POST['signature_bbc_enabledTags']))
1319
			$_POST['signature_bbc_enabledTags'] = array($_POST['signature_bbc_enabledTags']);
1320
1321
		$sig_limits = array();
1322
		foreach ($context['signature_settings'] as $key => $value)
1323
		{
1324
			if ($key == 'allow_smileys')
1325
				continue;
1326
			elseif ($key == 'max_smileys' && empty($_POST['signature_allow_smileys']))
1327
				$sig_limits[] = -1;
1328
			else
1329
				$sig_limits[] = !empty($_POST['signature_' . $key]) ? max(1, (int) $_POST['signature_' . $key]) : 0;
1330
		}
1331
1332
		call_integration_hook('integrate_save_signature_settings', array(&$sig_limits, &$bbcTags));
1333
1334
		$_POST['signature_settings'] = implode(',', $sig_limits) . ':' . implode(',', array_diff($bbcTags, $_POST['signature_bbc_enabledTags']));
1335
1336
		// Even though we have practically no settings let's keep the convention going!
1337
		$save_vars = array();
1338
		$save_vars[] = array('text', 'signature_settings');
1339
1340
		saveDBSettings($save_vars);
1341
		$_SESSION['adm-save'] = true;
1342
		redirectexit('action=admin;area=featuresettings;sa=sig');
1343
	}
1344
1345
	$context['post_url'] = $scripturl . '?action=admin;area=featuresettings;save;sa=sig';
1346
	$context['settings_title'] = $txt['signature_settings'];
1347
1348
	$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>';
1349
1350
	prepareDBSettingContext($config_vars);
1351
}
1352
1353
/**
1354
 * Just pause the signature applying thing.
1355
 */
1356
function pauseSignatureApplySettings()
1357
{
1358
	global $context, $txt, $sig_start;
1359
1360
	// Try get more time...
1361
	@set_time_limit(600);
1362
	if (function_exists('apache_reset_timeout'))
1363
		@apache_reset_timeout();
1364
1365
	// Have we exhausted all the time we allowed?
1366
	if (time() - array_sum(explode(' ', $sig_start)) < 3)
1367
		return;
1368
1369
	$context['continue_get_data'] = '?action=admin;area=featuresettings;sa=sig;apply;step=' . $_GET['step'] . ';' . $context['session_var'] . '=' . $context['session_id'];
1370
	$context['page_title'] = $txt['not_done_title'];
1371
	$context['continue_post_data'] = '';
1372
	$context['continue_countdown'] = '2';
1373
	$context['sub_template'] = 'not_done';
1374
1375
	// Specific stuff to not break this template!
1376
	$context[$context['admin_menu_name']]['current_subsection'] = 'sig';
1377
1378
	// Get the right percent.
1379
	$context['continue_percent'] = round(($_GET['step'] / $context['max_member']) * 100);
1380
1381
	// Never more than 100%!
1382
	$context['continue_percent'] = min($context['continue_percent'], 100);
1383
1384
	obExit();
1385
}
1386
1387
/**
1388
 * Show all the custom profile fields available to the user.
1389
 */
1390
function ShowCustomProfiles()
1391
{
1392
	global $txt, $scripturl, $context;
1393
	global $sourcedir;
1394
1395
	$context['page_title'] = $txt['custom_profile_title'];
1396
	$context['sub_template'] = 'show_custom_profile';
1397
1398
	// What about standard fields they can tweak?
1399
	$standard_fields = array('website', 'personal_text', 'timezone', 'posts', 'warning_status');
1400
	// What fields can't you put on the registration page?
1401
	$context['fields_no_registration'] = array('posts', 'warning_status');
1402
1403
	// Are we saving any standard field changes?
1404
	if (isset($_POST['save']))
1405
	{
1406
		checkSession();
1407
		validateToken('admin-scp');
1408
1409
		// Do the active ones first.
1410
		$disable_fields = array_flip($standard_fields);
1411
		if (!empty($_POST['active']))
1412
		{
1413
			foreach ($_POST['active'] as $value)
1414
				if (isset($disable_fields[$value]))
1415
					unset($disable_fields[$value]);
1416
		}
1417
		// What we have left!
1418
		$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...
1419
1420
		// Things we want to show on registration?
1421
		$reg_fields = array();
1422
		if (!empty($_POST['reg']))
1423
		{
1424
			foreach ($_POST['reg'] as $value)
1425
				if (in_array($value, $standard_fields) && !isset($disable_fields[$value]))
1426
					$reg_fields[] = $value;
1427
		}
1428
		// What we have left!
1429
		$changes['registration_fields'] = empty($reg_fields) ? '' : implode(',', $reg_fields);
1430
1431
		$_SESSION['adm-save'] = true;
1432
		if (!empty($changes))
1433
			updateSettings($changes);
1434
	}
1435
1436
	createToken('admin-scp');
1437
1438
	// Need to know the max order for custom fields
1439
	$context['custFieldsMaxOrder'] = custFieldsMaxOrder();
1440
1441
	require_once($sourcedir . '/Subs-List.php');
1442
1443
	$listOptions = array(
1444
		'id' => 'standard_profile_fields',
1445
		'title' => $txt['standard_profile_title'],
1446
		'base_href' => $scripturl . '?action=admin;area=featuresettings;sa=profile',
1447
		'get_items' => array(
1448
			'function' => 'list_getProfileFields',
1449
			'params' => array(
1450
				true,
1451
			),
1452
		),
1453
		'columns' => array(
1454
			'field' => array(
1455
				'header' => array(
1456
					'value' => $txt['standard_profile_field'],
1457
				),
1458
				'data' => array(
1459
					'db' => 'label',
1460
					'style' => 'width: 60%;',
1461
				),
1462
			),
1463
			'active' => array(
1464
				'header' => array(
1465
					'value' => $txt['custom_edit_active'],
1466
					'class' => 'centercol',
1467
				),
1468
				'data' => array(
1469
					'function' => function($rowData)
1470
					{
1471
						$isChecked = $rowData['disabled'] ? '' : ' checked';
1472
						$onClickHandler = $rowData['can_show_register'] ? sprintf(' onclick="document.getElementById(\'reg_%1$s\').disabled = !this.checked;"', $rowData['id']) : '';
1473
						return sprintf('<input type="checkbox" name="active[]" id="active_%1$s" value="%1$s" %2$s%3$s>', $rowData['id'], $isChecked, $onClickHandler);
1474
					},
1475
					'style' => 'width: 20%;',
1476
					'class' => 'centercol',
1477
				),
1478
			),
1479
			'show_on_registration' => array(
1480
				'header' => array(
1481
					'value' => $txt['custom_edit_registration'],
1482
					'class' => 'centercol',
1483
				),
1484
				'data' => array(
1485
					'function' => function($rowData)
1486
					{
1487
						$isChecked = $rowData['on_register'] && !$rowData['disabled'] ? ' checked' : '';
1488
						$isDisabled = $rowData['can_show_register'] ? '' : ' disabled';
1489
						return sprintf('<input type="checkbox" name="reg[]" id="reg_%1$s" value="%1$s" %2$s%3$s>', $rowData['id'], $isChecked, $isDisabled);
1490
					},
1491
					'style' => 'width: 20%;',
1492
					'class' => 'centercol',
1493
				),
1494
			),
1495
		),
1496
		'form' => array(
1497
			'href' => $scripturl . '?action=admin;area=featuresettings;sa=profile',
1498
			'name' => 'standardProfileFields',
1499
			'token' => 'admin-scp',
1500
		),
1501
		'additional_rows' => array(
1502
			array(
1503
				'position' => 'below_table_data',
1504
				'value' => '<input type="submit" name="save" value="' . $txt['save'] . '" class="button">',
1505
			),
1506
		),
1507
	);
1508
	createList($listOptions);
1509
1510
	$listOptions = array(
1511
		'id' => 'custom_profile_fields',
1512
		'title' => $txt['custom_profile_title'],
1513
		'base_href' => $scripturl . '?action=admin;area=featuresettings;sa=profile',
1514
		'default_sort_col' => 'field_order',
1515
		'no_items_label' => $txt['custom_profile_none'],
1516
		'items_per_page' => 25,
1517
		'get_items' => array(
1518
			'function' => 'list_getProfileFields',
1519
			'params' => array(
1520
				false,
1521
			),
1522
		),
1523
		'get_count' => array(
1524
			'function' => 'list_getProfileFieldSize',
1525
		),
1526
		'columns' => array(
1527
			'field_order' => array(
1528
				'header' => array(
1529
					'value' => $txt['custom_profile_fieldorder'],
1530
				),
1531
				'data' => array(
1532
					'function' => function($rowData) use ($context, $txt, $scripturl)
1533
					{
1534
						$return = '<p class="centertext bold_text">' . $rowData['field_order'] . '<br>';
1535
1536
						if ($rowData['field_order'] > 1)
1537
							$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>';
1538
1539
						if ($rowData['field_order'] < $context['custFieldsMaxOrder'])
1540
							$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>';
1541
1542
						$return .= '</p>';
1543
1544
						return $return;
1545
					},
1546
					'style' => 'width: 12%;',
1547
				),
1548
				'sort' => array(
1549
					'default' => 'field_order',
1550
					'reverse' => 'field_order DESC',
1551
				),
1552
			),
1553
			'field_name' => array(
1554
				'header' => array(
1555
					'value' => $txt['custom_profile_fieldname'],
1556
				),
1557
				'data' => array(
1558
					'function' => function($rowData) use ($scripturl)
1559
					{
1560
						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']);
1561
					},
1562
					'style' => 'width: 62%;',
1563
				),
1564
				'sort' => array(
1565
					'default' => 'field_name',
1566
					'reverse' => 'field_name DESC',
1567
				),
1568
			),
1569
			'field_type' => array(
1570
				'header' => array(
1571
					'value' => $txt['custom_profile_fieldtype'],
1572
				),
1573
				'data' => array(
1574
					'function' => function($rowData) use ($txt)
1575
					{
1576
						$textKey = sprintf('custom_profile_type_%1$s', $rowData['field_type']);
1577
						return isset($txt[$textKey]) ? $txt[$textKey] : $textKey;
1578
					},
1579
					'style' => 'width: 15%;',
1580
				),
1581
				'sort' => array(
1582
					'default' => 'field_type',
1583
					'reverse' => 'field_type DESC',
1584
				),
1585
			),
1586
			'active' => array(
1587
				'header' => array(
1588
					'value' => $txt['custom_profile_active'],
1589
				),
1590
				'data' => array(
1591
					'function' => function($rowData) use ($txt)
1592
					{
1593
						return $rowData['active'] ? $txt['yes'] : $txt['no'];
1594
					},
1595
					'style' => 'width: 8%;',
1596
				),
1597
				'sort' => array(
1598
					'default' => 'active DESC',
1599
					'reverse' => 'active',
1600
				),
1601
			),
1602
			'placement' => array(
1603
				'header' => array(
1604
					'value' => $txt['custom_profile_placement'],
1605
				),
1606
				'data' => array(
1607
					'function' => function($rowData)
1608
					{
1609
						global $txt, $context;
1610
1611
						return $txt['custom_profile_placement_' . (empty($rowData['placement']) ? 'standard' : $context['cust_profile_fields_placement'][$rowData['placement']])];
1612
					},
1613
					'style' => 'width: 8%;',
1614
				),
1615
				'sort' => array(
1616
					'default' => 'placement DESC',
1617
					'reverse' => 'placement',
1618
				),
1619
			),
1620
			'show_on_registration' => array(
1621
				'data' => array(
1622
					'sprintf' => array(
1623
						'format' => '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=%1$s">' . $txt['modify'] . '</a>',
1624
						'params' => array(
1625
							'id_field' => false,
1626
						),
1627
					),
1628
					'style' => 'width: 15%;',
1629
				),
1630
			),
1631
		),
1632
		'form' => array(
1633
			'href' => $scripturl . '?action=admin;area=featuresettings;sa=profileedit',
1634
			'name' => 'customProfileFields',
1635
		),
1636
		'additional_rows' => array(
1637
			array(
1638
				'position' => 'below_table_data',
1639
				'value' => '<input type="submit" name="new" value="' . $txt['custom_profile_make_new'] . '" class="button">',
1640
			),
1641
		),
1642
	);
1643
	createList($listOptions);
1644
1645
	// There are two different ways we could get to this point. To keep it simple, they both do
1646
	// the same basic thing.
1647
	if (isset($_SESSION['adm-save']))
1648
	{
1649
		$context['saved_successful'] = true;
1650
		unset ($_SESSION['adm-save']);
1651
	}
1652
}
1653
1654
/**
1655
 * Callback for createList().
1656
 *
1657
 * @param int $start The item to start with (used for pagination purposes)
1658
 * @param int $items_per_page The number of items to display per page
1659
 * @param string $sort A string indicating how to sort the results
1660
 * @param bool $standardFields Whether or not to include standard fields as well
1661
 * @return array An array of info about the various profile fields
1662
 */
1663
function list_getProfileFields($start, $items_per_page, $sort, $standardFields)
1664
{
1665
	global $txt, $modSettings, $smcFunc;
1666
1667
	$list = array();
1668
1669
	if ($standardFields)
1670
	{
1671
		$standard_fields = array('website', 'personal_text', 'timezone', 'posts', 'warning_status');
1672
		$fields_no_registration = array('posts', 'warning_status');
1673
		$disabled_fields = isset($modSettings['disabled_profile_fields']) ? explode(',', $modSettings['disabled_profile_fields']) : array();
1674
		$registration_fields = isset($modSettings['registration_fields']) ? explode(',', $modSettings['registration_fields']) : array();
1675
1676
		foreach ($standard_fields as $field)
1677
			$list[] = array(
1678
				'id' => $field,
1679
				'label' => isset($txt['standard_profile_field_' . $field]) ? $txt['standard_profile_field_' . $field] : (isset($txt[$field]) ? $txt[$field] : $field),
1680
				'disabled' => in_array($field, $disabled_fields),
1681
				'on_register' => in_array($field, $registration_fields) && !in_array($field, $fields_no_registration),
1682
				'can_show_register' => !in_array($field, $fields_no_registration),
1683
			);
1684
	}
1685
	else
1686
	{
1687
		// Load all the fields.
1688
		$request = $smcFunc['db_query']('', '
1689
			SELECT id_field, col_name, field_name, field_desc, field_type, field_order, active, placement
1690
			FROM {db_prefix}custom_fields
1691
			ORDER BY {raw:sort}
1692
			LIMIT {int:start}, {int:items_per_page}',
1693
			array(
1694
				'sort' => $sort,
1695
				'start' => $start,
1696
				'items_per_page' => $items_per_page,
1697
			)
1698
		);
1699
		while ($row = $smcFunc['db_fetch_assoc']($request))
1700
			$list[] = $row;
1701
		$smcFunc['db_free_result']($request);
1702
	}
1703
1704
	return $list;
1705
}
1706
1707
/**
1708
 * Callback for createList().
1709
 *
1710
 * @return int The total number of custom profile fields
1711
 */
1712
function list_getProfileFieldSize()
1713
{
1714
	global $smcFunc;
1715
1716
	$request = $smcFunc['db_query']('', '
1717
		SELECT COUNT(*)
1718
		FROM {db_prefix}custom_fields',
1719
		array(
1720
		)
1721
	);
1722
1723
	list ($numProfileFields) = $smcFunc['db_fetch_row']($request);
1724
	$smcFunc['db_free_result']($request);
1725
1726
	return $numProfileFields;
1727
}
1728
1729
/**
1730
 * Edit some profile fields?
1731
 */
1732
function EditCustomProfiles()
1733
{
1734
	global $txt, $scripturl, $context, $smcFunc;
1735
1736
	// Sort out the context!
1737
	$context['fid'] = isset($_GET['fid']) ? (int) $_GET['fid'] : 0;
1738
	$context[$context['admin_menu_name']]['current_subsection'] = 'profile';
1739
	$context['page_title'] = $context['fid'] ? $txt['custom_edit_title'] : $txt['custom_add_title'];
1740
	$context['sub_template'] = 'edit_profile_field';
1741
1742
	// Load the profile language for section names.
1743
	loadLanguage('Profile');
1744
1745
	// There's really only a few places we can go...
1746
	$move_to = array('up', 'down');
1747
1748
	// We need this for both moving and saving so put it right here.
1749
	$order_count = custFieldsMaxOrder();
1750
1751
	if ($context['fid'])
1752
	{
1753
		$request = $smcFunc['db_query']('', '
1754
			SELECT
1755
				id_field, col_name, field_name, field_desc, field_type, field_order, field_length, field_options,
1756
				show_reg, show_display, show_mlist, show_profile, private, active, default_value, can_search,
1757
				bbc, mask, enclose, placement
1758
			FROM {db_prefix}custom_fields
1759
			WHERE id_field = {int:current_field}',
1760
			array(
1761
				'current_field' => $context['fid'],
1762
			)
1763
		);
1764
		$context['field'] = array();
1765
		while ($row = $smcFunc['db_fetch_assoc']($request))
1766
		{
1767
			if ($row['field_type'] == 'textarea')
1768
				@list ($rows, $cols) = @explode(',', $row['default_value']);
1769
			else
1770
			{
1771
				$rows = 3;
1772
				$cols = 30;
1773
			}
1774
1775
			$context['field'] = array(
1776
				'name' => $row['field_name'],
1777
				'desc' => $row['field_desc'],
1778
				'col_name' => $row['col_name'],
1779
				'profile_area' => $row['show_profile'],
1780
				'reg' => $row['show_reg'],
1781
				'display' => $row['show_display'],
1782
				'mlist' => $row['show_mlist'],
1783
				'type' => $row['field_type'],
1784
				'order' => $row['field_order'],
1785
				'max_length' => $row['field_length'],
1786
				'rows' => $rows,
1787
				'cols' => $cols,
1788
				'bbc' => $row['bbc'] ? true : false,
1789
				'default_check' => $row['field_type'] == 'check' && $row['default_value'] ? true : false,
1790
				'default_select' => $row['field_type'] == 'select' || $row['field_type'] == 'radio' ? $row['default_value'] : '',
1791
				'options' => strlen($row['field_options']) > 1 ? explode(',', $row['field_options']) : array('', '', ''),
1792
				'active' => $row['active'],
1793
				'private' => $row['private'],
1794
				'can_search' => $row['can_search'],
1795
				'mask' => $row['mask'],
1796
				'regex' => substr($row['mask'], 0, 5) == 'regex' ? substr($row['mask'], 5) : '',
1797
				'enclose' => $row['enclose'],
1798
				'placement' => $row['placement'],
1799
			);
1800
		}
1801
		$smcFunc['db_free_result']($request);
1802
	}
1803
1804
	// Setup the default values as needed.
1805
	if (empty($context['field']))
1806
		$context['field'] = array(
1807
			'name' => '',
1808
			'col_name' => '???',
1809
			'desc' => '',
1810
			'profile_area' => 'forumprofile',
1811
			'reg' => false,
1812
			'display' => false,
1813
			'mlist' => false,
1814
			'type' => 'text',
1815
			'order' => 0,
1816
			'max_length' => 255,
1817
			'rows' => 4,
1818
			'cols' => 30,
1819
			'bbc' => false,
1820
			'default_check' => false,
1821
			'default_select' => '',
1822
			'options' => array('', '', ''),
1823
			'active' => true,
1824
			'private' => false,
1825
			'can_search' => false,
1826
			'mask' => 'nohtml',
1827
			'regex' => '',
1828
			'enclose' => '',
1829
			'placement' => 0,
1830
		);
1831
1832
	// Are we moving it?
1833
	if (isset($_GET['move']) && in_array($smcFunc['htmlspecialchars']($_GET['move']), $move_to))
1834
	{
1835
		// Down is the new up.
1836
		$new_order = ($_GET['move'] == 'up' ? ($context['field']['order'] - 1) : ($context['field']['order'] + 1));
1837
1838
		// Is this a valid position?
1839
		if ($new_order <= 0 || $new_order > $order_count)
1840
			redirectexit('action=admin;area=featuresettings;sa=profile'); // @todo implement an error handler
1841
1842
		// All good, proceed.
1843
		$smcFunc['db_query']('', '
1844
			UPDATE {db_prefix}custom_fields
1845
			SET field_order = {int:old_order}
1846
			WHERE field_order = {int:new_order}',
1847
			array(
1848
				'new_order' => $new_order,
1849
				'old_order' => $context['field']['order'],
1850
			)
1851
		);
1852
		$smcFunc['db_query']('', '
1853
			UPDATE {db_prefix}custom_fields
1854
			SET field_order = {int:new_order}
1855
			WHERE id_field = {int:id_field}',
1856
			array(
1857
				'new_order' => $new_order,
1858
				'id_field' => $context['fid'],
1859
			)
1860
		);
1861
		redirectexit('action=admin;area=featuresettings;sa=profile'); // @todo perhaps a nice confirmation message, dunno.
1862
	}
1863
1864
	// Are we saving?
1865
	if (isset($_POST['save']))
1866
	{
1867
		checkSession();
1868
		validateToken('admin-ecp');
1869
1870
		// Everyone needs a name - even the (bracket) unknown...
1871
		if (trim($_POST['field_name']) == '')
1872
			redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=need_name');
1873
1874
		// Regex you say?  Do a very basic test to see if the pattern is valid
1875
		if (!empty($_POST['regex']) && @preg_match($_POST['regex'], 'dummy') === false)
1876
			redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=regex_error');
1877
1878
		$_POST['field_name'] = $smcFunc['htmlspecialchars']($_POST['field_name']);
1879
		$_POST['field_desc'] = $smcFunc['htmlspecialchars']($_POST['field_desc']);
1880
1881
		// Checkboxes...
1882
		$show_reg = isset($_POST['reg']) ? (int) $_POST['reg'] : 0;
1883
		$show_display = isset($_POST['display']) ? 1 : 0;
1884
		$show_mlist = isset($_POST['mlist']) ? 1 : 0;
1885
		$bbc = isset($_POST['bbc']) ? 1 : 0;
1886
		$show_profile = $_POST['profile_area'];
1887
		$active = isset($_POST['active']) ? 1 : 0;
1888
		$private = isset($_POST['private']) ? (int) $_POST['private'] : 0;
1889
		$can_search = isset($_POST['can_search']) ? 1 : 0;
1890
1891
		// Some masking stuff...
1892
		$mask = isset($_POST['mask']) ? $_POST['mask'] : '';
1893
		if ($mask == 'regex' && isset($_POST['regex']))
1894
			$mask .= $_POST['regex'];
1895
1896
		$field_length = isset($_POST['max_length']) ? (int) $_POST['max_length'] : 255;
1897
		$enclose = isset($_POST['enclose']) ? $_POST['enclose'] : '';
1898
		$placement = isset($_POST['placement']) ? (int) $_POST['placement'] : 0;
1899
1900
		// Select options?
1901
		$field_options = '';
1902
		$newOptions = array();
1903
		$default = isset($_POST['default_check']) && $_POST['field_type'] == 'check' ? 1 : '';
1904
		if (!empty($_POST['select_option']) && ($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio'))
1905
		{
1906
			foreach ($_POST['select_option'] as $k => $v)
1907
			{
1908
				// Clean, clean, clean...
1909
				$v = $smcFunc['htmlspecialchars']($v);
1910
				$v = strtr($v, array(',' => ''));
1911
1912
				// Nada, zip, etc...
1913
				if (trim($v) == '')
1914
					continue;
1915
1916
				// Otherwise, save it boy.
1917
				$field_options .= $v . ',';
1918
				// This is just for working out what happened with old options...
1919
				$newOptions[$k] = $v;
1920
1921
				// Is it default?
1922
				if (isset($_POST['default_select']) && $_POST['default_select'] == $k)
1923
					$default = $v;
1924
			}
1925
			$field_options = substr($field_options, 0, -1);
1926
		}
1927
1928
		// Text area has default has dimensions
1929
		if ($_POST['field_type'] == 'textarea')
1930
			$default = (int) $_POST['rows'] . ',' . (int) $_POST['cols'];
1931
1932
		// Come up with the unique name?
1933
		if (empty($context['fid']))
1934
		{
1935
			$col_name = $smcFunc['substr'](strtr($_POST['field_name'], array(' ' => '')), 0, 6);
1936
			preg_match('~([\w\d_-]+)~', $col_name, $matches);
1937
1938
			// If there is nothing to the name, then let's start out own - for foreign languages etc.
1939
			if (isset($matches[1]))
1940
				$col_name = $initial_col_name = 'cust_' . strtolower($matches[1]);
1941
			else
1942
				$col_name = $initial_col_name = 'cust_' . mt_rand(1, 9999);
1943
1944
			// Make sure this is unique.
1945
			$current_fields = array();
1946
			$request = $smcFunc['db_query']('', '
1947
				SELECT id_field, col_name
1948
				FROM {db_prefix}custom_fields'
1949
			);
1950
			while ($row = $smcFunc['db_fetch_assoc']($request))
1951
				$current_fields[$row['id_field']] = $row['col_name'];
1952
1953
			$smcFunc['db_free_result']($request);
1954
1955
			$unique = false;
1956
			for ($i = 0; !$unique && $i < 9; $i++)
1957
			{
1958
				if (!in_array($col_name, $current_fields))
1959
					$unique = true;
1960
				else
1961
					$col_name = $initial_col_name . $i;
1962
			}
1963
1964
			// Still not a unique column name? Leave it up to the user, then.
1965
			if (!$unique)
1966
				fatal_lang_error('custom_option_not_unique');
1967
		}
1968
		// Work out what to do with the user data otherwise...
1969
		else
1970
		{
1971
			// Anything going to check or select is pointless keeping - as is anything coming from check!
1972
			if (($_POST['field_type'] == 'check' && $context['field']['type'] != 'check')
1973
				|| (($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio') && $context['field']['type'] != 'select' && $context['field']['type'] != 'radio')
1974
				|| ($context['field']['type'] == 'check' && $_POST['field_type'] != 'check'))
1975
			{
1976
				$smcFunc['db_query']('', '
1977
					DELETE FROM {db_prefix}themes
1978
					WHERE variable = {string:current_column}
1979
						AND id_member > {int:no_member}',
1980
					array(
1981
						'no_member' => 0,
1982
						'current_column' => $context['field']['col_name'],
1983
					)
1984
				);
1985
			}
1986
			// Otherwise - if the select is edited may need to adjust!
1987
			elseif ($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio')
1988
			{
1989
				$optionChanges = array();
1990
				$takenKeys = array();
1991
				// Work out what's changed!
1992
				foreach ($context['field']['options'] as $k => $option)
1993
				{
1994
					if (trim($option) == '')
1995
						continue;
1996
1997
					// Still exists?
1998
					if (in_array($option, $newOptions))
1999
					{
2000
						$takenKeys[] = $k;
2001
						continue;
2002
					}
2003
				}
2004
2005
				// Finally - have we renamed it - or is it really gone?
2006
				foreach ($optionChanges as $k => $option)
2007
				{
2008
					// Just been renamed?
2009
					if (!in_array($k, $takenKeys) && !empty($newOptions[$k]))
2010
						$smcFunc['db_query']('', '
2011
							UPDATE {db_prefix}themes
2012
							SET value = {string:new_value}
2013
							WHERE variable = {string:current_column}
2014
								AND value = {string:old_value}
2015
								AND id_member > {int:no_member}',
2016
							array(
2017
								'no_member' => 0,
2018
								'new_value' => $newOptions[$k],
2019
								'current_column' => $context['field']['col_name'],
2020
								'old_value' => $option,
2021
							)
2022
						);
2023
				}
2024
			}
2025
			// @todo Maybe we should adjust based on new text length limits?
2026
		}
2027
2028
		// Do the insertion/updates.
2029
		if ($context['fid'])
2030
		{
2031
			$smcFunc['db_query']('', '
2032
				UPDATE {db_prefix}custom_fields
2033
				SET
2034
					field_name = {string:field_name}, field_desc = {string:field_desc},
2035
					field_type = {string:field_type}, field_length = {int:field_length},
2036
					field_options = {string:field_options}, show_reg = {int:show_reg},
2037
					show_display = {int:show_display}, show_mlist = {int:show_mlist}, show_profile = {string:show_profile},
2038
					private = {int:private}, active = {int:active}, default_value = {string:default_value},
2039
					can_search = {int:can_search}, bbc = {int:bbc}, mask = {string:mask},
2040
					enclose = {string:enclose}, placement = {int:placement}
2041
				WHERE id_field = {int:current_field}',
2042
				array(
2043
					'field_length' => $field_length,
2044
					'show_reg' => $show_reg,
2045
					'show_display' => $show_display,
2046
					'show_mlist' => $show_mlist,
2047
					'private' => $private,
2048
					'active' => $active,
2049
					'can_search' => $can_search,
2050
					'bbc' => $bbc,
2051
					'current_field' => $context['fid'],
2052
					'field_name' => $_POST['field_name'],
2053
					'field_desc' => $_POST['field_desc'],
2054
					'field_type' => $_POST['field_type'],
2055
					'field_options' => $field_options,
2056
					'show_profile' => $show_profile,
2057
					'default_value' => $default,
2058
					'mask' => $mask,
2059
					'enclose' => $enclose,
2060
					'placement' => $placement,
2061
				)
2062
			);
2063
2064
			// Just clean up any old selects - these are a pain!
2065
			if (($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio') && !empty($newOptions))
2066
				$smcFunc['db_query']('', '
2067
					DELETE FROM {db_prefix}themes
2068
					WHERE variable = {string:current_column}
2069
						AND value NOT IN ({array_string:new_option_values})
2070
						AND id_member > {int:no_member}',
2071
					array(
2072
						'no_member' => 0,
2073
						'new_option_values' => $newOptions,
2074
						'current_column' => $context['field']['col_name'],
2075
					)
2076
				);
2077
		}
2078
		else
2079
		{
2080
			// Gotta figure it out the order.
2081
			$new_order = $order_count > 1 ? ($order_count + 1) : 1;
2082
2083
			$smcFunc['db_insert']('',
2084
				'{db_prefix}custom_fields',
2085
				array(
2086
					'col_name' => 'string', 'field_name' => 'string', 'field_desc' => 'string',
2087
					'field_type' => 'string', 'field_length' => 'string', 'field_options' => 'string', 'field_order' => 'int',
2088
					'show_reg' => 'int', 'show_display' => 'int', 'show_mlist' => 'int', 'show_profile' => 'string',
2089
					'private' => 'int', 'active' => 'int', 'default_value' => 'string', 'can_search' => 'int',
2090
					'bbc' => 'int', 'mask' => 'string', 'enclose' => 'string', 'placement' => 'int',
2091
				),
2092
				array(
2093
					$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...
2094
					$_POST['field_type'], $field_length, $field_options, $new_order,
2095
					$show_reg, $show_display, $show_mlist, $show_profile,
2096
					$private, $active, $default, $can_search,
2097
					$bbc, $mask, $enclose, $placement,
2098
				),
2099
				array('id_field')
2100
			);
2101
		}
2102
	}
2103
	// Deleting?
2104
	elseif (isset($_POST['delete']) && $context['field']['col_name'])
2105
	{
2106
		checkSession();
2107
		validateToken('admin-ecp');
2108
2109
		// Delete the user data first.
2110
		$smcFunc['db_query']('', '
2111
			DELETE FROM {db_prefix}themes
2112
			WHERE variable = {string:current_column}
2113
				AND id_member > {int:no_member}',
2114
			array(
2115
				'no_member' => 0,
2116
				'current_column' => $context['field']['col_name'],
2117
			)
2118
		);
2119
		// Finally - the field itself is gone!
2120
		$smcFunc['db_query']('', '
2121
			DELETE FROM {db_prefix}custom_fields
2122
			WHERE id_field = {int:current_field}',
2123
			array(
2124
				'current_field' => $context['fid'],
2125
			)
2126
		);
2127
2128
		// Re-arrange the order.
2129
		$smcFunc['db_query']('', '
2130
			UPDATE {db_prefix}custom_fields
2131
			SET field_order = field_order - 1
2132
			WHERE field_order > {int:current_order}',
2133
			array(
2134
				'current_order' => $context['field']['order'],
2135
			)
2136
		);
2137
	}
2138
2139
	// Rebuild display cache etc.
2140
	if (isset($_POST['delete']) || isset($_POST['save']))
2141
	{
2142
		checkSession();
2143
2144
		$request = $smcFunc['db_query']('', '
2145
			SELECT col_name, field_name, field_type, field_order, bbc, enclose, placement, show_mlist, field_options
2146
			FROM {db_prefix}custom_fields
2147
			WHERE show_display = {int:is_displayed}
2148
				AND active = {int:active}
2149
				AND private != {int:not_owner_only}
2150
				AND private != {int:not_admin_only}
2151
			ORDER BY field_order',
2152
			array(
2153
				'is_displayed' => 1,
2154
				'active' => 1,
2155
				'not_owner_only' => 2,
2156
				'not_admin_only' => 3,
2157
			)
2158
		);
2159
2160
		$fields = array();
2161
		while ($row = $smcFunc['db_fetch_assoc']($request))
2162
		{
2163
			$fields[] = array(
2164
				'col_name' => strtr($row['col_name'], array('|' => '', ';' => '')),
2165
				'title' => strtr($row['field_name'], array('|' => '', ';' => '')),
2166
				'type' => $row['field_type'],
2167
				'order' => $row['field_order'],
2168
				'bbc' => $row['bbc'] ? '1' : '0',
2169
				'placement' => !empty($row['placement']) ? $row['placement'] : '0',
2170
				'enclose' => !empty($row['enclose']) ? $row['enclose'] : '',
2171
				'mlist' => $row['show_mlist'],
2172
				'options' => (!empty($row['field_options']) ? explode(',', $row['field_options']) : array()),
2173
			);
2174
		}
2175
		$smcFunc['db_free_result']($request);
2176
2177
		updateSettings(array('displayFields' => $smcFunc['json_encode']($fields)));
2178
		$_SESSION['adm-save'] = true;
2179
		redirectexit('action=admin;area=featuresettings;sa=profile');
2180
	}
2181
2182
	createToken('admin-ecp');
2183
}
2184
2185
/**
2186
 * Returns the maximum field_order value for the custom fields
2187
 *
2188
 * @return int The maximum value of field_order from the custom_fields table
2189
 */
2190
function custFieldsMaxOrder()
2191
{
2192
	global $smcFunc;
2193
2194
	// Gotta know the order limit
2195
	$result = $smcFunc['db_query']('', '
2196
		SELECT MAX(field_order)
2197
		FROM {db_prefix}custom_fields',
2198
		array()
2199
	);
2200
2201
	list ($order_count) = $smcFunc['db_fetch_row']($result);
2202
	$smcFunc['db_free_result']($result);
2203
2204
	return (int) $order_count;
2205
}
2206
2207
/**
2208
 * Allow to edit the settings on the pruning screen.
2209
 *
2210
 * @param bool $return_config Whether or not to return the config_vars array (used for admin search)
2211
 * @return void|array Returns nothing or returns the $config_vars array if $return_config is true
2212
 */
2213
function ModifyLogSettings($return_config = false)
2214
{
2215
	global $txt, $scripturl, $sourcedir, $context, $modSettings;
2216
2217
	// Make sure we understand what's going on.
2218
	loadLanguage('ManageSettings');
2219
2220
	$context['page_title'] = $txt['log_settings'];
2221
2222
	$config_vars = array(
2223
		array('check', 'modlog_enabled', 'help' => 'modlog'),
2224
		array('check', 'adminlog_enabled', 'help' => 'adminlog'),
2225
		array('check', 'userlog_enabled', 'help' => 'userlog'),
2226
		// The error log is a wonderful thing.
2227
		array('title', 'errorlog'),
2228
		array('desc', 'error_log_desc'),
2229
		array('check', 'enableErrorLogging'),
2230
		array('check', 'enableErrorQueryLogging'),
2231
		// Even do the pruning?
2232
		array('title', 'pruning_title'),
2233
		array('desc', 'pruning_desc'),
2234
		// The array indexes are there so we can remove/change them before saving.
2235
		'pruningOptions' => array('check', 'pruningOptions'),
2236
		'',
2237
2238
		// Various logs that could be pruned.
2239
		array('int', 'pruneErrorLog', 'postinput' => $txt['days_word'], 'subtext' => $txt['zero_to_disable']), // Error log.
2240
		array('int', 'pruneModLog', 'postinput' => $txt['days_word'], 'subtext' => $txt['zero_to_disable']), // Moderation log.
2241
		array('int', 'pruneBanLog', 'postinput' => $txt['days_word'], 'subtext' => $txt['zero_to_disable']), // Ban hit log.
2242
		array('int', 'pruneReportLog', 'postinput' => $txt['days_word'], 'subtext' => $txt['zero_to_disable']), // Report to moderator log.
2243
		array('int', 'pruneScheduledTaskLog', 'postinput' => $txt['days_word'], 'subtext' => $txt['zero_to_disable']), // Log of the scheduled tasks and how long they ran.
2244
		array('int', 'pruneSpiderHitLog', 'postinput' => $txt['days_word'], 'subtext' => $txt['zero_to_disable']), // Log of the scheduled tasks and how long they ran.
2245
		// 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.
2246
		// Mod Developers: Do NOT use the pruningOptions master variable for this as SMF Core may overwrite your setting in the future!
2247
	);
2248
2249
	// 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.
2250
	$prune_toggle = array('pruneErrorLog', 'pruneModLog', 'pruneBanLog', 'pruneReportLog', 'pruneScheduledTaskLog', 'pruneSpiderHitLog');
2251
2252
	call_integration_hook('integrate_prune_settings', array(&$config_vars, &$prune_toggle, false));
2253
2254
	$prune_toggle_dt = array();
2255
	foreach ($prune_toggle as $item)
2256
		$prune_toggle_dt[] = 'setting_' . $item;
2257
2258
	if ($return_config)
2259
		return $config_vars;
2260
2261
	addInlineJavaScript('
2262
	function togglePruned()
2263
	{
2264
		var newval = $("#pruningOptions").prop("checked");
2265
		$("#' . implode(', #', $prune_toggle) . '").closest("dd").toggle(newval);
2266
		$("#' . implode(', #', $prune_toggle_dt) . '").closest("dt").toggle(newval);
2267
	};
2268
	togglePruned();
2269
	$("#pruningOptions").click(function() { togglePruned(); });', true);
2270
2271
	// We'll need this in a bit.
2272
	require_once($sourcedir . '/ManageServer.php');
2273
2274
	// Saving?
2275
	if (isset($_GET['save']))
2276
	{
2277
		checkSession();
2278
2279
		// Because of the excitement attached to combining pruning log items, we need to duplicate everything here.
2280
		$savevar = array(
2281
			array('check', 'modlog_enabled'),
2282
			array('check', 'adminlog_enabled'),
2283
			array('check', 'userlog_enabled'),
2284
			array('check', 'enableErrorLogging'),
2285
			array('check', 'enableErrorQueryLogging'),
2286
			array('text', 'pruningOptions')
2287
		);
2288
2289
		call_integration_hook('integrate_prune_settings', array(&$savevar, &$prune_toggle, true));
2290
2291
		if (!empty($_POST['pruningOptions']))
2292
		{
2293
			$vals = array();
2294
			foreach ($config_vars as $index => $dummy)
2295
			{
2296
				if (!is_array($dummy) || $index == 'pruningOptions' || !in_array($dummy[1], $prune_toggle))
2297
					continue;
2298
2299
				$vals[] = empty($_POST[$dummy[1]]) || $_POST[$dummy[1]] < 0 ? 0 : (int) $_POST[$dummy[1]];
2300
			}
2301
			$_POST['pruningOptions'] = implode(',', $vals);
2302
		}
2303
		else
2304
			$_POST['pruningOptions'] = '';
2305
2306
		saveDBSettings($savevar);
2307
		$_SESSION['adm-save'] = true;
2308
		redirectexit('action=admin;area=logs;sa=settings');
2309
	}
2310
2311
	$context['post_url'] = $scripturl . '?action=admin;area=logs;save;sa=settings';
2312
	$context['settings_title'] = $txt['log_settings'];
2313
	$context['sub_template'] = 'show_settings';
2314
2315
	// Get the actual values
2316
	if (!empty($modSettings['pruningOptions']))
2317
		@list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
2318
	else
2319
		$modSettings['pruneErrorLog'] = $modSettings['pruneModLog'] = $modSettings['pruneBanLog'] = $modSettings['pruneReportLog'] = $modSettings['pruneScheduledTaskLog'] = $modSettings['pruneSpiderHitLog'] = 0;
2320
2321
	prepareDBSettingContext($config_vars);
2322
}
2323
2324
/**
2325
 * If you have a general mod setting to add stick it here.
2326
 *
2327
 * @param bool $return_config Whether or not to return the config_vars array (used for admin search)
2328
 * @return void|array Returns nothing or returns the $config_vars array if $return_config is true
2329
 */
2330
function ModifyGeneralModSettings($return_config = false)
2331
{
2332
	global $txt, $scripturl, $context;
2333
2334
	$config_vars = array(
2335
		// Mod authors, add any settings UNDER this line. Include a comma at the end of the line and don't remove this statement!!
2336
	);
2337
2338
	// Make it even easier to add new settings.
2339
	call_integration_hook('integrate_general_mod_settings', array(&$config_vars));
2340
2341
	if ($return_config)
2342
		return $config_vars;
2343
2344
	$context['post_url'] = $scripturl . '?action=admin;area=modsettings;save;sa=general';
2345
	$context['settings_title'] = $txt['mods_cat_modifications_misc'];
2346
2347
	// No removing this line you, dirty unwashed mod authors. :p
2348
	if (empty($config_vars))
2349
	{
2350
		$context['settings_save_dont_show'] = true;
2351
		$context['settings_message'] = '<div class="centertext">' . $txt['modification_no_misc_settings'] . '</div>';
2352
2353
		return prepareDBSettingContext($config_vars);
0 ignored issues
show
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...
2354
	}
2355
2356
	// Saving?
2357
	if (isset($_GET['save']))
2358
	{
2359
		checkSession();
2360
2361
		$save_vars = $config_vars;
2362
2363
		call_integration_hook('integrate_save_general_mod_settings', array(&$save_vars));
2364
2365
		// This line is to help mod authors do a search/add after if you want to add something here. Keyword: FOOT TAPPING SUCKS!
2366
		saveDBSettings($save_vars);
2367
2368
		// This line is to remind mod authors that it's nice to let the users know when something has been saved.
2369
		$_SESSION['adm-save'] = true;
2370
2371
		// This line is to help mod authors do a search/add after if you want to add something here. Keyword: I LOVE TEA!
2372
		redirectexit('action=admin;area=modsettings;sa=general');
2373
	}
2374
2375
	// 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!
2376
	prepareDBSettingContext($config_vars);
2377
}
2378
2379
/**
2380
 * Handles modifying the alerts settings
2381
 */
2382
function ModifyAlertsSettings()
2383
{
2384
	global $context, $modSettings, $sourcedir, $txt;
2385
2386
	// Dummy settings for the template...
2387
	$modSettings['allow_disableAnnounce'] = false;
2388
	$context['user']['is_owner'] = false;
2389
	$context['member'] = array();
2390
	$context['id_member'] = 0;
2391
	$context['menu_item_selected'] = 'alerts';
2392
	$context['token_check'] = 'noti-admin';
2393
2394
	// Specify our action since we'll want to post back here instead of the profile
2395
	$context['action'] = 'action=admin;area=featuresettings;sa=alerts;' . $context['session_var'] . '=' . $context['session_id'];
2396
2397
	loadTemplate('Profile');
2398
	loadLanguage('Profile');
2399
2400
	include_once($sourcedir . '/Profile-Modify.php');
2401
	alert_configuration(0);
2402
2403
	$context['page_title'] = $txt['notify_settings'];
2404
2405
	// Override the description
2406
	$context['description'] = $txt['notifications_desc'];
2407
	$context['sub_template'] = 'alert_configuration';
2408
}
2409
2410
?>