PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 1.1.0
Forumax – AI Powered Advanced Community Forum Plugin v1.1.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 / Elementor / Search.php

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

593 lines 16.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\Core\Schemes\Typography;
7 use Elementor\Group_Control_Typography;
8 use Elementor\Widget_Base;
9 use Elementor\Group_Control_Border;
10
11 // Exit if accessed directly
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit;
14 }
15
16 class Search extends Widget_Base {
17 public function get_name() {
18 return 'ama_search';
19 }
20
21 public function get_title() {
22 return esc_html__( 'BBPC Search', 'bbp-core' );
23 }
24
25 public function get_icon() {
26 return 'bbpc_icon_ama_search';
27 }
28
29 public function get_style_depends() {
30 return [ 'ama-core-style' ];
31 }
32
33 public function get_script_depends() {
34 return [ 'bbpc-frontend-js' ];
35 }
36
37 public function get_categories() {
38 return [ 'bbp-core' ];
39 }
40
41 protected function register_controls() {
42
43 $this->start_controls_section(
44 'search_form_sec', [
45 'label' => esc_html__( 'Form', 'bbp-core' ),
46 ]
47 );
48
49 $this->add_control(
50 'placeholder', [
51 'label' => esc_html__( 'Placeholder', 'bbp-core' ),
52 'type' => Controls_Manager::TEXT,
53 'label_block' => true,
54 'default' => 'Search for Topics....',
55 ]
56 );
57
58 // select controls
59 $this->add_control(
60 'submit_btn_type', [
61 'label' => __( 'Search Type', 'bbp-core' ),
62 'type' => \Elementor\Controls_Manager::SELECT,
63 'default' => 'icon',
64 'options' => [
65 'icon' => __( 'Icon', 'bbp-core' ),
66 'text' => __( 'Text', 'bbp-core' )
67 ],
68 ]
69 );
70
71 $this->add_control(
72 'submit_btn_icon', [
73 'label' => __( 'Submit Button Icon', 'bbp-core' ),
74 'type' => \Elementor\Controls_Manager::ICONS,
75 'default' => [
76 'value' => 'fas fa-search',
77 'library' => 'solid',
78 ],
79 'condition' => [
80 'submit_btn_type' => 'icon'
81 ]
82 ]
83 );
84
85 $this->add_control(
86 'submit_btn_text', [
87 'label' => esc_html__( 'Submit Button Text', 'bbp-core' ),
88 'type' => Controls_Manager::TEXT,
89 'label_block' => true,
90 'default' => __( 'Search', 'bbp-core' ),
91 'condition' => [
92 'submit_btn_type' => 'text'
93 ]
94 ]
95 );
96
97 $this->add_control(
98 'submit_btn_align', [
99 'label' => __( 'Submit Alignment', 'bbp-core' ),
100 'type' => \Elementor\Controls_Manager::CHOOSE,
101 'options' => [
102 'right' => [
103 'title' => __( 'Left', 'bbp-core' ),
104 'icon' => 'fa fa-align-left',
105 ],
106 'left' => [
107 'title' => __( 'Right', 'bbp-core' ),
108 'icon' => 'fa fa-align-right',
109 ],
110 ],
111 'toggle' => false,
112 'default' => 'left'
113 ]
114 );
115
116 $this->add_control(
117 'is_keywords', [
118 'label' => esc_html__( 'Keywords', 'bbp-core' ),
119 'type' => \Elementor\Controls_Manager::SWITCHER,
120 'return_value' => 'yes',
121 'default' => 'yes',
122 'separator' => 'before',
123 ]
124 );
125
126 $this->add_control(
127 'keywords_label',
128 [
129 'label' => esc_html__( 'Keywords Label', 'bbp-core' ),
130 'type' => Controls_Manager::TEXT,
131 'label_block' => true,
132 'default' => 'Popular:',
133 'condition' => [
134 'is_keywords' => 'yes'
135 ]
136 ]
137 );
138
139 $this->add_control(
140 'keywords_align', [
141 'label' => __( 'Keywords Alignment', 'bbp-core' ),
142 'type' => \Elementor\Controls_Manager::CHOOSE,
143 'options' => [
144 'left' => [
145 'title' => __( 'Left', 'bbp-core' ),
146 'icon' => 'fa fa-align-left',
147 ],
148 'center' => [
149 'title' => __( 'Center', 'bbp-core' ),
150 'icon' => 'fa fa-align-center',
151 ],
152 'right' => [
153 'title' => __( 'Right', 'bbp-core' ),
154 'icon' => 'fa fa-align-right',
155 ],
156 ],
157 'toggle' => false,
158 'default' => 'center'
159 ]
160 );
161
162 $keywords = new \Elementor\Repeater();
163
164 $keywords->add_control(
165 'title', [
166 'label' => __( 'Title', 'bbp-core' ),
167 'type' => \Elementor\Controls_Manager::TEXT,
168 'label_block' => true,
169 ]
170 );
171
172 $this->add_control(
173 'keywords',
174 [
175 'label' => __( 'Repeater List', 'bbp-core' ),
176 'type' => \Elementor\Controls_Manager::REPEATER,
177 'fields' => $keywords->get_controls(),
178 'default' => [
179 [
180 'title' => __( 'Keyword #1', 'bbp-core' ),
181 ],
182 [
183 'title' => __( 'Keyword #2', 'bbp-core' ),
184 ],
185 ],
186 'title_field' => '{{{ title }}}',
187 'prevent_empty' => false,
188 'condition' => [
189 'is_keywords' => 'yes'
190 ]
191 ]
192 );
193
194 $this->end_controls_section();
195
196 /**
197 * Style Keywords
198 * Global
199 */
200 $this->start_controls_section(
201 'style_form', [
202 'label' => esc_html__( 'Form', 'bbp-core' ),
203 'tab' => Controls_Manager::TAB_STYLE,
204 ]
205 );
206
207 $this->add_control(
208 'input_heading_form', [
209 'label' => esc_html__( 'Input', 'bbp-core' ),
210 'type' => Controls_Manager::HEADING
211 ]
212 );
213
214 $this->add_control(
215 'color_text', [
216 'label' => esc_html__( 'Text Color', 'bbp-core' ),
217 'type' => Controls_Manager::COLOR,
218 'selectors' => [
219 '{{WRAPPER}} .bbpc_search_form_wrapper .input-wrapper input' => 'color: {{VALUE}};',
220 ]
221 ]
222 );
223
224 $this->add_control(
225 'color_placeholder', [
226 'label' => esc_html__( 'Placeholder Color', 'bbp-core' ),
227 'type' => Controls_Manager::COLOR,
228 'selectors' => [
229 '{{WRAPPER}} .bbpc_search_form_wrapper .input-wrapper input::placeholder' => 'color: {{VALUE}};',
230 ],
231 ]
232 );
233
234 $this->add_group_control(
235 Group_Control_Border::get_type(), [
236 'name' => 'input_border',
237 'label' => esc_html__( 'Border', 'bbp-core' ),
238 'selector' => '{{WRAPPER}} .bbpc_search_form_wrapper .input-wrapper input',
239 ]
240 );
241
242 $this->add_control(
243 'input_bg_color', [
244 'label' => esc_html__( 'Background Color', 'bbp-core' ),
245 'type' => Controls_Manager::COLOR,
246 'selectors' => [
247 '{{WRAPPER}} .bbpc_search_form_wrapper .input-wrapper input' => 'background-color: {{VALUE}};',
248 ],
249 ]
250 );
251
252 $this->add_group_control(
253 Group_Control_Typography::get_type(), [
254 'name' => 'typography_placeholder',
255 'label' => esc_html__( 'Typography', 'bbp-core' ),
256 'scheme' => Typography::TYPOGRAPHY_1,
257 'selector' => '{{WRAPPER}} .bbpc_search_form_wrapper .input-wrapper input::placeholder, .bbpc_search_form_wrapper .input-wrapper input',
258 ]
259 );
260
261 $this->add_responsive_control(
262 'input-padding', [
263 'label' => esc_html__( 'Padding', 'bbp-core' ),
264 'type' => Controls_Manager::DIMENSIONS,
265 'size_units' => [ 'px', '%', 'em' ],
266 'selectors' => [
267 '{{WRAPPER}} .bbpc_search_form_wrapper .input-wrapper input' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};'
268 ]
269 ]
270 );
271
272 $this->add_responsive_control(
273 'input-border-radius', [
274 'label' => __( 'Border Radius', 'bbp-core' ),
275 'type' => Controls_Manager::DIMENSIONS,
276 'size_units' => [ 'px', '%', 'em' ],
277 'selectors' => [
278 '{{WRAPPER}} .bbpc_search_form_wrapper .input-wrapper input' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
279 ],
280 ]
281 );
282
283 $this->add_control(
284 'submit_heading_form', [
285 'label' => esc_html__( 'Submit', 'bbp-core' ),
286 'type' => Controls_Manager::HEADING,
287 'separator' => 'before'
288 ]
289 );
290
291 $this->add_control(
292 'color_icon', [
293 'label' => esc_html__( 'Button Color', 'bbp-core' ),
294 'type' => Controls_Manager::COLOR,
295 'selectors' => [
296 '{{WRAPPER}} .bbpc_search_form_wrapper .input-wrapper button' => 'color: {{VALUE}};',
297 ],
298 ]
299 );
300
301
302 $this->add_control(
303 'search_bg',
304 [
305 'label' => __( 'Background', 'bbp-core' ),
306 'type' => \Elementor\Controls_Manager::COLOR,
307 'selectors' => [
308 '{{WRAPPER}} .bbpc_search_form_wrapper .input-wrapper button' => 'background: {{VALUE}}',
309 ],
310 ]
311 );
312
313 $this->add_responsive_control(
314 'btn-padding', [
315 'label' => esc_html__( 'Padding', 'bbp-core' ),
316 'type' => Controls_Manager::DIMENSIONS,
317 'size_units' => [ 'px', '%', 'em' ],
318 'selectors' => [
319 '{{WRAPPER}} .bbpc_search_form_wrapper .input-wrapper button' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};'
320 ]
321 ]
322 );
323
324 $this->add_responsive_control(
325 'btn-border-radius', [
326 'label' => __( 'Border Radius', 'bbp-core' ),
327 'type' => Controls_Manager::DIMENSIONS,
328 'size_units' => [ 'px', '%', 'em' ],
329 'selectors' => [
330 '{{WRAPPER}} .bbpc_search_form_wrapper .input-wrapper button' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
331 ],
332 ]
333 );
334
335 // slider controls
336 $this->add_control(
337 'typography_btn', [
338 'label' => esc_html__( 'Icon Size', 'bbp-core' ),
339 'type' => Controls_Manager::SLIDER,
340 'range' => [
341 'px' => [
342 'min' => 10,
343 'max' => 100,
344 ],
345 ],
346 'selectors' => [
347 '{{WRAPPER}} .bbpc_search_form_wrapper .input-wrapper button i' => 'font-size: {{SIZE}}{{UNIT}};'
348 ],
349 'condition' => [
350 'submit_btn_type' => 'icon'
351 ],
352 ]
353 );
354
355
356 // slider controls
357 $this->add_control(
358 'submit_btn_align_left', [
359 'label' => esc_html__( 'Spacing', 'bbp-core' ),
360 'type' => Controls_Manager::SLIDER,
361 'range' => [
362 'px' => [
363 'min' => 10,
364 'max' => 100,
365 ],
366 ],
367 'selectors' => [
368 '{{WRAPPER}} .bbpc_search_form_wrapper .input-wrapper .submit-btn-left' => 'right: {{SIZE}}{{UNIT}};',
369 ],
370 'condition' => [
371 'submit_btn_align' => 'left'
372 ],
373 ]
374 );
375
376
377 // slider controls
378 $this->add_control(
379 'submit_btn_align_right', [
380 'label' => esc_html__( 'Spacing', 'bbp-core' ),
381 'type' => Controls_Manager::SLIDER,
382 'range' => [
383 'px' => [
384 'min' => 10,
385 'max' => 100,
386 ],
387 ],
388 'selectors' => [
389 '{{WRAPPER}} .bbpc_search_form_wrapper .input-wrapper .submit-btn-right' => 'left: {{SIZE}}{{UNIT}};',
390 ],
391 'condition' => [
392 'submit_btn_align' => 'right'
393 ],
394 ]
395 );
396
397 // typography controls
398 $this->add_group_control(
399 Group_Control_Typography::get_type(), [
400 'name' => 'typography_btn',
401 'label' => esc_html__( 'Typography', 'bbp-core' ),
402 'scheme' => Typography::TYPOGRAPHY_1,
403 'condition' => [
404 'submit_btn_type' => 'text'
405 ],
406 'selector' => '{{WRAPPER}} .bbpc_search_form_wrapper .input-wrapper button',
407 ]
408 );
409
410 $this->end_controls_section();
411
412 $this->start_controls_section(
413 'style_keywords', [
414 'label' => esc_html__( 'Keywords', 'bbp-core' ),
415 'tab' => Controls_Manager::TAB_STYLE,
416 ]
417 );
418
419 $this->add_control(
420 'margin_keywords', [
421 'label' => __( 'Margin', 'bbp-core' ),
422 'description' => __( 'Margin around the keywords block', 'bbp-core' ),
423 'type' => Controls_Manager::DIMENSIONS,
424 'size_units' => [ 'px', '%', 'em' ],
425 'selectors' => [ '{{WRAPPER}} .bbpc-search-keyword ul li' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ],
426 'separator' => 'before',
427 'default' => [
428 'unit' => 'px', // The selected CSS Unit. 'px', '%', 'em',
429 ],
430 ]
431 );
432
433 $this->add_control(
434 'color_keywords_label', [
435 'label' => esc_html__( 'Label Color', 'bbp-core' ),
436 'type' => Controls_Manager::COLOR,
437 'selectors' => [
438 '{{WRAPPER}} .bbpc-search-keyword span.bbpc-search-keywords-label' => 'color: {{VALUE}};',
439 ],
440 ]
441 );
442
443 $this->add_group_control(
444 \Elementor\Group_Control_Typography::get_type(),
445 [
446 'name' => 'keyword_label_typography',
447 'label' => __( 'Label Typography', 'bbp-core' ),
448 'scheme' => \Elementor\Core\Schemes\Typography::TYPOGRAPHY_1,
449 'selector' => '{{WRAPPER}} .bbpc-search-keyword span.bbpc-search-keywords-label',
450 ]
451 );
452
453 $this->add_control(
454 'color_keywords', [
455 'label' => esc_html__( 'Keyword Color', 'bbp-core' ),
456 'type' => Controls_Manager::COLOR,
457 'separator' => 'before',
458 'selectors' => [
459 '{{WRAPPER}} .bbpc-search-keyword ul li a' => 'color: {{VALUE}};',
460 ],
461 ]
462 );
463
464 $this->add_control(
465 'color_keywords_bg', [
466 'label' => esc_html__( 'Background Color', 'bbp-core' ),
467 'type' => Controls_Manager::COLOR,
468 'selectors' => [
469 '{{WRAPPER}} .bbpc-search-keyword ul li a' => 'background: {{VALUE}};',
470 ],
471 ]
472 );
473
474
475 $this->add_group_control(
476 Group_Control_Typography::get_type(), [
477 'name' => 'typography_keywords',
478 'label' => esc_html__( 'Typography', 'bbp-core' ),
479 'scheme' => Typography::TYPOGRAPHY_1,
480 'selector' => '{{WRAPPER}} .bbpc-search-keyword ul li a',
481 ]
482 );
483
484 $this->add_control(
485 'keywords_padding', [
486 'label' => __( 'Padding', 'bbp-core' ),
487 'type' => Controls_Manager::DIMENSIONS,
488 'size_units' => [ 'px', '%', 'em' ],
489 'selectors' => [ '{{WRAPPER}} .bbpc-search-keyword ul li a' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ],
490 'default' => [
491 'unit' => 'px', // The selected CSS Unit. 'px', '%', 'em',
492 ],
493 ]
494 );
495
496 $this->add_control(
497 'border_radius', [
498 'label' => __( 'Border Radius', 'bbp-core' ),
499 'type' => Controls_Manager::DIMENSIONS,
500 'size_units' => [ 'px', '%', 'em' ],
501 'selectors' => [ '{{WRAPPER}} .bbpc-search-keyword ul li a' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ],
502 'default' => [
503 'unit' => 'px', // The selected CSS Unit. 'px', '%', 'em',
504 ],
505 ]
506 );
507
508 $this->end_controls_section();
509
510 }
511
512 protected function render() {
513 $settings = $this->get_settings();
514 $title_tag = ! empty( $settings['title_tag'] ) ? $settings['title_tag'] : 'h2';
515 $cross_position = $settings['submit_btn_align'] ?? 'right';
516 if ( $cross_position == 'right' ) {
517 $cross_position = 'left';
518 } else {
519 $cross_position = 'right';
520 }
521 ?>
522
523 <form action="<?php echo esc_url( home_url( '/' ) ) ?>" role="search" method="get" class="bbpc_search_form_wrapper">
524 <div class="form-group">
525 <div class="input-wrapper <?php echo esc_attr( $cross_position ); ?>">
526
527 <span class="submit-btn-<?php echo esc_attr( $settings['submit_btn_align'] ?? 'left' ); ?>">
528 <button type="submit">
529 <?php
530 $submit_btn = $settings['submit_btn_type'] ?? 'icon';
531 if ( $submit_btn == 'icon' ) {
532 \Elementor\Icons_Manager::render_icon( $settings['submit_btn_icon'], [ 'aria-hidden' => 'true' ] );
533 } else {
534 echo esc_html( $settings['submit_btn_text'] );
535 }
536 ?>
537 </button>
538 </span>
539
540 <input type='search' id="searchInput" autocomplete="off" name="s" placeholder="<?php echo esc_attr( $settings['placeholder'] ) ?>">
541
542 <!-- Ajax Search Loading Spinner -->
543 <?php include( 'Search/search-spinner.php' ); ?>
544
545 <!-- WPML Language Code -->
546 <?php if ( defined( 'ICL_LANGUAGE_CODE' ) ) : ?>
547 <input type="hidden" name="lang" value="<?php echo( ICL_LANGUAGE_CODE ); ?>"/>
548 <?php endif; ?>
549
550 <input type="hidden" id="hidden_post_type" name="post_type" value="docs"/>
551 </div>
552 </div>
553 <?php include( 'Search/ajax-sarch-results.php' ); ?>
554 <?php include( 'Search/keywords.php' ); ?>
555 </form>
556
557 <script>
558 ;(function($){
559 $(document).ready(function(){
560 // Focus in search input
561 $('.bbpc_search_form_wrapper').focusin(function () {
562
563 if ( $('body .body_wrapper').length > 0 ) {
564 $('body .body_wrapper').css('position', 'unset');
565 }
566
567 $('.body_dark #searchInput').addClass('input_focused');
568
569 if ( $('#bbpc-search-result.ajax-search').length > 0 ) {
570 $('.body_dark #searchInput').addClass('input_focused');
571 }
572 });
573
574 // Focus out search input
575 $('.bbpc_search_form_wrapper').focusout(function () {
576
577 if ( $('body .body_wrapper').length > 0 ) {
578 $('body .body_wrapper').css('position','relative');
579 }
580
581 if ( $('#bbpc-search-result.ajax-search').length > 0 ) {
582 $('.body_dark #searchInput').addClass('input_focused');
583 } else {
584 $('.body_dark #searchInput').removeClass('input_focused');
585 }
586 });
587
588 });
589 })(jQuery);
590 </script>
591 <?php
592 }
593 }