| @@ -7,99 +7,30 @@ | ||
| 7 | 7 | * @since 2.03.04 |
| 8 | 8 | */ |
| 9 | 9 | class FrmEmail { |
| 10 | 10 | |
| 11 | - /** | |
| 12 | - * @var string $email_key | |
| 13 | - */ | |
| 14 | 11 | private $email_key = ''; |
| 15 | - | |
| 16 | - /** | |
| 17 | - * @var array $to | |
| 18 | - */ | |
| 19 | 12 | private $to = array(); |
| 20 | - | |
| 21 | - /** | |
| 22 | - * @var array $cc | |
| 23 | - */ | |
| 24 | 13 | private $cc = array(); |
| 25 | - | |
| 26 | - /** | |
| 27 | - * @var array $bcc | |
| 28 | - */ | |
| 29 | 14 | private $bcc = array(); |
| 30 | - | |
| 31 | - /** | |
| 32 | - * @var string $from | |
| 33 | - */ | |
| 34 | 15 | private $from = ''; |
| 35 | - | |
| 36 | - /** | |
| 37 | - * @var string $reply_to | |
| 38 | - */ | |
| 39 | 16 | private $reply_to = ''; |
| 40 | - | |
| 41 | - /** | |
| 42 | - * @var string $subject | |
| 43 | - */ | |
| 44 | 17 | private $subject = ''; |
| 45 | - | |
| 46 | - /** | |
| 47 | - * @var string $message | |
| 48 | - */ | |
| 49 | 18 | private $message = ''; |
| 50 | - | |
| 51 | - /** | |
| 52 | - * @var array $attachments | |
| 53 | - */ | |
| 54 | 19 | private $attachments = array(); |
| 55 | 20 | |
| 56 | - /** | |
| 57 | - * @var bool $is_plain_text | |
| 58 | - */ | |
| 59 | 21 | private $is_plain_text = false; |
| 60 | - | |
| 61 | - /** | |
| 62 | - * @var bool $is_single_recipient | |
| 63 | - */ | |
| 64 | 22 | private $is_single_recipient = false; |
| 65 | - | |
| 66 | - /** | |
| 67 | - * @var bool $include_user_info | |
| 68 | - */ | |
| 69 | 23 | private $include_user_info = false; |
| 70 | 24 | |
| 71 | - /** | |
| 72 | - * @var string $charset | |
| 73 | - */ | |
| 74 | 25 | private $charset = ''; |
| 75 | - | |
| 76 | - /** | |
| 77 | - * @var string $content_type | |
| 78 | - */ | |
| 79 | 26 | private $content_type = 'text/html'; |
| 80 | 27 | |
| 81 | - /** | |
| 82 | - * @var array $settings | |
| 83 | - */ | |
| 84 | 28 | private $settings = array(); |
| 85 | - | |
| 86 | - /** | |
| 87 | - * @var stdClass $entry | |
| 88 | - */ | |
| 89 | 29 | private $entry; |
| 90 | - | |
| 91 | - /** | |
| 92 | - * @var stdClass $form | |
| 93 | - */ | |
| 94 | 30 | private $form; |
| 95 | 31 | |
| 96 | 32 | /** |
| 97 | - * @var int $action_id | |
| 98 | - */ | |
| 99 | - private $action_id = 0; | |
| 100 | - | |
| 101 | - /** | |
| 102 | 33 | * FrmEmail constructor |
| 103 | 34 | * |
| 104 | 35 | * @param object $action |
| 105 | 36 | * @param object $entry |
| @@ -106,12 +37,11 @@ | ||
| 106 | 37 | * @param object $form |
| 107 | 38 | */ |
| 108 | 39 | public function __construct( $action, $entry, $form ) { |
| 109 | 40 | $this->set_email_key( $action ); |
| 110 | - $this->entry = $entry; | |
| 111 | - $this->form = $form; | |
| 112 | - $this->settings = $action->post_content; | |
| 113 | - $this->action_id = (int) $action->ID; | |
| 41 | + $this->entry = $entry; | |
| 42 | + $this->form = $form; | |
| 43 | + $this->settings = $action->post_content; | |
| 114 | 44 | |
| 115 | 45 | $user_id_args = self::get_user_id_args( $form->id ); |
| 116 | 46 | $this->set_to( $user_id_args ); |
| 117 | 47 | $this->set_cc( $user_id_args ); |
| @@ -141,10 +71,8 @@ | ||
| 141 | 71 | * |
| 142 | 72 | * @since 2.03.04 |
| 143 | 73 | * |
| 144 | 74 | * @param object $action |
| 145 | - * | |
| 146 | - * @return void | |
| 147 | 75 | */ |
| 148 | 76 | private function set_email_key( $action ) { |
| 149 | 77 | $this->email_key = $action->ID; |
| 150 | 78 | } |
| @@ -154,10 +82,8 @@ | ||
| 154 | 82 | * |
| 155 | 83 | * @since 2.03.04 |
| 156 | 84 | * |
| 157 | 85 | * @param array $user_id_args |
| 158 | - * | |
| 159 | - * @return void | |
| 160 | 86 | */ |
| 161 | 87 | private function set_to( $user_id_args ) { |
| 162 | 88 | $to = $this->prepare_email_setting( $this->settings['email_to'], $user_id_args ); |
| 163 | 89 | $to = $this->explode_emails( $to ); |
| @@ -190,10 +116,8 @@ | ||
| 190 | 116 | * |
| 191 | 117 | * @since 2.03.04 |
| 192 | 118 | * |
| 193 | 119 | * @param array $user_id_args |
| 194 | - * | |
| 195 | - * @return void | |
| 196 | 120 | */ |
| 197 | 121 | private function set_cc( $user_id_args ) { |
| 198 | 122 | $this->cc = $this->prepare_additional_recipients( $this->settings['cc'], $user_id_args ); |
| 199 | 123 | } |
| @@ -203,10 +127,8 @@ | ||
| 203 | 127 | * |
| 204 | 128 | * @since 2.03.04 |
| 205 | 129 | * |
| 206 | 130 | * @param array $user_id_args |
| 207 | - * | |
| 208 | - * @return void | |
| 209 | 131 | */ |
| 210 | 132 | private function set_bcc( $user_id_args ) { |
| 211 | 133 | $this->bcc = $this->prepare_additional_recipients( $this->settings['bcc'], $user_id_args ); |
| 212 | 134 | } |
| @@ -236,9 +158,8 @@ | ||
| 236 | 158 | * |
| 237 | 159 | * @since 2.03.04 |
| 238 | 160 | * |
| 239 | 161 | * @param array $user_id_args |
| 240 | - * @return void | |
| 241 | 162 | */ |
| 242 | 163 | private function set_from( $user_id_args ) { |
| 243 | 164 | if ( empty( $this->settings['from'] ) ) { |
| 244 | 165 | $from = get_option( 'admin_email' ); |
| @@ -254,10 +175,8 @@ | ||
| 254 | 175 | * |
| 255 | 176 | * @since 2.03.04 |
| 256 | 177 | * |
| 257 | 178 | * @param array $user_id_args |
| 258 | - * | |
| 259 | - * @return void | |
| 260 | 179 | */ |
| 261 | 180 | private function set_reply_to( $user_id_args ) { |
| 262 | 181 | $this->reply_to = trim( $this->settings['reply_to'] ); |
| 263 | 182 | |
| @@ -276,10 +195,8 @@ | ||
| 276 | 195 | * Set the is_plain_text property |
| 277 | 196 | * This should be set before the message |
| 278 | 197 | * |
| 279 | 198 | * @since 2.03.04 |
| 280 | - * | |
| 281 | - * @return void | |
| 282 | 199 | */ |
| 283 | 200 | private function set_is_plain_text() { |
| 284 | 201 | if ( $this->settings['plain_text'] ) { |
| 285 | 202 | $this->is_plain_text = true; |
| @@ -290,10 +207,8 @@ | ||
| 290 | 207 | * Set the include_user_info property |
| 291 | 208 | * This should be set before the message |
| 292 | 209 | * |
| 293 | 210 | * @since 2.03.04 |
| 294 | - * | |
| 295 | - * @return void | |
| 296 | 211 | */ |
| 297 | 212 | private function set_include_user_info() { |
| 298 | 213 | if ( isset( $this->settings['inc_user_info'] ) ) { |
| 299 | 214 | $this->include_user_info = $this->settings['inc_user_info']; |
| @@ -305,11 +220,8 @@ | ||
| 305 | 220 | * |
| 306 | 221 | * @since 2.03.04 |
| 307 | 222 | * |
| 308 | 223 | * @param $action |
| 309 | - * @param object $action | |
| 310 | - * | |
| 311 | - * @return void | |
| 312 | 224 | */ |
| 313 | 225 | private function set_is_single_recipient( $action ) { |
| 314 | 226 | $args = array( |
| 315 | 227 | 'form' => $this->form, |
| @@ -328,10 +240,8 @@ | ||
| 328 | 240 | /** |
| 329 | 241 | * Set the charset |
| 330 | 242 | * |
| 331 | 243 | * @since 2.03.04 |
| 332 | - * | |
| 333 | - * @return void | |
| 334 | 244 | */ |
| 335 | 245 | private function set_charset() { |
| 336 | 246 | $this->charset = get_option( 'blog_charset' ); |
| 337 | 247 | } |
| @@ -339,10 +249,8 @@ | ||
| 339 | 249 | /** |
| 340 | 250 | * Set the content type |
| 341 | 251 | * |
| 342 | 252 | * @since 2.03.04 |
| 343 | - * | |
| 344 | - * @return void | |
| 345 | 253 | */ |
| 346 | 254 | private function set_content_type() { |
| 347 | 255 | if ( $this->is_plain_text ) { |
| 348 | 256 | $this->content_type = 'text/plain'; |
| @@ -352,10 +260,8 @@ | ||
| 352 | 260 | /** |
| 353 | 261 | * Set the subject |
| 354 | 262 | * |
| 355 | 263 | * @since 2.03.04 |
| 356 | - * | |
| 357 | - * @return void | |
| 358 | 264 | */ |
| 359 | 265 | private function set_subject() { |
| 360 | 266 | if ( empty( $this->settings['email_subject'] ) ) { |
| 361 | 267 | /* translators: %1$s: Form name, %2$s: Site name */ |
| @@ -363,9 +269,8 @@ | ||
| 363 | 269 | } else { |
| 364 | 270 | $this->subject = $this->settings['email_subject']; |
| 365 | 271 | } |
| 366 | 272 | |
| 367 | - // This also replaces [sitename] shortcode in default. | |
| 368 | 273 | $this->subject = FrmFieldsHelper::basic_replace_shortcodes( $this->subject, $this->form, $this->entry ); |
| 369 | 274 | |
| 370 | 275 | $args = array( |
| 371 | 276 | 'form' => $this->form, |
| @@ -372,8 +277,9 @@ | ||
| 372 | 277 | 'entry' => $this->entry, |
| 373 | 278 | 'email_key' => $this->email_key, |
| 374 | 279 | ); |
| 375 | 280 | $this->subject = apply_filters( 'frm_email_subject', $this->subject, $args ); |
| 281 | + | |
| 376 | 282 | $this->subject = wp_specialchars_decode( strip_tags( stripslashes( $this->subject ) ), ENT_QUOTES ); |
| 377 | 283 | } |
| 378 | 284 | |
| 379 | 285 | /** |
| @@ -379,20 +285,12 @@ | ||
| 379 | 285 | /** |
| 380 | 286 | * Set the email message |
| 381 | 287 | * |
| 382 | 288 | * @since 2.03.04 |
| 383 | - * | |
| 384 | - * @return void | |
| 385 | 289 | */ |
| 386 | 290 | private function set_message() { |
| 387 | - $this->message = $this->settings['email_message']; | |
| 291 | + $this->message = FrmFieldsHelper::basic_replace_shortcodes( $this->settings['email_message'], $this->form, $this->entry ); | |
| 388 | 292 | |
| 389 | - if ( ! $this->is_plain_text ) { | |
| 390 | - $this->message = html_entity_decode( $this->message ); // The decode is to support [default-html] shortcodes. | |
| 391 | - } | |
| 392 | - | |
| 393 | - $this->message = FrmFieldsHelper::basic_replace_shortcodes( $this->message, $this->form, $this->entry ); | |
| 394 | - | |
| 395 | 293 | $prev_mail_body = $this->message; |
| 396 | 294 | $pass_entry = clone $this->entry; // make a copy to prevent changes by reference |
| 397 | 295 | $mail_body = FrmEntriesHelper::replace_default_message( |
| 398 | 296 | $prev_mail_body, |
| @@ -418,35 +316,13 @@ | ||
| 418 | 316 | $this->message = do_shortcode( $this->message ); |
| 419 | 317 | |
| 420 | 318 | if ( $this->is_plain_text ) { |
| 421 | 319 | $this->message = wp_specialchars_decode( strip_tags( $this->message ), ENT_QUOTES ); |
| 422 | - } else { | |
| 423 | - $this->add_autop(); | |
| 424 | 320 | } |
| 425 | 321 | |
| 426 | 322 | $this->message = apply_filters( 'frm_email_message', $this->message, $this->package_atts() ); |
| 427 | 323 | } |
| 428 | 324 | |
| 429 | - /** | |
| 430 | - * Runs message through autop, extracting the content inside body tag if it has <body>. | |
| 431 | - * | |
| 432 | - * @return void | |
| 433 | - */ | |
| 434 | - private function add_autop() { | |
| 435 | - $message = $this->message; | |
| 436 | - $result = preg_match( '/<body[^>]*>([\s\S]*?)<\/body>/', $message, $match ); | |
| 437 | - if ( ! empty( $match[1] ) ) { | |
| 438 | - $this->message = str_replace( $match[1], trim( wpautop( $match[1] ) ), $message ); | |
| 439 | - } else { | |
| 440 | - $this->message = trim( wpautop( $message ) ); | |
| 441 | - } | |
| 442 | - } | |
| 443 | - | |
| 444 | - /** | |
| 445 | - * @param string $mail_body | |
| 446 | - * | |
| 447 | - * @return void | |
| 448 | - */ | |
| 449 | 325 | private function maybe_add_ip( &$mail_body ) { |
| 450 | 326 | if ( ! empty( $this->entry->ip ) ) { |
| 451 | 327 | $mail_body .= __( 'IP Address', 'formidable' ) . ': ' . $this->entry->ip . "\r\n"; |
| 452 | 328 | } |
| @@ -455,11 +331,8 @@ | ||
| 455 | 331 | /** |
| 456 | 332 | * Set the attachments for an email message |
| 457 | 333 | * |
| 458 | 334 | * @since 2.03.04 |
| 459 | - * @since 5.0.16 added new action_id key to $args. | |
| 460 | - * | |
| 461 | - * @return void | |
| 462 | 335 | */ |
| 463 | 336 | private function set_attachments() { |
| 464 | 337 | $args = array( |
| 465 | 338 | 'entry' => $this->entry, |
| @@ -464,9 +337,8 @@ | ||
| 464 | 337 | $args = array( |
| 465 | 338 | 'entry' => $this->entry, |
| 466 | 339 | 'email_key' => $this->email_key, |
| 467 | 340 | 'settings' => $this->settings, |
| 468 | - 'action_id' => $this->action_id, | |
| 469 | 341 | ); |
| 470 | 342 | |
| 471 | 343 | $this->attachments = apply_filters( 'frm_notification_attachment', array(), $this->form, $args ); |
| 472 | 344 | } |
| @@ -767,12 +639,8 @@ | ||
| 767 | 639 | /** |
| 768 | 640 | * Get only the email if the name and email have been combined |
| 769 | 641 | * |
| 770 | 642 | * @since 3.0.06 |
| 771 | - * | |
| 772 | - * @param string $name | |
| 773 | - * | |
| 774 | - * @return string | |
| 775 | 643 | */ |
| 776 | 644 | private function get_email_from_name( $name ) { |
| 777 | 645 | $email = trim( trim( $name, '>' ), '<' ); |
| 778 | 646 | if ( strpos( $email, '<' ) !== false ) { |
| @@ -808,11 +676,8 @@ | ||
| 808 | 676 | } |
| 809 | 677 | |
| 810 | 678 | /** |
| 811 | 679 | * @since 3.0.06 |
| 812 | - * | |
| 813 | - * @param string $name | |
| 814 | - * @param string $email | |
| 815 | 680 | */ |
| 816 | 681 | private function format_from_email( $name, $email ) { |
| 817 | 682 | if ( '' !== $name ) { |
| 818 | 683 | $email = $name . ' <' . $email . '>'; |
| @@ -825,10 +690,8 @@ | ||
| 825 | 690 | * Remove phone numbers from To addresses |
| 826 | 691 | * Send the phone numbers to the frm_send_to_not_email hook |
| 827 | 692 | * |
| 828 | 693 | * @since 2.03.04 |
| 829 | - * | |
| 830 | - * @return void | |
| 831 | 694 | */ |
| 832 | 695 | private function handle_phone_numbers() { |
| 833 | 696 | |
| 834 | 697 | foreach ( $this->to as $key => $recipient ) { |
| @@ -886,10 +749,8 @@ | ||
| 886 | 749 | /** |
| 887 | 750 | * Remove the Buddypress email filters |
| 888 | 751 | * |
| 889 | 752 | * @since 2.03.04 |
| 890 | - * | |
| 891 | - * @return void | |
| 892 | 753 | */ |
| 893 | 754 | private function remove_buddypress_filters() { |
| 894 | 755 | remove_filter( 'wp_mail_from', 'bp_core_email_from_address_filter' ); |
| 895 | 756 | remove_filter( 'wp_mail_from_name', 'bp_core_email_from_name_filter' ); |
| @@ -899,10 +760,8 @@ | ||
| 899 | 760 | * Add Mandrill line break filter |
| 900 | 761 | * Remove line breaks in HTML emails to prevent conflicts with Mandrill |
| 901 | 762 | * |
| 902 | 763 | * @since 2.03.04 |
| 903 | - * | |
| 904 | - * @return void | |
| 905 | 764 | */ |
| 906 | 765 | private function add_mandrill_filter() { |
| 907 | 766 | if ( ! $this->is_plain_text ) { |
| 908 | 767 | add_filter( 'mandrill_nl2br', 'FrmEmailHelper::remove_mandrill_br' ); |
| @@ -912,10 +771,8 @@ | ||
| 912 | 771 | /** |
| 913 | 772 | * Remove Mandrill line break filter |
| 914 | 773 | * |
| 915 | 774 | * @since 2.03.04 |
| 916 | - * | |
| 917 | - * @return void | |
| 918 | 775 | */ |
| 919 | 776 | private function remove_mandrill_filter() { |
| 920 | 777 | remove_filter( 'mandrill_nl2br', 'FrmEmailHelper::remove_mandrill_br' ); |
| 921 | 778 | } |