PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 2.4.2
Forumax – AI Powered Advanced Community Forum Plugin v2.4.2
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 / Elementor / Search.php

Search.php in Forumax – AI Powered Advanced Community Forum Plugin 2.4.2, at includes/Elementor/Search.php

669 lines 18.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace admin\Elementor;
4
5 use Elementor\Controls_Manager;
6 use Elementor\Group_Control_Typography;
7 use Elementor\Widget_Base;
8 use Elementor\Group_Control_Border;
9
10 // Exit if accessed directly
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 class Search extends Widget_Base {
16 public function get_name() {
17 return 'ama_search';
18 }
19
20 public function get_title() {
21 return esc_html__( 'Search (Forumax)', 'forumax' );
22 }
23
24 public function get_icon() {
25 return 'bbpc_icon_ama_search eicon-search';
26 }
27
28 public function get_style_depends() {
29 return [ 'ama-core-style', 'bbpc-el-widgets' ];
30 }
31
32 public function get_script_depends() {
33 return [ 'bbpc-frontend-js', 'bbpc-frontend-js' ];
34 }
35
36 public function get_categories() {
37 return [ 'forumax' ];
38 }
39
40 protected function register_controls() {
41
42 $this->start_controls_section(
43 'search_form_sec', [
44 'label' => esc_html__( 'Form', 'forumax' ),
45 ]
46 );
47
48 $this->add_control(
49 'placeholder', [
50 'label' => esc_html__( 'Placeholder', 'forumax' ),
51 'type' => Controls_Manager::TEXT,
52 'label_block' => true,
53 'default' => 'Search for Topics....',
54 ]
55 );
56
57 $this->add_control(
58 'search_post_type', [
59 'label' => esc_html__( 'Post Type', 'forumax' ),
60 'type' => Controls_Manager::SELECT,
61 'default' => 'all',
62 'options' => [
63 'all' => esc_html__( 'All (Forums, Topics & Replies)', 'forumax' ),
64 'forum' => esc_html__( 'Forum', 'forumax' ),
65 'topic' => esc_html__( 'Topic', 'forumax' ),
66 'reply' => esc_html__( 'Reply', 'forumax' ),
67 'post' => esc_html__( 'Post', 'forumax' ),
68 'page' => esc_html__( 'Page', 'forumax' ),
69 'docs' => esc_html__( 'Docs', 'forumax' ),
70 ],
71 ]
72 );
73
74 $this->add_control(
75 'is_ajax_search', [
76 'label' => esc_html__( 'AJAX Live Search', 'forumax' ),
77 'description' => esc_html__( 'Show search results instantly as users type without page reload.', 'forumax' ),
78 'type' => Controls_Manager::SWITCHER,
79 'return_value' => 'yes',
80 'default' => '',
81 ]
82 );
83
84 $this->add_control(
85 'search_highlight', [
86 'label' => esc_html__( 'Highlight Keywords', 'forumax' ),
87 'description' => esc_html__( 'Highlight the matching keyword in search results.', 'forumax' ),
88 'type' => Controls_Manager::SWITCHER,
89 'return_value' => 'yes',
90 'default' => '',
91 'condition' => [
92 'is_ajax_search' => 'yes',
93 ],
94 ]
95 );
96
97 // select controls
98 $this->add_control(
99 'submit_btn_type', [
100 'label' => __( 'Search Type', 'forumax' ),
101 'type' => \Elementor\Controls_Manager::SELECT,
102 'default' => 'icon',
103 'options' => [
104 'icon' => __( 'Icon', 'forumax' ),
105 'text' => __( 'Text', 'forumax' )
106 ],
107 ]
108 );
109
110 $this->add_control(
111 'submit_btn_icon', [
112 'label' => __( 'Submit Button Icon', 'forumax' ),
113 'type' => \Elementor\Controls_Manager::ICONS,
114 'default' => [
115 'value' => 'fas fa-search',
116 'library' => 'solid',
117 ],
118 'condition' => [
119 'submit_btn_type' => 'icon'
120 ]
121 ]
122 );
123
124 $this->add_control(
125 'submit_btn_text', [
126 'label' => esc_html__( 'Submit Button Text', 'forumax' ),
127 'type' => Controls_Manager::TEXT,
128 'label_block' => true,
129 'default' => __( 'Search', 'forumax' ),
130 'condition' => [
131 'submit_btn_type' => 'text'
132 ]
133 ]
134 );
135
136 $this->add_control(
137 'submit_btn_align', [
138 'label' => __( 'Submit Alignment', 'forumax' ),
139 'type' => \Elementor\Controls_Manager::CHOOSE,
140 'options' => [
141 'left' => [
142 'title' => __( 'Left', 'forumax' ),
143 'icon' => 'fa fa-align-left',
144 ],
145 'right' => [
146 'title' => __( 'Right', 'forumax' ),
147 'icon' => 'fa fa-align-right',
148 ],
149 ],
150 'toggle' => false,
151 'default' => 'left',
152 ]
153 );
154
155 $this->add_control(
156 'is_keywords', [
157 'label' => esc_html__( 'Keywords', 'forumax' ),
158 'type' => \Elementor\Controls_Manager::SWITCHER,
159 'return_value' => 'yes',
160 'default' => 'yes',
161 'separator' => 'before',
162 ]
163 );
164
165 $this->add_control(
166 'keywords_label',
167 [
168 'label' => esc_html__( 'Keywords Label', 'forumax' ),
169 'type' => Controls_Manager::TEXT,
170 'label_block' => true,
171 'default' => 'Popular:',
172 'condition' => [
173 'is_keywords' => 'yes'
174 ]
175 ]
176 );
177
178 $this->add_control(
179 'keywords_align', [
180 'label' => __( 'Keywords Alignment', 'forumax' ),
181 'type' => \Elementor\Controls_Manager::CHOOSE,
182 'options' => [
183 'left' => [
184 'title' => __( 'Left', 'forumax' ),
185 'icon' => 'fa fa-align-left',
186 ],
187 'center' => [
188 'title' => __( 'Center', 'forumax' ),
189 'icon' => 'fa fa-align-center',
190 ],
191 'right' => [
192 'title' => __( 'Right', 'forumax' ),
193 'icon' => 'fa fa-align-right',
194 ],
195 ],
196 'toggle' => false,
197 'default' => 'center'
198 ]
199 );
200
201 $keywords = new \Elementor\Repeater();
202
203 $keywords->add_control(
204 'title', [
205 'label' => __( 'Title', 'forumax' ),
206 'type' => \Elementor\Controls_Manager::TEXT,
207 'label_block' => true,
208 ]
209 );
210
211 $this->add_control(
212 'keywords',
213 [
214 'label' => __( 'Repeater List', 'forumax' ),
215 'type' => \Elementor\Controls_Manager::REPEATER,
216 'fields' => $keywords->get_controls(),
217 'default' => [
218 [
219 'title' => __( 'Keyword #1', 'forumax' ),
220 ],
221 [
222 'title' => __( 'Keyword #2', 'forumax' ),
223 ],
224 ],
225 'title_field' => '{{{ title }}}',
226 'prevent_empty' => false,
227 'condition' => [
228 'is_keywords' => 'yes'
229 ]
230 ]
231 );
232
233 $this->end_controls_section();
234
235 /**
236 * Style Keywords
237 * Global
238 */
239 $this->start_controls_section(
240 'style_form', [
241 'label' => esc_html__( 'Form', 'forumax' ),
242 'tab' => Controls_Manager::TAB_STYLE,
243 ]
244 );
245
246 $this->add_control(
247 'input_heading_form', [
248 'label' => esc_html__( 'Input', 'forumax' ),
249 'type' => Controls_Manager::HEADING
250 ]
251 );
252
253 $this->add_control(
254 'color_text', [
255 'label' => esc_html__( 'Text Color', 'forumax' ),
256 'type' => Controls_Manager::COLOR,
257 'selectors' => [
258 '{{WRAPPER}} .bbpc_search_form_wrapper .input-wrapper input' => 'color: {{VALUE}};',
259 ]
260 ]
261 );
262
263 $this->add_control(
264 'color_placeholder', [
265 'label' => esc_html__( 'Placeholder Color', 'forumax' ),
266 'type' => Controls_Manager::COLOR,
267 'selectors' => [
268 '{{WRAPPER}} .bbpc_search_form_wrapper .input-wrapper input::placeholder' => 'color: {{VALUE}};',
269 ],
270 ]
271 );
272
273 $this->add_group_control(
274 Group_Control_Border::get_type(), [
275 'name' => 'input_border',
276 'label' => esc_html__( 'Border', 'forumax' ),
277 'selector' => '{{WRAPPER}} .bbpc_search_form_wrapper .input-wrapper input',
278 ]
279 );
280
281 $this->add_control(
282 'input_bg_color', [
283 'label' => esc_html__( 'Background Color', 'forumax' ),
284 'type' => Controls_Manager::COLOR,
285 'selectors' => [
286 '{{WRAPPER}} .bbpc_search_form_wrapper .input-wrapper input' => 'background-color: {{VALUE}};',
287 ],
288 ]
289 );
290
291 $this->add_group_control(
292 Group_Control_Typography::get_type(), [
293 'name' => 'typography_placeholder',
294 'label' => esc_html__( 'Typography', 'forumax' ),
295 'selector' => '{{WRAPPER}} .bbpc_search_form_wrapper .input-wrapper input::placeholder, .bbpc_search_form_wrapper .input-wrapper input',
296 ]
297 );
298
299 $this->add_responsive_control(
300 'input-padding', [
301 'label' => esc_html__( 'Padding', 'forumax' ),
302 'type' => Controls_Manager::DIMENSIONS,
303 'size_units' => [ 'px', '%', 'em' ],
304 'selectors' => [
305 '{{WRAPPER}} .bbpc_search_form_wrapper .input-wrapper input' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};'
306 ]
307 ]
308 );
309
310 $this->add_responsive_control(
311 'input-border-radius', [
312 'label' => __( 'Border Radius', 'forumax' ),
313 'type' => Controls_Manager::DIMENSIONS,
314 'size_units' => [ 'px', '%', 'em' ],
315 'selectors' => [
316 '{{WRAPPER}} .bbpc_search_form_wrapper .input-wrapper input' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
317 ],
318 ]
319 );
320
321 $this->add_control(
322 'submit_heading_form', [
323 'label' => esc_html__( 'Submit', 'forumax' ),
324 'type' => Controls_Manager::HEADING,
325 'separator' => 'before'
326 ]
327 );
328
329 $this->add_control(
330 'color_icon', [
331 'label' => esc_html__( 'Button Color', 'forumax' ),
332 'type' => Controls_Manager::COLOR,
333 'selectors' => [
334 '{{WRAPPER}} .bbpc_search_form_wrapper .input-wrapper button' => 'color: {{VALUE}};',
335 ],
336 ]
337 );
338
339
340 $this->add_control(
341 'search_bg',
342 [
343 'label' => __( 'Background', 'forumax' ),
344 'type' => \Elementor\Controls_Manager::COLOR,
345 'selectors' => [
346 '{{WRAPPER}} .bbpc_search_form_wrapper .input-wrapper button' => 'background: {{VALUE}}',
347 ],
348 ]
349 );
350
351 $this->add_responsive_control(
352 'btn-padding', [
353 'label' => esc_html__( 'Padding', 'forumax' ),
354 'type' => Controls_Manager::DIMENSIONS,
355 'size_units' => [ 'px', '%', 'em' ],
356 'selectors' => [
357 '{{WRAPPER}} .bbpc_search_form_wrapper .input-wrapper button' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};'
358 ]
359 ]
360 );
361
362 $this->add_responsive_control(
363 'btn-border-radius', [
364 'label' => __( 'Border Radius', 'forumax' ),
365 'type' => Controls_Manager::DIMENSIONS,
366 'size_units' => [ 'px', '%', 'em' ],
367 'selectors' => [
368 '{{WRAPPER}} .bbpc_search_form_wrapper .input-wrapper button' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
369 ],
370 ]
371 );
372
373 // slider controls
374 $this->add_control(
375 'typography_btn', [
376 'label' => esc_html__( 'Icon Size', 'forumax' ),
377 'type' => Controls_Manager::SLIDER,
378 'range' => [
379 'px' => [
380 'min' => 10,
381 'max' => 100,
382 ],
383 ],
384 'selectors' => [
385 '{{WRAPPER}} .bbpc_search_form_wrapper .input-wrapper button i' => 'font-size: {{SIZE}}{{UNIT}};'
386 ],
387 'condition' => [
388 'submit_btn_type' => 'icon'
389 ],
390 ]
391 );
392
393
394 // Spacing slider when icon is on the LEFT.
395 $this->add_control(
396 'submit_btn_align_left', [
397 'label' => esc_html__( 'Spacing', 'forumax' ),
398 'type' => Controls_Manager::SLIDER,
399 'range' => [
400 'px' => [
401 'min' => 0,
402 'max' => 100,
403 ],
404 ],
405 'selectors' => [
406 '{{WRAPPER}} .bbpc_search_form_wrapper .input-wrapper .submit-btn-left' => 'left: {{SIZE}}{{UNIT}};',
407 ],
408 'condition' => [
409 'submit_btn_align' => 'left',
410 ],
411 ]
412 );
413
414 // Spacing slider when icon is on the RIGHT.
415 $this->add_control(
416 'submit_btn_align_right', [
417 'label' => esc_html__( 'Spacing', 'forumax' ),
418 'type' => Controls_Manager::SLIDER,
419 'range' => [
420 'px' => [
421 'min' => 0,
422 'max' => 100,
423 ],
424 ],
425 'selectors' => [
426 '{{WRAPPER}} .bbpc_search_form_wrapper .input-wrapper .submit-btn-right' => 'right: {{SIZE}}{{UNIT}};',
427 ],
428 'condition' => [
429 'submit_btn_align' => 'right',
430 ],
431 ]
432 );
433
434 // typography controls
435 $this->add_group_control(
436 Group_Control_Typography::get_type(), [
437 'name' => 'typography_btn',
438 'label' => esc_html__( 'Typography', 'forumax' ),
439 'condition' => [
440 'submit_btn_type' => 'text'
441 ],
442 'selector' => '{{WRAPPER}} .bbpc_search_form_wrapper .input-wrapper button',
443 ]
444 );
445
446 $this->end_controls_section();
447
448 $this->start_controls_section(
449 'style_keywords', [
450 'label' => esc_html__( 'Keywords', 'forumax' ),
451 'tab' => Controls_Manager::TAB_STYLE,
452 ]
453 );
454
455 $this->add_control(
456 'margin_keywords', [
457 'label' => __( 'Margin', 'forumax' ),
458 'description' => __( 'Margin around the keywords block', 'forumax' ),
459 'type' => Controls_Manager::DIMENSIONS,
460 'size_units' => [ 'px', '%', 'em' ],
461 'selectors' => [ '{{WRAPPER}} .bbpc-search-keyword ul li' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ],
462 'separator' => 'before',
463 'default' => [
464 'unit' => 'px',
465 ],
466 ]
467 );
468
469 $this->add_control(
470 'color_keywords_label', [
471 'label' => esc_html__( 'Label Color', 'forumax' ),
472 'type' => Controls_Manager::COLOR,
473 'selectors' => [
474 '{{WRAPPER}} .bbpc-search-keyword span.bbpc-search-keywords-label' => 'color: {{VALUE}};',
475 ],
476 ]
477 );
478
479 $this->add_group_control(
480 \Elementor\Group_Control_Typography::get_type(),
481 [
482 'name' => 'keyword_label_typography',
483 'label' => __( 'Label Typography', 'forumax' ),
484 'selector' => '{{WRAPPER}} .bbpc-search-keyword span.bbpc-search-keywords-label',
485 ]
486 );
487
488 $this->start_controls_tabs(
489 'bbpc_tabs_keywords_style'
490 );
491
492 $this->start_controls_tab(
493 'bbpc_keywords_style',
494 [
495 'label' => esc_html__( 'Normal', 'forumax' ),
496 ]
497 );
498
499 $this->add_control(
500 'bbpc_color_keywords', [
501 'label' => esc_html__( 'Keyword Color', 'forumax' ),
502 'type' => Controls_Manager::COLOR,
503 'separator' => 'before',
504 'selectors' => [
505 '{{WRAPPER}} .bbpc-search-keyword ul li a' => 'color: {{VALUE}};',
506 ],
507 ]
508 );
509
510 $this->add_control(
511 'bbpc_color_keywords_bg', [
512 'label' => esc_html__( 'Background Color', 'forumax' ),
513 'type' => Controls_Manager::COLOR,
514 'separator' => 'after',
515 'selectors' => [
516 '{{WRAPPER}} .bbpc-search-keyword ul li a' => 'background: {{VALUE}};',
517 ],
518 ]
519 );
520
521 $this->end_controls_tab();
522
523 $this->start_controls_tab(
524 'bbpc_keywords_style_hover',
525 [
526 'label' => esc_html__( 'Hover', 'forumax' ),
527 ]
528 );
529
530 $this->add_control(
531 'bbpc_color_keywords_hover', [
532 'label' => esc_html__( 'Keyword Color', 'forumax' ),
533 'type' => Controls_Manager::COLOR,
534 'selectors' => [
535 '{{WRAPPER}} .bbpc-search-keyword ul li a:hover' => 'color: {{VALUE}};',
536 ],
537 ]
538 );
539
540 $this->add_control(
541 'bbpc_color_keywords_bg_hover', [
542 'label' => esc_html__( 'Background Color', 'forumax' ),
543 'type' => Controls_Manager::COLOR,
544 'selectors' => [
545 '{{WRAPPER}} .bbpc-search-keyword ul li a:hover' => 'background: {{VALUE}};',
546 ],
547 ]
548 );
549
550 $this->end_controls_tabs();
551
552
553 $this->add_group_control(
554 Group_Control_Typography::get_type(), [
555 'name' => 'typography_keywords',
556 'label' => esc_html__( 'Typography', 'forumax' ),
557 'selector' => '{{WRAPPER}} .bbpc-search-keyword ul li a',
558 ]
559 );
560
561 $this->add_control(
562 'keywords_padding', [
563 'label' => __( 'Padding', 'forumax' ),
564 'type' => Controls_Manager::DIMENSIONS,
565 'size_units' => [ 'px', '%', 'em' ],
566 'selectors' => [ '{{WRAPPER}} .bbpc-search-keyword ul li a' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ],
567 'default' => [
568 'unit' => 'px',
569 ],
570 ]
571 );
572
573 $this->add_control(
574 'border_radius', [
575 'label' => __( 'Border Radius', 'forumax' ),
576 'type' => Controls_Manager::DIMENSIONS,
577 'size_units' => [ 'px', '%', 'em' ],
578 'selectors' => [ '{{WRAPPER}} .bbpc-search-keyword ul li a' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ],
579 'default' => [
580 'unit' => 'px',
581 ],
582 ]
583 );
584
585 $this->end_controls_section();
586
587 }
588
589 protected function render() {
590 $settings = $this->get_settings();
591 $widget_id = 'frmx-search-' . $this->get_id();
592 $input_id = $widget_id . '-input';
593 $result_id = $widget_id . '-result';
594 $post_type_id = $widget_id . '-post-type';
595
596 /*
597 * $btn_position holds the raw saved value: 'left' or 'right'.
598 * It is used directly — no inversion needed — so the span class
599 * and the input-wrapper class both reflect the actual chosen side.
600 */
601 $btn_position = $settings['submit_btn_align'] ?? 'left';
602
603 $search_post_type = ! empty( $settings['search_post_type'] ) ? $settings['search_post_type'] : 'all';
604 $is_ajax_search = ! empty( $settings['is_ajax_search'] ) ? 'true' : 'false';
605 $search_highlight = ! empty( $settings['search_highlight'] ) ? 'true' : 'false';
606 ?>
607
608 <div class="bbpc-search-overlay" data-widget-id="<?php echo esc_attr( $widget_id ); ?>"></div>
609
610 <form
611 action="<?php echo esc_url( bbp_get_search_url() ); ?>"
612 role="search"
613 method="get"
614 class="bbpc_search_form_wrapper"
615 data-widget-id="<?php echo esc_attr( $widget_id ); ?>"
616 data-input-id="<?php echo esc_attr( $input_id ); ?>"
617 data-result-id="<?php echo esc_attr( $result_id ); ?>"
618 >
619 <div class="form-group">
620 <div class="input-wrapper <?php echo esc_attr( $btn_position ); ?>">
621
622 <span class="submit-btn-<?php echo esc_attr( $btn_position ); ?>">
623 <button type="submit">
624 <?php
625 $submit_btn = $settings['submit_btn_type'] ?? 'icon';
626 if ( 'icon' === $submit_btn ) {
627 \Elementor\Icons_Manager::render_icon( $settings['submit_btn_icon'], [ 'aria-hidden' => 'true' ] );
628 } else {
629 echo esc_html( $settings['submit_btn_text'] );
630 }
631 ?>
632 </button>
633 </span>
634
635 <!-- bbPress search request sentinel -->
636 <input type="hidden" name="action" value="bbp-search-request" />
637
638 <input
639 type="search"
640 id="<?php echo esc_attr( $input_id ); ?>"
641 class="frmx-search-input"
642 autocomplete="off"
643 name="bbp_search"
644 placeholder="<?php echo esc_attr( $settings['placeholder'] ); ?>"
645 data-post-type="<?php echo esc_attr( $search_post_type ); ?>"
646 data-ajax-search="<?php echo esc_attr( $is_ajax_search ); ?>"
647 data-highlight="<?php echo esc_attr( $search_highlight ); ?>"
648 data-result-id="<?php echo esc_attr( $result_id ); ?>"
649 >
650
651 <!-- Ajax Search Loading Spinner -->
652 <?php include( 'Search/search-spinner.php' ); ?>
653
654 <!-- WPML Language Code -->
655 <?php if ( defined( 'ICL_LANGUAGE_CODE' ) ) : ?>
656 <input type="hidden" name="lang" value="<?php echo esc_attr( ICL_LANGUAGE_CODE ); ?>"/>
657 <?php endif; ?>
658 </div>
659 </div>
660 <?php
661 // Pass unique result ID to the partials via a local variable.
662 $frmx_result_id = $result_id;
663 include 'Search/ajax-sarch-results.php';
664 include 'Search/keywords.php';
665 ?>
666 </form>
667 <?php
668 }
669 }