Marcos_Alexandre

cspml-list-filter

Mar 29th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 181.02 KB | None | 0 0
  1. <?php
  2.  
  3. if(!defined('ABSPATH')){
  4.     exit; // Exit if accessed directly
  5. }
  6.  
  7. if( !class_exists( 'CspmListFilter' ) ){
  8.    
  9.     class CspmListFilter{
  10.        
  11.         private static $_this; 
  12.        
  13.         private $plugin_path;      
  14.         private $plugin_url;
  15.        
  16.         public $plugin_settings = array();
  17.         public $map_settings = array();
  18.        
  19.         public $metafield_prefix; //@since 2.0
  20.        
  21.         public $post_type = '';
  22.         public $map_type = 'normal_map'; //@since 2.3 | Whethear it's a "search map" or a "normal map"
  23.        
  24.         /**
  25.          * Layout settings */
  26.        
  27.         public $cspml_list_layout = 'vertical'; // Possible values are, "vertical", "horizontal-left", "horizontal-right"
  28.         public $cspml_map_height = '400';
  29.         public $cspml_list_height = '';
  30.         public $cspml_map_cols = '4'; //@since 2.6
  31.        
  32.         /**
  33.          * Options Bar Settings */
  34.          
  35.         public $cspml_show_options_bar = 'yes';
  36.        
  37.         /**
  38.          * View Options Settings */
  39.          
  40.         public $cspml_show_view_options = 'yes';
  41.         public $cspml_default_view_option = 'list';
  42.         public $cspml_grid_cols = 'cols3';
  43.        
  44.         /**
  45.          * Listings Count Settings */
  46.          
  47.         public $cspml_show_posts_count = 'yes';
  48.         public $cspml_posts_count_clause = '[posts_count] Result(s)';
  49.        
  50.         /**
  51.          * Content Settings */
  52.          
  53.         public $cspml_listings_title = '';
  54.         public $cspml_listings_details = '[l=700]';
  55.         public $cspml_click_on_title = 'no'; //@since 1.1
  56.         public $cspml_click_on_img = 'no'; //@since 1.1
  57.         public $cspml_external_link = 'same_window'; //@since 1.1
  58.         public $cspml_scroll_to_list_item = 'yes'; //@since 2.2
  59.         public $cspml_list_items_featured_img = 'show'; //@since 2.6
  60.         public $cspml_ellipses = 'yes'; //@since 2.6
  61.        
  62.         /**
  63.          * "Marker Position" Button Settings */
  64.          
  65.         public $cspml_show_fire_pinpoint_btn = 'yes';
  66.        
  67.         /**
  68.          * Sort Listings Settings */
  69.          
  70.         public $cspml_show_sort_option = 'yes';
  71.         public $cspml_sort_options = array(
  72.             'default|Default|init',
  73.             'data-date-created|Date (Newest first)|desc',
  74.             'data-date-created|Date (Oldest first)|asc',
  75.             'data-title|Title A to Z|asc',
  76.             'data-title|Title Z to A|desc'
  77.         );
  78.         public $cspml_custom_sort_options = '';
  79.         public $cspml_sort_options_order = array(); //@since 2.1
  80.        
  81.         /**
  82.          * Pagination Settings */
  83.          
  84.         public $cspml_posts_per_page = '';
  85.         public $cspml_pagination_position = 'bottom'; // Possible values are, "top", "bottom", "both"
  86.         public $cspml_pagination_align = 'center'; // Possible values are, "left", "right", "center"
  87.         public $cspml_prev_page_text = '&laquo;';
  88.         public $cspml_next_page_text = '&raquo;';
  89.         public $cspml_show_all = 'false';
  90.        
  91.         /**
  92.          * Listing's Filter Form Settings */
  93.          
  94.         public $cspml_faceted_search_option = 'no';
  95.         public $cspml_faceted_search_position = 'left';
  96.         public $cspml_faceted_search_display_option = 'show'; //@since 2.0
  97.         public $cspml_filter_btns_position = 'bottom'; // @since 1.2 / Possible values are, "top", "bottom", "both"
  98.        
  99.         public $cspml_taxonomies = array();
  100.         public $cspml_taxonomy_relation_param = 'AND';
  101.        
  102.         public $cspml_custom_fields = array();
  103.         public $cspml_custom_field_relation_param = 'AND';
  104.        
  105.         public $cspml_filter_btn_text = 'Filter';
  106.        
  107.         public $cspml_date_filter_option = 'no'; //@since 2.1
  108.         public $cspml_date_filter_parameters = ''; //@since 2.1
  109.         public $cspml_filter_fields_order = array(); //@since 2.1
  110.         public $cspml_date_filter_display_status = 'open'; //@since 2.3
  111.        
  112.         public $cspml_keyword_filter_option = 'no'; //@since 2.2
  113.         public $cspml_keyword_filter_label = 'Keyword'; //@since 2.2
  114.         public $cspml_keyword_filter_placeholder = 'Keyword'; //@since 2.2
  115.         public $cspml_keyword_display_status = 'open'; //@since 2.3
  116.         public $cspml_keyword_filter_description = ''; //@since 2.4
  117.  
  118.         /**
  119.          * Map Filter Form Settings */
  120.          
  121.         public $cspml_mfs_faceted_search_option = 'no';
  122.        
  123.         /**
  124.          * Custom settings */
  125.        
  126.         public $cspml_exclude_from_field_options = array();
  127.    
  128.         function __construct($atts = array()){
  129.  
  130.             if (!class_exists('CSProgressMap'))
  131.                 return;
  132.                
  133.             $CSProgressMap = CSProgressMap::this();
  134.            
  135.             if (!class_exists('CspmMainMap') && !class_exists('ProgressMapList'))
  136.                 return;
  137.  
  138.             extract( wp_parse_args( $atts, array(
  139.                 'init' => false,
  140.                 'plugin_settings' => array(),
  141.                 'map_settings' => array(),
  142.                 'metafield_prefix' => '',
  143.             )));
  144.  
  145.             self::$_this = $this;    
  146.            
  147.             $ProgressMapList = ProgressMapList::this();  
  148.            
  149.             $this->plugin_path = $ProgressMapList->cspml_plugin_path;
  150.             $this->plugin_url = $ProgressMapList->cspml_plugin_url;
  151.            
  152.             $this->metafield_prefix = $metafield_prefix;
  153.                
  154.             /**
  155.              * Get plugin settings */
  156.              
  157.             $this->plugin_settings = $plugin_settings;
  158.            
  159.             if(!$init){
  160.                
  161.                 /**
  162.                  * Get all map settings */
  163.                  
  164.                 $this->map_settings = $map_settings;
  165.  
  166.                 /**
  167.                  * Get this map type
  168.                  * @since 2.3 */
  169.                
  170.                 $this->map_type = $this->cspml_get_map_option('map_type', 'normal_map');
  171.                
  172.                 /**
  173.                  * [@map_object_id] | The ID of the map
  174.                  * @since 2.0 */
  175.                  
  176.                 $this->map_object_id = isset($this->map_settings['map_object_id']) ? $this->map_settings['map_object_id'] : '';
  177.                    
  178.                 /**
  179.                  * List Layout Settings */
  180.            
  181.                 $this->cspml_list_layout = $this->cspml_get_map_option('list_layout', 'vertical');
  182.                 $this->cspml_map_height = $this->cspml_get_map_option('map_height', '400');
  183.                 $this->cspml_list_height = $this->cspml_get_map_option('list_height', '');
  184.                 $this->cspml_map_cols = $this->cspml_get_map_option('map_cols', '4');
  185.    
  186.                 /**
  187.                  * Options Bar Settings */
  188.        
  189.                 $this->cspml_show_options_bar = $this->cspml_get_map_option('show_options_bar', 'yes');
  190.                 $this->cspml_show_view_options = $this->cspml_get_map_option('show_view_options', 'yes');
  191.                 $this->cspml_default_view_option = $this->cspml_get_map_option('default_view_option', 'list');
  192.                 $this->cspml_grid_cols = $this->cspml_get_map_option('grid_cols', 'cols3');
  193.                 $this->cspml_show_posts_count = $this->cspml_get_map_option('cslf_show_posts_count', 'yes');
  194.                 $this->cspml_posts_count_clause = $this->cspml_get_map_option('cslf_posts_count_clause', '[posts_count] Result(s)');
  195.                 $this->cspml_sort_options_order = unserialize($this->cspml_get_map_option('sort_options_order', serialize(array('default', 'custom')))); //@since 2.1
  196.                
  197.                 /**
  198.                  * List Items settings */
  199.        
  200.                 $this->cspml_listings_title = $this->cspml_get_map_option('listings_title', '');
  201.                 $this->cspml_listings_details = $this->cspml_get_map_option('listings_details', '[l=700]');
  202.                 $this->cspml_show_fire_pinpoint_btn = $this->cspml_get_map_option('show_fire_pinpoint_btn', 'yes');
  203.                 $this->cspml_click_on_title = $this->cspml_get_map_option('cslf_click_on_title', 'yes'); //@since 1.1
  204.                 $this->cspml_click_on_img = $this->cspml_get_map_option('cslf_click_on_img', 'yes'); //@since 1.1
  205.                 $this->cspml_external_link = $this->cspml_get_map_option('cslf_external_link', 'same_window'); //@since 1.1
  206.                 $this->cspml_scroll_to_list_item = $this->cspml_get_map_option('scroll_to_list_item', 'yes'); //@since 2.2
  207.                 $this->cspml_list_items_featured_img = $this->cspml_get_map_option('list_items_featured_img', 'show'); //@since 2.6        
  208.                 $this->cspml_ellipses = $this->cspml_get_map_option('cslf_ellipses', 'yes'); //@since 2.6
  209.                
  210.                 /**
  211.                  * Sort listings settings */
  212.                
  213.                 $this->cspml_show_sort_option = $this->cspml_get_map_option('show_sort_option', 'yes');
  214.                 $this->cspml_sort_options = unserialize($this->cspml_get_map_option('sort_options', serialize(array())));
  215.                 $this->cspml_custom_sort_options = unserialize($this->cspml_get_map_option('custom_sort_options', serialize(array())));
  216.        
  217.                 /**
  218.                  * Pagination Settings */
  219.                
  220.                 $this->cspml_posts_per_page = $this->cspml_get_map_option('posts_per_page', get_option('posts_per_page'));
  221.                 $this->cspml_pagination_position = $this->cspml_get_map_option('pagination_position', 'bottom');
  222.                 $this->cspml_pagination_align = $this->cspml_get_map_option('pagination_align', 'center');
  223.                 $this->cspml_prev_page_text = $this->cspml_get_map_option('prev_page_text', '&laquo;');
  224.                 $this->cspml_next_page_text = $this->cspml_get_map_option('next_page_text', '&raquo;');
  225.                 $this->cspml_show_all = $this->cspml_get_map_option('show_all', 'false');
  226.        
  227.                 /**
  228.                  * Filter serch settings section */
  229.                
  230.                 $this->cspml_faceted_search_option = $this->cspml_get_map_option('cslf_faceted_search_option', 'no');
  231.                 $this->cspml_faceted_search_position = $this->cspml_get_map_option('faceted_search_position', 'left');
  232.                 $this->cspml_taxonomies = unserialize($this->cspml_get_map_option('cslf_taxonomies', serialize(array())));
  233.                 $this->cspml_taxonomy_relation_param = $this->cspml_get_map_option('cslf_taxonomy_relation_param', 'AND');
  234.                 $this->cspml_custom_fields = unserialize($this->cspml_get_map_option('cslf_custom_fields', serialize(array())));
  235.                 $this->cspml_custom_field_relation_param = $this->cspml_get_map_option('cslf_custom_field_relation_param', 'AND');
  236.                 $this->cspml_filter_btn_text = $this->cspml_get_map_option('cslf_filter_btn_text', esc_html__('Filter'));
  237.                 $this->cspml_filter_btns_position = $this->cspml_get_map_option('filter_btns_position', 'bottom'); //@since 1.2
  238.                 $this->cspml_faceted_search_display_option = $this->cspml_get_map_option('faceted_search_display_option', 'show'); //@since 2.0
  239.                 $this->cspml_date_filter_option = $this->cspml_get_map_option('date_filter_option', 'no'); //@since 2.1
  240.                 $this->cspml_date_filter_parameters = unserialize($this->cspml_get_map_option('date_filter_param', serialize(array()))); //@since 2.1
  241.                 $this->cspml_filter_fields_order = unserialize($this->cspml_get_map_option('filter_fields_order', serialize(array('keyword', 'date_filter', 'taxonomies', 'custom_fields')))); //@since 2.1
  242.                 $this->cspml_keyword_filter_option = $this->cspml_get_map_option('keyword_filter_option', 'no'); //@since 2.2
  243.                 $this->cspml_keyword_filter_label = $this->cspml_get_map_option('keyword_filter_label', 'Keyword'); //@since 2.2
  244.                 $this->cspml_keyword_filter_placeholder = $this->cspml_get_map_option('keyword_filter_placeholder', 'Keyword'); //@since 2.2
  245.                 $this->cspml_keyword_display_status = $this->cspml_get_map_option('keyword_display_status', 'open'); //@since 2.3
  246.                 $this->cspml_keyword_filter_description = $this->cspml_get_map_option('keyword_filter_description', ''); //@since 2.4
  247.                 $this->cspml_date_filter_display_status = $this->cspml_get_map_option('date_filter_display_status', 'open'); //@since 2.3              
  248.  
  249.                 if(!is_admin()){                           
  250.                    
  251.                     /**
  252.                      * These are all the hooks that communicates with Progress Map by displaying the listings and the filters
  253.                      * Note: Always call these hooks in the custructor 'cause we need to execute them any time ...
  254.                      * ... a shortcode is called. In each shortcode, these hooks will load different settings ...
  255.                      * ... that a map needs. */
  256.                      
  257.                     add_filter('cspm_main_map_output_atts', array(&$this, 'cspml_add_main_map_output_atts'), 10, 2);
  258.                     add_filter('cspm_main_map_output', array(&$this, 'cspml_listings_map'), 10, 2);
  259.                     add_filter('cspm_main_map_post_ids', array(&$this, 'cspml_overide_post_ids_array'), 10, 3);
  260.                     add_action('cspm_before_main_map_query', array(&$this, 'cspml_clear_session_on_page_load'), 10, 2);
  261.                    
  262.                 }
  263.                                            
  264.             }
  265.  
  266.         }
  267.        
  268.        
  269.         static function this() {
  270.            
  271.             return self::$_this;
  272.        
  273.         }
  274.        
  275.        
  276.         function cspml_hooks(){
  277.                
  278.             /**
  279.              * Ajax function */
  280.              
  281.             add_action('wp_ajax_cspml_listings_html', array(&$this, 'cspml_listings_html'));
  282.             add_action('wp_ajax_nopriv_cspml_listings_html', array(&$this, 'cspml_listings_html'));
  283.            
  284.             add_action('wp_ajax_cspml_faceted_search_query', array(&$this, 'cspml_faceted_search_query'));
  285.             add_action('wp_ajax_nopriv_cspml_faceted_search_query', array(&$this, 'cspml_faceted_search_query'));
  286.  
  287.             if(is_admin()){
  288.                
  289.                 /**
  290.                  * Add plugin menu */
  291.                  
  292.                 add_action( 'admin_menu', array(&$this, 'cspml_admin_menu'), 100 );
  293.            
  294.             }
  295.            
  296.         }
  297.        
  298.        
  299.         /**
  300.          * Add this plugin to the admin menu
  301.          *
  302.          * @since 1.0
  303.          */
  304.         function cspml_admin_menu(){   
  305.            
  306.             if (!class_exists('CSProgressMap'))
  307.                 return;
  308.                
  309.             add_submenu_page( 'cs_progress_map_plugin', esc_html__( 'List & Filter', 'cspml' ), esc_html__( 'List & Filter', 'cspml' ), 'manage_options', 'cspml', array(&$this, 'cspml_settings_page') );
  310.    
  311.         }
  312.        
  313.        
  314.         /**
  315.          * This will display the plugin settings form
  316.          *
  317.          * @since 1.0
  318.          * @updated 2.0 [settings removed]
  319.          */
  320.         function cspml_settings_page(){
  321.                                
  322.             echo '<div class="update-nag">';
  323.                  
  324.                 echo '<strong style="color:red;">'.esc_html__( 'Since the version 2.0, the "List & Filter" settings page has been removed. To create/edit your list & filter, follow these instructions:', 'cspml' ).'</strong>';
  325.                
  326.                 echo '<br /><br />';
  327.                
  328.                 echo '<strong>'.esc_html__( 'Create a new map:', 'cspml' ).'</strong>';
  329.                
  330.                     echo '<br /><br />';
  331.                    
  332.                     echo esc_html__( '1. Click on the menu "Progress Map => Add new map".', 'cspml' );
  333.                    
  334.                     echo '<br /><br />';
  335.                    
  336.                     echo esc_html__( '2. Select a post type in the metabox "(Custom) Post Type", then, Click on the button "Publish".', 'cspml' );
  337.                    
  338.                     echo '<br /><br />';
  339.                    
  340.                     echo esc_html__( '3. A new metabox titled "List & Filter Settings" will be available. Use the fields on that metabox to create your list & filter.', 'cspml' );
  341.                    
  342.                     echo '<br /><br />';
  343.                
  344.                 echo '<strong>'.esc_html__( 'Edit an existing map:', 'cspml' ).'</strong>';
  345.                
  346.                     echo '<br /><br />';
  347.                    
  348.                     echo esc_html__( '1. Click on the menu "Progress Map => All maps".', 'cspml' );
  349.                
  350.                     echo '<br /><br />';
  351.                    
  352.                     echo esc_html__( '2. Edit a map on the list of all maps.', 'cspml' );
  353.                
  354.                     echo '<br /><br />';
  355.                    
  356.                     echo esc_html__( '3. Use the fields on the metabox "List & Filter Settings" to create/edit your list & filter.', 'cspml' );
  357.                    
  358.             echo '</div>';
  359.            
  360.         }
  361.        
  362.        
  363.         /**
  364.          * Get an option from a map options
  365.          *
  366.          * @since 2.0
  367.          */
  368.         function cspml_get_map_option($option_id, $default_value = ''){
  369.            
  370.             /**
  371.              * We'll check if the default settings can be found in the array containing the "(shared) plugin settings".
  372.              * If found, we'll use it. If not found, we'll use the one in [@default_value] instead. */
  373.              
  374.             $default = $this->cspml_setting_exists($option_id, $this->plugin_settings, $default_value);
  375.            
  376.             return $this->cspml_setting_exists($this->metafield_prefix.'_'.$option_id, $this->map_settings, $default);
  377.            
  378.         }
  379.        
  380.        
  381.         /**
  382.          * Get the value of a setting
  383.          *
  384.          * @since 2.0
  385.          */
  386.         function cspml_get_plugin_setting($setting_id, $default_value = ''){
  387.            
  388.             return $this->cspml_setting_exists($setting_id, $this->plugin_settings, $default_value);           
  389.            
  390.         }
  391.        
  392.            
  393.         /**
  394.          * Check if array_key_exists and if empty() doesn't return false
  395.          * Replace the empty value with the default value if available
  396.          * @empty() return false when the value is (null, 0, "0", "", 0.0, false, array())
  397.          *
  398.          * @since 1.0
  399.          */
  400.         function cspml_setting_exists($key, $array, $default = ''){
  401.            
  402.             $array_value = isset($array[$key]) ? $array[$key] : $default;
  403.            
  404.             $setting_value = empty($array_value) ? $default : $array_value;
  405.            
  406.             return $setting_value;
  407.            
  408.         }
  409.    
  410.            
  411.         /**
  412.          * Enqueue CSS files
  413.          *
  414.          * @since 1.0
  415.          */
  416.         function cspml_enqueue_styles(){
  417.  
  418.             if (!class_exists('CspmMainMap'))
  419.                 return;
  420.            
  421.             $CspmMainMap = CspmMainMap::this();
  422.            
  423.             do_action('cspml_before_enqueue_style');
  424.                        
  425.             if($CspmMainMap->combine_files == "combine"){
  426.                    
  427.                 wp_enqueue_style('cspml_combined_styles');
  428.                                
  429.             }else{
  430.            
  431.                 /**
  432.                  * Selectize
  433.                  * @since 1.0 */
  434.                  
  435.                 wp_enqueue_style('cspml_selectize');
  436.                 wp_enqueue_style('cspml_selectize_skin');
  437.                            
  438.                 /**
  439.                  * ion-Check Radio
  440.                  * @since 1.0 */
  441.                  
  442.                 wp_enqueue_style('cspml_ion_check_radio');                             
  443.                 wp_enqueue_style('cspml_ion_check_radio_skin');
  444.    
  445.                 /**
  446.                  * Range Slider
  447.                  * Note: File located in "Progress Map" directory
  448.                  * @since 1.0 */
  449.                                
  450.                 wp_enqueue_style('cspm_rangeSlider_css');
  451.                 wp_enqueue_style('cspm_rangeSlider_skin_css');
  452.                    
  453.                 /**
  454.                  * Spinner
  455.                  * @since 1.0 */
  456.                  
  457.                 wp_enqueue_style('cspml_spinner');
  458.                
  459.                 /**
  460.                  * Hover
  461.                  * @since 1.0 */
  462.                  
  463.                 wp_enqueue_style('cspml_hover');
  464.                
  465.                 /**
  466.                  * Datepicker
  467.                  * @since 2.1 */
  468.                
  469.                 wp_enqueue_style('cspml_datepicker');
  470.                
  471.                 /**
  472.                  * Date Range Picker
  473.                  * @since 2.4 */
  474.                
  475.                 wp_enqueue_style('cspml_daterangepicker');
  476.                            
  477.                 /**
  478.                  * iziModal (Registred inside "Progress Map")
  479.                  * @since 2.5 */
  480.                  
  481.                 wp_enqueue_style('cspm_izimodal_css');                         
  482.                
  483.                 /**
  484.                  * Progress Map List Style
  485.                  * @since 1.0 */
  486.                            
  487.                 wp_enqueue_style('cspml_styles');
  488.                
  489.             }
  490.            
  491.             do_action('cspml_after_enqueue_style');
  492.                        
  493.         }  
  494.        
  495.        
  496.         /**
  497.          * Enqueue JS files
  498.          *
  499.          * @since 1.0
  500.          */
  501.         function cspml_enqueue_scripts(){      
  502.  
  503.             if (!class_exists('CspmMainMap'))
  504.                 return;
  505.            
  506.             $CspmMainMap = CspmMainMap::this();
  507.            
  508.             do_action('cspml_before_enqueue_script');
  509.                        
  510.             if($CspmMainMap->combine_files == "combine"){
  511.            
  512.                 wp_enqueue_script('cspml_combined_scripts');   
  513.    
  514.             }else{
  515.                
  516.                 /**
  517.                  * ScrollTo jQuery Plugin
  518.                  * Registered in the plugin "Progress Map */
  519.                
  520.                 wp_enqueue_script('cspm_scrollTo_js');
  521.                                                    
  522.                 /**
  523.                  * Selectize
  524.                  * @since 1.0 */
  525.                  
  526.                 wp_enqueue_script('cspml_selectize_js');
  527.            
  528.                 /**
  529.                  * ion-Check Radio
  530.                  * @since 1.0 */
  531.                  
  532.                 wp_enqueue_script('cspml_ion_check_radio_js');
  533.    
  534.                 /**
  535.                  * Range Slider
  536.                  * Note: File located in "Progress Map" directory
  537.                  * @since 1.0 */
  538.                                
  539.                 wp_enqueue_script('cspm_rangeSlider_js');
  540.                    
  541.                 /**
  542.                  * Spinner
  543.                  * @since 1.0 */
  544.                  
  545.                 wp_enqueue_script('cspml_spinner_js');
  546.                
  547.                 /**
  548.                  * Datepicker
  549.                  * @since 2.1 */
  550.                
  551.                 wp_enqueue_script('cspml_datepicker_js');
  552.                
  553.                 /**
  554.                  * Moment.js
  555.                  * @since 2.4 */
  556.                
  557.                 wp_enqueue_script('cspml_moment_js');
  558.                
  559.                 /**
  560.                  * Date Range Picker
  561.                  * @since 2.4 */
  562.                
  563.                 wp_enqueue_script('cspml_daterangepicker_js');
  564.                            
  565.                 /**
  566.                  * iziModal (Registred inside "Progress Map")
  567.                  * @since 2.5 */
  568.                  
  569.                 wp_enqueue_script('cspm_izimodal_js');
  570.                                            
  571.                 /**
  572.                  * Progress Map List Custom Functions
  573.                  * @since 1.0 */
  574.              
  575.                 wp_enqueue_script('cspml_scripts');
  576.    
  577.             }
  578.            
  579.             do_action('cspml_after_enqueue_script');
  580.                        
  581.         }
  582.            
  583.        
  584.         /**
  585.          * Add custom attributes to the array of attributes sent to the main map output (carousel)
  586.          *
  587.          * @since 1.0
  588.          */
  589.         function cspml_add_main_map_output_atts($val, $atts){
  590.            
  591.             if(!is_array($atts))
  592.                 return;
  593.            
  594.             foreach($atts as $key => $value)
  595.                 $val[$key] = $value;
  596.            
  597.             return $val;
  598.            
  599.         }
  600.        
  601.        
  602.         /**
  603.          * If there was no pagination passed, clean the filtering session  
  604.          * In other words, we clean all session when the page is refreshed ...
  605.          * ... because everything works with ajax, and the only case when the page is reloaded ...     
  606.          * ... is when using/ the pagination.
  607.          * We use the URL attribute "paginate" to detect the pagination
  608.          *
  609.          * @since 1.0
  610.          */
  611.         function cspml_clear_session_on_page_load($map_id, $atts = array()){
  612.                        
  613.             extract( wp_parse_args( $atts, array() ) );
  614.    
  615.             if(isset($list_ext) && $list_ext == 'yes' && !isset($_GET['paginate'])){
  616.    
  617.                 unset($_SESSION['cspml_posts_in_search'][$map_id]);
  618.                 unset($_SESSION['cspml_sort_args'][$map_id]);              
  619.                 unset($_SESSION['cspml_listings_filter_post_ids'][$map_id]);
  620.                
  621.             }
  622.            
  623.         }
  624.  
  625.        
  626.         /**
  627.          * Used in the filter hook that overides the post_ids array when there's a faceted search request
  628.          * The faceted search request can be detected by the presence of the $_SESSION['cspml_listings_filter_post_ids'][$map_id]
  629.          *
  630.          * @since 1.0
  631.          */
  632.         function cspml_overide_post_ids_array($value, $map_id, $atts = array()){
  633.            
  634.             extract( wp_parse_args( $atts, array() ) );
  635.                    
  636.             if(isset($list_ext) && $list_ext == 'yes' && isset($_SESSION['cspml_listings_filter_post_ids'][$map_id]))
  637.                 return $_SESSION['cspml_listings_filter_post_ids'][$map_id];
  638.             else return $value;
  639.                
  640.         }
  641.        
  642.        
  643.         function cspml_listings_map($output, $atts = array()){
  644.  
  645.             if (!class_exists('CspmMainMap'))
  646.                 return;
  647.            
  648.             $CspmMainMap = CspmMainMap::this();
  649.            
  650.             extract( wp_parse_args( $atts, array() ) );
  651.  
  652.             if(isset($list_ext) && $list_ext == 'yes'){
  653.            
  654.                 /**
  655.                  * Load styles & scripts from "Progress Map" */
  656.                
  657.                 $CspmMainMap->cspm_enqueue_styles();
  658.                 $CspmMainMap->cspm_enqueue_scripts();
  659.                
  660.                 /**
  661.                  * Load styles & scripts of this extension */
  662.                  
  663.                 $this->cspml_enqueue_styles();
  664.                 $this->cspml_enqueue_scripts();
  665.  
  666.                 $list_layout = $this->cspml_list_layout;
  667.                 $map_height = $this->cspml_map_height.'px';
  668.                 $list_height = $this->cspml_list_height;
  669.                 $list_filter = $this->cspml_faceted_search_option;
  670.                 $map_filter = $this->cspml_mfs_faceted_search_option;
  671.  
  672.                 /**
  673.                  * Define fixed/fullwidth layout height and width */
  674.                
  675.                 if($CspmMainMap->layout_type == 'fixed')
  676.                     $layout_style = "width:".$CspmMainMap->layout_fixed_width."px; height:auto;";
  677.                 else $layout_style = $layout_style = "width:100%; height:auto;";
  678.                    
  679.                 $output = '';
  680.                
  681.                 /**
  682.                  * Set layout CSS classes */
  683.                
  684.                 if(isset($list_layout) && ($list_layout == 'horizontal-left' || $list_layout == 'horizontal-right')){
  685.                    
  686.                     $map_position = ($list_layout == 'horizontal-right') ? ' pull-right' : '';
  687.                    
  688.                     $row_classes = ' class="row no-margin"';
  689.                     $map_container_classes = ' class="col-lg-'.$this->cspml_map_cols.' col-md-'.$this->cspml_map_cols.' col-sm-12 col-xs-12'.$map_position.'"';
  690.                    
  691.                     $list_cols = array(
  692.                         '2' => '10',
  693.                         '3' => '9',
  694.                         '4' => '8',
  695.                         '6' => '6',
  696.                         '8' => '4'
  697.                     ); //@since 2.6
  698.                    
  699.                     $list_container_classes = ' class="col-lg-'.$list_cols[$this->cspml_map_cols].' col-md-'.$list_cols[$this->cspml_map_cols].' col-sm-12 col-xs-12"';
  700.                     $clearfix_div_classes = ' class="visible-sm visible-xs margin-top-30"';
  701.                    
  702.                 }else{
  703.                    
  704.                     $row_classes = $map_container_classes = $clearfix_div_classes = '';
  705.                     $list_container_classes = ' class="margin-top-30"';
  706.                    
  707.                 }
  708.                
  709.                 $output .= '<div id="cspml_container" data-map-id="'.$map_id.'" '.$row_classes.'>';
  710.                
  711.                     $output .= '<div'.$map_container_classes.'>';
  712.                
  713.                         /**
  714.                          * Plugin Container */
  715.                            
  716.                         $output .= '<div class="codespacing_progress_map_area" '.apply_filters('cspml_container_custom_atts', '', $map_id).' style="'.$layout_style.'">';
  717.                            
  718.                             /**
  719.                              * force to hide "Progress Map" faceted search if the listing's faceted search is active */
  720.                              
  721.                             if($list_filter == 'yes' || $map_filter == 'yes')
  722.                                 $faceted_search = 'no';
  723.                                                                            
  724.                             /**
  725.                              * Interface elements
  726.                              * @updated 1.1 */
  727.                              
  728.                             $output .= $CspmMainMap->cspm_map_interface_element(array(
  729.                                 'map_id' => $map_id,       
  730.                                 'carousel' => 'no',
  731.                                 'faceted_search' => $faceted_search,
  732.                                 'search_form' => $search_form,
  733.                                 'faceted_search_tax_slug' => $faceted_search_tax_slug,
  734.                                 'faceted_search_tax_terms' => $faceted_search_tax_terms,
  735.                                 'geo' => $geo,
  736.                                 'infobox_type' => $infobox_type, //@since 1.1
  737.                                 'extensions' => array('list_ext' => $list_ext),
  738.                             ));
  739.                                        
  740.                             /**
  741.                              * Map */
  742.                              
  743.                             $output .= '<div class="position-relative">';
  744.                                        
  745.                                 $output .= '<div id="codespacing_progress_map_div_'.$map_id.'" class="col-lg-12 col-xs-12 col-sm-12 col-md-12" style="height:'.$map_height.'"></div>';
  746.                                
  747.                                 if(isset($list_layout) && $list_layout == 'vertical'){
  748.                                    
  749.                                     $output .= '<div class="clearfix"></div>';
  750.                                    
  751.                                     $txt_resize_the_map = apply_filters('__resize_the_map', esc_html__('Resize the map', 'cspml'));
  752.                                    
  753.                                     $output .= '<div class="cspml_resize_map cspm_border_top_radius cspm_border_shadow" data-map-id="'.$map_id.'" data-map-height="'.$map_height.'" title="'.$txt_resize_the_map.'">';
  754.                                         $output .= '<img src="'.apply_filters('cspml_resize_map_img', $this->plugin_url.'img/collapse.png', str_replace('map', '', $map_id)).'" class="cspm_animated push" alt="'.$txt_resize_the_map.'" />';
  755.                                     $output .= '</div>';
  756.                                    
  757.                                 }
  758.                                
  759.                             $output .= '</div>';           
  760.                        
  761.                         $output .= '</div>';   
  762.                
  763.                     $output .= '</div>';
  764.                
  765.                     /**
  766.                      * HTML Listings */
  767.    
  768.                     $attr = array();
  769.                    
  770.                     if(!empty($post_ids)) $attr['post_ids'] = esc_attr($post_ids);
  771.                    
  772.                     $attr['optional_latlng'] = (!empty($optional_latlng)) ? esc_attr($optional_latlng) : 'true';
  773.                    
  774.                     /**
  775.                      * Posts per page */
  776.                      
  777.                     $posts_per_page = (isset($posts_per_page) && !empty($posts_per_page)) ? $posts_per_page : $this->cspml_posts_per_page;
  778.  
  779.                     /**
  780.                      * Set the list height */
  781.                    
  782.                     if(isset($list_height) && !empty($list_height)){
  783.                    
  784.                         $list_height = $list_height;
  785.                        
  786.                     }else $list_height = '';
  787.                    
  788.                     /**
  789.                      * Display the list */
  790.  
  791.                     $output .= '<div'.$list_container_classes.'>';
  792.                    
  793.                         $output .= '<div'.$clearfix_div_classes.'></div>';
  794.                        
  795.                         $output .= $this->cspml_listings_html(
  796.                             array_merge(
  797.                                 array(             
  798.                                     'map_id' => $map_id,
  799.                                 ),
  800.                                 $attr
  801.                             )
  802.                         );
  803.                
  804.                     $output .= '</div>';
  805.                
  806.                 $output .= '</div>';
  807.            
  808.             }
  809.            
  810.             /**
  811.              * Remove the filter "cspm_main_map_output" after the current "list & filter" been displayed.
  812.              *
  813.              * @since 2.1
  814.              * ----------
  815.              * A fix to the following issue:
  816.              *
  817.              * When displaying multiple "lists & filters" on the same page,
  818.              * the hook "cspm_main_map_output" merge the the previous list(s) data to the next list data!
  819.              * This creats a JS conflicts in the Datepicker used in the feature "Filter by Posts publish date"!
  820.              * Removing the filter "cspm_main_map_output" after displaying a list solved the problem!
  821.              * If another "list & filter" should be displayed on the same page, the hook "cspm_main_map_output" ...
  822.              * ... will be called again from the constructor and will load the new list data only!
  823.              */
  824.                                
  825.             remove_filter('cspm_main_map_output', array(&$this, 'cspml_listings_map')); //@since 2.1
  826.            
  827.             /**
  828.              * Return the list & filter */
  829.              
  830.             return $output;
  831.            
  832.         }
  833.        
  834.        
  835.         /**
  836.          * This will display all Listings & the faceted search
  837.          *
  838.          * @since 1.0
  839.          * @updated 2.7
  840.          */
  841.         function cspml_listings_html($atts = array()){
  842.  
  843.             if (!class_exists('CspmMainMap'))
  844.                 return;
  845.                
  846.             $CspmMainMap = CspmMainMap::this();
  847.                
  848.             global $post, $wp_query, $wp_rewrite, $paged;
  849.            
  850.             /**
  851.              * Reload map settings */
  852.              
  853.             $this->map_settings = (isset($_POST['map_settings'])) ? $_POST['map_settings'] : $this->map_settings;
  854.            
  855.             $map_id = (isset($_POST['map_id'])) ? esc_attr($_POST['map_id']) : 'initial';
  856.        
  857.             /**
  858.              * Get The ID Of The Page Where The Shortcode was Executed */
  859.              
  860.             $shortcode_page_id = isset($_POST['shortcode_page_id']) ? esc_attr($_POST['shortcode_page_id']) : $wp_query->get_queried_object_id();
  861.            
  862.             $template_tax_query = ''; //@since 2.7
  863.            
  864.             if(is_tax() || is_category() || is_tag()){
  865.  
  866.                 /**
  867.                  * Get the current taxonomy and terms
  868.                  * @since 2.7 */
  869.                
  870.                 $queried_object = get_queried_object();
  871.                
  872.                 $taxonomy = (isset($queried_object->taxonomy)) ? $queried_object->taxonomy : ''; // The taxonomy slug/name
  873.                 $term_id = (isset($queried_object->term_id)) ? $queried_object->term_id : ''; // The term ID
  874.                 $term_slug = (isset($queried_object->slug)) ? $queried_object->slug : ''; // The term Name
  875.                
  876.                 $page_template = $taxonomy;
  877.                
  878.                 $template_tax_query = $taxonomy.','.$term_slug;
  879.                
  880.             }elseif(is_author())
  881.                 $page_template = 'author';
  882.             else $page_template = get_page_template_slug($shortcode_page_id);
  883.            
  884.             if(isset($_POST['page_template'])) $page_template = esc_attr($_POST['page_template']);
  885.             if(isset($_POST['template_tax_query'])) $template_tax_query = esc_attr($_POST['template_tax_query']);          
  886.                                    
  887.             /**
  888.              * Get the link of the page where the shortcode was executed */
  889.            
  890.             if($page_template == 'author'){
  891.                
  892.                 $shortcode_page_link = get_author_posts_url($shortcode_page_id);
  893.            
  894.             }elseif(!empty($template_tax_query)){ //@since 2.7
  895.                
  896.                 $shortcode_page_link = (isset($_POST['shortcode_page_link']))
  897.                     ? esc_attr($_POST['shortcode_page_link'])
  898.                     : get_term_link($shortcode_page_id); //@since 2.7
  899.            
  900.             }else $shortcode_page_link = get_permalink($shortcode_page_id);
  901.                                                                        
  902.             /**
  903.              * Get the page template slug used to render the listings
  904.              * Usefull for re-executing hooks after AJAX load */
  905.              
  906.             do_action('cspml_before_listings', $shortcode_page_id, $page_template, $template_tax_query);
  907.  
  908.             /**
  909.              * Function atts */
  910.              
  911.             extract( wp_parse_args( $atts, array(
  912.                
  913.                 'map_id' => $map_id,       
  914.                 'post_ids' => '',
  915.                 'post_type' => $this->cspml_get_map_option('post_type'),
  916.                 'map_type' => $this->cspml_get_map_option('map_type', 'normal_map'), //@since 2.3
  917.                 'orderby' => 'post__in',
  918.                 'order' => 'ASC',
  919.                 'posts_per_page' => $this->cspml_get_map_option('posts_per_page', get_option('posts_per_page')),
  920.                 'list_filter' => $this->cspml_get_map_option('cslf_faceted_search_option'),
  921.                 'filter_position' => $this->cspml_get_map_option('faceted_search_position'),
  922.                 'filter_display_option' => $this->cspml_get_map_option('faceted_search_display_option', 'show'),
  923.                 'list_height' => $this->cspml_get_map_option('list_height'),
  924.                 'default_view' => $this->cspml_get_map_option('default_view_option'),
  925.                 'paginate_position' => $this->cspml_get_map_option('pagination_position'),
  926.                 'paginate_align' => $this->cspml_get_map_option('pagination_align'),
  927.                 'show_options_bar' => $this->cspml_get_map_option('show_options_bar'),
  928.                 'show_listings' => 'true',
  929.                 'list_layout' => $this->cspml_get_map_option('list_layout', 'vertical'), //@since 2.6
  930.                 'map_cols' => $this->cspml_get_map_option('map_cols', '4'), //@since 2.6
  931.                 'optional_latlng' => '', // Wether we will display all posts event those with no Lat & Lng             
  932.            
  933.             )));   
  934.  
  935.             /**
  936.              * Clear the following sessions after the page refresh.
  937.              * Note: The page refresh on, Pagination, Sort Listings, Filter listings & on any other Ajax Request. ...
  938.              * ... This code will detect a simple page refresh (F5), that's what we want. */
  939.              
  940.             if(!isset($_GET['paginate']) && !isset($_POST['sort_call']) && !isset($_POST['ajax_call']) && !isset($_POST['filter_form_call'])){
  941.                
  942.                 unset($_SESSION['cspml_posts_in_search'][$map_id]);
  943.                 unset($_SESSION['cspml_sort_args'][$map_id]);              
  944.                 unset($_SESSION['cspml_listings_filter_post_ids'][$map_id]);
  945.                
  946.             }else{             
  947.                                                        
  948.                 /**
  949.                  * Recover shortcode atts missed during an AJAX request.
  950.                  * Note: When runing an AJAX request, some shortcode atts became empty.
  951.                  * A workaround fix is to send them whith the AJAX request to get/use them later! */
  952.                
  953.                 if(isset($_POST['paginate_position']))
  954.                     $paginate_position = esc_attr($_POST['paginate_position']);
  955.                    
  956.                 if(isset($_POST['paginate_align']))
  957.                     $paginate_align = esc_attr($_POST['paginate_align']);
  958.                
  959.                 if(isset($_POST['posts_per_page']))
  960.                     $posts_per_page = esc_attr($_POST['posts_per_page']);
  961.                
  962.             }
  963.  
  964.             $map_id = esc_attr($map_id);
  965.            
  966.             /**
  967.              * Specify which divider to use for the pagination */
  968.              
  969.             $exploded_URI = explode('?', esc_url($_SERVER['REQUEST_URI']));
  970.            
  971.             if(is_home() || is_front_page()) $divider = '?';
  972.             else $divider = (count($exploded_URI) > 1) ? '&' : '?';
  973.            
  974.             /**
  975.              * This will save the current view (List or Grid) even after AJAX request */
  976.              
  977.             $current_view = (isset($_POST['current_view'])) ? esc_attr($_POST['current_view']) : $default_view;
  978.            
  979.             /**
  980.              * Init empty sort_args array() */
  981.              
  982.             $sort_args = array();
  983.            
  984.             /**
  985.              * Detect when a sort call was sent and return data */
  986.              
  987.             if(isset($_POST['sort_call'])){
  988.                
  989.                 $shortcode_page_id = esc_attr($_POST['shortcode_page_id']);
  990.                 $divider = esc_attr($_POST['divider']);        
  991.                 $post_ids = esc_attr($_POST['init_post_ids']);
  992.                 $optional_latlng = esc_attr($_POST['optional_latlng']);
  993.  
  994.             }
  995.  
  996.             /**
  997.              * $_POST['ajax_call'] is only used when the user filter listings OR uses the search/filter form of the map */
  998.  
  999.             if(isset($_POST['ajax_call'])){
  1000.                
  1001.                 $map_id = esc_attr($_POST['map_id']);
  1002.                 $post_ids = isset($_POST['post_ids']) ? $_POST['post_ids'] : '';
  1003.                 $shortcode_page_id = esc_attr($_POST['shortcode_page_id']);
  1004.                 $divider = esc_attr($_POST['divider']);
  1005.                 $optional_latlng = esc_attr($_POST['optional_latlng']);
  1006.                
  1007.                 if(isset($_POST['save_session'])){
  1008.    
  1009.                     /**
  1010.                      * After filtering, we store the post_ids retreived from the map ...
  1011.                      * ... in order to use them again in the pagination, this way the pagination ...
  1012.                      * ... wont start again from the begining.
  1013.                      * After the page has been loaded from the pagination ...
  1014.                      * ... the $_POST['ajax_call'] will not exist ...
  1015.                      * ... now we check if $_SESSION['cspml_posts_in_search'][$map_id]['filtering'] equals TRUE ...
  1016.                      * ... if so, we call the post_ids stored in $_SESSION['cspml_posts_in_search'][$map_id]['post_ids'] */
  1017.                      
  1018.                     $_SESSION['cspml_posts_in_search'][$map_id]['filtering'] = true;
  1019.                     $_SESSION['cspml_posts_in_search'][$map_id]['post_ids'] = $post_ids;   
  1020.                                
  1021.                     /**
  1022.                      * Save the post_ids in a session in order to not start ...
  1023.                      * ... calling all posts when paginating or sorting by or filtering */
  1024.                      
  1025.                     $_SESSION['cspml_listings_filter_post_ids'][$map_id] = $post_ids;
  1026.                    
  1027.                 }
  1028.                
  1029.             /**
  1030.              * This case means that no filtering has been done from the faceted search in the map ...
  1031.              * ... or that we've just simply start loading the script.
  1032.              * But, This could be fired also when doing a sort call */
  1033.              
  1034.             }else{
  1035.  
  1036.                 /**
  1037.                  * Check if there was no filtering done before by the faceted search in the map */
  1038.                  
  1039.                 if(!isset($_SESSION['cspml_posts_in_search'][$map_id]['filtering'])){
  1040.                    
  1041.                     /**
  1042.                      * Remove $_SESSION['cspml_posts_in_search'][$map_id]['filtering'] And laod post_ids */
  1043.                      
  1044.                     unset($_SESSION['cspml_posts_in_search'][$map_id]);
  1045.                        
  1046.                     /**
  1047.                      * If post ids being pased from the shortcode parameter @post_ids
  1048.                      * ... OR ...
  1049.                      * If a sort call has been done and returns a list of post IDs */
  1050.                      
  1051.                     if(!empty($post_ids)){
  1052.                        
  1053.                         $query_post_ids = explode(',', $post_ids);                         
  1054.                        
  1055.                     }else{
  1056.                            
  1057.                         $query_post_ids = $CspmMainMap->cspm_main_query(array(
  1058.                             'optional_latlng' => esc_attr($optional_latlng)
  1059.                         ));
  1060.  
  1061.                     }
  1062.                    
  1063.                     $post_ids = $query_post_ids;               
  1064.  
  1065.                 /**
  1066.                  * If there was a filetring before, we call post_ids stored in the session */
  1067.                  
  1068.                 }else $post_ids = $_SESSION['cspml_posts_in_search'][$map_id]['post_ids'];
  1069.    
  1070.             }
  1071.            
  1072.             /**
  1073.              * Get the sort data (Of the "sort by" select box) after posts filtering & pagination */
  1074.              
  1075.             if((isset($_POST['ajax_call']) || isset($_GET['paginate'])) && isset($_SESSION['cspml_sort_args'][$map_id]))
  1076.                 $sort_args = $_SESSION['cspml_sort_args'][$map_id];
  1077.    
  1078.             /**
  1079.              * Get "post_ids" when a request for the listings filter form (Of the listings's faceted search) was sent */
  1080.  
  1081.             if(isset($_SESSION['cspml_listings_filter_post_ids'][$map_id]))
  1082.                 $post_ids = $_SESSION['cspml_listings_filter_post_ids'][$map_id];
  1083.            
  1084.             /**
  1085.              * Set "init_post_ids" as "post_ids" when we reset the filter or the "Progress Map" search */
  1086.  
  1087.             if(isset($_POST['reset_list']) && isset($_POST['init_post_ids'])){
  1088.    
  1089.                 $post_ids = explode(',', esc_attr($_POST['init_post_ids']));
  1090.                  
  1091.                 $_SESSION['cspml_listings_filter_post_ids'][$map_id] = $post_ids;
  1092.                 $_SESSION['cspml_posts_in_search'][$map_id]['post_ids'] = $post_ids;   
  1093.                
  1094.             }
  1095.            
  1096.             /**
  1097.              * This will contain all the post IDs of the first page load
  1098.              * This is usefull to know the post_ids we begins with in order to do other calculations */    
  1099.            
  1100.             $init_post_ids = (isset($_POST['init_post_ids'])) ? esc_attr($_POST['init_post_ids']) : implode(',', $post_ids);
  1101.             $count_init_post_ids = !empty($init_post_ids) ? count(explode(',', $init_post_ids)) : '0';
  1102.  
  1103.             $output = '';  
  1104.  
  1105.             if(esc_attr($show_listings) == 'true'){
  1106.                
  1107.                 /**
  1108.                  * Note: When doing an AJAX request, the result returns this element.
  1109.                  * We need this element only when loading the listings for the first time.
  1110.                  * To prevent this, we must detect AJAX requests and hide/show this element accordingly! */
  1111.                      
  1112.                 if(!isset($_POST['ajax_call']) && !isset($_POST['sort_call']))
  1113.                     $output .= '<div id="cspml_listings_container" data-map-id="'.$map_id.'" data-grid-cols="'.$this->cspml_get_map_option('grid_cols').'" data-map-type="'.$map_type.'" data-first-load="true" class="row">';
  1114.                                    
  1115.                     /**
  1116.                      * == The options bar
  1117.                      * Note: When doing an AJAX request, the result returns this element.
  1118.                      * We need this element only when loading the listings for the first time.
  1119.                      * To prevent this, we must detect AJAX requests and hide/show this element accordingly! */
  1120.                    
  1121.                     if(!isset($_POST['ajax_call']) && !isset($_POST['sort_call']) && $show_options_bar == 'yes'){
  1122.                        
  1123.                         /**
  1124.                          * Make sure to set the posts count to 0 on the first map load ...
  1125.                          * ... but only when it's a search map
  1126.                          * @since 2.3 */
  1127.                          
  1128.                         if($map_type != 'normal_map')
  1129.                             $count_init_post_ids = 0;
  1130.                        
  1131.                         /**
  1132.                          * Display the options bar
  1133.                          * @updated 2.3 */
  1134.                          
  1135.                         $output .= '<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">';
  1136.                             $output .= $this->cspml_options_bar(
  1137.                                 array(
  1138.                                     'map_id' => $map_id,       
  1139.                                     'nbr_items' => $count_init_post_ids,
  1140.                                     'page_id' => $shortcode_page_id,
  1141.                                     'current_view' => $current_view,
  1142.                                     'list_filter' => $list_filter,
  1143.                                     'filter_position' => $filter_position,
  1144.                                 )
  1145.                             );
  1146.                         $output .= '</div>';
  1147.                    
  1148.                     }
  1149.                    
  1150.                     /**
  1151.                      * Set the list height & style */
  1152.                                        
  1153.                     if(!empty($list_height)){
  1154.                        
  1155.                         $list_height = (strpos($list_height, 'px') !== false) ? $list_height : $list_height.'px';
  1156.                         $list_style = 'style="max-height:'.$list_height.'; overflow:auto;"';
  1157.                        
  1158.                     }else $list_style = '';
  1159.                                        
  1160.                     /**
  1161.                      * Note: When doing an AJAX request, the result returns this element.
  1162.                      * We need this element only when loading the listings for the first time.
  1163.                      * To prevent this, we must detect AJAX requests and hide/show this element accordingly! */
  1164.                      
  1165.                     if(!isset($_POST['ajax_call']) && !isset($_POST['sort_call'])){
  1166.                    
  1167.                         $output .= '<div class="clear-both"></div>';
  1168.                        
  1169.                         $output .= '<div data-map-id="'.$map_id.'" class="cspml_list_and_filter_container row no-margin" '.$list_style.'>';
  1170.                    
  1171.                     }
  1172.                    
  1173.                         if(esc_attr($list_filter) == 'yes'){
  1174.                            
  1175.                             /**
  1176.                              * Note: When doing an AJAX request, the result returns this element.
  1177.                              * We need this element only when loading the listings for the first time.
  1178.                              * To prevent this, we must detect AJAX requests and hide/show this element accordingly! */
  1179.                          
  1180.                             if(!isset($_POST['ajax_call']) && !isset($_POST['sort_call'])){
  1181.                            
  1182.                                 /**
  1183.                                  * == The faceted search form */
  1184.                                
  1185.                                 $pull_direction = ($filter_position == 'left') ? '' : 'pull-right';
  1186.                                 $display_option = ($filter_display_option == 'hide') ? ' style="display:none;"' : '';
  1187.                                
  1188.                                 if($list_layout != 'vertical' && $map_cols >= 6){ //@since 2.6
  1189.                                     $filter_cols_classes = 'col-lg-12 col-md-12 col-sm-12 col-xs-12'; //@since 2.6
  1190.                                 }else $filter_cols_classes = 'col-lg-3 col-md-3 col-sm-12 col-xs-12'; //@since 2.6
  1191.                                
  1192.                                 $output .= '<div class="cspml_fs_container '.$filter_cols_classes.' '.$pull_direction.'" data-map-id="'.$map_id.'" '.$display_option.'>';
  1193.                                
  1194.                                     $output .= $this->cspml_listings_faceted_search_form($map_id, $post_type, $post_ids, $list_filter);
  1195.                                
  1196.                                 $output .= '</div>';
  1197.                              
  1198.                             }
  1199.                                
  1200.                             if($list_layout != 'vertical' && $map_cols >= 6){ //@since 2.6
  1201.                                 $listings_area_cols_classes = 'col-lg-12 col-md-12 col-sm-12 col-xs-12'; //@since 2.6
  1202.                             }else $listings_area_cols_classes = 'col-lg-9 col-md-9 col-sm-12 col-xs-12'; //@since 2.6
  1203.                                
  1204.                             $listings_area_cols = ($filter_display_option == 'show') ? $listings_area_cols_classes : 'col-lg-12 col-md-12 col-sm-12 col-xs-12';
  1205.                            
  1206.                         }else $listings_area_cols = 'col-lg-12 col-md-12 col-sm-12 col-xs-12';
  1207.                        
  1208.                         /**
  1209.                          * Note: When doing an AJAX request, the result returns this element.
  1210.                          * We need this element only when loading the listings for the first time.
  1211.                          * To prevent this, we must detect AJAX requests and hide/show this element accordingly! */
  1212.                          
  1213.                         if(!isset($_POST['ajax_call']) && !isset($_POST['sort_call']))
  1214.                             $output .= '<div class="cspml_listing_items_container_'.$map_id.' '.$listings_area_cols.'" data-list-layout="'.$list_layout.'" data-map-cols="'.$map_cols.'">';
  1215.                            
  1216.                             /**
  1217.                              * == The loading spinner
  1218.                              * Note: When doing an AJAX request, the result returns this element.
  1219.                              * We need this element only when loading the listings for the first time.
  1220.                              * To prevent this, we must detect AJAX requests and hide/show this element accordingly! */
  1221.                              
  1222.                             if(!isset($_POST['ajax_call']) && !isset($_POST['sort_call'])){
  1223.                                    
  1224.                                 $output .= '<div id="cspml_loading_container_'.$map_id.'" class="cspml_loading_container cspm_border_shadow cspm_border_radius">';
  1225.                                     $output .= '<span>'.apply_filters('__loading', esc_html__('Loading', 'cspml')).'</span>';
  1226.                                     $output .= '<span class="wrapper"><span class="cssload-loader"></span></span>';
  1227.                                 $output .= '</div>';
  1228.                                
  1229.                             }
  1230.                            
  1231.                             /**
  1232.                              * == Listings
  1233.                              * Note: When doing an AJAX request, the result returns this element.
  1234.                              * We need this element only when loading the listings for the first time.
  1235.                              * To prevent this, we must detect AJAX requests and hide/show this element accordingly! */
  1236.                              
  1237.                             if(!isset($_POST['ajax_call']) && !isset($_POST['sort_call']))
  1238.                                 $output .= '<div class="cspml_listings_area_'.$map_id.' row" data-map-id="'.$map_id.'" data-paginate-position="'.$paginate_position.'" data-paginate-align="'.$paginate_align.'" data-posts-per-page="'.$posts_per_page.'" data-map-type="'.$map_type.'">';
  1239.                            
  1240.                                 /**
  1241.                                  * Post IDs loaded for the first time */
  1242.                                  
  1243.                                 $output .= '<input type="hidden" name="init_post_ids" id="init_post_ids" value="'.$init_post_ids.'" />';
  1244.                                
  1245.                                 /**
  1246.                                  * Number of posts loaded for the first time */
  1247.                                  
  1248.                                 $output .= '<input type="hidden" name="count_init_post_ids" id="count_init_post_ids" value="'.$count_init_post_ids.'" />';                         
  1249.                                
  1250.                                 /**
  1251.                                  * Post IDs returned after filter request */
  1252.                                  
  1253.                                 $output .= '<input type="hidden" name="post_ids" id="post_ids" value="'.implode(',', $post_ids).'" />';
  1254.                                
  1255.                                 /**
  1256.                                  * The ID of the page that executes the shortcode */
  1257.                                  
  1258.                                 $output .= '<input type="hidden" name="shortcode_page_id" id="shortcode_page_id" value="'.$shortcode_page_id.'" />';
  1259.                                
  1260.                                 /**
  1261.                                  * The name of the page template that contains the shortcode.
  1262.                                  * Useful to hide/show or customize elements by page template. */
  1263.                                  
  1264.                                 $output .= '<input type="hidden" name="page_template" id="page_template" value="'.$page_template.'" />';
  1265.                                
  1266.                                 /**
  1267.                                  * The taxonomy of the page template.
  1268.                                  * Used for archive and taxonomy page templates. */
  1269.                                  
  1270.                                 $output .= '<input type="hidden" name="template_tax_query" id="template_tax_query" value="'.$template_tax_query.'" />';
  1271.                                
  1272.                                 /**
  1273.                                  * The devider to use befor pagination (? or &) */
  1274.                                  
  1275.                                 $output .= '<input type="hidden" name="divider" id="divider" value="'.$divider.'" />';
  1276.                                
  1277.                                 /**
  1278.                                  * Whether to show or hide listings */
  1279.                                  
  1280.                                 $output .= '<input type="hidden" name="show_listings" id="show_listings" value="'.$show_listings.'" />';
  1281.                                
  1282.                                 /**
  1283.                                  * Whether to show or hide listings that doesn't have LatLng coordinates */
  1284.                                  
  1285.                                 $output .= '<input type="hidden" name="optional_latlng" id="optional_latlng" value="'.$optional_latlng.'" />';
  1286.                                
  1287.                                 /**
  1288.                                  * The shortcode page link | @since 2.7 */
  1289.                                  
  1290.                                 $output .= '<input type="hidden" name="shortcode_page_link" id="shortcode_page_link" value="'.$shortcode_page_link.'" />';
  1291.  
  1292.                                 if(!empty($post_ids) && !empty($init_post_ids) && $show_listings == 'true'){
  1293.                                    
  1294.                                     if ( get_query_var('paged') ) $paged = get_query_var('paged');
  1295.                                     elseif ( get_query_var('page') ) $paged = get_query_var('page');
  1296.                                     else $paged = 1;
  1297.                                    
  1298.                                     $total_pages = ceil(count($post_ids)/$posts_per_page);
  1299.                      
  1300.                                     /**
  1301.                                      * Check to see if we are using rewrite rules */
  1302.                                    
  1303.                                     $rewrite = $wp_rewrite->wp_rewrite_rules();
  1304.                                         $format = (!empty($rewrite)) ? 'page/%#%/?paginate=true' : $divider.'page=%#%&paginate=true';
  1305.                                                                        
  1306.                                     $show_all = $this->cspml_get_map_option('show_all');
  1307.                                    
  1308.                                     $show_all_pages = ($show_all == 'false') ? false : true;
  1309.                                    
  1310.                                     /**
  1311.                                      * Get the sort args when a sort request was sent
  1312.                                      * @updated 2.0 [added @data_type] */
  1313.                                      
  1314.                                     if(isset($_POST['sort_call']) && isset($_POST['data_sort']) && isset($_POST['data_order']) && isset($_POST['data_type'])){
  1315.                                        
  1316.                                         $sort_args = $this->cspml_set_posts_order(esc_attr($_POST['data_sort']), esc_attr($_POST['data_order']), esc_attr($_POST['data_type']));
  1317.                                                            
  1318.                                         $_SESSION['cspml_sort_args'][$map_id] = $sort_args;
  1319.                    
  1320.                                     }
  1321.        
  1322.                                     $query_args = array(
  1323.                                         'post_type' => $post_type,
  1324.                                         'post__in' => $post_ids,
  1325.                                         'posts_per_page' => $posts_per_page,
  1326.                                         'post_status' => unserialize(stripslashes($this->cspml_get_map_option('items_status', serialize('publish')))), //$post_status,
  1327.                                         'paged' => $paged,
  1328.                                         'orderby' => $orderby,
  1329.                                         'order' => $order,
  1330.                                     );
  1331.    
  1332.                                     /**
  1333.                                      * Remove the default query order atts and replace them with the new atts ...
  1334.                                      * ... of the listings "sort by" feature */
  1335.                                      
  1336.                                     if(count($sort_args) > 0){
  1337.                                        
  1338.                                         unset($query_args['orderby']);
  1339.                                         unset($query_args['meta_key']);
  1340.                                         unset($query_args['order']);   
  1341.                                        
  1342.                                     }
  1343.                                    
  1344.                                     /**
  1345.                                      * Make the query args and the sort data one array */
  1346.                                      
  1347.                                     $combined_query_args = $query_args + $sort_args;                       
  1348.  
  1349.                                     /**
  1350.                                      * The listings */
  1351.                                      
  1352.                                     $cspml_query_posts = query_posts( $combined_query_args );
  1353.                                    
  1354.                                     /**
  1355.                                      * First, check the map type.
  1356.                                      * Make sure to display locations in the following cases:
  1357.                                      * - When it's a normal map.
  1358.                                      * - When it's a search map but only after sending a filter/search request. Hide them when reset!
  1359.                                      * - When using pagination.
  1360.                                      *
  1361.                                      * @since 2.3 */
  1362.  
  1363.                                     if(
  1364.                                         $map_type == 'normal_map'
  1365.                                         || ($map_type != 'normal_map' && isset($_POST['request_type']) && $_POST['request_type'] != 'reset')
  1366.                                         || isset($_GET['paginate'])
  1367.                                     ){ // @since 2.3
  1368.                                      
  1369.                                         if(have_posts()){
  1370.                                            
  1371.                                             $pagination = paginate_links( array(
  1372.                                                 'base' => !is_wp_error($shortcode_page_link) ? $shortcode_page_link.'%_%' : '%_%', //@add_query_arg('paged','%#%'), // the base URL, including query arg
  1373.                                                 'format' => $format, // this defines the query parameter that will be used, in this case "p"
  1374.                                                 'prev_text' => esc_html__($this->cspml_get_map_option('prev_page_text'), 'cspml'), // text for previous page
  1375.                                                 'next_text' => esc_html__($this->cspml_get_map_option('next_page_text'), 'cspml'), // text for next page
  1376.                                                 'total' => $total_pages, // the total number of pages we have
  1377.                                                 'current' => $paged, // the current page
  1378.                                                 'show_all' => $show_all_pages,
  1379.                                                 'end_size' => 1,
  1380.                                                 'mid_size' => 2,
  1381.                                                 'type' => 'array',
  1382.                                             ));
  1383.                                            
  1384.                                             /**
  1385.                                              * Pagination */
  1386.                                              
  1387.                                             if($paginate_position == 'top' || $paginate_position == 'both')
  1388.                                                 $output .= $this->cspml_pagination($map_id, $pagination, $paginate_align);                             
  1389.                                            
  1390.                                             $i = 1;
  1391.                                            
  1392.                                             $output .= apply_filters('cspml_before_listing_loop', '');
  1393.                                            
  1394.                                             while ( have_posts() ) : the_post();
  1395.                                            
  1396.                                                 $post_id = $post->ID;
  1397.                                                
  1398.                                                 /**
  1399.                                                  * Get lat and lng data */
  1400.                                                  
  1401.                                                 $lat = get_post_meta($post_id, CSPM_LATITUDE_FIELD, true);
  1402.                                                 $lng = get_post_meta($post_id, CSPM_LONGITUDE_FIELD, true);
  1403.                                                
  1404.                                                 $secondary_latlng = get_post_meta($post_id, CSPM_SECONDARY_LAT_LNG_FIELD, true);
  1405.                                            
  1406.                                                 /**
  1407.                                                  * Show items only if lat and lng are not empty.
  1408.                                                  * Note: To display all items even those without Lat&Lng, we use the attribute @optional_latlng. */
  1409.                                                
  1410.                                                 if(!empty($lat) && !empty($lng) || esc_attr($optional_latlng) == 'true'){
  1411.                                                    
  1412.                                                     $marker_img_array = apply_filters('cspml_post_thumb', wp_get_attachment_image_src( get_post_thumbnail_id($post_id), 'cspml-listings-thumbnail' ), $post_id);
  1413.                                                    
  1414.                                                     $marker_img = isset($marker_img_array[0]) ? $marker_img_array[0] : apply_filters('cspml_empty_thumb_img', $this->plugin_url.'img/thumbnail.jpg', str_replace('map', '', $map_id));                                                                         
  1415.    
  1416.                                                     $item_title = $this->cspml_items_title(
  1417.                                                         $post_id,
  1418.                                                         $this->cspml_get_map_option('listings_title'),
  1419.                                                         true
  1420.                                                     );
  1421.                                                    
  1422.                                                     $item_details = $this->cspml_items_details(
  1423.                                                         $post_id,
  1424.                                                         $this->cspml_get_map_option('listings_details')
  1425.                                                     );
  1426.                                                    
  1427.                                                     $click_on_img = $this->cspml_get_map_option('cslf_click_on_img');
  1428.                                                    
  1429.                                                     $the_permalink = ($click_on_img == 'yes') ? $CspmMainMap->cspm_get_permalink($post_id) : '';                                                                           
  1430.                                                                                
  1431.                                                     if($current_view == "list"){
  1432.                                                        
  1433.                                                         $list_view_atts = array(
  1434.                                                             'index' => $i,
  1435.                                                             'map_id' => $map_id,
  1436.                                                             'post_id' => $post_id,
  1437.                                                             'lat' => $lat,
  1438.                                                             'lng' => $lng,
  1439.                                                             'marker_img' => $marker_img,
  1440.                                                             'item_title' => $item_title,
  1441.                                                             'item_details' => apply_filters('cspml_list_item_description', $item_details, $post_id, 'list', esc_attr($list_filter), $map_id, $lat.'_'.$lng),
  1442.                                                             'the_permalink' => $the_permalink,
  1443.                                                         );
  1444.                                                        
  1445.                                                         $output .= $this->cspml_list_view_output($list_view_atts);
  1446.                                                    
  1447.                                                     }else{
  1448.                                                                                                        
  1449.                                                         $grid_view_atts = array(
  1450.                                                             'index' => $i,
  1451.                                                             'map_id' => $map_id,
  1452.                                                             'post_id' => $post_id,
  1453.                                                             'lat' => $lat,
  1454.                                                             'lng' => $lng,
  1455.                                                             'marker_img' => $marker_img,
  1456.                                                             'item_title' => $item_title,
  1457.                                                             'item_details' => apply_filters('cspml_grid_item_description', $item_details, $post_id, 'grid', esc_attr($list_filter), $map_id, $lat.'_'.$lng),
  1458.                                                             'the_permalink' => $the_permalink,
  1459.                                                         );
  1460.                                                          
  1461.                                                         $output .= $this->cspml_grid_view_output($grid_view_atts);
  1462.                                                    
  1463.                                                     }
  1464.                                                    
  1465.                                                     $i++;
  1466.                                                                                    
  1467.                                                 }
  1468.                                                
  1469.                                             endwhile;
  1470.                                            
  1471.                                             $output .= apply_filters('cspml_after_listing_loop', '');
  1472.                                            
  1473.                                             /**
  1474.                                              * Pagination */
  1475.                                              
  1476.                                             if($paginate_position == 'bottom' || $paginate_position == 'both')
  1477.                                                 $output .= $this->cspml_pagination($map_id, $pagination, $paginate_align);                         
  1478.    
  1479.                                         }else{
  1480.                                
  1481.                                             $output .= '<div class="cspml_no_results">'.apply_filters('cspml_no_results_msg', esc_html__('We couldn\'t find any results!', 'cspml')).'</div>';
  1482.                                        
  1483.                                         }
  1484.                                        
  1485.                                     }else{
  1486.                                        
  1487.                                         /**
  1488.                                          * @since 2.3 */
  1489.                                          
  1490.                                         $output .= '<div class="cspml_no_results">'.apply_filters('cspml_start_search_msg', esc_html__('Find your locations', 'cspml')).'</div>';
  1491.                                        
  1492.                                     }
  1493.                                    
  1494.                                     wp_reset_query();
  1495.                                    
  1496.                                 }else $output .= '<div class="cspml_no_results">'.apply_filters('cspml_no_results_msg', esc_html__('We couldn\'t find any results!', 'cspml')).'</div>';
  1497.                        
  1498.                             /**
  1499.                              * Note: When doing an AJAX request, the result returns this element.
  1500.                              * We need this element only when loading the listings for the first time.
  1501.                              * To prevent this, we must detect AJAX requests and hide/show this element accordingly! */
  1502.                              
  1503.                             if(!isset($_POST['ajax_call']) && !isset($_POST['sort_call']))
  1504.                                 $output .= '</div><div class="clear-both"></div>';
  1505.                        
  1506.                         /**
  1507.                          * Note: When doing an AJAX request, the result returns this element.
  1508.                          * We need this element only when loading the listings for the first time.
  1509.                          * To prevent this, we must detect AJAX requests and hide/show this element accordingly! */
  1510.                          
  1511.                         if(!isset($_POST['ajax_call']) && !isset($_POST['sort_call']))
  1512.                             $output .= '</div>';
  1513.                        
  1514.                     /**
  1515.                      * Note: When doing an AJAX request, the result returns this element.
  1516.                      * We need this element only when loading the listings for the first time.
  1517.                      * To prevent this, we must detect AJAX requests and hide/show this element accordingly! */
  1518.                      
  1519.                     if(!isset($_POST['ajax_call']) && !isset($_POST['sort_call']))
  1520.                         $output .= '</div>';
  1521.                    
  1522.                 /**
  1523.                  * Note: When doing an AJAX request, the result returns this element.
  1524.                  * We need this element only when loading the listings for the first time.
  1525.                  * To prevent this, we must detect AJAX requests and hide/show this element accordingly! */
  1526.                  
  1527.                 if(!isset($_POST['ajax_call']) && !isset($_POST['sort_call']))
  1528.                     $output .= '</div><div class="clear-both"></div>';
  1529.            
  1530.             /**
  1531.              * In case we don't want to display the listings. And in case we want to display a fullscreen map with the filter,
  1532.              * we'll need this hidden inputs for the filter query */
  1533.                
  1534.             }else{
  1535.                
  1536.                 $output .= '<div class="cspml_listings_area_'.$map_id.'" data-map-id="'.$map_id.'" data-paginate-position="'.$paginate_position.'" data-paginate-align="'.$paginate_align.'" data-map-type="'.$map_type.'">';                  
  1537.                                
  1538.                     /**
  1539.                      * Post IDs loaded for the first time */
  1540.                      
  1541.                     $output .= '<input type="hidden" name="init_post_ids" id="init_post_ids" value="'.$init_post_ids.'" />';
  1542.                    
  1543.                     /**
  1544.                      * Number of posts loaded for the first time */
  1545.                      
  1546.                     $output .= '<input type="hidden" name="count_init_post_ids" id="count_init_post_ids" value="'.$count_init_post_ids.'" />';                         
  1547.                    
  1548.                     /**
  1549.                      * Post IDs returned after filter request */
  1550.                      
  1551.                     $output .= '<input type="hidden" name="post_ids" id="post_ids" value="'.implode(',', $post_ids).'" />';
  1552.                    
  1553.                     /**
  1554.                      * The ID of the page that executes the shortcode */
  1555.                      
  1556.                     $output .= '<input type="hidden" name="shortcode_page_id" id="shortcode_page_id" value="'.$shortcode_page_id.'" />';
  1557.                    
  1558.                     /**
  1559.                      * The page template name of the page that contains the shortcode.
  1560.                      * Useful to hide/show or customize elements by page template. */
  1561.                      
  1562.                     $output .= '<input type="hidden" name="page_template" id="page_template" value="'.$page_template.'" />';
  1563.                    
  1564.                     /**
  1565.                      * The taxonomy of the page template.
  1566.                      * Used for archive and taxonomy page templates. */
  1567.                      
  1568.                     $output .= '<input type="hidden" name="template_tax_query" id="template_tax_query" value="'.$template_tax_query.'" />';
  1569.                    
  1570.                     /**
  1571.                      * The devider to use befor pagination (? or &) */
  1572.                      
  1573.                     $output .= '<input type="hidden" name="divider" id="divider" value="'.$divider.'" />';
  1574.                    
  1575.                     /**
  1576.                      * Whether to show or hide listings */
  1577.                      
  1578.                     $output .= '<input type="hidden" name="show_listings" id="show_listings" value="'.$show_listings.'" />';
  1579.                                
  1580.                     /**
  1581.                      * Whether to show or hide listings that doesn't have LatLng coordinates */
  1582.                      
  1583.                     $output .= '<input type="hidden" name="optional_latlng" id="optional_latlng" value="'.$optional_latlng.'" />';
  1584.                                
  1585.                     /**
  1586.                      * The shortcode page link | @since 2.7 */
  1587.                      
  1588.                     $output .= '<input type="hidden" name="shortcode_page_link" id="shortcode_page_link" value="'.$shortcode_page_link.'" />';
  1589.  
  1590.                 $output .= '</div>';
  1591.                        
  1592.             }
  1593.                    
  1594.             if(isset($_POST['ajax_call']) || isset($_POST['sort_call']) || isset($_POST['filter_form_call'])) die($output);
  1595.             else return $output;
  1596.            
  1597.         }
  1598.        
  1599.        
  1600.         /**
  1601.          * The list view output
  1602.          *
  1603.          * @since 1.0
  1604.          * @updated 1.1
  1605.          */
  1606.         function cspml_list_view_output($atts = array()){
  1607.            
  1608.             $defaults = array(
  1609.                 'index' => '',
  1610.                 'map_id' => '',
  1611.                 'post_id' => '',
  1612.                 'lat' => '',
  1613.                 'lng' => '',
  1614.                 'marker_img' => '',
  1615.                 'item_title' => '',
  1616.                 'item_details' => '',
  1617.                 'the_permalink' => '',
  1618.             ); 
  1619.            
  1620.             extract(wp_parse_args($atts, $defaults));
  1621.            
  1622.             $this->cspml_show_fire_pinpoint_btn = $this->cspml_get_map_option('show_fire_pinpoint_btn', 'yes');
  1623.             $this->cspml_external_link = $this->cspml_get_map_option('cslf_external_link', 'same_window');
  1624.             $this->cspml_list_items_featured_img = $this->cspml_get_map_option('list_items_featured_img', 'show'); //@since 2.6
  1625.    
  1626.             $output = '';
  1627.            
  1628.             $output .= '<div id="'.$map_id.'_listing_item_'.$post_id.'" data-coords="'.$lat.'_'.$lng.'" data-view="list" data-map-id="'.$map_id.'" data-post-id="'.$post_id.'" class="cspml_item_holder row cspm_animated fadeIn" data-attr-scrollto="'.$this->cspml_scroll_to_list_item.'">';
  1629.                
  1630.                 $output .= '<div id="list_view_holder_'.$map_id.'" class="list_view_holder col-lg-12 col-md-12 col-sm-12 col-xs-12">';             
  1631.                    
  1632.                     /**
  1633.                      * A filter to display custom HTML/code before the item's HTML */
  1634.                    
  1635.                     $output .= apply_filters('cspml_before_listing_item', '', $post_id, $map_id, 'listview', $lat.'_'.$lng, $the_permalink);
  1636.                    
  1637.                     $output .= '<div class="clear-both"></div>';   
  1638.                            
  1639.                     $output .= '<div class="'.apply_filters('cspml_item_holder_class', 'cspml_item', $post_id).' row row-no-margin cspm_border_shadow cspm_border_radius">';
  1640.                        
  1641.                         $show_pinpoint_btn = ($this->cspml_show_fire_pinpoint_btn == 'yes' && !empty($lat) && !empty($lng)) ? 'yes' : 'no';
  1642.                        
  1643.                         if($this->cspml_list_items_featured_img == 'show'){ //@since 2.6
  1644.    
  1645.                             $output .= '<div data-map-id="'.$map_id.'" class="cspml_thumb_container '.apply_filters('cspml_thumb_container_class', 'col-lg-5 col-md-5 col-sm-5 col-xs-12', 'listview').' no-padding">';
  1646.                        
  1647.                                 /**
  1648.                                  * A filter to display custom HTML/code before the item's thumb */
  1649.                                  
  1650.                                 $output .= apply_filters('cspml_before_listing_thumb', '', $post_id, $map_id, 'listview', $lat.'_'.$lng, $the_permalink);
  1651.                                
  1652.                                 $link_overlay_corner_class = $show_pinpoint_btn == 'yes' ? 'cspm_remove_bg_corner' : '';
  1653.                                
  1654.                                 /**
  1655.                                  * Item's permalink */
  1656.                                
  1657.                                 if(!empty($the_permalink)){
  1658.    
  1659.                                     $target = ($this->cspml_external_link == "same_window") ? '' : ' target="_blank"';
  1660.                                     $link_class = ($this->cspml_external_link == 'popup') ? 'class="cspml_popup_single_post"' : ''; //@since 2.5
  1661.                                    
  1662.                                     $only_item_title = $this->cspml_items_title(
  1663.                                         $post_id,
  1664.                                         $this->cspml_get_map_option('listings_title'),
  1665.                                         false
  1666.                                     ); //@since 2.5
  1667.                                                                                        
  1668.                                     $output .= '<a href="'.$the_permalink.'" title="'.$only_item_title.'"'.$target.' '.$link_class.'><div class="cspml_item_link_overlay '.$link_overlay_corner_class.' cspm_animated fadeIn">';
  1669.                                    
  1670.                                         $output .= '<img alt="" src="'.apply_filters('cspml_item_link_img', $this->plugin_url.'img/link.png', str_replace('map', '', $map_id)).'" title="'.apply_filters('__visit', esc_html__('Visit', 'cspml')).'" class="cspml_item_link" />';
  1671.                                    
  1672.                                     $output .= '</div></a>';
  1673.                                
  1674.                                 }
  1675.    
  1676.                                 /**
  1677.                                  * Item's thumb */
  1678.                                
  1679.                                 $output .= '<img alt="" src="'.$marker_img.'" class="thumb img-responsive" />';
  1680.                                
  1681.                                 /**
  1682.                                  * Item's Pinpoint */
  1683.                                  
  1684.                                 if($show_pinpoint_btn == 'yes'){
  1685.                                      
  1686.                                     $output .= '<div class="cspml_item_pinpoint_overlay cspml_fire_pinpoint" data-map-id="'.$map_id.'" data-coords="'.$lat.'_'.$lng.'" data-post-id="'.$post_id.'">';
  1687.                                        
  1688.                                         $output .= '<img alt="" src="'.apply_filters('cspml_item_pinpoint_img', $this->plugin_url.'img/pinpoint.png', str_replace('map', '', $map_id)).'" title="'.apply_filters('__show_position', esc_html__('Show position on the map', 'cspml')).'" class="cspml_item_pinpoint" />';
  1689.                                        
  1690.                                         $output .= '<div class="cspml_item_pinpoint_triangle"></div>';
  1691.                                        
  1692.                                     $output .= '</div>';
  1693.                                
  1694.                                 }
  1695.                                
  1696.                                 /**
  1697.                                  * A filter to display custom HTML/code after the item's thumb */
  1698.                                  
  1699.                                 $output .= apply_filters('cspml_after_listing_thumb', '', $post_id, $map_id, 'listview', $lat.'_'.$lng, $the_permalink);
  1700.                                
  1701.                             $output .= '</div>';
  1702.                        
  1703.                         }
  1704.                        
  1705.                         /**
  1706.                          * Title & Content */
  1707.                        
  1708.                         $content_row_classes = ($this->cspml_list_items_featured_img == 'show')
  1709.                             ? 'col-lg-7 col-md-7 col-sm-7 col-xs-12'
  1710.                             : 'col-lg-12 col-md-12 col-sm-12 col-xs-12'; //@since 2.6
  1711.                                
  1712.                         $output .= '<div data-map-id="'.$map_id.'" class="'.apply_filters('cspml_details_container_class', 'cspml_details_container '.$content_row_classes, 'listview').'" data-view="list">'; 
  1713.                                                            
  1714.                             /**
  1715.                              * Item's Pinpoint
  1716.                              * @since 2.6 */
  1717.                    
  1718.                             if($this->cspml_list_items_featured_img == 'hide' && $show_pinpoint_btn == 'yes'){
  1719.                                      
  1720.                                 $output .= '<div class="cspml_item_pinpoint_overlay cspml_fire_pinpoint" data-map-id="'.$map_id.'" data-coords="'.$lat.'_'.$lng.'" data-post-id="'.$post_id.'">';
  1721.                                    
  1722.                                     $output .= '<img alt="" src="'.apply_filters('cspml_item_pinpoint_img', $this->plugin_url.'img/pinpoint.png', str_replace('map', '', $map_id)).'" title="'.apply_filters('__show_position', esc_html__('Show position on the map', 'cspml')).'" class="cspml_item_pinpoint" />';
  1723.                                    
  1724.                                     $output .= '<div class="cspml_item_pinpoint_triangle"></div>';
  1725.                                    
  1726.                                 $output .= '</div>';
  1727.                                    
  1728.                             }
  1729.                                            
  1730.                             /**
  1731.                              * A filter to display custom HTML/code before the item's title container */
  1732.                              
  1733.                             $output .= apply_filters('cspml_before_title_container', '', $post_id, $map_id, 'listview', $lat.'_'.$lng, $the_permalink);
  1734.  
  1735.                             $output .= '<div data-map-id="'.$map_id.'" class="cspml_details_title '.apply_filters('cspml_details_title_extra_class', '').' col-lg-12 col-xs-12 col-sm-12 col-md-12">';
  1736.                    
  1737.                                 /**
  1738.                                  * A filter to display custom HTML/code before the item's title */
  1739.                                  
  1740.                                 $output .= apply_filters('cspml_before_listing_title', '', $post_id, $map_id, 'listview', $lat.'_'.$lng, $the_permalink);
  1741.                                
  1742.                                 /**
  1743.                                  * Item's title */
  1744.                                  
  1745.                                 $output .= stripslashes_deep($item_title);
  1746.                    
  1747.                                 /**
  1748.                                  * A filter to display custom HTML/code before the item's title */
  1749.                                  
  1750.                                 $output .= apply_filters('cspml_after_listing_title', '', $post_id, $map_id, 'listview', $lat.'_'.$lng, $the_permalink);
  1751.                                
  1752.                             $output .= '</div>';
  1753.                            
  1754.                             /**
  1755.                              * Item's excerpt/content */
  1756.                              
  1757.                             $output .= '<div class="cspml_details_content '.apply_filters('cspml_details_content_extra_class', '').' col-lg-12 col-xs-12 col-sm-12 col-md-12">';
  1758.                                
  1759.                                 $output .= '<hr class="no-margin-top margin-bottom-15" />';
  1760.                                
  1761.                                 /**
  1762.                                  * A filter to display custom HTML/code before the item's title */
  1763.                                  
  1764.                                 $output .= apply_filters('cspml_before_listing_excerpt', '', $post_id, $map_id, 'listview', $lat.'_'.$lng, $the_permalink);
  1765.                                
  1766.                                 /**
  1767.                                  * Item's excerpt/content */
  1768.                                  
  1769.                                 $output .= stripslashes_deep($item_details);
  1770.                                
  1771.                                 /**
  1772.                                  * A filter to display custom HTML/code after the item's title */
  1773.                                  
  1774.                                 $output .= apply_filters('cspml_after_listing_excerpt', '', $post_id, $map_id, 'listview', $lat.'_'.$lng, $the_permalink);
  1775.                                
  1776.                             $output .= '</div>';   
  1777.                    
  1778.                             /**
  1779.                              * A filter to display custom HTML/code after the item's excerpt/content container */
  1780.                              
  1781.                             $output .= apply_filters('cspml_after_excerpt_container', '', $post_id, $map_id, 'listview', $lat.'_'.$lng, $the_permalink);
  1782.                            
  1783.                         $output .= '</div>';
  1784.                            
  1785.                         $output .= '<div class="clear-both"></div>';
  1786.                            
  1787.                     $output .= '</div>';
  1788.                
  1789.                     $output .= '<div class="clear-both"></div>';
  1790.  
  1791.                     /**
  1792.                      * A filter to display custom HTML/code after the item's HTML */
  1793.                                                
  1794.                     $output .= apply_filters('cspml_after_listing_item', '', $post_id, $map_id, 'listview', $lat.'_'.$lng, $the_permalink);
  1795.            
  1796.                 $output .= '</div>';               
  1797.    
  1798.             $output .= '</div>';                       
  1799.            
  1800.             return apply_filters('cspml_list_view_item', $output, $post_id, $map_id, $lat.'_'.$lng, $the_permalink);                       
  1801.                                                                
  1802.         }
  1803.        
  1804.        
  1805.         /**
  1806.          * The grid view output
  1807.          *
  1808.          * @since 1.0
  1809.          * @updated 1.1
  1810.          */
  1811.         function cspml_grid_view_output($atts = array()){
  1812.            
  1813.             $defaults = array(
  1814.                 'index' => '',
  1815.                 'map_id' => '',
  1816.                 'post_id' => '',
  1817.                 'lat' => '',
  1818.                 'lng' => '',
  1819.                 'marker_img' => '',
  1820.                 'item_title' => '',
  1821.                 'item_details' => '',
  1822.                 'the_permalink' => '',
  1823.             ); 
  1824.            
  1825.             extract(wp_parse_args($atts, $defaults));
  1826.            
  1827.             $this->cspml_show_fire_pinpoint_btn = $this->cspml_get_map_option('show_fire_pinpoint_btn', 'yes');
  1828.             $this->cspml_external_link = $this->cspml_get_map_option('cslf_external_link', 'same_window');
  1829.             $this->cspml_grid_cols = $this->cspml_get_map_option('grid_cols', 'cols3');
  1830.             $this->cspml_list_items_featured_img = $this->cspml_get_map_option('list_items_featured_img', 'show'); //@since 2.6
  1831.    
  1832.             $grid_cols = $this->cspml_grid_cols;
  1833.            
  1834.             /**
  1835.              * @cols1, displays one item per row */
  1836.  
  1837.             if($grid_cols == 'cols1'){
  1838.                
  1839.                 $grid_classes = ' col-lg-12 col-md-12 col-sm-12 col-xs-12';
  1840.            
  1841.             /**
  1842.              * @cols2, displays two items per row */
  1843.              
  1844.             }elseif($grid_cols == 'cols2'){
  1845.                
  1846.                 $grid_classes = ' col-lg-6 col-md-6 col-sm-6 col-xs-12';
  1847.            
  1848.             /**
  1849.              * @cols4, displays four items per row */
  1850.              
  1851.             }elseif($grid_cols == 'cols4') {
  1852.                
  1853.                 $grid_classes = ' col-lg-3 col-md-3 col-sm-6 col-xs-12';
  1854.            
  1855.             /**
  1856.              * @cols6, displays six items per row */
  1857.              
  1858.             }elseif($grid_cols == 'cols6') {
  1859.                
  1860.                 $grid_classes = ' col-lg-2 col-md-2 col-sm-6 col-xs-12';
  1861.            
  1862.             /**
  1863.              * @cols3, displays three items per row */
  1864.              
  1865.             }else $grid_classes = ' col-lg-4 col-md-4 col-sm-6 col-xs-12';
  1866.            
  1867.             /**
  1868.              * A filter to change the grid classes */
  1869.              
  1870.             $grid_classes = apply_filters('cspml_listing_grid_classes', $grid_classes);
  1871.            
  1872.             /**
  1873.              * Displaying items */
  1874.                
  1875.             $output = '';
  1876.            
  1877.             $output .= '<div id="'.$map_id.'_listing_item_'.$post_id.'" data-coords="'.$lat.'_'.$lng.'" data-view="grid" data-map-id="'.$map_id.'" data-post-id="'.$post_id.'" class="cspml_item_holder '.$grid_classes.' cspm_animated fadeIn" data-attr-scrollto="'.$this->cspml_scroll_to_list_item.'">';
  1878.                
  1879.                 $output .= '<div id="list_view_holder_'.$map_id.'" class="list_view_holder">';             
  1880.                    
  1881.                     /**
  1882.                      * A filter to display custom HTML/code before the item's HTML */
  1883.                      
  1884.                     $output .= apply_filters('cspml_before_listing_item', '', $post_id, $map_id, 'gridview', $lat.'_'.$lng, $the_permalink);
  1885.                    
  1886.                     $output .= '<div class="clear-both"></div>';   
  1887.                            
  1888.                     $output .= '<div class="'.apply_filters('cspml_item_holder_class', 'cspml_item', $post_id).' col-lg-12 col-xs-12 col-sm-12 col-md-12 cspm_border_shadow cspm_border_radius">';
  1889.                                
  1890.                         $show_pinpoint_btn = ($this->cspml_show_fire_pinpoint_btn == 'yes' && !empty($lat) && !empty($lng)) ? 'yes' : 'no';
  1891.                        
  1892.                         if($this->cspml_list_items_featured_img == 'show'){ //@since 2.6
  1893.    
  1894.                             $output .= '<div data-map-id="'.$map_id.'" class="cspml_thumb_container '.apply_filters('cspml_thumb_container_class', 'col-lg-12 col-xs-12 col-sm-12 col-md-12', 'gridview').' no-padding">';
  1895.                        
  1896.                                 /**
  1897.                                  * A filter to display custom HTML/code before the item's thumb */
  1898.                                  
  1899.                                 $output .= apply_filters('cspml_before_listing_thumb', '', $post_id, $map_id, 'gridview', $lat.'_'.$lng, $the_permalink);
  1900.                                
  1901.                                 $link_overlay_corner_class = $show_pinpoint_btn == 'yes' ? 'cspm_remove_bg_corner' : '';
  1902.                                
  1903.                                 /**
  1904.                                  * Item's permalink */
  1905.                                
  1906.                                 if(!empty($the_permalink)){                                
  1907.                                    
  1908.                                     $target = ($this->cspml_external_link == "same_window") ? '' : ' target="_blank"';
  1909.                                     $link_class = ($this->cspml_external_link == 'popup') ? 'class="cspml_popup_single_post"' : ''; //@since 2.5
  1910.                                    
  1911.                                     $only_item_title = $this->cspml_items_title(
  1912.                                         $post_id,
  1913.                                         $this->cspml_get_map_option('listings_title'),
  1914.                                         false
  1915.                                     ); //@since 2.5
  1916.                                                                                        
  1917.                                     $output .= '<a href="'.$the_permalink.'" title="'.$only_item_title.'"'.$target.' '.$link_class.'><div class="cspml_item_link_overlay '.$link_overlay_corner_class.' cspm_animated fadeIn">';
  1918.                                    
  1919.                                         $output .= '<img alt="" src="'.apply_filters('cspml_item_link_img', $this->plugin_url.'img/link.png', str_replace('map', '', $map_id)).'" title="'.apply_filters('__visit', esc_html__('Visit', 'cspml')).'" class="cspml_item_link" />';
  1920.                                    
  1921.                                     $output .= '</div></a>';
  1922.                                    
  1923.                                 }
  1924.    
  1925.                                 /**
  1926.                                  * Item's thumb */
  1927.                                  
  1928.                                 $output .= '<img alt="" src="'.$marker_img.'" class="thumb img-responsive" />';
  1929.                                
  1930.                                 /**
  1931.                                  * Item's Pinpoint */
  1932.                                  
  1933.                                 if($show_pinpoint_btn == 'yes'){
  1934.                                      
  1935.                                     $output .= '<div class="cspml_item_pinpoint_overlay cspml_fire_pinpoint" data-map-id="'.$map_id.'" data-coords="'.$lat.'_'.$lng.'" data-post-id="'.$post_id.'">';
  1936.                                        
  1937.                                         $output .= '<img alt="" src="'.apply_filters('cspml_item_pinpoint_img', $this->plugin_url.'img/pinpoint.png', str_replace('map', '', $map_id)).'" title="'.apply_filters('__show_position', esc_html__('Show position on the map', 'cspml')).'" class="cspml_item_pinpoint" />';
  1938.                                        
  1939.                                         $output .= '<div class="cspml_item_pinpoint_triangle"></div>';
  1940.                                        
  1941.                                     $output .= '</div>';
  1942.                                
  1943.                                 }
  1944.                                
  1945.                                 /**
  1946.                                  * A filter to display custom HTML/code after the item's thumb */
  1947.                                  
  1948.                                 $output .= apply_filters('cspml_after_listing_thumb', '', $post_id, $map_id, 'gridview', $lat.'_'.$lng, $the_permalink);
  1949.                                
  1950.                             $output .= '</div>';
  1951.                            
  1952.                         }
  1953.                        
  1954.                         /**
  1955.                          * Title & Content */
  1956.                                                        
  1957.                         $output .= '<div data-map-id="'.$map_id.'" class="'.apply_filters('cspml_details_container_class', 'cspml_details_container col-lg-12 col-xs-12 col-sm-12 col-md-12', 'gridview').'" data-view="grid">';   
  1958.                                                            
  1959.                             /**
  1960.                              * Item's Pinpoint
  1961.                              * @since 2.6 */
  1962.                    
  1963.                             if($this->cspml_list_items_featured_img == 'hide' && $show_pinpoint_btn == 'yes'){
  1964.                                      
  1965.                                 $output .= '<div class="cspml_item_pinpoint_overlay cspml_fire_pinpoint" data-map-id="'.$map_id.'" data-coords="'.$lat.'_'.$lng.'" data-post-id="'.$post_id.'">';
  1966.                                    
  1967.                                     $output .= '<img alt="" src="'.apply_filters('cspml_item_pinpoint_img', $this->plugin_url.'img/pinpoint.png', str_replace('map', '', $map_id)).'" title="'.apply_filters('__show_position', esc_html__('Show position on the map', 'cspml')).'" class="cspml_item_pinpoint" />';
  1968.                                    
  1969.                                     $output .= '<div class="cspml_item_pinpoint_triangle"></div>';
  1970.                                    
  1971.                                 $output .= '</div>';
  1972.                                                                
  1973.                             }
  1974.                                            
  1975.                             /**
  1976.                              * A filter to display custom HTML/code before the item's title container */
  1977.                              
  1978.                             $output .= apply_filters('cspml_before_title_container', '', $post_id, $map_id, 'gridview', $lat.'_'.$lng, $the_permalink);
  1979.                            
  1980.                             $output .= '<div data-map-id="'.$map_id.'" class="cspml_details_title '.apply_filters('cspml_details_title_extra_class', '').' col-lg-12 col-xs-12 col-sm-12 col-md-12">';
  1981.                    
  1982.                                 /**
  1983.                                  * A filter to display custom HTML/code before the item's title */
  1984.                                  
  1985.                                 $output .= apply_filters('cspml_before_listing_title', '', $post_id, $map_id, 'gridview', $lat.'_'.$lng, $the_permalink);
  1986.                                
  1987.                                 /**
  1988.                                  * Item's title */
  1989.                                  
  1990.                                 $output .= stripslashes_deep($item_title);
  1991.                    
  1992.                                 /**
  1993.                                  * A filter to display custom HTML/code after the item's title */
  1994.                                  
  1995.                                 $output .= apply_filters('cspml_after_listing_title', '', $post_id, $map_id, 'gridview', $lat.'_'.$lng, $the_permalink);
  1996.                            
  1997.                             $output .= '</div>';
  1998.                            
  1999.                             $output .= '<div class="cspml_details_content '.apply_filters('cspml_details_content_extra_class', 'grid').' col-lg-12 col-xs-12 col-sm-12 col-md-12">';
  2000.                                
  2001.                                 $output .= '<hr class="no-margin-top margin-bottom-15" />';
  2002.                                
  2003.                                 /**
  2004.                                  * A filter to display custom HTML/code before the item's title */
  2005.                                  
  2006.                                 $output .= apply_filters('cspml_before_listing_content', '', $post_id, $map_id, 'gridview', $lat.'_'.$lng, $the_permalink);
  2007.                                
  2008.                                 /**
  2009.                                  * Item's excerpt/content */
  2010.                                  
  2011.                                 $output .= stripslashes_deep($item_details);
  2012.                    
  2013.                                 /**
  2014.                                  * A filter to display custom HTML/code after the item's title */
  2015.                                  
  2016.                                 $output .= apply_filters('cspml_after_listing_excerpt', '', $post_id, $map_id, 'gridview', $lat.'_'.$lng, $the_permalink);
  2017.                            
  2018.                             $output .= '</div>';                                           
  2019.                    
  2020.                             /**
  2021.                              * A filter to display custom HTML/code after the item's excerpt/content container */
  2022.                              
  2023.                             $output .= apply_filters('cspml_after_excerpt_container', '', $post_id, $map_id, 'gridview', $lat.'_'.$lng, $the_permalink);
  2024.                            
  2025.                         $output .= '</div>';
  2026.                        
  2027.                         $output .= '<div class="clear-both"></div>';
  2028.                        
  2029.                     $output .= '</div>';
  2030.                    
  2031.                     /**
  2032.                      * A filter to display custom HTML/code after the item's HTML */
  2033.                      
  2034.                     $output .= apply_filters('cspml_after_listing_item', '', $post_id, $map_id, 'gridview', $lat.'_'.$lng, $the_permalink);
  2035.                
  2036.                 $output .= '</div>';
  2037.                                    
  2038.             $output .= '</div>';
  2039.            
  2040.             return apply_filters('cspml_grid_view_item', $output, $post_id, $map_id, $lat.'_'.$lng, $the_permalink);                       
  2041.                                                                
  2042.         }
  2043.        
  2044.        
  2045.         /**
  2046.          * Listings pagination
  2047.          *
  2048.          * @since 1.0
  2049.          */
  2050.         function cspml_pagination($map_id, $pagination = array(), $paginate_align){
  2051.            
  2052.             if(count($pagination) > 0){
  2053.                
  2054.                 $output = '<div class="clear-both"></div>';
  2055.                
  2056.                 $output .= '<div class="row no-margin">';
  2057.                    
  2058.                     $output .= '<div id="'.$map_id.'" class="cspml_pagination_'.$map_id.' col-lg-12 col-md-12 col-sm-12 col-xs-12" style="text-align:'.$paginate_align.'">';
  2059.                        
  2060.                         $output .= '<ul>';
  2061.                        
  2062.                             $output .= '<div class="cspml_transparent_layer_'.$map_id.'"></div>';
  2063.                        
  2064.                             foreach($pagination as $pagination_link)
  2065.                                 $output .= '<li data-map-id="'.$map_id.'">'.$pagination_link.'</li>';                      
  2066.                            
  2067.                             $output .= '<div class="clear-both"></div>';
  2068.                            
  2069.                         $output .= '</ul>';
  2070.                        
  2071.                     $output .= '</div>';
  2072.                
  2073.                 $output .= '</div>';
  2074.                
  2075.                 $output .= '<div class="clear-both"></div>';
  2076.                
  2077.             }else $output = '';
  2078.                    
  2079.             return $output;
  2080.            
  2081.         }
  2082.        
  2083.        
  2084.         /**
  2085.          * This will display an option on top of the listings.
  2086.          * The option bar will contain the following items:
  2087.          * - Widget that displays the number of listings
  2088.          * - A list that allow sorting listings
  2089.          * - Two buttons to switch between different views (List/Grid)
  2090.          * - Open/Close Faceted search button
  2091.          *
  2092.          * @since 1.0
  2093.          * @updated 2.3
  2094.          * @updated 2.6
  2095.          */
  2096.         function cspml_options_bar($atts = array()){
  2097.  
  2098.             /**
  2099.              * Function atts */
  2100.              
  2101.             extract( wp_parse_args( $atts, array(
  2102.                 'map_id' => '',    
  2103.                 'nbr_items' => 0,
  2104.                 'page_id' => '',
  2105.                 'current_view' => '',
  2106.                 'list_filter' => '',
  2107.                 'filter_position' => '',
  2108.             )));   
  2109.  
  2110.             /**
  2111.              * Options Bar */
  2112.            
  2113.             $output = '';
  2114.                    
  2115.             /**
  2116.              * A filter that allows adding extra HTML before the options bar */
  2117.              
  2118.             $output .= apply_filters('cspml_before_options_bar', '');
  2119.  
  2120.             /**
  2121.              * Options Bar Container */
  2122.            
  2123.             $show_posts_count = $this->cspml_show_posts_count;                     
  2124.             $show_view_options = $this->cspml_show_view_options;
  2125.             $show_sort_option = $this->cspml_show_sort_option;
  2126.  
  2127.             $output .= '<div class="cspml_options_bar_'.$map_id.' row">';                  
  2128.                
  2129.                 $pull_fs_direction = ($filter_position == 'left') ? 'pull-right' : '';
  2130.                
  2131.                 if($list_filter == 'yes'){
  2132.                    
  2133.                     if($this->cspml_list_layout != 'vertical' && $this->cspml_map_cols >= 6){ //@since 2.6
  2134.                         $options_bar_cols_classes = 'col-lg-12 col-md-12 col-sm-12 col-xs-12'; //@since 2.6
  2135.                     }else $options_bar_cols_classes = 'col-lg-9 col-md-9 col-sm-12 col-xs-12'; //@since 2.6
  2136.                    
  2137.                     $output .= '<div class="'.$pull_fs_direction.' '.$options_bar_cols_classes.'">';
  2138.                    
  2139.                 }
  2140.                    
  2141.                     if($list_filter == 'yes')
  2142.                         $output .= '<div class="row">';
  2143.                    
  2144.                         /**
  2145.                          * Number of listings */
  2146.                            
  2147.                         $post_count_classes = ($show_view_options == 'yes') ? 'col-lg-4 col-md-4 col-sm-10 col-xs-8' : 'col-lg-4 col-md-4 col-sm-12 col-xs-12';
  2148.                        
  2149.                         $output .= '<div class="cspml_nbr_items_container '.apply_filters('cspml_post_count_class', $post_count_classes).'">';             
  2150.                        
  2151.                             if($show_posts_count == "yes")
  2152.                                 $output .= '<div class="cspml_nbr_items cspm_border_radius cspm_border_shadow text-center">'.$this->cspml_posts_count_clause($nbr_items, $map_id).'</div>';                                
  2153.                    
  2154.                         $output .= '</div>';
  2155.                                                                
  2156.                         /**
  2157.                          * View options */                                                             
  2158.                        
  2159.                         if($show_view_options == 'yes'){
  2160.                            
  2161.                             $output .= '<div class="cspml_view_options_container '.apply_filters('cspml_view_options_class', 'col-lg-2 col-md-2 col-sm-2 col-xs-4').' pull-right">';
  2162.                                
  2163.                                 $output .= '<div class="cspml_transparent_layer_'.$map_id.'"></div>';
  2164.                                
  2165.                                 /**
  2166.                                  * A filter that allows adding extra HTML before the view options */
  2167.                                  
  2168.                                 $output .= apply_filters('cspml_before_view_options', '', $page_id);
  2169.                                
  2170.                                 /**
  2171.                                  * Switch between the grid view & the list view */
  2172.                                
  2173.                                 $next_view = ($current_view == 'grid') ? 'list' : 'grid';
  2174.                                
  2175.                                 $output .= '<div class="'.$current_view.'_view view_option '.apply_filters('cspml_view_option_class', 'col-lg-12 col-sm-12 col-xs-12 col-md-12').' cspm_border_right_radius cspm_border_shadow" data-map-id="'.$map_id.'">';
  2176.                                    
  2177.                                     $output .= '<a class="cspml_view_icon push" data-map-id="'.$map_id.'" data-current-view="'.$current_view.'" data-next-view="'.$next_view.'" title="'.sprintf(apply_filters('__swicth_view', esc_html__('Switch to %s view', 'cspml')), $next_view).'">';
  2178.                                    
  2179.                                         $output .= '<img src="'.apply_filters('cspml_switch_view_img', $this->plugin_url.'img/'.$next_view.'.png', str_replace('map', '', $map_id), $current_view).'" style="height:15px; width:auto;" />';
  2180.                                    
  2181.                                     $output .= '</a>';
  2182.                                    
  2183.                                 $output .= '</div>';       
  2184.                                
  2185.                                 /**
  2186.                                  * A filter that allows adding extra HTML after the view options */
  2187.                                                                
  2188.                                 $output .= apply_filters('cspml_after_view_options', '', $page_id);
  2189.                                
  2190.                             $output .= '</div>';
  2191.                        
  2192.                         }
  2193.                        
  2194.                         if($show_posts_count == 'yes')
  2195.                             $output .= '<div class="clear-both visible-sm visible-xs margin-bottom-10"></div>';
  2196.                        
  2197.                         /**
  2198.                          * Sort by container */
  2199.  
  2200.                         if($show_posts_count == 'yes'){
  2201.                            
  2202.                             $sort_list_classes = 'col-lg-6 col-md-6 col-sm-12 col-xs-12 pull-right';
  2203.                            
  2204.                         }else{
  2205.                            
  2206.                             if($show_view_options == 'yes')
  2207.                                 $sort_list_classes = 'col-lg-6 col-md-6 col-sm-10 col-xs-8 pull-right';
  2208.                             else $sort_list_classes = 'col-lg-6 col-md-6 col-sm-12 col-xs-12 pull-right';
  2209.                            
  2210.                         }
  2211.                        
  2212.                         $output .= '<div class="'.apply_filters('cspml_sort_and_view_options_class', $sort_list_classes).'">';                 
  2213.                            
  2214.                             $output .= '<div class="cspml_transparent_layer_'.$map_id.'"></div>';
  2215.                            
  2216.                             /**
  2217.                              * Drop-down sort list */
  2218.                                    
  2219.                             if($show_sort_option == 'yes')
  2220.                                 $output .= $this->cspml_build_sort_options_list($map_id);
  2221.  
  2222.                         $output .= '</div>';
  2223.                        
  2224.                         $output .= '<div class="clear-both"></div>';
  2225.                    
  2226.                     if($list_filter == 'yes')
  2227.                         $output .= '</div>';
  2228.                    
  2229.                 if($list_filter == 'yes')
  2230.                     $output .= '</div>';
  2231.                        
  2232.                 /**
  2233.                  * Open/Close button for Faceted Search container */                   
  2234.                  
  2235.                 if($list_filter == 'yes'){
  2236.                    
  2237.                     if($this->cspml_list_layout != 'vertical' && $this->cspml_map_cols >= 6){ //@since 2.6
  2238.                         $toggle_filter_cols_classes = 'col-lg-12 col-md-12 col-sm-12 col-xs-12 margin-top-10'; //@since 2.6
  2239.                     }else $toggle_filter_cols_classes = 'col-lg-3 col-md-3 col-sm-12 col-xs-12'; //@since 2.6
  2240.  
  2241.                     $output .= '<div class="'.$toggle_filter_cols_classes.'">';
  2242.                        
  2243.                         $output .= '<div class="visible-sm visible-xs margin-top-10"></div>';
  2244.                        
  2245.                         /**
  2246.                          * Faceted Search Open/Close button */                 
  2247.                        
  2248.                         $output .= '<div class="cspml_fs_title cspm_border_radius cspm_border_shadow" data-map-id="'.$map_id.'">';
  2249.                        
  2250.                             $output .= '<img src="'.apply_filters('cspml_refine_img', $this->plugin_url.'img/refine.png', str_replace('map', '', $map_id)).'" title="'.apply_filters('__refine_search', esc_html__('Refine Search', 'cspml')).'" style="width:15px; height:auto;" />';
  2251.                        
  2252.                             $output .= apply_filters('__refine_search', esc_html__('Refine Search', 'cspml'));
  2253.                            
  2254.                             $output .= '<span class="cspml_close_fs cspm_border_right_radius cspm_border_shadow" data-map-id="'.$map_id.'">';
  2255.                                                                                        
  2256.                                 $output .= '<img src="'.apply_filters('cspml_toggle_filter_img', $this->plugin_url.'img/close.png', str_replace('map', '', $map_id)).'" title="'.apply_filters('__close', esc_html__('Close', 'cspml')).'" style="width:15px; height:auto;" />';
  2257.                            
  2258.                             $output .= '</span>';
  2259.                            
  2260.                         $output .= '</div>';
  2261.                    
  2262.                     $output .= '</div>';
  2263.  
  2264.                 }
  2265.                
  2266.                 $output .= '<div class="clear-both"></div>';
  2267.                    
  2268.             $output .= '</div>';
  2269.                            
  2270.             /**
  2271.              * A filter that allows adding extra HTML after the options bar */
  2272.                          
  2273.             $output .= apply_filters('cspml_after_options_bar', '');
  2274.                
  2275.             return $output;
  2276.                
  2277.         }
  2278.        
  2279.         /**
  2280.          * Build the sort data HTML list
  2281.          *
  2282.          * @since 1.0
  2283.          */
  2284.         function cspml_build_sort_options_list($map_id){
  2285.            
  2286.             $output = '';
  2287.            
  2288.             $output .= '<div data-map-id="'.$map_id.'" class="cspml_sort_list_container cspm_border_radius cspm_border_shadow">';//.$this->cspml_sort_option_clause.
  2289.            
  2290.                 $output .= '<img src="'.apply_filters('cspml_sort_img', $this->plugin_url.'img/sort.png', str_replace('map', '', $map_id)).'" title="'.apply_filters('__sort_listings', esc_html__('Sort Listings', 'cspml')).'" style="height:15px; width:auto;" />';
  2291.                
  2292.                 $output .= '<span class="cspml_sort_val">'.apply_filters('__default', esc_html__('Default', 'cspml')).'</span>';
  2293.                
  2294.                 $output .= '<span class="cspml_sort_btn cspm_border_right_radius cspm_border_shadow">';
  2295.                    
  2296.                     $output .= '<img src="'.apply_filters('cspml_sort_arrow_down_img', $this->plugin_url.'img/arrow-down.png', str_replace('map', '', $map_id)).'" title="'.apply_filters('__sort_listings', esc_html__('Sort Listings', 'cspml')).'" style="height:15px; width:auto;" />';
  2297.                
  2298.                 $output .= '</span>';
  2299.                
  2300.             $output .= '</div>';
  2301.            
  2302.             $output .= '<ul data-map-id="'.$map_id.'" class="cspml_sort_list cspm_border_radius cspm_border_shadow">';
  2303.                
  2304.                 /**
  2305.                  * Display the sort list */
  2306.                  
  2307.                 $output .= $this->cspml_build_sort_data($map_id, 'list', NULL);
  2308.                
  2309.             $output .= '</ul>';
  2310.            
  2311.             return $output;
  2312.            
  2313.         }
  2314.        
  2315.        
  2316.         /**
  2317.          * Create the list of the sort data (Default data)
  2318.          *
  2319.          * @since 1.0
  2320.          * @updated 2.0 [added @data_type]
  2321.          */
  2322.         function cspml_build_sort_data($map_id, $type, $post_id = NULL){
  2323.            
  2324.             /**
  2325.              * Usage Example:
  2326.              *
  2327.              * $sort_options_array = array(
  2328.                     'default|Default|init' => 'Default',
  2329.                     'data-date-created|Date (Newest first)|desc' => 'Date (Newest first)',
  2330.                     'data-date-created|Date (Oldest first)|asc' => 'Date (Oldest first)',
  2331.                     'data-title|Title A to Z|asc' => 'Title A to Z',
  2332.                     'data-title|Title Z to A|desc' => 'Title Z to A'
  2333.                ); */
  2334.    
  2335.             $output = '';
  2336.  
  2337.             foreach($this->cspml_sort_options_order as $display_order){
  2338.                
  2339.                 if($display_order == 'default'){
  2340.                        
  2341.                     /**
  2342.                      * The default sort by data */
  2343.        
  2344.                     foreach($this->cspml_sort_options as $sort_option){
  2345.                    
  2346.                         $explode_sort_option = explode("|", $sort_option);
  2347.                        
  2348.                         if(isset($explode_sort_option[0]) && isset($explode_sort_option[1]) && isset($explode_sort_option[2])){
  2349.                            
  2350.                             /**
  2351.                              * Build the list */
  2352.                              
  2353.                             if($type == 'list'){
  2354.                                
  2355.                                 $output .= '<li class="sort push" data-map-id="'.$map_id.'" ';
  2356.                                
  2357.                                     $output .= 'data-sort="'.$explode_sort_option[0].'"';
  2358.                                
  2359.                                     if($explode_sort_option[2] != 'init')
  2360.                                         $output .= ' data-order="'.$explode_sort_option[2].'"';
  2361.                                        
  2362.                                     else $output .= ' data-order="desc"';
  2363.                                    
  2364.                                     $output .= 'data-type=""'; //@since 2.0
  2365.                                            
  2366.                                 $output .= '>'.esc_html__($explode_sort_option[1], 'cspml').'</li>';
  2367.                            
  2368.                             /**
  2369.                              * Build the data attributes */
  2370.                              
  2371.                             }elseif($type == 'data' && $post_id != NULL){
  2372.                                
  2373.                                 /**
  2374.                                  * data-title attribute/value */
  2375.                                  
  2376.                                 if($explode_sort_option[0] == 'data-title'){
  2377.                                    
  2378.                                     $item_title = $this->cspml_items_title($post_id, $this->cspml_listings_title);
  2379.                                    
  2380.                                     $output .= ' data-title="'.stripslashes_deep($item_title).'"';
  2381.                                
  2382.                                 /**
  2383.                                  * data-date-created attribute/value */
  2384.                                  
  2385.                                 }elseif($explode_sort_option[0] == 'data-date-created'){
  2386.                                    
  2387.                                     $output .= ' data-date-created="'.$post_id.'"';
  2388.                                    
  2389.                                 }
  2390.                            
  2391.                             }
  2392.                            
  2393.                         }
  2394.                        
  2395.                     }
  2396.                    
  2397.                 }elseif($display_order == 'custom'){
  2398.            
  2399.                     /**
  2400.                      * The custom sort data (Custom fields) */
  2401.        
  2402.                     if(!empty($this->cspml_custom_sort_options)){
  2403.                        
  2404.                         if($type == 'list'){
  2405.                            
  2406.                             $output .= $this->cspml_build_custom_sort_data($map_id, $type, NULL, $this->cspml_custom_sort_options);
  2407.                                    
  2408.                         }elseif($type == 'data' && $post_id != NULL){
  2409.                            
  2410.                             $output .= $this->cspml_build_custom_sort_data($map_id, $type, $post_id, $this->cspml_custom_sort_options);
  2411.                
  2412.                         }
  2413.                            
  2414.                     }
  2415.                    
  2416.                 }
  2417.                
  2418.             }
  2419.            
  2420.             return $output;
  2421.            
  2422.         }
  2423.        
  2424.        
  2425.         /**
  2426.          * Create the list of the custom sort data (Custom fields)
  2427.          *
  2428.          * @since 1.0
  2429.          * @updated 2.0 [added @sort_meta_type]
  2430.          */
  2431.         function cspml_build_custom_sort_data($map_id, $type, $post_id = NULL, $sort_by_structure){
  2432.            
  2433.             $output = '';
  2434.  
  2435.             if(!empty($sort_by_structure)){
  2436.                        
  2437.                 /**
  2438.                  * Get custom sort by structure */
  2439.                  
  2440.                 $sort_data_attrs = (array) $sort_by_structure;
  2441.                            
  2442.                 /**
  2443.                  * Loop throught sort by data */
  2444.                  
  2445.                 foreach($sort_data_attrs as $sort_data_value){
  2446.                    
  2447.                     /**
  2448.                      * Get the custom field name */
  2449.                      
  2450.                     $custom_field_name = isset($sort_data_value['sort_options_name']) ? $sort_data_value['sort_options_name'] : '';
  2451.                    
  2452.                     if(!empty($custom_field_name)){
  2453.                        
  2454.                         $sort_options_name = $this->cspml_setting_exists('sort_options_name', $sort_data_value);
  2455.                         $sort_meta_type = $this->cspml_setting_exists('sort_meta_type', $sort_data_value); //@since 2.0
  2456.                         $sort_options_label = $this->cspml_setting_exists('sort_options_label', $sort_data_value);
  2457.                         $sort_options_order = $this->cspml_setting_exists('sort_options_order', $sort_data_value, array('desc', 'asc'));
  2458.                         $sort_options_desc_suffix = $this->cspml_setting_exists('sort_options_desc_suffix', $sort_data_value);
  2459.                         $sort_options_asc_suffix = $this->cspml_setting_exists('sort_options_asc_suffix', $sort_data_value);
  2460.                         $sort_options_visibilty = $this->cspml_setting_exists('sort_options_visibilty', $sort_data_value, 'yes');
  2461.        
  2462.                         /**
  2463.                          * Loop throught the sort order and create the sort list */
  2464.                          
  2465.                         foreach($sort_options_order as $sort_order){
  2466.                            
  2467.                             if($type == 'list'){
  2468.                                
  2469.                                 $label_suffix = ($sort_order == 'desc') ? $sort_options_desc_suffix : $sort_options_asc_suffix;
  2470.                                    
  2471.                                 $output .= '<li class="sort push" data-map-id="'.$map_id.'" ';
  2472.                                
  2473.                                     $output .= 'data-sort="'.$sort_options_name.'"';
  2474.                                
  2475.                                     $output .= ' data-order="'.$sort_order.'"';
  2476.                                    
  2477.                                     $output .= ' data-type="'.$sort_meta_type.'"'; //@since 2.0
  2478.                                            
  2479.                                 $output .= '>'.esc_html__($sort_options_label, 'cspml').' '.esc_html__($label_suffix, 'cspml').'</li>';
  2480.                        
  2481.                             }elseif($type == 'data' && $post_id != NULL){
  2482.                                
  2483.                                 $post_meta = $sort_options_name;
  2484.                                
  2485.                                 $meta_data = get_post_meta($post_id, $post_meta, true);
  2486.                                
  2487.                                 if(!empty($meta_data))
  2488.                                     $output .= ' data-'.$post_meta.'="'.$meta_data.'"';
  2489.                                
  2490.                                 else $output .= ' data-'.$post_meta.'="'.$post_id.'"';
  2491.                        
  2492.                             }
  2493.                            
  2494.                         }
  2495.                        
  2496.                     }
  2497.                                    
  2498.                 }          
  2499.                
  2500.             }
  2501.            
  2502.             return $output;
  2503.            
  2504.         }
  2505.        
  2506.        
  2507.         /**
  2508.          * Preapare the sort order Query when a sort by request is sent via ajax
  2509.          *
  2510.          * @since 1.0
  2511.          * @updated 2.0 [added @meta_type for custom fields]
  2512.          */
  2513.         function cspml_set_posts_order($sort_data, $sort_order, $meta_type = 'CHAR'){
  2514.            
  2515.             $output = array();
  2516.            
  2517.             if(!empty($sort_data) && !empty($sort_order)){
  2518.                
  2519.                 /**
  2520.                  * Check the value of the $sort_data
  2521.                  * If the data is a title sort request */
  2522.                  
  2523.                 if($sort_data == "data-title"){
  2524.                    
  2525.                     $orderby = array('orderby' => 'title');
  2526.                
  2527.                 /**
  2528.                  * If the data is a date sort request */
  2529.                  
  2530.                 }elseif($sort_data == "data-date-created"){
  2531.                    
  2532.                     $orderby = array('orderby' => 'date');
  2533.                
  2534.                 /**
  2535.                  * If the data is a default sort request */
  2536.                  
  2537.                 }elseif($sort_data == "default"){
  2538.                    
  2539.                     //$orderby = array('orderby' => 'post__in');
  2540.                    
  2541.                     $orderby = array(
  2542.                         'orderby' => $this->cspml_get_map_option('orderby_param'),
  2543.                         'meta_key' => $this->cspml_get_map_option('orderby_meta_key'),
  2544.                     );
  2545.                    
  2546.                     $sort_order = $this->cspml_get_map_option('order_param');
  2547.                
  2548.                 /**
  2549.                  * If the data is a custom field request */
  2550.                  
  2551.                 }else{
  2552.                    
  2553.                     $orderby = array(
  2554.                         'meta_key' => $sort_data,
  2555.                         'orderby' => 'meta_value',
  2556.                         'meta_type' => $meta_type //@since 2.0
  2557.                     );             
  2558.                    
  2559.                 }
  2560.                
  2561.                 $output = array_merge($orderby, array('order' => strtoupper($sort_order)));
  2562.                
  2563.             }
  2564.            
  2565.             return $output;
  2566.            
  2567.         }
  2568.        
  2569.        
  2570.         /**
  2571.          * show the number of listings
  2572.          *
  2573.          * @since 1.0
  2574.          */
  2575.         function cspml_posts_count_clause($count, $map_id){
  2576.            
  2577.             return str_replace('[posts_count]', '<span class="cspml_the_count_'.$map_id.'">'.$count.'</span>', esc_html__($this->cspml_posts_count_clause, 'cspml'));
  2578.                    
  2579.         }
  2580.        
  2581.        
  2582.         /**
  2583.          * Parse item custom title
  2584.          *
  2585.          * @since 1.0
  2586.          * @updated 1.1
  2587.          */
  2588.         function cspml_items_title($post_id, $title, $click_title = false){
  2589.                        
  2590.             if (!class_exists('CspmMainMap'))
  2591.                 return;
  2592.            
  2593.             $CspmMainMap = CspmMainMap::this();
  2594.                
  2595.             /**
  2596.              * Custom title structure */
  2597.              
  2598.             $post_meta = esc_attr($title);
  2599.            
  2600.             $this->cspml_click_on_title = $this->cspml_get_map_option('cslf_click_on_title', 'yes');
  2601.             $this->cspml_external_link = $this->cspml_get_map_option('cslf_external_link', 'same_window');
  2602.            
  2603.             $the_permalink = ($click_title && $this->cspml_click_on_title == 'yes') ? ' href="'.$CspmMainMap->cspm_get_permalink($post_id).'"' : '';
  2604.             $target = ($this->cspml_external_link == "same_window") ? '' : ' target="_blank"';
  2605.            
  2606.             /**
  2607.              * Init vars */
  2608.              
  2609.             $items_title = '';     
  2610.             $items_title_lenght = 0;
  2611.            
  2612.             /**
  2613.              * If no custom title is set ...
  2614.              * ... Call item original title */
  2615.              
  2616.             if(empty($post_meta)){                     
  2617.                
  2618.                 $items_title = get_the_title($post_id);
  2619.                
  2620.             /**
  2621.              * If custom title is set ... */
  2622.              
  2623.             }else{
  2624.                
  2625.                 /**
  2626.                  * ... Get post metas from custom title structure */
  2627.                  
  2628.                 $explode_post_meta = explode('][', $post_meta);
  2629.                
  2630.                 /**
  2631.                  * Loop throught post metas */
  2632.                  
  2633.                 foreach($explode_post_meta as $single_post_meta){
  2634.                    
  2635.                     /**
  2636.                      * Clean post meta name */
  2637.                      
  2638.                     $single_post_meta = str_replace(array('[', ']'), '', $single_post_meta);
  2639.                    
  2640.                     /**
  2641.                      * Get the first two letters from post meta name */
  2642.                      
  2643.                     $check_string = substr($single_post_meta, 0, 2);
  2644.                     $check_title = substr($single_post_meta, 0, 5);
  2645.                    
  2646.                     /**
  2647.                      * Title case */
  2648.                      
  2649.                     if($check_title == 'title'){
  2650.                        
  2651.                         $items_title .= get_the_title($post_id);
  2652.                        
  2653.                     /**
  2654.                      * Separator case */
  2655.                      
  2656.                     }elseif($check_string === 's='){
  2657.                        
  2658.                         /**
  2659.                          * Add separator to title */
  2660.                          
  2661.                         $items_title .= str_replace('s=', '', $single_post_meta);
  2662.                    
  2663.                     /**
  2664.                      * Lenght case */
  2665.                      
  2666.                     }elseif($check_string === 'l='){
  2667.                        
  2668.                         /**
  2669.                          * Define title lenght */
  2670.                          
  2671.                         $items_title_lenght = str_replace('l=', '', $single_post_meta);
  2672.                    
  2673.                     /**
  2674.                      * Empty space case */
  2675.                      
  2676.                     }elseif($single_post_meta == '-'){
  2677.                        
  2678.                         /**
  2679.                          * Add space to title */
  2680.                          
  2681.                         $items_title .= ' ';
  2682.                    
  2683.                     /**
  2684.                      * Taxonomy case */
  2685.                      
  2686.                     }elseif($check_string === 'x='){
  2687.                        
  2688.                         /**
  2689.                          * Add taxonomy term(s) */
  2690.                          
  2691.                         $taxonomy = str_replace('x=', '', $single_post_meta);
  2692.                         $items_title .= implode(', ', wp_get_post_terms($post_id, $taxonomy, array("fields" => "names")));
  2693.                        
  2694.                     /**
  2695.                      * Post metas case */
  2696.                      
  2697.                     }else{
  2698.                        
  2699.                         /**
  2700.                          * Add post meta value to title */
  2701.                          
  2702.                         $items_title .= get_post_meta($post_id, $single_post_meta, true);
  2703.                            
  2704.                     }
  2705.                    
  2706.                 }
  2707.                
  2708.                 /**
  2709.                  * If custom title is empty (Maybe someone will type something by error), call original title */
  2710.                  
  2711.                 if(empty($items_title)) $items_title = get_the_title($post_id);
  2712.                
  2713.             }
  2714.            
  2715.             /**
  2716.              * Show title as title lenght is defined */
  2717.          
  2718.             /**
  2719.              * Use the function mb_substr() instead of substr()!
  2720.              * mb_substr() is multi-byte safe !
  2721.              *
  2722.              * @since 1.2 */
  2723.          
  2724.             if($items_title_lenght > 0) $items_title = mb_substr($items_title, 0, $items_title_lenght);
  2725.            
  2726.             if($click_title && $this->cspml_click_on_title == 'yes'){
  2727.                
  2728.                 $link_class = ($this->cspml_external_link == 'popup') ? 'class="cspml_popup_single_post"' : ''; //@since 2.5
  2729.                
  2730.                 return apply_filters('cspml_item_title', '<a'.$the_permalink.''.$target.' title="'.addslashes_gpc($items_title).'" '.$link_class.'>'.addslashes_gpc($items_title).'</a>', $post_id);
  2731.            
  2732.             }else return apply_filters('cspml_item_title', addslashes_gpc($items_title), $post_id);
  2733.            
  2734.         }
  2735.        
  2736.        
  2737.         /**
  2738.          * Parse item custom details
  2739.          *
  2740.          * @since 1.0
  2741.          */      
  2742.         function cspml_items_details($post_id, $details){          
  2743.            
  2744.             /**
  2745.              * Custom details structure */
  2746.              
  2747.             $post_meta = esc_attr($details);       
  2748.            
  2749.             /**
  2750.              * Init vars */
  2751.              
  2752.             $items_details = '';
  2753.             $items_title_lenght = 0;
  2754.             $items_details_lenght = 0;
  2755.                    
  2756.             $ellipses = '';
  2757.            
  2758.             if($this->cspml_get_map_option('cslf_ellipses') == 'yes')
  2759.                 $ellipses = '&hellip;';                              
  2760.            
  2761.             /**
  2762.              * If new structure is set ... */
  2763.              
  2764.             if(!empty($post_meta)){
  2765.                
  2766.                 /**
  2767.                  * ... Get post metas from custom details structure */
  2768.                  
  2769.                 $explode_post_meta = explode('][', $post_meta);
  2770.                
  2771.                 /**
  2772.                  * Loop throught post metas */
  2773.                  
  2774.                 foreach($explode_post_meta as $single_post_meta){
  2775.                    
  2776.                     /**
  2777.                      * Clean post meta name */
  2778.                      
  2779.                     $single_post_meta = str_replace(array('[', ']'), '', $single_post_meta);
  2780.                                
  2781.                     /**
  2782.                      * Get the first two letters from post meta name */
  2783.                      
  2784.                     $check_string = substr($single_post_meta, 0, 2);
  2785.                     $check_taxonomy = substr($single_post_meta, 0, 4);
  2786.                     $check_content = substr($single_post_meta, 0, 7);
  2787.                    
  2788.                     /**
  2789.                      * Taxonomy case */
  2790.                      
  2791.                     if(!empty($check_taxonomy) && $check_taxonomy == 'tax='){
  2792.                        
  2793.                         /**
  2794.                          * Add taxonomy term(s) */
  2795.                          
  2796.                         $taxonomy = str_replace('tax=', '', $single_post_meta);
  2797.                         $items_details .= implode(', ', wp_get_post_terms($post_id, $taxonomy, array("fields" => "names")));
  2798.                        
  2799.                     /**
  2800.                      * The content */
  2801.                      
  2802.                     }elseif(!empty($check_content) && $check_content == 'content'){
  2803.                        
  2804.                         $explode_content = explode(';', str_replace(' ', '', $single_post_meta));
  2805.                        
  2806.                         /**
  2807.                          * Get original post details */
  2808.                          
  2809.                         $post_record = get_post($post_id, ARRAY_A);
  2810.                        
  2811.                         /**
  2812.                          * Post content */
  2813.                          
  2814.                         $post_content = trim(preg_replace('/\s+/', ' ', $post_record['post_content']));
  2815.                        
  2816.                         /**
  2817.                          * Post excerpt */
  2818.                          
  2819.                         $post_excerpt = trim(preg_replace('/\s+/', ' ', $post_record['post_excerpt']));
  2820.                        
  2821.                         /**
  2822.                          * Excerpt is recommended */
  2823.                          
  2824.                         $the_content = (!empty($post_excerpt)) ? $post_excerpt : $post_content;
  2825.                
  2826.                         /**
  2827.                          * Show excerpt/content as details lenght is defined */
  2828.                      
  2829.                         /**
  2830.                          * Use the function mb_substr() instead of substr()!
  2831.                          * mb_substr() is multi-byte safe !
  2832.                          *
  2833.                          * @since 1.2 */
  2834.                      
  2835.                         if(isset($explode_content[1]) && $explode_content[1] > 0) $items_details .= mb_substr($the_content, 0, $explode_content[1]).'&hellip;';
  2836.                                    
  2837.                     /**
  2838.                      * Separator case */
  2839.                      
  2840.                     }elseif(!empty($check_string) && $check_string == 's='){
  2841.                        
  2842.                         /**
  2843.                          * Add separator to details */
  2844.                          
  2845.                         $separator = str_replace('s=', '', $single_post_meta);
  2846.                        
  2847.                         $separator == 'br' ? $items_details .= '<br />' : $items_details .= $separator;
  2848.                        
  2849.                     /**
  2850.                      * Meta post title OR Label case */
  2851.                      
  2852.                     }elseif(!empty($check_string) && $check_string == 't='){
  2853.                        
  2854.                         /**
  2855.                          * Add label to details */
  2856.                          
  2857.                         $items_details .= str_replace('t=', '', $single_post_meta);
  2858.                        
  2859.                     /**
  2860.                      * Lenght case */
  2861.                      
  2862.                     }elseif(!empty($check_string) && $check_string == 'l='){
  2863.                        
  2864.                         /**
  2865.                          * Define details lenght */
  2866.                          
  2867.                         $items_details_lenght = str_replace('l=', '', $single_post_meta);
  2868.                        
  2869.                     /**
  2870.                      * Empty space case */
  2871.                      
  2872.                     }elseif($single_post_meta == '-'){
  2873.                        
  2874.                         /**
  2875.                          * Add space to details */
  2876.                          
  2877.                         $items_details .= ' ';
  2878.                    
  2879.                     /**
  2880.                      * Post metas case */
  2881.                      
  2882.                     }else{
  2883.    
  2884.                         /**
  2885.                          * Add post metas to details */
  2886.                          
  2887.                         $items_details .= get_post_meta($post_id, $single_post_meta, true);
  2888.                            
  2889.                     }
  2890.                    
  2891.                 }                      
  2892.                
  2893.             }
  2894.            
  2895.             /**
  2896.              * If no custom details structure is set ... */
  2897.              
  2898.             if(empty($post_meta) || empty($items_details)){
  2899.                
  2900.                 /**
  2901.                  * Get original post details */
  2902.                  
  2903.                 $post_record = get_post($post_id, ARRAY_A);
  2904.                
  2905.                 /**
  2906.                  * Post content */
  2907.                  
  2908.                 $post_content = trim(preg_replace('/\s+/', ' ', $post_record['post_content']));
  2909.                
  2910.                 /**
  2911.                  * Post excerpt */
  2912.                  
  2913.                 $post_excerpt = trim(preg_replace('/\s+/', ' ', $post_record['post_excerpt']));
  2914.                
  2915.                 /**
  2916.                  * Excerpt is recommended */
  2917.                  
  2918.                 $items_details = (!empty($post_excerpt)) ? $post_excerpt : $post_content;
  2919.                
  2920.                 /**
  2921.                  * Show excerpt/content as details lenght is defined */
  2922.                  
  2923.                 if($items_details_lenght > 0){
  2924.                      
  2925.                      /**
  2926.                       * Use the function mb_substr() instead of substr()!
  2927.                       * mb_substr() is multi-byte safe !
  2928.                       *
  2929.                       * @since 1.2 */
  2930.                      
  2931.                     $items_details = mb_substr($items_details, 0, $items_details_lenght).$ellipses;
  2932.                    
  2933.                 }
  2934.                
  2935.             }
  2936.            
  2937.             return apply_filters('cspml_item_description', strip_tags(addslashes_gpc($items_details), '<strong><b><i><u><a><br>'), $post_id);
  2938.            
  2939.         }
  2940.        
  2941.        
  2942.         /**
  2943.          * Create the "Listings faceted search form"
  2944.          *
  2945.          * @since 1.0
  2946.          * @updated 2.1
  2947.          */
  2948.         function cspml_listings_faceted_search_form($map_id, $post_type, $post_ids = array(), $list_filter){
  2949.            
  2950.             if (!class_exists('CspmMainMap'))
  2951.                 return;
  2952.            
  2953.             $CspmMainMap = CspmMainMap::this();
  2954.                
  2955.             $output = '';
  2956.  
  2957.             if($list_filter == 'yes'){
  2958.                
  2959.                 $output .= '<div class="cspml_transparent_layer_'.$map_id.'"></div>';  
  2960.                
  2961.                 /**
  2962.                  * A filter that allows adding extra HTML before the filter form */
  2963.                  
  2964.                 $output .= apply_filters('cspml_before_filter_form', '', $map_id);
  2965.  
  2966.                 $output .= '<form action="" method="post" id="cspml_listings_filter_form" class="cspml_filter_form col-lg-12 col-md-12 col-sm-12 col-xs-12 cspm_border_radius cspm_border_shadow no-padding cspm_animated fadeIn" data-map-id="'.$map_id.'">';
  2967.                    
  2968.                     /**
  2969.                      * Dispay filter buttons on the top area
  2970.                      * @since 1.2 */
  2971.                    
  2972.                     if($this->cspml_filter_btns_position == 'top' || $this->cspml_filter_btns_position == 'both'){
  2973.                        
  2974.                         $output .= '<div class="row row-no-margin cspm_filter_btns">'; 
  2975.                            
  2976.                             $output .= '<a class="cspml_reset_lsitings_filter cspml_btn cspm_border_shadow col-lg-4 col-md-4 col-sm-3 col-xs-3" title="'.apply_filters('__reset_all_filters', esc_html__('Reset all filters', 'cspml')).'" data-request-type="reset" data-map-id="'.$map_id.'" data-display-location="listings">';
  2977.                                 $output .= '<img src="'.apply_filters('cspml_refresh_filter_img', $this->plugin_url.'img/refresh.png', str_replace('map', '', $map_id)).'" class="no-margin-right" />';
  2978.                             $output .= '</a>';
  2979.                                        
  2980.                             $output .= '<a class="cspml_submit_listings_filter cspml_btn cspm_border_shadow col-lg-8 col-md-8 col-sm-9 col-xs-9" title="'.apply_filters('__filter', esc_html__('Filter', 'cspml')).'" data-request-type="filter" data-map-id="'.$map_id.'" data-display-location="listings">';
  2981.                                 $output .= '<img src="'.apply_filters('cspml_filter_search_img', $this->plugin_url.'img/filter.png', str_replace('map', '', $map_id)).'" />';
  2982.                                 $output .= esc_html__($this->cspml_filter_btn_text, 'cspml');
  2983.                             $output .= '</a>';
  2984.                        
  2985.                         $output .= '</div>';
  2986.  
  2987.                     }
  2988.                    
  2989.                     $output .= '<div class="clear-both"></div>';
  2990.                    
  2991.                     foreach($this->cspml_filter_fields_order as $display_order){
  2992.                        
  2993.                         if($display_order == 'keyword'){
  2994.                            
  2995.                             /**
  2996.                              * Keyword text field
  2997.                              * @since 2.2 */
  2998.                            
  2999.                             $output .= $this->cspml_keyword_search_field($map_id, $post_type, $post_ids);
  3000.                            
  3001.                         }elseif($display_order == 'date_filter'){
  3002.                            
  3003.                             /**
  3004.                              * Display the date filter field
  3005.                              * @since 2.1 */
  3006.                            
  3007.                             $output .= $this->cspml_posts_publish_date_field($map_id, $post_type, $post_ids);      
  3008.                      
  3009.                         }elseif($display_order == 'taxonomies'){
  3010.                            
  3011.                             /**
  3012.                              * Loop throught taxonomies */
  3013.                            
  3014.                             if(count($this->cspml_taxonomies) > 0){
  3015.                                
  3016.                                 $rendered_taxonomies = array();
  3017.                                
  3018.                                 foreach($this->cspml_taxonomies as $taxonomy_data){
  3019.                                    
  3020.                                     $taxonomy_data = (array) $taxonomy_data;
  3021.                                    
  3022.                                     if(count($taxonomy_data) > 0){
  3023.        
  3024.                                         $taxonomy_label = $this->cspml_setting_exists('taxonomy_label', $taxonomy_data);
  3025.                                         $taxonomy_name = $this->cspml_setting_exists('taxonomy_name', $taxonomy_data);
  3026.                                         $taxonomy_description = $this->cspml_setting_exists('taxonomy_description', $taxonomy_data); //@since 2.4                                      
  3027.                                         $taxonomy_visbility = $this->cspml_setting_exists('taxonomy_visibilty', $taxonomy_data, 'yes');
  3028.                                         $taxonomy_exists = taxonomy_exists($taxonomy_name);
  3029.                                                            
  3030.                                         if(!empty($taxonomy_label) && !empty($taxonomy_name) && $taxonomy_visbility == "yes" && $taxonomy_exists && !in_array($taxonomy_name, $rendered_taxonomies)){
  3031.                                            
  3032.                                             /**
  3033.                                              * Hide empty terms */
  3034.                                              
  3035.                                             $taxonomy_hide_empty = $this->cspml_setting_exists('taxonomy_hide_empty', $taxonomy_data, "yes");
  3036.                                                 $hide_empty = ($taxonomy_hide_empty == 'yes') ? true : false;                                  
  3037.                                                
  3038.                                             /**
  3039.                                              * Terms to exclude */
  3040.                                              
  3041.                                             $exclude_term_ids = str_replace(' ', '', $this->cspml_setting_exists('taxonomy_exclude_terms_'.$taxonomy_name, $taxonomy_data));
  3042.                                                
  3043.                                             /**
  3044.                                              * Terms to include */
  3045.                                              
  3046.                                             $include_term_ids = str_replace(' ', '', $this->cspml_setting_exists('taxonomy_include_terms_'.$taxonomy_name, $taxonomy_data));
  3047.                                                
  3048.                                             /**
  3049.                                              * Terms orderby */
  3050.                                              
  3051.                                             $terms_orderby = str_replace(' ', '', $this->cspml_setting_exists('taxonomy_orderby_param', $taxonomy_data));
  3052.                                                
  3053.                                             /**
  3054.                                              * Terms order */
  3055.                                              
  3056.                                             $terms_order = str_replace(' ', '', $this->cspml_setting_exists('taxonomy_order_param', $taxonomy_data));
  3057.                                            
  3058.                                             /**
  3059.                                              * Get taxonomy terms
  3060.                                              * @updated 1.1 */
  3061.                                              
  3062.                                             $terms = (array) get_terms(array(
  3063.                                                                 'taxonomy' => $taxonomy_name,
  3064.                                                                 'orderby' => apply_filters('cspml_filter_terms_orderby', $terms_orderby), //@since 1.1
  3065.                                                                 'order' => apply_filters('cspml_filter_terms_order', $terms_order), //@since 1.1                                                       
  3066.                                                                 'include' => $include_term_ids,
  3067.                                                                 'exclude' => $exclude_term_ids,
  3068.                                                                 'hide_empty' => $hide_empty
  3069.                                                              ));
  3070.        
  3071.                                             /**
  3072.                                              * Show the field only when terms are more than 0 */
  3073.                                              
  3074.                                             if(count($terms) > 0){                                                             
  3075.                                                
  3076.                                                 $search_all_option = $this->cspml_setting_exists('taxonomy_search_all_option', $taxonomy_data, 'no');
  3077.                                                 $search_all_text = $this->cspml_setting_exists('taxonomy_search_all_text', $taxonomy_data, 'All');
  3078.                                                 $show_count = $this->cspml_setting_exists('taxonomy_show_count', $taxonomy_data, 'no');
  3079.                                                 $symbol = $this->cspml_setting_exists('taxonomy_symbol', $taxonomy_data);
  3080.                                                 $symbol_position = $this->cspml_setting_exists('taxonomy_symbol_position', $taxonomy_data, 'before');
  3081.                                                 $display_status = $this->cspml_setting_exists('taxonomy_display_status', $taxonomy_data, 'open'); //@since 2.3
  3082.                                                        
  3083.                                                 $field_atts = array(
  3084.                                                     'field_name' => $taxonomy_name,
  3085.                                                     'field_label' => esc_html__($taxonomy_label, 'cspml'),
  3086.                                                     'field_description' => $taxonomy_description, //@since 2.4
  3087.                                                     'field_options' => $terms,
  3088.                                                     'symbol' => esc_html__($symbol, 'cspml'),
  3089.                                                     'symbol_position' => $symbol_position,
  3090.                                                     'search_all_option' => $search_all_option,
  3091.                                                     'search_all_text' => esc_html__($search_all_text, 'cspml'),
  3092.                                                     'show_count' => $show_count,
  3093.                                                     'display_status' => $display_status, //@since 2.3
  3094.                                                 );
  3095.                            
  3096.                                                 $output .= '<div class="cspml_fs_item_container col-lg-12 col-xs-12 col-sm-12 col-md-12" data-map-id="'.$map_id.'">';
  3097.                                                    
  3098.                                                     $display_type = $this->cspml_setting_exists('taxonomy_display_type', $taxonomy_data);
  3099.                                                    
  3100.                                                     if(!empty($display_type))
  3101.                                                         $output .= $this->cspml_faceted_search_fields($map_id, $display_type, $field_atts, true, $post_type, $post_ids);       
  3102.                                                    
  3103.                                                 $output .= '</div>';
  3104.                                                
  3105.                                             }
  3106.                                            
  3107.                                         }
  3108.                                        
  3109.                                         $rendered_taxonomies[] = $taxonomy_name;
  3110.            
  3111.                                     }
  3112.                                    
  3113.                                 }
  3114.                                                
  3115.                             }
  3116.                            
  3117.                         }elseif($display_order == 'custom_fields'){
  3118.    
  3119.                             /**
  3120.                              * Loop throught custom fields */
  3121.                            
  3122.                             if(count($this->cspml_custom_fields) > 0){
  3123.                                
  3124.                                 $rendered_custom_fields = array();
  3125.                                
  3126.                                 foreach($this->cspml_custom_fields as $custom_field_data){
  3127.                                    
  3128.                                     $custom_field_data = (array) $custom_field_data;
  3129.        
  3130.                                     if(count($custom_field_data) > 0){
  3131.                                        
  3132.                                         $custom_field_orderby = $this->cspml_setting_exists('custom_field_orderby_param', $custom_field_data, 'pm.meta_value');
  3133.                                         $custom_field_order = $this->cspml_setting_exists('custom_field_order_param', $custom_field_data, 'ASC');
  3134.                                         $custom_field_label = $this->cspml_setting_exists('custom_field_label', $custom_field_data);
  3135.                                         $custom_field_name = $this->cspml_setting_exists('custom_field_name', $custom_field_data);
  3136.                                         $custom_field_description = $this->cspml_setting_exists('custom_field_description', $custom_field_data); //@since 2.4                                                                              
  3137.                                         $custom_field_visbility = $this->cspml_setting_exists('custom_field_visibilty', $custom_field_data, 'yes');
  3138.                                        
  3139.                                         if(!empty($custom_field_label) && !empty($custom_field_name) && $custom_field_visbility == "yes" && !in_array($custom_field_name, $rendered_custom_fields)){
  3140.                                        
  3141.                                             /**
  3142.                                              * Get All Post Meta And Count The Number Of Each One */
  3143.                                              
  3144.                                             $custom_field_values = $this->cspml_get_meta_values($custom_field_name, $post_type, 'publish', $custom_field_orderby, $custom_field_order);
  3145.                                        
  3146.                                             $custom_field_options = array_unique($custom_field_values);
  3147.        
  3148.                                             /**
  3149.                                              * Show options only when custom_field_options are more than 0 */
  3150.                                              
  3151.                                             if(count($custom_field_options) > 0){
  3152.                                                
  3153.                                                 $term_ids_array = array();
  3154.                                                    
  3155.                                                 $display_type = $this->cspml_setting_exists('custom_field_display_type', $custom_field_data);
  3156.                                                 $search_all_option = $this->cspml_setting_exists('custom_field_search_all_option', $custom_field_data, 'no');
  3157.                                                 $search_all_text = $this->cspml_setting_exists('custom_field_search_all_text', $custom_field_data, 'All');
  3158.                                                 $show_count = $this->cspml_setting_exists('custom_field_show_count', $custom_field_data, 'no');
  3159.                                                 $symbol = $this->cspml_setting_exists('custom_field_symbol', $custom_field_data);
  3160.                                                 $symbol_position = $this->cspml_setting_exists('custom_field_symbol_position', $custom_field_data, 'before');
  3161.                                                 $compare_parameter = $this->cspml_setting_exists('custom_field_compare_param', $custom_field_data);
  3162.                                                 $display_status = $this->cspml_setting_exists('custom_field_display_status', $custom_field_data, 'open'); //@since 2.3
  3163.                
  3164.                                                 /**
  3165.                                                  * Custom field Datepicker parameters
  3166.                                                  * @since 2.4 */
  3167.                                                
  3168.                                                 $cf_datepicker_parameters = ($display_type == 'datepicker') ? array(
  3169.                                                     'date_format' => $this->cspml_setting_exists('cf_datepicker_date_format', $custom_field_data, 'YYYY/MM/DD'),
  3170.                                                     'date_separator' => $this->cspml_setting_exists('cf_datepicker_date_separator', $custom_field_data, 'slash'),
  3171.                                                     'start_date' => $this->cspml_setting_exists('cf_datepicker_start_date', $custom_field_data, ''),
  3172.                                                     'end_date' => $this->cspml_setting_exists('cf_datepicker_end_date', $custom_field_data, ''),
  3173.                                                     'week_start' => $this->cspml_setting_exists('cf_datepicker_week_start', $custom_field_data, 'sunday'),
  3174.                                                 ) : array();
  3175.                                                
  3176.                                                 /**
  3177.                                                  * [@field_atts]
  3178.                                                  * @updated 2.4 [added custom field Datepicker parameters] */
  3179.                                                  
  3180.                                                 $field_atts = array_merge(
  3181.                                                     array(
  3182.                                                         'field_name' => $custom_field_name,
  3183.                                                         'field_label' => esc_html__($custom_field_label, 'cspml'),
  3184.                                                         'field_description' => $custom_field_description, //@since 2.4
  3185.                                                         'field_options' => $custom_field_options,
  3186.                                                         'symbol' => esc_html__($symbol, 'cspml'),
  3187.                                                         'symbol_position' => $symbol_position,
  3188.                                                         'search_all_option' => $search_all_option,
  3189.                                                         'search_all_text' => esc_html__($search_all_text, 'cspml'),
  3190.                                                         'show_count' => $show_count,
  3191.                                                         'compare_parameter' => $compare_parameter,
  3192.                                                         'display_status' => $display_status, //@since 2.3
  3193.                                                     ),
  3194.                                                     $cf_datepicker_parameters // CF. Datepicker atts | @since 2.4
  3195.                                                 );
  3196.                                                
  3197.                                                 $output .= '<div class="cspml_fs_item_container col-lg-12 col-xs-12 col-sm-12 col-md-12" data-map-id="'.$map_id.'">';
  3198.                                                    
  3199.                                                     if(!empty($display_type))
  3200.                                                         $output .= $this->cspml_faceted_search_fields($map_id, $display_type, $field_atts, false, $post_type, $post_ids);      
  3201.                                                
  3202.                                                 $output .= '</div>';
  3203.                                                
  3204.                                             }
  3205.                                            
  3206.                                         }
  3207.                                        
  3208.                                         $rendered_custom_fields[] = $custom_field_name;
  3209.                                    
  3210.                                     }
  3211.                                    
  3212.                                 }
  3213.                                                
  3214.                             }
  3215.                        
  3216.                         }
  3217.                        
  3218.                     }
  3219.                      
  3220.                     $output .= '<div class="clearfix"></div>';
  3221.                    
  3222.                     if($this->cspml_filter_btns_position == 'bottom' || $this->cspml_filter_btns_position == 'both'){
  3223.                        
  3224.                         $output .= '<div class="row row-no-margin cspm_filter_btns">'; 
  3225.                            
  3226.                             $output .= '<a class="cspml_reset_lsitings_filter cspml_btn cspm_border_shadow col-lg-4 col-md-4 col-sm-3 col-xs-3" title="'.apply_filters('__reset_all_filters', esc_html__('Reset all filters', 'cspml')).'" data-request-type="reset" data-map-id="'.$map_id.'" data-display-location="listings">';
  3227.                                 $output .= '<img src="'.apply_filters('cspml_refresh_filter_img', $this->plugin_url.'img/refresh.png', str_replace('map', '', $map_id)).'" class="no-margin-right" />';
  3228.                             $output .= '</a>';
  3229.                                        
  3230.                             $output .= '<a class="cspml_submit_listings_filter cspml_btn cspm_border_shadow col-lg-8 col-md-8 col-sm-9 col-xs-9" title="'.apply_filters('__filter', esc_html__('Filter', 'cspml')).'" data-request-type="filter" data-map-id="'.$map_id.'" data-display-location="listings">';
  3231.                                 $output .= '<img src="'.apply_filters('cspml_filter_search_img', $this->plugin_url.'img/filter.png', str_replace('map', '', $map_id)).'" />';
  3232.                                 $output .= esc_html__($this->cspml_filter_btn_text, 'cspml');
  3233.                             $output .= '</a>';
  3234.                        
  3235.                         $output .= '</div>';
  3236.                        
  3237.                         $output .= '<div class="clear-both"></div>';
  3238.                        
  3239.                     }
  3240.                    
  3241.                 $output .= '</form>';
  3242.                
  3243.                 /**
  3244.                  * A filter that allows adding extra HTML after the filter form */
  3245.                  
  3246.                 $output .= apply_filters('cspml_after_filter_form', '', $map_id);
  3247.  
  3248.                 $output .= '<div class="clear-both visible-sm visible-xs"></div>';
  3249.                
  3250.             }
  3251.            
  3252.             return $output;
  3253.        
  3254.         }
  3255.        
  3256.        
  3257.         /**
  3258.          * Prepare the fields for the filter form
  3259.          *
  3260.          * @since 1.0
  3261.          * @update 1.1
  3262.          * @updated 2.3
  3263.          * @updated 2.4 [added datepicker for custom fields]
  3264.          */
  3265.         function cspml_faceted_search_fields($map_id, $field_type, $field_atts, $is_terms = false, $post_type, $post_ids = array(), $filter_container = "listings"){
  3266.            
  3267.             $defaults = array(
  3268.                 'field_name' => '',
  3269.                 'field_label' => '',
  3270.                 'field_description' => '', //@since 2.4
  3271.                 'field_options' => array(),
  3272.                 'symbol' => '',
  3273.                 'symbol_position' => 'text',
  3274.                 'search_all_option' => 'false',
  3275.                 'search_all_text' => apply_filters('__all', esc_html__('All', 'cspml')),
  3276.                 'show_count' => '',
  3277.                 'compare_parameter' => '',
  3278.                 'default_value' => '',
  3279.                 'display_status' => 'open', //@since 2.3
  3280.                
  3281.                 /**
  3282.                  * Custom fields Datepicker parameters
  3283.                  * @since 2.4 */
  3284.                
  3285.                 'date_format' => '',
  3286.                 'date_separator' => '',
  3287.                 'start_date' => '',
  3288.                 'end_date' => '',
  3289.                 'week_start' => '',
  3290.             );
  3291.            
  3292.             extract( wp_parse_args( $field_atts, $defaults ) );
  3293.                
  3294.             $option_ids_array = array();
  3295.            
  3296.             $output = '';              
  3297.            
  3298.             $i = 1;
  3299.            
  3300.             $count_options = count($field_options);
  3301.            
  3302.             $arrow_down_img = apply_filters('cspml_filter_arrow_down_img', $this->plugin_url.'img/arrow-down.png', str_replace('map', '', $map_id));
  3303.            
  3304.             $display_css = ($display_status == 'open') ? '' : ' style="display:none;"'; //@since 2.3
  3305.            
  3306.             /**
  3307.              * Checkbox field */
  3308.              
  3309.             if($field_type == "checkbox"){
  3310.                
  3311.                 if($filter_container != "map"){
  3312.                                                            
  3313.                     $output .= '<div class="cspml_fs_label row" for="'.$field_name.'" id="'.$field_name.'" data-map-id="'.$map_id.'">';
  3314.                         $output .= '<span class="cspml_label_text">'.$field_label.'</span>';
  3315.                         $output .= '<span class="cspml_toggle_btn" data-field-name="'.$field_name.'" data-display-location="'.$filter_container.'" data-map-id="'.$map_id.'">';
  3316.                             $output .= '<img src="'.$arrow_down_img.'" style="height:15px; width:auto;" />';
  3317.                         $output .= '</span>';
  3318.                     $output .= '</div>';
  3319.                    
  3320.                 }else{
  3321.                    
  3322.                     $output .= '<div class="cspml_mfs_label row" for="'.$field_name.'" id="'.$field_name.'">';                                     
  3323.                         $output .= '<span class="cspml_label_text col-lg-10 col-sm-10 col-xs-11 col-md-10">'.$field_label.'</span>';
  3324.                     $output .= '</div>';
  3325.                    
  3326.                 }
  3327.                        
  3328.                 $output .= '<div class="cspml_fs_options_list" data-field-name="'.$field_name.'" data-display-location="'.$filter_container.'" data-map-id="'.$map_id.'" '.$display_css.'>';
  3329.                    
  3330.                     if(!empty($field_description))
  3331.                         $output .= '<div class="cspml_field_desc">'.$field_description.'</div>'; //@since 2.4
  3332.                    
  3333.                     $filter_type = ($is_terms) ? "taxonomy" : "custom_field";
  3334.                    
  3335.                     $output .= '<input type="hidden" name="'.$field_name.'_filter_type" value="'.$filter_type.'" />';
  3336.                    
  3337.                     /**
  3338.                      * List of options */
  3339.                    
  3340.                     foreach($field_options as $option){
  3341.                        
  3342.                         if($is_terms){
  3343.                                                            
  3344.                             $label = $option->name;
  3345.                             $name  = $option->slug;
  3346.                             $id    = $option->term_id;
  3347.                             $value = $option->term_id;
  3348.                            
  3349.                             $filter_type = "taxonomy";
  3350.                            
  3351.                             if($show_count == "yes")                                                                                                   
  3352.                                 $count_posts = $this->cspml_count_term_posts($field_name, $id, $post_type, $post_ids);
  3353.                            
  3354.                         }else{
  3355.                            
  3356.                             $label = $name = $id = $value = $option;
  3357.                            
  3358.                             if($show_count == "yes"){      
  3359.                                 $count_posts = $this->cspml_count_custom_field_posts($post_type, $field_name);                         
  3360.                                 $count_posts = isset($count_posts[$name]) ? $count_posts[$name] : '0';
  3361.                             }
  3362.                            
  3363.                             $filter_type = "custom_field";
  3364.                        
  3365.                         }
  3366.                        
  3367.                            
  3368.                         $option_ids_array[] = $id;
  3369.                              
  3370.                         $output .= '<div class="cspml_input_container">';
  3371.                         $output .= '<input type="checkbox" name="'.$field_name.'[]" id="'.$map_id.'_'.$filter_container.'_'.$field_name.$id.'" data-filter-type="'.$filter_type.'" value="'.$value.'" />';
  3372.                         $output .= '<label for="'.$map_id.'_'.$filter_container.'_'.$field_name.$id.'" id="'.$map_id.'_'.$filter_container.'_'.$field_name.$id.'">';
  3373.                             $output .= ($symbol_position == "before") ? $symbol : '';
  3374.                             $output .= ($show_count == "yes") ? $label.' ('.$count_posts.')' : $label;
  3375.                             $output .= ($symbol_position == "after") ? $symbol : '';
  3376.                         $output .= '</label>'; 
  3377.                         $output .= '</div>';               
  3378.                    
  3379.                         /**
  3380.                          * Show all option */
  3381.                          
  3382.                         if($search_all_option == "yes" && $i++ == $count_options){
  3383.                             $output .= '<div class="cspml_input_container">';
  3384.                             $output .= '<input type="checkbox" name="'.$field_name.'[]" class="cspml_show_all" id="show_all_'.$map_id.'_'.$field_name.'" data-filter-type="'.$filter_type.'" value="'.implode(',', $option_ids_array).'" />';
  3385.                             $output .= '<label for="show_all_'.$map_id.'_'.$field_name.'" id="show_all_'.$map_id.'_'.$field_name.'">'.$search_all_text.'</label>';
  3386.                             $output .= '</div>';
  3387.                         }
  3388.        
  3389.                     }
  3390.                
  3391.                 $output .= '</div>';
  3392.            
  3393.             /**
  3394.              * Radio field */
  3395.              
  3396.             }elseif($field_type == "radio"){
  3397.                    
  3398.                 if($filter_container != "map"){
  3399.                                                            
  3400.                     $output .= '<div class="cspml_fs_label row" for="'.$field_name.'" id="'.$field_name.'" data-map-id="'.$map_id.'">';
  3401.                         $output .= '<span class="cspml_label_text">'.$field_label.'</span>';
  3402.                         $output .= '<span class="cspml_toggle_btn" data-field-name="'.$field_name.'" data-display-location="'.$filter_container.'" data-map-id="'.$map_id.'">';
  3403.                             $output .= '<img src="'.$arrow_down_img.'" style="height:15px; width:auto;" />';
  3404.                         $output .= '</span>';
  3405.                     $output .= '</div>';
  3406.                    
  3407.                 }else{
  3408.                    
  3409.                     $output .= '<div class="cspml_mfs_label row" for="'.$field_name.'" id="'.$field_name.'">';                                     
  3410.                         $output .= '<span class="cspml_label_text col-lg-10 col-sm-10 col-xs-11 col-md-10">'.$field_label.'</span>';
  3411.                     $output .= '</div>';
  3412.                    
  3413.                 }
  3414.                    
  3415.                 $output .= '<div class="cspml_fs_options_list" data-field-name="'.$field_name.'" data-display-location="'.$filter_container.'" data-map-id="'.$map_id.'" '.$display_css.'>';
  3416.                    
  3417.                     if(!empty($field_description))
  3418.                         $output .= '<div class="cspml_field_desc">'.$field_description.'</div>'; //@since 2.4
  3419.                    
  3420.                     $filter_type = ($is_terms) ? "taxonomy" : "custom_field";
  3421.                    
  3422.                     $output .= '<input type="hidden" name="'.$field_name.'_filter_type" value="'.$filter_type.'" />';
  3423.                    
  3424.                     /**
  3425.                      * List of options */
  3426.                      
  3427.                     foreach($field_options as $option){
  3428.                        
  3429.                         if($is_terms){
  3430.                                                            
  3431.                             $label = $option->name;
  3432.                             $name  = $option->slug;
  3433.                             $id    = $option->term_id;
  3434.                             $value = $option->term_id;
  3435.                            
  3436.                             $filter_type = "taxonomy";
  3437.                            
  3438.                             if($show_count == "yes")                                                                                                   
  3439.                                 $count_posts = $this->cspml_count_term_posts($field_name, $id, $post_type, $post_ids);
  3440.                            
  3441.                         }else{
  3442.                            
  3443.                             $label = $name = $id = $value = $option;
  3444.                            
  3445.                             if($show_count == "yes"){      
  3446.                                 $count_posts = $this->cspml_count_custom_field_posts($post_type, $field_name);
  3447.                                 $count_posts = isset($count_posts[$name]) ? $count_posts[$name] : '0';
  3448.                             }
  3449.                            
  3450.                             $filter_type = "custom_field";
  3451.                        
  3452.                         }
  3453.                        
  3454.                         $option_ids_array[] = $id;
  3455.                                                                                                                                                    
  3456.                         $output .= '<div class="cspml_input_container">';
  3457.                         $output .= '<input type="radio" name="'.$field_name.'" id="'.$map_id.'_'.$filter_container.'_'.$field_name.$id.'" data-filter-type="'.$filter_type.'" value="'.$value.'" />';
  3458.                         $output .= '<label for="'.$map_id.'_'.$filter_container.'_'.$field_name.$id.'" id="'.$map_id.'_'.$filter_container.'_'.$field_name.$id.'">';
  3459.                             $output .= ($symbol_position == "before") ? $symbol : '';
  3460.                             $output .= ($show_count == "yes") ? $label.' ('.$count_posts.')' : $label;
  3461.                             $output .= ($symbol_position == "after") ? $symbol : '';
  3462.                         $output .= '</label>';
  3463.                         $output .= '</div>';   
  3464.                        
  3465.                            
  3466.                         if($i++ == $count_options){
  3467.                            
  3468.                             /**
  3469.                              * Show all option */
  3470.                              
  3471.                             if($search_all_option == "yes"){
  3472.                                 $output .= '<div class="cspml_input_container">';
  3473.                                 $output .= '<input type="radio" name="'.$field_name.'" class="cspml_show_all" id="show_all_'.$map_id.'_'.$field_name.'" data-filter-type="'.$filter_type.'" value="'.implode(',', $option_ids_array).'" />';
  3474.                                 $output .= '<label for="show_all_'.$map_id.'_'.$field_name.'" id="show_all_'.$map_id.'_'.$field_name.'">'.$search_all_text.'</label>';
  3475.                                 $output .= '</div>';
  3476.                             }
  3477.                                
  3478.                         }
  3479.                        
  3480.                     }
  3481.                        
  3482.                 $output .= '</div>';                   
  3483.                
  3484.             /**
  3485.              * Select field */
  3486.              
  3487.             }elseif($field_type == "select"){
  3488.                    
  3489.                 if($is_terms)
  3490.                     $filter_type = "taxonomy";         
  3491.                 else
  3492.                     $filter_type = "custom_field";
  3493.                
  3494.                 $select_extra_class = ($search_all_option == "yes") ? ' cspml_show_all' : '';
  3495.                     $filter_type;
  3496.                
  3497.                 if($filter_container != "map"){
  3498.                                                            
  3499.                     $output .= '<div class="cspml_fs_label row" for="'.$field_name.'" id="'.$field_name.'" data-map-id="'.$map_id.'">';
  3500.                         $output .= '<span class="cspml_label_text">'.$field_label.'</span>';
  3501.                         $output .= '<span class="cspml_toggle_btn" data-field-name="'.$field_name.'" data-display-location="'.$filter_container.'" data-map-id="'.$map_id.'">';
  3502.                             $output .= '<img src="'.$arrow_down_img.'" style="height:15px; width:auto;" />';
  3503.                         $output .= '</span>';
  3504.                     $output .= '</div>';
  3505.                    
  3506.                 }else{
  3507.                    
  3508.                     $output .= '<div class="cspml_mfs_label row" for="'.$field_name.'" id="'.$field_name.'">';                                     
  3509.                         $output .= '<span class="cspml_label_text col-lg-10 col-sm-10 col-xs-11 col-md-10">'.$field_label.'</span>';
  3510.                     $output .= '</div>';
  3511.                    
  3512.                 }
  3513.                    
  3514.                 $output .= '<div class="cspml_fs_options_list" data-field-name="'.$field_name.'" data-display-location="'.$filter_container.'" data-map-id="'.$map_id.'" '.$display_css.'>';
  3515.                    
  3516.                     if(!empty($field_description))
  3517.                         $output .= '<div class="cspml_field_desc">'.$field_description.'</div>'; //@since 2.4
  3518.                    
  3519.                     $output .= '<input type="hidden" name="'.$field_name.'_filter_type" value="'.$filter_type.'" />';
  3520.                                        
  3521.                     $output .= '<div class="cspml_input_container">';
  3522.                     $output .= '<select name="'.$field_name.'" id="'.$field_name.'" data-filter-type="'.$filter_type.'" class="cspml_fs_selectize'.$select_extra_class.'" data-map-id="'.$map_id.'">';
  3523.                         $output .= '<option value=""></option>';
  3524.                        
  3525.                         /**
  3526.                          * List of options */
  3527.                          
  3528.                         foreach($field_options as $option){
  3529.                            
  3530.                             if($is_terms){
  3531.                                                                
  3532.                                 $label = $option->name;
  3533.                                 $name  = $option->slug;
  3534.                                 $id    = $option->term_id;
  3535.                                 $value = $option->term_id;
  3536.                                
  3537.                                 $filter_type = "taxonomy";
  3538.                                
  3539.                                 if($show_count == "yes")                                                                                                   
  3540.                                     $count_posts = $this->cspml_count_term_posts($field_name, $id, $post_type, $post_ids);
  3541.                                
  3542.                             }else{
  3543.                                
  3544.                                 $label = $name = $id = $value = $option;
  3545.                                
  3546.                                 if($show_count == "yes"){      
  3547.                                     $count_posts = $this->cspml_count_custom_field_posts($post_type, $field_name);
  3548.                                     $count_posts = isset($count_posts[$name]) ? $count_posts[$name] : '0';
  3549.                                 }
  3550.                                
  3551.                                 $filter_type = "custom_field";
  3552.                            
  3553.                             }
  3554.                            
  3555.                             $option_ids_array[] = $id;
  3556.                                                                                                                                
  3557.                             $output .= '<option value="'.$value.'">';
  3558.                                 $output .= ($symbol_position == "before") ? $symbol : '';
  3559.                                 $output .= ($show_count == "yes") ? $label.' ('.$count_posts.')' : $label;
  3560.                                 $output .= ($symbol_position == "after") ? $symbol : '';
  3561.                             $output .= '</option>';                                        
  3562.                        
  3563.                             /**
  3564.                              * Show all option */
  3565.                              
  3566.                             if($search_all_option == "yes" && $i++ == $count_options){
  3567.                                 $output .= '<option class="cspml_show_all" value="'.implode(',', $option_ids_array).'">';
  3568.                                     $output .= ($symbol_position == "before") ? $symbol : '';
  3569.                                     $output .= $search_all_text;
  3570.                                     $output .= ($symbol_position == "after") ? $symbol : '';
  3571.                                 $output .= '</option>';                                        
  3572.                             }
  3573.        
  3574.                         }
  3575.                
  3576.                     $output .= '</select>';
  3577.                     $output .= '</div>';
  3578.                
  3579.                 $output .= '</div>';       
  3580.                
  3581.             /**
  3582.              * Number field */
  3583.              
  3584.             }elseif($field_type == "number"){
  3585.                
  3586.                 $field_options = (array) str_replace($this->cspml_exclude_from_field_options, array('', ''), $field_options);
  3587.                
  3588.                 $implode_options = '';
  3589.                    
  3590.                 if($is_terms){
  3591.                    
  3592.                     $filter_type = "taxonomy";         
  3593.                    
  3594.                     $taxonomy_options = array();
  3595.                    
  3596.                     foreach($field_options as $option){
  3597.                        
  3598.                         $option = (array) $option;
  3599.                        
  3600.                         if(isset($option['name']))
  3601.                             $taxonomy_options[] = $option['name'];
  3602.                     }
  3603.                    
  3604.                     $field_options = $taxonomy_options;
  3605.                    
  3606.                     $implode_options = implode('', $taxonomy_options);
  3607.                    
  3608.                 }else{
  3609.                    
  3610.                     $filter_type = "custom_field";
  3611.                    
  3612.                     $implode_options = implode('', $field_options);
  3613.                    
  3614.                 }
  3615.                
  3616.                 if(is_numeric(floor($implode_options))){
  3617.                        
  3618.                     $min_value = min($field_options);
  3619.                     $max_value = max($field_options) == $min_value ? $min_value + 10 : max($field_options);
  3620.                    
  3621.                     if($filter_container != "map"){
  3622.                                                                
  3623.                         $output .= '<div class="cspml_fs_label row" for="'.$field_name.'" id="'.$field_name.'" data-map-id="'.$map_id.'">';
  3624.                             $output .= '<span class="cspml_label_text">'.$field_label.'</span>';
  3625.                             $output .= '<span class="cspml_toggle_btn" data-field-name="'.$field_name.'" data-display-location="'.$filter_container.'" data-map-id="'.$map_id.'">';
  3626.                                 $output .= '<img src="'.$arrow_down_img.'" style="height:15px; width:auto;" />';
  3627.                             $output .= '</span>';
  3628.                         $output .= '</div>';
  3629.                        
  3630.                     }else{
  3631.                        
  3632.                         $output .= '<div class="cspml_mfs_label row" for="'.$field_name.'" id="'.$field_name.'">';                                     
  3633.                             $output .= '<span class="cspml_label_text col-lg-10 col-sm-10 col-xs-11 col-md-10">'.$field_label.'</span>';
  3634.                         $output .= '</div>';
  3635.                        
  3636.                     }
  3637.                    
  3638.                     $output .= '<div class="cspml_fs_options_list" data-field-name="'.$field_name.'" data-display-location="'.$filter_container.'" data-map-id="'.$map_id.'" '.$display_css.'>';
  3639.                    
  3640.                         if(!empty($field_description))
  3641.                             $output .= '<div class="cspml_field_desc">'.$field_description.'</div>'; //@since 2.4
  3642.                    
  3643.                         $output .= '<input type="hidden" name="'.$field_name.'_filter_type" value="'.$filter_type.'" />';
  3644.                    
  3645.                         $output .= '<div class="cspml_input_container">';
  3646.                        
  3647.                             $output .= '<div data-trigger="spinner" class="input_spinner cspml_fs_number_field">';
  3648.                                
  3649.                                 $output .= '<div class="cspml_spinner_btn"><a href="javascript:;" data-spin="down"><span>&nbsp;</span></a></div>';
  3650.                                
  3651.                                 $output .= '<div class="cspml_spinner_symbol">';
  3652.                                     $output .= ($symbol_position == "before" && !empty($symbol)) ? $symbol : '&nbsp;';
  3653.                                 $output .= '</div>';
  3654.                                
  3655.                                 $output .= '<div class="cspml_input_container">';
  3656.                                     $output .= '<input type="text" name="'.$field_name.'" value="'.$min_value.'" data-filter-type="'.$filter_type.'" data-rule="quantity" data-min="'.$min_value.'" data-max="'.$max_value.'" class="cspml_type_text_like" />';
  3657.                                 $output .= '</div>';
  3658.                                
  3659.                                 $output .= '<div class="cspml_spinner_symbol">';
  3660.                                     $output .= ($symbol_position == "after" && !empty($symbol)) ? $symbol : '&nbsp;';
  3661.                                 $output .= '</div>';
  3662.                                
  3663.                                 $output .= '<div class="cspml_spinner_btn"><a href="javascript:;" data-spin="up"><span>&nbsp;</span></a></div>';
  3664.                                
  3665.                             $output .= '</div>';
  3666.                            
  3667.                             $output .= '<div class="clear-both"></div>';
  3668.                                                    
  3669.                             $output .= '<div class="cspml_reset_spinner"><a data-map-id="'.$map_id.'" data-field-name="'.$field_name.'" data-display-location="'.$filter_container.'">'.apply_filters('__any', esc_html__('Any', 'cspml')).'</a></div>';   
  3670.                            
  3671.                         $output .= '</div>';
  3672.                        
  3673.                     $output .= '</div>';   
  3674.                
  3675.                 }
  3676.                                            
  3677.             /**
  3678.              * Double Range slider */
  3679.              
  3680.             }elseif($field_type == "double_slider"){
  3681.                
  3682.                 $field_options = (array) str_replace($this->cspml_exclude_from_field_options, array('', ''), $field_options);
  3683.                
  3684.                 $implode_options = '';
  3685.                    
  3686.                 if($is_terms){
  3687.                    
  3688.                     $filter_type = "taxonomy";         
  3689.                    
  3690.                     $taxonomy_options = array();
  3691.                    
  3692.                     foreach($field_options as $option){
  3693.                        
  3694.                         $option = (array) $option;
  3695.                        
  3696.                         if(isset($option['name']))
  3697.                             $taxonomy_options[] = $option['name'];
  3698.                     }
  3699.                    
  3700.                     $field_options = $taxonomy_options;
  3701.                    
  3702.                     $implode_options = implode('', $taxonomy_options);
  3703.                    
  3704.                 }else{
  3705.                    
  3706.                     $filter_type = "custom_field";
  3707.                    
  3708.                     $implode_options = implode('', $field_options);
  3709.                    
  3710.                 }
  3711.                
  3712.                 if(is_numeric(floor($implode_options))){
  3713.  
  3714.                     $min_value = (min($field_options)-10 < 1) ? 1 : min($field_options)-10;
  3715.                     $max_value = max($field_options) == $min_value ? $min_value + 10 : max($field_options)+10;
  3716.                    
  3717.                     if($filter_container != "map"){
  3718.                                                                
  3719.                         $output .= '<div class="cspml_fs_label row" for="'.$field_name.'" id="'.$field_name.'" data-map-id="'.$map_id.'">';
  3720.                             $output .= '<span class="cspml_label_text">'.$field_label.'</span>';
  3721.                             $output .= '<span class="cspml_toggle_btn" data-field-name="'.$field_name.'" data-display-location="'.$filter_container.'" data-map-id="'.$map_id.'">';
  3722.                                 $output .= '<img src="'.$arrow_down_img.'" style="height:15px; width:auto;" />';
  3723.                             $output .= '</span>';
  3724.                         $output .= '</div>';
  3725.                        
  3726.                     }else{
  3727.                        
  3728.                         $output .= '<div class="cspml_mfs_label row" for="'.$field_name.'" id="'.$field_name.'">';                                     
  3729.                             $output .= '<span class="cspml_label_text col-lg-10 col-sm-10 col-xs-11 col-md-10">'.$field_label.'</span>';
  3730.                         $output .= '</div>';
  3731.                        
  3732.                     }
  3733.                    
  3734.                     $output .= '<div class="cspml_fs_options_list" data-field-name="'.$field_name.'" data-display-location="'.$filter_container.'" data-map-id="'.$map_id.'" '.$display_css.'>';
  3735.                    
  3736.                         if(!empty($field_description))
  3737.                             $output .= '<div class="cspml_field_desc">'.$field_description.'</div>'; //@since 2.4
  3738.                    
  3739.                         if($symbol_position == "before")
  3740.                             $prefix = 'data-prefix="'.$symbol.'"';             
  3741.                         elseif($symbol_position == "after")
  3742.                             $prefix = 'data-postfix="'.$symbol.'"';
  3743.                         else $prefix = '';
  3744.                    
  3745.                         $output .= '<input type="hidden" name="'.$field_name.'_filter_type" value="'.$filter_type.'" />';
  3746.                    
  3747.                         $output .= '<div class="cspml_input_container">';
  3748.                             $output .= '<input type="text" name="'.$field_name.'" class="cspml_fs_slider_range" data-min="'.$min_value.'" data-max="'.$max_value.'" data-values-separator=" to " data-prettify-separator="," data-filter-type="'.$filter_type.'" data-type="double" '.$prefix.' />';
  3749.                         $output .= '</div>';
  3750.                        
  3751.                     $output .= '</div>';   
  3752.                    
  3753.                 }
  3754.                                            
  3755.             /**
  3756.              * Single slider */
  3757.              
  3758.             }elseif($field_type == "single_slider"){
  3759.                
  3760.                 $field_options = (array) str_replace($this->cspml_exclude_from_field_options, array('', ''), $field_options);
  3761.                
  3762.                 $implode_options = '';
  3763.                    
  3764.                 if($is_terms){
  3765.                    
  3766.                     $filter_type = "taxonomy";         
  3767.                    
  3768.                     $taxonomy_options = array();
  3769.                    
  3770.                     foreach($field_options as $option){
  3771.                        
  3772.                         $option = (array) $option;
  3773.                        
  3774.                         if(isset($option['name']))
  3775.                             $taxonomy_options[] = $option['name'];
  3776.                     }
  3777.                    
  3778.                     $field_options = $taxonomy_options;
  3779.                    
  3780.                     $implode_options = implode('', $taxonomy_options);
  3781.                    
  3782.                 }else{
  3783.                    
  3784.                     $filter_type = "custom_field";
  3785.                    
  3786.                     $implode_options = implode('', $field_options);
  3787.                    
  3788.                 }
  3789.                
  3790.                 if(is_numeric(floor($implode_options))){
  3791.                                
  3792.                     $min_value = (min($field_options)-10 < 1) ? 1 : min($field_options)-10;
  3793.                     $max_value = max($field_options) == $min_value ? $min_value + 10 : max($field_options)+10;
  3794.                    
  3795.                     if($filter_container != "map"){
  3796.                                                                
  3797.                         $output .= '<div class="cspml_fs_label row" for="'.$field_name.'" id="'.$field_name.'" data-map-id="'.$map_id.'">';
  3798.                             $output .= '<span class="cspml_label_text">'.$field_label.'</span>';
  3799.                             $output .= '<span class="cspml_toggle_btn" data-field-name="'.$field_name.'" data-display-location="'.$filter_container.'" data-map-id="'.$map_id.'">';
  3800.                                 $output .= '<img src="'.$arrow_down_img.'" style="height:15px; width:auto;" />';
  3801.                             $output .= '</span>';
  3802.                         $output .= '</div>';
  3803.                        
  3804.                     }else{
  3805.                        
  3806.                         $output .= '<div class="cspml_mfs_label row" for="'.$field_name.'" id="'.$field_name.'">';                                     
  3807.                             $output .= '<span class="cspml_label_text col-lg-10 col-sm-10 col-xs-11 col-md-10">'.$field_label.'</span>';
  3808.                         $output .= '</div>';
  3809.                        
  3810.                     }
  3811.                    
  3812.                     $output .= '<div class="cspml_fs_options_list" data-field-name="'.$field_name.'" data-display-location="'.$filter_container.'" data-map-id="'.$map_id.'" '.$display_css.'>';
  3813.                        
  3814.                         if(!empty($field_description))
  3815.                             $output .= '<div class="cspml_field_desc">'.$field_description.'</div>'; //@since 2.4
  3816.                    
  3817.                         if($symbol_position == "before")
  3818.                             $prefix = 'data-prefix="'.$symbol.'"';             
  3819.                         elseif($symbol_position == "after")
  3820.                             $prefix = 'data-postfix="'.$symbol.'"';
  3821.                         else $prefix = '';
  3822.                    
  3823.                         $output .= '<input type="hidden" name="'.$field_name.'_filter_type" value="'.$filter_type.'" />';
  3824.                            
  3825.                         $output .= '<div class="cspml_input_container">';
  3826.                             $output .= '<input type="text" name="'.$field_name.'" class="cspml_fs_slider_range" value="'.$min_value.'" data-min="'.$min_value.'" data-max="'.$max_value.'" data-filter-type="'.$filter_type.'" data-type="single" '.$prefix.' />';
  3827.                         $output .= '</div>';   
  3828.                        
  3829.                     $output .= '</div>';   
  3830.                
  3831.                 }
  3832.                
  3833.             /**
  3834.              * Datepicker (for custom fields)
  3835.              * @since 2.4 */
  3836.  
  3837.             }elseif($field_type == "datepicker"){
  3838.                
  3839.                 $datepicker_atts = array_merge(
  3840.                     $field_atts,
  3841.                     array(
  3842.                         'map_id' => $map_id,
  3843.                         'post_type' => $post_type,
  3844.                         'post_ids' => $post_ids,
  3845.                         'filter_type' => 'custom_field',
  3846.                     )
  3847.                 );
  3848.                
  3849.                 $output .= $this->cspml_custom_field_datepicker($datepicker_atts);     
  3850.  
  3851.             }
  3852.            
  3853.             return $output;
  3854.            
  3855.         }
  3856.        
  3857.        
  3858.         /**
  3859.          * This will display a text field in the filter for keyword search
  3860.          *
  3861.          * @since 2.2
  3862.          * @updated 2.3
  3863.          */
  3864.         function cspml_keyword_search_field($map_id, $post_type, $post_ids){
  3865.                        
  3866.             $output = '';
  3867.            
  3868.             $filter_container = 'list';
  3869.            
  3870.             if($this->cspml_keyword_filter_option == 'yes'){
  3871.                
  3872.                 $field_name = 'cspml_keyword';             
  3873.                 $field_label = $this->cspml_keyword_filter_label;
  3874.                 $field_placeholder = $this->cspml_keyword_filter_placeholder;
  3875.                 $field_description = $this->cspml_keyword_filter_description; //@since 2.4
  3876.                 $display_status = $this->cspml_keyword_display_status; //@since 2.3
  3877.                
  3878.                 $arrow_down_img = apply_filters('cspml_filter_arrow_down_img', $this->plugin_url.'img/arrow-down.png', str_replace('map', '', $map_id));
  3879.                
  3880.                 $output .= '<div class="cspml_fs_item_container col-lg-12 col-xs-12 col-sm-12 col-md-12" data-map-id="'.$map_id.'">';
  3881.                
  3882.                     if($filter_container != "map"){
  3883.                                                                
  3884.                         $output .= '<div class="cspml_fs_label row" for="'.$field_name.'" id="'.$field_name.'" data-map-id="'.$map_id.'">';
  3885.                             $output .= '<span class="cspml_label_text">'.$field_label.'</span>';
  3886.                             $output .= '<span class="cspml_toggle_btn" data-field-name="'.$field_name.'" data-display-location="'.$filter_container.'" data-map-id="'.$map_id.'">';
  3887.                                 $output .= '<img src="'.$arrow_down_img.'" style="height:15px; width:auto;" />';
  3888.                             $output .= '</span>';
  3889.                         $output .= '</div>';
  3890.                        
  3891.                     }else{
  3892.                        
  3893.                         $output .= '<div class="cspml_mfs_label row" for="'.$field_name.'" id="'.$field_name.'">';                                     
  3894.                             $output .= '<span class="cspml_label_text col-lg-10 col-sm-10 col-xs-11 col-md-10">'.$field_label.'</span>';
  3895.                         $output .= '</div>';
  3896.                        
  3897.                     }
  3898.                    
  3899.                     $display_css = ($display_status == 'open') ? '' : ' style="display:none;"';
  3900.                    
  3901.                     $output .= '<div class="cspml_fs_options_list" data-field-name="'.$field_name.'" data-display-location="'.$filter_container.'" data-map-id="'.$map_id.'" '.$display_css.'>';
  3902.                            
  3903.                         $output .= '<input type="hidden" name="'.$field_name.'_filter_type" value="keyword" />';
  3904.                        
  3905.                         if(!empty($field_description))
  3906.                             $output .= '<div class="cspml_field_desc">'.$field_description.'</div>'; //@since 2.4
  3907.                                                    
  3908.                         $output .= '<div class="cspml_input_container">';
  3909.                             $output .= '<input type="text" name="'.$field_name.'" class="'.$field_name.' cspml_type_text_like" value="" placeholder="'.$field_placeholder.'" data-map-id="'.$map_id.'" />';
  3910.                         $output .= '</div>';
  3911.                    
  3912.                     $output .= '</div>';
  3913.                                                
  3914.                 $output .= '</div>';
  3915.                    
  3916.             }
  3917.            
  3918.             return $output;
  3919.            
  3920.         }
  3921.        
  3922.        
  3923.         /**
  3924.          * This will display a datepicker in the filter that allows filtering ...
  3925.          * ... posts by publish date
  3926.          *
  3927.          * @since 2.1
  3928.          * @updated 2.3
  3929.          */
  3930.         function cspml_posts_publish_date_field($map_id, $post_type, $post_ids){
  3931.                        
  3932.             $output = '';
  3933.            
  3934.             $filter_container = 'list';
  3935.            
  3936.             if($this->cspml_date_filter_option == 'yes'){
  3937.                
  3938.                 $display_status = $this->cspml_date_filter_display_status; //@since 2.3
  3939.                    
  3940.                 /**
  3941.                  * Get Datepicker parameters */
  3942.            
  3943.                 $date_filter_params = isset($this->cspml_date_filter_parameters[0])
  3944.                     ? $this->cspml_date_filter_parameters[0]
  3945.                     : array();
  3946.                
  3947.                 $field_name = 'cspml_posts_date_filter';
  3948.                 $field_label = $this->cspml_setting_exists('date_filter_label', $date_filter_params, 'Posts publish date');
  3949.                 $field_description = $this->cspml_setting_exists('date_filter_description', $date_filter_params, ''); //@since 2.4
  3950.                
  3951.                 $arrow_down_img = apply_filters('cspml_filter_arrow_down_img', $this->plugin_url.'img/arrow-down.png', str_replace('map', '', $map_id));
  3952.                
  3953.                 $date_filter_type = $this->cspml_setting_exists('date_filter_type', $date_filter_params, 'exact_date');                
  3954.                
  3955.                 /**
  3956.                  * Set date format */
  3957.                
  3958.                 $date_format = $this->cspml_setting_exists('date_format', $date_filter_params, 'ymd');
  3959.                 $exclude_from_date = $this->cspml_setting_exists('exclude_date_atts', $date_filter_params, array());
  3960.                 $final_date_format = implode(
  3961.                     '/',
  3962.                     str_replace(
  3963.                         'yy',
  3964.                         'yyyy',
  3965.                         str_split(
  3966.                             str_replace(
  3967.                                 array('d', 'm', 'y'),
  3968.                                 array('dd', 'mm', 'yy'),
  3969.                                 str_replace($exclude_from_date, '', $date_format) /** 1. Remove attribute ("y" OR "m" OR "d") from date format ("ymd" or "dmy") **/
  3970.                             ), /** 2. Replace ["ymd" To "yymmdd"] OR ["dmy" To "ddmmyy"] **/
  3971.                             2
  3972.                         ) /** 3. Replace [from "yymmdd" To "array('yy', 'mm', 'dd')"] OR ["ddmmyy" To "array('dd', 'mm', 'yy')"] **/
  3973.                     ) /** 4. Replace [array('yyyy', 'mm', 'dd') To array('yyyy', 'mm', 'dd')] OR ["array('dd', 'mm', 'yy')" To "array('dd', 'mm', 'yyyy')"] **/
  3974.                 ); /** 5. Implode ["array('yyyy', 'mm', 'dd')" To "yyyy/mm/dd"] OR ["array('dd', 'mm', 'yy')" To "dd/mm/yyyy"] **/
  3975.                    
  3976.                 $language = $this->cspml_setting_exists('language', $date_filter_params, 'en-US');
  3977.                 $start_date = $this->cspml_setting_exists('start_date', $date_filter_params, '');
  3978.                 $end_date = $this->cspml_setting_exists('end_date', $date_filter_params, '');                  
  3979.                
  3980.                 $start_view = str_replace(                 
  3981.                     array('days', 'months', 'years'),
  3982.                     array(0, 1, 2),
  3983.                     $this->cspml_setting_exists('start_view', $date_filter_params, 'days')
  3984.                 ); // 0: days | 1: months | 2: years
  3985.                
  3986.                 $week_start = str_replace(                 
  3987.                     array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'),
  3988.                     array(0, 1, 2, 3, 4, 5, 6, 7),
  3989.                     $this->cspml_setting_exists('week_start', $date_filter_params, 'sunday')
  3990.                 ); // 0: Sunday | 1: Monday | 2: Tuesday | 3: Wednesday | 4: Thursday | 5: Friday | 6: Saturday
  3991.                
  3992.                 $year_first = str_replace(
  3993.                     array('yes', 'no'),
  3994.                     array('true', 'false'),
  3995.                     $this->cspml_setting_exists('year_first', $date_filter_params, 'no')
  3996.                 );
  3997.                
  3998.                 $year_suffix = $this->cspml_setting_exists('year_suffix', $date_filter_params, '');
  3999.                
  4000.                 $auto_show = str_replace(
  4001.                     array('yes', 'no'),
  4002.                     array('true', 'false'),
  4003.                     $this->cspml_setting_exists('auto_show', $date_filter_params, 'no')
  4004.                 );
  4005.                
  4006.                 $auto_hide = str_replace(
  4007.                     array('yes', 'no'),
  4008.                     array('true', 'false'),
  4009.                     $this->cspml_setting_exists('auto_hide', $date_filter_params, 'no')
  4010.                 );
  4011.                
  4012.                 $inline = str_replace(
  4013.                     array('yes', 'no'),
  4014.                     array('true', 'false'),
  4015.                     $this->cspml_setting_exists('inline', $date_filter_params, 'no')
  4016.                 );
  4017.                
  4018.                 $output .= '<div class="cspml_fs_item_container col-lg-12 col-xs-12 col-sm-12 col-md-12" data-map-id="'.$map_id.'">';
  4019.                
  4020.                     if($filter_container != "map"){
  4021.                                                                
  4022.                         $output .= '<div class="cspml_fs_label row" for="'.$field_name.'" id="'.$field_name.'" data-map-id="'.$map_id.'">';
  4023.                             $output .= '<span class="cspml_label_text">'.$field_label.'</span>';
  4024.                             $output .= '<span class="cspml_toggle_btn" data-field-name="'.$field_name.'" data-display-location="'.$filter_container.'" data-map-id="'.$map_id.'">';
  4025.                                 $output .= '<img src="'.$arrow_down_img.'" style="height:15px; width:auto;" />';
  4026.                             $output .= '</span>';
  4027.                         $output .= '</div>';
  4028.                        
  4029.                     }else{
  4030.                        
  4031.                         $output .= '<div class="cspml_mfs_label row" for="'.$field_name.'" id="'.$field_name.'">';                                     
  4032.                             $output .= '<span class="cspml_label_text col-lg-10 col-sm-10 col-xs-11 col-md-10">'.$field_label.'</span>';
  4033.                         $output .= '</div>';
  4034.                        
  4035.                     }
  4036.                    
  4037.                     /**
  4038.                      * Whether we'll filter using two dates or one date.
  4039.                      * Two dates, means we need to datepickers */
  4040.                      
  4041.                     $nbr_datepickers = ($date_filter_type == 'date_range') ? 2 : 1;
  4042.                    
  4043.                     $display_css = ($display_status == 'open') ? '' : ' style="display:none;"';                  
  4044.                      
  4045.                     $output .= '<div class="cspml_fs_options_list" data-field-name="'.$field_name.'" data-display-location="'.$filter_container.'" data-map-id="'.$map_id.'" '.$display_css.'>';
  4046.                        
  4047.                         $output .= '<div class="cspml_input_container">';
  4048.                            
  4049.                             if(!empty($field_description))
  4050.                                 $output .= '<div class="cspml_field_desc">'.$field_description.'</div>'; //@since 2.4
  4051.                            
  4052.                             /**
  4053.                              * Datepickers */
  4054.                            
  4055.                             for($i = 1; $i <= $nbr_datepickers; $i++){
  4056.                                
  4057.                                 $new_field_name = $field_name.'_'.str_replace(array(1, 2), array('start', 'end'), $i);
  4058.                            
  4059.                                 $output .= '<input type="hidden" name="'.$new_field_name.'_filter_type" value="'.$date_filter_type.'" />';
  4060.                                
  4061.                                 $output .= '<div class="cspml_datepicker_container">';
  4062.                                
  4063.                                     if($nbr_datepickers == 2){
  4064.                                         $output .= '<div class="cspml_datepicker_label_'.$i.'">';
  4065.                                             $output .= str_replace(
  4066.                                                 array(1, 2),
  4067.                                                 array(
  4068.                                                     apply_filters('__start_date', esc_html__('Start date', 'cspml')),
  4069.                                                     apply_filters('__start_date', esc_html__('End date', 'cspml'))
  4070.                                                 ),
  4071.                                                 $i
  4072.                                             );
  4073.                                         $output .= '</div>';
  4074.                                     }
  4075.                                    
  4076.                                     $output .= '<div style="float:left; width:75%;">';
  4077.                                         $output .= '<input type="text" data-toggle="cspml_datepicker_'.$i.'" name="'.$new_field_name.'" data-map-id="'.$map_id.'" class="cspml_fs_datepicker cspml_type_text_like" />';
  4078.                                     $output .= '</div>';
  4079.                                    
  4080.                                     $output .= '<div style="float:left; width:25%;">';
  4081.                                         $output .= '<div class="cspm_datepicker_trigger_'.$map_id.'_'.$i.' cspm_border_radius cspm_border_shadow">';
  4082.                                             $output .= '<img src="'.apply_filters('cspml_calendar_img', $this->plugin_url.'img/calendar.png', str_replace('map', '', $map_id)).'" />';
  4083.                                         $output .= '</div>';
  4084.                                     $output .= '</div>';
  4085.                                    
  4086.                                     $output .= '<div style="clear:both;"></div>';
  4087.                                    
  4088.                                 $output .= '</div>';
  4089.                                
  4090.                                 if($inline == 'true')
  4091.                                     $output .= '<div class="cspml_inline_datepicker_container_'.$i.'" data-map-id="'.$map_id.'"></div>';
  4092.                            
  4093.                             }
  4094.                            
  4095.                         $output .= '</div>';
  4096.                        
  4097.                         /**
  4098.                          * Load Datepickers language */
  4099.                        
  4100.                         wp_enqueue_script('cspml_datepicker_i18n_'.$language);                 
  4101.                        
  4102.                         /**
  4103.                          * Build Datepickers script */
  4104.                          
  4105.                         $datepicker_js_script = "jQuery(document).ready(function($){";
  4106.                        
  4107.                         for($i = 1; $i <= $nbr_datepickers; $i++){
  4108.                            
  4109.                             /**
  4110.                              * Disable auto show option for the second datepicker in filter type "date_range" */
  4111.                              
  4112.                             if($nbr_datepickers == 2 && $i == 2)
  4113.                                 $auto_show = 'false';
  4114.                            
  4115.                             /**
  4116.                              * Datepicker script */
  4117.                                
  4118.                             $new_field_name = $field_name.'_'.str_replace(array(1, 2), array('start', 'end'), $i);
  4119.                                    
  4120.                             $datepicker_js_script .= "
  4121.                             $('[name=".$new_field_name."][data-map-id=".$map_id."]').cspmlDatepicker({
  4122.                                 autoShow: ".strval($auto_show).",
  4123.                                 autoHide: ".strval($auto_hide).",
  4124.                                 inline: ".strval($inline).",
  4125.                                 container: 'div.cspml_inline_datepicker_container_".$i."[data-map-id=".$map_id."]',
  4126.                                 trigger: '.cspm_datepicker_trigger_".$map_id."_".$i."', // A element for triggering the datepicker
  4127.                                 date: null, // Initial date
  4128.                                 language: '".$language."',
  4129.                                 format: '".$final_date_format."',
  4130.                                 startDate: '".$start_date."',
  4131.                                 endDate: '".$end_date."',
  4132.                                 startView: ".$start_view.",
  4133.                                 weekStart: ".$week_start.",
  4134.                                 yearFirst: ".strval($year_first).",
  4135.                                 yearSuffix: '".$year_suffix."',
  4136.                             });";
  4137.    
  4138.                         }
  4139.                                            
  4140.                         $datepicker_js_script .= "});";
  4141.                        
  4142.                         /**
  4143.                          * Add Datepicker script */
  4144.                            
  4145.                         $localize_script_handle = ($this->plugin_settings['combine_files'] == "combine") ? 'cspml_combined_scripts' : 'cspml_scripts';
  4146.                        
  4147.                         wp_add_inline_script($localize_script_handle, $datepicker_js_script);
  4148.                    
  4149.                     $output .= '</div>';   
  4150.                
  4151.                 $output .= '</div>';   
  4152.                    
  4153.             }
  4154.            
  4155.             return $output;
  4156.                    
  4157.         }
  4158.        
  4159.                
  4160.         /**
  4161.          * This will build the Posts publish date_query args ...
  4162.          * ... to add to the filter query args.
  4163.          *
  4164.          * [@filter_args] | The selected date(s) returned by the filter form when sending a filter request.
  4165.          *
  4166.          * @since 2.1
  4167.          */
  4168.         function cspml_posts_publish_date_query($filter_args = array()){
  4169.                            
  4170.             $date_query_args = $start_date_attributes = $end_date_attributes = array();
  4171.            
  4172.             /**
  4173.              * Check if the start date field exists
  4174.              * The array [@filter_args['cspml_posts_date_filter_start']] contains the following:
  4175.              * 1 - The filter type. ("extact_date", "after_date", "before_date" and "date_range")
  4176.              * 2 - The selected start date. */
  4177.              
  4178.             if(is_array($filter_args) && array_key_exists('cspml_posts_date_filter_start', $filter_args)){
  4179.                
  4180.                 if(count($filter_args['cspml_posts_date_filter_start']) > 0){
  4181.                    
  4182.                     /**
  4183.                      * Get Datepicker parameters */
  4184.                
  4185.                     $date_filter_params = (array) unserialize(stripslashes($this->cspml_get_map_option('date_filter_param', serialize(array())))); //@since 2.1
  4186.                        
  4187.                     $date_filter_params = isset($date_filter_params[0])
  4188.                         ? (array) $date_filter_params[0]
  4189.                         : array();
  4190.                    
  4191.                     $date_format = $this->cspml_setting_exists('date_format', $date_filter_params, 'ymd');
  4192.                     $exclude_from_date = $this->cspml_setting_exists('exclude_date_atts', $date_filter_params, array());
  4193.                     $final_date_format = str_split(
  4194.                         str_replace($exclude_from_date, '', $date_format), /** 1. Remove attribute ("y" OR "m" OR "d") from date format ("ymd" or "dmy") **/
  4195.                         1
  4196.                     ); /** 2. Replace [from "ymd" To "array('y', 'm', 'd')"] OR ["dmy" To "array('d', 'm', 'y')"] **/
  4197.                    
  4198.                     /**
  4199.                      * Get the start date */
  4200.                    
  4201.                     if(isset($filter_args['cspml_posts_date_filter_start'][1])){
  4202.                        
  4203.                         /**
  4204.                          * Explode the start date from "yy/mm/dd" to "array(yy, mm, dd)" */
  4205.                          
  4206.                         $start_date = explode('/', $filter_args['cspml_posts_date_filter_start'][1]);
  4207.                            
  4208.                         /**
  4209.                          * Combine the date format with the selected date to build ...
  4210.                          * ... array of date attibutes.
  4211.                          *
  4212.                          * Array(
  4213.                          *  [y] => selected year,
  4214.                          *  [m] => selected month,
  4215.                          *  [d] => selected day
  4216.                          * ) */
  4217.                          
  4218.                         $start_date_array = array_combine($final_date_format, $start_date);
  4219.                        
  4220.                         /**
  4221.                          * Build the Start "date_query" array
  4222.                          *
  4223.                          * Array(
  4224.                          *  [year] => selected year,
  4225.                          *  [month] => selected month,
  4226.                          *  [day] => selected day
  4227.                          * ) */
  4228.                          
  4229.                         foreach($final_date_format as $date_attribute){
  4230.                             if($date_attribute == 'y')
  4231.                                 $start_date_attributes['year'] = $start_date_array['y'];
  4232.                             elseif($date_attribute == 'm')
  4233.                                 $start_date_attributes['month'] = $start_date_array['m'];
  4234.                             elseif($date_attribute == 'd')
  4235.                                 $start_date_attributes['day'] = $start_date_array['d'];
  4236.                         }
  4237.                    
  4238.                         /**
  4239.                          * Get end date
  4240.                          * Note: If end date exists, this means that the filter type is "data_range (Between two dates)" */
  4241.                        
  4242.                         if(isset($filter_args['cspml_posts_date_filter_end'][1])){
  4243.                        
  4244.                             /**
  4245.                              * Explode the end date from "yy/mm/dd" to "array(yy, mm, dd)" */
  4246.                                                          
  4247.                             $end_date = (array_key_exists('cspml_posts_date_filter_end', $filter_args))
  4248.                                 ? explode('/', $filter_args['cspml_posts_date_filter_end'][1])
  4249.                                 : array();
  4250.                                                            
  4251.                             if(is_array($end_date) && count($end_date) > 0){
  4252.                                
  4253.                                 /**
  4254.                                  * Combine the date format with the selected date to build ...
  4255.                                  * ... array of date attibutes.
  4256.                                  *
  4257.                                  * Array(
  4258.                                  *  [y] => selected year,
  4259.                                  *  [m] => selected month,
  4260.                                  *  [d] => selected day
  4261.                                  * ) */
  4262.                                                    
  4263.                                 $end_date_array = array_combine($final_date_format, $end_date);
  4264.                            
  4265.                                 /**
  4266.                                  * Build the End "date_query" array
  4267.                                  *
  4268.                                  * Array(
  4269.                                  *  [year] => selected year,
  4270.                                  *  [month] => selected month,
  4271.                                  *  [day] => selected day
  4272.                                  * ) */
  4273.                            
  4274.                                 foreach($final_date_format as $date_attribute){
  4275.                                     if($date_attribute == 'y')
  4276.                                         $end_date_attributes['year'] = $end_date_array['y'];
  4277.                                     elseif($date_attribute == 'm')
  4278.                                         $end_date_attributes['month'] = $end_date_array['m'];
  4279.                                     elseif($date_attribute == 'd')
  4280.                                         $end_date_attributes['day'] = $end_date_array['d'];
  4281.                                 }
  4282.                                
  4283.                             }
  4284.                                
  4285.                         }
  4286.  
  4287.                         /**
  4288.                          * Build the "date_query" args */
  4289.                        
  4290.                         if(isset($filter_args['cspml_posts_date_filter_start'][0])){
  4291.                            
  4292.                             /**
  4293.                              * Get the filter type */
  4294.                                                                        
  4295.                             $filter_type = $filter_args['cspml_posts_date_filter_start'][0];
  4296.                        
  4297.                             if($filter_type == 'exact_date'){
  4298.                            
  4299.                                 $date_query_args = array(
  4300.                                     $start_date_attributes,
  4301.                                     'compare' => '=',
  4302.                                 );
  4303.                            
  4304.                             }elseif($filter_type == 'after_date'){
  4305.                                
  4306.                                 $date_query_args = array(
  4307.                                     array(
  4308.                                         'after' => $start_date_attributes,
  4309.                                         'inclusive' => false, // Don't get the posts created in the same date in "after" parameters
  4310.                                     )
  4311.                                 );
  4312.                            
  4313.                             }elseif($filter_type == 'before_date'){
  4314.                                
  4315.                                 $date_query_args = array(
  4316.                                     array(
  4317.                                         'before' => $start_date_attributes,
  4318.                                         'inclusive' => false, // Don't get the posts created in the same date in "before" parameters
  4319.                                     )
  4320.                                 );
  4321.                                
  4322.                             }elseif($filter_type == 'date_range'){
  4323.                                
  4324.                                 $date_query_args = array(
  4325.                                     array(
  4326.                                         'after' => array_merge(
  4327.                                            
  4328.                                             $start_date_attributes,
  4329.                                                                                        
  4330.                                             /**
  4331.                                              * Note: set (H:m:s) to 0 (day start) to get post created the same date in "after" parameters ...
  4332.                                              * ... when attribute "inclusive" is set to TRUE! */
  4333.        
  4334.                                             array(                                                                     
  4335.                                                 'hour' => '0',
  4336.                                                 'minute' => '0',
  4337.                                                 'second' => '0',
  4338.                                             )
  4339.                                            
  4340.                                         ),
  4341.                                         'before' => array_merge(
  4342.                                            
  4343.                                             $end_date_attributes,
  4344.                                            
  4345.                                             /**
  4346.                                              * Note: set (H:m:s) to 23:59:59 (day end) to get post created the same date in "before" parameters ...
  4347.                                              * ... when attribute "inclusive" is set to TRUE! */
  4348.                                            
  4349.                                             array(
  4350.                                                 'hour' => '23',
  4351.                                                 'minute' => '59',
  4352.                                                 'second' => '59',  
  4353.                                             )
  4354.                                                                    
  4355.                                         ),
  4356.                                         'inclusive' => true, // Get the post created in the same date in "after" & "before" parameters
  4357.                                         'relation' => 'AND',
  4358.                                         'compare' => 'BETWEEN',
  4359.                                     )
  4360.                                 );
  4361.                                
  4362.                             }
  4363.                            
  4364.                         }
  4365.                        
  4366.                     }
  4367.                    
  4368.                 }
  4369.                
  4370.             }
  4371.            
  4372.             return $date_query_args;
  4373.  
  4374.         }
  4375.        
  4376.        
  4377.         /**
  4378.          * This will display a datepicker in the filter that allows filtering ...
  4379.          * ... posts by a custom field type datepicker
  4380.          *
  4381.          * @since 2.4
  4382.          */
  4383.         function cspml_custom_field_datepicker($field_atts){
  4384.            
  4385.             $defaults = array(
  4386.                 'map_id' => '',
  4387.                 'post_type' => '',
  4388.                 'post_ids' => '',
  4389.                 'field_name' => '',
  4390.                 'field_label' => '',
  4391.                 'field_description' => '',
  4392.                 'field_options' => array(),
  4393.                 'symbol' => '',
  4394.                 'symbol_position' => 'text',
  4395.                 'search_all_option' => 'false',
  4396.                 'search_all_text' => apply_filters('__all', esc_html__('All', 'cspml')),
  4397.                 'show_count' => '',
  4398.                 'compare_parameter' => '',
  4399.                 'default_value' => '',
  4400.                 'display_status' => 'open',
  4401.                 'filter_type' => '',
  4402.                
  4403.                 /**
  4404.                  * Custom fields Datepicker parameters
  4405.                  * @since 2.4 */
  4406.                
  4407.                 'date_format' => '',
  4408.                 'date_separator' => '',
  4409.                 'start_date' => '',
  4410.                 'end_date' => '',
  4411.                 'week_start' => '',
  4412.             );
  4413.            
  4414.             extract( wp_parse_args( $field_atts, $defaults ) );
  4415.            
  4416.             $output = '';
  4417.            
  4418.             $filter_container = 'list';
  4419.                
  4420.             $display_status = $display_status;
  4421.                
  4422.             /**
  4423.              * Get Datepicker parameters */
  4424.  
  4425.             $arrow_down_img = apply_filters('cspml_filter_arrow_down_img', $this->plugin_url.'img/arrow-down.png', str_replace('map', '', $map_id));
  4426.            
  4427.             $output .= '<div class="cspml_fs_item_container col-lg-12 col-xs-12 col-sm-12 col-md-12" data-map-id="'.$map_id.'">';
  4428.            
  4429.                 if($filter_container != "map"){
  4430.                                                            
  4431.                     $output .= '<div class="cspml_fs_label row" for="'.$field_name.'" id="'.$field_name.'" data-map-id="'.$map_id.'">';
  4432.                         $output .= '<span class="cspml_label_text">'.$field_label.'</span>';
  4433.                         $output .= '<span class="cspml_toggle_btn" data-field-name="'.$field_name.'" data-display-location="'.$filter_container.'" data-map-id="'.$map_id.'">';
  4434.                             $output .= '<img src="'.$arrow_down_img.'" style="height:15px; width:auto;" />';
  4435.                         $output .= '</span>';
  4436.                     $output .= '</div>';
  4437.                    
  4438.                 }else{
  4439.                    
  4440.                     $output .= '<div class="cspml_mfs_label row" for="'.$field_name.'" id="'.$field_name.'">';                                     
  4441.                         $output .= '<span class="cspml_label_text col-lg-10 col-sm-10 col-xs-11 col-md-10">'.$field_label.'</span>';
  4442.                     $output .= '</div>';
  4443.                    
  4444.                 }
  4445.                
  4446.                 $display_css = ($display_status == 'open') ? '' : ' style="display:none;"';                  
  4447.                    
  4448.                 /**
  4449.                  * Add Range Datepicker */
  4450.                    
  4451.                 $output .= '<div class="cspml_fs_options_list" data-field-name="'.$field_name.'" data-display-location="'.$filter_container.'" data-map-id="'.$map_id.'" '.$display_css.'>';
  4452.                    
  4453.                     if(!empty($field_description))
  4454.                         $output .= '<div class="cspml_field_desc">'.$field_description.'</div>'; //@since 2.4
  4455.                    
  4456.                     $output .= '<input type="hidden" name="'.$field_name.'_filter_type" value="custom_field" />';
  4457.                                                
  4458.                     $output .= '<div class="cspml_input_container">';
  4459.                        
  4460.                         /**
  4461.                          * Range Datepicker */
  4462.                            
  4463.                         $output .= '<input type="text" name="'.$field_name.'" id="date_range_value_'.$field_name.'" data-map-id="'.$map_id.'" value="" style="display:none;">';            
  4464.                        
  4465.                         $output .= '<div style="float:left; width:75%;">';
  4466.                             $output .= '<span id="date_range_'.$field_name.'" data-map-id="'.$map_id.'" class="cspml_fs_range_datepicker cspml_type_text_like">'.apply_filters('__select_a_date', esc_html__('Select a date', 'cspml')).'</span>';
  4467.                         $output .= '</div>';
  4468.                                    
  4469.                         $output .= '<div style="float:left; width:25%;">';                     
  4470.                            
  4471.                             $output .= '<span id="open_date_range_'.$field_name.'" class="cspml_fs_open_range_datepicker cspm_border_shadow cspm_border_radius" data-map-id="'.$map_id.'">';
  4472.                                 $output .= '<img src="'.apply_filters('cspml_calendar2_img', $this->plugin_url.'img/calendar2.png', str_replace('map', '', $map_id)).'" />';
  4473.                             $output .= '</span>';
  4474.                                                            
  4475.                             $output .= '<span id="clear_date_range_'.$field_name.'" data-map-id="'.$map_id.'" class="cspml_fs_clear_range_datepicker cspm_border_shadow cspm_border_radius">';
  4476.                                 $output .= '<img src="'.apply_filters('cspml_clear_date_img', $this->plugin_url.'img/delete.png', str_replace('map', '', $map_id)).'" />';
  4477.                             $output .= '</span>';
  4478.                        
  4479.                         $output .= '</div>';
  4480.                        
  4481.                         $output .= '<div style="clear:both;"></div>';
  4482.                                    
  4483.                     $output .= '</div>';
  4484.                    
  4485.                     /**
  4486.                      * Build Range Datepicker script */
  4487.        
  4488.                     $single_date = $single_month = (in_array($compare_parameter, array('IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'))) ? 'false' : 'true';
  4489.                      
  4490.                     $date_separator = str_replace(                 
  4491.                         array('slash', 'dash', 'dot', 'space', 'none'),
  4492.                         array('/', '-', '.', ' ', ''),
  4493.                         $date_separator
  4494.                     );
  4495.                    
  4496.                     $explode_date_format = explode('/', $date_format); // From "YYYY/MM/DD" to array("YYYY", "MM", "DD")
  4497.                    
  4498.                     $date_format = implode($date_separator, $explode_date_format); // From "array("YYYY", "MM", "DD")" to "YYYY{@date_separator}MM{@date_separator}DD"
  4499.                    
  4500.                     $start_and_end_date_format = 'Y'.$date_separator.'m'.$date_separator.'d'; // Default to "Y{@date_separator}m{@date_separator}d"
  4501.                    
  4502.                     if(isset($explode_date_format[0], $explode_date_format[2])){
  4503.                         if($explode_date_format[0] == 'YYYY'){
  4504.                             $start_and_end_date_format = 'Y'.$date_separator.'m'.$date_separator.'d';
  4505.                         }elseif($explode_date_format[0] == 'YY'){
  4506.                             $start_and_end_date_format = 'y'.$date_separator.'m'.$date_separator.'d';
  4507.                         }elseif($explode_date_format[0] == 'DD' && $explode_date_format[2] == 'YYYY'){
  4508.                             $start_and_end_date_format = 'd'.$date_separator.'m'.$date_separator.'Y';
  4509.                         }elseif($explode_date_format[0] == 'DD' && $explode_date_format[2] == 'YY'){
  4510.                             $start_and_end_date_format = 'd'.$date_separator.'m'.$date_separator.'y';
  4511.                         }
  4512.                     }
  4513.                    
  4514.                     if(!empty($start_date)){
  4515.                         $start_date_obj = new DateTime($start_date);
  4516.                         $start_date = date($start_and_end_date_format, $start_date_obj->getTimestamp());
  4517.                     }else $start_date = false;
  4518.                    
  4519.                     if(!empty($end_date)){
  4520.                         $end_date_obj = new DateTime($end_date);
  4521.                         $end_date = date($start_and_end_date_format, $end_date_obj->getTimestamp());
  4522.                     }else $end_date = false;
  4523.                    
  4524.                     $datepicker_js_script = "jQuery(document).ready(function($){";
  4525.        
  4526.                         $datepicker_js_script .= "$('span#date_range_".$field_name."[data-map-id=".$map_id."]').dateRangePicker({
  4527.                             autoClose: true,
  4528.                             format: '".$date_format."',
  4529.                             separator: '".apply_filters('cspml_range_datepicker_separator', ' ... ', $map_id)."',
  4530.                             language: 'auto',
  4531.                             startOfWeek: '".$week_start."',
  4532.                             startDate: '".$start_date."',
  4533.                             endDate: '".$end_date."',
  4534.                             time: { enabled: false },
  4535.                             minDays: 0,
  4536.                             maxDays: 0,
  4537.                             inline:false,
  4538.                             container:'body',
  4539.                             singleDate:".$single_date.",
  4540.                             singleMonth:".$single_month.",
  4541.                             showTopbar: true,
  4542.                             monthSelect: true,
  4543.                             yearSelect: true,
  4544.                             getValue: function(){
  4545.                                 return this.innerHTML;
  4546.                             },
  4547.                             setValue: function(s){
  4548.                                 this.innerHTML = s;
  4549.                                 $('input#date_range_value_".$field_name."[data-map-id=".$map_id."]').val(s);
  4550.                                 $('span#open_date_range_".$field_name."[data-map-id=".$map_id."]').hide();
  4551.                                 $('span#clear_date_range_".$field_name."[data-map-id=".$map_id."]').show();
  4552.                             }                          
  4553.                         });
  4554.                        
  4555.                         $('span#open_date_range_".$field_name."[data-map-id=".$map_id."]').click(function(evt){
  4556.                             evt.stopPropagation();
  4557.                             $('span#date_range_".$field_name."[data-map-id=".$map_id."]').data('dateRangePicker').open();
  4558.                         });
  4559.  
  4560.                         $('span#clear_date_range_".$field_name."[data-map-id=".$map_id."]').click(function(evt){
  4561.                             evt.stopPropagation();
  4562.                             $('span#date_range_".$field_name."[data-map-id=".$map_id."]').data('dateRangePicker').clear();
  4563.                             $('span#date_range_".$field_name."[data-map-id=".$map_id."]').html('".apply_filters('__select_a_date', esc_html__('Select a date', 'cspml'))."');
  4564.                             $('input#date_range_value_".$field_name."[data-map-id=".$map_id."]').val();
  4565.                             $(this).hide();
  4566.                             $('span#open_date_range_".$field_name."[data-map-id=".$map_id."]').show();
  4567.                         });";              
  4568.                                            
  4569.                     $datepicker_js_script .= "});";
  4570.                    
  4571.                     /**
  4572.                      * Add Range Datepicker script */
  4573.                            
  4574.                     $localize_script_handle = ($this->plugin_settings['combine_files'] == "combine") ? 'cspml_combined_scripts' : 'cspml_scripts';
  4575.                    
  4576.                     wp_add_inline_script($localize_script_handle, $datepicker_js_script);
  4577.                    
  4578.                 $output .= '</div>';   
  4579.            
  4580.             $output .= '</div>';   
  4581.            
  4582.             return $output;
  4583.                    
  4584.         }
  4585.                    
  4586.        
  4587.         /**
  4588.          * The filter form Query
  4589.          *
  4590.          * @since 1.0
  4591.          */
  4592.         function cspml_faceted_search_query(){
  4593.            
  4594.             if (!class_exists('CspmMainMap'))
  4595.                 return;
  4596.            
  4597.             $CspmMainMap = CspmMainMap::this();
  4598.            
  4599.             /**
  4600.              * Reload map settings */
  4601.              
  4602.             $this->map_settings = (isset($_POST['map_settings'])) ? $_POST['map_settings'] : $this->map_settings;
  4603.        
  4604.             if(!isset($_POST['filter_args']) && !isset($_POST['map_id'])){
  4605.                 $post_ids = array();
  4606.                 print_r(json_encode($post_ids));
  4607.                 die();
  4608.             }
  4609.        
  4610.             $post_ids = $tax_query = $custom_fields = $date_query_args = array();
  4611.            
  4612.             /**
  4613.              * [@filter_args] The selected fields and their values */
  4614.              
  4615.             $filter_args = isset($_POST['filter_args']) ? $_POST['filter_args'] : array();
  4616.        
  4617.             $map_id = esc_attr($_POST['map_id']);
  4618.            
  4619.             /**
  4620.              * [@post_ids] Post IDs of all post to show */
  4621.              
  4622.             $post_ids = isset($_POST['post_ids']) ? $_POST['post_ids'] : array();
  4623.            
  4624.             /**
  4625.              * [@init_post_ids] Post IDs of all post we've started with before doing any filter */
  4626.              
  4627.             $init_post_ids = !empty($_POST['init_post_ids']) ? explode(',', esc_attr($_POST['init_post_ids'])) : array();          
  4628.                                                
  4629.             /**
  4630.              * Get The ID Of The Page Where The Shortcode was Executed */
  4631.              
  4632.             $shortcode_page_id = esc_attr($_POST['shortcode_page_id']);
  4633.             $page_template = esc_attr($_POST['page_template']);
  4634.             $template_tax_query  = esc_attr($_POST['template_tax_query']);
  4635.            
  4636.             $post__in = array();
  4637.            
  4638.             /**
  4639.              * Usefull for re-executing hooks after AJAX load */
  4640.              
  4641.             do_action('cspml_before_faceted_search_query', $shortcode_page_id, $page_template, $template_tax_query);
  4642.  
  4643.             if(count($filter_args) > 0){
  4644.  
  4645.                 /**
  4646.                  * Get the post_ids that were the result of the search form in the map ("Progress Map Search").
  4647.                  * That way, the faceted search query will take in concediration that it should only search within a given post_ids */
  4648.                  
  4649.                 if(isset($_SESSION['cspml_posts_in_search'][$map_id]['filtering']) && $_SESSION['cspml_posts_in_search'][$map_id]['filtering'] == true && isset($_SESSION['cspml_posts_in_search'][$map_id]['post_ids']))
  4650.                     $post__in = $_SESSION['cspml_posts_in_search'][$map_id]['post_ids'];
  4651.                
  4652.                 /**
  4653.                  * Taxonomies
  4654.                  * Note: Do not use the variables initialized in the constructor.
  4655.                  * Vars in the constructor cannot be called in an AJAX request! */
  4656.  
  4657.                 $cspml_taxonomies_array = (array) unserialize(stripslashes($this->cspml_get_map_option('cslf_taxonomies', serialize(array()))));
  4658.                     $cspml_taxonomies = array();
  4659.                     foreach($cspml_taxonomies_array as $key => $values){
  4660.                         $cspml_taxonomies[$values['taxonomy_name']] = $values;
  4661.                     }
  4662.                
  4663.                 $cspml_taxonomy_relation_param = $this->cspml_get_map_option('cslf_taxonomy_relation_param', 'AND');
  4664.  
  4665.                 /**
  4666.                  * Custom fields
  4667.                  * Note: Do not use the variables initialized in the constructor.
  4668.                  * Vars in the constructor cannot be called in an AJAX request! */
  4669.                  
  4670.                 $cspml_custom_fields_array = (array) unserialize(stripslashes($this->cspml_get_map_option('cslf_custom_fields', serialize(array()))));
  4671.                     $cspml_custom_fields = array();
  4672.                     foreach($cspml_custom_fields_array as $key => $values){
  4673.                         if(isset($values['custom_field_name']))
  4674.                             $cspml_custom_fields[$values['custom_field_name']] = $values;
  4675.                     }
  4676.                
  4677.                 $cspml_custom_field_relation_param = $this->cspml_get_map_option('cslf_custom_field_relation_param', 'AND');
  4678.  
  4679.                 $taxonomies_array = $meta_query_array = array();
  4680.                
  4681.                 /**
  4682.                  * When used in a taxonomy page (archive), we need to add the current tax to the query */
  4683.                  
  4684.                 if(!empty($template_tax_query)){
  4685.                    
  4686.                     $explode_template_tax_query = explode(',', $template_tax_query);
  4687.                    
  4688.                     if(count($explode_template_tax_query == 2)){
  4689.                        
  4690.                         $taxonomies_array[] = array(
  4691.                             'taxonomy' => $explode_template_tax_query[0], // taxonomy name
  4692.                             'field' => 'slug', // Compare with term_ids
  4693.                             'terms' => array($explode_template_tax_query[1]), // Selected values
  4694.                             'operator' => 'IN', // Operator parameter for select values
  4695.                         );
  4696.                                                
  4697.                     }
  4698.                    
  4699.                 }
  4700.  
  4701.                 /**
  4702.                  * Loop throught the fields in the filter form */
  4703.                  
  4704.                 foreach($filter_args as $field_key => $field_values){
  4705.  
  4706.                     /**
  4707.                      * Get the name of the field which in fact could be the name of ...
  4708.                      * ... the taxonomy or the custom_field */
  4709.                      
  4710.                     $attr_name = $field_key;
  4711.                    
  4712.                     /**
  4713.                      * The field values are:
  4714.                      * @The field_type (taxonomy or custom_field)
  4715.                      * @The selected values (terms, tags, custom field value, ...) */
  4716.                        
  4717.                     /**
  4718.                      * If the field_values contains more that one value
  4719.                      * The first value in the array is always the field_type (taxonomy or custom_field) ...
  4720.                      * ... So if there's only the field_type, no need to continue cause there will be no selected values */
  4721.  
  4722.                     if(count($field_values) > 1){
  4723.                        
  4724.                         /**
  4725.                          * If the field_type is a taxonomy
  4726.                          * Create taxonomy args */
  4727.                              
  4728.                         if(isset($field_values[0]) && $field_values[0] == "taxonomy"){
  4729.                            
  4730.                             /**
  4731.                              * Get Taxonomy Name */
  4732.                              
  4733.                             $tax_name = $attr_name;
  4734.                            
  4735.                             /**
  4736.                              * Remove the field_type from the array of selected values */
  4737.                              
  4738.                             unset($field_values[0]);
  4739.                        
  4740.                             /**
  4741.                              * Get the value of the field from the data registered for its tag in the admin */
  4742.                              
  4743.                             $tag_array_value = (array) $cspml_taxonomies[$tax_name];
  4744.                    
  4745.                             /**
  4746.                              * Call the taxonomy operator and make sure it exists */
  4747.  
  4748.                             if(isset($tag_array_value['taxonomy_operator_param'])){
  4749.                                
  4750.                                 $operator = $tag_array_value['taxonomy_operator_param'];
  4751.                                
  4752.                                 /**
  4753.                                  * Check if the select values array is not empty */
  4754.                                  
  4755.                                 if(count($field_values) > 0){
  4756.                                    
  4757.                                     $array_compare = array('IN', 'NOT IN', 'AND');
  4758.                                    
  4759.                                     if(in_array($operator, $array_compare))
  4760.                                         $value = array_values(array_unique($field_values));
  4761.                                     else $value = implode('', $field_values);
  4762.  
  4763.                                     if($tag_array_value['taxonomy_display_type'] == "double_slider")
  4764.                                         $value = explode(';', implode('', $value));
  4765.                                    
  4766.                                     if(!empty($value)){
  4767.                                            
  4768.                                         /**
  4769.                                          * And create the args array for the query */
  4770.                                          
  4771.                                         $taxonomies_array[] = array(
  4772.                                             'taxonomy' => $tax_name, // taxonomy name
  4773.                                             'field' => 'id', // Compare with term_ids
  4774.                                             'terms' => $value, // Selected values
  4775.                                             'operator' => $operator, // Operator parameter for select values
  4776.                                         );
  4777.                                    
  4778.                                     }
  4779.                                    
  4780.                                 }
  4781.                            
  4782.                             }
  4783.                        
  4784.                         /**
  4785.                          * If the field_type is a custom field
  4786.                          * Create custom fields args */
  4787.                          
  4788.                         }elseif(isset($field_values[0]) && $field_values[0] == "custom_field"){
  4789.    
  4790.                             /**
  4791.                              * Get custom field Name */
  4792.                              
  4793.                             $custom_field_name = $attr_name;
  4794.                            
  4795.                             /**
  4796.                              * Remove the field_type from the array of selected values */
  4797.                              
  4798.                             unset($field_values[0]);
  4799.                            
  4800.                             /**
  4801.                              * Get the value of the field from the data registered for its tag in the admin */
  4802.                              
  4803.                             $tag_array_value = (array) $cspml_custom_fields[$custom_field_name];
  4804.                
  4805.                             /**
  4806.                              * Call the custom field operator and make sure it exists */
  4807.                              
  4808.                             if(isset($tag_array_value['custom_field_compare_param'])){ 
  4809.                                
  4810.                                 $compare = $tag_array_value['custom_field_compare_param'];
  4811.                                
  4812.                                 /**
  4813.                                  * Check if the select values array is not empty */
  4814.                                  
  4815.                                 if(count($field_values) > 0){
  4816.                
  4817.                                     $array_compare = array('IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN');
  4818.                                    
  4819.                                     if(in_array($compare, $array_compare)){
  4820.                                         $value = array_values(array_unique($field_values));
  4821.                                     }else $value = implode('', $field_values);
  4822.                                    
  4823.                                     if($tag_array_value['custom_field_display_type'] == "double_slider"){
  4824.                                         $value = explode(';', implode('', $value));
  4825.                                     }elseif($tag_array_value['custom_field_display_type'] == "datepicker" && in_array($compare, $array_compare)) //@since 2.4
  4826.                                         $value = explode(apply_filters('cspml_range_datepicker_separator', ' ... ', $map_id), implode('', $value)); //@since 2.4
  4827.  
  4828.                                     if(!empty($value)){
  4829.                                        
  4830.                                         $args = array(
  4831.                                             'key' => $custom_field_name, // custom field name
  4832.                                             'value' => $value, // Selected values
  4833.                                             'compare' => $compare, // Operator parameter for select values
  4834.                                         );
  4835.                                        
  4836.                                         $numeric_fields = array('double_slider', 'single_slider', 'number');
  4837.                                        
  4838.                                         if(in_array($tag_array_value['custom_field_display_type'], $numeric_fields))
  4839.                                             $args = array_merge($args, array('type' => 'NUMERIC'));
  4840.                                                    
  4841.                                         /**
  4842.                                          * And create the args array for the query */
  4843.                                          
  4844.                                         $meta_query_array[] = $args;
  4845.                                    
  4846.                                     }
  4847.                                    
  4848.                                 }
  4849.                            
  4850.                             }
  4851.                            
  4852.                         }
  4853.                        
  4854.                     }
  4855.                    
  4856.                 }
  4857.                    
  4858.                 /**
  4859.                  * At the end, collect all taxonomies and custom fields args array for the query */
  4860.                  
  4861.                 $tax_query = (count($taxonomies_array) == 0) ? array() : array('tax_query' => array_merge(array('relation' => $cspml_taxonomy_relation_param), $taxonomies_array));
  4862.                 $custom_fields = (count($meta_query_array) == 0) ? array() : array('meta_query' => array_merge(array('relation' => $cspml_custom_field_relation_param), $meta_query_array));       
  4863.                
  4864.                 /**
  4865.                  * Get the "date_query" args based on the field "Posts publish date"
  4866.                  * @since 2.1 */
  4867.                  
  4868.                 $date_query_args = $this->cspml_posts_publish_date_query($filter_args);
  4869.                 $custom_fields = (count($meta_query_array) == 0) ? array() : array('meta_query' => array_merge(array('relation' => $cspml_custom_field_relation_param), $meta_query_array));       
  4870.                  
  4871.             }
  4872.                
  4873.             if(count($init_post_ids) > 0){
  4874.  
  4875.                 /**
  4876.                  * post status */
  4877.                  
  4878.                 $status = unserialize(stripslashes($this->cspml_get_map_option('items_status', serialize('publish'))));
  4879.                
  4880.                 /**
  4881.                  * Query */
  4882.                  
  4883.                 $query_args = array(
  4884.                     'post_type' => $this->cspml_get_map_option('post_type'),
  4885.                     'post_status' => $status,
  4886.                     'post__in' => (is_array($post__in) && count($post__in) > 0) ? $post__in : $init_post_ids,
  4887.                     'posts_per_page' => -1,
  4888.                     'orderby' => 'post__in',                           
  4889.                     'fields' => 'ids',
  4890.                 );
  4891.                
  4892.                 /**
  4893.                  * Get the keyword term from the field "keyword"
  4894.                  * @since 2.2 */
  4895.                
  4896.                 if(is_array($filter_args) && array_key_exists('cspml_keyword', $filter_args)){
  4897.                     if($this->cspml_setting_exists(1, $filter_args['cspml_keyword']))
  4898.                         $query_args['s'] = $filter_args['cspml_keyword'][1];
  4899.                 }
  4900.                
  4901.                 /**
  4902.                  * Add "date_query" args
  4903.                  * @since 2.1
  4904.                  */
  4905.                
  4906.                 if(is_array($date_query_args) && count($date_query_args) > 0){
  4907.                     $query_args['date_query'] = $date_query_args;
  4908.                 }
  4909.  
  4910.                 /**
  4911.                  * Taxonomies query args */
  4912.                  
  4913.                 if(count($tax_query) > 0 && isset($tax_query['tax_query'])) $query_args = array_merge($query_args, array('tax_query' => $tax_query['tax_query']));
  4914.                
  4915.                 /**
  4916.                  * Custom fields query args */
  4917.                  
  4918.                 if(count($custom_fields) > 0 && isset($custom_fields['meta_query'])){
  4919.                     $query_args = array_merge(
  4920.                         $query_args,
  4921.                         array('meta_query' => $custom_fields['meta_query'])            
  4922.                     );         
  4923.                 }                      
  4924.  
  4925.                 /**
  4926.                  * Add Progress Map Custom Fields to the query */
  4927.                
  4928.                 $cspm_extra_custom_fields = unserialize(stripslashes($this->cspml_get_map_option('custom_fields', serialize(array()))));
  4929.  
  4930.                 if(!empty($cspm_extra_custom_fields)){
  4931.                    
  4932.                     $cspm_custom_fields = $CspmMainMap->cspm_parse_query_meta_fields($cspm_extra_custom_fields, $this->cspml_get_map_option('custom_field_relation_param'));
  4933.                    
  4934.                     if(count($custom_fields) == 0 && count($cspm_custom_fields) > 0){      
  4935.                                    
  4936.                         $query_args = array_merge(
  4937.                             $query_args,
  4938.                             array('meta_query' => $cspm_custom_fields['meta_query'])
  4939.                         );
  4940.                        
  4941.                     }elseif(count($custom_fields) > 0 && count($cspm_custom_fields) > 0){
  4942.                        
  4943.                         unset($cspm_custom_fields['meta_query']['relation']);
  4944.                        
  4945.                         $custom_field_query = array_merge(
  4946.                             $query_args['meta_query'],
  4947.                             $cspm_custom_fields['meta_query']
  4948.                         );
  4949.                        
  4950.                         $query_args['meta_query'] = $custom_field_query;
  4951.                        
  4952.                     }
  4953.                 }
  4954.                
  4955.                 $post_ids = query_posts( $query_args );
  4956.  
  4957.             }else $post_ids = $init_post_ids;
  4958.            
  4959.             /**
  4960.              * Save the post_ids in a session in order not to start ...
  4961.              * ... calling all posts when paginating or sorting by or filtering */
  4962.              
  4963.             $_SESSION['cspml_listings_filter_post_ids'][$map_id] = $post_ids;
  4964.  
  4965.             print_r(json_encode($post_ids));
  4966.            
  4967.             die();
  4968.            
  4969.         }
  4970.        
  4971.        
  4972.         /**
  4973.          * Count the number of posts per term
  4974.          *
  4975.          * @since 1.0
  4976.          */
  4977.         function cspml_count_term_posts($taxonomy, $term_id, $post_type, $post_ids = array()){
  4978.                    
  4979.             if (!class_exists('CspmMainMap'))
  4980.                 return;
  4981.            
  4982.             $CspmMainMap = CspmMainMap::this();
  4983.                
  4984.             /**
  4985.              * post status */
  4986.              
  4987.             $status = (count($CspmMainMap->post_status) == 0) ? 'publish' : $CspmMainMap->post_status;             
  4988.  
  4989.             if(count($post_ids) > 0){
  4990.                                                                        
  4991.                 $posts = get_posts(array(
  4992.                     'post_type' => $post_type,
  4993.                     'post_status' => $status,
  4994.                     'tax_query' => array(
  4995.                         array(
  4996.                             'taxonomy' => $taxonomy,
  4997.                             'field' => 'id',
  4998.                             'terms' => $term_id
  4999.                         )
  5000.                     ),
  5001.                     'post__in' => $post_ids,
  5002.                     'fields' => 'ids',
  5003.                     'posts_per_page' => -1,
  5004.                     'suppress_filters' => false,
  5005.                 ));
  5006.  
  5007.                 wp_reset_postdata();
  5008.    
  5009.             }else $posts = array();
  5010.            
  5011.             return count($posts);
  5012.        
  5013.         }
  5014.        
  5015.        
  5016.         /**
  5017.          * Count the number of posts by custom field value
  5018.          *
  5019.          * @since 1.0
  5020.          */
  5021.         function cspml_count_custom_field_posts($post_type, $custom_field_name){
  5022.                        
  5023.             if (!class_exists('CspmMainMap'))
  5024.                 return;
  5025.            
  5026.             $CspmMainMap = CspmMainMap::this();
  5027.                
  5028.             /**
  5029.              * post status */
  5030.              
  5031.             $status = (count($CspmMainMap->post_status) == 0) ? 'publish' : $CspmMainMap->post_status;             
  5032.            
  5033.             $custom_field_values = $this->cspml_get_meta_values( $custom_field_name, $post_type, $status );
  5034.            
  5035.             $meta_counts = array();
  5036.            
  5037.             if( !empty( $custom_field_values ) ) {
  5038.                
  5039.                 $meta_counts = array();
  5040.                
  5041.                 foreach( $custom_field_values as $meta_value ){
  5042.                    
  5043.                     $meta_counts[$meta_value] = ( isset( $meta_counts[$meta_value] ) ) ? $meta_counts[$meta_value] + 1 : 1;
  5044.                    
  5045.                 }
  5046.                
  5047.             }
  5048.            
  5049.             return $meta_counts;
  5050.            
  5051.         }
  5052.        
  5053.        
  5054.         /**
  5055.          * Get All Values For A Custom Field Key
  5056.          *
  5057.          * @key: The meta_key of the post meta
  5058.          * @type: The name of the custom post type
  5059.          * @status: The status of the post
  5060.          *
  5061.          * @since 1.0
  5062.          * @updated 1.2
  5063.          */
  5064.         function cspml_get_meta_values($key = '', $post_type = 'post', $status = 'publish', $orderby = 'pm.meta_value', $order = 'ASC') {
  5065.            
  5066.             global $wpdb;
  5067.            
  5068.             if( empty( $key ) )
  5069.                 return;
  5070.            
  5071.             /**
  5072.              * [@status_cndt] Different SQL condition depending on the number of selected status!
  5073.              * @since 1.2 */
  5074.              
  5075.             if(is_array($status)){
  5076.                 $sql_statuses = implode("','", $status);
  5077.                 $sql_statuses = "'".$sql_statuses."'";
  5078.                 $status_cndt = "(p.post_status IN (".$sql_statuses."))";
  5079.             }else $status_cndt = "p.post_status = '".$status."' ";
  5080.  
  5081.             $results = $wpdb->get_col( $wpdb->prepare( "
  5082.                 SELECT pm.meta_value FROM {$wpdb->postmeta} pm
  5083.                 LEFT JOIN {$wpdb->posts} p ON p.ID = pm.post_id
  5084.                 WHERE pm.meta_key = '%s'
  5085.                 AND pm.meta_value != ''
  5086.                 AND ".$status_cndt."
  5087.                 AND p.post_type = '%s'
  5088.                 ORDER BY ".$orderby." ".$order."
  5089.             ", $key, $post_type ) );
  5090.            
  5091.             return $results;
  5092.            
  5093.         }
  5094.    
  5095.     }
  5096.    
  5097. }
Add Comment
Please, Sign In to add comment