Completed
Pull Request — development (#2907)
by Martyn
13:27
created

ManageFeatures_Controller::action_pmsettings()   B

Complexity

Conditions 5
Paths 2

Size

Total Lines 39
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
cc 5
eloc 20
nc 2
nop 0
dl 0
loc 39
ccs 0
cts 24
cp 0
crap 30
rs 8.439
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Manage features and options administration page.
5
 *
6
 * @name      ElkArte Forum
7
 * @copyright ElkArte Forum contributors
8
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause
9
 *
10
 * This file contains code covered by:
11
 * copyright:	2011 Simple Machines (http://www.simplemachines.org)
12
 * license:		BSD, See included LICENSE.TXT for terms and conditions.
13
 *
14
 * @version 1.1 Release Candidate 1
15
 *
16
 */
17
18
/**
19
 * Manage features and options administration page.
20
 *
21
 * This controller handles the pages which allow the admin
22
 * to see and change the basic feature settings of their site.
23
 */
24
class ManageFeatures_Controller extends Action_Controller
25
{
26
	/**
27
	 * Pre Dispatch, called before other methods.
28
	 */
29 6
	public function pre_dispatch()
30
	{
31
		// We need this in few places so it's easier to have it loaded here
32 6
		require_once(SUBSDIR . '/ManageFeatures.subs.php');
33 6
	}
34
35
	/**
36
	 * This function passes control through to the relevant tab.
37
	 *
38
	 * @see Action_Controller::action_index()
39
	 * @uses Help, ManageSettings languages
40
	 * @uses sub_template show_settings
41
	 */
42
	public function action_index()
43
	{
44
		global $context, $txt, $settings, $scripturl;
45
46
		// Often Helpful
47
		loadLanguage('Help');
48
		loadLanguage('ManageSettings');
49
		loadLanguage('Mentions');
50
51
		// All the actions we know about
52
		$subActions = array(
53
			'basic' => array(
54
				'controller' => $this,
55
				'function' => 'action_basicSettings_display',
56
				'permission' => 'admin_forum'
57
			),
58
			'layout' => array(
59
				'controller' => $this,
60
				'function' => 'action_layoutSettings_display',
61
				'permission' => 'admin_forum'
62
			),
63
			'karma' => array(
64
				'controller' => $this,
65
				'function' => 'action_karmaSettings_display',
66
				'enabled' => in_array('k', $context['admin_features']),
67
				'permission' => 'admin_forum'
68
			),
69
			'pmsettings' => array(
70
				'controller' => $this,
71
				'function' => 'action_pmsettings',
72
				'permission' => 'admin_forum'
73
			),
74
			'likes' => array(
75
				'controller' => $this,
76
				'function' => 'action_likesSettings_display',
77
				'enabled' => in_array('l', $context['admin_features']),
78
				'permission' => 'admin_forum'
79
			),
80
			'mention' => array(
81
				'controller' => $this,
82
				'function' => 'action_notificationsSettings_display',
83
				'permission' => 'admin_forum'
84
			),
85
			'sig' => array(
86
				'controller' => $this,
87
				'function' => 'action_signatureSettings_display',
88
				'permission' => 'admin_forum'
89
			),
90
			'profile' => array(
91
				'controller' => $this,
92
				'function' => 'action_profile',
93
				'enabled' => in_array('cp', $context['admin_features']),
94
				'permission' => 'admin_forum'
95
			),
96
			'profileedit' => array(
97
				'controller' => $this,
98
				'function' => 'action_profileedit',
99
				'permission' => 'admin_forum'
100
			),
101
		);
102
103
		// Set up the action control
104
		$action = new Action('modify_features');
105
106
		// Load up all the tabs...
107
		$context[$context['admin_menu_name']]['tab_data'] = array(
108
			'title' => $txt['modSettings_title'],
109
			'help' => 'featuresettings',
110
			'description' => sprintf($txt['modSettings_desc'], $scripturl . '?action=admin;area=theme;sa=list;th=' . $settings['theme_id'] . ';' . $context['session_id'] . '=' . $context['session_var']),
111
			'tabs' => array(
112
				'basic' => array(
113
				),
114
				'layout' => array(
115
				),
116
				'pmsettings' => array(
117
				),
118
				'karma' => array(
119
				),
120
				'likes' => array(
121
				),
122
				'mention' => array(
123
					'description' => $txt['mentions_settings_desc'],
124
				),
125
				'sig' => array(
126
					'description' => $txt['signature_settings_desc'],
127
				),
128
				'profile' => array(
129
					'description' => $txt['custom_profile_desc'],
130
				),
131
			),
132
		);
133
134
		// By default do the basic settings, call integrate_sa_modify_features
135
		$subAction = $action->initialize($subActions, 'basic');
136
137
		// Some final pieces for the template
138
		$context['sub_template'] = 'show_settings';
139
		$context['sub_action'] = $subAction;
140
		$context['page_title'] = $txt['modSettings_title'];
141
142
		// Call the right function for this sub-action.
143
		$action->dispatch($subAction);
144
	}
145
146
	/**
147
	 * Config array for changing the basic forum settings
148
	 *
149
	 * - Accessed from ?action=admin;area=featuresettings;sa=basic;
150
	 */
151
	public function action_basicSettings_display()
152
	{
153
		global $txt, $scripturl, $context;
154
155
		// Initialize the form
156
		$settingsForm = new Settings_Form(Settings_Form::DB_ADAPTER);
157
158
		// Initialize it with our settings
159
		$settingsForm->setConfigVars($this->_basicSettings());
160
161
		// Saving?
162
		if (isset($this->_req->query->save))
163
		{
164
			checkSession();
165
166
			// Prevent absurd boundaries here - make it a day tops.
167
			if (isset($this->_req->post->lastActive))
168
				$this->_req->post->lastActive = min((int) $this->_req->post->lastActive, 1440);
169
170
			call_integration_hook('integrate_save_basic_settings');
171
172
			$settingsForm->setConfigValues((array) $this->_req->post);
173
			$settingsForm->save();
174
175
			writeLog();
176
			redirectexit('action=admin;area=featuresettings;sa=basic');
177
		}
178
		if (isset($this->_req->post->cleanhives))
179
		{
180
			$clean_hives_result = theme()->cleanHives();
181
182
			Template_Layers::getInstance()->removeAll();
183
			loadTemplate('Json');
184
			addJavascriptVar(array('txt_invalid_response' => $txt['ajax_bad_response']), true);
185
			$context['sub_template'] = 'send_json';
186
			$context['json_data'] = array(
187
				'success' => $clean_hives_result,
188
				'response' => $clean_hives_result ? $txt['clean_hives_sucess'] : $txt['clean_hives_failed']
189
			);
190
			return;
191
		}
192
193
		$context['post_url'] = $scripturl . '?action=admin;area=featuresettings;save;sa=basic';
194
		$context['settings_title'] = $txt['mods_cat_features'];
195
196
		// Show / hide custom jquery fields as required
197
		addInlineJavascript('showhideJqueryOptions();', true);
198
199
		$settingsForm->prepare();
200
	}
201
202
	/**
203
	 * Allows modifying the global layout settings in the forum
204
	 *
205
	 * - Accessed through ?action=admin;area=featuresettings;sa=layout;
206
	 */
207
	public function action_layoutSettings_display()
208
	{
209
		global $txt, $scripturl, $context, $modSettings;
210
211
		// Initialize the form
212
		$settingsForm = new Settings_Form(Settings_Form::DB_ADAPTER);
213
214
		// Initialize it with our settings
215
		$settingsForm->setConfigVars($this->_layoutSettings());
216
217
		// Saving?
218
		if (isset($this->_req->query->save))
219
		{
220
			// Setting a custom frontpage, set the hook to the FrontpageInterface of the controller
221
			if (!empty($this->_req->post->front_page))
222
			{
223
				$front_page = (string) $this->_req->post->front_page;
224
				if (
225
					is_callable(array($modSettings['front_page'], 'validateFrontPageOptions'))
226
					&& !$front_page::validateFrontPageOptions($this->_req->post)
227
				) {
228
					$this->_req->post->front_page = '';
229
				}
230
			}
231
232
			checkSession();
233
234
			call_integration_hook('integrate_save_layout_settings');
235
236
			$settingsForm->setConfigValues((array) $this->_req->post);
237
			$settingsForm->save();
238
			writeLog();
239
240
			redirectexit('action=admin;area=featuresettings;sa=layout');
241
		}
242
243
		$context['post_url'] = $scripturl . '?action=admin;area=featuresettings;save;sa=layout';
244
		$context['settings_title'] = $txt['mods_cat_layout'];
245
246
		$settingsForm->prepare();
247
	}
248
249
	/**
250
	 * Display configuration settings page for karma settings.
251
	 *
252
	 * - Accessed from ?action=admin;area=featuresettings;sa=karma;
253
	 */
254 View Code Duplication
	public function action_karmaSettings_display()
255
	{
256
		global $txt, $scripturl, $context;
257
258
		// Initialize the form
259
		$settingsForm = new Settings_Form(Settings_Form::DB_ADAPTER);
260
261
		// Initialize it with our settings
262
		$settingsForm->setConfigVars($this->_karmaSettings());
263
264
		// Saving?
265
		if (isset($this->_req->query->save))
266
		{
267
			checkSession();
268
269
			call_integration_hook('integrate_save_karma_settings');
270
271
			$settingsForm->setConfigValues((array) $this->_req->post);
272
			$settingsForm->save();
273
			redirectexit('action=admin;area=featuresettings;sa=karma');
274
		}
275
276
		$context['post_url'] = $scripturl . '?action=admin;area=featuresettings;save;sa=karma';
277
		$context['settings_title'] = $txt['karma'];
278
279
		$settingsForm->prepare();
280
	}
281
282
	/**
283
	 * Display configuration settings page for likes settings.
284
	 *
285
	 * - Accessed from ?action=admin;area=featuresettings;sa=likes;
286
	 */
287 View Code Duplication
	public function action_likesSettings_display()
288
	{
289
		global $txt, $scripturl, $context;
290
291
		// Initialize the form
292
		$settingsForm = new Settings_Form(Settings_Form::DB_ADAPTER);
293
294
		// Initialize it with our settings
295
		$settingsForm->setConfigVars($this->_likesSettings());
296
297
		// Saving?
298
		if (isset($this->_req->query->save))
299
		{
300
			checkSession();
301
302
			call_integration_hook('integrate_save_likes_settings');
303
304
			$settingsForm->setConfigValues((array) $this->_req->post);
305
			$settingsForm->save();
306
			redirectexit('action=admin;area=featuresettings;sa=likes');
307
		}
308
309
		$context['post_url'] = $scripturl . '?action=admin;area=featuresettings;save;sa=likes';
310
		$context['settings_title'] = $txt['likes'];
311
312
		$settingsForm->prepare();
313
	}
314
315
	/**
316
	 * Initializes the mentions settings admin page.
317
	 *
318
	 * - Accessed from ?action=admin;area=featuresettings;sa=mention;
319
	 */
320
	public function action_notificationsSettings_display()
321
	{
322
		global $txt, $context, $scripturl, $modSettings;
323
324
		loadLanguage('Mentions');
325
326
		// Instantiate the form
327
		$settingsForm = new Settings_Form(Settings_Form::DB_ADAPTER);
328
329
		// Initialize it with our settings
330
		$settingsForm->setConfigVars($this->_notificationsSettings());
331
332
		// Some context stuff
333
		$context['page_title'] = $txt['mentions_settings'];
334
		$context['sub_template'] = 'show_settings';
335
336
		// Saving the settings?
337
		if (isset($this->_req->query->save))
338
		{
339
			checkSession();
340
341
			call_integration_hook('integrate_save_modify_mention_settings');
342
343
			if (empty($this->_req->post->notifications))
344
			{
345
				$notification_methods = serialize(array());
346
			}
347
			else
348
			{
349
				$notification_methods = serialize($this->_req->post->notifications);
350
			}
351
352
			require_once(SUBSDIR . '/Mentions.subs.php');
353
			$enabled_mentions = array();
354
			$current_settings = unserialize($modSettings['notification_methods']);
355
356
			// Fist hide what was visible
357
			$modules_toggle = array('enable' => array(), 'disable' => array());
358 View Code Duplication
			foreach ($current_settings as $type => $val)
359
			{
360
				if (!isset($this->_req->post->notifications[$type]))
361
				{
362
					toggleMentionsVisibility($type, false);
363
					$modules_toggle['disable'][] = $type;
364
				}
365
			}
366
367
			// Then make visible what was hidden, but only if there is anything
368
			if (!empty($this->_req->post->notifications))
369
			{
370 View Code Duplication
				foreach ($this->_req->post->notifications as $type => $val)
371
				{
372
					if (!isset($current_settings[$type]))
373
					{
374
						toggleMentionsVisibility($type, true);
375
						$modules_toggle['enable'][] = $type;
376
					}
377
				}
378
379
				$enabled_mentions = array_keys($this->_req->post->notifications);
380
			}
381
382
			// Let's just keep it active, there are too many reasons it should be.
383
			require_once(SUBSDIR . '/ScheduledTasks.subs.php');
384
			toggleTaskStatusByName('user_access_mentions', true);
385
386
			// Disable or enable modules as needed
387
			foreach ($modules_toggle as $action => $toggles)
388
			{
389
				if (!empty($toggles))
390
				{
391
					// The modules associated with the notification (mentionmem, likes, etc) area
392
					$modules = getMentionsModules($toggles);
393
394
					// The action will either be enable to disable
395
					$function = $action . 'Modules';
396
397
					// Something like enableModule('mentions', array('post', 'display');
398
					foreach ($modules as $key => $val)
399
						$function($key, $val);
400
				}
401
			}
402
403
			updateSettings(array('enabled_mentions' => implode(',', array_unique($enabled_mentions)), 'notification_methods' => $notification_methods));
404
			$settingsForm->setConfigValues((array) $this->_req->post);
405
			$settingsForm->save();
406
			redirectexit('action=admin;area=featuresettings;sa=mention');
407
		}
408
409
		// Prepare the settings for display
410
		$context['post_url'] = $scripturl . '?action=admin;area=featuresettings;save;sa=mention';
411
		$settingsForm->prepare();
412
	}
413
414
	/**
415
	 * Display configuration settings for signatures on forum.
416
	 *
417
	 * - Accessed from ?action=admin;area=featuresettings;sa=sig;
418
	 */
419
	public function action_signatureSettings_display()
420
	{
421
		global $context, $txt, $modSettings, $sig_start, $scripturl;
422
423
		// Initialize the form
424
		$settingsForm = new Settings_Form(Settings_Form::DB_ADAPTER);
425
426
		// Initialize it with our settings
427
		$settingsForm->setConfigVars($this->_signatureSettings());
428
429
		// Setup the template.
430
		$context['page_title'] = $txt['signature_settings'];
431
		$context['sub_template'] = 'show_settings';
432
433
		// Disable the max smileys option if we don't allow smileys at all!
434
		addInlineJavascript('
435
			document.getElementById(\'signature_max_smileys\').disabled = !document.getElementById(\'signature_allow_smileys\').checked;', true);
436
437
		// Load all the signature settings.
438
		list ($sig_limits, $sig_bbc) = explode(':', $modSettings['signature_settings']);
439
		$sig_limits = explode(',', $sig_limits);
440
		$disabledTags = !empty($sig_bbc) ? explode(',', $sig_bbc) : array();
441
442
		// @todo temporary since it does not work, and seriously why would you do this?
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
443
		$disabledTags[] = 'footnote';
444
445
		// Applying to ALL signatures?!!
446
		if (isset($this->_req->query->apply))
447
		{
448
			// Security!
449
			checkSession('get');
450
451
			$sig_start = time();
452
453
			// This is horrid - but I suppose some people will want the option to do it.
454
			$applied_sigs = $this->_req->getQuery('step', 'intval', 0);
455
			updateAllSignatures($applied_sigs);
456
457
			$settings_applied = true;
458
		}
459
460
		$context['signature_settings'] = array(
461
			'enable' => isset($sig_limits[0]) ? $sig_limits[0] : 0,
462
			'max_length' => isset($sig_limits[1]) ? $sig_limits[1] : 0,
463
			'max_lines' => isset($sig_limits[2]) ? $sig_limits[2] : 0,
464
			'max_images' => isset($sig_limits[3]) ? $sig_limits[3] : 0,
465
			'allow_smileys' => isset($sig_limits[4]) && $sig_limits[4] == -1 ? 0 : 1,
466
			'max_smileys' => isset($sig_limits[4]) && $sig_limits[4] != -1 ? $sig_limits[4] : 0,
467
			'max_image_width' => isset($sig_limits[5]) ? $sig_limits[5] : 0,
468
			'max_image_height' => isset($sig_limits[6]) ? $sig_limits[6] : 0,
469
			'max_font_size' => isset($sig_limits[7]) ? $sig_limits[7] : 0,
470
			'repetition_guests' => isset($sig_limits[8]) ? $sig_limits[8] : 0,
471
			'repetition_members' => isset($sig_limits[9]) ? $sig_limits[9] : 0,
472
		);
473
474
		// Temporarily make each setting a modSetting!
475
		foreach ($context['signature_settings'] as $key => $value)
476
			$modSettings['signature_' . $key] = $value;
477
478
		// Make sure we check the right tags!
479
		$modSettings['bbc_disabled_signature_bbc'] = $disabledTags;
480
481
		// Saving?
482
		if (isset($this->_req->query->save))
483
		{
484
			checkSession();
485
486
			// Clean up the tag stuff!
487
			$codes = \BBC\ParserWrapper::getInstance()->getCodes();
488
			$bbcTags = $codes->getTags();
489
490 View Code Duplication
			if (!isset($this->_req->post->signature_bbc_enabledTags))
491
				$this->_req->post->signature_bbc_enabledTags = array();
492
			elseif (!is_array($this->_req->post->signature_bbc_enabledTags))
493
				$this->_req->post->signature_bbc_enabledTags = array($this->_req->post->signature_bbc_enabledTags);
494
495
			$sig_limits = array();
496
			foreach ($context['signature_settings'] as $key => $value)
497
			{
498
				if ($key == 'allow_smileys')
499
					continue;
500
				elseif ($key == 'max_smileys' && empty($this->_req->post->signature_allow_smileys))
501
					$sig_limits[] = -1;
502
				else
503
				{
504
					$current_key = $this->_req->getPost('signature_' . $key, 'intval');
505
					$sig_limits[] = !empty($current_key) ? max(1, $current_key) : 0;
506
				}
507
			}
508
509
			call_integration_hook('integrate_save_signature_settings', array(&$sig_limits, &$bbcTags));
510
511
			$this->_req->post->signature_settings = implode(',', $sig_limits) . ':' . implode(',', array_diff($bbcTags, $this->_req->post->signature_bbc_enabledTags));
512
513
			// Even though we have practically no settings let's keep the convention going!
514
			$save_vars = array();
515
			$save_vars[] = array('text', 'signature_settings');
516
517
			$settingsForm->setConfigVars($save_vars);
518
			$settingsForm->setConfigValues((array) $this->_req->post);
519
			$settingsForm->save();
520
			redirectexit('action=admin;area=featuresettings;sa=sig');
521
		}
522
523
		$context['post_url'] = $scripturl . '?action=admin;area=featuresettings;save;sa=sig';
524
		$context['settings_title'] = $txt['signature_settings'];
525
		$context['settings_message'] = !empty($settings_applied) ? $txt['signature_settings_applied'] : sprintf($txt['signature_settings_warning'], $scripturl . '?action=admin;area=featuresettings;sa=sig;apply;' . $context['session_var'] . '=' . $context['session_id']);
526
527
		$settingsForm->prepare();
528
	}
529
530
	/**
531
	 * Show all the custom profile fields available to the user.
532
	 *
533
	 * - Allows for drag/drop sorting of custom profile fields
534
	 * - Accessed with ?action=admin;area=featuresettings;sa=profile
535
	 *
536
	 * @uses sub template show_custom_profile
537
	 */
538 2
	public function action_profile()
539
	{
540
		global $txt, $scripturl, $context;
541
542
		loadTemplate('ManageFeatures');
543
		$context['page_title'] = $txt['custom_profile_title'];
544
		$context['sub_template'] = 'show_custom_profile';
545
546
		// What about standard fields they can tweak?
547
		$standard_fields = array('website', 'posts', 'warning_status', 'date_registered');
548
549
		// What fields can't you put on the registration page?
550
		$context['fields_no_registration'] = array('posts', 'warning_status', 'date_registered');
551
552
		// Are we saving any standard field changes?
553
		if (isset($this->_req->post->save))
554
		{
555
			checkSession();
556
			validateToken('admin-scp');
557
558
			$changes = array();
559
560
			// Do the active ones first.
561
			$disable_fields = array_flip($standard_fields);
562
			if (!empty($this->_req->post->active))
563
			{
564
				foreach ($this->_req->post->active as $value)
565
				{
566
					if (isset($disable_fields[$value]))
567
					{
568
						unset($disable_fields[$value]);
569
					}
570
				}
571
			}
572
573
			// What we have left!
574
			$changes['disabled_profile_fields'] = empty($disable_fields) ? '' : implode(',', array_keys($disable_fields));
575
576
			// Things we want to show on registration?
577
			$reg_fields = array();
578
			if (!empty($this->_req->post->reg))
579
			{
580
				foreach ($this->_req->post->reg as $value)
581
				{
582
					if (in_array($value, $standard_fields) && !isset($disable_fields[$value]))
583
						$reg_fields[] = $value;
584
				}
585
			}
586
587
			// What we have left!
588
			$changes['registration_fields'] = empty($reg_fields) ? '' : implode(',', $reg_fields);
589
590
			if (!empty($changes))
591
				updateSettings($changes);
592
		}
593
594
		createToken('admin-scp');
595
596
		// Create a listing for all our standard fields
597
		$listOptions = array(
598
			'id' => 'standard_profile_fields',
599
			'title' => $txt['standard_profile_title'],
600
			'base_href' => $scripturl . '?action=admin;area=featuresettings;sa=profile',
601
			'get_items' => array(
602
				'function' => 'list_getProfileFields',
603
				'params' => array(
604
					true,
605
				),
606
			),
607
			'columns' => array(
608
				'field' => array(
609
					'header' => array(
610
						'value' => $txt['standard_profile_field'],
611
					),
612
					'data' => array(
613
						'db' => 'label',
614
						'style' => 'width: 60%;',
615
					),
616
				),
617
				'active' => array(
618
					'header' => array(
619
						'value' => $txt['custom_edit_active'],
620
						'class' => 'centertext',
621
					),
622
					'data' => array(
623 View Code Duplication
						'function' => function ($rowData) {
624
							$isChecked = $rowData['disabled'] ? '' : ' checked="checked"';
625
							$onClickHandler = $rowData['can_show_register'] ? sprintf('onclick="document.getElementById(\'reg_%1$s\').disabled = !this.checked;"', $rowData['id']) : '';
626
							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);
627
						},
628
						'style' => 'width: 20%;',
629
						'class' => 'centertext',
630
					),
631
				),
632
				'show_on_registration' => array(
633
					'header' => array(
634
						'value' => $txt['custom_edit_registration'],
635
						'class' => 'centertext',
636
					),
637
					'data' => array(
638 View Code Duplication
						'function' => function ($rowData) {
639
							$isChecked = $rowData['on_register'] && !$rowData['disabled'] ? ' checked="checked"' : '';
640
							$isDisabled = $rowData['can_show_register'] ? '' : ' disabled="disabled"';
641
							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);
642
						},
643
						'style' => 'width: 20%;',
644
						'class' => 'centertext',
645
					),
646
				),
647
			),
648
			'form' => array(
649
				'href' => $scripturl . '?action=admin;area=featuresettings;sa=profile',
650
				'name' => 'standardProfileFields',
651
				'token' => 'admin-scp',
652
			),
653
			'additional_rows' => array(
654
				array(
655
					'position' => 'below_table_data',
656
					'value' => '<input type="submit" name="save" value="' . $txt['save'] . '" class="right_submit" />',
657
				),
658
			),
659
		);
660
		createList($listOptions);
661
662
		// And now we do the same for all of our custom ones
663
		$token = createToken('admin-sort');
664
		$listOptions = array(
665
			'id' => 'custom_profile_fields',
666
			'title' => $txt['custom_profile_title'],
667
			'base_href' => $scripturl . '?action=admin;area=featuresettings;sa=profile',
668
			'default_sort_col' => 'vieworder',
669
			'no_items_label' => $txt['custom_profile_none'],
670
			'items_per_page' => 25,
671
			'sortable' => true,
672
			'get_items' => array(
673
				'function' => 'list_getProfileFields',
674
				'params' => array(
675
					false,
676
				),
677
			),
678
			'get_count' => array(
679
				'function' => 'list_getProfileFieldSize',
680
			),
681
			'columns' => array(
682
				'vieworder' => array(
683
					'header' => array(
684
						'value' => '',
685
						'class' => 'hide',
686
					),
687
					'data' => array(
688
						'db' => 'vieworder',
689
						'class' => 'hide',
690
					),
691
					'sort' => array(
692
						'default' => 'vieworder',
693
					),
694
				),
695
				'field_name' => array(
696
					'header' => array(
697
						'value' => $txt['custom_profile_fieldname'],
698
					),
699
					'data' => array(
700
						'function' => function ($rowData) {
701
							global $scripturl;
702
703
							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']);
704
						},
705
						'style' => 'width: 65%;',
706
					),
707
					'sort' => array(
708
						'default' => 'field_name',
709
						'reverse' => 'field_name DESC',
710
					),
711
				),
712
				'field_type' => array(
713
					'header' => array(
714
						'value' => $txt['custom_profile_fieldtype'],
715
					),
716
					'data' => array(
717
						'function' => function ($rowData) {
718
							global $txt;
719
720
							$textKey = sprintf('custom_profile_type_%1$s', $rowData['field_type']);
721
							return isset($txt[$textKey]) ? $txt[$textKey] : $textKey;
722
						},
723
						'style' => 'width: 10%;',
724
					),
725
					'sort' => array(
726
						'default' => 'field_type',
727
						'reverse' => 'field_type DESC',
728
					),
729
				),
730
				'cust' => array(
731
					'header' => array(
732
						'value' => $txt['custom_profile_active'],
733
						'class' => 'centertext',
734
					),
735
					'data' => array(
736
						'function' => function ($rowData) {
737
							$isChecked = $rowData['active'] ? ' checked="checked"' : '';
738
							return sprintf('<input type="checkbox" name="cust[]" id="cust_%1$s" value="%1$s" class="input_check"%2$s />', $rowData['id_field'], $isChecked);
739
						},
740
						'style' => 'width: 8%;',
741
						'class' => 'centertext',
742
					),
743
					'sort' => array(
744
						'default' => 'active DESC',
745
						'reverse' => 'active',
746
					),
747
				),
748
				'placement' => array(
749
					'header' => array(
750
						'value' => $txt['custom_profile_placement'],
751
					),
752
					'data' => array(
753 2
						'function' => function ($rowData) {
754
							global $txt;
755
							$placement = 'custom_profile_placement_';
756
757
							switch ((int) $rowData['placement'])
758
							{
759
								case 0:
760
									$placement .= 'standard';
761
									break;
762
								case 1:
763
									$placement .= 'withicons';
764
									break;
765
								case 2:
766 2
									$placement .= 'abovesignature';
767
									break;
768
								case 3:
769
									$placement .= 'aboveicons';
770
									break;
771
							}
772
773
							return $txt[$placement];
774
						},
775
						'style' => 'width: 5%;',
776
					),
777
					'sort' => array(
778
						'default' => 'placement DESC',
779
						'reverse' => 'placement',
780
					),
781
				),
782
				'show_on_registration' => array(
783
					'data' => array(
784
						'sprintf' => array(
785
							'format' => '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=%1$s">' . $txt['modify'] . '</a>',
786
							'params' => array(
787
								'id_field' => false,
788
							),
789
						),
790
						'style' => 'width: 5%;',
791
					),
792
				),
793
			),
794
			'form' => array(
795
				'href' => $scripturl . '?action=admin;area=featuresettings;sa=profileedit',
796
				'name' => 'customProfileFields',
797
				'token' => 'admin-scp',
798
			),
799
			'additional_rows' => array(
800
				array(
801
					'class' => 'submitbutton',
802
					'position' => 'below_table_data',
803
					'value' => '<input type="submit" name="onoff" value="' . $txt['save'] . '" class="right_submit" />
804
					<input type="submit" name="new" value="' . $txt['custom_profile_make_new'] . '" class="right_submit" />',
805
				),
806
				array(
807
					'position' => 'top_of_list',
808
					'value' => '<p class="infobox">' . $txt['custom_profile_sort'] . '</p>',
809
				),
810
			),
811
			'javascript' => '
812
				$().elkSortable({
813
					sa: "profileorder",
814
					error: "' . $txt['admin_order_error'] . '",
815
					title: "' . $txt['admin_order_title'] . '",
816
					placeholder: "ui-state-highlight",
817
					href: "?action=admin;area=featuresettings;sa=profile",
818
					token: {token_var: "' . $token['admin-sort_token_var'] . '", token_id: "' . $token['admin-sort_token'] . '"}
819
				});
820
			',
821
		);
822
823
		createList($listOptions);
824
	}
825
826
	/**
827
	 * Edit some profile fields?
828
	 *
829
	 * - Accessed with ?action=admin;area=featuresettings;sa=profileedit
830
	 *
831
	 * @uses sub template edit_profile_field
832
	 */
833
	public function action_profileedit()
834
	{
835
		global $txt, $scripturl, $context;
836
837
		loadTemplate('ManageFeatures');
838
839
		// Sort out the context!
840
		$context['fid'] = $this->_req->getQuery('fid', 'intval', 0);
841
		$context[$context['admin_menu_name']]['current_subsection'] = 'profile';
842
		$context['page_title'] = $context['fid'] ? $txt['custom_edit_title'] : $txt['custom_add_title'];
843
		$context['sub_template'] = 'edit_profile_field';
844
845
		// Any errors messages to show?
846
		if (isset($this->_req->query->msg))
847
		{
848
			loadLanguage('Errors');
849
850
			if (isset($txt['custom_option_' . $this->_req->query->msg]))
851
				$context['custom_option__error'] = $txt['custom_option_' . $this->_req->query->msg];
852
		}
853
854
		// Load the profile language for section names.
855
		loadLanguage('Profile');
856
857
		// Load up the profile field, if one was supplied
858
		if ($context['fid'])
859
			$context['field'] = getProfileField($context['fid']);
860
861
		// Setup the default values as needed.
862
		if (empty($context['field']))
863
			$context['field'] = array(
864
				'name' => '',
865
				'colname' => '???',
866
				'desc' => '',
867
				'profile_area' => 'forumprofile',
868
				'reg' => false,
869
				'display' => false,
870
				'memberlist' => false,
871
				'type' => 'text',
872
				'max_length' => 255,
873
				'rows' => 4,
874
				'cols' => 30,
875
				'bbc' => false,
876
				'default_check' => false,
877
				'default_select' => '',
878
				'default_value' => '',
879
				'options' => array('', '', ''),
880
				'active' => true,
881
				'private' => false,
882
				'can_search' => false,
883
				'mask' => 'nohtml',
884
				'regex' => '',
885
				'enclose' => '',
886
				'placement' => 0,
887
			);
888
889
		// All the javascript for this page... everything else is in admin.js
890
		addJavascriptVar(array('startOptID' => count($context['field']['options'])));
891
		addInlineJavascript('updateInputBoxes();', true);
892
893
		// Are we toggling which ones are active?
894
		if (isset($this->_req->post->onoff))
895
		{
896
			checkSession();
897
			validateToken('admin-scp');
898
899
			// Enable and disable custom fields as required.
900
			$enabled = array(0);
901
			if(isset($this->_req->post->cust) && is_array($this->_req->post->cust)) {
902
				foreach ($this->_req->post->cust as $id)
903
					$enabled[] = (int) $id;
904
			}
905
906
			updateRenamedProfileStatus($enabled);
907
		}
908
		// Are we saving?
909
		elseif (isset($this->_req->post->save))
910
		{
911
			checkSession();
912
			validateToken('admin-ecp');
913
914
			// Everyone needs a name - even the (bracket) unknown...
915
			if (trim($this->_req->post->field_name) == '')
916
				redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $this->_req->query->fid . ';msg=need_name');
917
918
			// Regex you say?  Do a very basic test to see if the pattern is valid
919
			if (!empty($this->_req->post->regex) && @preg_match($this->_req->post->regex, 'dummy') === false)
920
				redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $this->_req->query->fid . ';msg=regex_error');
921
922
			$this->_req->post->field_name = $this->_req->getPost('field_name', 'Util::htmlspecialchars');
923
			$this->_req->post->field_desc = $this->_req->getPost('field_desc', 'Util::htmlspecialchars');
924
925
			$rows = isset($this->_req->post->rows) ? (int) $this->_req->post->rows : 4;
926
			$cols = isset($this->_req->post->cols) ? (int) $this->_req->post->cols : 30;
927
928
			// Checkboxes...
929
			$show_reg = $this->_req->getPost('reg', 'intval', 0);
930
			$show_display = isset($this->_req->post->display) ? 1 : 0;
931
			$show_memberlist = isset($this->_req->post->memberlist) ? 1 : 0;
932
			$bbc = isset($this->_req->post->bbc) ? 1 : 0;
933
			$show_profile = $this->_req->post->profile_area;
934
			$active = isset($this->_req->post->active) ? 1 : 0;
935
			$private = $this->_req->getPost('private', 'intval', 0);
936
			$can_search = isset($this->_req->post->can_search) ? 1 : 0;
937
938
			// Some masking stuff...
939
			$mask = $this->_req->getPost('mask', 'strval', '');
940
			if ($mask == 'regex' && isset($this->_req->post->regex))
941
				$mask .= $this->_req->post->regex;
942
943
			$field_length = $this->_req->getPost('max_length', 'intval', 255);
944
			$enclose = $this->_req->getPost('enclose', 'strval', '');
945
			$placement = $this->_req->getPost('placement', 'intval', 0);
946
947
			// Select options?
948
			$field_options = '';
949
			$newOptions = array();
950
951
			// Set default
952
			$default = '';
953
954
			switch ($this->_req->post->field_type)
955
			{
956
				case 'check':
957
					$default = isset($this->_req->post->default_check) ? 1 : '';
958
					break;
959
				case 'select':
960
				case 'radio':
961
					if (!empty($this->_req->post->select_option))
962
					{
963
						foreach ($this->_req->post->select_option as $k => $v)
964
						{
965
							// Clean, clean, clean...
966
							$v = Util::htmlspecialchars($v);
967
							$v = strtr($v, array(',' => ''));
968
969
							// Nada, zip, etc...
970
							if (trim($v) == '')
971
								continue;
972
973
							// Otherwise, save it boy.
974
							$field_options .= $v . ',';
975
976
							// This is just for working out what happened with old options...
977
							$newOptions[$k] = $v;
978
979
							// Is it default?
980
							if (isset($this->_req->post->default_select) && $this->_req->post->default_select == $k)
981
								$default = $v;
982
						}
983
984
						if (isset($_POST['default_select']) && $_POST['default_select'] == 'no_default')
985
							$default = 'no_default';
986
987
						$field_options = substr($field_options, 0, -1);
988
					}
989
					break;
990
				default:
991
					$default = isset($this->_req->post->default_value) ? $this->_req->post->default_value : '';
992
			}
993
994
			// Text area by default has dimensions
995
//			if ($this->_req->post->field_type == 'textarea')
996
//				$default = (int) $this->_req->post->rows . ',' . (int) $this->_req->post->cols;
997
998
			// Come up with the unique name?
999
			if (empty($context['fid']))
1000
			{
1001
				$colname = Util::substr(strtr($this->_req->post->field_name, array(' ' => '')), 0, 6);
1002
				preg_match('~([\w\d_-]+)~', $colname, $matches);
1003
1004
				// If there is nothing to the name, then let's start our own - for foreign languages etc.
1005
				if (isset($matches[1]))
1006
					$colname = $initial_colname = 'cust_' . strtolower($matches[1]);
1007
				else
1008
					$colname = $initial_colname = 'cust_' . mt_rand(1, 999999);
1009
1010
				$unique = ensureUniqueProfileField($colname, $initial_colname);
1011
1012
				// Still not a unique column name? Leave it up to the user, then.
1013
				if (!$unique)
1014
					throw new Elk_Exception('custom_option_not_unique');
1015
1016
				// And create a new field
1017
				$new_field = array(
1018
					'col_name' => $colname,
1019
					'field_name' => $this->_req->post->field_name,
1020
					'field_desc' => $this->_req->post->field_desc,
1021
					'field_type' => $this->_req->post->field_type,
1022
					'field_length' => $field_length,
1023
					'field_options' => $field_options,
1024
					'show_reg' => $show_reg,
1025
					'show_display' => $show_display,
1026
					'show_memberlist' => $show_memberlist,
1027
					'show_profile' => $show_profile,
1028
					'private' => $private,
1029
					'active' => $active,
1030
					'default_value' => $default,
1031
					'rows' => $rows,
1032
					'cols' => $cols,
1033
					'can_search' => $can_search,
1034
					'bbc' => $bbc,
1035
					'mask' => $mask,
1036
					'enclose' => $enclose,
1037
					'placement' => $placement,
1038
					'vieworder' => list_getProfileFieldSize() + 1,
1039
				);
1040
				addProfileField($new_field);
1041
			}
1042
			// Work out what to do with the user data otherwise...
1043
			else
1044
			{
1045
				// Anything going to check or select is pointless keeping - as is anything coming from check!
1046
				if (($this->_req->post->field_type == 'check' && $context['field']['type'] != 'check')
1047
					|| (($this->_req->post->field_type == 'select' || $this->_req->post->field_type == 'radio') && $context['field']['type'] != 'select' && $context['field']['type'] != 'radio')
1048
					|| ($context['field']['type'] == 'check' && $this->_req->post->field_type != 'check'))
1049
				{
1050
					deleteProfileFieldUserData($context['field']['colname']);
1051
				}
1052
				// Otherwise - if the select is edited may need to adjust!
1053
				elseif ($this->_req->post->field_type == 'select' || $this->_req->post->field_type == 'radio')
1054
				{
1055
					$optionChanges = array();
1056
					$takenKeys = array();
1057
1058
					// Work out what's changed!
1059
					foreach ($context['field']['options'] as $k => $option)
1060
					{
1061
						if (trim($option) == '')
1062
							continue;
1063
1064
						// Still exists?
1065
						if (in_array($option, $newOptions))
1066
						{
1067
							$takenKeys[] = $k;
1068
							continue;
1069
						}
1070
					}
1071
1072
					// Finally - have we renamed it - or is it really gone?
1073
					foreach ($optionChanges as $k => $option)
1074
					{
1075
						// Just been renamed?
1076
						if (!in_array($k, $takenKeys) && !empty($newOptions[$k]))
1077
							updateRenamedProfileField($k, $newOptions, $context['field']['colname'], $option);
1078
					}
1079
				}
1080
				// @todo Maybe we should adjust based on new text length limits?
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
1081
1082
				// And finally update an existing field
1083
				$field_data = array(
1084
					'field_length' => $field_length,
1085
					'show_reg' => $show_reg,
1086
					'show_display' => $show_display,
1087
					'show_memberlist' => $show_memberlist,
1088
					'private' => $private,
1089
					'active' => $active,
1090
					'can_search' => $can_search,
1091
					'bbc' => $bbc,
1092
					'current_field' => $context['fid'],
1093
					'field_name' => $this->_req->post->field_name,
1094
					'field_desc' => $this->_req->post->field_desc,
1095
					'field_type' => $this->_req->post->field_type,
1096
					'field_options' => $field_options,
1097
					'show_profile' => $show_profile,
1098
					'default_value' => $default,
1099
					'mask' => $mask,
1100
					'enclose' => $enclose,
1101
					'placement' => $placement,
1102
					'rows' => $rows,
1103
					'cols' => $cols,
1104
				);
1105
1106
				updateProfileField($field_data);
1107
1108
				// Just clean up any old selects - these are a pain!
1109
				if (($this->_req->post->field_type == 'select' || $this->_req->post->field_type == 'radio') && !empty($newOptions))
1110
					deleteOldProfileFieldSelects($newOptions, $context['field']['colname']);
1111
			}
1112
		}
1113
		// Deleting?
1114
		elseif (isset($this->_req->post->delete) && $context['field']['colname'])
1115
		{
1116
			checkSession();
1117
			validateToken('admin-ecp');
1118
1119
			// Delete the old data first, then the field.
1120
			deleteProfileFieldUserData($context['field']['colname']);
1121
			deleteProfileField($context['fid']);
1122
		}
1123
1124
		// Rebuild display cache etc.
1125
		if (isset($this->_req->post->delete) || isset($this->_req->post->save) || isset($this->_req->post->onoff))
1126
		{
1127
			checkSession();
1128
1129
			// Update the display cache
1130
			updateDisplayCache();
1131
			redirectexit('action=admin;area=featuresettings;sa=profile');
1132
		}
1133
1134
		createToken('admin-ecp');
1135
	}
