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

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

1,175 lines 48.3 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.com
7 * @since 1.0.0
8 *
9 * @package BetterDocs
10 * @subpackage BetterDocs/public
11 */
12
13 use WPML\FP\Str;
14
15 /**
16 * Docs Reactions Shortcode
17 * *
18 * @since 1.0.2
19 *
20 */
21 add_shortcode('betterdocs_article_reactions', 'betterdocs_article_reaction');
22 function betterdocs_article_reaction($atts, $content = null)
23 {
24 $get_args = shortcode_atts(
25 array(
26 'text' => ''
27 ),
28 $atts
29 );
30 do_action( 'betterdocs_before_shortcode_load' );
31 if ($get_args['text']) {
32 $reactions_text = $get_args['text'];
33 } else {
34 $reactions_text = get_theme_mod('betterdocs_post_reactions_text', esc_html__('What are your Feelings', 'betterdocs'));
35 }
36 ?>
37 <div class="betterdocs-article-reactions">
38 <div class="betterdocs-article-reactions-heading">
39 <?php
40 if ($reactions_text) {
41 echo '<h5>' . esc_html($reactions_text) . '</h5>';
42 }
43 ?>
44 </div>
45 <ul class="betterdocs-article-reaction-links">
46 <li>
47 <a class="betterdocs-feelings" data-feelings="happy" href="#">
48 <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 20 20" style="enable-background:new 0 0 20 20;" xml:space="preserve">
49 <path class="st0" d="M10,0.1c-5.4,0-9.9,4.4-9.9,9.8c0,5.4,4.4,9.9,9.8,9.9c5.4,0,9.9-4.4,9.9-9.8C19.9,4.5,15.4,0.1,10,0.1z
50 M13.3,6.4c0.8,0,1.5,0.7,1.5,1.5c0,0.8-0.7,1.5-1.5,1.5c-0.8,0-1.5-0.7-1.5-1.5C11.8,7.1,12.5,6.4,13.3,6.4z M6.7,6.4
51 c0.8,0,1.5,0.7,1.5,1.5c0,0.8-0.7,1.5-1.5,1.5c-0.8,0-1.5-0.7-1.5-1.5C5.2,7.1,5.9,6.4,6.7,6.4z M10,16.1c-2.6,0-4.9-1.6-5.8-4
52 l1.2-0.4c0.7,1.9,2.5,3.2,4.6,3.2s3.9-1.3,4.6-3.2l1.2,0.4C14.9,14.5,12.6,16.1,10,16.1z" />
53 <path class="st1" d="M-6.6-119.7c-7.1,0-12.9,5.8-12.9,12.9s5.8,12.9,12.9,12.9s12.9-5.8,12.9-12.9S0.6-119.7-6.6-119.7z
54 M-2.3-111.4c1.1,0,2,0.9,2,2c0,1.1-0.9,2-2,2c-1.1,0-2-0.9-2-2C-4.3-110.5-3.4-111.4-2.3-111.4z M-10.9-111.4c1.1,0,2,0.9,2,2
55 c0,1.1-0.9,2-2,2c-1.1,0-2-0.9-2-2C-12.9-110.5-12-111.4-10.9-111.4z M-6.6-98.7c-3.4,0-6.4-2.1-7.6-5.3l1.6-0.6
56 c0.9,2.5,3.3,4.2,6,4.2s5.1-1.7,6-4.2L1-104C-0.1-100.8-3.2-98.7-6.6-98.7z" />
57 </svg>
58 </a>
59 </li>
60 <li>
61 <a class="betterdocs-feelings" data-feelings="normal" href="#">
62 <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 20 20" style="enable-background:new 0 0 20 20;" xml:space="preserve">
63 <path class="st0" d="M10,0.2c-5.4,0-9.8,4.4-9.8,9.8s4.4,9.8,9.8,9.8s9.8-4.4,9.8-9.8S15.4,0.2,10,0.2z M6.7,6.5
64 c0.8,0,1.5,0.7,1.5,1.5c0,0.8-0.7,1.5-1.5,1.5C5.9,9.5,5.2,8.9,5.2,8C5.2,7.2,5.9,6.5,6.7,6.5z M14.2,14.3H5.9
65 c-0.3,0-0.6-0.3-0.6-0.6c0-0.3,0.3-0.6,0.6-0.6h8.3c0.3,0,0.6,0.3,0.6,0.6C14.8,14,14.5,14.3,14.2,14.3z M13.3,9.5
66 c-0.8,0-1.5-0.7-1.5-1.5c0-0.8,0.7-1.5,1.5-1.5c0.8,0,1.5,0.7,1.5,1.5C14.8,8.9,14.1,9.5,13.3,9.5z" />
67 </svg>
68 </a>
69 </li>
70 <li>
71 <a class="betterdocs-feelings" data-feelings="sad" href="#">
72 <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 20 20" style="enable-background:new 0 0 20 20;" xml:space="preserve">
73 <circle class="st0" cx="27.5" cy="0.6" r="1.9" />
74 <circle class="st0" cx="36" cy="0.6" r="1.9" />
75 <path class="st1" d="M10,0.3c-5.4,0-9.8,4.4-9.8,9.8s4.4,9.8,9.8,9.8s9.8-4.4,9.8-9.8S15.4,0.3,10,0.3z M13.3,6.6
76 c0.8,0,1.5,0.7,1.5,1.5c0,0.8-0.7,1.5-1.5,1.5c-0.8,0-1.5-0.7-1.5-1.5C11.8,7.3,12.4,6.6,13.3,6.6z M6.7,6.6c0.8,0,1.5,0.7,1.5,1.5
77 c0,0.8-0.7,1.5-1.5,1.5C5.9,9.6,5.2,9,5.2,8.1C5.2,7.3,5.9,6.6,6.7,6.6z M14.1,15L14.1,15c-0.2,0-0.4-0.1-0.5-0.2
78 c-0.9-1-2.2-1.7-3.7-1.7s-2.8,0.6-3.7,1.7C6.2,14.9,6,15,5.9,15h0c-0.6,0-0.8-0.6-0.5-1.1c1.1-1.3,2.8-2.1,4.6-2.1
79 c1.8,0,3.5,0.8,4.6,2.1C15,14.3,14.7,15,14.1,15z" />
80 </svg>
81 </a>
82 </li>
83 </ul>
84 </div> <!-- Social Share end-->
85 <?php
86 }
87
88 /**
89 * Get terms post count including child terms
90 */
91 function betterdocs_get_postcount($term_count, $term_id, $nested_subcategory=false)
92 {
93 if ($nested_subcategory==false) {
94 return $term_count;
95 }
96
97 $taxonomy = 'doc_category';
98
99 $args = array(
100 'child_of' => $term_id
101 );
102
103 $tax_terms = get_terms($taxonomy, $args);
104
105 if ($tax_terms) {
106 foreach ($tax_terms as $tax_term) {
107 $term_count += $tax_term->count;
108 }
109 }
110
111 return $term_count;
112 }
113
114 /**
115 * Get the category grid with docs list.
116 * *
117 * @since 1.0.0
118 * *
119 * @param int $atts Get attributes for the categories.
120 * @param int $content Get content to category.
121 */
122 add_shortcode('betterdocs_category_grid', 'betterdocs_category_grid');
123 function betterdocs_category_grid($atts, $content = null)
124 {
125 do_action( 'betterdocs_before_shortcode_load' );
126 ob_start();
127 global $wp_query;
128
129 $column_val = '';
130 $masonry_layout = BetterDocs_DB::get_settings('masonry_layout');
131 $alphabetic_order = BetterDocs_DB::get_settings('alphabetically_order_post');
132 $column_number = BetterDocs_DB::get_settings('column_number');
133 $posts_number = BetterDocs_DB::get_settings('posts_number');
134 $exploremore_btn = BetterDocs_DB::get_settings('exploremore_btn');
135 $exploremore_btn_txt = BetterDocs_DB::get_settings('exploremore_btn_txt');
136 $get_args = shortcode_atts(
137 array(
138 'sidebar_list' => false,
139 'post_type' => 'docs',
140 'category' => 'doc_category',
141 'orderby' => BetterDocs_DB::get_settings('alphabetically_order_post'),
142 'order' => BetterDocs_DB::get_settings('docs_order'),
143 'post_counter' => BetterDocs_DB::get_settings('post_count') != 'off' ? 'true' : 'false',
144 'icon' => true,
145 'masonry' => '',
146 'column' => '',
147 'posts_per_grid' => '',
148 'nested_subcategory' => BetterDocs_DB::get_settings('nested_subcategory') != 'off' ? 'true' : 'false',
149 'terms' => '',
150 'terms_orderby' => '',
151 'terms_order' => '',
152 'kb_slug' => '',
153 'multiple_knowledge_base' => false,
154 'disable_customizer_style' => false,
155 'title_tag' => 'h2'
156 ),
157 $atts
158 );
159
160 $post_counter = ( $get_args['post_counter'] == 'true' ) ? true : false;
161 $post_icon_check = ( $get_args['icon'] == 'true' ) ? true : false;
162 $masonry_check = ( $get_args['masonry'] == 'true' ) ? true : false;
163 $nested_subcategory = $get_args['nested_subcategory'] === 'true' ? true : false;
164 $masonry = ($masonry_layout == 1 && $masonry_check == '') || ($masonry_check == true && $masonry_check != "false");
165 $taxonomy_objects = BetterDocs_Helper::taxonomy_object($get_args['multiple_knowledge_base'], $get_args['terms'], $get_args['terms_order'], $get_args['terms_orderby'], $get_args['kb_slug'], $nested_subcategory);
166 if ($taxonomy_objects && !is_wp_error($taxonomy_objects)) {
167 $class = ['betterdocs-categories-wrap category-grid white-bg'];
168 if (!is_singular('docs') && !is_tax('doc_category') && !is_tax('doc_tag')) {
169 if ($get_args['sidebar_list'] == true) {
170 $class[] = 'layout-flex';
171 } elseif ($masonry == true) {
172 wp_enqueue_script('masonry');
173 $class[] = 'layout-masonry';
174 } else {
175 $class[] = 'layout-flex';
176 }
177
178 if ($get_args['sidebar_list'] == true) {
179 $column_val = 1;
180 } elseif (isset($get_args['column']) && $get_args['column'] == true && is_numeric($get_args['column'])) {
181 $column_val = $get_args['column'];
182 } else {
183 $column_val = $column_number;
184 }
185 $class[] = 'docs-col-' . $column_val;
186 if ($get_args['disable_customizer_style'] == false) {
187 $class[] = 'single-kb';
188 }
189 }
190
191 echo '<div class="'. implode(' ', $class) .'" data-column="'. esc_html($column_val) .'">';
192 $term_list = wp_get_post_terms(get_the_ID(), 'doc_category', array("fields" => "all"));
193 // get single page category id
194 if (is_single() && !empty($term_list)) {
195 $category_id = array_column($term_list, 'term_id');
196 $cat_index = isset( $category_id[0] ) ? $category_id[0] : '';
197 $ancestors = get_ancestors($cat_index, 'doc_category');
198 $page_cat = get_the_ID();
199 } else {
200 $category_id = array();
201 $page_cat = '';
202 $ancestors = array();
203 }
204 /**
205 * Get Queried Object - For KB
206 */
207
208 // display category grid by order
209 foreach ($taxonomy_objects as $term) {
210 //for single doc category page ID
211 $current_cat_id = get_queried_object();
212 //for single post Category ID
213 $current_post_cat_id = get_the_terms( get_the_ID(), 'doc_category');
214 $term_id = $term->term_id;
215 $term_slug = $term->slug;
216 $count = $term->count;
217 $get_term_count = betterdocs_get_postcount($count, $term_id, $nested_subcategory);
218 $term_count = apply_filters('betterdocs_postcount', $get_term_count, $get_args['multiple_knowledge_base'], $term_id, $term_slug, $count, $nested_subcategory);
219 $current_term_id = isset( $current_post_cat_id[0]->term_id ) ? $current_post_cat_id[0]->term_id : '';
220 if ($term_count > 0) {
221 if (is_single() && ( $current_term_id == $term_id || ( $nested_subcategory == 1 && in_array($term_id, $ancestors ) ) ) ) {
222 // set active category class in single page
223 $wrap_class = 'docs-single-cat-wrap current-category';
224 $title_class = 'docs-cat-title-wrap active-title';
225 } elseif( BetterDocs_Helper::get_tax() == 'doc_category' && $current_cat_id->term_id == $term_id ) {
226 $wrap_class = 'docs-single-cat-wrap current-category';
227 $title_class = 'docs-cat-title-wrap active-title';
228 } else {
229 // by default docs page
230 $wrap_class = 'docs-single-cat-wrap';
231 $title_class = 'docs-cat-title-wrap';
232 }
233
234 $cat_icon_id = get_term_meta($term_id, 'doc_category_image-id', true);
235
236 if ($cat_icon_id) {
237 $cat_icon_url = wp_get_attachment_image_url($cat_icon_id, 'thumbnail');
238 $cat_icon = '<img class="docs-cat-icon" src="' . $cat_icon_url . '" alt="'.$term->name.'">';
239 } else {
240 $cat_icon = '<img class="docs-cat-icon" src="' . BETTERDOCS_ADMIN_URL . 'assets/img/betterdocs-cat-icon.svg" alt="'.$term->name.'">';
241 }
242
243 if ($post_icon_check == false) {
244 $cat_icon = '';
245 }
246
247 echo '<div id="cat-id-'. esc_attr($term_id) .'" class="'. esc_attr($wrap_class) .'">
248 <div class="'. esc_attr($title_class) .'">
249 <div class="docs-cat-title-inner">';
250 $term_permalink = BetterDocs_Helper::term_permalink('doc_category', $term->slug);
251
252 if ($get_args['sidebar_list'] == true) {
253 echo '<div class="docs-cat-title">' . $cat_icon . '<'. BetterDocs_Helper::validate_html_tag($get_args['title_tag']) .' class="docs-cat-heading">' . $term->name . '</'. BetterDocs_Helper::validate_html_tag($get_args['title_tag']) .'></div>';
254 } else {
255 echo '<div class="docs-cat-title">' . $cat_icon . '<a href="' . esc_url($term_permalink) . '"><'. BetterDocs_Helper::validate_html_tag($get_args['title_tag']) .' class="docs-cat-heading">' . $term->name . '</'. BetterDocs_Helper::validate_html_tag($get_args['title_tag']) .'></a></div>';
256 }
257
258 if ( $post_counter === true ) {
259 echo '<div class="docs-item-count"><span>' . $term_count . '</span></div>';
260 }
261
262 echo '<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="angle-down" class="cat-list-arrow-down svg-inline--fa fa-angle-down fa-w-10" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512">
263 <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>
264 </svg>
265 </div>
266 </div>
267 <div class="docs-item-container">';
268 if (isset($get_args['posts_per_grid']) && $get_args['posts_per_grid'] == true && is_numeric($get_args['posts_per_grid'])) {
269 $posts_per_grid = $get_args['posts_per_grid'];
270 } else {
271 $posts_per_grid = $posts_number;
272 }
273
274 $list_args = BetterDocs_Helper::list_query_arg('docs', $get_args['multiple_knowledge_base'], $term_slug, $posts_per_grid, $get_args['orderby'], $get_args['order'], $get_args['kb_slug']);
275 $args = apply_filters('betterdocs_articles_args', $list_args, $term->term_id);
276 $post_query = new WP_Query($args);
277 if ($post_query->have_posts()) :
278 echo '<ul>';
279 while ($post_query->have_posts()) : $post_query->the_post();
280 $attr = ['href="' . get_the_permalink() . '"'];
281 if ($page_cat === get_the_ID() && BetterDocs_Helper::get_tax() != 'doc_category') {
282 $attr[] = 'class="active"';
283 }
284 echo '<li>' . BetterDocs_Helper::list_svg() . '<a ' . implode(' ', $attr) . '>' . wp_kses(get_the_title(), BETTERDOCS_KSES_ALLOWED_HTML) . '</a></li>';
285 endwhile;
286 echo '</ul>';
287 endif;
288 wp_reset_query();
289
290 // Sub category query
291 if ($nested_subcategory == true) {
292 nested_category_list(
293 $term_id,
294 $get_args['multiple_knowledge_base'],
295 $category_id,
296 'docs',
297 $get_args['orderby'],
298 $get_args['order'],
299 $get_args['terms_orderby'],
300 $get_args['terms_order'],
301 $page_cat,
302 $get_args['kb_slug']
303 );
304 }
305
306 // Read More Button
307 if ($get_args['posts_per_grid'] == '-1' || $posts_number == '-1') {
308 echo '';
309 } else if ($exploremore_btn == 1 && !is_singular('docs') && BetterDocs_Helper::get_tax() != 'doc_category' && !is_tax('doc_tag')) {
310 echo '<a class="docs-cat-link-btn" href="' . $term_permalink . '">' . esc_html(stripslashes($exploremore_btn_txt)) . '</a>';
311 }
312 echo '</div>
313 </div>';
314 }
315 }
316 echo '</div>';
317 }
318
319 if ($masonry == true ) {
320 $output = betterdocs_generate_output();
321 echo '<script>
322 jQuery(document).ready(function() {
323 let masonryGrid = jQuery(".betterdocs-categories-wrap.layout-masonry");
324 let columnPerGrid = jQuery(".betterdocs-categories-wrap.layout-masonry").attr("data-column");
325 let masonryItem = jQuery(".betterdocs-categories-wrap.layout-masonry .docs-single-cat-wrap");
326 let doc_page_column_space = '.$output['betterdocs_doc_page_column_space'].';
327 let total_margin = (columnPerGrid - 1) * doc_page_column_space;
328 if (masonryGrid.length) {
329 masonryItem.css("width", "calc((100% - "+total_margin+"px) / "+parseInt(columnPerGrid)+")");
330 masonryGrid.masonry({
331 itemSelector: ".docs-single-cat-wrap",
332 percentPosition: true,
333 gutter: doc_page_column_space
334 });
335 }
336 });
337 </script>';
338 }
339 return ob_get_clean();
340 }
341
342 function nested_category_list($term_id, $multiple_kb, $category_id, $post_type, $docs_orderby, $docs_order, $terms_orderby, $terms_order, $page_cat, $kb_slug='', $nested_posts_num = -1) {
343 $sub_categories = BetterDocs_Helper::child_taxonomy_terms($term_id, $multiple_kb, $terms_orderby, $terms_order, $kb_slug);
344 if ($sub_categories) {
345 foreach ($sub_categories as $sub_category) {
346 if (is_single() && in_array($sub_category->term_id, $category_id)) {
347 $subcat_class = 'docs-sub-cat current-sub-cat';
348 } else {
349 $subcat_class = 'docs-sub-cat';
350 }
351
352 echo '<span class="docs-sub-cat-title">
353 ' . BetterDocs_Helper::arrow_right_svg() . '
354 ' . BetterDocs_Helper::arrow_down_svg() . '
355 <a href="#">' . $sub_category->name . '</a></span>';
356
357 echo '<ul class="' . esc_attr($subcat_class) . '">';
358 $sub_args = BetterDocs_Helper::list_query_arg($post_type, $multiple_kb, $sub_category->slug, $nested_posts_num, $docs_orderby, $docs_order, $kb_slug);
359 $sub_args = apply_filters('betterdocs_articles_args', $sub_args, $sub_category->term_id);
360 $sub_post_query = new WP_Query($sub_args);
361
362 if ($sub_post_query->have_posts()) :
363 while ($sub_post_query->have_posts()) : $sub_post_query->the_post();
364 $sub_attr = ['href="' . get_the_permalink() . '"'];
365 if ($page_cat === get_the_ID() && BetterDocs_Helper::get_tax() != 'doc_category') {
366 $sub_attr[] = 'class="active"';
367 }
368 echo '<li class="sub-list">' . BetterDocs_Helper::list_svg() . '<a ' . implode(' ', $sub_attr) . '>' . wp_kses(get_the_title(), BETTERDOCS_KSES_ALLOWED_HTML) . '</a></li>';
369 endwhile;
370 endif;
371 wp_reset_query();
372 nested_category_list( $sub_category->term_id, $multiple_kb, $category_id, $post_type, $docs_orderby, $docs_order, $terms_orderby, $terms_order, $page_cat, $kb_slug, $nested_posts_num );
373 echo '</ul>';
374 }
375 }
376 }
377
378
379 /**
380 * Get the category grid with docs list.
381 * *
382 * @since 1.0.0
383 * *
384 * @param int $atts Get attributes for the categories.
385 * @param int $content Get content to category.
386 */
387 add_shortcode('betterdocs_category_list', 'betterdocs_category_list');
388 function betterdocs_category_list($atts, $content = null)
389 {
390 do_action( 'betterdocs_before_shortcode_load' );
391 ob_start();
392 $alphabetic_order = BetterDocs_DB::get_settings('alphabetically_order_post');
393 $nested_subcategory = BetterDocs_DB::get_settings('nested_subcategory');
394 $get_args = shortcode_atts(
395 array(
396 'post_type' => 'docs',
397 'category' => 'doc_category',
398 'orderby' => BetterDocs_DB::get_settings('alphabetically_order_post'),
399 'order' => BetterDocs_DB::get_settings('docs_order'),
400 'masonry' => '',
401 'column' => '',
402 'posts_per_page' => '',
403 'nested_subcategory' => '',
404 'terms' => '',
405 'terms_orderby' => '',
406 'terms_order' => '',
407 'kb_slug' => '',
408 'multiple_knowledge_base' => false,
409 'title_tag' => 'h2'
410 ),
411 $atts
412 );
413
414 $nested_subcategory = ($nested_subcategory == 1 && $get_args['nested_subcategory'] == '') || ($get_args['nested_subcategory'] == true && $get_args['nested_subcategory'] != "false");
415 $taxonomy_objects = BetterDocs_Helper::taxonomy_object($get_args['multiple_knowledge_base'], $get_args['terms'], $get_args['terms_order'], $get_args['terms_orderby'], $get_args['kb_slug'], $nested_subcategory);
416
417 if ($taxonomy_objects && !is_wp_error($taxonomy_objects)) : ?>
418 <div class="betterdocs-categories-wrap category-list">
419 <?php
420 $term_list = wp_get_post_terms(get_the_ID(), 'doc_category', array("fields" => "all"));
421
422 // get single page category id
423 if (is_single() && $term_list) {
424 $category_id = array_column($term_list, 'term_id');
425 $page_cat = get_the_ID();
426 } else {
427 $category_id = array();
428 $page_cat = '';
429 }
430
431 /**
432 * For Multiple KB
433 */
434 $q_object = get_queried_object();
435 $kb_slug = '';
436
437 if ($q_object instanceof WP_Term) {
438 $kb_slug = $q_object->slug;
439 }
440
441 // display category grid by order
442 foreach ($taxonomy_objects as $term) {
443 $term_id = $term->term_id;
444 $term_slug = $term->slug;
445 $count = $term->count;
446 $get_term_count = betterdocs_get_postcount($count, $term_id, $nested_subcategory);
447 $term_count = apply_filters('betterdocs_postcount', $get_term_count, $get_args['multiple_knowledge_base'], $term_id, $term_slug, $count, $nested_subcategory);
448 if ($term_count > 0) {
449 // set active category class in single page
450 if (is_single() && in_array($term_id, $category_id)) {
451 $wrap_class = 'docs-single-cat-wrap-2 current-category';
452 $title_class = 'active-title';
453 } else {
454 $wrap_class = 'docs-single-cat-wrap-2';
455 $title_class = '';
456 }
457
458 $term_permalink = BetterDocs_Helper::term_permalink('doc_category', $term_slug);
459 ?>
460 <div id="cat-id-<?php echo $term_id; ?>" class="cat tet <?php echo esc_attr($wrap_class) ?>">
461 <div class="<?php echo esc_attr($title_class) ?>">
462 <div class="docs-cat-title-inner">
463 <?php
464 echo '<div class="docs-cat-title"><a href="' . esc_url($term_permalink) . '"><'. BetterDocs_Helper::validate_html_tag($get_args['title_tag']) .' class="docs-cat-heading">' . $term->name . '</'. BetterDocs_Helper::validate_html_tag($get_args['title_tag']) .'></a></div>';
465 ?>
466 </div>
467 </div>
468 <div class="docs-item-container">
469 <?php
470 $list_args = BetterDocs_Helper::list_query_arg('docs', $get_args['multiple_knowledge_base'], $term_slug, -1, $get_args['orderby'], $get_args['order'], $kb_slug);
471 $args = apply_filters('betterdocs_articles_args', $list_args, $term->term_id);
472 $post_query = new WP_Query($args);
473 if ($post_query->have_posts()) :
474
475 echo '<ul>';
476 while ($post_query->have_posts()) : $post_query->the_post();
477 $attr = ['href="' . get_the_permalink() . '"'];
478 if ($page_cat === get_the_ID()) {
479 $attr[] = 'class="active"';
480 }
481 echo '<li><a ' . implode(' ', $attr) . '>' . wp_kses(get_the_title(), BETTERDOCS_KSES_ALLOWED_HTML) . '</a></li>';
482 endwhile;
483
484 echo '</ul>';
485
486 endif;
487 wp_reset_query();
488
489 // Sub category query
490 if (($nested_subcategory == 1 || $get_args['nested_subcategory'] == true) && $get_args['nested_subcategory'] != "false") {
491 nested_category_list(
492 $term_id,
493 $get_args['multiple_knowledge_base'],
494 $category_id,
495 'docs',
496 $get_args['orderby'],
497 $get_args['order'],
498 $get_args['terms_orderby'],
499 $get_args['terms_order'],
500 $page_cat,
501 ''
502 );
503 }
504 ?>
505 </div>
506 </div>
507 <?php }
508 } ?>
509 </div>
510 <?php
511 endif;
512 return ob_get_clean();
513 }
514
515 /**
516 * Get the category grid with docs list.
517 * *
518 * @since 1.0.0
519 * *
520 * @param int $atts Get attributes for the categories.
521 * @param int $content Get content to category.
522 */
523 add_shortcode('betterdocs_category_box', 'betterdocs_category_box');
524 function betterdocs_category_box($atts, $content = null)
525 {
526 do_action( 'betterdocs_before_shortcode_load' );
527 ob_start();
528 $column_number = BetterDocs_DB::get_settings('column_number');
529 $post_count = BetterDocs_DB::get_settings('post_count');
530 $count_text_singular = BetterDocs_DB::get_settings('count_text_singular');
531 $count_text = BetterDocs_DB::get_settings('count_text');
532 $nested_subcategory = BetterDocs_DB::get_settings('nested_subcategory');
533 $get_args = shortcode_atts(
534 array(
535 'post_type' => 'docs',
536 'category' => 'doc_category',
537 'orderby' => BetterDocs_DB::get_settings('alphabetically_order_post'),
538 'column' => '',
539 'nested_subcategory' => '',
540 'terms' => '',
541 'terms_orderby' => BetterDocs_DB::get_settings('alphabetically_order_term'),
542 'terms_order' => '',
543 'icon' => true,
544 'kb_slug' => '',
545 'title_tag' => 'h2',
546 'multiple_knowledge_base' => false,
547 'disable_customizer_style' => false,
548 'border_bottom' => false
549 ),
550 $atts
551 );
552 $post_icon_check = ( $get_args['icon'] == 'true' ) ? true : false;
553 $nested_subcategory = ($nested_subcategory == 1 && $get_args['nested_subcategory'] == '') || ($get_args['nested_subcategory'] == true && $get_args['nested_subcategory'] != "false");
554 $taxonomy_objects = BetterDocs_Helper::taxonomy_object($get_args['multiple_knowledge_base'], $get_args['terms'], $get_args['terms_order'], $get_args['terms_orderby'], $get_args['kb_slug'], $nested_subcategory);
555
556 if ($taxonomy_objects && !is_wp_error($taxonomy_objects)) :
557 $class = ['betterdocs-categories-wrap betterdocs-category-box layout-2 ash-bg'];
558 $class[] = 'layout-flex';
559
560 if (isset($get_args['column']) && $get_args['column'] == true && is_numeric($get_args['column'])) {
561 $class[] = 'docs-col-' . $get_args['column'];
562 } else {
563 $class[] = 'docs-col-' . $column_number;
564 }
565
566 if (isset($get_args['border_bottom']) && $get_args['border_bottom'] == true) {
567 $class[] = 'border-bottom';
568 }
569
570 if ($get_args['disable_customizer_style'] == false) {
571 $class[] = 'single-kb';
572 }
573
574 echo '<div class="'.implode(' ', $class).'">';
575 // display category grid by order
576 foreach ($taxonomy_objects as $term) {
577 $term_id = $term->term_id;
578 $term_slug = $term->slug;
579 $count = $term->count;
580 $get_term_count = betterdocs_get_postcount($count, $term_id, $nested_subcategory);
581 $term_count = apply_filters('betterdocs_postcount', $get_term_count, $get_args['multiple_knowledge_base'], $term_id, $term_slug, $count, $nested_subcategory);
582
583 if ($term_count > 0) {
584 // set active category class in single page
585 $wrap_class = 'docs-single-cat-wrap';
586 $term_permalink = BetterDocs_Helper::term_permalink('doc_category', $term->slug);
587 echo '<a href="'.esc_url($term_permalink).'" class="'.esc_attr($wrap_class).'" id="cat-id-'.$term_id.'">';
588 if($post_icon_check) {
589 $cat_icon_id = get_term_meta($term_id, 'doc_category_image-id', true);
590 if ($cat_icon_id) {
591 echo wp_get_attachment_image($cat_icon_id, 'thumbnail');
592 } else {
593 echo '<img class="docs-cat-icon" src="' . BETTERDOCS_ADMIN_URL . 'assets/img/betterdocs-cat-icon.svg" alt="">';
594 }
595 }
596 echo '<'. BetterDocs_Helper::validate_html_tag($get_args['title_tag']) .' class="docs-cat-title">' . $term->name . '</'. BetterDocs_Helper::validate_html_tag($get_args['title_tag']) .'>';
597 $cat_desc = get_theme_mod('betterdocs_doc_page_cat_desc');
598 if ($cat_desc == true) {
599 echo '<p class="cat-description">' . $term->description . '</p>';
600 }
601 if ($post_count == 1) {
602 if ($term->count == 1) {
603 echo wp_sprintf('<span class="docs-count">%s %s</span>', $term_count, ($count_text_singular) ? $count_text_singular : __('article', 'betterdocs'));
604 } else {
605 echo wp_sprintf('<span class="docs-count">%s %s</span>', $term_count, ($count_text) ? $count_text : __('articles', 'betterdocs'));
606 }
607 }
608 echo '</a>';
609 }
610 }
611 echo '</div>';
612 endif;
613 return ob_get_clean();
614 }
615
616 /**
617 * Advance search search form with live dropdown result
618 * *
619 * @since 1.0.0
620 *
621 */
622 add_shortcode('betterdocs_search_form', 'betterdocs_search_form');
623 function betterdocs_search_form($atts, $content = null)
624 {
625 $get_args = shortcode_atts(
626 apply_filters('betterdocs_search_form_atts', array(
627 'placeholder' => false,
628 'heading' => false,
629 'subheading' => false,
630 'heading_tag' => 'h2',
631 'subheading_tag' => 'h3'
632 )),
633 $atts
634 );
635
636 do_action( 'betterdocs_before_shortcode_load' );
637
638 ob_start();
639 echo '<div class="betterdocs-live-search">';
640 if ( $get_args['heading'] == true || $get_args['subheading'] == true ) {
641 echo '<div class="betterdocs-search-heading">';
642 if ( $get_args['heading'] == true ) {
643 echo '<'.$get_args['heading_tag'].' class="heading"> ' . esc_html($get_args['heading']) . ' </'.$get_args['heading_tag'].'>';
644 }
645
646 if ( $get_args['subheading'] == true ) {
647 echo '<'.$get_args['subheading_tag'].' class="subheading"> ' . esc_html($get_args['subheading']) . ' </'.$get_args['subheading_tag'].'>';
648 }
649 echo '</div>';
650 }
651
652 do_action('betterdocs_before_live_search_form', $get_args);
653
654 echo '<form class="betterdocs-searchform betterdocs-advance-searchform">
655 <div class="betterdocs-searchform-input-wrap">
656 <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">
657 <g id="surface1">
658 <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>
659 </g>
660 </svg>
661 <input type="text" class="betterdocs-search-field" name="s" placeholder="'. $get_args['placeholder'] .'" autocomplete="off" value="'.get_search_query().'">
662 <svg class="docs-search-loader" width="38" height="38" viewBox="0 0 38 38" xmlns="http://www.w3.org/2000/svg" stroke="#444b54">
663 <g fill="none" fill-rule="evenodd">
664 <g transform="translate(1 1)" stroke-width="2">
665 <circle stroke-opacity=".5" cx="18" cy="18" r="18" />
666 <path d="M36 18c0-9.94-8.06-18-18-18">
667 <animateTransform attributeName="transform" type="rotate" from="0 18 18" to="360 18 18" dur="1s" repeatCount="indefinite" />
668 </path>
669 </g>
670 </g>
671 </svg>
672 <svg class="docs-search-close" xmlns="http://www.w3.org/2000/svg" width="38px" viewBox="0 0 128 128">
673 <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>
674 <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>
675 <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>
676 <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>
677 </svg>
678 </div>';
679
680 do_action('betterdocs_live_search_form_footer', $get_args);
681
682 echo '<input type="hidden" value="Search" class="betterdocs-search-submit">';
683 echo '</form>';
684
685 do_action('betterdocs_after_live_search_form', $get_args);
686
687 echo '</div>';
688 return ob_get_clean();
689 }
690
691 /**
692 * Get the search result from ajax load.
693 * *
694 * @since 1.0.0
695 *
696 */
697 add_action('wp_ajax_nopriv_betterdocs_get_search_result', 'betterdocs_get_search_result');
698 add_action('wp_ajax_betterdocs_get_search_result', 'betterdocs_get_search_result');
699 function betterdocs_get_search_result() {
700 global $wpdb;
701 $search_input = isset($_POST['search_input']) ? sanitize_text_field($_POST['search_input']) : '';
702 $search_cat = isset($_POST['search_cat']) ? wp_strip_all_tags($_POST['search_cat']) : '';
703 $search_input = preg_replace('/[^A-Za-z0-9_\- ][]]/', '', strtolower($search_input));
704 $args = array(
705 'post_type' => 'docs',
706 'post_status' => 'publish',
707 'posts_per_page' => -1,
708 'suppress_filters' => true,
709 's' => $search_input,
710 );
711 $tax_query = '';
712 if($search_cat) {
713 $tax_query = array(
714 array(
715 'taxonomy' => 'doc_category',
716 'field' => 'slug',
717 'terms' => $search_cat,
718 'operator' => 'AND',
719 'include_children' => true
720 )
721 );
722 }
723
724 $args['tax_query'] = array(
725 apply_filters('betterdocs_live_search_tax_query', $tax_query, $_POST)
726 );
727
728 $args = apply_filters('betterdocs_articles_args', $args);
729 $loop = new WP_Query($args);
730 $output = '<div class="betterdocs-search-result-wrap"><ul class="docs-search-result">';
731 if ($loop->have_posts()) :
732 $input_not_found = '';
733 while ($loop->have_posts()) : $loop->the_post();
734 preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', get_the_content(), $matches);
735
736 if ($matches[1]) {
737 $first_img = $matches[1][0];
738 } else {
739 $first_img = '';
740 }
741
742 $terms = get_the_terms(get_the_ID(), 'doc_category');
743 $terms_name = array();
744
745 if ( $terms && ! is_wp_error( $terms ) ) {
746 foreach ($terms as $term) {
747 $terms_name[] = $term->name;
748 }
749 }
750
751 $all_terms = join(", ", $terms_name);
752 $icon = '';
753 $search_result_image = BetterDocs_DB::get_settings('search_result_image');
754 if ($search_result_image == 1 && has_post_thumbnail()) {
755 $icon = get_the_post_thumbnail();
756 } elseif ($search_result_image == 1 && !empty($first_img)) {
757 $icon = '<img src="' . $first_img . '" alt="">';
758 }
759 $output .= '<li>' . $icon . '<a href="' . get_permalink() . '"><span class="betterdocs-search-title">' . wp_kses(get_the_title(), BETTERDOCS_KSES_ALLOWED_HTML) . '</span><br><span class="betterdocs-search-category">' . $all_terms . '</span></a></li>';
760 endwhile;
761 else :
762 $input_not_found = $search_input;
763 $output .= '<li>' . stripslashes(BetterDocs_DB::get_settings('search_not_found_text')) . '</li>';
764 endif;
765 $output .= '</ul></div>';
766 $response[ 'post_lists' ] = $output;
767
768 if ( $output && strlen( $search_input ) >= 3) {
769 BetterDocs_Helper::search_insert($search_input, $input_not_found);
770 }
771 wp_send_json_success( $response );
772 wp_reset_postdata();
773 die();
774 }
775
776 /**
777 * feedback form shortcode
778 * *
779 * @since 1.0.0
780 *
781 */
782 add_shortcode('betterdocs_feedback_form', 'betterdocs_feedback_form');
783 function betterdocs_feedback_form($atts, $content = null)
784 {
785 do_action( 'betterdocs_before_shortcode_load' );
786 $get_args = shortcode_atts(
787 array(
788 'button_text' => esc_html__('Send', 'betterdocs')
789 ),
790 $atts
791 );
792 ob_start();
793 if (is_user_logged_in()) {
794 $userdata = get_userdata(get_current_user_id());
795 $name = $userdata->first_name . ' ' . $userdata->last_name;
796 $email = $userdata->user_email;
797 } else {
798 $name = '';
799 $email = '';
800 }
801
802 ?>
803 <div class="form-wrapper">
804 <div class="response"></div>
805 <form id="betterdocs-feedback-form" class="betterdocs-feedback-form" action="" method="post">
806 <p><label for="message_name" class="form-name">
807 <?php esc_html_e('Name:', 'betterdocs') ?> <span>*</span> <br>
808 <input type="text" id="message_name" name="message_name" value="<?php echo esc_html($name) ?>">
809 </label>
810 </p>
811 <p><label for="message_email" class="form-email">
812 <?php esc_html_e('Email:', 'betterdocs') ?> <span>*</span> <br>
813 <input type="text" id="message_email" name="message_email" value="<?php echo esc_html($email) ?>">
814 </label>
815 </p>
816 <p><label for="message_text" class="form-message">
817 <?php esc_html_e('Message:', 'betterdocs') ?> <span>*</span> <br>
818 <textarea type="text" id="message_text" name="message_text"></textarea>
819 </label>
820 </p>
821 <div class="feedback-from-button">
822 <input type="hidden" name="submitted" value="1">
823 <input type="submit" name="submit" class="button" id="feedback_form_submit_btn" value="<?php echo esc_attr($get_args['button_text']) ?>" />
824 </div>
825 </form>
826 </div>
827 <?php
828 return ob_get_clean();
829 }
830
831 /**
832 * Submit form via ajax
833 * *
834 * @since 1.0.0
835 *
836 */
837 add_action('wp_ajax_nopriv_betterdocs_feedback_form_submit', 'betterdocs_feedback_form_submit');
838 add_action('wp_ajax_betterdocs_feedback_form_submit', 'betterdocs_feedback_form_submit');
839
840 function betterdocs_feedback_form_submit()
841 {
842 check_ajax_referer( 'betterdocs_submit_data', 'security' );
843 $postID = isset($_POST['postID']) ? $_POST['postID'] : '';
844 $article = get_the_title($postID);
845 $name = isset($_POST['message_name']) ? sanitize_text_field(stripslashes($_POST['message_name'])) : '';
846 $email = isset($_POST['message_email']) ? sanitize_email(stripslashes($_POST['message_email'])) : '';
847 $message_text = isset($_POST['message_text']) ? sanitize_textarea_field(stripslashes($_POST['message_text'])) : '';
848 $message = <<<EOD
849 Name : {$name} <br>
850 Docs : {$article}
851 Email: {$email}
852 {$message_text}
853 EOD;
854
855 //response messages
856 $missing_name = esc_html__('Please enter your name.', 'betterdocs');
857 $email_invalid = esc_html__('Enter a valid email address.', 'betterdocs');
858 $missing_message = esc_html__('Please write your message.', 'betterdocs');
859 $message_unsent = esc_html__('Message was not sent. Try Again.', 'betterdocs');
860 $message_sent = esc_html__('Thanks! Your message has been sent.', 'betterdocs');
861
862 //php mailer variables
863 $to = BetterDocs_DB::get_settings('email_address');
864 if (empty($to)) {
865 $to = get_option('admin_email');
866 }
867
868 $subject = wp_sprintf( '%s %s', __( 'Feedback message from', 'betterdocs' ), get_bloginfo( 'name' ) );
869 $headers = 'From: ' . $email . "\r\n" .
870 'Reply-To: ' . $email . "\r\n";
871 $response = array();
872
873 //validate presence of name
874 if (empty($name)) {
875 $response['nameStatus'] = 'error';
876 $response['nameMessage'] = $missing_name;
877 }
878
879 //validate email
880 if (empty($email) && !filter_var($email, FILTER_VALIDATE_EMAIL)) {
881 $response['emailStatus'] = 'error';
882 $response['emailMessage'] = $email_invalid;
883 }
884
885 //validate presence of message
886 if (empty($message_text)) {
887 $response['messageStatus'] = 'error';
888 $response['messageMessage'] = $missing_message;
889 }
890
891 if (!empty($name) && !empty($email) && filter_var($email, FILTER_VALIDATE_EMAIL) && !empty($message_text)) {
892 $sent = wp_mail($to, $subject, strip_tags($message), $headers);
893 if ($sent) {
894 $response['sentStatus'] = 'success';
895 $response['sentMessage'] = $message_sent;
896 } else {
897 $response['sentStatus'] = 'error';
898 $response['sentMessage'] = $message_unsent;
899 }
900 }
901 echo json_encode($response);
902 die();
903 }
904
905 /**
906 * Social Share Shortcode
907 * *
908 * @since 1.0.0
909 *
910 */
911 add_shortcode('betterdocs_social_share', 'betterdocs_social_share');
912 function betterdocs_social_share($atts, $content = null)
913 {
914 do_action( 'betterdocs_before_shortcode_load' );
915 $get_args = shortcode_atts(
916 array(
917 'title' => esc_html__('Share This Article :', 'betterdocs'),
918 'facebook_sharing' => '1',
919 'twitter_sharing' => '1',
920 'linkedin_sharing' => '1',
921 'pinterest_sharing' => '1'
922 ),
923 $atts
924 );
925 $thumbnail = '';
926 if (function_exists('has_post_thumbnail')) {
927 if (has_post_thumbnail()) {
928 $thumbnail = wp_get_attachment_url(get_post_thumbnail_id());
929 }
930 }
931
932 ?>
933 <div class="betterdocs-social-share">
934 <div class="betterdocs-social-share-heading">
935 <?php
936 if ($get_args['title']) :
937 echo '<h5>' . esc_html($get_args['title']) . '</h5>';
938 endif;
939 ?>
940 </div>
941 <ul class="betterdocs-social-share-links">
942 <?php if ($get_args['facebook_sharing'] == true) : ?>
943 <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="Facebook"></a></li>
944 <?php endif; ?>
945
946 <?php if ($get_args['twitter_sharing'] == true) : ?>
947 <li><a href="https://twitter.com/intent/tweet?url=<?php the_permalink(); ?>" target="_blank"><img src="<?php echo BETTERDOCS_URL ?>public/img/twitter.svg" alt="Twitter"></a></li>
948 <?php endif; ?>
949
950 <?php if ($get_args['linkedin_sharing'] == true) : ?>
951 <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="LinkedIn"></a></li>
952 <?php endif; ?>
953
954 <?php if ($get_args['pinterest_sharing'] == true) : ?>
955 <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="Pinterest"></a></li>
956 <?php endif; ?>
957 </ul>
958 </div> <!-- Social Share end-->
959 <?php }
960
961
962 add_shortcode('betterdocs_post_content', 'betterdocs_post_content');
963 function betterdocs_post_content($atts, $content = null)
964 {
965 do_action( 'betterdocs_before_shortcode_load' );
966 $get_args = shortcode_atts(
967 array(
968 'post_id' => get_the_ID(),
969 'htags' => 'h1,h2,h3,h4,h5,h6',
970 'enable_toc' => '',
971 'toc_hierarchy' => '',
972 'list_number' => '',
973 'display_toc_on_top' => '',
974 'collapsible_toc_mobile' => ''
975 ),
976 $atts
977 );
978
979 $get_post = get_post($get_args['post_id']);
980 $post_content = $get_post->post_content;
981 $the_content = BetterDocs_Public::betterdocs_the_content(
982 $post_content,
983 $get_args['htags'],
984 $get_args['enable_toc']
985 );
986
987 return $the_content;
988 }
989
990 add_shortcode('betterdocs_faq_list_modern', 'betterdocs_faq_list_modern');
991
992 function betterdocs_faq_list_modern( $atts, $content = null ) {
993 do_action( 'betterdocs_before_shortcode_load' );
994
995 ob_start();
996
997 $get_args = shortcode_atts(
998 array(
999 'groups' => '',
1000 'class' => '',
1001 'group_exclude' => '',
1002 'faq_heading' => __('Frequently Asked Questions', 'betterdocs'),
1003 'faq_schema' => false
1004 ),
1005 $atts
1006 );
1007
1008 $class = ! empty( $get_args['class'] ) ? ' '.$get_args['class'] : '';
1009
1010 $faq_terms = BetterDocs_Helper::faq_category_terms( $get_args['groups'], $get_args['group_exclude'] );
1011
1012 $faq_markup = ! empty( $faq_terms ) ? '<h2 class="betterdocs-faq-section-title'.$class.'">'.$get_args['faq_heading'].'</h2>' : '';
1013
1014 $faq_markup .= '<div class="betterdocs-faq-main-wrapper betterdocs-faq-main-wrapper-layout-1'.$class.'">';
1015
1016 if( ! is_wp_error( $faq_terms ) ) {
1017
1018 if ( $get_args['faq_schema'] == 'true' ) {
1019 $json = [
1020 '@context' => 'https://schema.org',
1021 '@type' => 'FAQPage',
1022 'mainEntity' => [],
1023 ];
1024 }
1025
1026 foreach( $faq_terms as $term ) {
1027 $term_count = isset( $term->count ) ? $term->count : '';
1028 $term_title = isset( $term->name ) ? $term->name : '';
1029 $term_id = isset( $term->term_id ) ? $term->term_id : '';
1030 $faq_markup .= '<div class="betterdocs-faq-title"><h2>'.$term_title.'</h2></div>';
1031 if( $term_count > 0 ) {
1032 $faq_args = $faq_terms = BetterDocs_Helper::faq_args( $term_id );
1033 $faq_query = new WP_Query( $faq_args );
1034 if ( $faq_query->have_posts() ) {
1035 $faq_markup .= '<ul class="betterdocs-faq-list">';
1036 while ( $faq_query->have_posts() ) : $faq_query->the_post();
1037 $faq_markup .= '<li>';
1038 $faq_markup .= '<div class="betterdocs-faq-group">';
1039 $faq_markup .= '<div class="betterdocs-faq-post">';
1040 $faq_markup .= '<span class="betterdocs-faq-post-name">'. get_the_title() .'</span>';
1041 $faq_markup .= '<svg class="betterdocs-faq-iconminus" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" stroke-width="2"><g fill="none" stroke="#528ffe" stroke-linecap="round" stroke-miterlimit="10" stroke-linejoin="round"><path d="M17 12H7"></path><circle cx="12" cy="12" r="11"></circle></g></svg>';
1042 $faq_markup .= '<svg class="betterdocs-faq-iconplus" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><g stroke-width="2" fill="none" stroke="#528ffe" stroke-linecap="square" stroke-miterlimit="10"><path d="M12 7v10M17 12H7"></path><circle cx="12" cy="12" r="11"></circle></g></svg>';
1043 $faq_markup .= '</div>';
1044 $faq_markup .= '<div class="betterdocs-faq-main-content">';
1045 $faq_markup .= get_the_content();
1046 $faq_markup .= '</div>';
1047 $faq_markup .= '</li>';
1048 if ( $get_args['faq_schema'] == 'true' ) {
1049 $json['mainEntity'][] = [
1050 '@type' => 'Question',
1051 'name' => get_the_title(),
1052 'acceptedAnswer' => [
1053 '@type' => 'Answer',
1054 'text' => get_the_content(),
1055 ],
1056 ];
1057 }
1058 endwhile;
1059 $faq_markup .= '</ul>';
1060
1061 wp_reset_postdata();
1062 } else {
1063 echo '<p>' . esc_html__( 'Sorry, no FAQ matched your criteria.', 'betterdocs') . '</p>';
1064 }
1065 }
1066 }
1067
1068 if ( $get_args['faq_schema'] == 'true' ) {
1069 echo '<script type="application/ld+json">'. wp_json_encode( $json ) .'</script>';
1070 }
1071 }
1072 $faq_markup .= '</div>';
1073
1074 echo $faq_markup;
1075
1076 return ob_get_clean();
1077 }
1078
1079
1080 add_shortcode('betterdocs_faq_list_classic', 'betterdocs_faq_list_classic');
1081
1082 function betterdocs_faq_list_classic( $atts, $content = null ) {
1083 do_action( 'betterdocs_before_shortcode_load' );
1084
1085 ob_start();
1086
1087 $get_args = shortcode_atts(
1088 array(
1089 'groups' => '',
1090 'class' => '',
1091 'group_exclude' => '',
1092 'faq_heading' => __('Frequently Asked Questions', 'betterdocs'),
1093 'faq_schema' => false
1094 ),
1095 $atts
1096 );
1097
1098 $class = ! empty( $get_args['class'] ) ? ' '.$get_args['class'] : '';
1099
1100 $faq_terms = BetterDocs_Helper::faq_category_terms( $get_args['groups'], $get_args['group_exclude'] );
1101
1102 $faq_markup = ! empty( $faq_terms ) ? '<h2 class="betterdocs-faq-section-title'.$class.'">'.$get_args['faq_heading'].'</h2>' : '';
1103
1104 $faq_markup .= '<div class="betterdocs-faq-main-wrapper betterdocs-faq-main-wrapper-layout-2'.$class.'">';
1105
1106 if( ! is_wp_error( $faq_terms ) ) {
1107
1108 if ( $get_args['faq_schema'] == 'true' ) {
1109 $json = [
1110 '@context' => 'https://schema.org',
1111 '@type' => 'FAQPage',
1112 'mainEntity' => [],
1113 ];
1114 }
1115
1116 foreach( $faq_terms as $term ) {
1117 $term_count = isset( $term->count ) ? $term->count : '';
1118 $term_title = isset( $term->name ) ? $term->name : '';
1119 $term_slug = isset( $term->slug ) ? $term->slug : '';
1120 $term_id = isset( $term->term_id ) ? $term->term_id : '';
1121
1122 $faq_markup .= '<div class="betterdocs-faq-title betterdocs-faq-title-layout-2"><h2>'.$term_title.'</h2></div>';
1123
1124 if ( $term_count > 0 ) {
1125 $faq_args = $faq_terms = BetterDocs_Helper::faq_args( $term_id );
1126 $faq_query = new WP_Query( $faq_args );
1127 if( $faq_query->have_posts() ) {
1128 $faq_markup .= '<ul class="betterdocs-faq-list betterdocs-faq-list-layout-2">';
1129 while ( $faq_query->have_posts() ) : $faq_query->the_post();
1130 $faq_markup .= '<li>';
1131 $faq_markup .= '<div class="betterdocs-faq-group betterdocs-faq-group-layout-2">';
1132 $faq_markup .= '<div class="betterdocs-faq-post-layout-2">';
1133 $faq_markup .= '<div class="betterdocs-faq-post-layout-2-icon-group">';
1134 $faq_markup .= '<svg class="betterdocs-faq-iconplus-layout-2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="#000000" d="M18 10h-4V6h-4v4H6v4h4v4h4v-4h4"></path></svg>';
1135 $faq_markup .= '<svg class="betterdocs-faq-iconminus-layout-2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="#000000" d="M6 10h12v4H6z"></path></svg>';
1136 $faq_markup .= '</div>';
1137 $faq_markup .= '<span class="betterdocs-faq-post-name betterdocs-faq-post-name-layout-2">'. get_the_title() .'</span>';
1138 $faq_markup .= '</div>';
1139 $faq_markup .= '<div class="betterdocs-faq-main-content betterdocs-faq-main-content-layout-2">';
1140 $faq_markup .= get_the_content();
1141 $faq_markup .= '</div>';
1142 $faq_markup .= '</li>';
1143 if ( $get_args['faq_schema'] == 'true' ) {
1144 $json['mainEntity'][] = [
1145 '@type' => 'Question',
1146 'name' => get_the_title(),
1147 'acceptedAnswer' => [
1148 '@type' => 'Answer',
1149 'text' => get_the_content(),
1150 ],
1151 ];
1152 }
1153 endwhile;
1154 $faq_markup .= '</ul>';
1155
1156
1157
1158 wp_reset_postdata();
1159 } else {
1160 echo '<p>' . esc_html__( 'Sorry, no FAQ matched your criteria.', 'betterdocs') . '</p>';
1161 }
1162 }
1163 }
1164
1165 if ( $get_args['faq_schema'] == 'true' ) {
1166 echo '<script type="application/ld+json">'. wp_json_encode( $json ) .'</script>';
1167 }
1168 }
1169
1170 $faq_markup .= '</div>';
1171
1172 echo $faq_markup;
1173
1174 return ob_get_clean();
1175 }