bp_nouveau_get_thread_messages( int $thread_id, array $post )
messages for each thread.
Description
Parameters
- $post
-
(Required) $_POST data.
- $thread_id
-
(Required) thread id.
Source
File: bp-templates/bp-nouveau/includes/messages/ajax.php
function bp_nouveau_get_thread_messages( $thread_id, $post ) { global $thread_template, $media_template, $wpdb, $document_template; if ( ! $thread_id ) { return; } $bp = buddypress(); $reset_action = $bp->current_action; // Override bp_current_action(). $bp->current_action = 'view'; bp_get_thread( array( 'thread_id' => $thread_id ) ); $thread = new stdClass(); // Check recipients if connected or not. if ( bp_force_friendship_to_message() && bp_is_active( 'friends' ) ) { $recipients = (array) $thread_template->thread->recipients; // Strip the sender from the recipient list, and unset them if they are // not alone. If they are alone, let them talk to themselves. if ( isset( $recipients[ bp_loggedin_user_id() ] ) && ( count( $recipients ) > 1 ) ) { unset( $recipients[ bp_loggedin_user_id() ] ); } foreach ( $recipients as $recipient ) { if ( bp_loggedin_user_id() != $recipient->user_id && ! friends_check_friendship( bp_loggedin_user_id(), $recipient->user_id ) ) { if ( sizeof( $recipients ) > 1 ) { $thread->feedback_error = array( 'feedback' => __( 'You need to be connected with all recipients to continue this conversation.', 'buddyboss' ), 'type' => 'error', ); } else { $thread->feedback_error = array( 'feedback' => __( 'You need to be connected with this member to continue this conversation.', 'buddyboss' ), 'type' => 'error', ); } break; } } } $last_message_id = $thread_template->thread->messages[0]->id; $group_id = bp_messages_get_meta( $last_message_id, 'group_id', true ); $group_name = ''; $group_avatar = ''; $group_link = ''; $group_message_users = ''; $group_message_type = ''; $group_message_thread_type = ''; $group_message_fresh = ''; $message_from = ''; $is_deleted_group = 0; if ( ! empty( $group_id ) ) { $group_message_users = bp_messages_get_meta( $last_message_id, 'group_message_users', true ); $group_message_type = bp_messages_get_meta( $last_message_id, 'group_message_type', true ); $group_message_thread_type = bp_messages_get_meta( $last_message_id, 'group_message_thread_type', true ); $group_message_fresh = bp_messages_get_meta( $last_message_id, 'group_message_fresh', true ); $message_from = bp_messages_get_meta( $last_message_id, 'message_from', true ); if ( bp_is_active( 'groups' ) ) { $group_name = bp_get_group_name( groups_get_group( $group_id ) ); if ( empty( $group_name ) ) { $group_link = 'javascript:void(0);'; } else { $group_link = bp_get_group_permalink( groups_get_group( $group_id ) ); } $group_avatar = bp_core_fetch_avatar( array( 'item_id' => $group_id, 'object' => 'group', 'type' => 'full', 'avatar_dir' => 'group-avatars', 'alt' => sprintf( __( 'Group logo of %s', 'buddyboss' ), $group_name ), 'title' => $group_name, 'html' => false, ) ); } else { $prefix = apply_filters( 'bp_core_get_table_prefix', $wpdb->base_prefix ); $groups_table = $prefix . 'bp_groups'; $group_name = $wpdb->get_var( "SELECT `name` FROM `{$groups_table}` WHERE `id` = '{$group_id}';" ); // db call ok; no-cache ok; $group_link = 'javascript:void(0);'; $group_avatar = buddypress()->plugin_url . 'bp-core/images/mystery-group.png'; $legacy_group_avatar_name = '-groupavatar-full'; $legacy_user_avatar_name = '-avatar2'; if ( ! empty( $group_name ) ) { $group_link = 'javascript:void(0);'; $directory = 'group-avatars'; $avatar_size = '-bpfull'; $avatar_folder_dir = bp_core_avatar_upload_path() . '/' . $directory . '/' . $group_id; $avatar_folder_url = bp_core_avatar_url() . '/' . $directory . '/' . $group_id; $avatar = bp_core_get_group_avatar( $legacy_user_avatar_name, $legacy_group_avatar_name, $avatar_size, $avatar_folder_dir, $avatar_folder_url ); if ( '' !== $avatar ) { $group_avatar = $avatar; } } } $is_deleted_group = ( empty( $group_name ) ) ? 1 : 0; $group_name = ( empty( $group_name ) ) ? __( 'Deleted Group', 'buddyboss' ) : $group_name; } // Simulate the loop. $args = array( 'thread_id' => $thread_id, 'per_page' => isset( $post['per_page'] ) && $post['per_page'] ? $post['per_page'] : 10, 'before' => isset( $post['before'] ) && $post['before'] ? $post['before'] : null, ); if ( ! bp_thread_has_messages( $args ) ) { // Remove the bp_current_action() override. $bp->current_action = $reset_action; wp_send_json_error( $args['before'] ? $response_no_more : $response ); } if ( ! $group_id ) { $first_message = BP_Messages_Thread::get_first_message( bp_get_the_thread_id() ); $group_message_thread_id = bp_messages_get_meta( $first_message->id, 'group_message_thread_id', true ); // group $group_id = (int) bp_messages_get_meta( $first_message->id, 'group_id', true ); if ( $group_id ) { if ( bp_is_active( 'groups' ) ) { $group_name = bp_get_group_name( groups_get_group( $group_id ) ); $group_link = bp_get_group_permalink( groups_get_group( $group_id ) ); $group_avatar = bp_core_fetch_avatar( array( 'item_id' => $group_id, 'object' => 'group', 'type' => 'full', 'avatar_dir' => 'group-avatars', 'alt' => sprintf( __( 'Group logo of %s', 'buddyboss' ), $group_name ), 'title' => $group_name, 'html' => false, ) ); } else { $prefix = apply_filters( 'bp_core_get_table_prefix', $wpdb->base_prefix ); $groups_table = $prefix . 'bp_groups'; $group_name = $wpdb->get_var( "SELECT `name` FROM `{$groups_table}` WHERE `id` = '{$group_id}';" ); // db call ok; no-cache ok; $group_link = 'javascript:void(0);'; $group_avatar = buddypress()->plugin_url . 'bp-core/images/mystery-group.png'; $legacy_group_avatar_name = '-groupavatar-full'; $legacy_user_avatar_name = '-avatar2'; if ( ! empty( $group_name ) ) { $group_link = 'javascript:void(0);'; $directory = 'group-avatars'; $avatar_size = '-bpfull'; $avatar_folder_dir = bp_core_avatar_upload_path() . '/' . $directory . '/' . $group_id; $avatar_folder_url = bp_core_avatar_url() . '/' . $directory . '/' . $group_id; $avatar = bp_core_get_group_avatar( $legacy_user_avatar_name, $legacy_group_avatar_name, $avatar_size, $avatar_folder_dir, $avatar_folder_url ); if ( '' !== $avatar ) { $group_avatar = $avatar; } } } $group_name = ( empty( $group_name ) ) ? __( 'Deleted Group', 'buddyboss' ) : $group_name; } } $is_group_thread = 0; if ( (int) $group_id > 0 ) { $first_message = BP_Messages_Thread::get_first_message( bp_get_the_thread_id() ); $group_message_thread_id = bp_messages_get_meta( $first_message->id, 'group_message_thread_id', true ); // group $group_id = (int) bp_messages_get_meta( $first_message->id, 'group_id', true ); $message_users = bp_messages_get_meta( $first_message->id, 'group_message_users', true ); // all - individual $message_type = bp_messages_get_meta( $first_message->id, 'group_message_type', true ); // open - private $message_from = bp_messages_get_meta( $first_message->id, 'message_from', true ); // group if ( 'group' === $message_from && bp_get_the_thread_id() === (int) $group_message_thread_id && 'open' === $message_type ) { $is_group_thread = 1; unset($thread->feedback_error); } } $subject_deleted_text = apply_filters( 'delete_user_message_subject_text', 'Deleted' ); $is_participated = $wpdb->get_col( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_messages} WHERE thread_id = %d AND sender_id = %d AND subject != %s", $thread_template->thread->thread_id, bp_loggedin_user_id(), $subject_deleted_text ) ); // WPCS: db call ok. // WPCS: cache ok. $thread->thread = array( 'id' => bp_get_the_thread_id(), 'subject' => wp_strip_all_tags( bp_get_the_thread_subject() ), 'started_date' => bp_nouveau_get_message_date( $thread_template->thread->first_message_date, get_option( 'date_format' ) ), 'group_id' => $group_id, 'group_name' => html_entity_decode( ucwords( $group_name ) ), 'is_group_thread' => $is_group_thread, 'is_deleted' => $is_deleted_group, 'group_avatar' => $group_avatar, 'group_link' => $group_link, 'group_message_users' => $group_message_users, 'group_message_type' => $group_message_type, 'group_message_thread_type' => $group_message_thread_type, 'group_message_fresh' => $group_message_fresh, 'message_from' => $message_from, 'is_participated' => empty( $is_participated ) ? 0 : 1, ); if ( is_array( $thread_template->thread->recipients ) ) { foreach ( $thread_template->thread->recipients as $recipient ) { if ( empty( $recipient->is_deleted ) ) { $thread->thread['recipients'][] = array( 'avatar' => esc_url( bp_core_fetch_avatar( array( 'item_id' => $recipient->user_id, 'object' => 'user', 'type' => 'thumb', 'width' => BP_AVATAR_THUMB_WIDTH, 'height' => BP_AVATAR_THUMB_HEIGHT, 'html' => false, ) ) ), 'user_link' => bp_core_get_userlink( $recipient->user_id, false, true ), 'user_name' => bp_core_get_user_displayname( $recipient->user_id ), 'is_deleted' => empty( get_userdata( $recipient->user_id ) ) ? 1 : 0, 'is_you' => $recipient->user_id === bp_loggedin_user_id(), ); } } } $thread->messages = array(); $i = 0; while ( bp_thread_messages() ) : bp_thread_the_message(); $group_id = bp_messages_get_meta( bp_get_the_thread_message_id(), 'group_id', true ); $group_message_users = bp_messages_get_meta( bp_get_the_thread_message_id(), 'group_message_users', true ); $group_message_type = bp_messages_get_meta( bp_get_the_thread_message_id(), 'group_message_type', true ); $group_message_thread_type = bp_messages_get_meta( bp_get_the_thread_message_id(), 'group_message_thread_type', true ); $group_message_fresh = bp_messages_get_meta( bp_get_the_thread_message_id(), 'group_message_fresh', true ); $message_from = bp_messages_get_meta( bp_get_the_thread_message_id(), 'message_from', true ); $message_left = bp_messages_get_meta( bp_get_the_thread_message_id(), 'group_message_group_left', true ); $message_joined = bp_messages_get_meta( bp_get_the_thread_message_id(), 'group_message_group_joined', true ); $message_banned = bp_messages_get_meta( bp_get_the_thread_message_id(), 'group_message_group_ban', true ); $message_unbanned = bp_messages_get_meta( bp_get_the_thread_message_id(), 'group_message_group_un_ban', true ); $message_deleted = bp_messages_get_meta( bp_get_the_thread_message_id(), 'bp_messages_deleted', true ); if ( $group_id && $message_from && 'group' === $message_from ) { if ( bp_is_active( 'groups' ) ) { $group_name = bp_get_group_name( groups_get_group( $group_id ) ); if ( empty( $group_name ) ) { $group_link = 'javascript:void(0);'; } else { $group_link = bp_get_group_permalink( groups_get_group( $group_id ) ); } $group_avatar = bp_core_fetch_avatar( array( 'item_id' => $group_id, 'object' => 'group', 'type' => 'full', 'avatar_dir' => 'group-avatars', 'alt' => sprintf( __( 'Group logo of %s', 'buddyboss' ), $group_name ), 'title' => $group_name, 'html' => false, ) ); } else { $prefix = apply_filters( 'bp_core_get_table_prefix', $wpdb->base_prefix ); $groups_table = $prefix . 'bp_groups'; $group_name = $wpdb->get_var( "SELECT `name` FROM `{$groups_table}` WHERE `id` = '{$group_id}';" ); // db call ok; no-cache ok; $group_link = 'javascript:void(0);'; $group_avatar = buddypress()->plugin_url . 'bp-core/images/mystery-group.png'; $legacy_group_avatar_name = '-groupavatar-full'; $legacy_user_avatar_name = '-avatar2'; if ( ! empty( $group_name ) ) { $group_link = 'javascript:void(0);'; $directory = 'group-avatars'; $avatar_size = '-bpfull'; $avatar_folder_dir = bp_core_avatar_upload_path() . '/' . $directory . '/' . $group_id; $avatar_folder_url = bp_core_avatar_url() . '/' . $directory . '/' . $group_id; $avatar = bp_core_get_group_avatar( $legacy_user_avatar_name, $legacy_group_avatar_name, $avatar_size, $avatar_folder_dir, $avatar_folder_url ); if ( '' !== $avatar ) { $group_avatar = $avatar; } } } if ( empty( $group_name ) ) { $group_name = '"' . __( 'Deleted Group', 'buddyboss' ) . '"'; if ( $group_message_users && $group_message_type && 'all' === $group_message_users && 'open' === $group_message_type ) { $group_text = sprintf( __( 'Sent from group %s to all group members.', 'buddyboss' ), $group_name ); } elseif ( $group_message_users && $group_message_type && 'individual' === $group_message_users && 'open' === $group_message_type ) { $group_text = sprintf( __( 'Sent from group %s to the people in this conversation.', 'buddyboss' ), $group_name ); } elseif ( $group_message_users && $group_message_type && 'all' === $group_message_users && 'private' === $group_message_type ) { $group_text = sprintf( __( 'Sent from group %s individually to all group members.', 'buddyboss' ), $group_name ); } elseif ( $group_message_users && $group_message_type && 'individual' === $group_message_users && 'private' === $group_message_type ) { $group_text = sprintf( __( 'Sent from group %s to individual members.', 'buddyboss' ), $group_name ); } } else { if ( $group_message_users && $group_message_type && 'all' === $group_message_users && 'open' === $group_message_type ) { $group_text = sprintf( __( 'Sent from group <a href="%1$s">%2$s</a> to all group members.', 'buddyboss' ), $group_link, $group_name ); } elseif ( $group_message_users && $group_message_type && 'individual' === $group_message_users && 'open' === $group_message_type ) { $group_text = sprintf( __( 'Sent from group <a href="%1$s">%2$s</a> to the people in this conversation.', 'buddyboss' ), $group_link, $group_name ); } elseif ( $group_message_users && $group_message_type && 'all' === $group_message_users && 'private' === $group_message_type ) { $group_text = sprintf( __( 'Sent from group <a href="%1$s">%2$s</a> individually to all group members.', 'buddyboss' ), $group_link, $group_name ); } elseif ( $group_message_users && $group_message_type && 'individual' === $group_message_users && 'private' === $group_message_type ) { $group_text = sprintf( __( 'Sent from group <a href="%1$s">%2$s</a> to individual members.', 'buddyboss' ), $group_link, $group_name ); } } $content = ''; if ( $message_left && 'yes' === $message_left ) { $content = sprintf( __( '<p class="joined">Left "%s"</p>', 'buddyboss' ), ucwords( $group_name ) ); } elseif ( $message_deleted && 'yes' === $message_deleted ) { $content = '<p class="joined">' . __( 'This message was deleted.', 'buddyboss' ) . '</p>'; } elseif ( $message_unbanned && 'yes' === $message_unbanned ) { $content = sprintf( __( '<p class="joined">Removed Ban "%s"</p>', 'buddyboss' ), ucwords( $group_name ) ); } elseif ( $message_banned && 'yes' === $message_banned ) { $content = sprintf( __( '<p class="joined">Ban "%s"</p>', 'buddyboss' ), ucwords( $group_name ) ); } elseif ( $message_joined && 'yes' === $message_joined ) { $content = sprintf( __( '<p class="joined">Joined "%s"</p>', 'buddyboss' ), ucwords( $group_name ) ); } elseif ( 'This message was deleted.' === wp_strip_all_tags( bp_get_the_thread_message_content() ) ) { $content = '<p class="joined">' . wp_strip_all_tags( bp_get_the_thread_message_content() ) . '</p>'; } else { $content = do_shortcode( bp_get_the_thread_message_content() ); } $thread->messages[ $i ] = array( 'group_name' => $group_name, 'is_deleted' => $is_deleted_group, 'group_link' => $group_link, 'group_avatar' => $group_avatar, 'group_message_users' => $group_message_users, 'group_message_type' => $group_message_type, 'group_message_thread_type' => $group_message_thread_type, 'group_message_fresh' => $group_message_fresh, 'message_from' => $message_from, 'group_text' => $group_text, 'id' => bp_get_the_thread_message_id(), 'content' => $content, 'sender_id' => bp_get_the_thread_message_sender_id(), 'sender_name' => esc_html( bp_get_the_thread_message_sender_name() ), 'sender_link' => bp_get_the_thread_message_sender_link(), 'sender_is_you' => bp_get_the_thread_message_sender_id() === bp_loggedin_user_id(), 'sender_avatar' => esc_url( bp_core_fetch_avatar( array( 'item_id' => bp_get_the_thread_message_sender_id(), 'object' => 'user', 'type' => 'thumb', 'width' => 32, 'height' => 32, 'html' => false, ) ) ), 'date' => bp_get_the_thread_message_date_sent() * 1000, 'display_date' => bp_get_the_thread_message_time_since(), ); } else { $message_left = bp_messages_get_meta( bp_get_the_thread_message_id(), 'group_message_group_left', true ); $message_joined = bp_messages_get_meta( bp_get_the_thread_message_id(), 'group_message_group_joined', true ); $message_banned = bp_messages_get_meta( bp_get_the_thread_message_id(), 'group_message_group_ban', true ); $message_unbanned = bp_messages_get_meta( bp_get_the_thread_message_id(), 'group_message_group_un_ban', true ); $message_deleted = bp_messages_get_meta( bp_get_the_thread_message_id(), 'bp_messages_deleted', true ); $content = ''; if ( $message_left && 'yes' === $message_left ) { $content = sprintf( __( '<p class="joined">Left "%s"</p>', 'buddyboss' ), ucwords( $group_name ) ); } elseif ( $message_deleted && 'yes' === $message_deleted ) { $content = '<p class="joined">' . __( 'This message was deleted.', 'buddyboss' ) . '</p>'; } elseif ( $message_unbanned && 'yes' === $message_unbanned ) { $content = sprintf( __( '<p class="joined">Removed Ban "%s"</p>', 'buddyboss' ), ucwords( $group_name ) ); } elseif ( $message_banned && 'yes' === $message_banned ) { $content = sprintf( __( '<p class="joined">Ban "%s"</p>', 'buddyboss' ), ucwords( $group_name ) ); } elseif ( $message_joined && 'yes' === $message_joined ) { $content = sprintf( __( '<p class="joined">Joined "%s"</p>', 'buddyboss' ), ucwords( $group_name ) ); } elseif ( 'This message was deleted.' === wp_strip_all_tags( bp_get_the_thread_message_content() ) ) { $content = '<p class="joined">' . wp_strip_all_tags( bp_get_the_thread_message_content() ) . '</p>'; } else { $content = do_shortcode( bp_get_the_thread_message_content() ); } $thread->messages[ $i ] = array( 'id' => bp_get_the_thread_message_id(), 'content' => $content, 'sender_id' => bp_get_the_thread_message_sender_id(), 'sender_name' => esc_html( bp_get_the_thread_message_sender_name() ), 'is_deleted' => empty( get_userdata( bp_get_the_thread_message_sender_id() ) ) ? 1 : 0, 'sender_link' => bp_get_the_thread_message_sender_link(), 'sender_is_you' => bp_get_the_thread_message_sender_id() === bp_loggedin_user_id(), 'sender_avatar' => esc_url( bp_core_fetch_avatar( array( 'item_id' => bp_get_the_thread_message_sender_id(), 'object' => 'user', 'type' => 'thumb', 'width' => 32, 'height' => 32, 'html' => false, ) ) ), 'date' => bp_get_the_thread_message_date_sent() * 1000, 'display_date' => bp_get_the_thread_message_time_since(), ); } if ( bp_is_active( 'messages', 'star' ) ) { $star_link = bp_get_the_message_star_action_link( array( 'message_id' => bp_get_the_thread_message_id(), 'url_only' => true, ) ); $thread->messages[ $i ]['star_link'] = $star_link; $thread->messages[ $i ]['is_starred'] = array_search( 'unstar', explode( '/', $star_link ) ); $thread->messages[ $i ]['star_nonce'] = wp_create_nonce( 'bp-messages-star-' . bp_get_the_thread_message_id() ); } if ( bp_is_active( 'media' ) && bp_is_messages_media_support_enabled() ) { $media_ids = bp_messages_get_meta( bp_get_the_thread_message_id(), 'bp_media_ids', true ); if ( ! empty( $media_ids ) && bp_has_media( array( 'include' => $media_ids, 'privacy' => array( 'message' ), 'order_by' => 'menu_order', 'sort' => 'ASC', 'user_id' => false, ) ) ) { $thread->messages[ $i ]['media'] = array(); while ( bp_media() ) { bp_the_media(); $thread->messages[ $i ]['media'][] = array( 'id' => bp_get_media_id(), 'message_id' => bp_get_the_thread_message_id(), 'thread_id' => bp_get_the_thread_id(), 'title' => bp_get_media_title(), 'attachment_id' => bp_get_media_attachment_id(), 'thumbnail' => bp_get_media_attachment_image_thumbnail(), 'full' => bp_get_media_attachment_image(), 'meta' => $media_template->media->attachment_data->meta, 'privacy' => bp_get_media_privacy(), ); } } } if ( bp_is_active( 'media' ) && bp_is_messages_document_support_enabled() ) { $document_ids = bp_messages_get_meta( bp_get_the_thread_message_id(), 'bp_document_ids', true ); if ( ! empty( $document_ids ) && bp_has_document( array( 'include' => $document_ids, 'order_by' => 'menu_order', 'sort' => 'ASC', ) ) ) { $thread->messages[ $i ]['document'] = array(); while ( bp_document() ) { bp_the_document(); $attachment_id = bp_get_document_attachment_id(); $extension = bp_document_extension( $attachment_id ); $svg_icon = bp_document_svg_icon( $extension, $attachment_id ); $svg_icon_download = bp_document_svg_icon( 'download' ); $download_url = bp_document_download_link( $attachment_id, bp_get_document_id() ); $filename = basename( get_attached_file( $attachment_id ) ); $size = bp_document_size_format( filesize( get_attached_file( $attachment_id ) ) ); $extension_description = ''; $url = wp_get_attachment_url( $attachment_id ); $extension_lists = bp_document_extensions_list(); $text_attachment_url = wp_get_attachment_url( $attachment_id ); $attachment_url = bp_document_get_preview_image_url( bp_get_document_id(), $extension, bp_get_document_preview_attachment_id() ); $mirror_text = bp_document_mirror_text( $attachment_id ); $audio_url = ''; if ( in_array( $extension, bp_get_document_preview_doc_extensions(), true ) ) { $attachment_url = wp_get_attachment_url( bp_get_document_preview_attachment_id() ); } if ( in_array( $extension, bp_get_document_preview_music_extensions(), true ) ) { $audio_url = bp_document_get_preview_audio_url( bp_get_document_id(), $extension, $attachment_id ); } if ( ! empty( $extension_lists ) ) { $extension_lists = array_column( $extension_lists, 'description', 'extension' ); $extension_name = '.' . $extension; if ( ! empty( $extension_lists ) && ! empty( $extension ) && array_key_exists( $extension_name, $extension_lists ) ) { $extension_description = '<span class="document-extension-description">' . esc_html( $extension_lists[ $extension_name ] ) . '</span>'; } } $output = ''; ob_start(); if ( in_array( $extension, bp_get_document_preview_music_extensions(), true ) ) { $audio_url = bp_document_get_preview_audio_url( bp_get_document_id(), $extension, $attachment_id ); ?> <div class="document-audio-wrap"> <audio controls controlsList="nodownload"> <source src="<?php echo esc_url( $audio_url ); ?>" type="audio/mpeg"> <?php esc_html_e( 'Your browser does not support the audio element.', 'buddyboss' ); ?> </audio> </div> <?php } $attachment_url = bp_document_get_preview_image_url( bp_get_document_id(), $extension, bp_get_document_preview_attachment_id() ); if ( $attachment_url ) { ?> <div class="document-preview-wrap"> <img src="<?php echo esc_url( $attachment_url ); ?>" alt="" /> </div><!-- .document-preview-wrap --> <?php } $sizes = is_file( get_attached_file( $attachment_id ) ) ? get_attached_file( $attachment_id ) : 0; if ( $sizes && filesize( $sizes ) / 1e+6 < 2 ) { if ( in_array( $extension, bp_get_document_preview_code_extensions(), true ) ) { $data = bp_document_get_preview_text_from_attachment( $attachment_id ); $file_data = $data['text']; $more_text = $data['more_text'] ?> <div class="document-text-wrap"> <div class="document-text" data-extension="<?php echo esc_attr( $extension ); ?>"> <textarea class="document-text-file-data-hidden" style="display: none;"><?php echo wp_kses_post( $file_data ); ?></textarea> </div> <div class="document-expand"> <a href="#" class="document-expand-anchor"><i class="bb-icon-plus document-icon-plus"></i> <?php esc_html_e( 'Click to expand', 'buddyboss' ); ?></a> </div> </div> <!-- .document-text-wrap --> <?php if ( true === $more_text ) { printf( /* translators: %s: download string */ '<div class="more_text_view">%s</div>', sprintf( /* translators: %s: download url */ wp_kses_post( 'This file was truncated for preview. Please <a href="%s">download</a> to view the full file.', 'buddyboss' ), esc_url( $download_url ) ) ); } } } $output .= ob_get_clean(); $thread->messages[ $i ]['document'][] = array( 'id' => bp_get_document_id(), 'title' => bp_get_document_title(), 'attachment_id' => bp_get_document_attachment_id(), 'url' => $download_url, 'extension' => $extension, 'svg_icon' => $svg_icon, 'svg_icon_download' => $svg_icon_download, 'filename' => $filename, 'size' => $size, 'meta' => $document_template->document->attachment_data->meta, 'download_text' => __( 'Click to view', 'buddyboss' ), 'extension_description' => $extension_description, 'download' => __( 'Download', 'buddyboss' ), 'collapse' => __( 'Collapse', 'buddyboss' ), 'copy_download_link' => __( 'Copy Download Link', 'buddyboss' ), 'more_action' => __( 'More actions', 'buddyboss' ), 'preview' => $attachment_url, 'msg_preview' => $output, 'privacy' => bp_get_db_document_privacy(), 'author' => bp_get_document_user_id(), 'text_preview' => $text_attachment_url ? esc_url( $text_attachment_url ) : '', 'mp3_preview' => $audio_url ? $audio_url : '', 'document_title' => $filename ? $filename : '', 'mirror_text' => $mirror_text ? $mirror_text : '', ); } } } if ( bp_is_active( 'media' ) && bp_is_messages_gif_support_enabled() ) { $gif_data = bp_messages_get_meta( bp_get_the_thread_message_id(), '_gif_data', true ); if ( ! empty( $gif_data ) ) { $preview_url = wp_get_attachment_url( $gif_data['still'] ); $video_url = wp_get_attachment_url( $gif_data['mp4'] ); $thread->messages[ $i ]['gif'] = array( 'preview_url' => $preview_url, 'video_url' => $video_url, ); } } $extra_content = bp_nouveau_messages_catch_hook_content( array( 'beforeMeta' => 'bp_before_message_meta', 'afterMeta' => 'bp_after_message_meta', 'beforeContent' => 'bp_before_message_content', 'afterContent' => 'bp_after_message_content', ) ); if ( array_filter( $extra_content ) ) { $thread->messages[ $i ] = array_merge( $thread->messages[ $i ], $extra_content ); } $i += 1; endwhile; $thread->messages = array_filter( $thread->messages ); // Remove the bp_current_action() override. $bp->current_action = $reset_action; // pagination $thread->per_page = $thread_template->thread->messages_perpage; $thread->messages_count = $thread_template->thread->total_messages; $thread->next_messages_timestamp = $thread_template->thread->messages[ count( $thread_template->thread->messages ) - 1 ]->date_sent; return $thread; }
Changelog
Version | Description |
---|---|
BuddyBoss 1.3.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.