/** * Sends a message to subscribed users informing them of a new PM * * @global $current_user * @param $message_id */ function cpm_mail_new($message_id) { global $current_user; get_currentuserinfo(); $message = cpm_getMessageInfo($message_id); foreach ($message['users'] as $user_id) { if ($current_user->ID != $user_id && cpm_userCheckSubscription($user_id, $message['thread_id'])) { $user = get_user_by('id', $user_id); if ($user) { $to = $user->user_email; //$to = '*****@*****.**'; /** @todo Remove this: DEBUG */ $from_name = get_option('cpm_email_from_name'); $from_email = get_option('cpm_email_from_email'); $subject = get_option('cpm_email_subject'); $contents = nl2br(get_option('cpm_email_body')); $replace['%sender%'] = $current_user->display_name; $replace['%subject%'] = $message['subject']; $replace['%recipient%'] = $user->display_name; $replace['%blog_name%'] = get_bloginfo('name'); $replace['%blog_email%'] = get_bloginfo('admin_email'); $replace['%pm_link%'] = cpm_buildURL(array('cpm_action' => 'read', 'cpm_id' => $message['thread_id'])) . '#cpm-message-' . $message['id']; $replace['%message%'] = $message['message']; list($from_name, $from_email, $subject, $contents) = str_replace(array_keys($replace), $replace, array($from_name, $from_email, $subject, $contents)); $headers = "MIME-Version: 1.0\n" . 'From: ' . $from_name . ' <' . $from_email . '>' . "\n" . "Content-Type: text/html; charset=\"" . get_option('blog_charset') . "\"\n"; wp_mail($to, $subject, $contents, $headers); do_action('cpm_mail', $message_id, $user->ID); } } } }
/** * Build HTML to show thread info * * @todo Add thread info here * * @param bool $cpm_currentThread_isParticipant * @param int $thread_id * @param int $user_id * @return string */ function cpm_page_read_buildInfo($thread_id, $user_id) { global $cpm_currentThread_isParticipant; $thread = cpm_getThreadInfo($thread_id); $html = '<h2>'; $html .= $thread['subject']; $html .= '</h2>'; $html .= '<div class="cpm-thread-meta">'; $html .= '<div class="cpm-thread-meta-users">'; $html .= '<span class="cpm-thread-meta-label">' . __('Participants', 'cubepm') . ':</span> '; $from = array(); foreach ($thread['users'] as $thread_user_id) { $user = get_user_by('id', $thread_user_id); if ($user) { $from[] = '<span class="cpm-user" style="background-image:url(https://secure.gravatar.com/avatar/' . md5(strtolower(trim($user->user_email))) . '?s=16);"><a href="' . apply_filters('cpm_user_link', '#', $user) . '">' . $user->display_name . '</a></span>'; } } $html .= implode('<span class="cpm-user-separator">, </span>', $from); $html .= '</div>'; if ($cpm_currentThread_isParticipant && get_option('cpm_email_enabled')) { $html .= '<div class="cpm-thread-meta-subscribe">'; $html .= '<form method="post" action="' . cpm_buildURL(array('cpm_action' => 'read', 'cpm_id' => $thread_id)) . '">'; $html .= '<input type="hidden" name="cpm_subscribe" id="cpm_subscribe" value="1" />'; $html .= '<input type="checkbox" name="cpm_subscribe_value" id="cpm_subscribe_value" value="1" onclick="this.form.submit();"' . (cpm_userCheckSubscription($user_id, $thread_id) ? ' checked="yes"' : '') . ' />'; $html .= '<label for="cpm_subscribe_value">' . __('Notify me by email when I receive a reply to this conversation.', 'cubepm') . '</label>'; $html .= '</form>'; $html .= '<div class="clear"></div>'; $html .= '</div>'; } $html .= '</div>'; return $html; }