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'));
}
function messages_action_bulk_delete()
{
    if (!bp_is_messages_component() || !bp_is_action_variable('bulk-delete', 0)) {
        return false;
    }
    $thread_ids = $_POST['thread_ids'];
    if (!$thread_ids || !messages_check_thread_access($thread_ids)) {
        bp_core_redirect(trailingslashit(bp_displayed_user_domain() . bp_get_messages_slug() . '/' . bp_current_action()));
    } else {
        if (!check_admin_referer('messages_delete_thread')) {
            return false;
        }
        if (!messages_delete_thread($thread_ids)) {
            bp_core_add_message(__('There was an error deleting messages.', 'buddypress'), 'error');
        } else {
            bp_core_add_message(__('Messages deleted.', 'buddypress'));
        }
        bp_core_redirect(trailingslashit(bp_displayed_user_domain() . bp_get_messages_slug() . '/' . bp_current_action()));
    }
}
Ejemplo n.º 3
0
 /**
  * Update a single message
  *
  * @param WP_REST_Request $request Full details about the request.
  * @return WP_Error|WP_REST_Response
  */
 public function update_item($request)
 {
     $id = (int) $request['id'];
     if (!messages_check_thread_access($id)) {
         return new WP_Error('bp_json_message_invalid_id', __('Message ID is invalid.'), array('status' => 400));
     }
     switch ($request['action']) {
         case 'read':
             messages_mark_thread_read($id);
             break;
         case 'unread':
             messages_mark_thread_unread($id);
             break;
         case 'star':
             $thread = new BP_Messages_thread($id);
             $mids = wp_list_pluck($thread->messages, 'id');
             bp_messages_star_set_action(array('action' => 'star', 'message_id' => $mids[0]));
             break;
         case 'unstar':
             bp_messages_star_set_action(array('action' => 'unstar', 'thread_id' => $id, 'bulk' => true));
             break;
             /* Single message */
             //            case 'star_single':
             //                bp_messages_star_set_action( array(
             //                    'action'     => 'star',
             //                    'message_id' => $id,
             //                ) );
             //                break;
             //            case 'unstar_single':
             //                bp_messages_star_set_action( array(
             //                    'action'     => 'unstar',
             //                    'message_id' => $id,
             //                ) );
             //                break;
     }
     $response = $this->get_item(array('id' => $id, 'context' => 'edit'));
     return rest_ensure_response($response);
 }
Ejemplo n.º 4
0
function messages_action_bulk_delete() {
	global $bp, $thread_ids;

	if ( $bp->current_component != $bp->messages->slug || $bp->action_variables[0] != 'bulk-delete' )
		return false;

	$thread_ids = $_POST['thread_ids'];

	if ( !$thread_ids || !messages_check_thread_access($thread_ids) ) {
		bp_core_redirect( $bp->displayed_user->domain . $bp->current_component . '/' . $bp->current_action );
	} else {
		if ( !check_admin_referer( 'messages_delete_thread' ) )
			return false;

		if ( !messages_delete_thread( $thread_ids ) ) {
			bp_core_add_message( __('There was an error deleting messages.', 'buddypress'), 'error' );
		} else {
			bp_core_add_message( __('Messages deleted.', 'buddypress') );
		}
		bp_core_redirect( $bp->loggedin_user->domain . $bp->current_component . '/' . $bp->current_action );
	}
}
Ejemplo n.º 5
0
/**
 * 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'));
}
/**
 * Save or delete star message meta according to a message's star status.
 *
 * @since 2.3.0
 *
 * @param array $args {
 *     Array of arguments.
 *     @type string $action     The star action. Either 'star' or 'unstar'. Default: 'star'.
 *     @type int    $thread_id  The message thread ID. Default: 0. If not zero, this takes precedence over
 *                              $message_id.
 *     @type int    $message_id The indivudal message ID to star or unstar.  Default: 0.
 *     @type int    $user_id    The user ID. Defaults to the logged-in user ID.
 *     @type bool   $bulk       Whether to mark all messages in a thread as a certain action. Only relevant
 *                              when $action is 'unstar' at the moment. Default: false.
 * }
 * @return bool
 */
function bp_messages_star_set_action($args = array())
{
    $r = wp_parse_args($args, array('action' => 'star', 'thread_id' => 0, 'message_id' => 0, 'user_id' => bp_loggedin_user_id(), 'bulk' => false));
    // Set thread ID.
    if (!empty($r['thread_id'])) {
        $thread_id = (int) $r['thread_id'];
    } else {
        $thread_id = messages_get_message_thread_id($r['message_id']);
    }
    if (empty($thread_id)) {
        return false;
    }
    // Check if user has access to thread.
    if (!messages_check_thread_access($thread_id, $r['user_id'])) {
        return false;
    }
    $is_starred = bp_messages_is_message_starred($r['message_id'], $r['user_id']);
    // Star.
    if ('star' == $r['action']) {
        if (true === $is_starred) {
            return true;
        } else {
            bp_messages_add_meta($r['message_id'], 'starred_by_user', $r['user_id']);
            return true;
        }
        // Unstar.
    } else {
        // Unstar one message.
        if (false === $r['bulk']) {
            if (false === $is_starred) {
                return true;
            } else {
                bp_messages_delete_meta($r['message_id'], 'starred_by_user', $r['user_id']);
                return true;
            }
            // Unstar all messages in a thread.
        } else {
            $thread = new BP_Messages_Thread($thread_id);
            $mids = wp_list_pluck($thread->messages, 'id');
            foreach ($mids as $mid) {
                if (true === bp_messages_is_message_starred($mid, $r['user_id'])) {
                    bp_messages_delete_meta($mid, 'starred_by_user', $r['user_id']);
                }
            }
            return true;
        }
    }
}
Ejemplo 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');
             }
         }
     }
 }