<?php

/**
 * Custom Archive Title modifier
 */
if (!function_exists('bexplore_get_the_archive_title')) {
	function bexplore_get_the_archive_title() {

		if (is_category()) {
			$title = single_cat_title('', false);
		} elseif (is_tag()) {
			$title = single_tag_title('', false);
		} elseif (is_author()) {
			$title = get_the_author();
		} elseif (is_year()) {
			$title = get_the_date(_x('Y', 'yearly archives date format', 'bexplore'));
		} elseif (is_month()) {
			$title = get_the_date(_x('F Y', 'monthly archives date format', 'bexplore'));
		} elseif (is_day()) {
			$title = get_the_date(_x('F j, Y', 'daily archives date format', 'bexplore'));
		} elseif (is_post_type_archive()) {
			$title = post_type_archive_title('', false);
			if (is_shop()) {
				$title = woocommerce_page_title();
			}
		} elseif (is_tax()) {
			$tax = get_taxonomy(get_queried_object()->taxonomy);
			$title = sprintf(__('%1$s: %2$s', 'bexplore'), $tax->labels->singular_name, single_term_title('', false));
		} else {
			$title = esc_html__('Archives', 'bexplore');
		}

		/**
		 * Filters the archive title.
		 *
		 * @param string $title Archive title to be displayed.
		 */
		return apply_filters('bexplore_get_the_archive_title', $title);
	}
}

/**
 * Function for breadcrumb title
 */
if (!function_exists('bexplore_breadcrumb_title')) {
	function bexplore_breadcrumb_title() {

		if (is_home() && is_front_page()) {
			$breadcrumb_title = esc_html(get_bloginfo('title'));
		} elseif (is_home() && !is_front_page()) {
			$breadcrumb_title = get_the_title(get_option('page_for_posts'));
		} elseif (is_archive()) {
			$breadcrumb_title = bexplore_get_the_archive_title();
		} elseif (is_search()) {
			$breadcrumb_title = esc_html__('Search Results for: ', 'bexplore') . esc_html(get_search_query());
		} elseif (is_404()) {
			$breadcrumb_title = esc_html__('404', 'bexplore');
		} else {
			$breadcrumb_title = get_the_title();
		}

		return $breadcrumb_title;
	}
}


/**
 * Breadcrumb area show
 */
if (!function_exists('bexplore_breadcrumb_show')) {
	function bexplore_breadcrumb_show() {
		if ('hide' == get_theme_mod('bexplore_breadcrumb_on_off', 'hide')) {
			return false;
		} else {
			return true;
		}
	}
}


/**
 * Breadcrumb
 */
if (!function_exists('bexplore_breadcrumb')) {
	function bexplore_breadcrumb() {
		echo '<ul class="bexplore-breadcrumb-link"><li>';
		if (!(is_home() && is_front_page())) {
			printf('<a class="active" href="%s"><i class="fas fa-home"></i>' . esc_html__('Home', 'bexplore') . '</a><span class="breadcrumb-sperarator"><i class="fas fa-chevron-right"></i></span>', esc_url(home_url()));
		}
		$name = get_bloginfo('name');
		$desc = get_bloginfo('description');
		//is_home means blog page.
		if (is_home() && is_front_page()) {
			echo esc_html($desc);
		} elseif (!is_home() && is_front_page()) {
			echo get_the_title();
		} elseif (is_home() && !is_front_page()) {
			$id = (get_option('page_for_posts') != '0') ? get_option('page_for_posts') : '';
			echo get_the_title($id);
		} elseif (is_search()) {
			echo esc_html__('Search Results for: ', 'bexplore') . esc_html(get_search_query());
		} elseif (is_404()) {
			esc_html_e('404', 'bexplore');
		} elseif (is_category()) {
			echo single_term_title();
		} elseif (is_singular()) {
			$pt_name = get_post_type(get_the_ID());
			$obj = get_post_type_object($pt_name);
			$name = str_replace(array('_', '-'), array(' ', ' '), $pt_name);
			if (is_single()) {
				echo get_the_title();
			} elseif (is_page()) {
				echo get_the_title();
			} else {
				echo esc_html($name);
			}
		} elseif (is_archive()) {
			echo bexplore_get_the_archive_title();
		}
		echo '</li></ul>';
	}
}