PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 2.4.0
Forumax – AI Powered Advanced Community Forum Plugin v2.4.0
2.5.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 All 30 releases
bbp-core / includes / Blocks / Render / search.php

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

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