-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemail-newsletter.php
964 lines (846 loc) · 35 KB
/
email-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
<?php
/*
Plugin Name: Email newsletter
Plugin URI: http://www.gopiplus.com/work/2010/09/25/email-newsletter/
Description: This easy-to-use plugin provides a simple way for Wordpress users to email registered users, commenters and subscribers. To place widget click <a href="widgets.php">here</a>.
Author: Gopi.R, tanaylakhani
Version: 20.15
Author URI: http://www.gopiplus.com
Donate link: http://www.gopiplus.com/work/2010/09/25/email-newsletter/
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
global $wpdb, $wp_version;
define("WP_eemail_TABLE", $wpdb->prefix . "eemail_newsletter");
define("WP_eemail_TABLE_SUB", $wpdb->prefix . "eemail_newsletter_sub");
define("WP_eemail_TABLE_SCF", $wpdb->prefix . "gCF");
define("WP_eemail_TABLE_APP", $wpdb->prefix . "eemail_newsletter_app");
//plugin version upgrades
define( 'EE_VERSION', '20.15' );
if (get_option('EE_VERSION') && strlen(get_option('EE_VERSION')) > 0){
if (get_option('EE_VERSION') !== EE_VERSION ) {
add_action('shutdown', 'ee_update');
}
} else {
update_option('EE_VERSION', EE_VERSION);
}
if (!function_exists('ee_update')) {
function ee_update() {
///plugin version check and upgrade code
}
}
if ( ! defined( 'EMAIL_PLUGIN_BASENAME' ) )
define( 'EMAIL_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
if ( ! defined( 'EMAIL_PLUGIN_NAME' ) )
define( 'EMAIL_PLUGIN_NAME', trim( dirname( EMAIL_PLUGIN_BASENAME ), '/' ) );
if ( ! defined( 'EMAIL_PLUGIN_DIR' ) )
define( 'EMAIL_PLUGIN_DIR', WP_PLUGIN_DIR . '/' . EMAIL_PLUGIN_NAME );
if ( ! defined( 'EMAIL_PLUGIN_URL' ) )
define( 'EMAIL_PLUGIN_URL', WP_PLUGIN_URL . '/' . EMAIL_PLUGIN_NAME );
function emailnews_plugin_path( $path = '' ) {
return path_join( FIFO_PLUGIN_DIR, trim( $path, '/' ) );
}
function emailnews_plugin_url( $path = '' ) {
return plugins_url( $path, EMAIL_PLUGIN_BASENAME );
}
define("WP_eemail_UNIQUE_NAME", "email-newsletter");
define("WP_eemail_TITLE", "Email Newsletter");
define('WP_eemail_LINK', 'Check official website for more information <a target="_blank" href="http://www.gopiplus.com/work/2010/09/25/email-newsletter/">click here</a>');
define('WP_eemail_FAV', 'http://www.gopiplus.com/work/2010/09/25/email-newsletter/');
if (!session_id()) { session_start(); }
function eemail_install()
{
global $wpdb, $wp_version;
$admin_email = get_option('admin_email');
add_option('eemail_title', "Email Newsletter");
add_option('eemail_bcc', "0");
add_option('eemail_widget_cap', "Sign up for our email newsletters");
add_option('eemail_widget_txt_cap', "Enter email");
add_option('eemail_widget_but_cap', "Submit");
add_option('eemail_on_homepage', "YES");
add_option('eemail_on_posts', "YES");
add_option('eemail_on_pages', "YES");
add_option('eemail_on_search', "NO");
add_option('eemail_on_archives', "NO");
add_option('my_plugin_do_activation_redirect', true);
add_option('eemail_from_name', "noreply");
add_option('eemail_from_email', "[email protected]");
add_option('eemail_admin_email_option', "YES");
add_option('eemail_admin_email_address', $admin_email);
add_option('eemail_admin_email_subject', "New email subscription");
add_option('eemail_admin_email_content', "Hi Admin, We have received a request to subscribe new email address (##USEREMAIL##) to receive emails from our website. Thank you.");
add_option('eemail_user_email_option', "YES");
add_option('eemail_user_email_subject', "Confirm subscription");
add_option('eemail_user_email_content', "Hi User, We have received a request to subscribe this email address to receive newsletter from our website. Thank you.");
add_option('eemail_email_type', "HTML");
if(strtoupper($wpdb->get_var("show tables like '". WP_eemail_TABLE . "'")) != strtoupper(WP_eemail_TABLE))
{
$wpdb->query("
CREATE TABLE IF NOT EXISTS `". WP_eemail_TABLE . "` (
`eemail_id` int(11) NOT NULL auto_increment,
`eemail_subject` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL ,
`eemail_content` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL ,
`eemail_status` char(3) NOT NULL default 'YES',
`eemail_date` datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (`eemail_id`) )
");
$sql = "insert into ".WP_eemail_TABLE.""
. " set `eemail_subject` = '" . 'Sample Subject'
. "', `eemail_content` = '" . 'This is sample mail content, Can add HTML content here.'
. "', `eemail_status` = '" . 'YES'
. "', `eemail_date` = CURDATE()";
$wpdb->get_results($sql);
$Sample = '<strong style="color: #990000"> Email newsletter</strong><p>Email newsletter plugin have option to send HTML Mails/Newsletters to registered user,';
$Sample .= ' Comment author, Subscriber and Users who contacted you. Sending email is much cheaper than most other forms of communication. Email marketing has proven very';
$Sample .= ' successful for those who do it right. This plugin is very useful those who need to send Newsletters to users who subscribed to your blogs.</p>';
$Sample .= ' <strong style="color: #990000">Advantage of this plugin</strong><ol>';
$Sample .= ' <li>No coding knowledge required to setup this plugin.</li>';
$Sample .= ' <li>Very easy installation and setup.</li><li>Option to send email newsletter to registered user.</li>';
$Sample .= ' <li>Option to send email newsletter to commenter (Comment author).</li>';
$Sample .= ' <li>Option to send email newsletter to users who contacted you.</li>';
$Sample .= ' <li>Option to setup email subscription box and option to send email newsletter to subscriber.</li>';
$Sample .= ' <li>Option to setup unsubscribe link in newsletter.</li><li>Option to Export and Import email address.</li>';
$Sample .= ' <li>Automatic welcome email to new subscriber.</li><li>Admin email notification for every new subscriber.</li>';
$Sample .= ' </ol><strong style="color: #990000">Thanks & Regards</strong><br>www.gopiplus.com';
$sql = "insert into ".WP_eemail_TABLE.""
. " set `eemail_subject` = '" . 'Sample HTML Mail'
. "', `eemail_content` = '" . $Sample
. "', `eemail_status` = '" . 'YES'
. "', `eemail_date` = CURDATE()";
$wpdb->get_results($sql);
}
if(strtoupper($wpdb->get_var("show tables like '". WP_eemail_TABLE_SUB . "'")) != strtoupper(WP_eemail_TABLE_SUB))
{
$wpdb->query("
CREATE TABLE `". WP_eemail_TABLE_SUB . "` (
`eemail_id_sub` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`eemail_name_sub` VARCHAR( 250 ) NOT NULL ,
`eemail_email_sub` VARCHAR( 250 ) NOT NULL ,
`eemail_status_sub` VARCHAR( 3 ) NOT NULL ,
`eemail_date_sub` DATE NOT NULL )
");
}
$unsubscribelink = get_option('siteurl') . "/unsubscribe.php?rand=##rand##&reff=##reff##&user=##user##";
add_option('eemail_un_option', "Yes");
add_option('eemail_un_text', "If you do not want to receive any more newsletters, Please <a href='##LINK##'>click here</a>");
add_option('eemail_un_link', $unsubscribelink);
$eemail_msgdis_1 = '<html><head><title>Email Newsletter</title></head><body style="background:#F2F2F2;font-family:Verdana, Arial, Helvetica, sans-serif;padding-top:65px;text-align:center;"><div style="background:#FFF;border:1px solid #ddd;border-radius:6px;max-width:580px;margin:0 auto;padding:34px 0 24px;width:580px"><div class="title"><h2>Thank You</h2><p>You have been successfully subscribed to our newsletter.</p></div></div></body></html>';
$eemail_msgdis_3 = '<html><head><title>Email Newsletter</title></head><body style="background:#F2F2F2;font-family:Verdana, Arial, Helvetica, sans-serif;padding-top:65px;text-align:center;"><div style="background:#FFF;border:1px solid #ddd;border-radius:6px;max-width:580px;margin:0 auto;padding:34px 0 24px;width:580px"><div class="title"><h2>Thank You</h2><p>You have been successfully unsubscribed. You will no longer hear from us.</p></div></div></body></html>';
$doubleoptinlink = get_option('siteurl') . "/wp-content/plugins/email-newsletter/double-optin/double-optin.php?rand=##rand##&guid=##guid##&user=##user##";
add_option('eemail_opt_option', "double-optin");
add_option('eemail_opt_subject', "Please confirm subscription (Email Newsletter)");
add_option('eemail_opt_content', "A newsletter subscription request for this email address was received. Please confirm it by <a href='##LINK##'>clicking here</a>. If you cannot click the link, please use the following link. <br /><br /> ##LINK## <br /><br /> Thanks.");
add_option('eemail_opt_link', $doubleoptinlink);
add_option('eemail_msgdis_1', $eemail_msgdis_1);
add_option('eemail_msgdis_2', "Oops.. This subscription cant be completed, sorry. The email address is blocked or already subscribed. Thank you.");
add_option('eemail_msgdis_3', $eemail_msgdis_3);
add_option('eemail_msgdis_4', "Oops.. We are getting some technical error. Please try again or contact admin.");
add_option('eemail_msgdis_5', "Oops.. Unexpected error occurred. Please try again.");
add_option('eemail_msgdis_6', "Oops.. Unexpected error occurred. Please try again.");
}
function eemail_admin_option()
{
global $wpdb;
include_once('pages/welcome-page.php');
}
function add_admin_menu_email_general()
{
global $wpdb;
include_once('pages/welcome-page.php');
}
function eemail_deactivation()
{
// No action required.
}
function eemail_get_emailid()
{
global $wpdb;
$arrData = array();
$i=0;
$sSql = "select eemail_id_sub, eemail_email_sub from " . WP_eemail_TABLE_SUB . " order by eemail_id_sub";
$myData = $wpdb->get_results($sSql, ARRAY_A);
if ( ! empty($myData) )
{
if( count($myData) > 0 )
{
foreach ($myData as $data)
{
$arrData[$i]["eemail_id_sub"] = $data["eemail_id_sub"];
$arrData[$i]["eemail_email_sub"] = $data["eemail_email_sub"];
$i=$i+1;
}
}
}
return $arrData;
}
function eemail_get_emails( $eemail_id )
{
global $wpdb;
$arrData = array();
$sSql = "select eemail_subject, eemail_content from " . WP_eemail_TABLE . " where";
$sSql = $sSql . " eemail_id = " . trim($eemail_id);
$sSql = $sSql . " order by eemail_id limit 0, 1";
$data = $wpdb->get_results($sSql);
if ( ! empty($data) )
{
$data = $data[0];
$arrData[0]["eemail_subject"] = stripslashes($data->eemail_subject);
$arrData[0]["eemail_content"] = stripslashes($data->eemail_content);
}
else
{
$arrData[0]["eemail_subject"] = "NA";
$arrData[0]["eemail_content"] = "NA";
}
return $arrData;
}
function eemail_send_mail($recipients = array(), $eemail_id = 0, $source = "")
{
global $wpdb;
global $user_login , $user_email;
$arrSubscriber = array();
$num_sent = 0;
$sender_name = "";
$sender_name = "";
$eemail_email_type = "";
$eemail_un_text = "";
$eemail_un_link = "";
$eemail_un_option = "NO";
$eemail_errors = array();
$eemail_error_found = FALSE;
$sender_name = get_option('eemail_from_name');
$sender_email = get_option('eemail_from_email');
$eemail_email_type = get_option('eemail_email_type');
$eemail_un_option = get_option('eemail_un_option');
if($eemail_email_type == "")
{
$eemail_email_type = "HTML";
}
// Check emails from address and from name.
if(trim($sender_name) == "" || trim($sender_email) == '')
{
get_currentuserinfo();
$sender_name = $user_login;
$sender_email = $user_email;
}
// Check recipients count.
if(empty($recipients))
{
return $num_sent;
}
// Check email content valid or not.
if($eemail_id == 0)
{
return false;
}
$headers = "From: \"$sender_name\" <$sender_email>\n";
$headers .= "Return-Path: <" . $sender_email . ">\n";
$headers .= "Reply-To: \"" . $sender_name . "\" <" . $sender_email . ">\n";
$headers .= "X-Mailer: PHP" . phpversion() . "\n";
// Load email subject and email newsletter details.
$arrEmails = eemail_get_emails($eemail_id);
if(count($arrEmails) > 0)
{
$form = array(
'eemail_subject' => $arrEmails[0]['eemail_subject'],
'eemail_content' => $arrEmails[0]['eemail_content']
);
$subject = $form['eemail_subject'];
$message = $form['eemail_content'];
}
if($subject == "")
{
return false;
}
// Check unsubscribe option
if( strtoupper($eemail_un_option) == "YES" )
{
$eemail_un_text = get_option('eemail_un_text');
$eemail_un_link = get_option('eemail_un_link');
}
if( strtoupper($eemail_email_type) == "HTML" )
{
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: " . get_bloginfo('html_type') . "; charset=\"". get_bloginfo('charset') . "\"\n";
$headers .= "Content-type: text/html\r\n";
$mailtext = "<html><head><title>" . $subject . "</title></head><body>" . $message . "</body></html>";
}
else
{
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/plain; charset=\"". get_bloginfo('charset') . "\"\n";
$message = preg_replace('|&[^a][^m][^p].{0,3};|', '', $message);
$message = preg_replace('|&|', '&', $message);
$mailtext = wordwrap(strip_tags($message), 80, "\n");
}
$mailtext = str_replace("\r\n", "<br />", $mailtext);
if(count($recipients) > 0)
{
$emailaddress = "";
$emaildbid = "";
for ( $i = 0; $i < count($recipients); $i++)
{
if($source == "subscriber")
{
$recipientsvalue = explode("<||>", $recipients[$i]);
$recipientsvaluecount = count($recipientsvalue);
if($recipientsvaluecount == 2)
{
$emailaddress = $recipientsvalue[0];
$emaildbid = $recipientsvalue[1];
}
else
{
$eemail_errors[] = __($emailaddress, 'email-newsletter');
$eemail_error_found = TRUE;
}
}
else
{
$emailaddress = $recipients[$i];
$emaildbid = "";
}
if ( !eemail_valid_email($emailaddress) )
{
$eemail_errors[] = __($emailaddress, 'email-newsletter');
$eemail_error_found = TRUE;
}
else
{
$unsubscribe = "";
if($source == "subscriber")
{
if( strtoupper($eemail_un_option) == "YES" )
{
$unsubscribemyguid = myguid();
if($emaildbid <> "0" && $emaildbid <> "")
{
$unsubscriberand = str_replace("##rand##", $emaildbid, $eemail_un_link);
$unsubscribeuser = str_replace("##user##", $emailaddress, $unsubscriberand);
$unsubscribelink = str_replace("##reff##", $unsubscribemyguid, $unsubscribeuser);
$unsubscribe = str_replace('##LINK##', $unsubscribelink, $eemail_un_text);
}
else
{
$unsubscribe = "";
}
}
else
{
$unsubscribe = "";
}
if ( strtoupper($eemail_email_type) == "HTML" )
{
$unsubscribe = '<br>' . $unsubscribe;
}
else
{
$unsubscribe = '\n' . $unsubscribe;
}
}
@wp_mail($emailaddress, $subject, $mailtext . $unsubscribe, $headers);
$num_sent = $num_sent + 1;
}
}
}
if($num_sent > 0)
{
?>
<?php _e('<div class="updated fade"><strong><p>Email has been sent successfully.</p></strong></div>', 'email-newsletter'); ?>
<?php
}
if ($eemail_error_found == TRUE && isset($eemail_errors[0]) == TRUE)
{
$eemail_value = "";
$value = "";
$j = 0;
foreach($eemail_errors as $value)
{
if ($j % 4 == 0 && $j <> 0)
{
$eemail_value = $eemail_value . "<br>";
}
$eemail_value = $eemail_value . $value . ", ";
$j = $j + 1;
}
?>
<div class="error fade"><p><strong><?php _e('Some invalid email address found.', 'email-newsletter'); ?></strong><br /><?php echo $eemail_value; ?></p></div>
<?php
}
return $num_sent;
}
function myguid()
{
$random_id_length = 60;
$rnd_id = crypt(uniqid(rand(),1));
$rnd_id = strip_tags(stripslashes($rnd_id));
$rnd_id = str_replace(".","",$rnd_id);
$rnd_id = strrev(str_replace("/","",$rnd_id));
$rnd_id = strrev(str_replace("$","",$rnd_id));
$rnd_id = strrev(str_replace("#","",$rnd_id));
$rnd_id = strrev(str_replace("@","",$rnd_id));
$rnd_id = substr($rnd_id,0,$random_id_length);
$rnd_id = strtolower($rnd_id);
return $rnd_id;
}
function eemail_valid_email($email)
{
$regex = '/^[A-z0-9][\w.+-]*@[A-z0-9][\w\-\.]+\.[A-z0-9]{2,6}$/';
return (preg_match($regex, $email));
}
function eemail_get_max_bcc_recipients()
{
return get_option( 'eemail_bcc' );
}
function eemail_get_email_content($eemail_id)
{
global $wpdb;
$emailrecord = array();
$data = $wpdb->get_results("select eemail_subject,eemail_content from ".WP_eemail_TABLE." where eemail_id=$eemail_id limit 1");
if ( !empty($data) )
{
$data = $data[0];
$emailrecord["eemail_subject"] = $data->eemail_subject;
$emailrecord["eemail_content"] = $data->eemail_content;
}
return $emailrecord;
}
function eemail_show()
{
global $wpdb, $wp_version;
include_once("widget/widget.php");
}
function eemail_widget($args)
{
if(is_home() && get_option('eemail_on_homepage') == 'YES') { $display = "show"; }
if(is_single() && get_option('eemail_on_posts') == 'YES') { $display = "show"; }
if(is_page() && get_option('eemail_on_pages') == 'YES') { $display = "show"; }
if(is_archive() && get_option('eemail_on_search') == 'YES') { $display = "show"; }
if(is_search() && get_option('eemail_on_archives') == 'YES') { $display = "show"; }
if($display == "show")
{
extract($args);
echo $before_widget;
echo $before_title;
echo get_option('eemail_title');
echo $after_title;
eemail_show();
echo $after_widget;
}
}
add_shortcode( 'email-newsletter-plugin', 'eemail_form_shortcode' );
function eemail_form_shortcode( $atts )
{
$ccf = "";
//[email-newsletter-plugin]
return eemail_show();
}
function eemail_control()
{
_e('Email Newsletter', 'email-newsletter');
}
function eemai_widget_init()
{
if(function_exists('wp_register_sidebar_widget'))
{
wp_register_sidebar_widget( __('Email Newsletter', 'email-newsletter'), __('Email Newsletter', 'email-newsletter'), 'eemail_widget');
}
if(function_exists('wp_register_widget_control'))
{
wp_register_widget_control( __('Email Newsletter', 'email-newsletter') , array( __('Email Newsletter', 'email-newsletter') , 'widgets'), 'eemail_control');
}
}
function add_app_register_page(){
global $wpdb;
include_once('pages/app-page.php');
}
function add_admin_menu_email_compose()
{
global $wpdb;
$current_page = isset($_GET['ac']) ? $_GET['ac'] : '';
switch($current_page)
{
case 'add':
include('compose/compose-email-add.php');
break;
case 'edit':
include('compose/compose-email-edit.php');
break;
default:
include('compose/compose-email-show.php');
break;
}
}
function add_admin_menu_email_to_registered_user()
{
global $wpdb;
include('sendemail/sendmail-registereduser.php');
}
function add_admin_menu_email_to_comment_posed_user()
{
global $wpdb;
include('sendemail/sendmail-commenter.php');
}
function add_admin_menu_email_to_subscriber()
{
global $wpdb;
include('sendemail/sendmail-subscriber.php');
}
function add_admin_menu_view_subscriber()
{
global $wpdb;
$current_page = isset($_GET['ac']) ? $_GET['ac'] : '';
switch($current_page)
{
case 'add':
include('subscriber/view-subscriber-add.php');
break;
case 'edit':
include('subscriber/view-subscriber-edit.php');
break;
default:
include('subscriber/view-subscriber-show.php');
break;
}
}
function add_admin_menu_widget_option()
{
global $wpdb;
include('pages/widget-setting.php');
}
function add_admin_menu_email_option()
{
global $wpdb;
include('pages/email-setting.php');
}
function add_admin_menu_email_to_simple_contact_form()
{
global $wpdb;
include_once("sendemail/sendmail-contactform.php");
}
function add_admin_menu_export_csv()
{
global $wpdb;
include('export/export-subscriber-show.php');
}
function add_admin_menu_import_emails()
{
global $wpdb;
include('subscriber/view-subscriber-add.php');
}
function add_unsubscribe_option()
{
global $wpdb;
include('pages/unsubscribe-setting.php');
}
function add_admin_menu_email_testemail()
{
global $wpdb;
include('sendemail/sendmail-testing.php');
}
function add_admin_menu_opt_in()
{
global $wpdb;
include('pages/optin-setting.php');
}
function ViewSubscriberResendEmail($did)
{
global $wpdb;
$sSql = $wpdb->prepare("SELECT * FROM ".WP_eemail_TABLE_SUB." WHERE eemail_id_sub = %d LIMIT 1", array($did));
$data = array();
$data = $wpdb->get_row($sSql, ARRAY_A);
if(count($data) > 0)
{
$arrFromEmail = array();
$arrCheck = GetFromEmail();
$eemail_from_name = $arrCheck[0]['eemail_from_name'];
$eemail_from_email = $arrCheck[0]['eemail_from_email'];
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=utf-8" . "\r\n";
$headers .= "From: \"$eemail_from_name\" <$eemail_from_email>\n";
$to_dbid = $data['eemail_id_sub'];
$to_email = $data['eemail_email_sub'];
$to_guid = myguid();
$to_subject = get_option('eemail_opt_subject');
$to_message = get_option('eemail_opt_content');
$eemail_opt_link = get_option('eemail_opt_link');
$eemail_opt_link = str_replace("##rand##", $to_dbid, $eemail_opt_link);
$eemail_opt_link = str_replace("##user##", $to_email, $eemail_opt_link);
$eemail_opt_link = str_replace("##guid##", $to_guid, $eemail_opt_link);
$to_message = str_replace('##LINK##', $eemail_opt_link, $to_message);
$to_message = str_replace("\r\n", "<br />", $to_message);
@wp_mail($to_email, $to_subject, $to_message, $headers);
$sSql = $wpdb->prepare("UPDATE ".WP_eemail_TABLE_SUB." SET eemail_status_sub = 'PEN' WHERE eemail_id_sub = %d LIMIT 1", array($to_dbid));
$wpdb->query($sSql);
}
}
function GetFromEmail()
{
global $wpdb;
$arrData = array();
$eemail_from_name = get_option('eemail_from_name');
$eemail_from_email = get_option('eemail_from_email');
if($eemail_from_name == "" || $eemail_from_email == "")
{
get_currentuserinfo();
$eemail_from_name = $user_login;
$eemail_from_email = $user_email;
}
$arrData[0]["eemail_from_name"] = $eemail_from_name;
$arrData[0]["eemail_from_email"] = $eemail_from_email;
return $arrData;
}
function add_admin_menu_option()
{
add_menu_page( __( 'Email Newsletter', 'email-newsletter' ), __( 'Email Newsletter', 'email-newsletter' ), 'admin_dashboard', 'email-newsletter', 'eemail_admin_option' );
add_submenu_page('email-newsletter', 'General Information', __( 'General Information', 'email-newsletter' ), 'administrator', 'general-information', 'add_admin_menu_email_general');
add_submenu_page('email-newsletter', 'Compose Mail', __( 'Compose Mail', 'email-newsletter' ), 'administrator', 'compose-email', 'add_admin_menu_email_compose');
add_submenu_page('email-newsletter', 'Send Mail to a Registered User', __( 'Mail to Registered User', 'email-newsletter' ), 'administrator', 'sendmail-registereduser', 'add_admin_menu_email_to_registered_user');
add_submenu_page('email-newsletter', 'Send Mail to Commenters', __( 'Mail to Commenter', 'email-newsletter' ), 'administrator', 'sendmail-commenter', 'add_admin_menu_email_to_comment_posed_user');
add_submenu_page('email-newsletter', 'Send Mail to Subscribed Users', __( 'Mail to Subscriber', 'email-newsletter' ), 'administrator', 'sendmail-subscriber', 'add_admin_menu_email_to_subscriber');
add_submenu_page('email-newsletter', 'Send Mail to Users who Contacted You', __( 'Mail to Contact Form User', 'email-newsletter' ), 'administrator', 'sendmail-contactform', 'add_admin_menu_email_to_simple_contact_form');
add_submenu_page('email-newsletter', 'View subscribed user', __( 'View Subscriber', 'email-newsletter' ), 'administrator', 'view-subscriber', 'add_admin_menu_view_subscriber');
add_submenu_page('email-newsletter', 'Widget setting', __( 'Setup Widget', 'email-newsletter' ), 'administrator', 'widget-setting', 'add_admin_menu_widget_option');
add_submenu_page('email-newsletter', 'Email setting', __( 'Setup Email', 'email-newsletter' ), 'administrator', 'email-setting', 'add_admin_menu_email_option');
add_submenu_page('email-newsletter', 'Unsubscribe link option', __( 'Setup Unsubscribe', 'email-newsletter' ), 'administrator', 'unsubscribe-setting', 'add_unsubscribe_option');
add_submenu_page('email-newsletter', 'Opt In Setting', __( 'Opt In Setting', 'email-newsletter' ), 'administrator', 'opt-in', 'add_admin_menu_opt_in');
add_submenu_page('email-newsletter', 'Export CSV', __( 'Export Users to CSV', 'email-newsletter' ), 'administrator', 'export-subscriber', 'add_admin_menu_export_csv');
add_submenu_page('email-newsletter', 'Import emails', __( 'Import Mails', 'email-newsletter' ), 'administrator', 'import-subscriber', 'add_admin_menu_import_emails');
add_submenu_page('email-newsletter', 'Send Test Mail', __( 'Send Test Mail', 'email-newsletter' ), 'administrator', 'test-email', 'add_admin_menu_email_testemail');
}
function eemail_textdomain()
{
load_plugin_textdomain( 'email-newsletter' , false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
add_action('plugins_loaded', 'eemail_textdomain');
add_action('admin_menu', 'add_admin_menu_option');
register_activation_hook(__FILE__, 'eemail_install');
register_deactivation_hook(__FILE__, 'eemail_deactivation');
//add_action('admin_init', 'on_plugin_activated_redirect');
add_action("plugins_loaded", "eemai_widget_init");
add_action('init', 'eemai_widget_init');
function export_setting() {
if (isset($_SESSION['exportcsv']) && $_SESSION['exportcsv'] == "YES")
{
if($_SERVER['REQUEST_METHOD'] == "POST")
{
if (strpos($_SERVER['HTTP_REFERER'], get_option('siteurl')) !== false)
{
global $wpdb;
$option = isset($_REQUEST['option']) ? $_REQUEST['option'] : '';
switch ($option)
{
case "view_subscriber":
$data = $wpdb->get_results("select eemail_email_sub as 'Subscriber Email', eemail_date_sub as 'Date' from ".WP_eemail_TABLE_SUB." where 1=1 ORDER BY eemail_date_sub");
download($data, 's', '');
break;
case "registered_user":
$data = $wpdb->get_results("select user_nicename as 'Name', user_email as 'Email' from ". $wpdb->prefix . "users ORDER BY user_nicename");
download($data, 'r', '');
break;
case "commentposed_user":
$data = $wpdb->get_results("SELECT DISTINCT(comment_author_email) as Email, comment_author as 'Comment Author' FROM ". $wpdb->prefix . "comments WHERE comment_author_email <> '' ORDER BY comment_author_email");
download($data, 'c', '');
break;
case "contact_user":
$data = $wpdb->get_results("select distinct gCF_email as Email, gCF_name as Name from ".WP_eemail_TABLE_SCF." ORDER BY gCF_email");
download($data, 'cc', '');
break;
default:
//_e('Unexpected url submit has been detected 4', 'email-newsletter');
break;
}
}
else
{
_e('Unexpected url submit has been detected 1', 'email-newsletter');
}
}
}
}
function download($arrays, $filename = 'output.csv', $option)
{
$string = '';
$c=0;
$filename = 'EmailNewsletter_'.$option.'_'.date('Ymd_His').".csv";
foreach($arrays AS $array)
{
$val_array = array();
$key_array = array();
foreach($array AS $key => $val)
{
$key_array[] = $key;
$val = str_replace('"', '""', $val);
$val_array[] = "\"$val\"";
}
if($c == 0)
{
$string .= implode(",", $key_array)."\n";
}
$string .= implode(",", $val_array)."\n";
$c++;
}
ob_clean();
header('Content-type: application/ms-excel');
header('Content-Disposition: attachment; filename='.$filename);
echo $string;
exit(0);
}
add_action( 'admin_init', 'export_setting' );
function eemail_subscribe() {
$Email = "";
$Email = isset($_POST['txt_email_newsletter']) ? $_POST['txt_email_newsletter'] : '';
$Email = trim(sanitize_email($Email));
if($Email <> "")
{
$regex = '/^[A-z0-9][\w.+-]*@[A-z0-9][\w\-\.]+\.[A-z0-9]{2,6}$/';
$eemail_valid_email = preg_match($regex, $Email);
if($eemail_valid_email)
{
global $wpdb, $wp_version;
global $user_login , $user_email;
$result = '0';
$sSql = $wpdb->prepare(
"SELECT COUNT(*) AS `count` FROM ".WP_eemail_TABLE_SUB."
WHERE `eemail_email_sub` = %s", $Email);
$result = $wpdb->get_var($sSql);
if ($result == '0')
{
$eemail_opt_option = get_option('eemail_opt_option');
if($eemail_opt_option == "double-optin")
{
$doubleoptin = "PEN";
}
else
{
$doubleoptin = "SIG";
}
$CurrentDate = date('Y-m-d G:i:s');
$sql = $wpdb->prepare(
"INSERT INTO `". WP_eemail_TABLE_SUB ."`
(`eemail_name_sub`,`eemail_email_sub`, `eemail_status_sub`, `eemail_date_sub`)
VALUES(%s, %s, %s, %s)",
array('NA', $Email, $doubleoptin, $CurrentDate)
);
$wpdb->query($sql);
$eemail_admin_email_option = strtoupper(get_option('eemail_admin_email_option'));
$eemail_user_email_option = strtoupper(get_option('eemail_user_email_option'));
$eemail_admin_email_address = get_option('eemail_admin_email_address');
$eemail_from_name = get_option('eemail_from_name');
$eemail_from_email = get_option('eemail_from_email');
if($eemail_admin_email_address == "")
{
get_currentuserinfo();
$eemail_admin_email_address = $user_email;
}
if($eemail_from_name == "" || $eemail_from_email == "")
{
get_currentuserinfo();
$eemail_from_name = $user_login;
$eemail_from_email = $user_email;
}
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=utf-8" . "\r\n";
$headers .= "From: \"$eemail_from_name\" <$eemail_from_email>\n";
if(trim($eemail_admin_email_option) == "YES")
{
$to_email = $eemail_admin_email_address;
$to_subject = get_option('eemail_admin_email_subject');
$to_message = get_option('eemail_admin_email_content');
$to_message = str_replace("\r\n", "<br />", $to_message);
$to_message = str_replace("##USEREMAIL##", $Email, $to_message);
@wp_mail($to_email, $to_subject, $to_message, $headers);
}
if($doubleoptin == "PEN")
{
$to_email = $Email;
$eemail_opt_guid = eemail_opt_guid();
$to_subject = get_option('eemail_opt_subject');
$to_message = get_option('eemail_opt_content');
$eemail_opt_link = get_option('eemail_opt_link');
$sSql = $wpdb->prepare("SELECT * FROM ".WP_eemail_TABLE_SUB." WHERE eemail_email_sub = '%s' LIMIT 1 ", array($to_email));
$data = array();
$data = $wpdb->get_row($sSql, ARRAY_A);
$emaildbid = 0;
if(count($data) > 0)
{
$emaildbid = $data['eemail_id_sub'];
}
$eemail_opt_rand = str_replace("##rand##", $emaildbid, $eemail_opt_link);
$eemail_opt_user = str_replace("##user##", $to_email, $eemail_opt_rand);
$eemail_opt_link = str_replace("##guid##", $eemail_opt_guid, $eemail_opt_user);
$to_message = str_replace('##LINK##', $eemail_opt_link, $to_message);
$to_message = str_replace("\r\n", "<br />", $to_message);
@wp_mail($to_email, $to_subject, $to_message, $headers);
echo "subscribed-pending-doubleoptin";
}
else
{
if(trim($eemail_user_email_option) == "YES")
{
$to_email = $Email;
$to_subject = get_option('eemail_user_email_subject');
$to_message = get_option('eemail_user_email_content');
$to_message = str_replace("\r\n", "<br />", $to_message);
@wp_mail($to_email, $to_subject, $to_message, $headers);
}
echo "subscribed-successfully";
}
}
else
{
echo "already-exist";
}
}
else
{
echo "invalid-email";
}
}
}
function eemail_opt_guid()
{
$random_id_length = 60;
$rnd_id = crypt(uniqid(rand(),1));
$rnd_id = strip_tags(stripslashes($rnd_id));
$rnd_id = str_replace(".","",$rnd_id);
$rnd_id = strrev(str_replace("/","",$rnd_id));
$rnd_id = strrev(str_replace("$","",$rnd_id));
$rnd_id = strrev(str_replace("#","",$rnd_id));
$rnd_id = strrev(str_replace("@","",$rnd_id));
$rnd_id = substr($rnd_id,0,$random_id_length);
$rnd_id = strtolower($rnd_id);
return $rnd_id;
}
add_action( 'wp_ajax_nopriv_eemail-subscribe', 'eemail_subscribe' );
add_action( 'wp_ajax_eemail-subscribe', 'eemail_subscribe' );
add_action( 'init', 'eemail_subscribe' );
add_action( 'admin_init', 'eemail_subscribe' );
function eemail_unsubscribe() {
$url = str_replace( trailingslashit( site_url() ), '', plugins_url( 'unsubscribe/unsubscribe.php', __FILE__ ) );
add_rewrite_rule( 'unsubscribe/$', $url, 'top' );
}
add_action( 'init', 'eemail_unsubscribe' );
add_action( 'init', 'eemail_init_internal' );
function eemail_init_internal()
{
$url = str_replace( trailingslashit( site_url() ), '', plugins_url( 'unsubscribe/unsubscribe.php', __FILE__ ) );
add_rewrite_rule( 'unsubscribe.php$', 'index.php?eemail_api=1', 'top' );
}
add_filter( 'query_vars', 'eemail_query_vars' );
function eemail_query_vars( $query_vars )
{
$query_vars[] = 'eemail_api';
return $query_vars;
}
add_action( 'parse_request', 'eemail_parse_request' );
function eemail_parse_request( &$wp )
{
if ( array_key_exists( 'eemail_api', $wp->query_vars ) ) {
$path = plugin_dir_path( __FILE__ ).'/unsubscribe/unsubscribe.php';
include $path;
exit();
}
return;
}
?>