1136
1137
	/**
1138
	 * Editing personal messages settings
1139
	 *
1140
	 * - Accessed with ?action=admin;area=featuresettings;sa=pmsettings
1141
	 */
1142
	public function action_pmsettings()
1143
	{
1144
		global $txt, $scripturl, $context;
1145
1146
		// Initialize the form
1147
		$settingsForm = new Settings_Form(Settings_Form::DB_ADAPTER);
1148
1149
		// Initialize it with our settings
1150
		$settingsForm->setConfigVars($this->_pmSettings());
1151
1152
		require_once(SUBSDIR . '/PersonalMessage.subs.php');
1153
		loadLanguage('ManageMembers');
1154
1155
		$context['pm_limits'] = loadPMLimits();
1156
1157
		// Saving?
1158
		if (isset($this->_req->query->save))
1159
		{
1160
			checkSession();
1161
1162
			require_once(SUBSDIR . '/Membergroups.subs.php');
1163
			foreach ($context['pm_limits'] as $group_id => $group)
1164
			{
1165
				if (isset($this->_req->post->group[$group_id]) && $this->_req->post->group[$group_id] != $group['max_messages'])
1166
					updateMembergroupProperties(array('current_group' => $group_id, 'max_messages' => $this->_req->post->group[$group_id]));
1167
			}
1168
1169
			call_integration_hook('integrate_save_pmsettings_settings');
1170
1171
			$settingsForm->setConfigValues((array) $this->_req->post);
1172
			$settingsForm->save();
1173
			redirectexit('action=admin;area=featuresettings;sa=pmsettings');
1174
		}
1175
1176
		$context['post_url'] = $scripturl . '?action=admin;area=featuresettings;save;sa=pmsettings';
1177
		$context['settings_title'] = $txt['personal_messages'];
1178
1179
		$settingsForm->prepare();
1180
	}
