PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 1.7.1
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v1.7.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 / public / betterdocs-shortcodes.php

betterdocs-shortcodes.php in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 1.7.1, at public/betterdocs-shortcodes.php

881 lines 29.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * BetterDocs all shortcodes
5 *
6 * @link https://wpdeveloper.net
7 * @since 1.0.0
8 *
9 * @package BetterDocs
10 * @subpackage BetterDocs/public
11 */
12
13 /**
14 * Get terms post count including child terms
15 */
16 function betterdocs_get_postcount($term_count = 0, $term_id)
17 {
18 $taxonomy = 'doc_category';
19 $args = array(
20 'child_of' => $term_id,
21 );
22 $tax_terms = get_terms($taxonomy, $args);
23
24 if ($tax_terms) {
25
26 foreach ($tax_terms as $tax_term) {
27 $term_count += $tax_term->count;
28 }
29 }
30
31 return $term_count;
32 }
33
34 /**
35 * Get the category grid with docs list.
36 * *
37 * @since 1.0.0
38 * *
39 * @param int $atts Get attributes for the categories.
40 * @param int $content Get content to category.
41 */
42 add_shortcode('betterdocs_category_grid', 'betterdocs_category_grid');
43 function betterdocs_category_grid($atts, $content = null)
44 {
45 ob_start();
46 global $wp_query;
47
48 $column_val = '';
49 $masonry_layout = BetterDocs_DB::get_settings('masonry_layout');
50 $alphabetic_order = BetterDocs_DB::get_settings('alphabetically_order_post');
51 $nested_subcategory = BetterDocs_DB::get_settings('nested_subcategory');
52 $column_number = BetterDocs_DB::get_settings('column_number');
53 $posts_number = BetterDocs_DB::get_settings('posts_number');
54 $post_count = BetterDocs_DB::get_settings('post_count');
55 $exploremore_btn = BetterDocs_DB::get_settings('exploremore_btn');
56 $exploremore_btn_txt = BetterDocs_DB::get_settings('exploremore_btn_txt');
57 $get_args = shortcode_atts(
58 array(
59 'sidebar_list' => false,
60 'post_type' => 'docs',
61 'category' => 'doc_category',
62 'post_counter' => true,
63 'icon' => true,
64 'masonry' => '',
65 'column' => '',
66 'posts_per_grid' => '',
67 'nested_subcategory' => '',
68 'terms' => '',
69 'multiple_knowledge_base' => false,
70 'disable_customizer_style' => false,
71 ),
72 $atts
73 );
74
75 $taxonomy_objects = BetterDocs_Helper::taxonomy_object($get_args['multiple_knowledge_base'], $get_args['terms']);
76
77 if ($taxonomy_objects && !is_wp_error($taxonomy_objects)) {
78 $class = ['betterdocs-categories-wrap category-grid white-bg'];
79 if (!is_singular('docs') && !is_tax('doc_category') && !is_tax('doc_tag')) {
80 if ($get_args['sidebar_list'] == true) {
81 $class[] = 'layout-flex';
82 } elseif (isset($get_args['masonry']) && $get_args['masonry'] == true && $get_args['masonry'] != "false") {
83 $class[] = 'layout-masonry';
84 } elseif ($masonry_layout == 1 && $nested_subcategory != 1 && $get_args['masonry'] != "false") {
85 $class[] = 'layout-masonry';
86 } else {
87 $class[] = 'layout-flex';
88 }
89
90 if ($get_args['sidebar_list'] == true) {
91 $column_val = 1;
92 } elseif (isset($get_args['column']) && $get_args['column'] == true && is_numeric($get_args['column'])) {
93 $column_val = $get_args['column'];
94 } else {
95 $column_val = $column_number;
96 }
97 $class[] = 'docs-col-' . $column_val;
98 if ($get_args['disable_customizer_style'] == false) {
99 $class[] = 'single-kb';
100 }
101 }
102 ?>
103 <div class="<?php echo implode(' ', $class) ?>" data-column="<?php echo esc_html($column_val) ?>">
104 <?php
105 $term_list = wp_get_post_terms(get_the_ID(), 'doc_category', array("fields" => "all"));
106 // get single page category id
107 if (is_single() && !empty($term_list)) {
108 $category_id = array_column($term_list, 'term_id');
109 $ancestors = get_ancestors($category_id[0], 'doc_category');
110 $page_cat = get_the_ID();
111 } else {
112 $category_id = array();
113 $page_cat = '';
114 $ancestors = array();
115 }
116 /**
117 * Get Queried Object - For KB
118 */
119
120 // display category grid by order
121 foreach ($taxonomy_objects as $term) {
122 $term_id = $term->term_id;
123 $term_slug = $term->slug;
124 $count = $term->count;
125 $get_term_count = betterdocs_get_postcount($count, $term_id);
126 $term_count = apply_filters('betterdocs_postcount', $get_term_count, $get_args['multiple_knowledge_base'], $term_id, $term_slug, $count);
127
128 if ($term_count > 0) {
129 // set active category class in single page
130 if (is_single() && (in_array($term_id, $category_id) || in_array($term_id, $ancestors))) {
131 $wrap_class = 'docs-single-cat-wrap current-category';
132 $title_class = 'docs-cat-title-wrap active-title';
133 } else {
134 $wrap_class = 'docs-single-cat-wrap';
135 $title_class = 'docs-cat-title-wrap';
136 }
137
138 $cat_icon_id = get_term_meta($term_id, 'doc_category_image-id', true);
139
140 if ($cat_icon_id) {
141 $cat_icon_url = wp_get_attachment_image_url($cat_icon_id, 'thumbnail');
142 $cat_icon = '<img class="docs-cat-icon" src="' . $cat_icon_url . '" alt="">';
143 } else {
144 $cat_icon = '<img class="docs-cat-icon" src="' . BETTERDOCS_ADMIN_URL . 'assets/img/betterdocs-cat-icon.svg" alt="">';
145 }
146
147 if ($get_args['icon'] == false) {
148 $cat_icon = '';
149 }
150 ?>
151 <div class="<?php echo esc_attr($wrap_class) ?>">
152 <div class="<?php echo esc_attr($title_class) ?>">
153 <div class="docs-cat-title-inner">
154 <?php
155 $term_permalink = BetterDocs_Helper::term_permalink($get_args['category'], $term->slug);
156
157 if ($get_args['sidebar_list'] == true) {
158
159 echo '<div class="docs-cat-title">' . $cat_icon . '<h3>' . $term->name . '</h3></div>';
160 } else {
161
162 echo '<div class="docs-cat-title">' . $cat_icon . '<a href="' . esc_url($term_permalink) . '"><h3>' . $term->name . '</h3></a></div>';
163 }
164
165 if ($post_count == 1 && $get_args['post_counter'] == true) {
166
167 echo '<div class="docs-item-count"><span>' . $term_count . '</span></div>';
168 }
169 ?>
170 <svg class="cat-list-arrow-down" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="angle-down" class="svg-inline--fa fa-angle-down fa-w-10" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512">
171 <path fill="currentColor" d="M143 352.3L7 216.3c-9.4-9.4-9.4-24.6 0-33.9l22.6-22.6c9.4-9.4 24.6-9.4 33.9 0l96.4 96.4 96.4-96.4c9.4-9.4 24.6-9.4 33.9 0l22.6 22.6c9.4 9.4 9.4 24.6 0 33.9l-136 136c-9.2 9.4-24.4 9.4-33.8 0z"></path>
172 </svg>
173 </div>
174 </div>
175
176 <div class="docs-item-container">
177 <?php
178 if (isset($get_args['posts_per_grid']) && $get_args['posts_per_grid'] == true && is_numeric($get_args['posts_per_grid'])) {
179 $posts_per_grid = $get_args['posts_per_grid'];
180 } else {
181 $posts_per_grid = $posts_number;
182 }
183
184 $list_args = BetterDocs_Helper::list_query_arg($get_args['post_type'], $get_args['multiple_knowledge_base'], $term_slug, $posts_per_grid, $alphabetic_order);
185 $args = apply_filters('betterdocs_articles_args', $list_args, $term->term_id);
186 $post_query = new WP_Query($args);
187
188 if ($post_query->have_posts()) :
189 echo '<ul>';
190 while ($post_query->have_posts()) : $post_query->the_post();
191 $attr = ['href="' . get_the_permalink() . '"'];
192 if ($page_cat === get_the_ID()) {
193 $attr[] = 'class="active"';
194 }
195 echo '<li>' . BetterDocs_Helper::list_svg() . '<a ' . implode(' ', $attr) . '>' . get_the_title() . '</a></li>';
196 endwhile;
197 echo '</ul>';
198 endif;
199 wp_reset_query();
200
201 // Sub category query
202 if (($nested_subcategory == 1 || $get_args['nested_subcategory'] == true) && $get_args['nested_subcategory'] != "false") {
203 nested_category_list(
204 $term_id,
205 $get_args['multiple_knowledge_base'],
206 $category_id,
207 $get_args['post_type'],
208 $alphabetic_order,
209 $page_cat
210 );
211 }
212
213 // Read More Button
214 if ($get_args['posts_per_grid'] == '-1' || $posts_number == '-1') {
215 echo '';
216 } else if ($exploremore_btn == 1 && !is_singular('docs') && BetterDocs_Helper::get_tax() != 'doc_category' && !is_tax('doc_tag')) {
217 echo '<a class="docs-cat-link-btn" href="' . $term_permalink . '">' . esc_html($exploremore_btn_txt) . '</a>';
218 }
219 ?>
220 </div>
221 </div>
222 <?php }
223 }
224 ?>
225 </div>
226 <?php } else { ?>
227 <div class="betterdocs-categories-wrap category-grid">
228 <div class="docs-single-cat-wrap">
229 <div class="docs-cat-title-wrap">
230 <div class="docs-cat-title-inner">
231 <div class="docs-cat-title">
232 <img class="docs-cat-icon" src="<?php echo BETTERDOCS_ADMIN_URL ?>assets/img/betterdocs-cat-icon.svg" alt="">
233 <h3><?php esc_html_e('Uncategorised', 'betterdocs') ?></h3>
234 </div>
235 </div>
236 </div>
237 <div class="docs-item-container">
238 <?php
239 $args = array(
240 'post_type' => $get_args['post_type']
241 );
242 if (isset($get_args['posts_per_grid']) && $get_args['posts_per_grid'] == true && is_numeric($get_args['posts_per_grid'])) {
243 $posts_number = $get_args['posts_per_grid'];
244 }
245 $args['posts_per_page'] = $posts_number;
246
247 if ($alphabetic_order == 1) {
248 $args['orderby'] = 'title';
249 $args['order'] = 'ASC';
250 }
251
252 $uncategorised_tax_query = '';
253 $args['tax_query'] = apply_filters('betterdocs_kb_uncategorised_tax_query', $uncategorised_tax_query, $wp_query);
254
255 $post_query = new WP_Query($args);
256
257 if ($post_query->have_posts()) :
258
259 echo '<ul>';
260
261 while ($post_query->have_posts()) : $post_query->the_post();
262 $attr = ['href="' . get_the_permalink() . '"'];
263 echo '<li>' . BetterDocs_Helper::list_svg() . '<a ' . implode(' ', $attr) . '>' . get_the_title() . '</a></li>';
264 endwhile;
265
266 echo '</ul>';
267
268 endif;
269 wp_reset_query();
270 ?>
271 </div>
272 </div>
273 </div>
274 <?php
275 }
276 return ob_get_clean();
277 }
278
279 function nested_category_list($term_id, $multiple_kb, $category_id, $post_type, $alphabetic_order, $page_cat) {
280 $sub_categories = BetterDocs_Helper::child_taxonomy_terms($term_id, $multiple_kb);
281 if ($sub_categories) {
282 foreach ($sub_categories as $sub_category) {
283 if (is_single() && in_array($sub_category->term_id, $category_id)) {
284 $subcat_class = 'docs-sub-cat current-sub-cat';
285 } else {
286 $subcat_class = 'docs-sub-cat';
287 }
288
289 echo '<span class="docs-sub-cat-title">
290 ' . BetterDocs_Helper::arrow_right_svg() . '
291 ' . BetterDocs_Helper::arrow_down_svg() . '
292 <a href="#">' . $sub_category->name . '</a></span>';
293
294 echo '<ul class="' . esc_attr($subcat_class) . '">';
295 $sub_args = BetterDocs_Helper::list_query_arg($post_type, $multiple_kb, $sub_category->slug, -1, $alphabetic_order);
296 $sub_args = apply_filters('betterdocs_sub_cat_articles_args', $sub_args, $sub_category->term_id);
297 $sub_post_query = new WP_Query($sub_args);
298
299 if ($sub_post_query->have_posts()) :
300 while ($sub_post_query->have_posts()) : $sub_post_query->the_post();
301 $sub_attr = ['href="' . get_the_permalink() . '"'];
302 if ($page_cat === get_the_ID()) {
303 $sub_attr[] = 'class="active"';
304 }
305 echo '<li class="sub-list">' . BetterDocs_Helper::list_svg() . '<a ' . implode(' ', $sub_attr) . '>' . get_the_title() . '</a></li>';
306 endwhile;
307 endif;
308 wp_reset_query();
309 nested_category_list($sub_category->term_id, $multiple_kb, $category_id, $post_type, $alphabetic_order, $page_cat);
310 echo '</ul>';
311 }
312 }
313 }
314
315
316 /**
317 * Get the category grid with docs list.
318 * *
319 * @since 1.0.0
320 * *
321 * @param int $atts Get attributes for the categories.
322 * @param int $content Get content to category.
323 */
324 add_shortcode('betterdocs_category_list', 'betterdocs_category_list');
325 function betterdocs_category_list($atts, $content = null)
326 {
327 ob_start();
328 $alphabetic_order = BetterDocs_DB::get_settings('alphabetically_order_post');
329 $exploremore_btn = BetterDocs_DB::get_settings('exploremore_btn');
330 $exploremore_btn_txt = BetterDocs_DB::get_settings('exploremore_btn_txt');
331 $nested_subcategory = BetterDocs_DB::get_settings('nested_subcategory');
332 $get_args = shortcode_atts(
333 array(
334 'post_type' => 'docs',
335 'category' => 'doc_category',
336 'masonry' => '',
337 'column' => '',
338 'posts_per_page' => '',
339 'nested_subcategory' => '',
340 'terms' => '',
341 'multiple_knowledge_base' => false
342 ),
343 $atts
344 );
345
346 $taxonomy_objects = BetterDocs_Helper::taxonomy_object($get_args['multiple_knowledge_base'], $get_args['terms']);
347
348 if ($taxonomy_objects && !is_wp_error($taxonomy_objects)) :
349 ?>
350 <div class="betterdocs-categories-wrap category-list">
351 <?php
352 $term_list = wp_get_post_terms(get_the_ID(), 'doc_category', array("fields" => "all"));
353
354 // get single page category id
355 if (is_single() && $term_list) {
356 $category_id = array_column($term_list, 'term_id');
357 $page_cat = get_the_ID();
358 } else {
359 $category_id = array();
360 $page_cat = '';
361 }
362
363 /**
364 * For Multiple KB
365 */
366 $q_object = get_queried_object();
367 $kb_slug = '';
368
369 if ($q_object instanceof WP_Term) {
370 $kb_slug = $q_object->slug;
371 }
372
373 // display category grid by order
374 foreach ($taxonomy_objects as $term) {
375 $term_id = $term->term_id;
376 $term_slug = $term->slug;
377
378 // set active category class in single page
379 if (is_single() && in_array($term_id, $category_id)) {
380 $wrap_class = 'docs-single-cat-wrap-2 current-category';
381 $title_class = 'active-title';
382 } else {
383 $wrap_class = 'docs-single-cat-wrap-2';
384 $title_class = '';
385 }
386
387 $term_permalink = BetterDocs_Helper::term_permalink($get_args['category'], $term_slug);
388 ?>
389 <div class="cat tet <?php echo esc_attr($wrap_class) ?>">
390 <div class="<?php echo esc_attr($title_class) ?>">
391 <div class="docs-cat-title-inner">
392 <?php
393 echo '<div class="docs-cat-title"><a href="' . esc_url($term_permalink) . '"><h3>' . $term->name . '</h3></a></div>';
394 ?>
395 </div>
396 </div>
397 <div class="docs-item-container">
398 <?php
399 $list_args = BetterDocs_Helper::list_query_arg($get_args['post_type'], $get_args['multiple_knowledge_base'], $term_slug, -1, $alphabetic_order);
400 $post_query = new WP_Query($list_args);
401 if ($post_query->have_posts()) :
402
403 echo '<ul>';
404 while ($post_query->have_posts()) : $post_query->the_post();
405 $attr = ['href="' . get_the_permalink() . '"'];
406 if ($page_cat === get_the_ID()) {
407 $attr[] = 'class="active"';
408 }
409 echo '<li><a ' . implode(' ', $attr) . '>' . get_the_title() . '</a></li>';
410 endwhile;
411
412 echo '</ul>';
413
414 endif;
415 wp_reset_query();
416
417 // Sub category query
418 if (($nested_subcategory == 1 || $get_args['nested_subcategory'] == true) && $get_args['nested_subcategory'] != "false") {
419 nested_category_list(
420 $term_id,
421 $get_args['multiple_knowledge_base'],
422 $category_id,
423 $get_args['post_type'],
424 $alphabetic_order,
425 $page_cat
426 );
427 }
428 ?>
429
430 </div>
431 </div>
432 <?php } ?>
433 </div>
434 <?php
435 endif;
436 return ob_get_clean();
437 }
438
439 /**
440 * Get the category grid with docs list.
441 * *
442 * @since 1.0.0
443 * *
444 * @param int $atts Get attributes for the categories.
445 * @param int $content Get content to category.
446 */
447 add_shortcode('betterdocs_category_box', 'betterdocs_category_box');
448 function betterdocs_category_box($atts, $content = null)
449 {
450 ob_start();
451 $column_number = BetterDocs_DB::get_settings('column_number');
452 $post_count = BetterDocs_DB::get_settings('post_count');
453 $count_text_singular = BetterDocs_DB::get_settings('count_text_singular');
454 $count_text = BetterDocs_DB::get_settings('count_text');
455 $get_args = shortcode_atts(
456 array(
457 'post_type' => 'docs',
458 'category' => 'doc_category',
459 'column' => '',
460 'nested_subcategory' => '',
461 'terms' => '',
462 'multiple_knowledge_base' => false,
463 'disable_customizer_style' => false
464 ),
465 $atts
466 );
467
468 $taxonomy_objects = BetterDocs_Helper::taxonomy_object($get_args['multiple_knowledge_base'], $get_args['terms']);
469
470 if ($taxonomy_objects && !is_wp_error($taxonomy_objects)) :
471 $class = ['betterdocs-categories-wrap betterdocs-category-box layout-2 ash-bg'];
472 $class[] = 'layout-flex';
473
474 if (isset($get_args['column']) && $get_args['column'] == true && is_numeric($get_args['column'])) {
475 $class[] = 'docs-col-' . $get_args['column'];
476 } else {
477 $class[] = 'docs-col-' . $column_number;
478 }
479
480 if ($get_args['disable_customizer_style'] == false) {
481 $class[] = 'single-kb';
482 }
483 ?>
484 <div class="<?php echo implode(' ', $class) ?>">
485 <?php
486 // display category grid by order
487 foreach ($taxonomy_objects as $term) {
488 $term_id = $term->term_id;
489 if ($term->count != 0) {
490
491 // set active category class in single page
492 $wrap_class = 'docs-single-cat-wrap';
493
494 $term_permalink = BetterDocs_Helper::term_permalink($get_args['category'], $term->slug);
495 ?>
496 <a href="<?php echo esc_url($term_permalink) ?>" class="<?php echo esc_attr($wrap_class) ?>">
497 <?php
498 $cat_icon_id = get_term_meta($term_id, 'doc_category_image-id', true);
499 if ($cat_icon_id) {
500 echo wp_get_attachment_image($cat_icon_id, 'thumbnail');
501 } else {
502 echo '<img class="docs-cat-icon" src="' . BETTERDOCS_ADMIN_URL . 'assets/img/betterdocs-cat-icon.svg" alt="">';
503 }
504 echo '<h3 class="docs-cat-title">' . $term->name . '</h3>';
505 $cat_desc = get_theme_mod('betterdocs_doc_page_cat_desc');
506 if ($cat_desc == true) {
507 echo '<p class="cat-description">' . $term->description . '</p>';
508 }
509 if ($post_count == 1) {
510 if ($term->count == 1) {
511 echo wp_sprintf('<span>%s %s</span>', $term->count, ($count_text_singular) ? $count_text_singular : __('article', 'betterdocs'));
512 } else {
513 echo wp_sprintf('<span>%s %s</span>', $term->count, ($count_text) ? $count_text : __('articles', 'betterdocs'));
514 }
515 }
516 ?>
517 </a>
518 <?php
519 }
520 }
521 ?>
522 </div>
523 <?php
524 endif;
525 return ob_get_clean();
526 }
527
528 /**
529 * search form with live dropdown result
530 * *
531 * @since 1.0.0
532 *
533 */
534 add_shortcode('betterdocs_search_form', 'betterdocs_search_form');
535 function betterdocs_search_form($atts, $content = null)
536 {
537 $search_placeholder = BetterDocs_DB::get_settings('search_placeholder');
538 ob_start();
539 ?>
540 <div class="betterdocs-live-search">
541 <?php
542 if (get_theme_mod('betterdocs_live_search_heading_switch') == true) {
543 echo '<div class="betterdocs-search-heading">';
544 if (get_theme_mod('betterdocs_live_search_heading')) {
545 echo '<h2> ' . esc_html(get_theme_mod('betterdocs_live_search_heading')) . ' </h2>';
546 }
547 if (get_theme_mod('betterdocs_live_search_heading')) {
548 echo '<h3> ' . get_theme_mod('betterdocs_live_search_subheading') . ' </h3>';
549 }
550 echo '</div>';
551 }
552 ?>
553 <form id="betterdocs-searchform" class="betterdocs-searchform">
554 <svg class="docs-search-icon" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="38px" viewBox="0 0 50 50" version="1.1">
555 <g id="surface1">
556 <path style=" " d="M 21 3 C 11.601563 3 4 10.601563 4 20 C 4 29.398438 11.601563 37 21 37 C 24.355469 37 27.460938 36.015625 30.09375 34.34375 L 42.375 46.625 L 46.625 42.375 L 34.5 30.28125 C 36.679688 27.421875 38 23.878906 38 20 C 38 10.601563 30.398438 3 21 3 Z M 21 7 C 28.199219 7 34 12.800781 34 20 C 34 27.199219 28.199219 33 21 33 C 13.800781 33 8 27.199219 8 20 C 8 12.800781 13.800781 7 21 7 Z "></path>
557 </g>
558 </svg>
559 <input type="text" id="betterdocs-search-field" class="betterdocs-search-field" name="s" placeholder="<?php echo $search_placeholder ?>" autocomplete="off" value="<?php the_search_query(); ?>">
560 <input type="hidden" value="Search" class="betterdocs-search-submit">
561 <svg class="docs-search-loader" width="38" height="38" viewBox="0 0 38 38" xmlns="http://www.w3.org/2000/svg" stroke="#444b54">
562 <g fill="none" fill-rule="evenodd">
563 <g transform="translate(1 1)" stroke-width="2">
564 <circle stroke-opacity=".5" cx="18" cy="18" r="18" />
565 <path d="M36 18c0-9.94-8.06-18-18-18">
566 <animateTransform attributeName="transform" type="rotate" from="0 18 18" to="360 18 18" dur="1s" repeatCount="indefinite" />
567 </path>
568 </g>
569 </g>
570 </svg>
571 <svg class="docs-search-close" xmlns="http://www.w3.org/2000/svg" width="38px" viewBox="0 0 128 128">
572 <path fill="#fff" d="M64 14A50 50 0 1 0 64 114A50 50 0 1 0 64 14Z" transform="rotate(-45.001 64 64.001)"></path>
573 <path class="close-border" d="M64,117c-14.2,0-27.5-5.5-37.5-15.5c-20.7-20.7-20.7-54.3,0-75C36.5,16.5,49.8,11,64,11c14.2,0,27.5,5.5,37.5,15.5c10,10,15.5,23.3,15.5,37.5s-5.5,27.5-15.5,37.5C91.5,111.5,78.2,117,64,117z M64,17c-12.6,0-24.4,4.9-33.2,13.8c-18.3,18.3-18.3,48.1,0,66.5C39.6,106.1,51.4,111,64,111c12.6,0,24.4-4.9,33.2-13.8S111,76.6,111,64s-4.9-24.4-13.8-33.2S76.6,17,64,17z"></path>
574 <path class="close-line" d="M53.4,77.6c-0.8,0-1.5-0.3-2.1-0.9c-1.2-1.2-1.2-3.1,0-4.2l21.2-21.2c1.2-1.2,3.1-1.2,4.2,0c1.2,1.2,1.2,3.1,0,4.2L55.5,76.7C54.9,77.3,54.2,77.6,53.4,77.6z"></path>
575 <path class="close-line" d="M74.6,77.6c-0.8,0-1.5-0.3-2.1-0.9L51.3,55.5c-1.2-1.2-1.2-3.1,0-4.2c1.2-1.2,3.1-1.2,4.2,0l21.2,21.2c1.2,1.2,1.2,3.1,0,4.2C76.1,77.3,75.4,77.6,74.6,77.6z"></path>
576 </svg>
577 </form>
578 </div>
579 <?php
580 return ob_get_clean();
581 }
582
583 /**
584 * Get the search result from ajax load.
585 * *
586 * @since 1.0.0
587 *
588 */
589 add_action('wp_ajax_nopriv_betterdocs_get_search_result', 'betterdocs_get_search_result');
590 add_action('wp_ajax_betterdocs_get_search_result', 'betterdocs_get_search_result');
591 function betterdocs_get_search_result()
592 {
593
594 $search_input = isset($_POST['search_input']) ? sanitize_text_field($_POST['search_input']) : '';
595
596 $args = array(
597 'post_type' => 'docs',
598 'post_status' => 'publish',
599 'posts_per_page' => -1,
600 'suppress_filters' => false,
601 's' => $search_input,
602 );
603 $loop = new WP_Query($args);
604 $output = '';
605 $output .= '<div class="betterdocs-search-result-wrap"><ul class="docs-search-result">';
606 if ($loop->have_posts()) :
607 while ($loop->have_posts()) : $loop->the_post();
608 $imagematcha = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', get_the_content(), $matches);
609
610 if ($matches[1]) {
611 $first_img = $matches[1][0];
612 } else {
613 $first_img = '';
614 }
615
616 $terms = get_the_terms(get_the_ID(), 'doc_category');
617 $terms_name = array();
618
619 if ($terms) {
620
621 foreach ($terms as $term) {
622 $terms_name[] = $term->name;
623 }
624 }
625
626 $all_terms = join(", ", $terms_name);
627 $icon = '';
628 $search_result_image = BetterDocs_DB::get_settings('search_result_image');
629 if ($search_result_image == 1 && has_post_thumbnail()) {
630 $icon = get_the_post_thumbnail();
631 } elseif ($search_result_image == 1 && !empty($first_img)) {
632 $icon = '<img src="' . $first_img . '" alt="">';
633 }
634 $output .= '<li>' . $icon . '<a href="' . get_permalink() . '">' . get_the_title() . '<br><span>' . $all_terms . '<span></a></li>';
635 endwhile;
636 else :
637 $output .= '<li>' . esc_html__('Sorry, no docs were found.', 'betterdocs') . '</li>';
638 endif;
639 $output .= '</ul></div>';
640 echo $output;
641 wp_reset_postdata();
642 die();
643 }
644
645 /**
646 * feedback form shortcode
647 * *
648 * @since 1.0.0
649 *
650 */
651 add_shortcode('betterdocs_feedback_form', 'betterdocs_feedback_form');
652 function betterdocs_feedback_form($atts, $content = null)
653 {
654 $get_args = shortcode_atts(
655 array(
656 'button_text' => esc_html__('Send', 'betterdocs')
657 ),
658 $atts
659 );
660 ob_start();
661 if (is_user_logged_in()) {
662 $userdata = get_userdata(get_current_user_id());
663 $name = $userdata->first_name . ' ' . $userdata->last_name;
664 $email = $userdata->user_email;
665 } else {
666 $name = '';
667 $email = '';
668 }
669
670 ?>
671 <div class="form-wrapper">
672 <div class="response"></div>
673 <form id="betterdocs-feedback-form" class="betterdocs-feedback-form" action="" method="post">
674 <p><label for="message_name" class="form-name">
675 <?php esc_html_e('Name:', 'betterdocs') ?> <span>*</span> <br>
676 <input type="text" id="message_name" name="message_name" value="<?php echo esc_html($name) ?>">
677 </label>
678 </p>
679 <p><label for="message_email" class="form-email">
680 <?php esc_html_e('Email:', 'betterdocs') ?> <span>*</span> <br>
681 <input type="text" id="message_email" name="message_email" value="<?php echo esc_html($email) ?>">
682 </label>
683 </p>
684 <p><label for="message_text" class="form-message">
685 <?php esc_html_e('Message:', 'betterdocs') ?> <span>*</span> <br>
686 <textarea type="text" id="message_text" name="message_text"></textarea>
687 </label>
688 </p>
689 <div class="feedback-from-button">
690 <input type="hidden" name="submitted" value="1">
691 <input type="submit" name="submit" class="button" id="feedback_form_submit_btn" value="<?php echo $get_args['button_text'] ?>" />
692 </div>
693 </form>
694 </div>
695 <?php
696 return ob_get_clean();
697 }
698
699 /**
700 * Submit form via ajax
701 * *
702 * @since 1.0.0
703 *
704 */
705 add_action('wp_ajax_nopriv_betterdocs_feedback_form_submit', 'betterdocs_feedback_form_submit');
706 add_action('wp_ajax_betterdocs_feedback_form_submit', 'betterdocs_feedback_form_submit');
707
708 function betterdocs_feedback_form_submit()
709 {
710 check_ajax_referer( 'betterdocs_submit_data', 'security' );
711 $postID = isset($_POST['postID']) ? $_POST['postID'] : '';
712 $article = get_the_title($postID);
713 $name = isset($_POST['message_name']) ? sanitize_text_field($_POST['message_name']) : '';
714 $email = isset($_POST['message_email']) ? sanitize_email($_POST['message_email']) : '';
715 $message_text = isset($_POST['message_text']) ? sanitize_textarea_field($_POST['message_text']) : '';
716 $message = <<<EOD
717 Name : {$name} <br>
718 Docs : {$article}
719 {$message_text}
720 EOD;
721
722 //response messages
723 $missing_name = esc_html__('Please enter your name.', 'betterdocs');
724 $email_invalid = esc_html__('Enter a valid email address.', 'betterdocs');
725 $missing_message = esc_html__('Please write your message.', 'betterdocs');
726 $message_unsent = esc_html__('Message was not sent. Try Again.', 'betterdocs');
727 $message_sent = esc_html__('Thanks! Your message has been sent.', 'betterdocs');
728
729 //php mailer variables
730 $to = BetterDocs_DB::get_settings('email_address');
731 if (empty($to)) {
732 $to = get_option('admin_email');
733 }
734
735 $subject = wp_sprintf(__('Feedback message from %s', 'betterdocs'), get_bloginfo('name'));
736 $headers = 'From: ' . $email . "\r\n" .
737 'Reply-To: ' . $email . "\r\n";
738 $response = array();
739
740 //validate presence of name
741 if (empty($name)) {
742 $response['nameStatus'] = 'error';
743 $response['nameMessage'] = $missing_name;
744 }
745
746 //validate email
747 if (empty($email) && !filter_var($email, FILTER_VALIDATE_EMAIL)) {
748 $response['emailStatus'] = 'error';
749 $response['emailMessage'] = $email_invalid;
750 }
751
752 //validate presence of message
753 if (empty($message_text)) {
754 $response['messageStatus'] = 'error';
755 $response['messageMessage'] = $missing_message;
756 }
757
758 if (!empty($name) && !empty($email) && filter_var($email, FILTER_VALIDATE_EMAIL) && !empty($message_text)) {
759 $sent = wp_mail($to, $subject, strip_tags($message), $headers);
760 if ($sent) {
761 $response['sentStatus'] = 'success';
762 $response['sentMessage'] = $message_sent;
763 } else {
764 $response['sentStatus'] = 'error';
765 $response['sentMessage'] = $message_unsent;
766 }
767 }
768 echo json_encode($response);
769 die();
770 }
771
772 /**
773 * Social Share Shortcode
774 * *
775 * @since 1.0.0
776 *
777 */
778 add_shortcode('betterdocs_social_share', 'betterdocs_social_share');
779 function betterdocs_social_share($atts, $content = null)
780 {
781 $get_args = shortcode_atts(
782 array(
783 'title' => esc_html__('Share This Article :', 'betterdocs'),
784 'facebook_sharing' => '1',
785 'twitter_sharing' => '1',
786 'linkedin_sharing' => '1',
787 'pinterest_sharing' => '1'
788 ),
789 $atts
790 );
791 $thumbnail = '';
792 if (function_exists('has_post_thumbnail')) {
793 if (has_post_thumbnail()) {
794 $thumbnail = wp_get_attachment_url(get_post_thumbnail_id());
795 }
796 }
797
798 ?>
799 <div class="betterdocs-social-share">
800 <div class="betterdocs-social-share-heading">
801 <?php
802 if ($get_args['title']) :
803 echo '<h5>' . esc_html($get_args['title']) . '</h5>';
804 endif;
805 ?>
806 </div>
807 <ul class="betterdocs-social-share-links">
808 <?php if ($get_args['facebook_sharing'] == true) : ?>
809 <li><a href="https://www.facebook.com/sharer/sharer.php?u=<?php the_permalink(); ?>" target="_blank"><img src="<?php echo BETTERDOCS_URL ?>public/img/facebook.svg" alt=""></a></li>
810 <?php endif; ?>
811
812 <?php if ($get_args['twitter_sharing'] == true) : ?>
813 <li><a href="https://twitter.com/home?status=<?php the_permalink(); ?>" target="_blank"><img src="<?php echo BETTERDOCS_URL ?>public/img/twitter.svg" alt=""></a></li>
814 <?php endif; ?>
815
816 <?php if ($get_args['linkedin_sharing'] == true) : ?>
817 <li><a href="https://www.linkedin.com/shareArticle?mini=true&url=<?php the_permalink(); ?>&title=&summary=&source=" target="_blank"><img src="<?php echo BETTERDOCS_URL ?>public/img/linkedin.svg" alt=""></a></li>
818 <?php endif; ?>
819
820 <?php if ($get_args['pinterest_sharing'] == true) : ?>
821 <li><a href="https://pinterest.com/pin/create/button/?url=<?php the_permalink(); ?>&media=<?php echo $thumbnail; ?>&description=" target="_blank"><img src="<?php echo BETTERDOCS_URL ?>public/img/pinterest.svg" alt=""></a></li>
822 <?php endif; ?>
823 </ul>
824 </div> <!-- Social Share end-->
825 <?php }
826
827 add_shortcode('betterdocs_toc', 'betterdocs_toc');
828 function betterdocs_toc($atts, $content = null)
829 {
830 $get_args = shortcode_atts(
831 array(
832 'post_type' => 'docs',
833 'post_id' => get_the_ID(),
834 'htags' => '1,2,3,4,5,6',
835 'hierarchy' => '',
836 'list_number' => '',
837 'collapsible_on_mobile' => '',
838 ),
839 $atts
840 );
841
842 $get_post = get_post($get_args['post_id']);
843 $post_content = $get_post->post_content;
844
845 $toc = BetterDocs_Public::betterdocs_toc(
846 $post_content,
847 $get_args['htags'],
848 $get_args['hierarchy'],
849 $get_args['list_number'],
850 $get_args['collapsible_on_mobile']
851 );
852
853 return $toc;
854 }
855
856 add_shortcode('betterdocs_post_content', 'betterdocs_post_content');
857 function betterdocs_post_content($atts, $content = null)
858 {
859 $get_args = shortcode_atts(
860 array(
861 'post_id' => get_the_ID(),
862 'htags' => 'h1,h2,h3,h4,h5,h6',
863 'enable_toc' => '',
864 'toc_hierarchy' => '',
865 'list_number' => '',
866 'display_toc_on_top' => '',
867 'collapsible_toc_mobile' => ''
868 ),
869 $atts
870 );
871
872 $get_post = get_post($get_args['post_id']);
873 $post_content = $get_post->post_content;
874 $the_content = BetterDocs_Public::betterdocs_the_content(
875 $post_content,
876 $get_args['htags'],
877 $get_args['enable_toc']
878 );
879
880 return $the_content;
881 }