PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / trunk
Forumax – AI Powered Advanced Community Forum Plugin vtrunk
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 trunk, at includes/Blocks/Render/search.php

384 lines 14.4 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( bbp_get_search_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 <!-- bbPress search request sentinel -->
90 <input type="hidden" name="action" value="bbp-search-request" />
91
92 <input type='search' id="<?php echo esc_attr( $input_id ); ?>" class="frmx-search-input" autocomplete="off" name="bbp_search"
93 placeholder="<?php echo esc_attr( $placeholder ); ?>"
94 data-post-type="<?php echo esc_attr( $search_post_type ); ?>"
95 data-highlight="<?php echo esc_attr( $search_highlight ); ?>"
96 data-ajax-search="<?php echo esc_attr( $is_ajax_search ); ?>"
97 data-result-id="<?php echo esc_attr( $result_id ); ?>">
98
99 <!-- Ajax Search Loading Spinner -->
100 <span class="spinner" aria-hidden="true">
101 <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">
102 <circle cx="12" cy="12" r="10" stroke-opacity="0.2" />
103 <path d="M12 2a10 10 0 0 1 10 10" />
104 </svg>
105 </span>
106
107 <!-- WPML Language Code -->
108 <?php if (defined('ICL_LANGUAGE_CODE')): ?>
109 <input type="hidden" name="lang" value="<?php echo esc_attr(ICL_LANGUAGE_CODE); ?>" />
110 <?php endif; ?>
111 </div>
112 </div>
113 <div id="<?php echo esc_attr( $result_id ); ?>" class="bbpc-search-result-container" data-noresult="<?php esc_attr_e( 'No Results Found', 'forumax' ); ?>"></div>
114
115 <?php if ($is_keywords): ?>
116 <?php if ( $is_pro_active ): ?>
117 <div class="bbpc-search-keyword">
118 <div class="bbpc-keywords-wrapper" style="text-align: <?php echo esc_attr($keywords_align); ?>">
119 <?php if (!empty($keywords_label)): ?>
120 <span class="bbpc-search-keywords-label"><?php echo esc_html($keywords_label); ?></span>
121 <?php endif; ?>
122 <ul>
123 <?php foreach ( $keywords as $keyword ) : ?>
124 <?php
125 $keyword_url = home_url( '/?s=' . $keyword['title'] );
126 if ( ! empty( $search_post_type ) ) {
127 $keyword_url .= '&post_type=' . $search_post_type;
128 }
129 ?>
130 <li><a href="<?php echo esc_url( $keyword_url ); ?>">
131 <?php echo esc_html( $keyword['title'] ); ?> </a></li>
132 <?php endforeach; ?>
133 </ul>
134 </div>
135 </div>
136 <?php else: ?>
137 <?php
138 // Show only in Editor (via ServerSideRender or admin page)
139 if ((defined('REST_REQUEST') && REST_REQUEST) || is_admin()):
140 $upsell_img = FORUMAX_FRONT_ASS . 'img/upsell-search-keywords.png';
141 $upgrade_url = admin_url('admin.php?page=forumax-pricing');
142 ?>
143 <div class="bbpc-search-keyword-upsell">
144 <img src="<?php echo esc_url($upsell_img); ?>" alt="<?php esc_attr_e('Upgrade to Pro', 'forumax'); ?>">
145 <div class="upsell-btn-wrapper bbpc-upgrade-btn">
146 <a href="<?php echo esc_url($upgrade_url); ?>" target="_blank" rel="noopener noreferrer">
147 <?php esc_html_e('Upgrade to Pro', 'forumax'); ?>
148 </a>
149 </div>
150 </div>
151 <?php endif; ?>
152 <?php endif; ?>
153 <?php endif; ?>
154 </form>
155 </div>
156
157 <style>
158 <?php if (!empty($attributes['color_text'])): ?>
159 #<?php echo esc_attr($unique_id); ?> .bbpc_search_form_wrapper .input-wrapper input {
160 color:
161 <?php echo esc_attr($attributes['color_text']); ?>
162 ;
163 }
164
165 <?php endif; ?>
166 <?php if (!empty($attributes['color_placeholder'])): ?>
167 #<?php echo esc_attr($unique_id); ?> .bbpc_search_form_wrapper .input-wrapper input::placeholder {
168 color:
169 <?php echo esc_attr($attributes['color_placeholder']); ?>
170 ;
171 }
172
173 <?php endif; ?>
174 <?php if (!empty($attributes['input_bg_color'])): ?>
175 #<?php echo esc_attr($unique_id); ?> .bbpc_search_form_wrapper .input-wrapper input {
176 background-color:
177 <?php echo esc_attr($attributes['input_bg_color']); ?>
178 ;
179 }
180
181 <?php endif; ?>
182 <?php if (!empty($attributes['color_icon'])): ?>
183 #<?php echo esc_attr($unique_id); ?> .bbpc_search_form_wrapper .input-wrapper button {
184 color:
185 <?php echo esc_attr($attributes['color_icon']); ?>
186 ;
187 }
188
189 <?php endif; ?>
190 <?php if (!empty($attributes['search_bg'])): ?>
191 #<?php echo esc_attr($unique_id); ?> .bbpc_search_form_wrapper .input-wrapper button {
192 background:
193 <?php echo esc_attr($attributes['search_bg']); ?>
194 ;
195 }
196
197 <?php endif; ?>
198
199 /* Keywords Styles */
200 <?php if (!empty($attributes['color_keywords_label'])): ?>
201 #<?php echo esc_attr($unique_id); ?> .bbpc-search-keyword span.bbpc-search-keywords-label {
202 color:
203 <?php echo esc_attr($attributes['color_keywords_label']); ?>
204 ;
205 }
206
207 <?php endif; ?>
208 <?php if (!empty($attributes['bbpc_color_keywords'])): ?>
209 #<?php echo esc_attr($unique_id); ?> .bbpc-search-keyword ul li a {
210 color:
211 <?php echo esc_attr($attributes['bbpc_color_keywords']); ?>
212 ;
213 }
214
215 <?php endif; ?>
216 <?php if (!empty($attributes['bbpc_color_keywords_bg'])): ?>
217 #<?php echo esc_attr($unique_id); ?> .bbpc-search-keyword ul li a {
218 background:
219 <?php echo esc_attr($attributes['bbpc_color_keywords_bg']); ?>
220 ;
221 }
222
223 <?php endif; ?>
224 <?php if (!empty($attributes['bbpc_color_keywords_hover'])): ?>
225 #<?php echo esc_attr($unique_id); ?> .bbpc-search-keyword ul li a:hover {
226 color:
227 <?php echo esc_attr($attributes['bbpc_color_keywords_hover']); ?>
228 ;
229 }
230
231 <?php endif; ?>
232 <?php if (!empty($attributes['bbpc_color_keywords_bg_hover'])): ?>
233 #<?php echo esc_attr($unique_id); ?> .bbpc-search-keyword ul li a:hover {
234 background:
235 <?php echo esc_attr($attributes['bbpc_color_keywords_bg_hover']); ?>
236 ;
237 }
238
239 <?php endif; ?>
240
241 /* Input Border & Border Radius */
242 <?php if ( isset( $attributes['input_border_radius'] ) ) : ?>
243 #<?php echo esc_attr( $unique_id ); ?> .bbpc_search_form_wrapper .input-wrapper input {
244 border-radius:
245 <?php echo esc_attr( $attributes['input_border_radius'] ); ?>px
246 ;
247 }
248 <?php endif; ?>
249
250 <?php if ( ! empty( $attributes['input_border_color'] ) ) : ?>
251 #<?php echo esc_attr( $unique_id ); ?> .bbpc_search_form_wrapper .input-wrapper input {
252 border-color:
253 <?php echo esc_attr( $attributes['input_border_color'] ); ?>
254 ;
255 border-style: solid;
256 }
257 <?php endif; ?>
258
259 <?php if ( isset( $attributes['input_border_width'] ) ) : ?>
260 #<?php echo esc_attr( $unique_id ); ?> .bbpc_search_form_wrapper .input-wrapper input {
261 border-width:
262 <?php echo esc_attr( $attributes['input_border_width'] ); ?>px
263 ;
264 border-style: solid;
265 }
266 <?php endif; ?>
267
268 <?php if ( ! empty( $attributes['input_focus_border_color'] ) ) : ?>
269 #<?php echo esc_attr( $unique_id ); ?> .bbpc_search_form_wrapper .input-wrapper input:focus {
270 border-color:
271 <?php echo esc_attr( $attributes['input_focus_border_color'] ); ?>
272 ;
273 outline: none;
274 }
275 <?php endif; ?>
276
277 <?php if ( isset( $attributes['input_height'] ) ) : ?>
278 #<?php echo esc_attr( $unique_id ); ?> .bbpc_search_form_wrapper .input-wrapper input {
279 height:
280 <?php echo esc_attr( $attributes['input_height'] ); ?>px
281 ;
282 }
283 <?php endif; ?>
284
285 /* Wrapper Max Width */
286 <?php if ( isset( $attributes['wrapper_max_width'] ) ) : ?>
287 #<?php echo esc_attr( $unique_id ); ?> .bbpc_search_form_wrapper {
288 max-width:
289 <?php echo esc_attr( $attributes['wrapper_max_width'] ); ?>px
290 ;
291 margin-left: auto;
292 margin-right: auto;
293 }
294 <?php endif; ?>
295
296 /* Button Hover Styles */
297 <?php if ( ! empty( $attributes['btn_hover_color'] ) ) : ?>
298 #<?php echo esc_attr( $unique_id ); ?> .bbpc_search_form_wrapper .input-wrapper button:hover {
299 color:
300 <?php echo esc_attr( $attributes['btn_hover_color'] ); ?>
301 ;
302 }
303 <?php endif; ?>
304
305 <?php if ( ! empty( $attributes['btn_hover_bg'] ) ) : ?>
306 #<?php echo esc_attr( $unique_id ); ?> .bbpc_search_form_wrapper .input-wrapper button:hover {
307 background:
308 <?php echo esc_attr( $attributes['btn_hover_bg'] ); ?>
309 ;
310 }
311 <?php endif; ?>
312
313 <?php if ( isset( $attributes['btn_border_radius'] ) ) : ?>
314 #<?php echo esc_attr( $unique_id ); ?> .bbpc_search_form_wrapper .input-wrapper button {
315 border-radius:
316 <?php echo esc_attr( $attributes['btn_border_radius'] ); ?>px
317 ;
318 }
319 <?php endif; ?>
320
321 /* Search Results Dropdown */
322 <?php if ( ! empty( $attributes['results_bg_color'] ) ) : ?>
323 #<?php echo esc_attr( $unique_id ); ?> #<?php echo esc_attr( $result_id ); ?> {
324 background:
325 <?php echo esc_attr( $attributes['results_bg_color'] ); ?>
326 ;
327 }
328 <?php endif; ?>
329
330 <?php if ( ! empty( $attributes['results_border_color'] ) ) : ?>
331 #<?php echo esc_attr( $unique_id ); ?> #<?php echo esc_attr( $result_id ); ?> {
332 border-color:
333 <?php echo esc_attr( $attributes['results_border_color'] ); ?>
334 ;
335 }
336 <?php endif; ?>
337
338 <?php if ( ! empty( $attributes['results_text_color'] ) ) : ?>
339 #<?php echo esc_attr( $unique_id ); ?> #<?php echo esc_attr( $result_id ); ?>,
340 #<?php echo esc_attr( $unique_id ); ?> #<?php echo esc_attr( $result_id ); ?> a,
341 #<?php echo esc_attr( $unique_id ); ?> .search-result-item a {
342 color:
343 <?php echo esc_attr( $attributes['results_text_color'] ); ?>
344 ;
345 }
346 <?php endif; ?>
347
348 <?php if ( ! empty( $attributes['results_hover_bg'] ) ) : ?>
349 #<?php echo esc_attr( $unique_id ); ?> .search-result-item:hover {
350 background:
351 <?php echo esc_attr( $attributes['results_hover_bg'] ); ?>
352 ;
353 }
354 <?php endif; ?>
355
356 <?php if ( isset( $attributes['results_border_radius'] ) ) : ?>
357 #<?php echo esc_attr( $unique_id ); ?> #<?php echo esc_attr( $result_id ); ?> {
358 border-radius:
359 <?php echo esc_attr( $attributes['results_border_radius'] ); ?>px
360 ;
361 }
362 <?php endif; ?>
363
364 <?php if ( ! empty( $attributes['highlight_bg_color'] ) ) : ?>
365 #<?php echo esc_attr( $unique_id ); ?> .frmx-search-highlight {
366 background-color:
367 <?php echo esc_attr( $attributes['highlight_bg_color'] ); ?>
368 ;
369 }
370 <?php endif; ?>
371
372 <?php if ( ! empty( $attributes['highlight_text_color'] ) ) : ?>
373 #<?php echo esc_attr( $unique_id ); ?> .frmx-search-highlight {
374 color:
375 <?php echo esc_attr( $attributes['highlight_text_color'] ); ?>
376 ;
377 }
378 <?php endif; ?>
379 </style>
380 <?php
381 return ob_get_clean();
382 }
383 }
384