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

if ( !function_exists('guj_conditional_blog_sidebar') ):
    
    /**
     * Get sidebar only if left or right sidebar selected in customizer for blog
     */
    function guj_conditional_blog_sidebar () {
        $blog_content_layout = guj_get_option('blog_layout_options');
            if ( 'pull-left' === $blog_content_layout || 'pull-right' === $blog_content_layout ) {
                get_sidebar() ;
        }
    }
    
endif;

if ( !function_exists('guj_conditional_page_sidebar') ):
    
    /**
     * Get page sidebar only if right or left sidebar selected in customizer
     */
    
    function guj_conditional_page_sidebar() {
        $page_contet_layout = guj_get_option('page_layout');
        if ( 'page-pull-left' === $page_contet_layout || 'page-pull-right' === $page_contet_layout ) {
            dynamic_sidebar( 'sidebar-2' );
        }
    }
    
endif;

if ( !function_exists('guj_conditional_archive_featured_image') ):
    
    /**
     * Get page sidebar only if right or left sidebar selected in customizer
     */
    
    function guj_conditional_archive_featured_image() {
        $blog_content_layout = guj_get_option('blog_layout_options');
        if ( ! is_active_sidebar('sidebar-1') || 'no-sidebar' === $blog_content_layout ) {
            add_image_size( 'guj-index-img', 1080, 450, true );
        } else {
            add_image_size( 'guj-index-img', 800, 450, true );
        }
    }
    
endif;

if ( ! function_exists( 'guj_posted_on' ) ) :
	/**
	 * Prints HTML with meta information for the current post-date/time.
	 */
	function guj_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 = sprintf(
			/* translators: %s: post date. */
			esc_html_x( 'Published %s', 'post date', 'guj' ),
			'<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>'
		);

		echo '<span class="posted-on">' . $posted_on . '</span>'; // WPCS: XSS OK.

		if ( ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
			echo ' <span class="comments-link"><span class="extra">Discussion </span>';
			comments_popup_link(
				sprintf(
					wp_kses(
						/* translators: %s: post title */
						__( 'Leave a Comment<span class="screen-reader-text"> on %s</span>', 'guj' ),
						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>', 'guj' ),
					array(
						'span' => array(
							'class' => array(),
						),
					)
				),
				get_the_title()
			),
			' <span class="edit-link"><span class="extra">Admin </span>',
			'</span>'
		);

	}
endif;

if ( ! function_exists( 'guj_posted_by' ) ) :
	/**
	 * Prints HTML with meta information for the current author.
	 */
	function guj_posted_by() {
		$byline = sprintf(
			/* translators: %s: post author. */
			esc_html_x( 'Written by %s ', 'post author', 'guj' ),
			'<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"> ' . $byline . '</span>'; // WPCS: XSS OK.

	}
endif;

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

	}
endif;

/**
* Display Category list
*/
if ( ! function_exists('guj_the_category_list' ) ):
function guj_the_category_list () {
	/* translators: used between list items, there is a space after the comma */
	$categories_list = get_the_category_list( esc_html__( ', ', 'guj' ) );
	if ( $categories_list ) {
		/* translators: 1: list of categories. */
		printf( '<span class="cat-links">' . esc_html__( 'Posted in %1$s', 'guj' ) . '</span>', $categories_list ); // WPCS: XSS OK.
	}
}
endif;

/**
* Post Navigation for single posts
*/
if ( !function_exists('guj_post_navigation') ) :
function guj_post_navigation () {
	the_post_navigation(array(
		'next_text'		=> '<span class="meta-nav" aria-hidden="true">' . __( 'Next', 'guj' ) . '</span>' .
		'<span class="screen-reader-text">' . __('Next Post:', 'guj') . '</span>' .
		'<span class="post-title"> %title </span>',

		'prev_text'		=> '<span class="meta-nav" aria-hidden="true">' . __( 'Previous', 'guj' ) . '</span>' .
		'<span class="screen-reader-text">' . __('Previous Post:', 'guj') . '</span>' .
		'<span class="post-title"> %title </span>',
	));
}

endif;

