PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 3.3.4
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v3.3.4
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.3.4, at includes/Editors/BlockEditor/Blocks/CategoryBox.php

146 lines 4.8 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 'includeCategories' => '',
35 'excludeCategories' => '',
36 'boxPerPage' => 9,
37 'orderBy' => 'name',
38 'order' => 'asc',
39 'layout' => 'default',
40 'showIcon' => true,
41 'showTitle' => true,
42 'titleTag' => 'h2',
43 'showCount' => true,
44 'prefix' => '',
45 'suffix' => __( 'articles', 'betterdocs' ),
46 'suffixSingular' => __( 'article', 'betterdocs' ),
47 'colRange' => 3,
48 'TABcolRange' => 2,
49 'MOBcolRange' => 1
50 ];
51 }
52
53 public function view_params() {
54 $attributes = &$this->attributes;
55
56 $terms_object = [
57 'taxonomy' => 'doc_category',
58 'order' => $attributes['order'],
59 'orderby' => $attributes['orderBy'],
60 'number' => isset( $attributes['boxPerPage'] ) ? $attributes['boxPerPage'] : 5,
61 'hide_empty' => true
62 ];
63
64 if ( 'doc_category_order' === $attributes['orderBy'] ) {
65 $terms_object['meta_key'] = 'doc_category_order';
66 $terms_object['orderby'] = 'meta_value_num';
67 }
68
69 $includes = $this->string_to_array( $attributes['includeCategories'] );
70 $excludes = $this->string_to_array( $attributes['excludeCategories'] );
71
72 if ( ! empty( $includes ) ) {
73 $terms_object['include'] = array_diff( $includes, (array) $excludes );
74 }
75
76 if ( ! empty( $excludes ) ) {
77 $terms_object['exclude'] = $excludes;
78 }
79
80 $_wrapper_classes = [
81 'betterdocs-category-box-wrapper',
82 'betterdocs-blocks-grid',
83 'betterdocs-box-' . $attributes['layout']
84 ];
85
86 $_inner_wrapper_classes = [
87 'betterdocs-category-box-inner-wrapper',
88 'layout-flex',
89 $attributes['layout'] === 'default' ? 'layout-1' : $attributes['layout'],
90 "betterdocs-column-" . $attributes['colRange'],
91 "betterdocs-column-tablet-" . $attributes['TABcolRange'],
92 "betterdocs-column-mobile-" . $attributes['MOBcolRange']
93 ];
94
95 $wrapper_attr = [
96 'class' => $_wrapper_classes
97 ];
98 $inner_wrapper_attr = [
99 'class' => $_inner_wrapper_classes,
100 'data-column_desktop' => $attributes['colRange'],
101 'data-column_tab' => $attributes['TABcolRange'],
102 'data-column_mobile' => $attributes['MOBcolRange']
103 ];
104
105 $default_multiple_kb = betterdocs()->settings->get( 'multiple_kb' );
106 if ( is_tax( 'knowledge_base' ) && $default_multiple_kb == 1 ) {
107 $object = get_queried_object();
108 $terms_object['meta_query'] = [
109 'relation' => 'OR',
110 [
111 'key' => 'doc_category_knowledge_base',
112 'value' => $object->slug,
113 'compare' => 'LIKE'
114 ]
115 ];
116 }
117
118 $_params = [
119 'wrapper_attr' => $wrapper_attr,
120 'inner_wrapper_attr' => $inner_wrapper_attr,
121 'terms_query_args' => $terms_object,
122 'widget_type' => 'category-box',
123 'multiple_knowledge_base' => $default_multiple_kb,
124 'kb_slug' => '',
125 'nested_subcategory' => false,
126 'show_header' => true
127 ];
128
129 if ( $attributes['layout'] === 'layout-2' ) {
130 $_params['count_prefix'] = '';
131 $_params['count_suffix'] = '';
132 $_params['count_suffix_singular'] = '';
133 }
134
135 return $_params;
136 }
137
138 public function render( $attributes, $content ) {
139 $_eligible = ( $attributes['layout'] == 'layout-2' || $attributes['layout'] == 'layout-3' );
140
141 $this->add_filter( $_eligible );
142 $this->views( 'layouts/base' );
143 $this->remove_filter( $_eligible );
144 }
145 }
146