Ejemplo n.º 1
0
 public function send_mail($users, Falcon_Message $message)
 {
     $options = $message->get_options();
     $from = Falcon::get_from_address();
     $author = $message->get_author();
     $messages = array();
     foreach ($users as $user) {
         $data = array('from_email' => $from, 'to' => array(array('email' => $user->user_email, 'name' => $user->display_name)), 'subject' => $message->get_subject(), 'headers' => array('Reply-To' => $message->get_reply_address($user)));
         if ($author) {
             $data['from_name'] = $author;
         }
         if ($text = $message->get_text()) {
             $data['text'] = $text;
         }
         if ($html = $message->get_html()) {
             $data['html'] = $html;
         }
         // Set the message ID if we've got one
         if (!empty($options['message-id'])) {
             $data['headers']['Message-ID'] = $options['message-id'];
         }
         // If this is a reply, set the headers as needed
         if (!empty($options['in-reply-to'])) {
             $original = $options['in-reply-to'];
             if (is_array($original)) {
                 $original = isset($options['in-reply-to'][$user->ID]) ? $options['in-reply-to'][$user->ID] : null;
             }
             if (!empty($original)) {
                 $data['headers']['In-Reply-To'] = $original;
             }
         }
         if (!empty($options['references'])) {
             $references = implode(' ', $options['references']);
             $data['headers']['References'] = $references;
         }
         try {
             $messages[$user->ID] = $this->send_single($data);
         } catch (Exception $e) {
             $error = sprintf(__('Exception while sending: %s', 'falcon'), $e->getMessage());
             trigger_error($error, E_USER_WARNING);
         }
     }
     return $messages;
 }
Ejemplo n.º 2
0
 public function send_mail($users, Falcon_Message $message)
 {
     $options = $message->get_options();
     $from = Falcon::get_from_address();
     if ($author = $message->get_author()) {
         $from = sprintf('%s <%s>', $author, $from);
     }
     $messages = array();
     foreach ($users as $user) {
         $data = array('From' => $from, 'ReplyTo' => $message->get_reply_address($user), 'To' => $user->user_email, 'Subject' => $message->get_subject(), 'Headers' => array());
         if ($text = $message->get_text()) {
             $data['TextBody'] = $text;
         }
         if ($html = $message->get_html()) {
             $data['HtmlBody'] = $html;
         }
         // Set the message ID if we've got one
         if (!empty($options['message-id'])) {
             $data['Headers'][] = array('Name' => 'Message-ID', 'Value' => $options['message-id']);
         }
         // If this is a reply, set the headers as needed
         if (!empty($options['in-reply-to'])) {
             $original = $options['in-reply-to'];
             if (is_array($original)) {
                 $original = isset($options['in-reply-to'][$user->ID]) ? $options['in-reply-to'][$user->ID] : null;
             }
             if (!empty($original)) {
                 $data['Headers'][] = array('Name' => 'In-Reply-To', 'Value' => $original);
             }
         }
         if (!empty($options['references'])) {
             $references = implode(' ', $options['references']);
             $data['Headers'][] = array('Name' => 'References', 'Value' => $references);
         }
         $messages[$user->ID] = $this->send_single($data);
     }
     return $messages;
 }
Ejemplo n.º 3
0
 /**
  * Send a notification to subscribers
  */
 public function notify_on_reply($id = 0, $comment = null)
 {
     if (empty($this->handler) || !Falcon::is_enabled_for_site()) {
         return false;
     }
     if (wp_get_comment_status($comment) !== 'approved') {
         return false;
     }
     // Is the post published?
     $post = get_post($comment->comment_post_ID);
     if (get_post_status($post) !== 'publish') {
         return false;
     }
     // Grab the users we should notify
     $users = $this->get_comment_subscribers($comment);
     if (empty($users)) {
         return false;
     }
     $message = new Falcon_Message();
     // Poster name
     $message->set_author(apply_filters('falcon.connector.wordpress.comment_author', $comment->comment_author));
     // Don't send notifications to the person who made the post
     $send_to_author = Falcon::get_option('bbsub_send_to_author', false);
     if (!$send_to_author && !empty($comment->user_id)) {
         $author = (int) $comment->user_id;
         $users = array_filter($users, function ($user) use($author) {
             return $user->ID !== $author;
         });
     }
     // Sanitize the HTML into text
     $message->set_text($this->get_comment_content_as_text($comment));
     $message->set_html($this->get_comment_content_as_html($comment));
     $subject = apply_filters('bbsub_email_subject', 'Re: [' . get_option('blogname') . '] ' . html_entity_decode(get_the_title($post), ENT_QUOTES), $id, $post->ID);
     $message->set_subject($subject);
     $message->set_reply_address_handler(function (WP_User $user, Falcon_Message $message) use($comment) {
         return Falcon::get_reply_address('comment_' . $comment->comment_ID, $user);
     });
     $options = array();
     if ($this->handler->supports_message_ids()) {
         $options['references'] = $this->get_references_for_comment($comment);
         $options['message-id'] = $this->get_message_id_for_comment($comment);
         if (!empty($comment->comment_parent)) {
             $parent = get_comment($comment->comment_parent);
             $options['in-reply-to'] = $this->get_message_id_for_comment($parent);
         } else {
             $options['in-reply-to'] = $this->get_message_id_for_post($post);
         }
     } else {
         $message_ids = get_post_meta($id, self::MESSAGE_ID_KEY, $responses);
         $options['in-reply-to'] = $message_ids;
     }
     $message->set_options($options);
     $this->handler->send_mail($users, $message);
     return true;
 }