PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 3.9.1
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v3.9.1
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 3.9.1, at includes/Shortcodes/SearchModal.php

115 lines 4.9 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' => 'h2',
43 'subheading_tag' => 'h3',
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 ]
54 );
55 }
56
57 public function render( $atts, $content = null ) {
58 betterdocs()->assets->localize(
59 'betterdocs-search-modal',
60 'searchModalConfig',
61 [
62 'nonce' => wp_create_nonce( 'wp_rest' )
63 ]
64 );
65
66 $defaults_attrs = $this->default_attributes();
67
68 if ( isset( $atts['layout'] ) && $atts['layout'] == 'layout-1' ) {
69 $attributes = [
70 'placeholder' => isset( $atts['placeholder'] ) ? $atts['placeholder'] : $defaults_attrs['placeholder'],
71 'heading' => isset( $atts['heading'] ) ? $atts['heading'] : $defaults_attrs['heading'],
72 'subheading' => isset( $atts['subheading'] ) ? $atts['subheading'] : $defaults_attrs['subheading'],
73 'headingtag' => isset( $atts['heading_tag'] ) ? $atts['heading_tag'] : $defaults_attrs['heading_tag'],
74 'subheadingtag' => isset( $atts['subheading_tag'] ) ? $atts['subheading_tag'] : $defaults_attrs['subheading_tag'],
75 'buttontext' => isset( $atts['search_button_text'] ) ? $atts['search_button_text'] : '',
76 'numberofdocs' => isset( $atts['number_of_docs'] ) ? $atts['number_of_docs'] : 5,
77 'numberoffaqs' => isset( $atts['number_of_faqs'] ) ? $atts['number_of_faqs'] : 5,
78 'faq_categories_ids' => isset( $atts['faq_categories_ids'] ) ? $atts['faq_categories_ids'] : '',
79 'doc_ids' => isset( $atts['doc_ids'] ) ? $atts['doc_ids'] : '',
80 'doc_categories_ids' => isset( $atts['doc_categories_ids'] ) ? $atts['doc_categories_ids'] : '',
81 'enable_faq_search' => isset( $atts['enable_faq_search'] ) ? $atts['enable_faq_search'] : $defaults_attrs['enable_faq_search'],
82 'enable_docs_search' => isset( $atts['enable_docs_search'] ) ? $atts['enable_docs_search'] : $defaults_attrs['enable_docs_search']
83 ];
84 $attributes = apply_filters( 'betterdocs_search_modal_shortcode_attributes', $attributes );
85 echo '<div class="betterdocs-search-modal-layout-1" id="betterdocs-search-modal"';
86 foreach ( $attributes as $key => $value ) {
87 if ( ! empty( $value ) ) {
88 echo ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
89 }
90 }
91 echo '></div>';
92 } elseif ( isset( $atts['layout'] ) && $atts['layout'] == 'sidebar' ) {
93 $attributes = [
94 'placeholder' => $atts['placeholder'],
95 'numberofdocs' => isset( $atts['number_of_docs'] ) ? $atts['number_of_docs'] : 5,
96 'numberoffaqs' => isset( $atts['number_of_faqs'] ) ? $atts['number_of_faqs'] : 5,
97 'faq_categories_ids' => isset( $atts['faq_categories_ids'] ) ? $atts['faq_categories_ids'] : '',
98 'doc_ids' => isset( $atts['doc_ids'] ) ? $atts['doc_ids'] : '',
99 'doc_categories_ids' => isset( $atts['doc_categories_ids'] ) ? $atts['doc_categories_ids'] : '',
100 'enable_faq_search' => isset( $atts['enable_faq_search'] ) ? $atts['enable_faq_search'] : $defaults_attrs['enable_faq_search'],
101 'enable_docs_search' => isset( $atts['enable_docs_search'] ) ? $atts['enable_docs_search'] : $defaults_attrs['enable_docs_search']
102 ];
103 $attributes = apply_filters( 'betterdocs_search_modal_shortcode_attributes', $attributes );
104
105 echo '<div class="betterdocs-search-modal-sidebar" id="betterdocs-search-modal"';
106 foreach ( $attributes as $key => $value ) {
107 if ( ! empty( $value ) ) {
108 echo ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
109 }
110 }
111 echo '></div>';
112 }
113 }
114 }
115