PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.5
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.5
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 +52 -134 6.265.5 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,27 @@
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 - $this->message = $this->settings['email_message'];
364 + $this->message = FrmFieldsHelper::basic_replace_shortcodes( $this->settings['email_message'], $this->form, $this->entry );
392 365
393 - if ( ! $this->is_plain_text ) {
394 - // The decode is to support [default-html] shortcodes.
395 - $this->message = html_entity_decode( $this->message );
396 - }
397 -
398 - $this->message = FrmFieldsHelper::basic_replace_shortcodes( $this->message, $this->form, $this->entry );
399 366 $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(
367 + $pass_entry = clone $this->entry; // make a copy to prevent changes by reference
368 + $mail_body = FrmEntriesHelper::replace_default_message(
404 369 $prev_mail_body,
405 370 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'],
371 + 'id' => $this->entry->id,
372 + 'entry' => $pass_entry,
373 + 'plain_text' => $this->is_plain_text,
374 + 'user_info' => $this->include_user_info,
411 375 )
412 376 );
413 377
414 378 // Add the user info if it isn't already included
415 379 if ( $this->include_user_info && $prev_mail_body === $mail_body ) {
416 - $data = $this->entry->description;
380 + $data = $this->entry->description;
417 381 $mail_body .= "\r\n\r\n" . __( 'User Information', 'formidable' ) . "\r\n";
418 382 $this->maybe_add_ip( $mail_body );
419 383 $mail_body .= __( 'User-Agent (Browser/OS)', 'formidable' ) . ': ' . FrmEntriesHelper::get_browser( $data['browser'] ) . "\r\n";
420 384 $mail_body .= __( 'Referrer', 'formidable' ) . ': ' . $data['referrer'] . "\r\n";
@@ -421,39 +385,17 @@
421 385 }
422 386
423 387 $this->message = $mail_body;
424 388
389 + $this->message = do_shortcode( $this->message );
390 +
425 391 if ( $this->is_plain_text ) {
426 392 $this->message = wp_specialchars_decode( strip_tags( $this->message ), ENT_QUOTES );
427 - $this->message = str_replace( ' ', '', $this->message );
428 - } else {
429 - $this->add_autop();
430 393 }
431 394
432 395 $this->message = apply_filters( 'frm_email_message', $this->message, $this->package_atts() );
433 396 }
434 397
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 398 private function maybe_add_ip( &$mail_body ) {
457 399 if ( ! empty( $this->entry->ip ) ) {
458 400 $mail_body .= __( 'IP Address', 'formidable' ) . ': ' . $this->entry->ip . "\r\n";
459 401 }
@@ -518,10 +460,11 @@
518 460 */
519 461 private function has_recipients() {
520 462 if ( empty( $this->to ) && empty( $this->cc ) && empty( $this->bcc ) ) {
521 463 return false;
464 + } else {
465 + return true;
522 466 }
523 - return true;
524 467 }
525 468
526 469 /**
527 470 * Send an email
@@ -534,9 +477,8 @@
534 477 $this->remove_buddypress_filters();
535 478 $this->add_mandrill_filter();
536 479
537 480 $sent = false;
538 -
539 481 if ( count( $this->to ) > 1 && $this->is_single_recipient ) {
540 482 foreach ( $this->to as $recipient ) {
541 483 $sent = $this->send_single( $recipient );
542 484 }
@@ -575,9 +517,8 @@
575 517 if ( ! $sent ) {
576 518 if ( is_array( $header ) ) {
577 519 $header = implode( "\r\n", $header );
578 520 }
579 -
580 521 $recipient = implode( ',', (array) $recipient );
581 522 $sent = mail( $recipient, $subject, $this->message, $header );
582 523 }
583 524
@@ -615,9 +556,9 @@
615 556 * Get the userID field ID and key for email settings
616 557 *
617 558 * @since 2.03.04
618 559 *
619 - * @param int $form_id
560 + * @param $form_id
620 561 *
621 562 * @return array
622 563 */
623 564 private function get_user_id_args( $form_id ) {
@@ -626,9 +567,8 @@
626 567 'field_key' => '',
627 568 );
628 569
629 570 $user_id_args['field_id'] = FrmEmailHelper::get_user_id_field_for_form( $form_id );
630 -
631 571 if ( $user_id_args['field_id'] ) {
632 572 $user_id_args['field_key'] = FrmField::get_key_by_id( $user_id_args['field_id'] );
633 573 }
634 574
@@ -640,9 +580,9 @@
640 580 *
641 581 * @since 2.03.04
642 582 *
643 583 * @param string $value
644 - * @param array $user_id_args
584 + * @param array $user_id_args
645 585 *
646 586 * @return string
647 587 */
648 588 private function prepare_email_setting( $value, $user_id_args ) {
@@ -672,9 +612,8 @@
672 612 * @return array|string $emails
673 613 */
674 614 private function explode_emails( $emails ) {
675 615 $emails = ( ! empty( $emails ) ? preg_split( '/(,|;)/', $emails ) : '' );
676 -
677 616 if ( is_array( $emails ) ) {
678 617 $emails = array_map( 'trim', $emails );
679 618 } else {
680 619 $emails = trim( $emails );
@@ -700,24 +639,24 @@
700 639
701 640 if ( is_email( $val ) ) {
702 641 // If a plain email is used, no formatting is needed
703 642 continue;
704 - }
643 + } else {
644 + $parts = explode( ' ', $val );
645 + $email = end( $parts );
705 646
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;
647 + if ( is_email( $email ) ) {
648 + // If user enters a name and email
649 + $name = trim( str_replace( $email, '', $val ) );
650 + } else {
651 + // If user enters a name without an email
652 + unset( $recipients[ $key ] );
653 + continue;
654 + }
716 655 }
717 656
718 657 $recipients[ $key ] = $this->format_from_email( $name, $email );
719 - }//end foreach
658 + }
720 659
721 660 return $recipients;
722 661 }
723 662
@@ -743,9 +682,8 @@
743 682 if ( strpos( $from_email, '@yahoo.com' ) ) {
744 683
745 684 // Get the site domain and get rid of www.
746 685 $sitename = strtolower( FrmAppHelper::get_server_value( 'SERVER_NAME' ) );
747 -
748 686 if ( substr( $sitename, 0, 4 ) === 'www.' ) {
749 687 $sitename = substr( $sitename, 4 );
750 688 }
751 689
@@ -768,9 +706,9 @@
768 706 $reply_to = trim( $reply_to );
769 707
770 708 if ( ! is_email( $reply_to ) ) {
771 709 list( $name, $email ) = $this->get_name_and_email_for_sender( $reply_to );
772 - $reply_to = $this->format_from_email( $name, $email );
710 + $reply_to = $this->format_from_email( $name, $email );
773 711 }
774 712
775 713 return $reply_to;
776 714 }
@@ -778,16 +716,11 @@
778 716 /**
779 717 * Get only the email if the name and email have been combined
780 718 *
781 719 * @since 3.0.06
782 - *
783 - * @param string $name
784 - *
785 - * @return string
786 720 */
787 721 private function get_email_from_name( $name ) {
788 722 $email = trim( trim( $name, '>' ), '<' );
789 -
790 723 if ( strpos( $email, '<' ) !== false ) {
791 724 $parts = explode( '<', $email );
792 725 $email = trim( $parts[1], '>' );
793 726 }
@@ -820,13 +753,8 @@
820 753 }
821 754
822 755 /**
823 756 * @since 3.0.06
824 - *
825 - * @param string $name
826 - * @param string $email
827 - *
828 - * @return string
829 757 */
830 758 private function format_from_email( $name, $email ) {
831 759 if ( '' !== $name ) {
832 760 $email = $name . ' <' . $email . '>';
@@ -839,10 +767,8 @@
839 767 * Remove phone numbers from To addresses
840 768 * Send the phone numbers to the frm_send_to_not_email hook
841 769 *
842 770 * @since 2.03.04
843 - *
844 - * @return void
845 771 */
846 772 private function handle_phone_numbers() {
847 773
848 774 foreach ( $this->to as $key => $recipient ) {
@@ -869,10 +795,10 @@
869 795 );
870 796
871 797 // Remove phone number from to addresses
872 798 unset( $this->to[ $key ] );
873 - }//end if
874 - }//end foreach
799 + }
800 + }
875 801 }
876 802
877 803 /**
878 804 * Package an array of FrmEmail properties
@@ -891,12 +817,10 @@
891 817 'subject' => $this->subject,
892 818 'message' => $this->message,
893 819 'attachments' => $this->attachments,
894 820 'plain_text' => $this->is_plain_text,
895 - 'email_key' => $this->email_key,
896 821 'form' => $this->form,
897 822 'entry' => $this->entry,
898 - 'email_style' => $this->settings['email_style'],
899 823 );
900 824 }
901 825
902 826 /**
@@ -902,10 +826,8 @@
902 826 /**
903 827 * Remove the Buddypress email filters
904 828 *
905 829 * @since 2.03.04
906 - *
907 - * @return void
908 830 */
909 831 private function remove_buddypress_filters() {
910 832 remove_filter( 'wp_mail_from', 'bp_core_email_from_address_filter' );
911 833 remove_filter( 'wp_mail_from_name', 'bp_core_email_from_name_filter' );
@@ -915,10 +837,8 @@
915 837 * Add Mandrill line break filter
916 838 * Remove line breaks in HTML emails to prevent conflicts with Mandrill
917 839 *
918 840 * @since 2.03.04
919 - *
920 - * @return void
921 841 */
922 842 private function add_mandrill_filter() {
923 843 if ( ! $this->is_plain_text ) {
924 844 add_filter( 'mandrill_nl2br', 'FrmEmailHelper::remove_mandrill_br' );
@@ -928,10 +848,8 @@
928 848 /**
929 849 * Remove Mandrill line break filter
930 850 *
931 851 * @since 2.03.04
932 - *
933 - * @return void
934 852 */
935 853 private function remove_mandrill_filter() {
936 854 remove_filter( 'mandrill_nl2br', 'FrmEmailHelper::remove_mandrill_br' );
937 855 }