Issues (1061)

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