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

/**
 * Adds custom classes to the array of body classes.
 *
 * @param array $classes Classes for the body element.
 * @return array
 */
function electromix_body_classes( $classes ) {
	// Adds a class of group-blog to blogs with more than 1 published author.
	if ( is_multi_author() ) {
		$classes[] = 'group-blog';
	}

	// Adds a class of hfeed to non-singular pages.
	if ( ! is_singular() ) {
		$classes[] = 'hfeed';
	}
	if ( is_page_template( 'templates/template-homepage.php' ) ) {
		$classes[] = 'home';
	}
	if( class_exists('WooCommerce')) {
		if (   is_shop() || is_product() || is_page('wishlist') || is_page('compare') || is_archive() ) {
			$classes[] = 'woocommerce-paged-aux';
		}
	}
	
		//$classes[] = 'electromix-home2';
	
	return $classes;
}
add_filter( 'body_class', 'electromix_body_classes' );

if ( ! function_exists( 'wp_body_open' ) ) {
	/**
	 * Backward compatibility for wp_body_open hook.
	 *
	 * @since 1.0.0
	 */
	function wp_body_open() {
		do_action( 'wp_body_open' );
	}
}

if (!function_exists('electromix_str_replace_assoc')) {

    /**
     * electromix_str_replace_assoc
     * @param  array $replace
     * @param  array $subject
     * @return array
     */
    function electromix_str_replace_assoc(array $replace, $subject) {
        return str_replace(array_keys($replace), array_values($replace), $subject);
    }
}

// Comments Counts
if ( ! function_exists( 'electromix_comment_count' ) ) :
function electromix_comment_count() {
	$electromix_comments_count 	= get_comments_number();
	if ( 0 === intval( $electromix_comments_count ) ) {
		echo esc_html__( '0 Comments', 'electromix' );
	} else {
		/* translators: %s Comment number */
		 echo sprintf( _n( '%s Comment', '%s Comments', $electromix_comments_count, 'electromix' ), number_format_i18n( $electromix_comments_count ) );
	}
} 
endif;


/**
 * Display Sidebars
 */
if ( ! function_exists( 'electromix_get_sidebars' ) ) {
	/**
	 * Get Sidebar
	 *
	 * @since 1.0
	 * @param  string $sidebar_id   Sidebar Id.
	 * @return void
	 */
	function electromix_get_sidebars( $sidebar_id ) {
		if ( is_active_sidebar( $sidebar_id ) ) {
			dynamic_sidebar( $sidebar_id );
		} elseif ( current_user_can( 'edit_theme_options' ) ) {
			?>
			<div class="widget widget_none">
				<p class='no-widget-text'>
					<a href='<?php echo esc_url( admin_url( 'widgets.php' ) ); ?>'>
						<?php esc_html_e( 'Add Widget', 'electromix' ); ?>
					</a>
				</p>
			</div>
			<?php
		}
	}
}


/**
 * Electromix Logo
 */
if ( ! function_exists( 'electromix_logo' ) ) {
	function electromix_logo() {
		if(has_custom_logo())
			{	
				the_custom_logo();
			}
			?>
			<a href="<?php echo esc_url( home_url( '/' ) ); ?>" class="site-title">				
					<?php 
						echo esc_html(get_bloginfo('name'));
					?>				
			</a>
		<?php
			$electromix_description = get_bloginfo( 'description');
			if ($electromix_description) : ?>
				<p class="site-description"><?php echo esc_html($electromix_description); ?></p>
		<?php endif;
	}
}
add_action( 'electromix_logo', 'electromix_logo' );


/**
 * Electromix Navigation
 */
if ( ! function_exists( 'electromix_main_nav' ) ) {
	function electromix_main_nav() {
		wp_nav_menu( 
			array(  
				'theme_location' => 'primary_menu',
				'container'  => '',
				'menu_class' => 'nav menu-wrap',
				'fallback_cb' => 'WP_Bootstrap_Navwalker::fallback',
				'walker' => new WP_Bootstrap_Navwalker()
				 ) 
			);
	}
}
add_action( 'electromix_main_nav', 'electromix_main_nav' );


