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

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