| @@ -1,8 +1,5 @@ | ||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 3 | - die( 'You are not allowed to call this page directly.' ); | |
| 4 | -} | |
| 5 | 2 | |
| 6 | 3 | /** |
| 7 | 4 | * @since 2.03.04 |
| 8 | 5 | */ |
| @@ -7,99 +4,30 @@ | ||
| 7 | 4 | * @since 2.03.04 |
| 8 | 5 | */ |
| 9 | 6 | class FrmEmail { |
| 10 | 7 | |
| 11 | - /** | |
| 12 | - * @var string $email_key | |
| 13 | - */ | |
| 14 | 8 | private $email_key = ''; |
| 15 | - | |
| 16 | - /** | |
| 17 | - * @var array $to | |
| 18 | - */ | |
| 19 | 9 | private $to = array(); |
| 20 | - | |
| 21 | - /** | |
| 22 | - * @var array $cc | |
| 23 | - */ | |
| 24 | 10 | private $cc = array(); |
| 25 | - | |
| 26 | - /** | |
| 27 | - * @var array $bcc | |
| 28 | - */ | |
| 29 | 11 | private $bcc = array(); |
| 30 | - | |
| 31 | - /** | |
| 32 | - * @var string $from | |
| 33 | - */ | |
| 34 | 12 | private $from = ''; |
| 35 | - | |
| 36 | - /** | |
| 37 | - * @var string $reply_to | |
| 38 | - */ | |
| 39 | 13 | private $reply_to = ''; |
| 40 | - | |
| 41 | - /** | |
| 42 | - * @var string $subject | |
| 43 | - */ | |
| 44 | 14 | private $subject = ''; |
| 45 | - | |
| 46 | - /** | |
| 47 | - * @var string $message | |
| 48 | - */ | |
| 49 | 15 | private $message = ''; |
| 50 | - | |
| 51 | - /** | |
| 52 | - * @var array $attachments | |
| 53 | - */ | |
| 54 | 16 | private $attachments = array(); |
| 55 | 17 | |
| 56 | - /** | |
| 57 | - * @var bool $is_plain_text | |
| 58 | - */ | |
| 59 | 18 | private $is_plain_text = false; |
| 60 | - | |
| 61 | - /** | |
| 62 | - * @var bool $is_single_recipient | |
| 63 | - */ | |
| 64 | 19 | private $is_single_recipient = false; |
| 65 | - | |
| 66 | - /** | |
| 67 | - * @var bool $include_user_info | |
| 68 | - */ | |
| 69 | 20 | private $include_user_info = false; |
| 70 | 21 | |
| 71 | - /** | |
| 72 | - * @var string $charset | |
| 73 | - */ | |
| 74 | 22 | private $charset = ''; |
| 75 | - | |
| 76 | - /** | |
| 77 | - * @var string $content_type | |
| 78 | - */ | |
| 79 | 23 | private $content_type = 'text/html'; |
| 80 | 24 | |
| 81 | - /** | |
| 82 | - * @var array $settings | |
| 83 | - */ | |
| 84 | 25 | private $settings = array(); |
| 85 | - | |
| 86 | - /** | |
| 87 | - * @var stdClass $entry | |
| 88 | - */ | |
| 89 | 26 | private $entry; |
| 90 | - | |
| 91 | - /** | |
| 92 | - * @var stdClass $form | |
| 93 | - */ | |
| 94 | 27 | private $form; |
| 95 | 28 | |
| 96 | 29 | /** |
| 97 | - * @var int $action_id | |
| 98 | - */ | |
| 99 | - private $action_id = 0; | |
| 100 | - | |
| 101 | - /** | |
| 102 | 30 | * FrmEmail constructor |
| 103 | 31 | * |
| 104 | 32 | * @param object $action |
| 105 | 33 | * @param object $entry |
| @@ -106,12 +34,11 @@ | ||
| 106 | 34 | * @param object $form |
| 107 | 35 | */ |
| 108 | 36 | public function __construct( $action, $entry, $form ) { |
| 109 | 37 | $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; | |
| 38 | + $this->entry = $entry; | |
| 39 | + $this->form = $form; | |
| 40 | + $this->settings = $action->post_content; | |
| 114 | 41 | |
| 115 | 42 | $user_id_args = self::get_user_id_args( $form->id ); |
| 116 | 43 | $this->set_to( $user_id_args ); |
| 117 | 44 | $this->set_cc( $user_id_args ); |
| @@ -141,10 +68,8 @@ | ||
| 141 | 68 | * |
| 142 | 69 | * @since 2.03.04 |
| 143 | 70 | * |
| 144 | 71 | * @param object $action |
| 145 | - * | |
| 146 | - * @return void | |
| 147 | 72 | */ |
| 148 | 73 | private function set_email_key( $action ) { |
| 149 | 74 | $this->email_key = $action->ID; |
| 150 | 75 | } |
| @@ -154,16 +79,14 @@ | ||
| 154 | 79 | * |
| 155 | 80 | * @since 2.03.04 |
| 156 | 81 | * |
| 157 | 82 | * @param array $user_id_args |
| 158 | - * | |
| 159 | - * @return void | |
| 160 | 83 | */ |
| 161 | 84 | private function set_to( $user_id_args ) { |
| 162 | 85 | $to = $this->prepare_email_setting( $this->settings['email_to'], $user_id_args ); |
| 163 | 86 | $to = $this->explode_emails( $to ); |
| 164 | 87 | |
| 165 | - $where = array( | |
| 88 | + $where = array( | |
| 166 | 89 | 'it.field_id !' => 0, |
| 167 | 90 | 'it.item_id' => $this->entry->id, |
| 168 | 91 | ); |
| 169 | 92 | $values = FrmEntryMeta::getAll( $where, ' ORDER BY fi.field_order' ); |
| @@ -190,10 +113,8 @@ | ||
| 190 | 113 | * |
| 191 | 114 | * @since 2.03.04 |
| 192 | 115 | * |
| 193 | 116 | * @param array $user_id_args |
| 194 | - * | |
| 195 | - * @return void | |
| 196 | 117 | */ |
| 197 | 118 | private function set_cc( $user_id_args ) { |
| 198 | 119 | $this->cc = $this->prepare_additional_recipients( $this->settings['cc'], $user_id_args ); |
| 199 | 120 | } |
| @@ -203,10 +124,8 @@ | ||
| 203 | 124 | * |
| 204 | 125 | * @since 2.03.04 |
| 205 | 126 | * |
| 206 | 127 | * @param array $user_id_args |
| 207 | - * | |
| 208 | - * @return void | |
| 209 | 128 | */ |
| 210 | 129 | private function set_bcc( $user_id_args ) { |
| 211 | 130 | $this->bcc = $this->prepare_additional_recipients( $this->settings['bcc'], $user_id_args ); |
| 212 | 131 | } |
| @@ -236,9 +155,8 @@ | ||
| 236 | 155 | * |
| 237 | 156 | * @since 2.03.04 |
| 238 | 157 | * |
| 239 | 158 | * @param array $user_id_args |
| 240 | - * @return void | |
| 241 | 159 | */ |
| 242 | 160 | private function set_from( $user_id_args ) { |
| 243 | 161 | if ( empty( $this->settings['from'] ) ) { |
| 244 | 162 | $from = get_option( 'admin_email' ); |
| @@ -254,22 +172,17 @@ | ||
| 254 | 172 | * |
| 255 | 173 | * @since 2.03.04 |
| 256 | 174 | * |
| 257 | 175 | * @param array $user_id_args |
| 258 | - * | |
| 259 | - * @return void | |
| 260 | 176 | */ |
| 261 | 177 | private function set_reply_to( $user_id_args ) { |
| 262 | 178 | $this->reply_to = trim( $this->settings['reply_to'] ); |
| 263 | 179 | |
| 264 | - if ( $this->reply_to ) { | |
| 180 | + if ( empty( $this->reply_to ) ) { | |
| 181 | + $this->reply_to = $this->get_email_from_name( $this->from ); | |
| 182 | + } else { | |
| 265 | 183 | $this->reply_to = $this->prepare_email_setting( $this->settings['reply_to'], $user_id_args ); |
| 266 | 184 | } |
| 267 | - | |
| 268 | - if ( ! $this->reply_to ) { | |
| 269 | - $this->reply_to = $this->get_email_from_name( $this->from ); | |
| 270 | - } | |
| 271 | - | |
| 272 | 185 | $this->reply_to = $this->format_reply_to( $this->reply_to ); |
| 273 | 186 | } |
| 274 | 187 | |
| 275 | 188 | /** |
| @@ -276,10 +189,8 @@ | ||
| 276 | 189 | * Set the is_plain_text property |
| 277 | 190 | * This should be set before the message |
| 278 | 191 | * |
| 279 | 192 | * @since 2.03.04 |
| 280 | - * | |
| 281 | - * @return void | |
| 282 | 193 | */ |
| 283 | 194 | private function set_is_plain_text() { |
| 284 | 195 | if ( $this->settings['plain_text'] ) { |
| 285 | 196 | $this->is_plain_text = true; |
| @@ -290,10 +201,8 @@ | ||
| 290 | 201 | * Set the include_user_info property |
| 291 | 202 | * This should be set before the message |
| 292 | 203 | * |
| 293 | 204 | * @since 2.03.04 |
| 294 | - * | |
| 295 | - * @return void | |
| 296 | 205 | */ |
| 297 | 206 | private function set_include_user_info() { |
| 298 | 207 | if ( isset( $this->settings['inc_user_info'] ) ) { |
| 299 | 208 | $this->include_user_info = $this->settings['inc_user_info']; |
| @@ -305,11 +214,8 @@ | ||
| 305 | 214 | * |
| 306 | 215 | * @since 2.03.04 |
| 307 | 216 | * |
| 308 | 217 | * @param $action |
| 309 | - * @param object $action | |
| 310 | - * | |
| 311 | - * @return void | |
| 312 | 218 | */ |
| 313 | 219 | private function set_is_single_recipient( $action ) { |
| 314 | 220 | $args = array( |
| 315 | 221 | 'form' => $this->form, |
| @@ -328,10 +234,8 @@ | ||
| 328 | 234 | /** |
| 329 | 235 | * Set the charset |
| 330 | 236 | * |
| 331 | 237 | * @since 2.03.04 |
| 332 | - * | |
| 333 | - * @return void | |
| 334 | 238 | */ |
| 335 | 239 | private function set_charset() { |
| 336 | 240 | $this->charset = get_option( 'blog_charset' ); |
| 337 | 241 | } |
| @@ -339,10 +243,8 @@ | ||
| 339 | 243 | /** |
| 340 | 244 | * Set the content type |
| 341 | 245 | * |
| 342 | 246 | * @since 2.03.04 |
| 343 | - * | |
| 344 | - * @return void | |
| 345 | 247 | */ |
| 346 | 248 | private function set_content_type() { |
| 347 | 249 | if ( $this->is_plain_text ) { |
| 348 | 250 | $this->content_type = 'text/plain'; |
| @@ -352,10 +254,8 @@ | ||
| 352 | 254 | /** |
| 353 | 255 | * Set the subject |
| 354 | 256 | * |
| 355 | 257 | * @since 2.03.04 |
| 356 | - * | |
| 357 | - * @return void | |
| 358 | 258 | */ |
| 359 | 259 | private function set_subject() { |
| 360 | 260 | if ( empty( $this->settings['email_subject'] ) ) { |
| 361 | 261 | /* translators: %1$s: Form name, %2$s: Site name */ |
| @@ -363,9 +263,8 @@ | ||
| 363 | 263 | } else { |
| 364 | 264 | $this->subject = $this->settings['email_subject']; |
| 365 | 265 | } |
| 366 | 266 | |
| 367 | - // This also replaces [sitename] shortcode in default. | |
| 368 | 267 | $this->subject = FrmFieldsHelper::basic_replace_shortcodes( $this->subject, $this->form, $this->entry ); |
| 369 | 268 | |
| 370 | 269 | $args = array( |
| 371 | 270 | 'form' => $this->form, |
| @@ -372,8 +271,9 @@ | ||
| 372 | 271 | 'entry' => $this->entry, |
| 373 | 272 | 'email_key' => $this->email_key, |
| 374 | 273 | ); |
| 375 | 274 | $this->subject = apply_filters( 'frm_email_subject', $this->subject, $args ); |
| 275 | + | |
| 376 | 276 | $this->subject = wp_specialchars_decode( strip_tags( stripslashes( $this->subject ) ), ENT_QUOTES ); |
| 377 | 277 | } |
| 378 | 278 | |
| 379 | 279 | /** |
| @@ -379,20 +279,12 @@ | ||
| 379 | 279 | /** |
| 380 | 280 | * Set the email message |
| 381 | 281 | * |
| 382 | 282 | * @since 2.03.04 |
| 383 | - * | |
| 384 | - * @return void | |
| 385 | 283 | */ |
| 386 | 284 | private function set_message() { |
| 387 | - $this->message = $this->settings['email_message']; | |
| 285 | + $this->message = FrmFieldsHelper::basic_replace_shortcodes( $this->settings['email_message'], $this->form, $this->entry ); | |
| 388 | 286 | |
| 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 | 287 | $prev_mail_body = $this->message; |
| 396 | 288 | $pass_entry = clone $this->entry; // make a copy to prevent changes by reference |
| 397 | 289 | $mail_body = FrmEntriesHelper::replace_default_message( |
| 398 | 290 | $prev_mail_body, |
| @@ -405,9 +297,9 @@ | ||
| 405 | 297 | ); |
| 406 | 298 | |
| 407 | 299 | // Add the user info if it isn't already included |
| 408 | 300 | if ( $this->include_user_info && $prev_mail_body === $mail_body ) { |
| 409 | - $data = $this->entry->description; | |
| 301 | + $data = maybe_unserialize( $this->entry->description ); | |
| 410 | 302 | $mail_body .= "\r\n\r\n" . __( 'User Information', 'formidable' ) . "\r\n"; |
| 411 | 303 | $this->maybe_add_ip( $mail_body ); |
| 412 | 304 | $mail_body .= __( 'User-Agent (Browser/OS)', 'formidable' ) . ': ' . FrmEntriesHelper::get_browser( $data['browser'] ) . "\r\n"; |
| 413 | 305 | $mail_body .= __( 'Referrer', 'formidable' ) . ': ' . $data['referrer'] . "\r\n"; |
| @@ -418,35 +310,13 @@ | ||
| 418 | 310 | $this->message = do_shortcode( $this->message ); |
| 419 | 311 | |
| 420 | 312 | if ( $this->is_plain_text ) { |
| 421 | 313 | $this->message = wp_specialchars_decode( strip_tags( $this->message ), ENT_QUOTES ); |
| 422 | - } else { | |
| 423 | - $this->add_autop(); | |
| 424 | 314 | } |
| 425 | 315 | |
| 426 | 316 | $this->message = apply_filters( 'frm_email_message', $this->message, $this->package_atts() ); |
| 427 | 317 | } |
| 428 | 318 | |
| 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 | 319 | private function maybe_add_ip( &$mail_body ) { |
| 450 | 320 | if ( ! empty( $this->entry->ip ) ) { |
| 451 | 321 | $mail_body .= __( 'IP Address', 'formidable' ) . ': ' . $this->entry->ip . "\r\n"; |
| 452 | 322 | } |
| @@ -455,18 +325,13 @@ | ||
| 455 | 325 | /** |
| 456 | 326 | * Set the attachments for an email message |
| 457 | 327 | * |
| 458 | 328 | * @since 2.03.04 |
| 459 | - * @since 5.0.16 added new action_id key to $args. | |
| 460 | - * | |
| 461 | - * @return void | |
| 462 | 329 | */ |
| 463 | 330 | private function set_attachments() { |
| 464 | 331 | $args = array( |
| 465 | 332 | 'entry' => $this->entry, |
| 466 | 333 | 'email_key' => $this->email_key, |
| 467 | - 'settings' => $this->settings, | |
| 468 | - 'action_id' => $this->action_id, | |
| 469 | 334 | ); |
| 470 | 335 | |
| 471 | 336 | $this->attachments = apply_filters( 'frm_notification_attachment', array(), $this->form, $args ); |
| 472 | 337 | } |
| @@ -565,11 +430,9 @@ | ||
| 565 | 430 | |
| 566 | 431 | $sent = wp_mail( $recipient, $subject, $this->message, $header, $this->attachments ); |
| 567 | 432 | |
| 568 | 433 | if ( ! $sent ) { |
| 569 | - if ( is_array( $header ) ) { | |
| 570 | - $header = implode( "\r\n", $header ); | |
| 571 | - } | |
| 434 | + $header = 'From: ' . $this->from . "\r\n"; | |
| 572 | 435 | $recipient = implode( ',', (array) $recipient ); |
| 573 | 436 | $sent = mail( $recipient, $subject, $this->message, $header ); |
| 574 | 437 | } |
| 575 | 438 | |
| @@ -585,9 +448,9 @@ | ||
| 585 | 448 | * |
| 586 | 449 | * @return array |
| 587 | 450 | */ |
| 588 | 451 | private function package_header() { |
| 589 | - $header = array(); | |
| 452 | + $header = array(); | |
| 590 | 453 | |
| 591 | 454 | if ( ! empty( $this->cc ) ) { |
| 592 | 455 | $header[] = 'CC: ' . implode( ',', $this->cc ); |
| 593 | 456 | } |
| @@ -658,9 +521,8 @@ | ||
| 658 | 521 | * |
| 659 | 522 | * @since 2.03.04 |
| 660 | 523 | * |
| 661 | 524 | * @param string $emails |
| 662 | - * | |
| 663 | 525 | * @return array|string $emails |
| 664 | 526 | */ |
| 665 | 527 | private function explode_emails( $emails ) { |
| 666 | 528 | $emails = ( ! empty( $emails ) ? preg_split( '/(,|;)/', $emails ) : '' ); |
| @@ -767,12 +629,8 @@ | ||
| 767 | 629 | /** |
| 768 | 630 | * Get only the email if the name and email have been combined |
| 769 | 631 | * |
| 770 | 632 | * @since 3.0.06 |
| 771 | - * | |
| 772 | - * @param string $name | |
| 773 | - * | |
| 774 | - * @return string | |
| 775 | 633 | */ |
| 776 | 634 | private function get_email_from_name( $name ) { |
| 777 | 635 | $email = trim( trim( $name, '>' ), '<' ); |
| 778 | 636 | if ( strpos( $email, '<' ) !== false ) { |
| @@ -778,9 +636,8 @@ | ||
| 778 | 636 | if ( strpos( $email, '<' ) !== false ) { |
| 779 | 637 | $parts = explode( '<', $email ); |
| 780 | 638 | $email = trim( $parts[1], '>' ); |
| 781 | 639 | } |
| 782 | - | |
| 783 | 640 | return $email; |
| 784 | 641 | } |
| 785 | 642 | |
| 786 | 643 | /** |
| @@ -808,17 +665,13 @@ | ||
| 808 | 665 | } |
| 809 | 666 | |
| 810 | 667 | /** |
| 811 | 668 | * @since 3.0.06 |
| 812 | - * | |
| 813 | - * @param string $name | |
| 814 | - * @param string $email | |
| 815 | 669 | */ |
| 816 | 670 | private function format_from_email( $name, $email ) { |
| 817 | 671 | if ( '' !== $name ) { |
| 818 | 672 | $email = $name . ' <' . $email . '>'; |
| 819 | 673 | } |
| 820 | - | |
| 821 | 674 | return $email; |
| 822 | 675 | } |
| 823 | 676 | |
| 824 | 677 | /** |
| @@ -825,10 +678,8 @@ | ||
| 825 | 678 | * Remove phone numbers from To addresses |
| 826 | 679 | * Send the phone numbers to the frm_send_to_not_email hook |
| 827 | 680 | * |
| 828 | 681 | * @since 2.03.04 |
| 829 | - * | |
| 830 | - * @return void | |
| 831 | 682 | */ |
| 832 | 683 | private function handle_phone_numbers() { |
| 833 | 684 | |
| 834 | 685 | foreach ( $this->to as $key => $recipient ) { |
| @@ -886,10 +737,8 @@ | ||
| 886 | 737 | /** |
| 887 | 738 | * Remove the Buddypress email filters |
| 888 | 739 | * |
| 889 | 740 | * @since 2.03.04 |
| 890 | - * | |
| 891 | - * @return void | |
| 892 | 741 | */ |
| 893 | 742 | private function remove_buddypress_filters() { |
| 894 | 743 | remove_filter( 'wp_mail_from', 'bp_core_email_from_address_filter' ); |
| 895 | 744 | remove_filter( 'wp_mail_from_name', 'bp_core_email_from_name_filter' ); |
| @@ -899,10 +748,8 @@ | ||
| 899 | 748 | * Add Mandrill line break filter |
| 900 | 749 | * Remove line breaks in HTML emails to prevent conflicts with Mandrill |
| 901 | 750 | * |
| 902 | 751 | * @since 2.03.04 |
| 903 | - * | |
| 904 | - * @return void | |
| 905 | 752 | */ |
| 906 | 753 | private function add_mandrill_filter() { |
| 907 | 754 | if ( ! $this->is_plain_text ) { |
| 908 | 755 | add_filter( 'mandrill_nl2br', 'FrmEmailHelper::remove_mandrill_br' ); |
| @@ -912,10 +759,8 @@ | ||
| 912 | 759 | /** |
| 913 | 760 | * Remove Mandrill line break filter |
| 914 | 761 | * |
| 915 | 762 | * @since 2.03.04 |
| 916 | - * | |
| 917 | - * @return void | |
| 918 | 763 | */ |
| 919 | 764 | private function remove_mandrill_filter() { |
| 920 | 765 | remove_filter( 'mandrill_nl2br', 'FrmEmailHelper::remove_mandrill_br' ); |
| 921 | 766 | } |
| @@ -927,9 +772,9 @@ | ||
| 927 | 772 | * |
| 928 | 773 | * @return string |
| 929 | 774 | */ |
| 930 | 775 | private function encode_subject( $subject ) { |
| 931 | - if ( apply_filters( 'frm_encode_subject', false, $subject ) ) { | |
| 776 | + if ( apply_filters( 'frm_encode_subject', 1, $subject ) ) { | |
| 932 | 777 | $subject = '=?' . $this->charset . '?B?' . base64_encode( $subject ) . '?='; |
| 933 | 778 | } |
| 934 | 779 | |
| 935 | 780 | return $subject; |