PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 4.2.6
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v4.2.6
4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.5.2 All 199 releases
betterdocs / includes / Shortcodes / SearchModal.php

SearchModal.php in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 4.2.6, at includes/Shortcodes/SearchModal.php

140 lines 6.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPDeveloper\BetterDocs\Shortcodes;
4
5 use WPDeveloper\BetterDocs\Core\Query;
6 use WPDeveloper\BetterDocs\Utils\Helper;
7 use WPDeveloper\BetterDocs\Core\Settings;
8 use WPDeveloper\BetterDocs\Core\Shortcode;
9 use WPDeveloper\BetterDocs\Admin\Customizer\Defaults;
10
11 class SearchModal extends Shortcode {
12 public function __construct( Settings $settings, Query $query, Helper $helper, Defaults $defaults ) {
13 parent::__construct( $settings, $query, $helper, $defaults );
14
15 add_action( 'wp_ajax_nopriv_betterdocs_get_search_result', [ $this, 'get_search_results' ] );
16 add_action( 'wp_ajax_betterdocs_get_search_result', [ $this, 'get_search_results' ] );
17 }
18
19 public function get_style_depends() {
20 return [ 'betterdocs-search-modal' ];
21 }
22
23 public function get_script_depends() {
24 return [ 'betterdocs-search-modal' ];
25 }
26
27 public function get_name() {
28 return 'betterdocs_search_modal';
29 }
30
31 /**
32 * Summary of default_attributes
33 * @return array
34 */
35 public function default_attributes() {
36 return apply_filters(
37 'betterdocs_search_modal_default_attr',
38 [
39 'placeholder' => __( 'Search Doc', 'betterdocs' ),
40 'heading' => '',
41 'subheading' => '',
42 'heading_tag' => 'h1',
43 'subheading_tag' => 'p',
44 'number_of_docs' => '5',
45 'number_of_faqs' => '5',
46 'search_button_text' => __( 'Search', 'betterdocs' ),
47 'faq_categories_ids' => '',
48 'layout' => 'layout-1',
49 'doc_ids' => '',
50 'doc_categories_ids' => '',
51 'enable_docs_search' => true,
52 'enable_faq_search' => true,
53 'enable_ai_powered_search' => false
54 ]
55 );
56 }
57
58 public function render( $atts, $content = null ) {
59 betterdocs()->assets->localize(
60 'betterdocs-search-modal',
61 'searchModalConfig',
62 [
63 'nonce' => wp_create_nonce( 'wp_rest' )
64 ]
65 );
66
67 $defaults_attrs = $this->default_attributes();
68
69 if ( isset( $atts['layout'] ) && $atts['layout'] == 'layout-1' ) {
70 $attributes = [
71 'placeholder' => isset( $atts['placeholder'] ) ? $atts['placeholder'] : $defaults_attrs['placeholder'],
72 'heading' => isset( $atts['heading'] ) ? $atts['heading'] : $defaults_attrs['heading'],
73 'subheading' => isset( $atts['subheading'] ) ? $atts['subheading'] : $defaults_attrs['subheading'],
74 'headingtag' => isset( $atts['heading_tag'] ) ? $atts['heading_tag'] : $defaults_attrs['heading_tag'],
75 'subheadingtag' => isset( $atts['subheading_tag'] ) ? $atts['subheading_tag'] : $defaults_attrs['subheading_tag'],
76 'buttontext' => isset( $atts['search_button_text'] ) ? $atts['search_button_text'] : '',
77 'numberofdocs' => isset( $atts['number_of_docs'] ) ? $atts['number_of_docs'] : 5,
78 'numberoffaqs' => isset( $atts['number_of_faqs'] ) ? $atts['number_of_faqs'] : 5,
79 'faq_categories_ids' => isset( $atts['faq_categories_ids'] ) ? $atts['faq_categories_ids'] : '',
80 'doc_ids' => isset( $atts['doc_ids'] ) ? $atts['doc_ids'] : '',
81 'doc_categories_ids' => isset( $atts['doc_categories_ids'] ) ? $atts['doc_categories_ids'] : '',
82 'enable_faq_search' => isset( $atts['enable_faq_search'] ) ? $atts['enable_faq_search'] : $defaults_attrs['enable_faq_search'],
83 'enable_docs_search' => isset( $atts['enable_docs_search'] ) ? $atts['enable_docs_search'] : $defaults_attrs['enable_docs_search'],
84 'enable_ai_powered_search' => isset( $atts['enable_ai_powered_search'] ) ? $atts['enable_ai_powered_search'] : $defaults_attrs['enable_ai_powered_search']
85 ];
86 $attributes = apply_filters( 'betterdocs_search_modal_shortcode_attributes', $attributes );
87 echo '<div class="betterdocs-search-modal-layout-1" id="betterdocs-search-modal"';
88 foreach ( $attributes as $key => $value ) {
89 if ( ! empty( $value ) ) {
90 echo ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
91 }
92 }
93 echo '></div>';
94 } else if ( isset( $atts['layout'] ) && $atts['layout'] == 'docs-archive' ) {
95 $attributes = [
96 'placeholder' => isset( $atts['placeholder'] ) ? $atts['placeholder'] : '',
97 'buttontext' => isset( $atts['search_button_text'] ) ? $atts['search_button_text'] : '',
98 'numberofdocs' => isset( $atts['number_of_docs'] ) ? $atts['number_of_docs'] : 5,
99 'numberoffaqs' => isset( $atts['number_of_faqs'] ) ? $atts['number_of_faqs'] : 5,
100 'faq_categories_ids' => isset( $atts['faq_categories_ids'] ) ? $atts['faq_categories_ids'] : '',
101 'doc_ids' => isset( $atts['doc_ids'] ) ? $atts['doc_ids'] : '',
102 'doc_categories_ids' => isset( $atts['doc_categories_ids'] ) ? $atts['doc_categories_ids'] : '',
103 'enable_faq_search' => isset( $atts['enable_faq_search'] ) ? $atts['enable_faq_search'] : $defaults_attrs['enable_faq_search'],
104 'enable_docs_search' => isset( $atts['enable_docs_search'] ) ? $atts['enable_docs_search'] : $defaults_attrs['enable_docs_search'],
105 'enable_ai_powered_search' => isset( $atts['enable_ai_powered_search'] ) ? $atts['enable_ai_powered_search'] : $defaults_attrs['enable_ai_powered_search']
106 ];
107 $attributes = apply_filters( 'betterdocs_search_modal_shortcode_attributes', $attributes );
108
109 echo '<div class="betterdocs-search-modal-archive" id="betterdocs-search-modal"';
110 foreach ( $attributes as $key => $value ) {
111 if ( ! empty( $value ) ) {
112 echo ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
113 }
114 }
115 echo '></div>';
116 } elseif ( isset( $atts['layout'] ) && $atts['layout'] == 'sidebar' ) {
117 $attributes = [
118 'placeholder' => $atts['placeholder'],
119 'numberofdocs' => isset( $atts['number_of_docs'] ) ? $atts['number_of_docs'] : 5,
120 'numberoffaqs' => isset( $atts['number_of_faqs'] ) ? $atts['number_of_faqs'] : 5,
121 'faq_categories_ids' => isset( $atts['faq_categories_ids'] ) ? $atts['faq_categories_ids'] : '',
122 'doc_ids' => isset( $atts['doc_ids'] ) ? $atts['doc_ids'] : '',
123 'doc_categories_ids' => isset( $atts['doc_categories_ids'] ) ? $atts['doc_categories_ids'] : '',
124 'enable_faq_search' => isset( $atts['enable_faq_search'] ) ? $atts['enable_faq_search'] : $defaults_attrs['enable_faq_search'],
125 'enable_docs_search' => isset( $atts['enable_docs_search'] ) ? $atts['enable_docs_search'] : $defaults_attrs['enable_docs_search'],
126 'enable_ai_powered_search' => isset( $atts['enable_ai_powered_search'] ) ? $atts['enable_ai_powered_search'] : $defaults_attrs['enable_ai_powered_search']
127 ];
128 $attributes = apply_filters( 'betterdocs_search_modal_shortcode_attributes', $attributes );
129
130 echo '<div class="betterdocs-search-modal-sidebar" id="betterdocs-search-modal"';
131 foreach ( $attributes as $key => $value ) {
132 if ( ! empty( $value ) ) {
133 echo ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
134 }
135 }
136 echo '></div>';
137 }
138 }
139 }
140