<?php
/**
 * Add post shortcodes.
 *
 * @package SplendorStudio\Framework\Templates\Fragments
 *
 * @since   1.0.0
 */

Fancify_Lite_Actions::add_smart_action( 'fancify_lite_post_meta_date', 'fancify_lite_post_meta_date_shortcode' );
/**
 * Echo post meta date shortcode.
 *
 * @since 1.0.0
 *
 * @return void
 */
function fancify_lite_post_meta_date_shortcode() {
	fancify_lite_output_e( 'fancify_lite_post_meta_date_prefix', esc_html__( 'Posted on ', 'fancify-lite' ) );

	fancify_lite_open_markup_e(
		'fancify_lite_post_meta_date',
		'time',
		array(
			'datetime' => esc_attr( get_the_time( 'c' ) ),
			'itemprop' => 'datePublished',
		)
	);

		fancify_lite_output_e( 'fancify_lite_post_meta_date_text', esc_html( get_the_time( get_option( 'date_format' ) ) ) );

	fancify_lite_close_markup_e( 'fancify_lite_post_meta_date', 'time' );
}

Fancify_Lite_Actions::add_smart_action( 'fancify_lite_post_meta_author', 'fancify_lite_post_meta_author_shortcode' );
/**
 * Echo post meta author shortcode.
 *
 * @since 1.0.0
 *
 * @return void
 */
function fancify_lite_post_meta_author_shortcode() {
	fancify_lite_output_e( 'fancify_lite_post_meta_author_prefix', esc_html__( 'By ', 'fancify-lite' ) );

	fancify_lite_open_markup_e(
		'fancify_lite_post_meta_author',
		'a',
		array(
			'href'      => esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
			'rel'       => 'author',
			'itemprop'  => 'author',
			'itemscope' => '',
			'itemtype'  => 'https://schema.org/Person',
		)
	);

		fancify_lite_output_e( 'fancify_lite_post_meta_author_text', esc_html( get_the_author() ) );

		fancify_lite_selfclose_markup_e(
			'fancify_lite_post_meta_author_name_meta',
			'meta',
			array(
				'itemprop' => 'name',
				'content'  => esc_attr( get_the_author() ),
			)
		);

	fancify_lite_close_markup_e( 'fancify_lite_post_meta_author', 'a' );
}

Fancify_Lite_Actions::add_smart_action( 'fancify_lite_post_meta_comments', 'fancify_lite_post_meta_comments_shortcode' );
/**
 * Echo post meta comments shortcode.
 *
 * @since 1.0.0
 *
 * @return void
 */
function fancify_lite_post_meta_comments_shortcode() {
	if ( post_password_required() || ! comments_open() ) {
		return;
	}

	global $post;
	$comments_number = (int) get_comments_number( $post->ID );

	if ( $comments_number < 1 ) {
		$comment_text = fancify_lite_output( 'fancify_lite_post_meta_empty_comment_text', esc_html__( 'Leave a comment', 'fancify-lite' ) );
	} elseif ( 1 === $comments_number ) {
		$comment_text = fancify_lite_output( 'fancify_lite_post_meta_comments_text_singular', esc_html__( '1 comment', 'fancify-lite' ) );
	} else {
		$comment_text = fancify_lite_output(
			'fancify_lite_post_meta_comments_text_plural',
			// translators: %s: Number of comments. Plural.
			esc_html__( '%s comments', 'fancify-lite' )
		);
	}

	fancify_lite_open_markup_e( 'fancify_lite_post_meta_comments', 'a', array( 'href' => esc_url( get_comments_link() ) ) ); // Automatically escaped.

		printf( $comment_text, (int) get_comments_number( $post->ID ) ); // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped -- Escaping handled prior to this printf.

	fancify_lite_close_markup_e( 'fancify_lite_post_meta_comments', 'a' );
}

Fancify_Lite_Actions::add_smart_action( 'fancify_lite_post_meta_tags', 'fancify_lite_post_meta_tags_shortcode' );
/**
 * Echo post meta tags shortcode.
 *
 * @since 1.0.0
 *
 * @return void
 */
function fancify_lite_post_meta_tags_shortcode() {
	$tags = get_the_tag_list( null, ', ' );

	if ( ! $tags || is_wp_error( $tags ) ) {
		return;
	}

	printf( '%1$s%2$s', fancify_lite_output( 'fancify_lite_post_meta_tags_prefix', esc_html__( 'Tagged with: ', 'fancify-lite' ) ), $tags ); // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped -- Tags are escaped by WordPress.
}

Fancify_Lite_Actions::add_smart_action( 'fancify_lite_post_meta_categories', 'fancify_lite_post_meta_categories_shortcode' );
/**
 * Echo post meta categories shortcode.
 *
 * @since 1.0.0
 *
 * @return void
 */
function fancify_lite_post_meta_categories_shortcode() {
	$categories = get_the_category_list( ', ' );

	if ( ! $categories || is_wp_error( $categories ) ) {
		return;
	}

	printf( '%1$s%2$s', fancify_lite_output( 'fancify_lite_post_meta_categories_prefix', esc_html__( 'Filed under: ', 'fancify-lite' ) ), $categories ); // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped -- Categories are escaped by WordPress.
}