/**
 * Mega_Mart Browse Category
 */
function electromix_render_category_item($cat) {
	$output = '';
	$category_id = $cat->term_id;
	$count = $cat->count;
	$thumbnail_id = get_term_meta($category_id, 'thumbnail_id', true);
	$image = wp_get_attachment_url($thumbnail_id);
	$icon = get_term_meta($category_id, 'electromix_product_cat_icon', true);
	$has_children = electromix_has_Children($category_id);
	$child_class = $has_children ? 'menu-item-has-children' : '';

	$output .= '<li class="menu-item main-top-menu' . $child_class . '">';
	$output .= '<a class="nav-link" href="' . get_term_link($cat->slug, 'product_cat') . '">';
	$output .= !empty($icon) ? "<i class='fa {$icon}'></i>" : "<img src='{$image}'>";
	// $output .= $cat->name . '<span class="count-badge ms-2">' . $count . '</span></a>';
	$output .= $cat->name.'</a>' ;

	if ($has_children) {
		$output .= '<span class="mobile-collapsed"><button type="button" class="fa fa-chevron-right" aria-label="Mobile Collapsed"></button></span>';
		$sub_categories = get_categories([
			'taxonomy'     => 'product_cat',
			'parent'       => $category_id,
			'hierarchical' => 1,
			'hide_empty'   => 0,
		]);

		if ($sub_categories) {
			$output .= '<ul class="dropdown-menu">';
			foreach ($sub_categories as $sub_cat) {
				$output .= electromix_render_category_item($sub_cat); // Recursive call
			}
			$output .= '</ul>';
		}
	}

	$output .= '</li>';
	return $output;
}
	
function electromix_has_Children($term_id) {
    $children = get_categories([
        'taxonomy'   => 'product_cat',
        'parent'     => $term_id,
        'hide_empty' => 0,
        'number'     => 1,
    ]);
    return !empty($children);
}

if ( ! function_exists( 'electromix_hdr_browse_cat' ) ) {
	function electromix_hdr_browse_cat() {
		if (!class_exists('WooCommerce')) {
			return;
		}

		?>
		<div class="docker-right-list w-100">
			<div class="product-category-menus">
				<div class="product-category-menus-list active">
					<ul class="main-menu mt-2 category-menu-wrap">
						<?php
						$top_level_categories = get_categories([
							'taxonomy'     => 'product_cat',
							'parent'       => 0,
							'hierarchical' => 1,
							'hide_empty'   => 0,
						]);

						foreach ($top_level_categories as $cat) {
							echo electromix_render_category_item($cat);
						}
						?>
					</ul>
				</div>
			</div>
		</div>
		<?php
	}	
}
add_action( 'electromix_hdr_browse_cat', 'electromix_hdr_browse_cat' );

/**
 * Mega_Mart Mobile Browse Category
 */
if ( ! function_exists( 'electromix_hdr_mobile_browse_cat' ) ) {
	function electromix_hdr_mobile_browse_cat() {
		$electromix_hs_browse_cat		= get_theme_mod( 'hs_browse_cat','1');
		if($electromix_hs_browse_cat=='1' && class_exists( 'woocommerce' )):
		?>
			<div class="product-category-menus product-category-menu-mobile">
				<div class="product-category-menus-list active">
				<ul class="main-menu mt-2 category-menu-wrap">
						<?php
						$top_level_categories = get_categories([
							'taxonomy'     => 'product_cat',
							'parent'       => 0,
							'hierarchical' => 1,
							'hide_empty'   => 0,
						]);

						foreach ($top_level_categories as $cat) {
							echo electromix_render_category_item($cat);
						}
						?>
					</ul>
				</div>
			</div>		
		<?php endif;
	}
}
add_action( 'electromix_hdr_mobile_browse_cat', 'electromix_hdr_mobile_browse_cat' );
/**
 * Electromix Product Search
 */
