forked from b2evolution/b2evolution
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquick_unsubscribe.php
More file actions
1118 lines (967 loc) · 39.8 KB
/
quick_unsubscribe.php
File metadata and controls
1118 lines (967 loc) · 39.8 KB
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
/**
* Initialize everything:
*/
require_once dirname(__FILE__).'/../conf/_config.php';
require_once $inc_path.'/_main.inc.php';
if( empty( $params ) )
{
$params = array();
}
global $UserSettings, $Settings;
param( 'type', 'string', true );
param( 'comment_ID', 'integer', NULL );
param( 'user_ID', 'integer', ( $comment_ID === NULL ) );
param( 'key', 'string', true );
param( 'coll_ID', 'integer', 0 );
param( 'post_ID', 'integer', 0 );
param( 'confirmed', 'integer', 0 );
param( 'action', 'string', NULL );
param( 'ecmp_ID', 'integer', 0 );
$unsub_Comment = false;
if( $comment_ID !== NULL )
{ // This is a case to unsubscribe anonymous user from comment:
$CommentCache = & get_CommentCache();
$unsub_Comment = & $CommentCache->get_by_ID( $comment_ID, false, false );
if( $unsub_Comment->get( 'author_email' ) == '' || $unsub_Comment->get( 'author_user_ID' ) !== NULL )
{ // Don't allow to do unsubcription action if the requested comment is not from anonymous user:
$unsub_Comment = false;
}
}
if( ! $unsub_Comment )
{ // This is a case to unsubscribe a registered user:
$UserCache = & get_UserCache();
$edited_User = $UserCache->get_by_ID( $user_ID, false, false );
}
if( empty( $edited_User ) && empty( $unsub_Comment ) )
{ // Registered or anonymous user is not found:
$error_msg = T_( 'The user you are trying to unsubscribe does not seem to exist. You may already have deleted your account.' );
}
elseif( ( ! $unsub_Comment && $key != md5( $user_ID.$edited_User->get( 'unsubscribe_key' ) ) ) || // Registered user
( $unsub_Comment && $key != md5( $comment_ID.$unsub_Comment->get( 'secret' ) ) ) ) // Anonymous user
{ // Security check is failed:
$error_msg = T_('Invalid unsubscribe link!');
}
elseif( $confirmed )
{ // Unsubscribe is confirmed let's proceed
switch( $action )
{
case 'unsubscribe':
$Session->assert_received_crumb( 'unsubscribe' );
// Crumb should only be used once
$Session->delete( 'crumb_latest_unsubscribe' );
$Session->delete( 'crumb_prev_unsubscribe' );
switch( $type )
{
case 'coll_comment':
case 'coll_post':
// unsubscribe from blog
if( $coll_ID == 0 )
{
$error_msg = T_('Invalid unsubscribe link!');
}
else
{
$BlogCache = & get_BlogCache();
$Blog = $BlogCache->get_by_ID( $coll_ID );
$subscription_name = ( ( $type == 'coll_comment' ) ? 'sub_comments' : 'sub_items' );
// Get previous setting
$sub_values = $DB->get_row( 'SELECT sub_items, sub_items_mod, sub_comments FROM T_subscriptions WHERE sub_coll_ID = '.$coll_ID.' AND sub_user_ID = '.$user_ID, ARRAY_A );
$Blog = & $BlogCache->get_by_ID( $coll_ID );
if( $Blog->get( 'advanced_perms' )
&& ( ( $Blog->get_setting( 'allow_subscriptions' ) && $Blog->get_setting( 'opt_out_subscription' ) ) ||
( $Blog->get_setting( 'allow_comment_subscriptions' ) && $Blog->get_setting( 'opt_out_comment_subscription' ) ) ||
( $Blog->get_setting( 'allow_item_mod_subscriptions' ) && $Blog->get_setting( 'opt_out_item_mod_subscription' ) ) )
&& $edited_User->check_perm( 'blog_ismember', 'view', false, $coll_ID ) )
{ // opt-out collection
if( $subscription_name == 'sub_items' )
{
$sub_items_value = 0;
$sub_items_mod_value = empty( $sub_values ) ? 1 : $sub_values['sub_items_mod'];
$sub_comments_value = empty( $sub_values ) ? 1 : $sub_values['sub_comments'];
}
elseif( $subscription_name == 'sub_comments' )
{
$sub_items_value = empty( $sub_values ) ? 1 : $sub_values['sub_items'];
$sub_items_mod_value = empty( $sub_values ) ? 1 : $sub_values['sub_items_mod'];
$sub_comments_value = 0;
}
else
{ // should be impossible to go here
$sub_items_value = 0;
$sub_items_mod_value = 0;
$sub_comments_value = 0;
}
$DB->query( 'REPLACE INTO T_subscriptions( sub_coll_ID, sub_user_ID, sub_items, sub_items_mod, sub_comments )
VALUES ( '.$coll_ID.', '.$user_ID.', '.$sub_items_value.', '.$sub_items_mod_value.', '.$sub_comments_value.' )' );
}
else
{
$DB->query( 'UPDATE T_subscriptions SET '.$subscription_name.' = 0
WHERE sub_user_ID = '.$user_ID.' AND sub_coll_ID = '.$coll_ID );
}
}
break;
case 'post':
// unsubscribe from a specific post:
if( $post_ID == 0 )
{
$error_msg = T_('Invalid unsubscribe link!');
}
else
{
if( $unsub_Comment )
{ // Anonymous user form Comment:
$DB->query( 'UPDATE T_comments
SET comment_anon_notify = 0
WHERE comment_item_ID = '.$unsub_Comment->get( 'item_ID' ).'
AND comment_author_user_ID IS NULL
AND comment_author_email = '.$DB->quote( $unsub_Comment->get( 'author_email' ) ) );
}
else
{ // Registered User:
$ItemCache = & get_ItemCache();
$BlogCache = & get_BlogCache();
$Item = $ItemCache->get_by_ID( $post_ID );
$blog_ID = $Item->get_blog_ID();
$Blog = $BlogCache->get_by_ID( $blog_ID );
if( $Blog->get( 'advanced_perms' )
&& $Blog->get_setting( 'allow_item_subscriptions' )
&& $Blog->get_setting( 'opt_out_item_subscription' )
&& $edited_User->check_perm( 'blog_ismember', 'view', false, $blog_ID ) )
{
$DB->query( 'REPLACE INTO T_items__subscriptions( isub_item_ID, isub_user_ID, isub_comments )
VALUES ( '.$post_ID.', '.$user_ID.', 0 )' );
}
else
{
$DB->query( 'DELETE FROM T_items__subscriptions
WHERE isub_user_ID = '.$user_ID.' AND isub_item_ID = '.$post_ID );
}
}
}
break;
case 'creator':
// unsubscribe from the user own posts
$UserSettings->set( 'notify_published_comments', '0', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'cmt_moderation_reminder':
// unsubscribe from comment moderation reminder notifications
$UserSettings->set( 'send_cmt_moderation_reminder', '0', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'comment_moderator':
case 'moderator': // Note: This was not chaned to 'comment_moderator' to make sure old emails unsubscribe link are also work
// unsubscribe from new comment may need moderation notifications:
$UserSettings->set( 'notify_comment_moderation', '0', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'comment_moderator_edit':
// unsubscribe from updated comment may need moderation notifications:
$UserSettings->set( 'notify_edit_cmt_moderation', '0', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'comment_moderator_spam':
// unsubscribe from spam comment may need moderation notifications:
$UserSettings->set( 'notify_spam_cmt_moderation', '0', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'pst_moderation_reminder':
// unsubscribe from post moderation reminder notifications
$UserSettings->set( 'send_pst_moderation_reminder', '0', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'pst_stale_alert':
// unsubscribe from stale posts alert notifications:
$UserSettings->set( 'send_pst_stale_alert', '0', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'post_moderator':
// unsubscribe from new post moderation notifications:
$UserSettings->set( 'notify_post_moderation', '0', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'post_assignment':
// unsubscribe from new post moderation notifications:
$UserSettings->set( 'notify_post_assignment', '0', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'post_moderator_edit':
// unsubscribe from updated post moderation notifications:
$notify_edit_pst_moderation = $UserSettings->get( 'notify_edit_pst_moderation', $edited_User->ID );
if( $notify_edit_pst_moderation )
{ // Unsubscribe from ALL collections:
$UserSettings->set( 'notify_edit_pst_moderation', '0', $edited_User->ID );
$UserSettings->dbupdate();
// Additional form params in order to know user was unsubscribed from ALL collections:
$hidden_form_params = array( 'subs_edit_pst_type' => 'all' );
}
elseif( ! empty( $coll_ID ) )
{ // Unsubscribe ONLY from the selected collection:
$SQL = new SQL( 'Get user subscription per collection for post modifications' );
$SQL->SELECT( 'sub_items_mod' );
$SQL->FROM( 'T_subscriptions' );
$SQL->WHERE( 'sub_coll_ID = '.$DB->quote( $coll_ID ) );
$SQL->WHERE_and( 'sub_user_ID = '.$DB->quote( $user_ID ) );
if( $DB->get_var( $SQL ) === '1' )
{ // If user is really subscribed on the selected collection:
$DB->query( 'UPDATE T_subscriptions
SET sub_items_mod = 0
WHERE sub_user_ID = '.$DB->quote( $user_ID ).'
AND sub_coll_ID = '.$DB->quote( $coll_ID ) );
// Additional form params in order to know user was unsubscribed from single collection:
$hidden_form_params = array( 'subs_edit_pst_type' => 'coll' );
}
}
break;
case 'post_proposed_change':
// unsubscribe from post proposed change notifications:
$UserSettings->set( 'notify_post_proposed', '0', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'unread_msg':
// unsubscribe from unread messages reminder
$UserSettings->set( 'notify_unread_messages', '0', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'new_msg':
// unsubscribe from new messages notification
$UserSettings->set( 'notify_messages', '0', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'account_activation':
// unsubscribe from account activation reminder
$UserSettings->set( 'send_activation_reminder', '0', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'newsletter':
// unsubscribe from newsletter
// Use first newsletter by default for old unsubscribe url when we had only one static newsletter,
// which was upgraded to Newsletter with ID = 1
$newsletter_ID = param( 'newsletter', 'integer', 1 );
$assigned_user_tag = NULL;
$email_campaign_ID = param( 'ecmp_ID', 'integer', 0 );
$EmailCampaignCache = & get_EmailCampaignCache();
if( $email_campaign_ID )
{
if( $EmailCampaign = & $EmailCampaignCache->get_by_ID( $email_campaign_ID, false, false ) )
{
$assigned_user_tag = $EmailCampaign->get( 'user_tag_unsubscribe' );
}
else
{
$error_msg = T_('Invalid unsubscribe link!');
break;
}
}
if( ! $edited_User->unsubscribe( $newsletter_ID, array( 'usertags' => $assigned_user_tag ) ) )
{ // Display a message is the user is not subscribed on the requested newsletter:
$error_msg = T_('You are not subscribed to this list.');
// Send notification to owners of lists where user unsubscribed:
$edited_User->send_list_owner_notifications( 'unsubscribe' );
}
elseif( ! empty( $assigned_user_tag ) )
{
$edited_User->add_usertags( $assigned_user_tag );
$edited_User->dbupdate();
}
break;
case 'user_registration':
// unsubscribe from new user registration notifications
$UserSettings->set( 'notify_new_user_registration', '0', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'account_activated':
// unsubscribe from account activated notifications
$UserSettings->set( 'notify_activated_account', '0', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'account_closed':
// unsubscribe from account closed notifications
$UserSettings->set( 'notify_closed_account', '0', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'account_reported':
// unsubscribe from account reported notifications
$UserSettings->set( 'notify_reported_account', '0', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'account_changed':
// unsubscribe from account changed notifications
$UserSettings->set( 'notify_changed_account', '0', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'msgform':
// turn off allow emails through b2evo message forms
$UserSettings->set( 'enable_email', '0', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'cronjob_error':
// unsubscribe from cron job error notifications
$UserSettings->set( 'notify_cronjob_error', '0', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'automation_owner_notification':
// unsubscribe from automation step owner notifications:
$UserSettings->set( 'notify_automation_owner', '0', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'meta_comment':
// unsubscribe from internal comment notifications
$UserSettings->set( 'notify_meta_comments', '0', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'comment_mentioned':
// unsubscribe from new comment notifications when user is mentioned:
$UserSettings->set( 'notify_comment_mentioned', '0', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'meta_comment_mentioned':
// unsubscribe from new internal comment notifications when user is mentioned:
$UserSettings->set( 'notify_meta_comment_mentioned', '0', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'post_mentioned':
// unsubscribe from new post notifications when user is mentioned:
$UserSettings->set( 'notify_post_mentioned', '0', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'list_new_subscriber':
// unsubscribe from notifications when someone subscribes to one of the user's lists:
$UserSettings->set( 'notify_list_new_subscriber', '0', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'list_lost_subscriber':
// unsubscribe from notifications when a user unsubscribes to one of the user's lists:
$UserSettings->set( 'notify_list_lost_subscriber', '0', $edited_User->ID );
$UserSettings->dbupdate();
break;
default:
// DEFENSIVE programming:
$error_msg = 'Unhandled unsubscribe type.';
}
if( ! isset( $error_msg ) )
{
$unsubscribed = true;
}
break;
case 'resubscribe':
$Session->assert_received_crumb( 'resubscribe' );
// Crumb should only be used once
$Session->delete( 'crumb_latest_resubscribe' );
$Session->delete( 'crumb_prev_resubscribe' );
switch( $type )
{
case 'coll_comment':
case 'coll_post':
// resubscribe from blog
if( $coll_ID == 0 )
{
$error_msg = T_('Invalid resubscribe link!');
}
else
{
$BlogCache = & get_BlogCache();
$Blog = $BlogCache->get_by_ID( $coll_ID );
$subscription_name = ( ( $type == 'coll_comment' ) ? 'sub_comments' : 'sub_items' );
// Get previous setting
$sub_values = $DB->get_row( 'SELECT sub_items, sub_items_mod, sub_comments FROM T_subscriptions WHERE sub_coll_ID = '.$coll_ID.' AND sub_user_ID = '.$user_ID, ARRAY_A );
$Blog = & $BlogCache->get_by_ID( $coll_ID );
if( $Blog->get( 'advanced_perms' )
&& ( ( $Blog->get_setting( 'allow_subscriptions' ) && $Blog->get_setting( 'opt_out_subscription' ) ) ||
( $Blog->get_setting( 'allow_item_mod_subscriptions' ) && $Blog->get_setting( 'opt_out_item_mod_subscription' ) ) ||
( $Blog->get_setting( 'allow_comment_subscriptions' ) && $Blog->get_setting( 'opt_out_comment_subscription' ) ) )
&& $edited_User->check_perm( 'blog_ismember', 'view', false, $coll_ID ) )
{ // opt-out collection
if( $subscription_name == 'sub_items' )
{
$sub_items_value = 1;
$sub_items_mod_value = empty( $sub_values ) ? 1 : $sub_values['sub_items_mod'];
$sub_comments_value = empty( $sub_values ) ? 1 : $sub_values['sub_comments'];
}
elseif( $subscription_name == 'sub_comments' )
{
$sub_items_value = empty( $sub_values ) ? 1 : $sub_values['sub_items'];
$sub_items_mod_value = empty( $sub_values ) ? 1 : $sub_values['sub_items_mod'];
$sub_comments_value = 1;
}
else
{ // should be impossible to go here
$sub_items_value = $sub_values['sub_items'];
$sub_items_mod_value = $sub_values['sub_items_mod'];
$sub_comments_value = $sub_values['sub_comments'];
}
$DB->query( 'REPLACE INTO T_subscriptions( sub_coll_ID, sub_user_ID, sub_items, sub_items_mod, sub_comments )
VALUES ( '.$coll_ID.', '.$user_ID.', '.$sub_items_value.', '.$sub_items_mod_value.', '.$sub_comments_value.' )' );
}
else
{
$DB->query( 'UPDATE T_subscriptions SET '.$subscription_name.' = 1
WHERE sub_user_ID = '.$user_ID.' AND sub_coll_ID = '.$coll_ID );
}
}
break;
case 'post':
// resubscribe from a specific post:
if( $post_ID == 0 )
{
$error_msg = T_('Invalid resubscribe link!');
}
else
{
if( $unsub_Comment )
{ // Anonymous user form Comment:
$DB->query( 'UPDATE T_comments
SET comment_anon_notify = 1
WHERE comment_item_ID = '.$unsub_Comment->get( 'item_ID' ).'
AND comment_author_user_ID IS NULL
AND comment_author_email = '.$DB->quote( $unsub_Comment->get( 'author_email' ) ) );
}
else
{ // Registered User:
$ItemCache = & get_ItemCache();
$BlogCache = & get_BlogCache();
$Item = $ItemCache->get_by_ID( $post_ID );
$blog_ID = $Item->get_blog_ID();
$Blog = $BlogCache->get_by_ID( $blog_ID );
if( $Blog->get( 'advanced_perms' )
&& $Blog->get_setting( 'allow_item_subscriptions' )
&& $Blog->get_setting( 'opt_out_item_subscription' )
&& $edited_User->check_perm( 'blog_ismember', 'view', false, $blog_ID ) )
{
$DB->query( 'REPLACE INTO T_items__subscriptions( isub_item_ID, isub_user_ID, isub_comments )
VALUES ( '.$post_ID.', '.$user_ID.', 1 )' );
}
else
{
$DB->query( 'INSERT INTO T_items__subscriptions( isub_item_ID, isub_user_ID, isub_comments )
VALUES ( '.$post_ID.', '.$user_ID.', 1 )' );
}
}
}
break;
case 'creator':
// resubscribe from the user own posts
$UserSettings->set( 'notify_published_comments', '1', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'cmt_moderation_reminder':
// resubscribe from comment moderation reminder notifications
$UserSettings->set( 'send_cmt_moderation_reminder', '1', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'comment_moderator':
case 'moderator': // Note: This was not chaned to 'comment_moderator' to make sure old emails subscribe link are also work
// resubscribe from new comment may need moderation notifications:
$UserSettings->set( 'notify_comment_moderation', '1', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'comment_moderator_edit':
// resubscribe from updated comment may need moderation notifications:
$UserSettings->set( 'notify_edit_cmt_moderation', '1', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'comment_moderator_spam':
// resubscribe from spam comment may need moderation notifications:
$UserSettings->set( 'notify_spam_cmt_moderation', '1', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'pst_moderation_reminder':
// resubscribe from post moderation reminder notifications
$UserSettings->set( 'send_pst_moderation_reminder', '1', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'pst_stale_alert':
// resubscribe from stale posts alert notifications:
$UserSettings->set( 'send_pst_stale_alert', '1', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'post_moderator':
// resubscribe from new post moderation notifications:
$UserSettings->set( 'notify_post_moderation', '1', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'post_assignment':
// resubscribe from post assignment notifications:
$UserSettings->set( 'notify_post_assignment', '1', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'post_moderator_edit':
// resubscribe to updated post moderation notifications:
$subs_edit_pst_type = param( 'subs_edit_pst_type', 'string', 'all' );
if( $subs_edit_pst_type == 'all' )
{ // If user was unsubscribed from ALL collections we should subsribe to ALL collections as well:
$UserSettings->set( 'notify_edit_pst_moderation', '1', $edited_User->ID );
$UserSettings->dbupdate();
}
elseif( ! empty( $coll_ID ) )
{ // If user was unsubscribed from SINGLE collection we should subsribe ONLY to that collection:
$SQL = new SQL( 'Get user subscription per collection for post modifications' );
$SQL->SELECT( 'sub_items_mod' );
$SQL->FROM( 'T_subscriptions' );
$SQL->WHERE( 'sub_coll_ID = '.$DB->quote( $coll_ID ) );
$SQL->WHERE_and( 'sub_user_ID = '.$DB->quote( $user_ID ) );
if( $DB->get_var( $SQL ) === '0' )
{ // If user is really unsubscribed from the selected collection:
$DB->query( 'UPDATE T_subscriptions
SET sub_items_mod = 1
WHERE sub_user_ID = '.$DB->quote( $user_ID ).'
AND sub_coll_ID = '.$DB->quote( $coll_ID ) );
}
}
break;
case 'post_proposed_change':
// resubscribe to post proposed change notifications:
$UserSettings->set( 'notify_post_proposed', '1', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'unread_msg':
// resubscribe from unread messages reminder
$UserSettings->set( 'notify_unread_messages', '1', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'new_msg':
// resubscribe from new messages notification
$UserSettings->set( 'notify_messages', '1', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'account_activation':
// resubscribe from account activation reminder
$UserSettings->set( 'send_activation_reminder', '1', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'newsletter':
// resubscribe from newsletter
// Use first newsletter by default for old unsubscribe url when we had only one static newsletter,
// which was upgraded to Newsletter with ID = 1
$newsletter_ID = param( 'newsletter', 'integer', 1 );
if( $edited_User->subscribe( $newsletter_ID ) )
{
// Send notification to owners of lists where user subscribed:
$edited_User->send_list_owner_notifications( 'subscribe' );
}
else
{ // Display a message is the user is not subscribed on the requested newsletter:
$error_msg = T_('You are already subscribed to this list.');
}
break;
case 'user_registration':
// resubscribe from new user registration notifications
$UserSettings->set( 'notify_new_user_registration', '1', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'account_activated':
// resubscribe from account activated notifications
$UserSettings->set( 'notify_activated_account', '1', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'account_closed':
// resubscribe from account closed notifications
$UserSettings->set( 'notify_closed_account', '1', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'account_reported':
// resubscribe from account reported notifications
$UserSettings->set( 'notify_reported_account', '1', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'account_changed':
// resubscribe from account changed notifications
$UserSettings->set( 'notify_changed_account', '1', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'msgform':
// turn on allow emails through b2evo message forms
$UserSettings->set( 'enable_email', '1', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'cronjob_error':
// resubscribe from cron job error notifications
$UserSettings->set( 'notify_cronjob_error', '1', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'automation_owner_notification':
// resubscribe from automation step owner notifications:
$UserSettings->set( 'notify_automation_owner', '1', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'meta_comment':
// resubscribe from internal comment notifications
$UserSettings->set( 'notify_meta_comments', '1', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'comment_mentioned':
// resubscribe to new comment notifications when user is mentioned:
$UserSettings->set( 'notify_comment_mentioned', '1', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'meta_comment_mentioned':
// resubscribe to new internal comment notifications when user is mentioned:
$UserSettings->set( 'notify_meta_comment_mentioned', '1', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'post_mentioned':
// resubscribe to new post notifications when user is mentioned:
$UserSettings->set( 'notify_post_mentioned', '1', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'list_new_subscriber':
// resubscribe from notifications when someone subscribes to one of the user's lists:
$UserSettings->set( 'notify_list_new_subscriber', '1', $edited_User->ID );
$UserSettings->dbupdate();
break;
case 'list_lost_subscriber':
// resubscribe from notifications when a user unsubscribes to one of the user's lists:
$UserSettings->set( 'notify_list_lost_subscriber', '1', $edited_User->ID );
$UserSettings->dbupdate();
break;
default:
// DEFENSIVE programming:
$error_msg = 'Unhandled resubscribe type.';
}
if( ! isset( $error_msg ) )
{
$resubscribed = true;
}
break;
}
}
$notification_prefix = T_( 'Notify me by email whenever' );
switch( $type )
{
case 'coll_comment':
// unsubscribe from new comment in collection notifications
if( $coll_ID == 0 )
{
$error_msg = T_('Invalid unsubscribe link!');
}
else
{
$BlogCache = & get_BlogCache();
$Blog = $BlogCache->get_by_ID( $coll_ID );
$type_str = T_('Notify me of any new comment in this collection').':<br /><a href="'.$Blog->get( 'url' ).'">'.$Blog->get_shortname().'</a>';
}
break;
case 'coll_post':
// unsubscribe from new post in collection notifications
if( $coll_ID == 0 )
{
$error_msg = T_('Invalid unsubscribe link!');
}
else
{
$BlogCache = & get_BlogCache();
$Blog = $BlogCache->get_by_ID( $coll_ID );
$type_str = T_('Notify me of any new post in this collection').':<br/><a href="'.$Blog->get( 'url' ).'">'.$Blog->get_shortname().'</a>';
}
break;
case 'post':
// unsubscribe from post update notifications
if( $post_ID == 0 )
{
$error_msg = T_('Invalid unsubscribe link!');
}
else
{
$ItemCache = & get_ItemCache();
$Item = $ItemCache->get_by_ID( $post_ID );
$type_str = T_('Notify me by email when someone comments here.').'<br/>'.$Item->get_title();
}
break;
case 'creator':
// unsubscribe from the user own posts
$type_str = $notification_prefix.': '.T_('a comment is published on one of <strong>my</strong> posts.');
break;
case 'cmt_moderation_reminder':
// unsubscribe from comment moderation reminder notifications
$type_str = $notification_prefix.': '.sprintf( T_('comments are awaiting moderation for more than %s.'), seconds_to_period( $Settings->get( 'comment_moderation_reminder_threshold' ) ) );
break;
case 'comment_moderator':
case 'moderator': // Note: This was not chaned to 'comment_moderator' to make sure old emails unsubscribe link are also work
// unsubscribe from new comment may need moderation notifications:
$type_str = $notification_prefix.': '.T_('a comment is posted and I have permissions to moderate it.');
break;
case 'comment_moderator_edit':
// unsubscribe from updated comment may need moderation notifications:
$type_str = $notification_prefix.': '.T_('a comment is modified and I have permissions to moderate it.');
break;
case 'comment_moderator_spam':
// unsubscribe from spam comment may need moderation notifications:
$type_str = $notification_prefix.': '.T_('a comment is reported as spam and I have permissions to moderate it.');
break;
case 'pst_moderation_reminder':
// unsubscribe from post moderation reminder notifications
$type_str = $notification_prefix.': '.sprintf( T_('posts are awaiting moderation for more than %s.'), seconds_to_period( $Settings->get( 'post_moderation_reminder_threshold' ) ) );
break;
case 'pst_stale_alert':
// unsubscribe from stale posts alert notifications:
$type_str = $notification_prefix.': '.T_('there are stale posts and I have permission to moderate them.');
break;
case 'post_moderator':
// unsubscribe from new post moderation notifications:
$type_str = $notification_prefix.': '.T_('a post is created and I have permissions to moderate it.');
break;
case 'post_assignment':
// unsubscribe from post assignment notifications:
$type_str = $notification_prefix.': '.T_('a post was assigned to me.');
break;
case 'post_moderator_edit':
// unsubscribe from updated post moderation notifications:
$type_str = $notification_prefix.': '.T_('a post is modified and I have permissions to moderate it.');
break;
case 'post_proposed_change':
// unsubscribe from post proposed change notifications:
$type_str = $notification_prefix.': '.T_('someone proposed a change on a post and I have permissions to moderate it.');
break;
case 'unread_msg':
// unsubscribe from unread messages reminder
$type_str = $notification_prefix.': '.sprintf( T_('I have unread private messages for more than %s.'), seconds_to_period( $Settings->get( 'unread_message_reminder_threshold' ) ) );
break;
case 'new_msg':
// unsubscribe from new messages notification
$type_str = $notification_prefix.': '.T_('I receive a private message.');
break;
case 'account_activation':
// unsubscribe from account activation reminder
$type_str = $notification_prefix.': '.sprintf( T_('my account was deactivated or is not activated for more than %s.'), seconds_to_period( $Settings->get( 'activate_account_reminder_threshold' ) ) );
break;
case 'newsletter':
// unsubscribe from newsletter
// Use first newsletter by default for old unsubscribe url when we had only one static newsletter,
// which was upgraded to Newsletter with ID = 1
$newsletter_ID = param( 'newsletter', 'integer', 1 );
$NewsletterCache = & get_NewsletterCache();
$Newsletter = $NewsletterCache->get_by_ID( $newsletter_ID );
$type_str = $Newsletter->get_name();
break;
case 'user_registration':
// unsubscribe from new user registration notifications
$type_str = $notification_prefix.': '.T_( 'a new user has registered.' );
break;
case 'account_activated':
// unsubscribe from account activated notifications
$type_str = $notification_prefix.': '.T_( 'an account was activated.' );
break;
case 'account_closed':
// unsubscribe from account closed notifications
$type_str = $notification_prefix.': '.T_( 'an account was closed.' );
break;
case 'account_reported':
// unsubscribe from account reported notifications
$type_str = $notification_prefix.': '.T_( 'an account was reported.' );
break;
case 'account_changed':
// unsubscribe from account changed notifications
$type_str = $notification_prefix.': '.T_( 'an account was changed.' );
break;
case 'msgform':
// turn off allow emails through b2evo message forms
$type_str = T_( 'emails through a message form that will NOT reveal my email address.' );
break;
case 'cronjob_error':
// unsubscribe from cron job error notifications
$type_str = $notification_prefix.': '.T_( 'a scheduled task ends with an error or timeout.' );
break;
case 'automation_owner_notification':
// unsubscribe from automation step owner notifications:
$type_str = $notification_prefix.': '.T_( 'one of my automations wants to notify me.' );
break;
case 'meta_comment':
// unsubscribe from internal comment notifications
$type_str = $notification_prefix.': '.T_('an internal comment is posted.');
break;
case 'comment_mentioned':
// unsubscribe from new comment notifications when user is mentioned:
$type_str = $notification_prefix.': '.T_('I have been mentioned on a comment.');
break;
case 'meta_comment_mentioned':
// unsubscribe from new internal comment notifications when user is mentioned:
$type_str = $notification_prefix.': '.T_('I have been mentioned on an internal comment.');
break;
case 'post_mentioned':
// unsubscribe from new comment notifications when user is mentioned:
$type_str = $notification_prefix.': '.T_('I have been mentioned on a post.');
break;
case 'list_new_subscriber':
// unsubscribe from notifications when someone subscribes to one of the user's lists:
$type_str = $notification_prefix.': '.T_('one of my Lists gets a new subscriber.');
break;
case 'list_lost_subscriber':
// unsubscribe from notifications when a user unsubscribes to one of the user's lists:
$type_str = $notification_prefix.': '.T_('one of my Lists loses a subscriber.');
break;
default:
// DEFENSIVE programming:
$type_str = T_('Unhandled unsubscribe type');
}
// Form template
$unsubscribe_form_params = array(
'layout' => 'fieldset',
'formclass' => 'form-horizontal',
'formstart' => '<div class="panel panel-default">'
.'<div class="panel-heading">'
.'<h3 class="panel-title">$form_title$</h3>'
.'</div>'
.'<div class="panel-body">',
'formend' => '</div></div>',
'title_fmt' => '<span style="float:right">$global_icons$</span><h2>$title$</h2>'."\n",
'no_title_fmt' => '<span style="float:right">$global_icons$</span>'."\n",
'fieldset_begin' => '<div class="fieldset_wrapper $class$" id="fieldset_wrapper_$id$"><fieldset $fieldset_attribs$>'."\n"
.'<legend $title_attribs$>$fieldset_title$</legend>'."\n",
'fieldset_end' => '</fieldset></div>'."\n",
'fieldstart' => '<div class="form-group" $ID$>'."\n",
'fieldend' => "</div>\n\n",
'labelclass' => 'control-label col-xs-3',
'labelstart' => '',
'labelend' => "\n",
'labelempty' => '<label class="control-label col-xs-3"></label>',
'inputstart' => '<div class="controls col-xs-9">',
'inputend' => "</div>\n",
'infostart' => '<div class="controls col-xs-9"><p class="form-control-static">',
'infoend' => "</p></div>\n",
'buttonsstart' => '<div class="form-group text-center"><div class="control-buttons col-xs-12">',
'buttonsend' => "</div></div>\n\n",
'customstart' => '<div class="custom_content">',
'customend' => "</div>\n",
'note_format' => ' <span class="help-inline">%s</span>',
'bottom_note_format' => ' <div><span class="help-inline">%s</span></div>',
// Additional params depending on field type:
// - checkbox
'inputclass_checkbox' => '',
'inputstart_checkbox' => '<div class="controls col-sm-9"><div class="checkbox"><label>',
'inputend_checkbox' => "</label></div></div>\n",
'checkbox_newline_start' => '<div class="checkbox">',
'checkbox_newline_end' => "</div>\n",
// - radio
'fieldstart_radio' => '<div class="form-group radio-group" $ID$>'."\n",
'fieldend_radio' => "</div>\n\n",
'inputclass_radio' => '',
'radio_label_format' => '$radio_option_label$',
'radio_newline_start' => '<div class="radio"><label>',
'radio_newline_end' => "</label></div>\n",
'radio_oneline_start' => '<label class="radio-inline">',
'radio_oneline_end' => "</label>\n",
);
// Default params:
$params = array_merge( array(
'wrap_width' => '580px',
'skin_form_before' => '',
'skin_form_after' => '',
'unsubscribe_page_before' => '<div class="evo_panel__unsubscribe">',
'unsubscribe_page_after' => '</div>',
'unsubscribe_form_title' => T_('Unsubscribe'),
'form_class_unsubscribe' => 'evo_form__unsubscribe',
'unsubscribe_links_attrs' => ' style="margin: 1em 0 1ex"',
'unsubscribe_field_width' => 140,
'unsubscribe_form_footer' => true,
'unsubscribe_form_params' => NULL,
'unsubscribe_disp_home_button' => false, // Display button to go home when registration is disabled
'display_form_messages' => false,
), $params );
// Header
$page_title = $params['unsubscribe_form_title'];
$wrap_width = $params['wrap_width'];