/**
  * Builds an email batch with content based on a subscribable object.
  *
  * @since 2.0.0
  *
  * @param Prompt_Interface_Subscribable[]|Prompt_Interface_Subscribable $lists
  * @param array $message_data
  */
 public function __construct($lists, $message_data = array())
 {
     $this->lists = is_array($lists) ? $lists : array($lists);
     $this->users_data = array();
     $this->message_data = $message_data;
     $message_data = array_merge(array('lists' => $this->lists), $message_data);
     /**
      * Filter new user subscription verification email template data.
      * @param array $message_data {
      * @type Prompt_Interface_Subscribable $lists The object being subscribed to
      * }
      */
     $message_data = apply_filters('prompt/subscription_agreement_email/template_data', $message_data);
     $html_template = new Prompt_Template('subscription-agreement-email.php');
     $text_template = new Prompt_Text_Template('subscription-agreement-email-text.php');
     $subject = sprintf(__('Please verify your subscription to %s', 'Postmatic'), $this->lists[0]->subscription_object_label());
     if (count($this->lists) > 1) {
         $subject = __('Please select your subscription', 'Postmatic');
     }
     $batch_message_template = array('subject' => $subject, 'from_name' => get_option('blogname'), 'message_type' => Prompt_Enum_Message_Types::SUBSCRIPTION, 'html_content' => $html_template->render($message_data), 'text_content' => $text_template->render($message_data), 'reply_to' => '{{{reply_to}}}');
     // Override template with message data
     foreach ($batch_message_template as $name => $value) {
         if (isset($message_data[$name])) {
             $batch_message_template[$name] = $message_data[$name];
         }
     }
     $batch_message_template['footnote_html'] = $this->footnote_html($batch_message_template['message_type']);
     $batch_message_template['footnote_text'] = $this->footnote_text($batch_message_template['message_type']);
     parent::__construct($batch_message_template);
 }