1181
1182
	/**
1183
	 * Return basic feature settings.
1184
	 */
1185 6
	private function _basicSettings()
1186
	{
1187 6
		global $txt;
1188
1189
		$config_vars = array(
1190
				// Basic stuff, titles, permissions...
1191 6
				array('check', 'allow_guestAccess'),
1192 4
				array('check', 'enable_buddylist'),
1193 4
				array('check', 'allow_editDisplayName'),
1194 4
				array('check', 'allow_hideOnline'),
1195 4
				array('check', 'titlesEnable'),
1196 6
			'',
1197
				// Javascript and CSS options
1198 6
				array('select', 'jquery_source', array('auto' => $txt['jquery_auto'], 'local' => $txt['jquery_local'], 'cdn' => $txt['jquery_cdn'])),
1199 4
				array('check', 'jquery_default', 'onchange' => 'showhideJqueryOptions();'),
1200 6
				array('text', 'jquery_version', 'postinput' => $txt['jquery_custom_after']),
1201 4
				array('check', 'jqueryui_default', 'onchange' => 'showhideJqueryOptions();'),
1202 6
				array('text', 'jqueryui_version', 'postinput' => $txt['jqueryui_custom_after']),
1203 6
				array('check', 'minify_css_js', 'postinput' => '<a href="#" id="clean_hives" class="linkbutton">' . $txt['clean_hives'] . '</a>'),
1204 6
			'',
1205
				// Number formatting, timezones.
1206 4
				array('text', 'time_format'),
1207 6
				array('float', 'time_offset', 'subtext' => $txt['setting_time_offset_note'], 6, 'postinput' => $txt['hours']),
1208 4
				'default_timezone' => array('select', 'default_timezone', array()),
1209 6
			'',
1210
				// Who's online?
1211 4
				array('check', 'who_enabled'),
1212 6
				array('int', 'lastActive', 6, 'postinput' => $txt['minutes']),
1213 6
			'',
1214
				// Statistics.
1215 4
				array('check', 'trackStats'),
1216 4
				array('check', 'hitStats'),
1217 6
			'',
1218
				// Option-ish things... miscellaneous sorta.
1219 4
				array('check', 'allow_disableAnnounce'),
1220 4
				array('check', 'disallow_sendBody'),
1221 6
				array('select', 'enable_contactform', array('disabled' => $txt['contact_form_disabled'], 'registration' => $txt['contact_form_registration'], 'menu' => $txt['contact_form_menu'])),
1222 4
		);
1223
1224
		// Get all the time zones.
1225 6
		$all_zones = timezone_identifiers_list();
1226 6
		if ($all_zones === false)
1227 4
			unset($config_vars['default_timezone']);
1228
		else
1229
		{
1230
			// Make sure we set the value to the same as the printed value.
1231 6
			foreach ($all_zones as $zone)
1232 6
				$config_vars['default_timezone'][2][$zone] = $zone;
1233
		}
1234
1235 6
		call_integration_hook('integrate_modify_basic_settings', array(&$config_vars));
1236
1237 6
		return $config_vars;
1238
	}
