PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 3.5.2
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v3.5.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 3.5.2 All 199 releases
betterdocs / includes / Editors / BlockEditor / Blocks / CategoryBox.php

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

160 lines 5.4 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 use WPDeveloper\BetterDocs\Traits\CategoryBox as CategoryBoxTraits;
7
8 class CategoryBox extends Block {
9 use CategoryBoxTraits;
10
11 protected $editor_styles = [
12 'betterdocs-fontawesome',
13 'betterdocs-blocks-editor',
14 'betterdocs-blocks-category-box'
15 ];
16
17 protected $frontend_styles = [
18 'betterdocs-fontawesome',
19 'betterdocs-blocks-category-box'
20 ];
21
22 /**
23 * unique name of block
24 * @return string
25 */
26 public function get_name() {
27 return 'categorybox';
28 }
29
30 public function get_default_attributes() {
31 return [
32 'blockId' => '',
33 'categories' => [],
34 'selectKB' => '',
35 'includeCategories' => '',
36 'excludeCategories' => '',
37 'boxPerPage' => 9,
38 'orderBy' => 'name',
39 'order' => 'asc',
40 'layout' => 'default',
41 'showIcon' => true,
42 'showTitle' => true,
43 'titleTag' => 'h2',
44 'showCount' => true,
45 'prefix' => '',
46 'suffix' => __( 'articles', 'betterdocs' ),
47 'suffixSingular' => __( 'article', 'betterdocs' ),
48 'colRange' => 3,
49 'TABcolRange' => 2,
50 'MOBcolRange' => 1
51 ];
52 }
53
54 public function view_params() {
55 $attributes = &$this->attributes;
56
57 $terms_object = [
58 'taxonomy' => 'doc_category',
59 'order' => $attributes['order'],
60 'orderby' => $attributes['orderBy'],
61 'number' => isset( $attributes['boxPerPage'] ) ? $attributes['boxPerPage'] : 5,
62 'hide_empty' => true
63 ];
64
65 if ( 'doc_category_order' === $attributes['orderBy'] ) {
66 $terms_object['meta_key'] = 'doc_category_order';
67 $terms_object['orderby'] = 'meta_value_num';
68 }
69
70 $includes = $this->string_to_array( $attributes['includeCategories'] );
71 $excludes = $this->string_to_array( $attributes['excludeCategories'] );
72
73 if ( ! empty( $includes ) ) {
74 $terms_object['include'] = array_diff( $includes, (array) $excludes );
75 }
76
77 if ( ! empty( $excludes ) ) {
78 $terms_object['exclude'] = $excludes;
79 }
80
81 $_wrapper_classes = [
82 'betterdocs-category-box-wrapper',
83 'betterdocs-blocks-grid',
84 'betterdocs-box-' . $attributes['layout']
85 ];
86
87 $_inner_wrapper_classes = [
88 'betterdocs-category-box-inner-wrapper',
89 'layout-flex',
90 $attributes['layout'] === 'default' ? 'layout-1' : $attributes['layout'],
91 "betterdocs-column-" . $attributes['colRange'],
92 "betterdocs-column-tablet-" . $attributes['TABcolRange'],
93 "betterdocs-column-mobile-" . $attributes['MOBcolRange']
94 ];
95
96 $wrapper_attr = [
97 'class' => $_wrapper_classes
98 ];
99 $inner_wrapper_attr = [
100 'class' => $_inner_wrapper_classes,
101 'data-column_desktop' => $attributes['colRange'],
102 'data-column_tab' => $attributes['TABcolRange'],
103 'data-column_mobile' => $attributes['MOBcolRange']
104 ];
105
106 $default_multiple_kb = betterdocs()->settings->get( 'multiple_kb' );
107 $kb_slug = ! empty( $attributes['selectKB'] ) && isset( $attributes['selectKB'] ) ? json_decode( $attributes['selectKB'] )->value : '';
108
109 if ( is_tax( 'knowledge_base' ) && $default_multiple_kb == 1 ) {
110 $object = get_queried_object();
111 $terms_object['meta_query'] = [
112 'relation' => 'OR',
113 [
114 'key' => 'doc_category_knowledge_base',
115 'value' => $object->slug,
116 'compare' => 'LIKE'
117 ]
118 ];
119 }
120
121 if( ! empty( $kb_slug ) ) {
122 $terms_object['meta_query'] = [
123 'relation' => 'OR',
124 [
125 'key' => 'doc_category_knowledge_base',
126 'value' => $kb_slug,
127 'compare' => 'LIKE'
128 ]
129 ];
130 }
131
132 $_params = [
133 'wrapper_attr' => $wrapper_attr,
134 'inner_wrapper_attr' => $inner_wrapper_attr,
135 'terms_query_args' => betterdocs()->query->terms_query( $terms_object ),
136 'widget_type' => 'category-box',
137 'multiple_knowledge_base' => $default_multiple_kb,
138 'nested_subcategory' => false,
139 'show_header' => true,
140 'show_description' => false
141 ];
142
143 if ( $attributes['layout'] === 'layout-2' ) {
144 $_params['count_prefix'] = '';
145 $_params['count_suffix'] = '';
146 $_params['count_suffix_singular'] = '';
147 }
148
149 return $_params;
150 }
151
152 public function render( $attributes, $content ) {
153 $_eligible = ( $attributes['layout'] == 'layout-2' || $attributes['layout'] == 'layout-3' );
154
155 $this->add_filter( $_eligible );
156 $this->views( 'layouts/base' );
157 $this->remove_filter( $_eligible );
158 }
159 }
160