/**
 * Process a request to view a single message thread.
 */
function messages_action_conversation()
{
    // Bail if not viewing a single conversation
    if (!bp_is_messages_component() || !bp_is_current_action('view')) {
        return false;
    }
    // Get the thread ID from the action variable
    $thread_id = (int) bp_action_variable(0);
    if (!messages_is_valid_thread($thread_id) || !messages_check_thread_access($thread_id) && !bp_current_user_can('bp_moderate')) {
        bp_core_redirect(trailingslashit(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');
        $new_reply = messages_new_message(array('thread_id' => $thread_id, 'subject' => !empty($_POST['subject']) ? $_POST['subject'] : false, 'content' => $_POST['content']));
        // Send the reply
        if (!empty($new_reply)) {
            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);
    /**
     * Fires after processing a view request for a single message thread.
     *
     * @since BuddyPress (1.7.0)
     */
    do_action('messages_action_conversation');
}
Esempio n. 2
0
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 messages_action_conversation()
{
    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) && !bp_current_user_can('bp_moderate')) {
        bp_core_redirect(trailingslashit(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' => !empty($_POST['subject']) ? $_POST['subject'] : false, '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);
    do_action('messages_action_conversation');
}
function messages_screen_conversation()
{
    // Bail if not viewing a single message
    if (!bp_is_messages_component() || !bp_is_current_action('view')) {
        return false;
    }
    $thread_id = (int) bp_action_variable(0);
    if (empty($thread_id) || !messages_is_valid_thread($thread_id) || !messages_check_thread_access($thread_id) && !bp_current_user_can('bp_moderate')) {
        bp_core_redirect(trailingslashit(bp_displayed_user_domain() . bp_get_messages_slug()));
    }
    // Load up BuddyPress one time
    $bp = buddypress();
    // Decrease the unread count in the nav before it's rendered
    $bp->bp_nav[$bp->messages->slug]['name'] = sprintf(__('Messages <span>%s</span>', 'buddypress'), bp_get_total_unread_messages_count());
    do_action('messages_screen_conversation');
    bp_core_load_template(apply_filters('messages_template_view_message', 'members/single/home'));
}
Esempio n. 5
0
function messages_action_view_message() {
	global $bp, $thread_id;

	if ( $bp->current_component != $bp->messages->slug || $bp->current_action != 'view' )
		return false;

	$thread_id = $bp->action_variables[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->current_component );

	/* 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->current_component . '/view/' . $thread_id . '/' );
	}

	/* Mark message read */
	messages_mark_thread_read( $thread_id );

	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' => $bp->loggedin_user->domain . $bp->messages->slug . '/', 'parent_slug' => $bp->messages->slug, 'screen_function' => true, 'position' => 40, 'user_has_access' => bp_is_my_profile() ) );
	bp_core_load_template( apply_filters( 'messages_template_view_message', 'members/single/home' ) );
}
/**
 * Load an individual conversation screen.
 *
 * @since 1.0.0
 *
 * @return bool|null False on failure.
 */
function messages_screen_conversation()
{
    // Bail if not viewing a single message.
    if (!bp_is_messages_component() || !bp_is_current_action('view')) {
        return false;
    }
    $thread_id = (int) bp_action_variable(0);
    if (empty($thread_id) || !messages_is_valid_thread($thread_id) || !messages_check_thread_access($thread_id) && !bp_current_user_can('bp_moderate')) {
        bp_core_redirect(trailingslashit(bp_displayed_user_domain() . bp_get_messages_slug()));
    }
    // Load up BuddyPress one time.
    $bp = buddypress();
    // Decrease the unread count in the nav before it's rendered.
    $count = bp_get_total_unread_messages_count();
    $class = 0 === $count ? 'no-count' : 'count';
    $nav_name = sprintf(__('Messages <span class="%s">%s</span>', 'buddypress'), esc_attr($class), bp_core_number_format($count));
    $bp->bp_nav[$bp->messages->slug]['name'] = $nav_name;
    /**
     * Fires right before the loading of the Messages view screen template file.
     *
     * @since 1.7.0
     */
    do_action('messages_screen_conversation');
    /**
     * Filters the template to load for the Messages view screen.
     *
     * @since 1.0.0
     *
     * @param string $template Path to the messages template to load.
     */
    bp_core_load_template(apply_filters('messages_template_view_message', 'members/single/home'));
}
Esempio n. 7
0
 /**
  * Post by email routine.
  *
  * Validates the parsed data and posts the various BuddyPress content.
  *
  * @since 1.0-RC3
  *
  * @param bool $retval True by default.
  * @param array $data {
  *     An array of arguments.
  *
  *     @type array $headers Email headers.
  *     @type string $content The email body content.
  *     @type string $subject The email subject line.
  *     @type int $user_id The user ID who sent the email.
  *     @type bool $is_html Whether the email content is HTML or not.
  *     @type int $i The email message number.
  * }
  * @param array $params Parsed paramaters from the email address querystring.
  *   See {@link BP_Reply_By_Email_Parser::get_parameters()}.
  * @return array|object Array of the parsed item on success. WP_Error object
  *  on failure.
  */
 public function post($retval, $data, $params)
 {
     global $bp, $wpdb;
     // Activity reply
     if (!empty($params['a'])) {
         bp_rbe_log('Message #' . $data['i'] . ': this is an activity reply, checking if parent activities still exist');
         // Check to see if the root activity ID and the parent activity ID exist before posting
         $activity_count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$bp->activity->table_name} WHERE id IN ( %d, %d )", $params['a'], $params['p']));
         // If $a = $p, this means that we're replying to a top-level activity update
         // So check if activity count is 1
         if ($params['a'] == $params['p'] && $activity_count != 1) {
             //do_action( 'bp_rbe_imap_no_match', $this->connection, $i, $headers, 'root_activity_deleted' );
             return new WP_Error('root_activity_deleted');
             // If we're here, this means we're replying to an activity comment
             // If count != 2, this means either the super admin or activity author has deleted one of the update(s)
         } elseif ($params['a'] != $params['p'] && $activity_count != 2) {
             //do_action( 'bp_rbe_imap_no_match', $this->connection, $i, $headers, 'root_or_parent_activity_deleted' );
             return new WP_Error('root_or_parent_activity_deleted');
         }
         /* Let's start posting! */
         // Add our filter to override the activity action in bp_activity_new_comment()
         bp_rbe_activity_comment_action_filter($data['user_id']);
         $comment_id = bp_activity_new_comment(array('content' => $data['content'], 'user_id' => $data['user_id'], 'activity_id' => $params['a'], 'parent_id' => $params['p']));
         if (!$comment_id) {
             //do_action( 'bp_rbe_imap_no_match', $this->connection, $i, $headers, 'activity_comment_fail' );
             return new WP_Error('activity_comment_fail');
         }
         // special hook for RBE activity items
         // might want to do something like add some activity meta
         do_action('bp_rbe_new_activity', array('activity_id' => $comment_id, 'type' => 'activity_comment', 'user_id' => $data['user_id'], 'item_id' => $params['a'], 'secondary_item_id' => $params['p'], 'content' => $data['content']));
         bp_rbe_log('Message #' . $data['i'] . ': activity comment successfully posted!');
         // remove the filter after posting
         remove_filter('bp_activity_comment_action', 'bp_rbe_activity_comment_action');
         // return array of item on success
         return array('activity_comment_id' => $comment_id);
         // Private message reply
     } elseif (!empty($params['m'])) {
         if (bp_is_active($bp->messages->id)) {
             bp_rbe_log('Message #' . $data['i'] . ': this is a private message reply');
             // see if the PM thread still exists
             if (messages_is_valid_thread($params['m'])) {
                 // see if the user is in the PM conversation
                 $has_access = messages_check_thread_access($params['m'], $data['user_id']) || is_super_admin($data['user_id']);
                 if (!$has_access) {
                     //do_action( 'bp_rbe_imap_no_match', $this->connection, $i, $headers, 'private_message_not_in_thread' );
                     return new WP_Error('private_message_not_in_thread');
                 }
                 // post the PM!
                 $message_id = messages_new_message(array('thread_id' => $params['m'], 'sender_id' => $data['user_id'], 'content' => $data['content']));
                 if (!$message_id) {
                     //do_action( 'bp_rbe_imap_no_match', $this->connection, $i, $headers, 'private_message_fail' );
                     return new WP_Error('private_message_fail');
                 }
                 // special hook for RBE parsed PMs
                 do_action('bp_rbe_new_pm_reply', array('thread_id' => $params['m'], 'sender_id' => $data['user_id'], 'content' => $data['content']));
                 bp_rbe_log('Message #' . $data['i'] . ': PM reply successfully posted!');
                 // return array of item on success
                 return array('message_id' => $message_id);
                 // the PM thread doesn't exist anymore
             } else {
                 //do_action( 'bp_rbe_imap_no_match', $this->connection, $i, $headers, 'private_message_thread_deleted' );
                 return new WP_Error('private_message_thread_deleted');
             }
         }
     }
 }