<?php
/**
 * Functions which enhance the theme by hooking into WordPress
 *
 * @package Author Blog
 */
/**
 * Adds custom classes to the array of body classes.
 *
 * @param array $classes Classes for the body element.
 * @return array
 */
function author_blog_body_classes( $classes ) {
	// Adds a class of hfeed to non-singular pages.
	if ( ! is_singular() ) {
		$classes[] = 'hfeed';
	}
	$classes[]             = 'preloader-wrapper';
	$get_border_box_shadow = get_theme_mod( 'border_box_shadow_show_hide', true );
	if ( false == $get_border_box_shadow ) {
		$classes[] = 'border_and_box_shadow_hide';
	}
	// Adds a class of no-sidebar when there is no sidebar present.
	if ( ! is_active_sidebar( 'sidebar-1' ) ) {
		$classes[] = 'no-sidebar';
	}
	return $classes;
}
add_filter( 'body_class', 'author_blog_body_classes' );
/**
 * Add a pingback url auto-discovery header for single posts, pages, or attachments.
 */
function author_blog_pingback_header() {
	if ( is_singular() && pings_open() ) {
		echo '<link rel="pingback" href="', esc_url( get_bloginfo( 'pingback_url' ) ), '">';
	}
}
add_action( 'wp_head', 'author_blog_pingback_header' );
if ( ! function_exists( 'author_blog_comment_list' ) ) :
	/**
	 * Template for comments and pingbacks.
	 *
	 * Used as a callback by wp_list_comments() for displaying the comments.
	 *
	 * @since Shape 1.0
	 */
	function author_blog_comment_list( $comment, $args, $depth ) {
		extract( $args, EXTR_SKIP );
		if ( 'div' == $args['style'] ) {
			$tag       = 'div';
			$add_below = 'comment';
		} else {
			$tag       = 'li';
			$add_below = 'div-comment';
		}
		?>
  <<?php echo esc_attr( $tag ); ?> <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ); ?> id="comment-<?php comment_ID(); ?>">
		<?php if ( 'div' == $args['style'] ) : ?>
  <div id="div-comment-<?php comment_ID(); ?>" class="comment-body review-list">
	<?php endif; ?>
	<div class="single-comment">
		<div class="commenter-image">
			<?php
			if ( 0 != $args['avatar_size'] ) {
				echo get_avatar( $comment, $args['avatar_size'] );}
			?>
		</div>
		<div class="commnenter-details">
		<?php if ( $comment->comment_approved == '0' ) : ?>
			<em><?php esc_html_e( 'Your comment is awaiting moderation.', 'author-blog' ); ?></em>
			<br />
		<?php endif; ?>
			<div class="comment-meta">
				<h4><?php printf( wp_kses_post( '%s', 'author-blog' ), sprintf( '%s', get_comment_author_link() ) ); ?></h4>
				<div class="comment-time">
					<p>
						<time datetime="<?php comment_time( 'c' ); ?>">
							<?php
								echo esc_html( get_comment_date() . ' ' );
								echo esc_html( get_comment_time() );
							?>
						</time>
					</p>
				</div>
			</div>
				<?php comment_text(); ?>
				<?php
				comment_reply_link(
					array_merge(
						$args,
						array(
							'depth'     => $depth,
							'max_depth' => $args['max_depth'],
							'before'    => '<div class="reply">',
							'after'     => '</div>',
						)
					)
				);
				?>
		</div>
	</div>
		<?php if ( 'div' == $args['style'] ) : ?>
  </div>
			<?php
  endif;
	}
endif; // ends check for author_blog_comment_list();
/**
 * author_blog Breadcrumbs
 */
if ( ! function_exists( 'author_blog_bredcrumbs' ) ) {
	function author_blog_bredcrumbs() {
		?>
		<nav>
			<div class="breadcrumb">
				<?php
				if ( function_exists( 'yoast_breadcrumb' ) ) {
					yoast_breadcrumb( '<p id="breadcrumbs">', '</p>' );
				}
				?>
			</div>
		</nav>
		<?php
	}
}
/**
 * Author VCard
 */
function author_blog_author_vcard() {
	?>
	<div class="author-vcard">
		<div class="author-vcard__image">
			<?php
			echo get_avatar( get_the_author_meta( 'ID' ), 100, '', '', null );
			?>
		</div>
		<div class="author-vcard__about">
			<h4><?php echo esc_html( get_the_author_meta( 'nickname' ) ); ?></h4>
			<p><?php echo wp_kses_post( get_the_author_meta( 'description' ) ); ?></p>
			<p>
			<?php
			$userpost_count = count_user_posts( get_the_author_meta( 'ID' ), 'post', false );
			if ( $userpost_count > 1 ) {
				$numberingtext = 'posts';
			} else {
				$numberingtext = 'post';
			}
			$userposts = esc_html__( 'the user has only %1$s %2$s', 'author-blog' );
			printf( $userposts, $userpost_count, $numberingtext );
			?>
			 </p>
		</div>
	</div>
	<?php
	return;
}


function author_blog_utm_url($medium){
    $rawUrl = sprintf(
        'https://rswpthemes.com/author-blog-pro-wordpress-theme/?utm_source=free_theme&utm_medium=%s&utm_campaign=author_blog',
        rawurlencode($medium)
    );
    return $rawUrl;
}

function author_blog_post_page_pagination(){
	$prev_post = get_adjacent_post(false, '', true);
	$next_post = get_adjacent_post(false, '', false);
	?>
	<div class="d-flex single-post-navigation justify-content-between">
		<?php if (get_previous_post_link()): ?>
			<div class="previous-post">
				<div class="postarrow">
					<a href="<?php echo get_permalink($prev_post->ID); ?>">
						<i class="fa fa-long-arrow-left"></i><?php echo esc_html_e( 'Previous Post', 'author-blog' ); ?>
					</a>
				</div>
				<?php echo wp_kses_post( get_previous_post_link( '%link' ) ); ?>
			</div>
		<?php endif;
		if(get_next_post_link()): ?>
			<div class="next-post">
				<div class="postarrow">
					<a href="<?php echo get_permalink($next_post->ID); ?>">
						<?php echo esc_html_e( 'Next Post', 'author-blog' ); ?><i class="fa fa-long-arrow-right"></i>
					</a>
				</div>
				<?php echo wp_kses_post( get_next_post_link( '%link' ) ); ?>
			</div>
		<?php endif;
		?>
	</div>
	<?php
}