예제 #1
1
 /**
  * Get all messages
  *
  * @param WP_REST_Request $request
  * @return array|WP_Error
  */
 public function get_items($request)
 {
     /* filter messages */
     $args = array();
     $args['box'] = $request['box'];
     if ($request['box'] == 'starred') {
         $args['meta_query'] = array(array('key' => 'starred_by_user', 'value' => bp_loggedin_user_id()));
     }
     if (isset($request['filter'])) {
         $args = array_merge($args, $request['filter']);
         unset($args['filter']);
     }
     global $messages_template;
     $data = array();
     if (bp_has_message_threads($args)) {
         while (bp_message_threads()) {
             bp_message_thread();
             $single_msg = array('thread_id' => $messages_template->thread->thread_id, 'read' => bp_message_thread_has_unread() ? false : true, 'total_messages' => bp_get_message_thread_total_count($messages_template->thread->thread_id), 'unread_messages' => bp_get_message_thread_unread_count($messages_template->thread->thread_id), 'avatar' => bp_core_fetch_avatar(array('item_id' => $messages_template->thread->last_sender_id, 'width' => 25, 'height' => 25, 'html' => false)), 'from' => bp_core_get_username($messages_template->thread->last_sender_id), 'from_id' => $messages_template->thread->last_sender_id, 'last_message_date' => $messages_template->thread->last_message_date, 'subject' => bp_get_message_thread_subject(), 'excerpt' => bp_get_message_thread_excerpt(), 'content' => bp_get_message_thread_content());
             if (bp_is_active('messages', 'star')) {
                 $single_msg['star'] = strpos(bp_get_the_message_star_action_link(array('thread_id' => bp_get_message_thread_id())), 'unstar') ? true : false;
             }
             if ($args['box'] == 'sentbox') {
                 foreach ($messages_template->thread->recipients as $user => $userdata) {
                     if ((int) $user !== bp_loggedin_user_id()) {
                         $single_msg['to'][$user]['name'] = bp_core_get_username($user);
                     }
                 }
             }
             $links['self'] = array('href' => rest_url(sprintf(BP_API_SLUG . '/messages/%d', $messages_template->thread->thread_id)));
             if ($args['box'] == 'sentbox') {
                 $links['collection'] = array('href' => rest_url(BP_API_SLUG . '/messages?box=sentbox'));
             } else {
                 $links['collection'] = array('href' => rest_url(BP_API_SLUG . '/messages/'));
             }
             $single_msg['_links'] = $links;
             $data[] = $single_msg;
         }
     } else {
         return new WP_Error('bp_json_messages', __('No Messages Found.', BP_API_PLUGIN_SLUG), array('status' => 200));
     }
     $data = apply_filters('bp_json_prepare_messages', $data);
     return new WP_REST_Response($data, 200);
 }
예제 #2
0
	<?php 
    do_action('bp_after_member_messages_pagination');
    do_action('bp_before_member_messages_threads');
    ?>

	<table id="message-threads" class="messages-notices">
		<?php 
    while (bp_message_threads()) {
        bp_message_thread();
        ?>
			<tr id="m-<?php 
        bp_message_thread_id();
        ?>
" class="<?php 
        bp_message_css_class();
        if (bp_message_thread_has_unread()) {
            ?>
 unread"<?php 
        } else {
            ?>
 read"<?php 
        }
        ?>
>
				<td width="1%" class="thread-count">
					<span class="unread-count"><?php 
        bp_message_thread_unread_count();
        ?>
</span>
				</td>
				<td width="1%" class="thread-avatar"><?php 
예제 #3
0
			<?php bp_messages_pagination_count() ?>
		</div>

		<div class="pagination-links" id="messages-dir-pag">
			<?php bp_messages_pagination() ?>
		</div>

	</div><!-- .pagination -->

	<?php do_action( 'bp_after_member_messages_pagination' ) ?>
	<?php do_action( 'bp_before_member_messages_threads' ) ?>

	<table id="message-threads" class="zebra">
		<?php while ( bp_message_threads() ) : bp_message_thread(); ?>

			<tr id="m-<?php bp_message_thread_id() ?>"<?php if ( bp_message_thread_has_unread() ) : ?> class="unread"<?php else: ?> class="read"<?php endif; ?>>
				<td width="1%" class="thread-count">
					<span class="unread-count"><?php bp_message_thread_unread_count() ?></span>
				</td>
				<td width="1%" class="thread-avatar"><?php bp_message_thread_avatar() ?></td>

				<?php if ( 'sentbox' != bp_current_action() ) : ?>
					<td width="30%" class="thread-from">
						<?php _e( 'From:', 'buddypress' ); ?> <?php bp_message_thread_from() ?><br />
						<span class="activity"><?php bp_message_thread_last_post_date() ?></span>
					</td>
				<?php else: ?>
					<td width="30%" class="thread-from">
						<?php _e( 'To:', 'buddypress' ); ?> <?php bp_message_thread_to() ?><br />
						<span class="activity"><?php bp_message_thread_last_post_date() ?></span>
					</td>