fictioneer/author.php

272 lines
8.3 KiB
PHP
Raw Normal View History

2023-01-21 01:31:34 +01:00
<?php
/**
* Author
*
* @package WordPress
* @subpackage Fictioneer
* @since 4.6
2023-09-17 18:21:46 +02:00
* @see fictioneer_clause_sticky_stories()
2023-01-21 01:31:34 +01:00
*/
?>
<?php
// Get queried author
$author_id = get_queried_object_id();
$author = get_userdata( $author_id );
// Return home if not a valid author
if (
2023-06-12 00:16:05 +02:00
! fictioneer_is_author( $author_id ) ||
count_user_posts( $author_id, ['fcn_story', 'fcn_chapter'] ) < 1
2023-01-21 01:31:34 +01:00
) {
wp_redirect( home_url() );
exit();
}
// Setup
$current_url = get_author_posts_url( $author_id );
2023-06-12 00:16:05 +02:00
$current_tab = $_GET['tab'] ?? null;
$current_page = get_query_var( 'pg', 1 ) ?: 1;
$order = array_intersect( [ strtolower( $_GET['order'] ?? 0 ) ], ['desc', 'asc'] );
$order = reset( $order ) ?: 'desc';
2023-01-21 01:31:34 +01:00
$author_page = get_the_author_meta( 'fictioneer_author_page', $author_id );
$author_page = $author_page > 0 ? $author_page : false;
2023-06-12 00:16:05 +02:00
$author_statistics = fictioneer_get_author_statistics( $author_id );
$max_pages = 1;
$tabs = [];
2023-01-21 01:31:34 +01:00
2023-06-12 00:16:05 +02:00
// Stories tab
2023-01-21 01:31:34 +01:00
$tabs['stories'] = array(
'name' => __( 'Stories', 'fictioneer' ),
'query_args' => array(
'fictioneer_query_name' => 'author_stories',
2023-01-21 01:31:34 +01:00
'post_type' => 'fcn_story',
'author' => $author_id,
2023-08-07 12:07:48 +02:00
'orderby' => 'modified',
2023-01-21 01:31:34 +01:00
'paged' => $current_page,
2023-06-12 00:16:05 +02:00
'order' => $order,
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'fictioneer_story_hidden',
'value' => '0'
),
array(
'key' => 'fictioneer_story_hidden',
'compare' => 'NOT EXISTS'
),
)
2023-01-21 01:31:34 +01:00
),
'classes' => [],
'empty' => __( 'No stories published yet.', 'fictioneer' )
);
2023-06-12 00:16:05 +02:00
// Chapters tab
2023-01-21 01:31:34 +01:00
$tabs['chapters'] = array(
'name' => __( 'Chapters', 'fictioneer' ),
'query_args' => array(
'fictioneer_query_name' => 'author_chapters',
2023-01-21 01:31:34 +01:00
'post_type' => 'fcn_chapter',
'author' => $author_id,
'paged' => $current_page,
'order' => $order,
'meta_query' => array(
'relation' => 'AND',
array(
'relation' => 'OR',
array(
'key' => 'fictioneer_chapter_hidden',
'value' => '0'
),
array(
'key' => 'fictioneer_chapter_hidden',
'compare' => 'NOT EXISTS'
)
2023-01-21 01:31:34 +01:00
),
array(
'relation' => 'OR',
array(
'key' => 'fictioneer_chapter_no_chapter',
'value' => '0'
),
array(
'key' => 'fictioneer_chapter_no_chapter',
'compare' => 'NOT EXISTS'
)
2023-01-21 01:31:34 +01:00
)
)
),
'classes' => [],
'empty' => __( 'No chapters published yet.', 'fictioneer' )
);
2023-06-12 00:16:05 +02:00
// Recommendations tab
2023-09-01 22:45:47 +02:00
if ( user_can( $author_id, 'publish_fcn_recommendations' ) ) {
$tabs['recommendations'] = array(
'name' => __( 'Recommendations', 'fictioneer' ),
'query_args' => array(
'fictioneer_query_name' => 'author_recommendations',
2023-09-01 22:45:47 +02:00
'post_type' => 'fcn_recommendation',
'author' => $author_id,
'paged' => $current_page,
'order' => $order
),
'classes' => [],
'empty' => __( 'No recommendations published yet.', 'fictioneer' )
);
}
2023-01-21 01:31:34 +01:00
// Use first tab if queried tab is not available
2023-08-08 13:38:11 +02:00
if ( ! array_key_exists( $current_tab, $tabs ) ) {
$current_tab = array_key_first( $tabs );
}
2023-01-21 01:31:34 +01:00
// Select tab
$tabs[ $current_tab ]['classes'][] = '_current';
?>
<?php get_header(); ?>
<main id="main" class="main author-page singular">
2023-07-30 17:00:40 +02:00
<div class="observer main-observer"></div>
2023-01-21 01:31:34 +01:00
<?php do_action( 'fictioneer_main' ); ?>
<div class="main__background polygon polygon--main background-texture"></div>
<div class="main__wrapper">
<?php do_action( 'fictioneer_main_wrapper' ); ?>
<article class="singular__article author-page__article padding-left padding-right padding-top padding-bottom">
<?php
$title = $author_page ? trim( get_the_title( $author_page ) ) : $author->display_name;
$title = empty( $title ) ? $author->display_name : $title;
$order_link = add_query_arg(
array(
'tab' => $current_tab,
2023-06-12 00:16:05 +02:00
'order' => $order === 'desc' ? 'asc' : 'desc'
2023-01-21 01:31:34 +01:00
),
$current_url
) . '#main';
?>
<header class="singular__header">
<h1 class="singular__title"><?php echo $title; ?></h1>
</header>
<?php if ( $author_page || ! empty( $author->user_description ) ) : ?>
<section class="singular__content author-page__content content-section">
<?php
if ( $author_page ) {
$post = get_post( $author_page );
setup_postdata( $post );
2023-01-21 01:31:34 +01:00
the_content();
wp_reset_postdata();
2023-01-21 01:31:34 +01:00
} elseif ( ! empty( $author->user_description ) ) {
echo $author->user_description;
}
?>
</section>
<?php endif; ?>
2023-07-31 00:05:38 +02:00
<section class="statistics spacing-top">
2023-01-21 01:31:34 +01:00
<div class="statistics__inline-stat">
<strong><?php _e( 'Stories', 'fictioneer' ); ?></strong>
<span><?php echo number_format_i18n( $author_statistics['story_count'] ); ?></span>
</div>
<div class="statistics__inline-stat">
<strong><?php _e( 'Chapters', 'fictioneer' ); ?></strong>
<span><?php echo number_format_i18n( $author_statistics['chapter_count'] ); ?></span>
</div>
<div class="statistics__inline-stat">
<strong><?php _e( 'Words', 'fictioneer' ); ?></strong>
<span><?php echo fictioneer_shorten_number( $author_statistics['word_count'] ); ?></span>
</div>
<div class="statistics__inline-stat">
<strong><?php _e( 'Comments', 'fictioneer' ); ?></strong>
<span><?php echo number_format_i18n( $author_statistics['comment_count'] ); ?></span>
</div>
<div class="statistics__inline-stat">
<strong><?php _e( 'Reading', 'fictioneer' ); ?></strong>
<span><?php echo fictioneer_get_reading_time_nodes( $author_statistics['word_count'] ); ?></span>
</div>
</section>
2023-09-16 02:52:18 +02:00
<section id="tabs" class="scroll-margin-top author-page__tabs tabs-wrapper spacing-top">
2023-01-21 01:31:34 +01:00
<div class="tabs">
<?php foreach ( $tabs as $key => $value ) : ?>
2023-06-12 00:16:05 +02:00
<a
href="<?php echo esc_url( add_query_arg( array( 'tab' => $key, 'order' => $order ), $current_url ) . '#main'); ?>"
class="tabs__item <?php echo implode( ' ', $value['classes'] )?>"
><?php echo $value['name']; ?></a>
2023-01-21 01:31:34 +01:00
<?php endforeach; ?>
</div>
<div class="author-page__sorting">
<a class="list-button _order <?php echo $order == 'desc' ? '_on' : '_off'; ?>" href="<?php echo esc_url( $order_link ); ?>">
<i class="fa-solid fa-arrow-up-short-wide _off"></i>
<i class="fa-solid fa-arrow-down-wide-short _on"></i>
</a>
</div>
</section>
<?php
// Setup pagination (cannot use main pagination due to different sub-queries)
$pag_args = array(
'base' => add_query_arg( 'pg', '%#%' ),
'format' => '?pg=%#%',
'current' => max( 1, $current_page ),
'prev_text' => fcntr( 'previous' ),
'next_text' => fcntr( 'next' ),
2023-06-12 00:16:05 +02:00
'add_args' => $current_tab ? array( 'tab' => $current_tab ) : null,
2023-01-21 01:31:34 +01:00
'add_fragment' => '#tabs',
'total' => 0
);
?>
<section id="list" class="author-page __list">
<ul class="author-page __list card-list _no-mutation-observer">
<?php
$list_items = fictioneer_get_card_list(
$tabs[ $current_tab ]['query_args']['post_type'],
$tabs[ $current_tab ]['query_args'],
$tabs[ $current_tab ]['empty'],
2023-06-12 00:16:05 +02:00
array(
'show_latest' => true
)
2023-01-21 01:31:34 +01:00
);
// Output list
echo $list_items['html'];
// Update pagination arguments
$pag_args['total'] = $list_items['query']->max_num_pages ?? 1;
// Output pagination
if ( $pag_args['total'] > 1 ) {
echo '<li class="pagination">' . fictioneer_paginate_links( $pag_args ) . '</li>';
2023-01-21 01:31:34 +01:00
}
?>
</ul>
</section>
</article>
</div>
</main>
<?php
// Footer arguments
$footer_args = array(
'post_type' => null,
'post_id' => null,
'template' => 'author.php',
'breadcrumbs' => array(
2023-06-12 13:01:32 +02:00
[fcntr( 'frontpage' ), get_home_url()],
[__( 'Author', 'fictioneer' ), null],
[$author->display_name, null]
2023-01-21 01:31:34 +01:00
)
);
// Get footer with breadcrumbs
get_footer( null, $footer_args );
?>