PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 2.2.0
Forumax – AI Powered Advanced Community Forum Plugin v2.2.0
2.4.4 2.4.3 2.4.2 2.4.1 2.4.0 trunk 1.0.8 1.1.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 2.0.0 2.1.0 All 29 releases
bbp-core / includes / Blocks / Render / search.php

search.php in Forumax – AI Powered Advanced Community Forum Plugin 2.2.0, at includes/Blocks/Render/search.php

372 lines 13.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace admin\Blocks\Render;
3
4 use WP_Query;
5
6 class Search {
7 public function render_search($attributes, $content)
8 {
9 $placeholder = isset($attributes['placeholder']) ? $attributes['placeholder'] : 'Search for Topics....';
10 $submit_btn_type = isset($attributes['submit_btn_type']) ? $attributes['submit_btn_type'] : 'icon';
11 $submit_btn_text = isset($attributes['submit_btn_text']) ? $attributes['submit_btn_text'] : __('Search', 'forumax');
12 $submit_btn_align = isset($attributes['submit_btn_align']) ? $attributes['submit_btn_align'] : 'left';
13 $submit_btn_icon = isset($attributes['submit_btn_icon']) ? $attributes['submit_btn_icon'] : ['value' => 'fas fa-search', 'library' => 'solid'];
14 $is_keywords = isset($attributes['is_keywords']) ? $attributes['is_keywords'] : true;
15 $keywords_label = isset($attributes['keywords_label']) ? $attributes['keywords_label'] : 'Popular:';
16 $keywords_align = isset($attributes['keywords_align']) ? $attributes['keywords_align'] : 'center';
17 $keywords = isset($attributes['keywords']) ? $attributes['keywords'] : [['title' => 'Keyword #1'], ['title' => 'Keyword #2']];
18 $search_post_type = isset($attributes['search_post_type']) ? $attributes['search_post_type'] : 'docs';
19
20 // AJAX Search and Highlight are Pro-only features.
21 $is_pro_active = class_exists( 'Forumax_Pro' ) && function_exists( 'bc_fs' ) && bc_fs()->can_use_premium_code();
22 $search_highlight = ( $is_pro_active && ! empty( $attributes['search_highlight'] ) ) ? 'true' : 'false';
23 $is_ajax_search = ( $is_pro_active && ! empty( $attributes['is_ajax_search'] ) ) ? 'true' : 'false';
24
25 // Enforce free defaults for Pro-gated attributes.
26 if ( ! $is_pro_active ) {
27 $search_post_type = 'forum';
28 unset( $attributes['wrapper_max_width'] );
29 }
30
31 $unique_id = uniqid('bbpc-search-');
32
33 $cross_position = $submit_btn_align == 'right' ? 'left' : 'right';
34
35 // Include dependencies.
36 if ( ! wp_style_is( 'bbpc-el-widgets', 'registered' ) ) {
37 wp_register_style( 'bbpc-el-widgets', FORUMAX_FRONT_ASS . 'css/el-widgets.css' );
38 }
39 wp_enqueue_style( 'bbpc-el-widgets' );
40
41 wp_enqueue_script( 'bbpc-frontend-js', FORUMAX_FRONT_ASS . 'js/frontend.js', array( 'jquery' ), FORUMAX_VERSION, true );
42
43 // Localize AJAX data for the search script.
44 wp_localize_script( 'bbpc-frontend-js', 'forumax_localize_script', array(
45 'ajaxurl' => admin_url( 'admin-ajax.php' ),
46 'nonce' => wp_create_nonce( 'forumax-nonce' ),
47 ) );
48
49 $wrapper_attributes = get_block_wrapper_attributes([
50 'id' => $unique_id,
51 ]);
52
53 ob_start();
54 ?>
55 <div <?php echo $wrapper_attributes; ?>>
56 <div class="bbpc-search-overlay"></div>
57
58 <form action="<?php echo esc_url(home_url('/')) ?>" role="search" method="get" class="bbpc_search_form_wrapper">
59 <div class="form-group">
60 <div class="input-wrapper <?php echo esc_attr($cross_position); ?>">
61
62 <span class="submit-btn-<?php echo esc_attr($submit_btn_align); ?>">
63 <button type="submit">
64 <?php
65 if ($submit_btn_type == 'icon') {
66 // Use inline SVG for editor compatibility (Font Awesome is not loaded in Gutenberg).
67 if (is_array($submit_btn_icon) && !empty($submit_btn_icon['value'])) {
68 echo '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="16" height="16" fill="currentColor"><path d="M416 208c0 45.9-14.9 88.3-40 122.7L502.6 457.4c12.5 12.5 12.5 32.8 0 45.3s-32.8 12.5-45.3 0L330.7 376c-34.4 25.2-76.8 40-122.7 40C93.1 416 0 322.9 0 208S93.1 0 208 0S416 93.1 416 208zM208 352a144 144 0 1 0 0-288 144 144 0 1 0 0 288z"/></svg>';
69 } else {
70 echo '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="16" height="16" fill="currentColor"><path d="M416 208c0 45.9-14.9 88.3-40 122.7L502.6 457.4c12.5 12.5 12.5 32.8 0 45.3s-32.8 12.5-45.3 0L330.7 376c-34.4 25.2-76.8 40-122.7 40C93.1 416 0 322.9 0 208S93.1 0 208 0S416 93.1 416 208zM208 352a144 144 0 1 0 0-288 144 144 0 1 0 0 288z"/></svg>';
71 }
72 } else {
73 echo esc_html($submit_btn_text);
74 }
75 ?>
76 </button>
77 </span>
78
79 <input type='search' id="searchInput" autocomplete="off" name="s"
80 placeholder="<?php echo esc_attr( $placeholder ); ?>"
81 data-post-type="<?php echo esc_attr( $search_post_type ); ?>"
82 data-highlight="<?php echo esc_attr( $search_highlight ); ?>"
83 data-ajax-search="<?php echo esc_attr( $is_ajax_search ); ?>">
84
85 <!-- Ajax Search Loading Spinner -->
86 <div class="spinner">
87 <div class="bounce1"></div>
88 <div class="bounce2"></div>
89 <div class="bounce3"></div>
90 </div>
91
92 <!-- WPML Language Code -->
93 <?php if (defined('ICL_LANGUAGE_CODE')): ?>
94 <input type="hidden" name="lang" value="<?php echo esc_attr(ICL_LANGUAGE_CODE); ?>" />
95 <?php endif; ?>
96
97 <?php if ( ! empty( $search_post_type ) ) : ?>
98 <input type="hidden" id="hidden_post_type" name="post_type" value="<?php echo esc_attr( $search_post_type ); ?>" />
99 <?php endif; ?>
100 </div>
101 </div>
102 <div id="bbpc-search-result"></div>
103
104 <?php if ($is_keywords): ?>
105 <?php if ( $is_pro_active ): ?>
106 <div class="bbpc-search-keyword">
107 <div class="bbpc-keywords-wrapper" style="text-align: <?php echo esc_attr($keywords_align); ?>">
108 <?php if (!empty($keywords_label)): ?>
109 <span class="bbpc-search-keywords-label"><?php echo esc_html($keywords_label); ?></span>
110 <?php endif; ?>
111 <ul>
112 <?php foreach ( $keywords as $keyword ) : ?>
113 <?php
114 $keyword_url = home_url( '/?s=' . $keyword['title'] );
115 if ( ! empty( $search_post_type ) ) {
116 $keyword_url .= '&post_type=' . $search_post_type;
117 }
118 ?>
119 <li><a href="<?php echo esc_url( $keyword_url ); ?>">
120 <?php echo esc_html( $keyword['title'] ); ?> </a></li>
121 <?php endforeach; ?>
122 </ul>
123 </div>
124 </div>
125 <?php else: ?>
126 <?php
127 // Show only in Editor (via ServerSideRender or admin page)
128 if ((defined('REST_REQUEST') && REST_REQUEST) || is_admin()):
129 $upsell_img = FORUMAX_FRONT_ASS . 'img/upsell-search-keywords.png';
130 $upgrade_url = admin_url('admin.php?page=forumax-pricing');
131 ?>
132 <div class="bbpc-search-keyword-upsell">
133 <img src="<?php echo esc_url($upsell_img); ?>" alt="<?php esc_attr_e('Upgrade to Pro', 'forumax'); ?>">
134 <div class="upsell-btn-wrapper bbpc-upgrade-btn">
135 <a href="<?php echo esc_url($upgrade_url); ?>" target="_blank" rel="noopener noreferrer">
136 <?php esc_html_e('Upgrade to Pro', 'forumax'); ?>
137 </a>
138 </div>
139 </div>
140 <?php endif; ?>
141 <?php endif; ?>
142 <?php endif; ?>
143 </form>
144 </div>
145
146 <style>
147 <?php if (!empty($attributes['color_text'])): ?>
148 #<?php echo esc_attr($unique_id); ?> .bbpc_search_form_wrapper .input-wrapper input {
149 color:
150 <?php echo esc_attr($attributes['color_text']); ?>
151 ;
152 }
153
154 <?php endif; ?>
155 <?php if (!empty($attributes['color_placeholder'])): ?>
156 #<?php echo esc_attr($unique_id); ?> .bbpc_search_form_wrapper .input-wrapper input::placeholder {
157 color:
158 <?php echo esc_attr($attributes['color_placeholder']); ?>
159 ;
160 }
161
162 <?php endif; ?>
163 <?php if (!empty($attributes['input_bg_color'])): ?>
164 #<?php echo esc_attr($unique_id); ?> .bbpc_search_form_wrapper .input-wrapper input {
165 background-color:
166 <?php echo esc_attr($attributes['input_bg_color']); ?>
167 ;
168 }
169
170 <?php endif; ?>
171 <?php if (!empty($attributes['color_icon'])): ?>
172 #<?php echo esc_attr($unique_id); ?> .bbpc_search_form_wrapper .input-wrapper button {
173 color:
174 <?php echo esc_attr($attributes['color_icon']); ?>
175 ;
176 }
177
178 <?php endif; ?>
179 <?php if (!empty($attributes['search_bg'])): ?>
180 #<?php echo esc_attr($unique_id); ?> .bbpc_search_form_wrapper .input-wrapper button {
181 background:
182 <?php echo esc_attr($attributes['search_bg']); ?>
183 ;
184 }
185
186 <?php endif; ?>
187
188 /* Keywords Styles */
189 <?php if (!empty($attributes['color_keywords_label'])): ?>
190 #<?php echo esc_attr($unique_id); ?> .bbpc-search-keyword span.bbpc-search-keywords-label {
191 color:
192 <?php echo esc_attr($attributes['color_keywords_label']); ?>
193 ;
194 }
195
196 <?php endif; ?>
197 <?php if (!empty($attributes['bbpc_color_keywords'])): ?>
198 #<?php echo esc_attr($unique_id); ?> .bbpc-search-keyword ul li a {
199 color:
200 <?php echo esc_attr($attributes['bbpc_color_keywords']); ?>
201 ;
202 }
203
204 <?php endif; ?>
205 <?php if (!empty($attributes['bbpc_color_keywords_bg'])): ?>
206 #<?php echo esc_attr($unique_id); ?> .bbpc-search-keyword ul li a {
207 background:
208 <?php echo esc_attr($attributes['bbpc_color_keywords_bg']); ?>
209 ;
210 }
211
212 <?php endif; ?>
213 <?php if (!empty($attributes['bbpc_color_keywords_hover'])): ?>
214 #<?php echo esc_attr($unique_id); ?> .bbpc-search-keyword ul li a:hover {
215 color:
216 <?php echo esc_attr($attributes['bbpc_color_keywords_hover']); ?>
217 ;
218 }
219
220 <?php endif; ?>
221 <?php if (!empty($attributes['bbpc_color_keywords_bg_hover'])): ?>
222 #<?php echo esc_attr($unique_id); ?> .bbpc-search-keyword ul li a:hover {
223 background:
224 <?php echo esc_attr($attributes['bbpc_color_keywords_bg_hover']); ?>
225 ;
226 }
227
228 <?php endif; ?>
229
230 /* Input Border & Border Radius */
231 <?php if ( isset( $attributes['input_border_radius'] ) ) : ?>
232 #<?php echo esc_attr( $unique_id ); ?> .bbpc_search_form_wrapper .input-wrapper input {
233 border-radius:
234 <?php echo esc_attr( $attributes['input_border_radius'] ); ?>px
235 ;
236 }
237 <?php endif; ?>
238
239 <?php if ( ! empty( $attributes['input_border_color'] ) ) : ?>
240 #<?php echo esc_attr( $unique_id ); ?> .bbpc_search_form_wrapper .input-wrapper input {
241 border-color:
242 <?php echo esc_attr( $attributes['input_border_color'] ); ?>
243 ;
244 border-style: solid;
245 }
246 <?php endif; ?>
247
248 <?php if ( isset( $attributes['input_border_width'] ) ) : ?>
249 #<?php echo esc_attr( $unique_id ); ?> .bbpc_search_form_wrapper .input-wrapper input {
250 border-width:
251 <?php echo esc_attr( $attributes['input_border_width'] ); ?>px
252 ;
253 border-style: solid;
254 }
255 <?php endif; ?>
256
257 <?php if ( ! empty( $attributes['input_focus_border_color'] ) ) : ?>
258 #<?php echo esc_attr( $unique_id ); ?> .bbpc_search_form_wrapper .input-wrapper input:focus {
259 border-color:
260 <?php echo esc_attr( $attributes['input_focus_border_color'] ); ?>
261 ;
262 outline: none;
263 }
264 <?php endif; ?>
265
266 <?php if ( isset( $attributes['input_height'] ) ) : ?>
267 #<?php echo esc_attr( $unique_id ); ?> .bbpc_search_form_wrapper .input-wrapper input {
268 height:
269 <?php echo esc_attr( $attributes['input_height'] ); ?>px
270 ;
271 }
272 <?php endif; ?>
273
274 /* Wrapper Max Width */
275 <?php if ( isset( $attributes['wrapper_max_width'] ) ) : ?>
276 #<?php echo esc_attr( $unique_id ); ?> .bbpc_search_form_wrapper {
277 max-width:
278 <?php echo esc_attr( $attributes['wrapper_max_width'] ); ?>px
279 ;
280 margin-left: auto;
281 margin-right: auto;
282 }
283 <?php endif; ?>
284
285 /* Button Hover Styles */
286 <?php if ( ! empty( $attributes['btn_hover_color'] ) ) : ?>
287 #<?php echo esc_attr( $unique_id ); ?> .bbpc_search_form_wrapper .input-wrapper button:hover {
288 color:
289 <?php echo esc_attr( $attributes['btn_hover_color'] ); ?>
290 ;
291 }
292 <?php endif; ?>
293
294 <?php if ( ! empty( $attributes['btn_hover_bg'] ) ) : ?>
295 #<?php echo esc_attr( $unique_id ); ?> .bbpc_search_form_wrapper .input-wrapper button:hover {
296 background:
297 <?php echo esc_attr( $attributes['btn_hover_bg'] ); ?>
298 ;
299 }
300 <?php endif; ?>
301
302 <?php if ( isset( $attributes['btn_border_radius'] ) ) : ?>
303 #<?php echo esc_attr( $unique_id ); ?> .bbpc_search_form_wrapper .input-wrapper button {
304 border-radius:
305 <?php echo esc_attr( $attributes['btn_border_radius'] ); ?>px
306 ;
307 }
308 <?php endif; ?>
309
310 /* Search Results Dropdown */
311 <?php if ( ! empty( $attributes['results_bg_color'] ) ) : ?>
312 #<?php echo esc_attr( $unique_id ); ?> #bbpc-search-result {
313 background:
314 <?php echo esc_attr( $attributes['results_bg_color'] ); ?>
315 ;
316 }
317 <?php endif; ?>
318
319 <?php if ( ! empty( $attributes['results_border_color'] ) ) : ?>
320 #<?php echo esc_attr( $unique_id ); ?> #bbpc-search-result {
321 border-color:
322 <?php echo esc_attr( $attributes['results_border_color'] ); ?>
323 ;
324 }
325 <?php endif; ?>
326
327 <?php if ( ! empty( $attributes['results_text_color'] ) ) : ?>
328 #<?php echo esc_attr( $unique_id ); ?> #bbpc-search-result,
329 #<?php echo esc_attr( $unique_id ); ?> #bbpc-search-result a,
330 #<?php echo esc_attr( $unique_id ); ?> .search-result-item a {
331 color:
332 <?php echo esc_attr( $attributes['results_text_color'] ); ?>
333 ;
334 }
335 <?php endif; ?>
336
337 <?php if ( ! empty( $attributes['results_hover_bg'] ) ) : ?>
338 #<?php echo esc_attr( $unique_id ); ?> .search-result-item:hover {
339 background:
340 <?php echo esc_attr( $attributes['results_hover_bg'] ); ?>
341 ;
342 }
343 <?php endif; ?>
344
345 <?php if ( isset( $attributes['results_border_radius'] ) ) : ?>
346 #<?php echo esc_attr( $unique_id ); ?> #bbpc-search-result {
347 border-radius:
348 <?php echo esc_attr( $attributes['results_border_radius'] ); ?>px
349 ;
350 }
351 <?php endif; ?>
352
353 <?php if ( ! empty( $attributes['highlight_bg_color'] ) ) : ?>
354 #<?php echo esc_attr( $unique_id ); ?> .frmx-search-highlight {
355 background-color:
356 <?php echo esc_attr( $attributes['highlight_bg_color'] ); ?>
357 ;
358 }
359 <?php endif; ?>
360
361 <?php if ( ! empty( $attributes['highlight_text_color'] ) ) : ?>
362 #<?php echo esc_attr( $unique_id ); ?> .frmx-search-highlight {
363 color:
364 <?php echo esc_attr( $attributes['highlight_text_color'] ); ?>
365 ;
366 }
367 <?php endif; ?>
368 </style>
369 <?php
370 return ob_get_clean();
371 }
372 }