PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.5.4
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.5.4
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 -116 6.265.5.4 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,11 +391,12 @@
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 400 $this->add_autop();
430 401 }
431 402
@@ -433,15 +404,12 @@
433 404 }
434 405
435 406 /**
436 407 * Runs message through autop, extracting the content inside body tag if it has <body>.
437 - *
438 - * @return void
439 408 */
440 409 private function add_autop() {
441 410 $message = $this->message;
442 - preg_match( '/<body[^>]*>([\s\S]*?)<\/body>/', $message, $match );
443 -
411 + $result = preg_match( '/<body[^>]*>([\s\S]*?)<\/body>/', $message, $match );
444 412 if ( ! empty( $match[1] ) ) {
445 413 $this->message = str_replace( $match[1], trim( wpautop( $match[1] ) ), $message );
446 414 } else {
447 415 $this->message = trim( wpautop( $message ) );
@@ -447,13 +415,8 @@
447 415 $this->message = trim( wpautop( $message ) );
448 416 }
449 417 }
450 418
451 - /**
452 - * @param string $mail_body
453 - *
454 - * @return void
455 - */
456 419 private function maybe_add_ip( &$mail_body ) {
457 420 if ( ! empty( $this->entry->ip ) ) {
458 421 $mail_body .= __( 'IP Address', 'formidable' ) . ': ' . $this->entry->ip . "\r\n";
459 422 }
@@ -518,10 +481,11 @@
518 481 */
519 482 private function has_recipients() {
520 483 if ( empty( $this->to ) && empty( $this->cc ) && empty( $this->bcc ) ) {
521 484 return false;
485 + } else {
486 + return true;
522 487 }
523 - return true;
524 488 }
525 489
526 490 /**
527 491 * Send an email
@@ -534,9 +498,8 @@
534 498 $this->remove_buddypress_filters();
535 499 $this->add_mandrill_filter();
536 500
537 501 $sent = false;
538 -
539 502 if ( count( $this->to ) > 1 && $this->is_single_recipient ) {
540 503 foreach ( $this->to as $recipient ) {
541 504 $sent = $this->send_single( $recipient );
542 505 }
@@ -575,9 +538,8 @@
575 538 if ( ! $sent ) {
576 539 if ( is_array( $header ) ) {
577 540 $header = implode( "\r\n", $header );
578 541 }
579 -
580 542 $recipient = implode( ',', (array) $recipient );
581 543 $sent = mail( $recipient, $subject, $this->message, $header );
582 544 }
583 545
@@ -615,9 +577,9 @@
615 577 * Get the userID field ID and key for email settings
616 578 *
617 579 * @since 2.03.04
618 580 *
619 - * @param int $form_id
581 + * @param $form_id
620 582 *
621 583 * @return array
622 584 */
623 585 private function get_user_id_args( $form_id ) {
@@ -626,9 +588,8 @@
626 588 'field_key' => '',
627 589 );
628 590
629 591 $user_id_args['field_id'] = FrmEmailHelper::get_user_id_field_for_form( $form_id );
630 -
631 592 if ( $user_id_args['field_id'] ) {
632 593 $user_id_args['field_key'] = FrmField::get_key_by_id( $user_id_args['field_id'] );
633 594 }
634 595
@@ -640,9 +601,9 @@
640 601 *
641 602 * @since 2.03.04
642 603 *
643 604 * @param string $value
644 - * @param array $user_id_args
605 + * @param array $user_id_args
645 606 *
646 607 * @return string
647 608 */
648 609 private function prepare_email_setting( $value, $user_id_args ) {
@@ -672,9 +633,8 @@
672 633 * @return array|string $emails
673 634 */
674 635 private function explode_emails( $emails ) {
675 636 $emails = ( ! empty( $emails ) ? preg_split( '/(,|;)/', $emails ) : '' );
676 -
677 637 if ( is_array( $emails ) ) {
678 638 $emails = array_map( 'trim', $emails );
679 639 } else {
680 640 $emails = trim( $emails );
@@ -700,24 +660,24 @@
700 660
701 661 if ( is_email( $val ) ) {
702 662 // If a plain email is used, no formatting is needed
703 663 continue;
704 - }
664 + } else {
665 + $parts = explode( ' ', $val );
666 + $email = end( $parts );
705 667
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;
668 + if ( is_email( $email ) ) {
669 + // If user enters a name and email
670 + $name = trim( str_replace( $email, '', $val ) );
671 + } else {
672 + // If user enters a name without an email
673 + unset( $recipients[ $key ] );
674 + continue;
675 + }
716 676 }
717 677
718 678 $recipients[ $key ] = $this->format_from_email( $name, $email );
719 - }//end foreach
679 + }
720 680
721 681 return $recipients;
722 682 }
723 683
@@ -743,9 +703,8 @@
743 703 if ( strpos( $from_email, '@yahoo.com' ) ) {
744 704
745 705 // Get the site domain and get rid of www.
746 706 $sitename = strtolower( FrmAppHelper::get_server_value( 'SERVER_NAME' ) );
747 -
748 707 if ( substr( $sitename, 0, 4 ) === 'www.' ) {
749 708 $sitename = substr( $sitename, 4 );
750 709 }
751 710
@@ -768,9 +727,9 @@
768 727 $reply_to = trim( $reply_to );
769 728
770 729 if ( ! is_email( $reply_to ) ) {
771 730 list( $name, $email ) = $this->get_name_and_email_for_sender( $reply_to );
772 - $reply_to = $this->format_from_email( $name, $email );
731 + $reply_to = $this->format_from_email( $name, $email );
773 732 }
774 733
775 734 return $reply_to;
776 735 }
@@ -778,16 +737,11 @@
778 737 /**
779 738 * Get only the email if the name and email have been combined
780 739 *
781 740 * @since 3.0.06
782 - *
783 - * @param string $name
784 - *
785 - * @return string
786 741 */
787 742 private function get_email_from_name( $name ) {
788 743 $email = trim( trim( $name, '>' ), '<' );
789 -
790 744 if ( strpos( $email, '<' ) !== false ) {
791 745 $parts = explode( '<', $email );
792 746 $email = trim( $parts[1], '>' );
793 747 }
@@ -820,13 +774,8 @@
820 774 }
821 775
822 776 /**
823 777 * @since 3.0.06
824 - *
825 - * @param string $name
826 - * @param string $email
827 - *
828 - * @return string
829 778 */
830 779 private function format_from_email( $name, $email ) {
831 780 if ( '' !== $name ) {
832 781 $email = $name . ' <' . $email . '>';
@@ -839,10 +788,8 @@
839 788 * Remove phone numbers from To addresses
840 789 * Send the phone numbers to the frm_send_to_not_email hook
841 790 *
842 791 * @since 2.03.04
843 - *
844 - * @return void
845 792 */
846 793 private function handle_phone_numbers() {
847 794
848 795 foreach ( $this->to as $key => $recipient ) {
@@ -869,10 +816,10 @@
869 816 );
870 817
871 818 // Remove phone number from to addresses
872 819 unset( $this->to[ $key ] );
873 - }//end if
874 - }//end foreach
820 + }
821 + }
875 822 }
876 823
877 824 /**
878 825 * Package an array of FrmEmail properties
@@ -891,12 +838,10 @@
891 838 'subject' => $this->subject,
892 839 'message' => $this->message,
893 840 'attachments' => $this->attachments,
894 841 'plain_text' => $this->is_plain_text,
895 - 'email_key' => $this->email_key,
896 842 'form' => $this->form,
897 843 'entry' => $this->entry,
898 - 'email_style' => $this->settings['email_style'],
899 844 );
900 845 }
901 846
902 847 /**
@@ -902,10 +847,8 @@
902 847 /**
903 848 * Remove the Buddypress email filters
904 849 *
905 850 * @since 2.03.04
906 - *
907 - * @return void
908 851 */
909 852 private function remove_buddypress_filters() {
910 853 remove_filter( 'wp_mail_from', 'bp_core_email_from_address_filter' );
911 854 remove_filter( 'wp_mail_from_name', 'bp_core_email_from_name_filter' );
@@ -915,10 +858,8 @@
915 858 * Add Mandrill line break filter
916 859 * Remove line breaks in HTML emails to prevent conflicts with Mandrill
917 860 *
918 861 * @since 2.03.04
919 - *
920 - * @return void
921 862 */
922 863 private function add_mandrill_filter() {
923 864 if ( ! $this->is_plain_text ) {
924 865 add_filter( 'mandrill_nl2br', 'FrmEmailHelper::remove_mandrill_br' );
@@ -928,10 +869,8 @@
928 869 /**
929 870 * Remove Mandrill line break filter
930 871 *
931 872 * @since 2.03.04
932 - *
933 - * @return void
934 873 */
935 874 private function remove_mandrill_filter() {
936 875 remove_filter( 'mandrill_nl2br', 'FrmEmailHelper::remove_mandrill_br' );
937 876 }