| @@ -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 ) { |
| @@ -240,9 +232,9 @@ | ||
| 240 | 232 | * @return void |
| 241 | 233 | */ |
| 242 | 234 | private function set_from( $user_id_args ) { |
| 243 | 235 | if ( empty( $this->settings['from'] ) ) { |
| 244 | - $from = FrmEmailHelper::get_default_from_email(); | |
| 236 | + $from = get_option( 'admin_email' ); | |
| 245 | 237 | } else { |
| 246 | 238 | $from = $this->prepare_email_setting( $this->settings['from'], $user_id_args ); |
| 247 | 239 | } |
| 248 | 240 | |
| @@ -254,10 +246,8 @@ | ||
| 254 | 246 | * |
| 255 | 247 | * @since 2.03.04 |
| 256 | 248 | * |
| 257 | 249 | * @param array $user_id_args |
| 258 | - * | |
| 259 | - * @return void | |
| 260 | 250 | */ |
| 261 | 251 | private function set_reply_to( $user_id_args ) { |
| 262 | 252 | $this->reply_to = trim( $this->settings['reply_to'] ); |
| 263 | 253 | |
| @@ -276,19 +266,13 @@ | ||
| 276 | 266 | * Set the is_plain_text property |
| 277 | 267 | * This should be set before the message |
| 278 | 268 | * |
| 279 | 269 | * @since 2.03.04 |
| 280 | - * | |
| 281 | - * @return void | |
| 282 | 270 | */ |
| 283 | 271 | 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; | |
| 272 | + if ( $this->settings['plain_text'] ) { | |
| 273 | + $this->is_plain_text = true; | |
| 288 | 274 | } |
| 289 | - | |
| 290 | - $this->is_plain_text = 'plain' === $this->settings['email_style']; | |
| 291 | 275 | } |
| 292 | 276 | |
| 293 | 277 | /** |
| 294 | 278 | * Set the include_user_info property |
| @@ -294,10 +278,8 @@ | ||
| 294 | 278 | * Set the include_user_info property |
| 295 | 279 | * This should be set before the message |
| 296 | 280 | * |
| 297 | 281 | * @since 2.03.04 |
| 298 | - * | |
| 299 | - * @return void | |
| 300 | 282 | */ |
| 301 | 283 | private function set_include_user_info() { |
| 302 | 284 | if ( isset( $this->settings['inc_user_info'] ) ) { |
| 303 | 285 | $this->include_user_info = $this->settings['inc_user_info']; |
| @@ -308,11 +290,9 @@ | ||
| 308 | 290 | * Set the is_single_recipient property |
| 309 | 291 | * |
| 310 | 292 | * @since 2.03.04 |
| 311 | 293 | * |
| 312 | - * @param object $action | |
| 313 | - * | |
| 314 | - * @return void | |
| 294 | + * @param $action | |
| 315 | 295 | */ |
| 316 | 296 | private function set_is_single_recipient( $action ) { |
| 317 | 297 | $args = array( |
| 318 | 298 | 'form' => $this->form, |
| @@ -331,10 +311,8 @@ | ||
| 331 | 311 | /** |
| 332 | 312 | * Set the charset |
| 333 | 313 | * |
| 334 | 314 | * @since 2.03.04 |
| 335 | - * | |
| 336 | - * @return void | |
| 337 | 315 | */ |
| 338 | 316 | private function set_charset() { |
| 339 | 317 | $this->charset = get_option( 'blog_charset' ); |
| 340 | 318 | } |
| @@ -342,10 +320,8 @@ | ||
| 342 | 320 | /** |
| 343 | 321 | * Set the content type |
| 344 | 322 | * |
| 345 | 323 | * @since 2.03.04 |
| 346 | - * | |
| 347 | - * @return void | |
| 348 | 324 | */ |
| 349 | 325 | private function set_content_type() { |
| 350 | 326 | if ( $this->is_plain_text ) { |
| 351 | 327 | $this->content_type = 'text/plain'; |
| @@ -382,38 +358,33 @@ | ||
| 382 | 358 | /** |
| 383 | 359 | * Set the email message |
| 384 | 360 | * |
| 385 | 361 | * @since 2.03.04 |
| 386 | - * | |
| 387 | - * @return void | |
| 388 | 362 | */ |
| 389 | 363 | private function set_message() { |
| 390 | 364 | $this->message = $this->settings['email_message']; |
| 391 | 365 | |
| 392 | 366 | if ( ! $this->is_plain_text ) { |
| 393 | - // The decode is to support [default-html] shortcodes. | |
| 394 | - $this->message = html_entity_decode( $this->message ); | |
| 367 | + $this->message = html_entity_decode( $this->message ); // The decode is to support [default-html] shortcodes. | |
| 395 | 368 | } |
| 396 | 369 | |
| 397 | - $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 | + | |
| 398 | 372 | $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( | |
| 373 | + $pass_entry = clone $this->entry; // make a copy to prevent changes by reference | |
| 374 | + $mail_body = FrmEntriesHelper::replace_default_message( | |
| 403 | 375 | $prev_mail_body, |
| 404 | 376 | 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'], | |
| 377 | + 'id' => $this->entry->id, | |
| 378 | + 'entry' => $pass_entry, | |
| 379 | + 'plain_text' => $this->is_plain_text, | |
| 380 | + 'user_info' => $this->include_user_info, | |
| 410 | 381 | ) |
| 411 | 382 | ); |
| 412 | 383 | |
| 413 | 384 | // Add the user info if it isn't already included |
| 414 | 385 | if ( $this->include_user_info && $prev_mail_body === $mail_body ) { |
| 415 | - $data = $this->entry->description; | |
| 386 | + $data = $this->entry->description; | |
| 416 | 387 | $mail_body .= "\r\n\r\n" . __( 'User Information', 'formidable' ) . "\r\n"; |
| 417 | 388 | $this->maybe_add_ip( $mail_body ); |
| 418 | 389 | $mail_body .= __( 'User-Agent (Browser/OS)', 'formidable' ) . ': ' . FrmEntriesHelper::get_browser( $data['browser'] ) . "\r\n"; |
| 419 | 390 | $mail_body .= __( 'Referrer', 'formidable' ) . ': ' . $data['referrer'] . "\r\n"; |
| @@ -420,11 +391,12 @@ | ||
| 420 | 391 | } |
| 421 | 392 | |
| 422 | 393 | $this->message = $mail_body; |
| 423 | 394 | |
| 395 | + $this->message = do_shortcode( $this->message ); | |
| 396 | + | |
| 424 | 397 | if ( $this->is_plain_text ) { |
| 425 | 398 | $this->message = wp_specialchars_decode( strip_tags( $this->message ), ENT_QUOTES ); |
| 426 | - $this->message = str_replace( ' ', '', $this->message ); | |
| 427 | 399 | } else { |
| 428 | 400 | $this->add_autop(); |
| 429 | 401 | } |
| 430 | 402 | |
| @@ -432,10 +404,8 @@ | ||
| 432 | 404 | } |
| 433 | 405 | |
| 434 | 406 | /** |
| 435 | 407 | * Runs message through autop, extracting the content inside body tag if it has <body>. |
| 436 | - * | |
| 437 | - * @return void | |
| 438 | 408 | */ |
| 439 | 409 | private function add_autop() { |
| 440 | 410 | $message = $this->message; |
| 441 | 411 | $result = preg_match( '/<body[^>]*>([\s\S]*?)<\/body>/', $message, $match ); |
| @@ -445,13 +415,8 @@ | ||
| 445 | 415 | $this->message = trim( wpautop( $message ) ); |
| 446 | 416 | } |
| 447 | 417 | } |
| 448 | 418 | |
| 449 | - /** | |
| 450 | - * @param string $mail_body | |
| 451 | - * | |
| 452 | - * @return void | |
| 453 | - */ | |
| 454 | 419 | private function maybe_add_ip( &$mail_body ) { |
| 455 | 420 | if ( ! empty( $this->entry->ip ) ) { |
| 456 | 421 | $mail_body .= __( 'IP Address', 'formidable' ) . ': ' . $this->entry->ip . "\r\n"; |
| 457 | 422 | } |
| @@ -516,10 +481,11 @@ | ||
| 516 | 481 | */ |
| 517 | 482 | private function has_recipients() { |
| 518 | 483 | if ( empty( $this->to ) && empty( $this->cc ) && empty( $this->bcc ) ) { |
| 519 | 484 | return false; |
| 485 | + } else { | |
| 486 | + return true; | |
| 520 | 487 | } |
| 521 | - return true; | |
| 522 | 488 | } |
| 523 | 489 | |
| 524 | 490 | /** |
| 525 | 491 | * Send an email |
| @@ -611,9 +577,9 @@ | ||
| 611 | 577 | * Get the userID field ID and key for email settings |
| 612 | 578 | * |
| 613 | 579 | * @since 2.03.04 |
| 614 | 580 | * |
| 615 | - * @param int $form_id | |
| 581 | + * @param $form_id | |
| 616 | 582 | * |
| 617 | 583 | * @return array |
| 618 | 584 | */ |
| 619 | 585 | private function get_user_id_args( $form_id ) { |
| @@ -635,9 +601,9 @@ | ||
| 635 | 601 | * |
| 636 | 602 | * @since 2.03.04 |
| 637 | 603 | * |
| 638 | 604 | * @param string $value |
| 639 | - * @param array $user_id_args | |
| 605 | + * @param array $user_id_args | |
| 640 | 606 | * |
| 641 | 607 | * @return string |
| 642 | 608 | */ |
| 643 | 609 | private function prepare_email_setting( $value, $user_id_args ) { |
| @@ -694,24 +660,24 @@ | ||
| 694 | 660 | |
| 695 | 661 | if ( is_email( $val ) ) { |
| 696 | 662 | // If a plain email is used, no formatting is needed |
| 697 | 663 | continue; |
| 698 | - } | |
| 664 | + } else { | |
| 665 | + $parts = explode( ' ', $val ); | |
| 666 | + $email = end( $parts ); | |
| 699 | 667 | |
| 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; | |
| 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 | + } | |
| 710 | 676 | } |
| 711 | 677 | |
| 712 | 678 | $recipients[ $key ] = $this->format_from_email( $name, $email ); |
| 713 | - }//end foreach | |
| 679 | + } | |
| 714 | 680 | |
| 715 | 681 | return $recipients; |
| 716 | 682 | } |
| 717 | 683 | |
| @@ -761,9 +727,9 @@ | ||
| 761 | 727 | $reply_to = trim( $reply_to ); |
| 762 | 728 | |
| 763 | 729 | if ( ! is_email( $reply_to ) ) { |
| 764 | 730 | list( $name, $email ) = $this->get_name_and_email_for_sender( $reply_to ); |
| 765 | - $reply_to = $this->format_from_email( $name, $email ); | |
| 731 | + $reply_to = $this->format_from_email( $name, $email ); | |
| 766 | 732 | } |
| 767 | 733 | |
| 768 | 734 | return $reply_to; |
| 769 | 735 | } |
| @@ -771,12 +737,8 @@ | ||
| 771 | 737 | /** |
| 772 | 738 | * Get only the email if the name and email have been combined |
| 773 | 739 | * |
| 774 | 740 | * @since 3.0.06 |
| 775 | - * | |
| 776 | - * @param string $name | |
| 777 | - * | |
| 778 | - * @return string | |
| 779 | 741 | */ |
| 780 | 742 | private function get_email_from_name( $name ) { |
| 781 | 743 | $email = trim( trim( $name, '>' ), '<' ); |
| 782 | 744 | if ( strpos( $email, '<' ) !== false ) { |
| @@ -812,11 +774,8 @@ | ||
| 812 | 774 | } |
| 813 | 775 | |
| 814 | 776 | /** |
| 815 | 777 | * @since 3.0.06 |
| 816 | - * | |
| 817 | - * @param string $name | |
| 818 | - * @param string $email | |
| 819 | 778 | */ |
| 820 | 779 | private function format_from_email( $name, $email ) { |
| 821 | 780 | if ( '' !== $name ) { |
| 822 | 781 | $email = $name . ' <' . $email . '>'; |
| @@ -829,10 +788,8 @@ | ||
| 829 | 788 | * Remove phone numbers from To addresses |
| 830 | 789 | * Send the phone numbers to the frm_send_to_not_email hook |
| 831 | 790 | * |
| 832 | 791 | * @since 2.03.04 |
| 833 | - * | |
| 834 | - * @return void | |
| 835 | 792 | */ |
| 836 | 793 | private function handle_phone_numbers() { |
| 837 | 794 | |
| 838 | 795 | foreach ( $this->to as $key => $recipient ) { |
| @@ -859,10 +816,10 @@ | ||
| 859 | 816 | ); |
| 860 | 817 | |
| 861 | 818 | // Remove phone number from to addresses |
| 862 | 819 | unset( $this->to[ $key ] ); |
| 863 | - }//end if | |
| 864 | - }//end foreach | |
| 820 | + } | |
| 821 | + } | |
| 865 | 822 | } |
| 866 | 823 | |
| 867 | 824 | /** |
| 868 | 825 | * Package an array of FrmEmail properties |
| @@ -883,9 +840,8 @@ | ||
| 883 | 840 | 'attachments' => $this->attachments, |
| 884 | 841 | 'plain_text' => $this->is_plain_text, |
| 885 | 842 | 'form' => $this->form, |
| 886 | 843 | 'entry' => $this->entry, |
| 887 | - 'email_style' => $this->settings['email_style'], | |
| 888 | 844 | ); |
| 889 | 845 | } |
| 890 | 846 | |
| 891 | 847 | /** |
| @@ -891,10 +847,8 @@ | ||
| 891 | 847 | /** |
| 892 | 848 | * Remove the Buddypress email filters |
| 893 | 849 | * |
| 894 | 850 | * @since 2.03.04 |
| 895 | - * | |
| 896 | - * @return void | |
| 897 | 851 | */ |
| 898 | 852 | private function remove_buddypress_filters() { |
| 899 | 853 | remove_filter( 'wp_mail_from', 'bp_core_email_from_address_filter' ); |
| 900 | 854 | remove_filter( 'wp_mail_from_name', 'bp_core_email_from_name_filter' ); |
| @@ -904,10 +858,8 @@ | ||
| 904 | 858 | * Add Mandrill line break filter |
| 905 | 859 | * Remove line breaks in HTML emails to prevent conflicts with Mandrill |
| 906 | 860 | * |
| 907 | 861 | * @since 2.03.04 |
| 908 | - * | |
| 909 | - * @return void | |
| 910 | 862 | */ |
| 911 | 863 | private function add_mandrill_filter() { |
| 912 | 864 | if ( ! $this->is_plain_text ) { |
| 913 | 865 | add_filter( 'mandrill_nl2br', 'FrmEmailHelper::remove_mandrill_br' ); |
| @@ -917,10 +869,8 @@ | ||
| 917 | 869 | /** |
| 918 | 870 | * Remove Mandrill line break filter |
| 919 | 871 | * |
| 920 | 872 | * @since 2.03.04 |
| 921 | - * | |
| 922 | - * @return void | |
| 923 | 873 | */ |
| 924 | 874 | private function remove_mandrill_filter() { |
| 925 | 875 | remove_filter( 'mandrill_nl2br', 'FrmEmailHelper::remove_mandrill_br' ); |
| 926 | 876 | } |