1239
1240
	/**
1241
	 * Public method to return the basic settings, used for admin search
1242
	 */
1243 6
	public function basicSettings_search()
1244
	{
1245 6
		return $this->_basicSettings();
1246
	}
1247
1248
	/**
1249
	 * Return layout settings.
1250
	 */
1251 6
	private function _layoutSettings()
1252
	{
1253 6
		global $txt;
1254
1255 6
		$config_vars = array_merge(getFrontPageControllers(), array(
1256 6
			'',
1257
				// Pagination stuff.
1258 4
				array('check', 'compactTopicPagesEnable'),
1259 6
				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>')),
1260 4
				array('int', 'defaultMaxMembers'),
1261 4
				array('check', 'displayMemberNames'),
1262 6
			'',
1263
				// Stuff that just is everywhere - today, search, online, etc.
1264 6
				array('select', 'todayMod', array($txt['today_disabled'], $txt['today_only'], $txt['yesterday_today'], $txt['relative_time'])),
1265 4
				array('check', 'onlineEnable'),
1266 4
				array('check', 'enableVBStyleLogin'),
1267 6
			'',
1268
				// Automagic image resizing.
1269 6
				array('int', 'max_image_width', 'subtext' => $txt['zero_for_no_limit']),
1270 6
				array('int', 'max_image_height', 'subtext' => $txt['zero_for_no_limit']),
1271 6
			'',
1272
				// This is like debugging sorta.
1273 4
				array('check', 'timeLoadPageEnable'),
1274 4
		));
1275
1276 6
		call_integration_hook('integrate_modify_layout_settings', array(&$config_vars));
1277
1278 6
		return $config_vars;
1279
	}
