Passed
Push — dependabot/composer/phpcompati... ( 2dc932 )
by
unknown
05:12
created
includes/template-tags.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -9,6 +9,6 @@
 block discarded – undo
9 9
  * Adds text domain.
10 10
  */
11 11
 function lsx_search_load_plugin_textdomain() {
12
-	load_plugin_textdomain( 'lsx-search', false, basename( LSX_SEARCH_PATH ) . '/languages' );
12
+     load_plugin_textdomain( 'lsx-search', false, basename( LSX_SEARCH_PATH ) . '/languages' );
13 13
 }
14 14
 add_action( 'init', 'lsx_search_load_plugin_textdomain' );
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -9,6 +9,6 @@
 block discarded – undo
9 9
  * Adds text domain.
10 10
  */
11 11
 function lsx_search_load_plugin_textdomain() {
12
-	load_plugin_textdomain( 'lsx-search', false, basename( LSX_SEARCH_PATH ) . '/languages' );
12
+	load_plugin_textdomain('lsx-search', false, basename(LSX_SEARCH_PATH).'/languages');
13 13
 }
14
-add_action( 'init', 'lsx_search_load_plugin_textdomain' );
14
+add_action('init', 'lsx_search_load_plugin_textdomain');
Please login to merge, or discard this patch.
includes/functions.php 2 patches
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -13,17 +13,17 @@  discard block
 block discarded – undo
13 13
  * @return array
14 14
  */
15 15
 function get_options() {
16
-	$options = array();
17
-	if ( function_exists( 'tour_operator' ) ) {
18
-		$options = get_option( '_lsx-to_settings', false );
19
-	} else {
20
-		$options = get_option( '_lsx_settings', false );
16
+     $options = array();
17
+     if ( function_exists( 'tour_operator' ) ) {
18
+          $options = get_option( '_lsx-to_settings', false );
19
+     } else {
20
+          $options = get_option( '_lsx_settings', false );
21 21
 
22
-		if ( false === $options ) {
23
-			$options = get_option( '_lsx_lsx-settings', false );
24
-		}
25
-	}
26
-	return $options;
22
+          if ( false === $options ) {
23
+               $options = get_option( '_lsx_lsx-settings', false );
24
+          }
25
+     }
26
+     return $options;
27 27
 }
28 28
 
29 29
 /**
@@ -32,26 +32,26 @@  discard block
 block discarded – undo
32 32
  * @return array
33 33
  */
