Example #1
0
    ?>
</a>
    </p>

    <?php 
    /**
     * Fires before the display of the message thread list.
     *
     * @since BuddyPress (1.1.0)
     */
    do_action('bp_before_message_thread_list');
    ?>

    <?php 
    while (bp_thread_messages()) {
        bp_thread_the_message();
        ?>

      <div class="message-box <?php 
        bp_the_thread_message_css_class();
        ?>
">

        <div class="message-metadata">

          <?php 
        /** This action is documented in bp-templates/bp-legacy/buddypress-functions.php */
        do_action('bp_before_message_meta');
        ?>

          <?php 
/**
 * Send a private message reply to a thread via a POST request.
 *
 * @return string HTML
 * @since BuddyPress (1.2)
 */
function bp_legacy_theme_ajax_messages_send_reply()
{
    // Bail if not a POST action
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    check_ajax_referer('messages_send_message');
    $result = messages_new_message(array('thread_id' => (int) $_REQUEST['thread_id'], 'content' => $_REQUEST['content']));
    if (!empty($result)) {
        // pretend we're in the message loop
        global $thread_template;
        bp_thread_has_messages(array('thread_id' => (int) $_REQUEST['thread_id']));
        // set the current message to the 2nd last
        $thread_template->message = end($thread_template->thread->messages);
        $thread_template->message = prev($thread_template->thread->messages);
        // set current message to current key
        $thread_template->current_message = key($thread_template->thread->messages);
        // now manually iterate message like we're in the loop
        bp_thread_the_message();
        // manually call oEmbed
        // this is needed because we're not at the beginning of the loop
        bp_messages_embed();
        ?>

		<div class="message-box new-message <?php 
        bp_the_thread_message_css_class();
        ?>
">
			<div class="message-metadata">
				<?php 
        /**
         * Fires before the single message header is displayed.
         *
         * @since BuddyPress (1.1.0)
         */
        do_action('bp_before_message_meta');
        ?>
				<?php 
        echo bp_loggedin_user_avatar('type=thumb&width=30&height=30');
        ?>

				<strong><a href="<?php 
        echo bp_loggedin_user_domain();
        ?>
"><?php 
        bp_loggedin_user_fullname();
        ?>
</a> <span class="activity"><?php 
        printf(__('Sent %s', 'buddypress'), bp_core_time_since(bp_core_current_time()));
        ?>
</span></strong>

				<?php 
        /**
         * Fires after the single message header is displayed.
         *
         * @since BuddyPress (1.1.0)
         */
        do_action('bp_after_message_meta');
        ?>
			</div>

			<?php 
        /**
         * Fires before the message content for a private message.
         *
         * @since BuddyPress (1.1.0)
         */
        do_action('bp_before_message_content');
        ?>

			<div class="message-content">
				<?php 
        bp_the_thread_message_content();
        ?>
			</div>

			<?php 
        /**
         * Fires after the message content for a private message.
         *
         * @since BuddyPress (1.1.0)
         */
        do_action('bp_after_message_content');
        ?>

			<div class="clear"></div>
		</div>
	<?php 
        // clean up the loop
        bp_thread_messages();
    } else {
        echo "-1<div id='message' class='error'><p>" . __('There was a problem sending that reply. Please try again.', 'buddypress') . '</p></div>';
    }
    exit;
}
/**
 * Send a private message reply to a thread via a POST request.
 *
 * @since 1.2.0
 *
 * @return string HTML
 */
function bp_legacy_theme_ajax_messages_send_reply()
{
    // Bail if not a POST action.
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    check_ajax_referer('messages_send_message');
    $result = messages_new_message(array('thread_id' => (int) $_REQUEST['thread_id'], 'content' => $_REQUEST['content']));
    if (!empty($result)) {
        // Pretend we're in the message loop.
        global $thread_template;
        bp_thread_has_messages(array('thread_id' => (int) $_REQUEST['thread_id']));
        // Set the current message to the 2nd last.
        $thread_template->message = end($thread_template->thread->messages);
        $thread_template->message = prev($thread_template->thread->messages);
        // Set current message to current key.
        $thread_template->current_message = key($thread_template->thread->messages);
        // Now manually iterate message like we're in the loop.
        bp_thread_the_message();
        // Manually call oEmbed
        // this is needed because we're not at the beginning of the loop.
        bp_messages_embed();
        // Add new-message css class.
        add_filter('bp_get_the_thread_message_css_class', create_function('$retval', '
			$retval[] = "new-message";
			return $retval;
		'));
        // Output single message template part.
        bp_get_template_part('members/single/messages/message');
        // Clean up the loop.
        bp_thread_messages();
    } else {
        echo "-1<div id='message' class='error'><p>" . __('There was a problem sending that reply. Please try again.', 'buddypress') . '</p></div>';
    }
    exit;
}
Example #4
0
	<?php do_action( 'bp_before_message_thread_content' ) ?>

	<?php if ( bp_thread_has_messages() ) : ?>

		<h3 id="message-subject"><?php bp_the_thread_subject() ?></h3>

		<p id="message-recipients">
			<span class="highlight">
				<?php printf( __('Sent between %s and %s', 'buddypress'), bp_get_the_thread_recipients(), '<a href="' . bp_get_loggedin_user_link() . '" title="' . bp_get_loggedin_user_fullname() . '">' . bp_get_loggedin_user_fullname() . '</a>' ) ?>
			</span>
		</p>

		<?php do_action( 'bp_before_message_thread_list' ) ?>

		<?php while ( bp_thread_messages() ) : bp_thread_the_message(); ?>

			<div class="message-box">

				<div class="message-metadata">

					<?php do_action( 'bp_before_message_meta' ) ?>

					<?php bp_the_thread_message_sender_avatar( 'type=thumb&width=30&height=30' ) ?>
					<strong><a href="<?php bp_the_thread_message_sender_link() ?>" title="<?php bp_the_thread_message_sender_name() ?>"><?php bp_the_thread_message_sender_name() ?></a> <span class="activity"><?php bp_the_thread_message_time_since() ?></span></strong>

					<?php do_action( 'bp_after_message_meta' ) ?>

				</div><!-- .message-metadata -->

				<?php do_action( 'bp_before_message_content' ) ?>
/**
 * Send a private message reply to a thread via a POST request.
 *
 * @return string HTML
 * @since BuddyPress (1.2)
 */
function bp_legacy_theme_ajax_messages_send_reply()
{
    // Bail if not a POST action
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    check_ajax_referer('messages_send_message');
    $result = messages_new_message(array('thread_id' => (int) $_REQUEST['thread_id'], 'content' => $_REQUEST['content']));
    if (!empty($result)) {
        // Get the zebra line classes correct on ajax requests
        global $thread_template;
        bp_thread_has_messages(array('thread_id' => (int) $_REQUEST['thread_id']));
        bp_thread_the_message();
        if ($thread_template->message_count % 2 == 1) {
            $class = 'odd';
        } else {
            $class = 'even alt';
        }
        ?>

		<div class="message-box new-message <?php 
        echo $class;
        ?>
">
			<div class="message-metadata">
				<?php 
        do_action('bp_before_message_meta');
        ?>
				<?php 
        echo bp_loggedin_user_avatar('type=thumb&width=30&height=30');
        ?>

				<strong><a href="<?php 
        echo bp_loggedin_user_domain();
        ?>
"><?php 
        bp_loggedin_user_fullname();
        ?>
</a> <span class="activity"><?php 
        printf(__('Sent %s', 'buddypress'), bp_core_time_since(bp_core_current_time()));
        ?>
</span></strong>

				<?php 
        do_action('bp_after_message_meta');
        ?>
			</div>

			<?php 
        do_action('bp_before_message_content');
        ?>

			<div class="message-content">
				<?php 
        echo stripslashes(apply_filters('bp_get_the_thread_message_content', $_REQUEST['content']));
        ?>
			</div>

			<?php 
        do_action('bp_after_message_content');
        ?>

			<div class="clear"></div>
		</div>
	<?php 
    } else {
        echo "-1<div id='message' class='error'><p>" . __('There was a problem sending that reply. Please try again.', 'buddypress') . '</p></div>';
    }
    exit;
}
Example #6
0
 /**
  * Get a specific message
  *
  * @param WP_REST_Request $request
  * @return array|WP_Error
  */
 public function get_item($request)
 {
     global $thread_template;
     $id = $request['id'];
     if (bp_thread_has_messages(array('thread_id' => $id))) {
         $data = array();
         $data['thread_id'] = $id;
         $data['subject'] = bp_get_the_thread_subject();
         if (bp_is_active('messages', 'star')) {
             $data['star'] = strpos(bp_get_the_message_star_action_link(array('thread_id' => $id)), 'unstar') ? true : false;
         }
         if (bp_get_thread_recipients_count() <= 1) {
             $data['thread_title'] = __('You are alone in this conversation.', BP_API_PLUGIN_SLUG);
         } elseif (bp_get_max_thread_recipients_to_list() <= bp_get_thread_recipients_count()) {
             $data['thread_title'] = sprintf(__('Conversation between %s recipients.', BP_API_PLUGIN_SLUG), number_format_i18n(bp_get_thread_recipients_count()));
         } else {
             foreach ((array) $thread_template->thread->recipients as $recipient) {
                 if ((int) $recipient->user_id !== bp_loggedin_user_id()) {
                     $recipient_name = bp_core_get_user_displayname($recipient->user_id);
                     if (empty($recipient_name)) {
                         $recipient_name = __('Deleted User', BP_API_PLUGIN_SLUG);
                     }
                     $recipient_names[] = $recipient_name;
                 }
             }
             $data['thread_title'] = sprintf(__('Conversation between %s and you.'), implode(',', $recipient_names));
             $data['thread_msg'] = [];
             while (bp_thread_messages()) {
                 bp_thread_the_message();
                 $single_msg = (array) $thread_template->message;
                 $single_msg['sender_avatar'] = bp_core_fetch_avatar(array('item_id' => $thread_template->message->sender_id, 'width' => 25, 'height' => 25, 'html' => false));
                 $single_msg['sender_name'] = bp_get_the_thread_message_sender_name();
                 if (bp_is_active('messages', 'star')) {
                     $single_msg['star'] = bp_messages_is_message_starred($thread_template->message->id, bp_loggedin_user_id());
                 }
                 $data['thread_msg'][] = $single_msg;
             }
         }
     } else {
         return new WP_Error('bp_json_message', __('Message Not Found.', BP_API_PLUGIN_SLUG), array('status' => 404));
     }
     return new WP_REST_Response($data, 200);
 }