PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 2.5.5
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v2.5.5
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 / CategoryBox.php

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

132 lines 4.3 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-box-' . $attributes['layout']
83 ];
84
85 $_inner_wrapper_classes = [
86 'betterdocs-category-box-inner-wrapper',
87 'layout-flex',
88 $attributes['layout'] === 'default' ? 'layout-1' : $attributes['layout'],
89 "betterdocs-column-" . $attributes['colRange'],
90 "betterdocs-column-tablet-" . $attributes['TABcolRange'],
91 "betterdocs-column-mobile-" . $attributes['MOBcolRange']
92 ];
93
94 $wrapper_attr = [
95 'class' => $_wrapper_classes
96 ];
97 $inner_wrapper_attr = [
98 'class' => $_inner_wrapper_classes,
99 'data-column_desktop' => $attributes['colRange'],
100 'data-column_tab' => $attributes['TABcolRange'],
101 'data-column_mobile' => $attributes['MOBcolRange']
102 ];
103
104 $_params = [
105 'wrapper_attr' => $wrapper_attr,
106 'inner_wrapper_attr' => $inner_wrapper_attr,
107 'terms_query_args' => $terms_object,
108 'widget_type' => 'category-box',
109 'multiple_knowledge_base' => false,
110 'kb_slug' => '',
111 'nested_subcategory' => false,
112 'show_header' => true
113 ];
114
115 if ( $attributes['layout'] === 'layout-2' ) {
116 $_params['count_prefix'] = '';
117 $_params['count_suffix'] = '';
118 $_params['count_suffix_singular'] = '';
119 }
120
121 return $_params;
122 }
123
124 public function render( $attributes, $content ) {
125 $_eligible = ( $attributes['layout'] == 'layout-2' || $attributes['layout'] == 'layout-3' );
126
127 $this->add_filter( $_eligible );
128 $this->views( 'layouts/base' );
129 $this->remove_filter( $_eligible );
130 }
131 }
132