-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathwp-email.php
1471 lines (1327 loc) · 60.5 KB
/
wp-email.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: WP-EMail
Plugin URI: https://lesterchan.net/portfolio/programming/php/
Description: Allows people to recommand/send your WordPress blog's post/page to a friend.
Version: 2.69.2
Author: Lester 'GaMerZ' Chan
Author URI: https://lesterchan.net
Text Domain: wp-email
*/
/*
Copyright 2024 Lester Chan (email : lesterchan@gmail.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
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
*/
define( 'WP_EMAIL_VERSION', '2.69.3' );
### Define: Show Email Remarks In Logs?
define('EMAIL_SHOW_REMARKS', true);
### E-Mail Table Name
global $wpdb;
$wpdb->email = $wpdb->prefix.'email';
### Function: E-Mail Administration Menu
add_action('admin_menu', 'email_menu');
function email_menu() {
add_menu_page(__('E-Mail', 'wp-email'), __('E-Mail', 'wp-email'), 'manage_email', 'wp-email/email-manager.php', '', 'dashicons-email-alt');
add_submenu_page('wp-email/email-manager.php', __('Manage E-Mail', 'wp-email'), __('Manage E-Mail', 'wp-email'), 'manage_email', 'wp-email/email-manager.php');
add_submenu_page('wp-email/email-manager.php', __('E-Mail Options', 'wp-email'), __('E-Mail Options', 'wp-email'), 'manage_email', 'wp-email/email-options.php');
}
### Function: Add htaccess Rewrite Endpoint - this handles all the rules
add_action( 'init', 'wp_email_endpoint' );
function wp_email_endpoint() {
add_rewrite_endpoint( 'email', EP_PERMALINK | EP_PAGES, 'wp_email' );
add_rewrite_endpoint( 'emailpopup', EP_PERMALINK | EP_PAGES, 'wp_email_popup' );
}
### Function: E-Mail Public Variables
add_filter('query_vars', 'email_variables');
function email_variables($public_query_vars) {
$public_query_vars[] = 'wp_email';
$public_query_vars[] = 'wp_email_popup';
return $public_query_vars;
}
### Function: Print Out jQuery Script At The Top
add_action('wp_head', 'email_javascripts_header');
function email_javascripts_header() {
wp_print_scripts('jquery');
}
### Function: Enqueue E-Mail Javascripts/CSS
add_action('wp_enqueue_scripts', 'email_scripts');
function email_scripts() {
if(@file_exists(get_stylesheet_directory().'/email-css.css')) {
wp_enqueue_style('wp-email', get_stylesheet_directory_uri().'/email-css.css', false, WP_EMAIL_VERSION, 'all');
} else {
wp_enqueue_style('wp-email', plugins_url('wp-email/email-css.css'), false, WP_EMAIL_VERSION, 'all');
}
if( is_rtl() ) {
if(@file_exists(get_stylesheet_directory().'/email-css-rtl.css')) {
wp_enqueue_style('wp-email-rtl', get_stylesheet_directory_uri().'/email-css-rtl.css', false, WP_EMAIL_VERSION, 'all');
} else {
wp_enqueue_style('wp-email-rtl', plugins_url('wp-email/email-css-rtl.css'), false, WP_EMAIL_VERSION, 'all');
}
}
$email_max = (int) get_option('email_multiple');
wp_enqueue_script('wp-email', plugins_url('wp-email/email-js.js'), array('jquery'), WP_EMAIL_VERSION, true);
wp_localize_script('wp-email', 'emailL10n', array(
'ajax_url' => admin_url('admin-ajax.php'),
'max_allowed' => $email_max,
'text_error' => __('The Following Error Occurs:', 'wp-email'),
'text_name_invalid' => __('- Your Name is empty/invalid', 'wp-email'),
'text_email_invalid' => __('- Your Email is empty/invalid', 'wp-email'),
'text_remarks_invalid' => __('- Your Remarks is invalid', 'wp-email'),
'text_friend_names_empty' => __('- Friend Name(s) is empty', 'wp-email'),
'text_friend_name_invalid' => __('- Friend Name is empty/invalid: ', 'wp-email'),
'text_max_friend_names_allowed' => sprintf(_n('- Maximum %s Friend Name allowed', '- Maximum %s Friend Names allowed', $email_max, 'wp-email'), number_format_i18n($email_max)),
'text_friend_emails_empty' => __('- Friend Email(s) is empty', 'wp-email'),
'text_friend_email_invalid' => __('- Friend Email is invalid: ', 'wp-email'),
'text_max_friend_emails_allowed' => sprintf(_n('- Maximum %s Friend Email allowed', '- Maximum %s Friend Emails allowed', $email_max, 'wp-email'), number_format_i18n($email_max)),
'text_friends_tally' => __('- Friend Name(s) count does not tally with Friend Email(s) count', 'wp-email'),
'text_image_verify_empty' => __('- Image Verification is empty', 'wp-email')
));
}
### Function: Display E-Mail Link
function email_link($email_post_text = '', $email_page_text = '', $echo = true) {
$output = '';
$using_permalink = get_option('permalink_structure');
$email_options = get_option('email_options');
$email_style = (int) $email_options['email_style'];
$email_type = (int) $email_options['email_type'];
if(empty($email_post_text)) {
$email_text = stripslashes($email_options['post_text']);
} else {
$email_text = $email_post_text;
}
$email_icon = plugins_url('wp-email/images/'.$email_options['email_icon']);
$email_link = get_permalink();
$email_html = stripslashes($email_options['email_html']);
$onclick = '';
// Fix For Static Page
if(get_option('show_on_front') === 'page' && is_page()) {
if((int) get_option('page_on_front') > 0) {
$email_link = _get_page_link();
}
}
switch($email_type) {
// E-Mail Standalone Page
case 1:
if(!empty($using_permalink)) {
if(substr($email_link, -1, 1) !== '/') {
$email_link= $email_link.'/';
}
if(is_page()) {
if(empty($email_page_text)) {
$email_text = stripslashes($email_options['page_text']);
} else {
$email_text = $email_page_text;
}
}
$email_link .= 'email/';
} else {
if(is_page()) {
if(empty($email_page_text)) {
$email_text = stripslashes($email_options['page_text']);
} else {
$email_text = $email_page_text;
}
}
$email_link .= '&wp_email=1';
}
break;
// E-Mail Popup
case 2:
if(!empty($using_permalink)) {
if(substr($email_link, -1, 1) !== '/') {
$email_link= $email_link.'/';
}
if(is_page()) {
if(empty($email_page_text)) {
$email_text = stripslashes($email_options['page_text']);
} else {
$email_text = $email_page_text;
}
}
$email_link .= 'emailpopup/';
} else {
if(is_page()) {
if(empty($email_page_text)) {
$email_text = stripslashes($email_options['page_text']);
} else {
$email_text = $email_page_text;
}
}
$email_link .= '&wp_email_popup=1';
}
$onclick = ' onclick="email_popup(this.href); return false;" ';
break;
}
unset($email_options);
switch($email_style) {
// Icon + Text Link
case 1:
$output = '<a href="'.$email_link.'"'.$onclick.' title="'.$email_text.'" rel="nofollow"><img class="WP-EmailIcon" src="' . esc_attr( $email_icon ) .'" alt="' . esc_attr( $email_text ) . '" title="' . esc_attr( $email_text ) . '" style="border: 0px;" /></a> <a href="' . esc_attr( $email_link ) .'"' . $onclick . ' title="' . esc_attr( $email_text ) . '" rel="nofollow">' . $email_text . '</a>';
break;
// Icon Only
case 2:
$output = '<a href="'.$email_link.'"'.$onclick.' title="'.$email_text.'" rel="nofollow"><img class="WP-EmailIcon" src="' . esc_attr( $email_icon ) .'" alt="' . esc_attr( $email_text ) . '" title="' . esc_attr( $email_text ) .'" style="border: 0px;" /></a>';
break;
// Text Link Only
case 3:
$output = '<a href="'.$email_link.'"'.$onclick.' title="'.$email_text.'" rel="nofollow">'.$email_text.'</a>';
break;
case 4:
$email_html = str_replace("%EMAIL_URL%", $email_link, $email_html);
$email_html = str_replace("%EMAIL_POPUP%", $onclick, $email_html);
$email_html = str_replace("%EMAIL_TEXT%", $email_text, $email_html);
$email_html = str_replace("%EMAIL_ICON_URL%", $email_icon, $email_html);
$output = $email_html;
break;
}
if($echo) {
echo $output."\n";
} else {
return $output;
}
}
### Function: Short Code For Inserting Email Links Into Posts/Pages
add_shortcode('email_link', 'email_link_shortcode');
function email_link_shortcode($atts) {
if(!is_feed()) {
return email_link('', '', false);
}
return __('Note: There is an email link embedded within this post, please visit this post to email it.', 'wp-email');
}
function email_link_shortcode2($atts) {
return '';
}
### Function: Short Code For DO NOT EMAIL Content
add_shortcode('donotemail', 'email_donotemail_shortcode');
function email_donotemail_shortcode($atts, $content = null) {
return do_shortcode($content);
}
function email_donotemail_shortcode2($atts, $content = null) {
return '';
}
### Function: Snippet Words
if(!function_exists( 'snippet_words' ) ) {
function snippet_words( $text, $length = 0 ) {
$words = explode(' ', $text);
return implode(' ', array_slice( $words, 0, $length ) ) . ' ...';
}
}
### Function: Snippet Text
if(!function_exists('snippet_text')) {
function snippet_text($text, $length = 0) {
$text = @html_entity_decode($text, ENT_QUOTES, get_option('blog_charset'));
if (mb_strlen($text) > $length) {
return htmlentities(mb_substr($text,0,$length), ENT_COMPAT, get_option('blog_charset')).'...';
}
return htmlentities($text, ENT_COMPAT, get_option('blog_charset'));
}
}
### Function: Add E-Mail Filters
function email_addfilters( $wp_query ) {
if ( $wp_query->is_main_query() ) {
add_filter( 'the_title', 'email_title' );
add_filter( 'the_content', 'email_form', 10, 5 );
}
}
### Function: Remove E-Mail Filters
function email_removefilters() {
remove_action( 'loop_start', 'email_addfilters' );
remove_filter( 'the_title', 'email_title' );
remove_filter( 'the_content', 'email_form', 10, 5 );
}
### Function: E-Mail Page Title
function email_pagetitle($page_title) {
$page_title .= ' » '.__('E-Mail', 'wp-email');
return $page_title;
}
### Function: Add noindex & nofollow to meta
function email_meta_nofollow() {
echo '<meta name="robots" content="noindex, nofollow" />'."\n";
}
### Function: E-Mail Post ID
if(!function_exists('get_the_id')) {
function get_the_id() {
global $id;
return $id;
}
}
### Function: Get E-Mail Remark
function email_get_remark() {
global $post;
return get_post_meta($post->ID, 'wp-email-remark', true);
}
### Function: Get E-Mail Title
function email_get_title() {
global $post;
$post_title = get_post_meta($post->ID, 'wp-email-title', true);
if( empty($post_title) ) {
$post_title = $post->post_title;
}
if(!empty($post->post_password)) {
$post_title = sprintf(__('Protected: %s', 'wp-email'), $post_title);
} elseif($post->post_status === 'private') {
$post_title = sprintf(__('Private: %s', 'wp-email'), $post_title);
}
return $post_title;
}
### Function: E-Mail Title
function email_title($page_title) {
if(in_the_loop()) {
$post_title = email_get_title();
$post_author = get_the_author();
$post_date = get_the_time(get_option('date_format').' ('.get_option('time_format').')', '', '', false);
$post_category = email_category(__(',', 'wp-email').' ');
$post_category_alt = strip_tags($post_category);
$template_title = stripslashes(get_option('email_template_title'));
$template_title = str_replace("%EMAIL_POST_TITLE%", $post_title, $template_title);
$template_title = str_replace("%EMAIL_POST_AUTHOR%", $post_author, $template_title);
$template_title = str_replace("%EMAIL_POST_DATE%", $post_date, $template_title);
$template_title = str_replace("%EMAIL_POST_CATEGORY%", $post_category, $template_title);
$template_title = str_replace("%EMAIL_BLOG_NAME%", get_bloginfo('name'), $template_title);
$template_title = str_replace("%EMAIL_BLOG_URL%", get_bloginfo('url'), $template_title);
$template_title = str_replace("%EMAIL_PERMALINK%", get_permalink(), $template_title);
return $template_title;
} else {
return $page_title;
}
}
### Function: E-Mail Category
function email_category($separator = ', ', $parents='') {
return get_the_category_list($separator, $parents);
}
### Function: E-Mail Content
function email_content() {
$content = get_email_content();
$email_snippet = (int) get_option('email_snippet');
if($email_snippet > 0) {
return snippet_words($content , $email_snippet);
} else {
return $content;
}
}
### Function: E-Mail Alternate Content
function email_content_alt() {
remove_filter('the_content', 'wptexturize');
$content = get_email_content();
$content = strip_tags($content);
$email_snippet = (int) get_option('email_snippet');
if($email_snippet > 0) {
return snippet_words($content , $email_snippet);
} else {
return $content;
}
}
### Function: E-Mail Get The Content
function get_email_content() {
global $pages, $multipage, $numpages;
$content = '';
if(post_password_required()) {
return __('Password Protected Post', 'wp-email');
}
if($multipage) {
for($page = 0; $page < $numpages; $page++) {
$content .= $pages[$page];
}
} else {
$content = $pages[0];
}
$content = html_entity_decode($content);
$content = htmlspecialchars_decode($content);
if(function_exists('print_rewrite')) {
remove_shortcode('donotprint');
add_shortcode('donotprint', 'print_donotprint_shortcode2');
}
remove_shortcode('donotemail');
add_shortcode('donotemail', 'email_donotemail_shortcode2');
remove_shortcode('email_link');
add_shortcode('email_link', 'email_link_shortcode2');
$content = apply_filters('the_content', $content);
return $content;
}
### Function: Get IP Address
if ( ! function_exists( 'get_ipaddress' ) ) {
function get_ipaddress() {
foreach ( array( 'HTTP_CF_CONNECTING_IP', 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR' ) as $key ) {
if ( array_key_exists( $key, $_SERVER ) === true ) {
foreach ( explode( ',', $_SERVER[$key] ) as $ip ) {
$ip = trim( $ip );
if ( filter_var( $ip, FILTER_VALIDATE_IP ) !== false ) {
return esc_attr( $ip );
}
}
}
}
}
}
function email_get_ipaddress() {
$ip = get_ipaddress();
$email_options = get_option( 'email_options' );
if ( ! empty( $email_options ) && ! empty( $email_options['ip_header'] ) && ! empty( $_SERVER[ $email_options['ip_header'] ] ) ) {
$ip = esc_attr( $_SERVER[ $email_options['ip_header'] ] );
}
return apply_filters( 'wp_email_ipaddress', $ip );
}
### Function: There Are Still Many PHP 4.x Users
if(!function_exists('htmlspecialchars_decode')) {
function htmlspecialchars_decode($string, $style = ENT_COMPAT) {
$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS,$style));
if($style === ENT_QUOTES) {
$translation['''] = '\'';
}
return strtr($string, $translation);
}
}
### Function: Check Vaild Name (AlphaNumeric With Spaces Allowed Only)
if(!function_exists('is_valid_name')) {
function is_valid_name($name) {
$regex = '/[(\*\(\)\[\]\+\,\/\?\:\;\'\"\`\~\\#\$\%\^\&\<\>)+]/';
return !(preg_match($regex, $name));
}
}
### Function: Check Valid E-Mail Address
if(!function_exists('is_valid_email')) {
function is_valid_email($email) {
$regex = '/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/';
return (preg_match($regex, $email));
}
}
### Function: Check Valid Remarks (Ensure No E-Mail Injections)
if(!function_exists('is_valid_remarks')) {
function is_valid_remarks($content) {
$injection_strings = array('apparently-to', 'content-disposition', 'content-type', 'content-transfer-encoding', 'errors-to', 'in-reply-to', 'message-id', 'mime-version', 'multipart/mixed', 'multipart/alternative', 'multipart/related', 'reply-to', 'x-mailer', 'x-sender', 'x-uidl');
foreach ($injection_strings as $spam) {
$check = strpos(strtolower($content), $spam);
if ($check !== false) {
return false;
}
}
return true;
}
}
### Function: Check For E-Mail Spamming
function not_spamming() {
global $wpdb;
$last_emailed = $wpdb->get_var(
$wpdb->prepare( "SELECT email_timestamp FROM $wpdb->email WHERE email_ip = %s AND email_status = %s ORDER BY email_timestamp DESC LIMIT 1", email_get_ipaddress(), __( 'Success', 'wp-email' ) )
);
$email_allow_interval = (int) get_option( 'email_interval' ) * 60;
if( ( current_time( 'timestamp' ) - $last_emailed) < $email_allow_interval ) {
return false;
}
return true;
}
### Function: E-Mail Flood Interval
function email_flood_interval($echo = true) {
$email_allow_interval_min = (int) get_option('email_interval');
if($echo) {
echo $email_allow_interval_min;
} else {
return $email_allow_interval_min;
}
}
### Function: Fill In Email Fills If Logged In (By Aaron Campbell)
add_filter('email_form-fieldvalues', 'email_fill_fields');
function email_fill_fields($email_fields) {
global $current_user;
if ($current_user->ID > 0) {
$email_fields['yourname'] = esc_attr( $current_user->display_name );
$email_fields['youremail'] = esc_attr( $current_user->user_email );
}
return $email_fields;
}
### Function: E-Mail Form Header
function email_form_header( $temp_id, $echo = true ) {
global $id;
if((int) $temp_id > 0) {
$id = $temp_id;
}
$using_permalink = get_option('permalink_structure');
$permalink = get_permalink();
// Fix For Static Page
if(get_option('show_on_front') === 'page' && is_page()) {
if((int) get_option('page_on_front') > 0) {
$permalink = _get_page_link();
}
}
$output = '';
if(!empty($using_permalink)) {
if(is_page()) {
$output .= '<form action="'.$permalink.'emailpage/" method="post">'."\n";
$output .= '<p style="display: none;"><input type="hidden" id="page_id" name="page_id" value="'.$id.'" /></p>'."\n";
} else {
$output = '<form action="'.$permalink.'email/" method="post">'."\n";
$output .= '<p style="display: none;"><input type="hidden" id="p" name="p" value="'.$id.'" /></p>'."\n";
}
} else {
if(is_page()) {
$output .= '<form action="'.$permalink.'&wp_email=1" method="post">'."\n";
$output .= '<p style="display: none;"><input type="hidden" id="page_id" name="page_id" value="'.$id.'" /></p>'."\n";
} else {
$output .= '<form action="'.$permalink.'&wp_email=1" method="post">'."\n";
$output .= '<p style="display: none;"><input type="hidden" id="p" name="p" value="'.$id.'" /></p>'."\n";
}
}
$output .= '<p style="display: none;"><input type="hidden" id="wp-email_nonce" name="wp-email_nonce" value="'.wp_create_nonce('wp-email-nonce').'" /></p>'."\n";
if($echo) {
echo $output;
} else {
return $output;
}
}
### Function: E-Mail Form Header For Popup
function email_popup_form_header($echo = true, $temp_id = 0) {
global $post;
$id = (int) $post->ID;
if((int) $temp_id > 0) {
$id = $temp_id;
}
$using_permalink = get_option('permalink_structure');
$permalink = get_permalink();
// Fix For Static Page
if(get_option('show_on_front') === 'page' && is_page()) {
if((int) get_option('page_on_front') > 0) {
$permalink = _get_page_link();
}
}
$output = '';
if(!empty($using_permalink)) {
if(is_page()) {
$output .= '<form action="'.$permalink.'emailpopuppage/" method="post">'."\n";
$output .= '<p style="display: none;"><input type="hidden" id="page_id" name="page_id" value="'.$id.'" /></p>'."\n";
} else {
$output = '<form action="'.$permalink.'emailpopup/" method="post">'."\n";
$output .= '<p style="display: none;"><input type="hidden" id="p" name="p" value="'.$id.'" /></p>'."\n";
}
} else {
if(is_page()) {
$output .= '<form action="'.$permalink.'&emailpopup=1" method="post">'."\n";
$output .= '<p style="display: none;"><input type="hidden" id="page_id" name="page_id" value="'.$id.'" /></p>'."\n";
} else {
$output .= '<form action="'.$permalink.'&emailpopup=1" method="post">'."\n";
$output .= '<p style="display: none;"><input type="hidden" id="p" name="p" value="'.$id.'" /></p>'."\n";
}
}
$output .= '<p style="display: none;"><input type="hidden" id="wp-email_nonce" name="wp-email_nonce" value="'.wp_create_nonce('wp-email-nonce').'" /></p>'."\n";
if($echo) {
echo $output;
} else {
return $output;
}
}
### Function: Multiple E-Mails
function email_multiple($echo = true) {
$email_multiple = (int) get_option('email_multiple');
$outut = '';
if($email_multiple > 1) {
$output = '<br /><em>'.sprintf(_n('Separate multiple entries with a comma. Maximum %s entry.', 'Separate multiple entries with a comma. Maximum %s entries.', $email_multiple, 'wp-email'), number_format_i18n($email_multiple)).'</em>';
if($echo) {
echo $outut;
} else {
return $output;
}
}
}
### Function: Get EMail Total Sent
if(!function_exists('get_emails')) {
function get_emails($echo = true) {
global $wpdb;
$totalemails = $wpdb->get_var("SELECT COUNT(email_id) FROM $wpdb->email");
if($echo) {
echo number_format_i18n($totalemails);
} else {
return number_format_i18n($totalemails);
}
}
}
### Function: Get EMail Total Sent Success
if( ! function_exists( 'get_emails_success' ) ) {
function get_emails_success( $echo = true ) {
global $wpdb;
$totalemails_success = $wpdb->get_var(
$wpdb->prepare( "SELECT COUNT(email_id) FROM $wpdb->email WHERE email_status = %s", __('Success', 'wp-email') )
);
if( $echo ) {
echo number_format_i18n( $totalemails_success );
} else {
return number_format_i18n( $totalemails_success );
}
}
}
### Function: Get EMail Total Sent Failed
if( ! function_exists( 'get_emails_failed' ) ) {
function get_emails_failed( $echo = true ) {
global $wpdb;
$totalemails_failed = $wpdb->get_var(
$wpdb->prepare( "SELECT COUNT(email_id) FROM $wpdb->email WHERE email_status = %s", __('Failed', 'wp-email') )
);
if( $echo ) {
echo number_format_i18n( $totalemails_failed );
} else {
return number_format_i18n( $totalemails_failed );
}
}
}
### Function: Get EMail Sent For Post
if( ! function_exists( 'get_email_count' ) ) {
function get_email_count( $post_id = 0, $echo = true ) {
global $wpdb;
if( $post_id === 0 ) {
global $post;
$post_id = $post->ID;
}
$totalemails = $wpdb->get_var(
$wpdb->prepare( "SELECT COUNT(email_id) FROM $wpdb->email WHERE email_postid = %d", $post_id )
);
if( $echo ) {
echo number_format_i18n( $totalemails );
} else {
return number_format_i18n( $totalemails );
}
}
}
### Function: Get Most E-Mailed
if(!function_exists('get_mostemailed')) {
function get_mostemailed($mode = '', $limit = 10, $chars = 0, $echo = true) {
global $wpdb, $post;
$temp_post = $post;
$where = '';
$temp = '';
if(!empty($mode) && $mode != 'both') {
$where = "post_type = '$mode'";
} else {
$where = '1=1';
}
$mostemailed= $wpdb->get_results("SELECT $wpdb->posts.*, COUNT($wpdb->email.email_postid) AS email_total FROM $wpdb->email LEFT JOIN $wpdb->posts ON $wpdb->email.email_postid = $wpdb->posts.ID WHERE post_date < '".current_time('mysql')."' AND $where AND post_password = '' AND post_status = 'publish' GROUP BY $wpdb->email.email_postid ORDER BY email_total DESC LIMIT $limit");
if($mostemailed) {
if($chars > 0) {
foreach ($mostemailed as $post) {
$post_title = get_the_title();
$email_total = (int) $post->email_total;
$temp .= "<li><a href=\"".get_permalink()."\">".snippet_text($post_title, $chars)."</a> - ".sprintf(_n('%s email', '%s emails', $email_total, 'wp-email'), number_format_i18n($email_total))."</li>\n";
}
} else {
foreach ($mostemailed as $post) {
$post_title = get_the_title();
$email_total = (int) $post->email_total;
$temp .= "<li><a href=\"".get_permalink()."\">$post_title</a> - ".sprintf(_n('%s email', '%s emails', $email_total, 'wp-email'), number_format_i18n($email_total))."</li>\n";
}
}
} else {
$temp = '<li>'.__('N/A', 'wp-email').'</li>'."\n";
}
$post = $temp_post;
if($echo) {
echo $temp;
} else {
return $temp;
}
}
}
### Function: Load WP-EMail
add_action('template_redirect', 'wp_email', 5);
function wp_email() {
global $wp_query;
$template_redirect = apply_filters( 'wp_email_template_redirect', true );
if( $template_redirect ) {
if (array_key_exists('wp_email', $wp_query->query_vars)) {
include(WP_PLUGIN_DIR . '/wp-email/email-standalone.php');
exit();
} elseif (array_key_exists('wp_email_popup', $wp_query->query_vars)) {
include(WP_PLUGIN_DIR . '/wp-email/email-popup.php');
exit();
}
}
}
### Function: Process E-Mail Form
add_action('wp_ajax_email', 'process_email_form');
add_action('wp_ajax_nopriv_email', 'process_email_form');
function process_email_form() {
global $wpdb, $post;
// If User Click On Mail
if(isset($_POST['action']) && $_POST['action'] == 'email') {
// Verify Referer
if(!check_ajax_referer('wp-email-nonce', 'wp-email_nonce', false))
{
_e('Failed To Verify Referrer', 'wp-email');
exit();
}
@session_start();
header('Content-Type: text/html; charset='.get_option('blog_charset').'');
// POST Variables
$yourname = ! empty($_POST['yourname']) ? sanitize_text_field( $_POST['yourname'] ) : '';
$youremail = ! empty($_POST['youremail']) ? sanitize_text_field( $_POST['youremail'] ) : '';
$yourremarks = ! empty($_POST['yourremarks'])? sanitize_text_field( $_POST['yourremarks'] ) : '';
$friendname = ! empty($_POST['friendname']) ? sanitize_text_field( $_POST['friendname'] ) : '';
$friendemail = ! empty($_POST['friendemail'])? sanitize_text_field( $_POST['friendemail'] ) : '';
$imageverify = ! empty($_POST['imageverify'])? $_POST['imageverify'] : '';
$p = ! empty($_POST['p']) ? (int) $_POST['p'] : 0;
$page_id = ! empty($_POST['page_id']) ? (int) $_POST['page_id'] : 0;
// Get Post Information
if($p > 0) {
$post_type = get_post_type($p);
$query_post = 'p='. $p . '&post_type=' . $post_type;
$id = $p;
} else {
$query_post = 'page_id='.$page_id;
$id = $page_id;
}
query_posts($query_post);
if(have_posts()) {
while(have_posts()) {
the_post();
$post_title = email_get_title();
$post_author = get_the_author();
$post_date = get_the_time(get_option('date_format').' ('.get_option('time_format').')', '', '', false);
$post_category = email_category(__(',', 'wp-email').' ');
$post_category_alt = strip_tags($post_category);
$post_excerpt = get_the_excerpt();
$post_content = email_content();
$post_content_alt = email_content_alt();
}
}
// Error
$error = '';
$error_field = array('yourname' => $yourname, 'youremail' => $youremail, 'yourremarks' => $yourremarks, 'friendname' => $friendname, 'friendemail' => $friendemail, 'id' => $id);
// Get Options
$email_fields = get_option('email_fields');
$email_image_verify = (int) get_option('email_imageverify');
// Multiple Names/Emails
$friends = array();
$friendname_count = 0;
$friendemail_count = 0;
$multiple_names = preg_split('/,|;/', $friendname);
$multiple_emails = preg_split('/,|;/', $friendemail);
$multiple_max = (int) get_option('email_multiple');
if($multiple_max === 0) { $multiple_max = 1; }
// Checking Your Name Field For Errors
if((int) $email_fields['yourname'] === 1) {
if(empty($yourname)) {
$error .= '<br /><strong>»</strong> '.__('Your Name is empty', 'wp-email');
}
if(!is_valid_name($yourname)) {
$error .= '<br /><strong>»</strong> '.__('Your Name is invalid', 'wp-email');
}
}
// Checking Your E-Mail Field For Errors
if((int) $email_fields['youremail'] === 1) {
if(empty($youremail)) {
$error .= '<br /><strong>»</strong> '.__('Your Email is empty', 'wp-email');
}
if(!is_valid_email($youremail)) {
$error .= '<br /><strong>»</strong> '.__('Your Email is invalid', 'wp-email');
}
}
// Checking Your Remarks Field For Errors
if((int) $email_fields['yourremarks'] === 1) {
if(!is_valid_remarks($yourremarks)) {
$error .= '<br /><strong>»</strong> '.__('Your Remarks is invalid', 'wp-email');
}
}
// Checking Friend's Name Field For Errors
if((int) $email_fields['friendname'] === 1) {
if(empty($friendname)) {
$error .= '<br /><strong>»</strong> '.__('Friend Name(s) is empty', 'wp-email');
} else {
if($multiple_names) {
foreach($multiple_names as $multiple_name) {
$multiple_name = trim($multiple_name);
if(empty($multiple_name)) {
$error .= '<br /><strong>»</strong> '.sprintf(__('Friend Name is empty: %s', 'wp-email'), $multiple_name);
} elseif(!is_valid_name($multiple_name)) {
$error .= '<br /><strong>»</strong> '.sprintf(__('Friend Name is invalid: %s', 'wp-email'), $multiple_name);
} else {
$friends[$friendname_count]['name'] = $multiple_name;
$friendname_count++;
}
if($friendname_count > $multiple_max) {
break;
}
}
}
}
}
// Checking Friend's E-Mail Field For Errors
if(empty($friendemail)) {
$error .= '<br /><strong>»</strong> '.__('Friend Email(s) is empty', 'wp-email');
} else {
if($multiple_emails) {
foreach($multiple_emails as $multiple_email) {
$multiple_email = trim($multiple_email);
if(empty($multiple_email)) {
$error .= '<br /><strong>»</strong> '.sprintf(__('Friend Email is empty: %s', 'wp-email'), $multiple_email);
} elseif(!is_valid_email($multiple_email)) {
$error .= '<br /><strong>»</strong> '.sprintf(__('Friend Email is invalid: %s', 'wp-email'), $multiple_email);
} else {
$friends[$friendemail_count]['email'] = $multiple_email;
$friendemail_count++;
}
if($friendemail_count > $multiple_max) {
break;
}
}
}
}
// Checking If The Fields Exceed The Size Of Maximum Entries Allowed
if(count($friends) > $multiple_max) {
$error .= '<br /><strong>»</strong> '.sprintf(_n('Maximum %s Friend allowed', 'Maximum %s Friend(s) allowed', $multiple_max, 'wp-email'), number_format_i18n($multiple_max));
}
if((int) $email_fields['friendname'] === 1) {
if($friendname_count !== $friendemail_count) {
$error .= '<br /><strong>»</strong> '.__('Friend Name(s) count does not tally with Friend Email(s) count', 'wp-email');
}
}
// Check Whether We Enable Image Verification
if($email_image_verify) {
$imageverify = strtoupper($imageverify);
if(empty($imageverify)) {
$error .= '<br /><strong>»</strong> '.__('Image Verification is empty', 'wp-email');
} else {
if($_SESSION['email_verify'] !== md5($imageverify)) {
$error .= '<br /><strong>»</strong> '.__('Image Verification failed', 'wp-email');
}
}
}
// If There Is No Error, We Process The E-Mail
if(empty($error) && not_spamming()) {
// If Remarks Is Empty, Assign N/A
if(empty($yourremarks)) { $yourremarks = __('N/A', 'wp-email'); }
// Template For E-Mail Subject
$template_email_subject = stripslashes(get_option('email_template_subject'));
$template_email_subject = str_replace("%EMAIL_YOUR_NAME%", $yourname, $template_email_subject);
$template_email_subject = str_replace("%EMAIL_YOUR_EMAIL%", $youremail, $template_email_subject);
$template_email_subject = str_replace("%EMAIL_POST_TITLE%", $post_title, $template_email_subject);
$template_email_subject = str_replace("%EMAIL_POST_AUTHOR%", $post_author, $template_email_subject);
$template_email_subject = str_replace("%EMAIL_POST_DATE%", $post_date, $template_email_subject);
$template_email_subject = str_replace("%EMAIL_POST_CATEGORY%", $post_category_alt, $template_email_subject);
$template_email_subject = str_replace("%EMAIL_BLOG_NAME%", get_bloginfo('name'), $template_email_subject);
$template_email_subject = str_replace("%EMAIL_BLOG_URL%", get_bloginfo('url'), $template_email_subject);
$template_email_subject = str_replace("%EMAIL_PERMALINK%", get_permalink(), $template_email_subject);
// Template For E-Mail Body
$template_email_body = stripslashes(get_option('email_template_body'));
$template_email_body = str_replace("%EMAIL_YOUR_NAME%", $yourname, $template_email_body);
$template_email_body = str_replace("%EMAIL_YOUR_EMAIL%", $youremail, $template_email_body);
$template_email_body = str_replace("%EMAIL_YOUR_REMARKS%", $yourremarks, $template_email_body);
$template_email_body = str_replace("%EMAIL_FRIEND_NAME%", $friendname, $template_email_body);
$template_email_body = str_replace("%EMAIL_FRIEND_EMAIL%", $friendemail, $template_email_body);
$template_email_body = str_replace("%EMAIL_POST_TITLE%", $post_title, $template_email_body);
$template_email_body = str_replace("%EMAIL_POST_AUTHOR%", $post_author, $template_email_body);
$template_email_body = str_replace("%EMAIL_POST_DATE%", $post_date, $template_email_body);
$template_email_body = str_replace("%EMAIL_POST_CATEGORY%", $post_category, $template_email_body);
$template_email_body = str_replace("%EMAIL_POST_EXCERPT%", $post_excerpt, $template_email_body);
$template_email_body = str_replace("%EMAIL_POST_CONTENT%", $post_content, $template_email_body);
$template_email_body = str_replace("%EMAIL_BLOG_NAME%", get_bloginfo('name'), $template_email_body);
$template_email_body = str_replace("%EMAIL_BLOG_URL%", get_bloginfo('url'), $template_email_body);
$template_email_body = str_replace("%EMAIL_PERMALINK%", get_permalink(), $template_email_body);
if( is_rtl() ) {
$template_email_body = "<div style=\"direction: rtl;\">$template_email_body</div>";
}
// Template For E-Mail Alternate Body
$template_email_bodyalt = stripslashes(get_option('email_template_bodyalt'));
$template_email_bodyalt = str_replace("%EMAIL_YOUR_NAME%", $yourname, $template_email_bodyalt);
$template_email_bodyalt = str_replace("%EMAIL_YOUR_EMAIL%", $youremail, $template_email_bodyalt);
$template_email_bodyalt = str_replace("%EMAIL_YOUR_REMARKS%", $yourremarks, $template_email_bodyalt);
$template_email_bodyalt = str_replace("%EMAIL_FRIEND_NAME%", $friendname, $template_email_bodyalt);
$template_email_bodyalt = str_replace("%EMAIL_FRIEND_EMAIL%", $friendemail, $template_email_bodyalt);
$template_email_bodyalt = str_replace("%EMAIL_POST_TITLE%", $post_title, $template_email_bodyalt);
$template_email_bodyalt = str_replace("%EMAIL_POST_AUTHOR%", $post_author, $template_email_bodyalt);
$template_email_bodyalt = str_replace("%EMAIL_POST_DATE%", $post_date, $template_email_bodyalt);
$template_email_bodyalt = str_replace("%EMAIL_POST_CATEGORY%", $post_category_alt, $template_email_bodyalt);
$template_email_bodyalt = str_replace("%EMAIL_POST_EXCERPT%", $post_excerpt, $template_email_bodyalt);
$template_email_bodyalt = str_replace("%EMAIL_POST_CONTENT%", $post_content_alt, $template_email_bodyalt);
$template_email_bodyalt = str_replace("%EMAIL_BLOG_NAME%", get_bloginfo('name'), $template_email_bodyalt);
$template_email_bodyalt = str_replace("%EMAIL_BLOG_URL%", get_bloginfo('url'), $template_email_bodyalt);
$template_email_bodyalt = str_replace("%EMAIL_PERMALINK%", get_permalink(), $template_email_bodyalt);
$email_contenttype = get_option( 'email_contenttype' );
$email_charset = get_bloginfo( 'charset' );
$from = $yourname . ' <' . $youremail . '>';
$to = array();
foreach($friends as $friend) {
$to[] = $friend['name'] . ' <' . $friend['email'] . '>';
}
$subject = $template_email_subject;
$message = $email_contenttype === 'text/plain' ? $template_email_bodyalt : $template_email_body;
$headers = array(
'From: ' . $from,
'Content-Type: ' . $email_contenttype . '; charset=' . $email_charset,
);
$send_mail = wp_mail( implode( ', ', $to ), $subject, $message, $headers );
if( $send_mail ) {
$email_status = __('Success', 'wp-email');
// Template For Sent Successfully
$template_email_sentsuccess = stripslashes(get_option('email_template_sentsuccess'));
$template_email_sentsuccess = str_replace("%EMAIL_FRIEND_NAME%", $friendname, $template_email_sentsuccess);
$template_email_sentsuccess = str_replace("%EMAIL_FRIEND_EMAIL%", $friendemail, $template_email_sentsuccess);
$template_email_sentsuccess = str_replace("%EMAIL_POST_TITLE%", $post_title, $template_email_sentsuccess);
$template_email_sentsuccess = str_replace("%EMAIL_BLOG_NAME%", get_bloginfo('name'), $template_email_sentsuccess);
$template_email_sentsuccess = str_replace("%EMAIL_BLOG_URL%", get_bloginfo('url'), $template_email_sentsuccess);
$template_email_sentsuccess = str_replace("%EMAIL_PERMALINK%", get_permalink(), $template_email_sentsuccess);
// If There Is Error Sending
} else {
if($yourremarks === __('N/A', 'wp-email')) { $yourremarks = ''; }
$email_status = __('Failed', 'wp-email');
// Template For Sent Failed
$template_email_sentfailed = stripslashes(get_option('email_template_sentfailed'));
$template_email_sentfailed = str_replace("%EMAIL_FRIEND_NAME%", $friendname, $template_email_sentfailed);
$template_email_sentfailed = str_replace("%EMAIL_FRIEND_EMAIL%", $friendemail, $template_email_sentfailed);
$template_email_sentfailed = str_replace("%EMAIL_ERROR_MSG%", '', $template_email_sentfailed);
$template_email_sentfailed = str_replace("%EMAIL_POST_TITLE%", $post_title, $template_email_sentfailed);
$template_email_sentfailed = str_replace("%EMAIL_BLOG_NAME%", get_bloginfo('name'), $template_email_sentfailed);
$template_email_sentfailed = str_replace("%EMAIL_BLOG_URL%", get_bloginfo('url'), $template_email_sentfailed);
$template_email_sentfailed = str_replace("%EMAIL_PERMALINK%", get_permalink(), $template_email_sentfailed);
}
// Logging
$email_yourname = addslashes($yourname);
$email_youremail = addslashes($youremail);
$email_yourremarks = addslashes($yourremarks);
$email_postid = (int) get_the_id();
$email_posttitle = addslashes($post_title);
$email_timestamp = current_time('timestamp');
$email_ip = email_get_ipaddress();
$email_host = esc_attr(@gethostbyaddr($email_ip));
foreach($friends as $friend) {
$email_friendname = addslashes($friend['name']);
$email_friendemail = addslashes($friend['email']);
$wpdb->insert(
$wpdb->email,
array(