function messages_action_view_message() { global $thread_id, $bp; if (!bp_is_messages_component() || !bp_is_current_action('view')) { return false; } $thread_id = (int) bp_action_variable(0); if (!$thread_id || !messages_is_valid_thread($thread_id) || !messages_check_thread_access($thread_id) && !is_super_admin()) { bp_core_redirect(bp_displayed_user_domain() . bp_get_messages_slug()); } // Check if a new reply has been submitted if (isset($_POST['send'])) { // Check the nonce check_admin_referer('messages_send_message', 'send_message_nonce'); // Send the reply if (messages_new_message(array('thread_id' => $thread_id, 'subject' => $_POST['subject'], 'content' => $_POST['content']))) { bp_core_add_message(__('Your reply was sent successfully', 'buddypress')); } else { bp_core_add_message(__('There was a problem sending your reply, please try again', 'buddypress'), 'error'); } bp_core_redirect(bp_displayed_user_domain() . bp_get_messages_slug() . '/view/' . $thread_id . '/'); } // Mark message read messages_mark_thread_read($thread_id); // Decrease the unread count in the nav before it's rendered $name = sprintf(__('Messages <span>%s</span>', 'buddypress'), bp_get_total_unread_messages_count()); $bp->bp_nav[$bp->messages->slug]['name'] = $name; do_action('messages_action_view_message'); bp_core_new_subnav_item(array('name' => sprintf(__('From: %s', 'buddypress'), BP_Messages_Thread::get_last_sender($thread_id)), 'slug' => 'view', 'parent_url' => trailingslashit(bp_displayed_user_domain() . bp_get_messages_slug()), 'parent_slug' => bp_get_messages_slug(), 'screen_function' => true, 'position' => 40, 'user_has_access' => bp_is_my_profile(), 'link' => bp_displayed_user_domain() . bp_get_messages_slug() . '/view/' . (int) $thread_id)); bp_core_load_template(apply_filters('messages_template_view_message', 'members/single/home')); }
function bp_messages_box_template( $user_id, $box, $per_page, $max, $type ) { $this->pag_page = isset( $_GET['mpage'] ) ? intval( $_GET['mpage'] ) : 1; $this->pag_num = isset( $_GET['num'] ) ? intval( $_GET['num'] ) : $per_page; $this->user_id = $user_id; $this->box = $box; $this->type = $type; if ( 'notices' == $this->box ) { $this->threads = BP_Messages_Notice::get_notices(); } else { $threads = BP_Messages_Thread::get_current_threads_for_user( $this->user_id, $this->box, $this->type, $this->pag_num, $this->pag_page ); $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( 'mpage', '%#%' ), 'format' => '', 'total' => ceil( (int)$this->total_thread_count / (int)$this->pag_num ), 'current' => $this->pag_page, 'prev_text' => '←', 'next_text' => '→', 'mid_size' => 1 ) ); } }
function messages_ajax_delete() { global $bp; if (!isset($_POST['thread_ids'])) { echo "-1[[split]]" . __('There was a problem deleting messages.', 'buddypress'); } else { $thread_ids = explode(',', $_POST['thread_ids']); for ($i = 0; $i < count($thread_ids); $i++) { BP_Messages_Thread::delete($thread_ids[$i]); } _e('Messages deleted.', 'buddypress'); } }
function __construct($user_id, $box, $per_page, $max, $type, $search_terms, $page_arg = 'mpage') { $this->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 bp_dtheme_ajax_messages_delete() { global $bp; if (!isset($_POST['thread_ids'])) { echo "-1<div id='message' class='error'><p>" . __('There was a problem deleting messages.', 'buddypress') . '</p></div>'; } else { $thread_ids = explode(',', $_POST['thread_ids']); for ($i = 0, $count = count($thread_ids); $i < $count; ++$i) { BP_Messages_Thread::delete($thread_ids[$i]); } _e('Messages deleted.', 'buddypress'); } }
function messages_is_valid_thread( $thread_id ) { return BP_Messages_Thread::is_valid( $thread_id ); }
/** * When a message is deleted, delete corresponding notifications. * * @since BuddyPress (2.0.0) * * @param int $thread_id ID of the thread. * @param array $message_ids IDs of the messages. */ function bp_messages_message_delete_notifications($thread_id, $message_ids) { if (!bp_is_active('notifications')) { return; } // For each recipient, delete notifications corresponding to each message. $thread = new BP_Messages_Thread($thread_id); foreach ($thread->get_recipients() as $recipient) { foreach ($message_ids as $message_id) { bp_notifications_delete_notifications_by_item_id($recipient->user_id, (int) $message_id, buddypress()->messages->id, 'new_message'); } } }
function bp_update_db_stuff() { $bp_prefix = bp_core_get_table_prefix(); // Rename the old user activity cached table if needed. if ($nxtdb->get_var("SHOW TABLES LIKE '%{$bp_prefix}bp_activity_user_activity_cached%'")) { $nxtdb->query("RENAME TABLE {$bp_prefix}bp_activity_user_activity_cached TO {$bp->activity->table_name}"); } // Rename fields from pre BP 1.2 if ($nxtdb->get_var("SHOW TABLES LIKE '%{$bp->activity->table_name}%'")) { if ($nxtdb->get_var("SHOW COLUMNS FROM {$bp->activity->table_name} LIKE 'component_action'")) { $nxtdb->query("ALTER TABLE {$bp->activity->table_name} CHANGE component_action type varchar(75) NOT NULL"); } if ($nxtdb->get_var("SHOW COLUMNS FROM {$bp->activity->table_name} LIKE 'component_name'")) { $nxtdb->query("ALTER TABLE {$bp->activity->table_name} CHANGE component_name component varchar(75) NOT NULL"); } } // On first installation - record all existing blogs in the system. if (!(int) $bp->site_options['bp-blogs-first-install']) { bp_blogs_record_existing_blogs(); bp_update_option('bp-blogs-first-install', 1); } if (is_multisite()) { bp_core_add_illegal_names(); } // Update and remove the message threads table if it exists if ($nxtdb->get_var("SHOW TABLES LIKE '%{$bp_prefix}bp_messages_threads%'")) { $update = BP_Messages_Thread::update_tables(); if ($update) { $nxtdb->query("DROP TABLE {$bp_prefix}bp_messages_threads"); } } }
/** * Mark a thread initialized in this class as unread. * * @since 1.0.0 * * @see BP_Messages_Thread::mark_as_unread() */ public function mark_unread() { BP_Messages_Thread::mark_as_unread($this->thread_id); }
function bp_dtheme_ajax_messages_delete() { // Bail if not a POST action if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) { return; } if (!isset($_POST['thread_ids'])) { echo "-1<div id='message' class='error'><p>" . __('There was a problem deleting messages.', 'buddypress') . '</p></div>'; } else { $thread_ids = explode(',', $_POST['thread_ids']); for ($i = 0, $count = count($thread_ids); $i < $count; ++$i) { BP_Messages_Thread::delete($thread_ids[$i]); } _e('Messages deleted.', 'buddypress'); } }
/** * Mark a private message as read in your inbox via a POST request. * * @return mixed String on error, void on success * @since BuddyPress (1.2) */ function bp_legacy_theme_ajax_message_markread() { // Bail if not a POST action if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) { return; } if (!isset($_POST['thread_ids'])) { echo "-1<div id='message' class='error'><p>" . __('There was a problem marking messages as read.', 'buddypress') . '</p></div>'; } else { $thread_ids = explode(',', $_POST['thread_ids']); for ($i = 0, $count = count($thread_ids); $i < $count; ++$i) { BP_Messages_Thread::mark_as_read((int) $thread_ids[$i]); } } exit; }
/** * Get the unread messages count for the current inbox. * * @return int */ function bp_get_total_unread_messages_count() { /** * Filters the unread messages count for the current inbox. * * @since 1.0.0 * * @param int $value Unread messages count for the current inbox. */ return apply_filters('bp_get_total_unread_messages_count', BP_Messages_Thread::get_inbox_count()); }
/** * @group is_valid */ public function test_is_valid_invalid_thread() { $this->assertEquals(null, BP_Messages_Thread::is_valid(999)); }
function messages_get_unread_count($user_id = false) { global $bp; if (!$user_id) { $user_id = $bp->loggedin_user->id; } return BP_Messages_Thread::get_inbox_count($user_id); }
/** * Constructor method. * * @param array $args { * Array of arguments. See bp_has_message_threads() for full description. * } */ public function __construct($args = array()) { // Backward compatibility with old method of passing arguments if (!is_array($args) || func_num_args() > 1) { _deprecated_argument(__METHOD__, '2.2.0', sprintf(__('Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress'), __METHOD__, __FILE__)); $old_args_keys = array(0 => 'user_id', 1 => 'box', 2 => 'per_page', 3 => 'max', 4 => 'type', 5 => 'search_terms', 6 => 'page_arg'); $func_args = func_get_args(); $args = bp_core_parse_args_array($old_args_keys, $func_args); } $r = wp_parse_args($args, array('page' => 1, 'per_page' => 10, 'page_arg' => 'mpage', 'box' => 'inbox', 'type' => 'all', 'user_id' => bp_loggedin_user_id(), 'max' => false, 'search_terms' => '', 'meta_query' => array())); $this->pag_arg = sanitize_key($r['page_arg']); $this->pag_page = bp_sanitize_pagination_arg($this->pag_arg, $r['page']); $this->pag_num = bp_sanitize_pagination_arg('num', $r['per_page']); $this->user_id = $r['user_id']; $this->box = $r['box']; $this->type = $r['type']; $this->search_terms = $r['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(array('user_id' => $this->user_id, 'box' => $this->box, 'type' => $this->type, 'limit' => $this->pag_num, 'page' => $this->pag_page, 'search_terms' => $this->search_terms, 'meta_query' => $r['meta_query'])); $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 (empty($r['max']) || (int) $r['max'] >= (int) $total_notice_count) { if ('notices' === $this->box) { $this->total_thread_count = (int) $total_notice_count; } } else { $this->total_thread_count = (int) $r['max']; } if (!empty($r['max'])) { if ((int) $r['max'] >= count($this->threads)) { $this->thread_count = count($this->threads); } else { $this->thread_count = (int) $r['max']; } } else { $this->thread_count = count($this->threads); } } if ((int) $this->total_thread_count && (int) $this->pag_num) { $pag_args = array($r['page_arg'] => '%#%'); if (defined('DOING_AJAX') && true === (bool) DOING_AJAX) { $base = remove_query_arg('s', wp_get_referer()); } else { $base = ''; } $add_args = array(); if (!empty($this->search_terms)) { $add_args['s'] = $this->search_terms; } $this->pag_links = paginate_links(array('base' => add_query_arg($pag_args, $base), '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, 'add_args' => $add_args)); } }