<?php

	 function fancyfilter_cat_type_portfolio(){

		$el_categories = get_terms(array (
			'taxonomy' => 'fl_portfolio',

			'hide_empty' => true,
		));

		$el_cat_value = array();
		foreach ($el_categories as $el_category) {


			$el_cat_value[$el_category->term_id] = $el_category->name;

		}


		return $el_cat_value;



	}

	function fancyfilter_cat_portfolio_not_in(){

	$args = [
	  'post_type'=>'fancyfilter',
	  'posts_per_page' => -1,
	];

	$posts = get_posts($args);


	$el_post_value = array();
	foreach ($posts as $post) {


		$el_post_value[$post->ID] = $post->post_title;

	}


	return $el_post_value;


	}
	function fancyfilterduct_not_in(){

	$args = [
	  'post_type' => 'product',
	  'posts_per_page' => -1,
	];

	$posts = get_posts($args);


	$el_post_value = array();
	foreach ($posts as $post) {


		$el_post_value[$post->ID] = $post->post_title;

	}


	return $el_post_value;


	}
	function fancyfilter_lite_blog_not_in(){

	$args = [
	  'post_type' => 'post',
	  'posts_per_page' => -1,
	];

	$posts = get_posts($args);


	$el_post_value = array();
	foreach ($posts as $post) {


		$el_post_value[$post->ID] = $post->post_title;

	}


	return $el_post_value;


	}


		function fancyfilter_cat_type_product(){



		$el_categories = get_terms(array (
			'taxonomy' => 'product_cat',
			'hide_empty' => true,
		));

		$el_cat_value = array();
		foreach ($el_categories as $el_category) {


			$el_cat_value[$el_category->term_id] = $el_category->name;
		}


		return $el_cat_value;
		}
			function fancyfilter_cat_type_post(){

			$el_categories = get_terms(array (
				'taxonomy' => 'category',
				'hide_empty' => true,
			));

			$el_cat_value = array();
			foreach ($el_categories as $el_category) {


				$el_cat_value[$el_category->term_id] = $el_category->name;
			}

			return $el_cat_value;
		}


			function fancyfilter_title($full_text){

				$title = get_the_title(get_the_ID());
				if($full_text == 'yes'){
				$get_title = get_the_title(get_the_ID());	
			}else{

			
			if (strlen($title) > 13) {
			$get_title = substr($title, 0, 13). '...';
			} else {
			$get_title = $title;
			}
			}
		return $get_title;
		}		


			function fancyfilter_shtcode_title(){
				$options = get_option('fancyfilter_options');
				$show_fancyfilter_pro_title = isset($options['show_fancyfilter_pro_title']) && $options['show_fancyfilter_pro_title'] === 'show_fancyfilter_pro_title' ? 'checked' : '';
				$title = get_the_title(get_the_ID());
				if($show_fancyfilter_pro_title == 'checked'){
				$get_title = get_the_title(get_the_ID());	
			}else{

			
			if (strlen($title) > 13) {
			$get_title = substr($title, 0, 13). '...';
			} else {
			$get_title = $title;
			}
			}
		return $get_title;
		}	


		function fancyfilter_lite_blog_thumbnail(){

				if(has_post_thumbnail(get_the_ID())){

				$fancyfilter_thumnai  = get_the_post_thumbnail_url(get_the_ID());
				}else{
					$default_image = FANCYFILTER_DIR.'fancy-fiter/assets/img/placeholder.png';
				$fancyfilter_thumnai = $default_image; 	
				}
				return $fancyfilter_thumnai ;
			}
			function fancyfilter_alt_text(){

					if(has_post_thumbnail(get_the_id())){

					$fancyfilter_alt_text = get_post_meta (get_post_thumbnail_id(), '_wp_attachment_image_alt', true );

						if(!empty($fancyfilter_alt_text)){
							$fancyfilter_alt_text = $fancyfilter_alt_text;
						}else{
							$fancyfilter_alt_text = get_the_title();

						}

					}else{

					$fancyfilter_alt_text = 'default-image';	
					}
					return $fancyfilter_alt_text ;
				}


			function fancyfilter_excerpt_length($length){

			$excerpt_length = $length;
			$excerpt = get_the_content();
			$excerpt = preg_replace(" ([.*?])",'',$excerpt);
			$excerpt = strip_shortcodes($excerpt);
			$excerpt = wp_strip_all_tags($excerpt);
			$excerpt = substr($excerpt, 0, $excerpt_length);
			$excerpt = substr($excerpt, 0, strripos($excerpt, " "));


			return $excerpt;
		}


			function fancyfilter_comments_count(){

			$commetts_count = get_comments_number(get_the_ID());
			if($commetts_count<= 1){
			 $commetts_ = 'comment';
			}else{
				$commetts_ = 'comments';
			}
			$comment_hit = $commetts_count . '' .$commetts_;

			return $comment_hit;
		}

	
if (!function_exists('fancyfilter_custom_posts_pagination')) :
    function fancyfilter_custom_posts_pagination($the_query=NULL, $paged=1){

        global $wp_query;
        $the_query = !empty($the_query) ? $the_query : $wp_query;

        if ($the_query->max_num_pages > 1) {
            $big = 999999999; // need an unlikely integer
            $items = paginate_links(apply_filters('adimans_posts_pagination_paginate_links', array(
                'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
                'format' => '?paged=%#%',
                'prev_next' => TRUE,
                'current' => max(1, $paged),
                'total' => $the_query->max_num_pages,
                'type' => 'array',
                'prev_text' => ' <i class="fas angle_double_left">&#8592;</i> ',
                'next_text' => ' <i class="fas angle_double_right">&#8594;</i> ',
                'end_size' => 1,
                'mid_size' => 1
            )));

            $pagination = "<div class=\"fancyfilter_pro_pagination\"><ul><li>";
            $pagination .= join("</li><li>", (array)$items);
            $pagination .= "</li></ul></div>";

            echo apply_filters('ic_posts_pagination', $pagination, $items, $the_query);
        }
    }
endif;