Пример #1
0
 /**
  * Send a comment a notification when their comment is rejected.
  *
  * This could be due to a deleted post, change in post status, or comments being closed.
  *
  * @param $user_id
  * @param $post_id
  */
 public static function send_rejected_notification($user_id, $post_id)
 {
     $comment_author = get_userdata($user_id);
     $post = get_post($post_id);
     $post_title = $post ? $post->post_title : __('a deleted post', 'Postmatic');
     $template_data = compact('comment_author', 'post', 'post_title');
     /**
      * Filter comment rejected email template data.
      *
      * @param array $template_data {
      *      @type WP_User $comment_author
      *      @type WP_Post $post
      *      @type string $post_title Post title or placeholder if post no longer exists
      * }
      */
     $template_data = apply_filters('prompt/comment_rejected_email/template_data', $template_data);
     $subject = sprintf(__('Unable to publish your reply to "%s"', 'Postmatic'), $post_title);
     $template = new Prompt_Template('comment-rejected-email.php');
     $batch = Prompt_Email_Batch::make_for_single_recipient(array('to_address' => $comment_author->user_email, 'subject' => $subject, 'html_content' => $template->render($template_data), 'message_type' => Prompt_Enum_Message_Types::ADMIN));
     /**
      * Filter comment rejected email.
      *
      * @param Prompt_Email_Batch $batch
      * @param array $template_data see prompt/comment_reject_email/template_data
      */
     $batch = apply_filters('prompt/comment_rejected_batch', $batch, $template_data);
     Prompt_Factory::make_mailer($batch)->send();
 }
 /**
  * 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);
 }
Пример #3
0
 /**
  * Convert HTML data to Markdown before rendering.
  *
  * @since 2.0.0
  *
  * @param array $data
  * @param bool|false $echo
  * @return string rendered text
  */
 public function render($data = array(), $echo = false)
 {
     foreach ($data as $key => $value) {
         $data[$key] = $this->convert_html_string_to_markdown($value);
     }
     return parent::render($data, $echo);
 }
Пример #4
0
 public function render($args, $echo = true)
 {
     $status = $this->execute($args);
     $data = array('site' => new Prompt_Site(), 'subscriber' => $this->subscriber, 'status' => $status, 'suppress_delivery' => true, 'footer_type' => Prompt_Enum_Email_Footer_Types::TEXT);
     $wrapper_template = new Prompt_Template('html-local-email-wrapper.php');
     $wrapper_template->render(array('html_content' => parent::render($data, false)), true);
 }
Пример #5
0
 /**
  * Send an email to a user who has had an account created for them.
  *
  * @param int|object $user
  * @param string $password
  * @param Prompt_Template $template
  */
 public static function send_new_user_notification($user, $password, $template)
 {
     $user = is_integer($user) ? get_userdata($user) : $user;
     $template_data = compact('user', 'password');
     /**
      * Filter new user email template data.
      *
      * @param array $template_data {
      * @type WP_User $user
      * @type string $password
      * }
      */
     $template_data = apply_filters('prompt/new_user_email/template_data', $template_data);
     $subject = sprintf(__('Welcome to %s', 'Postmatic'), get_option('blogname'));
     $batch = Prompt_Email_Batch::make_for_single_recipient(array('to_address' => $user->user_email, 'from_address' => get_option('admin_email'), 'subject' => $subject, 'html_content' => $template->render($template_data), 'message_type' => Prompt_Enum_Message_Types::ADMIN));
     /**
      * Filter new user email.
      *
      * @param Prompt_Email_Batch $batch
      * @param array $template_data {
      * @type WP_User $user
      * @type string $password
      * }
      */
     $batch = apply_filters('prompt/new_user_batch', $batch, $template_data);
     Prompt_Factory::make_mailer($batch)->send();
 }
Пример #6
0
 /**
  * Display an admin notice when a key is needed, and we are not on the settings page.
  */
 public function maybe_display()
 {
     if ($this->key or !current_user_can('manage_options')) {
         return;
     }
     if ($this->options_page->is_current_page()) {
         return;
     }
     $template = new Prompt_Template('activate-account-notice.php');
     echo $template->render(array('options_page_url' => $this->options_page->url()));
 }
Пример #7
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);
 }
