2023-01-21 01:31:34 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Partial: Story Card
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Fictioneer
|
2024-01-26 17:45:59 +01:00
|
|
|
* @since 4.0.0
|
2023-01-21 01:31:34 +01:00
|
|
|
*
|
2023-06-07 23:23:19 +02:00
|
|
|
* @internal $args['show_type'] Whether to show the post type label. Unsafe.
|
|
|
|
* @internal $args['cache'] Whether to account for active caching. Unsafe.
|
|
|
|
* @internal $args['hide_author'] Whether to hide the author. Unsafe.
|
|
|
|
* @internal $args['show_latest'] Whether to show (up to) the latest 3 chapters. Unsafe.
|
|
|
|
* @internal $args['order'] Current order. Default 'desc'. Unsafe.
|
|
|
|
* @internal $args['orderby'] Current orderby. Default 'modified'. Unsafe.
|
2023-01-21 01:31:34 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2023-08-20 20:21:48 +02:00
|
|
|
// No direct access!
|
|
|
|
defined( 'ABSPATH' ) OR exit;
|
|
|
|
|
2024-08-13 19:18:51 +02:00
|
|
|
// Card cache?
|
|
|
|
$card_cache_active = get_option( 'fictioneer_enable_story_card_caching' );
|
|
|
|
|
|
|
|
if ( $card_cache_active ) {
|
|
|
|
$cache_key = $post->ID . '_' . date( 'Y-m-d-H-i-s', strtotime( $post->post_modified_gmt ) ) .
|
|
|
|
'_' . md5( json_encode( $args ) );
|
|
|
|
|
|
|
|
if ( $cache = fictioneer_get_cached_story_card( $cache_key ) ) {
|
|
|
|
echo $cache;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-21 01:31:34 +01:00
|
|
|
// Setup
|
2024-05-17 17:46:54 +02:00
|
|
|
$post_id = $post->ID;
|
|
|
|
$story = fictioneer_get_story_data( $post_id );
|
|
|
|
$story_link = ( $story['redirect'] ?? 0 ) ?: get_permalink( $post_id );
|
2024-07-01 11:02:19 +02:00
|
|
|
$latest = $args['show_latest'] ?? FICTIONEER_SHOW_LATEST_CHAPTERS_ON_STORY_CARDS;
|
2024-08-15 01:51:45 +02:00
|
|
|
$chapter_limit = max( 0, FICTIONEER_STORY_CARD_CHAPTER_LIMIT );
|
|
|
|
$chapter_ids = array_slice(
|
|
|
|
$story['chapter_ids'],
|
|
|
|
$latest ? -1 * $chapter_limit : 0, $chapter_limit,
|
|
|
|
true
|
|
|
|
); // Does not include hidden or non-chapters
|
2023-08-08 01:51:03 +02:00
|
|
|
$chapter_count = count( $chapter_ids );
|
2023-11-30 16:03:53 +01:00
|
|
|
$excerpt = fictioneer_first_paragraph_as_excerpt(
|
2024-05-17 17:46:54 +02:00
|
|
|
fictioneer_get_content_field( 'fictioneer_story_short_description', $post_id )
|
2023-11-30 16:03:53 +01:00
|
|
|
);
|
2024-07-20 23:13:26 +02:00
|
|
|
$excerpt = empty( $excerpt ) ? fictioneer_get_excerpt( $post_id ) : $excerpt;
|
2023-08-08 01:51:03 +02:00
|
|
|
$tags = false;
|
2024-02-11 23:55:32 +01:00
|
|
|
$card_classes = [];
|
2023-08-08 01:51:03 +02:00
|
|
|
|
|
|
|
if (
|
|
|
|
get_option( 'fictioneer_show_tags_on_story_cards' ) &&
|
|
|
|
! get_option( 'fictioneer_hide_taxonomies_on_story_cards' )
|
|
|
|
) {
|
|
|
|
$tags = get_the_tags();
|
2023-02-04 16:15:25 +01:00
|
|
|
}
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
// Flags
|
2023-08-08 01:51:03 +02:00
|
|
|
$hide_author = $args['hide_author'] ?? false && ! get_option( 'fictioneer_show_authors' );
|
2024-08-23 23:12:24 +02:00
|
|
|
$show_terms = ! get_option( 'fictioneer_hide_taxonomies_on_story_cards' ) && ( $story['has_taxonomies'] || $tags );
|
2024-01-26 12:02:28 +01:00
|
|
|
$is_sticky = FICTIONEER_ENABLE_STICKY_CARDS &&
|
2024-05-17 17:46:54 +02:00
|
|
|
get_post_meta( $post_id, 'fictioneer_story_sticky', true ) && ! is_search() && ! is_archive();
|
2023-01-21 01:31:34 +01:00
|
|
|
|
2024-02-11 23:55:32 +01:00
|
|
|
// Extra classes
|
|
|
|
if ( $is_sticky ) {
|
|
|
|
$card_classes[] = '_sticky';
|
|
|
|
}
|
2024-02-12 00:27:58 +01:00
|
|
|
|
2024-02-12 01:40:38 +01:00
|
|
|
if ( get_theme_mod( 'card_style', 'default' ) !== 'default' ) {
|
|
|
|
$card_classes[] = '_' . get_theme_mod( 'card_style' );
|
2024-02-12 00:27:58 +01:00
|
|
|
}
|
|
|
|
|
2024-05-14 18:40:52 +02:00
|
|
|
if ( get_theme_mod( 'card_image_style', 'default' ) !== 'default' ) {
|
|
|
|
$card_classes[] = '_' . get_theme_mod( 'card_image_style' );
|
|
|
|
}
|
|
|
|
|
2024-08-23 23:12:24 +02:00
|
|
|
if ( ! $show_terms ) {
|
|
|
|
$card_classes[] = '_no-tax';
|
|
|
|
}
|
|
|
|
|
2024-03-04 01:54:53 +01:00
|
|
|
// Card attributes
|
|
|
|
$attributes = apply_filters( 'fictioneer_filter_card_attributes', [], $post, 'card-story' );
|
|
|
|
$card_attributes = '';
|
|
|
|
|
|
|
|
foreach ( $attributes as $key => $value ) {
|
|
|
|
$card_attributes .= esc_attr( $key ) . '="' . esc_attr( $value ) . '" ';
|
|
|
|
}
|
|
|
|
|
2024-03-16 14:49:51 +01:00
|
|
|
// Thumbnail attributes
|
|
|
|
$thumbnail_args = array(
|
|
|
|
'alt' => sprintf( __( '%s Cover', 'fictioneer' ), $story['title'] ),
|
|
|
|
'class' => 'no-auto-lightbox'
|
|
|
|
);
|
|
|
|
|
2024-08-13 19:18:51 +02:00
|
|
|
// Buffer HTML for cache if active
|
|
|
|
if ( $card_cache_active ) {
|
|
|
|
ob_start();
|
|
|
|
}
|
|
|
|
|
2023-01-21 01:31:34 +01:00
|
|
|
?>
|
|
|
|
|
2023-06-09 23:19:18 +02:00
|
|
|
<li
|
2024-05-17 17:46:54 +02:00
|
|
|
id="story-card-<?php echo $post_id; ?>"
|
|
|
|
class="post-<?php echo $post_id; ?> card _large _story <?php echo implode( ' ', $card_classes ); ?>"
|
|
|
|
data-story-id="<?php echo $post_id; ?>"
|
|
|
|
data-check-id="<?php echo $post_id; ?>"
|
2024-03-04 01:54:53 +01:00
|
|
|
<?php echo $card_attributes; ?>
|
2023-06-09 23:19:18 +02:00
|
|
|
>
|
2023-01-21 01:31:34 +01:00
|
|
|
<div class="card__body polygon">
|
|
|
|
|
2024-05-14 10:05:05 +02:00
|
|
|
<div class="card__main _grid _large">
|
2023-01-21 01:31:34 +01:00
|
|
|
|
2024-05-14 10:05:05 +02:00
|
|
|
<div class="card__header _large">
|
2023-01-21 01:31:34 +01:00
|
|
|
|
2024-05-14 10:05:05 +02:00
|
|
|
<?php if ( $args['show_type'] ?? false ) : ?>
|
|
|
|
<div class="card__label"><?php _ex( 'Story', 'Story card label.', 'fictioneer' ); ?></div>
|
|
|
|
<?php endif; ?>
|
2024-01-18 21:44:29 +01:00
|
|
|
|
2024-05-14 10:05:05 +02:00
|
|
|
<h3 class="card__title"><a href="<?php echo $story_link; ?>" class="truncate _1-1"><?php
|
|
|
|
if ( ! empty( $post->post_password ) ) {
|
|
|
|
echo '<i class="fa-solid fa-lock protected-icon"></i> ';
|
|
|
|
}
|
2023-01-21 01:31:34 +01:00
|
|
|
|
2024-05-14 10:05:05 +02:00
|
|
|
echo $story['title'];
|
|
|
|
?></a></h3>
|
2023-01-21 01:31:34 +01:00
|
|
|
|
2024-05-17 17:46:54 +02:00
|
|
|
<?php echo fictioneer_get_card_controls( $post_id ); ?>
|
2023-01-21 01:31:34 +01:00
|
|
|
|
2024-05-14 10:05:05 +02:00
|
|
|
</div>
|
2023-01-21 01:31:34 +01:00
|
|
|
|
2023-08-08 01:51:03 +02:00
|
|
|
<?php
|
2024-01-27 22:32:10 +01:00
|
|
|
// Action hook
|
|
|
|
do_action( 'fictioneer_large_card_body_story', $post, $story, $args );
|
|
|
|
|
2023-08-08 01:51:03 +02:00
|
|
|
// Thumbnail
|
2024-05-14 18:40:52 +02:00
|
|
|
if ( has_post_thumbnail() && get_theme_mod( 'card_image_style', 'default' ) !== 'none' ) {
|
2023-08-08 01:51:03 +02:00
|
|
|
printf(
|
|
|
|
'<a href="%1$s" title="%2$s" class="card__image cell-img" %3$s>%4$s</a>',
|
|
|
|
get_the_post_thumbnail_url( null, 'full' ),
|
|
|
|
sprintf( __( '%s Thumbnail', 'fictioneer' ), $story['title'] ),
|
|
|
|
fictioneer_get_lightbox_attribute(),
|
2024-03-16 14:49:51 +01:00
|
|
|
get_the_post_thumbnail( null, 'cover', $thumbnail_args )
|
2023-08-08 01:51:03 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Content
|
|
|
|
printf(
|
2024-01-19 14:13:17 +01:00
|
|
|
'<div class="card__content cell-desc"><div class="truncate %1$s">%2$s<span>%3$s</span></div></div>',
|
2024-05-13 23:26:51 +02:00
|
|
|
$chapter_count > 2 ? '_3-4' : '_4-4',
|
2023-08-08 01:51:03 +02:00
|
|
|
$hide_author ? '' : sprintf(
|
2024-01-19 23:43:31 +01:00
|
|
|
'<span class="card__by-author cq-show-below-640">%s</span> ',
|
2023-08-08 01:51:03 +02:00
|
|
|
sprintf(
|
|
|
|
_x( 'by %s —', 'Large card: by {Author} —.', 'fictioneer' ),
|
|
|
|
fictioneer_get_author_node()
|
|
|
|
)
|
|
|
|
),
|
2024-07-20 23:13:26 +02:00
|
|
|
$excerpt ?: __( 'No description provided yet.', 'fictioneer' )
|
2023-08-08 01:51:03 +02:00
|
|
|
);
|
|
|
|
?>
|
|
|
|
|
2024-04-09 11:11:32 +02:00
|
|
|
<?php if ( $chapter_count > 0 && ! get_option( 'fictioneer_hide_large_card_chapter_list' ) ) : ?>
|
2023-01-21 01:31:34 +01:00
|
|
|
<ol class="card__link-list cell-list">
|
2023-08-04 01:33:12 +02:00
|
|
|
<?php
|
|
|
|
// Prepare
|
|
|
|
$chapter_query_args = array(
|
|
|
|
'post_type' => 'fcn_chapter',
|
|
|
|
'post_status' => 'publish',
|
2024-05-14 22:59:02 +02:00
|
|
|
'post__in' => $chapter_ids ?: [0], // Must not be empty!
|
2023-08-26 21:11:29 +02:00
|
|
|
'orderby' => 'post__in',
|
2024-08-15 01:51:45 +02:00
|
|
|
'posts_per_page' => FICTIONEER_STORY_CARD_CHAPTER_LIMIT,
|
2023-08-04 01:33:12 +02:00
|
|
|
'no_found_rows' => true, // Improve performance
|
|
|
|
'update_post_term_cache' => false // Improve performance
|
|
|
|
);
|
|
|
|
|
|
|
|
$chapters = new WP_Query( $chapter_query_args );
|
|
|
|
?>
|
|
|
|
<?php foreach ( $chapters->posts as $chapter ) : ?>
|
2024-02-06 14:18:37 +01:00
|
|
|
<?php
|
|
|
|
// Chapter title
|
|
|
|
$list_title = get_post_meta( $chapter->ID, 'fictioneer_chapter_list_title', true );
|
|
|
|
$list_title = trim( wp_strip_all_tags( $list_title ) );
|
|
|
|
|
|
|
|
if ( empty( $list_title ) ) {
|
2024-03-01 12:39:42 +01:00
|
|
|
$chapter_title = fictioneer_get_safe_title( $chapter->ID, 'card-story-chapter-list' );
|
2024-02-06 14:18:37 +01:00
|
|
|
} else {
|
|
|
|
$chapter_title = $list_title;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Extra classes
|
|
|
|
$list_item_classes = [];
|
|
|
|
|
|
|
|
if ( ! empty( $chapter->post_password ) ) {
|
|
|
|
$list_item_classes[] = '_password';
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
<li class="card__link-list-item <?php echo implode( ' ', $list_item_classes ); ?>">
|
2023-01-21 01:31:34 +01:00
|
|
|
<div class="card__left text-overflow-ellipsis">
|
|
|
|
<i class="fa-solid fa-caret-right"></i>
|
2023-09-18 13:20:45 +02:00
|
|
|
<a href="<?php the_permalink( $chapter->ID ); ?>" class="card__link-list-link"><?php
|
2024-02-06 14:18:37 +01:00
|
|
|
echo $chapter_title;
|
2023-01-21 01:31:34 +01:00
|
|
|
?></a>
|
|
|
|
</div>
|
2023-06-06 13:44:16 +02:00
|
|
|
<div class="card__right">
|
|
|
|
<?php
|
2023-08-08 01:51:03 +02:00
|
|
|
printf(
|
2024-05-29 00:06:28 +02:00
|
|
|
'<span class="words">%1$s<span class="cq-hide-below-460"> %2$s</span></span><span class="separator-dot"> • </span><span class="date">%3$s</span>',
|
2023-11-30 17:10:19 +01:00
|
|
|
fictioneer_shorten_number( fictioneer_get_word_count( $chapter->ID ) ),
|
2023-08-08 01:51:03 +02:00
|
|
|
__( 'Words', 'fictioneer' ),
|
2024-05-26 01:00:01 +02:00
|
|
|
current_time( 'timestamp' ) - get_post_time( 'U', false, $chapter->ID ) < DAY_IN_SECONDS ?
|
2023-08-17 00:40:44 +02:00
|
|
|
__( 'New', 'fictioneer' ) : get_the_time( FICTIONEER_CARD_STORY_LI_DATE, $chapter->ID )
|
2023-08-08 01:51:03 +02:00
|
|
|
);
|
2023-06-06 13:44:16 +02:00
|
|
|
?>
|
2023-01-21 01:31:34 +01:00
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
<?php endforeach; ?>
|
|
|
|
</ol>
|
|
|
|
<?php endif; ?>
|
|
|
|
|
2024-08-23 23:35:49 +02:00
|
|
|
<?php
|
|
|
|
if ( $show_terms ) {
|
|
|
|
$terms = array_merge(
|
|
|
|
$story['fandoms'] ? fictioneer_get_term_nodes( $story['fandoms'], '_inline _fandom' ) : [],
|
|
|
|
$story['genres'] ? fictioneer_get_term_nodes( $story['genres'], '_inline _genre' ) : [],
|
|
|
|
$tags ? fictioneer_get_term_nodes( $tags, '_inline _tag' ) : [],
|
|
|
|
$story['characters'] ? fictioneer_get_term_nodes( $story['characters'], '_inline _character' ) : []
|
|
|
|
);
|
2023-06-04 01:49:00 +02:00
|
|
|
|
2024-08-23 23:35:49 +02:00
|
|
|
$terms = apply_filters(
|
|
|
|
'fictioneer_filter_card_story_terms',
|
|
|
|
$terms, $post, $args, $story
|
|
|
|
);
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
|
|
|
|
<?php if ( $show_terms && $terms ) : ?>
|
|
|
|
<div class="card__tag-list cell-tax"><?php
|
|
|
|
// Implode with separator
|
|
|
|
echo implode( fictioneer_get_bullet_separator( 'story-card' ), $terms );
|
|
|
|
?></div>
|
2023-01-21 01:31:34 +01:00
|
|
|
<?php endif; ?>
|
|
|
|
|
2024-05-13 23:26:51 +02:00
|
|
|
<div class="card__footer cell-footer">
|
2023-01-21 01:31:34 +01:00
|
|
|
|
2024-05-13 23:26:51 +02:00
|
|
|
<div class="card__footer-box _left text-overflow-ellipsis"><?php
|
|
|
|
// Build footer items
|
|
|
|
$footer_items = [];
|
2023-01-21 01:31:34 +01:00
|
|
|
|
2024-05-13 23:26:51 +02:00
|
|
|
if ( $story['status'] !== 'Oneshot' || $story['chapter_count'] > 1 ) {
|
2024-07-28 12:50:45 +02:00
|
|
|
$footer_items['chapters'] = '<span class="card__footer-chapters"><i class="card-footer-icon fa-solid fa-list" title="' . esc_attr__( 'Chapters', 'fictioneer' ) . '"></i> ' . $story['chapter_count'] . '</span>';
|
2024-05-13 23:26:51 +02:00
|
|
|
}
|
2023-08-30 02:32:39 +02:00
|
|
|
|
2024-06-04 11:57:30 +02:00
|
|
|
if ( $story['word_count'] > 2000 || $story['status'] === 'Oneshot' ) {
|
2024-07-28 12:50:45 +02:00
|
|
|
$footer_items['words'] = '<span class="card__footer-status"><i class="card-footer-icon fa-solid fa-font" title="' . esc_attr__( 'Total Words', 'fictioneer' ) . '"></i> ' . $story['word_count_short'] . '</span>';
|
2024-06-04 11:57:30 +02:00
|
|
|
}
|
2023-08-30 02:32:39 +02:00
|
|
|
|
2024-05-13 23:26:51 +02:00
|
|
|
if ( ( $args['orderby'] ?? 0 ) === 'date' ) {
|
2024-07-28 12:50:45 +02:00
|
|
|
$footer_items['publish_date'] = '<span class="card__footer-publish-date"><i class="card-footer-icon fa-solid fa-clock" title="' . esc_attr__( 'Published', 'fictioneer' ) .'"></i> ' . get_the_date( FICTIONEER_CARD_STORY_FOOTER_DATE ) . '</span>';
|
2024-05-13 23:26:51 +02:00
|
|
|
} else {
|
2024-07-28 12:50:45 +02:00
|
|
|
$footer_items['modified_date'] = '<span class="card__footer-modified-date"><i class="card-footer-icon fa-regular fa-clock" title="' . esc_attr__( 'Last Updated', 'fictioneer' ) .'"></i> ' . get_the_modified_date( FICTIONEER_CARD_STORY_FOOTER_DATE ) . '</span>';
|
2024-05-13 23:26:51 +02:00
|
|
|
}
|
2023-08-30 02:32:39 +02:00
|
|
|
|
2024-05-13 23:26:51 +02:00
|
|
|
if ( ! $hide_author ) {
|
2024-07-28 12:50:45 +02:00
|
|
|
$footer_items['author'] = '<span class="card__footer-author"><i class="card-footer-icon fa-solid fa-circle-user cq-hide-below-640"></i> ' . fictioneer_get_author_node( get_the_author_meta( 'ID' ), 'cq-hide-below-640' ) . '</span>';
|
2024-05-13 23:26:51 +02:00
|
|
|
}
|
2023-01-21 01:31:34 +01:00
|
|
|
|
2024-07-28 12:50:45 +02:00
|
|
|
$footer_items['comments'] = '<span class="card__footer-comments"><i class="card-footer-icon fa-solid fa-message cq-hide-below-460" title="' . esc_attr__( 'Comments', 'fictioneer' ) . '"></i> <span class="cq-hide-below-460" title="' . esc_attr__( 'Comments', 'fictioneer' ) . '">' . $story['comment_count'] . '</span></span>';
|
2023-01-21 01:31:34 +01:00
|
|
|
|
2024-10-30 20:36:01 +01:00
|
|
|
$footer_items['status'] = '<span class="card__footer-status _' . strtolower( $story['status'] ) . '"><i class="card-footer-icon ' . $story['icon'] . '"></i> ' . fcntr( $story['status'] ) . '</span>';
|
2023-01-21 01:31:34 +01:00
|
|
|
|
2024-05-13 23:26:51 +02:00
|
|
|
// Filter footer items
|
|
|
|
$footer_items = apply_filters( 'fictioneer_filter_story_card_footer', $footer_items, $post, $story, $args );
|
2023-01-21 01:31:34 +01:00
|
|
|
|
2024-05-13 23:26:51 +02:00
|
|
|
// Implode and render footer items
|
|
|
|
echo implode( ' ', $footer_items );
|
|
|
|
?></div>
|
2023-06-04 22:17:42 +02:00
|
|
|
|
2024-10-30 20:36:01 +01:00
|
|
|
<div class="card__footer-box _right rating-letter-label _large tooltipped _<?php echo strtolower( $story['rating'] ); ?>" data-tooltip="<?php echo fcntr( $story['rating'], true ); ?>">
|
2024-05-13 23:26:51 +02:00
|
|
|
<span class="cq-hide-below-460"><?php echo fcntr( $story['rating'] ); ?></span>
|
|
|
|
<span class="cq-show-below-460"><?php echo fcntr( $story['rating_letter'] ); ?></span>
|
|
|
|
</div>
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</li>
|
2024-08-13 19:18:51 +02:00
|
|
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
// Capture, store, and output cache if active
|
|
|
|
if ( $card_cache_active ) {
|
|
|
|
// Get buffered HTML
|
|
|
|
$cache = fictioneer_minify_html( ob_get_clean() );
|
|
|
|
|
|
|
|
// Save in cache
|
2024-08-16 22:01:48 +02:00
|
|
|
fictioneer_cache_story_card( $cache_key, $cache );
|
2024-08-13 19:18:51 +02:00
|
|
|
|
|
|
|
// Render card
|
|
|
|
echo $cache;
|
|
|
|
}
|