1280
1281
	/**
1282
	 * Public method to return the layout settings, used for admin search
1283
	 */
1284 6
	public function layoutSettings_search()
1285
	{
1286 6
		return $this->_layoutSettings();
1287
	}
1288
1289
	/**
1290
	 * Return karma settings.
1291
	 */
1292 6
	private function _karmaSettings()
1293
	{
1294 6
		global $txt;
1295
1296
		$config_vars = array(
1297
				// Karma - On or off?
1298 6
				array('select', 'karmaMode', explode('|', $txt['karma_options'])),
1299 6
			'',
1300
				// Who can do it.... and who is restricted by time limits?
1301 6
				array('int', 'karmaMinPosts', 6, 'postinput' => $txt['manageposts_posts']),
1302 6
				array('float', 'karmaWaitTime', 6, 'postinput' => $txt['hours']),
1303 4
				array('check', 'karmaTimeRestrictAdmins'),
1304 4
				array('check', 'karmaDisableSmite'),
1305 6
			'',
1306
				// What does it look like?  [smite]?
1307 4
				array('text', 'karmaLabel'),
1308 4
				array('text', 'karmaApplaudLabel', 'mask' => 'nohtml'),
1309 4
				array('text', 'karmaSmiteLabel', 'mask' => 'nohtml'),
1310 4
		);
1311
1312 6
		call_integration_hook('integrate_modify_karma_settings', array(&$config_vars));
1313
1314 6
		return $config_vars;
1315
	}
