/** @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> </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>'; }
/** * Format notifications for the Messages component. * * @since BuddyPress (1.0.0) * * @param string $action The kind of notification being rendered. * @param int $item_id The primary item id. * @param int $secondary_item_id The secondary item id. * @param int $total_items The total number of messaging-related notifications * waiting for the user. * @param string $format Return value format. 'string' for BuddyBar-compatible * notifications; 'array' for WP Toolbar. Default: 'string'. * * @return string|array Formatted notifications. */ function messages_format_notifications($action, $item_id, $secondary_item_id, $total_items, $format = 'string') { $total_items = (int) $total_items; $link = trailingslashit(bp_loggedin_user_domain() . bp_get_messages_slug() . '/inbox'); $title = __('Inbox', 'buddypress'); $amount = 'single'; if ('new_message' === $action) { if ($total_items > 1) { $amount = 'multiple'; $text = sprintf(__('You have %d new messages', 'buddypress'), $total_items); } else { $amount = 'single'; // get message thread ID $message = new BP_Messages_Message($item_id); $thread_id = $message->thread_id; $link = !empty($thread_id) ? bp_get_message_thread_view_link($thread_id) : false; if (!empty($secondary_item_id)) { $text = sprintf(__('%s sent you a new private message', 'buddypress'), bp_core_get_user_displayname($secondary_item_id)); } else { $text = sprintf(_n('You have %s new private message', 'You have %s new private messages', $total_items, 'buddypress'), bp_core_number_format($total_items)); } } } if ('string' === $format) { if (!empty($link)) { $retval = '<a href="' . esc_url($link) . '" title="' . esc_attr($title) . '">' . esc_html($text) . '</a>'; } else { $retval = esc_html($text); } /** * Filters the new message notification text before the notification is created. * * This is a dynamic filter. Possible filter names are: * - 'bp_messages_multiple_new_message_notification'. * - 'bp_messages_single_new_message_notification'. * * @param string $retval Notification text. * @param int $total_items Number of messages referred to by the notification. * @param string $text The raw notification test (ie, not wrapped in a link). * @param int $item_id ID of the associated item. * @param int $secondary_item_id ID of the secondary associated item. */ $return = apply_filters('bp_messages_' . $amount . '_new_message_notification', $retval, (int) $total_items, $text, $link, $item_id, $secondary_item_id); } else { /** This filter is documented in bp-messages/bp-messages-notifications.php */ $return = apply_filters('bp_messages_' . $amount . '_new_message_notification', array('text' => $text, 'link' => $link), $link, (int) $total_items, $text, $link, $item_id, $secondary_item_id); } /** * Fires right before returning the formatted message notifications. * * @since BuddyPress (1.0.0) * * @param string $action The type of message notification. * @param int $item_id The primary item ID. * @param int $secondary_item_id The secondary item ID. * @param int $total_items Total amount of items to format. */ do_action('messages_format_notifications', $action, $item_id, $secondary_item_id, $total_items); return $return; }
function bp_message_thread_view_link() { echo bp_get_message_thread_view_link(); }
/** * Output the permalink for a particular thread. * * @param int $thread_id Optional. ID of the thread. Default: current thread * being iterated on in the loop. */ function bp_message_thread_view_link($thread_id = 0) { echo bp_get_message_thread_view_link($thread_id); }
/** * Format notifications for the Messages component. * * @since 1.0.0 * * @param string $action The kind of notification being rendered. * @param int $item_id The primary item id. * @param int $secondary_item_id The secondary item id. * @param int $total_items The total number of messaging-related notifications * waiting for the user. * @param string $format Return value format. 'string' for BuddyBar-compatible * notifications; 'array' for WP Toolbar. Default: 'string'. * @return string|array Formatted notifications. */ function messages_format_notifications($action, $item_id, $secondary_item_id, $total_items, $format = 'string') { $total_items = (int) $total_items; $text = ''; $link = trailingslashit(bp_loggedin_user_domain() . bp_get_messages_slug() . '/inbox'); $title = __('Inbox', 'buddypress'); $amount = 'single'; if ('new_message' === $action) { if ($total_items > 1) { $amount = 'multiple'; $text = sprintf(__('You have %d new messages', 'buddypress'), $total_items); } else { // Get message thread ID. $message = new BP_Messages_Message($item_id); $thread_id = $message->thread_id; $link = !empty($thread_id) ? bp_get_message_thread_view_link($thread_id) : false; if (!empty($secondary_item_id)) { $text = sprintf(__('%s sent you a new private message', 'buddypress'), bp_core_get_user_displayname($secondary_item_id)); } else { $text = sprintf(_n('You have %s new private message', 'You have %s new private messages', $total_items, 'buddypress'), bp_core_number_format($total_items)); } } if ('string' === $format) { if (!empty($link)) { $return = '<a href="' . esc_url($link) . '" title="' . esc_attr($title) . '">' . esc_html($text) . '</a>'; } else { $return = esc_html($text); } /** * Filters the new message notification text before the notification is created. * * This is a dynamic filter. Possible filter names are: * - 'bp_messages_multiple_new_message_notification'. * - 'bp_messages_single_new_message_notification'. * * @param string $return Notification text. * @param int $total_items Number of messages referred to by the notification. * @param string $text The raw notification test (ie, not wrapped in a link). * @param int $item_id ID of the associated item. * @param int $secondary_item_id ID of the secondary associated item. */ $return = apply_filters('bp_messages_' . $amount . '_new_message_notification', $return, (int) $total_items, $text, $link, $item_id, $secondary_item_id); } else { /** This filter is documented in bp-messages/bp-messages-notifications.php */ $return = apply_filters('bp_messages_' . $amount . '_new_message_notification', array('text' => $text, 'link' => $link), $link, (int) $total_items, $text, $link, $item_id, $secondary_item_id); } // Custom notification action for the Messages component } else { if ('string' === $format) { $return = $text; } else { $return = array('text' => $text, 'link' => $link); } /** * Backcompat for plugins that used to filter bp_messages_single_new_message_notification * for their custom actions. These plugins should now use 'bp_messages_' . $action . '_notification' */ if (has_filter('bp_messages_single_new_message_notification')) { if ('string' === $format) { /** This filter is documented in bp-messages/bp-messages-notifications.php */ $return = apply_filters('bp_messages_single_new_message_notification', $return, (int) $total_items, $text, $link, $item_id, $secondary_item_id); // Notice that there are seven parameters instead of six? Ugh... } else { /** This filter is documented in bp-messages/bp-messages-notifications.php */ $return = apply_filters('bp_messages_single_new_message_notification', $return, $link, (int) $total_items, $text, $link, $item_id, $secondary_item_id); } } /** * Filters the custom action notification before the notification is created. * * This is a dynamic filter based on the message notification action. * * @since 2.6.0 * * @param array $value An associative array containing the text and the link of the notification * @param int $item_id ID of the associated item. * @param int $secondary_item_id ID of the secondary associated item. * @param int $total_items Number of messages referred to by the notification. * @param string $format Return value format. 'string' for BuddyBar-compatible * notifications; 'array' for WP Toolbar. Default: 'string'. */ $return = apply_filters("bp_messages_{$action}_notification", $return, $item_id, $secondary_item_id, $total_items, $format); } /** * Fires right before returning the formatted message notifications. * * @since 1.0.0 * * @param string $action The type of message notification. * @param int $item_id The primary item ID. * @param int $secondary_item_id The secondary item ID. * @param int $total_items Total amount of items to format. */ do_action('messages_format_notifications', $action, $item_id, $secondary_item_id, $total_items); return $return; }
/** * 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; }
/** * Format notifications for the Messages component. * * @since BuddyPress (1.0.0) * * @param string $action The kind of notification being rendered. * @param int $item_id The primary item id. * @param int $secondary_item_id The secondary item id. * @param int $total_items The total number of messaging-related notifications * waiting for the user * @param string $format Return value format. 'string' for BuddyBar-compatible * notifications; 'array' for WP Toolbar. Default: 'string'. * @return string|array Formatted notifications. */ function messages_format_notifications($action, $item_id, $secondary_item_id, $total_items, $format = 'string') { $total_items = (int) $total_items; $link = trailingslashit(bp_loggedin_user_domain() . bp_get_messages_slug() . '/inbox'); $title = __('Inbox', 'buddypress'); if ('new_message' === $action) { if ($total_items > 1) { $text = sprintf(__('You have %d new messages', 'buddypress'), $total_items); $filter = 'bp_messages_multiple_new_message_notification'; } else { // get message thread ID $message = new BP_Messages_Message($item_id); $thread_id = $message->thread_id; $link = !empty($thread_id) ? bp_get_message_thread_view_link($thread_id) : false; if (!empty($secondary_item_id)) { $text = sprintf(__('%s sent you a new private message', 'buddypress'), bp_core_get_user_displayname($secondary_item_id)); } else { $text = sprintf(_n('You have %s new private message', 'You have %s new private messages', $total_items, 'buddypress'), bp_core_number_format($total_items)); } $filter = 'bp_messages_single_new_message_notification'; } } if ('string' === $format) { if (!empty($link)) { $retval = '<a href="' . esc_url($link) . '" title="' . esc_attr($title) . '">' . esc_html($text) . '</a>'; } else { $retval = esc_html($text); } $return = apply_filters($filter, $retval, (int) $total_items, $text, $link, $item_id, $secondary_item_id); } else { $return = apply_filters($filter, array('text' => $text, 'link' => $link), $link, (int) $total_items, $text, $link, $item_id, $secondary_item_id); } do_action('messages_format_notifications', $action, $item_id, $secondary_item_id, $total_items); return $return; }