| 1 |
<?php |
| 2 |
/** |
| 3 |
* This template contains the content header part for an article on /friends/. |
| 4 |
* |
| 5 |
* @version 1.0 |
| 6 |
* @package Friends |
| 7 |
*/ |
| 8 |
|
| 9 |
$friend_user = $args['friend_user']; |
| 10 |
$avatar = $args['avatar']; |
| 11 |
$author_name = $args['friend_user']->display_name; |
| 12 |
|
| 13 |
/** |
| 14 |
* Allows overriding the authorname for a post. |
| 15 |
* |
| 16 |
* @param string $override_author_name The author name to override with. |
| 17 |
* @param string $author_name The author name. |
| 18 |
* @param int $post_id The post ID. |
| 19 |
* |
| 20 |
* Example: |
| 21 |
* ```php |
| 22 |
* add_filter( 'friends_override_author_name', function( $override_author_name, $author_name, $post_id ) { |
| 23 |
* if ( ! $override_author_name ) { // Only override if not already overridden. |
| 24 |
* $override_author_name = get_post_meta( $post_id, 'author', true ); |
| 25 |
* } |
| 26 |
* return $override_author_name; |
| 27 |
* }, 10, 3 ); |
| 28 |
* ``` |
| 29 |
*/ |
| 30 |
$override_author_name = apply_filters( 'friends_override_author_name', '', $author_name, get_the_id() ); |
| 31 |
|
| 32 |
/** |
| 33 |
* Allows modifying the avatar for a post. |
| 34 |
* |
| 35 |
* @param string $avatar The avatar. |
| 36 |
* @param string $friend_user The friend user if any. |
| 37 |
* @param int $post_id The post ID. |
| 38 |
* |
| 39 |
* Example: |
| 40 |
* ```php |
| 41 |
* add_filter( 'friends_author_avatar_url', function( $avatar, $friend_user, $post_id ) { |
| 42 |
* return get_avatar_url( 'mystery-man' ); |
| 43 |
* }, 10, 3 ); |
| 44 |
* ``` |
| 45 |
*/ |
| 46 |
$avatar = apply_filters( 'friends_author_avatar_url', $avatar, $friend_user, get_the_id() ); |
| 47 |
|
| 48 |
/** |
| 49 |
* Allows modifying the author URL for a post. |
| 50 |
* |
| 51 |
* @param string $author_url The author URL. |
| 52 |
* @param User $friend_user The friend user if any. |
| 53 |
* @param int $post_id The post ID. |
| 54 |
*/ |
| 55 |
$author_url = apply_filters( 'friends_author_url', $friend_user->get_local_friends_page_url(), $friend_user, get_the_id() ); |
| 56 |
?><header class="entry-header card-header columns"> |
| 57 |
<div class="avatar col-auto mr-2"> |
| 58 |
<?php if ( ! $avatar && in_array( get_post_type(), apply_filters( 'friends_frontend_post_types', array() ), true ) ) : ?> |
| 59 |
<a href="<?php echo esc_attr( $author_url ); ?>" class="author-avatar"><?php echo get_avatar( $args['friend_user']->user_login, 36 ); ?></a> |
| 60 |
<?php else : ?> |
| 61 |
<?php |
| 62 |
$activitypub_meta = get_post_meta( get_the_id(), 'activitypub', true ); |
| 63 |
$is_reblog = is_array( $activitypub_meta ) && ! empty( $activitypub_meta['reblog'] ); |
| 64 |
?> |
| 65 |
<?php |
| 66 |
echo '<a href="' . esc_url( in_array( get_post_type(), apply_filters( 'friends_frontend_post_types', array() ), true ) ? $author_url : get_the_author_meta( 'url' ) ) . '" class="author-avatar">'; |
| 67 |
if ( $is_reblog && $avatar !== $args['avatar'] ) { |
| 68 |
echo '<img src="' . esc_url( $avatar ) . '" width="36" height="36" class="avatar" />'; |
| 69 |
echo '<img src="' . esc_url( $args['avatar'] ) . '" width="20" height="20" class="avatar avatar-overlay" />'; |
| 70 |
} else { |
| 71 |
echo '<img src="' . esc_url( $avatar ) . '" width="36" height="36" class="avatar" />'; |
| 72 |
} |
| 73 |
echo '</a>'; |
| 74 |
?> |
| 75 |
<?php endif; ?> |
| 76 |
</div> |
| 77 |
<div class="post-meta"> |
| 78 |
<div class="author"> |
| 79 |
<?php if ( in_array( get_post_type(), apply_filters( 'friends_frontend_post_types', array() ), true ) ) : ?> |
| 80 |
<?php |
| 81 |
// If there's an override author that differs from the friend's display name, |
| 82 |
// and it's not already part of the display name, show only the override name. |
| 83 |
// Only apply this for the External user - for regular subscriptions, always use friend_user display name. |
| 84 |
$is_external_user = 'external' === $friend_user->user_login; |
| 85 |
$names_differ = $is_external_user && $override_author_name && trim( str_replace( $override_author_name, '', $author_name ) ) === $author_name; |
| 86 |
$display_name = $names_differ ? $override_author_name : $friend_user->display_name; |
| 87 |
?> |
| 88 |
<a href="<?php echo esc_attr( $author_url ); ?>"><strong><?php echo wp_kses( Friends\Feed_Parser_ActivityPub::replace_custom_emojis_for_user( $display_name, $friend_user ), Friends\Feed_Parser_ActivityPub::get_custom_emoji_allowed_html() ); ?></strong></a> |
| 89 |
<?php do_action( 'friends_post_author_meta', $friend_user ); ?> |
| 90 |
<?php if ( get_post_meta( get_the_ID(), '_has_mention_in_comments', true ) ) : ?> |
| 91 |
<span class="mention-indicator" title="<?php esc_attr_e( 'You were mentioned in a comment', 'friends' ); ?>">@</span> |
| 92 |
<?php endif; ?> |
| 93 |
<?php else : ?> |
| 94 |
<a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>"><strong><?php the_author(); ?></strong></a> |
| 95 |
<?php endif; ?> |
| 96 |
</div> |
| 97 |
<div class="permalink"> |
| 98 |
<?php |
| 99 |
echo wp_kses( |
| 100 |
sprintf( |
| 101 |
// translators: %1$s is a date or relative time, %2$s is a site name or domain. |
| 102 |
_x( '%1$s on %2$s', 'at-date-on-post', 'friends' ), |
| 103 |
'<a href="' . esc_attr( $friend_user->get_local_friends_page_url() . get_the_ID() . '/' ) . '" title="' . get_the_time( 'r' ) . '">' . |
| 104 |
/* translators: %s is a time span */ sprintf( __( '%s ago' ), human_time_diff( get_post_time( 'U', true ) ) ) . // phpcs:ignore WordPress.WP.I18n.MissingArgDomain |
| 105 |
'</a>', |
| 106 |
'<a href="' . esc_url( get_the_permalink() ) . '" rel="noopener noreferrer" target="_blank">' . esc_html( wp_parse_url( get_the_permalink(), PHP_URL_HOST ) ) . '</a>' |
| 107 |
), |
| 108 |
array( |
| 109 |
'a' => array( |
| 110 |
'href' => array(), |
| 111 |
'rel' => array(), |
| 112 |
'target' => array(), |
| 113 |
'title' => array(), |
| 114 |
), |
| 115 |
) |
| 116 |
); |
| 117 |
|
| 118 |
if ( isset( $args['read_time'] ) ) { |
| 119 |
echo ' <span class="reading-time" title="', esc_html__( 'Estimated reading time', 'friends' ), '">', esc_html( |
| 120 |
sprintf( |
| 121 |
// translators: %s is a timeframe, e.g. < 1 min or 2min. |
| 122 |
__( '%s read', 'friends' ), |
| 123 |
$args['read_time'] |
| 124 |
) |
| 125 |
), '</span>'; |
| 126 |
} |
| 127 |
?> |
| 128 |
</div> |
| 129 |
</div> |
| 130 |
<div class="overflow col-ml-auto"> |
| 131 |
<a class="btn btn-link collapse-post" tabindex="0" title="<?php esc_html_e( 'Double or meta/shift/cmd click to toggle all', 'friends' ); ?>"><i class="dashicons dashicons-fullscreen-exit-alt"></i></a> |
| 132 |
<div class="friends-dropdown friends-dropdown-right"> |
| 133 |
<a class="btn btn-link friends-dropdown-toggle" tabindex="0"><i class="dashicons dashicons-menu-alt2"></i></a> |
| 134 |
<ul class="menu" style="min-width: <?php echo esc_attr( intval( _x( '250', 'dropdown-menu-width', 'friends' ) ) ); ?>px"> |
| 135 |
<?php |
| 136 |
Friends\Friends::template_loader()->get_template_part( |
| 137 |
'frontend/parts/header-menu', |
| 138 |
null, |
| 139 |
$args |
| 140 |
); |
| 141 |
?> |
| 142 |
</ul> |
| 143 |
</div> |
| 144 |
|
| 145 |
</div> |
| 146 |
</header> |
| 147 |
<div class="teaser col-ml-auto"> |
| 148 |
<?php echo wp_kses( str_replace( '/p>', '/p> ', preg_replace( '#<span class="invisible">.*?</span>#', '', get_the_content() ) ), array( 'a' => array( 'href' => array() ) ) ); ?> |
| 149 |
</div> |
| 150 |
|