if ( ! function_exists( 'electromix_hdr_product_search' ) ) {
	function electromix_hdr_product_search() {
		$electromix_hs_product_search	= get_theme_mod( 'hs_product_search','1'); 
		 if($electromix_hs_product_search=='1' && class_exists( 'woocommerce' )): ?>
			<div class="header-search-form w-100">
			<form name="product-search" method="get" action="<?php echo esc_url(home_url('/')); ?>">
					<input type="search" name="s" class="search header-search-input" name="s" placeholder="<?php echo esc_attr__( 'Search Products', 'electromix' ); ?>" value="">
					
					<input type="hidden" name="post_type" value="product" />
					<button class="header-search-button" type="submit"><i class="fa fa-search"></i></button>
				</form>
			</div>
			<?php
				$selected_categories = get_theme_mod('selected_product_categories');				
				$most_phrase			= get_theme_mod('most_phrase');
				$most_phrase_hs			= get_theme_mod('most_phrase_hs','1');				
				$selected_categories = explode(',',$selected_categories);
				
				if ( !empty($selected_categories) && $most_phrase_hs == '1' ) { ?>
				<div class="popular-search-keywords">
				<?php 
					$product_categories = get_terms(array(
						'taxonomy'   => 'product_cat',
						'orderby'    => 'name',
						'hide_empty' => false ,
						'slug'    => $selected_categories,
					));
					
					if (!empty($product_categories) && !is_wp_error($product_categories)) {
						echo '<ul class="popular-list">';

						foreach ($product_categories as $category) {
							$category_link = get_term_link($category->term_id, 'product_cat');

							echo '<li>';
							echo '<a href="' . esc_url($category_link) . '">' . esc_html($category->name) . '</a>';
							echo '</li>';
						}

						echo '</ul>';
					} 				 
				?>
				<?php if(!empty($most_phrase)): ?><span class="hot-tag"><?php echo esc_html($most_phrase); ?></span> <?php endif; ?>
			</div>
		<?php } endif;
	}
}
add_action( 'electromix_hdr_product_search', 'electromix_hdr_product_search' );


/**
	Header Slider
	**
*/
function get_default_hdr_slider() {
	return apply_filters(
		'get_default_hdr_slider', wp_json_encode(
				 array(
				array(
					'icon_value'      	=> 'fa-truck',
					'title'           	=> esc_html__( 'Free Delivery', 'electromix' ),
					'text'	  			=>  esc_html__( 'From $250', 'electromix' ),
					'link'	  			=>  '#',
					'id'              	=> 'customizer_repeater_hdr_slide_001',
				),
				array(
					'icon_value'       	=> 'fa-dollar',
					'title'           	=> esc_html__( 'Money Back', 'electromix' ),
					'text'	  			=>  esc_html__( 'Guarantee', 'electromix' ),
					'link'	  			=>  '#',
					'id'             	=> 'customizer_repeater_hdr_slide_002',
				),
				array(
					'icon_value'       	=> 'fa-credit-card',
					'title'           	=> esc_html__( 'Cash On Delivery', 'electromix' ),
					'text'	  			=>  esc_html__( 'From $50', 'electromix' ),
					'link'	 			=>  '#',
					'id'             	=> 'customizer_repeater_hdr_slide_003',
				)
			)
		)
	);	
}


/**
	Footer Side Middle Widget
	**
*/
function foot_mid_wid_imgs() {
	return apply_filters(
		'foot_mid_wid_imgs', wp_json_encode(
				 array(
				array(
					'image_url'       => get_template_directory_uri() . '/assets/images/footer/amazon.png',
					'id'              	=> 'customizer_repeater_fmw_slide_001',
				),
				array(
					'image_url'       => get_template_directory_uri() . '/assets/images/footer/flipkart.png',
					'id'             	=> 'customizer_repeater_fmw_slide_002',
				),
				array(
					'image_url'       => get_template_directory_uri() . '/assets/images/footer/ebay.png',
					'id'             	=> 'customizer_repeater_fmw_slide_003',
				)
			)
		)
	);	
}

