PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.4
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.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 +53 -127 6.255.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,13 +228,12 @@
236 228 *
237 229 * @since 2.03.04
238 230 *
239 231 * @param array $user_id_args
240 - * @return void
241 232 */
242 233 private function set_from( $user_id_args ) {
243 234 if ( empty( $this->settings['from'] ) ) {
244 - $from = FrmEmailHelper::get_default_from_email();
235 + $from = get_option( 'admin_email' );
245 236 } else {
246 237 $from = $this->prepare_email_setting( $this->settings['from'], $user_id_args );
247 238 }
248 239
@@ -254,10 +245,8 @@
254 245 *
255 246 * @since 2.03.04
256 247 *
257 248 * @param array $user_id_args
258 - *
259 - * @return void
260 249 */
261 250 private function set_reply_to( $user_id_args ) {
262 251 $this->reply_to = trim( $this->settings['reply_to'] );
263 252
@@ -276,19 +265,13 @@
276 265 * Set the is_plain_text property
277 266 * This should be set before the message
278 267 *
279 268 * @since 2.03.04
280 - *
281 - * @return void
282 269 */
283 270 private function set_is_plain_text() {
284 - if ( empty( $this->settings['email_style'] ) ) {
285 - // If `email_style` isn't set, use the `plain_text` checkbox.
286 - $this->is_plain_text = ! empty( $this->settings['plain_text'] );
287 - return;
271 + if ( $this->settings['plain_text'] ) {
272 + $this->is_plain_text = true;
288 273 }
289 -
290 - $this->is_plain_text = 'plain' === $this->settings['email_style'];
291 274 }
292 275
293 276 /**
294 277 * Set the include_user_info property
@@ -294,10 +277,8 @@
294 277 * Set the include_user_info property
295 278 * This should be set before the message
296 279 *
297 280 * @since 2.03.04
298 - *
299 - * @return void
300 281 */
301 282 private function set_include_user_info() {
302 283 if ( isset( $this->settings['inc_user_info'] ) ) {
303 284 $this->include_user_info = $this->settings['inc_user_info'];
@@ -308,11 +289,9 @@
308 289 * Set the is_single_recipient property
309 290 *
310 291 * @since 2.03.04
311 292 *
312 - * @param object $action
313 - *
314 - * @return void
293 + * @param $action
315 294 */
316 295 private function set_is_single_recipient( $action ) {
317 296 $args = array(
318 297 'form' => $this->form,
@@ -331,10 +310,8 @@
331 310 /**
332 311 * Set the charset
333 312 *
334 313 * @since 2.03.04
335 - *
336 - * @return void
337 314 */
338 315 private function set_charset() {
339 316 $this->charset = get_option( 'blog_charset' );
340 317 }
@@ -342,10 +319,8 @@
342 319 /**
343 320 * Set the content type
344 321 *
345 322 * @since 2.03.04
346 - *
347 - * @return void
348 323 */
349 324 private function set_content_type() {
350 325 if ( $this->is_plain_text ) {
351 326 $this->content_type = 'text/plain';
@@ -355,10 +330,8 @@
355 330 /**
356 331 * Set the subject
357 332 *
358 333 * @since 2.03.04
359 - *
360 - * @return void
361 334 */
362 335 private function set_subject() {
363 336 if ( empty( $this->settings['email_subject'] ) ) {
364 337 /* translators: %1$s: Form name, %2$s: Site name */
@@ -366,9 +339,8 @@
366 339 } else {
367 340 $this->subject = $this->settings['email_subject'];
368 341 }
369 342
370 - // This also replaces [sitename] shortcode in default.
371 343 $this->subject = FrmFieldsHelper::basic_replace_shortcodes( $this->subject, $this->form, $this->entry );
372 344
373 345 $args = array(
374 346 'form' => $this->form,
@@ -375,8 +347,9 @@
375 347 'entry' => $this->entry,
376 348 'email_key' => $this->email_key,
377 349 );
378 350 $this->subject = apply_filters( 'frm_email_subject', $this->subject, $args );
351 +
379 352 $this->subject = wp_specialchars_decode( strip_tags( stripslashes( $this->subject ) ), ENT_QUOTES );
380 353 }
381 354
382 355 /**
@@ -382,38 +355,27 @@
382 355 /**
383 356 * Set the email message
384 357 *
385 358 * @since 2.03.04
386 - *
387 - * @return void
388 359 */
389 360 private function set_message() {
390 - $this->message = $this->settings['email_message'];
361 + $this->message = FrmFieldsHelper::basic_replace_shortcodes( $this->settings['email_message'], $this->form, $this->entry );
391 362
392 - if ( ! $this->is_plain_text ) {
393 - // The decode is to support [default-html] shortcodes.
394 - $this->message = html_entity_decode( $this->message );
395 - }
396 -
397 - $this->message = FrmFieldsHelper::basic_replace_shortcodes( $this->message, $this->form, $this->entry );
398 363 $prev_mail_body = $this->message;
399 -
400 - // Make a copy to prevent changes by reference.
401 - $pass_entry = clone $this->entry;
402 - $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(
403 366 $prev_mail_body,
404 367 array(
405 - 'id' => $this->entry->id,
406 - 'entry' => $pass_entry,
407 - 'plain_text' => $this->is_plain_text,
408 - 'user_info' => $this->include_user_info,
409 - '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,
410 372 )
411 373 );
412 374
413 375 // Add the user info if it isn't already included
414 376 if ( $this->include_user_info && $prev_mail_body === $mail_body ) {
415 - $data = $this->entry->description;
377 + $data = $this->entry->description;
416 378 $mail_body .= "\r\n\r\n" . __( 'User Information', 'formidable' ) . "\r\n";
417 379 $this->maybe_add_ip( $mail_body );
418 380 $mail_body .= __( 'User-Agent (Browser/OS)', 'formidable' ) . ': ' . FrmEntriesHelper::get_browser( $data['browser'] ) . "\r\n";
419 381 $mail_body .= __( 'Referrer', 'formidable' ) . ': ' . $data['referrer'] . "\r\n";
@@ -420,38 +382,17 @@
420 382 }
421 383
422 384 $this->message = $mail_body;
423 385
386 + $this->message = do_shortcode( $this->message );
387 +
424 388 if ( $this->is_plain_text ) {
425 389 $this->message = wp_specialchars_decode( strip_tags( $this->message ), ENT_QUOTES );
426 - $this->message = str_replace( ' ', '', $this->message );
427 - } else {
428 - $this->add_autop();
429 390 }
430 391
431 392 $this->message = apply_filters( 'frm_email_message', $this->message, $this->package_atts() );
432 393 }
433 394
434 - /**
435 - * Runs message through autop, extracting the content inside body tag if it has <body>.
436 - *
437 - * @return void
438 - */
439 - private function add_autop() {
440 - $message = $this->message;
441 - $result = preg_match( '/<body[^>]*>([\s\S]*?)<\/body>/', $message, $match );
442 - if ( ! empty( $match[1] ) ) {
443 - $this->message = str_replace( $match[1], trim( wpautop( $match[1] ) ), $message );
444 - } else {
445 - $this->message = trim( wpautop( $message ) );
446 - }
447 - }
448 -
449 - /**
450 - * @param string $mail_body
451 - *
452 - * @return void
453 - */
454 395 private function maybe_add_ip( &$mail_body ) {
455 396 if ( ! empty( $this->entry->ip ) ) {
456 397 $mail_body .= __( 'IP Address', 'formidable' ) . ': ' . $this->entry->ip . "\r\n";
457 398 }
@@ -516,10 +457,11 @@
516 457 */
517 458 private function has_recipients() {
518 459 if ( empty( $this->to ) && empty( $this->cc ) && empty( $this->bcc ) ) {
519 460 return false;
461 + } else {
462 + return true;
520 463 }
521 - return true;
522 464 }
523 465
524 466 /**
525 467 * Send an email
@@ -611,9 +553,9 @@
611 553 * Get the userID field ID and key for email settings
612 554 *
613 555 * @since 2.03.04
614 556 *
615 - * @param int $form_id
557 + * @param $form_id
616 558 *
617 559 * @return array
618 560 */
619 561 private function get_user_id_args( $form_id ) {
@@ -635,9 +577,9 @@
635 577 *
636 578 * @since 2.03.04
637 579 *
638 580 * @param string $value
639 - * @param array $user_id_args
581 + * @param array $user_id_args
640 582 *
641 583 * @return string
642 584 */
643 585 private function prepare_email_setting( $value, $user_id_args ) {
@@ -694,24 +636,24 @@
694 636
695 637 if ( is_email( $val ) ) {
696 638 // If a plain email is used, no formatting is needed
697 639 continue;
698 - }
640 + } else {
641 + $parts = explode( ' ', $val );
642 + $email = end( $parts );
699 643
700 - $parts = explode( ' ', $val );
701 - $email = end( $parts );
702 -
703 - if ( is_email( $email ) ) {
704 - // If user enters a name and email
705 - $name = trim( str_replace( $email, '', $val ) );
706 - } else {
707 - // If user enters a name without an email
708 - unset( $recipients[ $key ] );
709 - 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 + }
710 652 }
711 653
712 654 $recipients[ $key ] = $this->format_from_email( $name, $email );
713 - }//end foreach
655 + }
714 656
715 657 return $recipients;
716 658 }
717 659
@@ -761,9 +703,9 @@
761 703 $reply_to = trim( $reply_to );
762 704
763 705 if ( ! is_email( $reply_to ) ) {
764 706 list( $name, $email ) = $this->get_name_and_email_for_sender( $reply_to );
765 - $reply_to = $this->format_from_email( $name, $email );
707 + $reply_to = $this->format_from_email( $name, $email );
766 708 }
767 709
768 710 return $reply_to;
769 711 }
@@ -771,12 +713,8 @@
771 713 /**
772 714 * Get only the email if the name and email have been combined
773 715 *
774 716 * @since 3.0.06
775 - *
776 - * @param string $name
777 - *
778 - * @return string
779 717 */
780 718 private function get_email_from_name( $name ) {
781 719 $email = trim( trim( $name, '>' ), '<' );
782 720 if ( strpos( $email, '<' ) !== false ) {
@@ -812,11 +750,8 @@
812 750 }
813 751
814 752 /**
815 753 * @since 3.0.06
816 - *
817 - * @param string $name
818 - * @param string $email
819 754 */
820 755 private function format_from_email( $name, $email ) {
821 756 if ( '' !== $name ) {
822 757 $email = $name . ' <' . $email . '>';
@@ -829,10 +764,8 @@
829 764 * Remove phone numbers from To addresses
830 765 * Send the phone numbers to the frm_send_to_not_email hook
831 766 *
832 767 * @since 2.03.04
833 - *
834 - * @return void
835 768 */
836 769 private function handle_phone_numbers() {
837 770
838 771 foreach ( $this->to as $key => $recipient ) {
@@ -859,10 +792,10 @@
859 792 );
860 793
861 794 // Remove phone number from to addresses
862 795 unset( $this->to[ $key ] );
863 - }//end if
864 - }//end foreach
796 + }
797 + }
865 798 }
866 799
867 800 /**
868 801 * Package an array of FrmEmail properties
@@ -883,9 +816,8 @@
883 816 'attachments' => $this->attachments,
884 817 'plain_text' => $this->is_plain_text,
885 818 'form' => $this->form,
886 819 'entry' => $this->entry,
887 - 'email_style' => $this->settings['email_style'],
888 820 );
889 821 }
890 822
891 823 /**
@@ -891,10 +823,8 @@
891 823 /**
892 824 * Remove the Buddypress email filters
893 825 *
894 826 * @since 2.03.04
895 - *
896 - * @return void
897 827 */
898 828 private function remove_buddypress_filters() {
899 829 remove_filter( 'wp_mail_from', 'bp_core_email_from_address_filter' );
900 830 remove_filter( 'wp_mail_from_name', 'bp_core_email_from_name_filter' );
@@ -904,10 +834,8 @@
904 834 * Add Mandrill line break filter
905 835 * Remove line breaks in HTML emails to prevent conflicts with Mandrill
906 836 *
907 837 * @since 2.03.04
908 - *
909 - * @return void
910 838 */
911 839 private function add_mandrill_filter() {
912 840 if ( ! $this->is_plain_text ) {
913 841 add_filter( 'mandrill_nl2br', 'FrmEmailHelper::remove_mandrill_br' );
@@ -917,10 +845,8 @@
917 845 /**
918 846 * Remove Mandrill line break filter
919 847 *
920 848 * @since 2.03.04
921 - *
922 - * @return void
923 849 */
924 850 private function remove_mandrill_filter() {
925 851 remove_filter( 'mandrill_nl2br', 'FrmEmailHelper::remove_mandrill_br' );
926 852 }