PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 4.6.0
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v4.6.0
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 / views / layouts / base.php

base.php in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 4.6.0, at views/layouts/base.php

181 lines 6.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- view template receives variables via extract(); prefixing is impractical.
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7 if ( $terms_query_args == false ) {
8 return;
9 }
10 $terms = get_terms( apply_filters( 'betterdocs_base_terms_args', $terms_query_args ) );
11 /**
12 * Base Layout Before Wrapper
13 */
14 do_action_ref_array( 'betterdocs_base_layout_wrapper_before', [ & $terms ] );
15 ?>
16
17 <div
18 <?php echo $wrapper_attr; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
19 <?php
20 /**
21 * Base Layout Before Inner Wrapper
22 */
23 do_action_ref_array( 'betterdocs_base_layout_inner_wrapper_before', [ & $terms ] );
24 ?>
25 <div
26 <?php echo $inner_wrapper_attr; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
27 <?php
28 $_defined_vars = get_defined_vars();
29 $_params = isset( $_defined_vars['params'] ) ? $_defined_vars['params'] : [];
30
31 $nested_subcategory = isset( $nested_subcategory ) ? $nested_subcategory : false;
32
33 $_current_queried_object_id = null;
34 $_current_queried_object = get_queried_object();
35
36 if ( $_current_queried_object instanceof \WP_Post ) {
37 $_current_terms = get_the_terms( $_current_queried_object->ID, 'doc_category' );
38 $_current_queried_object_id = isset( $_current_terms[0]->term_id ) ? $_current_terms[0]->term_id : null;
39 } elseif ( $_current_queried_object instanceof \WP_Term ) {
40 $_current_queried_object_id = $_current_queried_object->term_id;
41 }
42
43 $ancestors = [];
44
45 if ( is_single() && ! empty( $_current_queried_object_id ) ) {
46 $_category_ids = wp_get_post_terms( get_the_ID(), 'doc_category', [ 'fields' => 'ids' ] );
47 $ancestors = get_ancestors( $_category_ids[0], 'doc_category' );
48 }
49
50 if ( ! is_wp_error( $terms ) ) {
51 do_action_ref_array( 'betterdocs_layout_base_loop_start', [ & $terms, &$_defined_vars ] );
52
53 $_docs_query_args = [
54 'posts_per_page' => isset( $_params['posts_per_page'] ) ? $_params['posts_per_page'] : 0,
55 'multiple_kb' => isset( $_params['multiple_knowledge_base'] ) ? $_params['multiple_knowledge_base'] : false,
56 'kb_slug' => isset( $_params['kb_slug'] ) ? $_params['kb_slug'] : ''
57 ];
58
59 $docs_query_args = ! isset( $docs_query_args ) ? $_docs_query_args : wp_parse_args( $docs_query_args, $_docs_query_args );
60
61 $terms_count = count( $terms );
62 $terms_number = 1;
63 foreach ( $terms as $term ) {
64 $_counts = betterdocs()->query->get_docs_count(
65 $term,
66 $nested_subcategory,
67 [
68 'multiple_knowledge_base' => isset( $_params['multiple_knowledge_base'] ) ? $_params['multiple_knowledge_base'] : false,
69 'kb_slug' => isset( $_params['kb_slug'] ) ? $_params['kb_slug'] : ''
70 ]
71 );
72
73 if ( $_counts <= 0 ) {
74 continue;
75 }
76
77 if ( $widget_type == 'category-box' || ( $widget_type == 'category-grid' && $layout == 'layout-2' ) ) {
78 $_counts = [
79 'counts' => $_counts,
80 'prefix' => ! empty( $count_prefix ) ? $count_prefix : '',
81 'suffix' => ! empty( $count_suffix ) ? $count_suffix : '',
82 'suffix_singular' => ! empty( $count_suffix_singular ) ? $count_suffix_singular : ''
83 ];
84 }
85
86 // Count Sub Terms
87 $sub_terms_count = 0;
88 if ( isset( $_params['taxonomy'] ) && $_params['taxonomy'] == 'doc_category' ) {
89 $sub_terms_count = count( betterdocs()->query->get_all_child_term_ids( $_params['taxonomy'], $term->term_id ) );
90 } elseif ( isset( $_params['taxonomy'] ) && $_params['taxonomy'] == 'knowledge_base' ) {
91 $count_doc_categories = betterdocs()->query->count_doc_categories_for_knowledge_base( $term->slug );
92 $sub_terms_count = $count_doc_categories;
93 }
94
95
96 $permalink = apply_filters(
97 'betterdocs_term_permalink',
98 get_term_link( $term->term_id, $term->taxonomy ),
99 $term,
100 'doc_category',
101 $_params
102 );
103
104 $docs_query_args['term_id'] = $term->term_id;
105 $docs_query_args['term_slug'] = $term->slug;
106 $docs_query_args['nested_subcategory'] = $nested_subcategory;
107
108 $_params = wp_parse_args(
109 [
110 'permalink' => $permalink,
111 'wrapper_class' => [ $layout ],
112 'term' => $term,
113 'counts' => $_counts,
114 'terms_count' => $terms_count,
115 'terms_number' => $terms_number,
116 'sub_terms_count' => $sub_terms_count,
117 'queried_object' => $_current_queried_object,
118 'current_queried_object_id' => $_current_queried_object_id,
119 'ancestors' => $ancestors,
120 'query_args' => betterdocs()->query->docs_query_args( $docs_query_args )
121 ],
122 $_params
123 );
124
125 $template_params = apply_filters( 'betterdocs_template_params', $_params, $layout, $term, $widget_type );
126 $layout_filename = apply_filters( 'betterdocs_layout_filename', $layout, $layout, $widget_type );
127 $layout_filename = sanitize_file_name( $layout_filename );
128
129 betterdocs()->views->get( 'layouts/' . $widget_type . '/' . $layout_filename, $template_params );
130 ++$terms_number;
131 --$terms_count;
132 }
133
134 do_action_ref_array( 'betterdocs_layout_base_loop_end', [ & $terms, &$_defined_vars ] );
135 } else {
136 betterdocs()->views->get( 'layout-parts/no-content' );
137 }
138
139 wp_reset_postdata();
140 ?>
141 </div>
142 <?php
143 /**
144 * Base Layout After Inner Wrapper
145 */
146 do_action_ref_array( 'betterdocs_base_layout_inner_wrapper_after', [ & $terms ] );
147 ?>
148 <div class="clearfix"></div>
149 <?php if ( isset( $is_edit_mode ) && $is_edit_mode && $widget_type == 'category-grid' ) : ?>
150 <script>
151 /**
152 * TODO: Not working in Elementor Editor on first Load.
153 */
154 jQuery(document).ready(function($) {
155 $('.betterdocs-category-grid').each(function() {
156 let $grid = $(this),
157 $layout_mode = $grid.data('layout-mode'),
158 $column = $grid.data('column'),
159 $column_space = $grid.data('column_space');
160 if ($layout_mode === 'masonry') {
161 let masonryItem = $(".betterdocs-single-category-wrapper", $grid);
162 let total_margin = ($column - 1) * $column_space;
163 masonryItem.css("width", "calc((100% - " + total_margin + "px) / " + parseInt($column) + ")");
164 $grid.masonry({
165 itemSelector: ".betterdocs-single-category-wrapper",
166 percentPosition: true,
167 gutter: $column_space
168 });
169 }
170 });
171 });
172 </script>
173 <?php endif; ?>
174 </div>
175 <?php
176 /**
177 * Base Layout After Wrapper
178 */
179 do_action_ref_array( 'betterdocs_base_layout_wrapper_after', [ & $terms ] );
180 ?>
181