/**
	Footer Side Above Widget
	**
*/
function foot_abv_wid_imgs() {
	return apply_filters(
		'foot_abv_wid_imgs', wp_json_encode(
				 array(
				array(
					'image_url'       => get_template_directory_uri() . '/assets/images/footer/googleplay.png',
					'id'              => 'customizer_repeater_faw_slide_001',
				),
				array(
					'image_url'       => get_template_directory_uri() . '/assets/images/footer/appstore.png',
					'id'              => 'customizer_repeater_faw_slide_002',
				),
			)
		)
	);	
}

/*
 *
 * Info Default
 */
 function electromix_get_info_default() {
	return apply_filters(
		'electromix_get_info_default', wp_json_encode(
				 array(
				array(
					'icon_value'       => 'fa-phone',
					'title'           => esc_html__( 'Repair & Warranty', 'electromix' ),
					'text'           => esc_html__( 'Call Us: 70 975 975 70', 'electromix' ),
					'link'	  =>  esc_html__( '#', 'electromix' ),
					'id'              => 'customizer_repeater_info_001',
				),
				array(
					'icon_value'       => 'fa-users',
					'title'           => esc_html__( 'Demo & Installation', 'electromix' ),
					'text'           => esc_html__( 'Call Us: 70 975 975 70', 'electromix' ),
					'link'	  =>  esc_html__( '#', 'electromix' ),
					'id'              => 'customizer_repeater_info_002',
				),
				array(
					'icon_value'       => 'fa-cogs',
					'title'           => esc_html__( 'Sales & Service', 'electromix' ),
					'text'           => esc_html__( 'Call Us: 70 975 975 70', 'electromix' ),
					'link'	  =>  esc_html__( '#', 'electromix' ),
					'id'              => 'customizer_repeater_info_003',			
				),
			)
		)
	);
}

 /**
 * Add WooCommerce Cart Icon With Cart Count (https://isabelcastillo.com/woocommerce-cart-icon-count-theme-header)
 */
function electromix_add_to_cart_count_fragment( $fragments ) {
	
    ob_start();
    $count = WC()->cart->cart_contents_count; 
    ?> 	
	<?php
    if ( $count > 0 ) {
	?>
		 <span class="cart-count"><?php echo esc_html( $count ); ?></span>
	<?php 
	}
	else {
		?>
		<span class="cart-count"><?php esc_html_e('0','electromix')?></span>
		<?php 
	}
    ?><?php
 
    $fragments['span.cart-count'] = ob_get_clean();
     
    return $fragments;
}
add_filter( 'woocommerce_add_to_cart_fragments', 'electromix_add_to_cart_count_fragment' );


function electromix_add_to_cart_total_fragment( $fragments ) {
	
    ob_start(); 
    ?> 	
	<span class="cart-label">
		<span><?php echo WC()->cart->get_cart_subtotal(); ?></span>
	</span>
   <?php
    $fragments['span.cart-label'] = ob_get_clean();
     
    return $fragments;
}
add_filter( 'woocommerce_add_to_cart_fragments', 'electromix_add_to_cart_total_fragment' );
 
/**
 * Register widget area.
 *
 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 */

