| 1 |
<?php |
| 2 |
/** |
| 3 |
* This template contains the messages from a friend on /friends/. |
| 4 |
* |
| 5 |
* @package Friends |
| 6 |
*/ |
| 7 |
|
| 8 |
$time_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' ); |
| 9 |
if ( false === strpos( $time_format, ':s' ) ) { |
| 10 |
$time_format = str_replace( 'H:i', 'H:i:s', $time_format ); |
| 11 |
$time_format = str_replace( 'g:i', 'g:i:s', $time_format ); |
| 12 |
} |
| 13 |
|
| 14 |
?> |
| 15 |
<div class="card mt-2 p-2 friends-profile-messages"> |
| 16 |
<div class="friends-profile-messages-header"> |
| 17 |
<strong><?php esc_html_e( 'Direct messages', 'friends' ); ?></strong> |
| 18 |
<a href="<?php echo esc_url( home_url( '/friends/messages/' ) ); ?>"><?php esc_html_e( 'View all', 'friends' ); ?></a> |
| 19 |
</div> |
| 20 |
<?php |
| 21 |
foreach ( $args['existing_messages']->get_posts() as $_post ) { |
| 22 |
$messages = get_posts( |
| 23 |
array( |
| 24 |
'post_parent' => $_post->ID, |
| 25 |
'post_type' => 'friend_message', |
| 26 |
'post_status' => array( 'friends_read', 'friends_unread' ), |
| 27 |
'order' => 'ASC', |
| 28 |
'numberposts' => -1, |
| 29 |
) |
| 30 |
); |
| 31 |
array_unshift( $messages, $_post ); |
| 32 |
|
| 33 |
$classes = array( 'friends-dm-conversation' => true ); |
| 34 |
$subject = false; |
| 35 |
$last_message_time = false; |
| 36 |
$unread_count = 0; |
| 37 |
foreach ( $messages as $message ) { |
| 38 |
if ( get_post_status( $message ) === 'friends_unread' ) { |
| 39 |
$classes['is-unread'] = true; |
| 40 |
++$unread_count; |
| 41 |
} |
| 42 |
$post_time = get_post_modified_time( 'U', true, $message ); |
| 43 |
if ( ! $last_message_time || $post_time > $last_message_time ) { |
| 44 |
$last_message_time = $post_time; |
| 45 |
|
| 46 |
$subject = get_the_title( $message ); |
| 47 |
if ( ! $subject ) { |
| 48 |
$subject = get_the_excerpt( $message ); |
| 49 |
} |
| 50 |
} |
| 51 |
} |
| 52 |
$conversation_url = add_query_arg( 'conversation', $_post->ID, home_url( '/friends/messages/' ) ); |
| 53 |
?> |
| 54 |
<a class="<?php echo esc_attr( implode( ' ', array_keys( $classes ) ) ); ?>" href="<?php echo esc_url( $conversation_url ); ?>"> |
| 55 |
<span class="friends-dm-conversation-main"> |
| 56 |
<span class="friends-dm-conversation-name"><?php echo esc_html( $args['friend_user']->display_name ); ?></span> |
| 57 |
<span class="friends-dm-conversation-preview"><?php echo esc_html( $subject ); ?></span> |
| 58 |
</span> |
| 59 |
<span class="friends-dm-conversation-meta"> |
| 60 |
<time title="<?php echo esc_attr( date_i18n( $time_format, $last_message_time ) ); ?>"> |
| 61 |
<?php echo esc_html( human_time_diff( $last_message_time ) ); ?> |
| 62 |
</time> |
| 63 |
<?php if ( $unread_count ) : ?> |
| 64 |
<span class="friends-dm-unread-count"><?php echo esc_html( number_format_i18n( $unread_count ) ); ?></span> |
| 65 |
<?php endif; ?> |
| 66 |
</span> |
| 67 |
</a> |
| 68 |
<?php |
| 69 |
} |
| 70 |
?> |
| 71 |
</div> |
| 72 |
|