<?php
/**
 * Custom menda Theme template tags
 *
 * Eventually, some of the functionality here could be replaced by core features.
 *
 * @package WordPress
 * @subpackage menda
 * @since menda Theme 1.0
 */

if ( ! function_exists( 'ebid_entry_meta' ) ) :
/**
 * Prints HTML with meta information for the categories, tags.
 *
 * Create your own ebid_entry_meta() function to override in a child theme.
 *
 * @since menda Theme 1.0
 */
function ebid_entry_meta() {
	if ( 'post' === get_post_type() ) {
			//	get_comments_number() ) ) {
		echo '<span class="comments-link">';
		comments_popup_link( sprintf( __( '<i class="fa fa-comment" aria-hidden="true"></i> comment<span class="screen-reader-text"> on %s</span>', 'menda' ), get_the_title() ) );
		echo '</span>';
	}
	
	if ( in_array( get_post_type(), array( 'post', 'attachment' ) ) ) {
		ebid_entry_date();
	}

	$format = get_post_format();
	?>
	<div class="view">
		<a href="<?php the_permalink(); ?>"> <i class="fa fa-eye" aria-hidden="true"></i>
		 
			 <?php
			echo ebid_post_counter(get_the_ID()); 
			
		
			_e( '&nbsp; views', 'menda' );
			
			?>
			
		</a>
	</div>
	
	<?php 
    if (is_single())
	{
		?>
	<div class="post-admin">
		<a href="<?php the_permalink(); ?>"><?php the_author_link(); ?> </a>
	</div>
	<?php
	}
	?>
	<?php

	if ( 'post' === get_post_type() ) {
		ebid_entry_taxonomies();
	}
 }
endif;

if ( ! function_exists( 'ebid_entry_date' ) ) :
/**
 * Prints HTML with date information for current post.
 *
 * Create your own ebid_entry_date() function to override in a child theme.
 *
 * @since menda Theme 1.0
 */
function ebid_entry_date() {
	$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' ) ),
		get_the_date(),
		esc_attr( get_the_modified_date( 'c' ) ),
		get_the_modified_date()
	);
	
	//$thumbs_post  = ebid_thumbnail();


	
	?>
	<?php
		if ( has_post_thumbnail() ) {
			?>
		<div class="blog-days">
		
		<?php  
	
		$post_date = get_the_date ('d M'); echo esc_html($post_date); 
		
		?>
		
		</div>
		<?php 
		  }	
		?>
	
<?php


}

endif;

if ( ! function_exists( 'ebid_entry_taxonomies' ) ) :
/**
 * Prints HTML with category and tags for current post.
 *
 * Create your own ebid_entry_taxonomies() function to override in a child theme.
 *
 * @since menda Theme 1.0
 */
function ebid_entry_taxonomies() {
	$categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'menda' ) );

	$tags_list = get_the_tag_list( '', _x( ', ', 'Used between list items, there is a space after the comma.', 'menda' ) );
	{
	?>
	
				
			<?php
	
	}

}

endif;


if ( ! function_exists( 'ebid_post_thumbnail' ) ) :
/**
 * Displays an optional post thumbnail.
 *
 * Wraps the post thumbnail in an anchor element on index views, or a div
 * element when on single views.
 *
 * Create your own ebid_post_thumbnail() function to override in a child theme.
 *
 * @since menda Theme 1.0
 */
function ebid_post_thumbnail() {
	if ( post_password_required() || is_attachment() || ! has_post_thumbnail() ) {
		return;
	}

	if ( is_singular() ) :
	?>

	<div class="post-thumbnail">
		<?php the_post_thumbnail(); ?>
	</div><!-- .post-thumbnail -->

	<?php else : ?>

	<a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true">
		<?php the_post_thumbnail( 'post-thumbnail', array( 'alt' => the_title_attribute( 'echo=0' ) ) ); ?>
	</a>

	<?php endif; // End is_singular()
}
endif;

if ( ! function_exists( 'ebid_excerpt' ) ) :
	/**
	 * Displays the optional excerpt.
	 *
	 * Wraps the excerpt in a div element.
	 *
	 * Create your own ebid_excerpt() function to override in a child theme.
	 *
	 * @since menda Theme 1.0
	 *
	 * @param string $class Optional. Class string of the div element. Defaults to 'entry-summary'.
	 */
	function ebid_excerpt( $class = 'entry-summary' ) {
		$class = esc_attr( $class );

		if ( has_excerpt() || is_search() ) : ?>
			<div class="<?php echo esc_attr( $class ); ?>">
				<?php the_excerpt(); ?>
			</div>
		<?php endif;
	}
endif;

if ( ! function_exists( 'ebid_excerpt_more' ) && ! is_admin() ) :
/**
 * Replaces "[...]" (appended to automatically generated excerpts) with ... and
 * a 'Continue reading' link.
 *
 * Create your own ebid_excerpt_more() function to override in a child theme.
 *
 * @since menda Theme 1.0
 *
 * @return string 'Continue reading' link prepended with an ellipsis.
 */
function ebid_excerpt_more() {
	$link = sprintf( '<a href="%1$s" class="more-link">%2$s</a>',
		esc_url( get_permalink( get_the_ID() ) ),
		/* translators: %s: Name of current post */
		sprintf( __( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'menda' ), get_the_title( get_the_ID() ) )
	);
	return ' &hellip; ' . $link;
}
add_filter( 'excerpt_more', 'ebid_excerpt_more' );
endif;

/**
 * Determines whether blog/site has more than one category.
 *
 * Create your own ebid_categorized_blog() function to override in a child theme.
 *
 * @since menda Theme 1.0
 *
 * @return bool True if there is more than one category, false otherwise.
 */
function ebid_categorized_blog() {
	if ( false === ( $all_the_cool_cats = get_transient( 'ebid_categories' ) ) ) {
		// Create an array of all the categories that are attached to posts.
		$all_the_cool_cats = get_categories( array(
			'fields'     => 'ids',
			// We only need to know if there is more than one category.
			'number'     => 2,
		) );

		// Count the number of categories that are attached to the posts.
		$all_the_cool_cats = count( $all_the_cool_cats );

		set_transient( 'ebid_categories', $all_the_cool_cats );
	}

	if ( $all_the_cool_cats > 1 ) {
		// This blog has more than 1 category so ebid_categorized_blog should return true.
		return true;
	} else {
		// This blog has only 1 category so ebid_categorized_blog should return false.
		return false;
	}
}

/**
 * Flushes out the transients used in ebid_categorized_blog().
 *
 * @since menda Theme 1.0
 */
function ebid_category_transient_flusher() {
	if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
		return;
	}
	// Like, beat it. Dig?
	delete_transient( 'ebid_categories' );
}
add_action( 'edit_category', 'ebid_category_transient_flusher' );
add_action( 'save_post',     'ebid_category_transient_flusher' );

if ( ! function_exists( 'ebid_the_custom_logo' ) ) :
/**
 * Displays the optional custom logo.
 *
 * Does nothing if the custom logo is not available.
 *
 * @since menda Theme 1.2
 */
function ebid_the_custom_logo() {
	if ( function_exists( 'the_custom_logo' ) ) {
		the_custom_logo();
	}
}
endif;