<?php
/**
* Post meta functions
*
* @package GridFeel WordPress Theme
* @copyright Copyright (C) 2025 ThemesDNA
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or later
* @author ThemesDNA <themesdna@gmail.com>
*/

if ( ! function_exists( 'gridfeel_post_tags' ) ) :
/**
 * Prints HTML with meta information for the tags.
 */
function gridfeel_post_tags() {
    if ( 'post' == get_post_type() ) {
        /* translators: used between list items, there is a space after the comma */
        $tags_list = get_the_tag_list( '', esc_html_x( ', ', 'list item separator', 'gridfeel' ) );
        if ( $tags_list ) {
            /* translators: 1: list of tags. */
            printf( '<span class="gridfeel-tags-links"><i class="fas fa-tags" aria-hidden="true"></i> ' . esc_html__( 'Tagged %1$s', 'gridfeel' ) . '</span>', $tags_list ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
        }
    }
}
endif;

if ( ! function_exists( 'gridfeel_grid_cats' ) ) :
function gridfeel_grid_cats() {
    global $post;
    if ( !(gridfeel_get_option('hide_post_categories_home')) && has_category() ) {
        if ( 'post' == get_post_type() ) {
            /* translators: used between list items, there is a space */
            $categories_list = get_the_category_list( esc_html__( '&nbsp;', 'gridfeel' ) );
            if ( $categories_list ) {
                /* translators: 1: list of categories. */
                printf( '<div class="gridfeel-grid-post-categories gridfeel-grid-post-block">' . __( '<span class="gridfeel-sr-only">Posted in </span>%1$s', 'gridfeel' ) . '</div>', $categories_list ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
            }
        }
    }
}
endif;

if ( ! function_exists( 'gridfeel_single_cats' ) ) :
function gridfeel_single_cats() {
    if ( 'post' == get_post_type() ) {
        /* translators: used between list items, there is a space */
        $categories_list = get_the_category_list( esc_html__( ', ', 'gridfeel' ) );
        if ( $categories_list ) {
            /* translators: 1: list of categories. */
            printf( '<span class="gridfeel-entry-meta-single-cats"><i class="far fa-folder-open" aria-hidden="true"></i>&nbsp;' . __( '<span class="gridfeel-sr-only">Posted in </span>%1$s', 'gridfeel' ) . '</span>', $categories_list ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
        }
    }
}
endif;

if ( ! function_exists( 'gridfeel_single_postmeta' ) ) :
function gridfeel_single_postmeta() { ?>
    <?php global $post; ?>
    <?php if ( !(gridfeel_get_option('hide_post_author')) || !(gridfeel_get_option('hide_posted_date')) || !(gridfeel_get_option('hide_comments_link')) || !(gridfeel_get_option('hide_post_categories')) || !(gridfeel_get_option('hide_post_edit')) ) { ?>
    <div class="gridfeel-entry-meta-single">
    <?php if ( !(gridfeel_get_option('hide_post_author')) ) { ?><span class="gridfeel-entry-meta-single-author"><i class="far fa-user-circle" aria-hidden="true"></i>&nbsp;<span class="author vcard" itemscope="itemscope" itemtype="http://schema.org/Person" itemprop="author"><a class="url fn n" href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>"><?php echo esc_html( get_the_author() ); ?></a></span></span><?php } ?>
    <?php if ( gridfeel_get_option('post_date_type') == 'updated' ) { ?>
        <?php if ( !(gridfeel_get_option('hide_posted_date')) ) { ?><span class="gridfeel-entry-meta-single-date"><i class="far fa-clock" aria-hidden="true"></i>&nbsp;<?php echo esc_html( get_the_modified_date() ); ?></span><?php } ?>
    <?php } else { ?>
        <?php if ( !(gridfeel_get_option('hide_posted_date')) ) { ?><span class="gridfeel-entry-meta-single-date"><i class="far fa-clock" aria-hidden="true"></i>&nbsp;<?php echo esc_html( get_the_date() ); ?></span><?php } ?>
    <?php } ?>
    <?php if ( !(gridfeel_get_option('hide_comments_link')) ) { ?><?php if ( ! post_password_required() && ( comments_open() || get_comments_number() ) ) { ?>
    <span class="gridfeel-entry-meta-single-comments"><i class="far fa-comments" aria-hidden="true"></i>&nbsp;<?php comments_popup_link( sprintf( wp_kses( /* translators: %s: post title */ __( 'Leave a Comment<span class="gridfeel-sr-only"> on %s</span>', 'gridfeel' ), array( 'span' => array( 'class' => array(), ), ) ), wp_kses_post( get_the_title() ) ) ); ?></span>
    <?php } ?><?php } ?>
    <?php if ( !(gridfeel_get_option('hide_post_categories')) ) { ?><?php gridfeel_single_cats(); ?><?php } ?>
    <?php if ( !(gridfeel_get_option('hide_post_edit')) ) { ?><?php edit_post_link( sprintf( wp_kses( /* translators: %s: Name of current post. Only visible to screen readers */ __( 'Edit<span class="gridfeel-sr-only"> %s</span>', 'gridfeel' ), array( 'span' => array( 'class' => array(), ), ) ), wp_kses_post( get_the_title() ) ), '<span class="edit-link">&nbsp;&nbsp;<i class="far fa-edit" aria-hidden="true"></i> ', '</span>' ); ?><?php } ?>
    </div>
    <?php } ?>
<?php }
endif;

if ( ! function_exists( 'gridfeel_page_postmeta' ) ) :
function gridfeel_page_postmeta() { ?>
    <?php global $post; ?>
    <?php if ( !(gridfeel_get_option('hide_page_author')) || !(gridfeel_get_option('hide_page_date')) || !(gridfeel_get_option('hide_page_comments')) ) { ?>
    <?php if ( !((is_front_page()) && (gridfeel_get_option('hide_static_page_meta'))) ) { ?>
    <div class="gridfeel-entry-meta-single">
    <?php if ( !(gridfeel_get_option('hide_page_author')) ) { ?><span class="gridfeel-entry-meta-single-author"><i class="far fa-user-circle" aria-hidden="true"></i>&nbsp;<span class="author vcard" itemscope="itemscope" itemtype="http://schema.org/Person" itemprop="author"><a class="url fn n" href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>"><?php echo esc_html( get_the_author() ); ?></a></span></span><?php } ?>
    <?php if ( gridfeel_get_option('page_date_type') == 'updated' ) { ?>
        <?php if ( !(gridfeel_get_option('hide_page_date')) ) { ?><span class="gridfeel-entry-meta-single-date"><i class="far fa-clock" aria-hidden="true"></i>&nbsp;<?php echo esc_html( get_the_modified_date() ); ?></span><?php } ?>
    <?php } else { ?>
        <?php if ( !(gridfeel_get_option('hide_page_date')) ) { ?><span class="gridfeel-entry-meta-single-date"><i class="far fa-clock" aria-hidden="true"></i>&nbsp;<?php echo esc_html( get_the_date() ); ?></span><?php } ?>
    <?php } ?>
    <?php if ( !(gridfeel_get_option('hide_page_comments')) ) { ?><?php if ( ! post_password_required() && ( comments_open() || get_comments_number() ) ) { ?>
    <span class="gridfeel-entry-meta-single-comments"><i class="far fa-comments" aria-hidden="true"></i>&nbsp;<?php comments_popup_link( sprintf( wp_kses( /* translators: %s: post title */ __( 'Leave a Comment<span class="gridfeel-sr-only"> on %s</span>', 'gridfeel' ), array( 'span' => array( 'class' => array(), ), ) ), wp_kses_post( get_the_title() ) ) ); ?></span>
    <?php } ?><?php } ?>
    </div>
    <?php } ?>
    <?php } ?>
<?php }
endif;

if ( ! function_exists( 'gridfeel_grid_media_bottom_data' ) ) :
function gridfeel_grid_media_bottom_data() { ?>
    <?php global $post; ?>
    <?php if ( (!(gridfeel_get_option('hide_post_categories_home')) && has_category()) || !(gridfeel_get_option('hide_post_title_home')) || !(gridfeel_get_option('hide_post_author_home')) || !(gridfeel_get_option('hide_posted_date_home')) || (gridfeel_get_option('show_comments_link_home') && (! post_password_required() && ( comments_open() || get_comments_number() ))) ) { ?>
    <div class="gridfeel-thumbnail-overlay gridfeel-clearfix">
    <div class="gridfeel-thumbnail-overlay-inside gridfeel-clearfix">

    <?php if ( !(gridfeel_get_option('hide_post_categories_home')) && has_category() ) { ?><?php gridfeel_grid_cats(); ?><?php } ?>

    <?php if ( !(gridfeel_get_option('hide_post_title_home')) ) { ?>

    <?php if ( gridfeel_get_option('remove_post_title_link_home') ) { ?>
        <?php if ( gridfeel_get_option('limit_post_titles_home') ) { ?>
            <div class="gridfeel-grid-post-header gridfeel-grid-post-block gridfeel-clearfix"><h3 class="gridfeel-grid-post-title"><?php echo esc_html( wp_trim_words( get_the_title(), gridfeel_grid_post_title_length(), '...' ) ); ?></h3></div>
        <?php } else { ?>
            <div class="gridfeel-grid-post-header gridfeel-grid-post-block gridfeel-clearfix"><?php the_title( '<h3 class="gridfeel-grid-post-title">', '</h3>' ); ?></div>
        <?php } ?>
    <?php } else { ?>
        <?php if ( gridfeel_get_option('limit_post_titles_home') ) { ?>
            <div class="gridfeel-grid-post-header gridfeel-grid-post-block gridfeel-clearfix"><h3 class="gridfeel-grid-post-title"><a href="<?php echo esc_url( get_permalink() ); ?>" rel="bookmark"><?php echo esc_html( wp_trim_words( get_the_title(), gridfeel_grid_post_title_length(), '...' ) ); ?></a></h3></div>
        <?php } else { ?>
            <div class="gridfeel-grid-post-header gridfeel-grid-post-block gridfeel-clearfix"><?php the_title( sprintf( '<h3 class="gridfeel-grid-post-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h3>' ); ?></div>
        <?php } ?>
    <?php } ?>

    <?php } ?>

    <?php if ( !(gridfeel_get_option('hide_post_author_home')) || !(gridfeel_get_option('hide_posted_date_home')) || (gridfeel_get_option('show_comments_link_home') && (! post_password_required() && ( comments_open() || get_comments_number() ))) ) { ?>
    <div class="gridfeel-grid-post-details gridfeel-grid-post-block">
    <div class="gridfeel-grid-post-details-inside">
    <?php if ( !(gridfeel_get_option('hide_post_author_home')) ) { ?><span class="gridfeel-grid-post-author gridfeel-grid-post-meta"><a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>"><?php echo esc_html( get_the_author() ); ?></a></span><?php } ?>
    <?php if ( gridfeel_get_option('post_date_home_type') == 'updated' ) { ?>
        <?php if ( !(gridfeel_get_option('hide_posted_date_home')) ) { ?><span class="gridfeel-grid-post-date gridfeel-grid-post-meta"><?php echo esc_html( get_the_modified_date() ); ?></span><?php } ?>
    <?php } else { ?>
        <?php if ( !(gridfeel_get_option('hide_posted_date_home')) ) { ?><span class="gridfeel-grid-post-date gridfeel-grid-post-meta"><?php echo esc_html( get_the_date() ); ?></span><?php } ?>
    <?php } ?>
    <?php if ( gridfeel_get_option('show_comments_link_home') && (! post_password_required() && ( comments_open() || get_comments_number() )) ) { ?><span class="gridfeel-grid-post-comments gridfeel-grid-post-meta"><?php comments_popup_link( sprintf( wp_kses( /* translators: %s: post title */ __( '0 Comment<span class="gridfeel-sr-only"> on %s</span>', 'gridfeel' ), array( 'span' => array( 'class' => array(), ), ) ), wp_kses_post( get_the_title() ) ) ); ?></span><?php } ?>
    </div>
    </div>
    <?php } ?>

    </div>
    </div>
    <?php } ?>
<?php }
endif;