Completed
Branch development (176841)
by Elk
06:59
created

ManageFeatures::action_layoutSettings_display()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 41

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
cc 5
nc 4
nop 0
dl 0
loc 41
ccs 0
cts 20
cp 0
crap 30
rs 8.9528
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Manage features and options administration page.
5
 *
6
 * @package   ElkArte Forum
7
 * @copyright ElkArte Forum contributors
8
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause (see accompanying LICENSE.txt file)
9
 *
10
 * This file contains code covered by:
11
 * copyright:	2011 Simple Machines (http://www.simplemachines.org)
12
 *
13
 * @version 2.0 dev
14
 *
15
 */
16
17
namespace ElkArte\AdminController;
18
19
/**
20
 * Manage features and options administration page.
21
 *
22
 * This controller handles the pages which allow the admin
23
 * to see and change the basic feature settings of their site.
24
 */
25
class ManageFeatures extends \ElkArte\AbstractController
26
{
27
	/**
28
	 * Pre Dispatch, called before other methods.
29
	 */
30 2
	public function pre_dispatch()
31
	{
32
		// We need this in few places so it's easier to have it loaded here
33 2
		require_once(SUBSDIR . '/ManageFeatures.subs.php');
34 2
	}
35
36
	/**
37
	 * This function passes control through to the relevant tab.
38
	 *
39
	 * @event integrate_sa_modify_features Use to add new Configuration tabs
40
	 * @see \ElkArte\AbstractController::action_index()
41
	 * @uses Help, ManageSettings languages
42
	 * @uses sub_template show_settings
43
	 */
44
	public function action_index()
45
	{
46
		global $context, $txt, $settings;
47
48
		// Often Helpful
49
		theme()->getTemplates()->loadLanguageFile('Help');
50
		theme()->getTemplates()->loadLanguageFile('ManageSettings');
51
		theme()->getTemplates()->loadLanguageFile('Mentions');
52
53
		// All the actions we know about
54
		$subActions = array(
55
			'basic' => array(
56
				'controller' => $this,
57
				'function' => 'action_basicSettings_display',
58
				'permission' => 'admin_forum'
59
			),
60
			'layout' => array(
61
				'controller' => $this,
62
				'function' => 'action_layoutSettings_display',
63
				'permission' => 'admin_forum'
64
			),
65
			'karma' => array(
66
				'controller' => $this,
67
				'function' => 'action_karmaSettings_display',
68
				'enabled' => featureEnabled('k'),
69
				'permission' => 'admin_forum'
70
			),
71
			'pmsettings' => array(
72
				'controller' => $this,
73
				'function' => 'action_pmsettings',
74
				'permission' => 'admin_forum'
75
			),
76
			'likes' => array(
77
				'controller' => $this,
78
				'function' => 'action_likesSettings_display',
79
				'enabled' => featureEnabled('l'),
80
				'permission' => 'admin_forum'
81
			),
82
			'mention' => array(
83
				'controller' => $this,
84
				'function' => 'action_notificationsSettings_display',
85
				'permission' => 'admin_forum'
86
			),
87
			'sig' => array(
88
				'controller' => $this,
89
				'function' => 'action_signatureSettings_display',
90
				'permission' => 'admin_forum'
91
			),
92
			'profile' => array(
93
				'controller' => $this,
94
				'function' => 'action_profile',
95
				'enabled' => featureEnabled('cp'),
96
				'permission' => 'admin_forum'
97
			),
98
			'profileedit' => array(
99
				'controller' => $this,
100
				'function' => 'action_profileedit',
101
				'permission' => 'admin_forum'
102
			),
103
		);
104
105
		// Set up the action control
106
		$action = new \ElkArte\Action('modify_features');
107
108
		// Load up all the tabs...
109
		$context[$context['admin_menu_name']]['tab_data'] = array(
110
			'title' => $txt['modSettings_title'],
111
			'help' => 'featuresettings',
112
			'description' => sprintf($txt['modSettings_desc'], getUrl('admin', ['action' => 'admin', 'area' => 'theme', 'sa' => 'list', 'th' => $settings['theme_id'], '{session_data}'])),
113
			'tabs' => array(
114
				'basic' => array(
115
				),
116
				'layout' => array(
117
				),
118
				'pmsettings' => array(
119
				),
120
				'karma' => array(
121
				),
122
				'likes' => array(
123
				),
124
				'mention' => array(
125
					'description' => $txt['mentions_settings_desc'],
126
				),
127
				'sig' => array(
128
					'description' => $txt['signature_settings_desc'],
129
				),
130
				'profile' => array(
131
					'description' => $txt['custom_profile_desc'],
132
				),
133
			),
134
		);
135
136
		// By default do the basic settings, call integrate_sa_modify_features
137
		$subAction = $action->initialize($subActions, 'basic');
138
139
		// Some final pieces for the template
140
		$context['sub_template'] = 'show_settings';
141
		$context['sub_action'] = $subAction;
142
		$context['page_title'] = $txt['modSettings_title'];
143
144
		// Call the right function for this sub-action.
145
		$action->dispatch($subAction);
146
	}
147
148
	/**
149
	 * Config array for changing the basic forum settings
150
	 *
151
	 * - Accessed from ?action=admin;area=featuresettings;sa=basic;
152
	 *
153
	 * @event integrate_save_basic_settings
154
	 */
155
	public function action_basicSettings_display()
156
	{
157
		global $txt, $context;
158
159
		// Initialize the form
160
		$settingsForm = new \ElkArte\SettingsForm\SettingsForm(\ElkArte\SettingsForm\SettingsForm::DB_ADAPTER);
161
162
		// Initialize it with our settings
163
		$settingsForm->setConfigVars($this->_basicSettings());
164
165
		// Saving?
166
		if (isset($this->_req->query->save))
167
		{
168
			checkSession();
169
170
			// Prevent absurd boundaries here - make it a day tops.
171
			if (isset($this->_req->post->lastActive))
172
				$this->_req->post->lastActive = min((int) $this->_req->post->lastActive, 1440);
173
174
			call_integration_hook('integrate_save_basic_settings');
175
176
			$settingsForm->setConfigValues((array) $this->_req->post);
177
			$settingsForm->save();
178
179
			writeLog();
180
			redirectexit('action=admin;area=featuresettings;sa=basic');
181
		}
182
		if (isset($this->_req->post->cleanhives))
183
		{
184
			$clean_hives_result = theme()->cleanHives();
185
186
			theme()->getLayers()->removeAll();
187
			theme()->getTemplates()->load('Json');
188
			theme()->addJavascriptVar(array('txt_invalid_response' => $txt['ajax_bad_response']), true);
189
			$context['sub_template'] = 'send_json';
190
			$context['json_data'] = array(
191
				'success' => $clean_hives_result,
192
				'response' => $clean_hives_result ? $txt['clean_hives_sucess'] : $txt['clean_hives_failed']
193
			);
194
			return;
195
		}
196
197
		$context['post_url'] = getUrl('admin', ['action' => 'admin', 'area' => 'featuresettings', 'sa' => 'basic', 'save']);
198
		$context['settings_title'] = $txt['mods_cat_features'];
199
200
		// Show / hide custom jquery fields as required
201
		theme()->addInlineJavascript('showhideJqueryOptions();', true);
202
203
		$settingsForm->prepare();
204
	}
205
206
	/**
207
	 * Allows modifying the global layout settings in the forum
208
	 *
209
	 * - Accessed through ?action=admin;area=featuresettings;sa=layout;
210
	 *
211
	 * @event integrate_save_layout_settings
212
	 */
213
	public function action_layoutSettings_display()
214
	{
215
		global $txt, $context, $modSettings;
216
217
		// Initialize the form
218
		$settingsForm = new \ElkArte\SettingsForm\SettingsForm(\ElkArte\SettingsForm\SettingsForm::DB_ADAPTER);
219
220
		// Initialize it with our settings
221
		$settingsForm->setConfigVars($this->_layoutSettings());
222
223
		// Saving?
224
		if (isset($this->_req->query->save))
225
		{
226
			// Setting a custom frontpage, set the hook to the FrontpageInterface of the controller
227
			if (!empty($this->_req->post->front_page))
228
			{
229
				$front_page = (string) $this->_req->post->front_page;
230
				if (
231
					is_callable(array($modSettings['front_page'], 'validateFrontPageOptions'))
232
					&& !$front_page::validateFrontPageOptions($this->_req->post)
233
				) {
234
					$this->_req->post->front_page = '';
235
				}
236
			}
237
238
			checkSession();
239
240
			call_integration_hook('integrate_save_layout_settings');
241
242
			$settingsForm->setConfigValues((array) $this->_req->post);
243
			$settingsForm->save();
244
			writeLog();
245
246
			redirectexit('action=admin;area=featuresettings;sa=layout');
247
		}
248
249
		$context['post_url'] = getUrl('admin', ['action' => 'admin', 'area' => 'featuresettings', 'sa' => 'layout', 'save']);
250
		$context['settings_title'] = $txt['mods_cat_layout'];
251
252
		$settingsForm->prepare();
253
	}
254
255
	/**
256
	 * Display configuration settings page for karma settings.
257
	 *
258
	 * - Accessed from ?action=admin;area=featuresettings;sa=karma;
259
	 *
260
	 * @event integrate_save_karma_settings
261
	 */
262 View Code Duplication
	public function action_karmaSettings_display()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
263
	{
264
		global $txt, $context;
265
266
		// Initialize the form
267
		$settingsForm = new \ElkArte\SettingsForm\SettingsForm(\ElkArte\SettingsForm\SettingsForm::DB_ADAPTER);
268
269
		// Initialize it with our settings
270
		$settingsForm->setConfigVars($this->_karmaSettings());
271
272
		// Saving?
273
		if (isset($this->_req->query->save))
274
		{
275
			checkSession();
276
277
			call_integration_hook('integrate_save_karma_settings');
278
279
			$settingsForm->setConfigValues((array) $this->_req->post);
280
			$settingsForm->save();
281
			redirectexit('action=admin;area=featuresettings;sa=karma');
282
		}
283
284
		$context['post_url'] = getUrl('admin', ['action' => 'admin', 'area' => 'featuresettings', 'sa' => 'karm', 'save']);
285
		$context['settings_title'] = $txt['karma'];
286
287
		$settingsForm->prepare();
288
	}
289
290
	/**
291
	 * Display configuration settings page for likes settings.
292
	 *
293
	 * - Accessed from ?action=admin;area=featuresettings;sa=likes;
294
	 *
295
	 * @event integrate_save_likes_settings
296
	 */
297 View Code Duplication
	public function action_likesSettings_display()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
298
	{
299
		global $txt, $context;
300
301
		// Initialize the form
302
		$settingsForm = new \ElkArte\SettingsForm\SettingsForm(\ElkArte\SettingsForm\SettingsForm::DB_ADAPTER);
303
304
		// Initialize it with our settings
305
		$settingsForm->setConfigVars($this->_likesSettings());
306
307
		// Saving?
308
		if (isset($this->_req->query->save))
309
		{
310
			checkSession();
311
312
			call_integration_hook('integrate_save_likes_settings');
313
314
			$settingsForm->setConfigValues((array) $this->_req->post);
315
			$settingsForm->save();
316
			redirectexit('action=admin;area=featuresettings;sa=likes');
317
		}
318
319
		$context['post_url'] = getUrl('admin', ['action' => 'admin', 'area' => 'featuresettings', 'sa' => 'likes', 'save']);
320
		$context['settings_title'] = $txt['likes'];
321
322
		$settingsForm->prepare();
323
	}
324
325
	/**
326
	 * Initializes the mentions settings admin page.
327
	 *
328
	 * - Accessed from ?action=admin;area=featuresettings;sa=mention;
329
	 *
330
	 * @event integrate_save_modify_mention_settings
331
	 */
332
	public function action_notificationsSettings_display()
333
	{
334
		global $txt, $context, $modSettings;
335
336
		theme()->getTemplates()->loadLanguageFile('Mentions');
337
338
		// Instantiate the form
339
		$settingsForm = new \ElkArte\SettingsForm\SettingsForm(\ElkArte\SettingsForm\SettingsForm::DB_ADAPTER);
340
341
		// Initialize it with our settings
342
		$settingsForm->setConfigVars($this->_notificationsSettings());
343
344
		// Some context stuff
345
		$context['page_title'] = $txt['mentions_settings'];
346
		$context['sub_template'] = 'show_settings';
347
348
		// Saving the settings?
349
		if (isset($this->_req->query->save))
350
		{
351
			checkSession();
352
353
			call_integration_hook('integrate_save_modify_mention_settings');
354
355
			if (!empty($this->_req->post->mentions_enabled))
356
			{
357
				enableModules('mentions', array('post', 'display'));
358
			}
359
			else
360
			{
361
				disableModules('mentions', array('post', 'display'));
362
			}
363
364
			if (empty($this->_req->post->notifications))
365
			{
366
				$notification_methods = serialize(array());
367
			}
368
			else
369
			{
370
				$notification_methods = serialize($this->_req->post->notifications);
371
			}
372
373
			require_once(SUBSDIR . '/Mentions.subs.php');
374
			$enabled_mentions = array();
375
			$current_settings = unserialize($modSettings['notification_methods']);
376
377
			// Fist hide what was visible
378
			$modules_toggle = array('enable' => array(), 'disable' => array());
379 View Code Duplication
			foreach ($current_settings as $type => $val)
380
			{
381
				if (!isset($this->_req->post->notifications[$type]))
382
				{
383
					toggleMentionsVisibility($type, false);
384
					$modules_toggle['disable'][] = $type;
385
				}
386
			}
387
388
			// Then make visible what was hidden, but only if there is anything
389
			if (!empty($this->_req->post->notifications))
390
			{
391 View Code Duplication
				foreach ($this->_req->post->notifications as $type => $val)
392
				{
393
					if (!isset($current_settings[$type]))
394
					{
395
						toggleMentionsVisibility($type, true);
396
						$modules_toggle['enable'][] = $type;
397
					}
398
				}
399
400
				$enabled_mentions = array_keys($this->_req->post->notifications);
401
			}
402
403
			// Let's just keep it active, there are too many reasons it should be.
404
			require_once(SUBSDIR . '/ScheduledTasks.subs.php');
405
			toggleTaskStatusByName('user_access_mentions', true);
406
407
			// Disable or enable modules as needed
408
			foreach ($modules_toggle as $action => $toggles)
409
			{
410
				if (!empty($toggles))
411
				{
412
					// The modules associated with the notification (mentionmem, likes, etc) area
413
					$modules = getMentionsModules($toggles);
414
415
					// The action will either be enable to disable
416
					$function = $action . 'Modules';
417
418
					// Something like enableModule('mentions', array('post', 'display');
419
					foreach ($modules as $key => $val)
420
						$function($key, $val);
421
				}
422
			}
423
424
			updateSettings(array('enabled_mentions' => implode(',', array_unique($enabled_mentions)), 'notification_methods' => $notification_methods));
425
			$settingsForm->setConfigValues((array) $this->_req->post);
426
			$settingsForm->save();
427
			redirectexit('action=admin;area=featuresettings;sa=mention');
428
		}
429
430
		// Prepare the settings for display
431
		$context['post_url'] = getUrl('admin', ['action' => 'admin', 'area' => 'featuresettings', 'sa' => 'mention', 'save']);
432
		$settingsForm->prepare();
433
	}
434
435
	/**
436
	 * Display configuration settings for signatures on forum.
437
	 *
438
	 * - Accessed from ?action=admin;area=featuresettings;sa=sig;
439
	 *
440
	 * @event integrate_save_signature_settings
441
	 */
442
	public function action_signatureSettings_display()
443
	{
444
		global $context, $txt, $modSettings;
445
446
		// Initialize the form
447
		$settingsForm = new \ElkArte\SettingsForm\SettingsForm(\ElkArte\SettingsForm\SettingsForm::DB_ADAPTER);
448
449
		// Initialize it with our settings
450
		$settingsForm->setConfigVars($this->_signatureSettings());
451
452
		// Setup the template.
453
		$context['page_title'] = $txt['signature_settings'];
454
		$context['sub_template'] = 'show_settings';
455
456
		// Disable the max smileys option if we don't allow smileys at all!
457
		theme()->addInlineJavascript('
458
			document.getElementById(\'signature_max_smileys\').disabled = !document.getElementById(\'signature_allow_smileys\').checked;', true);
459
460
		// Load all the signature settings.
461
		list ($sig_limits, $sig_bbc) = explode(':', $modSettings['signature_settings']);
462
		$sig_limits = explode(',', $sig_limits);
463
		$disabledTags = !empty($sig_bbc) ? explode(',', $sig_bbc) : array();
464
465
		// @todo temporary since it does not work, and seriously why would you do this?
466
		$disabledTags[] = 'footnote';
467
468
		// Applying to ALL signatures?!!
469
		if (isset($this->_req->query->apply))
470
		{
471
			// Security!
472
			checkSession('get');
473
474
			// This is horrid - but I suppose some people will want the option to do it.
475
			$applied_sigs = $this->_req->getQuery('step', 'intval', 0);
476
			updateAllSignatures($applied_sigs);
477
478
			$settings_applied = true;
479
		}
480
481
		$context['signature_settings'] = array(
482
			'enable' => isset($sig_limits[0]) ? $sig_limits[0] : 0,
483
			'max_length' => isset($sig_limits[1]) ? $sig_limits[1] : 0,
484
			'max_lines' => isset($sig_limits[2]) ? $sig_limits[2] : 0,
485
			'max_images' => isset($sig_limits[3]) ? $sig_limits[3] : 0,
486
			'allow_smileys' => isset($sig_limits[4]) && $sig_limits[4] == -1 ? 0 : 1,
487
			'max_smileys' => isset($sig_limits[4]) && $sig_limits[4] != -1 ? $sig_limits[4] : 0,
488
			'max_image_width' => isset($sig_limits[5]) ? $sig_limits[5] : 0,
489
			'max_image_height' => isset($sig_limits[6]) ? $sig_limits[6] : 0,
490
			'max_font_size' => isset($sig_limits[7]) ? $sig_limits[7] : 0,
491
			'repetition_guests' => isset($sig_limits[8]) ? $sig_limits[8] : 0,
492
			'repetition_members' => isset($sig_limits[9]) ? $sig_limits[9] : 0,
493
		);
494
495
		// Temporarily make each setting a modSetting!
496
		foreach ($context['signature_settings'] as $key => $value)
497
			$modSettings['signature_' . $key] = $value;
498
499
		// Make sure we check the right tags!
500
		$modSettings['bbc_disabled_signature_bbc'] = $disabledTags;
501
502
		// Saving?
503
		if (isset($this->_req->query->save))
504
		{
505
			checkSession();
506
507
			// Clean up the tag stuff!
508
			$codes = \BBC\ParserWrapper::instance()->getCodes();
509
			$bbcTags = $codes->getTags();
510
511 View Code Duplication
			if (!isset($this->_req->post->signature_bbc_enabledTags))
512
				$this->_req->post->signature_bbc_enabledTags = array();
513
			elseif (!is_array($this->_req->post->signature_bbc_enabledTags))
514
				$this->_req->post->signature_bbc_enabledTags = array($this->_req->post->signature_bbc_enabledTags);
515
516
			$sig_limits = array();
517
			foreach ($context['signature_settings'] as $key => $value)
518
			{
519
				if ($key == 'allow_smileys')
520
					continue;
521
				elseif ($key == 'max_smileys' && empty($this->_req->post->signature_allow_smileys))
522
					$sig_limits[] = -1;
523
				else
524
				{
525
					$current_key = $this->_req->getPost('signature_' . $key, 'intval');
526
					$sig_limits[] = !empty($current_key) ? max(1, $current_key) : 0;
527
				}
528
			}
529
530
			call_integration_hook('integrate_save_signature_settings', array(&$sig_limits, &$bbcTags));
531
532
			$this->_req->post->signature_settings = implode(',', $sig_limits) . ':' . implode(',', array_diff($bbcTags, $this->_req->post->signature_bbc_enabledTags));
533
534
			// Even though we have practically no settings let's keep the convention going!
535
			$save_vars = array();
536
			$save_vars[] = array('text', 'signature_settings');
537
538
			$settingsForm->setConfigVars($save_vars);
539
			$settingsForm->setConfigValues((array) $this->_req->post);
540
			$settingsForm->save();
541
			redirectexit('action=admin;area=featuresettings;sa=sig');
542
		}
543
544
		$context['post_url'] = getUrl('admin', ['action' => 'admin', 'area' => 'featuresettings', 'sa' => 'sig', 'save']);
545
		$context['settings_title'] = $txt['signature_settings'];
546
		$context['settings_message'] = !empty($settings_applied) ? $txt['signature_settings_applied'] : sprintf($txt['signature_settings_warning'], getUrl('admin', ['action' => 'admin', 'area' => 'featuresettings', 'sa' => 'sig', 'apply', '{session_data}']));
547
548
		$settingsForm->prepare();
549
	}
550
551
	/**
552
	 * Show all the custom profile fields available to the user.
553
	 *
554
	 * - Allows for drag/drop sorting of custom profile fields
555
	 * - Accessed with ?action=admin;area=featuresettings;sa=profile
556
	 *
557
	 * @uses sub template show_custom_profile
558
	 */
559
	public function action_profile()
560
	{
561
		global $txt, $scripturl, $context;
562
563
		theme()->getTemplates()->load('ManageFeatures');
564
		$context['page_title'] = $txt['custom_profile_title'];
565
		$context['sub_template'] = 'show_custom_profile';
566
567
		// What about standard fields they can tweak?
568
		$standard_fields = array('website', 'posts', 'warning_status', 'date_registered');
569
570
		// What fields can't you put on the registration page?
571
		$context['fields_no_registration'] = array('posts', 'warning_status', 'date_registered');
572
573
		// Are we saving any standard field changes?
574
		if (isset($this->_req->post->save))
575
		{
576
			checkSession();
577
			validateToken('admin-scp');
578
579
			$changes = array();
580
581
			// Do the active ones first.
582
			$disable_fields = array_flip($standard_fields);
583
			if (!empty($this->_req->post->active))
584
			{
585
				foreach ($this->_req->post->active as $value)
586
				{
587
					if (isset($disable_fields[$value]))
588
					{
589
						unset($disable_fields[$value]);
590
					}
591
				}
592
			}
593
594
			// What we have left!
595
			$changes['disabled_profile_fields'] = empty($disable_fields) ? '' : implode(',', array_keys($disable_fields));
596
597
			// Things we want to show on registration?
598
			$reg_fields = array();
599
			if (!empty($this->_req->post->reg))
600
			{
601
				foreach ($this->_req->post->reg as $value)
602
				{
603
					if (in_array($value, $standard_fields) && !isset($disable_fields[$value]))
604
						$reg_fields[] = $value;
605
				}
606
			}
607
608
			// What we have left!
609
			$changes['registration_fields'] = empty($reg_fields) ? '' : implode(',', $reg_fields);
610
611
			if (!empty($changes))
612
				updateSettings($changes);
613
		}
614
615
		createToken('admin-scp');
616
617
		// Create a listing for all our standard fields
618
		$listOptions = array(
619
			'id' => 'standard_profile_fields',
620
			'title' => $txt['standard_profile_title'],
621
			'base_href' => getUrl('admin', ['action' => 'admin', 'area' => 'featuresettings', 'sa' => 'profile']),
622
			'get_items' => array(
623
				'function' => 'list_getProfileFields',
624
				'params' => array(
625
					true,
626
				),
627
			),
628
			'columns' => array(
629
				'field' => array(
630
					'header' => array(
631
						'value' => $txt['standard_profile_field'],
632
					),
633
					'data' => array(
634
						'db' => 'label',
635
						'style' => 'width: 60%;',
636
					),
637
				),
638
				'active' => array(
639
					'header' => array(
640
						'value' => $txt['custom_edit_active'],
641
						'class' => 'centertext',
642
					),
643
					'data' => array(
644 View Code Duplication
						'function' => function ($rowData) {
645
							$isChecked = $rowData['disabled'] ? '' : ' checked="checked"';
646
							$onClickHandler = $rowData['can_show_register'] ? sprintf('onclick="document.getElementById(\'reg_%1$s\').disabled = !this.checked;"', $rowData['id']) : '';
647
							return sprintf('<input type="checkbox" name="active[]" id="active_%1$s" value="%1$s" class="input_check" %2$s %3$s />', $rowData['id'], $isChecked, $onClickHandler);
648
						},
649
						'style' => 'width: 20%;',
650
						'class' => 'centertext',
651
					),
652
				),
653
				'show_on_registration' => array(
654
					'header' => array(
655
						'value' => $txt['custom_edit_registration'],
656
						'class' => 'centertext',
657
					),
658
					'data' => array(
659 View Code Duplication
						'function' => function ($rowData) {
660
							$isChecked = $rowData['on_register'] && !$rowData['disabled'] ? ' checked="checked"' : '';
661
							$isDisabled = $rowData['can_show_register'] ? '' : ' disabled="disabled"';
662
							return sprintf('<input type="checkbox" name="reg[]" id="reg_%1$s" value="%1$s" class="input_check" %2$s %3$s />', $rowData['id'], $isChecked, $isDisabled);
663
						},
664
						'style' => 'width: 20%;',
665
						'class' => 'centertext',
666
					),
667
				),
668
			),
669
			'form' => array(
670
				'href' => getUrl('admin', ['action' => 'admin', 'area' => 'featuresettings', 'sa' => 'profile']),
671
				'name' => 'standardProfileFields',
672
				'token' => 'admin-scp',
673
			),
674
			'additional_rows' => array(
675
				array(
676
					'position' => 'below_table_data',
677
					'value' => '<input type="submit" name="save" value="' . $txt['save'] . '" class="right_submit" />',
678
				),
679
			),
680
		);
681
		createList($listOptions);
682
683
		// And now we do the same for all of our custom ones
684
		$token = createToken('admin-sort');
685
		$listOptions = array(
686
			'id' => 'custom_profile_fields',
687
			'title' => $txt['custom_profile_title'],
688
			'base_href' => getUrl('admin', ['action' => 'admin', 'area' => 'featuresettings', 'sa' => 'profile']),
689
			'default_sort_col' => 'vieworder',
690
			'no_items_label' => $txt['custom_profile_none'],
691
			'items_per_page' => 25,
692
			'sortable' => true,
693
			'get_items' => array(
694
				'function' => 'list_getProfileFields',
695
				'params' => array(
696
					false,
697
				),
698
			),
699
			'get_count' => array(
700
				'function' => 'list_getProfileFieldSize',
701
			),
702
			'columns' => array(
703
				'vieworder' => array(
704
					'header' => array(
705
						'value' => '',
706
						'class' => 'hide',
707
					),
708
					'data' => array(
709
						'db' => 'vieworder',
710
						'class' => 'hide',
711
					),
712
					'sort' => array(
713
						'default' => 'vieworder',
714
					),
715
				),
716
				'field_name' => array(
717
					'header' => array(
718
						'value' => $txt['custom_profile_fieldname'],
719
					),
720
					'data' => array(
721
						'function' => function ($rowData) {
722
							return sprintf('<a href="%1$s">%2$s</a><div class="smalltext">%3$s</div>', getUrl('admin', ['action' => 'admin', 'area' => 'featuresettings', 'sa' => 'profileedit', 'fid' => (int) $rowData['id_field']]), $rowData['field_name'], $rowData['field_desc']);
723
						},
724
						'style' => 'width: 65%;',
725
					),
726
					'sort' => array(
727
						'default' => 'field_name',
728
						'reverse' => 'field_name DESC',
729
					),
730
				),
731
				'field_type' => array(
732
					'header' => array(
733
						'value' => $txt['custom_profile_fieldtype'],
734
					),
735
					'data' => array(
736
						'function' => function ($rowData) {
737
							global $txt;
738
739
							$textKey = sprintf('custom_profile_type_%1$s', $rowData['field_type']);
740
							return isset($txt[$textKey]) ? $txt[$textKey] : $textKey;
741
						},
742
						'style' => 'width: 10%;',
743
					),
744
					'sort' => array(
745
						'default' => 'field_type',
746
						'reverse' => 'field_type DESC',
747
					),
748
				),
749
				'cust' => array(
750
					'header' => array(
751
						'value' => $txt['custom_profile_active'],
752
						'class' => 'centertext',
753
					),
754
					'data' => array(
755
						'function' => function ($rowData) {
756
							$isChecked = $rowData['active'] ? ' checked="checked"' : '';
757
							return sprintf('<input type="checkbox" name="cust[]" id="cust_%1$s" value="%1$s" class="input_check"%2$s />', $rowData['id_field'], $isChecked);
758
						},
759
						'style' => 'width: 8%;',
760
						'class' => 'centertext',
761
					),
762
					'sort' => array(
763
						'default' => 'active DESC',
764
						'reverse' => 'active',
765
					),
766
				),
767
				'placement' => array(
768
					'header' => array(
769
						'value' => $txt['custom_profile_placement'],
770
					),
771
					'data' => array(
772
						'function' => function ($rowData) {
773
							global $txt;
774
							$placement = 'custom_profile_placement_';
775
776
							switch ((int) $rowData['placement'])
777
							{
778
								case 0:
779
									$placement .= 'standard';
780
									break;
781
								case 1:
782
									$placement .= 'withicons';
783
									break;
784
								case 2:
785
									$placement .= 'abovesignature';
786
									break;
787
								case 3:
788
									$placement .= 'aboveicons';
789
									break;
790
							}
791
792
							return $txt[$placement];
793
						},
794
						'style' => 'width: 5%;',
795
					),
796
					'sort' => array(
797
						'default' => 'placement DESC',
798
						'reverse' => 'placement',
799
					),
800
				),
801
				'show_on_registration' => array(
802
					'data' => array(
803
						'sprintf' => array(
804
							'format' => '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=%1$s">' . $txt['modify'] . '</a>',
805
							'params' => array(
806
								'id_field' => false,
807
							),
808
						),
809
						'style' => 'width: 5%;',
810
					),
811
				),
812
			),
813
			'form' => array(
814
				'href' => getUrl('admin', ['action' => 'admin', 'area' => 'featuresettings', 'sa' => 'profileedit']),
815
				'name' => 'customProfileFields',
816
				'token' => 'admin-scp',
817
			),
818
			'additional_rows' => array(
819
				array(
820
					'class' => 'submitbutton',
821
					'position' => 'below_table_data',
822
					'value' => '<input type="submit" name="onoff" value="' . $txt['save'] . '" class="right_submit" />
823
					<input type="submit" name="new" value="' . $txt['custom_profile_make_new'] . '" class="right_submit" />',
824
				),
825
				array(
826
					'position' => 'top_of_list',
827
					'value' => '<p class="infobox">' . $txt['custom_profile_sort'] . '</p>',
828
				),
829
			),
830
			'javascript' => '
831
				$().elkSortable({
832
					sa: "profileorder",
833
					error: "' . $txt['admin_order_error'] . '",
834
					title: "' . $txt['admin_order_title'] . '",
835
					placeholder: "ui-state-highlight",
836
					href: "?action=admin;area=featuresettings;sa=profile",
837
					token: {token_var: "' . $token['admin-sort_token_var'] . '", token_id: "' . $token['admin-sort_token'] . '"}
838
				});
839
			',
840
		);
841
842
		createList($listOptions);
843
	}
844
845
	/**
846
	 * Edit some profile fields?
847
	 *
848
	 * - Accessed with ?action=admin;area=featuresettings;sa=profileedit
849
	 *
850
	 * @uses sub template edit_profile_field
851
	 */
852
	public function action_profileedit()
853
	{
854
		global $txt, $context;
855
856
		theme()->getTemplates()->load('ManageFeatures');
857
858
		// Sort out the context!
859
		$context['fid'] = $this->_req->getQuery('fid', 'intval', 0);
860
		$context[$context['admin_menu_name']]['current_subsection'] = 'profile';
861
		$context['page_title'] = $context['fid'] ? $txt['custom_edit_title'] : $txt['custom_add_title'];
862
		$context['sub_template'] = 'edit_profile_field';
863
864
		// Any errors messages to show?
865
		if (isset($this->_req->query->msg))
866
		{
867
			theme()->getTemplates()->loadLanguageFile('Errors');
868
869
			if (isset($txt['custom_option_' . $this->_req->query->msg]))
870
				$context['custom_option__error'] = $txt['custom_option_' . $this->_req->query->msg];
871
		}
872
873
		// Load the profile language for section names.
874
		theme()->getTemplates()->loadLanguageFile('Profile');
875
876
		// Load up the profile field, if one was supplied
877
		if ($context['fid'])
878
		{
879
			$context['field'] = getProfileField($context['fid']);
880
		}
881
882
		// Setup the default values as needed.
883
		if (empty($context['field']))
884
		{
885
			$context['field'] = array(
886
				'name' => '',
887
				'colname' => '???',
888
				'desc' => '',
889
				'profile_area' => 'forumprofile',
890
				'reg' => false,
891
				'display' => false,
892
				'memberlist' => false,
893
				'type' => 'text',
894
				'max_length' => 255,
895
				'rows' => 4,
896
				'cols' => 30,
897
				'bbc' => false,
898
				'default_check' => false,
899
				'default_select' => '',
900
				'default_value' => '',
901
				'options' => array('', '', ''),
902
				'active' => true,
903
				'private' => false,
904
				'can_search' => false,
905
				'mask' => 'nohtml',
906
				'regex' => '',
907
				'enclose' => '',
908
				'placement' => 0,
909
			);
910
		}
911
912
		// All the javascript for this page... everything else is in admin.js
913
		theme()->addJavascriptVar(array('startOptID' => count($context['field']['options'])));
914
		theme()->addInlineJavascript('updateInputBoxes();', true);
915
916
		// Are we toggling which ones are active?
917
		if (isset($this->_req->post->onoff))
918
		{
919
			checkSession();
920
			validateToken('admin-scp');
921
922
			// Enable and disable custom fields as required.
923
			$enabled = array(0);
924
			if (isset($this->_req->post->cust) && is_array($this->_req->post->cust)) {
925
				foreach ($this->_req->post->cust as $id)
926
					$enabled[] = (int) $id;
927
			}
928
929
			updateRenamedProfileStatus($enabled);
930
		}
931
		// Are we saving?
932
		elseif (isset($this->_req->post->save))
933
		{
934
			checkSession();
935
			validateToken('admin-ecp');
936
937
			// Everyone needs a name - even the (bracket) unknown...
938
			if (trim($this->_req->post->field_name) == '')
939
				redirectexit('action=admin;area=featuresettings;sa=profileedit;fid=' . $this->_req->query->fid . ';msg=need_name');
940
941
			// Regex you say?  Do a very basic test to see if the pattern is valid
942
			if (!empty($this->_req->post->regex) && @preg_match($this->_req->post->regex, 'dummy') === false)
943
				redirectexit('action=admin;area=featuresettings;sa=profileedit;fid=' . $this->_req->query->fid . ';msg=regex_error');
944
945
			$this->_req->post->field_name = $this->_req->getPost('field_name', '\\ElkArte\\Util::htmlspecialchars');
946
			$this->_req->post->field_desc = $this->_req->getPost('field_desc', '\\ElkArte\\Util::htmlspecialchars');
947
948
			$rows = isset($this->_req->post->rows) ? (int) $this->_req->post->rows : 4;
949
			$cols = isset($this->_req->post->cols) ? (int) $this->_req->post->cols : 30;
950
951
			// Checkboxes...
952
			$show_reg = $this->_req->getPost('reg', 'intval', 0);
953
			$show_display = isset($this->_req->post->display) ? 1 : 0;
954
			$show_memberlist = isset($this->_req->post->memberlist) ? 1 : 0;
955
			$bbc = isset($this->_req->post->bbc) ? 1 : 0;
956
			$show_profile = $this->_req->post->profile_area;
957
			$active = isset($this->_req->post->active) ? 1 : 0;
958
			$private = $this->_req->getPost('private', 'intval', 0);
959
			$can_search = isset($this->_req->post->can_search) ? 1 : 0;
960
961
			// Some masking stuff...
962
			$mask = $this->_req->getPost('mask', 'strval', '');
963
			if ($mask == 'regex' && isset($this->_req->post->regex))
964
				$mask .= $this->_req->post->regex;
965
966
			$field_length = $this->_req->getPost('max_length', 'intval', 255);
967
			$enclose = $this->_req->getPost('enclose', 'strval', '');
968
			$placement = $this->_req->getPost('placement', 'intval', 0);
969
970
			// Select options?
971
			$field_options = '';
972
			$newOptions = array();
973
974
			// Set default
975
			$default = '';
976
977
			switch ($this->_req->post->field_type)
978
			{
979
				case 'check':
980
					$default = isset($this->_req->post->default_check) ? 1 : '';
981
					break;
982
				case 'select':
983
				case 'radio':
984
					if (!empty($this->_req->post->select_option))
985
					{
986
						foreach ($this->_req->post->select_option as $k => $v)
987
						{
988
							// Clean, clean, clean...
989
							$v = \ElkArte\Util::htmlspecialchars($v);
990
							$v = strtr($v, array(',' => ''));
991
992
							// Nada, zip, etc...
993
							if (trim($v) == '')
994
								continue;
995
996
							// Otherwise, save it boy.
997
							$field_options .= $v . ',';
998
999
							// This is just for working out what happened with old options...
1000
							$newOptions[$k] = $v;
1001
1002
							// Is it default?
1003
							if (isset($this->_req->post->default_select) && $this->_req->post->default_select == $k)
1004
							{
1005
								$default = $v;
1006
							}
1007
						}
1008
1009
						if (isset($_POST['default_select']) && $_POST['default_select'] == 'no_default')
1010
							$default = 'no_default';
1011
1012
						$field_options = substr($field_options, 0, -1);
1013
					}
1014
					break;
1015
				default:
1016
					$default = isset($this->_req->post->default_value) ? $this->_req->post->default_value : '';
1017
			}
1018
1019
			// Text area by default has dimensions
1020
//			if ($this->_req->post->field_type == 'textarea')
1021
//				$default = (int) $this->_req->post->rows . ',' . (int) $this->_req->post->cols;
1022
1023
			// Come up with the unique name?
1024
			if (empty($context['fid']))
1025
			{
1026
				$colname = \ElkArte\Util::substr(strtr($this->_req->post->field_name, array(' ' => '')), 0, 6);
1027
				preg_match('~([\w\d_-]+)~', $colname, $matches);
1028
1029
				// If there is nothing to the name, then let's start our own - for foreign languages etc.
1030
				if (isset($matches[1]))
1031
					$colname = $initial_colname = 'cust_' . strtolower($matches[1]);
1032
				else
1033
					$colname = $initial_colname = 'cust_' . mt_rand(1, 999999);
1034
1035
				$unique = ensureUniqueProfileField($colname, $initial_colname);
1036
1037
				// Still not a unique column name? Leave it up to the user, then.
1038
				if (!$unique)
1039
					throw new \ElkArte\Exceptions\Exception('custom_option_not_unique');
1040
1041
				// And create a new field
1042
				$new_field = array(
1043
					'col_name' => $colname,
1044
					'field_name' => $this->_req->post->field_name,
1045
					'field_desc' => $this->_req->post->field_desc,
1046
					'field_type' => $this->_req->post->field_type,
1047
					'field_length' => $field_length,
1048
					'field_options' => $field_options,
1049
					'show_reg' => $show_reg,
1050
					'show_display' => $show_display,
1051
					'show_memberlist' => $show_memberlist,
1052
					'show_profile' => $show_profile,
1053
					'private' => $private,
1054
					'active' => $active,
1055
					'default_value' => $default,
1056
					'rows' => $rows,
1057
					'cols' => $cols,
1058
					'can_search' => $can_search,
1059
					'bbc' => $bbc,
1060
					'mask' => $mask,
1061
					'enclose' => $enclose,
1062
					'placement' => $placement,
1063
					'vieworder' => list_getProfileFieldSize() + 1,
1064
				);
1065
				addProfileField($new_field);
1066
			}
1067
			// Work out what to do with the user data otherwise...
1068
			else
1069
			{
1070
				// Anything going to check or select is pointless keeping - as is anything coming from check!
1071
				if (($this->_req->post->field_type == 'check' && $context['field']['type'] != 'check')
1072
					|| (($this->_req->post->field_type == 'select' || $this->_req->post->field_type == 'radio') && $context['field']['type'] != 'select' && $context['field']['type'] != 'radio')
1073
					|| ($context['field']['type'] == 'check' && $this->_req->post->field_type != 'check'))
1074
				{
1075
					deleteProfileFieldUserData($context['field']['colname']);
1076
				}
1077
				// Otherwise - if the select is edited may need to adjust!
1078
				elseif ($this->_req->post->field_type == 'select' || $this->_req->post->field_type == 'radio')
1079
				{
1080
					$optionChanges = array();
1081
					$takenKeys = array();
1082
1083
					// Work out what's changed!
1084
					foreach ($context['field']['options'] as $k => $option)
1085
					{
1086
						if (trim($option) == '')
1087
							continue;
1088
1089
						// Still exists?
1090
						if (in_array($option, $newOptions))
1091
						{
1092
							$takenKeys[] = $k;
1093
							continue;
1094
						}
1095
					}
1096
1097
					// Finally - have we renamed it - or is it really gone?
1098
					foreach ($optionChanges as $k => $option)
1099
					{
1100
						// Just been renamed?
1101
						if (!in_array($k, $takenKeys) && !empty($newOptions[$k]))
1102
							updateRenamedProfileField($k, $newOptions, $context['field']['colname'], $option);
1103
					}
1104
				}
1105
				// @todo Maybe we should adjust based on new text length limits?
1106
1107
				// And finally update an existing field
1108
				$field_data = array(
1109
					'field_length' => $field_length,
1110
					'show_reg' => $show_reg,
1111
					'show_display' => $show_display,
1112
					'show_memberlist' => $show_memberlist,
1113
					'private' => $private,
1114
					'active' => $active,
1115
					'can_search' => $can_search,
1116
					'bbc' => $bbc,
1117
					'current_field' => $context['fid'],
1118
					'field_name' => $this->_req->post->field_name,
1119
					'field_desc' => $this->_req->post->field_desc,
1120
					'field_type' => $this->_req->post->field_type,
1121
					'field_options' => $field_options,
1122
					'show_profile' => $show_profile,
1123
					'default_value' => $default,
1124
					'mask' => $mask,
1125
					'enclose' => $enclose,
1126
					'placement' => $placement,
1127
					'rows' => $rows,
1128
					'cols' => $cols,
1129
				);
1130
1131
				updateProfileField($field_data);
1132
1133
				// Just clean up any old selects - these are a pain!
1134
				if (($this->_req->post->field_type == 'select' || $this->_req->post->field_type == 'radio') && !empty($newOptions))
1135
					deleteOldProfileFieldSelects($newOptions, $context['field']['colname']);
1136
			}
1137
		}
1138
		// Deleting?
1139
		elseif (isset($this->_req->post->delete) && $context['field']['colname'])
1140
		{
1141
			checkSession();
1142
			validateToken('admin-ecp');
1143
1144
			// Delete the old data first, then the field.
1145
			deleteProfileFieldUserData($context['field']['colname']);
1146
			deleteProfileField($context['fid']);
1147
		}
1148
1149
		// Rebuild display cache etc.
1150
		if (isset($this->_req->post->delete) || isset($this->_req->post->save) || isset($this->_req->post->onoff))
1151
		{
1152
			checkSession();
1153
1154
			// Update the display cache
1155
			updateDisplayCache();
1156
			redirectexit('action=admin;area=featuresettings;sa=profile');
1157
		}
1158
1159
		createToken('admin-ecp');
1160
	}
1161
1162
	/**
1163
	 * Editing personal messages settings
1164
	 *
1165
	 * - Accessed with ?action=admin;area=featuresettings;sa=pmsettings
1166
	 *
1167
	 * @event integrate_save_pmsettings_settings
1168
	 */
1169
	public function action_pmsettings()
1170
	{
1171
		global $txt, $context;
1172
1173
		// Initialize the form
1174
		$settingsForm = new \ElkArte\SettingsForm\SettingsForm(\ElkArte\SettingsForm\SettingsForm::DB_ADAPTER);
1175
1176
		// Initialize it with our settings
1177
		$settingsForm->setConfigVars($this->_pmSettings());
1178
1179
		require_once(SUBSDIR . '/PersonalMessage.subs.php');
1180
		theme()->getTemplates()->loadLanguageFile('ManageMembers');
1181
1182
		$context['pm_limits'] = loadPMLimits();
1183
1184
		// Saving?
1185
		if (isset($this->_req->query->save))
1186
		{
1187
			checkSession();
1188
1189
			require_once(SUBSDIR . '/Membergroups.subs.php');
1190
			foreach ($context['pm_limits'] as $group_id => $group)
1191
			{
1192
				if (isset($this->_req->post->group[$group_id]) && $this->_req->post->group[$group_id] != $group['max_messages'])
1193
					updateMembergroupProperties(array('current_group' => $group_id, 'max_messages' => $this->_req->post->group[$group_id]));
1194
			}
1195
1196
			call_integration_hook('integrate_save_pmsettings_settings');
1197
1198
			$settingsForm->setConfigValues((array) $this->_req->post);
1199
			$settingsForm->save();
1200
			redirectexit('action=admin;area=featuresettings;sa=pmsettings');
1201
		}
1202
1203
		$context['post_url'] = getUrl('admin', ['action' => 'admin', 'area' => 'featuresettings', 'sa' => 'pmsettings', 'save']);
1204
		$context['settings_title'] = $txt['personal_messages'];
1205
1206
		$settingsForm->prepare();
1207
	}
1208
1209
	/**
1210
	 * Return basic feature settings.
1211
	 *
1212
	 * @event integrate_modify_basic_settings Adds to General features and Options
1213
	 */
1214 2
	private function _basicSettings()
1215
	{
1216 2
		global $txt;
1217
1218
		$config_vars = array(
1219
				// Basic stuff, titles, permissions...
1220 2
				array('check', 'allow_guestAccess'),
1221
				array('check', 'enable_buddylist'),
1222
				array('check', 'allow_editDisplayName'),
1223
				array('check', 'allow_hideOnline'),
1224
				array('check', 'titlesEnable'),
1225 2
			'',
1226
				// Javascript and CSS options
1227 2
				array('select', 'jquery_source', array('auto' => $txt['jquery_auto'], 'local' => $txt['jquery_local'], 'cdn' => $txt['jquery_cdn'])),
1228
				array('check', 'jquery_default', 'onchange' => 'showhideJqueryOptions();'),
1229 2
				array('text', 'jquery_version', 'postinput' => $txt['jquery_custom_after']),
1230
				array('check', 'jqueryui_default', 'onchange' => 'showhideJqueryOptions();'),
1231 2
				array('text', 'jqueryui_version', 'postinput' => $txt['jqueryui_custom_after']),
1232 2
				array('check', 'minify_css_js', 'postinput' => '<a href="#" id="clean_hives" class="linkbutton">' . $txt['clean_hives'] . '</a>'),
1233 2
			'',
1234
				// Number formatting, timezones.
1235
				array('text', 'time_format'),
1236 2
				array('float', 'time_offset', 'subtext' => $txt['setting_time_offset_note'], 6, 'postinput' => $txt['hours']),
1237
				'default_timezone' => array('select', 'default_timezone', array()),
1238 2
			'',
1239
				// Who's online?
1240
				array('check', 'who_enabled'),
1241 2
				array('int', 'lastActive', 6, 'postinput' => $txt['minutes']),
1242 2
			'',
1243
				// Statistics.
1244
				array('check', 'trackStats'),
1245
				array('check', 'hitStats'),
1246 2
			'',
1247
				// Option-ish things... miscellaneous sorta.
1248
				array('check', 'allow_disableAnnounce'),
1249
				array('check', 'disallow_sendBody'),
1250 2
				array('select', 'enable_contactform', array('disabled' => $txt['contact_form_disabled'], 'registration' => $txt['contact_form_registration'], 'menu' => $txt['contact_form_menu'])),
1251
		);
1252
1253
		// Get all the time zones.
1254 2
		$all_zones = timezone_identifiers_list();
1255 2
		if ($all_zones === false)
1256
			unset($config_vars['default_timezone']);
1257
		else
1258
		{
1259
			// Make sure we set the value to the same as the printed value.
1260 2
			foreach ($all_zones as $zone)
1261 2
				$config_vars['default_timezone'][2][$zone] = $zone;
1262
		}
1263
1264 2
		call_integration_hook('integrate_modify_basic_settings', array(&$config_vars));
1265
1266 2
		return $config_vars;
1267
	}
1268
1269
	/**
1270
	 * Public method to return the basic settings, used for admin search
1271
	 */
1272 2
	public function basicSettings_search()
1273
	{
1274 2
		return $this->_basicSettings();
1275
	}
1276
1277
	/**
1278
	 * Return layout settings.
1279
	 *
1280
	 * @event integrate_modify_layout_settings Adds options to Configuration->Layout
1281
	 */
1282 2
	private function _layoutSettings()
1283
	{
1284 2
		global $txt;
1285
1286 2
		$config_vars = array_merge(getFrontPageControllers(), array(
1287 2
			'',
1288
				// Pagination stuff.
1289
				array('check', 'compactTopicPagesEnable'),
1290 2
				array('int', 'compactTopicPagesContiguous', 'subtext' => 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>')),
1291
				array('int', 'defaultMaxMembers'),
1292
				array('check', 'displayMemberNames'),
1293 2
			'',
1294
				// Stuff that just is everywhere - today, search, online, etc.
1295 2
				array('select', 'todayMod', array($txt['today_disabled'], $txt['today_only'], $txt['yesterday_today'], $txt['relative_time'])),
1296
				array('check', 'onlineEnable'),
1297
				array('check', 'enableVBStyleLogin'),
1298 2
			'',
1299
				// Automagic image resizing.
1300 2
				array('int', 'max_image_width', 'subtext' => $txt['zero_for_no_limit']),
1301 2
				array('int', 'max_image_height', 'subtext' => $txt['zero_for_no_limit']),
1302 2
			'',
1303
				// This is like debugging sorta.
1304
				array('check', 'timeLoadPageEnable'),
1305
		));
1306
1307 2
		call_integration_hook('integrate_modify_layout_settings', array(&$config_vars));
1308
1309 2
		return $config_vars;
1310
	}
1311
1312
	/**
1313
	 * Public method to return the layout settings, used for admin search
1314
	 */
1315 2
	public function layoutSettings_search()
1316
	{
1317 2
		return $this->_layoutSettings();
1318
	}
1319
1320
	/**
1321
	 * Return karma settings.
1322
	 *
1323
	 * @event integrate_modify_karma_settings Adds to Configuration->Karma
1324
	 */
1325 2
	private function _karmaSettings()
1326
	{
1327 2
		global $txt;
1328
1329
		$config_vars = array(
1330
				// Karma - On or off?
1331 2
				array('select', 'karmaMode', explode('|', $txt['karma_options'])),
1332 2
			'',
1333
				// Who can do it.... and who is restricted by time limits?
1334 2
				array('int', 'karmaMinPosts', 6, 'postinput' => $txt['manageposts_posts']),
1335 2
				array('float', 'karmaWaitTime', 6, 'postinput' => $txt['hours']),
1336
				array('check', 'karmaTimeRestrictAdmins'),
1337
				array('check', 'karmaDisableSmite'),
1338 2
			'',
1339
				// What does it look like?  [smite]?
1340
				array('text', 'karmaLabel'),
1341
				array('text', 'karmaApplaudLabel', 'mask' => 'nohtml'),
1342
				array('text', 'karmaSmiteLabel', 'mask' => 'nohtml'),
1343
		);
1344
1345 2
		call_integration_hook('integrate_modify_karma_settings', array(&$config_vars));
1346
1347 2
		return $config_vars;
1348
	}
1349
1350
	/**
1351
	 * Public method to return the karma settings, used for admin search
1352
	 */
1353 2
	public function karmaSettings_search()
1354
	{
1355 2
		return $this->_karmaSettings();
1356
	}
1357
1358
	/**
1359
	 * Return likes settings.
1360
	 *
1361
	 * @event integrate_modify_likes_settings Adds to Configuration->Likes
1362
	 */
1363 2
	private function _likesSettings()
1364
	{
1365 2
		global $txt;
1366
1367
		$config_vars = array(
1368
				// Likes - On or off?
1369 2
				array('check', 'likes_enabled'),
1370 2
			'',
1371
				// Who can do it.... and who is restricted by count limits?
1372 2
				array('int', 'likeMinPosts', 6, 'postinput' => $txt['manageposts_posts']),
1373 2
				array('int', 'likeWaitTime', 6, 'postinput' => $txt['minutes']),
1374
				array('int', 'likeWaitCount', 6),
1375
				array('check', 'likeRestrictAdmins'),
1376
				array('check', 'likeAllowSelf'),
1377 2
			'',
1378
				array('int', 'likeDisplayLimit', 6)
1379
		);
1380
1381 2
		call_integration_hook('integrate_modify_likes_settings', array(&$config_vars));
1382
1383 2
		return $config_vars;
1384
	}
1385
1386
	/**
1387
	 * Public method to return the likes settings, used for admin search
1388
	 */
1389 2
	public function likesSettings_search()
1390
	{
1391 2
		return $this->_likesSettings();
1392
	}
1393
1394
	/**
1395
	 * Return mentions settings.
1396
	 *
1397
	 * @event integrate_modify_mention_settings Adds to Configuration->Mentions
1398
	 */
1399 2
	private function _notificationsSettings()
1400
	{
1401 2
		global $txt, $modSettings;
1402
1403 2
		theme()->getTemplates()->loadLanguageFile('Profile');
1404 2
		theme()->getTemplates()->loadLanguageFile('UserNotifications');
1405
1406
		// The mentions settings
1407
		$config_vars = array(
1408 2
			array('title', 'mentions_settings'),
1409
			array('check', 'mentions_enabled'),
1410
		);
1411
1412 2
		$notification_methods = \ElkArte\Notifications::instance()->getNotifiers();
1413 2
		$notification_types = getNotificationTypes();
1414 2
		$current_settings = unserialize($modSettings['notification_methods']);
1415
1416 2
		foreach ($notification_types as $title)
1417
		{
1418
			$config_vars[] = array('title', 'setting_' . $title);
1419
1420
			foreach ($notification_methods as $method)
1421
			{
1422
				if ($method === 'notification')
1423
					$text_label = $txt['setting_notify_enable_this'];
1424
				else
1425
					$text_label = $txt['notify_' . $method];
1426
1427
				$config_vars[] = array('check', 'notifications[' . $title . '][' . $method . ']', 'text_label' => $text_label);
1428
				$modSettings['notifications[' . $title . '][' . $method . ']'] = !empty($current_settings[$title][$method]);
1429
			}
1430
		}
1431
1432 2
		call_integration_hook('integrate_modify_mention_settings', array(&$config_vars));
1433
1434 2
		return $config_vars;
1435
	}
1436
1437
	/**
1438
	 * Public method to return the mention settings, used for admin search
1439
	 */
1440 2
	public function mentionSettings_search()
1441
	{
1442 2
		return $this->_notificationsSettings();
1443
	}
1444
1445
	/**
1446
	 * Return signature settings.
1447
	 *
1448
	 * - Used in admin center search and settings form
1449
	 *
1450
	 * @event integrate_modify_signature_settings Adds options to Signature Settings
1451
	 */
1452 2
	private function _signatureSettings()
1453
	{
1454 2
		global $txt;
1455
1456
		$config_vars = array(
1457
				// Are signatures even enabled?
1458 2
				array('check', 'signature_enable'),
1459 2
			'',
1460
				// Tweaking settings!
1461 2
				array('int', 'signature_max_length', 'subtext' => $txt['zero_for_no_limit']),
1462 2
				array('int', 'signature_max_lines', 'subtext' => $txt['zero_for_no_limit']),
1463 2
				array('int', 'signature_max_font_size', 'subtext' => $txt['zero_for_no_limit']),
1464
				array('check', 'signature_allow_smileys', 'onclick' => 'document.getElementById(\'signature_max_smileys\').disabled = !this.checked;'),
1465 2
				array('int', 'signature_max_smileys', 'subtext' => $txt['zero_for_no_limit']),
1466 2
				array('select', 'signature_repetition_guests',
1467
					array(
1468 2
						$txt['signature_always'],
1469 2
						$txt['signature_onlyfirst'],
1470 2
						$txt['signature_never'],
1471
					),
1472
				),
1473 2
				array('select', 'signature_repetition_members',
1474
					array(
1475 2
						$txt['signature_always'],
1476 2
						$txt['signature_onlyfirst'],
1477 2
						$txt['signature_never'],
1478
					),
1479
				),
1480 2
			'',
1481
				// Image settings.
1482 2
				array('int', 'signature_max_images', 'subtext' => $txt['signature_max_images_note']),
1483 2
				array('int', 'signature_max_image_width', 'subtext' => $txt['zero_for_no_limit']),
1484 2
				array('int', 'signature_max_image_height', 'subtext' => $txt['zero_for_no_limit']),
1485 2
			'',
1486
				array('bbc', 'signature_bbc'),
1487
		);
1488
1489 2
		call_integration_hook('integrate_modify_signature_settings', array(&$config_vars));
1490
1491 2
		return $config_vars;
1492
	}
1493
1494
	/**
1495
	 * Public method to return the signature settings, used for admin search
1496
	 */
1497 2
	public function signatureSettings_search()
1498
	{
1499 2
		return $this->_signatureSettings();
1500
	}
1501
1502
	/**
1503
	 * Return pm settings.
1504
	 *
1505
	 * - Used in admin center search and settings form
1506
	 *
1507
	 * @event integrate_modify_pmsettings_settings Adds / Modifies PM Settings
1508
	 */
1509
	private function _pmSettings()
1510
	{
1511
		global $txt;
1512
1513
		$config_vars = array(
1514
			// Reporting of personal messages?
1515
			array('check', 'enableReportPM'),
1516
			// Inline permissions.
1517
			array('permissions', 'pm_send'),
1518
			// PM Settings
1519
			array('title', 'antispam_PM'),
1520
				'pm1' => array('int', 'max_pm_recipients', 'postinput' => $txt['max_pm_recipients_note']),
1521
				'pm2' => array('int', 'pm_posts_verification', 'postinput' => $txt['pm_posts_verification_note']),
1522
				'pm3' => array('int', 'pm_posts_per_hour', 'postinput' => $txt['pm_posts_per_hour_note']),
1523
			array('title', 'membergroups_max_messages'),
1524
				array('desc', 'membergroups_max_messages_desc'),
1525
				array('callback', 'pm_limits'),
1526
		);
1527
1528
		call_integration_hook('integrate_modify_pmsettings_settings', array(&$config_vars));
1529
1530
		return $config_vars;
1531
	}
1532
}
1533