2023-01-21 01:31:34 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Custom Post Type: Chapter
|
|
|
|
*
|
|
|
|
* Shows a single chapter.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Fictioneer
|
|
|
|
* @since 1.0
|
|
|
|
* @see comments.php
|
|
|
|
*/
|
|
|
|
|
2023-06-13 11:34:10 +02:00
|
|
|
|
2024-05-10 01:26:09 +02:00
|
|
|
// Setup
|
|
|
|
$password_required = post_password_required();
|
2024-05-17 17:10:24 +02:00
|
|
|
$post_id = get_the_ID();
|
2024-05-10 01:26:09 +02:00
|
|
|
|
2023-06-13 11:34:10 +02:00
|
|
|
// Header
|
2024-05-10 01:26:09 +02:00
|
|
|
get_header(
|
|
|
|
null,
|
|
|
|
array(
|
|
|
|
'type' => 'fcn_chapter',
|
2024-05-17 17:10:24 +02:00
|
|
|
'no_index' => get_post_meta( $post_id, 'fictioneer_chapter_hidden', true ) ? 1 : 0
|
2024-05-10 01:26:09 +02:00
|
|
|
)
|
2023-06-13 11:34:10 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
?>
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
<div class="progress">
|
|
|
|
<div class="progress__bar"></div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<main id="main" class="main chapter">
|
2024-04-14 12:57:59 +02:00
|
|
|
|
2024-06-14 00:31:31 +02:00
|
|
|
<?php do_action( 'fictioneer_main', 'chapter' ); ?>
|
2024-04-14 12:57:59 +02:00
|
|
|
|
2023-01-21 01:31:34 +01:00
|
|
|
<div class="main__wrapper">
|
2024-04-14 12:57:59 +02:00
|
|
|
|
2023-01-21 01:31:34 +01:00
|
|
|
<?php do_action( 'fictioneer_main_wrapper' ); ?>
|
|
|
|
|
2024-05-10 01:26:09 +02:00
|
|
|
<?php while ( have_posts() ) : the_post(); ?>
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
<?php
|
|
|
|
// Setup
|
|
|
|
$chapter_ids = [];
|
2024-04-23 02:47:23 +02:00
|
|
|
$indexed_chapters = [];
|
2023-01-21 01:31:34 +01:00
|
|
|
$password_class = ! empty( $post->post_password ) ? 'password' : '';
|
2024-05-17 17:10:24 +02:00
|
|
|
$title = fictioneer_get_safe_title( $post_id, 'single-chapter' );
|
|
|
|
$age_rating = get_post_meta( $post_id, 'fictioneer_chapter_rating', true );
|
2023-12-02 00:00:13 +01:00
|
|
|
$this_breadcrumb = [ $title, get_the_permalink() ];
|
2023-01-21 01:31:34 +01:00
|
|
|
|
2024-05-17 17:10:24 +02:00
|
|
|
$story_id = get_post_meta( $post_id, 'fictioneer_chapter_story', true );
|
2023-08-17 21:30:42 +02:00
|
|
|
$story_data = null;
|
|
|
|
$story_post = null;
|
|
|
|
|
2023-08-31 17:30:24 +02:00
|
|
|
if ( $story_id && in_array( get_post_status( $story_id ), ['publish', 'private'] ) ) {
|
2023-08-17 21:30:42 +02:00
|
|
|
$story_post = empty( $story_id ) ? null : get_post( $story_id );
|
|
|
|
}
|
|
|
|
|
2023-01-21 01:31:34 +01:00
|
|
|
// Story data
|
|
|
|
if ( $story_post ) {
|
2023-08-05 18:31:39 +02:00
|
|
|
$story_data = fictioneer_get_story_data( $story_id, false ); // Does not refresh comment count!
|
2023-01-21 01:31:34 +01:00
|
|
|
$chapter_ids = $story_data['chapter_ids'];
|
2024-04-23 02:47:23 +02:00
|
|
|
$indexed_chapters = $story_data['indexed_chapter_ids'] ?? $chapter_ids;
|
2024-01-20 14:41:33 +01:00
|
|
|
|
|
|
|
if ( empty( $age_rating ) ) {
|
|
|
|
$age_rating = $story_data['rating'];
|
|
|
|
}
|
2023-01-21 01:31:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Chapter navigation
|
2024-05-17 17:10:24 +02:00
|
|
|
$current_index = array_search( $post_id, $indexed_chapters );
|
2023-01-21 01:31:34 +01:00
|
|
|
$prev_index = $current_index - 1;
|
|
|
|
$next_index = $current_index + 1;
|
|
|
|
|
|
|
|
// Arguments for hooks and templates/etc. and includes
|
|
|
|
$hook_args = array(
|
|
|
|
'author' => get_userdata( $post->post_author ),
|
|
|
|
'story_post' => $story_post,
|
|
|
|
'story_data' => $story_data,
|
2024-05-17 17:10:24 +02:00
|
|
|
'chapter_id' => $post_id,
|
2023-01-21 01:31:34 +01:00
|
|
|
'chapter_title' => $title,
|
|
|
|
'chapter_password' => $post->post_password,
|
2024-05-10 01:26:09 +02:00
|
|
|
'password_required' => $password_required,
|
2023-01-21 01:31:34 +01:00
|
|
|
'chapter_ids' => $chapter_ids,
|
2024-04-23 02:47:23 +02:00
|
|
|
'indexed_chapter_ids' => $indexed_chapters,
|
2023-01-21 01:31:34 +01:00
|
|
|
'current_index' => $current_index,
|
|
|
|
'prev_index' => $prev_index >= 0 ? $prev_index : false,
|
2024-04-23 02:47:23 +02:00
|
|
|
'next_index' => isset( $indexed_chapters[ $next_index ] ) ? $next_index : false
|
2023-01-21 01:31:34 +01:00
|
|
|
);
|
|
|
|
?>
|
|
|
|
|
2024-04-23 02:47:23 +02:00
|
|
|
<?php if ( $story_post && $indexed_chapters ): ?>
|
2023-01-21 01:31:34 +01:00
|
|
|
<div id="story-chapter-list" class="hidden" data-story-id="<?php echo $story_id; ?>">
|
2024-05-17 17:10:24 +02:00
|
|
|
<ul data-current-id="<?php echo $post_id; ?>"><?php
|
2024-10-08 12:54:12 +02:00
|
|
|
echo fictioneer_get_simple_chapter_list_items( $story_id, $story_data, $current_index );
|
2024-01-27 20:43:20 +01:00
|
|
|
?></ul>
|
2023-01-21 01:31:34 +01:00
|
|
|
</div>
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
|
|
<?php
|
|
|
|
if ( get_option( 'fictioneer_enable_bookmarks' ) ) {
|
|
|
|
// Bookmark data
|
|
|
|
$bookmark_story_title = '';
|
2024-05-17 17:10:24 +02:00
|
|
|
$bookmark_title = get_post_meta( $post_id, 'fictioneer_chapter_list_title', true );
|
2023-10-08 15:28:23 +02:00
|
|
|
$bookmark_title = trim( wp_strip_all_tags( $bookmark_title ) );
|
|
|
|
$bookmark_title = $bookmark_title ?: $title;
|
2023-01-21 01:31:34 +01:00
|
|
|
$bookmark_thumbnail = get_the_post_thumbnail_url( null, 'snippet' );
|
|
|
|
$bookmark_image = get_the_post_thumbnail_url( null, 'full' );
|
|
|
|
|
|
|
|
// If story is set...
|
|
|
|
if ( $story_post ) {
|
|
|
|
$bookmark_story_title = $story_data['title'];
|
|
|
|
|
|
|
|
// If chapter has no featured image, look in story...
|
|
|
|
if ( ! $bookmark_thumbnail ) {
|
|
|
|
$bookmark_thumbnail = get_the_post_thumbnail_url( $story_id, 'snippet' );
|
|
|
|
$bookmark_image = get_the_post_thumbnail_url( $story_id, 'full' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
|
|
|
|
<?php if ( get_option( 'fictioneer_enable_bookmarks' ) ) : ?>
|
|
|
|
<div id="chapter-bookmark-data"
|
|
|
|
data-thumb="<?php echo esc_url( $bookmark_thumbnail ); ?>"
|
|
|
|
data-image="<?php echo esc_url( $bookmark_image ); ?>"
|
|
|
|
data-link="<?php the_permalink(); ?>"
|
|
|
|
data-title="<?php echo esc_attr( $bookmark_title ); ?>"
|
|
|
|
data-story-title="<?php echo esc_attr( $bookmark_story_title ); ?>"
|
2024-03-09 00:39:11 +01:00
|
|
|
hidden data-nosnippet>
|
2023-01-21 01:31:34 +01:00
|
|
|
</div>
|
|
|
|
<?php endif; ?>
|
|
|
|
|
2024-08-12 02:42:45 +02:00
|
|
|
<article id="ch-<?php echo $post_id; ?>" data-author-id="<?php echo get_the_author_meta( 'ID' ); ?>" class="chapter__article <?php echo $password_required ? '_password' : ''; ?>" data-age-rating="<?php echo strtolower( $age_rating ); ?>">
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
<?php
|
2024-07-31 11:35:06 +02:00
|
|
|
// Before chapter article header; includes the actions row, foreword, and warnings
|
2023-01-21 01:31:34 +01:00
|
|
|
do_action( 'fictioneer_chapter_before_header', $hook_args );
|
|
|
|
|
|
|
|
// Render article header
|
|
|
|
get_template_part( 'partials/_chapter-header', null, $hook_args );
|
|
|
|
|
|
|
|
// After chapter article header
|
|
|
|
do_action( 'fictioneer_chapter_after_header', $hook_args );
|
|
|
|
|
|
|
|
// Password note
|
2024-05-17 17:10:24 +02:00
|
|
|
$password_note = fictioneer_get_content_field( 'fictioneer_chapter_password_note', $post_id );
|
2024-03-03 12:24:59 +01:00
|
|
|
|
2024-05-10 01:26:09 +02:00
|
|
|
if ( $story_post && $password_required && empty( $password_note ) ) {
|
2024-03-03 12:24:59 +01:00
|
|
|
$password_note = fictioneer_get_content_field( 'fictioneer_story_password_note', $story_id );
|
|
|
|
|
|
|
|
if ( ! empty( $password_note ) && strpos( $password_note, '[!global]' ) !== false ) {
|
|
|
|
$password_note = str_replace( '[!global]', '', $password_note );
|
|
|
|
} else {
|
|
|
|
$password_note = '';
|
|
|
|
}
|
|
|
|
}
|
2023-01-21 01:31:34 +01:00
|
|
|
?>
|
|
|
|
|
2024-04-09 21:04:31 +02:00
|
|
|
<section id="chapter-content" class="chapter__content content-section"><?php
|
2024-05-10 01:26:09 +02:00
|
|
|
if ( $password_required && $password_note ) {
|
|
|
|
echo '<div class="chapter__password-note infobox">' . $password_note . '</div>';
|
2024-04-09 21:04:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
echo '<div class="resize-font chapter-formatting chapter-font-color chapter-font-family">';
|
|
|
|
|
2024-05-10 01:26:09 +02:00
|
|
|
if ( $password_required && get_option( 'fictioneer_show_protected_excerpt' ) ) {
|
2024-05-17 17:10:24 +02:00
|
|
|
echo '<p class="chapter__forced-excerpt">' . fictioneer_get_forced_excerpt( $post_id, 512 ) . '</p>';
|
2024-04-09 21:04:31 +02:00
|
|
|
}
|
|
|
|
|
2024-05-20 01:56:48 +02:00
|
|
|
fictioneer_the_static_content();
|
2024-04-09 21:04:31 +02:00
|
|
|
|
|
|
|
echo '</div>';
|
|
|
|
?></section>
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
<?php
|
2024-07-31 11:35:06 +02:00
|
|
|
// After chapter content; includes the footer, afterword, and support box
|
2023-01-21 01:31:34 +01:00
|
|
|
do_action( 'fictioneer_chapter_after_content', $hook_args );
|
|
|
|
?>
|
|
|
|
|
|
|
|
</article>
|
|
|
|
|
2024-05-17 17:10:24 +02:00
|
|
|
<?php
|
|
|
|
do_action( 'fictioneer_chapter_before_comments', $hook_args );
|
|
|
|
do_action( 'fictioneer_before_comments' );
|
|
|
|
?>
|
2023-01-21 01:31:34 +01:00
|
|
|
|
2024-05-10 01:26:09 +02:00
|
|
|
<?php if ( comments_open() && ! $password_required ) : ?>
|
2024-08-12 02:42:45 +02:00
|
|
|
<section class="chapter__comments comment-section chapter-comments-hideable">
|
2023-01-21 01:31:34 +01:00
|
|
|
<?php comments_template(); ?>
|
|
|
|
</section>
|
|
|
|
<?php endif; ?>
|
|
|
|
|
2024-05-10 01:26:09 +02:00
|
|
|
<?php endwhile; ?>
|
2024-04-14 12:57:59 +02:00
|
|
|
|
2023-01-21 01:31:34 +01:00
|
|
|
</div>
|
2024-04-14 12:57:59 +02:00
|
|
|
|
2024-09-07 16:57:34 +02:00
|
|
|
<?php do_action( 'fictioneer_main_end', 'chapter' ); ?>
|
|
|
|
|
2023-01-21 01:31:34 +01:00
|
|
|
</main>
|
|
|
|
|
|
|
|
<?php
|
|
|
|
// After chapter main; includes the micro menu, paragraph tools, and suggestion tools
|
2024-05-10 01:26:09 +02:00
|
|
|
if ( ! $password_required ) {
|
2023-01-21 01:31:34 +01:00
|
|
|
do_action( 'fictioneer_chapter_after_main', $hook_args );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Footer arguments
|
|
|
|
$footer_args = array(
|
|
|
|
'post_type' => 'fcn_chapter',
|
2024-05-17 17:10:24 +02:00
|
|
|
'post_id' => $post_id,
|
2023-01-21 01:31:34 +01:00
|
|
|
'breadcrumbs' => array(
|
|
|
|
[fcntr( 'frontpage' ), get_home_url()]
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Add stories list breadcrumb (if set)
|
2023-08-03 23:51:04 +02:00
|
|
|
$stories_page_id = intval( get_option( 'fictioneer_stories_page', -1 ) ?: -1 );
|
2023-01-21 01:31:34 +01:00
|
|
|
|
2023-08-03 23:51:04 +02:00
|
|
|
if ( $stories_page_id > 0 ) {
|
|
|
|
$stories_page_title = trim( get_the_title( $stories_page_id ) );
|
2023-01-21 01:31:34 +01:00
|
|
|
$stories_page_title = empty( $stories_page_title ) ? __( 'Stories', 'fictioneer' ) : $stories_page_title;
|
|
|
|
|
|
|
|
$footer_args['breadcrumbs'][] = array(
|
|
|
|
$stories_page_title,
|
2023-08-03 23:51:04 +02:00
|
|
|
fictioneer_get_assigned_page_link( 'fictioneer_stories_page' )
|
2023-01-21 01:31:34 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add story (if set)
|
|
|
|
if ( $story_post ) {
|
|
|
|
$footer_args['breadcrumbs'][] = array(
|
|
|
|
$story_data['title'],
|
|
|
|
get_the_permalink( $story_id )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add current breadcrumb
|
|
|
|
$footer_args['breadcrumbs'][] = $this_breadcrumb;
|
|
|
|
|
|
|
|
// Get footer with breadcrumbs
|
|
|
|
get_footer( null, $footer_args );
|
|
|
|
?>
|