PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 3.8.1
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v3.8.1
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
betterdocs / includes / Editors / BlockEditor / Blocks / CategoryGrid.php

CategoryGrid.php in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 3.8.1, at includes/Editors/BlockEditor/Blocks/CategoryGrid.php

230 lines 8.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPDeveloper\BetterDocs\Editors\BlockEditor\Blocks;
4
5 use WPDeveloper\BetterDocs\Editors\BlockEditor\Block;
6
7 class CategoryGrid extends Block {
8 protected $editor_scripts = [
9 'betterdocs-blocks-editor',
10 'betterdocs-categorygrid'
11 ];
12
13 protected $editor_styles = [
14 'betterdocs-blocks-editor',
15 'betterdocs-fontawesome',
16 'betterdocs-blocks-category-grid'
17 ];
18
19 protected $frontend_scripts = [
20 'betterdocs-category-grid'
21 ];
22 protected $frontend_styles = [
23 'betterdocs-fontawesome',
24 'betterdocs-blocks-category-grid'
25 ];
26
27 /**
28 * unique name of block
29 * @return string
30 */
31 public function get_name() {
32 return 'categorygrid';
33 }
34
35 public function register_scripts() {
36 //when thrive editor mode is active, do not enqueue this script, this causes an issue with thrive edit mode
37 $check_for_thrive = isset( $_GET['action'] ) ? $_GET['action'] : '';
38
39 //when thrive editor mode is active, do not enqueue this script, this causes an issue with thrive edit mode
40 if ( $check_for_thrive == 'architect' ) {
41 return;
42 }
43
44 $this->assets_manager->enqueue(
45 'betterdocs-categorygrid',
46 'blocks/categorygrid/frontend.js',
47 ['masonry']
48 );
49 }
50
51 public function get_default_attributes() {
52 return [
53 'blockId' => '',
54 'categories' => [],
55 'includeCategories' => '',
56 'excludeCategories' => '',
57 'gridPerPage' => 9,
58 'subCategoryPerGrid' => 2,
59 'orderBy' => 'name',
60 'order' => 'asc',
61 'layout' => 'default',
62 'showTitle' => true,
63 'titleTag' => 'h2',
64 'showCount' => true,
65 'showIcon' => true,
66 'showList' => true,
67 'layoutMode' => 'grid',
68 'showHeader' => true,
69 'showButton' => true,
70 'listIcon' => 'far fa-file-alt',
71 'postsPerPage' => 5,
72 'postsOrderBy' => 'date',
73 'postsOrder' => 'asc',
74 'enableNestedSubcategory' => false,
75 'postPerSubcategory' => 3,
76 'buttonIconPosition' => 'after',
77 'buttonIcon' => 'fas fa-angle-right',
78 'buttonPosition' => 'after',
79 'showButtonIcon' => true,
80 'colRange' => 3,
81 'TABcolRange' => 2,
82 'MOBcolRange' => 1,
83 'gridSpaceRange' => 10,
84 'TABgridSpaceRange' => 10,
85 'MOBgridSpaceRange' => 10,
86 'buttonText' => __( 'Explore More', 'betterdocs' ),
87 'categoryTitleLink' => false,
88 'selectKB' => '',
89 'listIconImageUrl' => '',
90 'prefix' => '',
91 'suffix' => '',
92 'suffixSingular' => ''
93 ];
94 }
95
96 public function render( $attributes, $content ) {
97 $this->views( 'layouts/base' );
98 }
99
100 public function view_params() {
101 $attributes = &$this->attributes;
102
103 $terms_object = [
104 'taxonomy' => 'doc_category',
105 'order' => $attributes['order'],
106 'orderby' => $attributes['orderBy'],
107 'number' => isset( $attributes['gridPerPage'] ) ? $attributes['gridPerPage'] : 5,
108 'hide_empty' => true
109 ];
110
111 if ( 'doc_category_order' === $attributes['orderBy'] ) {
112 $terms_object['meta_key'] = 'doc_category_order';
113 $terms_object['orderby'] = 'meta_value_num';
114 }
115
116 if ( $attributes['enableNestedSubcategory'] ) {
117 $terms_object['parent'] = 0;
118 }
119
120 $includes = $this->string_to_array( $attributes['includeCategories'] );
121 $excludes = $this->string_to_array( $attributes['excludeCategories'] );
122
123 if ( ! empty( $includes ) ) {
124 $terms_object['include'] = array_diff( $includes, (array) $excludes );
125 }
126
127 if ( ! empty( $excludes ) ) {
128 $terms_object['exclude'] = $excludes;
129 }
130
131 $_wrapper_classes = [
132 'betterdocs-category-grid-wrapper',
133 'betterdocs-blocks-grid'
134 ];
135
136 $layout_class = ( $attributes['layout'] === 'default' ) ? 'layout-1' : $attributes['layout'];
137
138 $_inner_wrapper_classes = [
139 'betterdocs-category-grid-inner-wrapper',
140 'layout-flex',
141 $layout_class,
142 $attributes['layoutMode'],
143 "betterdocs-column-" . $attributes['colRange'],
144 "betterdocs-column-tablet-" . $attributes['TABcolRange'],
145 "betterdocs-column-mobile-" . $attributes['MOBcolRange']
146 ];
147
148 $wrapper_attr = [
149 'class' => $_wrapper_classes
150 ];
151
152 $inner_wrapper_attr = [
153 'class' => $_inner_wrapper_classes,
154 'data-column_desktop' => $attributes['colRange'],
155 'data-column_tab' => $attributes['TABcolRange'],
156 'data-column_mobile' => $attributes['MOBcolRange'],
157 'data-column_space_desktop' => $attributes['gridSpaceRange'],
158 'data-colomn_space_tab' => $attributes['TABgridSpaceRange'],
159 'data-colomn_space_mobile' => $attributes['MOBgridSpaceRange']
160 ];
161
162 $docs_query = [
163 'orderby' => $attributes['postsOrderBy'],
164 'order' => $attributes['postsOrder'],
165 'posts_per_page' => $attributes['postsPerPage'],
166 'nested_subcategory' => $attributes['enableNestedSubcategory']
167 ];
168
169 $default_multiple_kb = betterdocs()->settings->get( 'multiple_kb' );
170 $kb_slug = ! empty( $attributes['selectKB'] ) && isset( $attributes['selectKB'] ) ? json_decode( $attributes['selectKB'] )->value : '';
171
172 if ( is_tax( 'knowledge_base' ) && $default_multiple_kb == 1 ) {
173 $object = get_queried_object();
174 $terms_object['meta_query'] = [
175 'relation' => 'OR',
176 [
177 'key' => 'doc_category_knowledge_base',
178 'value' => $object->slug,
179 'compare' => 'LIKE'
180 ]
181 ];
182 }
183
184 if ( ! empty( $kb_slug ) ) {
185 $terms_object['meta_query'] = [
186 'relation' => 'OR',
187 [
188 'key' => 'doc_category_knowledge_base',
189 'value' => $kb_slug,
190 'compare' => 'LIKE'
191 ]
192 ];
193 }
194
195 /**
196 * Add This Attribute When Using Outside Betterdocs Templates Only
197 */
198 if ( $default_multiple_kb == 1 && ( ! empty( $kb_slug ) ) && ( ! betterdocs()->helper->is_templates() ) ) {
199 $inner_wrapper_attr['data-mkb-slug'] = $kb_slug;
200 }
201
202 return [
203 'wrapper_attr' => $wrapper_attr,
204 'inner_wrapper_attr' => $inner_wrapper_attr,
205 'terms_query_args' => betterdocs()->query->terms_query( $terms_object ),
206 'docs_query_args' => $docs_query,
207 'widget_type' => 'category-grid',
208 'multiple_knowledge_base' => $default_multiple_kb,
209 'nested_terms_query' => [
210 'number' => $attributes['subCategoryPerGrid']
211 ],
212 'list_icon_url' => '', // not needed for blocks, provided the prop for formality
213 'layout_type' => 'block',
214 'nested_docs_query_args' => [
215 'orderby' => $attributes['postsOrderBy'],
216 'order' => $attributes['postsOrder'],
217 'posts_per_page' => $attributes['postPerSubcategory']
218 ],
219 'list_icon_name' => ! empty( $attributes['listIconImageUrl'] ) ? ['value' => ['url' => str_replace( 'blob:', '', $attributes['listIconImageUrl'] )]] : ( ! empty( $attributes['listIcon'] ) ? ['value' => ['url' => $attributes['listIcon']]] : ( ! empty( betterdocs()->settings->get( 'docs_list_icon' ) ) ? ['value' => ['url' => betterdocs()->settings->get( 'docs_list_icon' )['url']]] : [] ) ),
220 'button_icon' => [
221 'value' => $attributes['buttonIcon']
222 ],
223 'category_title_link' => $attributes['categoryTitleLink'],
224 'count_prefix' => $attributes['prefix'],
225 'count_suffix' => $attributes['suffix'],
226 'count_suffix_singular' => $attributes['suffixSingular']
227 ];
228 }
229 }
230