function electromix_widgets_init() {	
	register_sidebar( array(
		'name' => __( 'Header Widget Area 1', 'electromix' ),
		'id' => 'electromix-header-above-first',
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget' => '</aside>',
		'before_title' => '<h5 class="widget-title">',
		'after_title' => '<span></span></h5>',
	) );
	
	register_sidebar( array(
		'name' => __( 'Header Widget Area 2', 'electromix' ),
		'id' => 'electromix-header-above-second',
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget' => '</aside>',
		'before_title' => '<h5 class="widget-title">',
		'after_title' => '</h5>',
	) );
	
	register_sidebar( array(
		'name' => __( 'Header Widget Area 3', 'electromix' ),
		'id' => 'electromix-header-above-third',
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget' => '</aside>',
		'before_title' => '<h5 class="widget-title">',
		'after_title' => '</h5>',
	) );
	
	register_sidebar( array(
		'name' => __( 'Sidebar Widget Area', 'electromix' ),
		'id' => 'electromix-sidebar-primary',
		'description' => __( 'The Primary Widget Area', 'electromix' ),
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget' => '</aside>',
		'before_title' => '<h5 class="widget-title"><span></span>',
		'after_title' => '</h5>',
	) );
	
	register_sidebar( array(
		'name' => __( 'Footer Left', 'electromix' ),
		'id' => 'electromix-footer-left',
		'description' => __( 'The Footer Left', 'electromix' ),
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget' => '</aside>',
		'before_title' => '<h4 class="widget-title">',
		'after_title' => '</h4>',
	) );
	
	register_sidebar( array(
		'name' => __( 'Footer Widget Area 1', 'electromix' ),
		'id' => 'electromix-footer-widget',
		'description' => __( 'Footer Widget', 'electromix' ),
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget' => '</aside>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );
	
	register_sidebar( array(
		'name' => __( 'Footer Widget Area 2', 'electromix' ),
		'id' => 'electromix-footer-widget-2',
		'description' => __( 'Footer Widget', 'electromix' ),
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget' => '</aside>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );
	
	register_sidebar( array(
		'name' => __( 'Footer Widget Area 3', 'electromix' ),
		'id' => 'electromix-footer-widget-3',
		'description' => __( 'Footer Widget', 'electromix' ),
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget' => '</aside>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );
	
	register_sidebar( array(
		'name' => __( 'Footer Widget Area 4', 'electromix' ),
		'id' => 'electromix-footer-widget-4',
		'description' => __( 'Footer Widget', 'electromix' ),
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget' => '</aside>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );
	
	register_sidebar( array(
		'name' => __( 'Footer Copyright Widget 1', 'electromix' ),
		'id' => 'electromix-footer-copy-1',
		'description' => __( 'Footer Widget', 'electromix' ),
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget' => '</aside>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );
	
	register_sidebar( array(
		'name' => __( 'Footer Copyright Widget 2', 'electromix' ),
		'id' => 'electromix-footer-copy-2',
		'description' => __( 'Footer Widget', 'electromix' ),
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget' => '</aside>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );
	
	register_sidebar( array(
		'name' => __( 'WooCommerce Widget Area', 'electromix' ),
		'id' => 'electromix-woocommerce-sidebar',
		'description' => __( 'This Widget area for WooCommerce Widget', 'electromix' ),
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget' => '</aside>',
		'before_title' => '<h4 class="widget-title">',
		'after_title' => '</h4>',
	) );
}
add_action( 'widgets_init', 'electromix_widgets_init' );



/**
 * This Function Check whether Sidebar active or Not
 */
if(!function_exists( 'electromix_blog_column_layout' )) :
function electromix_blog_column_layout(){
	if(is_active_sidebar('electromix-sidebar-primary'))
		{ return 'col-lg-8'; } 
	else 
		{ return 'col-lg-12'; }  
} endif;


/**
 * This Function Check whether Sidebar active or Not
 */
if(!function_exists( 'electromix_post_layout' )) :
function electromix_post_layout(){
	if(is_active_sidebar('electromix-sidebar-primary'))
		{ return 'col-md-6'; } 
	else 
		{ return 'col-md-4'; }  
} endif;


function electromix_breadcrumbs() {
	
	$showOnHome	= esc_html__('1','electromix'); 	// 1 - Show breadcrumbs on the homepage, 0 - don't show
	$delimiter 	= '';   // Delimiter between breadcrumb
	$home 		= esc_html__('Home','electromix'); 	// Text for the 'Home' link
	$showCurrent= esc_html__('1','electromix'); // Current post/page title in breadcrumb in use 1, Use 0 for don't show
	$before		= '<li class="active">'; // Tag before the current Breadcrumb
	$after 		= '</li>'; // Tag after the current Breadcrumb
	// $breadcrumb_seprator	= get_theme_mod('breadcrumb_seprator','fa-angle-right');
	global $post;
	$homeLink = home_url();

	if (is_home() || is_front_page()) {
 
	if ($showOnHome == 1) echo '<li><a href="' . esc_url($homeLink) . '">  ' . esc_html($home) . '</a></li>';
 
	} else {
 
    echo '<li><a href="' . esc_url($homeLink) . '">  ' . esc_html($home) . '</a> ' . '&nbsp<i class="fa fa-angle-right"></i>&nbsp';
 
    if ( is_category() ) 
	{
		$thisCat = get_category(get_query_var('cat'), false);
		if ($thisCat->parent != 0) echo get_category_parents($thisCat->parent, TRUE, ' ' . ' ');
		echo $before . esc_html__('Archive by category','electromix').' "' . esc_html(single_cat_title('', false)) . '"' .$after;
		
	} 
	
	elseif ( is_search() ) 
	{
		echo $before . esc_html__('Search results for ','electromix').' "' . esc_html(get_search_query()) . '"' . $after;
	} 
	
	elseif ( is_day() )
	{
		echo '<a href="' . esc_url(get_year_link(get_the_time('Y'))) . '">' . esc_html(get_the_time('Y')) . '</a> ' . '&nbsp<i class="fa fa-angle-right"></i>&nbsp';
		echo '<a href="' . esc_url(get_month_link(get_the_time('Y'),get_the_time('m'))) . '">' . esc_html(get_the_time('F')) . '</a> '. '&nbsp<i class="fa fa-angle-right"></i>&nbsp';
		echo $before . esc_html(get_the_time('d')) . $after;
	} 
	
	elseif ( is_month() )
	{
		echo '<a href="' . esc_url(get_year_link(get_the_time('Y'))) . '">' . esc_html(get_the_time('Y')) . '</a> ' . esc_attr($delimiter) . '&nbsp<i class="fa fa-angle-right"></i>&nbsp';
		echo $before . esc_html(get_the_time('F')) . $after;
	} 
	
	elseif ( is_year() )
	{
		echo $before . esc_html(get_the_time('Y')) . $after;
	} 
	
	elseif ( is_single() && !is_attachment() )
	{
		if ( get_post_type() != 'post' )
		{
			$post_type = get_post_type_object(get_post_type());
			$slug = $post_type->rewrite;
			echo '<a href="' . esc_url($homeLink) . '/' . $slug['slug'] . '/">  ' . $post_type->labels->singular_name . '</a>';
			if ($showCurrent == 1) echo ' ' . esc_attr($delimiter) . '&nbsp<i class="fa fa-angle-right"></i>&nbsp' . $before . wp_kses_post(get_the_title()) . $after;
		}
		else
		{
			$cat = get_the_category(); $cat = $cat[0];
			$cats = get_category_parents($cat, TRUE, ' ' . esc_attr($delimiter) . '&nbsp<i class="fa fa-angle-right"></i>&nbsp');
			if ($showCurrent == 0) $cats = preg_replace("#^(.+)\s$delimiter\s$#", "$1", $cats);
			echo $cats;
			if ($showCurrent == 1) echo $before . esc_html(get_the_title()) . $after;
		}
 
    }
		
	elseif ( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) {
		if ( class_exists( 'woocommerce' ) ) {
			if ( is_shop() ) {
				$thisshop = woocommerce_page_title();
			}
			if ( is_product_category() ) {
				$term = get_queried_object(); 
				if ( $term && ! is_wp_error( $term ) ) {
					echo $term->name;
				}
			}
		}	
		else  {
			$post_type = get_post_type_object(get_post_type());
			echo $before . $post_type->labels->singular_name . $after;
		}	
	} 
	
	elseif ( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) 
	{
		$post_type = get_post_type_object(get_post_type());
		echo $before . $post_type->labels->singular_name . $after;
	} 
	
	elseif ( is_attachment() ) 
	{
		$parent = get_post($post->post_parent);
		$cat = get_the_category($parent->ID); 
		if(!empty($cat)){
		$cat = $cat[0];
		echo get_category_parents($cat, TRUE, ' ' . esc_attr($delimiter) . '&nbsp <i class="fa fa-angle-right"></i> &nbsp');
		}
		echo '<a href="' . esc_url(get_permalink($parent)) . '">' . $parent->post_title . '</a>';
		if ($showCurrent == 1) echo ' ' . esc_attr($delimiter) . ' ' . $before . esc_html(get_the_title()) . $after;
 
    } 
	
	elseif ( is_page() && !$post->post_parent ) 
	{
		if ($showCurrent == 1) echo $before . esc_html(get_the_title()) . $after;
	} 
	
	elseif ( is_page() && $post->post_parent ) 
	{
		$parent_id  = $post->post_parent;
		$breadcrumbs = array();
		while ($parent_id) 
		{
			$page = get_page($parent_id);
			$breadcrumbs[] = '<a href="' . esc_url(get_permalink($page->ID)) . '">' . esc_html(get_the_title($page->ID)) . '</a>' . '&nbsp <i class="fa fa-angle-right"></i> &nbsp';
			$parent_id  = $page->post_parent;
		}
		
		$breadcrumbs = array_reverse($breadcrumbs);
		for ($i = 0; $i < count($breadcrumbs); $i++) 
		{
			echo $breadcrumbs[$i];
			if ($i != count($breadcrumbs)-1) echo ' ' . esc_attr($delimiter) . '&nbsp <i class="fa fa-angle-right"></i> &nbsp';
		}
		if ($showCurrent == 1) echo ' ' . esc_attr($delimiter) . ' ' . $before . esc_html(get_the_title()) . $after;
 
    } 
	elseif ( is_tag() ) 
	{
		echo $before . esc_html__('Posts tagged ','electromix').' "' . esc_html(single_tag_title('', false)) . '"' . $after;
	} 
	
	elseif ( is_author() ) {
		global $author;
		$userdata = get_userdata($author);
		echo $before . esc_html__('Articles posted by ','electromix').'' . $userdata->display_name . $after;
	} 
	
	elseif ( is_404() ) {
		echo $before . esc_html__('Error 404 ','electromix'). $after;
    }
	
    if ( get_query_var('paged') ) {
		if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo '';
		echo ' ( ' . esc_html__('Page','electromix') . '' . esc_html(get_query_var('paged')). ' )';
		if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo '';
    }
 
    echo '</li>';
 
  }
}

if ( ! function_exists( 'electromix_get_allowed_html_tags' ) ) {
	/**
	 * Array of allowed HTML Tags.
	 *
	 * @since 1.0.0
	 * @param string $type predefined HTML tags group name.
	 * @return array, allowed HTML tags.
	 */
	function electromix_get_allowed_html_tags( $type = 'basic' ) {

		$tags = array();

		switch ( $type ) {

			case 'basic':
				$tags = array(
					'strong' => array(),
					'em'     => array(),
					'b'      => array(),
					'br'     => array(),
					'p'     => array(),
					'i'      => array(
						'class' => array(),
					),
					'img'    => array(
						'src'    => array(),
						'alt'    => array(),
						'width'  => array(),
						'height' => array(),
						'class'  => array(),
						'id'     => array(),
					),
					'span'   => array(
						'class' => array(),
					),
					'a'      => array(
						'href'   => array(),
						'rel'    => array(),
						'target' => array(),
						'class'  => array(),
						'role'   => array(),
						'id'     => array(),
					),
				);
				break;

			case 'button':
				$tags = array(
					'strong' => array(),
					'em'     => array(),
					'span'   => array(
						'class' => array(),
					),
					'i'      => array(
						'class' => array(),
					),
				);
				break;

			case 'span':
				$tags = array(
					'span' => array(
						'class' => array(),
					),
				);
				break;

			case 'icon':
				$tags = array(
					'i'    => array(),
					'span' => array(),
					'img'  => array(),
				);
				break;

			default:
				$tags = array(
					'strong' => array(),
					'em'     => array(),
					'b'      => array(),
					'i'      => array(),
					'img'    => array(
						'src'    => array(),
						'alt'    => array(),
						'width'  => array(),
						'height' => array(),
						'class'  => array(),
						'id'     => array(),
					),
					'span'   => array(),
					'p'   => array(),
					'a'      => array(
						'href'   => array(),
						'rel'    => array(),
						'target' => array(),
						'class'  => array(),
						'role'   => array(),
						'id'     => array(),
					),
				);
				break;
		}

		return apply_filters( 'electromix_allowed_html_tags', $tags, $type );
	}
}