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

if ( ! function_exists( 'covfefe_posted_on' ) ) :
	/**
	 * Prints HTML with meta information for the current post-date/time.
	 */
	function covfefe_posted_on() {
		echo '<div class="entry-meta--text">';
		/* translators: used between list items, there is a space after the comma */
		$categories_list = get_the_category_list( esc_html__( ', ', 'covfefe' ) );
		if ( $categories_list ) {
			/* translators: 1: list of categories. */
			echo '<span class="cat-links">' . wp_kses_post( $categories_list ). ' | </span>  '; 
		}
		

		
		$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( DATE_W3C ) ),
			esc_html( get_the_date() ),
			esc_attr( get_the_modified_date( DATE_W3C ) ),
			esc_html( get_the_modified_date() )
		);

	

		echo '<span class="posted-on">' .  '<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>' . '</span>'; // WPCS: XSS OK.
		echo '</div>';
	}
endif;

if ( ! function_exists( 'covfefe_posted_by' ) ) :
	/**
	 * Prints HTML with meta information for the current author.
	 */
	function covfefe_posted_by() {
		echo '<div class="entry-meta--circle">'. wp_kses_post( covfefe_post_format_icon() ) . '</div>';
		echo '<div class="entry-meta--circle">'. get_avatar( get_the_author_meta( 'ID' ), 48 ) . '</div>';
		echo '<div class="entry-meta--text">';
		echo '<span class="byline"> ' . '<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>' . '</span>'; // WPCS: XSS OK.
		echo '</div>';

	}
endif;

if ( ! function_exists( 'covfefe_entry_footer' ) ) :
	/**
	 * Prints HTML with meta information for the categories, tags and comments.
	 */
	function covfefe_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( '', esc_html_x( ', ', 'list item separator', 'covfefe' ) );
			if ( $tags_list ) {
				/* translators: 1: list of tags. */
				printf( '<span class="tags-links">' . esc_html__( 'Tagged %1$s', 'covfefe' ) . '</span>', $tags_list ); // WPCS: XSS OK.
			}
		}

		if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
			echo '<span class="comments-link">';
			comments_popup_link(
				sprintf(
					wp_kses(
						/* translators: %s: post title */
						__( 'Leave a Comment<span class="screen-reader-text"> on %s</span>', 'covfefe' ),
						array(
							'span' => array(
								'class' => array(),
							),
						)
					),
					get_the_title()
				)
			);
			echo '</span>';
		}

		edit_post_link(
			sprintf(
				wp_kses(
					/* translators: %s: Name of current post. Only visible to screen readers */
					__( 'Edit <span class="screen-reader-text">%s</span>', 'covfefe' ),
					array(
						'span' => array(
							'class' => array(),
						),
					)
				),
				get_the_title()
			),
			'<span class="edit-link">',
			'</span>'
		);
	}
endif;

if ( ! function_exists( 'covfefe_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.
	 */
	function covfefe_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" tabindex="-1">
			<?php
			the_post_thumbnail( 'post-thumbnail', array(
				'alt' => the_title_attribute( array(
					'echo' => false,
				) ),
			) );
			?>
		</a>

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

// post icon
if ( ! function_exists( 'covfefe_post_format_icon' ) ) :
	function covfefe_post_format_icon() {
		switch ( get_post_format() ) {
			case 'audio': $icon = 'fa-volume-up'; break;
			case 'aside' : $icon = 'fa-sticky-note'; break;
			case 'chat' : $icon = 'fa-list-alt'; break;
			case 'image': $icon = 'fa-camera-retro'; break;
			case 'link' : $icon = 'fa-link	'; break;
			case 'gallery': $icon = 'fa-newspaper-o'; break;
			case 'status' : $icon = 'fa-commenting'; break;
			case 'video': $icon = 'fa-file-video-o'; break;
			case 'quote': $icon = 'fa-quote-left'; break;
			default: $icon = 'fa-pencil-square-o'; break;
		}
		return '<i class="fa ' . $icon . '"></i>';
	}
endif;


// Footer Widget

if ( ! function_exists( 'covfefe_footer_widgets' ) ) :
	function covfefe_footer_widgets() {
		$footer_1 = ''; $footer_2 = ''; $footer_3 = '';  $footer_columns = 0; $footer_class = 'col-md-4';
		if ( is_active_sidebar( 'footer-1') ) {
			$footer_1 = 1; $footer_columns++;
		}
		if ( is_active_sidebar( 'footer-2' ) ) {
			$footer_2 = 1; $footer_columns++;
		}
		if ( is_active_sidebar( 'footer-3') ) {
			$footer_3 = 1; $footer_columns++;
		}
		
		if ( $footer_columns == 1 ) {
			$footer_class = 'col-md-12';
		} 
		
		if ( $footer_1 || $footer_2 || $footer_3 ) {
			
				echo '<div class="container">';
					echo '<div class="row">';
						if ( $footer_1 ) {
							echo '<div class="' . esc_attr( $footer_class ) . '">' . "\n";
								dynamic_sidebar( 'footer-1' );
							echo '</div>' . "\n";
							
							if ($footer_columns == 2) {
								$footer_class = 'col-md-8';
							}
						}
						if ($footer_2) {
							echo '<div class="' . esc_attr( $footer_class ) . '">' . "\n";
								dynamic_sidebar( 'footer-2' );
							echo '</div>' . "\n";
							if ($footer_columns == 2) {
								$footer_class = 'col-md-8';
							}
						}
						if ($footer_3) {
							echo '<div class="' . esc_attr( $footer_class ) . '">' . "\n";
								dynamic_sidebar( 'footer-3' );
							echo '</div>' . "\n";
						}
					echo '</div>';
				echo '</div>';
			
		}
	}
endif;

if ( ! function_exists( 'covfefe_echo' ) ) :
	function covfefe_echo($start = '', $contain='',$end='') {
		if ($contain) {
			$temp = $start . $contain . $end;
			echo wp_kses_post( $temp );
		}
	}
endif;