<?php
/**
 * Custom template tags for this theme
 *
 * Eventually, some of the functionality here could be replaced by core features.
 *
 * @package customify
 */

if ( ! function_exists( 'customify_posted_on' ) ) :
	/**
	 * Prints HTML with meta information for the current post-date/time and author.
	 */
	function customify_posted_on() {
		$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
		if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
			$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
		}

		$time_string = sprintf(
			$time_string,
			esc_attr( get_the_date( 'c' ) ),
			esc_html( get_the_date() ),
			esc_attr( get_the_modified_date( 'c' ) ),
			esc_html( get_the_modified_date() )
		);

		$posted_on = sprintf(
			/* translators: %s: post date. */
			esc_html_x( 'Posted on %s', 'post date', 'customify' ),
			'<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>'
		);

		$byline = sprintf(
			/* translators: %s: post author. */
			esc_html_x( 'by %s', 'post author', 'customify' ),
			'<span class="author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author() ) . '</a></span>'
		);

		echo '<span class="posted-on">' . $posted_on . '</span><span class="byline"> ' . $byline . '</span>'; // WPCS: XSS OK.

	}
endif;

if ( ! function_exists( 'customify_entry_footer' ) ) :
	/**
	 * Prints HTML with meta information for the categories, tags and comments.
	 */
	function customify_entry_footer() {
		// Hide category and tag text for pages.
		if ( 'post' === get_post_type() ) {

			/* translators: used between list items, there is a space after the comma */
			$tags_list = get_the_tag_list( '', ' ' );
			if ( $tags_list ) {
				/* translators: 1: list of tags. */
				printf( '<div class="tags-links">%1$s</div>', $tags_list ); // WPCS: XSS OK.
			}
		}
	}
endif;


if ( ! function_exists( 'customify_comment' ) ) :
	/**
	 * Template for comments and pingbacks.
	 *
	 * To override this walker in a child theme without modifying the comments template
	 * simply create your own customify_comment(), and that function will be used instead.
	 *
	 * Used as a callback by wp_list_comments() for displaying the comments.
	 *
	 * @param object $comment Comment item.
	 * @param array  $args    Comment settings.
	 * @param int    $depth   Current depth.
	 *
	 * @return void
	 */
	function customify_comment( $comment, $args, $depth ) {
		switch ( $comment->comment_type ) {
			case 'pingback':
			case 'trackback':
				// Display trackbacks differently than normal comments.
				?>
				<li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">
				<p><?php _e( 'Pingback:', 'customify' ); ?><?php comment_author_link(); ?><?php edit_comment_link( __( '(Edit)', 'customify' ), '<span class="edit-link">', '</span>' ); ?></p>
				<?php
				break;
			default:
				// Proceed with normal comments.
				global $post;
				?>
			<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
				<article id="comment-<?php comment_ID(); ?>" class="comment clearfix">
					<div class="comment-image">
						<?php echo get_avatar( $comment, 60 ); ?>
					</div>
					<div class="comment-reply">

					</div>
					<div class="comment-wrap">
						<header class="comment-header">
							<?php
							// If current post author is also comment author, make it known visually.
							// Guest comments carry `user_id` 0, and a post whose author was
							// deleted (or that was inserted programmatically) carries
							// `post_author` 0 — the old strict comparison matched 0 === 0 and
							// badged EVERY guest comment as "Post author". Require a real
							// account, and compare as integers because the two values do not
							// reliably arrive with the same type.
							$customify_is_post_author = $post instanceof WP_Post
								&& (int) $comment->user_id > 0
								&& (int) $comment->user_id === (int) $post->post_author;
							printf(
								'<cite class="comment-author fn vcard">%1$s %2$s</cite>',
								get_comment_author_link(),
								$customify_is_post_author ? '<span class="comment-post-author text-uppercase text-xsmall">' . __( 'Post author', 'customify' ) . '</span>' : ''
							);
							?>
							<div class="comment-meta text-uppercase text-xsmall link-meta">
								<a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
									<time datetime="<?php comment_time( 'c' ); ?>">
										<?php printf( _x( '%1$s at %2$s', '1: date, 2: time', 'customify' ), get_comment_date(), get_comment_time() ); ?>
									</time>
								</a>
								<?php edit_comment_link( __( 'Edit', 'customify' ) ); ?>
								<div class="comment-reply pull-right">
									<?php comment_reply_link(
										array_merge(
											$args,
											array(
												'reply_text' => __( 'Reply', 'customify' ),
												'after'      => '',
												'depth'      => $depth,
												'max_depth'  => $args['max_depth'],
											)
										)
									); ?>
								</div>
							</div>

						</header><!-- .comment-meta -->

						<?php if ( '0' == $comment->comment_approved ) : ?>
							<p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'customify' ); ?></p>
						<?php endif; ?>

						<div class="comment-content entry-content">
							<?php comment_text(); ?>
						</div><!-- .comment-content -->

					</div><!--/comment-wrapper-->

				</article><!-- #comment-## -->
				<?php
				break;
		} // End comment_type check.
	}
endif;

if ( ! function_exists( 'customify_nav_next_icon' ) ) {
	function customify_nav_next_icon() {
		return '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 129 129" xmlns:xlink="http://www.w3.org/1999/xlink" enable-background="new 0 0 129 129"><g><path d="m40.4,121.3c-0.8,0.8-1.8,1.2-2.9,1.2s-2.1-0.4-2.9-1.2c-1.6-1.6-1.6-4.2 0-5.8l51-51-51-51c-1.6-1.6-1.6-4.2 0-5.8 1.6-1.6 4.2-1.6 5.8,0l53.9,53.9c1.6,1.6 1.6,4.2 0,5.8l-53.9,53.9z"/></g></svg>';
	}
}

add_filter( 'customify_nav_next_icon', 'customify_nav_next_icon' );


if ( ! function_exists( 'customify_nav_prev_icon' ) ) {
	function customify_nav_prev_icon() {
		return '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 129 129" xmlns:xlink="http://www.w3.org/1999/xlink" enable-background="new 0 0 129 129"><g><path d="m88.6,121.3c0.8,0.8 1.8,1.2 2.9,1.2s2.1-0.4 2.9-1.2c1.6-1.6 1.6-4.2 0-5.8l-51-51 51-51c1.6-1.6 1.6-4.2 0-5.8s-4.2-1.6-5.8,0l-54,53.9c-1.6,1.6-1.6,4.2 0,5.8l54,53.9z"/></g></svg>';
	}
}

add_filter( 'customify_nav_prev_icon', 'customify_nav_prev_icon' );
