PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 2.4.1
Forumax – AI Powered Advanced Community Forum Plugin v2.4.1
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.1, at includes/Elementor/Search.php

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