/** * 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; }
/** * 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; }
/** * Get info of a message * * @global object $wpdb * @param int $message_id * @return array */ function cpm_getMessageInfo($message_id) { global $wpdb; $query = 'SELECT * FROM ' . CPM_DB_MSG . ' WHERE id = ' . $message_id; $message = $wpdb->get_row($query, ARRAY_A); $thread = cpm_getThreadInfo($message['thread_id']); $message['subject'] = $thread['subject']; $message['freshness'] = $thread['freshness']; $message['users'] = $thread['users']; return $message; }