1316
1317
	/**
1318
	 * Public method to return the karma settings, used for admin search
1319
	 */
1320 6
	public function karmaSettings_search()
1321
	{
1322 6
		return $this->_karmaSettings();
1323
	}
1324
1325
	/**
1326
	 * Return likes settings.
1327
	 */
1328 6
	private function _likesSettings()
1329
	{
1330 6
		global $txt;
1331
1332
		$config_vars = array(
1333
				// Likes - On or off?
1334 6
				array('check', 'likes_enabled'),
1335 6
			'',
1336
				// Who can do it.... and who is restricted by count limits?
1337 6
				array('int', 'likeMinPosts', 6, 'postinput' => $txt['manageposts_posts']),
1338 6
				array('int', 'likeWaitTime', 6, 'postinput' => $txt['minutes']),
1339 4
				array('int', 'likeWaitCount', 6),
1340 4
				array('check', 'likeRestrictAdmins'),
1341 4
				array('check', 'likeAllowSelf'),
1342 6
			'',
1343 4
				array('int', 'likeDisplayLimit', 6)
1344 4
		);
1345
1346 6
		call_integration_hook('integrate_modify_likes_settings', array(&$config_vars));
1347
1348 6
		return $config_vars;
1349
	}
1350
1351
	/**
1352
	 * Public method to return the likes settings, used for admin search
1353
	 */