34 34
 function get_restricted_post_types() {
35
-	$post_types = array(
36
-		'page',
37
-		'attachment',
38
-		'lesson',
39
-		'certificate',
40
-		'envira',
41
-		'tribe_organizer',
42
-		'tribe_venue',
43
-		'envira',
44
-		'reply',
45
-		'topic',
46
-		'popup',
47
-		'question',
48
-		'certificate_template',
49
-		'sensei_message',
50
-		'tribe_events',
51
-		'tip',
52
-		'quiz',
53
-		'forum',
54
-	);
55
-	$post_types = apply_filters( 'lsx_search_restricted_post_types', $post_types );
56
-	return $post_types;
35
+     $post_types = array(
36
+          'page',
37
+          'attachment',
38
+          'lesson',
39
+          'certificate',
40
+          'envira',
41
+          'tribe_organizer',
42
+          'tribe_venue',
43
+          'envira',
44
+          'reply',
45
+          'topic',
46
+          'popup',
47
+          'question',
48
+          'certificate_template',
49
+          'sensei_message',
50
+          'tribe_events',
51
+          'tip',
52
+          'quiz',
53
+          'forum',
54
+     );
55
+     $post_types = apply_filters( 'lsx_search_restricted_post_types', $post_types );
56
+     return $post_types;
57 57
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -14,13 +14,13 @@  discard block
 block discarded – undo
14 14
  */
15 15
 function get_options() {
16 16
 	$options = array();
17
-	if ( function_exists( 'tour_operator' ) ) {
18
-		$options = get_option( '_lsx-to_settings', false );
17
+	if (function_exists('tour_operator')) {
18
+		$options = get_option('_lsx-to_settings', false);
19 19
 	} else {
20
-		$options = get_option( '_lsx_settings', false );
20
+		$options = get_option('_lsx_settings', false);
21 21
 
22
-		if ( false === $options ) {
23
-			$options = get_option( '_lsx_lsx-settings', false );
22
+		if (false === $options) {
23
+			$options = get_option('_lsx_lsx-settings', false);
24 24
 		}
25 25
 	}
26 26
 	return $options;
@@ -52,6 +52,6 @@  discard block
 block discarded – undo
52 52
 		'quiz',
53 53
 		'forum',
54 54
 	);
55
-	$post_types = apply_filters( 'lsx_search_restricted_post_types', $post_types );
55
+	$post_types = apply_filters('lsx_search_restricted_post_types', $post_types);
56 56
 	return $post_types;
57 57
 }
Please login to merge, or discard this patch.
lsx-search.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@
 block discarded – undo
13 13
 
14 14
 // If this file is called directly, abort.
15 15
 if ( ! defined( 'WPINC' ) ) {
16
-	die;
16
+     die;
17 17
 }
18 18
 
19 19
 define( 'LSX_SEARCH_PATH', plugin_dir_path( __FILE__ ) );
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -12,17 +12,17 @@
 block discarded – undo
12 12
  */
13 13
 
14 14
 // If this file is called directly, abort.
15
-if ( ! defined( 'WPINC' ) ) {
15
+if (!defined('WPINC')) {
16 16
 	die;
17 17
 }
18 18
 
19
-define( 'LSX_SEARCH_PATH', plugin_dir_path( __FILE__ ) );
20
-define( 'LSX_SEARCH_CORE', __FILE__ );
21
-define( 'LSX_SEARCH_URL', plugin_dir_url( __FILE__ ) );
22
-define( 'LSX_SEARCH_VER', '1.5.1' );
19
+define('LSX_SEARCH_PATH', plugin_dir_path(__FILE__));
20
+define('LSX_SEARCH_CORE', __FILE__);
21
+define('LSX_SEARCH_URL', plugin_dir_url(__FILE__));
22
+define('LSX_SEARCH_VER', '1.5.1');
23 23
 
24 24
 /* ======================= Below is the Plugin Class init ========================= */
25 25
 
26
-require_once LSX_SEARCH_PATH . '/includes/template-tags.php';
27
-require_once LSX_SEARCH_PATH . '/includes/functions.php';
28
-require_once LSX_SEARCH_PATH . '/classes/class-lsx-search.php';
26
+require_once LSX_SEARCH_PATH.'/includes/template-tags.php';
27
+require_once LSX_SEARCH_PATH.'/includes/functions.php';
28
+require_once LSX_SEARCH_PATH.'/classes/class-lsx-search.php';
Please login to merge, or discard this patch.
classes/admin/class-settings-theme.php 2 patches
Indentation   +176 added lines, -176 removed lines patch added patch discarded remove patch
@@ -10,186 +10,186 @@  discard block
 block discarded – undo
10 10
  */
11 11
 class Settings_Theme {
12 12
 
13
-	/**
14
-	 * Holds class instance
15
-	 *
16
-	 * @since 1.0.0
17
-	 *
18
-	 * @var      object \lsx\search\classes\admin\Settings_Theme()
19
-	 */
20
-	protected static $instance = null;
13
+     /**
14
+      * Holds class instance
15
+      *
16
+      * @since 1.0.0
17
+      *
18
+      * @var      object \lsx\search\classes\admin\Settings_Theme()
19
+      */
20
+     protected static $instance = null;
21 21
 
22
-	/**
23
-	 * Will return true if this is the LSX Search settings page.
24
-	 *
25
-	 * @var array
26
-	 */
27
-	public $is_options_page = false;
22
+     /**
23
+      * Will return true if this is the LSX Search settings page.
24
+      *
25
+      * @var array
26
+      */
27
+     public $is_options_page = false;
28 28
 
29
-	/**
30
-	 * Holds the id and labels for the navigation.
31
-	 *
32
-	 * @var array
33
-	 */
34
-	public $navigation = array();
29
+     /**
30
+      * Holds the id and labels for the navigation.
31
+      *
32
+      * @var array
33
+      */
34
+     public $navigation = array();
35 35
 
36
-	/**
37
-	 * Contructor
38
-	 */
39
-	public function __construct() {
40
-		add_filter( 'cmb2_enqueue_css', array( $this, 'disable_cmb2_styles' ), 1, 1 );
41
-		add_action( 'cmb2_before_form', array( $this, 'generate_navigation' ), 10, 4 );
42
-		add_action( 'cmb2_before_title_field_row', array( $this, 'output_tab_open_div' ), 10, 1 );
43
-		add_action( 'cmb2_after_tab_closing_field_row', array( $this, 'output_tab_closing_div' ), 10, 1 );
44
-		add_action( 'cmb2_render_tab_closing', array( $this, 'cmb2_render_callback_for_tab_closing' ), 10, 5 );
45
-		add_filter( 'cmb2_sanitize_tab_closing', array( $this, 'cmb2_sanitize_tab_closing_callback' ), 10, 2 );
46
-		add_action( 'cmb2_after_form', array( $this, 'navigation_js' ), 10, 4 );
47
-		add_filter( 'cmb2_options_page_redirect_url', array( $this, 'add_tab_argument' ), 10, 1 );
48
-	}
36
+     /**
37
+      * Contructor
38
+      */
39
+     public function __construct() {
40
+          add_filter( 'cmb2_enqueue_css', array( $this, 'disable_cmb2_styles' ), 1, 1 );
41
+          add_action( 'cmb2_before_form', array( $this, 'generate_navigation' ), 10, 4 );
42
+          add_action( 'cmb2_before_title_field_row', array( $this, 'output_tab_open_div' ), 10, 1 );
43
+          add_action( 'cmb2_after_tab_closing_field_row', array( $this, 'output_tab_closing_div' ), 10, 1 );
44
+          add_action( 'cmb2_render_tab_closing', array( $this, 'cmb2_render_callback_for_tab_closing' ), 10, 5 );
45
+          add_filter( 'cmb2_sanitize_tab_closing', array( $this, 'cmb2_sanitize_tab_closing_callback' ), 10, 2 );
46
+          add_action( 'cmb2_after_form', array( $this, 'navigation_js' ), 10, 4 );
47
+          add_filter( 'cmb2_options_page_redirect_url', array( $this, 'add_tab_argument' ), 10, 1 );
48
+     }
49 49
 
50
-	/**
51
-	 * Return an instance of this class.
52
-	 *
53
-	 * @since 1.0.0
54
-	 *
55
-	 * @return    object \lsx\search\classes\admin\Settings_Theme()    A single instance of this class.
56
-	 */
57
-	public static function get_instance() {
58
-		// If the single instance hasn't been set, set it now.
59
-		if ( null == self::$instance ) {
60
-			self::$instance = new self();
61
-		}
62
-		return self::$instance;
63
-	}
50
+     /**
51
+      * Return an instance of this class.
52
+      *
53
+      * @since 1.0.0
54
+      *
55
+      * @return    object \lsx\search\classes\admin\Settings_Theme()    A single instance of this class.
56
+      */
57
+     public static function get_instance() {
58
+          // If the single instance hasn't been set, set it now.
59
+          if ( null == self::$instance ) {
60
+               self::$instance = new self();
61
+          }
62
+          return self::$instance;
63
+     }
64 64
 
65
-	/**
66
-	 * Disable CMB2 styles on front end forms.
67
-	 *
68
-	 * @return bool $enabled Whether to enable (enqueue) styles.
69
-	 */
70
-	public function disable_cmb2_styles( $enabled ) {
71
-		if ( is_admin() ) {
72
-			$current_screen = get_current_screen();
73
-			if ( is_object( $current_screen ) && 'settings_page_lsx-search-settings' === $current_screen->id ) {
74
-				$enabled = false;
75
-			}
76
-		}
77
-		return $enabled;
78
-	}
65
+     /**
66
+      * Disable CMB2 styles on front end forms.
67
+      *
68
+      * @return bool $enabled Whether to enable (enqueue) styles.
69
+      */
70
+     public function disable_cmb2_styles( $enabled ) {
71
+          if ( is_admin() ) {
72
+               $current_screen = get_current_screen();
73
+               if ( is_object( $current_screen ) && 'settings_page_lsx-search-settings' === $current_screen->id ) {
74
+                    $enabled = false;
75
+               }
76
+          }
77
+          return $enabled;
78
+     }
79 79
 
80
-	/**
81
-	 * Generates the tabbed navigation for the settings page.
82
-	 *
83
-	 * @param string $cmb_id
84
-	 * @param string $object_id
85
-	 * @param string $object_type
86
-	 * @param object $cmb2_obj
87
-	 * @return void
88
-	 */
89
-	public function generate_navigation( $cmb_id, $object_id, $object_type, $cmb2_obj ) {
90
-		if ( 'lsx_search_settings' === $cmb_id && 'lsx-search-settings' === $object_id && 'options-page' === $object_type ) {
91
-			$this->navigation      = array();
92
-			$this->is_options_page = true;
93
-			if ( isset( $cmb2_obj->meta_box['fields'] ) && ! empty( $cmb2_obj->meta_box['fields'] ) ) {
94
-				foreach ( $cmb2_obj->meta_box['fields'] as $field_index => $field ) {
95
-					if ( 'title' === $field['type'] ) {
96
-						$this->navigation[ $field_index ] = $field['name'];
97
-					}
98
-				}
99
-			}
100
-			$this->output_navigation();
101
-		}
102
-	}
80
+     /**
81
+      * Generates the tabbed navigation for the settings page.
82
+      *
83
+      * @param string $cmb_id
84
+      * @param string $object_id
85
+      * @param string $object_type
86
+      * @param object $cmb2_obj
87
+      * @return void
88
+      */
89
+     public function generate_navigation( $cmb_id, $object_id, $object_type, $cmb2_obj ) {
90
+          if ( 'lsx_search_settings' === $cmb_id && 'lsx-search-settings' === $object_id && 'options-page' === $object_type ) {
91
+               $this->navigation      = array();
92
+               $this->is_options_page = true;
93
+               if ( isset( $cmb2_obj->meta_box['fields'] ) && ! empty( $cmb2_obj->meta_box['fields'] ) ) {
94
+                    foreach ( $cmb2_obj->meta_box['fields'] as $field_index => $field ) {
95
+                         if ( 'title' === $field['type'] ) {
96
+                              $this->navigation[ $field_index ] = $field['name'];
97
+                         }
98
+                    }
99
+               }
100
+               $this->output_navigation();
101
+          }
102
+     }
103 103
 
104
-	/**
105
-	 * Outputs the WP style navigation for the Settings page.
106
-	 *
107
-	 * @return void
108
-	 */
109
-	public function output_navigation() {
110
-		if ( ! empty( $this->navigation ) ) {
111
-			?>
104
+     /**
105
+      * Outputs the WP style navigation for the Settings page.
106
+      *
107
+      * @return void
108
+      */
109
+     public function output_navigation() {
110
+          if ( ! empty( $this->navigation ) ) {
111
+               ?>
112 112
 			<div class="wp-filter hide-if-no-js">
113 113
 				<ul class="filter-links">
114 114
 					<?php
115
-					$first_tab    = true;
116
-					$total        = count( $this->navigation );
117
-					$count        = 0;
118
-					$separator    = ' |';
119
-					$selected_tab = '';
120
-					if ( isset( $_GET['cmb_tab'] ) && '' !== $_GET['cmb_tab'] ) {
121
-						$selected_tab  = sanitize_text_field( $_GET['cmb_tab'] );
122
-						$selected_tab  = 'settings_' . $selected_tab;
123
-					}
124
-					foreach ( $this->navigation as $key => $label ) {
125
-						$count++;
126
-						$current_css = '';
127
-						if ( ( true === $first_tab && '' === $selected_tab ) || $key === $selected_tab ) {
128
-							$first_tab   = false;
129
-							$current_css = 'current';
130
-						}
131
-						if ( $count === $total ) {
132
-							$separator = '';
133
-						}
134
-						?>
115
+                         $first_tab    = true;
116
+                         $total        = count( $this->navigation );
117
+                         $count        = 0;
118
+                         $separator    = ' |';
119
+                         $selected_tab = '';
120
+                         if ( isset( $_GET['cmb_tab'] ) && '' !== $_GET['cmb_tab'] ) {
121
+                              $selected_tab  = sanitize_text_field( $_GET['cmb_tab'] );
122
+                              $selected_tab  = 'settings_' . $selected_tab;
123
+                         }
124
+                         foreach ( $this->navigation as $key => $label ) {
125
+                              $count++;
126
+                              $current_css = '';
127
+                              if ( ( true === $first_tab && '' === $selected_tab ) || $key === $selected_tab ) {
128
+                                   $first_tab   = false;
129
+                                   $current_css = 'current';
130
+                              }
131
+                              if ( $count === $total ) {
132
+                                   $separator = '';
133
+                              }
134
+                              ?>
135 135
 							<li><a href="#" class="<?php echo esc_attr( $current_css ); ?>" data-sort="<?php echo esc_attr( $key ); ?>_tab"><?php echo esc_attr( $label ); ?></a><?php echo esc_attr( $separator ); ?></li>
136 136
 						<?php
137
-					}
138
-					?>
137
+                         }
138
+                         ?>
139 139
 				</ul>
140 140
 			</div>
141 141
 			<?php
142
-		}
143
-	}
142
+          }
143
+     }
144 144
 
145
-	/**
146
-	 * Outputs the opening tab div.
147
-	 *
148
-	 * @param object $field CMB2_Field();
149
-	 * @return void
150
-	 */
151
-	public function output_tab_open_div( $field ) {
152
-		if ( true === $this->is_options_page && isset( $field->args['type'] ) && 'title' === $field->args['type'] ) {
153
-			?>
145
+     /**
146
+      * Outputs the opening tab div.
147
+      *
148
+      * @param object $field CMB2_Field();
149
+      * @return void
150
+      */
151
+     public function output_tab_open_div( $field ) {
152
+          if ( true === $this->is_options_page && isset( $field->args['type'] ) && 'title' === $field->args['type'] ) {
153
+               ?>
154 154
 			<div id="<?php echo esc_attr( $field->args['id'] ); ?>_tab" class="tab tab-nav hidden">
155 155
 			<?php
156
-		}
157
-	}
156
+          }
157
+     }
158 158
 
159
-	/**
160
-	 * Outputs the opening closing div.
161
-	 *
162
-	 * @param object $field CMB2_Field();
163
-	 * @return void
164
-	 */
165
-	public function output_tab_closing_div( $field ) {
166
-		if ( true === $this->is_options_page && isset( $field->args['type'] ) && 'tab_closing' === $field->args['type'] ) {
167
-			?>
159
+     /**
160
+      * Outputs the opening closing div.
161
+      *
162
+      * @param object $field CMB2_Field();
163
+      * @return void
164
+      */
165
+     public function output_tab_closing_div( $field ) {
166
+          if ( true === $this->is_options_page && isset( $field->args['type'] ) && 'tab_closing' === $field->args['type'] ) {
167
+               ?>
168 168
 			</div>
169 169
 			<?php
170
-		}
171
-	}
170
+          }
171
+     }
172 172
 
173
-	public function cmb2_render_callback_for_tab_closing( $field, $escaped_value, $object_id, $object_type, $field_type_object ) {
174
-		return;
175
-	}
173
+     public function cmb2_render_callback_for_tab_closing( $field, $escaped_value, $object_id, $object_type, $field_type_object ) {
174
+          return;
175
+     }
176 176
 
177
-	public function cmb2_sanitize_tab_closing_callback( $override_value, $value ) {
178
-		return '';
179
-	}
177
+     public function cmb2_sanitize_tab_closing_callback( $override_value, $value ) {
178
+          return '';
179
+     }
180 180
 
181
-	/**
182
-	 * Outputs the Script for the tabbed navigation.
183
-	 *
184
-	 * @param string $cmb_id
185
-	 * @param string $object_id
186
-	 * @param string $object_type
187
-	 * @param object $cmb2_obj
188
-	 * @return void
189
-	 */
190
-	public function navigation_js( $cmb_id, $object_id, $object_type, $cmb2_obj ) {
191
-		if ( 'lsx_search_settings' === $cmb_id && 'lsx-search-settings' === $object_id && 'options-page' === $object_type ) {
192
-			?>
181
+     /**
182
+      * Outputs the Script for the tabbed navigation.
183
+      *
184
+      * @param string $cmb_id
185
+      * @param string $object_id
186
+      * @param string $object_type
187
+      * @param object $cmb2_obj
188
+      * @return void
189
+      */
190
+     public function navigation_js( $cmb_id, $object_id, $object_type, $cmb2_obj ) {
191
+          if ( 'lsx_search_settings' === $cmb_id && 'lsx-search-settings' === $object_id && 'options-page' === $object_type ) {
192
+               ?>
193 193
 			<script>
194 194
 				var LSX_SEARCH_CMB2 = Object.create( null );
195 195
 
@@ -261,25 +261,25 @@  discard block
 block discarded – undo
261 261
 				} )( jQuery, window, document );
262 262
 			</script>
263 263
 			<?php
264
-		}
265
-	}
264
+          }
265
+     }
266 266
 
267
-	/**
268
-	 * This will add the tab selection to the url.
269
-	 *
270
-	 * @param string $url
271
-	 * @return void
272
-	 */
273
-	public function add_tab_argument( $url ) {
274
-		if ( isset( $_POST['cmb_tab'] ) && '' !== $_POST['cmb_tab'] ) { // @codingStandardsIgnoreLine
275
-			$tab_selection = sanitize_text_field( $_POST['cmb_tab'] ); // @codingStandardsIgnoreLine
276
-			$tab_selection = str_replace( array( 'settings_', '_tab' ), '', $tab_selection ); // @codingStandardsIgnoreLine
277
-			if ( 'single' !== $tab_selection ) {
278
-				$url = add_query_arg( 'cmb_tab', $tab_selection, $url );
279
-			} else {
280
-				$url = remove_query_arg( 'cmb_tab', $url );
281
-			}
282
-		}
283
-		return $url;
284
-	}
267
+     /**
268
+      * This will add the tab selection to the url.
269
+      *
270
+      * @param string $url
271
+      * @return void
272
+      */
273
+     public function add_tab_argument( $url ) {
274
+          if ( isset( $_POST['cmb_tab'] ) && '' !== $_POST['cmb_tab'] ) { // @codingStandardsIgnoreLine
275
+               $tab_selection = sanitize_text_field( $_POST['cmb_tab'] ); // @codingStandardsIgnoreLine
276
+               $tab_selection = str_replace( array( 'settings_', '_tab' ), '', $tab_selection ); // @codingStandardsIgnoreLine
277
+               if ( 'single' !== $tab_selection ) {
278
+                    $url = add_query_arg( 'cmb_tab', $tab_selection, $url );
279
+               } else {
280
+                    $url = remove_query_arg( 'cmb_tab', $url );
281
+               }
282
+          }
283
+          return $url;
284
+     }
285 285
 }
Please login to merge, or discard this patch.
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -37,14 +37,14 @@  discard block
 block discarded – undo
37 37
 	 * Contructor
38 38
 	 */
39 39
 	public function __construct() {
40
-		add_filter( 'cmb2_enqueue_css', array( $this, 'disable_cmb2_styles' ), 1, 1 );
41
-		add_action( 'cmb2_before_form', array( $this, 'generate_navigation' ), 10, 4 );
42
-		add_action( 'cmb2_before_title_field_row', array( $this, 'output_tab_open_div' ), 10, 1 );
43
-		add_action( 'cmb2_after_tab_closing_field_row', array( $this, 'output_tab_closing_div' ), 10, 1 );
44
-		add_action( 'cmb2_render_tab_closing', array( $this, 'cmb2_render_callback_for_tab_closing' ), 10, 5 );
45
-		add_filter( 'cmb2_sanitize_tab_closing', array( $this, 'cmb2_sanitize_tab_closing_callback' ), 10, 2 );
46
-		add_action( 'cmb2_after_form', array( $this, 'navigation_js' ), 10, 4 );
47
-		add_filter( 'cmb2_options_page_redirect_url', array( $this, 'add_tab_argument' ), 10, 1 );
40
+		add_filter('cmb2_enqueue_css', array($this, 'disable_cmb2_styles'), 1, 1);
41
+		add_action('cmb2_before_form', array($this, 'generate_navigation'), 10, 4);
42
+		add_action('cmb2_before_title_field_row', array($this, 'output_tab_open_div'), 10, 1);
43
+		add_action('cmb2_after_tab_closing_field_row', array($this, 'output_tab_closing_div'), 10, 1);
44
+		add_action('cmb2_render_tab_closing', array($this, 'cmb2_render_callback_for_tab_closing'), 10, 5);
45
+		add_filter('cmb2_sanitize_tab_closing', array($this, 'cmb2_sanitize_tab_closing_callback'), 10, 2);
46
+		add_action('cmb2_after_form', array($this, 'navigation_js'), 10, 4);
47
+		add_filter('cmb2_options_page_redirect_url', array($this, 'add_tab_argument'), 10, 1);
48 48
 	}
49 49
 
50 50
 	/**
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 	 */
57 57
 	public static function get_instance() {
58 58
 		// If the single instance hasn't been set, set it now.
59
-		if ( null == self::$instance ) {
59
+		if (null == self::$instance) {
60 60
 			self::$instance = new self();
61 61
 		}
62 62
 		return self::$instance;
@@ -67,10 +67,10 @@  discard block
 block discarded – undo
67 67
 	 *
68 68
 	 * @return bool $enabled Whether to enable (enqueue) styles.
69 69
 	 */
70
-	public function disable_cmb2_styles( $enabled ) {
71
-		if ( is_admin() ) {
70
+	public function disable_cmb2_styles($enabled) {
71
+		if (is_admin()) {
72 72
 			$current_screen = get_current_screen();
73
-			if ( is_object( $current_screen ) && 'settings_page_lsx-search-settings' === $current_screen->id ) {
73
+			if (is_object($current_screen) && 'settings_page_lsx-search-settings' === $current_screen->id) {
74 74
 				$enabled = false;
75 75
 			}
76 76
 		}
@@ -86,14 +86,14 @@  discard block
 block discarded – undo
86 86
 	 * @param object $cmb2_obj
87 87
 	 * @return void
88 88
 	 */
89
-	public function generate_navigation( $cmb_id, $object_id, $object_type, $cmb2_obj ) {
90
-		if ( 'lsx_search_settings' === $cmb_id && 'lsx-search-settings' === $object_id && 'options-page' === $object_type ) {
89
+	public function generate_navigation($cmb_id, $object_id, $object_type, $cmb2_obj) {
90
+		if ('lsx_search_settings' === $cmb_id && 'lsx-search-settings' === $object_id && 'options-page' === $object_type) {
91 91
 			$this->navigation      = array();
92 92
 			$this->is_options_page = true;
93
-			if ( isset( $cmb2_obj->meta_box['fields'] ) && ! empty( $cmb2_obj->meta_box['fields'] ) ) {
94
-				foreach ( $cmb2_obj->meta_box['fields'] as $field_index => $field ) {
95
-					if ( 'title' === $field['type'] ) {
96
-						$this->navigation[ $field_index ] = $field['name'];
93
+			if (isset($cmb2_obj->meta_box['fields']) && !empty($cmb2_obj->meta_box['fields'])) {
94
+				foreach ($cmb2_obj->meta_box['fields'] as $field_index => $field) {
95
+					if ('title' === $field['type']) {
96
+						$this->navigation[$field_index] = $field['name'];
97 97
 					}
98 98
 				}
99 99
 			}
@@ -107,32 +107,32 @@  discard block
 block discarded – undo
107 107
 	 * @return void
108 108
 	 */
109 109
 	public function output_navigation() {
110
-		if ( ! empty( $this->navigation ) ) {
110
+		if (!empty($this->navigation)) {
111 111
 			?>
112 112
 			<div class="wp-filter hide-if-no-js">
113 113
 				<ul class="filter-links">
114 114
 					<?php
115 115
 					$first_tab    = true;
116
-					$total        = count( $this->navigation );
116
+					$total        = count($this->navigation);
117 117
 					$count        = 0;
118 118
 					$separator    = ' |';
119 119
 					$selected_tab = '';
120
-					if ( isset( $_GET['cmb_tab'] ) && '' !== $_GET['cmb_tab'] ) {
121
-						$selected_tab  = sanitize_text_field( $_GET['cmb_tab'] );
122
-						$selected_tab  = 'settings_' . $selected_tab;
120
+					if (isset($_GET['cmb_tab']) && '' !== $_GET['cmb_tab']) {
121
+						$selected_tab  = sanitize_text_field($_GET['cmb_tab']);
122
+						$selected_tab  = 'settings_'.$selected_tab;
123 123
 					}
124
-					foreach ( $this->navigation as $key => $label ) {
124
+					foreach ($this->navigation as $key => $label) {
125 125
 						$count++;
126 126
 						$current_css = '';
127
-						if ( ( true === $first_tab && '' === $selected_tab ) || $key === $selected_tab ) {
127
+						if ((true === $first_tab && '' === $selected_tab) || $key === $selected_tab) {
128 128
 							$first_tab   = false;
129 129
 							$current_css = 'current';
130 130
 						}
131
-						if ( $count === $total ) {
131
+						if ($count === $total) {
132 132
 							$separator = '';
133 133
 						}
134 134
 						?>
135
-							<li><a href="#" class="<?php echo esc_attr( $current_css ); ?>" data-sort="<?php echo esc_attr( $key ); ?>_tab"><?php echo esc_attr( $label ); ?></a><?php echo esc_attr( $separator ); ?></li>
135
+							<li><a href="#" class="<?php echo esc_attr($current_css); ?>" data-sort="<?php echo esc_attr($key); ?>_tab"><?php echo esc_attr($label); ?></a><?php echo esc_attr($separator); ?></li>
136 136
 						<?php
137 137
 					}
138 138
 					?>
@@ -148,10 +148,10 @@  discard block
 block discarded – undo
148 148
 	 * @param object $field CMB2_Field();
149 149
 	 * @return void
150 150
 	 */
151
-	public function output_tab_open_div( $field ) {
152
-		if ( true === $this->is_options_page && isset( $field->args['type'] ) && 'title' === $field->args['type'] ) {
151
+	public function output_tab_open_div($field) {
152
+		if (true === $this->is_options_page && isset($field->args['type']) && 'title' === $field->args['type']) {
153 153
 			?>
154
-			<div id="<?php echo esc_attr( $field->args['id'] ); ?>_tab" class="tab tab-nav hidden">
154
+			<div id="<?php echo esc_attr($field->args['id']); ?>_tab" class="tab tab-nav hidden">
155 155
 			<?php
156 156
 		}
157 157
 	}
@@ -162,19 +162,19 @@  discard block
 block discarded – undo
162 162
 	 * @param object $field CMB2_Field();
163 163
 	 * @return void
164 164
 	 */
165
-	public function output_tab_closing_div( $field ) {
166
-		if ( true === $this->is_options_page && isset( $field->args['type'] ) && 'tab_closing' === $field->args['type'] ) {
165
+	public function output_tab_closing_div($field) {
166
+		if (true === $this->is_options_page && isset($field->args['type']) && 'tab_closing' === $field->args['type']) {
167 167
 			?>
168 168
 			</div>
169 169
 			<?php
170 170
 		}
171 171
 	}
172 172
 
173
-	public function cmb2_render_callback_for_tab_closing( $field, $escaped_value, $object_id, $object_type, $field_type_object ) {
173
+	public function cmb2_render_callback_for_tab_closing($field, $escaped_value, $object_id, $object_type, $field_type_object) {
174 174
 		return;
175 175
 	}
176 176
 
177
-	public function cmb2_sanitize_tab_closing_callback( $override_value, $value ) {
177
+	public function cmb2_sanitize_tab_closing_callback($override_value, $value) {
178 178
 		return '';
179 179
 	}
180 180
 
@@ -187,8 +187,8 @@  discard block
 block discarded – undo
187 187
 	 * @param object $cmb2_obj
188 188
 	 * @return void
189 189
 	 */
190
-	public function navigation_js( $cmb_id, $object_id, $object_type, $cmb2_obj ) {
191
-		if ( 'lsx_search_settings' === $cmb_id && 'lsx-search-settings' === $object_id && 'options-page' === $object_type ) {
190
+	public function navigation_js($cmb_id, $object_id, $object_type, $cmb2_obj) {
191
+		if ('lsx_search_settings' === $cmb_id && 'lsx-search-settings' === $object_id && 'options-page' === $object_type) {
192 192
 			?>
193 193
 			<script>
194 194
 				var LSX_SEARCH_CMB2 = Object.create( null );
@@ -270,14 +270,14 @@  discard block
 block discarded – undo
270 270
 	 * @param string $url
271 271
 	 * @return void
272 272
 	 */
273
-	public function add_tab_argument( $url ) {
274
-		if ( isset( $_POST['cmb_tab'] ) && '' !== $_POST['cmb_tab'] ) { // @codingStandardsIgnoreLine
275
-			$tab_selection = sanitize_text_field( $_POST['cmb_tab'] ); // @codingStandardsIgnoreLine
276
-			$tab_selection = str_replace( array( 'settings_', '_tab' ), '', $tab_selection ); // @codingStandardsIgnoreLine
277
-			if ( 'single' !== $tab_selection ) {
278
-				$url = add_query_arg( 'cmb_tab', $tab_selection, $url );
273
+	public function add_tab_argument($url) {
274
+		if (isset($_POST['cmb_tab']) && '' !== $_POST['cmb_tab']) { // @codingStandardsIgnoreLine
275
+			$tab_selection = sanitize_text_field($_POST['cmb_tab']); // @codingStandardsIgnoreLine
276
+			$tab_selection = str_replace(array('settings_', '_tab'), '', $tab_selection); // @codingStandardsIgnoreLine
277
+			if ('single' !== $tab_selection) {
278
+				$url = add_query_arg('cmb_tab', $tab_selection, $url);
279 279
 			} else {
280
-				$url = remove_query_arg( 'cmb_tab', $url );
280
+				$url = remove_query_arg('cmb_tab', $url);
281 281
 			}
282 282
 		}
283 283
 		return $url;
Please login to merge, or discard this patch.
classes/class-lsx-search.php 2 patches
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -6,76 +6,76 @@  discard block
 block discarded – undo
6 6
  */
7 7
 class LSX_Search {
8 8
 
9
-	/**
10
-	 * Holds class instance
11
-	 *
12
-	 * @since 1.0.0
13
-	 *
14
-	 * @var      object LSX_Search()
15
-	 */
16
-	protected static $instance = null;
9
+     /**
10
+      * Holds class instance
11
+      *
12
+      * @since 1.0.0
13
+      *
14
+      * @var      object LSX_Search()
15
+      */
16
+     protected static $instance = null;
17 17
 
18
-	/**
19
-	 * @var LSX_Search_Admin()
20
-	 */
21
-	public $admin;
18
+     /**
19
+      * @var LSX_Search_Admin()
20
+      */
21
+     public $admin;
22 22
 
23
-	/**
24
-	 * @var LSX_Search_Frontend()
25
-	 */
26
-	public $frontend;
23
+     /**
24
+      * @var LSX_Search_Frontend()
25
+      */
26
+     public $frontend;
27 27
 
28
-	/**
29
-	 * @var LSX_Search_FacetWP()
30
-	 */
31
-	public $facetwp;
28
+     /**
29
+      * @var LSX_Search_FacetWP()
30
+      */
31
+     public $facetwp;
32 32
 
33
-	/**
34
-	 * @var LSX_Search_Shortcode()
35
-	 */
36
-	public $shortcode;
33
+     /**
34
+      * @var LSX_Search_Shortcode()
35
+      */
36
+     public $shortcode;
37 37
 
38
-	/**
39
-	 * LSX_Search constructor
40
-	 */
41
-	public function __construct() {
42
-		$this->load_vendors();
38
+     /**
39
+      * LSX_Search constructor
40
+      */
41
+     public function __construct() {
42
+          $this->load_vendors();
43 43
 
44
-		require_once LSX_SEARCH_PATH . '/classes/class-admin.php';
45
-		require_once LSX_SEARCH_PATH . '/classes/class-frontend.php';
46
-		require_once LSX_SEARCH_PATH . '/classes/class-lsx-search-facetwp.php';
47
-		require_once LSX_SEARCH_PATH . '/classes/class-lsx-search-shortcode.php';
44
+          require_once LSX_SEARCH_PATH . '/classes/class-admin.php';
45
+          require_once LSX_SEARCH_PATH . '/classes/class-frontend.php';
46
+          require_once LSX_SEARCH_PATH . '/classes/class-lsx-search-facetwp.php';
47
+          require_once LSX_SEARCH_PATH . '/classes/class-lsx-search-shortcode.php';
48 48
 
49
-		$this->admin     = \lsx\search\classes\Admin::get_instance();
50
-		$this->frontend  = \lsx\search\classes\Frontend::get_instance();
51
-		$this->facetwp   = new LSX_Search_FacetWP();
52
-		$this->shortcode = new LSX_Search_Shortcode();
53
-	}
49
+          $this->admin     = \lsx\search\classes\Admin::get_instance();
50
+          $this->frontend  = \lsx\search\classes\Frontend::get_instance();
51
+          $this->facetwp   = new LSX_Search_FacetWP();
52
+          $this->shortcode = new LSX_Search_Shortcode();
53
+     }
54 54
 
55
-	/**
56
-	 * Return an instance of this class.
57
-	 *
58
-	 * @since 1.0.0
59
-	 *
60
-	 * @return    object LSX_Search()    A single instance of this class.
61
-	 */
62
-	public static function get_instance() {
63
-		// If the single instance hasn't been set, set it now.
64
-		if ( null === self::$instance ) {
65
-			self::$instance = new self();
66
-		}
67
-		return self::$instance;
68
-	}
55
+     /**
56
+      * Return an instance of this class.
57
+      *
58
+      * @since 1.0.0
59
+      *
60
+      * @return    object LSX_Search()    A single instance of this class.
61
+      */
62
+     public static function get_instance() {
63
+          // If the single instance hasn't been set, set it now.
64
+          if ( null === self::$instance ) {
65
+               self::$instance = new self();
66
+          }
67
+          return self::$instance;
68
+     }
69 69
 
70
-	/**
71
-	 * Loads the plugin functions.
72
-	 */
73
-	private function load_vendors() {
74
-		// Configure custom fields.
75
-		if ( ! class_exists( 'CMB2' ) ) {
76
-			require_once LSX_SEARCH_PATH . 'vendor/CMB2/init.php';
77
-		}
78
-	}
70
+     /**
71
+      * Loads the plugin functions.
72
+      */
73
+     private function load_vendors() {
74
+          // Configure custom fields.
75
+          if ( ! class_exists( 'CMB2' ) ) {
76
+               require_once LSX_SEARCH_PATH . 'vendor/CMB2/init.php';
77
+          }
78
+     }
79 79
 }
80 80
 
81 81
 /**
@@ -84,8 +84,8 @@  discard block
 block discarded – undo
84 84
  * @return object LSX_Search();
85 85
  */
86 86
 function lsx_search() {
87
-	global $lsx_search;
88
-	$lsx_search = LSX_Search::get_instance();
89
-	return $lsx_search;
87
+     global $lsx_search;
88
+     $lsx_search = LSX_Search::get_instance();
89
+     return $lsx_search;
90 90
 }
91 91
 lsx_search();
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -41,10 +41,10 @@  discard block
 block discarded – undo
41 41
 	public function __construct() {
42 42
 		$this->load_vendors();
43 43
 
44
-		require_once LSX_SEARCH_PATH . '/classes/class-admin.php';
45
-		require_once LSX_SEARCH_PATH . '/classes/class-frontend.php';
46
-		require_once LSX_SEARCH_PATH . '/classes/class-lsx-search-facetwp.php';
47
-		require_once LSX_SEARCH_PATH . '/classes/class-lsx-search-shortcode.php';
44
+		require_once LSX_SEARCH_PATH.'/classes/class-admin.php';
45
+		require_once LSX_SEARCH_PATH.'/classes/class-frontend.php';
46
+		require_once LSX_SEARCH_PATH.'/classes/class-lsx-search-facetwp.php';
47
+		require_once LSX_SEARCH_PATH.'/classes/class-lsx-search-shortcode.php';
48 48
 
49 49
 		$this->admin     = \lsx\search\classes\Admin::get_instance();
50 50
 		$this->frontend  = \lsx\search\classes\Frontend::get_instance();
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 	 */
62 62
 	public static function get_instance() {
63 63
 		// If the single instance hasn't been set, set it now.
64
-		if ( null === self::$instance ) {
64
+		if (null === self::$instance) {
65 65
 			self::$instance = new self();
66 66
 		}
67 67
 		return self::$instance;
@@ -72,8 +72,8 @@  discard block
 block discarded – undo
72 72
 	 */
73 73
 	private function load_vendors() {
74 74
 		// Configure custom fields.
75
-		if ( ! class_exists( 'CMB2' ) ) {
76
-			require_once LSX_SEARCH_PATH . 'vendor/CMB2/init.php';
75
+		if (!class_exists('CMB2')) {
76
+			require_once LSX_SEARCH_PATH.'vendor/CMB2/init.php';
77 77
 		}
78 78
 	}
79 79
 }
Please login to merge, or discard this patch.
classes/facetwp/class-hierarchy.php 2 patches
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -7,61 +7,61 @@  discard block
 block discarded – undo
7 7
 
8 8
 class Hierarchy {
9 9
 
10
-	/**
11
-	 * Holds class instance
12
-	 *
13
-	 * @since 1.0.0
14
-	 *
15
-	 * @var      object \lsx\search\classes\facetwp\Hierarchy()
16
-	 */
17
-	protected static $instance = null;
18
-
19
-	/**
20
-	 * Constructor
21
-	 */
22
-	public function __construct() {
23
-		add_filter( 'facetwp_facet_html', array( $this, 'checkbox_facet_html' ), 100, 2 );
24
-	}
25
-
26
-	/**
27
-	 * Return an instance of this class.
28
-	 *
29
-	 * @since 1.0.0
30
-	 *
31
-	 * @return    object \lsx\search\classes\facetwp\Hierarchy()    A single instance of this class.
32
-	 */
33
-	public static function get_instance() {
34
-		// If the single instance hasn't been set, set it now.
35
-		if ( null === self::$instance ) {
36
-			self::$instance = new self();
37
-		}
38
-		return self::$instance;
39
-	}
40
-
41
-	public function checkbox_facet_html( $output, $params ) {
42
-		if ( 'checkboxes' === $params['facet']['type'] && 'yes' === $params['facet']['hierarchical'] ) {
43
-			$output = $this->render_hierarchy( $params );
44
-		}
45
-		return $output;
46
-	}
47
-
48
-	/**
49
-	 * Generate the facet HTML (hierarchical taxonomies)
50
-	 */
51
-	function render_hierarchy( $params ) {
52
-
53
-		$output = '';
54
-		$facet = $params['facet'];
55
-		$selected_values = (array) $params['selected_values'];
56
-		$values = FWP()->helper->sort_taxonomy_values( $params['values'], $facet['orderby'] );
57
-
58
-		$init_depth = -1;
59
-		$last_depth = -1;
60
-
61
-		foreach ( $values as $result ) {
62
-			$depth = (int) $result['depth'];
63
-
64
-			/*if ( -1 == $last_depth ) {
10
+     /**
11
+      * Holds class instance
12
+      *
13
+      * @since 1.0.0
14
+      *
15
+      * @var      object \lsx\search\classes\facetwp\Hierarchy()
16
+      */
17
+     protected static $instance = null;
18
+
19
+     /**
20
+      * Constructor
21
+      */
22
+     public function __construct() {
23
+          add_filter( 'facetwp_facet_html', array( $this, 'checkbox_facet_html' ), 100, 2 );
24
+     }
25
+
26
+     /**
27
+      * Return an instance of this class.
28
+      *
29
+      * @since 1.0.0
30
+      *
31
+      * @return    object \lsx\search\classes\facetwp\Hierarchy()    A single instance of this class.
32
+      */
33
+     public static function get_instance() {
34
+          // If the single instance hasn't been set, set it now.
35
+          if ( null === self::$instance ) {
36
+               self::$instance = new self();
37
+          }
38
+          return self::$instance;
39
+     }
40
+
41
+     public function checkbox_facet_html( $output, $params ) {
42
+          if ( 'checkboxes' === $params['facet']['type'] && 'yes' === $params['facet']['hierarchical'] ) {
43
+               $output = $this->render_hierarchy( $params );
44
+          }
45
+          return $output;
46
+     }
47
+
48
+     /**
49
+      * Generate the facet HTML (hierarchical taxonomies)
50
+      */
51
+     function render_hierarchy( $params ) {
52
+
53
+          $output = '';
54
+          $facet = $params['facet'];
55
+          $selected_values = (array) $params['selected_values'];
56
+          $values = FWP()->helper->sort_taxonomy_values( $params['values'], $facet['orderby'] );
57
+
58
+          $init_depth = -1;
59
+          $last_depth = -1;
60
+
61
+          foreach ( $values as $result ) {
62
+               $depth = (int) $result['depth'];
63
+
64
+               /*if ( -1 == $last_depth ) {
65 65
 				$init_depth = $depth;
66 66
 			}
67 67
 			elseif ( $depth > $last_depth ) {
@@ -73,23 +73,23 @@  discard block
 block discarded – undo
73 73
 				}
74 74
 			}*/
75 75
 
76
-			$selected = in_array( $result['facet_value'], $selected_values ) ? ' checked' : '';
77
-			$selected .= ( 0 == $result['counter'] && '' == $selected ) ? ' disabled' : '';
76
+               $selected = in_array( $result['facet_value'], $selected_values ) ? ' checked' : '';
77
+               $selected .= ( 0 == $result['counter'] && '' == $selected ) ? ' disabled' : '';
78 78
 
79
-			$is_child = ( 0 == $result['parent_id'] && '0' == $result['parent_id'] ) ? ' is-child' : '';
80
-			$depth_css = ' depth-' . $result['depth'];
79
+               $is_child = ( 0 == $result['parent_id'] && '0' == $result['parent_id'] ) ? ' is-child' : '';
80
+               $depth_css = ' depth-' . $result['depth'];
81 81
 
82
-			$output .= '<div class="facetwp-checkbox' . $selected . $is_child . $depth_css . '" data-parent-id="' . esc_attr( $result['parent_id'] ) . '" data-value="' . esc_attr( $result['facet_value'] ) . '">';
83
-			$output .= esc_html( $result['facet_display_value'] ) . ' <span class="facetwp-counter">(' . $result['counter'] . ')</span>';
84
-			$output .= '</div>';
82
+               $output .= '<div class="facetwp-checkbox' . $selected . $is_child . $depth_css . '" data-parent-id="' . esc_attr( $result['parent_id'] ) . '" data-value="' . esc_attr( $result['facet_value'] ) . '">';
83
+               $output .= esc_html( $result['facet_display_value'] ) . ' <span class="facetwp-counter">(' . $result['counter'] . ')</span>';
84
+               $output .= '</div>';
85 85
 
86
-			$last_depth = $depth;
87
-		}
86
+               $last_depth = $depth;
87
+          }
88 88
 
89
-		for ( $i = $last_depth; $i > $init_depth; $i-- ) {
90
-			$output .= '</div>';
91
-		}
89
+          for ( $i = $last_depth; $i > $init_depth; $i-- ) {
90
+               $output .= '</div>';
91
+          }
92 92
 
93
-		return $output;
94
-	}
93
+          return $output;
94
+     }
95 95
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 	 * Constructor
21 21
 	 */
22 22
 	public function __construct() {
23
-		add_filter( 'facetwp_facet_html', array( $this, 'checkbox_facet_html' ), 100, 2 );
23
+		add_filter('facetwp_facet_html', array($this, 'checkbox_facet_html'), 100, 2);
24 24
 	}
25 25
 
26 26
 	/**
@@ -32,15 +32,15 @@  discard block
 block discarded – undo
32 32
 	 */
33 33
 	public static function get_instance() {
34 34
 		// If the single instance hasn't been set, set it now.
35
-		if ( null === self::$instance ) {
35
+		if (null === self::$instance) {
36 36
 			self::$instance = new self();
37 37
 		}
38 38
 		return self::$instance;
39 39
 	}
40 40
 
41
-	public function checkbox_facet_html( $output, $params ) {
42
-		if ( 'checkboxes' === $params['facet']['type'] && 'yes' === $params['facet']['hierarchical'] ) {
43
-			$output = $this->render_hierarchy( $params );
41
+	public function checkbox_facet_html($output, $params) {
42
+		if ('checkboxes' === $params['facet']['type'] && 'yes' === $params['facet']['hierarchical']) {
43
+			$output = $this->render_hierarchy($params);
44 44
 		}
45 45
 		return $output;
46 46
 	}
@@ -48,17 +48,17 @@  discard block
 block discarded – undo
48 48
 	/**
49 49
 	 * Generate the facet HTML (hierarchical taxonomies)
50 50
 	 */
51
-	function render_hierarchy( $params ) {
51
+	function render_hierarchy($params) {
52 52
 
53 53
 		$output = '';
54 54
 		$facet = $params['facet'];
55 55
 		$selected_values = (array) $params['selected_values'];
56
-		$values = FWP()->helper->sort_taxonomy_values( $params['values'], $facet['orderby'] );
56
+		$values = FWP()->helper->sort_taxonomy_values($params['values'], $facet['orderby']);
57 57
 
58 58
 		$init_depth = -1;
59 59
 		$last_depth = -1;
60 60
 
61
-		foreach ( $values as $result ) {
61
+		foreach ($values as $result) {
62 62
 			$depth = (int) $result['depth'];
63 63
 
64 64
 			/*if ( -1 == $last_depth ) {
@@ -73,20 +73,20 @@  discard block
 block discarded – undo
73 73
 				}
74 74
 			}*/
75 75
 
76
-			$selected = in_array( $result['facet_value'], $selected_values ) ? ' checked' : '';
77
-			$selected .= ( 0 == $result['counter'] && '' == $selected ) ? ' disabled' : '';
76
+			$selected = in_array($result['facet_value'], $selected_values) ? ' checked' : '';
77
+			$selected .= (0 == $result['counter'] && '' == $selected) ? ' disabled' : '';
78 78
 
79
-			$is_child = ( 0 == $result['parent_id'] && '0' == $result['parent_id'] ) ? ' is-child' : '';
80
-			$depth_css = ' depth-' . $result['depth'];
79
+			$is_child = (0 == $result['parent_id'] && '0' == $result['parent_id']) ? ' is-child' : '';
80
+			$depth_css = ' depth-'.$result['depth'];
81 81
 
82
-			$output .= '<div class="facetwp-checkbox' . $selected . $is_child . $depth_css . '" data-parent-id="' . esc_attr( $result['parent_id'] ) . '" data-value="' . esc_attr( $result['facet_value'] ) . '">';
83
-			$output .= esc_html( $result['facet_display_value'] ) . ' <span class="facetwp-counter">(' . $result['counter'] . ')</span>';
82
+			$output .= '<div class="facetwp-checkbox'.$selected.$is_child.$depth_css.'" data-parent-id="'.esc_attr($result['parent_id']).'" data-value="'.esc_attr($result['facet_value']).'">';
83
+			$output .= esc_html($result['facet_display_value']).' <span class="facetwp-counter">('.$result['counter'].')</span>';
84 84
 			$output .= '</div>';
85 85
 
86 86
 			$last_depth = $depth;
87 87
 		}
88 88
 
89
-		for ( $i = $last_depth; $i > $init_depth; $i-- ) {
89
+		for ($i = $last_depth; $i > $init_depth; $i--) {
90 90
 			$output .= '</div>';
91 91
 		}
92 92
 
Please login to merge, or discard this patch.
classes/facetwp/class-post-connections.php 2 patches
Indentation   +374 added lines, -374 removed lines patch added patch discarded remove patch
@@ -7,381 +7,381 @@
 block discarded – undo
7 7
 
8 8
 class Post_Connections {
9 9
 
10
-	/**
11
-	 * Holds class instance
12
-	 *
13
-	 * @since 1.0.0
14
-	 *
15
-	 * @var      object \lsx\search\classes\facetwp\Post_Connections()
16
-	 */
17
-	protected static $instance = null;
18
-
19
-	/**
20
-	 * Holds the plugin options.
21
-	 *
22
-	 * @var array
23
-	 */
24
-	public $options = array();
25
-
26
-	/**
27
-	 * Constructor
28
-	 */
29
-	public function __construct() {
30
-		$this->get_cmb2_options();
31
-		add_filter( 'facetwp_indexer_row_data', array( $this, 'facetwp_index_row_data' ), 10, 2 );
32
-		add_filter( 'facetwp_index_row', array( $this, 'facetwp_index_row' ), 10, 2 );
33
-		add_filter( 'facetwp_facet_html', array( $this, 'destination_facet_html' ), 10, 2 );
34
-	}
35
-
36
-	/**
37
-	 * Gets the cmb2 options.
38
-	 *
39
-	 * @return void
40
-	 */
41
-	private function get_cmb2_options() {
42
-		$cmb2_options = get_option( 'lsx-search-settings' );
43
-		if ( false !== $cmb2_options && ! empty( $cmb2_options ) ) {
44
-			$this->options['display'] = $cmb2_options;
45
-			foreach ( $this->options['display'] as $option_key => $option_value ) {
46
-				if ( is_array( $option_value ) && ! empty( $option_value ) ) {
47
-					$new_values = array();
48
-					foreach ( $option_value as $empty_key => $key_value ) {
49
-						$new_values[ $key_value ] = 'on';
50
-					}
51
-					$this->options['display'][ $option_key ] = $new_values;
52
-				}
53
-			}
54
-		}
55
-
56
-		/*print_r('<pre>');
10
+     /**
11
+      * Holds class instance
12
+      *
13
+      * @since 1.0.0
14
+      *
15
+      * @var      object \lsx\search\classes\facetwp\Post_Connections()
16
+      */
17
+     protected static $instance = null;
18
+
19
+     /**
20
+      * Holds the plugin options.
21
+      *
22
+      * @var array
23
+      */
24
+     public $options = array();
25
+
26
+     /**
27
+      * Constructor
28
+      */
29
+     public function __construct() {
30
+          $this->get_cmb2_options();
31
+          add_filter( 'facetwp_indexer_row_data', array( $this, 'facetwp_index_row_data' ), 10, 2 );
32
+          add_filter( 'facetwp_index_row', array( $this, 'facetwp_index_row' ), 10, 2 );
33
+          add_filter( 'facetwp_facet_html', array( $this, 'destination_facet_html' ), 10, 2 );
34
+     }
35
+
36
+     /**
37
+      * Gets the cmb2 options.
38
+      *
39
+      * @return void
40
+      */
41
+     private function get_cmb2_options() {
42
+          $cmb2_options = get_option( 'lsx-search-settings' );
43
+          if ( false !== $cmb2_options && ! empty( $cmb2_options ) ) {
44
+               $this->options['display'] = $cmb2_options;
45
+               foreach ( $this->options['display'] as $option_key => $option_value ) {
46
+                    if ( is_array( $option_value ) && ! empty( $option_value ) ) {
47
+                         $new_values = array();
48
+                         foreach ( $option_value as $empty_key => $key_value ) {
49
+                              $new_values[ $key_value ] = 'on';
50
+                         }
51
+                         $this->options['display'][ $option_key ] = $new_values;
52
+                    }
53
+               }
54
+          }
55
+
56
+          /*print_r('<pre>');
57 57
 		print_r($this->options);
58 58
 		print_r('</pre>');
59 59
 		die();*/
60
-	}
61
-
62
-	/**
63
-	 * Return an instance of this class.
64
-	 *
65
-	 * @since 1.0.0
66
-	 *
67
-	 * @return    object \lsx\search\classes\facetwp\Post_Connections()    A single instance of this class.
68
-	 */
69
-	public static function get_instance() {
70
-		// If the single instance hasn't been set, set it now.
71
-		if ( null === self::$instance ) {
72
-			self::$instance = new self();
73
-		}
74
-		return self::$instance;
75
-	}
76
-
77
-	/**
78
-	 *	Alter the rows and include extra facets rows for the continents
79
-	 */
80
-	public function facetwp_index_row_data( $rows, $params ) {
81
-		switch ( $params['facet']['source'] ) {
82
-			case 'cf/destination_to_tour':
83
-			case 'cf/destination_to_accommodation':
84
-				$countries = array();
85
-
86
-				foreach ( $rows as $r_index => $row ) {
87
-					$parent                        = wp_get_post_parent_id( $row['facet_value'] );
88
-					$rows[ $r_index ]['parent_id'] = $parent;
89
-
90
-					if ( 0 === $parent || '0' === $parent ) {
91
-						if ( ! isset( $countries[ $r_index ] ) ) {
92
-							$countries[ $r_index ] = $row['facet_value'];
93
-						}
94
-
95
-						if ( ! empty( $this->options['display']['engine_search_continent_filter'] ) ) {
96
-							$rows[ $r_index ]['depth'] = 1;
97
-						} else {
98
-							$rows[ $r_index ]['depth'] = 0;
99
-						}
100
-					} else {
101
-						if ( ! empty( $this->options['display']['engine_search_continent_filter'] ) ) {
102
-							$rows[ $r_index ]['depth'] = 2;
103
-						} else {
104
-							$rows[ $r_index ]['depth'] = 1;
105
-						}
106
-					}
107
-				}
108
-				if ( ! empty( $this->options['display']['enable_search_continent_filter'] ) ) {
109
-					if ( ! empty( $countries ) ) {
110
-						foreach ( $countries as $row_index => $country ) {
111
-							$continents   = wp_get_object_terms( $country, 'continent' );
112
-							$continent_id = 0;
113
-
114
-							if ( ! is_wp_error( $continents ) ) {
115
-								$new_row = $params['defaults'];
116
-								if ( ! is_array( $continents ) ) {
117
-									$continents = array( $continents );
118
-								}
119
-
120
-								foreach ( $continents as $continent ) {
121
-									$new_row['facet_value'] = $continent->slug;
122
-									$new_row['facet_display_value'] = $continent->name;
123
-									$continent_id = $continent->term_id;
124
-									$new_row['depth'] = 0;
125
-								}
126
-								$rows[] = $new_row;
127
-								$rows[ $row_index ]['parent_id'] = $continent_id;
128
-							}
129
-						}
130
-					}
131
-				}
132
-
133
-				break;
134
-
135
-			default:
136
-				break;
137
-		}
138
-
139
-		return $rows;
140
-	}
141
-
142
-	/**
143
-	 * Displays the destination specific settings
144
-	 */
145
-	public function facetwp_index_row( $params, $class ) {
146
-		$custom_field = false;
147
-		$meta_key = false;
148
-
149
-		preg_match( '/cf\//', $class->facet['source'], $custom_field );
150
-		preg_match( '/_to_/', $class->facet['source'], $meta_key );
151
-
152
-		if ( ! empty( $custom_field ) && ! empty( $meta_key ) ) {
153
-
154
-			if ( ( 'cf/destination_to_accommodation' === $class->facet['source'] || 'cf/destination_to_tour' === $class->facet['source'] ) && ! empty( $this->options['display']['engine_search_continent_filter'] ) && ( '0' === (string) $params['depth'] ) ) {
155
-				$title = '';
156
-			} else {
157
-				$title = get_the_title( $params['facet_value'] );
158
-				if ( '' !== $title ) {
159
-					$params['facet_display_value'] = $title;
160
-				}
161
-				if ( '' === $title && ! empty( $meta_key ) ) {
162
-					$params['facet_value'] = '';
163
-				}
164
-			}
165
-		}
166
-
167
-		// If its a price, save the value as a standard number.
168
-		if ( 'cf/price' === $class->facet['source'] ) {
169
-			$params['facet_value'] = preg_replace( '/[^0-9.]/', '', $params['facet_value'] );
170
-			$params['facet_value'] = ltrim( $params['facet_value'], '.' );
171
-			#$params['facet_value'] = number_format( (int) $params['facet_value'], 2 );
172
-			$params['facet_display_value'] = $params['facet_value'];
173
-		}
174
-
175
-		// If its a duration, save the value as a standard number.
176
-		if ( 'cf/duration' === $class->facet['source'] ) {
177
-			$params['facet_value'] = preg_replace( '/[^0-9 ]/', '', $params['facet_value'] );
178
-			$params['facet_value'] = trim( $params['facet_value'] );
179
-			$params['facet_value'] = explode( ' ', $params['facet_value'] );
180
-			$params['facet_value'] = $params['facet_value'][0];
181
-			#$params['facet_value'] = (int) $params['facet_value'];
182
-			$params['facet_display_value'] = $params['facet_value'];
183
-		}
184
-
185
-		return $params;
186
-	}
187
-
188
-	/**
189
-	 * Checks the facet source value and outputs the destination facet HTML if needed.
190
-	 *
191
-	 * @param  string  $output
192
-	 * @param  array   $params
193
-	 * @return string
194
-	 */
195
-	public function destination_facet_html( $output, $params ) {
196
-		$possible_keys = array(
197
-			'cf/destination_to_accommodation',
198
-			'cf/destination_to_tour',
199
-			'cf/destination_to_special',
200
-			'cf/destination_to_activity',
201
-			'cf/destination_to_review',
202
-			'cf/destination_to_vehicle',
203
-		);
204
-		if ( in_array( $params['facet']['source'], $possible_keys ) ) {
205
-			$output = $this->destination_facet_render( $params );
206
-		}
207
-		return $output;
208
-	}
209
-
210
-	/**
211
-	 * Generate the facet HTML
212
-	 */
213
-	public function destination_facet_render( $params ) {
214
-		$facet = $params['facet'];
215
-
216
-		$output = '';
217
-		$values = (array) $params['values'];
218
-		$selected_values = (array) $params['selected_values'];
219
-		$soft_limit = empty( $facet['soft_limit'] ) ? 0 : (int) $facet['soft_limit'];
220
-		$countries = array();
221
-		$continents = array();
222
-
223
-		$continent_terms = get_terms(
224
-			array(
225
-				'taxonomy' => 'continent',
226
-			)
227
-		);
228
-
229
-		if ( ! is_wp_error( $continent_terms ) ) {
230
-			foreach ( $continent_terms as $continent ) {
231
-				$continents[ $continent->term_id ] = $continent->slug;
232
-			}
233
-		}
234
-
235
-		//Create a relationship of the facet value and the their depths
236
-		$depths = array();
237
-		$parents = array();
238
-		foreach ( $values as $value ) {
239
-			$depths[ $value['facet_value'] ]  = (int) $value['depth'];
240
-			$parents[ $value['facet_value'] ] = (int) $value['parent_id'];
241
-		}
242
-
243
-		//Determine the current depth and check if the selected values parents are in the selected array.
244
-		$current_depth = 0;
245
-		$additional_values = array();
246
-		if ( ! empty( $selected_values ) ) {
247
-			foreach ( $selected_values as $selected ) {
248
-				if ( $depths[ $selected ] > $current_depth ) {
249
-					$current_depth = $depths[ $selected ];
250
-				}
251
-			}
252
-			$current_depth++;
253
-		}
254
-
255
-		if ( ! empty( $additional_values ) ) {
256
-			$selected_values = array_merge( $selected_values, $additional_values );
257
-		}
258
-
259
-		// This is where the items are sorted by their depth
260
-		$sorted_values = array();
261
-		$stored = $values;
262
-
263
-		//sort the options so
264
-		foreach ( $values as $key => $result ) {
265
-			if ( ! empty( $this->options['display']['engine_search_continent_filter'] ) ) {
266
-				if ( in_array( $result['facet_value'], $continents ) ) {
267
-					$sorted_values[] = $result;
268
-					$destinations    = $this->get_countries( $stored, $result['facet_value'], $continents, '1' );
269
-
270
-					if ( ! empty( $destinations ) ) {
271
-						foreach ( $destinations as $destination ) {
272
-							$sorted_values[] = $destination;
273
-						}
274
-					}
275
-				}
276
-			} else {
277
-				if ( '0' === $result['depth'] || 0 === $result['depth'] ) {
278
-					$sorted_values[] = $result;
279
-					$destinations    = $this->get_regions( $stored, $result['facet_value'], '1' );
280
-
281
-					if ( ! empty( $destinations ) ) {
282
-						foreach ( $destinations as $destination ) {
283
-							$sorted_values[] = $destination;
284
-						}
285
-					}
286
-				}
287
-			}
288
-		}
289
-		$values = $sorted_values;
290
-
291
-		$continent_class = '';
292
-		$country_class = '';
293
-
294
-		// Run through each value and output the values.
295
-		foreach ( $values as $key => $facet ) {
296
-			$depth_type = '';
297
-
298
-			if ( ! empty( $this->options['display']['engine_search_continent_filter'] ) ) {
299
-				switch ( $facet['depth'] ) {
300
-					case '0':
301
-						$depth_type = '';
302
-						$continent_class = in_array( $facet['facet_value'], $selected_values ) ? $depth_type .= ' continent-checked' : '';
303
-						break;
304
-
305
-					case '1':
306
-						$depth_type = 'country' . $continent_class;
307
-						$country_class = in_array( $facet['facet_value'], $selected_values ) ? $depth_type .= ' country-checked' : '';
308
-						break;
309
-
310
-					case '2':
311
-						$depth_type = 'region' . $continent_class . $country_class;
312
-						break;
313
-				}
314
-			} else {
315
-				switch ( $facet['depth'] ) {
316
-					case '0':
317
-						$depth_type = 'country continent-checked';
318
-						$country_class = in_array( $facet['facet_value'], $selected_values ) ? $depth_type .= ' country-checked' : '';
319
-						break;
320
-
321
-					case '1':
322
-						$depth_type = 'region continent-checked' . $country_class;
323
-						break;
324
-				}
325
-			}
326
-
327
-			if ( $facet['depth'] <= $current_depth ) {
328
-				$options[] = $this->format_single_facet( $key, $facet, $selected_values, $depth_type );
329
-			}
330
-		}
331
-
332
-		if ( ! empty( $options ) ) {
333
-			$output = implode( '', $options );
334
-		}
335
-
336
-		return $output;
337
-	}
338
-
339
-	/**
340
-	 * Gets the direct countries from the array.
341
-	 */
342
-	public function get_countries( $values, $parent, $continents, $depth ) {
343
-		$children = array();
344
-		$stored = $values;
345
-
346
-		foreach ( $values as $value ) {
347
-			if ( isset( $continents[ $value['parent_id'] ] ) && $continents[ $value['parent_id'] ] === $parent && $value['depth'] === $depth ) {
348
-				$children[] = $value;
349
-
350
-				$destinations = $this->get_regions( $stored, $value['facet_value'], '2' );
351
-				if ( ! empty( $destinations ) ) {
352
-					foreach ( $destinations as $destination ) {
353
-						$children[] = $destination;
354
-					}
355
-				}
356
-			}
357
-		}
358
-		return $children;
359
-	}
360
-
361
-	/**
362
-	 * Gets the direct regions from the array.
363
-	 */
364
-	public function get_regions( $values, $parent, $depth ) {
365
-		$children = array();
366
-		foreach ( $values as $value ) {
367
-			if ( $value['parent_id'] === $parent && $value['depth'] === $depth ) {
368
-				$children[] = $value;
369
-			}
370
-		}
371
-		return $children;
372
-	}
373
-
374
-	public function format_single_facet( $key, $result, $selected_values, $region = '' ) {
375
-		$temp_html = '';
376
-
377
-		$selected = in_array( $result['facet_value'], $selected_values ) ? ' checked' : '';
378
-		$selected .= ( 0 == $result['counter'] && '' == $selected ) ? ' disabled' : '';
379
-		$selected .= ' ' . $region;
380
-
381
-		$temp_html .= '<div class="facetwp-checkbox' . $selected . '" data-value="' . $result['facet_value'] . '">';
382
-		$temp_html .= $result['facet_display_value'] . ' <span class="facetwp-counter">(' . $result['counter'] . ')</span>';
383
-		$temp_html .= '</div>';
384
-
385
-		return $temp_html;
386
-	}
60
+     }
61
+
62
+     /**
63
+      * Return an instance of this class.
64
+      *
65
+      * @since 1.0.0
66
+      *
67
+      * @return    object \lsx\search\classes\facetwp\Post_Connections()    A single instance of this class.
68
+      */
69
+     public static function get_instance() {
70
+          // If the single instance hasn't been set, set it now.
71
+          if ( null === self::$instance ) {
72
+               self::$instance = new self();
73
+          }
74
+          return self::$instance;
75
+     }
76
+
77
+     /**
78
+      *	Alter the rows and include extra facets rows for the continents
79
+      */
80
+     public function facetwp_index_row_data( $rows, $params ) {
81
+          switch ( $params['facet']['source'] ) {
82
+               case 'cf/destination_to_tour':
83
+               case 'cf/destination_to_accommodation':
84
+                    $countries = array();
85
+
86
+                    foreach ( $rows as $r_index => $row ) {
87
+                         $parent                        = wp_get_post_parent_id( $row['facet_value'] );
88
+                         $rows[ $r_index ]['parent_id'] = $parent;
89
+
90
+                         if ( 0 === $parent || '0' === $parent ) {
91
+                              if ( ! isset( $countries[ $r_index ] ) ) {
92
+                                   $countries[ $r_index ] = $row['facet_value'];
93
+                              }
94
+
95
+                              if ( ! empty( $this->options['display']['engine_search_continent_filter'] ) ) {
96
+                                   $rows[ $r_index ]['depth'] = 1;
97
+                              } else {
98
+                                   $rows[ $r_index ]['depth'] = 0;
99
+                              }
100
+                         } else {
101
+                              if ( ! empty( $this->options['display']['engine_search_continent_filter'] ) ) {
102
+                                   $rows[ $r_index ]['depth'] = 2;
103
+                              } else {
104
+                                   $rows[ $r_index ]['depth'] = 1;
105
+                              }
106
+                         }
107
+                    }
108
+                    if ( ! empty( $this->options['display']['enable_search_continent_filter'] ) ) {
109
+                         if ( ! empty( $countries ) ) {
110
+                              foreach ( $countries as $row_index => $country ) {
111
+                                   $continents   = wp_get_object_terms( $country, 'continent' );
112
+                                   $continent_id = 0;
113
+
114
+                                   if ( ! is_wp_error( $continents ) ) {
115
+                                        $new_row = $params['defaults'];
116
+                                        if ( ! is_array( $continents ) ) {
117
+                                             $continents = array( $continents );
118
+                                        }
119
+
120
+                                        foreach ( $continents as $continent ) {
121
+                                             $new_row['facet_value'] = $continent->slug;
122
+                                             $new_row['facet_display_value'] = $continent->name;
123
+                                             $continent_id = $continent->term_id;
124
+                                             $new_row['depth'] = 0;
125
+                                        }
126
+                                        $rows[] = $new_row;
127
+                                        $rows[ $row_index ]['parent_id'] = $continent_id;
128
+                                   }
129
+                              }
130
+                         }
131
+                    }
132
+
133
+                    break;
134
+
135
+               default:
136
+                    break;
137
+          }
138
+
139
+          return $rows;
140
+     }
141
+
142
+     /**
143
+      * Displays the destination specific settings
144
+      */
145
+     public function facetwp_index_row( $params, $class ) {
146
+          $custom_field = false;
147
+          $meta_key = false;
148
+
149
+          preg_match( '/cf\//', $class->facet['source'], $custom_field );
150
+          preg_match( '/_to_/', $class->facet['source'], $meta_key );
151
+
152
+          if ( ! empty( $custom_field ) && ! empty( $meta_key ) ) {
153
+
154
+               if ( ( 'cf/destination_to_accommodation' === $class->facet['source'] || 'cf/destination_to_tour' === $class->facet['source'] ) && ! empty( $this->options['display']['engine_search_continent_filter'] ) && ( '0' === (string) $params['depth'] ) ) {
155
+                    $title = '';
156
+               } else {
157
+                    $title = get_the_title( $params['facet_value'] );
158
+                    if ( '' !== $title ) {
159
+                         $params['facet_display_value'] = $title;
160
+                    }
161
+                    if ( '' === $title && ! empty( $meta_key ) ) {
162
+                         $params['facet_value'] = '';
163
+                    }
164
+               }
165
+          }
166
+
167
+          // If its a price, save the value as a standard number.
168
+          if ( 'cf/price' === $class->facet['source'] ) {
169
+               $params['facet_value'] = preg_replace( '/[^0-9.]/', '', $params['facet_value'] );
170
+               $params['facet_value'] = ltrim( $params['facet_value'], '.' );
171
+               #$params['facet_value'] = number_format( (int) $params['facet_value'], 2 );
172
+               $params['facet_display_value'] = $params['facet_value'];
173
+          }
174
+
175
+          // If its a duration, save the value as a standard number.
176
+          if ( 'cf/duration' === $class->facet['source'] ) {
177
+               $params['facet_value'] = preg_replace( '/[^0-9 ]/', '', $params['facet_value'] );
178
+               $params['facet_value'] = trim( $params['facet_value'] );
179
+               $params['facet_value'] = explode( ' ', $params['facet_value'] );
180
+               $params['facet_value'] = $params['facet_value'][0];
181
+               #$params['facet_value'] = (int) $params['facet_value'];
182
+               $params['facet_display_value'] = $params['facet_value'];
183
+          }
184
+
185
+          return $params;
186
+     }
187
+
188
+     /**
189
+      * Checks the facet source value and outputs the destination facet HTML if needed.
190
+      *
191
+      * @param  string  $output
192
+      * @param  array   $params
193
+      * @return string
194
+      */
195
+     public function destination_facet_html( $output, $params ) {
196
+          $possible_keys = array(
197
+               'cf/destination_to_accommodation',
198
+               'cf/destination_to_tour',
199
+               'cf/destination_to_special',
200
+               'cf/destination_to_activity',
201
+               'cf/destination_to_review',
202
+               'cf/destination_to_vehicle',
203
+          );
204
+          if ( in_array( $params['facet']['source'], $possible_keys ) ) {
205
+               $output = $this->destination_facet_render( $params );
206
+          }
207
+          return $output;
208
+     }
209
+
210
+     /**
211
+      * Generate the facet HTML
212
+      */
213
+     public function destination_facet_render( $params ) {
214
+          $facet = $params['facet'];
215
+
216
+          $output = '';
217
+          $values = (array) $params['values'];
218
+          $selected_values = (array) $params['selected_values'];
219
+          $soft_limit = empty( $facet['soft_limit'] ) ? 0 : (int) $facet['soft_limit'];
220
+          $countries = array();
221
+          $continents = array();
222
+
223
+          $continent_terms = get_terms(
224
+               array(
225
+                    'taxonomy' => 'continent',
226
+               )
227
+          );
228
+
229
+          if ( ! is_wp_error( $continent_terms ) ) {
230
+               foreach ( $continent_terms as $continent ) {
231
+                    $continents[ $continent->term_id ] = $continent->slug;
232
+               }
233
+          }
234
+
235
+          //Create a relationship of the facet value and the their depths
236
+          $depths = array();
237
+          $parents = array();
238
+          foreach ( $values as $value ) {
239
+               $depths[ $value['facet_value'] ]  = (int) $value['depth'];
240
+               $parents[ $value['facet_value'] ] = (int) $value['parent_id'];
241
+          }
242
+
243
+          //Determine the current depth and check if the selected values parents are in the selected array.
244
+          $current_depth = 0;
245
+          $additional_values = array();
246
+          if ( ! empty( $selected_values ) ) {
247
+               foreach ( $selected_values as $selected ) {
248
+                    if ( $depths[ $selected ] > $current_depth ) {
249
+                         $current_depth = $depths[ $selected ];
250
+                    }
251
+               }
252
+               $current_depth++;
253
+          }
254
+
255
+          if ( ! empty( $additional_values ) ) {
256
+               $selected_values = array_merge( $selected_values, $additional_values );
257
+          }
258
+
259
+          // This is where the items are sorted by their depth
260
+          $sorted_values = array();
261
+          $stored = $values;
262
+
263
+          //sort the options so
264
+          foreach ( $values as $key => $result ) {
265
+               if ( ! empty( $this->options['display']['engine_search_continent_filter'] ) ) {
266
+                    if ( in_array( $result['facet_value'], $continents ) ) {
267
+                         $sorted_values[] = $result;
268
+                         $destinations    = $this->get_countries( $stored, $result['facet_value'], $continents, '1' );
269
+
270
+                         if ( ! empty( $destinations ) ) {
271
+                              foreach ( $destinations as $destination ) {
272
+                                   $sorted_values[] = $destination;
273
+                              }
274
+                         }
275
+                    }
276
+               } else {
277
+                    if ( '0' === $result['depth'] || 0 === $result['depth'] ) {
278
+                         $sorted_values[] = $result;
279
+                         $destinations    = $this->get_regions( $stored, $result['facet_value'], '1' );
280
+
281
+                         if ( ! empty( $destinations ) ) {
282
+                              foreach ( $destinations as $destination ) {
283
+                                   $sorted_values[] = $destination;
284
+                              }
285
+                         }
286
+                    }
287
+               }
288
+          }
289
+          $values = $sorted_values;
290
+
291
+          $continent_class = '';
292
+          $country_class = '';
293
+
294
+          // Run through each value and output the values.
295
+          foreach ( $values as $key => $facet ) {
296
+               $depth_type = '';
297
+
298
+               if ( ! empty( $this->options['display']['engine_search_continent_filter'] ) ) {
299
+                    switch ( $facet['depth'] ) {
300
+                         case '0':
301
+                              $depth_type = '';
302
+                              $continent_class = in_array( $facet['facet_value'], $selected_values ) ? $depth_type .= ' continent-checked' : '';
303
+                              break;
304
+
305
+                         case '1':
306
+                              $depth_type = 'country' . $continent_class;
307
+                              $country_class = in_array( $facet['facet_value'], $selected_values ) ? $depth_type .= ' country-checked' : '';
308
+                              break;
309
+
310
+                         case '2':
311
+                              $depth_type = 'region' . $continent_class . $country_class;
312
+                              break;
313
+                    }
314
+               } else {
315
+                    switch ( $facet['depth'] ) {
316
+                         case '0':
317
+                              $depth_type = 'country continent-checked';
318
+                              $country_class = in_array( $facet['facet_value'], $selected_values ) ? $depth_type .= ' country-checked' : '';
319
+                              break;
320
+
321
+                         case '1':
322
+                              $depth_type = 'region continent-checked' . $country_class;
323
+                              break;
324
+                    }
325
+               }
326
+
327
+               if ( $facet['depth'] <= $current_depth ) {
328
+                    $options[] = $this->format_single_facet( $key, $facet, $selected_values, $depth_type );
329
+               }
330
+          }
331
+
332
+          if ( ! empty( $options ) ) {
333
+               $output = implode( '', $options );
334
+          }
335
+
336
+          return $output;
337
+     }
338
+
339
+     /**
340
+      * Gets the direct countries from the array.
341
+      */
342
+     public function get_countries( $values, $parent, $continents, $depth ) {
343
+          $children = array();
344
+          $stored = $values;
345
+
346
+          foreach ( $values as $value ) {
347
+               if ( isset( $continents[ $value['parent_id'] ] ) && $continents[ $value['parent_id'] ] === $parent && $value['depth'] === $depth ) {
348
+                    $children[] = $value;
349
+
350
+                    $destinations = $this->get_regions( $stored, $value['facet_value'], '2' );
351
+                    if ( ! empty( $destinations ) ) {
352
+                         foreach ( $destinations as $destination ) {
353
+                              $children[] = $destination;
354
+                         }
355
+                    }
356
+               }
357
+          }
358
+          return $children;
359
+     }
360
+
361
+     /**
362
+      * Gets the direct regions from the array.
363
+      */
364
+     public function get_regions( $values, $parent, $depth ) {
365
+          $children = array();
366
+          foreach ( $values as $value ) {
367
+               if ( $value['parent_id'] === $parent && $value['depth'] === $depth ) {
368
+                    $children[] = $value;
369
+               }
370
+          }
371
+          return $children;
372
+     }
373
+
374
+     public function format_single_facet( $key, $result, $selected_values, $region = '' ) {
375
+          $temp_html = '';
376
+
377
+          $selected = in_array( $result['facet_value'], $selected_values ) ? ' checked' : '';
378
+          $selected .= ( 0 == $result['counter'] && '' == $selected ) ? ' disabled' : '';
379
+          $selected .= ' ' . $region;
380
+
381
+          $temp_html .= '<div class="facetwp-checkbox' . $selected . '" data-value="' . $result['facet_value'] . '">';
382
+          $temp_html .= $result['facet_display_value'] . ' <span class="facetwp-counter">(' . $result['counter'] . ')</span>';
383
+          $temp_html .= '</div>';
384
+
385
+          return $temp_html;
386
+     }
387 387
 }
Please login to merge, or discard this patch.
Spacing   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -28,9 +28,9 @@  discard block
 block discarded – undo
28 28
 	 */
29 29
 	public function __construct() {
30 30
 		$this->get_cmb2_options();
31
-		add_filter( 'facetwp_indexer_row_data', array( $this, 'facetwp_index_row_data' ), 10, 2 );
32
-		add_filter( 'facetwp_index_row', array( $this, 'facetwp_index_row' ), 10, 2 );
33
-		add_filter( 'facetwp_facet_html', array( $this, 'destination_facet_html' ), 10, 2 );
31
+		add_filter('facetwp_indexer_row_data', array($this, 'facetwp_index_row_data'), 10, 2);
32
+		add_filter('facetwp_index_row', array($this, 'facetwp_index_row'), 10, 2);
33
+		add_filter('facetwp_facet_html', array($this, 'destination_facet_html'), 10, 2);
34 34
 	}
35 35
 
36 36
 	/**
@@ -39,16 +39,16 @@  discard block
 block discarded – undo
39 39
 	 * @return void
40 40
 	 */
41 41
 	private function get_cmb2_options() {
42
-		$cmb2_options = get_option( 'lsx-search-settings' );
43
-		if ( false !== $cmb2_options && ! empty( $cmb2_options ) ) {
42
+		$cmb2_options = get_option('lsx-search-settings');
43
+		if (false !== $cmb2_options && !empty($cmb2_options)) {
44 44
 			$this->options['display'] = $cmb2_options;
45
-			foreach ( $this->options['display'] as $option_key => $option_value ) {
46
-				if ( is_array( $option_value ) && ! empty( $option_value ) ) {
45
+			foreach ($this->options['display'] as $option_key => $option_value) {
46
+				if (is_array($option_value) && !empty($option_value)) {
47 47
 					$new_values = array();
48
-					foreach ( $option_value as $empty_key => $key_value ) {
49
-						$new_values[ $key_value ] = 'on';
48
+					foreach ($option_value as $empty_key => $key_value) {
49
+						$new_values[$key_value] = 'on';
50 50
 					}
51
-					$this->options['display'][ $option_key ] = $new_values;
51
+					$this->options['display'][$option_key] = $new_values;
52 52
 				}
53 53
 			}
54 54
 		}
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 	 */
69 69
 	public static function get_instance() {
70 70
 		// If the single instance hasn't been set, set it now.
71
-		if ( null === self::$instance ) {
71
+		if (null === self::$instance) {
72 72
 			self::$instance = new self();
73 73
 		}
74 74
 		return self::$instance;
@@ -77,54 +77,54 @@  discard block
 block discarded – undo
77 77
 	/**
78 78
 	 *	Alter the rows and include extra facets rows for the continents
79 79
 	 */
80
-	public function facetwp_index_row_data( $rows, $params ) {
81
-		switch ( $params['facet']['source'] ) {
80
+	public function facetwp_index_row_data($rows, $params) {
81
+		switch ($params['facet']['source']) {
82 82
 			case 'cf/destination_to_tour':
83 83
 			case 'cf/destination_to_accommodation':
84 84
 				$countries = array();
85 85
 
86
-				foreach ( $rows as $r_index => $row ) {
87
-					$parent                        = wp_get_post_parent_id( $row['facet_value'] );
88
-					$rows[ $r_index ]['parent_id'] = $parent;
86
+				foreach ($rows as $r_index => $row) {
87
+					$parent                        = wp_get_post_parent_id($row['facet_value']);
88
+					$rows[$r_index]['parent_id'] = $parent;
89 89
 
90
-					if ( 0 === $parent || '0' === $parent ) {
91
-						if ( ! isset( $countries[ $r_index ] ) ) {
92
-							$countries[ $r_index ] = $row['facet_value'];
90
+					if (0 === $parent || '0' === $parent) {
91
+						if (!isset($countries[$r_index])) {
92
+							$countries[$r_index] = $row['facet_value'];
93 93
 						}
94 94
 
95
-						if ( ! empty( $this->options['display']['engine_search_continent_filter'] ) ) {
96
-							$rows[ $r_index ]['depth'] = 1;
95
+						if (!empty($this->options['display']['engine_search_continent_filter'])) {
96
+							$rows[$r_index]['depth'] = 1;
97 97
 						} else {
98
-							$rows[ $r_index ]['depth'] = 0;
98
+							$rows[$r_index]['depth'] = 0;
99 99
 						}
100 100
 					} else {
101
-						if ( ! empty( $this->options['display']['engine_search_continent_filter'] ) ) {
102
-							$rows[ $r_index ]['depth'] = 2;
101
+						if (!empty($this->options['display']['engine_search_continent_filter'])) {
102
+							$rows[$r_index]['depth'] = 2;
103 103
 						} else {
104
-							$rows[ $r_index ]['depth'] = 1;
104
+							$rows[$r_index]['depth'] = 1;
105 105
 						}
106 106
 					}
107 107
 				}
108
-				if ( ! empty( $this->options['display']['enable_search_continent_filter'] ) ) {
109
-					if ( ! empty( $countries ) ) {
110
-						foreach ( $countries as $row_index => $country ) {
111
-							$continents   = wp_get_object_terms( $country, 'continent' );
108
+				if (!empty($this->options['display']['enable_search_continent_filter'])) {
109
+					if (!empty($countries)) {
110
+						foreach ($countries as $row_index => $country) {
111
+							$continents   = wp_get_object_terms($country, 'continent');
112 112
 							$continent_id = 0;
113 113
 
114
-							if ( ! is_wp_error( $continents ) ) {
114
+							if (!is_wp_error($continents)) {
115 115
 								$new_row = $params['defaults'];
116
-								if ( ! is_array( $continents ) ) {
117
-									$continents = array( $continents );
116
+								if (!is_array($continents)) {
117
+									$continents = array($continents);
118 118
 								}
119 119
 
120
-								foreach ( $continents as $continent ) {
120
+								foreach ($continents as $continent) {
121 121
 									$new_row['facet_value'] = $continent->slug;
122 122
 									$new_row['facet_display_value'] = $continent->name;
123 123
 									$continent_id = $continent->term_id;
124 124
 									$new_row['depth'] = 0;
125 125
 								}
126 126
 								$rows[] = $new_row;
127
-								$rows[ $row_index ]['parent_id'] = $continent_id;
127
+								$rows[$row_index]['parent_id'] = $continent_id;
128 128
 							}
129 129
 						}
130 130
 					}
@@ -142,41 +142,41 @@  discard block
 block discarded – undo
142 142
 	/**
143 143
 	 * Displays the destination specific settings
144 144
 	 */
145
-	public function facetwp_index_row( $params, $class ) {
145
+	public function facetwp_index_row($params, $class) {
146 146
 		$custom_field = false;
147 147
 		$meta_key = false;
148 148
 
149
-		preg_match( '/cf\//', $class->facet['source'], $custom_field );
150
-		preg_match( '/_to_/', $class->facet['source'], $meta_key );
149
+		preg_match('/cf\//', $class->facet['source'], $custom_field);
150
+		preg_match('/_to_/', $class->facet['source'], $meta_key);
151 151
 
152
-		if ( ! empty( $custom_field ) && ! empty( $meta_key ) ) {
152
+		if (!empty($custom_field) && !empty($meta_key)) {
153 153
 
154
-			if ( ( 'cf/destination_to_accommodation' === $class->facet['source'] || 'cf/destination_to_tour' === $class->facet['source'] ) && ! empty( $this->options['display']['engine_search_continent_filter'] ) && ( '0' === (string) $params['depth'] ) ) {
154
+			if (('cf/destination_to_accommodation' === $class->facet['source'] || 'cf/destination_to_tour' === $class->facet['source']) && !empty($this->options['display']['engine_search_continent_filter']) && ('0' === (string) $params['depth'])) {
155 155
 				$title = '';
156 156
 			} else {
157
-				$title = get_the_title( $params['facet_value'] );
158
-				if ( '' !== $title ) {
157
+				$title = get_the_title($params['facet_value']);
158
+				if ('' !== $title) {
159 159
 					$params['facet_display_value'] = $title;
160 160
 				}
161
-				if ( '' === $title && ! empty( $meta_key ) ) {
161
+				if ('' === $title && !empty($meta_key)) {
162 162
 					$params['facet_value'] = '';
163 163
 				}
164 164
 			}
165 165
 		}
166 166
 
167 167
 		// If its a price, save the value as a standard number.
168
-		if ( 'cf/price' === $class->facet['source'] ) {
169
-			$params['facet_value'] = preg_replace( '/[^0-9.]/', '', $params['facet_value'] );
170
-			$params['facet_value'] = ltrim( $params['facet_value'], '.' );
168
+		if ('cf/price' === $class->facet['source']) {
169
+			$params['facet_value'] = preg_replace('/[^0-9.]/', '', $params['facet_value']);
170
+			$params['facet_value'] = ltrim($params['facet_value'], '.');
171 171
 			#$params['facet_value'] = number_format( (int) $params['facet_value'], 2 );
172 172
 			$params['facet_display_value'] = $params['facet_value'];
173 173
 		}
174 174
 
175 175
 		// If its a duration, save the value as a standard number.
176
-		if ( 'cf/duration' === $class->facet['source'] ) {
177
-			$params['facet_value'] = preg_replace( '/[^0-9 ]/', '', $params['facet_value'] );
178
-			$params['facet_value'] = trim( $params['facet_value'] );
179
-			$params['facet_value'] = explode( ' ', $params['facet_value'] );
176
+		if ('cf/duration' === $class->facet['source']) {
177
+			$params['facet_value'] = preg_replace('/[^0-9 ]/', '', $params['facet_value']);
178
+			$params['facet_value'] = trim($params['facet_value']);
179
+			$params['facet_value'] = explode(' ', $params['facet_value']);
180 180
 			$params['facet_value'] = $params['facet_value'][0];
181 181
 			#$params['facet_value'] = (int) $params['facet_value'];
182 182
 			$params['facet_display_value'] = $params['facet_value'];
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 	 * @param  array   $params
193 193
 	 * @return string
194 194
 	 */
195
-	public function destination_facet_html( $output, $params ) {
195
+	public function destination_facet_html($output, $params) {
196 196
 		$possible_keys = array(
197 197
 			'cf/destination_to_accommodation',
198 198
 			'cf/destination_to_tour',
@@ -201,8 +201,8 @@  discard block
 block discarded – undo
201 201
 			'cf/destination_to_review',
202 202
 			'cf/destination_to_vehicle',
203 203
 		);
204
-		if ( in_array( $params['facet']['source'], $possible_keys ) ) {
205
-			$output = $this->destination_facet_render( $params );
204
+		if (in_array($params['facet']['source'], $possible_keys)) {
205
+			$output = $this->destination_facet_render($params);
206 206
 		}
207 207
 		return $output;
208 208
 	}
@@ -210,13 +210,13 @@  discard block
 block discarded – undo
210 210
 	/**
211 211
 	 * Generate the facet HTML
212 212
 	 */
213
-	public function destination_facet_render( $params ) {
213
+	public function destination_facet_render($params) {
214 214
 		$facet = $params['facet'];
215 215
 
216 216
 		$output = '';
217 217
 		$values = (array) $params['values'];
218 218
 		$selected_values = (array) $params['selected_values'];
219
-		$soft_limit = empty( $facet['soft_limit'] ) ? 0 : (int) $facet['soft_limit'];
219
+		$soft_limit = empty($facet['soft_limit']) ? 0 : (int) $facet['soft_limit'];
220 220
 		$countries = array();
221 221
 		$continents = array();
222 222
 
@@ -226,34 +226,34 @@  discard block
 block discarded – undo
226 226
 			)
227 227
 		);
228 228
 
229
-		if ( ! is_wp_error( $continent_terms ) ) {
230
-			foreach ( $continent_terms as $continent ) {
231
-				$continents[ $continent->term_id ] = $continent->slug;
229
+		if (!is_wp_error($continent_terms)) {
230
+			foreach ($continent_terms as $continent) {
231
+				$continents[$continent->term_id] = $continent->slug;
232 232
 			}
233 233
 		}
234 234
 
235 235
 		//Create a relationship of the facet value and the their depths
236 236
 		$depths = array();
237 237
 		$parents = array();
238
-		foreach ( $values as $value ) {
239
-			$depths[ $value['facet_value'] ]  = (int) $value['depth'];
240
-			$parents[ $value['facet_value'] ] = (int) $value['parent_id'];
238
+		foreach ($values as $value) {
239
+			$depths[$value['facet_value']]  = (int) $value['depth'];
240
+			$parents[$value['facet_value']] = (int) $value['parent_id'];
241 241
 		}
242 242
 
243 243
 		//Determine the current depth and check if the selected values parents are in the selected array.
244 244
 		$current_depth = 0;
245 245
 		$additional_values = array();
246
-		if ( ! empty( $selected_values ) ) {
247
-			foreach ( $selected_values as $selected ) {
248
-				if ( $depths[ $selected ] > $current_depth ) {
249
-					$current_depth = $depths[ $selected ];
246
+		if (!empty($selected_values)) {
247
+			foreach ($selected_values as $selected) {
248
+				if ($depths[$selected] > $current_depth) {
249
+					$current_depth = $depths[$selected];
250 250
 				}
251 251
 			}
252 252
 			$current_depth++;
253 253
 		}
254 254
 
255
-		if ( ! empty( $additional_values ) ) {
256
-			$selected_values = array_merge( $selected_values, $additional_values );
255
+		if (!empty($additional_values)) {
256
+			$selected_values = array_merge($selected_values, $additional_values);
257 257
 		}
258 258
 
259 259
 		// This is where the items are sorted by their depth
@@ -261,25 +261,25 @@  discard block
 block discarded – undo
261 261
 		$stored = $values;
262 262
 
263 263
 		//sort the options so
264
-		foreach ( $values as $key => $result ) {
265
-			if ( ! empty( $this->options['display']['engine_search_continent_filter'] ) ) {
266
-				if ( in_array( $result['facet_value'], $continents ) ) {
264
+		foreach ($values as $key => $result) {
265
+			if (!empty($this->options['display']['engine_search_continent_filter'])) {
266
+				if (in_array($result['facet_value'], $continents)) {
267 267
 					$sorted_values[] = $result;
268
-					$destinations    = $this->get_countries( $stored, $result['facet_value'], $continents, '1' );
268
+					$destinations    = $this->get_countries($stored, $result['facet_value'], $continents, '1');
269 269
 
270
-					if ( ! empty( $destinations ) ) {
271
-						foreach ( $destinations as $destination ) {
270
+					if (!empty($destinations)) {
271
+						foreach ($destinations as $destination) {
272 272
 							$sorted_values[] = $destination;
273 273
 						}
274 274
 					}
275 275
 				}
276 276
 			} else {
277
-				if ( '0' === $result['depth'] || 0 === $result['depth'] ) {
277
+				if ('0' === $result['depth'] || 0 === $result['depth']) {
278 278
 					$sorted_values[] = $result;
279
-					$destinations    = $this->get_regions( $stored, $result['facet_value'], '1' );
279
+					$destinations    = $this->get_regions($stored, $result['facet_value'], '1');
280 280
 
281
-					if ( ! empty( $destinations ) ) {
282
-						foreach ( $destinations as $destination ) {
281
+					if (!empty($destinations)) {
282
+						foreach ($destinations as $destination) {
283 283
 							$sorted_values[] = $destination;
284 284
 						}
285 285
 					}
@@ -292,45 +292,45 @@  discard block
 block discarded – undo
292 292
 		$country_class = '';
293 293
 
294 294
 		// Run through each value and output the values.
295
-		foreach ( $values as $key => $facet ) {
295
+		foreach ($values as $key => $facet) {
296 296
 			$depth_type = '';
297 297
 
298
-			if ( ! empty( $this->options['display']['engine_search_continent_filter'] ) ) {
299
-				switch ( $facet['depth'] ) {
298
+			if (!empty($this->options['display']['engine_search_continent_filter'])) {
299
+				switch ($facet['depth']) {
300 300
 					case '0':
301 301
 						$depth_type = '';
302
-						$continent_class = in_array( $facet['facet_value'], $selected_values ) ? $depth_type .= ' continent-checked' : '';
302
+						$continent_class = in_array($facet['facet_value'], $selected_values) ? $depth_type .= ' continent-checked' : '';
303 303
 						break;
304 304
 
305 305
 					case '1':
306
-						$depth_type = 'country' . $continent_class;
307
-						$country_class = in_array( $facet['facet_value'], $selected_values ) ? $depth_type .= ' country-checked' : '';
306
+						$depth_type = 'country'.$continent_class;
307
+						$country_class = in_array($facet['facet_value'], $selected_values) ? $depth_type .= ' country-checked' : '';
308 308
 						break;
309 309
 
310 310
 					case '2':
311
-						$depth_type = 'region' . $continent_class . $country_class;
311
+						$depth_type = 'region'.$continent_class.$country_class;
312 312
 						break;
313 313
 				}
314 314
 			} else {
315
-				switch ( $facet['depth'] ) {
315
+				switch ($facet['depth']) {
316 316
 					case '0':
317 317
 						$depth_type = 'country continent-checked';
318
-						$country_class = in_array( $facet['facet_value'], $selected_values ) ? $depth_type .= ' country-checked' : '';
318
+						$country_class = in_array($facet['facet_value'], $selected_values) ? $depth_type .= ' country-checked' : '';
319 319
 						break;
320 320
 
321 321
 					case '1':
322
-						$depth_type = 'region continent-checked' . $country_class;
322
+						$depth_type = 'region continent-checked'.$country_class;
323 323
 						break;
324 324
 				}
325 325
 			}
326 326
 
327
-			if ( $facet['depth'] <= $current_depth ) {
328
-				$options[] = $this->format_single_facet( $key, $facet, $selected_values, $depth_type );
327
+			if ($facet['depth'] <= $current_depth) {
328
+				$options[] = $this->format_single_facet($key, $facet, $selected_values, $depth_type);
329 329
 			}
330 330
 		}
331 331
 
332
-		if ( ! empty( $options ) ) {
333
-			$output = implode( '', $options );
332
+		if (!empty($options)) {
333
+			$output = implode('', $options);
334 334
 		}
335 335
 
336 336
 		return $output;
@@ -339,17 +339,17 @@  discard block
 block discarded – undo
339 339
 	/**
340 340
 	 * Gets the direct countries from the array.
341 341
 	 */
342
-	public function get_countries( $values, $parent, $continents, $depth ) {
342
+	public function get_countries($values, $parent, $continents, $depth) {
343 343
 		$children = array();
344 344
 		$stored = $values;
345 345
 
346
-		foreach ( $values as $value ) {
347
-			if ( isset( $continents[ $value['parent_id'] ] ) && $continents[ $value['parent_id'] ] === $parent && $value['depth'] === $depth ) {
346
+		foreach ($values as $value) {
347
+			if (isset($continents[$value['parent_id']]) && $continents[$value['parent_id']] === $parent && $value['depth'] === $depth) {
348 348
 				$children[] = $value;
349 349
 
350
-				$destinations = $this->get_regions( $stored, $value['facet_value'], '2' );
351
-				if ( ! empty( $destinations ) ) {
352
-					foreach ( $destinations as $destination ) {
350
+				$destinations = $this->get_regions($stored, $value['facet_value'], '2');
351
+				if (!empty($destinations)) {
352
+					foreach ($destinations as $destination) {
353 353
 						$children[] = $destination;
354 354
 					}
355 355
 				}
@@ -361,25 +361,25 @@  discard block
 block discarded – undo
361 361
 	/**
362 362
 	 * Gets the direct regions from the array.
363 363
 	 */
364
-	public function get_regions( $values, $parent, $depth ) {
364
+	public function get_regions($values, $parent, $depth) {
365 365
 		$children = array();
366
-		foreach ( $values as $value ) {
367
-			if ( $value['parent_id'] === $parent && $value['depth'] === $depth ) {
366
+		foreach ($values as $value) {
367
+			if ($value['parent_id'] === $parent && $value['depth'] === $depth) {
368 368
 				$children[] = $value;
369 369
 			}
370 370
 		}
371 371
 		return $children;
372 372
 	}
373 373
 
374
-	public function format_single_facet( $key, $result, $selected_values, $region = '' ) {
374
+	public function format_single_facet($key, $result, $selected_values, $region = '') {
375 375
 		$temp_html = '';
376 376
 
377
-		$selected = in_array( $result['facet_value'], $selected_values ) ? ' checked' : '';
378
-		$selected .= ( 0 == $result['counter'] && '' == $selected ) ? ' disabled' : '';
379
-		$selected .= ' ' . $region;
377
+		$selected = in_array($result['facet_value'], $selected_values) ? ' checked' : '';
378
+		$selected .= (0 == $result['counter'] && '' == $selected) ? ' disabled' : '';
379
+		$selected .= ' '.$region;
380 380
 
381
-		$temp_html .= '<div class="facetwp-checkbox' . $selected . '" data-value="' . $result['facet_value'] . '">';
382
-		$temp_html .= $result['facet_display_value'] . ' <span class="facetwp-counter">(' . $result['counter'] . ')</span>';
381
+		$temp_html .= '<div class="facetwp-checkbox'.$selected.'" data-value="'.$result['facet_value'].'">';
382
+		$temp_html .= $result['facet_display_value'].' <span class="facetwp-counter">('.$result['counter'].')</span>';
383 383
 		$temp_html .= '</div>';
384 384
 
385 385
 		return $temp_html;
Please login to merge, or discard this patch.
classes/class-lsx-search-shortcode.php 2 patches
Indentation   +164 added lines, -164 removed lines patch added patch discarded remove patch
@@ -6,86 +6,86 @@  discard block
 block discarded – undo
6 6
  */
7 7
 class LSX_Search_Shortcode {
8 8
 
9
-	/**
10
-	 * Construct method.
11
-	 */
12
-	public function __construct() {
13
-		add_shortcode( 'lsx_search_form', array( $this, 'search_form' ) );
14
-	}
9
+     /**
10
+      * Construct method.
11
+      */
12
+     public function __construct() {
13
+          add_shortcode( 'lsx_search_form', array( $this, 'search_form' ) );
14
+     }
15 15
 
16
-	/**
17
-	 * Outputs the appropriate search form
18
-	 */
19
-	public function search_form( $atts = array() ) {
20
-		$classes = 'search-form lsx-search-form form-inline';
16
+     /**
17
+      * Outputs the appropriate search form
18
+      */
19
+     public function search_form( $atts = array() ) {
20
+          $classes = 'search-form lsx-search-form form-inline';
21 21
 
22
-		if ( isset( $atts['class'] ) ) {
23
-			$classes .= $atts['class'];
24
-		}
22
+          if ( isset( $atts['class'] ) ) {
23
+               $classes .= $atts['class'];
24
+          }
25 25
 
26
-		$placeholder = __( 'Where do you want to go?', 'lsx-search' );
26
+          $placeholder = __( 'Where do you want to go?', 'lsx-search' );
27 27
 
28
-		if ( isset( $atts['placeholder'] ) ) {
29
-			$placeholder = $atts['placeholder'];
30
-		}
28
+          if ( isset( $atts['placeholder'] ) ) {
29
+               $placeholder = $atts['placeholder'];
30
+          }
31 31
 
32
-		$action = '/';
32
+          $action = '/';
33 33
 
34
-		if ( isset( $atts['action'] ) ) {
35
-			$action = $atts['action'];
36
-		}
34
+          if ( isset( $atts['action'] ) ) {
35
+               $action = $atts['action'];
36
+          }
37 37
 
38
-		$method = 'get';
38
+          $method = 'get';
39 39
 
40
-		if ( isset( $atts['method'] ) ) {
41
-			$method = $atts['method'];
42
-		}
40
+          if ( isset( $atts['method'] ) ) {
41
+               $method = $atts['method'];
42
+          }
43 43
 
44
-		$button_label = __( 'Search', 'lsx-search' );
44
+          $button_label = __( 'Search', 'lsx-search' );
45 45
 
46
-		if ( isset( $atts['button_label'] ) ) {
47
-			$button_label = $atts['button_label'];
48
-		}
46
+          if ( isset( $atts['button_label'] ) ) {
47
+               $button_label = $atts['button_label'];
48
+          }
49 49
 
50
-		$button_class = 'btn cta-btn ';
50
+          $button_class = 'btn cta-btn ';
51 51
 
52
-		if ( isset( $atts['button_class'] ) ) {
53
-			$button_class .= $atts['button_class'];
54
-		}
52
+          if ( isset( $atts['button_class'] ) ) {
53
+               $button_class .= $atts['button_class'];
54
+          }
55 55
 
56
-		$engine = false;
56
+          $engine = false;
57 57
 
58
-		if ( isset( $atts['engine'] ) ) {
59
-			$engine = $atts['engine'];
60
-		}
58
+          if ( isset( $atts['engine'] ) ) {
59
+               $engine = $atts['engine'];
60
+          }
61 61
 
62
-		$engine_select = false;
62
+          $engine_select = false;
63 63
 
64
-		if ( isset( $atts['engine_select'] ) ) {
65
-			$engine_select = true;
66
-		}
64
+          if ( isset( $atts['engine_select'] ) ) {
65
+               $engine_select = true;
66
+          }
67 67
 
68
-		$display_search_field = true;
68
+          $display_search_field = true;
69 69
 
70
-		if ( isset( $atts['search_field'] ) ) {
71
-			$display_search_field = (boolean) $atts['search_field'];
72
-		}
70
+          if ( isset( $atts['search_field'] ) ) {
71
+               $display_search_field = (boolean) $atts['search_field'];
72
+          }
73 73
 
74
-		$facets = false;
74
+          $facets = false;
75 75
 
76
-		if ( isset( $atts['facets'] ) ) {
77
-			$facets = $atts['facets'];
78
-		}
76
+          if ( isset( $atts['facets'] ) ) {
77
+               $facets = $atts['facets'];
78
+          }
79 79
 
80
-		$combo_box = false;
80
+          $combo_box = false;
81 81
 
82
-		if ( isset( $atts['combo_box'] ) ) {
83
-			$combo_box = true;
84
-		}
82
+          if ( isset( $atts['combo_box'] ) ) {
83
+               $combo_box = true;
84
+          }
85 85
 
86
-		$return = '';
86
+          $return = '';
87 87
 
88
-		ob_start(); ?>
88
+          ob_start(); ?>
89 89
 
90 90
 		<?php do_action( 'lsx_search_form_before' ); ?>
91 91
 
@@ -103,62 +103,62 @@  discard block
 block discarded – undo
103 103
 					<?php endif; ?>
104 104
 
105 105
 					<?php if ( false !== $engine_select && false !== $engine && 'default' !== $engine ) :
106
-						$engines = explode( '|',$engine ); ?>
106
+                              $engines = explode( '|',$engine ); ?>
107 107
 						<div class="field engine-select">
108 108
 							<div class="dropdown nav-item">
109 109
 								<?php
110
-								$plural = 's';
111
-								if ( 'accommodation' === $engine[0] ) {
112
-									$plural = '';
113
-								}
114
-								?>
110
+                                        $plural = 's';
111
+                                        if ( 'accommodation' === $engine[0] ) {
112
+                                             $plural = '';
113
+                                        }
114
+                                        ?>
115 115
 								<button id="engine" data-selection="<?php echo esc_attr( $engines[0] ); ?>" class="btn border-btn btn-dropdown dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><?php echo esc_html( ucwords( str_replace( '_', ' ',$engines[0] ) ) . $plural ); ?> <span class="caret"></span></button>
116 116
 								<ul class="dropdown-menu">
117 117
 									<?php
118
-									foreach ( $engines as $engine ) {
119
-										$plural = 's';
120
-										if ( 'accommodation' === $engine ) {
121
-											$plural = '';
122
-										}
123
-										echo '<li><a data-value="' . esc_attr( $engine ) . '" href="#">' . esc_html( ucfirst( str_replace( '_', ' ',$engine ) ) . $plural ) . '</a></li>';
124
-									}
125
-									?>
118
+                                             foreach ( $engines as $engine ) {
119
+                                                  $plural = 's';
120
+                                                  if ( 'accommodation' === $engine ) {
121
+                                                       $plural = '';
122
+                                                  }
123
+                                                  echo '<li><a data-value="' . esc_attr( $engine ) . '" href="#">' . esc_html( ucfirst( str_replace( '_', ' ',$engine ) ) . $plural ) . '</a></li>';
124
+                                             }
125
+                                             ?>
126 126
 								</ul>
127 127
 							</div>
128 128
 						</div>
129 129
 					<?php endif; ?>
130 130
 
131 131
 					<?php if ( false !== $facets ) {
132
-						$facets = explode( '|',$facets );
132
+                              $facets = explode( '|',$facets );
133 133
 
134
-						if ( ! is_array( $facets ) ) {
135
-							$facets = array( $facets );
136
-						}
134
+                              if ( ! is_array( $facets ) ) {
135
+                                   $facets = array( $facets );
136
+                              }
137 137
 
138
-						$field_class = 'field';
138
+                              $field_class = 'field';
139 139
 
140
-						if ( false !== $combo_box ) {
141
-							$this->combo_box( $facets );
142
-							$field_class .= ' combination-toggle hidden';
143
-						}
140
+                              if ( false !== $combo_box ) {
141
+                                   $this->combo_box( $facets );
142
+                                   $field_class .= ' combination-toggle hidden';
143
+                              }
144 144
 
145
-						foreach ( $facets as $facet ) {
146
-							?>
145
+                              foreach ( $facets as $facet ) {
146
+                                   ?>
147 147
 							<div class="<?php echo wp_kses_post( $field_class ); ?>">
148 148
 								<?php
149
-								$facet = FWP()->helper->get_facet_by_name( $facet );
150
-								if ( isset( $facet['source'] ) ) {
151
-									$values = $this->get_form_facet( $facet['source'] );
152
-								} else {
153
-									$values = array();
154
-								}
155
-								$facet_display_type = apply_filters( 'lsx_search_form_field_type', 'select', $facet );
156
-								$this->display_form_field( $facet_display_type,$facet,$values,$combo_box );
157
-								?>
149
+                                        $facet = FWP()->helper->get_facet_by_name( $facet );
150
+                                        if ( isset( $facet['source'] ) ) {
151
+                                             $values = $this->get_form_facet( $facet['source'] );
152
+                                        } else {
153
+                                             $values = array();
154
+                                        }
155
+                                        $facet_display_type = apply_filters( 'lsx_search_form_field_type', 'select', $facet );
156
+                                        $this->display_form_field( $facet_display_type,$facet,$values,$combo_box );
157
+                                        ?>
158 158
 							</div>
159 159
 							<?php
160
-						}
161
-					} ?>
160
+                              }
161
+                         } ?>
162 162
 
163 163
 					<div class="field submit-button">
164 164
 						<button class="<?php echo esc_attr( $button_class ); ?>" type="submit"><?php echo wp_kses_post( $button_label ); ?></button>
@@ -177,19 +177,19 @@  discard block
 block discarded – undo
177 177
 
178 178
 		<?php do_action( 'lsx_search_form_after' ); ?>
179 179
 		<?php
180
-		$return = ob_get_clean();
180
+          $return = ob_get_clean();
181 181
 
182
-		$return = preg_replace( '/[\n]+/', ' ', $return );
183
-		$return = preg_replace( '/[\t]+/', ' ', $return );
182
+          $return = preg_replace( '/[\n]+/', ' ', $return );
183
+          $return = preg_replace( '/[\t]+/', ' ', $return );
184 184
 
185
-		return $return;
186
-	}
185
+          return $return;
186
+     }
187 187
 
188
-	/**
189
-	 * Outputs the combination selector
190
-	 */
191
-	public function combo_box( $facets ) {
192
-		?>
188
+     /**
189
+      * Outputs the combination selector
190
+      */
191
+     public function combo_box( $facets ) {
192
+          ?>
193 193
 		<div class="field combination-dropdown">
194 194
 			<div class="dropdown">
195 195
 				<button data-selection="0" class="btn border-btn btn-dropdown dropdown-toggle btn-combination" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
@@ -201,65 +201,65 @@  discard block
 block discarded – undo
201 201
 					<li style="display: none;"><a class="default" data-value="0" href="#"><?php esc_attr_e( 'Select ', 'lsx-search' ); ?></a></li>
202 202
 
203 203
 					<?php foreach ( $facets as $facet ) {
204
-						$facet = FWP()->helper->get_facet_by_name( $facet );
205
-						?>
204
+                              $facet = FWP()->helper->get_facet_by_name( $facet );
205
+                              ?>
206 206
 						<li><a data-value="fwp_<?php echo wp_kses_post( $facet['name'] ); ?>" href="#"><?php echo wp_kses_post( $facet['label'] ); ?></a></li>
207 207
 					<?php } ?>
208 208
 				</ul>
209 209
 			</div>
210 210
 		</div>
211 211
 		<?php
212
-	}
213
-
214
-	/**
215
-	 * Grabs the Values for the Facet in Question.
216
-	 */
217
-	protected function get_form_facet( $facet_source = false ) {
218
-		global $wpdb;
219
-
220
-		$values = array();
221
-		$select = 'f.facet_value, f.facet_display_value';
222
-		$from = "{$wpdb->prefix}facetwp_index f";
223
-		$where = "f.facet_source = '{$facet_source}'";
224
-
225
-		//Check if the current facet is showing destinations.
226
-		if ( stripos( $facet_source, 'destination_to' ) ) {
227
-			$from .= " INNER JOIN {$wpdb->posts} p ON f.facet_value = p.ID";
228
-			$where .= " AND p.post_parent = '0'";
229
-
230
-		}
231
-
232
-		$response = $wpdb->prepare( "SELECT {$select} FROM {$from} WHERE {$where}" );// WPCS: unprepared SQL OK.
233
-
234
-		if ( ! empty( $response ) ) {
235
-			foreach ( $response as $re ) {
236
-				$display_value = $re->facet_display_value;
237
-				if ( function_exists( 'pll_translate_string' ) ) {
238
-					$current_lang = pll_current_language();
239
-					$display_value = pll_translate_string( $display_value, $current_lang );
240
-				}
241
-				$display_value = apply_filters( 'lsx_search_facetwp_display_value', $display_value, $re->facet_value );
242
-				$values[ $re->facet_value ] = $display_value;
243
-			}
244
-		}
245
-
246
-		asort( $values );
247
-		return $values;
248
-	}
249
-
250
-	/**
251
-	 * Change FaceWP pagination HTML to be equal main pagination (WP-PageNavi)
252
-	 */
253
-	public function display_form_field( $type = 'select', $facet = array(), $values = array(), $combo = false ) {
254
-		if ( empty( $facet ) ) {
255
-			return;
256
-		}
257
-
258
-		$source = 'fwp_' . $facet['name'];
259
-
260
-		switch ( $type ) {
261
-
262
-			case 'select': ?>
212
+     }
213
+
214
+     /**
215
+      * Grabs the Values for the Facet in Question.
216
+      */
217
+     protected function get_form_facet( $facet_source = false ) {
218
+          global $wpdb;
219
+
220
+          $values = array();
221
+          $select = 'f.facet_value, f.facet_display_value';
222
+          $from = "{$wpdb->prefix}facetwp_index f";
223
+          $where = "f.facet_source = '{$facet_source}'";
224
+
225
+          //Check if the current facet is showing destinations.
226
+          if ( stripos( $facet_source, 'destination_to' ) ) {
227
+               $from .= " INNER JOIN {$wpdb->posts} p ON f.facet_value = p.ID";
228
+               $where .= " AND p.post_parent = '0'";
229
+
230
+          }
231
+
232
+          $response = $wpdb->prepare( "SELECT {$select} FROM {$from} WHERE {$where}" );// WPCS: unprepared SQL OK.
233
+
234
+          if ( ! empty( $response ) ) {
235
+               foreach ( $response as $re ) {
236
+                    $display_value = $re->facet_display_value;
237
+                    if ( function_exists( 'pll_translate_string' ) ) {
238
+                         $current_lang = pll_current_language();
239
+                         $display_value = pll_translate_string( $display_value, $current_lang );
240
+                    }
241
+                    $display_value = apply_filters( 'lsx_search_facetwp_display_value', $display_value, $re->facet_value );
242
+                    $values[ $re->facet_value ] = $display_value;
243
+               }
244
+          }
245
+
246
+          asort( $values );
247
+          return $values;
248
+     }
249
+
250
+     /**
251
+      * Change FaceWP pagination HTML to be equal main pagination (WP-PageNavi)
252
+      */
253
+     public function display_form_field( $type = 'select', $facet = array(), $values = array(), $combo = false ) {
254
+          if ( empty( $facet ) ) {
255
+               return;
256
+          }
257
+
258
+          $source = 'fwp_' . $facet['name'];
259
+
260
+          switch ( $type ) {
261
+
262
+               case 'select': ?>
263 263
 				<div class="dropdown nav-item <?php if ( true === $combo ) { echo 'combination-dropdown'; } ?>">
264 264
 					<button data-selection="0" class="btn border-btn btn-dropdown dropdown-toggle" type="button" id="<?php echo wp_kses_post( $source ); ?>" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
265 265
 						<?php echo esc_attr( apply_filters( 'lsx_search_facet_label', __( 'Select', 'lsx-search' ) . ' ' . wp_kses_post( $facet['label'] ) ) ); ?>
@@ -271,10 +271,10 @@  discard block
 block discarded – undo
271 271
 							<li style="display: none;">
272 272
 								<a class="default" data-value="0" href="#">
273 273
 									<?php
274
-										$facet_label = __( 'Select ', 'lsx-search' ) . ' ' . wp_kses_post( $facet['label'] );
275
-										$facet_label = apply_filters( 'lsx_search_facet_label', $facet_label );
276
-										echo esc_attr( $facet_label );
277
-									?>
274
+                                                  $facet_label = __( 'Select ', 'lsx-search' ) . ' ' . wp_kses_post( $facet['label'] );
275
+                                                  $facet_label = apply_filters( 'lsx_search_facet_label', $facet_label );
276
+                                                  echo esc_attr( $facet_label );
277
+                                             ?>
278 278
 								</a>
279 279
 							</li>
280 280
 
@@ -287,17 +287,17 @@  discard block
 block discarded – undo
287 287
 					</ul>
288 288
 				</div>
289 289
 				<?php
290
-				break;
290
+                    break;
291 291
 
292
-			case 'datepicker': ?>
292
+               case 'datepicker': ?>
293 293
 				<div class="datepicker nav-item">
294 294
 					<input autocomplete="off" class="datepicker-value" placeholder="<?php echo wp_kses_post( apply_filters( 'lsx_search_facet_label' , $facet['label'] ) ); ?>" name="<?php echo wp_kses_post( $source ); ?>"  id="<?php echo wp_kses_post( $source ); ?>" type="text" value="" />
295 295
 				</div>
296 296
 			<?php
297
-				break;
298
-		}
297
+                    break;
298
+          }
299 299
 
300
-		?>
300
+          ?>
301 301
 
302 302
 	<?php }
303 303
 }
Please login to merge, or discard this patch.
Spacing   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -10,76 +10,76 @@  discard block
 block discarded – undo
10 10
 	 * Construct method.
11 11
 	 */
12 12
 	public function __construct() {
13
-		add_shortcode( 'lsx_search_form', array( $this, 'search_form' ) );
13
+		add_shortcode('lsx_search_form', array($this, 'search_form'));
14 14
 	}
15 15
 
16 16
 	/**
17 17
 	 * Outputs the appropriate search form
18 18
 	 */
19
-	public function search_form( $atts = array() ) {
19
+	public function search_form($atts = array()) {
20 20
 		$classes = 'search-form lsx-search-form form-inline';
21 21
 
22
-		if ( isset( $atts['class'] ) ) {
22
+		if (isset($atts['class'])) {
23 23
 			$classes .= $atts['class'];
24 24
 		}
25 25
 
26
-		$placeholder = __( 'Where do you want to go?', 'lsx-search' );
26
+		$placeholder = __('Where do you want to go?', 'lsx-search');
27 27
 
28
-		if ( isset( $atts['placeholder'] ) ) {
28
+		if (isset($atts['placeholder'])) {
29 29
 			$placeholder = $atts['placeholder'];
30 30
 		}
31 31
 
32 32
 		$action = '/';
33 33
 
34
-		if ( isset( $atts['action'] ) ) {
34
+		if (isset($atts['action'])) {
35 35
 			$action = $atts['action'];
36 36
 		}
37 37
 
38 38
 		$method = 'get';
39 39
 
40
-		if ( isset( $atts['method'] ) ) {
40
+		if (isset($atts['method'])) {
41 41
 			$method = $atts['method'];
42 42
 		}
43 43
 
44
-		$button_label = __( 'Search', 'lsx-search' );
44
+		$button_label = __('Search', 'lsx-search');
45 45
 
46
-		if ( isset( $atts['button_label'] ) ) {
46
+		if (isset($atts['button_label'])) {
47 47
 			$button_label = $atts['button_label'];
48 48
 		}
49 49
 
50 50
 		$button_class = 'btn cta-btn ';
51 51
 
52
-		if ( isset( $atts['button_class'] ) ) {
52
+		if (isset($atts['button_class'])) {
53 53
 			$button_class .= $atts['button_class'];
54 54
 		}
55 55
 
56 56
 		$engine = false;
57 57
 
58
-		if ( isset( $atts['engine'] ) ) {
58
+		if (isset($atts['engine'])) {
59 59
 			$engine = $atts['engine'];
60 60
 		}
61 61
 
62 62
 		$engine_select = false;
63 63
 
64
-		if ( isset( $atts['engine_select'] ) ) {
64
+		if (isset($atts['engine_select'])) {
65 65
 			$engine_select = true;
66 66
 		}
67 67
 
68 68
 		$display_search_field = true;
69 69
 
70
-		if ( isset( $atts['search_field'] ) ) {
70
+		if (isset($atts['search_field'])) {
71 71
 			$display_search_field = (boolean) $atts['search_field'];
72 72
 		}
73 73
 
74 74
 		$facets = false;
75 75
 
76
-		if ( isset( $atts['facets'] ) ) {
76
+		if (isset($atts['facets'])) {
77 77
 			$facets = $atts['facets'];
78 78
 		}
79 79
 
80 80
 		$combo_box = false;
81 81
 
82
-		if ( isset( $atts['combo_box'] ) ) {
82
+		if (isset($atts['combo_box'])) {
83 83
 			$combo_box = true;
84 84
 		}
85 85
 
@@ -87,40 +87,40 @@  discard block
 block discarded – undo
87 87
 
88 88
 		ob_start(); ?>
89 89
 
90
-		<?php do_action( 'lsx_search_form_before' ); ?>
90
+		<?php do_action('lsx_search_form_before'); ?>
91 91
 
92 92
 		<nav class="navbar navbar-light bg-light">
93 93
 
94
-			<form class="<?php echo esc_attr( $classes ); ?>" action="<?php echo esc_attr( $action ); ?>" method="<?php echo esc_attr( $method ); ?>">
94
+			<form class="<?php echo esc_attr($classes); ?>" action="<?php echo esc_attr($action); ?>" method="<?php echo esc_attr($method); ?>">
95 95
 
96
-				<?php do_action( 'lsx_search_form_top' ); ?>
96
+				<?php do_action('lsx_search_form_top'); ?>
97 97
 
98 98
 				<div class="input-group navbar-nav">
99
-					<?php if ( true === $display_search_field ) : ?>
99
+					<?php if (true === $display_search_field) : ?>
100 100
 						<div class="field">
101
-							<input class="search-field form-control" name="s" type="search" placeholder="<?php echo esc_attr( $placeholder ); ?>" autocomplete="off">
101
+							<input class="search-field form-control" name="s" type="search" placeholder="<?php echo esc_attr($placeholder); ?>" autocomplete="off">
102 102
 						</div>
103 103
 					<?php endif; ?>
104 104
 
105
-					<?php if ( false !== $engine_select && false !== $engine && 'default' !== $engine ) :
106
-						$engines = explode( '|',$engine ); ?>
105
+					<?php if (false !== $engine_select && false !== $engine && 'default' !== $engine) :
106
+						$engines = explode('|', $engine); ?>
107 107
 						<div class="field engine-select">
108 108
 							<div class="dropdown nav-item">
109 109
 								<?php
110 110
 								$plural = 's';
111
-								if ( 'accommodation' === $engine[0] ) {
111
+								if ('accommodation' === $engine[0]) {
112 112
 									$plural = '';
113 113
 								}
114 114
 								?>
115
-								<button id="engine" data-selection="<?php echo esc_attr( $engines[0] ); ?>" class="btn border-btn btn-dropdown dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><?php echo esc_html( ucwords( str_replace( '_', ' ',$engines[0] ) ) . $plural ); ?> <span class="caret"></span></button>
115
+								<button id="engine" data-selection="<?php echo esc_attr($engines[0]); ?>" class="btn border-btn btn-dropdown dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><?php echo esc_html(ucwords(str_replace('_', ' ', $engines[0])).$plural); ?> <span class="caret"></span></button>
116 116
 								<ul class="dropdown-menu">
117 117
 									<?php
118
-									foreach ( $engines as $engine ) {
118
+									foreach ($engines as $engine) {
119 119
 										$plural = 's';
120
-										if ( 'accommodation' === $engine ) {
120
+										if ('accommodation' === $engine) {
121 121
 											$plural = '';
122 122
 										}
123
-										echo '<li><a data-value="' . esc_attr( $engine ) . '" href="#">' . esc_html( ucfirst( str_replace( '_', ' ',$engine ) ) . $plural ) . '</a></li>';
123
+										echo '<li><a data-value="'.esc_attr($engine).'" href="#">'.esc_html(ucfirst(str_replace('_', ' ', $engine)).$plural).'</a></li>';
124 124
 									}
125 125
 									?>
126 126
 								</ul>
@@ -128,32 +128,32 @@  discard block
 block discarded – undo
128 128
 						</div>
129 129
 					<?php endif; ?>
130 130
 
131
-					<?php if ( false !== $facets ) {
132
-						$facets = explode( '|',$facets );
131
+					<?php if (false !== $facets) {
132
+						$facets = explode('|', $facets);
133 133
 
134
-						if ( ! is_array( $facets ) ) {
135
-							$facets = array( $facets );
134
+						if (!is_array($facets)) {
135
+							$facets = array($facets);
136 136
 						}
137 137
 
138 138
 						$field_class = 'field';
139 139
 
140
-						if ( false !== $combo_box ) {
141
-							$this->combo_box( $facets );
140
+						if (false !== $combo_box) {
141
+							$this->combo_box($facets);
142 142
 							$field_class .= ' combination-toggle hidden';
143 143
 						}
144 144
 
145
-						foreach ( $facets as $facet ) {
145
+						foreach ($facets as $facet) {
146 146
 							?>
147
-							<div class="<?php echo wp_kses_post( $field_class ); ?>">
147
+							<div class="<?php echo wp_kses_post($field_class); ?>">
148 148
 								<?php
149
-								$facet = FWP()->helper->get_facet_by_name( $facet );
150
-								if ( isset( $facet['source'] ) ) {
151
-									$values = $this->get_form_facet( $facet['source'] );
149
+								$facet = FWP()->helper->get_facet_by_name($facet);
150
+								if (isset($facet['source'])) {
151
+									$values = $this->get_form_facet($facet['source']);
152 152
 								} else {
153 153
 									$values = array();
154 154
 								}
155
-								$facet_display_type = apply_filters( 'lsx_search_form_field_type', 'select', $facet );
156
-								$this->display_form_field( $facet_display_type,$facet,$values,$combo_box );
155
+								$facet_display_type = apply_filters('lsx_search_form_field_type', 'select', $facet);
156
+								$this->display_form_field($facet_display_type, $facet, $values, $combo_box);
157 157
 								?>
158 158
 							</div>
159 159
 							<?php
@@ -161,26 +161,26 @@  discard block
 block discarded – undo
161 161
 					} ?>
162 162
 
163 163
 					<div class="field submit-button">
164
-						<button class="<?php echo esc_attr( $button_class ); ?>" type="submit"><?php echo wp_kses_post( $button_label ); ?></button>
164
+						<button class="<?php echo esc_attr($button_class); ?>" type="submit"><?php echo wp_kses_post($button_label); ?></button>
165 165
 					</div>
166 166
 
167
-					<?php if ( false === $engine_select && false !== $engine && 'default' !== $engine ) : ?>
168
-						<input name="engine" type="hidden" value="<?php echo esc_attr( $engine ); ?>">
167
+					<?php if (false === $engine_select && false !== $engine && 'default' !== $engine) : ?>
168
+						<input name="engine" type="hidden" value="<?php echo esc_attr($engine); ?>">
169 169
 					<?php endif; ?>
170 170
 				</div>
171 171
 
172
-				<?php do_action( 'lsx_search_form_bottom' ); ?>
172
+				<?php do_action('lsx_search_form_bottom'); ?>
173 173
 
174 174
 			</form>
175 175
 
176 176
 		</nav>
177 177
 
178
-		<?php do_action( 'lsx_search_form_after' ); ?>
178
+		<?php do_action('lsx_search_form_after'); ?>
179 179
 		<?php
180 180
 		$return = ob_get_clean();
181 181
 
182
-		$return = preg_replace( '/[\n]+/', ' ', $return );
183
-		$return = preg_replace( '/[\t]+/', ' ', $return );
182
+		$return = preg_replace('/[\n]+/', ' ', $return);
183
+		$return = preg_replace('/[\t]+/', ' ', $return);
184 184
 
185 185
 		return $return;
186 186
 	}
@@ -188,22 +188,22 @@  discard block
 block discarded – undo
188 188
 	/**
189 189
 	 * Outputs the combination selector
190 190
 	 */
191
-	public function combo_box( $facets ) {
191
+	public function combo_box($facets) {
192 192
 		?>
193 193
 		<div class="field combination-dropdown">
194 194
 			<div class="dropdown">
195 195
 				<button data-selection="0" class="btn border-btn btn-dropdown dropdown-toggle btn-combination" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
196
-					<?php esc_attr_e( 'Select', 'lsx-search' ); ?>
196
+					<?php esc_attr_e('Select', 'lsx-search'); ?>
197 197
 					<span class="caret"></span>
198 198
 				</button>
199 199
 				<ul class="dropdown-menu">
200 200
 
201
-					<li style="display: none;"><a class="default" data-value="0" href="#"><?php esc_attr_e( 'Select ', 'lsx-search' ); ?></a></li>
201
+					<li style="display: none;"><a class="default" data-value="0" href="#"><?php esc_attr_e('Select ', 'lsx-search'); ?></a></li>
202 202
 
203
-					<?php foreach ( $facets as $facet ) {
204
-						$facet = FWP()->helper->get_facet_by_name( $facet );
203
+					<?php foreach ($facets as $facet) {
204
+						$facet = FWP()->helper->get_facet_by_name($facet);
205 205
 						?>
206
-						<li><a data-value="fwp_<?php echo wp_kses_post( $facet['name'] ); ?>" href="#"><?php echo wp_kses_post( $facet['label'] ); ?></a></li>
206
+						<li><a data-value="fwp_<?php echo wp_kses_post($facet['name']); ?>" href="#"><?php echo wp_kses_post($facet['label']); ?></a></li>
207 207
 					<?php } ?>
208 208
 				</ul>
209 209
 			</div>
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
 	/**
215 215
 	 * Grabs the Values for the Facet in Question.
216 216
 	 */
217
-	protected function get_form_facet( $facet_source = false ) {
217
+	protected function get_form_facet($facet_source = false) {
218 218
 		global $wpdb;
219 219
 
220 220
 		$values = array();
@@ -223,66 +223,66 @@  discard block
 block discarded – undo
223 223
 		$where = "f.facet_source = '{$facet_source}'";
224 224
 
225 225
 		//Check if the current facet is showing destinations.
226
-		if ( stripos( $facet_source, 'destination_to' ) ) {
226
+		if (stripos($facet_source, 'destination_to')) {
227 227
 			$from .= " INNER JOIN {$wpdb->posts} p ON f.facet_value = p.ID";
228 228
 			$where .= " AND p.post_parent = '0'";
229 229
 
230 230
 		}
231 231
 
232
-		$response = $wpdb->prepare( "SELECT {$select} FROM {$from} WHERE {$where}" );// WPCS: unprepared SQL OK.
232
+		$response = $wpdb->prepare("SELECT {$select} FROM {$from} WHERE {$where}"); // WPCS: unprepared SQL OK.
233 233
 
234
-		if ( ! empty( $response ) ) {
235
-			foreach ( $response as $re ) {
234
+		if (!empty($response)) {
235
+			foreach ($response as $re) {
236 236
 				$display_value = $re->facet_display_value;
237
-				if ( function_exists( 'pll_translate_string' ) ) {
237
+				if (function_exists('pll_translate_string')) {
238 238
 					$current_lang = pll_current_language();
239
-					$display_value = pll_translate_string( $display_value, $current_lang );
239
+					$display_value = pll_translate_string($display_value, $current_lang);
240 240
 				}
241
-				$display_value = apply_filters( 'lsx_search_facetwp_display_value', $display_value, $re->facet_value );
242
-				$values[ $re->facet_value ] = $display_value;
241
+				$display_value = apply_filters('lsx_search_facetwp_display_value', $display_value, $re->facet_value);
242
+				$values[$re->facet_value] = $display_value;
243 243
 			}
244 244
 		}
245 245
 
246
-		asort( $values );
246
+		asort($values);
247 247
 		return $values;
248 248
 	}
249 249
 
250 250
 	/**
251 251
 	 * Change FaceWP pagination HTML to be equal main pagination (WP-PageNavi)
252 252
 	 */
253
-	public function display_form_field( $type = 'select', $facet = array(), $values = array(), $combo = false ) {
254
-		if ( empty( $facet ) ) {
253
+	public function display_form_field($type = 'select', $facet = array(), $values = array(), $combo = false) {
254
+		if (empty($facet)) {
255 255
 			return;
256 256
 		}
257 257
 
258
-		$source = 'fwp_' . $facet['name'];
258
+		$source = 'fwp_'.$facet['name'];
259 259
 
260
-		switch ( $type ) {
260
+		switch ($type) {
261 261
 
262 262
 			case 'select': ?>
263
-				<div class="dropdown nav-item <?php if ( true === $combo ) { echo 'combination-dropdown'; } ?>">
264
-					<button data-selection="0" class="btn border-btn btn-dropdown dropdown-toggle" type="button" id="<?php echo wp_kses_post( $source ); ?>" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
265
-						<?php echo esc_attr( apply_filters( 'lsx_search_facet_label', __( 'Select', 'lsx-search' ) . ' ' . wp_kses_post( $facet['label'] ) ) ); ?>
263
+				<div class="dropdown nav-item <?php if (true === $combo) { echo 'combination-dropdown'; } ?>">
264
+					<button data-selection="0" class="btn border-btn btn-dropdown dropdown-toggle" type="button" id="<?php echo wp_kses_post($source); ?>" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
265
+						<?php echo esc_attr(apply_filters('lsx_search_facet_label', __('Select', 'lsx-search').' '.wp_kses_post($facet['label']))); ?>
266 266
 						<span class="caret"></span>
267 267
 					</button>
268
-					<ul class="dropdown-menu" aria-labelledby="<?php echo wp_kses_post( $source ); ?>">
269
-						<?php if ( ! empty( $values ) ) { ?>
268
+					<ul class="dropdown-menu" aria-labelledby="<?php echo wp_kses_post($source); ?>">
269
+						<?php if (!empty($values)) { ?>
270 270
 
271 271
 							<li style="display: none;">
272 272
 								<a class="default" data-value="0" href="#">
273 273
 									<?php
274
-										$facet_label = __( 'Select ', 'lsx-search' ) . ' ' . wp_kses_post( $facet['label'] );
275
-										$facet_label = apply_filters( 'lsx_search_facet_label', $facet_label );
276
-										echo esc_attr( $facet_label );
274
+										$facet_label = __('Select ', 'lsx-search').' '.wp_kses_post($facet['label']);
275
+										$facet_label = apply_filters('lsx_search_facet_label', $facet_label);
276
+										echo esc_attr($facet_label);
277 277
 									?>
278 278
 								</a>
279 279
 							</li>
280 280
 
281
-							<?php foreach ( $values as $key => $value ) { ?>
282
-								<li><a data-value="<?php echo wp_kses_post( $key ); ?>" href="#"><?php echo wp_kses_post( $value ); ?></a></li>
281
+							<?php foreach ($values as $key => $value) { ?>
282
+								<li><a data-value="<?php echo wp_kses_post($key); ?>" href="#"><?php echo wp_kses_post($value); ?></a></li>
283 283
 							<?php } ?>
284 284
 						<?php } else { ?>
285
-							<li><a data-value="0" href="#"><?php esc_attr_e( 'Please re-index your facets.', 'lsx-search' ); ?></a></li>
285
+							<li><a data-value="0" href="#"><?php esc_attr_e('Please re-index your facets.', 'lsx-search'); ?></a></li>
286 286
 						<?php } ?>
287 287
 					</ul>
288 288
 				</div>
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
 
292 292
 			case 'datepicker': ?>
293 293
 				<div class="datepicker nav-item">
294
-					<input autocomplete="off" class="datepicker-value" placeholder="<?php echo wp_kses_post( apply_filters( 'lsx_search_facet_label' , $facet['label'] ) ); ?>" name="<?php echo wp_kses_post( $source ); ?>"  id="<?php echo wp_kses_post( $source ); ?>" type="text" value="" />
294
+					<input autocomplete="off" class="datepicker-value" placeholder="<?php echo wp_kses_post(apply_filters('lsx_search_facet_label', $facet['label'])); ?>" name="<?php echo wp_kses_post($source); ?>"  id="<?php echo wp_kses_post($source); ?>" type="text" value="" />
295 295
 				</div>
296 296
 			<?php
297 297
 				break;
Please login to merge, or discard this patch.
classes/frontend/class-layout.php 2 patches
Indentation   +145 added lines, -145 removed lines patch added patch discarded remove patch
@@ -10,149 +10,149 @@
 block discarded – undo
10 10
  */
11 11
 class Layout {
12 12
 
13
-	/**
14
-	 * Holds class instance
15
-	 *
16
-	 * @since 1.0.0
17
-	 *
18
-	 * @var      object \lsx\search\classes\frontend\Layout()
19
-	 */
20
-	protected static $instance = null;
21
-
22
-	/**
23
-	 * Contructor
24
-	 */
25
-	public function __construct() {
26
-		add_action( 'wp', array( $this, 'load_functions' ), 24 );
27
-	}
28
-
29
-	/**
30
-	 * Return an instance of this class.
31
-	 *
32
-	 * @since 1.0.0
33
-	 *
34
-	 * @return    object \lsx\search\classes\frontend\Layout()    A single instance of this class.
35
-	 */
36
-	public static function get_instance() {
37
-		// If the single instance hasn't been set, set it now.
38
-		if ( null == self::$instance ) {
39
-			self::$instance = new self();
40
-		}
41
-		return self::$instance;
42
-	}
43
-
44
-	/**
45
-	 * Check all settings.
46
-	 */
47
-	public function load_functions() {
48
-		$lsx_search = LSX_Search::get_instance();
49
-		if ( $lsx_search->frontend->search_enabled ) {
50
-			if ( isset( $lsx_search->frontend->options['display'][ $lsx_search->frontend->search_prefix . '_layout_switcher_enable' ] ) ) {
51
-				add_filter( 'lsx_blog_customizer_show_switcher', array( $this, 'show_layout_switcher' ), 10, 1 );
52
-				add_filter( 'lsx_layout_switcher_options', array( $this, 'lsx_layout_switcher_options' ), 10, 1 );
53
-				add_filter( 'lsx_layout_switcher_page_key', array( $this, 'lsx_layout_switcher_page_key' ), 10, 1 );
54
-				add_filter( 'lsx_layout_switcher_options_default', array( $this, 'lsx_layout_switcher_options_default' ), 10, 1 );
55
-
56
-				// Layout Classes
57
-				add_filter( 'woocommerce_product_loop_start', array( $this, 'woocommerce_layout_class' ), 10, 1 );
58
-			}
59
-		}
60
-	}
61
-
62
-	/**
63
-	 * Display the woocommerce archive swticher.
64
-	 */
65
-	public function show_layout_switcher( $show = false ) {
66
-		$show = true;
67
-		return $show;
68
-	}
69
-
70
-	/**
71
-	 * Remove the default and half-grid options from the results layouts.
72
-	 *
73
-	 * @param  array $layout_options
74
-	 * @return array
75
-	 */
76
-	public function lsx_layout_switcher_options( $layout_options ) {
77
-		unset( $layout_options['default'] );
78
-		unset( $layout_options['half-grid'] );
79
-		return $layout_options;
80
-	}
81
-
82
-	/**
83
-	 * Replace the key for the layout switcher.
84
-	 *
85
-	 * @param  string $page_key
86
-	 * @return string
87
-	 */
88
-	public function lsx_layout_switcher_page_key( $page_key ) {
89
-		$lsx_search = LSX_Search::get_instance();
90
-		$page_key   = str_replace( '_search', '', $lsx_search->frontend->search_prefix );
91
-		return $page_key;
92
-	}
93
-
94
-	/**
95
-	 * CHange the default layout to a grid layout.
96
-	 *
97
-	 * @param  string $default
98
-	 * @return string
99
-	 */
100
-	public function lsx_layout_switcher_options_default( $default = 'grid' ) {
101
-		$lsx_search = LSX_Search::get_instance();
102
-		$default    = 'grid';
103
-		if ( isset( $lsx_search->frontend->options['display'][ $lsx_search->frontend->search_prefix . '_grid_list' ] ) && ! empty( $lsx_search->frontend->options['display'][ $lsx_search->frontend->search_prefix . '_grid_list' ] ) ) {
104
-			$default = $lsx_search->frontend->options['display'][ $lsx_search->frontend->search_prefix . '_grid_list' ];
105
-		}
106
-		return $default;
107
-	}
108
-
109
-	/**
110
-	 * Controls the layout for the woocommerce shop page.
111
-	 */
112
-	public function woocommerce_layout_class( $output = '' ) {
113
-		$default_class = $this->lsx_layout_switcher_options_default();
114
-		$selected      = $this->get_layout_value_from_cookie( 'product' );
115
-		if ( '' !== $selected ) {
116
-			$default_class = $selected;
117
-		}
118
-		$output = str_replace( 'products', 'products ' . $default_class, $output );
119
-		return $output;
120
-	}
121
-
122
-	/**
123
-	 * Get layout value from cookie
124
-	 *
125
-	 * @since 1.0.0
126
-	 */
127
-	public function get_layout_value_from_cookie( $page_key = 'blog' ) {
128
-		$archive_layout = 'grid';
129
-
130
-		if ( isset( $_COOKIE[ 'lsx-' . $page_key . '-layout' ] ) ) {
131
-			$archive_layout_from_cookie = sanitize_key( $_COOKIE[ 'lsx-' . $page_key . '-layout' ] );
132
-			$archive_layout_from_cookie = $this->sanitize_select_layout_switcher( $archive_layout_from_cookie );
133
-
134
-			if ( ! empty( $archive_layout_from_cookie ) ) {
135
-				$archive_layout = $archive_layout_from_cookie;
136
-			}
137
-		}
138
-		return $archive_layout;
139
-	}
140
-
141
-	/**
142
-	 * Sanitize select (layout switcher).
143
-	 *
144
-	 * @since 1.0.0
145
-	 */
146
-	public function sanitize_select_layout_switcher( $input ) {
147
-		$valid = array(
148
-			'list'      => esc_html__( 'List', 'lsx-search' ),
149
-			'grid'      => esc_html__( 'Grid', 'lsx-search' ),
150
-		);
151
-
152
-		if ( array_key_exists( $input, $valid ) ) {
153
-			return $input;
154
-		} else {
155
-			return '';
156
-		}
157
-	}
13
+     /**
14
+      * Holds class instance
15
+      *
16
+      * @since 1.0.0
17
+      *
18
+      * @var      object \lsx\search\classes\frontend\Layout()
19
+      */
20
+     protected static $instance = null;
21
+
22
+     /**
23
+      * Contructor
24
+      */
25
+     public function __construct() {
26
+          add_action( 'wp', array( $this, 'load_functions' ), 24 );
27
+     }
28
+
29
+     /**
30
+      * Return an instance of this class.
31
+      *
32
+      * @since 1.0.0
33
+      *
34
+      * @return    object \lsx\search\classes\frontend\Layout()    A single instance of this class.
35
+      */
36
+     public static function get_instance() {
37
+          // If the single instance hasn't been set, set it now.
38
+          if ( null == self::$instance ) {
39
+               self::$instance = new self();
40
+          }
41
+          return self::$instance;
42
+     }
43
+
44
+     /**
45
+      * Check all settings.
46
+      */
47
+     public function load_functions() {
48
+          $lsx_search = LSX_Search::get_instance();
49
+          if ( $lsx_search->frontend->search_enabled ) {
50
+               if ( isset( $lsx_search->frontend->options['display'][ $lsx_search->frontend->search_prefix . '_layout_switcher_enable' ] ) ) {
51
+                    add_filter( 'lsx_blog_customizer_show_switcher', array( $this, 'show_layout_switcher' ), 10, 1 );
52
+                    add_filter( 'lsx_layout_switcher_options', array( $this, 'lsx_layout_switcher_options' ), 10, 1 );
53
+                    add_filter( 'lsx_layout_switcher_page_key', array( $this, 'lsx_layout_switcher_page_key' ), 10, 1 );
54
+                    add_filter( 'lsx_layout_switcher_options_default', array( $this, 'lsx_layout_switcher_options_default' ), 10, 1 );
55
+
56
+                    // Layout Classes
57
+                    add_filter( 'woocommerce_product_loop_start', array( $this, 'woocommerce_layout_class' ), 10, 1 );
58
+               }
59
+          }
60
+     }
61
+
62
+     /**
63
+      * Display the woocommerce archive swticher.
64
+      */
65
+     public function show_layout_switcher( $show = false ) {
66
+          $show = true;
67
+          return $show;
68
+     }
69
+
70
+     /**
71
+      * Remove the default and half-grid options from the results layouts.
72
+      *
73
+      * @param  array $layout_options
74
+      * @return array
75
+      */
76
+     public function lsx_layout_switcher_options( $layout_options ) {
77
+          unset( $layout_options['default'] );
78
+          unset( $layout_options['half-grid'] );
79
+          return $layout_options;
80
+     }
81
+
82
+     /**
83
+      * Replace the key for the layout switcher.
84
+      *
85
+      * @param  string $page_key
86
+      * @return string
87
+      */
88
+     public function lsx_layout_switcher_page_key( $page_key ) {
89
+          $lsx_search = LSX_Search::get_instance();
90
+          $page_key   = str_replace( '_search', '', $lsx_search->frontend->search_prefix );
91
+          return $page_key;
92
+     }
93
+
94
+     /**
95
+      * CHange the default layout to a grid layout.
96
+      *
97
+      * @param  string $default
98
+      * @return string
99
+      */
100
+     public function lsx_layout_switcher_options_default( $default = 'grid' ) {
101
+          $lsx_search = LSX_Search::get_instance();
102
+          $default    = 'grid';
103
+          if ( isset( $lsx_search->frontend->options['display'][ $lsx_search->frontend->search_prefix . '_grid_list' ] ) && ! empty( $lsx_search->frontend->options['display'][ $lsx_search->frontend->search_prefix . '_grid_list' ] ) ) {
104
+               $default = $lsx_search->frontend->options['display'][ $lsx_search->frontend->search_prefix . '_grid_list' ];
105
+          }
106
+          return $default;
107
+     }
108
+
109
+     /**
110
+      * Controls the layout for the woocommerce shop page.
111
+      */
112
+     public function woocommerce_layout_class( $output = '' ) {
113
+          $default_class = $this->lsx_layout_switcher_options_default();
114
+          $selected      = $this->get_layout_value_from_cookie( 'product' );
115
+          if ( '' !== $selected ) {
116
+               $default_class = $selected;
117
+          }
118
+          $output = str_replace( 'products', 'products ' . $default_class, $output );
119
+          return $output;
120
+     }
121
+
122
+     /**
123
+      * Get layout value from cookie
124
+      *
125
+      * @since 1.0.0
126
+      */
127
+     public function get_layout_value_from_cookie( $page_key = 'blog' ) {
128
+          $archive_layout = 'grid';
129
+
130
+          if ( isset( $_COOKIE[ 'lsx-' . $page_key . '-layout' ] ) ) {
131
+               $archive_layout_from_cookie = sanitize_key( $_COOKIE[ 'lsx-' . $page_key . '-layout' ] );
132
+               $archive_layout_from_cookie = $this->sanitize_select_layout_switcher( $archive_layout_from_cookie );
133
+
134
+               if ( ! empty( $archive_layout_from_cookie ) ) {
135
+                    $archive_layout = $archive_layout_from_cookie;
136
+               }
137
+          }
138
+          return $archive_layout;
139
+     }
140
+
141
+     /**
142
+      * Sanitize select (layout switcher).
143
+      *
144
+      * @since 1.0.0
145
+      */
146
+     public function sanitize_select_layout_switcher( $input ) {
147
+          $valid = array(
148
+               'list'      => esc_html__( 'List', 'lsx-search' ),
149
+               'grid'      => esc_html__( 'Grid', 'lsx-search' ),
150
+          );
151
+
152
+          if ( array_key_exists( $input, $valid ) ) {
153
+               return $input;
154
+          } else {
155
+               return '';
156
+          }
157
+     }
158 158
 }
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 	 * Contructor
24 24
 	 */
25 25
 	public function __construct() {
26
-		add_action( 'wp', array( $this, 'load_functions' ), 24 );
26
+		add_action('wp', array($this, 'load_functions'), 24);
27 27
 	}
28 28
 
29 29
 	/**
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 	 */
36 36
 	public static function get_instance() {
37 37
 		// If the single instance hasn't been set, set it now.
38
-		if ( null == self::$instance ) {
38
+		if (null == self::$instance) {
39 39
 			self::$instance = new self();
40 40
 		}
41 41
 		return self::$instance;
@@ -46,15 +46,15 @@  discard block
 block discarded – undo
46 46
 	 */
47 47
 	public function load_functions() {
48 48
 		$lsx_search = LSX_Search::get_instance();
49
-		if ( $lsx_search->frontend->search_enabled ) {
50
-			if ( isset( $lsx_search->frontend->options['display'][ $lsx_search->frontend->search_prefix . '_layout_switcher_enable' ] ) ) {
51
-				add_filter( 'lsx_blog_customizer_show_switcher', array( $this, 'show_layout_switcher' ), 10, 1 );
52
-				add_filter( 'lsx_layout_switcher_options', array( $this, 'lsx_layout_switcher_options' ), 10, 1 );
53
-				add_filter( 'lsx_layout_switcher_page_key', array( $this, 'lsx_layout_switcher_page_key' ), 10, 1 );
54
-				add_filter( 'lsx_layout_switcher_options_default', array( $this, 'lsx_layout_switcher_options_default' ), 10, 1 );
49
+		if ($lsx_search->frontend->search_enabled) {
50
+			if (isset($lsx_search->frontend->options['display'][$lsx_search->frontend->search_prefix.'_layout_switcher_enable'])) {
51
+				add_filter('lsx_blog_customizer_show_switcher', array($this, 'show_layout_switcher'), 10, 1);
52
+				add_filter('lsx_layout_switcher_options', array($this, 'lsx_layout_switcher_options'), 10, 1);
53
+				add_filter('lsx_layout_switcher_page_key', array($this, 'lsx_layout_switcher_page_key'), 10, 1);
54
+				add_filter('lsx_layout_switcher_options_default', array($this, 'lsx_layout_switcher_options_default'), 10, 1);
55 55
 
56 56
 				// Layout Classes
57
-				add_filter( 'woocommerce_product_loop_start', array( $this, 'woocommerce_layout_class' ), 10, 1 );
57
+				add_filter('woocommerce_product_loop_start', array($this, 'woocommerce_layout_class'), 10, 1);
58 58
 			}
59 59
 		}
60 60
 	}
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 	/**
63 63
 	 * Display the woocommerce archive swticher.
64 64
 	 */
65
-	public function show_layout_switcher( $show = false ) {
65
+	public function show_layout_switcher($show = false) {
66 66
 		$show = true;
67 67
 		return $show;
68 68
 	}
@@ -73,9 +73,9 @@  discard block
 block discarded – undo
73 73
 	 * @param  array $layout_options
74 74
 	 * @return array
75 75
 	 */
76
-	public function lsx_layout_switcher_options( $layout_options ) {
77
-		unset( $layout_options['default'] );
78
-		unset( $layout_options['half-grid'] );
76
+	public function lsx_layout_switcher_options($layout_options) {
77
+		unset($layout_options['default']);
78
+		unset($layout_options['half-grid']);
79 79
 		return $layout_options;
80 80
 	}
81 81
 
@@ -85,9 +85,9 @@  discard block
 block discarded – undo
85 85
 	 * @param  string $page_key
86 86
 	 * @return string
87 87
 	 */
88
-	public function lsx_layout_switcher_page_key( $page_key ) {
88
+	public function lsx_layout_switcher_page_key($page_key) {
89 89
 		$lsx_search = LSX_Search::get_instance();
90
-		$page_key   = str_replace( '_search', '', $lsx_search->frontend->search_prefix );
90
+		$page_key   = str_replace('_search', '', $lsx_search->frontend->search_prefix);
91 91
 		return $page_key;
92 92
 	}
93 93
 
@@ -97,11 +97,11 @@  discard block
 block discarded – undo
97 97
 	 * @param  string $default
98 98
 	 * @return string
99 99
 	 */
100
-	public function lsx_layout_switcher_options_default( $default = 'grid' ) {
100
+	public function lsx_layout_switcher_options_default($default = 'grid') {
101 101
 		$lsx_search = LSX_Search::get_instance();
102 102
 		$default    = 'grid';
103
-		if ( isset( $lsx_search->frontend->options['display'][ $lsx_search->frontend->search_prefix . '_grid_list' ] ) && ! empty( $lsx_search->frontend->options['display'][ $lsx_search->frontend->search_prefix . '_grid_list' ] ) ) {
104
-			$default = $lsx_search->frontend->options['display'][ $lsx_search->frontend->search_prefix . '_grid_list' ];
103
+		if (isset($lsx_search->frontend->options['display'][$lsx_search->frontend->search_prefix.'_grid_list']) && !empty($lsx_search->frontend->options['display'][$lsx_search->frontend->search_prefix.'_grid_list'])) {
104
+			$default = $lsx_search->frontend->options['display'][$lsx_search->frontend->search_prefix.'_grid_list'];
105 105
 		}
106 106
 		return $default;
107 107
 	}
@@ -109,13 +109,13 @@  discard block
 block discarded – undo
109 109
 	/**
110 110
 	 * Controls the layout for the woocommerce shop page.
111 111
 	 */
112
-	public function woocommerce_layout_class( $output = '' ) {
112
+	public function woocommerce_layout_class($output = '') {
113 113
 		$default_class = $this->lsx_layout_switcher_options_default();
114
-		$selected      = $this->get_layout_value_from_cookie( 'product' );
115
-		if ( '' !== $selected ) {
114
+		$selected      = $this->get_layout_value_from_cookie('product');
115
+		if ('' !== $selected) {
116 116
 			$default_class = $selected;
117 117
 		}
118
-		$output = str_replace( 'products', 'products ' . $default_class, $output );
118
+		$output = str_replace('products', 'products '.$default_class, $output);
119 119
 		return $output;
120 120
 	}
121 121
 
@@ -124,14 +124,14 @@  discard block
 block discarded – undo
124 124
 	 *
125 125
 	 * @since 1.0.0
126 126
 	 */
127
-	public function get_layout_value_from_cookie( $page_key = 'blog' ) {
127
+	public function get_layout_value_from_cookie($page_key = 'blog') {
128 128
 		$archive_layout = 'grid';
129 129
 
130
-		if ( isset( $_COOKIE[ 'lsx-' . $page_key . '-layout' ] ) ) {
131
-			$archive_layout_from_cookie = sanitize_key( $_COOKIE[ 'lsx-' . $page_key . '-layout' ] );
132
-			$archive_layout_from_cookie = $this->sanitize_select_layout_switcher( $archive_layout_from_cookie );
130
+		if (isset($_COOKIE['lsx-'.$page_key.'-layout'])) {
131
+			$archive_layout_from_cookie = sanitize_key($_COOKIE['lsx-'.$page_key.'-layout']);
132
+			$archive_layout_from_cookie = $this->sanitize_select_layout_switcher($archive_layout_from_cookie);
133 133
 
134
-			if ( ! empty( $archive_layout_from_cookie ) ) {
134
+			if (!empty($archive_layout_from_cookie)) {
135 135
 				$archive_layout = $archive_layout_from_cookie;
136 136
 			}
137 137
 		}
@@ -143,13 +143,13 @@  discard block
 block discarded – undo
143 143
 	 *
144 144
 	 * @since 1.0.0
145 145
 	 */
146
-	public function sanitize_select_layout_switcher( $input ) {
146
+	public function sanitize_select_layout_switcher($input) {
147 147
 		$valid = array(
148
-			'list'      => esc_html__( 'List', 'lsx-search' ),
149
-			'grid'      => esc_html__( 'Grid', 'lsx-search' ),
148
+			'list'      => esc_html__('List', 'lsx-search'),
149
+			'grid'      => esc_html__('Grid', 'lsx-search'),
150 150
 		);
151 151
 
152
-		if ( array_key_exists( $input, $valid ) ) {
152
+		if (array_key_exists($input, $valid)) {
153 153
 			return $input;
154 154
 		} else {
155 155
 			return '';
Please login to merge, or discard this patch.