1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Integrations\WPBakery; |
4
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Controllers\AbstractController; |
6
|
|
|
use GeminiLabs\SiteReviews\Database; |
7
|
|
|
use GeminiLabs\SiteReviews\Helpers\Arr; |
8
|
|
|
use GeminiLabs\SiteReviews\Helpers\Cast; |
9
|
|
|
use GeminiLabs\SiteReviews\Modules\Html\Builder; |
10
|
|
|
|
11
|
|
|
class Controller extends AbstractController |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @action vc_frontend_editor_enqueue_js_css |
15
|
|
|
*/ |
16
|
|
|
public function enqueueInlineScripts(): void |
17
|
|
|
{ |
18
|
|
|
$script = file_get_contents(glsr()->path('assets/scripts/integrations/wpbakery-inline.js')); |
19
|
|
|
wp_add_inline_script('vc-frontend-editor-min-js', $script); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @action vc_backend_editor_enqueue_js_css |
24
|
|
|
* @action vc_frontend_editor_enqueue_js_css |
25
|
|
|
*/ |
26
|
|
|
public function enqueueInlineStyles(): void |
27
|
|
|
{ |
28
|
|
|
$css = file_get_contents(glsr()->path('assets/styles/integrations/wpbakery-inline.css')); |
29
|
|
|
wp_add_inline_style('js_composer', $css); |
30
|
|
|
wp_add_inline_style('vc_inline_css', $css); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @filter vc_autocomplete_site_reviews_assigned_posts_callback |
35
|
|
|
* @filter vc_autocomplete_site_reviews_form_assigned_posts_callback |
36
|
|
|
* @filter vc_autocomplete_site_reviews_summary_assigned_posts_callback |
37
|
|
|
*/ |
38
|
|
|
public function filterAutocompleteAssignedPosts(?string $query = ''): array |
39
|
|
|
{ |
40
|
|
|
$args = [ |
41
|
|
|
'post__in' => [], |
42
|
|
|
'posts_per_page' => 25, |
43
|
|
|
]; |
44
|
|
|
if (is_numeric($query)) { |
45
|
|
|
$args['post__in'][] = (int) $query; |
46
|
|
|
} else { |
47
|
|
|
$args['s'] = (string) $query; |
48
|
|
|
} |
49
|
|
|
$posts = glsr(Database::class)->posts($args); |
50
|
|
|
$callback = fn ($value, $label) => compact('value', 'label'); |
51
|
|
|
$results = array_map($callback, array_keys($posts), array_values($posts)); |
52
|
|
|
array_unshift($results, |
53
|
|
|
[ |
54
|
|
|
'label' => _x('The Current Page', 'admin-text', 'site-reviews'), |
55
|
|
|
'value' => 'post_id', |
56
|
|
|
], |
57
|
|
|
[ |
58
|
|
|
'label' => _x('The Parent Page', 'admin-text', 'site-reviews'), |
59
|
|
|
'value' => 'parent_id', |
60
|
|
|
] |
61
|
|
|
); |
62
|
|
|
return $results; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @filter vc_autocomplete_site_reviews_assigned_terms_callback |
67
|
|
|
* @filter vc_autocomplete_site_reviews_form_assigned_terms_callback |
68
|
|
|
* @filter vc_autocomplete_site_reviews_summary_assigned_terms_callback |
69
|
|
|
*/ |
70
|
|
|
public function filterAutocompleteAssignedTerms(?string $query = ''): array |
71
|
|
|
{ |
72
|
|
|
$users = glsr(Database::class)->terms([ |
73
|
|
|
'number' => 25, |
74
|
|
|
'search' => (string) $query, |
75
|
|
|
]); |
76
|
|
|
$callback = fn ($value, $label) => compact('value', 'label'); |
77
|
|
|
$results = array_map($callback, array_keys($users), array_values($users)); |
78
|
|
|
return $results; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @filter vc_autocomplete_site_reviews_assigned_users_callback |
83
|
|
|
* @filter vc_autocomplete_site_reviews_form_assigned_users_callback |
84
|
|
|
* @filter vc_autocomplete_site_reviews_summary_assigned_users_callback |
85
|
|
|
*/ |
86
|
|
|
public function filterAutocompleteAssignedUsers(?string $query = ''): array |
87
|
|
|
{ |
88
|
|
|
$users = glsr(Database::class)->users([ |
89
|
|
|
'number' => 25, |
90
|
|
|
'search_wild' => $query, |
91
|
|
|
]); |
92
|
|
|
$callback = fn ($value, $label) => compact('value', 'label'); |
93
|
|
|
$results = array_map($callback, array_keys($users), array_values($users)); |
94
|
|
|
array_unshift($results, |
95
|
|
|
[ |
96
|
|
|
'label' => _x('The Logged-in user', 'admin-text', 'site-reviews'), |
97
|
|
|
'value' => 'user_id', |
98
|
|
|
], |
99
|
|
|
[ |
100
|
|
|
'label' => _x('The Page author', 'admin-text', 'site-reviews'), |
101
|
|
|
'value' => 'author_id', |
102
|
|
|
], |
103
|
|
|
[ |
104
|
|
|
'label' => _x('The Profile user (BuddyPress/Ultimate Member)', 'admin-text', 'site-reviews'), |
105
|
|
|
'value' => 'profile_id', |
106
|
|
|
] |
107
|
|
|
); |
108
|
|
|
return $results; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @filter vc_autocomplete_site_review_post_id_callback |
113
|
|
|
*/ |
114
|
|
|
public function filterAutocompletePostId(?string $query = ''): array |
115
|
|
|
{ |
116
|
|
|
$args = [ |
117
|
|
|
'post__in' => [], |
118
|
|
|
'post_type' => glsr()->post_type, |
119
|
|
|
'posts_per_page' => 25, |
120
|
|
|
]; |
121
|
|
|
if (is_numeric($query)) { |
122
|
|
|
$args['post__in'][] = (int) $query; |
123
|
|
|
} else { |
124
|
|
|
$args['s'] = (string) $query; |
125
|
|
|
} |
126
|
|
|
$posts = glsr(Database::class)->posts($args); |
127
|
|
|
$callback = fn ($value, $label) => compact('value', 'label'); |
128
|
|
|
$results = array_map($callback, array_keys($posts), array_values($posts)); |
129
|
|
|
return $results; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @filter vc_single_param_edit_holder_output |
134
|
|
|
*/ |
135
|
|
|
public function filterSettingOutput($output, $param, $value, $settings): string |
|
|
|
|
136
|
|
|
{ |
137
|
|
|
if (!str_starts_with(Arr::get($settings, 'base'), 'site_review')) { |
138
|
|
|
return $output; |
139
|
|
|
} |
140
|
|
|
if ('checkbox' !== Arr::get($param, 'type')) { |
141
|
|
|
return $output; |
142
|
|
|
} |
143
|
|
|
$output = str_replace('label> <label', 'label><br><label', $output); |
144
|
|
|
return $output; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @action vc_before_init |
149
|
|
|
*/ |
150
|
|
|
public function registerShortcodes(): void |
151
|
|
|
{ |
152
|
|
|
VcSiteReview::vcRegister(); |
153
|
|
|
VcSiteReviews::vcRegister(); |
154
|
|
|
VcSiteReviewsForm::vcRegister(); |
155
|
|
|
VcSiteReviewsSummary::vcRegister(); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @action vc_load_default_params |
160
|
|
|
*/ |
161
|
|
|
public function registerParameters(): void |
162
|
|
|
{ |
163
|
|
|
vc_add_shortcode_param('glsr_type_range', [$this, 'renderFieldRange'], glsr()->url('assets/scripts/integrations/wpbakery-editor.js')); |
|
|
|
|
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @param mixed $settings |
168
|
|
|
* @param string $value |
169
|
|
|
* @callback vc_add_shortcode_param |
170
|
|
|
*/ |
171
|
|
|
public function renderFieldRange($settings, $value): string |
172
|
|
|
{ |
173
|
|
|
$max = Arr::get($settings, 'max'); |
174
|
|
|
$min = Arr::get($settings, 'min'); |
175
|
|
|
$step = Arr::get($settings, 'step'); |
176
|
|
|
if ('' !== $max) { |
177
|
|
|
$max = Cast::toInt($max); |
178
|
|
|
} |
179
|
|
|
if ('' !== $min) { |
180
|
|
|
$min = Cast::toInt($min); |
181
|
|
|
} |
182
|
|
|
if ('' !== $step) { |
183
|
|
|
$step = Cast::toInt($step); |
184
|
|
|
} |
185
|
|
|
$input = glsr(Builder::class)->input([ |
186
|
|
|
'class' => "wpb_vc_param_value wpb-textinput", |
187
|
|
|
'max' => $max, |
188
|
|
|
'min' => $min, |
189
|
|
|
'name' => $settings['param_name'], |
190
|
|
|
'step' => $step, |
191
|
|
|
'type' => 'range', |
192
|
|
|
'value' => sanitize_text_field(Cast::toString($value)), |
193
|
|
|
]); |
194
|
|
|
$info = glsr(Builder::class)->input([ |
195
|
|
|
'class' => 'wpb_vc_param_infobox', |
196
|
|
|
'max' => $max, |
197
|
|
|
'min' => $min, |
198
|
|
|
'step' => $step, |
199
|
|
|
'type' => 'number', |
200
|
|
|
'value' => sanitize_text_field(Cast::toString($value)), |
201
|
|
|
]); |
202
|
|
|
return glsr(Builder::class)->div([ |
203
|
|
|
'class' => "{$settings['type']}-wrapper", |
204
|
|
|
'text' => $info.$input, |
205
|
|
|
]); |
206
|
|
|
} |
207
|
|
|
} |
208
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.