1354 6
	public function likesSettings_search()
1355
	{
1356 6
		return $this->_likesSettings();
1357
	}
1358
1359
	/**
1360
	 * Return mentions settings.
1361
	 */
1362 6
	private function _notificationsSettings()
1363
	{
1364 6
		global $txt, $modSettings;
1365
1366 6
		loadLanguage('Profile');
1367 6
		loadLanguage('UserNotifications');
1368
1369
		// The mentions settings
1370
		$config_vars = array(
1371 6
			array('title', 'mentions_settings'),
1372 4
			array('check', 'mentions_enabled'),
1373 4
		);
1374
1375 6
		$notification_methods = Notifications::getInstance()->getNotifiers();
1376 6
		$notification_types = getNotificationTypes();
1377 6
		$current_settings = unserialize($modSettings['notification_methods']);
1378
1379 6
		foreach ($notification_types as $title)
1380
		{
1381 6
			$config_vars[] = array('title', 'setting_' . $title);
1382
1383 6
			foreach ($notification_methods as $method)
1384
			{
1385 6
				if ($method === 'notification')
1386 6
					$text_label = $txt['setting_notify_enable_this'];
1387
				else
1388 6
					$text_label = $txt['notify_' . $method];
1389
1390 6
				$config_vars[] = array('check', 'notifications[' . $title . '][' . $method . ']', 'text_label' => $text_label);
1391 6
				$modSettings['notifications[' . $title . '][' . $method . ']'] = !empty($current_settings[$title][$method]);
1392 4
			}
1393 4
		}
1394
1395 6
		call_integration_hook('integrate_modify_mention_settings', array(&$config_vars));
1396
1397 6
		return $config_vars;
1398
	}
