<?php 
/**
 * @package WordPress
 * @subpackage Campoal
 */


/**
* Display breadcrumbs
*
* @since Campoal 1.0.0
*/
if (!function_exists('conikal_petition_breadcrumbs')) :
	function conikal_petition_breadcrumbs($custom = '') {
		global $post;
		global $campoal_options;
		$show_bc = isset($campoal_options['conikal_breadcrumbs_field']) ? $campoal_options['conikal_breadcrumbs_field'] : 0;

		if ($show_bc == 0) {
			return $campoal_options;
		} 

		if (!is_front_page()) {
			$output = '<div class="ui breadcrumb truncate">';
			$output .= '<a class="section" href="' . esc_url( home_url('/') ) . '" data-bjax><i class="home icon"></i></a>';
			$output .= '<i class="right angle icon divider"></i>';
			if (is_home()) {
				$output .= '<a class="section" href="#" data-bjax>' . esc_html__('Blog', 'campoal') . '</a>';
			}
			if (is_single()) {
				$category = get_the_category($post->ID);
				if ($category) {
					$output .= '<i class="right angle icon divider"></i>';
					$output .= esc_html($category[0]->name);
				}
				$output .= get_the_title();
			} elseif (is_page()) {
				if (conikal_check_woocommerce_pages(false, 'edit-address')) {
					$output .= esc_html__('My Address', 'campoal');
				} else {
					$output .= get_the_title();
				}
			} elseif (is_author()) {
				$output .= esc_html__('Author', 'campoal');
				$output .= '<i class="right angle icon divider"></i>';
				$output .= $custom;
			} elseif (is_category()) {
				$output .= single_cat_title('<a class="section" href="#" data-bjax>' . esc_html__('Category', 'campoal') . '</a><i class="right angle icon divider"></i>', false);
			} elseif (is_search()) {
				$output .= '<a class="section" href="#" data-bjax>' . esc_html(get_search_query()) . '</a>';
			} elseif (is_tag()) {
				$output .= single_tag_title('<a class="section" href="#" data-bjax>' . esc_html__('Tag', 'campoal') . '</a><i class="right angle icon divider"></i>', false);
			} elseif (is_tax('petition_topics')) {
				$output .= single_term_title('<a class="section" href="#" data-bjax>' . esc_html__('Topic', 'campoal') . '</a><i class="right angle icon divider"></i>', false);
			} elseif (is_tax('petition_category')) {
				$output .= single_term_title('<a class="section" href="#" data-bjax>' . esc_html__('Category', 'campoal') . '</a><i class="right angle icon divider"></i>', false);
			} elseif (is_tax('give_forms_category')) {
				$output .= single_term_title('<a class="section" href="#" data-bjax>' . esc_html__('Category', 'campoal') . '</a><i class="right angle icon divider"></i>', false);
			} elseif (is_tax('give_forms_tag')) {
				$output .= single_term_title('<a class="section" href="#" data-bjax>' . esc_html__('Tag', 'campoal') . '</a><i class="right angle icon divider"></i>', false);
			} elseif (is_post_type_archive('petitions')) {
				$output .= single_term_title('<a class="section" href="#" data-bjax>' . esc_html__('Petition', 'campoal') . '</a><i class="right angle icon divider"></i>', false);
			} elseif (is_archive()) {
				$year     = get_query_var('year');
				$monthnum = get_query_var('monthnum');
				$day = get_query_var('day');
				$output .= single_term_title('<a class="section" href="#" data-bjax>' . esc_html__('Petition', 'campoal') . '</a><i class="right angle icon divider"></i>', false);
				if ($year && !$monthnum && !$day) {
					$output .= '<a class="section" href="#" data-bjax>' . esc_html($year) . '</a>';
				}
				if ($monthnum && !$day) {
					$output .= '<a class="section" href="#" data-bjax>' . esc_html( date_i18n('F Y', strtotime($monthnum . '/' . $year)) ) . '</a>';
				}
				if ($day) {
					$output .= '<a class="section" href="#" data-bjax>' . esc_html( date_i18n(get_option('date_format'), strtotime($year . '/' . $monthnum . '/' . $day)) ) . '</a>';
				}
			}
			$output .= '</div>';
		} else {
			$output = '<div class="none-breadcrumb"></div>';
		}

		echo wp_kses_post($output);
	}
endif;
?>