/**
* Post Pagination for archive pages
*/
if ( !function_exists('guj_post_pagination') ) :
function guj_post_pagination () {
	the_posts_pagination( array (
		'prev_text'						=>	__('Newer', 'guj'),
		'next_text'						=>	__('Older', 'guj'),
		'before_page_number'	=> '<span class="screen-reader-text">' . __('Page ', 'guj') . '</span>',
	));
}
endif;

/**
* Customize ellipsis at end of excerpts
*/
if ( !function_exists('guj_excerpt_more') ) :
    function guj_excerpt_more ($more) {
        if ( ! is_admin() ) {
        return "";
    }
}
endif;

add_filter('excerpt_more', 'guj_excerpt_more');

/**
* Customize read more
*/

if ( !function_exists('guj_customize_readmore') ) :
    
    function guj_customize_readmore () {
        
         ?>
<span class="continue-reading"><a href="<?php echo esc_url(get_permalink()); ?>"><?php esc_html_e('Read More', 'guj') ?><i class="fa fa-caret-right spaceLeft" aria-hidden="true"></i></a></span>
     <?php
    }
    
 endif;

/**
* Customize excerpt length
*/
if ( !function_exists('guj_excerpt_length') ) :
    
function guj_excerpt_length ($length) {
    
    $excerpt_length = guj_get_option('excerpt_blog_length');
    if( is_admin() ){
        return $length;
    } else {
            if ( absint( $excerpt_length ) > 0 && !is_admin() ) {
                $length = absint( $excerpt_length );
            }
	}

    return $length;
    
}
endif;

add_filter ('excerpt_length', 'guj_excerpt_length' , 999);

/**
 * Footer Social Links
 */
if ( !function_exists('guj_social_array') ) :
    
    function guj_social_array() {

    $social_sites = array(
        'twitter'       => 'guj_twitter_profile_url',
        'facebook'      => 'guj_facebook_profile_url',
        'google-plus'   => 'guj_googleplus_profile_url',
        'pinterest'     => 'guj_pinterest_profile_url',
        'linkedin'      => 'guj_linkedin_profile_url',
        'youtube'       => 'guj_youtube_profile_url',
        'vimeo'         => 'guj_vimeo_profile_url',
        'tumblr'        => 'guj_tumblr_profile_url',
        'instagram'     => 'guj_instagram_profile_url',
        'flickr'        => 'guj_flickr_profile_url',
        'dribbble'      => 'guj_dribbble_profile_url',
        'rss'           => 'guj_rss_profile_url',
        'reddit'        => 'guj_reddit_profile_url',
        'soundcloud'    => 'guj_soundcloud_profile_url',
        'spotify'       => 'guj_spotify_profile_url',
        'vine'          => 'guj_vine_profile_url',
        'behance'       => 'guj_behance_profile_url',
        'delicious'     => 'guj_delicious_profile_url',
        'stumbleupon'   => 'guj_stumbleupon_profile_url',
        'digg'          => 'guj_digg_profile_url',
        'github'        => 'guj_github_profile_url',
        'vk'            => 'guj_vk_profile_url',
        'weibo'         => 'guj_weibo_profile_url',
        'tencent-weibo' => 'guj_tencent_weibo_profile_url',
        'foursquare'    => 'guj_foursquare_profile_url',
        'slack'         => 'guj_slack_profile_url',
        'skype'         => 'guj_skype_profile_url',
        'xing'          => 'guj_xing_profile_url'
    );

    return apply_filters( 'guj_social_array_filter', $social_sites );
}
    
 endif;

if ( !function_exists('guj_social_icons_output') ) : 
    function guj_social_icons_output() {

        $social_sites = guj_social_array();

        foreach ( $social_sites as $social_site => $profile ) {

            if ( strlen( guj_get_option( $social_site ) ) > 0 ) {
                $active_sites[ $social_site ] = $social_site;
            }
        }

        if ( ! empty( $active_sites ) ) {

            echo '<ul>';
            foreach ( $active_sites as $key => $active_site ) { 
            $class = 'fa fa-' . $active_site; ?>
                <li>
                    <a class="<?php echo esc_attr( $active_site ); ?>" target="_blank" href="<?php echo esc_url( guj_get_option( $key ) ); ?>">
                        <i class="<?php echo esc_attr( $class ); ?>" title="<?php echo esc_attr( $active_site ); ?>"></i>
                    </a>
                </li>
            <?php } 
            echo "</ul>";
        }
    }
endif;

 