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

if ( ! function_exists( 'theia_lite_posted_on' ) ) :
/**
 * Prints HTML with meta information for the current post-date/time and author.
 */
function theia_lite_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 = '<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>';
	$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>';

	echo '<span class="byline spaceBright"><i class="fa fa-user spaceRight" aria-hidden="true"></i>' . $byline . '</span><span class="posted-on spaceBright"><i class="fa fa-calendar spaceRight" aria-hidden="true"></i>' . $posted_on . '</span>'; // WPCS: XSS OK.
}
endif;

if ( ! function_exists( 'theia_lite_entry_footer' ) ) :
/**
 * Prints HTML with meta information for the categories, tags and comments.
 */
function theia_lite_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__( ', ', 'theia-lite' ) );
			if ( $tags_list ) {
				echo '<span class="tags-links spaceBright"><i class="fa fa-tags spaceRight" aria-hidden="true"></i>' . $tags_list . '</span>';
			}
		}
		
	
	edit_post_link( esc_html__( 'Edit', 'theia-lite' ), '<span class="edit-link spaceBright"><i class="fa fa-wrench spaceRight" aria-hidden="true"></i>', '</span>' );
}
endif;

/**
 * Returns true if a blog has more than 1 category.
 *
 * @return bool
 */
if ( ! function_exists( 'theia_lite_categorized_blog' ) ) : 
function theia_lite_categorized_blog() {
	if ( false === ( $all_the_cool_cats = get_transient( 'theia_lite_categories' ) ) ) {
		// Create an array of all the categories that are attached to posts.
		$all_the_cool_cats = get_categories( array(
			'fields'     => 'ids',
			'hide_empty' => 1,
			// 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( 'theia_lite_categories', $all_the_cool_cats );
	}

	if ( $all_the_cool_cats > 1 ) {
		// This blog has more than 1 category so theia_lite_categorized_blog should return true.
		return true;
	} else {
		// This blog has only 1 category so theia_lite_categorized_blog should return false.
		return false;
	}
}
endif;
/**
 * Flush out the transients used in theia_lite_categorized_blog.
 */
if ( ! function_exists( 'theia_lite_category_transient_flusher' ) ) :  
function theia_lite_category_transient_flusher() {
	if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
		return;
	}
	// Like, beat it. Dig?
	delete_transient( 'theia_lite_categories' );
}
add_action( 'edit_category', 'theia_lite_category_transient_flusher' );
add_action( 'save_post',     'theia_lite_category_transient_flusher' );
endif;
 /**
 * Social Buttons
 */
if ( ! function_exists( 'theia_lite_social_buttons' ) ) :
	function theia_lite_social_buttons() {
		$facebookURL = get_theme_mod('theia_lite_theme_options_facebookurl', '');
		$twitterURL = get_theme_mod('theia_lite_theme_options_twitterurl', '');
		$googleplusURL = get_theme_mod('theia_lite_theme_options_googleplusurl', '');
		$linkedinURL = get_theme_mod('theia_lite_theme_options_linkedinurl', '');
		$instagramURL = get_theme_mod('theia_lite_theme_options_instagramurl', '');
		$youtubeURL = get_theme_mod('theia_lite_theme_options_youtubeurl', '');
		$pinterestURL = get_theme_mod('theia_lite_theme_options_pinteresturl', '');
		$tumblrURL = get_theme_mod('theia_lite_theme_options_tumblrurl', '');
		$flickrURL = get_theme_mod('theia_lite_theme_options_flickrurl', '');
		$vkURL = get_theme_mod('theia_lite_theme_options_vkurl', '');
		$facebookmessengerURL = get_theme_mod('theia_lite_theme_options_facebookmessengerurl', '');
		$skypeNAME = get_theme_mod('theia_lite_theme_options_skypename', '');
	?>
			<?php if (!empty($facebookURL)) : ?>
				<a href="<?php echo esc_url($facebookURL); ?>" title="<?php esc_attr_e( 'Facebook', 'theia-lite' ); ?>"><i class="fa fa-facebook spaceLeftRightS"><span class="screen-reader-text"><?php esc_html_e( 'Facebook', 'theia-lite' ); ?></span></i></a>
			<?php endif; ?>
			<?php if (!empty($twitterURL)) : ?>
				<a href="<?php echo esc_url($twitterURL); ?>" title="<?php esc_attr_e( 'Twitter', 'theia-lite' ); ?>"><i class="fa fa-twitter spaceLeftRightS"><span class="screen-reader-text"><?php esc_html_e( 'Twitter', 'theia-lite' ); ?></span></i></a>
			<?php endif; ?>
			<?php if (!empty($linkedinURL)) : ?>
				<a href="<?php echo esc_url($linkedinURL); ?>" title="<?php esc_attr_e( 'Linkedin', 'theia-lite' ); ?>"><i class="fa fa-linkedin spaceLeftRightS"><span class="screen-reader-text"><?php esc_html_e( 'Linkedin', 'theia-lite' ); ?></span></i></a>
			<?php endif; ?>
			<?php if (!empty($instagramURL)) : ?>
				<a href="<?php echo esc_url($instagramURL); ?>" title="<?php esc_attr_e( 'Instagram', 'theia-lite' ); ?>"><i class="fa fa-instagram spaceLeftRightS"><span class="screen-reader-text"><?php esc_html_e( 'Instagram', 'theia-lite' ); ?></span></i></a>
			<?php endif; ?>
			<?php if (!empty($youtubeURL)) : ?>
				<a href="<?php echo esc_url($youtubeURL); ?>" title="<?php esc_attr_e( 'YouTube', 'theia-lite' ); ?>"><i class="fa fa-youtube spaceLeftRightS"><span class="screen-reader-text"><?php esc_html_e( 'YouTube', 'theia-lite' ); ?></span></i></a>
			<?php endif; ?>
			<?php if (!empty($pinterestURL)) : ?>
				<a href="<?php echo esc_url($pinterestURL); ?>" title="<?php esc_attr_e( 'Pinterest', 'theia-lite' ); ?>"><i class="fa fa-pinterest spaceLeftRightS"><span class="screen-reader-text"><?php esc_html_e( 'Pinterest', 'theia-lite' ); ?></span></i></a>
			<?php endif; ?>
			<?php if (!empty($tumblrURL)) : ?>
				<a href="<?php echo esc_url($tumblrURL); ?>" title="<?php esc_attr_e( 'Tumblr', 'theia-lite' ); ?>"><i class="fa fa-tumblr spaceLeftRightS"><span class="screen-reader-text"><?php esc_html_e( 'Tumblr', 'theia-lite' ); ?></span></i></a>
			<?php endif; ?>
			<?php if (!empty($flickrURL)) : ?>
				<a href="<?php echo esc_url($flickrURL); ?>" title="<?php esc_attr_e( 'Flickr', 'theia-lite' ); ?>"><i class="fa fa-flickr spaceLeftRightS"><span class="screen-reader-text"><?php esc_html_e( 'Flickr', 'theia-lite' ); ?></span></i></a>
			<?php endif; ?>
			<?php if (!empty($vkURL)) : ?>
				<a href="<?php echo esc_url($vkURL); ?>" title="<?php esc_attr_e( 'VK', 'theia-lite' ); ?>"><i class="fa fa-vk spaceLeftRightS"><span class="screen-reader-text"><?php esc_html_e( 'VK', 'theia-lite' ); ?></span></i></a>
			<?php endif; ?>
			<?php if (!empty($facebookmessengerURL)) : ?>
				<a href="<?php echo esc_url($facebookmessengerURL); ?>" title="<?php esc_attr_e( 'Facebook Messenger', 'theia-lite' ); ?>"><i class="fa fa-commenting-o spaceLeftRightS"><span class="screen-reader-text"><?php esc_html_e( 'Facebook Messenger', 'theia-lite' ); ?></span></i></a>
			<?php endif; ?>
			<?php if (!empty($skypeNAME)) : ?>
				<a href="skype:<?php echo esc_attr($skypeNAME); ?>?call" title="<?php esc_attr_e( 'Skype', 'theia-lite' ); ?>"><i class="fa fa-skype spaceLeftRightS"><span class="screen-reader-text"><?php esc_html_e( 'Skype', 'theia-lite' ); ?></span></i></a>
			<?php endif;
	}
endif;