forked from elkarte/Elkarte
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathManageFeatures.php
1850 lines (1594 loc) · 54.6 KB
/
ManageFeatures.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Manage features and options administration page.
*
* @package ElkArte Forum
* @copyright ElkArte Forum contributors
* @license BSD http://opensource.org/licenses/BSD-3-Clause (see accompanying LICENSE.txt file)
*
* This file contains code covered by:
* copyright: 2011 Simple Machines (http://www.simplemachines.org)
*
* @version 2.0 dev
*
*/
namespace ElkArte\AdminController;
use BBC\ParserWrapper;
use DateTimeZone;
use ElkArte\AbstractController;
use ElkArte\Action;
use ElkArte\Exceptions\Exception;
use ElkArte\Helper\DataValidator;
use ElkArte\Helper\Util;
use ElkArte\Hooks;
use ElkArte\Languages\Txt;
use ElkArte\Mentions\MentionType\AbstractNotificationMessage;
use ElkArte\MetadataIntegrate;
use ElkArte\Notifications\Notifications;
use ElkArte\SettingsForm\SettingsForm;
/**
* Manage features and options administration page.
*
* This controller handles the pages which allow the admin
* to see and change the basic feature settings of their site.
*/
class ManageFeatures extends AbstractController
{
/**
* Pre Dispatch, called before other methods.
*/
public function pre_dispatch()
{
// We need this in few places so it's easier to have it loaded here
require_once(SUBSDIR . '/ManageFeatures.subs.php');
}
/**
* This function passes control through to the relevant tab.
*
* @event integrate_sa_modify_features Use to add new Configuration tabs
* @see AbstractController::action_index()
* @uses Help, ManageSettings languages
* @uses sub_template show_settings
*/
public function action_index()
{
global $context, $txt, $settings;
// Often Helpful
Txt::load('Help+ManageSettings+Mentions');
// All the actions we know about. These must exist in loadMenu() of the admin controller.
$subActions = array(
'basic' => array(
'controller' => $this,
'function' => 'action_basicSettings_display',
'permission' => 'admin_forum'
),
'layout' => array(
'controller' => $this,
'function' => 'action_layoutSettings_display',
'permission' => 'admin_forum'
),
'pwa' => array(
'controller' => $this,
'function' => 'action_pwaSettings_display',
'enabled' => true,
'permission' => 'admin_forum'
),
'karma' => array(
'controller' => $this,
'function' => 'action_karmaSettings_display',
'enabled' => featureEnabled('k'),
'permission' => 'admin_forum'
),
'pmsettings' => array(
'controller' => $this,
'function' => 'action_pmsettings',
'permission' => 'admin_forum'
),
'likes' => array(
'controller' => $this,
'function' => 'action_likesSettings_display',
'enabled' => featureEnabled('l'),
'permission' => 'admin_forum'
),
'mention' => array(
'controller' => $this,
'function' => 'action_notificationsSettings_display',
'permission' => 'admin_forum'
),
'sig' => array(
'controller' => $this,
'function' => 'action_signatureSettings_display',
'permission' => 'admin_forum'
),
'profile' => array(
'controller' => $this,
'function' => 'action_profile',
'enabled' => featureEnabled('cp'),
'permission' => 'admin_forum'
),
'profileedit' => array(
'controller' => $this,
'function' => 'action_profileedit',
'permission' => 'admin_forum'
),
);
// Set up the action control
$action = new Action('modify_features');
// By default, do the basic settings, call integrate_sa_modify_features
$subAction = $action->initialize($subActions, 'basic');
// Some final pieces for the template
$context['sub_template'] = 'show_settings';
$context['sub_action'] = $subAction;
$context['page_title'] = $txt['modSettings_title'];
// Load up all the tabs...
$context[$context['admin_menu_name']]['object']->prepareTabData([
'title' => 'modSettings_title',
'help' => 'featuresettings',
'description' => sprintf($txt['modSettings_desc'], getUrl('admin', ['action' => 'admin', 'area' => 'theme', 'sa' => 'list', 'th' => $settings['theme_id'], '{session_data}'])),
// All valid $subActions will be added, here you just specify any special tab data
'tabs' => [
'mention' => [
'description' => $txt['mentions_settings_desc'],
],
'sig' => [
'description' => $txt['signature_settings_desc'],
],
'profile' => [
'description' => $txt['custom_profile_desc'],
],
'pwa' => [
'description' => $txt['pwa_settings_desc'],
],
],
]);
// Call the right function for this sub-action.
$action->dispatch($subAction);
}
/**
* Config array for changing the basic forum settings
*
* - Accessed from ?action=admin;area=featuresettings;sa=basic;
*
* @event integrate_save_basic_settings
*/
public function action_basicSettings_display()
{
global $txt, $context, $modSettings;
// Initialize the form
$settingsForm = new SettingsForm(SettingsForm::DB_ADAPTER);
// Initialize it with our settings
$settingsForm->setConfigVars($this->_basicSettings());
theme()->addJavascriptVar(['txt_invalid_response' => $txt['ajax_bad_response']], true);
// Saving?
if (isset($this->_req->query->save))
{
checkSession();
// Prevent absurd boundaries here - make it a day tops.
if (isset($this->_req->post->lastActive))
{
$this->_req->post->lastActive = min((int) $this->_req->post->lastActive, 1440);
}
call_integration_hook('integrate_save_basic_settings');
// Microdata needs to enable its integration
if ($this->_req->isSet('metadata_enabled'))
{
Hooks::instance()->enableIntegration(MetadataIntegrate::class);
}
else
{
Hooks::instance()->disableIntegration(MetadataIntegrate::class);
}
// If they have changed Hive settings, lets clear them to avoid issues
if (empty($modSettings['minify_css_js']) !== empty($this->_req->post->minify_css_js))
{
theme()->cleanHives();
}
$settingsForm->setConfigValues((array) $this->_req->post);
$settingsForm->save();
writeLog();
redirectexit('action=admin;area=featuresettings;sa=basic');
}
if (isset($this->_req->post->cleanhives) && $this->getApi() === 'json')
{
$clean_hives_result = theme()->cleanHives();
setJsonTemplate();
$context['json_data'] = array(
'success' => $clean_hives_result,
'response' => $clean_hives_result ? $txt['clean_hives_sucess'] : $txt['clean_hives_failed']
);
return;
}
$context['post_url'] = getUrl('admin', ['action' => 'admin', 'area' => 'featuresettings', 'sa' => 'basic', 'save']);
$context['settings_title'] = $txt['mods_cat_features'];
$settingsForm->prepare();
}
/**
* Return basic feature settings.
*
* @event integrate_modify_basic_settings Adds to General features and Options
*/
private function _basicSettings()
{
global $txt;
$config_vars = array(
// Basic stuff, titles, permissions...
array('check', 'allow_guestAccess'),
array('check', 'enable_buddylist'),
array('check', 'allow_editDisplayName'),
array('check', 'allow_hideOnline'),
array('check', 'titlesEnable'),
'',
// Javascript and CSS options
array('select', 'jquery_source', array('auto' => $txt['jquery_auto'], 'local' => $txt['jquery_local'], 'cdn' => $txt['jquery_cdn'])),
array('check', 'minify_css_js', 'postinput' => '<a href="#" id="clean_hives" class="linkbutton">' . $txt['clean_hives'] . '</a>'),
'',
// Number formatting, timezones.
array('text', 'time_format'),
array('float', 'time_offset', 'subtext' => $txt['setting_time_offset_note'], 6, 'postinput' => $txt['hours']),
'default_timezone' => array('select', 'default_timezone', array()),
'',
// Who's online?
array('check', 'who_enabled'),
array('int', 'lastActive', 6, 'postinput' => $txt['minutes']),
'',
// Statistics.
array('check', 'trackStats'),
array('check', 'hitStats'),
'',
// Option-ish things... miscellaneous sorta.
array('check', 'metadata_enabled'),
array('check', 'allow_disableAnnounce'),
array('check', 'disallow_sendBody'),
array('select', 'enable_contactform', array('disabled' => $txt['contact_form_disabled'], 'registration' => $txt['contact_form_registration'], 'menu' => $txt['contact_form_menu'])),
);
// Get all the time zones.
$all_zones = DateTimeZone::listIdentifiers();
if (empty($all_zones))
{
unset($config_vars['default_timezone']);
}
else
{
// Make sure we set the value to the same as the printed value.
foreach ($all_zones as $zone)
{
$config_vars['default_timezone'][2][$zone] = $zone;
}
}
theme()->addInlineJavascript('
document.getElementById("clean_hives").addEventListener("click", function(event) {return cleanHives(event);});', ['defer' => true]);
call_integration_hook('integrate_modify_basic_settings', array(&$config_vars));
return $config_vars;
}
/**
* Allows modifying the global layout settings in the forum
*
* - Accessed through ?action=admin;area=featuresettings;sa=layout;
*
* @event integrate_save_layout_settings
*/
public function action_layoutSettings_display()
{
global $txt, $context, $modSettings;
// Initialize the form
$settingsForm = new SettingsForm(SettingsForm::DB_ADAPTER);
// Initialize it with our settings
$settingsForm->setConfigVars($this->_layoutSettings());
// Saving?
if (isset($this->_req->query->save))
{
// Setting a custom frontpage, set the hook to the FrontpageInterface of the controller
if (!empty($this->_req->post->front_page))
{
// Addons may have left this blank
$modSettings['front_page'] = empty($modSettings['front_page']) ? 'MessageIndex_Controller' : $modSettings['front_page'];
$front_page = (string) $this->_req->post->front_page;
if (
class_exists($modSettings['front_page'])
&& in_array('validateFrontPageOptions', get_class_methods($modSettings['front_page']))
&& !$front_page::validateFrontPageOptions($this->_req->post)
)
{
$this->_req->post->front_page = '';
}
}
checkSession();
call_integration_hook('integrate_save_layout_settings');
$settingsForm->setConfigValues((array) $this->_req->post);
$settingsForm->save();
writeLog();
redirectexit('action=admin;area=featuresettings;sa=layout');
}
$context['post_url'] = getUrl('admin', ['action' => 'admin', 'area' => 'featuresettings', 'sa' => 'layout', 'save']);
$context['settings_title'] = $txt['mods_cat_layout'];
$settingsForm->prepare();
}
/**
* Return layout settings.
*
* @event integrate_modify_layout_settings Adds options to Configuration->Layout
*/
private function _layoutSettings()
{
global $txt;
$config_vars = array_merge(getFrontPageControllers(), array(
'',
// Pagination stuff.
array('check', 'compactTopicPagesEnable'),
array('int', 'compactTopicPagesContiguous', 'subtext' => str_replace(' ', ' ', '"3" ' . $txt['to_display'] . ': <strong>1 ... 4 [5] 6 ... 9</strong>') . '<br />' . str_replace(' ', ' ', '"5" ' . $txt['to_display'] . ': <strong>1 ... 3 4 [5] 6 7 ... 9</strong>')),
array('int', 'defaultMaxMembers'),
array('check', 'displayMemberNames'),
'',
// Stuff that just is everywhere - today, search, online, etc.
array('select', 'todayMod', array($txt['today_disabled'], $txt['today_only'], $txt['yesterday_today'], $txt['relative_time'])),
array('check', 'onlineEnable'),
array('check', 'enableVBStyleLogin'),
'',
// Automagic image resizing.
array('int', 'max_image_width', 'subtext' => $txt['zero_for_no_limit']),
array('int', 'max_image_height', 'subtext' => $txt['zero_for_no_limit']),
'',
// This is like debugging sorta.
array('check', 'timeLoadPageEnable'),
));
call_integration_hook('integrate_modify_layout_settings', array(&$config_vars));
return $config_vars;
}
/**
* Display configuration settings page for progressive web application settings.
*
* - Accessed from ?action=admin;area=featuresettings;sa=pwa;
*
* @event integrate_save_pwa_settings
*/
public function action_pwaSettings_display()
{
global $txt, $context;
// Initialize the form
$settingsForm = new SettingsForm(SettingsForm::DB_ADAPTER);
// Initialize it with our settings
$settingsForm->setConfigVars($this->_pwaSettings());
// Saving, lots of checks then
if (isset($this->_req->query->save))
{
checkSession();
call_integration_hook('integrate_save_pwa_settings');
// Don't allow it to be enabled if we don't have SSL
$canUse = detectServer()->supportsSSL();
if (!$canUse)
{
$this->_req->post->pwa_enabled = 0;
}
// And you must enable this if PWA is enabled
if ($this->_req->getPost('pwa_enabled', 'intval') === 1)
{
$this->_req->post->pwa_manifest_enabled = 1;
}
$validator = new DataValidator();
$validation_rules = [
'pwa_theme_color' => 'valid_color',
'pwa_background_color' => 'valid_color',
'pwa_short_name' => 'max_length[12]'
];
// Only check the rest if they entered something.
$valid_urls = ['pwa_small_icon', 'pwa_large_icon', 'favicon_icon', 'apple_touch_icon'];
foreach ($valid_urls as $url)
{
if ($this->_req->getPost($url, 'trim') !== '')
{
$validation_rules[$url] = 'valid_url';
}
}
$validator->validation_rules($validation_rules);
if (!$validator->validate($this->_req->post))
{
// Some input error, lets tell them what is wrong
$context['error_type'] = 'minor';
$context['settings_message'] = [];
foreach ($validator->validation_errors() as $error)
{
$context['settings_message'][] = $error;
}
}
else
{
$settingsForm->setConfigValues((array) $this->_req->post);
$settingsForm->save();
redirectexit('action=admin;area=featuresettings;sa=pwa');
}
}
$context['post_url'] = getUrl('admin', ['action' => 'admin', 'area' => 'featuresettings', 'sa' => 'pwa', 'save']);
$context['settings_title'] = $txt['pwa_settings'];
theme()->addInlineJavascript('
pwaPreview("pwa_small_icon");
pwaPreview("pwa_large_icon");
pwaPreview("favicon_icon");
pwaPreview("apple_touch_icon");', true);
$settingsForm->prepare();
}
/**
* Return PWA settings.
*
* @event integrate_modify_karma_settings Adds to Configuration->Pwa
*/
private function _pwaSettings()
{
global $txt;
// PWA requires SSL
$canUse = detectServer()->supportsSSL();
$config_vars = array(
// PWA - On or off?
array('check', 'pwa_enabled', 'disabled' => !$canUse, 'invalid' => !$canUse, 'postinput' => !$canUse ? $txt['pwa_disabled'] : ''),
'',
array('check', 'pwa_manifest_enabled', 'helptext' => $txt['pwa_manifest_enabled_desc']),
array('text', 'pwa_short_name', 12, 'mask' => 'nohtml', 'helptext' => $txt['pwa_short_name_desc'], 'maxlength' => 12),
array('color', 'pwa_theme_color', 'helptext' => $txt['pwa_theme_color_desc']),
array('color', 'pwa_background_color', 'helptext' => $txt['pwa_background_color_desc']),
'',
array('url', 'pwa_small_icon', 'size' => 40, 'helptext' => $txt['pwa_small_icon_desc'], 'onchange' => "pwaPreview('pwa_small_icon');"),
array('url', 'pwa_large_icon', 'size' => 40, 'helptext' => $txt['pwa_large_icon_desc'], 'onchange' => "pwaPreview('pwa_large_icon');"),
array('title', 'other_icons_title'),
array('url', 'favicon_icon', 'size' => 40, 'helptext' => $txt['favicon_icon_desc'], 'onchange' => "pwaPreview('favicon_icon');"),
array('url', 'apple_touch_icon', 'size' => 40, 'helptext' => $txt['apple_touch_icon_desc'], 'onchange' => "pwaPreview('apple_touch_icon');"),
);
call_integration_hook('integrate_modify_pwa_settings', array(&$config_vars));
return $config_vars;
}
/**
* Display configuration settings page for karma settings.
*
* - Accessed from ?action=admin;area=featuresettings;sa=karma;
*
* @event integrate_save_karma_settings
*/
public function action_karmaSettings_display()
{
global $txt, $context;
// Initialize the form
$settingsForm = new SettingsForm(SettingsForm::DB_ADAPTER);
// Initialize it with our settings
$settingsForm->setConfigVars($this->_karmaSettings());
// Saving?
if (isset($this->_req->query->save))
{
checkSession();
call_integration_hook('integrate_save_karma_settings');
$settingsForm->setConfigValues((array) $this->_req->post);
$settingsForm->save();
redirectexit('action=admin;area=featuresettings;sa=karma');
}
$context['post_url'] = getUrl('admin', ['action' => 'admin', 'area' => 'featuresettings', 'sa' => 'karma', 'save']);
$context['settings_title'] = $txt['karma'];
$settingsForm->prepare();
}
/**
* Return karma settings.
*
* @event integrate_modify_karma_settings Adds to Configuration->Karma
*/
private function _karmaSettings()
{
global $txt;
$config_vars = array(
// Karma - On or off?
array('select', 'karmaMode', explode('|', $txt['karma_options'])),
'',
// Who can do it.... and who is restricted by time limits?
array('int', 'karmaMinPosts', 6, 'postinput' => $txt['manageposts_posts']),
array('float', 'karmaWaitTime', 6, 'postinput' => $txt['hours']),
array('check', 'karmaTimeRestrictAdmins'),
array('check', 'karmaDisableSmite'),
'',
// What does it look like? [smite]?
array('text', 'karmaLabel'),
array('text', 'karmaApplaudLabel', 'mask' => 'nohtml'),
array('text', 'karmaSmiteLabel', 'mask' => 'nohtml'),
);
call_integration_hook('integrate_modify_karma_settings', array(&$config_vars));
return $config_vars;
}
/**
* Display configuration settings page for likes settings.
*
* - Accessed from ?action=admin;area=featuresettings;sa=likes;
*
* @event integrate_save_likes_settings
*/
public function action_likesSettings_display()
{
global $txt, $context;
// Initialize the form
$settingsForm = new SettingsForm(SettingsForm::DB_ADAPTER);
// Initialize it with our settings
$settingsForm->setConfigVars($this->_likesSettings());
// Saving?
if (isset($this->_req->query->save))
{
checkSession();
call_integration_hook('integrate_save_likes_settings');
$settingsForm->setConfigValues((array) $this->_req->post);
$settingsForm->save();
redirectexit('action=admin;area=featuresettings;sa=likes');
}
$context['post_url'] = getUrl('admin', ['action' => 'admin', 'area' => 'featuresettings', 'sa' => 'likes', 'save']);
$context['settings_title'] = $txt['likes'];
$settingsForm->prepare();
}
/**
* Return likes settings.
*
* @event integrate_modify_likes_settings Adds to Configuration->Likes
*/
private function _likesSettings()
{
global $txt;
$config_vars = array(
// Likes - On or off?
array('check', 'likes_enabled'),
'',
// Who can do it.... and who is restricted by count limits?
array('int', 'likeMinPosts', 6, 'postinput' => $txt['manageposts_posts']),
array('int', 'likeWaitTime', 6, 'postinput' => $txt['minutes']),
array('int', 'likeWaitCount', 6),
array('check', 'likeRestrictAdmins'),
array('check', 'likeAllowSelf'),
array('check', 'useLikesNotViews'),
'',
array('int', 'likeDisplayLimit', 6)
);
call_integration_hook('integrate_modify_likes_settings', array(&$config_vars));
return $config_vars;
}
/**
* Initializes the mentions settings admin page.
*
* - Accessed from ?action=admin;area=featuresettings;sa=mention;
*
* @event integrate_save_modify_mention_settings
*/
public function action_notificationsSettings_display()
{
global $txt, $context, $modSettings;
Txt::load('Mentions');
// Instantiate the form
$settingsForm = new SettingsForm(SettingsForm::DB_ADAPTER);
// Initialize it with our settings
$settingsForm->setConfigVars($this->_notificationsSettings());
// Some context stuff
$context['page_title'] = $txt['mentions_settings'];
$context['sub_template'] = 'show_settings';
// Saving the settings?
if (isset($this->_req->query->save))
{
checkSession();
call_integration_hook('integrate_save_modify_mention_settings');
if (!empty($this->_req->post->mentions_enabled))
{
enableModules('mentions', array('post', 'display'));
}
else
{
disableModules('mentions', array('post', 'display'));
}
if (!empty($modSettings['hidden_notification_methods']))
{
foreach ($modSettings['hidden_notification_methods'] as $class)
{
$this->_req->post->notifications[$class::getType()] = $class::getSettings();
}
}
if (empty($this->_req->post->notifications))
{
$notification_methods = serialize(array());
}
else
{
$notification_methods = [];
foreach ($this->_req->post->notifications as $type => $notification)
{
if (!empty($notification['enable']))
{
$defaults = $notification['default'] ?? [];
unset($notification['enable'], $notification['default']);
foreach ($notification as $k => $v)
{
$notification[$k] = in_array($k, $defaults) ? Notifications::DEFAULT_LEVEL : $v;
}
$notification_methods[$type] = $notification;
}
}
$notification_methods = serialize($notification_methods);
}
require_once(SUBSDIR . '/Mentions.subs.php');
$enabled_mentions = array();
$current_settings = Util::unserialize($modSettings['notification_methods']);
// Fist hide what was visible
$modules_toggle = array('enable' => array(), 'disable' => array());
foreach ($current_settings as $type => $val)
{
if (!isset($this->_req->post->notifications[$type]))
{
toggleMentionsVisibility($type, false);
$modules_toggle['disable'][] = $type;
}
}
// Then make visible what was hidden, but only if there is anything
if (!empty($this->_req->post->notifications))
{
foreach ($this->_req->post->notifications as $type => $val)
{
if (!isset($current_settings[$type]))
{
toggleMentionsVisibility($type, true);
$modules_toggle['enable'][] = $type;
}
}
$enabled_mentions = array_keys($this->_req->post->notifications);
}
// Let's just keep it active, there are too many reasons it should be.
require_once(SUBSDIR . '/ScheduledTasks.subs.php');
toggleTaskStatusByName('user_access_mentions', true);
// Disable or enable modules as needed
foreach ($modules_toggle as $action => $toggles)
{
if (!empty($toggles))
{
// The modules associated with the notification (mentionmem, likes, etc) area
$modules = getMentionsModules($toggles);
// The action will either be enable to disable
$function = $action . 'Modules';
// Something like enableModule('mentions', array('post', 'display');
foreach ($modules as $key => $val)
{
$function($key, $val);
}
}
}
updateSettings(array('enabled_mentions' => implode(',', array_unique($enabled_mentions)), 'notification_methods' => $notification_methods));
$settingsForm->setConfigValues((array) $this->_req->post);
$settingsForm->save();
redirectexit('action=admin;area=featuresettings;sa=mention');
}
// Prepare the settings for display
$context['post_url'] = getUrl('admin', ['action' => 'admin', 'area' => 'featuresettings', 'sa' => 'mention', 'save']);
$settingsForm->prepare();
}
/**
* Return mentions settings.
*
* @event integrate_modify_mention_settings Adds to Configuration->Mentions
*/
private function _notificationsSettings()
{
global $txt, $modSettings;
Txt::load('Profile+UserNotifications');
loadJavascriptFile('ext/jquery.multiselect.min.js');
theme()->addInlineJavascript('
$(\'.select_multiple\').multiselect({\'language_strings\': {\'Select all\': ' . JavaScriptEscape($txt['notify_select_all']) . '}});
document.addEventListener("DOMContentLoaded", function() {
prepareNotificationOptions();
});', true);
loadCSSFile('multiselect.css');
// The mentions settings
$config_vars = array(
array('title', 'mentions_settings'),
array('check', 'mentions_enabled'),
);
$notification_methods = Notifications::instance()->getNotifiers();
$notification_classes = getAvailableNotifications();
$current_settings = unserialize($modSettings['notification_methods'], ['allowed_classes' => false]);
foreach ($notification_classes as $class)
{
// The canUse can be set by each notifier based on conditions, default is true;
/* @var $class AbstractNotificationMessage */
if ($class::canUse() === false)
{
continue;
}
if ($class::hasHiddenInterface() === true)
{
$modSettings['hidden_notification_methods'][] = $class;
continue;
}
// Set up config enable/disable setting for all notifications.
$title = strtolower($class::getType());
$config_vars[] = array('title', 'setting_' . $title);
$config_vars[] = array('check', 'notifications[' . $title . '][enable]', 'text_label' => $txt['setting_notify_enable_this']);
$modSettings['notifications[' . $title . '][enable]'] = !empty($current_settings[$title]);
$default_values = [];
$is_default = [];
// If its enabled, show all the available ways, like email, notify, weekly ...
foreach (array_keys($notification_methods) as $method_name)
{
$method_name = strtolower($method_name);
// Are they excluding any, like don't let mailfail be allowed to send email !
if ($class::isNotAllowed($method_name))
{
continue;
}
$config_vars[] = array('check', 'notifications[' . $title . '][' . $method_name . ']', 'text_label' => $txt['notify_' . $method_name]);
$modSettings['notifications[' . $title . '][' . $method_name . ']'] = !empty($current_settings[$title][$method_name]);
$default_values[] = [$method_name, $txt['notify_' . $method_name]];
if (empty($current_settings[$title][$method_name]))
{
continue;
}
if ((int) $current_settings[$title][$method_name] !== Notifications::DEFAULT_LEVEL)
{
continue;
}
$is_default[] = $method_name;
}
$config_vars[] = array('select', 'notifications[' . $title . '][default]', $default_values, 'text_label' => $txt['default_active'], 'multiple' => true, 'value' => $is_default);
$modSettings['notifications[' . $title . '][default]'] = $is_default;
}
call_integration_hook('integrate_modify_mention_settings', array(&$config_vars));
return $config_vars;
}
/**
* Display configuration settings for signatures on forum.
*
* - Accessed from ?action=admin;area=featuresettings;sa=sig;
*
* @event integrate_save_signature_settings
*/
public function action_signatureSettings_display()
{
global $context, $txt, $modSettings;
// Initialize the form
$settingsForm = new SettingsForm(SettingsForm::DB_ADAPTER);
// Initialize it with our settings
$settingsForm->setConfigVars($this->_signatureSettings());
// Setup the template.
$context['page_title'] = $txt['signature_settings'];
$context['sub_template'] = 'show_settings';
// Disable the max smileys option if we don't allow smileys at all!
theme()->addInlineJavascript('
document.getElementById(\'signature_max_smileys\').disabled = !document.getElementById(\'signature_allow_smileys\').checked;', true);
// Load all the signature settings.
[$sig_limits, $sig_bbc] = explode(':', $modSettings['signature_settings']);
$sig_limits = explode(',', $sig_limits);
$disabledTags = empty($sig_bbc) ? array() : explode(',', $sig_bbc);
// @todo temporary since it does not work, and seriously why would you do this?
$disabledTags[] = 'footnote';
// Applying to ALL signatures?!!
if (isset($this->_req->query->apply))
{
// Security!
checkSession('get');
// This is horrid - but I suppose some people will want the option to do it.
$applied_sigs = $this->_req->getQuery('step', 'intval', 0);
updateAllSignatures($applied_sigs);
$settings_applied = true;
}
$context['signature_settings'] = array(
'enable' => $sig_limits[0] ?? 0,
'max_length' => $sig_limits[1] ?? 0,
'max_lines' => $sig_limits[2] ?? 0,
'max_images' => $sig_limits[3] ?? 0,
'allow_smileys' => isset($sig_limits[4]) && $sig_limits[4] == -1 ? 0 : 1,
'max_smileys' => isset($sig_limits[4]) && $sig_limits[4] != -1 ? $sig_limits[4] : 0,
'max_image_width' => $sig_limits[5] ?? 0,
'max_image_height' => $sig_limits[6] ?? 0,
'max_font_size' => $sig_limits[7] ?? 0,
'repetition_guests' => $sig_limits[8] ?? 0,
'repetition_members' => $sig_limits[9] ?? 0,
);
// Temporarily make each setting a modSetting!
foreach ($context['signature_settings'] as $key => $value)
{
$modSettings['signature_' . $key] = $value;
}
// Make sure we check the right tags!
$modSettings['bbc_disabled_signature_bbc'] = $disabledTags;
// Saving?
if (isset($this->_req->query->save))
{
checkSession();
// Clean up the tag stuff!
$codes = ParserWrapper::instance()->getCodes();
$bbcTags = $codes->getTags();
$signature_bbc_enabledTags = $this->_req->getPost('signature_bbc_enabledTags', null, []);
if (!is_array($signature_bbc_enabledTags))
{
$signature_bbc_enabledTags = array($signature_bbc_enabledTags);
}
$this->_req->post->signature_bbc_enabledTags = $signature_bbc_enabledTags;
$sig_limits = array();
foreach (array_keys($context['signature_settings']) as $key)
{
if ($key === 'allow_smileys')
{
continue;
}
if ($key === 'max_smileys' && empty($this->_req->post->signature_allow_smileys))
{
$sig_limits[] = -1;
}
else
{
$current_key = $this->_req->getPost('signature_' . $key, 'intval');
$sig_limits[] = empty($current_key) ? 0 : max(1, $current_key);
}
}
call_integration_hook('integrate_save_signature_settings', array(&$sig_limits, &$bbcTags));
$this->_req->post->signature_settings = implode(',', $sig_limits) . ':' . implode(',', array_diff($bbcTags, $this->_req->post->signature_bbc_enabledTags));
// Even though we have practically no settings let's keep the convention going!
$save_vars = array();
$save_vars[] = array('text', 'signature_settings');
$settingsForm->setConfigVars($save_vars);
$settingsForm->setConfigValues((array) $this->_req->post);
$settingsForm->save();
redirectexit('action=admin;area=featuresettings;sa=sig');
}
$context['post_url'] = getUrl('admin', ['action' => 'admin', 'area' => 'featuresettings', 'sa' => 'sig', 'save']);
$context['settings_title'] = $txt['signature_settings'];
$context['settings_message'] = empty($settings_applied) ? sprintf($txt['signature_settings_warning'], getUrl('admin', ['action' => 'admin', 'area' => 'featuresettings', 'sa' => 'sig', 'apply', '{session_data}'])) : $txt['signature_settings_applied'];
$settingsForm->prepare();
}
/**
* Return signature settings.
*
* - Used in admin center search and settings form
*
* @event integrate_modify_signature_settings Adds options to Signature Settings
*/
private function _signatureSettings()
{
global $txt;
$config_vars = array(
// Are signatures even enabled?
array('check', 'signature_enable'),
'',
// Tweaking settings!
array('int', 'signature_max_length', 'subtext' => $txt['zero_for_no_limit']),
array('int', 'signature_max_lines', 'subtext' => $txt['zero_for_no_limit']),
array('int', 'signature_max_font_size', 'subtext' => $txt['zero_for_no_limit']),
array('check', 'signature_allow_smileys', 'onclick' => "document.getElementById('signature_max_smileys').disabled = !this.checked;"),