Пример #8
0
 /**
  * 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);
 }
Пример #9
0
 /**
  * @since 2.0.0
  */
 protected function forward()
 {
     $text = $this->get_message_text();
     $from_user = get_user_by('id', $this->from_user_id);
     $to_user = get_user_by('id', $this->to_user_id);
     $command = new Prompt_Forward_Command();
     $command->set_keys(array('', '', $this->to_user_id, $this->from_user_id));
     $template_data = array('sender' => $from_user, 'message' => $text);
     $html_template = new Prompt_Template('forward-email.php');
     $batch = Prompt_Email_Batch::make_for_single_recipient(array('to_address' => $to_user->user_email, 'from_name' => $from_user->display_name, 'subject' => $this->message->subject, 'html_content' => $html_template->render($template_data), 'message_type' => Prompt_Enum_Message_Types::ADMIN, 'reply_to' => array('trackable-address' => Prompt_Command_Handling::get_command_metadata($command))));
     Prompt_Factory::make_mailer($batch)->send();
 }
 /**
  * @since 1.0.0
  * @return string
  */
 protected function render_intro()
 {
     $template = new Prompt_Template('mailchimp-import-intro.php');
     return $template->render();
 }
 protected function send_notifications($recipient_ids)
 {
     $template_data = array('post' => $this->prompt_post, 'comment_header' => true);
     /**
      * Filter comment email template data.
      *
      * @param array $template_data {
      * @type Prompt_post $post
      * @type bool $comment_header
      * }
      */
     $template_data = apply_filters('prompt/comment_flood_email/template_data', $template_data);
     $html_template = new Prompt_Template('comment-flood-email.php');
     $text_template = new Prompt_Text_Template('comment-flood-email-text.php');
     $footnote_html = sprintf(__('You received this email because you\'re subscribed to %s.', 'Postmatic'), $this->prompt_post->subscription_object_label());
     $batch = new Prompt_Email_Batch(array('subject' => __('We\'re pausing comment notices for you.', 'Postmatic'), 'text_content' => $text_template->render($template_data), 'html_content' => $html_template->render($template_data), 'message_type' => Prompt_Enum_Message_Types::SUBSCRIPTION, 'reply_to' => '{{{reply_to}}}', 'footnote_html' => $footnote_html, 'footnote_text' => Prompt_Content_Handling::reduce_html_to_utf8($footnote_html)));
     foreach ($recipient_ids as $recipient_id) {
         $subscriber = get_userdata($recipient_id);
         if (!$subscriber or !$subscriber->user_email) {
             continue;
         }
         $command = new Prompt_Comment_Flood_Command();
         $command->set_post_id($this->prompt_post->id());
         $command->set_user_id($recipient_id);
         $batch->add_individual_message_values(array('to_address' => $subscriber->user_email, 'reply_to' => Prompt_Email_Batch::trackable_address(Prompt_Command_Handling::get_command_metadata($command))));
     }
     /**
      * Filter comment notification email batch.
      *
      * @param Prompt_Email_Batch $batch
      * @param array $template_data see prompt/comment_email/template_data
      */
     $batch = apply_filters('prompt/comment_flood_email_batch', $batch, $template_data);
     Prompt_Factory::make_mailer($batch)->send();
 }
Пример #12
0
 /**
  * @since 1.0.0
  * @return string
  */
 protected function footer()
 {
     if (Prompt_Enum_Email_Transports::LOCAL != $this->options->get('email_transport')) {
         return '';
     }
     $footer_template = new Prompt_Template('email-options-tab-footer.php');
     $data = array('upgrade_url' => Prompt_Enum_Urls::PREMIUM, 'image_url' => path_join(Prompt_Core::$url_path, 'media/screenshots.jpg'));
     return $footer_template->render($data);
 }
Пример #13
0
 /**
  * @since 1.0.0
  */
 protected function display_key_prompt()
 {
     $new_site_url = Prompt_Enum_Urls::MANAGE . '/sites/link?ajax_url=' . urlencode(admin_url('admin-ajax.php'));
     $template = new Prompt_Template('get-a-key.php');
     $content = $template->render(compact('new_site_url'));
     echo $content;
 }
Пример #14
0
 /**
  * Render the email content in the local HTML document template.
  *
  * @since 2.0.0
  *
  */
 protected function render_batch_template()
 {
     $template = $this->batch->get_batch_message_template();
     if (strpos($template['html_content'], '<html') !== false) {
         // Already rendered
         return;
     }
     if (isset($template['html_content'])) {
         $html_template = new Prompt_Template('html-local-email-wrapper.php');
         $template['html_content'] = $html_template->render($template);
     }
     if (isset($template['text_content'])) {
         $text_template = new Prompt_Template('text-email-wrapper.php');
         $template['text_content'] = $text_template->render($template);
     }
     $this->batch->set_batch_message_template($template);
 }