pag_page = isset( $_GET[$page_arg] ) ? intval( $_GET[$page_arg] ) : 1; $this->pag_num = isset( $_GET['num'] ) ? intval( $_GET['num'] ) : $per_page; $this->user_id = $user_id; $this->box = $box; $this->type = $type; $this->search_terms = $search_terms; if ( 'notices' == $this->box ) { $this->threads = BP_Messages_Notice::get_notices( array( 'pag_num' => $this->pag_num, 'pag_page' => $this->pag_page ) ); } else { $threads = BP_Messages_Thread::get_current_threads_for_user( $this->user_id, $this->box, $this->type, $this->pag_num, $this->pag_page, $this->search_terms ); $this->threads = $threads['threads']; $this->total_thread_count = $threads['total']; } if ( !$this->threads ) { $this->thread_count = 0; $this->total_thread_count = 0; } else { $total_notice_count = BP_Messages_Notice::get_total_notice_count(); if ( !$max || $max >= (int) $total_notice_count ) { if ( 'notices' == $this->box ) { $this->total_thread_count = (int) $total_notice_count; } } else { $this->total_thread_count = (int) $max; } if ( $max ) { if ( $max >= count( $this->threads ) ) { $this->thread_count = count( $this->threads ); } else { $this->thread_count = (int) $max; } } else { $this->thread_count = count( $this->threads ); } } if ( (int) $this->total_thread_count && (int) $this->pag_num ) { $this->pag_links = paginate_links( array( 'base' => add_query_arg( $page_arg, '%#%' ), 'format' => '', 'total' => ceil( (int) $this->total_thread_count / (int) $this->pag_num ), 'current' => $this->pag_page, 'prev_text' => _x( '←', 'Message pagination previous text', 'buddypress' ), 'next_text' => _x( '→', 'Message pagination next text', 'buddypress' ), 'mid_size' => 1 ) ); } } function has_threads() { if ( $this->thread_count ) return true; return false; } function next_thread() { $this->current_thread++; $this->thread = $this->threads[$this->current_thread]; return $this->thread; } function rewind_threads() { $this->current_thread = -1; if ( $this->thread_count > 0 ) { $this->thread = $this->threads[0]; } } function message_threads() { if ( $this->current_thread + 1 < $this->thread_count ) { return true; } elseif ( $this->current_thread + 1 == $this->thread_count ) { do_action('messages_box_loop_end'); // Do some cleaning up after the loop $this->rewind_threads(); } $this->in_the_loop = false; return false; } function the_message_thread() { $this->in_the_loop = true; $this->thread = $this->next_thread(); if ( ! bp_is_current_action( 'notices' ) ) { $last_message_index = count( $this->thread->messages ) - 1; $this->thread->messages = array_reverse( (array) $this->thread->messages ); // Set up the last message data if ( count($this->thread->messages) > 1 ) { if ( 'inbox' == $this->box ) { foreach ( (array) $this->thread->messages as $key => $message ) { if ( bp_loggedin_user_id() != $message->sender_id ) { $last_message_index = $key; break; } } } elseif ( 'sentbox' == $this->box ) { foreach ( (array) $this->thread->messages as $key => $message ) { if ( bp_loggedin_user_id() == $message->sender_id ) { $last_message_index = $key; break; } } } } $this->thread->last_message_id = $this->thread->messages[$last_message_index]->id; $this->thread->last_message_date = $this->thread->messages[$last_message_index]->date_sent; $this->thread->last_sender_id = $this->thread->messages[$last_message_index]->sender_id; $this->thread->last_message_subject = $this->thread->messages[$last_message_index]->subject; $this->thread->last_message_content = $this->thread->messages[$last_message_index]->message; } // loop has just started if ( 0 == $this->current_thread ) { do_action('messages_box_loop_start'); } } } /** * Retrieve private message threads for display in inbox/sentbox/notices * * Similar to WordPress's have_posts() function, this function is responsible * for querying the database and retrieving private messages for display inside * the theme via individual template parts for a member's inbox/sentbox/notices. * * @since BuddyPress (1.0.0) * * @global BP_Messages_Box_Template $messages_template * @param array $args * @return object */ function bp_has_message_threads( $args = '' ) { global $messages_template; // The default box the user is looking at if ( bp_is_current_action( 'sentbox' ) ) { $default_box = 'sentbox'; } elseif ( bp_is_current_action( 'notices' ) ) { $default_box = 'notices'; } else { $default_box = 'inbox'; } // Parse the arguments $r = bp_parse_args( $args, array( 'user_id' => bp_loggedin_user_id(), 'box' => $default_box, 'per_page' => 10, 'max' => false, 'type' => 'all', 'search_terms' => isset( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : '', 'page_arg' => 'mpage', // See https://buddypress.trac.wordpress.org/ticket/3679 ), 'has_message_threads' ); // If trying to access notices without capabilities, redirect to root domain if ( bp_is_current_action( 'notices' ) && !bp_current_user_can( 'bp_moderate' ) ) { bp_core_redirect( bp_displayed_user_domain() ); } // Load the messages loop global up with messages $messages_template = new BP_Messages_Box_Template( $r['user_id'], $r['box'], $r['per_page'], $r['max'], $r['type'], $r['search_terms'], $r['page_arg'] ); return apply_filters( 'bp_has_message_threads', $messages_template->has_threads(), $messages_template, $r ); } function bp_message_threads() { global $messages_template; return $messages_template->message_threads(); } function bp_message_thread() { global $messages_template; return $messages_template->the_message_thread(); } function bp_message_thread_id() { echo bp_get_message_thread_id(); } function bp_get_message_thread_id() { global $messages_template; return apply_filters( 'bp_get_message_thread_id', $messages_template->thread->thread_id ); } function bp_message_thread_subject() { echo bp_get_message_thread_subject(); } function bp_get_message_thread_subject() { global $messages_template; return apply_filters( 'bp_get_message_thread_subject', stripslashes_deep( $messages_template->thread->last_message_subject ) ); } function bp_message_thread_excerpt() { echo bp_get_message_thread_excerpt(); } function bp_get_message_thread_excerpt() { global $messages_template; return apply_filters( 'bp_get_message_thread_excerpt', strip_tags( bp_create_excerpt( $messages_template->thread->last_message_content, 75 ) ) ); } /** * Output the thread's last message content * * When viewing your Inbox, the last message is the most recent message in * the thread of which you are *not* the author. * * When viewing your Sentbox, last message is the most recent message in * the thread of which you *are* the member. * * @since BuddyPress (2.0.0) */ function bp_message_thread_content() { echo bp_get_message_thread_content(); } /** * Return the thread's last message content * * When viewing your Inbox, the last message is the most recent message in * the thread of which you are *not* the author. * * When viewing your Sentbox, last message is the most recent message in * the thread of which you *are* the member. * * @since BuddyPress (2.0.0) * @return string The raw content of the last message in the thread */ function bp_get_message_thread_content() { global $messages_template; return apply_filters( 'bp_get_message_thread_content', $messages_template->thread->last_message_content ); } function bp_message_thread_from() { echo bp_get_message_thread_from(); } function bp_get_message_thread_from() { global $messages_template; return apply_filters( 'bp_get_message_thread_from', bp_core_get_userlink( $messages_template->thread->last_sender_id ) ); } function bp_message_thread_to() { echo bp_get_message_thread_to(); } function bp_get_message_thread_to() { global $messages_template; return apply_filters( 'bp_message_thread_to', BP_Messages_Thread::get_recipient_links($messages_template->thread->recipients ) ); } function bp_message_thread_view_link( $thread_id = 0 ) { echo bp_get_message_thread_view_link( $thread_id ); } function bp_get_message_thread_view_link( $thread_id = 0 ) { global $messages_template; if ( empty( $messages_template ) && (int) $thread_id > 0 ) { $thread_id = (int) $thread_id; } else { $thread_id = $messages_template->thread->thread_id; } return apply_filters( 'bp_get_message_thread_view_link', trailingslashit( bp_loggedin_user_domain() . buddypress()->messages->slug . '/view/' . $thread_id ) ); } function bp_message_thread_delete_link() { echo bp_get_message_thread_delete_link(); } function bp_get_message_thread_delete_link() { global $messages_template, $bp; return apply_filters( 'bp_get_message_thread_delete_link', wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . $bp->messages->slug . '/' . bp_current_action() . '/delete/' . $messages_template->thread->thread_id ), 'messages_delete_thread' ) ); } function bp_message_css_class() { echo bp_get_message_css_class(); } function bp_get_message_css_class() { global $messages_template; $class = false; if ( $messages_template->current_thread % 2 == 1 ) $class .= 'alt'; return apply_filters( 'bp_get_message_css_class', trim( $class ) ); } function bp_message_thread_has_unread() { global $messages_template; if ( $messages_template->thread->unread_count ) return true; return false; } function bp_message_thread_unread_count() { echo bp_get_message_thread_unread_count(); } function bp_get_message_thread_unread_count() { global $messages_template; if ( (int) $messages_template->thread->unread_count ) return apply_filters( 'bp_get_message_thread_unread_count', $messages_template->thread->unread_count ); return false; } function bp_message_thread_last_post_date() { echo bp_get_message_thread_last_post_date(); } function bp_get_message_thread_last_post_date() { global $messages_template; return apply_filters( 'bp_get_message_thread_last_post_date', bp_format_time( strtotime( $messages_template->thread->last_message_date ) ) ); } /** * Output the avatar for the last sender in the current message thread. * * @see bp_get_message_thread_avatar() for a description of arguments. * * @param array $args See {@link bp_get_message_thread_avatar()}. */ function bp_message_thread_avatar( $args = '' ) { echo bp_get_message_thread_avatar( $args ); } /** * Return the avatar for the last sender in the current message thread. * * @see bp_core_fetch_avatar() For a description of arguments and * return values. * * @param array $args { * Arguments are listed here with an explanation of their defaults. * For more information about the arguments, see * {@link bp_core_fetch_avatar()}. * @type string $type Default: 'thumb'. * @type int|bool $width Default: false. * @type int|bool $height Default: false. * @type string $class Default: 'avatar'. * @type string|bool $id Default: false. * @type string $alt Default: 'Profile picture of [display name]'. * } * @return User avatar string. */ function bp_get_message_thread_avatar( $args = '' ) { global $messages_template; $fullname = bp_core_get_user_displayname( $messages_template->thread->last_sender_id ); $defaults = array( 'type' => 'thumb', 'width' => false, 'height' => false, 'class' => 'avatar', 'id' => false, 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), $fullname ) ); $r = wp_parse_args( $args, $defaults ); return apply_filters( 'bp_get_message_thread_avatar', bp_core_fetch_avatar( array( 'item_id' => $messages_template->thread->last_sender_id, 'type' => $r['type'], 'alt' => $r['alt'], 'css_id' => $r['id'], 'class' => $r['class'], 'width' => $r['width'], 'height' => $r['height'], ) ) ); } function bp_total_unread_messages_count() { echo bp_get_total_unread_messages_count(); } function bp_get_total_unread_messages_count() { return apply_filters( 'bp_get_total_unread_messages_count', BP_Messages_Thread::get_inbox_count() ); } function bp_messages_pagination() { echo bp_get_messages_pagination(); } function bp_get_messages_pagination() { global $messages_template; return apply_filters( 'bp_get_messages_pagination', $messages_template->pag_links ); } function bp_messages_pagination_count() { global $messages_template; $start_num = intval( ( $messages_template->pag_page - 1 ) * $messages_template->pag_num ) + 1; $from_num = bp_core_number_format( $start_num ); $to_num = bp_core_number_format( ( $start_num + ( $messages_template->pag_num - 1 ) > $messages_template->total_thread_count ) ? $messages_template->total_thread_count : $start_num + ( $messages_template->pag_num - 1 ) ); $total = bp_core_number_format( $messages_template->total_thread_count ); echo sprintf( _n( 'Viewing message %1$s to %2$s (of %3$s message)', 'Viewing message %1$s to %2$s (of %3$s messages)', $total, 'buddypress' ), $from_num, $to_num, number_format_i18n( $total ) ); ?>
thread->is_active ) return true; return false; } /** * Output a string for the active notice * * Since 1.6 this function has been deprecated in favor of text in the theme * * @since BuddyPress (1.0) * @deprecated BuddyPress (1.6) * @uses bp_get_message_is_active_notice() */ function bp_message_is_active_notice() { echo bp_get_message_is_active_notice(); } /** * Returns a string for the active notice * * Since 1.6 this function has been deprecated in favor of text in the theme * * @since BuddyPress (1.0) * @deprecated BuddyPress (1.6) * @uses bp_messages_is_active_notice() */ function bp_get_message_is_active_notice() { $string = ''; if ( bp_messages_is_active_notice() ) $string = __( 'Currently Active', 'buddypress' ); return apply_filters( 'bp_get_message_is_active_notice', $string ); } function bp_message_notice_id() { echo bp_get_message_notice_id(); } function bp_get_message_notice_id() { global $messages_template; return apply_filters( 'bp_get_message_notice_id', $messages_template->thread->id ); } function bp_message_notice_post_date() { echo bp_get_message_notice_post_date(); } function bp_get_message_notice_post_date() { global $messages_template; return apply_filters( 'bp_get_message_notice_post_date', bp_format_time( strtotime($messages_template->thread->date_sent) ) ); } function bp_message_notice_subject() { echo bp_get_message_notice_subject(); } function bp_get_message_notice_subject() { global $messages_template; return apply_filters( 'bp_get_message_notice_subject', $messages_template->thread->subject ); } function bp_message_notice_text() { echo bp_get_message_notice_text(); } function bp_get_message_notice_text() { global $messages_template; return apply_filters( 'bp_get_message_notice_text', $messages_template->thread->message ); } function bp_message_notice_delete_link() { echo bp_get_message_notice_delete_link(); } function bp_get_message_notice_delete_link() { global $messages_template, $bp; return apply_filters( 'bp_get_message_notice_delete_link', wp_nonce_url( bp_loggedin_user_domain() . $bp->messages->slug . '/notices/delete/' . $messages_template->thread->id, 'messages_delete_thread' ) ); } function bp_message_activate_deactivate_link() { echo bp_get_message_activate_deactivate_link(); } function bp_get_message_activate_deactivate_link() { global $messages_template, $bp; if ( 1 == (int) $messages_template->thread->is_active ) { $link = wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . $bp->messages->slug . '/notices/deactivate/' . $messages_template->thread->id ), 'messages_deactivate_notice' ); } else { $link = wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . $bp->messages->slug . '/notices/activate/' . $messages_template->thread->id ), 'messages_activate_notice' ); } return apply_filters( 'bp_get_message_activate_deactivate_link', $link ); } function bp_message_activate_deactivate_text() { echo bp_get_message_activate_deactivate_text(); } function bp_get_message_activate_deactivate_text() { global $messages_template; if ( 1 == (int) $messages_template->thread->is_active ) { $text = __('Deactivate', 'buddypress'); } else { $text = __('Activate', 'buddypress'); } return apply_filters( 'bp_message_activate_deactivate_text', $text ); } /** * Output the messages component slug * * @package BuddyPress * @subpackage Messages Template * @since BuddyPress (1.5) * * @uses bp_get_messages_slug() */ function bp_messages_slug() { echo bp_get_messages_slug(); } /** * Return the messages component slug * * @package BuddyPress * @subpackage Messages Template * @since BuddyPress (1.5) */ function bp_get_messages_slug() { global $bp; return apply_filters( 'bp_get_messages_slug', $bp->messages->slug ); } function bp_message_get_notices() { $notice = BP_Messages_Notice::get_active(); if ( empty( $notice ) ) return false; $closed_notices = bp_get_user_meta( bp_loggedin_user_id(), 'closed_notices', true ); if ( !$closed_notices ) $closed_notices = array(); if ( is_array($closed_notices) ) { if ( !in_array( $notice->id, $closed_notices ) && $notice->id ) { ?> 'private_message', 'component' => 'messages', 'must_be_logged_in' => true, 'block_self' => true, 'wrapper_id' => 'send-private-message', 'link_href' => bp_get_send_private_message_link(), 'link_title' => __( 'Send a private message to this user.', 'buddypress' ), 'link_text' => __( 'Private Message', 'buddypress' ), 'link_class' => 'send-message', ) ) ) ); } function bp_message_loading_image_src() { echo bp_get_message_loading_image_src(); } function bp_get_message_loading_image_src() { global $bp; return apply_filters( 'bp_get_message_loading_image_src', $bp->messages->image_base . '/ajax-loader.gif' ); } function bp_message_get_recipient_tabs() { $recipients = explode( ' ', bp_get_message_get_recipient_usernames() ); foreach ( $recipients as $recipient ) { $user_id = bp_is_username_compatibility_mode() ? bp_core_get_userid( $recipient ) : bp_core_get_userid_from_nicename( $recipient ); if ( $user_id ) : ?>