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.2 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 All 200 releases
← All changes | includes/Shortcodes/SearchForm.php +100 -177 3.4.23.8.9 View file →
@@ -8,204 +8,127 @@
8 8 use WPDeveloper\BetterDocs\Core\Shortcode;
9 9 use WPDeveloper\BetterDocs\Admin\Customizer\Defaults;
10 10
11 11 class SearchForm extends Shortcode {
12 - public function __construct( Settings $settings, Query $query, Helper $helper, Defaults $defaults ) {
13 - parent::__construct( $settings, $query, $helper, $defaults );
12 + public function __construct( Settings $settings, Query $query, Helper $helper, Defaults $defaults ) {
13 + parent::__construct( $settings, $query, $helper, $defaults );
14 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 - }
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 18
19 - public function get_style_depends() {
20 - return ['betterdocs-search'];
21 - }
19 + public function get_style_depends() {
20 + $handlers = [ 'betterdocs-search' ];
21 + return $handlers;
22 + }
22 23
23 - public function get_script_depends() {
24 - return ['betterdocs-search'];
25 - }
24 + public function get_script_depends() {
25 + $handlers = [ 'betterdocs-search' ];
26 26
27 - public function get_search_results() {
28 - global $wpdb;
29 - $search_input = isset( $_POST['search_input'] ) ? sanitize_text_field( $_POST['search_input'] ) : '';
30 - $search_cat = isset( $_POST['search_cat'] ) ? wp_strip_all_tags( $_POST['search_cat'] ) : '';
31 - $lang = isset( $_POST['lang'] ) ? wp_strip_all_tags( $_POST['lang'] ) : '';
32 - $search_input = preg_replace( '/[^A-Za-z0-9_\- ][]]/', '', strtolower( $search_input ) );
27 + if ( is_tax() ) {
28 + $handlers[] = 'betterdocs-glossaries';
29 + }
30 + return $handlers;
31 + }
33 32
34 - $tax_query = [];
35 - if ( $search_cat ) {
36 - $tax_query = [
37 - [
38 - 'taxonomy' => 'doc_category',
39 - 'field' => 'slug',
40 - 'terms' => $search_cat,
41 - 'operator' => 'AND',
42 - 'include_children' => true
43 - ]
44 - ];
45 - }
33 + public function get_search_results() {
34 + global $wpdb;
35 + $search_input = isset( $_POST['search_input'] ) ? sanitize_text_field( $_POST['search_input'] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing
36 + $search_cat = isset( $_POST['search_cat'] ) ? wp_strip_all_tags( $_POST['search_cat'] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing
37 + $lang = isset( $_POST['lang'] ) ? wp_strip_all_tags( $_POST['lang'] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing
38 + $search_input = preg_replace( '/[^A-Za-z0-9_\- ][]]/', '', strtolower( $search_input ) );
46 39
47 - $term = get_term_by( 'slug', $search_cat );
40 + $tax_query = [];
41 + if ( $search_cat ) {
42 + $tax_query = [
43 + [
44 + 'taxonomy' => 'doc_category',
45 + 'field' => 'slug',
46 + 'terms' => $search_cat,
47 + 'operator' => 'AND',
48 + 'include_children' => true
49 + ]
50 + ];
51 + }
48 52
49 - $args = [
50 - 'term_id' => isset( $term->term_id ) ? $term->term_id : 0,
51 - 'post_type' => 'docs',
52 - 'post_status' => 'publish',
53 - 'posts_per_page' => -1,
54 - 'suppress_filters' => true,
55 - 's' => $search_input,
56 - 'orderby' => 'relevance',
57 - 'tax_query' => $tax_query
58 - ];
53 + $term = get_term_by( 'slug', $search_cat );
59 54
60 - if ( is_plugin_active( 'sitepress-multilingual-cms/sitepress.php' ) ) {
61 - $args['suppress_filters'] = false;
62 - $args['lang'] = ICL_LANGUAGE_CODE;
63 - }
55 + $args = [
56 + 'term_id' => isset( $term->term_id ) ? $term->term_id : 0,
57 + 'post_type' => 'docs',
58 + 'post_status' => 'publish',
59 + 'posts_per_page' => -1,
60 + 'suppress_filters' => true,
61 + 's' => $search_input,
62 + 'orderby' => 'relevance',
63 + 'tax_query' => $tax_query
64 + ];
64 65
65 - $search_results = $this->query->get_posts( $args );
66 + if ( is_plugin_active( 'sitepress-multilingual-cms/sitepress.php' ) ) {
67 + $args['suppress_filters'] = false;
68 + $args['lang'] = ICL_LANGUAGE_CODE;
69 + }
66 70
67 - $response = [];
71 + $search_results = $this->query->get_posts( $args );
68 72
69 - ob_start();
70 - betterdocs()->views->get( 'shortcode-parts/search-results', [
71 - 'search_results' => $search_results,
72 - 'search_input' => $search_input
73 - ] );
73 + $response = [];
74 74
75 - $_output = ob_get_clean();
75 + ob_start();
76 + betterdocs()->views->get(
77 + 'shortcode-parts/search-results',
78 + [
79 + 'search_results' => $search_results,
80 + 'search_input' => $search_input
81 + ]
82 + );
76 83
77 - $_input_not_found = '';
78 - if ( ! $search_results->have_posts() ) {
79 - $_input_not_found = $search_input;
80 - }
84 + $_output = ob_get_clean();
81 85
82 - $response['post_lists'] = $_output;
86 + $_input_not_found = '';
87 + if ( ! $search_results->have_posts() ) {
88 + $_input_not_found = $search_input;
89 + }
83 90
84 - if ( $_output && strlen( $search_input ) >= 3 ) {
85 - $this->insert( $search_input, $_input_not_found );
86 - }
91 + $response['post_lists'] = $_output;
87 92
88 - wp_reset_query();
89 - wp_reset_postdata();
93 + if ( $_output && strlen( $search_input ) >= 3 ) {
94 + betterdocs()->query->insert_search_keyword( $search_input, $_input_not_found );
95 + }
90 96
91 - wp_send_json_success( $response );
92 - }
97 + wp_reset_postdata();
93 98
94 - private function insert( $search_input, $input_not_found ) {
95 - global $wpdb;
96 - $search = $wpdb->get_results(
97 - $wpdb->prepare(
98 - "SELECT *
99 - FROM {$wpdb->prefix}betterdocs_search_keyword
100 - WHERE keyword = %s",
101 - $search_input
102 - )
103 - );
99 + wp_send_json_success( $response );
100 + }
104 101
105 - if ( ! empty( $search ) ) {
106 - $search_log = $wpdb->get_results(
107 - $wpdb->prepare(
108 - "SELECT *
109 - FROM {$wpdb->prefix}betterdocs_search_log
110 - WHERE created_at = %s AND keyword_id = %d",
111 - date( 'Y-m-d' ), $search[0]->id
112 - )
113 - );
102 + public function get_name() {
103 + return 'betterdocs_search_form';
104 + }
114 105
115 - if ( ! empty( $search_log ) ) {
116 - if ( ! empty( $input_not_found ) ) {
117 - $tbl_field = 'not_found_count';
118 - $count = $search_log[0]->not_found_count + 1;
119 - } else {
120 - $tbl_field = 'count';
121 - $count = $search_log[0]->count + 1;
122 - }
123 - $wpdb->query(
124 - $wpdb->prepare(
125 - "UPDATE {$wpdb->prefix}betterdocs_search_log
126 - SET " . $tbl_field . " = " . $count . "
127 - WHERE created_at = %s AND keyword_id = %d",
128 - $search_log[0]->created_at, $search_log[0]->keyword_id
129 - )
130 - );
131 - } else {
132 - if ( ! empty( $input_not_found ) ) {
133 - $count = 0;
134 - $not_found_count = 1;
135 - } else {
136 - $count = 1;
137 - $not_found_count = 0;
138 - }
139 - $wpdb->query(
140 - $wpdb->prepare(
141 - "INSERT INTO {$wpdb->prefix}betterdocs_search_log
142 - ( keyword_id, count, not_found_count, created_at )
143 - VALUES ( %d, %d, %d, %s )",
144 - [
145 - $search[0]->id,
146 - $count,
147 - $not_found_count,
148 - date( 'Y-m-d' )
149 - ]
150 - )
151 - );
152 - }
153 - } else {
154 - $insert = $wpdb->query(
155 - $wpdb->prepare(
156 - "INSERT INTO {$wpdb->prefix}betterdocs_search_keyword
157 - ( keyword )
158 - VALUES ( %s )",
159 - [
160 - $search_input
161 - ]
162 - )
163 - );
106 + /**
107 + * Summary of default_attributes
108 + * @return array
109 + */
110 + public function default_attributes() {
111 + return apply_filters(
112 + 'betterdocs_search_form_attr',
113 + [
114 + 'placeholder' => __( 'Search', 'betterdocs' ),
115 + 'heading' => '',
116 + 'subheading' => '',
117 + 'heading_tag' => 'h2',
118 + 'subheading_tag' => 'h3'
119 + ]
120 + );
121 + }
164 122
165 - if ( $insert ) {
166 - if ( ! empty( $input_not_found ) ) {
167 - $count = 0;
168 - $not_found_count = 1;
169 - } else {
170 - $count = 1;
171 - $not_found_count = 0;
172 - }
173 - $wpdb->query(
174 - $wpdb->prepare(
175 - "INSERT INTO {$wpdb->prefix}betterdocs_search_log
176 - ( keyword_id, count, not_found_count, created_at )
177 - VALUES ( %d, %d, %d, %s )",
178 - [
179 - $wpdb->insert_id,
180 - $count,
181 - $not_found_count,
182 - date( 'Y-m-d' )
183 - ]
184 - )
185 - );
186 - }
187 - }
188 - }
123 + public function render( $atts, $content = null ) {
124 + betterdocs()->assets->localize(
125 + 'betterdocs-search',
126 + 'betterdocsSearchConfigTwo',
127 + [
128 + 'is_post_type_archive' => is_post_type_archive( 'docs' ),
129 + ]
130 + );
189 131
190 - public function get_name() {
191 - return 'betterdocs_search_form';
192 - }
193 -
194 - /**
195 - * Summary of default_attributes
196 - * @return array
197 - */
198 - public function default_attributes() {
199 - return apply_filters( 'betterdocs_search_form_attr', [
200 - 'placeholder' => __( 'Search', 'betterdocs' ),
201 - 'heading' => '',
202 - 'subheading' => '',
203 - 'heading_tag' => 'h2',
204 - 'subheading_tag' => 'h3'
205 - ] );
206 - }
207 -
208 - public function render( $atts, $content = null ) {
209 - $this->views( 'shortcodes/search' );
210 - }
132 + $this->views( 'shortcodes/search' );
133 + }
211 134 }