-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathj-query-filter.php
executable file
·142 lines (127 loc) · 4.1 KB
/
j-query-filter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
/*
Plugin Name: J-QueryFilter
Plugin URI: http://niewiarowski.it/
Description: Advanced taxonomy and meta post filtering plugin.
Author: Jakub 'marsjaninzmarsa' Niewiarowski
Author URI: http://niewiarowski.it/
Version: 0.0.2
License: GPL v3
*/
if(!defined('J_QUERY_FILTER_V'))
define('J_QUERY_FILTER_V', '0.0.1');
if(!extension_loaded('yaml') && !class_exists('Spyc')) {
require_once "spyc/spyc.php";
}
spl_autoload_register(function($class) {
if(is_file($file = dirname(__FILE__) . "/inc/$class.php")) {
include_once $file;
}
});
// Registering Widget
add_action('widgets_init', function() {
return register_widget("JQueryFilterWidget");
});
add_action('wp_register_sidebar_widget', function($widget) {
if($widget['classname'] == 'widget_j_query_filter_widget') {
$number = $widget['params'][0]['number'];
if($number < 0) {
return;
}
$settings = $widget['callback'][0]->get_settings();
$settings = $settings[$number];
$sidebarQueryFilter = new UiJQueryFilter($settings);
}
});
// $sidebarQueryFilter->form = UiJQueryFilter::LoadYaml(dirname(__FILE__) . '/form.yaml');
add_action( 'wp_enqueue_scripts', 'enqueue_and_register_j_query_filter' );
add_action( 'wp_ajax_nopriv_sidebar_query_filter', 'j_query_filter' );
add_action( 'wp_ajax_sidebar_query_filter', 'j_query_filter' );
function enqueue_and_register_j_query_filter(){
wp_register_script(
'jquery-deserialize',
plugins_url('js/jquery.deserialize.js', __FILE__),
array('jquery'),
'1.2.1'
);
wp_register_script(
'purl',
plugins_url('js/purl.js', __FILE__),
array(),
'2.3.1'
);
wp_register_script(
'j-query-filter',
plugins_url('js/j-query-filter.js', __FILE__),
array(
'jquery-ui-slider',
'jquery-form',
'jquery-deserialize',
'jquery-color',
'purl'
),
J_QUERY_FILTER_V
);
$instances = UiJQueryFilter::GetInstances();
$styles = array();
foreach (glob(plugin_dir_path( __FILE__ ).'css/*.css') as $file) {
$styles[] = $name = basename($file, '.css');
wp_register_style(
'j-query-filter-'.$name,
plugins_url('css/'.$name.'.css', __FILE__),
array(),
J_QUERY_FILTER_V
);
}
if(!empty($instances)) {
wp_enqueue_script( 'j-query-filter' );
foreach ($instances as $instance) {
if(in_array($name = $instance->style, $styles)) {
wp_enqueue_style( 'j-query-filter-'.$name );
}
}
}
}
function wyszukiwarka_ofert($data) {
global $sidebarQueryFilter, $wp_query;
if (!empty($data)) {
$args = array(
'post_type' => 'bm_work_offer',
'posts_per_page' => 16,
'offset' => (isset($_REQUEST['offset']) && $_REQUEST['offset']) ? $_REQUEST['offset'] : 0,
'suppress_filters' => true,
'post_status' => (in_array('administrator', wp_get_current_user()->roles)) ? 'any' : 'publish',
);
$args = $sidebarQueryFilter->QueryFilter($data, $args);
$wp_query = new WP_Query($args);
$wp_query->has_results = true;
} else {
$wp_query->has_results = false;
}
}
function j_query_filter($args = false) {
global $wp_query;
wyszukiwarka_ofert(($args)? $args: $_GET);
global $post;
foreach ($wp_query->posts as $key => $post) {
get_template_part('theme-template-parts/content/content', 'offer-item-13');
printf('<div hidden data-lp="%s"></div>', $key + get_query_var('offset') + 1);
}
if($wp_query->post_count && $wp_query->post_count <= $wp_query->query_vars['posts_per_page']) {
print('<div hidden class="eot"></div>');
}
if(isset($_REQUEST['search']) && !$_REQUEST['offset'] && !$wp_query->posts) {
printf('<div class="noResults">%s</div>', __('Brak wyników wyszukiwania', 'twentythirteen'));
}
if (defined('DOING_AJAX') && DOING_AJAX) exit;
}
add_action('pre_get_posts', function($query) {
if($query->is_main_query() && $query->is_post_type_archive() && in_array($pt = $query->query_vars['post_type'], UiJQueryFilter::GetFilteredPT())) {
$sidebarQueryFilter = UiJQueryFilter::GetFilterForPT($pt);
$args = array(
// 'post_type' => $pt,
);
$query->parse_query(array_merge($query->query, $sidebarQueryFilter->QueryFilter($_GET, $args)));
}
return;
});