@@ -9,663 +9,663 @@ discard block |
||
9 | 9 | |
10 | 10 | class Frontend { |
11 | 11 | |
12 | - /** |
|
13 | - * Holds class instance |
|
14 | - * |
|
15 | - * @since 1.0.0 |
|
16 | - * |
|
17 | - * @var object \lsx\search\classes\Frontend() |
|
18 | - */ |
|
19 | - protected static $instance = null; |
|
20 | - |
|
21 | - public $options = false; |
|
22 | - |
|
23 | - public $tabs = false; |
|
24 | - |
|
25 | - public $facet_data = false; |
|
26 | - |
|
27 | - /** |
|
28 | - * Determine weather or not search is enabled for this page. |
|
29 | - * |
|
30 | - * @var boolean |
|
31 | - */ |
|
32 | - public $search_enabled = false; |
|
33 | - |
|
34 | - public $search_core_suffix = false; |
|
35 | - |
|
36 | - public $search_prefix = false; |
|
37 | - |
|
38 | - /** |
|
39 | - * Holds the post types enabled |
|
40 | - * |
|
41 | - * @var array |
|
42 | - */ |
|
43 | - public $post_types = array(); |
|
44 | - |
|
45 | - /** |
|
46 | - * Holds the taxonomies enabled for search |
|
47 | - * |
|
48 | - * @var array |
|
49 | - */ |
|
50 | - public $taxonomies = array(); |
|
51 | - |
|
52 | - /** |
|
53 | - * If the current search page has posts or not |
|
54 | - * |
|
55 | - * @var boolean |
|
56 | - */ |
|
57 | - public $has_posts = false; |
|
58 | - |
|
59 | - /** |
|
60 | - * If we are using the CMB2 options or not. |
|
61 | - * |
|
62 | - * @var boolean |
|
63 | - */ |
|
64 | - public $new_options = false; |
|
65 | - |
|
66 | - /** |
|
67 | - * Construct method. |
|
68 | - */ |
|
69 | - public function __construct() { |
|
70 | - $this->options = \lsx\search\includes\get_options(); |
|
71 | - $this->load_classes(); |
|
72 | - |
|
73 | - add_filter( 'wpseo_json_ld_search_url', array( $this, 'change_json_ld_search_url' ), 10, 1 ); |
|
74 | - add_action( 'wp', array( $this, 'set_vars' ), 21 ); |
|
75 | - add_action( 'wp', array( $this, 'set_facetwp_vars' ), 22 ); |
|
76 | - add_action( 'wp', array( $this, 'core' ), 23 ); |
|
77 | - add_action( 'lsx_body_top', array( $this, 'check_for_results' ) ); |
|
78 | - |
|
79 | - add_action( 'pre_get_posts', array( $this, 'filter_post_types' ) ); |
|
80 | - |
|
81 | - add_filter( 'lsx_search_post_types', array( $this, 'register_post_types' ) ); |
|
82 | - add_filter( 'lsx_search_taxonomies', array( $this, 'register_taxonomies' ) ); |
|
83 | - add_filter( 'lsx_search_post_types_plural', array( $this, 'register_post_type_tabs' ) ); |
|
84 | - add_filter( 'facetwp_sort_options', array( $this, 'facetwp_sort_options' ), 10, 2 ); |
|
85 | - add_filter( 'wp_kses_allowed_html', array( $this, 'kses_allowed_html' ), 20, 2 ); |
|
86 | - |
|
87 | - // Redirects. |
|
88 | - add_action( 'template_redirect', array( $this, 'pretty_search_redirect' ) ); |
|
89 | - add_filter( 'pre_get_posts', array( $this, 'pretty_search_parse_query' ) ); |
|
90 | - |
|
91 | - add_action( 'lsx_search_sidebar_top', array( $this, 'search_sidebar_top' ) ); |
|
92 | - add_filter( 'facetwp_facet_html', array( $this, 'search_facet_html' ), 10, 2 ); |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Return an instance of this class. |
|
97 | - * |
|
98 | - * @since 1.0.0 |
|
99 | - * |
|
100 | - * @return object \lsx\member_directory\search\Frontend() A single instance of this class. |
|
101 | - */ |
|
102 | - public static function get_instance() { |
|
103 | - // If the single instance hasn't been set, set it now. |
|
104 | - if ( null === self::$instance ) { |
|
105 | - self::$instance = new self(); |
|
106 | - } |
|
107 | - return self::$instance; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Loads the variable classes and the static classes. |
|
112 | - */ |
|
113 | - private function load_classes() { |
|
114 | - require_once LSX_SEARCH_PATH . 'classes/frontend/class-layout.php'; |
|
115 | - $this->layout = frontend\Layout::get_instance(); |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * Check all settings. |
|
120 | - */ |
|
121 | - public function set_vars() { |
|
122 | - $post_type = ''; |
|
123 | - |
|
124 | - $this->post_types = apply_filters( 'lsx_search_post_types', array() ); |
|
125 | - $this->taxonomies = apply_filters( 'lsx_search_taxonomies', array() ); |
|
126 | - $this->tabs = apply_filters( 'lsx_search_post_types_plural', array() ); |
|
127 | - $this->options = apply_filters( 'lsx_search_options', $this->options ); |
|
128 | - $this->post_types = get_post_types(); |
|
129 | - $this->post_type_slugs = array( |
|
130 | - 'post' => 'posts', |
|
131 | - 'project' => 'projects', |
|
132 | - 'service' => 'services', |
|
133 | - 'team' => 'team', |
|
134 | - 'testimonial' => 'testimonials', |
|
135 | - 'video' => 'videos', |
|
136 | - 'product' => 'products', |
|
137 | - ); |
|
138 | - $this->set_search_prefix(); |
|
139 | - $this->get_cmb2_options(); |
|
140 | - $this->search_enabled = apply_filters( 'lsx_search_enabled', $this->is_search_enabled(), $this ); |
|
141 | - $this->search_prefix = apply_filters( 'lsx_search_prefix', $this->search_prefix, $this ); |
|
142 | - } |
|
143 | - |
|
144 | - private function get_cmb2_options() { |
|
145 | - $cmb2_options = get_option( 'lsx-search-settings' ); |
|
146 | - if ( false !== $cmb2_options && ! empty( $cmb2_options ) ) { |
|
147 | - $this->set_search_prefix( true ); |
|
148 | - $this->options['display'] = $cmb2_options; |
|
149 | - foreach ( $this->options['display'] as $option_key => $option_value ) { |
|
150 | - if ( is_array( $option_value ) && ! empty( $option_value ) ) { |
|
151 | - $new_values = array(); |
|
152 | - foreach ( $option_value as $empty_key => $key_value ) { |
|
153 | - $new_values[ $key_value ] = 'on'; |
|
154 | - } |
|
155 | - $this->options['display'][ $option_key ] = $new_values; |
|
156 | - } |
|
157 | - } |
|
158 | - $this->new_options = true; |
|
159 | - $this->disable_to_search_actions(); |
|
160 | - } |
|
161 | - } |
|
162 | - |
|
163 | - private function disable_to_search_actions() { |
|
164 | - global $lsx_to_search_fwp, $lsx_to_search; |
|
165 | - if ( null !== $lsx_to_search ) { |
|
166 | - // Redirects. |
|
167 | - remove_filter( 'template_include', array( $lsx_to_search, 'search_template_include' ), 99 ); |
|
168 | - remove_action( 'template_redirect', array( $lsx_to_search, 'pretty_search_redirect' ) ); |
|
169 | - remove_filter( 'pre_get_posts', array( $lsx_to_search, 'pretty_search_parse_query' ) ); |
|
170 | - |
|
171 | - // Layout Filter. |
|
172 | - remove_filter( 'lsx_layout', array( $lsx_to_search, 'lsx_layout' ), 20, 1 ); |
|
173 | - remove_filter( 'lsx_layout_selector', array( $lsx_to_search, 'lsx_layout_selector' ), 10, 4 ); |
|
174 | - remove_filter( 'lsx_to_archive_layout', array( $lsx_to_search, 'lsx_to_search_archive_layout' ), 10, 2 ); |
|
175 | - |
|
176 | - remove_action( 'lsx_search_sidebar_top', array( $lsx_to_search, 'search_sidebar_top' ) ); |
|
177 | - remove_action( 'pre_get_posts', array( $lsx_to_search, 'price_sorting' ), 100 ); |
|
178 | - |
|
179 | - //add_shortcode( 'lsx_search_form', array( 'LSX_TO_Search_Frontend', 'search_form' ) ); |
|
180 | - remove_filter( 'searchwp_short_circuit', array( $lsx_to_search, 'searchwp_short_circuit' ), 10, 2 ); |
|
181 | - remove_filter( 'get_search_query', array( $lsx_to_search, 'get_search_query' ) ); |
|
182 | - remove_filter( 'body_class', array( $lsx_to_search, 'to_add_search_url_class' ), 20 ); |
|
183 | - |
|
184 | - remove_filter( 'facetwp_preload_url_vars', array( $lsx_to_search, 'preload_url_vars' ), 10, 1 ); |
|
185 | - remove_filter( 'wpseo_json_ld_search_url', array( $lsx_to_search, 'change_json_ld_search_url' ), 10, 1 ); |
|
186 | - } |
|
187 | - if ( null !== $lsx_to_search_fwp ) { |
|
188 | - remove_filter( 'facetwp_indexer_row_data', array( $lsx_to_search_fwp, 'facetwp_index_row_data' ), 10, 2 ); |
|
189 | - remove_filter( 'facetwp_index_row', array( $lsx_to_search_fwp, 'facetwp_index_row' ), 10, 2 ); |
|
190 | - |
|
191 | - remove_filter( 'facetwp_sort_options', array( $lsx_to_search_fwp, 'facet_sort_options' ), 10, 2 ); |
|
192 | - |
|
193 | - remove_filter( 'facetwp_pager_html', array( $lsx_to_search_fwp, 'facetwp_pager_html' ), 10, 2 ); |
|
194 | - remove_filter( 'facetwp_result_count', array( $lsx_to_search_fwp, 'facetwp_result_count' ), 10, 2 ); |
|
195 | - |
|
196 | - remove_filter( 'facetwp_facet_html', array( $lsx_to_search_fwp, 'destination_facet_html' ), 10, 2 ); |
|
197 | - remove_filter( 'facetwp_facet_html', array( $lsx_to_search_fwp, 'slide_facet_html' ), 10, 2 ); |
|
198 | - remove_filter( 'facetwp_facet_html', array( $lsx_to_search_fwp, 'search_facet_html' ), 10, 2 ); |
|
199 | - remove_filter( 'facetwp_load_css', array( $lsx_to_search_fwp, 'facetwp_load_css' ), 10, 1 ); |
|
200 | - |
|
201 | - if ( class_exists( 'LSX_Currencies' ) ) { |
|
202 | - remove_filter( 'facetwp_render_output', array( $lsx_to_search_fwp, 'slide_price_lsx_currencies' ), 10, 2 ); |
|
203 | - } else { |
|
204 | - remove_filter( 'facetwp_render_output', array( $lsx_to_search_fwp, 'slide_price_to_currencies' ), 10, 2 ); |
|
205 | - } |
|
206 | - } |
|
207 | - } |
|
208 | - |
|
209 | - /** |
|
210 | - * Returns if the search is enabled. |
|
211 | - * |
|
212 | - * @return boolean |
|
213 | - */ |
|
214 | - public function is_search_enabled() { |
|
215 | - $search_enabled = false; |
|
216 | - |
|
217 | - if ( false === $this->new_options ) { |
|
218 | - if ( isset( $this->options['display'][ $this->search_prefix . '_enable_' . $this->search_core_suffix ] ) && ( ! empty( $this->options ) ) && 'on' == $this->options['display'][ $this->search_prefix . '_enable_' . $this->search_core_suffix ] ) { |
|
219 | - $search_enabled = true; |
|
220 | - } |
|
221 | - } else { |
|
222 | - $enable_prefix = $this->search_prefix; |
|
223 | - if ( ! empty( $this->options ) && isset( $this->options['display'] ) && isset( $this->options['display'][ $enable_prefix . '_enable' ] ) && 'on' === $this->options['display'][ $enable_prefix . '_enable' ] ) { |
|
224 | - $search_enabled = true; |
|
225 | - } |
|
226 | - } |
|
227 | - return $search_enabled; |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * Sets the search prefix. |
|
232 | - * |
|
233 | - * @return void |
|
234 | - */ |
|
235 | - private function set_search_prefix( $new_prefixes = false ) { |
|
236 | - $page_for_posts = get_option( 'page_for_posts' ); |
|
237 | - if ( false !== $new_prefixes ) { |
|
238 | - $this->taxonomies = array(); |
|
239 | - $this->post_types = array(); |
|
240 | - } |
|
241 | - |
|
242 | - if ( is_search() ) { |
|
243 | - if ( false === $new_prefixes ) { |
|
244 | - $this->search_core_suffix = 'core'; |
|
245 | - $this->search_prefix = 'search'; |
|
246 | - } else { |
|
247 | - $this->search_core_suffix = 'enable'; |
|
248 | - $this->search_prefix = 'engine_search'; |
|
249 | - } |
|
250 | - } elseif ( is_post_type_archive( $this->post_types ) || is_tax() || is_page( $page_for_posts ) || is_home() || is_category() || is_tag() ) { |
|
251 | - if ( false === $new_prefixes ) { |
|
252 | - $this->search_core_suffix = 'search'; |
|
253 | - } else { |
|
254 | - $this->search_core_suffix = 'enable'; |
|
255 | - } |
|
256 | - |
|
257 | - if ( is_tax() ) { |
|
258 | - $tax = get_query_var( 'taxonomy' ); |
|
259 | - $tax = get_taxonomy( $tax ); |
|
260 | - $post_type = $tax->object_type[0]; |
|
261 | - } else if ( is_page( $page_for_posts ) || is_category() || is_tag() || is_home() ) { |
|
262 | - $post_type = 'post'; |
|
263 | - } else { |
|
264 | - $post_type = get_query_var( 'post_type' ); |
|
265 | - } |
|
266 | - |
|
267 | - if ( false === $new_prefixes ) { |
|
268 | - if ( isset( $this->tabs[ $post_type ] ) ) { |
|
269 | - $this->search_prefix = $this->tabs[ $post_type ] . '_archive'; |
|
270 | - } |
|
271 | - } else { |
|
272 | - $this->search_prefix = $post_type . '_search'; |
|
273 | - } |
|
274 | - } |
|
275 | - } |
|
276 | - |
|
277 | - /** |
|
278 | - * Sets the FacetWP variables. |
|
279 | - */ |
|
280 | - public function set_facetwp_vars() { |
|
281 | - |
|
282 | - if ( class_exists( 'FacetWP' ) ) { |
|
283 | - $facet_data = FWP()->helper->get_facets(); |
|
284 | - } |
|
285 | - |
|
286 | - $this->facet_data = array(); |
|
287 | - |
|
288 | - $this->facet_data['search_form'] = array( |
|
289 | - 'name' => 'search_form', |
|
290 | - 'label' => esc_html__( 'Search Form', 'lsx-search' ), |
|
291 | - ); |
|
292 | - |
|
293 | - if ( ! empty( $facet_data ) && is_array( $facet_data ) ) { |
|
294 | - foreach ( $facet_data as $facet ) { |
|
295 | - $this->facet_data[ $facet['name'] ] = $facet; |
|
296 | - } |
|
297 | - } |
|
298 | - } |
|
299 | - |
|
300 | - /** |
|
301 | - * Check all settings. |
|
302 | - */ |
|
303 | - public function core() { |
|
304 | - |
|
305 | - if ( true === $this->search_enabled ) { |
|
306 | - add_action( 'wp_enqueue_scripts', array( $this, 'assets' ), 999 ); |
|
307 | - |
|
308 | - add_filter( 'lsx_layout', array( $this, 'lsx_layout' ), 20, 1 ); |
|
309 | - add_filter( 'lsx_layout_selector', array( $this, 'lsx_layout_selector' ), 10, 4 ); |
|
310 | - add_filter( 'lsx_slot_class', array( $this, 'change_slot_column_class' ) ); |
|
311 | - add_action( 'lsx_entry_top', array( $this, 'add_label_to_title' ) ); |
|
312 | - add_filter( 'body_class', array( $this, 'body_class' ), 10 ); |
|
313 | - |
|
314 | - add_filter( 'lsx_blog_customizer_top_of_blog_action', array( $this, 'top_of_blog_action' ), 10, 1 ); |
|
315 | - add_filter( 'lsx_blog_customizer_blog_description_class', array( $this, 'blog_description_class' ), 10, 1 ); |
|
316 | - |
|
317 | - if ( class_exists( 'LSX_Videos' ) ) { |
|
318 | - global $lsx_videos_frontend; |
|
319 | - remove_action( 'lsx_content_top', array( $lsx_videos_frontend, 'categories_tabs' ), 15 ); |
|
320 | - } |
|
321 | - |
|
322 | - add_filter( 'lsx_paging_nav_disable', '__return_true' ); |
|
323 | - add_action( 'lsx_content_top', array( $this, 'facet_top_bar' ) ); |
|
324 | - add_action( 'lsx_content_top', array( $this, 'facetwp_tempate_open' ) ); |
|
325 | - add_action( 'lsx_content_bottom', array( $this, 'facetwp_tempate_close' ) ); |
|
326 | - add_action( 'lsx_content_bottom', array( $this, 'facet_bottom_bar' ) ); |
|
327 | - |
|
328 | - if ( ! empty( $this->options['display'][ $this->search_prefix . '_layout' ] ) && '1c' !== $this->options['display'][ $this->search_prefix . '_layout' ] ) { |
|
329 | - add_filter( 'lsx_sidebar_enable', array( $this, 'lsx_sidebar_enable' ), 10, 1 ); |
|
330 | - } |
|
331 | - |
|
332 | - add_action( 'lsx_content_wrap_before', array( $this, 'search_sidebar' ), 150 ); |
|
333 | - |
|
334 | - if ( class_exists( 'WooCommerce' ) && ( is_shop() || is_product_category() || is_product_tag() ) ) { |
|
335 | - remove_action( 'woocommerce_archive_description', 'woocommerce_taxonomy_archive_description' ); |
|
336 | - remove_action( 'woocommerce_archive_description', 'woocommerce_product_archive_description' ); |
|
337 | - add_filter( 'woocommerce_show_page_title', '__return_false' ); |
|
338 | - |
|
339 | - add_filter( 'loop_shop_columns', function() { |
|
340 | - return 3; |
|
341 | - } ); |
|
342 | - |
|
343 | - // Actions added by LSX theme |
|
344 | - remove_action( 'lsx_content_wrap_before', 'lsx_global_header' ); |
|
345 | - add_action( 'lsx_content_wrap_before', array( $this, 'wc_archive_header' ), 140 ); |
|
346 | - |
|
347 | - // Actions added be LSX theme / woocommerce.php file |
|
348 | - remove_action( 'woocommerce_after_shop_loop', 'lsx_wc_sorting_wrapper', 9 ); |
|
349 | - remove_action( 'woocommerce_after_shop_loop', 'woocommerce_catalog_ordering', 10 ); |
|
350 | - remove_action( 'woocommerce_after_shop_loop', 'woocommerce_result_count', 20 ); |
|
351 | - remove_action( 'woocommerce_after_shop_loop', 'woocommerce_pagination', 30 ); |
|
352 | - remove_action( 'woocommerce_after_shop_loop', 'lsx_wc_sorting_wrapper_close', 31 ); |
|
353 | - |
|
354 | - // Actions added be LSX theme / woocommerce.php file |
|
355 | - remove_action( 'woocommerce_before_shop_loop', 'lsx_wc_sorting_wrapper', 9 ); |
|
356 | - remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 10 ); |
|
357 | - remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 ); |
|
358 | - remove_action( 'woocommerce_before_shop_loop', 'lsx_wc_woocommerce_pagination', 30 ); |
|
359 | - remove_action( 'woocommerce_before_shop_loop', 'lsx_wc_sorting_wrapper_close', 31 ); |
|
360 | - } |
|
361 | - } |
|
362 | - } |
|
363 | - |
|
364 | - /** |
|
365 | - * Adds a search class to the body to allow the styling of the sidebars etc. |
|
366 | - * |
|
367 | - * @param array $classes The classes. |
|
368 | - * @return array $classes The classes. |
|
369 | - */ |
|
370 | - public function body_class( $classes ) { |
|
371 | - $classes[] = 'lsx-search-enabled'; |
|
372 | - return $classes; |
|
373 | - } |
|
374 | - |
|
375 | - /** |
|
376 | - * Moves the blog description to above the content columns. |
|
377 | - * |
|
378 | - * @param string $action |
|
379 | - * @return string $action |
|
380 | - */ |
|
381 | - public function top_of_blog_action( $action = '' ) { |
|
382 | - $action = 'lsx_content_wrap_before'; |
|
383 | - return $action; |
|
384 | - } |
|
385 | - |
|
386 | - /** |
|
387 | - * Adds a class to the blog description. |
|
388 | - * |
|
389 | - * @param string $action |
|
390 | - * @return string $action |
|
391 | - */ |
|
392 | - public function blog_description_class( $class = '' ) { |
|
393 | - $class .= ' col-md-12 search-description'; |
|
394 | - return $class; |
|
395 | - } |
|
396 | - |
|
397 | - /** |
|
398 | - * Check the $wp_query global to see if there are posts in the current query. |
|
399 | - * |
|
400 | - * @return void |
|
401 | - */ |
|
402 | - public function check_for_results() { |
|
403 | - if ( true === $this->search_enabled ) { |
|
404 | - global $wp_query; |
|
405 | - if ( empty( $wp_query->posts ) ) { |
|
406 | - $this->has_posts = false; |
|
407 | - remove_action( 'lsx_content_top', array( $this, 'facet_top_bar' ) ); |
|
408 | - remove_action( 'lsx_content_bottom', array( $this, 'facet_bottom_bar' ) ); |
|
409 | - remove_action( 'lsx_content_wrap_before', array( $this, 'search_sidebar' ), 150 ); |
|
410 | - } else { |
|
411 | - $this->has_posts = true; |
|
412 | - } |
|
413 | - } |
|
414 | - } |
|
415 | - |
|
416 | - /** |
|
417 | - * Filter the post types. |
|
418 | - */ |
|
419 | - public function filter_post_types( $query ) { |
|
420 | - if ( ! is_admin() && $query->is_main_query() && $query->is_search() ) { |
|
421 | - if ( ! empty( $this->options ) && ! empty( $this->options['display']['search_enable_core'] ) ) { |
|
422 | - if ( ! empty( $this->options['general']['search_post_types'] ) && is_array( $this->options['general']['search_post_types'] ) ) { |
|
423 | - $post_types = array_keys( $this->options['general']['search_post_types'] ); |
|
424 | - $query->set( 'post_type', $post_types ); |
|
425 | - } |
|
426 | - } |
|
427 | - } |
|
428 | - } |
|
429 | - |
|
430 | - /** |
|
431 | - * Sets post types with active search options. |
|
432 | - */ |
|
433 | - public function register_post_types( $post_types ) { |
|
434 | - $post_types = array( 'post', 'project', 'service', 'team', 'testimonial', 'video', 'product' ); |
|
435 | - return $post_types; |
|
436 | - } |
|
437 | - |
|
438 | - /** |
|
439 | - * Sets taxonomies with active search options. |
|
440 | - */ |
|
441 | - public function register_taxonomies( $taxonomies ) { |
|
442 | - $taxonomies = array( 'category', 'post_tag', 'project-group', 'service-group', 'team_role', 'video-category', 'product_cat', 'product_tag' ); |
|
443 | - return $taxonomies; |
|
444 | - } |
|
445 | - |
|
446 | - /** |
|
447 | - * Sets post types with active search options. |
|
448 | - */ |
|
449 | - public function register_post_type_tabs( $post_types_plural ) { |
|
450 | - $post_types_plural = array( |
|
451 | - 'post' => 'posts', |
|
452 | - 'project' => 'projects', |
|
453 | - 'service' => 'services', |
|
454 | - 'team' => 'team', |
|
455 | - 'testimonial' => 'testimonials', |
|
456 | - 'video' => 'videos', |
|
457 | - 'product' => 'products', // WooCommerce |
|
458 | - ); |
|
459 | - return $post_types_plural; |
|
460 | - } |
|
461 | - |
|
462 | - /** |
|
463 | - * Enqueue styles and scripts. |
|
464 | - */ |
|
465 | - public function assets() { |
|
466 | - add_filter( 'lsx_defer_parsing_of_js', array( $this, 'skip_js_defer' ), 10, 4 ); |
|
467 | - wp_enqueue_script( 'touchSwipe', LSX_SEARCH_URL . 'assets/js/vendor/jquery.touchSwipe.min.js', array( 'jquery' ), LSX_SEARCH_VER, true ); |
|
468 | - wp_enqueue_script( 'slideandswipe', LSX_SEARCH_URL . 'assets/js/vendor/jquery.slideandswipe.min.js', array( 'jquery', 'touchSwipe' ), LSX_SEARCH_VER, true ); |
|
469 | - wp_enqueue_script( 'lsx-search', LSX_SEARCH_URL . 'assets/js/src/lsx-search.js', array( 'jquery', 'touchSwipe', 'slideandswipe', 'jquery-ui-datepicker' ), LSX_SEARCH_VER, true ); |
|
470 | - |
|
471 | - $params = apply_filters( 'lsx_search_js_params', array( |
|
472 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
473 | - )); |
|
474 | - |
|
475 | - wp_localize_script( 'lsx-search', 'lsx_customizer_params', $params ); |
|
476 | - |
|
477 | - wp_enqueue_style( 'lsx-search', LSX_SEARCH_URL . 'assets/css/lsx-search.css', array(), LSX_SEARCH_VER ); |
|
478 | - wp_style_add_data( 'lsx-search', 'rtl', 'replace' ); |
|
479 | - |
|
480 | - if ( true === $this->new_options ) { |
|
481 | - wp_deregister_style( 'lsx_to_search' ); |
|
482 | - wp_deregister_script( 'lsx_to_search' ); |
|
483 | - } |
|
484 | - } |
|
485 | - |
|
486 | - /** |
|
487 | - * Adds the to-search.min.js and the to-search.js |
|
488 | - * |
|
489 | - * @param boolean $should_skip |
|
490 | - * @param string $tag |
|
491 | - * @param string $handle |
|
492 | - * @param string $href |
|
493 | - * @return boolean |
|
494 | - */ |
|
495 | - public function skip_js_defer( $should_skip, $tag, $handle, $href ) { |
|
496 | - if ( ! is_admin() && ( false !== stripos( $href, 'lsx-search.min.js' ) || false !== stripos( $href, 'lsx-search.js' ) ) ) { |
|
497 | - $should_skip = true; |
|
498 | - } |
|
499 | - return $should_skip; |
|
500 | - } |
|
501 | - |
|
502 | - /** |
|
503 | - * Redirect wordpress to the search template located in the plugin |
|
504 | - * |
|
505 | - * @param $template |
|
506 | - * @return $template |
|
507 | - */ |
|
508 | - public function search_template_include( $template ) { |
|
509 | - if ( is_main_query() && is_search() ) { |
|
510 | - if ( file_exists( LSX_SEARCH_PATH . 'templates/search.php' ) ) { |
|
511 | - $template = LSX_SEARCH_PATH . 'templates/search.php'; |
|
512 | - } |
|
513 | - } |
|
514 | - |
|
515 | - return $template; |
|
516 | - } |
|
517 | - |
|
518 | - /** |
|
519 | - * Rewrite the search URL |
|
520 | - */ |
|
521 | - public function pretty_search_redirect() { |
|
522 | - global $wp_rewrite,$wp_query; |
|
523 | - |
|
524 | - if ( ! isset( $wp_rewrite ) || ! is_object( $wp_rewrite ) || ! $wp_rewrite->using_permalinks() ) { |
|
525 | - return; |
|
526 | - } |
|
527 | - |
|
528 | - $search_base = $wp_rewrite->search_base; |
|
529 | - |
|
530 | - if ( is_search() && ! is_admin() && strpos( $_SERVER['REQUEST_URI'], "/{$search_base}/" ) === false ) { |
|
531 | - $search_query = get_query_var( 's' ); |
|
532 | - $engine = ''; |
|
533 | - |
|
534 | - // If the search was triggered by a supplemental engine. |
|
535 | - if ( isset( $_GET['engine'] ) && 'default' !== $_GET['engine'] ) { |
|
536 | - $engine = $_GET['engine']; |
|
537 | - set_query_var( 'engine', $engine ); |
|
538 | - $engine = array_search( $engine, $this->post_type_slugs, true ) . '/'; |
|
539 | - } |
|
540 | - |
|
541 | - $get_array = $_GET; |
|
542 | - |
|
543 | - if ( is_array( $get_array ) && ! empty( $get_array ) ) { |
|
544 | - $vars_to_maintain = array(); |
|
545 | - |
|
546 | - foreach ( $get_array as $ga_key => $ga_value ) { |
|
547 | - if ( false !== strpos( $ga_key, 'fwp_' ) ) { |
|
548 | - $vars_to_maintain[] = $ga_key . '=' . $ga_value; |
|
549 | - } |
|
550 | - } |
|
551 | - } |
|
552 | - |
|
553 | - $redirect_url = home_url( "/{$search_base}/" . $engine . urlencode( $search_query ) ); |
|
554 | - |
|
555 | - if ( ! empty( $vars_to_maintain ) ) { |
|
556 | - $redirect_url .= '?' . implode( '&', $vars_to_maintain ); |
|
557 | - } |
|
558 | - |
|
559 | - wp_redirect( $redirect_url ); |
|
560 | - exit(); |
|
561 | - } |
|
562 | - } |
|
563 | - |
|
564 | - /** |
|
565 | - * Parse the Query and trigger a search |
|
566 | - */ |
|
567 | - public function pretty_search_parse_query( $query ) { |
|
568 | - $this->post_type_slugs = array( |
|
569 | - 'post' => 'posts', |
|
570 | - 'project' => 'projects', |
|
571 | - 'service' => 'services', |
|
572 | - 'team' => 'team', |
|
573 | - 'testimonial' => 'testimonials', |
|
574 | - 'video' => 'videos', |
|
575 | - 'product' => 'products', // WooCommerce |
|
576 | - ); |
|
577 | - if ( $query->is_search() && ! is_admin() && $query->is_main_query() ) { |
|
578 | - $search_query = $query->get( 's' ); |
|
579 | - $keyword_test = explode( '/', $search_query ); |
|
580 | - |
|
581 | - $index = array_search( $keyword_test[0], $this->post_type_slugs, true ); |
|
582 | - if ( false !== $index ) { |
|
583 | - $engine = $this->post_type_slugs[ $index ]; |
|
584 | - |
|
585 | - $query->set( 'post_type', $engine ); |
|
586 | - $query->set( 'engine', $engine ); |
|
587 | - |
|
588 | - if ( count( $keyword_test ) > 1 ) { |
|
589 | - $query->set( 's', $keyword_test[1] ); |
|
590 | - } elseif ( post_type_exists( $engine ) ) { |
|
591 | - $query->set( 's', '' ); |
|
592 | - } |
|
593 | - } else { |
|
594 | - if ( isset( $this->options['general']['search_post_types'] ) && is_array( $this->options['general']['search_post_types'] ) ) { |
|
595 | - $post_types = array_keys( $this->options['general']['search_post_types'] ); |
|
596 | - $query->set( 'post_type', $post_types ); |
|
597 | - } |
|
598 | - } |
|
599 | - } |
|
600 | - |
|
601 | - return $query; |
|
602 | - } |
|
603 | - |
|
604 | - /** |
|
605 | - * Change the search slug to /search/ for the JSON+LD output in Yoast SEO |
|
606 | - * |
|
607 | - * @return url |
|
608 | - */ |
|
609 | - public function change_json_ld_search_url() { |
|
610 | - return trailingslashit( home_url() ) . 'search/{search_term_string}'; |
|
611 | - } |
|
612 | - |
|
613 | - /** |
|
614 | - * A filter to set the layout to 2 column. |
|
615 | - */ |
|
616 | - public function lsx_layout( $layout ) { |
|
617 | - if ( ! empty( $this->options['display'][ $this->search_prefix . '_layout' ] ) ) { |
|
618 | - if ( false === $this->has_posts ) { |
|
619 | - $layout = '1c'; |
|
620 | - } else { |
|
621 | - $layout = $this->options['display'][ $this->search_prefix . '_layout' ]; |
|
622 | - } |
|
623 | - } |
|
624 | - return $layout; |
|
625 | - } |
|
626 | - |
|
627 | - /** |
|
628 | - * Outputs the Search Title Facet |
|
629 | - */ |
|
630 | - public function search_sidebar_top() { |
|
631 | - if ( ! empty( $this->options['display'][ $this->search_prefix . '_facets' ] ) && is_array( $this->options['display'][ $this->search_prefix . '_facets' ] ) && true !== apply_filters( 'lsx_search_hide_search_box', false ) ) { |
|
632 | - |
|
633 | - if ( ! is_search() ) { |
|
634 | - |
|
635 | - foreach ( $this->options['display'][ $this->search_prefix . '_facets' ] as $facet => $facet_useless ) { |
|
636 | - |
|
637 | - if ( isset( $this->facet_data[ $facet ] ) && 'search' === $this->facet_data[ $facet ]['type'] ) { |
|
638 | - echo wp_kses_post( '<div class="row">' ); |
|
639 | - $this->display_facet_default( $facet ); |
|
640 | - echo wp_kses_post( '</div>' ); |
|
641 | - unset( $this->options['display'][ $this->search_prefix . '_facets' ][ $facet ] ); |
|
642 | - } |
|
643 | - } |
|
644 | - } else { |
|
645 | - echo wp_kses_post( '<div class="row">' ); |
|
646 | - $this->display_facet_search(); |
|
647 | - echo wp_kses_post( '</div>' ); |
|
648 | - } |
|
649 | - } |
|
650 | - } |
|
651 | - |
|
652 | - /** |
|
653 | - * Overrides the search facet HTML |
|
654 | - * @param $output |
|
655 | - * @param $params |
|
656 | - * |
|
657 | - * @return string |
|
658 | - */ |
|
659 | - public function search_facet_html( $output, $params ) { |
|
660 | - if ( 'search' == $params['facet']['type'] ) { |
|
661 | - |
|
662 | - $value = (array) $params['selected_values']; |
|
663 | - $value = empty( $value ) ? '' : stripslashes( $value[0] ); |
|
664 | - $placeholder = isset( $params['facet']['placeholder'] ) ? $params['facet']['placeholder'] : __( 'Search...', 'lsx-search' ); |
|
665 | - $placeholder = facetwp_i18n( $placeholder ); |
|
666 | - |
|
667 | - ob_start(); |
|
668 | - ?> |
|
12 | + /** |
|
13 | + * Holds class instance |
|
14 | + * |
|
15 | + * @since 1.0.0 |
|
16 | + * |
|
17 | + * @var object \lsx\search\classes\Frontend() |
|
18 | + */ |
|
19 | + protected static $instance = null; |
|
20 | + |
|
21 | + public $options = false; |
|
22 | + |
|
23 | + public $tabs = false; |
|
24 | + |
|
25 | + public $facet_data = false; |
|
26 | + |
|
27 | + /** |
|
28 | + * Determine weather or not search is enabled for this page. |
|
29 | + * |
|
30 | + * @var boolean |
|
31 | + */ |
|
32 | + public $search_enabled = false; |
|
33 | + |
|
34 | + public $search_core_suffix = false; |
|
35 | + |
|
36 | + public $search_prefix = false; |
|
37 | + |
|
38 | + /** |
|
39 | + * Holds the post types enabled |
|
40 | + * |
|
41 | + * @var array |
|
42 | + */ |
|
43 | + public $post_types = array(); |
|
44 | + |
|
45 | + /** |
|
46 | + * Holds the taxonomies enabled for search |
|
47 | + * |
|
48 | + * @var array |
|
49 | + */ |
|
50 | + public $taxonomies = array(); |
|
51 | + |
|
52 | + /** |
|
53 | + * If the current search page has posts or not |
|
54 | + * |
|
55 | + * @var boolean |
|
56 | + */ |
|
57 | + public $has_posts = false; |
|
58 | + |
|
59 | + /** |
|
60 | + * If we are using the CMB2 options or not. |
|
61 | + * |
|
62 | + * @var boolean |
|
63 | + */ |
|
64 | + public $new_options = false; |
|
65 | + |
|
66 | + /** |
|
67 | + * Construct method. |
|
68 | + */ |
|
69 | + public function __construct() { |
|
70 | + $this->options = \lsx\search\includes\get_options(); |
|
71 | + $this->load_classes(); |
|
72 | + |
|
73 | + add_filter( 'wpseo_json_ld_search_url', array( $this, 'change_json_ld_search_url' ), 10, 1 ); |
|
74 | + add_action( 'wp', array( $this, 'set_vars' ), 21 ); |
|
75 | + add_action( 'wp', array( $this, 'set_facetwp_vars' ), 22 ); |
|
76 | + add_action( 'wp', array( $this, 'core' ), 23 ); |
|
77 | + add_action( 'lsx_body_top', array( $this, 'check_for_results' ) ); |
|
78 | + |
|
79 | + add_action( 'pre_get_posts', array( $this, 'filter_post_types' ) ); |
|
80 | + |
|
81 | + add_filter( 'lsx_search_post_types', array( $this, 'register_post_types' ) ); |
|
82 | + add_filter( 'lsx_search_taxonomies', array( $this, 'register_taxonomies' ) ); |
|
83 | + add_filter( 'lsx_search_post_types_plural', array( $this, 'register_post_type_tabs' ) ); |
|
84 | + add_filter( 'facetwp_sort_options', array( $this, 'facetwp_sort_options' ), 10, 2 ); |
|
85 | + add_filter( 'wp_kses_allowed_html', array( $this, 'kses_allowed_html' ), 20, 2 ); |
|
86 | + |
|
87 | + // Redirects. |
|
88 | + add_action( 'template_redirect', array( $this, 'pretty_search_redirect' ) ); |
|
89 | + add_filter( 'pre_get_posts', array( $this, 'pretty_search_parse_query' ) ); |
|
90 | + |
|
91 | + add_action( 'lsx_search_sidebar_top', array( $this, 'search_sidebar_top' ) ); |
|
92 | + add_filter( 'facetwp_facet_html', array( $this, 'search_facet_html' ), 10, 2 ); |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Return an instance of this class. |
|
97 | + * |
|
98 | + * @since 1.0.0 |
|
99 | + * |
|
100 | + * @return object \lsx\member_directory\search\Frontend() A single instance of this class. |
|
101 | + */ |
|
102 | + public static function get_instance() { |
|
103 | + // If the single instance hasn't been set, set it now. |
|
104 | + if ( null === self::$instance ) { |
|
105 | + self::$instance = new self(); |
|
106 | + } |
|
107 | + return self::$instance; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Loads the variable classes and the static classes. |
|
112 | + */ |
|
113 | + private function load_classes() { |
|
114 | + require_once LSX_SEARCH_PATH . 'classes/frontend/class-layout.php'; |
|
115 | + $this->layout = frontend\Layout::get_instance(); |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * Check all settings. |
|
120 | + */ |
|
121 | + public function set_vars() { |
|
122 | + $post_type = ''; |
|
123 | + |
|
124 | + $this->post_types = apply_filters( 'lsx_search_post_types', array() ); |
|
125 | + $this->taxonomies = apply_filters( 'lsx_search_taxonomies', array() ); |
|
126 | + $this->tabs = apply_filters( 'lsx_search_post_types_plural', array() ); |
|
127 | + $this->options = apply_filters( 'lsx_search_options', $this->options ); |
|
128 | + $this->post_types = get_post_types(); |
|
129 | + $this->post_type_slugs = array( |
|
130 | + 'post' => 'posts', |
|
131 | + 'project' => 'projects', |
|
132 | + 'service' => 'services', |
|
133 | + 'team' => 'team', |
|
134 | + 'testimonial' => 'testimonials', |
|
135 | + 'video' => 'videos', |
|
136 | + 'product' => 'products', |
|
137 | + ); |
|
138 | + $this->set_search_prefix(); |
|
139 | + $this->get_cmb2_options(); |
|
140 | + $this->search_enabled = apply_filters( 'lsx_search_enabled', $this->is_search_enabled(), $this ); |
|
141 | + $this->search_prefix = apply_filters( 'lsx_search_prefix', $this->search_prefix, $this ); |
|
142 | + } |
|
143 | + |
|
144 | + private function get_cmb2_options() { |
|
145 | + $cmb2_options = get_option( 'lsx-search-settings' ); |
|
146 | + if ( false !== $cmb2_options && ! empty( $cmb2_options ) ) { |
|
147 | + $this->set_search_prefix( true ); |
|
148 | + $this->options['display'] = $cmb2_options; |
|
149 | + foreach ( $this->options['display'] as $option_key => $option_value ) { |
|
150 | + if ( is_array( $option_value ) && ! empty( $option_value ) ) { |
|
151 | + $new_values = array(); |
|
152 | + foreach ( $option_value as $empty_key => $key_value ) { |
|
153 | + $new_values[ $key_value ] = 'on'; |
|
154 | + } |
|
155 | + $this->options['display'][ $option_key ] = $new_values; |
|
156 | + } |
|
157 | + } |
|
158 | + $this->new_options = true; |
|
159 | + $this->disable_to_search_actions(); |
|
160 | + } |
|
161 | + } |
|
162 | + |
|
163 | + private function disable_to_search_actions() { |
|
164 | + global $lsx_to_search_fwp, $lsx_to_search; |
|
165 | + if ( null !== $lsx_to_search ) { |
|
166 | + // Redirects. |
|
167 | + remove_filter( 'template_include', array( $lsx_to_search, 'search_template_include' ), 99 ); |
|
168 | + remove_action( 'template_redirect', array( $lsx_to_search, 'pretty_search_redirect' ) ); |
|
169 | + remove_filter( 'pre_get_posts', array( $lsx_to_search, 'pretty_search_parse_query' ) ); |
|
170 | + |
|
171 | + // Layout Filter. |
|
172 | + remove_filter( 'lsx_layout', array( $lsx_to_search, 'lsx_layout' ), 20, 1 ); |
|
173 | + remove_filter( 'lsx_layout_selector', array( $lsx_to_search, 'lsx_layout_selector' ), 10, 4 ); |
|
174 | + remove_filter( 'lsx_to_archive_layout', array( $lsx_to_search, 'lsx_to_search_archive_layout' ), 10, 2 ); |
|
175 | + |
|
176 | + remove_action( 'lsx_search_sidebar_top', array( $lsx_to_search, 'search_sidebar_top' ) ); |
|
177 | + remove_action( 'pre_get_posts', array( $lsx_to_search, 'price_sorting' ), 100 ); |
|
178 | + |
|
179 | + //add_shortcode( 'lsx_search_form', array( 'LSX_TO_Search_Frontend', 'search_form' ) ); |
|
180 | + remove_filter( 'searchwp_short_circuit', array( $lsx_to_search, 'searchwp_short_circuit' ), 10, 2 ); |
|
181 | + remove_filter( 'get_search_query', array( $lsx_to_search, 'get_search_query' ) ); |
|
182 | + remove_filter( 'body_class', array( $lsx_to_search, 'to_add_search_url_class' ), 20 ); |
|
183 | + |
|
184 | + remove_filter( 'facetwp_preload_url_vars', array( $lsx_to_search, 'preload_url_vars' ), 10, 1 ); |
|
185 | + remove_filter( 'wpseo_json_ld_search_url', array( $lsx_to_search, 'change_json_ld_search_url' ), 10, 1 ); |
|
186 | + } |
|
187 | + if ( null !== $lsx_to_search_fwp ) { |
|
188 | + remove_filter( 'facetwp_indexer_row_data', array( $lsx_to_search_fwp, 'facetwp_index_row_data' ), 10, 2 ); |
|
189 | + remove_filter( 'facetwp_index_row', array( $lsx_to_search_fwp, 'facetwp_index_row' ), 10, 2 ); |
|
190 | + |
|
191 | + remove_filter( 'facetwp_sort_options', array( $lsx_to_search_fwp, 'facet_sort_options' ), 10, 2 ); |
|
192 | + |
|
193 | + remove_filter( 'facetwp_pager_html', array( $lsx_to_search_fwp, 'facetwp_pager_html' ), 10, 2 ); |
|
194 | + remove_filter( 'facetwp_result_count', array( $lsx_to_search_fwp, 'facetwp_result_count' ), 10, 2 ); |
|
195 | + |
|
196 | + remove_filter( 'facetwp_facet_html', array( $lsx_to_search_fwp, 'destination_facet_html' ), 10, 2 ); |
|
197 | + remove_filter( 'facetwp_facet_html', array( $lsx_to_search_fwp, 'slide_facet_html' ), 10, 2 ); |
|
198 | + remove_filter( 'facetwp_facet_html', array( $lsx_to_search_fwp, 'search_facet_html' ), 10, 2 ); |
|
199 | + remove_filter( 'facetwp_load_css', array( $lsx_to_search_fwp, 'facetwp_load_css' ), 10, 1 ); |
|
200 | + |
|
201 | + if ( class_exists( 'LSX_Currencies' ) ) { |
|
202 | + remove_filter( 'facetwp_render_output', array( $lsx_to_search_fwp, 'slide_price_lsx_currencies' ), 10, 2 ); |
|
203 | + } else { |
|
204 | + remove_filter( 'facetwp_render_output', array( $lsx_to_search_fwp, 'slide_price_to_currencies' ), 10, 2 ); |
|
205 | + } |
|
206 | + } |
|
207 | + } |
|
208 | + |
|
209 | + /** |
|
210 | + * Returns if the search is enabled. |
|
211 | + * |
|
212 | + * @return boolean |
|
213 | + */ |
|
214 | + public function is_search_enabled() { |
|
215 | + $search_enabled = false; |
|
216 | + |
|
217 | + if ( false === $this->new_options ) { |
|
218 | + if ( isset( $this->options['display'][ $this->search_prefix . '_enable_' . $this->search_core_suffix ] ) && ( ! empty( $this->options ) ) && 'on' == $this->options['display'][ $this->search_prefix . '_enable_' . $this->search_core_suffix ] ) { |
|
219 | + $search_enabled = true; |
|
220 | + } |
|
221 | + } else { |
|
222 | + $enable_prefix = $this->search_prefix; |
|
223 | + if ( ! empty( $this->options ) && isset( $this->options['display'] ) && isset( $this->options['display'][ $enable_prefix . '_enable' ] ) && 'on' === $this->options['display'][ $enable_prefix . '_enable' ] ) { |
|
224 | + $search_enabled = true; |
|
225 | + } |
|
226 | + } |
|
227 | + return $search_enabled; |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * Sets the search prefix. |
|
232 | + * |
|
233 | + * @return void |
|
234 | + */ |
|
235 | + private function set_search_prefix( $new_prefixes = false ) { |
|
236 | + $page_for_posts = get_option( 'page_for_posts' ); |
|
237 | + if ( false !== $new_prefixes ) { |
|
238 | + $this->taxonomies = array(); |
|
239 | + $this->post_types = array(); |
|
240 | + } |
|
241 | + |
|
242 | + if ( is_search() ) { |
|
243 | + if ( false === $new_prefixes ) { |
|
244 | + $this->search_core_suffix = 'core'; |
|
245 | + $this->search_prefix = 'search'; |
|
246 | + } else { |
|
247 | + $this->search_core_suffix = 'enable'; |
|
248 | + $this->search_prefix = 'engine_search'; |
|
249 | + } |
|
250 | + } elseif ( is_post_type_archive( $this->post_types ) || is_tax() || is_page( $page_for_posts ) || is_home() || is_category() || is_tag() ) { |
|
251 | + if ( false === $new_prefixes ) { |
|
252 | + $this->search_core_suffix = 'search'; |
|
253 | + } else { |
|
254 | + $this->search_core_suffix = 'enable'; |
|
255 | + } |
|
256 | + |
|
257 | + if ( is_tax() ) { |
|
258 | + $tax = get_query_var( 'taxonomy' ); |
|
259 | + $tax = get_taxonomy( $tax ); |
|
260 | + $post_type = $tax->object_type[0]; |
|
261 | + } else if ( is_page( $page_for_posts ) || is_category() || is_tag() || is_home() ) { |
|
262 | + $post_type = 'post'; |
|
263 | + } else { |
|
264 | + $post_type = get_query_var( 'post_type' ); |
|
265 | + } |
|
266 | + |
|
267 | + if ( false === $new_prefixes ) { |
|
268 | + if ( isset( $this->tabs[ $post_type ] ) ) { |
|
269 | + $this->search_prefix = $this->tabs[ $post_type ] . '_archive'; |
|
270 | + } |
|
271 | + } else { |
|
272 | + $this->search_prefix = $post_type . '_search'; |
|
273 | + } |
|
274 | + } |
|
275 | + } |
|
276 | + |
|
277 | + /** |
|
278 | + * Sets the FacetWP variables. |
|
279 | + */ |
|
280 | + public function set_facetwp_vars() { |
|
281 | + |
|
282 | + if ( class_exists( 'FacetWP' ) ) { |
|
283 | + $facet_data = FWP()->helper->get_facets(); |
|
284 | + } |
|
285 | + |
|
286 | + $this->facet_data = array(); |
|
287 | + |
|
288 | + $this->facet_data['search_form'] = array( |
|
289 | + 'name' => 'search_form', |
|
290 | + 'label' => esc_html__( 'Search Form', 'lsx-search' ), |
|
291 | + ); |
|
292 | + |
|
293 | + if ( ! empty( $facet_data ) && is_array( $facet_data ) ) { |
|
294 | + foreach ( $facet_data as $facet ) { |
|
295 | + $this->facet_data[ $facet['name'] ] = $facet; |
|
296 | + } |
|
297 | + } |
|
298 | + } |
|
299 | + |
|
300 | + /** |
|
301 | + * Check all settings. |
|
302 | + */ |
|
303 | + public function core() { |
|
304 | + |
|
305 | + if ( true === $this->search_enabled ) { |
|
306 | + add_action( 'wp_enqueue_scripts', array( $this, 'assets' ), 999 ); |
|
307 | + |
|
308 | + add_filter( 'lsx_layout', array( $this, 'lsx_layout' ), 20, 1 ); |
|
309 | + add_filter( 'lsx_layout_selector', array( $this, 'lsx_layout_selector' ), 10, 4 ); |
|
310 | + add_filter( 'lsx_slot_class', array( $this, 'change_slot_column_class' ) ); |
|
311 | + add_action( 'lsx_entry_top', array( $this, 'add_label_to_title' ) ); |
|
312 | + add_filter( 'body_class', array( $this, 'body_class' ), 10 ); |
|
313 | + |
|
314 | + add_filter( 'lsx_blog_customizer_top_of_blog_action', array( $this, 'top_of_blog_action' ), 10, 1 ); |
|
315 | + add_filter( 'lsx_blog_customizer_blog_description_class', array( $this, 'blog_description_class' ), 10, 1 ); |
|
316 | + |
|
317 | + if ( class_exists( 'LSX_Videos' ) ) { |
|
318 | + global $lsx_videos_frontend; |
|
319 | + remove_action( 'lsx_content_top', array( $lsx_videos_frontend, 'categories_tabs' ), 15 ); |
|
320 | + } |
|
321 | + |
|
322 | + add_filter( 'lsx_paging_nav_disable', '__return_true' ); |
|
323 | + add_action( 'lsx_content_top', array( $this, 'facet_top_bar' ) ); |
|
324 | + add_action( 'lsx_content_top', array( $this, 'facetwp_tempate_open' ) ); |
|
325 | + add_action( 'lsx_content_bottom', array( $this, 'facetwp_tempate_close' ) ); |
|
326 | + add_action( 'lsx_content_bottom', array( $this, 'facet_bottom_bar' ) ); |
|
327 | + |
|
328 | + if ( ! empty( $this->options['display'][ $this->search_prefix . '_layout' ] ) && '1c' !== $this->options['display'][ $this->search_prefix . '_layout' ] ) { |
|
329 | + add_filter( 'lsx_sidebar_enable', array( $this, 'lsx_sidebar_enable' ), 10, 1 ); |
|
330 | + } |
|
331 | + |
|
332 | + add_action( 'lsx_content_wrap_before', array( $this, 'search_sidebar' ), 150 ); |
|
333 | + |
|
334 | + if ( class_exists( 'WooCommerce' ) && ( is_shop() || is_product_category() || is_product_tag() ) ) { |
|
335 | + remove_action( 'woocommerce_archive_description', 'woocommerce_taxonomy_archive_description' ); |
|
336 | + remove_action( 'woocommerce_archive_description', 'woocommerce_product_archive_description' ); |
|
337 | + add_filter( 'woocommerce_show_page_title', '__return_false' ); |
|
338 | + |
|
339 | + add_filter( 'loop_shop_columns', function() { |
|
340 | + return 3; |
|
341 | + } ); |
|
342 | + |
|
343 | + // Actions added by LSX theme |
|
344 | + remove_action( 'lsx_content_wrap_before', 'lsx_global_header' ); |
|
345 | + add_action( 'lsx_content_wrap_before', array( $this, 'wc_archive_header' ), 140 ); |
|
346 | + |
|
347 | + // Actions added be LSX theme / woocommerce.php file |
|
348 | + remove_action( 'woocommerce_after_shop_loop', 'lsx_wc_sorting_wrapper', 9 ); |
|
349 | + remove_action( 'woocommerce_after_shop_loop', 'woocommerce_catalog_ordering', 10 ); |
|
350 | + remove_action( 'woocommerce_after_shop_loop', 'woocommerce_result_count', 20 ); |
|
351 | + remove_action( 'woocommerce_after_shop_loop', 'woocommerce_pagination', 30 ); |
|
352 | + remove_action( 'woocommerce_after_shop_loop', 'lsx_wc_sorting_wrapper_close', 31 ); |
|
353 | + |
|
354 | + // Actions added be LSX theme / woocommerce.php file |
|
355 | + remove_action( 'woocommerce_before_shop_loop', 'lsx_wc_sorting_wrapper', 9 ); |
|
356 | + remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 10 ); |
|
357 | + remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 ); |
|
358 | + remove_action( 'woocommerce_before_shop_loop', 'lsx_wc_woocommerce_pagination', 30 ); |
|
359 | + remove_action( 'woocommerce_before_shop_loop', 'lsx_wc_sorting_wrapper_close', 31 ); |
|
360 | + } |
|
361 | + } |
|
362 | + } |
|
363 | + |
|
364 | + /** |
|
365 | + * Adds a search class to the body to allow the styling of the sidebars etc. |
|
366 | + * |
|
367 | + * @param array $classes The classes. |
|
368 | + * @return array $classes The classes. |
|
369 | + */ |
|
370 | + public function body_class( $classes ) { |
|
371 | + $classes[] = 'lsx-search-enabled'; |
|
372 | + return $classes; |
|
373 | + } |
|
374 | + |
|
375 | + /** |
|
376 | + * Moves the blog description to above the content columns. |
|
377 | + * |
|
378 | + * @param string $action |
|
379 | + * @return string $action |
|
380 | + */ |
|
381 | + public function top_of_blog_action( $action = '' ) { |
|
382 | + $action = 'lsx_content_wrap_before'; |
|
383 | + return $action; |
|
384 | + } |
|
385 | + |
|
386 | + /** |
|
387 | + * Adds a class to the blog description. |
|
388 | + * |
|
389 | + * @param string $action |
|
390 | + * @return string $action |
|
391 | + */ |
|
392 | + public function blog_description_class( $class = '' ) { |
|
393 | + $class .= ' col-md-12 search-description'; |
|
394 | + return $class; |
|
395 | + } |
|
396 | + |
|
397 | + /** |
|
398 | + * Check the $wp_query global to see if there are posts in the current query. |
|
399 | + * |
|
400 | + * @return void |
|
401 | + */ |
|
402 | + public function check_for_results() { |
|
403 | + if ( true === $this->search_enabled ) { |
|
404 | + global $wp_query; |
|
405 | + if ( empty( $wp_query->posts ) ) { |
|
406 | + $this->has_posts = false; |
|
407 | + remove_action( 'lsx_content_top', array( $this, 'facet_top_bar' ) ); |
|
408 | + remove_action( 'lsx_content_bottom', array( $this, 'facet_bottom_bar' ) ); |
|
409 | + remove_action( 'lsx_content_wrap_before', array( $this, 'search_sidebar' ), 150 ); |
|
410 | + } else { |
|
411 | + $this->has_posts = true; |
|
412 | + } |
|
413 | + } |
|
414 | + } |
|
415 | + |
|
416 | + /** |
|
417 | + * Filter the post types. |
|
418 | + */ |
|
419 | + public function filter_post_types( $query ) { |
|
420 | + if ( ! is_admin() && $query->is_main_query() && $query->is_search() ) { |
|
421 | + if ( ! empty( $this->options ) && ! empty( $this->options['display']['search_enable_core'] ) ) { |
|
422 | + if ( ! empty( $this->options['general']['search_post_types'] ) && is_array( $this->options['general']['search_post_types'] ) ) { |
|
423 | + $post_types = array_keys( $this->options['general']['search_post_types'] ); |
|
424 | + $query->set( 'post_type', $post_types ); |
|
425 | + } |
|
426 | + } |
|
427 | + } |
|
428 | + } |
|
429 | + |
|
430 | + /** |
|
431 | + * Sets post types with active search options. |
|
432 | + */ |
|
433 | + public function register_post_types( $post_types ) { |
|
434 | + $post_types = array( 'post', 'project', 'service', 'team', 'testimonial', 'video', 'product' ); |
|
435 | + return $post_types; |
|
436 | + } |
|
437 | + |
|
438 | + /** |
|
439 | + * Sets taxonomies with active search options. |
|
440 | + */ |
|
441 | + public function register_taxonomies( $taxonomies ) { |
|
442 | + $taxonomies = array( 'category', 'post_tag', 'project-group', 'service-group', 'team_role', 'video-category', 'product_cat', 'product_tag' ); |
|
443 | + return $taxonomies; |
|
444 | + } |
|
445 | + |
|
446 | + /** |
|
447 | + * Sets post types with active search options. |
|
448 | + */ |
|
449 | + public function register_post_type_tabs( $post_types_plural ) { |
|
450 | + $post_types_plural = array( |
|
451 | + 'post' => 'posts', |
|
452 | + 'project' => 'projects', |
|
453 | + 'service' => 'services', |
|
454 | + 'team' => 'team', |
|
455 | + 'testimonial' => 'testimonials', |
|
456 | + 'video' => 'videos', |
|
457 | + 'product' => 'products', // WooCommerce |
|
458 | + ); |
|
459 | + return $post_types_plural; |
|
460 | + } |
|
461 | + |
|
462 | + /** |
|
463 | + * Enqueue styles and scripts. |
|
464 | + */ |
|
465 | + public function assets() { |
|
466 | + add_filter( 'lsx_defer_parsing_of_js', array( $this, 'skip_js_defer' ), 10, 4 ); |
|
467 | + wp_enqueue_script( 'touchSwipe', LSX_SEARCH_URL . 'assets/js/vendor/jquery.touchSwipe.min.js', array( 'jquery' ), LSX_SEARCH_VER, true ); |
|
468 | + wp_enqueue_script( 'slideandswipe', LSX_SEARCH_URL . 'assets/js/vendor/jquery.slideandswipe.min.js', array( 'jquery', 'touchSwipe' ), LSX_SEARCH_VER, true ); |
|
469 | + wp_enqueue_script( 'lsx-search', LSX_SEARCH_URL . 'assets/js/src/lsx-search.js', array( 'jquery', 'touchSwipe', 'slideandswipe', 'jquery-ui-datepicker' ), LSX_SEARCH_VER, true ); |
|
470 | + |
|
471 | + $params = apply_filters( 'lsx_search_js_params', array( |
|
472 | + 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
473 | + )); |
|
474 | + |
|
475 | + wp_localize_script( 'lsx-search', 'lsx_customizer_params', $params ); |
|
476 | + |
|
477 | + wp_enqueue_style( 'lsx-search', LSX_SEARCH_URL . 'assets/css/lsx-search.css', array(), LSX_SEARCH_VER ); |
|
478 | + wp_style_add_data( 'lsx-search', 'rtl', 'replace' ); |
|
479 | + |
|
480 | + if ( true === $this->new_options ) { |
|
481 | + wp_deregister_style( 'lsx_to_search' ); |
|
482 | + wp_deregister_script( 'lsx_to_search' ); |
|
483 | + } |
|
484 | + } |
|
485 | + |
|
486 | + /** |
|
487 | + * Adds the to-search.min.js and the to-search.js |
|
488 | + * |
|
489 | + * @param boolean $should_skip |
|
490 | + * @param string $tag |
|
491 | + * @param string $handle |
|
492 | + * @param string $href |
|
493 | + * @return boolean |
|
494 | + */ |
|
495 | + public function skip_js_defer( $should_skip, $tag, $handle, $href ) { |
|
496 | + if ( ! is_admin() && ( false !== stripos( $href, 'lsx-search.min.js' ) || false !== stripos( $href, 'lsx-search.js' ) ) ) { |
|
497 | + $should_skip = true; |
|
498 | + } |
|
499 | + return $should_skip; |
|
500 | + } |
|
501 | + |
|
502 | + /** |
|
503 | + * Redirect wordpress to the search template located in the plugin |
|
504 | + * |
|
505 | + * @param $template |
|
506 | + * @return $template |
|
507 | + */ |
|
508 | + public function search_template_include( $template ) { |
|
509 | + if ( is_main_query() && is_search() ) { |
|
510 | + if ( file_exists( LSX_SEARCH_PATH . 'templates/search.php' ) ) { |
|
511 | + $template = LSX_SEARCH_PATH . 'templates/search.php'; |
|
512 | + } |
|
513 | + } |
|
514 | + |
|
515 | + return $template; |
|
516 | + } |
|
517 | + |
|
518 | + /** |
|
519 | + * Rewrite the search URL |
|
520 | + */ |
|
521 | + public function pretty_search_redirect() { |
|
522 | + global $wp_rewrite,$wp_query; |
|
523 | + |
|
524 | + if ( ! isset( $wp_rewrite ) || ! is_object( $wp_rewrite ) || ! $wp_rewrite->using_permalinks() ) { |
|
525 | + return; |
|
526 | + } |
|
527 | + |
|
528 | + $search_base = $wp_rewrite->search_base; |
|
529 | + |
|
530 | + if ( is_search() && ! is_admin() && strpos( $_SERVER['REQUEST_URI'], "/{$search_base}/" ) === false ) { |
|
531 | + $search_query = get_query_var( 's' ); |
|
532 | + $engine = ''; |
|
533 | + |
|
534 | + // If the search was triggered by a supplemental engine. |
|
535 | + if ( isset( $_GET['engine'] ) && 'default' !== $_GET['engine'] ) { |
|
536 | + $engine = $_GET['engine']; |
|
537 | + set_query_var( 'engine', $engine ); |
|
538 | + $engine = array_search( $engine, $this->post_type_slugs, true ) . '/'; |
|
539 | + } |
|
540 | + |
|
541 | + $get_array = $_GET; |
|
542 | + |
|
543 | + if ( is_array( $get_array ) && ! empty( $get_array ) ) { |
|
544 | + $vars_to_maintain = array(); |
|
545 | + |
|
546 | + foreach ( $get_array as $ga_key => $ga_value ) { |
|
547 | + if ( false !== strpos( $ga_key, 'fwp_' ) ) { |
|
548 | + $vars_to_maintain[] = $ga_key . '=' . $ga_value; |
|
549 | + } |
|
550 | + } |
|
551 | + } |
|
552 | + |
|
553 | + $redirect_url = home_url( "/{$search_base}/" . $engine . urlencode( $search_query ) ); |
|
554 | + |
|
555 | + if ( ! empty( $vars_to_maintain ) ) { |
|
556 | + $redirect_url .= '?' . implode( '&', $vars_to_maintain ); |
|
557 | + } |
|
558 | + |
|
559 | + wp_redirect( $redirect_url ); |
|
560 | + exit(); |
|
561 | + } |
|
562 | + } |
|
563 | + |
|
564 | + /** |
|
565 | + * Parse the Query and trigger a search |
|
566 | + */ |
|
567 | + public function pretty_search_parse_query( $query ) { |
|
568 | + $this->post_type_slugs = array( |
|
569 | + 'post' => 'posts', |
|
570 | + 'project' => 'projects', |
|
571 | + 'service' => 'services', |
|
572 | + 'team' => 'team', |
|
573 | + 'testimonial' => 'testimonials', |
|
574 | + 'video' => 'videos', |
|
575 | + 'product' => 'products', // WooCommerce |
|
576 | + ); |
|
577 | + if ( $query->is_search() && ! is_admin() && $query->is_main_query() ) { |
|
578 | + $search_query = $query->get( 's' ); |
|
579 | + $keyword_test = explode( '/', $search_query ); |
|
580 | + |
|
581 | + $index = array_search( $keyword_test[0], $this->post_type_slugs, true ); |
|
582 | + if ( false !== $index ) { |
|
583 | + $engine = $this->post_type_slugs[ $index ]; |
|
584 | + |
|
585 | + $query->set( 'post_type', $engine ); |
|
586 | + $query->set( 'engine', $engine ); |
|
587 | + |
|
588 | + if ( count( $keyword_test ) > 1 ) { |
|
589 | + $query->set( 's', $keyword_test[1] ); |
|
590 | + } elseif ( post_type_exists( $engine ) ) { |
|
591 | + $query->set( 's', '' ); |
|
592 | + } |
|
593 | + } else { |
|
594 | + if ( isset( $this->options['general']['search_post_types'] ) && is_array( $this->options['general']['search_post_types'] ) ) { |
|
595 | + $post_types = array_keys( $this->options['general']['search_post_types'] ); |
|
596 | + $query->set( 'post_type', $post_types ); |
|
597 | + } |
|
598 | + } |
|
599 | + } |
|
600 | + |
|
601 | + return $query; |
|
602 | + } |
|
603 | + |
|
604 | + /** |
|
605 | + * Change the search slug to /search/ for the JSON+LD output in Yoast SEO |
|
606 | + * |
|
607 | + * @return url |
|
608 | + */ |
|
609 | + public function change_json_ld_search_url() { |
|
610 | + return trailingslashit( home_url() ) . 'search/{search_term_string}'; |
|
611 | + } |
|
612 | + |
|
613 | + /** |
|
614 | + * A filter to set the layout to 2 column. |
|
615 | + */ |
|
616 | + public function lsx_layout( $layout ) { |
|
617 | + if ( ! empty( $this->options['display'][ $this->search_prefix . '_layout' ] ) ) { |
|
618 | + if ( false === $this->has_posts ) { |
|
619 | + $layout = '1c'; |
|
620 | + } else { |
|
621 | + $layout = $this->options['display'][ $this->search_prefix . '_layout' ]; |
|
622 | + } |
|
623 | + } |
|
624 | + return $layout; |
|
625 | + } |
|
626 | + |
|
627 | + /** |
|
628 | + * Outputs the Search Title Facet |
|
629 | + */ |
|
630 | + public function search_sidebar_top() { |
|
631 | + if ( ! empty( $this->options['display'][ $this->search_prefix . '_facets' ] ) && is_array( $this->options['display'][ $this->search_prefix . '_facets' ] ) && true !== apply_filters( 'lsx_search_hide_search_box', false ) ) { |
|
632 | + |
|
633 | + if ( ! is_search() ) { |
|
634 | + |
|
635 | + foreach ( $this->options['display'][ $this->search_prefix . '_facets' ] as $facet => $facet_useless ) { |
|
636 | + |
|
637 | + if ( isset( $this->facet_data[ $facet ] ) && 'search' === $this->facet_data[ $facet ]['type'] ) { |
|
638 | + echo wp_kses_post( '<div class="row">' ); |
|
639 | + $this->display_facet_default( $facet ); |
|
640 | + echo wp_kses_post( '</div>' ); |
|
641 | + unset( $this->options['display'][ $this->search_prefix . '_facets' ][ $facet ] ); |
|
642 | + } |
|
643 | + } |
|
644 | + } else { |
|
645 | + echo wp_kses_post( '<div class="row">' ); |
|
646 | + $this->display_facet_search(); |
|
647 | + echo wp_kses_post( '</div>' ); |
|
648 | + } |
|
649 | + } |
|
650 | + } |
|
651 | + |
|
652 | + /** |
|
653 | + * Overrides the search facet HTML |
|
654 | + * @param $output |
|
655 | + * @param $params |
|
656 | + * |
|
657 | + * @return string |
|
658 | + */ |
|
659 | + public function search_facet_html( $output, $params ) { |
|
660 | + if ( 'search' == $params['facet']['type'] ) { |
|
661 | + |
|
662 | + $value = (array) $params['selected_values']; |
|
663 | + $value = empty( $value ) ? '' : stripslashes( $value[0] ); |
|
664 | + $placeholder = isset( $params['facet']['placeholder'] ) ? $params['facet']['placeholder'] : __( 'Search...', 'lsx-search' ); |
|
665 | + $placeholder = facetwp_i18n( $placeholder ); |
|
666 | + |
|
667 | + ob_start(); |
|
668 | + ?> |
|
669 | 669 | <div class="col-xs-12 facetwp-item facetwp-form"> |
670 | 670 | <div class="search-form lsx-search-form 2"> |
671 | 671 | <div class="input-group facetwp-search-wrap"> |
@@ -680,74 +680,74 @@ discard block |
||
680 | 680 | </div> |
681 | 681 | </div> |
682 | 682 | <?php |
683 | - $output = ob_get_clean(); |
|
684 | - } |
|
685 | - return $output; |
|
686 | - } |
|
687 | - |
|
688 | - /** |
|
689 | - * Change the primary and secondary column classes. |
|
690 | - */ |
|
691 | - public function lsx_layout_selector( $return_class, $class, $layout, $size ) { |
|
692 | - if ( ! empty( $this->options['display'][ $this->search_prefix . '_layout' ] ) ) { |
|
693 | - |
|
694 | - if ( '2cl' === $layout || '2cr' === $layout ) { |
|
695 | - $main_class = 'col-sm-8 col-md-9'; |
|
696 | - $sidebar_class = 'col-sm-4 col-md-3'; |
|
697 | - |
|
698 | - if ( '2cl' === $layout ) { |
|
699 | - $main_class .= ' col-sm-pull-4 col-md-pull-3'; |
|
700 | - $sidebar_class .= ' col-sm-push-8 col-md-push-9'; |
|
701 | - } |
|
702 | - |
|
703 | - if ( 'main' === $class ) { |
|
704 | - return $main_class; |
|
705 | - } |
|
706 | - |
|
707 | - if ( 'sidebar' === $class ) { |
|
708 | - return $sidebar_class; |
|
709 | - } |
|
710 | - } |
|
711 | - } |
|
712 | - |
|
713 | - return $return_class; |
|
714 | - } |
|
715 | - |
|
716 | - /** |
|
717 | - * Displays the Alphabet sorter above the facets. |
|
718 | - * |
|
719 | - * @return void |
|
720 | - */ |
|
721 | - public function display_alphabet_facet() { |
|
722 | - if ( isset( $this->options['display'][ $this->search_prefix . '_az_pagination' ] ) ) { |
|
723 | - $az_pagination = $this->options['display'][ $this->search_prefix . '_az_pagination' ]; |
|
724 | - } else { |
|
725 | - $az_pagination = false; |
|
726 | - } |
|
727 | - $az_pagination = apply_filters( 'lsx_search_top_az_pagination', $az_pagination ); |
|
728 | - if ( false !== $az_pagination && '' !== $az_pagination ) { |
|
729 | - echo do_shortcode( '[facetwp facet="' . $az_pagination . '"]' ); |
|
730 | - } |
|
731 | - } |
|
732 | - |
|
733 | - /** |
|
734 | - * Outputs top. |
|
735 | - */ |
|
736 | - public function facet_top_bar() { |
|
737 | - if ( true === apply_filters( 'lsx_search_hide_top_bar', false ) ) { |
|
738 | - return; |
|
739 | - } |
|
740 | - $show_pagination = true; |
|
741 | - $pagination_visible = false; |
|
742 | - $show_per_page_combo = empty( $this->options['display'][ $this->search_prefix . '_disable_per_page' ] ); |
|
743 | - $show_sort_combo = empty( $this->options['display'][ $this->search_prefix . '_disable_all_sorting' ] ); |
|
744 | - |
|
745 | - $show_pagination = apply_filters( 'lsx_search_top_show_pagination', $show_pagination ); |
|
746 | - $pagination_visible = apply_filters( 'lsx_search_top_pagination_visible', $pagination_visible ); |
|
747 | - $show_per_page_combo = apply_filters( 'lsx_search_top_show_per_page_combo', $show_per_page_combo ); |
|
748 | - $show_sort_combo = apply_filters( 'lsx_search_top_show_sort_combo', $show_sort_combo ); |
|
749 | - $facet_row_classes = apply_filters( 'lsx_search_top_facetwp_row_classes', '' ); |
|
750 | - ?> |
|
683 | + $output = ob_get_clean(); |
|
684 | + } |
|
685 | + return $output; |
|
686 | + } |
|
687 | + |
|
688 | + /** |
|
689 | + * Change the primary and secondary column classes. |
|
690 | + */ |
|
691 | + public function lsx_layout_selector( $return_class, $class, $layout, $size ) { |
|
692 | + if ( ! empty( $this->options['display'][ $this->search_prefix . '_layout' ] ) ) { |
|
693 | + |
|
694 | + if ( '2cl' === $layout || '2cr' === $layout ) { |
|
695 | + $main_class = 'col-sm-8 col-md-9'; |
|
696 | + $sidebar_class = 'col-sm-4 col-md-3'; |
|
697 | + |
|
698 | + if ( '2cl' === $layout ) { |
|
699 | + $main_class .= ' col-sm-pull-4 col-md-pull-3'; |
|
700 | + $sidebar_class .= ' col-sm-push-8 col-md-push-9'; |
|
701 | + } |
|
702 | + |
|
703 | + if ( 'main' === $class ) { |
|
704 | + return $main_class; |
|
705 | + } |
|
706 | + |
|
707 | + if ( 'sidebar' === $class ) { |
|
708 | + return $sidebar_class; |
|
709 | + } |
|
710 | + } |
|
711 | + } |
|
712 | + |
|
713 | + return $return_class; |
|
714 | + } |
|
715 | + |
|
716 | + /** |
|
717 | + * Displays the Alphabet sorter above the facets. |
|
718 | + * |
|
719 | + * @return void |
|
720 | + */ |
|
721 | + public function display_alphabet_facet() { |
|
722 | + if ( isset( $this->options['display'][ $this->search_prefix . '_az_pagination' ] ) ) { |
|
723 | + $az_pagination = $this->options['display'][ $this->search_prefix . '_az_pagination' ]; |
|
724 | + } else { |
|
725 | + $az_pagination = false; |
|
726 | + } |
|
727 | + $az_pagination = apply_filters( 'lsx_search_top_az_pagination', $az_pagination ); |
|
728 | + if ( false !== $az_pagination && '' !== $az_pagination ) { |
|
729 | + echo do_shortcode( '[facetwp facet="' . $az_pagination . '"]' ); |
|
730 | + } |
|
731 | + } |
|
732 | + |
|
733 | + /** |
|
734 | + * Outputs top. |
|
735 | + */ |
|
736 | + public function facet_top_bar() { |
|
737 | + if ( true === apply_filters( 'lsx_search_hide_top_bar', false ) ) { |
|
738 | + return; |
|
739 | + } |
|
740 | + $show_pagination = true; |
|
741 | + $pagination_visible = false; |
|
742 | + $show_per_page_combo = empty( $this->options['display'][ $this->search_prefix . '_disable_per_page' ] ); |
|
743 | + $show_sort_combo = empty( $this->options['display'][ $this->search_prefix . '_disable_all_sorting' ] ); |
|
744 | + |
|
745 | + $show_pagination = apply_filters( 'lsx_search_top_show_pagination', $show_pagination ); |
|
746 | + $pagination_visible = apply_filters( 'lsx_search_top_pagination_visible', $pagination_visible ); |
|
747 | + $show_per_page_combo = apply_filters( 'lsx_search_top_show_per_page_combo', $show_per_page_combo ); |
|
748 | + $show_sort_combo = apply_filters( 'lsx_search_top_show_sort_combo', $show_sort_combo ); |
|
749 | + $facet_row_classes = apply_filters( 'lsx_search_top_facetwp_row_classes', '' ); |
|
750 | + ?> |
|
751 | 751 | <div id="facetwp-top"> |
752 | 752 | <?php if ( $show_sort_combo || ( $show_pagination && $show_per_page_combo ) ) { ?> |
753 | 753 | <div class="row facetwp-top-row-1 hidden-xs <?php echo esc_attr( $facet_row_classes ); ?>"> |
@@ -778,32 +778,32 @@ discard block |
||
778 | 778 | <?php } ?> |
779 | 779 | </div> |
780 | 780 | <?php |
781 | - } |
|
782 | - |
|
783 | - /** |
|
784 | - * Outputs bottom. |
|
785 | - */ |
|
786 | - public function facet_bottom_bar() { |
|
787 | - if ( true === apply_filters( 'lsx_search_hide_bottom_bar', false ) ) { |
|
788 | - return; |
|
789 | - } |
|
790 | - $show_pagination = true; |
|
791 | - $pagination_visible = false; |
|
792 | - if ( isset( $this->options['display'][ $this->search_prefix . '_az_pagination' ] ) ) { |
|
793 | - $az_pagination = $this->options['display'][ $this->search_prefix . '_az_pagination' ]; |
|
794 | - } else { |
|
795 | - $az_pagination = false; |
|
796 | - } |
|
797 | - |
|
798 | - $show_per_page_combo = empty( $this->options['display'][ $this->search_prefix . '_disable_per_page' ] ); |
|
799 | - $show_sort_combo = empty( $this->options['display'][ $this->search_prefix . '_disable_all_sorting' ] ); |
|
800 | - |
|
801 | - $show_pagination = apply_filters( 'lsx_search_bottom_show_pagination', $show_pagination ); |
|
802 | - $pagination_visible = apply_filters( 'lsx_search_bottom_pagination_visible', $pagination_visible ); |
|
803 | - $show_per_page_combo = apply_filters( 'lsx_search_bottom_show_per_page_combo', $show_per_page_combo ); |
|
804 | - $show_sort_combo = apply_filters( 'lsx_search_bottom_show_sort_combo', $show_sort_combo ); |
|
805 | - |
|
806 | - if ( $show_pagination || ! empty( $az_pagination ) ) { ?> |
|
781 | + } |
|
782 | + |
|
783 | + /** |
|
784 | + * Outputs bottom. |
|
785 | + */ |
|
786 | + public function facet_bottom_bar() { |
|
787 | + if ( true === apply_filters( 'lsx_search_hide_bottom_bar', false ) ) { |
|
788 | + return; |
|
789 | + } |
|
790 | + $show_pagination = true; |
|
791 | + $pagination_visible = false; |
|
792 | + if ( isset( $this->options['display'][ $this->search_prefix . '_az_pagination' ] ) ) { |
|
793 | + $az_pagination = $this->options['display'][ $this->search_prefix . '_az_pagination' ]; |
|
794 | + } else { |
|
795 | + $az_pagination = false; |
|
796 | + } |
|
797 | + |
|
798 | + $show_per_page_combo = empty( $this->options['display'][ $this->search_prefix . '_disable_per_page' ] ); |
|
799 | + $show_sort_combo = empty( $this->options['display'][ $this->search_prefix . '_disable_all_sorting' ] ); |
|
800 | + |
|
801 | + $show_pagination = apply_filters( 'lsx_search_bottom_show_pagination', $show_pagination ); |
|
802 | + $pagination_visible = apply_filters( 'lsx_search_bottom_pagination_visible', $pagination_visible ); |
|
803 | + $show_per_page_combo = apply_filters( 'lsx_search_bottom_show_per_page_combo', $show_per_page_combo ); |
|
804 | + $show_sort_combo = apply_filters( 'lsx_search_bottom_show_sort_combo', $show_sort_combo ); |
|
805 | + |
|
806 | + if ( $show_pagination || ! empty( $az_pagination ) ) { ?> |
|
807 | 807 | <div id="facetwp-bottom"> |
808 | 808 | <div class="row facetwp-bottom-row-1"> |
809 | 809 | <div class="col-xs-12"> |
@@ -818,61 +818,61 @@ discard block |
||
818 | 818 | <?php //} ?> |
819 | 819 | |
820 | 820 | <?php |
821 | - if ( $show_pagination ) { |
|
822 | - $output_pagination = do_shortcode( '[facetwp pager="true"]' ); |
|
823 | - if ( ! empty( $this->options['display'][ $this->search_prefix . '_facets' ] ) && is_array( $this->options['display'][ $this->search_prefix . '_facets' ] ) ) { |
|
824 | - foreach ( $this->options['display'][ $this->search_prefix . '_facets' ] as $facet => $facet_useless ) { |
|
825 | - if ( isset( $this->facet_data[ $facet ] ) && in_array( $this->facet_data[ $facet ]['type'], array( 'pager' ) ) ) { |
|
826 | - $output_pagination = do_shortcode( '[facetwp facet="pager_"]' ); |
|
827 | - } |
|
828 | - } |
|
829 | - } |
|
830 | - echo wp_kses_post( $output_pagination ); |
|
831 | - ?> |
|
821 | + if ( $show_pagination ) { |
|
822 | + $output_pagination = do_shortcode( '[facetwp pager="true"]' ); |
|
823 | + if ( ! empty( $this->options['display'][ $this->search_prefix . '_facets' ] ) && is_array( $this->options['display'][ $this->search_prefix . '_facets' ] ) ) { |
|
824 | + foreach ( $this->options['display'][ $this->search_prefix . '_facets' ] as $facet => $facet_useless ) { |
|
825 | + if ( isset( $this->facet_data[ $facet ] ) && in_array( $this->facet_data[ $facet ]['type'], array( 'pager' ) ) ) { |
|
826 | + $output_pagination = do_shortcode( '[facetwp facet="pager_"]' ); |
|
827 | + } |
|
828 | + } |
|
829 | + } |
|
830 | + echo wp_kses_post( $output_pagination ); |
|
831 | + ?> |
|
832 | 832 | <?php } ?> |
833 | 833 | </div> |
834 | 834 | </div> |
835 | 835 | </div> |
836 | 836 | <?php } |
837 | - } |
|
838 | - |
|
839 | - /** |
|
840 | - * Adds in the closing facetwp div |
|
841 | - * |
|
842 | - * @return void |
|
843 | - */ |
|
844 | - public function facetwp_tempate_open() { |
|
845 | - ?> |
|
837 | + } |
|
838 | + |
|
839 | + /** |
|
840 | + * Adds in the closing facetwp div |
|
841 | + * |
|
842 | + * @return void |
|
843 | + */ |
|
844 | + public function facetwp_tempate_open() { |
|
845 | + ?> |
|
846 | 846 | <div class="facetwp-template"> |
847 | 847 | <?php |
848 | - } |
|
849 | - |
|
850 | - /** |
|
851 | - * Adds in the closing facetwp div |
|
852 | - * |
|
853 | - * @return void |
|
854 | - */ |
|
855 | - public function facetwp_tempate_close() { |
|
856 | - ?> |
|
848 | + } |
|
849 | + |
|
850 | + /** |
|
851 | + * Adds in the closing facetwp div |
|
852 | + * |
|
853 | + * @return void |
|
854 | + */ |
|
855 | + public function facetwp_tempate_close() { |
|
856 | + ?> |
|
857 | 857 | </div> |
858 | 858 | <?php |
859 | - } |
|
860 | - |
|
861 | - /** |
|
862 | - * Disables default sidebar. |
|
863 | - */ |
|
864 | - public function lsx_sidebar_enable( $sidebar_enabled ) { |
|
865 | - $sidebar_enabled = false; |
|
866 | - return $sidebar_enabled; |
|
867 | - } |
|
868 | - |
|
869 | - /** |
|
870 | - * Outputs custom sidebar. |
|
871 | - */ |
|
872 | - public function search_sidebar() { |
|
873 | - |
|
874 | - $this->options = apply_filters( 'lsx_search_sidebar_options', $this->options ); |
|
875 | - ?> |
|
859 | + } |
|
860 | + |
|
861 | + /** |
|
862 | + * Disables default sidebar. |
|
863 | + */ |
|
864 | + public function lsx_sidebar_enable( $sidebar_enabled ) { |
|
865 | + $sidebar_enabled = false; |
|
866 | + return $sidebar_enabled; |
|
867 | + } |
|
868 | + |
|
869 | + /** |
|
870 | + * Outputs custom sidebar. |
|
871 | + */ |
|
872 | + public function search_sidebar() { |
|
873 | + |
|
874 | + $this->options = apply_filters( 'lsx_search_sidebar_options', $this->options ); |
|
875 | + ?> |
|
876 | 876 | <?php do_action( 'lsx_search_sidebar_before' ); ?> |
877 | 877 | |
878 | 878 | <div id="secondary" class="facetwp-sidebar widget-area <?php echo esc_attr( lsx_sidebar_class() ); ?>" role="complementary"> |
@@ -897,13 +897,13 @@ discard block |
||
897 | 897 | |
898 | 898 | <div class="row"> |
899 | 899 | <?php |
900 | - // Slider. |
|
901 | - foreach ( $this->options['display'][ $this->search_prefix . '_facets' ] as $facet => $facet_useless ) { |
|
902 | - if ( isset( $this->facet_data[ $facet ] ) && ! in_array( $this->facet_data[ $facet ]['type'], array( 'alpha', 'search', 'pager' ) ) ) { |
|
903 | - $this->display_facet_default( $facet ); |
|
904 | - } |
|
905 | - } |
|
906 | - ?> |
|
900 | + // Slider. |
|
901 | + foreach ( $this->options['display'][ $this->search_prefix . '_facets' ] as $facet => $facet_useless ) { |
|
902 | + if ( isset( $this->facet_data[ $facet ] ) && ! in_array( $this->facet_data[ $facet ]['type'], array( 'alpha', 'search', 'pager' ) ) ) { |
|
903 | + $this->display_facet_default( $facet ); |
|
904 | + } |
|
905 | + } |
|
906 | + ?> |
|
907 | 907 | </div> |
908 | 908 | |
909 | 909 | <div class="row hidden-sm hidden-md hidden-lg ssm-row-margin-top"> |
@@ -920,35 +920,35 @@ discard block |
||
920 | 920 | |
921 | 921 | <?php do_action( 'lsx_search_sidebar_after' ); ?> |
922 | 922 | <?php |
923 | - } |
|
924 | - |
|
925 | - /** |
|
926 | - * Check if the pager facet is on |
|
927 | - * |
|
928 | - * @return void |
|
929 | - */ |
|
930 | - public function pager_facet_enabled() { |
|
931 | - |
|
932 | - $pager_facet_off = false; |
|
933 | - |
|
934 | - if ( ! empty( $this->options['display'][ $this->search_prefix . '_facets' ] ) && is_array( $this->options['display'][ $this->search_prefix . '_facets' ] ) ) { |
|
935 | - foreach ( $this->options['display'][ $this->search_prefix . '_facets' ] as $facet => $facet_useless ) { |
|
936 | - if ( isset( $this->facet_data[ $facet ] ) && ! in_array( $this->facet_data[ $facet ]['type'], array( 'pager' ) ) ) { |
|
937 | - $pager_facet_off = true; |
|
938 | - } |
|
939 | - } |
|
940 | - } |
|
941 | - |
|
942 | - return $pager_facet_off; |
|
943 | - } |
|
944 | - |
|
945 | - /** |
|
946 | - * Display WooCommerce archive title. |
|
947 | - */ |
|
948 | - public function wc_archive_header() { |
|
949 | - $default_size = 'sm'; |
|
950 | - $size = apply_filters( 'lsx_bootstrap_column_size', $default_size ); |
|
951 | - ?> |
|
923 | + } |
|
924 | + |
|
925 | + /** |
|
926 | + * Check if the pager facet is on |
|
927 | + * |
|
928 | + * @return void |
|
929 | + */ |
|
930 | + public function pager_facet_enabled() { |
|
931 | + |
|
932 | + $pager_facet_off = false; |
|
933 | + |
|
934 | + if ( ! empty( $this->options['display'][ $this->search_prefix . '_facets' ] ) && is_array( $this->options['display'][ $this->search_prefix . '_facets' ] ) ) { |
|
935 | + foreach ( $this->options['display'][ $this->search_prefix . '_facets' ] as $facet => $facet_useless ) { |
|
936 | + if ( isset( $this->facet_data[ $facet ] ) && ! in_array( $this->facet_data[ $facet ]['type'], array( 'pager' ) ) ) { |
|
937 | + $pager_facet_off = true; |
|
938 | + } |
|
939 | + } |
|
940 | + } |
|
941 | + |
|
942 | + return $pager_facet_off; |
|
943 | + } |
|
944 | + |
|
945 | + /** |
|
946 | + * Display WooCommerce archive title. |
|
947 | + */ |
|
948 | + public function wc_archive_header() { |
|
949 | + $default_size = 'sm'; |
|
950 | + $size = apply_filters( 'lsx_bootstrap_column_size', $default_size ); |
|
951 | + ?> |
|
952 | 952 | <div class="archive-header-wrapper banner-woocommerce col-<?php echo esc_attr( $size ); ?>-12"> |
953 | 953 | <?php lsx_global_header_inner_bottom(); ?> |
954 | 954 | <header class="archive-header"> |
@@ -956,13 +956,13 @@ discard block |
||
956 | 956 | </header> |
957 | 957 | </div> |
958 | 958 | <?php |
959 | - } |
|
959 | + } |
|
960 | 960 | |
961 | - /** |
|
962 | - * Display facet search. |
|
963 | - */ |
|
964 | - public function display_facet_search() { |
|
965 | - ?> |
|
961 | + /** |
|
962 | + * Display facet search. |
|
963 | + */ |
|
964 | + public function display_facet_search() { |
|
965 | + ?> |
|
966 | 966 | <div class="col-xs-12 facetwp-item facetwp-form"> |
967 | 967 | <form class="search-form lsx-search-form" action="/" method="get"> |
968 | 968 | <div class="input-group"> |
@@ -977,17 +977,17 @@ discard block |
||
977 | 977 | </form> |
978 | 978 | </div> |
979 | 979 | <?php |
980 | - } |
|
980 | + } |
|
981 | 981 | |
982 | - /** |
|
983 | - * Display facet default. |
|
984 | - */ |
|
985 | - public function display_facet_default( $facet ) { |
|
982 | + /** |
|
983 | + * Display facet default. |
|
984 | + */ |
|
985 | + public function display_facet_default( $facet ) { |
|
986 | 986 | |
987 | - $show_collapse = ! isset( $this->options['display']['enable_collapse'] ) || 'on' !== $this->options['display']['enable_collapse']; |
|
988 | - $col_class = ''; |
|
987 | + $show_collapse = ! isset( $this->options['display']['enable_collapse'] ) || 'on' !== $this->options['display']['enable_collapse']; |
|
988 | + $col_class = ''; |
|
989 | 989 | |
990 | - if ( 'search' === $this->facet_data[ $facet ]['type'] ) : ?> |
|
990 | + if ( 'search' === $this->facet_data[ $facet ]['type'] ) : ?> |
|
991 | 991 | <?php echo do_shortcode( '[facetwp facet="' . $facet . '"]' ); ?> |
992 | 992 | <?php else : ?> |
993 | 993 | <div class="col-xs-12 facetwp-item parent-facetwp-facet-<?php echo esc_html( $facet ); ?> <?php echo esc_attr( $col_class ); ?>"> |
@@ -1005,72 +1005,72 @@ discard block |
||
1005 | 1005 | <?php } ?> |
1006 | 1006 | </div> |
1007 | 1007 | <?php |
1008 | - endif; |
|
1009 | - } |
|
1010 | - |
|
1011 | - /** |
|
1012 | - * Changes slot column class. |
|
1013 | - */ |
|
1014 | - public function change_slot_column_class( $class ) { |
|
1015 | - if ( is_post_type_archive( 'video' ) || is_tax( 'video-category' ) ) { |
|
1016 | - $column_class = 'col-xs-12 col-sm-4'; |
|
1017 | - } |
|
1018 | - |
|
1019 | - return $column_class; |
|
1020 | - } |
|
1021 | - |
|
1022 | - /** |
|
1023 | - * Add post type label to the title. |
|
1024 | - */ |
|
1025 | - public function add_label_to_title() { |
|
1026 | - if ( is_search() ) { |
|
1027 | - if ( ! empty( $this->options['display']['engine_search_enable_pt_label'] ) ) { |
|
1028 | - $post_type = get_post_type(); |
|
1029 | - $post_type = str_replace( '_', ' ', $post_type ); |
|
1030 | - $post_type = str_replace( '-', ' ', $post_type ); |
|
1031 | - if ( 'tribe events' === $post_type ) { |
|
1032 | - $post_type = 'Events'; |
|
1033 | - } |
|
1034 | - echo wp_kses_post( ' <span class="label label-default lsx-label-post-type">' . $post_type . '</span>' ); |
|
1035 | - } |
|
1036 | - } |
|
1037 | - } |
|
1038 | - |
|
1039 | - /** |
|
1040 | - * Changes the sort options. |
|
1041 | - */ |
|
1042 | - public function facetwp_sort_options( $options, $params ) { |
|
1043 | - $this->set_vars(); |
|
1044 | - |
|
1045 | - if ( true === $this->search_enabled ) { |
|
1046 | - if ( 'default' !== $params['template_name'] && 'wp' !== $params['template_name'] ) { |
|
1047 | - return $options; |
|
1048 | - } |
|
1049 | - |
|
1050 | - if ( ! empty( $this->options['display'][ $this->search_prefix . '_disable_date_sorting' ] ) ) { |
|
1051 | - unset( $options['date_desc'] ); |
|
1052 | - unset( $options['date_asc'] ); |
|
1053 | - } |
|
1054 | - |
|
1055 | - if ( ! empty( $this->options['display'][ $this->search_prefix . '_disable_az_sorting' ] ) ) { |
|
1056 | - unset( $options['title_desc'] ); |
|
1057 | - unset( $options['title_asc'] ); |
|
1058 | - } |
|
1059 | - } |
|
1060 | - |
|
1061 | - return $options; |
|
1062 | - } |
|
1063 | - |
|
1064 | - /** |
|
1065 | - * @param $allowedtags |
|
1066 | - * @param $context |
|
1067 | - * |
|
1068 | - * @return mixed |
|
1069 | - */ |
|
1070 | - public function kses_allowed_html( $allowedtags, $context ) { |
|
1071 | - $allowedtags['a']['data-value'] = true; |
|
1072 | - $allowedtags['a']['data-selection'] = true; |
|
1073 | - $allowedtags['button']['data-toggle'] = true; |
|
1074 | - return $allowedtags; |
|
1075 | - } |
|
1008 | + endif; |
|
1009 | + } |
|
1010 | + |
|
1011 | + /** |
|
1012 | + * Changes slot column class. |
|
1013 | + */ |
|
1014 | + public function change_slot_column_class( $class ) { |
|
1015 | + if ( is_post_type_archive( 'video' ) || is_tax( 'video-category' ) ) { |
|
1016 | + $column_class = 'col-xs-12 col-sm-4'; |
|
1017 | + } |
|
1018 | + |
|
1019 | + return $column_class; |
|
1020 | + } |
|
1021 | + |
|
1022 | + /** |
|
1023 | + * Add post type label to the title. |
|
1024 | + */ |
|
1025 | + public function add_label_to_title() { |
|
1026 | + if ( is_search() ) { |
|
1027 | + if ( ! empty( $this->options['display']['engine_search_enable_pt_label'] ) ) { |
|
1028 | + $post_type = get_post_type(); |
|
1029 | + $post_type = str_replace( '_', ' ', $post_type ); |
|
1030 | + $post_type = str_replace( '-', ' ', $post_type ); |
|
1031 | + if ( 'tribe events' === $post_type ) { |
|
1032 | + $post_type = 'Events'; |
|
1033 | + } |
|
1034 | + echo wp_kses_post( ' <span class="label label-default lsx-label-post-type">' . $post_type . '</span>' ); |
|
1035 | + } |
|
1036 | + } |
|
1037 | + } |
|
1038 | + |
|
1039 | + /** |
|
1040 | + * Changes the sort options. |
|
1041 | + */ |
|
1042 | + public function facetwp_sort_options( $options, $params ) { |
|
1043 | + $this->set_vars(); |
|
1044 | + |
|
1045 | + if ( true === $this->search_enabled ) { |
|
1046 | + if ( 'default' !== $params['template_name'] && 'wp' !== $params['template_name'] ) { |
|
1047 | + return $options; |
|
1048 | + } |
|
1049 | + |
|
1050 | + if ( ! empty( $this->options['display'][ $this->search_prefix . '_disable_date_sorting' ] ) ) { |
|
1051 | + unset( $options['date_desc'] ); |
|
1052 | + unset( $options['date_asc'] ); |
|
1053 | + } |
|
1054 | + |
|
1055 | + if ( ! empty( $this->options['display'][ $this->search_prefix . '_disable_az_sorting' ] ) ) { |
|
1056 | + unset( $options['title_desc'] ); |
|
1057 | + unset( $options['title_asc'] ); |
|
1058 | + } |
|
1059 | + } |
|
1060 | + |
|
1061 | + return $options; |
|
1062 | + } |
|
1063 | + |
|
1064 | + /** |
|
1065 | + * @param $allowedtags |
|
1066 | + * @param $context |
|
1067 | + * |
|
1068 | + * @return mixed |
|
1069 | + */ |
|
1070 | + public function kses_allowed_html( $allowedtags, $context ) { |
|
1071 | + $allowedtags['a']['data-value'] = true; |
|
1072 | + $allowedtags['a']['data-selection'] = true; |
|
1073 | + $allowedtags['button']['data-toggle'] = true; |
|
1074 | + return $allowedtags; |
|
1075 | + } |
|
1076 | 1076 | } |
@@ -6,142 +6,142 @@ |
||
6 | 6 | */ |
7 | 7 | class LSX_Search_FacetWP { |
8 | 8 | |
9 | - /** |
|
10 | - * @var object \lsx\search\classes\facetwp\Hierarchy() |
|
11 | - */ |
|
12 | - public $hierarchy; |
|
13 | - |
|
14 | - /** |
|
15 | - * @var object \lsx\search\classes\facetwp\Post_Connections() |
|
16 | - */ |
|
17 | - public $post_connections; |
|
18 | - |
|
19 | - /** |
|
20 | - * Class Constructor. |
|
21 | - */ |
|
22 | - public function __construct() { |
|
23 | - |
|
24 | - require_once LSX_SEARCH_PATH . '/classes/facetwp/class-hierarchy.php'; |
|
25 | - $this->hierarchy = lsx\search\classes\facetwp\Hierarchy::get_instance(); |
|
26 | - |
|
27 | - require_once LSX_SEARCH_PATH . '/classes/facetwp/class-post-connections.php'; |
|
28 | - $this->post_connections = lsx\search\classes\facetwp\Post_Connections::get_instance(); |
|
29 | - |
|
30 | - add_filter( 'facetwp_pager_html', array( $this, 'facetwp_pager_html' ), 10, 2 ); |
|
31 | - add_filter( 'facetwp_result_count', array( $this, 'facetwp_result_count' ), 10, 2 ); |
|
32 | - add_filter( 'facetwp_facet_html', array( $this, 'facetwp_slide_html' ), 10, 2 ); |
|
33 | - add_filter( 'facetwp_load_css', array( $this, 'facetwp_load_css' ), 10, 1 ); |
|
34 | - add_filter( 'facetwp_index_row', array( $this, 'index_row' ), 10, 2 ); |
|
35 | - } |
|
36 | - |
|
37 | - /** |
|
38 | - * Change FaceWP pagination HTML to be equal LSX pagination. |
|
39 | - */ |
|
40 | - public function facetwp_pager_html( $output, $params ) { |
|
41 | - $output = ''; |
|
42 | - $page = (int) $params['page']; |
|
43 | - $per_page = (int) $params['per_page']; |
|
44 | - $total_pages = (int) $params['total_pages']; |
|
45 | - |
|
46 | - if ( 1 < $total_pages ) { |
|
47 | - $output .= '<div class="lsx-pagination-wrapper facetwp-custom">'; |
|
48 | - $output .= '<div class="lsx-pagination">'; |
|
49 | - // $output .= '<span class="pages">Page '. $page .' of '. $total_pages .'</span>'; |
|
50 | - |
|
51 | - if ( 1 < $page ) { |
|
52 | - $output .= '<a class="prev page-numbers facetwp-page" rel="prev" data-page="' . ( $page - 1 ) . '">«</a>'; |
|
53 | - } |
|
54 | - |
|
55 | - $temp = false; |
|
56 | - |
|
57 | - for ( $i = 1; $i <= $total_pages; $i++ ) { |
|
58 | - if ( $i == $page ) { |
|
59 | - $output .= '<span class="page-numbers current">' . $i . '</span>'; |
|
60 | - } elseif ( ( $page - 2 ) < $i && ( $page + 2 ) > $i ) { |
|
61 | - $output .= '<a class="page-numbers facetwp-page" data-page="' . $i . '">' . $i . '</a>'; |
|
62 | - } elseif ( ( $page - 2 ) >= $i && $page > 2 ) { |
|
63 | - if ( ! $temp ) { |
|
64 | - $output .= '<span class="page-numbers dots">...</span>'; |
|
65 | - $temp = true; |
|
66 | - } |
|
67 | - } elseif ( ( $page + 2 ) <= $i && ( $page + 2 ) <= $total_pages ) { |
|
68 | - $output .= '<span class="page-numbers dots">...</span>'; |
|
69 | - break; |
|
70 | - } |
|
71 | - } |
|
72 | - |
|
73 | - if ( $page < $total_pages ) { |
|
74 | - $output .= '<a class="next page-numbers facetwp-page" rel="next" data-page="' . ( $page + 1 ) . '">»</a>'; |
|
75 | - } |
|
76 | - |
|
77 | - $output .= '</div>'; |
|
78 | - $output .= '</div>'; |
|
79 | - } |
|
80 | - |
|
81 | - return $output; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Change FaceWP result count HTML. |
|
86 | - */ |
|
87 | - public function facetwp_result_count( $output, $params ) { |
|
88 | - $output = $params['total']; |
|
89 | - return $output; |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Change FaceWP slider HTML. |
|
94 | - */ |
|
95 | - public function facetwp_slide_html( $html, $args ) { |
|
96 | - if ( 'slider' === $args['facet']['type'] ) { |
|
97 | - $html = str_replace( 'class="facetwp-slider-reset"', 'class="btn btn-md facetwp-slider-reset"', $html ); |
|
98 | - } |
|
99 | - |
|
100 | - return $html; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Change FaceWP slider HTML. |
|
105 | - */ |
|
106 | - public function facetwp_counts_html( $html, $args ) { |
|
107 | - if ( 'slider' === $args['facet']['type'] ) { |
|
108 | - $html = str_replace( 'class="facetwp-slider-reset"', 'class="btn btn-md facetwp-slider-reset"', $html ); |
|
109 | - } |
|
110 | - return $html; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Disable FacetWP styles. |
|
115 | - */ |
|
116 | - public function facetwp_load_css( $boolean ) { |
|
117 | - $boolean = false; |
|
118 | - return $boolean; |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * Get the price including the tax |
|
123 | - * @param $params |
|
124 | - * @param $class |
|
125 | - * |
|
126 | - * @return mixed |
|
127 | - */ |
|
128 | - public function index_row( $params, $class ) { |
|
129 | - // Custom woo fields |
|
130 | - if ( 0 === strpos( $params['facet_source'], 'woo' ) ) { |
|
131 | - $product = wc_get_product( $params['post_id'] ); |
|
132 | - |
|
133 | - // Price |
|
134 | - if ( in_array( $params['facet_source'], array( 'woo/price', 'woo/sale_price', 'woo/regular_price' ) ) ) { |
|
135 | - $price = $params['facet_value']; |
|
136 | - if ( $product->is_taxable() ) { |
|
137 | - $price = wc_get_price_including_tax( $product ); |
|
138 | - } |
|
139 | - $params['facet_value'] = $price; |
|
140 | - $params['facet_display_value'] = $price; |
|
141 | - |
|
142 | - } |
|
143 | - } |
|
144 | - return $params; |
|
145 | - } |
|
9 | + /** |
|
10 | + * @var object \lsx\search\classes\facetwp\Hierarchy() |
|
11 | + */ |
|
12 | + public $hierarchy; |
|
13 | + |
|
14 | + /** |
|
15 | + * @var object \lsx\search\classes\facetwp\Post_Connections() |
|
16 | + */ |
|
17 | + public $post_connections; |
|
18 | + |
|
19 | + /** |
|
20 | + * Class Constructor. |
|
21 | + */ |
|
22 | + public function __construct() { |
|
23 | + |
|
24 | + require_once LSX_SEARCH_PATH . '/classes/facetwp/class-hierarchy.php'; |
|
25 | + $this->hierarchy = lsx\search\classes\facetwp\Hierarchy::get_instance(); |
|
26 | + |
|
27 | + require_once LSX_SEARCH_PATH . '/classes/facetwp/class-post-connections.php'; |
|
28 | + $this->post_connections = lsx\search\classes\facetwp\Post_Connections::get_instance(); |
|
29 | + |
|
30 | + add_filter( 'facetwp_pager_html', array( $this, 'facetwp_pager_html' ), 10, 2 ); |
|
31 | + add_filter( 'facetwp_result_count', array( $this, 'facetwp_result_count' ), 10, 2 ); |
|
32 | + add_filter( 'facetwp_facet_html', array( $this, 'facetwp_slide_html' ), 10, 2 ); |
|
33 | + add_filter( 'facetwp_load_css', array( $this, 'facetwp_load_css' ), 10, 1 ); |
|
34 | + add_filter( 'facetwp_index_row', array( $this, 'index_row' ), 10, 2 ); |
|
35 | + } |
|
36 | + |
|
37 | + /** |
|
38 | + * Change FaceWP pagination HTML to be equal LSX pagination. |
|
39 | + */ |
|
40 | + public function facetwp_pager_html( $output, $params ) { |
|
41 | + $output = ''; |
|
42 | + $page = (int) $params['page']; |
|
43 | + $per_page = (int) $params['per_page']; |
|
44 | + $total_pages = (int) $params['total_pages']; |
|
45 | + |
|
46 | + if ( 1 < $total_pages ) { |
|
47 | + $output .= '<div class="lsx-pagination-wrapper facetwp-custom">'; |
|
48 | + $output .= '<div class="lsx-pagination">'; |
|
49 | + // $output .= '<span class="pages">Page '. $page .' of '. $total_pages .'</span>'; |
|
50 | + |
|
51 | + if ( 1 < $page ) { |
|
52 | + $output .= '<a class="prev page-numbers facetwp-page" rel="prev" data-page="' . ( $page - 1 ) . '">«</a>'; |
|
53 | + } |
|
54 | + |
|
55 | + $temp = false; |
|
56 | + |
|
57 | + for ( $i = 1; $i <= $total_pages; $i++ ) { |
|
58 | + if ( $i == $page ) { |
|
59 | + $output .= '<span class="page-numbers current">' . $i . '</span>'; |
|
60 | + } elseif ( ( $page - 2 ) < $i && ( $page + 2 ) > $i ) { |
|
61 | + $output .= '<a class="page-numbers facetwp-page" data-page="' . $i . '">' . $i . '</a>'; |
|
62 | + } elseif ( ( $page - 2 ) >= $i && $page > 2 ) { |
|
63 | + if ( ! $temp ) { |
|
64 | + $output .= '<span class="page-numbers dots">...</span>'; |
|
65 | + $temp = true; |
|
66 | + } |
|
67 | + } elseif ( ( $page + 2 ) <= $i && ( $page + 2 ) <= $total_pages ) { |
|
68 | + $output .= '<span class="page-numbers dots">...</span>'; |
|
69 | + break; |
|
70 | + } |
|
71 | + } |
|
72 | + |
|
73 | + if ( $page < $total_pages ) { |
|
74 | + $output .= '<a class="next page-numbers facetwp-page" rel="next" data-page="' . ( $page + 1 ) . '">»</a>'; |
|
75 | + } |
|
76 | + |
|
77 | + $output .= '</div>'; |
|
78 | + $output .= '</div>'; |
|
79 | + } |
|
80 | + |
|
81 | + return $output; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Change FaceWP result count HTML. |
|
86 | + */ |
|
87 | + public function facetwp_result_count( $output, $params ) { |
|
88 | + $output = $params['total']; |
|
89 | + return $output; |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Change FaceWP slider HTML. |
|
94 | + */ |
|
95 | + public function facetwp_slide_html( $html, $args ) { |
|
96 | + if ( 'slider' === $args['facet']['type'] ) { |
|
97 | + $html = str_replace( 'class="facetwp-slider-reset"', 'class="btn btn-md facetwp-slider-reset"', $html ); |
|
98 | + } |
|
99 | + |
|
100 | + return $html; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Change FaceWP slider HTML. |
|
105 | + */ |
|
106 | + public function facetwp_counts_html( $html, $args ) { |
|
107 | + if ( 'slider' === $args['facet']['type'] ) { |
|
108 | + $html = str_replace( 'class="facetwp-slider-reset"', 'class="btn btn-md facetwp-slider-reset"', $html ); |
|
109 | + } |
|
110 | + return $html; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Disable FacetWP styles. |
|
115 | + */ |
|
116 | + public function facetwp_load_css( $boolean ) { |
|
117 | + $boolean = false; |
|
118 | + return $boolean; |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * Get the price including the tax |
|
123 | + * @param $params |
|
124 | + * @param $class |
|
125 | + * |
|
126 | + * @return mixed |
|
127 | + */ |
|
128 | + public function index_row( $params, $class ) { |
|
129 | + // Custom woo fields |
|
130 | + if ( 0 === strpos( $params['facet_source'], 'woo' ) ) { |
|
131 | + $product = wc_get_product( $params['post_id'] ); |
|
132 | + |
|
133 | + // Price |
|
134 | + if ( in_array( $params['facet_source'], array( 'woo/price', 'woo/sale_price', 'woo/regular_price' ) ) ) { |
|
135 | + $price = $params['facet_value']; |
|
136 | + if ( $product->is_taxable() ) { |
|
137 | + $price = wc_get_price_including_tax( $product ); |
|
138 | + } |
|
139 | + $params['facet_value'] = $price; |
|
140 | + $params['facet_display_value'] = $price; |
|
141 | + |
|
142 | + } |
|
143 | + } |
|
144 | + return $params; |
|
145 | + } |
|
146 | 146 | |
147 | 147 | } |