PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.5.2
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.5.2
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/models/FrmEmail.php +55 -129 6.265.5.2 View file →
@@ -8,94 +8,94 @@
8 8 */
9 9 class FrmEmail {
10 10
11 11 /**
12 - * @var string
12 + * @var string $email_key
13 13 */
14 14 private $email_key = '';
15 15
16 16 /**
17 - * @var array
17 + * @var array $to
18 18 */
19 19 private $to = array();
20 20
21 21 /**
22 - * @var array
22 + * @var array $cc
23 23 */
24 24 private $cc = array();
25 25
26 26 /**
27 - * @var array
27 + * @var array $bcc
28 28 */
29 29 private $bcc = array();
30 30
31 31 /**
32 - * @var string
32 + * @var string $from
33 33 */
34 34 private $from = '';
35 35
36 36 /**
37 - * @var string
37 + * @var string $reply_to
38 38 */
39 39 private $reply_to = '';
40 40
41 41 /**
42 - * @var string
42 + * @var string $subject
43 43 */
44 44 private $subject = '';
45 45
46 46 /**
47 - * @var string
47 + * @var string $message
48 48 */
49 49 private $message = '';
50 50
51 51 /**
52 - * @var array
52 + * @var array $attachments
53 53 */
54 54 private $attachments = array();
55 55
56 56 /**
57 - * @var bool
57 + * @var bool $is_plain_text
58 58 */
59 59 private $is_plain_text = false;
60 60
61 61 /**
62 - * @var bool
62 + * @var bool $is_single_recipient
63 63 */
64 64 private $is_single_recipient = false;
65 65
66 66 /**
67 - * @var bool
67 + * @var bool $include_user_info
68 68 */
69 69 private $include_user_info = false;
70 70
71 71 /**
72 - * @var string
72 + * @var string $charset
73 73 */
74 74 private $charset = '';
75 75
76 76 /**
77 - * @var string
77 + * @var string $content_type
78 78 */
79 79 private $content_type = 'text/html';
80 80
81 81 /**
82 - * @var array
82 + * @var array $settings
83 83 */
84 84 private $settings = array();
85 85
86 86 /**
87 - * @var stdClass
87 + * @var stdClass $entry
88 88 */
89 89 private $entry;
90 90
91 91 /**
92 - * @var stdClass
92 + * @var stdClass $form
93 93 */
94 94 private $form;
95 95
96 96 /**
97 - * @var int
97 + * @var int $action_id
98 98 */
99 99 private $action_id = 0;
100 100
101 101 /**
@@ -141,10 +141,8 @@
141 141 *
142 142 * @since 2.03.04
143 143 *
144 144 * @param object $action
145 - *
146 - * @return void
147 145 */
148 146 private function set_email_key( $action ) {
149 147 $this->email_key = $action->ID;
150 148 }
@@ -154,10 +152,8 @@
154 152 *
155 153 * @since 2.03.04
156 154 *
157 155 * @param array $user_id_args
158 - *
159 - * @return void
160 156 */
161 157 private function set_to( $user_id_args ) {
162 158 $to = $this->prepare_email_setting( $this->settings['email_to'], $user_id_args );
163 159 $to = $this->explode_emails( $to );
@@ -190,10 +186,8 @@
190 186 *
191 187 * @since 2.03.04
192 188 *
193 189 * @param array $user_id_args
194 - *
195 - * @return void
196 190 */
197 191 private function set_cc( $user_id_args ) {
198 192 $this->cc = $this->prepare_additional_recipients( $this->settings['cc'], $user_id_args );
199 193 }
@@ -203,10 +197,8 @@
203 197 *
204 198 * @since 2.03.04
205 199 *
206 200 * @param array $user_id_args
207 - *
208 - * @return void
209 201 */
210 202 private function set_bcc( $user_id_args ) {
211 203 $this->bcc = $this->prepare_additional_recipients( $this->settings['bcc'], $user_id_args );
212 204 }
@@ -216,9 +208,9 @@
216 208 *
217 209 * @since 2.03.04
218 210 *
219 211 * @param string $recipients
220 - * @param array $user_id_args
212 + * @param array $user_id_args
221 213 *
222 214 * @return array
223 215 */
224 216 private function prepare_additional_recipients( $recipients, $user_id_args ) {
@@ -236,14 +228,13 @@
236 228 *
237 229 * @since 2.03.04
238 230 *
239 231 * @param array $user_id_args
240 - *
241 232 * @return void
242 233 */
243 234 private function set_from( $user_id_args ) {
244 235 if ( empty( $this->settings['from'] ) ) {
245 - $from = FrmEmailHelper::get_default_from_email();
236 + $from = get_option( 'admin_email' );
246 237 } else {
247 238 $from = $this->prepare_email_setting( $this->settings['from'], $user_id_args );
248 239 }
249 240
@@ -255,10 +246,8 @@
255 246 *
256 247 * @since 2.03.04
257 248 *
258 249 * @param array $user_id_args
259 - *
260 - * @return void
261 250 */
262 251 private function set_reply_to( $user_id_args ) {
263 252 $this->reply_to = trim( $this->settings['reply_to'] );
264 253
@@ -277,19 +266,13 @@
277 266 * Set the is_plain_text property
278 267 * This should be set before the message
279 268 *
280 269 * @since 2.03.04
281 - *
282 - * @return void
283 270 */
284 271 private function set_is_plain_text() {
285 - if ( empty( $this->settings['email_style'] ) ) {
286 - // If `email_style` isn't set, use the `plain_text` checkbox.
287 - $this->is_plain_text = ! empty( $this->settings['plain_text'] );
288 - return;
272 + if ( $this->settings['plain_text'] ) {
273 + $this->is_plain_text = true;
289 274 }
290 -
291 - $this->is_plain_text = 'plain' === $this->settings['email_style'];
292 275 }
293 276
294 277 /**
295 278 * Set the include_user_info property
@@ -295,10 +278,8 @@
295 278 * Set the include_user_info property
296 279 * This should be set before the message
297 280 *
298 281 * @since 2.03.04
299 - *
300 - * @return void
301 282 */
302 283 private function set_include_user_info() {
303 284 if ( isset( $this->settings['inc_user_info'] ) ) {
304 285 $this->include_user_info = $this->settings['inc_user_info'];
@@ -309,11 +290,9 @@
309 290 * Set the is_single_recipient property
310 291 *
311 292 * @since 2.03.04
312 293 *
313 - * @param object $action
314 - *
315 - * @return void
294 + * @param $action
316 295 */
317 296 private function set_is_single_recipient( $action ) {
318 297 $args = array(
319 298 'form' => $this->form,
@@ -332,10 +311,8 @@
332 311 /**
333 312 * Set the charset
334 313 *
335 314 * @since 2.03.04
336 - *
337 - * @return void
338 315 */
339 316 private function set_charset() {
340 317 $this->charset = get_option( 'blog_charset' );
341 318 }
@@ -343,10 +320,8 @@
343 320 /**
344 321 * Set the content type
345 322 *
346 323 * @since 2.03.04
347 - *
348 - * @return void
349 324 */
350 325 private function set_content_type() {
351 326 if ( $this->is_plain_text ) {
352 327 $this->content_type = 'text/plain';
@@ -383,38 +358,33 @@
383 358 /**
384 359 * Set the email message
385 360 *
386 361 * @since 2.03.04
387 - *
388 - * @return void
389 362 */
390 363 private function set_message() {
391 364 $this->message = $this->settings['email_message'];
392 365
393 366 if ( ! $this->is_plain_text ) {
394 - // The decode is to support [default-html] shortcodes.
395 - $this->message = html_entity_decode( $this->message );
367 + $this->message = html_entity_decode( $this->message ); // The decode is to support [default-html] shortcodes.
396 368 }
397 369
398 - $this->message = FrmFieldsHelper::basic_replace_shortcodes( $this->message, $this->form, $this->entry );
370 + $this->message = FrmFieldsHelper::basic_replace_shortcodes( $this->message, $this->form, $this->entry );
371 +
399 372 $prev_mail_body = $this->message;
400 -
401 - // Make a copy to prevent changes by reference.
402 - $pass_entry = clone $this->entry;
403 - $mail_body = FrmEntriesHelper::replace_default_message(
373 + $pass_entry = clone $this->entry; // make a copy to prevent changes by reference
374 + $mail_body = FrmEntriesHelper::replace_default_message(
404 375 $prev_mail_body,
405 376 array(
406 - 'id' => $this->entry->id,
407 - 'entry' => $pass_entry,
408 - 'plain_text' => $this->is_plain_text,
409 - 'user_info' => $this->include_user_info,
410 - 'table_style' => $this->settings['email_style'],
377 + 'id' => $this->entry->id,
378 + 'entry' => $pass_entry,
379 + 'plain_text' => $this->is_plain_text,
380 + 'user_info' => $this->include_user_info,
411 381 )
412 382 );
413 383
414 384 // Add the user info if it isn't already included
415 385 if ( $this->include_user_info && $prev_mail_body === $mail_body ) {
416 - $data = $this->entry->description;
386 + $data = $this->entry->description;
417 387 $mail_body .= "\r\n\r\n" . __( 'User Information', 'formidable' ) . "\r\n";
418 388 $this->maybe_add_ip( $mail_body );
419 389 $mail_body .= __( 'User-Agent (Browser/OS)', 'formidable' ) . ': ' . FrmEntriesHelper::get_browser( $data['browser'] ) . "\r\n";
420 390 $mail_body .= __( 'Referrer', 'formidable' ) . ': ' . $data['referrer'] . "\r\n";
@@ -421,39 +391,19 @@
421 391 }
422 392
423 393 $this->message = $mail_body;
424 394
395 + $this->message = do_shortcode( $this->message );
396 +
425 397 if ( $this->is_plain_text ) {
426 398 $this->message = wp_specialchars_decode( strip_tags( $this->message ), ENT_QUOTES );
427 - $this->message = str_replace( ' ', '', $this->message );
428 399 } else {
429 - $this->add_autop();
400 + $this->message = wpautop( $this->message, false ); // HTML emails should use autop.
430 401 }
431 402
432 403 $this->message = apply_filters( 'frm_email_message', $this->message, $this->package_atts() );
433 404 }
434 405
435 - /**
436 - * Runs message through autop, extracting the content inside body tag if it has <body>.
437 - *
438 - * @return void
439 - */
440 - private function add_autop() {
441 - $message = $this->message;
442 - preg_match( '/<body[^>]*>([\s\S]*?)<\/body>/', $message, $match );
443 -
444 - if ( ! empty( $match[1] ) ) {
445 - $this->message = str_replace( $match[1], trim( wpautop( $match[1] ) ), $message );
446 - } else {
447 - $this->message = trim( wpautop( $message ) );
448 - }
449 - }
450 -
451 - /**
452 - * @param string $mail_body
453 - *
454 - * @return void
455 - */
456 406 private function maybe_add_ip( &$mail_body ) {
457 407 if ( ! empty( $this->entry->ip ) ) {
458 408 $mail_body .= __( 'IP Address', 'formidable' ) . ': ' . $this->entry->ip . "\r\n";
459 409 }
@@ -518,10 +468,11 @@
518 468 */
519 469 private function has_recipients() {
520 470 if ( empty( $this->to ) && empty( $this->cc ) && empty( $this->bcc ) ) {
521 471 return false;
472 + } else {
473 + return true;
522 474 }
523 - return true;
524 475 }
525 476
526 477 /**
527 478 * Send an email
@@ -534,9 +485,8 @@
534 485 $this->remove_buddypress_filters();
535 486 $this->add_mandrill_filter();
536 487
537 488 $sent = false;
538 -
539 489 if ( count( $this->to ) > 1 && $this->is_single_recipient ) {
540 490 foreach ( $this->to as $recipient ) {
541 491 $sent = $this->send_single( $recipient );
542 492 }
@@ -575,9 +525,8 @@
575 525 if ( ! $sent ) {
576 526 if ( is_array( $header ) ) {
577 527 $header = implode( "\r\n", $header );
578 528 }
579 -
580 529 $recipient = implode( ',', (array) $recipient );
581 530 $sent = mail( $recipient, $subject, $this->message, $header );
582 531 }
583 532
@@ -615,9 +564,9 @@
615 564 * Get the userID field ID and key for email settings
616 565 *
617 566 * @since 2.03.04
618 567 *
619 - * @param int $form_id
568 + * @param $form_id
620 569 *
621 570 * @return array
622 571 */
623 572 private function get_user_id_args( $form_id ) {
@@ -626,9 +575,8 @@
626 575 'field_key' => '',
627 576 );
628 577
629 578 $user_id_args['field_id'] = FrmEmailHelper::get_user_id_field_for_form( $form_id );
630 -
631 579 if ( $user_id_args['field_id'] ) {
632 580 $user_id_args['field_key'] = FrmField::get_key_by_id( $user_id_args['field_id'] );
633 581 }
634 582
@@ -640,9 +588,9 @@
640 588 *
641 589 * @since 2.03.04
642 590 *
643 591 * @param string $value
644 - * @param array $user_id_args
592 + * @param array $user_id_args
645 593 *
646 594 * @return string
647 595 */
648 596 private function prepare_email_setting( $value, $user_id_args ) {
@@ -672,9 +620,8 @@
672 620 * @return array|string $emails
673 621 */
674 622 private function explode_emails( $emails ) {
675 623 $emails = ( ! empty( $emails ) ? preg_split( '/(,|;)/', $emails ) : '' );
676 -
677 624 if ( is_array( $emails ) ) {
678 625 $emails = array_map( 'trim', $emails );
679 626 } else {
680 627 $emails = trim( $emails );
@@ -700,24 +647,24 @@
700 647
701 648 if ( is_email( $val ) ) {
702 649 // If a plain email is used, no formatting is needed
703 650 continue;
704 - }
651 + } else {
652 + $parts = explode( ' ', $val );
653 + $email = end( $parts );
705 654
706 - $parts = explode( ' ', $val );
707 - $email = end( $parts );
708 -
709 - if ( is_email( $email ) ) {
710 - // If user enters a name and email
711 - $name = trim( str_replace( $email, '', $val ) );
712 - } else {
713 - // If user enters a name without an email
714 - unset( $recipients[ $key ] );
715 - continue;
655 + if ( is_email( $email ) ) {
656 + // If user enters a name and email
657 + $name = trim( str_replace( $email, '', $val ) );
658 + } else {
659 + // If user enters a name without an email
660 + unset( $recipients[ $key ] );
661 + continue;
662 + }
716 663 }
717 664
718 665 $recipients[ $key ] = $this->format_from_email( $name, $email );
719 - }//end foreach
666 + }
720 667
721 668 return $recipients;
722 669 }
723 670
@@ -743,9 +690,8 @@
743 690 if ( strpos( $from_email, '@yahoo.com' ) ) {
744 691
745 692 // Get the site domain and get rid of www.
746 693 $sitename = strtolower( FrmAppHelper::get_server_value( 'SERVER_NAME' ) );
747 -
748 694 if ( substr( $sitename, 0, 4 ) === 'www.' ) {
749 695 $sitename = substr( $sitename, 4 );
750 696 }
751 697
@@ -768,9 +714,9 @@
768 714 $reply_to = trim( $reply_to );
769 715
770 716 if ( ! is_email( $reply_to ) ) {
771 717 list( $name, $email ) = $this->get_name_and_email_for_sender( $reply_to );
772 - $reply_to = $this->format_from_email( $name, $email );
718 + $reply_to = $this->format_from_email( $name, $email );
773 719 }
774 720
775 721 return $reply_to;
776 722 }
@@ -778,16 +724,11 @@
778 724 /**
779 725 * Get only the email if the name and email have been combined
780 726 *
781 727 * @since 3.0.06
782 - *
783 - * @param string $name
784 - *
785 - * @return string
786 728 */
787 729 private function get_email_from_name( $name ) {
788 730 $email = trim( trim( $name, '>' ), '<' );
789 -
790 731 if ( strpos( $email, '<' ) !== false ) {
791 732 $parts = explode( '<', $email );
792 733 $email = trim( $parts[1], '>' );
793 734 }
@@ -820,13 +761,8 @@
820 761 }
821 762
822 763 /**
823 764 * @since 3.0.06
824 - *
825 - * @param string $name
826 - * @param string $email
827 - *
828 - * @return string
829 765 */
830 766 private function format_from_email( $name, $email ) {
831 767 if ( '' !== $name ) {
832 768 $email = $name . ' <' . $email . '>';
@@ -839,10 +775,8 @@
839 775 * Remove phone numbers from To addresses
840 776 * Send the phone numbers to the frm_send_to_not_email hook
841 777 *
842 778 * @since 2.03.04
843 - *
844 - * @return void
845 779 */
846 780 private function handle_phone_numbers() {
847 781
848 782 foreach ( $this->to as $key => $recipient ) {
@@ -869,10 +803,10 @@
869 803 );
870 804
871 805 // Remove phone number from to addresses
872 806 unset( $this->to[ $key ] );
873 - }//end if
874 - }//end foreach
807 + }
808 + }
875 809 }
876 810
877 811 /**
878 812 * Package an array of FrmEmail properties
@@ -891,12 +825,10 @@
891 825 'subject' => $this->subject,
892 826 'message' => $this->message,
893 827 'attachments' => $this->attachments,
894 828 'plain_text' => $this->is_plain_text,
895 - 'email_key' => $this->email_key,
896 829 'form' => $this->form,
897 830 'entry' => $this->entry,
898 - 'email_style' => $this->settings['email_style'],
899 831 );
900 832 }
901 833
902 834 /**
@@ -902,10 +834,8 @@
902 834 /**
903 835 * Remove the Buddypress email filters
904 836 *
905 837 * @since 2.03.04
906 - *
907 - * @return void
908 838 */
909 839 private function remove_buddypress_filters() {
910 840 remove_filter( 'wp_mail_from', 'bp_core_email_from_address_filter' );
911 841 remove_filter( 'wp_mail_from_name', 'bp_core_email_from_name_filter' );
@@ -915,10 +845,8 @@
915 845 * Add Mandrill line break filter
916 846 * Remove line breaks in HTML emails to prevent conflicts with Mandrill
917 847 *
918 848 * @since 2.03.04
919 - *
920 - * @return void
921 849 */
922 850 private function add_mandrill_filter() {
923 851 if ( ! $this->is_plain_text ) {
924 852 add_filter( 'mandrill_nl2br', 'FrmEmailHelper::remove_mandrill_br' );
@@ -928,10 +856,8 @@
928 856 /**
929 857 * Remove Mandrill line break filter
930 858 *
931 859 * @since 2.03.04
932 - *
933 - * @return void
934 860 */
935 861 private function remove_mandrill_filter() {
936 862 remove_filter( 'mandrill_nl2br', 'FrmEmailHelper::remove_mandrill_br' );
937 863 }