1399
1400
	/**
1401
	 * Public method to return the mention settings, used for admin search
1402
	 */
1403 6
	public function mentionSettings_search()
1404
	{
1405 6
		return $this->_notificationsSettings();
1406
	}
1407
1408
	/**
1409
	 * Return signature settings.
1410
	 *
1411
	 * - Used in admin center search and settings form
1412
	 */
1413 6
	private function _signatureSettings()
1414
	{
1415 6
		global $txt;
1416
1417
		$config_vars = array(
1418
				// Are signatures even enabled?
1419 6
				array('check', 'signature_enable'),
1420 6
			'',
1421
				// Tweaking settings!
1422 6
				array('int', 'signature_max_length', 'subtext' => $txt['zero_for_no_limit']),
1423 6
				array('int', 'signature_max_lines', 'subtext' => $txt['zero_for_no_limit']),
1424 6
				array('int', 'signature_max_font_size', 'subtext' => $txt['zero_for_no_limit']),
1425 4
				array('check', 'signature_allow_smileys', 'onclick' => 'document.getElementById(\'signature_max_smileys\').disabled = !this.checked;'),
1426 6
				array('int', 'signature_max_smileys', 'subtext' => $txt['zero_for_no_limit']),
1427 6
				array('select', 'signature_repetition_guests',
1428
					array(
1429 6
						$txt['signature_always'],
1430 6
						$txt['signature_onlyfirst'],
1431 6
						$txt['signature_never'],
1432 4
					),
1433 4
				),
1434 6
				array('select', 'signature_repetition_members',
1435
					array(
1436 6
						$txt['signature_always'],
1437 6
						$txt['signature_onlyfirst'],
1438 6
						$txt['signature_never'],
1439 4
					),
1440 4
				),
1441 6
			'',
1442
				// Image settings.
1443 6
				array('int', 'signature_max_images', 'subtext' => $txt['signature_max_images_note']),
1444 6
				array('int', 'signature_max_image_width', 'subtext' => $txt['zero_for_no_limit']),
1445 6
				array('int', 'signature_max_image_height', 'subtext' => $txt['zero_for_no_limit']),
1446 6
			'',
1447 4
				array('bbc', 'signature_bbc'),
1448 4
		);
1449
1450 6
		call_integration_hook('integrate_modify_signature_settings', array(&$config_vars));
1451
1452 6
		return $config_vars;
1453
	}
1454
1455
	/**
1456
	 * Public method to return the signature settings, used for admin search
1457
	 */
1458 6
	public function signatureSettings_search()
1459
	{
1460 6
		return $this->_signatureSettings();
1461
	}
1462
1463
	/**
1464
	 * Return pm settings.
1465
	 *
1466
	 * - Used in admin center search and settings form
1467
	 */
1468
	private function _pmSettings()
1469
	{
1470
		global $txt;
1471
1472
		$config_vars = array(
1473
			// Reporting of personal messages?
1474
			array('check', 'enableReportPM'),
1475
			// Inline permissions.
1476
			array('permissions', 'pm_send'),
1477
			// PM Settings
1478
			array('title', 'antispam_PM'),
1479
				'pm1' => array('int', 'max_pm_recipients', 'postinput' => $txt['max_pm_recipients_note']),
1480
				'pm2' => array('int', 'pm_posts_verification', 'postinput' => $txt['pm_posts_verification_note']),
1481
				'pm3' => array('int', 'pm_posts_per_hour', 'postinput' => $txt['pm_posts_per_hour_note']),
1482
			array('title', 'membergroups_max_messages'),
1483
				array('desc', 'membergroups_max_messages_desc'),
1484
				array('callback', 'pm_limits'),
1485
		);
1486
1487
		call_integration_hook('integrate_modify_pmsettings_settings', array(&$config_vars));
1488
1489
		return $config_vars;
1490
	}
1491
}
1492
1493
/**
1494
 * Just pause the signature applying thing.
1495
 *
1496
 * @todo Move to subs file
0 ignored issues
show
Coding Style introduced by
Comment refers to a TODO task

This check looks TODO comments that have been left in the code.

``TODO``s show that something is left unfinished and should be attended to.

Loading history...
1497
 * @todo Merge with other pause functions?
0 ignored issues
show
Coding Style introduced by
Comment refers to a TODO task

This check looks TODO comments that have been left in the code.

``TODO``s show that something is left unfinished and should be attended to.

Loading history...
1498
 *    pausePermsSave(), pauseAttachmentMaintenance(), pauseRepairProcess()
1499
 *
1500
 * @param int $applied_sigs
1501
 * @throws Elk_Exception
1502
 */
1503
function pauseSignatureApplySettings($applied_sigs)
1504
{
1505
	global $context, $txt, $sig_start;
1506
1507
	// Try get more time...
1508
	detectServer()->setTimeLimit(600);
1509
1510
	// Have we exhausted all the time we allowed?
1511
	if (time() - array_sum(explode(' ', $sig_start)) < 3)
1512
		return;
1513
1514
	$context['continue_get_data'] = '?action=admin;area=featuresettings;sa=sig;apply;step=' . $applied_sigs . ';' . $context['session_var'] . '=' . $context['session_id'];
1515
	$context['page_title'] = $txt['not_done_title'];
1516
	$context['continue_post_data'] = '';
1517
	$context['continue_countdown'] = '2';
1518
	$context['sub_template'] = 'not_done';
1519
1520
	// Specific stuff to not break this template!
1521
	$context[$context['admin_menu_name']]['current_subsection'] = 'sig';
1522
1523
	// Get the right percent.
1524
	$context['continue_percent'] = round(($applied_sigs / $context['max_member']) * 100);
1525
1526
	// Never more than 100%!
1527
	$context['continue_percent'] = min($context['continue_percent'], 100);
1528
1529
	obExit();
1530
}
1531