<?php
// don't load directly
if ( ! defined( 'ABSPATH' ) ) {
    die( '-1' );
}

if(!class_exists('nfp_shortcode')){
    class nfp_shortcode{

        /**
         * Constructor of filter plus shortcode
         *
         */
        function __construct(){
            add_shortcode('nfpfilter_products',array($this,'frontend_products'),1);
            add_shortcode('nfpfilter_toggle_button',array($this,'frontend_nfp_sidebar_button'),1);
            add_shortcode('nfpfilter_toggle_sidebar',array($this,'frontend_nfp_toggle_sidebar'),1);
            add_action( 'pre_get_posts', array($this,'nfp_product_query'), 99 );
            add_action( 'wp', array( $this, 'remove_product_query' ) );
            add_filter('nfpfilter_get_args',array($this,'filter_args'),5);
            add_filter('nfpfilter_string_to_array',array($this,'string_to_array'),1);

            $exclude_out_of_stock = get_option('nfp_exclude_stockout_products');
            $this->stockout_text = esc_html__('Out of stock','nfpfilter');
            if ( $exclude_out_of_stock == 'true'){
                add_action( 'woocommerce_before_shop_loop_item', array($this,'nfpfilter_archive_stockout_loop') );
            }

            // ajax
            add_action( 'wp_ajax_nfpfilter_ajax', array($this,'nfpfilter_ajax_callback') );
            add_action( 'wp_ajax_nopriv_nfpfilter_ajax', array($this,'nfpfilter_ajax_callback') );
        }


        function nfpfilter_archive_stockout_loop(){
            global $product;

            if($product->is_type('variable')){

                $variations = $product->get_available_variations();
                $is_in_stock = 'false';

                foreach ($variations as $variation) {
                    $key = str_replace('attribute_', '', key($variation['attributes']));
                    if (isset($_GET['nfp' . $key])) {
                        $get_values = explode(',', $_GET['nfp' . $key]);
                        foreach ($get_values as $get_value) {
                            if ($variation['attributes']['attribute_' . $key] === $get_value) {
                                if ($variation['is_in_stock'] == '1') {
                                    $is_in_stock = 'true';
                                }
                            }
                        }
                    } else{
                        $is_in_stock = 'true';
                    }
                }
                if ($is_in_stock === 'false') {
                    echo '<input class="nfpfilter-stockout-products-input" type="hidden" value="'.get_the_ID().'" data-text="'.esc_attr($this->stockout_text).'" >';
                }
            }elseif($product->is_type('simple') && !$product->is_in_stock()){
                echo '<input class="nfpfilter-stockout-products-input" type="hidden" value="'.get_the_ID().'" data-text="'.esc_attr($this->stockout_text).'" >';
            }
        }


        /**
         *
         * generate shortcode for sidebar button
         *
         */
        function frontend_nfp_sidebar_button($atts){
            extract( shortcode_atts( array(
                'float' => 'right',
            ), $atts ) );

                ob_start();
                $return = '<div class="nfpfilter-widget-header toggle-'.esc_attr($float).'"> <a class="nfp-toogle-sidebar " href="#"> <i class="demo-icon nfpicon-menu"></i></a><div style="clear:both;"></div> </div>';
                return $return;
        }


        /**
         * Hooked to pre_get_posts
         * Query products for archive products pages
         *
         */
        function nfp_product_query(  $query ){

            if ( is_admin() || get_post_type() != 'product' && !$query->is_main_query() ) { return;}

            if( is_archive() || is_category() || is_tax() && !is_single()){
                $nargs = array(
                    'object_type' => array('product')
                );

                $taxonmies = get_taxonomies($nargs);


                $queried_object = get_queried_object();
                if($queried_object->taxonomy == 'product_cat'){
                    $_GET['nfpproduct_cat'] = $queried_object->slug;
                }


                $nfp_default_per_page = get_option('nfp_default_per_page');
                if( !empty($nfp_default_per_page)){ $query->set( 'posts_per_page', intval($nfp_default_per_page) );}

                if(!empty($_GET)){
                    $prefix = 'nfp';
                    foreach($_GET as $filter => $value){
                        $meta_query = $query->get( 'meta_query' );

                        switch($filter){
                            case $prefix.'per_page':
                                if(isset($_GET[$prefix.'per_page']) && $_GET[$prefix.'per_page'] != 'default'){
                                    $query->set( 'posts_per_page', intval($_GET[$prefix.'per_page']) );
                                }

                                break;

                            case $prefix.'min_price':
                                $meta_query[] = array(
                                    'key'     => '_price',
                                    'value'   => $_GET[$prefix.'min_price'],
                                    'compare' => '>=',
                                    'type' => 'decimal'
                                );

                                break;

                            case $prefix.'max_price':

                                $meta_query[] = array(
                                    'key'     => '_price',
                                    'value'   => $_GET[$prefix.'max_price'],
                                    'type' => 'decimal',
                                    'compare' => '<='
                                );
                                break;


                            case $prefix.'min_rating':
                                $meta_query = $query->get( 'meta_query' );
                                $meta_query[] =array(
                                    'key'     => '_wc_average_rating',
                                    'value'   => $_GET[$prefix.'min_rating'],
                                    'type' => 'numeric',
                                    'compare' => '>='
                                );

                                break;

                            case $prefix.'min_discount':

                                $meta_query[] =array(
                                    'relation' => 'OR',
                                    array( // Simple products type
                                        'key'           => 'nfpdiscount',
                                        'value'         => $_GET[$prefix.'min_discount'],
                                        'compare'       => '>=',
                                        'type'          => 'numeric'
                                    ),
                                );


                                break;

                            case $prefix.'_s':
                                $value_array = explode(',',$value);
                                if($this->category_availability($value_array,$_GET) === false){
                                    break;
                                }

                                $searchQuery = self::nfp_search_default();
                                global $wpdb;
                                $ids = $wpdb->get_results("SELECT $wpdb->posts.ID FROM $wpdb->posts WHERE $searchQuery");
                                $post_ids = array();
                                foreach($ids as $id){
                                    $post_ids[] = $id->ID;
                                }
                                if(!empty($post_ids)){
                                    $args['post__in'] = $post_ids;
                                    $query->set( 'post__in', $post_ids );
                                }
                                break;


                            default:

                                $filter = str_replace('nfp','',$filter);
                                if(array_key_exists($filter,$taxonmies)){
                                    $tax_query = $query->get( 'tax_query' );
                                    $value_array = explode(',',$value);
                                    $tax_query[] = array(
                                        'taxonomy' => $filter,
                                        'field' => 'slug',
                                        'terms' => $value_array
                                    );
                                    $query->set( 'tax_query', $tax_query );
                                }
                                break;
                        }
                        $query->set( 'meta_query', $meta_query );

                    }
                }
            }

            remove_action('pre_get_posts', array($this,'nfp_product_query'),99);
        }

        /**
         * Remove main query of archive page
         */
        public function remove_product_query() {
            remove_action( 'pre_get_posts', array( $this, 'nfp_product_query' ) );
        }


        /**
         * Check if this optoin is available for current category
         *
         */
        function category_availability($value_array,$get = null){

            $get = !empty($get) ? $get : $_GET;
            $available_cats = array(); // category availability
            foreach($value_array as $value_single){

                if(strpos($value_single,'nfppcat') === 0){
                    $available_cats[] = str_replace('nfppcat','',$value_single);
                }
            }
            if(!empty($available_cats) && isset($get['nfpproduct_cat']) && !empty($get['nfpproduct_cat'])){
                if(array_search($get['nfpproduct_cat'],$available_cats) === false){
                    return false;
                }
            }
            return true;
        }


        /**
         * convert string into array
         *
         */
        public function string_to_array($link){
            if(!empty($link)){
                $link = substr(urldecode($link),strpos(urldecode($link),'?')+1);
                $link_parts = explode('&',str_replace('&#38;','&',str_replace('&#038;','&',$link)));
                $link_get = array();
                foreach($link_parts as $link_part){
                    $this_param = explode('=',$link_part);
                    $link_get[$this_param[0]] = $this_param[1];
                }
                return $link_get;
            }
        }


        /**
         * return base url from string
         *
         */
        function get_base_url_from_str($url){
            if(!empty($url)){
                $url = strpos(urldecode($url),'?') === true ? substr(urldecode($url),0,strpos(urldecode($url),'?')) : urldecode($url);
                if(strpos($url , 'admin-ajax') !== true ){return $url;}
            }
            return false;
        }
        /**
         * generate shortcode for filter plus product
         * It display recent products
         *
         */
        function frontend_products($atts){

            extract( shortcode_atts( array(
                'per_page_dropdown' => '10,20,30',
                'per_page' => '12',
                'orderby' => '',
                'order' => 'desc',
                'columns' => '3',
                'sorting' => 'yes',
                'result_count' => 'yes',
                'link' => '',
                'exclude_out_of_stock' => 'no',
                'cats' => '',
                'taxonomy_name' =>'',
                'taxonomy_slug' =>''
            ), $atts ) );


            if(!empty($link)){
                $link_get = $this->string_to_array($link);
                $link_only = substr($link,strpos($link,'?'));
            }

            $get = isset($link_get) ? $link_get : $_GET;

            $per_page = isset($get['nfpper_page']) && intval($get['nfpper_page']) > 1 ? $get['nfpper_page'] : $per_page;

            if($taxonomy_name && $taxonomy_slug){
                $get['nfp'.$taxonomy_name] = $taxonomy_slug;
            }

            if(!isset($get['nfpproduct_cat']) && isset($cats) && $cats){
                $get['nfpproduct_cat'] = $cats;
            }

            $args = $this->filter_args($get,$per_page,$orderby, $order);

            global $wp_query;
            global $woocommerce_loop;


            ob_start();

            echo '<div id="nfp-woocommerce-wrap" class="nfp-woocommerce-products woocommerce columns-' . esc_attr($columns) . '" data-per_page_dropdown="'.esc_attr($per_page_dropdown).'" data-per_page="'.esc_attr($per_page).'" data-orderby="'.esc_attr($orderby).'" data-order="'.esc_attr($order).'" data-columns="'.esc_attr($columns).'" data-sorting="'.esc_attr($sorting).'" data-result_count="'.esc_attr($result_count).'"  data-exclude-stockout="'.$exclude_out_of_stock.'">';


                $custom_query = new WP_Query($args);
                $temp_query = $wp_query;
                $wp_query   = null;
                $wp_query   = $custom_query;


                if($custom_query->have_posts() ):


                    $woocommerce_loop['columns'] = $columns;


                    if($result_count == 'yes'){
                        woocommerce_result_count();
                    }

                    if(!empty($per_page_dropdown)){
                        $option = '';
                        $per_page_options_array = explode(',',$per_page_dropdown);
                        $option .= "<option value='default'>".esc_html__("Per page: default","nfpfilter")."</option>";
                        foreach($per_page_options_array as $per_page_option){
                            if(is_int(intval($per_page_option))){
                                $selected = isset($_GET['nfpper_page']) && $_GET['nfpper_page'] == $per_page_option ? 'selected="selected"' : '';
                                $option .= '<option '.$selected.' value="'.$per_page_option.'">'.esc_html__('Per page: ','nfpfilter') . $per_page_option .' </option>';
                            }
                        }
                        $option = "<select id='nfp-product-per-page' class='orderby'>$option</select>";
                        echo $option;
                    }

                    if($sorting == 'yes'){
                        ?>
                        <form class="nfp-woocommerce-ordering" method="get">
                            <select name="orderby" class="orderby">
                                <option <?php echo isset($_GET['nfporderby']) && $_GET['nfporderby'] == 'menu_order' ?  'selected="selected"' : ''; ?> value="menu_order"><?php esc_html_e('Default sorting','nfpfilter');?></option>
                                <option <?php echo isset($_GET['nfporderby']) && $_GET['nfporderby'] == 'popularity' ?  'selected="selected"' : ''; ?> value="popularity"><?php esc_html_e('Sort by popularity','nfpfilter');?></option>
                                <option <?php echo isset($_GET['nfporderby']) && $_GET['nfporderby'] == 'rating' ?  'selected="selected"' : ''; ?> value="rating"><?php esc_html_e('Sort by average rating','nfpfilter');?></option>
                                <option <?php echo isset($_GET['nfporderby']) && $_GET['nfporderby'] == 'date' ?  'selected="selected"' : ''; ?> value="date"><?php esc_html_e('Sort by newness','nfpfilter');?></option>
                                <option <?php echo isset($_GET['nfporderby']) && $_GET['nfporderby'] == 'price' ?  'selected="selected"' : ''; ?> value="price"><?php esc_html_e('Sort by price: low to high','nfpfilter');?></option>
                                <option <?php echo isset($_GET['nfporderby']) && $_GET['nfporderby'] == 'price-desc' ?  'selected="selected"' : ''; ?> value="price-desc"><?php esc_html_e('Sort by price: high to low','nfpfilter');?></option>
                            </select>
                        </form>
                        <?php

                    }

                    woocommerce_product_loop_start();
                    woocommerce_product_subcategories();
                    $nfpfilter_exclude_ids = array();
                    while ($custom_query->have_posts()) : $custom_query->the_post();
                        wc_get_template_part( 'content', 'product' );
                    endwhile;

                    woocommerce_product_loop_end();
                    //
                    woocommerce_pagination();
                    // do_action( 'woocommerce_after_shop_loop' );


                endif;

            echo '</div>';

            $return = ob_get_contents();
            ob_end_clean();
            wp_reset_query();
             wp_reset_postdata();
           // Reset main query object
            $wp_query = null;
            $wp_query = $temp_query;

            return $return;

        }


        /*
         * make filter args
         * */

        function filter_args($get, $per_page = 12, $orderby = 'menu_order', $order = 'desc', $paged = null){

            $prefix = 'nfp';
            $args = array(
                'post_type' => 'product',
                'posts_per_page' => $per_page,
               // 'order' => $order
            );

			$temp_paged = $paged;
            global $paged;
			
			if($temp_paged == null){
				if ( get_query_var('paged') ) {
					$paged = get_query_var('paged');
				} elseif ( get_query_var('page') ) { // 'page' is used instead of 'paged' on Static Front Page
					$paged = get_query_var('page');
				} else {
					$paged = 1;
				}
			}else{
				$paged = $temp_paged;
			}

            

            $order_by = isset($get['nfporderby']) ? $get['nfporderby'] : $orderby;

            // queried taxonomy

            $queried_object = get_queried_object();
            if(is_object($queried_object) && isset($queried_object->taxonomy) && $queried_object->taxonomy){
                $args['tax_query'][] = array(
                    'taxonomy' => $queried_object->taxonomy,
                    'field' => 'slug',
                    'terms' => $queried_object->slug
                );
            }


            switch ($order_by){
                case 'price':
                    $args['orderby'] = 'meta_value_num';
                    $args['meta_key'] = '_price';
                    $args['order'] = 'asc';
                    break;

                case 'price-desc':
                    $args['orderby'] = 'meta_value_num';
                    $args['meta_key'] = '_price';
                    $args['order'] = 'desc';
                    break;

                case 'rating':
                    $args['orderby'] = 'meta_value_num';
                    $args['meta_key'] = '_wc_average_rating';
                    $args['order'] = 'desc';
                    break;

                case 'popularity':
                    $args['orderby'] = 'meta_value_num';
                    $args['meta_key'] = 'total_sales';
                    $args['order'] = 'desc';
                    break;
            }


            $nfpfilter_tax_query = array();


            if(!empty($get)){
                foreach($get as $filter => $value){
                    switch($filter){
                        case 'paged':
                            $paged = intval($value);
                            break;

                        case $prefix.'min_price':
                            $value_array = explode(',',$value);
                            if($this->category_availability($value_array,$get) === false){
                                break;
                            }
                            $args['meta_query'][] = array(
                                'key'     => '_price',
                                'value'   => $get[$prefix.'min_price'],
                                'type' => 'numeric',
                                'compare' => '>='
                            );

                            break;

                        case $prefix.'max_price':
                            $value_array = explode(',',$value);
                            if($this->category_availability($value_array,$get) === false){
                                break;
                            }
                            $args['meta_query'][] = array(
                                'key'     => '_price',
                                'value'   => $get[$prefix.'max_price'],
                                'type' => 'numeric',
                                'compare' => '<='
                            );

                            break;


                        case $prefix.'min_rating':
                            $value_array = explode(',',$value);
                            if($this->category_availability($value_array,$get) === false){
                                break;
                            }
                            $args['meta_query'][] = array(
                                'key'     => '_wc_average_rating',
                                'value'   => $get[$prefix.'min_rating'],
                                'type' => 'numeric',
                                'compare' => '>='
                            );

                            break;

                        case $prefix.'min_discount':
                            $value_array = explode(',',$value);
                            if($this->category_availability($value_array,$get) === false){
                                break;
                            }
                            $args['meta_query'][] = array(
                                'relation' => 'OR',
                                array( // Simple products type
                                    'key'           => 'nfpdiscount',
                                    'value'   => $get[$prefix.'min_discount'],
                                    'compare'       => '>=',
                                    'type'          => 'numeric'
                                ),
                            );

                            break;

                        case $prefix.'_s':
                            $value_array = explode(',',$value);
                            if($this->category_availability($value_array,$get) === false){
                                break;
                            }

                            $searchQuery = self::nfp_search_default();
                            global $wpdb;
                            $ids = $wpdb->get_results("SELECT $wpdb->posts.ID FROM $wpdb->posts WHERE $searchQuery");
                            $post_ids = array();
                            foreach($ids as $id){
                                $post_ids[] = $id->ID;
                            }
                            if(!empty($post_ids)){
                                $args['post__in'] = $post_ids;
                            }
                            break;


                        default:
                            $nargs=array(
                                'object_type' => array('product')
                            );

                            $taxonmies = get_taxonomies($nargs);
                            $value_array = explode(',',$value);

                            if($this->category_availability($value_array,$get) === false){
                                break;
                            }

                            $filter = str_replace('nfp','',$filter);
                            if(array_key_exists($filter,$taxonmies)){
                                $args['tax_query'][] =
                                    array(
                                        'taxonomy' => $filter,
                                        'field' => 'slug',
                                        'terms' => $value_array
                                    );

                                $nfpfilter_tax_query[$filter] = $value_array;
                            }
                            break;
                    }
                }
            }
            $args['paged'] = $paged;

            return $args;
        }

        /*
         *
         * */





        function nfp_search_default(){

            global $wpdb;

            $not_exact = empty($this->query_instance->query_vars['exact']);
            $search_sql_query = '';
            $seperator = '';
            $terms = $this->nfp_get_search_terms();


            // if it's not a sentance add other terms
            $search_sql_query .= '(';

            foreach ( $terms as $term ) {
                $search_sql_query .= $seperator;

                $esc_term = esc_sql($term);
                if ($not_exact) {
                    $esc_term = "%$esc_term%";
                }

                $like_title = "($wpdb->posts.post_title LIKE '$esc_term')";
                $like_post = "($wpdb->posts.post_content LIKE '$esc_term')";

                $search_sql_query .= "($like_title OR $like_post)";

                $seperator = ' AND ';
            }

            $search_sql_query .= ')';
            return $search_sql_query;
        }

        // creates the list of search keywords from the 's' parameters.
        function nfp_get_search_terms() {
            global $wpdb;
            $s = isset( $this->query_instance->query_vars['s'] ) ? $this->query_instance->query_vars['s'] : '';
            $sentence = isset( $this->query_instance->query_vars['sentence'] ) ? $this->query_instance->query_vars['sentence'] : false;
            $search_terms = array();

            $s = !empty($s) ? $s : str_replace(array("'","’", "\"", "&apos;", "&rsquo;", "&quot;"),"'", htmlentities (stripslashes(urldecode($_GET['nfp_s']))))  ;

            if ( !empty( $s ) ) {
                // added slashes screw with quote grouping when done early, so done later
                $s = stripslashes( $s );
                if ( $sentence ) {
                    $search_terms = array( $s );
                } else {
                    preg_match_all( '/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches ); // checking for security
                    $search_terms = array_filter(array_map( create_function( '$a', 'return trim($a, "\\"\'\\n\\r ");' ), $matches[0] ));
                }
            }

            return $search_terms;
        }


        /*
         * show sidebar and toggle button
         * */
        function frontend_nfp_toggle_sidebar($atts){
            extract( shortcode_atts( array(
                'sidebar_id' => '',
                'sidebar_style' => 'widget_and_button',
                'button_float' => 'right'
            ), $atts ) );

            if(!empty($sidebar_id)){
                ob_start();
                switch($sidebar_style){
                    case "widget_and_button" :
                        echo '<div style="clear: both"></div><div class="nfpfilter-widget-header toggle-'.esc_attr($button_float).'"> <a class="nfp-toogle-sidebar " href="#'.esc_attr($sidebar_id),'"> <i class="demo-icon nfpicon-menu"></i></span></a> </div><div style="clear:both;"></div><div class="nfp-sidebar-menu" data-sidebar-id="'.esc_attr($sidebar_id).'" data-sidebar_style="'.esc_attr($sidebar_style).'"><div class="nfp-sidebar-header clearfix">';
                        dynamic_sidebar($sidebar_id);
                        echo '<div style="clear: both"></div></div></div>';
                        break;

                    case "hidden_widget_and_button" :
                        echo '<div style="clear: both"></div><div class="nfpfilter-widget-header toggle-'.esc_attr($button_float).'"> <a class="nfp-toogle-sidebar " href="#'.esc_attr($sidebar_id),'"> <i class="demo-icon nfpicon-menu"></i></a> </div><div style="clear:both;"></div><div class="nfp-sidebar-menu" data-sidebar-id="'.esc_attr($sidebar_id).'" data-sidebar_style="'.esc_attr($sidebar_style).'" style="display: none"><div class="nfp-sidebar-header clearfix" >';
                        dynamic_sidebar($sidebar_id);
                        echo '<div style="clear: both"></div></div></div>';
                        break;

                    case "widget_only" :
                        echo '<div style="clear: both"></div><div class="nfp-sidebar-menu" data-sidebar-id="'.esc_attr($sidebar_id).'" data-sidebar_style="'.esc_attr($sidebar_style).'"><div class="nfp-sidebar-header clearfix">';
                        dynamic_sidebar($sidebar_id);
                        echo '<div style="clear: both"></div></div></div>';
                        break;

                    case "absolute_widget_and_button" :
                        echo '<div style="clear: both"></div><div class="nfpfilter-widget-header toggle-'.esc_attr($button_float).'"><a class="nfp-toogle-sidebar" href="#"> <i class="demo-icon nfpicon-menu"></i></a> </div><div style="clear:both;"></div><div class="nfp-sidebar-header nfpfilter-absolute-widget clearfix toggle-btn-'.esc_attr($button_float).'"><div class="nfp-sidebar-menu" data-sidebar-id="'.esc_attr($sidebar_id).'" data-sidebar_style="'.esc_attr($sidebar_style).'" style="display:none">';
                        dynamic_sidebar($sidebar_id);
                        echo '<div style="clear: both"></div></div></div>';
                        break;

                    default :
                        echo '<div style="clear: both"></div><div class="nfpfilter-widget-header toggle-'.esc_attr($button_float).'"> <a class="nfp-toogle-sidebar " href="#'.esc_attr($sidebar_id),'"> <i class="demo-icon nfpicon-menu"></i></a> </div><div style="clear:both;"></div><div class="nfp-sidebar-menu" data-sidebar-id="'.esc_attr($sidebar_id).'" data-sidebar_style="'.esc_attr($sidebar_style).'"><div  class="nfp-sidebar-header clearfix">';
                        dynamic_sidebar($sidebar_id);
                        echo '<div style="clear: both"></div></div></div>';

                }

                $return = ob_get_clean();
                return do_shortcode($return);
            }
        }

        /*
        * Ajax callback function
        * */
        function nfpfilter_ajax_callback(){
            $link = $_POST['link'];
            $sidebar_style = isset($_POST['sidebar_style']) ? $_POST['sidebar_style'] : '' ;
            $current_cat = isset($_POST['current_cat']) ? $_POST['current_cat'] : '';

            $get_backup = $_GET ;
            if(!empty($link)){
                $link_get = $this->string_to_array($link);
                $_GET = $link_get;
            }

            global $nfpfilter_initial_url;
            $nfpfilter_initial_url = $this->get_base_url_from_str($_POST['initial_url']);


            if(isset($_POST['sidebar_id']) && !empty($_POST['sidebar_id'])){
              echo do_shortcode('[nfpfilter_toggle_sidebar current_cat="'.esc_url($current_cat).'" sidebar_style="'.esc_attr($sidebar_style).'" sidebar_id="'.esc_attr($_POST['sidebar_id']).'"]');
            }


            if($_POST['is_archive'] == 'archive'){
                $_POST['settings_per_page_dropdown'] = get_option('nfp_insert_perpage_options');
                $_POST['settings_per_page'] = get_option('nfp_default_per_page');
                $_POST['settings_sorting'] = 'yes';
                $_POST['settings_result_count'] = 'yes';
            }


          echo do_shortcode('[nfpfilter_products per_page_dropdown="'.esc_attr($_POST['settings_per_page_dropdown']).'" per_page="'. esc_attr($_POST['settings_per_page']). '" orderby="'.esc_attr($_POST['settings_orderby']).'" order="' . esc_attr($_POST['settings_order']) .'" columns="'.esc_attr($_POST['settings_columns']).'" sorting="'. esc_attr($_POST['settings_sorting']).'" result_count="'. esc_attr($_POST['settings_result_count']).'" link="'.esc_url($link).'" exclude_out_of_stock="'.esc_attr($_POST['exclude_out_of_stock']).'" taxonomy_slug="'.esc_attr($_POST['taxonomySlug']).'" taxonomy_name="'.esc_attr($_POST['taxonomyName']).'"]');
            $_GET = $get_backup;
            $get_backup = $initial_url = null;
            wp_die();
        }
    }
    new nfp_shortcode;
}