Exemplo n.º 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);
 }
Exemplo n.º 2
1
 /** @see WP_Widget::widget -- do not rename this */
 function widget($args, $instance)
 {
     extract($args);
     //Our variables from the widget settings.
     $title = apply_filters('widget_title', $instance['title']);
     $num = $instance['number'];
     $activity = $instance['activity'];
     $messages = $instance['messages'];
     $friends = $instance['friends'];
     if (!is_numeric($num)) {
         $num = 5;
     }
     $user_id = bp_loggedin_user_id();
     $width = $instance['width'];
     echo '<div class="' . $width . '"><div class="dash-widget">' . $before_widget;
     echo '<div id="vibe-tabs-student-activity" class="tabs tabbable">
           <ul class="nav nav-tabs clearfix">';
     if (isset($messages) && $messages && function_exists('messages_get_unread_count')) {
         echo '<li><a href="#tab-messages" data-toggle="tab"><i class="icon-bubble-talk-1"></i>' . messages_get_unread_count($user_id) . '</a></li>';
     }
     if (isset($friends) && $friends) {
         $searchArgs = array('type' => 'online', 'page' => 1, 'per_page' => $num, 'user_id' => $user_id);
         if (bp_has_members($searchArgs)) {
             while (bp_members()) {
                 bp_the_member();
                 $user_friends[] = array('avatar' => bp_get_member_avatar(), 'name' => bp_get_member_name(), 'last_active' => bp_get_member_last_active());
             }
         }
         if (!is_array($user_friends)) {
             $user_friends = array();
         }
         echo '<li><a href="#tab-friends" data-toggle="tab"><i class="icon-myspace-alt"></i>' . count($user_friends) . '</a></li>';
     }
     if (isset($activity) && $activity) {
         echo '<li><a href="#tab-activity" data-toggle="tab"><i class="icon-atom"></i>&nbsp;</a></li>';
     }
     echo '</ul><div class="tab-content">';
     // Display the widget title
     global $wpdb, $bp;
     if (isset($messages) && $messages) {
         echo '<div id="tab-messages" class="tab-pane">
   <h4>' . __('Unread Messages', 'wplms-dashboard') . '</h4>';
         $message_args = array('user_id' => $user_id, 'box' => 'inbox', 'type' => 'unread', 'max' => $num);
         if (bp_has_message_threads($message_args)) {
             echo '<ul class="dash-unread-messages">';
             while (bp_message_threads()) {
                 bp_message_thread();
                 echo '<li>' . bp_get_message_thread_avatar() . '<a href="' . bp_get_message_thread_view_link() . '">' . bp_get_message_thread_subject() . '<span>' . bp_get_message_thread_from() . '</span></a></li>';
             }
             echo '</ul>';
         } else {
             echo '<div class="message error">' . __('No messages found', 'wplms-dashboard') . '</div>';
         }
         echo '</div>';
     }
     if (isset($friends) && $friends) {
         echo '<div id="tab-friends" class="tab-pane">
   <h4>' . __('Friends Online', 'wplms-dashboard') . '</h4>';
         if (count($user_friends)) {
             echo '<ul class="dash-user-friends">';
             foreach ($user_friends as $user_friend) {
                 echo '<li>' . $user_friend['avatar'] . ' ' . $user_friend['name'] . '<span>' . $user_friend['last_active'] . '</span></li>';
             }
             echo '</ul>';
         } else {
             echo '<div class="message error">' . __('No friends online', 'wplms-dashboard') . '</div>';
         }
         echo '</div>';
     }
     if (isset($activity) && $activity) {
         $activities = apply_filters('wplms_dashboard_activity', $wpdb->get_results($wpdb->prepare("\n\t\t\tSELECT *\n\t\t    FROM {$bp->activity->table_name} AS activity\n\t\t    WHERE \tactivity.user_id IN (%d)\n\t\t    AND     (activity.action != '' OR activity.action IS NOT NULL)\n\t\t    ORDER BY activity.date_recorded DESC\n\t\t    LIMIT 0,{$num}\n\t\t", $user_id)));
         echo '<div id="tab-activity" class="tab-pane student_activity">
       <h4>' . __('Recent Activity', 'wplms-dashboard') . '</h4>';
         if (isset($activities) && is_array($activities)) {
             echo '<ul class="dash-activities">';
             foreach ($activities as $activity) {
                 if (isset($activity->action) && $activity->action != '') {
                     $time = tofriendlytime(time() - strtotime($activity->date_recorded));
                     echo '<li class="' . $activity->component . ' ' . $activity->type . '">
   						<div class="dash-activity">
   							<span class="dash-activity-time">' . $time . ' ' . __('AGO', 'wplms-dashboard') . '</span>
   								<strong>' . $activity->action . '</strong>
   						</div>
   					  </li>';
                 }
             }
             echo '</ul>';
         } else {
             echo '<div class="message error">' . __('No activity found', 'wplms-dashboard') . '</div>';
         }
         echo '</div>';
     }
     echo '</div></div>' . $after_widget . '</div></div>';
 }
Exemplo n.º 3
0
		<div class="pagination-links" id="messages-dir-pag">
			<?php 
    bp_messages_pagination();
    ?>
		</div>
	</div><!-- .pagination -->

	<?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 
        }
        ?>
>
Exemplo n.º 4
0
 /**
  * Returns an object with messages for the current user
  * @return Object Messages
  */
 public function get_messages()
 {
     /* Possible parameters:
      * String box: the box you the messages are in (possible values are 'inbox', 'sentbox', 'notices', default is 'inbox')
      * int per_page: items to be displayed per page (default 10)
      * boolean limit: maximum numbers of emtries (default no limit)
      */
     $this->initVars('message');
     $oReturn = new stdClass();
     $aParams['box'] = $this->box;
     $aParams['per_page'] = $this->per_page;
     $aParams['max'] = $this->limit;
     if (bp_has_message_threads($aParams)) {
         while (bp_message_threads()) {
             bp_message_thread();
             $aTemp = new stdClass();
             $aTemp->id = bp_get_message_thread_id();
             $aTemp->from = bp_get_message_thread_from();
             $aTemp->to = bp_get_message_thread_to();
             $aTemp->subject = bp_get_message_thread_subject();
             $aTemp->excerpt = bp_get_message_thread_excerpt();
             $aTemp->link = bp_get_message_thread_view_link();
             $oReturn->messages[] = $aTemp;
         }
     } else {
         return $this->error('message');
     }
     return $oReturn;
 }
Exemplo n.º 5
0
		<div class="pag-count" id="messages-dir-count">
			<?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_notices_pagination' ) ?>
	<?php do_action( 'bp_before_notices' ) ?>

	<table id="message-threads" class="zebra">
		<?php while ( bp_message_threads() ) : bp_message_thread(); ?>
			<tr>
				<td width="1%">
				</td>
				<td width="38%">
					<strong><?php bp_message_notice_subject() ?></strong>
					<?php bp_message_notice_text() ?>
				</td>
				<td width="21%">
					<strong><?php bp_message_is_active_notice() ?></strong>
					<span class="activity"><?php _e("Sent:", "buddypress"); ?> <?php bp_message_notice_post_date() ?></span>
				</td>

				<?php do_action( 'bp_notices_list_item' ) ?>

				<td width="10%">