-
Notifications
You must be signed in to change notification settings - Fork 0
/
e-newsletter.php
executable file
·2742 lines (2231 loc) · 133 KB
/
e-newsletter.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
/*
Plugin Name: PS-eNewsletter
Plugin URI: https://cp-psource.github.io/ps-newsletter/
Description: Das ultimative Newsletter Plugin für WordPress. Keine Drittanbieterdienste oder Abo-Kosten, Newsletter direkt aus dem WordPress-Dashboard managen und versenden.
Natürlich mit der großartigen Piestingtal.Source Kompatibilität.
Version: 2.8.9
Text Domain: email-newsletter
Author: PSOURCE
Author URI: https://github.com/cp-psource
Copyright 2018-2024 PSOURCE (https://github.com/cp-psource)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License (Version 2 - GPLv2) as published by
the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
if ( ! defined( 'ABSPATH' ) ) {
die( 'Es tut uns leid, aber Du kannst nicht direkt auf diese Datei zugreifen.' );
}
/**
* @@@@@@@@@@@@@@@@@ PS UPDATER 1.3 @@@@@@@@@@@
**/
require 'psource/psource-plugin-update/plugin-update-checker.php';
use YahnisElsts\PluginUpdateChecker\v5\PucFactory;
$myUpdateChecker = PucFactory::buildUpdateChecker(
'https://github.com/cp-psource/ps-newsletter',
__FILE__,
'ps-newsletter'
);
//Set the branch that contains the stable release.
$myUpdateChecker->setBranch('master');
/**
* @@@@@@@@@@@@@@@@@ ENDE PS UPDATER 1.3 @@@@@@@@@@@
**/
require_once( 'email-newsletter-files/class.functions.php' );
require_once( 'email-newsletter-files/builder/class.builder.php' );
include_once( 'email-newsletter-files/class.wp_widgets.php' );
/**
* Plugin main class
**/
class Email_Newsletter extends Email_Newsletter_functions {
var $plugin_ver;
var $plugin_main_file;
var $plugin_dir;
var $plugin_url;
var $template_directory;
var $template_custom_directory;
var $settings;
var $tb_prefix;
var $cron_send_name;
var $cron_bounce_name;
var $plugin_templates = array();
var $capabilities = array();
var $loaded_theme_options = '';
var $debug;
/**
* PHP 5 constructor
**/
function __construct() {
global $wpdb;
$this->plugin_ver = 2.88;
//enable or disable debugging
$this->debug = 0;
//checking for MultiSite
if ( 1 < $wpdb->blogid )
$this->tb_prefix = $wpdb->base_prefix . $wpdb->blogid . '_';
else
$this->tb_prefix = $wpdb->base_prefix;
//set cron names
$this->cron_send_name = 'e_newsletter_cron_send_' . $wpdb->blogid;
$this->cron_bounce_name = 'e_newsletter_cron_check_bounces_' . $wpdb->blogid;
//setup proper directories
$this->plugin_main_file = __FILE__;
$this->plugin_dir = plugin_dir_path( __FILE__ );
$this->plugin_url = plugins_url( '/', __FILE__ );
if(!isset($this->plugin_dir) || !isset($this->plugin_url))
wp_die( __('Es gab ein Problem beim Bestimmen des Plugin-Pfads oder der URL', 'email-newsletter' ) );
//templates directories
$this->template_directory = $this->plugin_dir . 'email-newsletter-files/templates';
$this->template_custom_directory = $this->get_custom_theme_dir();
//get all setting of plugin
$this->settings = $this->get_settings();
// Setup all plugin capabilities
$this->capabilities['create_newsletter'] = __('Newsletter erstellen','email-newsletter');
$this->capabilities['save_newsletter'] = __('Newsletter bearbeiten','email-newsletter');
$this->capabilities['send_newsletter'] = __('Newsletter senden','email-newsletter');
$this->capabilities['delete_newsletter'] = __('Newsletter löschen','email-newsletter');
$this->capabilities['create_newsletter_group'] = __('Newsletter-Gruppen erstellen','email-newsletter');
$this->capabilities['edit_newsletter_group'] = __('Newsletter-Gruppen bearbeiten','email-newsletter');
$this->capabilities['delete_newsletter_group'] = __('Newsletter-Gruppen löschen','email-newsletter');
$this->capabilities['change_newsletter_group'] = __('Newsletter-Gruppen ändern','email-newsletter');
$this->capabilities['view_newsletter_members'] = __('Newsletter-Abonnenten anzeigen','email-newsletter');
$this->capabilities['add_newsletter_member'] = __('Newsletter-Abonnenten hinzufügen','email-newsletter');
$this->capabilities['edit_newsletter_member'] = __('Newsletter-Abonnenten bearbeiten','email-newsletter');
$this->capabilities['delete_newsletter_member'] = __('Newsletter-Abonnenten löschen','email-newsletter');
$this->capabilities['add_members_group'] = __('Abonnenten zur Gruppe hinzufügen','email-newsletter');
$this->capabilities['delete_members_group'] = __('Abonnenten aus Gruppe löschen','email-newsletter');
$this->capabilities['save_newsletter_settings'] = __('Newsletter-Einstellungen Speichern','email-newsletter');
$this->capabilities['view_newsletter_dashboard'] = __('Dashboard-Seite anzeigen','email-newsletter');
$this->capabilities['import_newsletter_members'] = __('Abonnenten importieren','email-newsletter');
$this->capabilities['install_newsletter'] = __('Erstinstallation','email-newsletter');
$this->capabilities['uninstall_newsletter'] = __('Deinstalliere alle Newsletter-Daten','email-newsletter');
//Activate/deactivate actions
register_activation_hook( $this->plugin_dir . 'e-newsletter.php', array( &$this, 'do_activation' ) );
register_deactivation_hook( $this->plugin_dir . 'e-newsletter.php', array( &$this, 'do_deactivation' ) );
//add new rewrite rules
add_filter( 'rewrite_rules_array', array( &$this, 'insert_rewrite_rules' ) );
add_filter( 'query_vars', array( &$this, 'insert_query_vars' ) );
add_action('plugins_loaded',array(&$this,'upgrade_check'));
add_action( 'email_newsletter_upgrade_cron',array( &$this, 'upgrade_cron' ) );
add_action( 'admin_init', array( &$this, 'admin_init' ) );
add_action( 'admin_enqueue_scripts', array(&$this,'admin_enqueue_scripts'));
// filter schedules
add_filter( 'cron_schedules', array( &$this, 'add_new_cron_time' ) );
add_action( 'init', array( &$this, 'init' ), 999 );
//some actions for MultiSite
if ( function_exists( 'is_multisite' ) && is_multisite() ) {
add_action( 'wpmu_activate_user', array( &$this, 'user_create' ) );
add_action( 'wpmu_new_user', array( &$this, 'user_create' ) );
add_action( 'added_existing_user', array( &$this, 'user_create' ) );
add_action( 'remove_user_from_blog', array( &$this, 'user_remove_from_site' ) );
add_action( 'wpmu_delete_user', array( &$this, 'user_delete' ) );
add_action( 'delete_blog', array( &$this, 'uninstall' ) );
add_action( 'network_admin_menu', array( &$this, 'admin_page' ) );
}
//changing list of members when we create or delete user of the standard site
add_action( 'user_register', array( &$this, 'user_create' ) );
add_action( 'delete_user', array( &$this, 'user_delete' ) );
//Update member when editing user action
add_action( 'edit_user_profile_update', array( &$this, 'edit_user_update_member' ) );
add_action( 'personal_options_update', array( &$this, 'edit_user_update_member' ) );
add_action( 'edit_user_profile', array( &$this, 'wp_admins_profile' ) );
add_action( 'show_user_profile', array( &$this, 'wp_admins_profile' ) );
//creating menu of the plugin
add_action( 'admin_menu', array( &$this, 'admin_page' ) );
//send email by WP-CRON
add_action( $this->cron_send_name, array( &$this, 'send_by_wpcron' ) );
//check bounces email by WP-CRON
add_action( $this->cron_bounce_name .'_1', array( &$this, 'check_bounces' ) );
add_action( $this->cron_bounce_name .'_2', array( &$this, 'check_bounces' ) );
//subscribe widget stuff
add_shortcode( 'enewsletter_subscribe', array( &$this, 'subscribe_shortcode' ) );
add_action( 'wp_enqueue_scripts', array( &$this, 'email_newsletter_widgets_scripts' ) );
//unsubscribe message
add_shortcode( 'enewsletter_unsubscribe_message', array( &$this, 'unsubscribe_message_shortcode' ) );
//unsubscribe message
add_shortcode( 'enewsletter_subscribe_message', array( &$this, 'subscribe_message_shortcode' ) );
//ajax action for sent preview (test) email
//add_action( 'wp_ajax_nopriv_send_preview', array( &$this, 'send_preview_ajax' ) );
add_action( 'wp_ajax_send_email_preview', array( &$this, 'send_preview_ajax' ) );
//ajax action for change member's group on members page
add_action( 'wp_ajax_nopriv_change_groups', array( &$this, 'change_groups_ajax' ) );
add_action( 'wp_ajax_change_groups', array( &$this, 'change_groups_ajax' ) );
//ajax action for show transparent image 1x1 for check that email was opened
add_action( 'wp_ajax_nopriv_check_email_opened', array( &$this, 'check_email_opened_ajax' ) );
add_action( 'wp_ajax_check_email_opened', array( &$this, 'check_email_opened_ajax' ) );
//ajax action for test connection to bounces email
add_action( 'wp_ajax_nopriv_test_bounces', array( &$this, 'test_bounces_ajax' ) );
add_action( 'wp_ajax_test_bounces', array( &$this, 'test_bounces_ajax' ) );
//ajax action for test connection to smtp server
add_action( 'wp_ajax_nopriv_test_smtp', array( &$this, 'test_smtp_ajax' ) );
add_action( 'wp_ajax_test_smtp', array( &$this, 'test_smtp_ajax' ) );
//ajax action for sand email to member
add_action( 'wp_ajax_nopriv_send_email_to_member', array( &$this, 'send_email_to_member' ) );
add_action( 'wp_ajax_send_email_to_member', array( &$this, 'send_email_to_member' ) );
//ajax action for subscribing
add_action( 'wp_ajax_manage_subscriptions_ajax', array( &$this, 'manage_subscriptions_ajax' ));
add_action( 'wp_ajax_nopriv_manage_subscriptions_ajax', array( &$this, 'manage_subscriptions_ajax'));
// filter does shortcodes
add_filter('email_newsletter_make_email_content', 'do_shortcode', 11);
add_action( 'template_redirect', array( &$this, 'template_redirect' ), 12 );
//privacy
add_filter( 'wp_privacy_personal_data_exporters', array( $this, 'register_plugin_exporter' ), 10 );
add_filter( 'wp_privacy_personal_data_erasers', array( $this, 'register_plugin_eraser' ), 10 );
//depraciated
add_action( 'wp_ajax_nopriv_confirm_subscibe', array( &$this, 'confirm_subscibe_ajax' ) );
add_action( 'wp_ajax_confirm_subscibe', array( &$this, 'confirm_subscibe_ajax' ) );
add_action( 'wp_ajax_nopriv_newsletter_unsubscribe', array( &$this, 'unsubscribe_ajax' ) );
add_action( 'wp_ajax_newsletter_unsubscribe', array( &$this, 'unsubscribe_ajax' ) );
}
/**
* Do the stuff on activation
*
*/
function do_activation() {
global $email_builder;
//Update rewrite_rules
flush_rewrite_rules( false );
//create folder for custom themes
$custom_theme_dir = $this->get_custom_theme_dir();
if (!is_dir($custom_theme_dir)) {
mkdir($custom_theme_dir);
}
//sets up cron
$settings = $this->get_settings();
if ( 1 == $settings['cron_enable'] ) {
if ( wp_next_scheduled( $this->cron_send_name ) )
wp_clear_scheduled_hook( $this->cron_send_name );
wp_schedule_event( time(), '2mins', $this->cron_send_name );
}
else {
if ( wp_next_scheduled( $this->cron_send_name ) )
wp_clear_scheduled_hook( $this->cron_send_name );
}
}
/**
* Do the stuff on deactivation
*
*/
function do_deactivation() {
if ( wp_next_scheduled( $this->cron_send_name ) )
wp_clear_scheduled_hook( $this->cron_send_name );
if ( wp_next_scheduled( $this->cron_bounce_name .'_1' ) )
wp_clear_scheduled_hook( $this->cron_bounce_name .'_1' );
if ( wp_next_scheduled( $this->cron_bounce_name .'_2' ) )
wp_clear_scheduled_hook( $this->cron_bounce_name .'_2' );
}
/**
* Do the stuff on upgrade
*
*/
function upgrade_check() {
//check if upgrade is necessary
if($this->is_plugin_active_for_network(plugin_basename($this->plugin_main_file))) {
$prev = get_site_option('email_newsletter_version', 2);
$upgraded_cron = get_site_option('email_newsletter_upgraded_cron', 1);
}
else {
$prev = get_option('email_newsletter_version', 1.25);
$upgraded_cron = get_option('email_newsletter_upgraded_cron', 1);
}
if ($this->plugin_ver > $prev) {
$this->upgrade('', $prev);
if($this->is_plugin_active_for_network(plugin_basename($this->plugin_main_file)))
update_site_option('email_newsletter_version', $this->plugin_ver);
else
update_option('email_newsletter_version', $this->plugin_ver);
}
if(!$upgraded_cron && !wp_next_scheduled('email_newsletter_upgrade_cron')) {
wp_schedule_single_event(time(), 'email_newsletter_upgrade_cron');
}
}
/**
* Adding a new rule
**/
function insert_rewrite_rules( $rules ) {
$newrules = array();
$newrules['e-newsletter/unsubscribe/([\w\d]{15})(\d*)/?$'] = 'index.php?unsubscribe_page=1&unsubscribe_code=$matches[1]&unsubscribe_member_id=$matches[2]';
$newrules['e-newsletter/view/([\w\d]{15})(\d*)/?$'] = 'index.php?view_newsletter=1&view_newsletter_code=$matches[1]&view_newsletter_send_id=$matches[2]';
return $newrules + $rules;
}
/**
* Adding the var for unsubscribe page
**/
function insert_query_vars( $vars ) {
array_push( $vars, 'subscribe_page' );
array_push( $vars, 'subscribe_code' );
array_push( $vars, 'subscribe_member_id' );
array_push( $vars, 'unsubscribe_page' );
array_push( $vars, 'unsubscribe_code' );
array_push( $vars, 'unsubscribe_member_id' );
array_push( $vars, 'view_newsletter' );
array_push( $vars, 'view_newsletter_code' );
array_push( $vars, 'view_newsletter_send_id' );
return $vars;
}
/**
* Loads script for enewsletter admin area
*/
function admin_enqueue_scripts($hook) {
global $wp_version;
//including JS scripts and CSS for Newsletter pages
if ( isset( $_REQUEST['page'] ) && 1 == $this->is_enewsletter_page( $_REQUEST['page'] ) ) {
wp_enqueue_script( 'jquery' );
//including JS scripts
wp_enqueue_script( 'jquery-ui-tabs' );
wp_enqueue_script( 'jquery-ui-core' );
//including JS scripts for tooltips
wp_register_script( 'jquery_tooltips', $this->plugin_url . 'email-newsletter-files/js/jquery.tools.min.js' );
wp_enqueue_script( 'jquery_tooltips' );
//including JS scripts for progressbar
//wp_register_script( 'jquery_ui_widget', $this->plugin_url . 'email-newsletter-files/js/ui.widget.js' );
wp_enqueue_script( 'jquery-ui-widget' );
//including JS scripts for progressbar
//wp_register_script( 'jquery_progressbar', $this->plugin_url . 'email-newsletter-files/js/jquery.ui.progressbar.js' );
wp_enqueue_script( 'jquery-ui-progressbar' );
// Including CSS file
wp_register_style( 'enewsletter-style', $this->plugin_url . 'email-newsletter-files/css/admin.css' );
wp_enqueue_style( 'enewsletter-style' );
// Including JS file
wp_register_script( 'enewsletter-script', $this->plugin_url . 'email-newsletter-files/js/admin.js' );
wp_enqueue_script( 'enewsletter-script' );
$admin_js_options = array(
'edit' => __( 'Bearbeiten', 'email-newsletter' ),
'close' => __( 'Schließen', 'email-newsletter' ),
'save' => __( 'Speichern', 'email-newsletter' ),
'write_email' => __( 'Bitte schreibe eine E-Mailadresse des Abonnents', 'email-newsletter' ),
'show_add_member' => __( 'Öffne Formular für neue Abonnenten/Importe an', 'email-newsletter' ),
'hide_add_member' => __( 'Blende die neuen Abonnenten-/Importformulare aus', 'email-newsletter' ),
'show_export_member' => __( 'Öffne Formular für Abonnentenexport an', 'email-newsletter' ),
'hide_export_member' => __( 'Blende das Formular für Exportmitglieder aus', 'email-newsletter' ),
'proper_email' => __( 'Bitte verwende die richtige E-Mail', 'email-newsletter' ),
'proper_email' => __( 'Bitte verwende die richtige E-Mail', 'email-newsletter' ),
'confirm' => __( 'Bist Du Dir sicher?', 'email-newsletter' ),
'save_groups' => __( 'Gruppen speichern', 'email-newsletter' ),
'change_groups' => __( 'Gruppen ändern', 'email-newsletter' ),
'select_members' => __( 'Wähle Abonnenten aus.', 'email-newsletter' ),
'settings_tab' => (isset($_GET['tab'])) ? $_GET['tab'] : (!$this->settings ? 'tabs-2' : 'tabs-1'),
'smtp_warning' => __( 'Bitte schreibe SMTP Outgoing Server oder wähle eine andere Sendemethode!', 'email-newsletter' )
);
wp_localize_script( 'enewsletter-script', 'enewsletter', $admin_js_options );
}
wp_register_style( 'enewsletter-mp6', $this->plugin_url . 'email-newsletter-files/css/mp6.css');
wp_enqueue_style('enewsletter-mp6');
}
/**
* Manage page redirects if necessary
**/
function template_redirect() {
if ( $this->is_enewsletter_page( 'unsubscribe_page' ) ) {
$member_id = get_query_var( 'unsubscribe_member_id' );
$unsubscribe_code = get_query_var( 'unsubscribe_code' );
$result = $this->unsubscribe_by_code( $unsubscribe_code );
if ( !$result['error'] ) {
$message = $result['message'];
$unsubscribed = 1;
}
else {
$message = $result['message'];
$unsubscribed = 0;
}
if(isset($this->settings['unsubscribe_page_id']) && is_numeric($this->settings['unsubscribe_page_id']) && get_post($this->settings['unsubscribe_page_id']))
wp_redirect( add_query_arg( array('member_id' => $member_id, 'message' => urlencode($message), 'enewsletter_unsubscribed' => $unsubscribed), get_permalink($this->settings['unsubscribe_page_id']) ) );
else {
if($unsubscribed)
echo "<center><br /><br /><br /><h2 style='color: #19700A;'>" . $message . "</h2></center>";
else
echo "<center><br /><br /><br /><h2 style='color: #ff0000;'>" . $message . "</h2></center>";
}
exit;
}
if ( $this->is_enewsletter_page( 'subscribe_page' ) ) {
global $wpdb;
$subscribed = 0;
$member_id = get_query_var( 'subscribe_member_id' );
$subscribe_code = get_query_var( 'subscribe_code' );
if ( $subscribe_code != md5( "sometext123" . $member_id ) )
$message = __( 'Fehler: Falsche Abonnementdaten!', 'email-newsletter' );
$member_data = $this->get_member( $member_id );
if($member_data) {
if(empty($member_data['unsubscribe_code'])) {
$unsubscribe_code = $this->gen_unsubscribe_code();
$result = $wpdb->query( $wpdb->prepare( "UPDATE {$this->tb_prefix}enewsletter_members SET member_info = '', unsubscribe_code = '%s' WHERE member_id = %d", $unsubscribe_code, $member_id ) );
//creating new list of groups for user
if ( is_array( $member_data['future_groups_id'] ) )
$this->add_members_to_groups( $member_id, $member_data['future_groups_id'] );
if($this->settings['subscribe_newsletter']) {
$send_details = $this->add_send_email_info( $this->settings['subscribe_newsletter'], $member_id, 0, 'waiting_send' );
$this->send_email_to_member($send_details['send_id']);
}
$subscribed = 1;
$message = __( 'Erfolgreiches Abonnement!', 'email-newsletter' );
}
else {
$message = __( 'Abonnent bereits abonniert!', 'email-newsletter' );
}
}
else {
$message = __( 'Beim Abonnieren ist ein Problem aufgetreten!', 'email-newsletter' );
}
if(isset($this->settings['subscribe_page_id']) && is_numeric($this->settings['subscribe_page_id']) && get_post($this->settings['subscribe_page_id']))
wp_redirect( add_query_arg( array('member_id' => $member_id, 'message' => urlencode($message), 'enewsletter_subscribed' => $subscribed), get_permalink($this->settings['subscribe_page_id']) ) );
else {
if($subscribed)
echo "<center><br /><br /><br /><h2 style='color: #19700A;'>" . $message . "</h2></center>";
else
echo "<center><br /><br /><br /><h2 style='color: #ff0000;'>" . $message . "</h2></center>";
}
exit;
}
elseif ( $this->is_enewsletter_page( 'view_newsletter' ) ) {
require_once( $this->plugin_dir . "email-newsletter-files/page-view-newsletter.php" );
exit;
}
}
/**
* init for admin
**/
function admin_init() {
$mu_cap = (function_exists('is_multisite' && is_multisite()) ? 'manage_network_options' : 'manage_options');
//Force caps for admin
$admin_role = get_role('administrator');
if(is_object($admin_role))
foreach($this->capabilities as $key => $cap) {
if(!isset($admin_role->capabilities[$key]) || $admin_role->capabilities[$key] == false ) {
$admin_role->add_cap($key,true);
}
}
//private actions of the plugin
if ( isset( $_REQUEST['newsletter_action'] ) ) {
//handle custom redirects
if(isset($_REQUEST['redirect_to']))
$redirect = esc_url_raw($_REQUEST['redirect_to']);
switch( $_REQUEST[ 'newsletter_action' ] ) {
//action for save Newsletter
case "clone_newsletter":
if(! (current_user_can('create_newsletter') || current_user_can($mu_cap)) )
wp_die('Du hast keine Erlaubnis das zu tun');
$result = $this->clone_newsletter( $_REQUEST['newsletter_id'], $_REQUEST['page'] );
$redirect = !isset($redirect) ? add_query_arg( array( 'page' => 'newsletters', 'updated' => 'true', 'message' => urlencode( __( 'Der Newsletter wurde kopiert!', 'email-newsletter' ) ) ), 'admin.php' ) : $redirect;
wp_redirect( $redirect );
exit();
break;
//action for delete Newsletter
case "delete_newsletter":
if(! (current_user_can('delete_newsletter') || current_user_can($mu_cap)) )
wp_die('Du hast keine Erlaubnis das zu tun');
$result = $this->delete_newsletter( $_REQUEST['newsletter_id'] );
$redirect = !isset($redirect) ? add_query_arg( array( 'page' => 'newsletters', 'updated' => 'true', 'message' => urlencode( __( 'Der Newsletter wird gelöscht!', 'email-newsletter' ) ) ), 'admin.php' ) : $redirect;
wp_redirect( $redirect );
exit();
break;
//action for create new group
case "create_group":
if(! (current_user_can('create_newsletter_group') || current_user_can($mu_cap)) )
wp_die('Du hast keine Erlaubnis das zu tun');
$edit_public = ( isset( $_REQUEST['public'] ) ) ? '1' : '0';
$result = $this->create_edit_group( $_REQUEST['group_name'], $edit_public );
$redirect = !isset($redirect) ? add_query_arg( array( 'page' => 'newsletters-groups', 'updated' => 'true', 'message' => urlencode( $result['message'] ) ), 'admin.php' ) : $redirect;
wp_redirect( $redirect );
exit();
break;
//action for edit group
case "edit_group":
if(! (current_user_can('edit_newsletter_group') || current_user_can($mu_cap)) )
wp_die('Du hast keine Erlaubnis das zu tun');
$edit_public = ( isset( $_REQUEST['edit_public'] ) ) ? '1' : '0';
$result = $this->create_edit_group( $_REQUEST['edit_group_name'], $edit_public, $_REQUEST['group_id'] );
$redirect = !isset($redirect) ? add_query_arg( array( 'page' => 'newsletters-groups', 'updated' => 'true', 'message' => urlencode( $result['message'] ) ), 'admin.php' ) : $redirect;
wp_redirect( $redirect );
exit();
break;
//action for delete group
case "delete_group":
if(! (current_user_can('delete_newsletter_group') || current_user_can($mu_cap)) )
wp_die('Du hast keine Erlaubnis das zu tun');
$result = $this->delete_group( $_REQUEST['group_id'] );
$redirect = !isset($redirect) ? add_query_arg( array( 'page' => 'newsletters-groups', 'updated' => 'true', 'message' => urlencode( __( 'Gruppe wird gelöscht!', 'email-newsletter' ) ) ), 'admin.php' ) : $redirect;
wp_redirect( $redirect );
exit();
break;
//action add new member
case "add_member":
if(! (current_user_can('add_newsletter_member') || current_user_can($mu_cap)) )
wp_die('Du hast keine Erlaubnis das zu tun');
$result = $this->add_member( $_REQUEST['member'] );
$redirect = !isset($redirect) ? esc_url_raw(add_query_arg( array( 'page' => 'newsletters-members', 'updated' => 'true', 'message' => urlencode( $result['message'] ) ) )) : $redirect;
wp_redirect( $redirect );
exit();
break;
//action edit member
case "edit_member":
if(! (current_user_can('edit_newsletter_member') || current_user_can($mu_cap)) )
wp_die('Du hast keine Erlaubnis das zu tun');
$result = $this->edit_member( $_REQUEST['member_id'], $_REQUEST['edit_member_nicename'], $_REQUEST['edit_member_email'] );
$redirect = !isset($redirect) ? esc_url_raw(add_query_arg( array( 'page' => 'newsletters-members', 'updated' => 'true', 'message' => urlencode( $result['message'] ) ) ) ) : $redirect;
wp_redirect( $redirect );
exit();
break;
//action delete member
case "delete_member":
if(! (current_user_can('delete_newsletter_member') || current_user_can($mu_cap)) )
wp_die('Du hast keine Erlaubnis das zu tun');
$member_id = array($_REQUEST['member_id']);
$result = $this->delete_members( $member_id );
$redirect = !isset($redirect) ? esc_url_raw(add_query_arg( array( 'page' => 'newsletters-members', 'updated' => 'true', 'message' => urlencode( $result['message'] ) ) ) ) : $redirect;
wp_redirect( $redirect );
exit;
break;
//Bulk action delete members
case "delete_members":
if(! (current_user_can('delete_newsletter_member') || current_user_can($mu_cap)) )
wp_die('Du hast keine Erlaubnis das zu tun');
$result = $this->delete_members( $_REQUEST['members_id'] );
$redirect = !isset($redirect) ? esc_url_raw(add_query_arg( array( 'page' => 'newsletters-members', 'updated' => 'true', 'message' => urlencode( $result['message'] ) ) )) : $redirect;
wp_redirect( $redirect );
exit();
break;
//Bulk action add members to group
case "add_members_group":
if(! (current_user_can('add_members_group') || current_user_can($mu_cap)) )
wp_die('Du hast keine Erlaubnis das zu tun');
if($_REQUEST['list_group_id'] == 'subscribed' || $_REQUEST['list_group_id'] == 'unsubscribed') {
global $wpdb;
foreach ($_REQUEST['members_id'] as $member_id) {
$member_data = $this->get_member( $member_id );
if($member_data) {
if(empty($member_data['unsubscribe_code']) && $_REQUEST['list_group_id'] == 'subscribed')
$result = $wpdb->query( $wpdb->prepare( "UPDATE {$this->tb_prefix}enewsletter_members SET unsubscribe_code = '%s' WHERE member_id = %d", $this->gen_unsubscribe_code(), $member_id ) );
elseif(!empty($member_data['unsubscribe_code']) && $_REQUEST['list_group_id'] == 'unsubscribed')
$result = $wpdb->query( $wpdb->prepare( "UPDATE {$this->tb_prefix}enewsletter_members SET unsubscribe_code = '' WHERE member_id = %d", $member_id ) );
}
}
}
else
$result = $this->add_members_to_groups( $_REQUEST['members_id'], $_REQUEST['list_group_id'] );
$redirect = !isset($redirect) ? esc_url_raw(add_query_arg( array( 'page' => 'newsletters-members', 'updated' => 'true', 'message' => urlencode( __( 'Abonnenten werden der Gruppe hinzugefügt!', 'email-newsletter' ) ) ) )) : $redirect;
wp_redirect( $redirect );
exit();
break;
//action for change group
case "change_group":
if(! (current_user_can('change_newsletter_group') || current_user_can($mu_cap)) )
wp_die('Du hast keine Erlaubnis das zu tun');
//subscribe/unsubscribe if necessary TODO Consider turning it into function
$member_data = $this->get_member( $_REQUEST['member_id'] );
if($member_data) {
global $wpdb;
$subscribed = isset($_REQUEST['groups_id']) ? array_search('subscribed', $_REQUEST['groups_id']) : false;
if($subscribed !== false && empty($member_data['unsubscribe_code']))
$result = $wpdb->query( $wpdb->prepare( "UPDATE {$this->tb_prefix}enewsletter_members SET unsubscribe_code = '%s' WHERE member_id = %d", $this->gen_unsubscribe_code(), $_REQUEST['member_id'] ) );
elseif($subscribed === false && !empty($member_data['unsubscribe_code']))
$result = $wpdb->query( $wpdb->prepare( "UPDATE {$this->tb_prefix}enewsletter_members SET unsubscribe_code = '' WHERE member_id = %d", $_REQUEST['member_id'] ) );
}
if($subscribed !== false && isset($_REQUEST['groups_id'][$subscribed]))
unset($_REQUEST['groups_id'][$subscribed]);
$groups_id = ( isset( $_REQUEST['groups_id'] ) ) ? $_REQUEST['groups_id'] : array();
$result = $this->add_members_to_groups( $_REQUEST['member_id'], $groups_id, 1 );
$redirect = !isset($redirect) ? esc_url_raw(add_query_arg( array( 'page' => 'newsletters-members', 'updated' => 'true', 'message' => urlencode( __( 'Gruppen werden geändert!', 'email-newsletter' ) ) ) )) : $redirect;
wp_redirect( $redirect );
exit;
break;
//Bulk action add members to group
case "delete_members_group":
if(! (current_user_can('delete_members_group') || current_user_can($mu_cap)) )
wp_die('Du hast keine Erlaubnis das zu tun');
$result = $this->delete_members_group( $_REQUEST['members_id'], $_REQUEST['list_group_id'] );
$redirect = !isset($redirect) ? esc_url_raw(add_query_arg( array( 'page' => 'newsletters-members', 'updated' => 'true', 'message' => urlencode( __( 'Abonnenten werden aus der Gruppe gelöscht!', 'email-newsletter' ) ) ) )) : $redirect;
wp_redirect( $redirect );
exit();
break;
//Bulk action add members to group
case "export_members":
if(! (current_user_can('edit_newsletter_member') || current_user_can($mu_cap)) )
wp_die('Du hast keine Erlaubnis das zu tun');
if($_REQUEST['separ_sign'] == 1)
$separate_by = ';';
else
$separate_by = ',';
$groups_id = isset($_REQUEST['groups_id']) ? $_REQUEST['groups_id'] : array();
$groups_ungrouped = isset($_REQUEST['groups_ungrouped']) ? $_REQUEST['groups_ungrouped'] : 0;
$this->export_members($groups_id, $groups_ungrouped, $separate_by);
break;
//action save settings
case "save_settings":
if(! (current_user_can('save_newsletter_settings') || current_user_can($mu_cap)) )
wp_die('Du hast keine Erlaubnis das zu tun');
$this->save_settings( $_REQUEST['settings'] );
break;
//action send newsletter
case "send_newsletter":
if(! (current_user_can('send_newsletter') || current_user_can($mu_cap)) )
wp_die('Du hast keine Erlaubnis das zu tun');
//Handles sending ajax sent stopped newsletters
if ( isset( $_REQUEST['cron'] ) && 'add_to_cron' == $_REQUEST['cron'] )
$this->add_to_cron( $_REQUEST['newsletter_id'], $_REQUEST['send_id'] );
elseif ( isset( $_REQUEST['cron'] ) && 'remove_from_cron' == $_REQUEST['cron'] )
$this->remove_from_cron( $_REQUEST['newsletter_id'], $_REQUEST['send_id'] );
//handles main send buttons
else if ( isset( $_REQUEST['action'] ) && 'send' == $_REQUEST["action"] )
$this->send_newsletter( $_REQUEST['newsletter_id'] );
break;
//action import members
case "import_members":
if(! (current_user_can('import_newsletter_members') || current_user_can($mu_cap)) )
wp_die('Du hast keine Erlaubnis das zu tun');
$this->import_members();
break;
//action install data in DB
case "install":
if(! (current_user_can('install_newsletter') || current_user_can($mu_cap)) )
wp_die('Du hast keine Erlaubnis das zu tun');
$this->install();
$this->save_settings( $_REQUEST['settings'] );
break;
//action uninstall data from DB
case "uninstall":
if(! (current_user_can('uninstall_newsletter') || current_user_can($mu_cap)) )
wp_die('Du hast keine Erlaubnis das zu tun');
$this->uninstall();
//redirection must happen here because it will stop site deleting in network
$redirect = !isset($redirect) ? add_query_arg( array( 'page' => 'newsletters-settings', 'updated' => 'true', 'message' => urlencode( __( "eNewsletter Daten wurden gelöscht.", 'email-newsletter' ) ) ), 'admin.php' ) : $redirect;
wp_redirect( $redirect );
exit();
break;
case "dismiss_install":
if(!current_user_can($mu_cap))
wp_die('Du hast keine Erlaubnis das zu tun');
update_option('email_newsletter_install_dismissed', 1);
break;
}
}
if(!$this->settings && get_option('email_newsletter_install_dismissed', 0) == 0 && current_user_can($mu_cap))
add_action( 'all_admin_notices', array( &$this, 'install_notice' ), 5 );
//privacy stuff
if(function_exists('wp_add_privacy_policy_content')) {
$privacy_text = __( "Diese Website verfügt über ein Newsletter-Anmeldeformular, das Folgendes erfasst: Name des Besuchers, E-Mail-Adresse, Beitrittszeit und Abonnementgruppen. Diese Details werden später verwendet, um Newsletter an Abonnenten zu senden. Statistiken zum Newsletter (gesendet, geöffnet und zurückgeschickt) werden ebenfalls gesammelt. Benutzer können sich jederzeit mit einem Link in jedem Newsletter abmelden.", 'email-newsletter' );
wp_add_privacy_policy_content('E-Newsletter', $privacy_text);
}
}
function install_notice() {
echo '<div class="updated fade"><p>' . sprintf(__('Bitte <strong><a href="%s" title="Installiere jetzt »">Installiere und konfiguriere PS-eNewsletter</a></strong> um alle Features nutzen zu können. <small><a style="color:red;" href="%s">(Verwerfen)</a></small>', 'email-newsletter'), admin_url('admin.php?page=newsletters-settings'), add_query_arg('newsletter_action', 'dismiss_install')) . '</a></p></div>';
}
/**
* init for all users
**/
function init() {
//load translation files
load_plugin_textdomain( 'email-newsletter', false, dirname( plugin_basename( __FILE__ ) ) . '/email-newsletter-files/languages/' );
//public actions of the plugin
if ( isset( $_REQUEST['newsletter_action'] ) && !defined('DOING_AJAX') ) {
//handle custom redirects
if(isset($_REQUEST['redirect_to']))
$redirect = $_REQUEST['redirect_to'];
switch( $_REQUEST['newsletter_action'] ) {
//action for subscribe
case "new_subscribe":
$result = $this->new_subscribe();
$redirect = isset($redirect) ? $redirect : (isset($result['data']['redirect']) ? $result['data']['redirect'] : 0);
if($redirect) {
wp_redirect( $redirect );
exit();
}
break;
//action for subscribe
case "subscribe":
$result = $this->subscribe();
$redirect = !isset($redirect) ? add_query_arg( array( 'page' => 'newsletters-subscribes', 'updated' => 'true', 'message' => urlencode( $result['message'] )), 'admin.php' ) : $redirect;
wp_redirect( $redirect );
exit();
break;
//action for save selected groups of subscribe
case "save_subscribes":
$result = $this->save_subscribes();
$redirect = !isset($redirect) ? add_query_arg( array( 'page' => 'newsletters-subscribes', 'updated' => 'true', 'message' => urlencode( $result['message'] ) ), 'admin.php' ) : $redirect;
wp_redirect( $redirect );
exit();
break;
//action for Unsubscribe
case "unsubscribe":
$unsubscribe_code = (isset($_REQUEST['unsubscribe_code'])) ? $_REQUEST['unsubscribe_code'] : '';
$result = $this->unsubscribe_by_code( $unsubscribe_code );
$redirect = !isset($redirect) ? add_query_arg( array( 'page' => 'newsletters-subscribes', 'updated' => 'true', 'message' => urlencode( $result['message']) ), 'admin.php' ) : $redirect;
wp_redirect( $redirect );
exit();
break;
}
}
}
/**
* subscribtion actions moslty(only:)) for ajax widget
*/
function manage_subscriptions_ajax() {
if ( isset( $_REQUEST['newsletter_action'] ) ) {
switch( $_REQUEST['newsletter_action'] ) {
//action for save selected groups of subscribe
case "save_subscribes":
$result = $this->save_subscribes();
$data['message'] = $result['message'];
$data['view'] = 'manage_subscriptions';
$data['hide'] = '';
echo json_encode($data);
die();
break;
//action for forcing into groups
case "subscribe_to_groups":
$result = $this->save_subscribes('add');
$data['message'] = $result['message'];
$data['view'] = 'unsubscribe_from_groups';
$data['hide'] = 'subscribe_to_groups';
echo json_encode($data);
die();
break;
//action for forcing out off groups
case "unsubscribe_from_groups":
$result = $this->save_subscribes('remove');
$data['message'] = $result['message'];
$data['view'] = 'subscribe_to_groups';
$data['hide'] = 'unsubscribe_from_groups';
echo json_encode($data);
die();
break;
//action for subscribe
case "subscribe":
$result = $this->subscribe();
$data['message'] = $result['message'];
if(!$result['error']) {
if(isset($this->settings['subscribe_page_id']) && is_numeric($this->settings['subscribe_page_id']) && get_post($this->settings['subscribe_page_id']))
$data['redirect'] = add_query_arg(array('message' => urlencode($result['message']), 'enewsletter_subscribed' => 1), get_permalink($this->settings['subscribe_page_id']));
$data['view'] = 'manage_subscriptions';
$data['hide'] = 'subscribe';
$data['unsubscribe_code'] = $result['data']['unsubscribe_code'];
if(isset($result['data']['subscribe_groups']))
$data['subscribe_groups'] = $result['data']['subscribe_groups'];
}
else {
$data['view'] = 'subscribe';
$data['hide'] = 'subscribe';
}
echo json_encode($data);
die();
break;
//action for Unsubscribe
case "unsubscribe":
$unsubscribe_code = (isset($_REQUEST['unsubscribe_code'])) ? $_REQUEST['unsubscribe_code'] : '';
$result = $this->unsubscribe_by_code( $unsubscribe_code );
if(isset($this->settings['unsubscribe_page_id']) && is_numeric($this->settings['unsubscribe_page_id']) && get_post($this->settings['unsubscribe_page_id']))
$data['redirect'] = add_query_arg(array('message' => urlencode($result['message']), 'enewsletter_unsubscribed' => 1), get_permalink($this->settings['unsubscribe_page_id']));
$data['message'] = $result['message'];
$data['view'] = 'subscribe';
$data['hide'] = 'manage_subscriptions';
echo json_encode($data);
die();
break;
//action for Subscribe of public member (not user of site)
case "new_subscribe":
$result = $this->new_subscribe();
$data = array('message' => $result['message']);
if(isset($result['data']['redirect']))
$data['redirect'] = $result['data']['redirect'];
echo json_encode($data);
die();
break;
}
}
die();
}
/**
* Add new member
**/
function add_member( $member_data, $double_opt_in = 0 ) {
global $wpdb;
do_action( 'enewsletter_before_user_add', $member_data );
//first lets check if email exists somewhere
if ( email_exists( $member_data['email'] ) !== false ) {
//if email of new member == email of site user
$wp_user_id = email_exists( $member_data['email'] );
$member_id = $this->get_members_by_wp_user_id( $wp_user_id );
//check that this site's user there is on list of members
if ( 0 < $member_id )
$message = __( 'Diese E-Mail wird bereits verwendet!', 'email-newsletter' );
} else {
//check email of new member that isn't on list of members
$member = $this->get_member_by_email($member_data['email']);
if ( isset($member['unsubscribe_code']) && !empty($member['unsubscribe_code']) )
$message = __( 'Diese E-Mail ist bereits abonniert!', 'email-newsletter' );
}
if(isset($message))
return array('action' => 'email_exists', 'error' => true, 'message' => $message, 'data' => array());
//New email, lets add it!
$subscribe = $double_opt_in ? "" : 1;
$member_data['member_info'] = $double_opt_in ? serialize(array("future_groups_id" => $member_data['groups_id'])) : '';
$member_data_ready = array(
'member_fname' => $member_data['fname'],
'member_lname' => $member_data['lname'],
'member_email' => $member_data['email'],
'member_info' => $member_data['member_info']
);
$result = $this->create_update_member_user('', $member_data_ready, $subscribe);
$member_id = $result['member_id'];
do_action( 'enewsletter_after_user_add', $member_id );
if ( $double_opt_in ) {
$status = $this->do_double_opt_in( $member_id );
if($status)
return array('action' => 'optin_sent', 'error' => false, 'message' => __( 'Bestätigungs-E-Mail wurde gesendet! Bitte bestätige Dein Abonnement.', 'email-newsletter' ));
else
return array('action' => 'optin_sent', 'error' => true, 'message' => __( 'Fehler beim Senden der Anmelde-E-Mail. Stelle sicher, dass Du diese noch nicht in Deinem Posteingang hast.', 'email-newsletter' ));
} else {
//creating new list of groups for user
if ( isset( $member_data['groups_id'] ) && is_array( $member_data['groups_id'] ) )
$this->add_members_to_groups( $member_id, $member_data['groups_id'] );
//set sending welcome newsletter if necessary
if($this->settings['subscribe_newsletter']) {
$send_details = $this->add_send_email_info( $this->settings['subscribe_newsletter'], $member_id, 0, 'waiting_send' );
$this->send_email_to_member($send_details['send_id']);
}
}