PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.2
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.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 -71 6.266.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 /**
@@ -216,9 +216,9 @@
216 216 *
217 217 * @since 2.03.04
218 218 *
219 219 * @param string $recipients
220 - * @param array $user_id_args
220 + * @param array $user_id_args
221 221 *
222 222 * @return array
223 223 */
224 224 private function prepare_additional_recipients( $recipients, $user_id_args ) {
@@ -236,14 +236,13 @@
236 236 *
237 237 * @since 2.03.04
238 238 *
239 239 * @param array $user_id_args
240 - *
241 240 * @return void
242 241 */
243 242 private function set_from( $user_id_args ) {
244 243 if ( empty( $this->settings['from'] ) ) {
245 - $from = FrmEmailHelper::get_default_from_email();
244 + $from = get_option( 'admin_email' );
246 245 } else {
247 246 $from = $this->prepare_email_setting( $this->settings['from'], $user_id_args );
248 247 }
249 248
@@ -281,15 +280,11 @@
281 280 *
282 281 * @return void
283 282 */
284 283 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;
284 + if ( $this->settings['plain_text'] ) {
285 + $this->is_plain_text = true;
289 286 }
290 -
291 - $this->is_plain_text = 'plain' === $this->settings['email_style'];
292 287 }
293 288
294 289 /**
295 290 * Set the include_user_info property
@@ -309,8 +304,9 @@
309 304 * Set the is_single_recipient property
310 305 *
311 306 * @since 2.03.04
312 307 *
308 + * @param $action
313 309 * @param object $action
314 310 *
315 311 * @return void
316 312 */
@@ -390,31 +386,28 @@
390 386 private function set_message() {
391 387 $this->message = $this->settings['email_message'];
392 388
393 389 if ( ! $this->is_plain_text ) {
394 - // The decode is to support [default-html] shortcodes.
395 - $this->message = html_entity_decode( $this->message );
390 + $this->message = html_entity_decode( $this->message ); // The decode is to support [default-html] shortcodes.
396 391 }
397 392
398 - $this->message = FrmFieldsHelper::basic_replace_shortcodes( $this->message, $this->form, $this->entry );
393 + $this->message = FrmFieldsHelper::basic_replace_shortcodes( $this->message, $this->form, $this->entry );
394 +
399 395 $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(
396 + $pass_entry = clone $this->entry; // make a copy to prevent changes by reference
397 + $mail_body = FrmEntriesHelper::replace_default_message(
404 398 $prev_mail_body,
405 399 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'],
400 + 'id' => $this->entry->id,
401 + 'entry' => $pass_entry,
402 + 'plain_text' => $this->is_plain_text,
403 + 'user_info' => $this->include_user_info,
411 404 )
412 405 );
413 406
414 407 // Add the user info if it isn't already included
415 408 if ( $this->include_user_info && $prev_mail_body === $mail_body ) {
416 - $data = $this->entry->description;
409 + $data = $this->entry->description;
417 410 $mail_body .= "\r\n\r\n" . __( 'User Information', 'formidable' ) . "\r\n";
418 411 $this->maybe_add_ip( $mail_body );
419 412 $mail_body .= __( 'User-Agent (Browser/OS)', 'formidable' ) . ': ' . FrmEntriesHelper::get_browser( $data['browser'] ) . "\r\n";
420 413 $mail_body .= __( 'Referrer', 'formidable' ) . ': ' . $data['referrer'] . "\r\n";
@@ -421,11 +414,12 @@
421 414 }
422 415
423 416 $this->message = $mail_body;
424 417
418 + $this->message = do_shortcode( $this->message );
419 +
425 420 if ( $this->is_plain_text ) {
426 421 $this->message = wp_specialchars_decode( strip_tags( $this->message ), ENT_QUOTES );
427 - $this->message = str_replace( ' ', '', $this->message );
428 422 } else {
429 423 $this->add_autop();
430 424 }
431 425
@@ -438,10 +432,9 @@
438 432 * @return void
439 433 */
440 434 private function add_autop() {
441 435 $message = $this->message;
442 - preg_match( '/<body[^>]*>([\s\S]*?)<\/body>/', $message, $match );
443 -
436 + $result = preg_match( '/<body[^>]*>([\s\S]*?)<\/body>/', $message, $match );
444 437 if ( ! empty( $match[1] ) ) {
445 438 $this->message = str_replace( $match[1], trim( wpautop( $match[1] ) ), $message );
446 439 } else {
447 440 $this->message = trim( wpautop( $message ) );
@@ -518,10 +511,11 @@
518 511 */
519 512 private function has_recipients() {
520 513 if ( empty( $this->to ) && empty( $this->cc ) && empty( $this->bcc ) ) {
521 514 return false;
515 + } else {
516 + return true;
522 517 }
523 - return true;
524 518 }
525 519
526 520 /**
527 521 * Send an email
@@ -534,9 +528,8 @@
534 528 $this->remove_buddypress_filters();
535 529 $this->add_mandrill_filter();
536 530
537 531 $sent = false;
538 -
539 532 if ( count( $this->to ) > 1 && $this->is_single_recipient ) {
540 533 foreach ( $this->to as $recipient ) {
541 534 $sent = $this->send_single( $recipient );
542 535 }
@@ -575,9 +568,8 @@
575 568 if ( ! $sent ) {
576 569 if ( is_array( $header ) ) {
577 570 $header = implode( "\r\n", $header );
578 571 }
579 -
580 572 $recipient = implode( ',', (array) $recipient );
581 573 $sent = mail( $recipient, $subject, $this->message, $header );
582 574 }
583 575
@@ -615,9 +607,9 @@
615 607 * Get the userID field ID and key for email settings
616 608 *
617 609 * @since 2.03.04
618 610 *
619 - * @param int $form_id
611 + * @param $form_id
620 612 *
621 613 * @return array
622 614 */
623 615 private function get_user_id_args( $form_id ) {
@@ -626,9 +618,8 @@
626 618 'field_key' => '',
627 619 );
628 620
629 621 $user_id_args['field_id'] = FrmEmailHelper::get_user_id_field_for_form( $form_id );
630 -
631 622 if ( $user_id_args['field_id'] ) {
632 623 $user_id_args['field_key'] = FrmField::get_key_by_id( $user_id_args['field_id'] );
633 624 }
634 625
@@ -640,9 +631,9 @@
640 631 *
641 632 * @since 2.03.04
642 633 *
643 634 * @param string $value
644 - * @param array $user_id_args
635 + * @param array $user_id_args
645 636 *
646 637 * @return string
647 638 */
648 639 private function prepare_email_setting( $value, $user_id_args ) {
@@ -672,9 +663,8 @@
672 663 * @return array|string $emails
673 664 */
674 665 private function explode_emails( $emails ) {
675 666 $emails = ( ! empty( $emails ) ? preg_split( '/(,|;)/', $emails ) : '' );
676 -
677 667 if ( is_array( $emails ) ) {
678 668 $emails = array_map( 'trim', $emails );
679 669 } else {
680 670 $emails = trim( $emails );
@@ -700,24 +690,24 @@
700 690
701 691 if ( is_email( $val ) ) {
702 692 // If a plain email is used, no formatting is needed
703 693 continue;
704 - }
694 + } else {
695 + $parts = explode( ' ', $val );
696 + $email = end( $parts );
705 697
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;
698 + if ( is_email( $email ) ) {
699 + // If user enters a name and email
700 + $name = trim( str_replace( $email, '', $val ) );
701 + } else {
702 + // If user enters a name without an email
703 + unset( $recipients[ $key ] );
704 + continue;
705 + }
716 706 }
717 707
718 708 $recipients[ $key ] = $this->format_from_email( $name, $email );
719 - }//end foreach
709 + }
720 710
721 711 return $recipients;
722 712 }
723 713
@@ -743,9 +733,8 @@
743 733 if ( strpos( $from_email, '@yahoo.com' ) ) {
744 734
745 735 // Get the site domain and get rid of www.
746 736 $sitename = strtolower( FrmAppHelper::get_server_value( 'SERVER_NAME' ) );
747 -
748 737 if ( substr( $sitename, 0, 4 ) === 'www.' ) {
749 738 $sitename = substr( $sitename, 4 );
750 739 }
751 740
@@ -768,9 +757,9 @@
768 757 $reply_to = trim( $reply_to );
769 758
770 759 if ( ! is_email( $reply_to ) ) {
771 760 list( $name, $email ) = $this->get_name_and_email_for_sender( $reply_to );
772 - $reply_to = $this->format_from_email( $name, $email );
761 + $reply_to = $this->format_from_email( $name, $email );
773 762 }
774 763
775 764 return $reply_to;
776 765 }
@@ -785,9 +774,8 @@
785 774 * @return string
786 775 */
787 776 private function get_email_from_name( $name ) {
788 777 $email = trim( trim( $name, '>' ), '<' );
789 -
790 778 if ( strpos( $email, '<' ) !== false ) {
791 779 $parts = explode( '<', $email );
792 780 $email = trim( $parts[1], '>' );
793 781 }
@@ -823,10 +811,8 @@
823 811 * @since 3.0.06
824 812 *
825 813 * @param string $name
826 814 * @param string $email
827 - *
828 - * @return string
829 815 */
830 816 private function format_from_email( $name, $email ) {
831 817 if ( '' !== $name ) {
832 818 $email = $name . ' <' . $email . '>';
@@ -869,10 +855,10 @@
869 855 );
870 856
871 857 // Remove phone number from to addresses
872 858 unset( $this->to[ $key ] );
873 - }//end if
874 - }//end foreach
859 + }
860 + }
875 861 }
876 862
877 863 /**
878 864 * Package an array of FrmEmail properties
@@ -891,12 +877,10 @@
891 877 'subject' => $this->subject,
892 878 'message' => $this->message,
893 879 'attachments' => $this->attachments,
894 880 'plain_text' => $this->is_plain_text,
895 - 'email_key' => $this->email_key,
896 881 'form' => $this->form,
897 882 'entry' => $this->entry,
898 - 'email_style' => $this->settings['email_style'],
899 883 );
900 884 }
901 885
902 886 /**