<?php
/**
 * Custom functions that act independently of the theme templates
 *
 * Eventually, some of the functionality here could be replaced by core features.
 *
 * @package Excel_Blog
 */

if ( ! function_exists( 'excel_blog_posted_on' ) ) :
/**
 * Prints HTML with meta information for the current post-date/time.
 */
function excel_blog_posted_on() {
	echo '<span class="posted-on"><i class="fa fa-calendar-o"></i><a href="' . esc_url( get_permalink() ) . '" rel="bookmark"><time class="entry-date">' . esc_html( get_the_date() ) . '</time></a></span>'; // WPCS: XSS OK.
    
    
}
endif;

if( ! function_exists( 'excel_blog_posted_by' ) ) :
/**
 * Prints HTML with meta information for the current post author.
*/
function excel_blog_posted_by(){
    echo '<span class="byline"><span class="author vcard"><i class="fa fa-user-o"></i><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>';
}
endif;

if( ! function_exists( 'excel_blog_comments_by' ) ) :
/**
 * Prints comments count and links for current post.
*/
function excel_blog_comments_by(){
    if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
		echo '<span class="comments-link"><i class="fa fa-comment"></i>';
		/* translators: %s: post title */
		comments_popup_link( sprintf( wp_kses( __( 'Leave a Comment<span class="screen-reader-text"> on %s</span>', 'excel-blog' ), array( 'span' => array( 'class' => array() ) ) ), get_the_title() ) );
		echo '</span>';
	}
}
endif;

if( ! function_exists( 'excel_blog_cat_tag' ) ) :
/**
 * Prints Category and Tags in single post.
*/
function excel_blog_cat_tag(){
    // Hide category and tag text for pages.
	if ( 'post' === get_post_type() ) {
		/* translators: used between list items, there is a space after the comma */
		$categories_list = get_the_category_list( esc_html__( ', ', 'excel-blog' ) );
		if ( $categories_list && excel_blog_categorized_blog() ) {
			printf( '<span class="cat-links">' . $categories_list . '</span>' );
		}

		/* translators: used between list items, there is a space after the comma */
		$tags_list = get_the_tag_list( '', esc_html__( ', ', 'excel-blog' ) );
		if ( $tags_list ) {
			printf( '<span class="tags-links">' . $tags_list . '</span>' );
		}
	}
}
endif;

if ( ! function_exists( 'excel_blog_entry_footer' ) ) :
/**
 * Prints HTML with meta information for the categories, tags and comments.
 */
function excel_blog_entry_footer() {
	edit_post_link(
		sprintf(
			/* translators: %s: Name of current post */
			esc_html__( 'Edit %s', 'excel-blog' ),
			the_title( '<span class="screen-reader-text">"', '"</span>', false )
		),
		'<span class="edit-link">',
		'</span>'
	);
}
endif;

/**
 * Returns true if a blog has more than 1 category.
 *
 * @return bool
 */
function excel_blog_categorized_blog() {
	if ( false === ( $all_the_cool_cats = get_transient( 'excel_blog_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( 'excel_blog_categories', $all_the_cool_cats );
	}

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

if( ! function_exists( 'excel_blog_get_social_links' ) ) :
/**
 * Get Social Links
*/
function excel_blog_get_social_links(){
    
    $facebook    = get_theme_mod( 'facebook' );
    $twitter     = get_theme_mod( 'twitter' );
    $pinterest   = get_theme_mod( 'pinterest' );
    $instagram   = get_theme_mod( 'instagram' );
    $linkedin    = get_theme_mod( 'linkedin' );
    $google_plus = get_theme_mod( 'google_plus' );
    $youtube     = get_theme_mod( 'youtube' );
    
    if( $facebook || $twitter || $instagram || $google_plus || $pinterest || $linkedin || $youtube ){
    ?>
    <ul class="social-networks">
		<?php if( $facebook ){ ?>
        <li><a href="<?php echo esc_url( $facebook ); ?>" class="fa fa-facebook" target="_blank" title="<?php esc_attr_e( 'Facebook', 'excel-blog' );?>"></a></li>
		<?php } if( $twitter ){ ?>
        <li><a href="<?php echo esc_url( $twitter ); ?>" class="fa fa-twitter" target="_blank" title="<?php esc_attr_e( 'Twitter', 'excel-blog' );?>"></a></li>
        <?php } if( $pinterest ){ ?>
        <li><a href="<?php echo esc_url( $pinterest ); ?>" class="fa fa-pinterest" target="_blank" title="<?php esc_attr_e( 'Pinterst', 'excel-blog' );?>"></a></li>
		<?php } if( $linkedin ){ ?>
        <li><a href="<?php echo esc_url( $linkedin ); ?>" class="fa fa-linkedin" target="_blank" title="<?php esc_attr_e( 'LinkedIn', 'excel-blog' );?>"></a></li>
        <?php } if( $google_plus ){ ?>
        <li><a href="<?php echo esc_url( $google_plus ); ?>" class="fa fa-google-plus" target="_blank" title="<?php esc_attr_e( 'Gooble Plus', 'excel-blog' );?>"></a></li>
        <?php } if( $instagram ){ ?>
        <li><a href="<?php echo esc_url( $instagram ); ?>" class="fa fa-instagram" target="_blank" title="<?php esc_attr_e( 'Instagram', 'excel-blog' );?>"></a></li>
		<?php } if( $youtube ){ ?>
        <li><a href="<?php echo esc_url( $youtube ); ?>" class="fa fa-youtube-play" target="_blank" title="<?php esc_attr_e( 'YouTube', 'excel-blog' );?>"></a></li>
        <?php } ?>
	</ul>
    <?php
    }
}
endif;