-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.php
162 lines (147 loc) · 4.79 KB
/
plugin.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
/*
Plugin Name: WP Custom Fields Search
Plugin URI: http://www.webhammer.co.uk/wp-custom-fields-search
Description: Adds powerful search forms to your wordpress site
Version: 0.9.9
Author: Don Benjamin
Author URI: http://www.webhammer.co.uk/
Text Domain: wp_custom_fields_search
*/
/*
* Copyright 2015 Webhammer UK Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
require_once(dirname(__FILE__).'/frontend.php');
class WPCustomFieldsSearchPlugin {
function __construct(){
/** Admin Hooks */
add_action('widgets_init',array($this,"widgets_init"));
add_action('admin_enqueue_scripts',array($this,"admin_enqueue_scripts"));
/** Base Types*/
add_filter("wp_custom_fields_search_inputs",array($this,"wp_custom_fields_search_inputs"));
add_filter("wp_custom_fields_search_datatypes",array($this,"wp_custom_fields_search_datatypes"));
add_filter("wp_custom_fields_search_comparisons",array($this,"wp_custom_fields_search_comparisons"));
}
function widgets_init(){
require_once(dirname(__FILE__).'/widget.php');
register_widget("WPCustomFieldsSearchWidget");
}
function admin_enqueue_scripts(){
wp_enqueue_script(
"angularjs",
"//ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js",
array('jquery')
);
wp_enqueue_script(
"angularjs-animate",
"//ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-animate.js",
array('jquery')
);
wp_enqueue_script(
"ng-sortable",
plugin_dir_url(__FILE__)."/ng/lib/ui-sortable.js",
array('angularjs')
);
wp_enqueue_script(
"wp-custom-fields-search-editor",
plugin_dir_url(__FILE__).'/js/wp-custom-fields-search-editor.js',
array('jquery','jquery-ui-core','jquery-ui-widget','jquery-ui-sortable','angularjs','ng-sortable')
);
wp_enqueue_script(
"wpcfs-angular-app",
plugin_dir_url(__FILE__).'/ng/js/app.js',
array('wp-custom-fields-search-editor')
);
wp_enqueue_script(
"wpcfs-angular-services",
plugin_dir_url(__FILE__).'/ng/js/services.js',
array('wp-custom-fields-search-editor')
);
wp_enqueue_script(
"wpcfs-angular-animations",
plugin_dir_url(__FILE__).'/ng/js/animations.js',
array('wp-custom-fields-search-editor','angularjs-animate')
);
wp_enqueue_script(
"wp-handlers",
plugin_dir_url(__FILE__).'/js/wp-handlers.js',
array('wp-custom-fields-search-editor')
);
wp_enqueue_style(
"wpcfs-angular-css",
plugin_dir_url(__FILE__).'/ng/css/wp-custom-fields-search-editor.css'
);
}
static function get_javascript_editor_config(){
error_reporting(E_ALL);
$inputs = apply_filters("wp_custom_fields_search_inputs",array());
$datatypes = apply_filters("wp_custom_fields_search_datatypes",array());
$comparisons = apply_filters("wp_custom_fields_search_comparisons",array());
foreach($inputs as $k=>$input){
$inputs[$k] = array(
"id"=>$input->getId(),
"name"=>$input->getName(),
"options"=>$input->getEditorOptions(),
);
}
foreach($datatypes as $k=>$datatype){
$datatypes[$k] = array(
"id"=>$datatype->getId(),
"name"=>$datatype->getName(),
"options"=>$datatype->getEditorOptions(),
);
}
foreach($comparisons as $k=>$comparison){
$comparisons[$k] = array(
"id"=>$comparison->getId(),
"name"=>$comparison->getName(),
"options"=>$comparison->getEditorOptions(),
);
}
return array(
"inputs"=>$inputs,
"datatypes"=>$datatypes,
"comparisons"=>$comparisons,
);
}
function wp_custom_fields_search_inputs($inputs){
require_once(dirname(__FILE__).'/engine.php');
$inputs = $inputs+array(
new WPCustomFieldsSearch_TextBoxInput(),
new WPCustomFieldsSearch_SelectInput(),
);
return $inputs;
}
function wp_custom_fields_search_datatypes($datatypes){
require_once(dirname(__FILE__).'/engine.php');
$datatypes = $datatypes+array(
new WPCustomFieldsSearch_PostField(),
new WPCustomFieldsSearch_CustomField(),
);
return $datatypes;
}
function wp_custom_fields_search_comparisons($comparisons){
require_once(dirname(__FILE__).'/engine.php');
$comparisons = $comparisons+array(
new WPCustomFieldsSearch_Equals(),
new WPCustomFieldsSearch_WordsIn(),
new WPCustomFieldsSearch_PhraseIn(),
new WPCustomFieldsSearch_GreaterThan(),
new WPCustomFieldsSearch_LessThan(),
new WPCustomFieldsSearch_Range(),
);
return $comparisons;
}
}
new WPCustomFieldsSearchPlugin();