示例#1
0
/**
 * 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);
            }
        }
    }
}
示例#2
0
/**
 * The HTML form to display the inbox
 * 
 * @global $current_user
 * @return string
 */
function cpm_page_inbox()
{
    $html = '<h2>' . __('Inbox', 'cubepm') . '</h2>';
    global $current_user;
    get_currentuserinfo();
    $user_id = $current_user->ID;
    $thread_ids = cpm_getUserInboxThreads($user_id);
    if (count($thread_ids) > 0) {
        $html .= '<table class="cpm-inbox">';
        $html .= '<thead>';
        $html .= '<tr>';
        $html .= '<th class="cpm-inbox-subject">' . __('Subject', 'cubepm') . '</th>';
        $html .= '<th class="cpm-inbox-from">' . __('From', 'cubepm') . '</th>';
        $html .= '<th class="cpm-inbox-received">' . __('Received', 'cubepm') . '</th>';
        $html .= '</tr>';
        $html .= '</thead>';
        $html .= '<tbody>';
        $count = 0;
        foreach ($thread_ids as $thread_id) {
            $count++;
            $thread = cpm_getThreadInfo($thread_id);
            $from = array();
            foreach ($thread['users'] as $thread_user_id) {
                if ($thread_user_id != $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>';
                    }
                }
            }
            if (count($from) > 0) {
                $from = implode('<span class="cpm-user-separator">, </span>', $from);
            } else {
                $from = '<i>' . __('Nobody', 'cubepm') . '</i>';
            }
            $html .= '<tr class="' . ($count % 2 == 0 ? 'even' : 'odd') . ' ' . (cpm_userCheckOpenedThread($user_id, $thread_id) ? 'opened' : 'unopened') . '">';
            $html .= '<td class="cpm-inbox-subject"><a href="' . cpm_buildURL(array('cpm_action' => 'read', 'cpm_id' => $thread['thread_id'])) . '">' . $thread['subject'] . '</a></td>';
            $html .= '<td class="cpm-inbox-from">' . $from . '</td>';
            $html .= '<td class="cpm-inbox-received">' . cpm_relativeTime($thread['freshness']) . '</td>';
            $html .= '</tr>';
        }
        $html .= '</tbody>';
        $html .= '</table>';
    } else {
        $html .= cpm_htmlMessage(__('You do not have any messages in your inbox!', 'cubepm'));
    }
    return $html;
}
示例#3
0
/**
 * CubePM HTML header
 * 
 * @todo Improve interface
 * 
 * @global $current_user;
 * @return string
 */
function cpm_header()
{
    $html = '<div class="cpm-header">';
    $html .= '<a class="cpm-button" href="' . cpm_buildURL(array('cpm_action' => 'inbox')) . '">' . __('Inbox', 'cubepm') . ' (' . cpm_inboxCount() . ')</a> ';
    if (cpm_currentUserCanStartThread()) {
        $html .= '<a class="cpm-button" href="' . cpm_buildURL(array('cpm_action' => 'new')) . '">' . __('New PM', 'cubepm') . '</a> ';
    }
    if (current_user_can('administrator')) {
        $html .= '<a class="cpm-button" href="' . cpm_buildURL(array('cpm_action' => 'admin-inbox')) . '">' . __('View all PMs', 'cubepm') . '</a> ';
    }
    $html .= '</div>';
    return $html;
}
示例#4
0
/**
 * Build HTML to show reply form
 * 
 * @todo Add reply form here
 * 
 * @param int $thread_id
 * @param int $user_id
 * @return string
 */
function cpm_page_read_buildReply($thread_id, $user_id, $cpm_errors = null)
{
    $html = '<a name="cpm-reply"></a>';
    $html .= '<h3>' . __('Reply', 'cubepm') . '</h3>';
    if ($cpm_errors != null) {
        if (count($cpm_errors->get_error_messages()) > 0) {
            $html .= cpm_htmlError($cpm_errors);
        } else {
            $html .= cpm_htmlMessage('Reply sent!', 'Success');
        }
    }
    $html .= '<table class="cpm-thread-reply">';
    $html .= '<tbody><tr><td>';
    $html .= '<form method="post" action="' . cpm_buildURL(array('cpm_action' => 'read', 'cpm_id' => $thread_id)) . '#cpm-reply">';
    $html .= '<input type="hidden" name="cpm_form_submit" value="1" />';
    $html .= '<p><textarea name="cpm_message" id="cpm_message">' . $cpm_message . '</textarea></p>';
    $html .= '<p><input type="submit" name="cpm_submit" id="cpm_submit" value="' . __('Reply', 'cubepm') . ' &raquo;" /></p>';
    $html .= '</form>';
    $html .= '</td></tr></tbody>';
    $html .= '</table>';
    return $html;
}
示例#5
0
/**
 * Filter that links names of users to send new PM
 * 
 * @param string $value
 * @param object $user
 * @return string
 */
function cpm_filter_sendPM($value, $user)
{
    return cpm_buildURL(array('cpm_action' => 'new', 'cpm_recipient' => $user->user_login));
}