示例#2
0
 /**
  * Builds an email without specific recipient info that can be used as a template for all recipients.
  *
  * The set_recipient method can be called to fill in recipient-specific fields.
  *
  * @since 2.0.0
  *
  * @param Prompt_Post_Rendering_Context $context      Rendering context for the target post
  * @param array                         $args         {
  * @type bool                           $excerpt_only Override the excerpt only checkbox in the delivery metabox.
  *                                                    }
  */
 public function __construct(Prompt_Post_Rendering_Context $context, $args = array())
 {
     $this->context = $context;
     $context->setup();
     $prompt_author = $context->get_author();
     $prompt_post = $context->get_post();
     $is_api_delivery = Prompt_Enum_Email_Transports::API == Prompt_Core::$options->get('email_transport');
     $will_strip_content = (!$is_api_delivery and $context->has_fancy_content());
     $subject = html_entity_decode($prompt_post->get_wp_post()->post_title, ENT_QUOTES);
     list($footnote_html, $footnote_text) = $this->footnote_content();
     if ('draft' == $prompt_post->get_wp_post()->post_status) {
         /* translators: %s is a post title */
         $subject = sprintf(__('PREVIEW of %s', 'Postmatic'), $subject);
         $footnote_html = $footnote_text = '';
     }
     $excerpt_only = Prompt_Admin_Delivery_Metabox::excerpt_only($prompt_post->id());
     if (isset($args['excerpt_only'])) {
         $excerpt_only = $args['excerpt_only'];
     }
     $this->comments = get_approved_comments($prompt_post->id());
     $template_data = array('prompt_author' => $prompt_author, 'prompt_post' => $prompt_post, 'featured_image_src' => $context->get_the_featured_image_src(), 'excerpt_only' => $excerpt_only, 'the_text_content' => $context->get_the_text_content(), 'subject' => $subject, 'alternate_versions_menu' => $context->alternate_versions_menu(), 'is_api_delivery' => $is_api_delivery, 'will_strip_content' => $will_strip_content, 'comments' => $this->comments);
     /**
      * Filter new post email template data.
      *
      * @param array      $template_data      {
      * @type Prompt_User $prompt_author
      * @type Prompt_Post $prompt_post
      * @type array       $featured_image_src url, width, height
      * @type bool        $excerpt_only       whether to include only the post excerpt
      * @type string      $the_text_content
      * @type string      $subject
      * @type bool        $is_api_delivery
      * @type bool        $will_strip_content
      *                                       }
      */
     $template_data = apply_filters('prompt/post_email/template_data', $template_data);
     $html_template = new Prompt_Template("new-post-email.php");
     $text_template = new Prompt_Text_Template("new-post-email-text.php");
     $batch_message_template = array('subject' => $subject, 'from_name' => '{{{from_name}}}', 'text_content' => $text_template->render($template_data), 'html_content' => $html_template->render($template_data), 'message_type' => Prompt_Enum_Message_Types::POST, 'reply_to' => '{{{reply_to}}}', 'footnote_html' => $footnote_html, 'footnote_text' => $footnote_text);
     $this->replyable = (comments_open($prompt_post->id()) and !$excerpt_only);
     if (!$this->replyable) {
         $batch_message_template['from_address'] = $prompt_author->get_wp_user()->user_email;
     }
     $default_values = array('from_name' => $this->to_utf8(get_option('blogname')));
     $context->reset();
     parent::__construct($batch_message_template, array(), $default_values);
 }
 /**
  * Builds an email batch with content and recipients based on a comment.
  *
  * @since 2.0.0
  *
  * @param object $comment Target comment
  * @param Prompt_Comment_Flood_Controller
  */
 public function __construct($comment, Prompt_Comment_Flood_Controller $flood_controller = null)
 {
     $this->comment = $comment;
     $this->prompt_post = $prompt_post = new Prompt_Post($this->comment->comment_post_ID);
     $this->flood_controller = $flood_controller ? $flood_controller : new Prompt_Comment_Flood_Controller($comment);
     $this->subscribed_post_title_link = html('a', array('href' => get_permalink($this->prompt_post->id())), get_the_title($this->prompt_post->id()));
     $comment_author = $this->comment_author_user();
     $is_api_delivery = Prompt_Enum_Email_Transports::API == Prompt_Core::$options->get('email_transport');
     $parent_comment = $parent_author = null;
     $parent_author_name = '';
     $template_file = 'new-comment-email.php';
     if ($this->comment->comment_parent) {
         $parent_comment = get_comment($this->comment->comment_parent);
         $parent_author = get_userdata($parent_comment->user_id);
         $parent_author_name = $parent_author ? $parent_author->display_name : $parent_comment->comment_author;
         $parent_author_name = $parent_author_name ? $parent_author_name : __('Anonymous', 'Postmatic');
         $template_file = $is_api_delivery ? 'comment-reply-email.php' : $template_file;
     }
     $this->parent_comment = $parent_comment;
     $this->parent_author = $parent_author;
     $this->parent_author_name = $parent_author_name;
     $commenter_name = $comment_author ? $comment_author->display_name : $this->comment->comment_author;
     $commenter_name = $commenter_name ? $commenter_name : __('Anonymous', 'Postmatic');
     $this->commenter_name = $commenter_name;
     $post_author = get_userdata($prompt_post->get_wp_post()->post_author);
     $post_author_name = $post_author ? $post_author->display_name : __('Anonymous', 'Postmatic');
     $this->set_previous_comments();
     $template_data = array('comment_author' => $comment_author, 'comment' => $this->comment, 'commenter_name' => $commenter_name, 'subscribed_post' => $prompt_post, 'subscribed_post_author_name' => $post_author_name, 'subscribed_post_title_link' => $this->subscribed_post_title_link, 'previous_comments' => $this->previous_comments, 'parent_author' => $parent_author, 'parent_author_name' => $parent_author_name, 'parent_comment' => $parent_comment, 'comment_header' => true, 'is_api_delivery' => $is_api_delivery);
     /**
      * Filter comment email template data.
      *
      * @param array $template_data {
      * @type WP_User $comment_author
      * @type WP_User $subscriber
      * @type object $comment
      * @type Prompt_post $subscribed_post
      * @type string $subscribed_post_author_name
      * @type array $previous_comments
      * @type WP_User $parent_author
      * @type string $parent_author_name
      * @type object $parent_comment
      * @type bool $comment_header
      * @type bool $is_api_delivery
      * }
      */
     $template_data = apply_filters('prompt/comment_email/template_data', $template_data);
     $html_template = new Prompt_Template($template_file);
     $text_template = new Prompt_Text_Template(str_replace('.php', '-text.php', $template_file));
     /* translators: %1$s is a subscription list title, %2$s the unsubscribe command */
     $footnote_format = __('You received this email because you\'re subscribed to %1$s. To no longer receive other comments or replies in this discussion reply with the word \'%2$s\'.', 'Postmatic');
     $message_template = array('from_name' => $commenter_name, 'text_content' => $text_template->render($template_data), 'html_content' => $html_template->render($template_data), 'message_type' => Prompt_Enum_Message_Types::COMMENT, 'subject' => '{{{subject}}}', 'reply_to' => '{{{reply_to}}}', 'footnote_html' => sprintf($footnote_format, $this->prompt_post->subscription_object_label(), "<a href=\"{$this->unsubscribe_mailto()}\">" . Prompt_Unsubscribe_Matcher::target() . "</a>"), 'footnote_text' => sprintf($footnote_format, $this->prompt_post->subscription_object_label(Prompt_Enum_Content_Types::TEXT), Prompt_Unsubscribe_Matcher::target()));
     parent::__construct($message_template);
     $recipient_ids = array_diff($this->flood_controlled_recipient_ids(), $this->sent_recipient_ids());
     /**
      * Filter whether to send new comment notifications.
      *
      * @param boolean $send Default true.
      * @param object $comment
      * @param array $recipient_ids
      */
     if (!apply_filters('prompt/send_comment_notifications', true, $this->comment, $recipient_ids)) {
         return null;
     }
     $this->add_recipients($recipient_ids);
 }