PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.1
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 +53 -138 6.265.1 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,12 @@
236 228 *
237 229 * @since 2.03.04
238 230 *
239 231 * @param array $user_id_args
240 - *
241 - * @return void
242 232 */
243 233 private function set_from( $user_id_args ) {
244 234 if ( empty( $this->settings['from'] ) ) {
245 - $from = FrmEmailHelper::get_default_from_email();
235 + $from = get_option( 'admin_email' );
246 236 } else {
247 237 $from = $this->prepare_email_setting( $this->settings['from'], $user_id_args );
248 238 }
249 239
@@ -255,10 +245,8 @@
255 245 *
256 246 * @since 2.03.04
257 247 *
258 248 * @param array $user_id_args
259 - *
260 - * @return void
261 249 */
262 250 private function set_reply_to( $user_id_args ) {
263 251 $this->reply_to = trim( $this->settings['reply_to'] );
264 252
@@ -277,19 +265,13 @@
277 265 * Set the is_plain_text property
278 266 * This should be set before the message
279 267 *
280 268 * @since 2.03.04
281 - *
282 - * @return void
283 269 */
284 270 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;
271 + if ( $this->settings['plain_text'] ) {
272 + $this->is_plain_text = true;
289 273 }
290 -
291 - $this->is_plain_text = 'plain' === $this->settings['email_style'];
292 274 }
293 275
294 276 /**
295 277 * Set the include_user_info property
@@ -295,10 +277,8 @@
295 277 * Set the include_user_info property
296 278 * This should be set before the message
297 279 *
298 280 * @since 2.03.04
299 - *
300 - * @return void
301 281 */
302 282 private function set_include_user_info() {
303 283 if ( isset( $this->settings['inc_user_info'] ) ) {
304 284 $this->include_user_info = $this->settings['inc_user_info'];
@@ -309,11 +289,9 @@
309 289 * Set the is_single_recipient property
310 290 *
311 291 * @since 2.03.04
312 292 *
313 - * @param object $action
314 - *
315 - * @return void
293 + * @param $action
316 294 */
317 295 private function set_is_single_recipient( $action ) {
318 296 $args = array(
319 297 'form' => $this->form,
@@ -332,10 +310,8 @@
332 310 /**
333 311 * Set the charset
334 312 *
335 313 * @since 2.03.04
336 - *
337 - * @return void
338 314 */
339 315 private function set_charset() {
340 316 $this->charset = get_option( 'blog_charset' );
341 317 }
@@ -343,10 +319,8 @@
343 319 /**
344 320 * Set the content type
345 321 *
346 322 * @since 2.03.04
347 - *
348 - * @return void
349 323 */
350 324 private function set_content_type() {
351 325 if ( $this->is_plain_text ) {
352 326 $this->content_type = 'text/plain';
@@ -356,10 +330,8 @@
356 330 /**
357 331 * Set the subject
358 332 *
359 333 * @since 2.03.04
360 - *
361 - * @return void
362 334 */
363 335 private function set_subject() {
364 336 if ( empty( $this->settings['email_subject'] ) ) {
365 337 /* translators: %1$s: Form name, %2$s: Site name */
@@ -367,9 +339,8 @@
367 339 } else {
368 340 $this->subject = $this->settings['email_subject'];
369 341 }
370 342
371 - // This also replaces [sitename] shortcode in default.
372 343 $this->subject = FrmFieldsHelper::basic_replace_shortcodes( $this->subject, $this->form, $this->entry );
373 344
374 345 $args = array(
375 346 'form' => $this->form,
@@ -376,8 +347,9 @@
376 347 'entry' => $this->entry,
377 348 'email_key' => $this->email_key,
378 349 );
379 350 $this->subject = apply_filters( 'frm_email_subject', $this->subject, $args );
351 +
380 352 $this->subject = wp_specialchars_decode( strip_tags( stripslashes( $this->subject ) ), ENT_QUOTES );
381 353 }
382 354
383 355 /**
@@ -383,38 +355,27 @@
383 355 /**
384 356 * Set the email message
385 357 *
386 358 * @since 2.03.04
387 - *
388 - * @return void
389 359 */
390 360 private function set_message() {
391 - $this->message = $this->settings['email_message'];
361 + $this->message = FrmFieldsHelper::basic_replace_shortcodes( $this->settings['email_message'], $this->form, $this->entry );
392 362
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 363 $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(
364 + $pass_entry = clone $this->entry; // make a copy to prevent changes by reference
365 + $mail_body = FrmEntriesHelper::replace_default_message(
404 366 $prev_mail_body,
405 367 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'],
368 + 'id' => $this->entry->id,
369 + 'entry' => $pass_entry,
370 + 'plain_text' => $this->is_plain_text,
371 + 'user_info' => $this->include_user_info,
411 372 )
412 373 );
413 374
414 375 // Add the user info if it isn't already included
415 376 if ( $this->include_user_info && $prev_mail_body === $mail_body ) {
416 - $data = $this->entry->description;
377 + $data = $this->entry->description;
417 378 $mail_body .= "\r\n\r\n" . __( 'User Information', 'formidable' ) . "\r\n";
418 379 $this->maybe_add_ip( $mail_body );
419 380 $mail_body .= __( 'User-Agent (Browser/OS)', 'formidable' ) . ': ' . FrmEntriesHelper::get_browser( $data['browser'] ) . "\r\n";
420 381 $mail_body .= __( 'Referrer', 'formidable' ) . ': ' . $data['referrer'] . "\r\n";
@@ -421,39 +382,17 @@
421 382 }
422 383
423 384 $this->message = $mail_body;
424 385
386 + $this->message = do_shortcode( $this->message );
387 +
425 388 if ( $this->is_plain_text ) {
426 389 $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 390 }
431 391
432 392 $this->message = apply_filters( 'frm_email_message', $this->message, $this->package_atts() );
433 393 }
434 394
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 395 private function maybe_add_ip( &$mail_body ) {
457 396 if ( ! empty( $this->entry->ip ) ) {
458 397 $mail_body .= __( 'IP Address', 'formidable' ) . ': ' . $this->entry->ip . "\r\n";
459 398 }
@@ -518,10 +457,11 @@
518 457 */
519 458 private function has_recipients() {
520 459 if ( empty( $this->to ) && empty( $this->cc ) && empty( $this->bcc ) ) {
521 460 return false;
461 + } else {
462 + return true;
522 463 }
523 - return true;
524 464 }
525 465
526 466 /**
527 467 * Send an email
@@ -534,9 +474,8 @@
534 474 $this->remove_buddypress_filters();
535 475 $this->add_mandrill_filter();
536 476
537 477 $sent = false;
538 -
539 478 if ( count( $this->to ) > 1 && $this->is_single_recipient ) {
540 479 foreach ( $this->to as $recipient ) {
541 480 $sent = $this->send_single( $recipient );
542 481 }
@@ -575,9 +514,8 @@
575 514 if ( ! $sent ) {
576 515 if ( is_array( $header ) ) {
577 516 $header = implode( "\r\n", $header );
578 517 }
579 -
580 518 $recipient = implode( ',', (array) $recipient );
581 519 $sent = mail( $recipient, $subject, $this->message, $header );
582 520 }
583 521
@@ -615,9 +553,9 @@
615 553 * Get the userID field ID and key for email settings
616 554 *
617 555 * @since 2.03.04
618 556 *
619 - * @param int $form_id
557 + * @param $form_id
620 558 *
621 559 * @return array
622 560 */
623 561 private function get_user_id_args( $form_id ) {
@@ -626,9 +564,8 @@
626 564 'field_key' => '',
627 565 );
628 566
629 567 $user_id_args['field_id'] = FrmEmailHelper::get_user_id_field_for_form( $form_id );
630 -
631 568 if ( $user_id_args['field_id'] ) {
632 569 $user_id_args['field_key'] = FrmField::get_key_by_id( $user_id_args['field_id'] );
633 570 }
634 571
@@ -640,9 +577,9 @@
640 577 *
641 578 * @since 2.03.04
642 579 *
643 580 * @param string $value
644 - * @param array $user_id_args
581 + * @param array $user_id_args
645 582 *
646 583 * @return string
647 584 */
648 585 private function prepare_email_setting( $value, $user_id_args ) {
@@ -672,9 +609,8 @@
672 609 * @return array|string $emails
673 610 */
674 611 private function explode_emails( $emails ) {
675 612 $emails = ( ! empty( $emails ) ? preg_split( '/(,|;)/', $emails ) : '' );
676 -
677 613 if ( is_array( $emails ) ) {
678 614 $emails = array_map( 'trim', $emails );
679 615 } else {
680 616 $emails = trim( $emails );
@@ -700,24 +636,24 @@
700 636
701 637 if ( is_email( $val ) ) {
702 638 // If a plain email is used, no formatting is needed
703 639 continue;
704 - }
640 + } else {
641 + $parts = explode( ' ', $val );
642 + $email = end( $parts );
705 643
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;
644 + if ( is_email( $email ) ) {
645 + // If user enters a name and email
646 + $name = trim( str_replace( $email, '', $val ) );
647 + } else {
648 + // If user enters a name without an email
649 + unset( $recipients[ $key ] );
650 + continue;
651 + }
716 652 }
717 653
718 654 $recipients[ $key ] = $this->format_from_email( $name, $email );
719 - }//end foreach
655 + }
720 656
721 657 return $recipients;
722 658 }
723 659
@@ -743,9 +679,8 @@
743 679 if ( strpos( $from_email, '@yahoo.com' ) ) {
744 680
745 681 // Get the site domain and get rid of www.
746 682 $sitename = strtolower( FrmAppHelper::get_server_value( 'SERVER_NAME' ) );
747 -
748 683 if ( substr( $sitename, 0, 4 ) === 'www.' ) {
749 684 $sitename = substr( $sitename, 4 );
750 685 }
751 686
@@ -768,9 +703,9 @@
768 703 $reply_to = trim( $reply_to );
769 704
770 705 if ( ! is_email( $reply_to ) ) {
771 706 list( $name, $email ) = $this->get_name_and_email_for_sender( $reply_to );
772 - $reply_to = $this->format_from_email( $name, $email );
707 + $reply_to = $this->format_from_email( $name, $email );
773 708 }
774 709
775 710 return $reply_to;
776 711 }
@@ -778,16 +713,11 @@
778 713 /**
779 714 * Get only the email if the name and email have been combined
780 715 *
781 716 * @since 3.0.06
782 - *
783 - * @param string $name
784 - *
785 - * @return string
786 717 */
787 718 private function get_email_from_name( $name ) {
788 719 $email = trim( trim( $name, '>' ), '<' );
789 -
790 720 if ( strpos( $email, '<' ) !== false ) {
791 721 $parts = explode( '<', $email );
792 722 $email = trim( $parts[1], '>' );
793 723 }
@@ -820,13 +750,8 @@
820 750 }
821 751
822 752 /**
823 753 * @since 3.0.06
824 - *
825 - * @param string $name
826 - * @param string $email
827 - *
828 - * @return string
829 754 */
830 755 private function format_from_email( $name, $email ) {
831 756 if ( '' !== $name ) {
832 757 $email = $name . ' <' . $email . '>';
@@ -839,10 +764,8 @@
839 764 * Remove phone numbers from To addresses
840 765 * Send the phone numbers to the frm_send_to_not_email hook
841 766 *
842 767 * @since 2.03.04
843 - *
844 - * @return void
845 768 */
846 769 private function handle_phone_numbers() {
847 770
848 771 foreach ( $this->to as $key => $recipient ) {
@@ -869,10 +792,10 @@
869 792 );
870 793
871 794 // Remove phone number from to addresses
872 795 unset( $this->to[ $key ] );
873 - }//end if
874 - }//end foreach
796 + }
797 + }
875 798 }
876 799
877 800 /**
878 801 * Package an array of FrmEmail properties
@@ -891,12 +814,10 @@
891 814 'subject' => $this->subject,
892 815 'message' => $this->message,
893 816 'attachments' => $this->attachments,
894 817 'plain_text' => $this->is_plain_text,
895 - 'email_key' => $this->email_key,
896 818 'form' => $this->form,
897 819 'entry' => $this->entry,
898 - 'email_style' => $this->settings['email_style'],
899 820 );
900 821 }
901 822
902 823 /**
@@ -902,10 +823,8 @@
902 823 /**
903 824 * Remove the Buddypress email filters
904 825 *
905 826 * @since 2.03.04
906 - *
907 - * @return void
908 827 */
909 828 private function remove_buddypress_filters() {
910 829 remove_filter( 'wp_mail_from', 'bp_core_email_from_address_filter' );
911 830 remove_filter( 'wp_mail_from_name', 'bp_core_email_from_name_filter' );
@@ -915,10 +834,8 @@
915 834 * Add Mandrill line break filter
916 835 * Remove line breaks in HTML emails to prevent conflicts with Mandrill
917 836 *
918 837 * @since 2.03.04
919 - *
920 - * @return void
921 838 */
922 839 private function add_mandrill_filter() {
923 840 if ( ! $this->is_plain_text ) {
924 841 add_filter( 'mandrill_nl2br', 'FrmEmailHelper::remove_mandrill_br' );
@@ -928,10 +845,8 @@
928 845 /**
929 846 * Remove Mandrill line break filter
930 847 *
931 848 * @since 2.03.04
932 - *
933 - * @return void
934 849 */
935 850 private function remove_mandrill_filter() {
936 851 remove_filter( 'mandrill_nl2br', 'FrmEmailHelper::remove_mandrill_br' );
937 852 }