PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 4.5.1
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v4.5.1
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 / ArchiveList.php

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

148 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
7 class ArchiveList extends Block {
8
9 public $tax_query_block = [];
10
11 public function get_name() {
12 return 'doc-archive-list';
13 }
14
15 protected $editor_styles = [
16 'betterdocs-fontawesome',
17 'betterdocs-blocks-editor',
18 'betterdocs-doc-archive-list',
19 'betterdocs-doc_category',
20 'betterdocs-category-archive-doc-list',
21 'betterdocs-pagination'
22 ];
23
24 protected $frontend_styles = [
25 'betterdocs-fontawesome',
26 'betterdocs-doc-archive-list',
27 'betterdocs-doc_category',
28 'betterdocs-category-archive-doc-list',
29 'betterdocs-pagination'
30 ];
31
32 public function get_default_attributes() {
33 return [
34 'blockId' => '',
35 'nested_subcategory' => false,
36 'order' => 'asc',
37 'orderby' => 'betterdocs_order',
38 'layout' => 'layout-1',
39 'list_icon' => 'far fa-file-alt',
40 'postsPerPageLayoutTwo' => -1,
41 'listIconImageUrl' => '',
42 'pagination' => false,
43 'listTitleTag' => 'h2',
44 'listEntryHeadingTag' => 'h3'
45 ];
46 }
47
48 public function render( $attributes, $content ) {
49 if ( $this->attributes['layout'] == 'layout-2' ) {
50 // Layout 2 is handled by Pro version
51 add_action( 'archive_handbook_list', [$this, 'render_handbook_view'] );
52 }
53 $this->views( 'widgets/block-archive-list' );
54 }
55
56 public function render_handbook_view() {
57 // This method can be overridden by Pro version
58 }
59
60 public function view_params() {
61 // Sanitize the layout attribute to prevent path traversal (LFI).
62 $this->attributes['layout'] = sanitize_file_name( $this->attributes['layout'] );
63
64 global $wp_query;
65 $_term_slug = '';
66 if ( isset( $wp_query->query ) && array_key_exists( 'doc_category', $wp_query->query ) ) {
67 $_term_slug = $wp_query->query['doc_category'];
68 }
69
70 if ( isset( $wp_query->query ) && array_key_exists( 'doc_tag', $wp_query->query ) ) {
71 $_term_slug = $wp_query->query['doc_tag'];
72 add_filter(
73 'betterdocs_docs_tax_query_args',
74 function ( $tax_query, $_multiple_kb, $_term_slug, $_kb_slug, $_origin_args ) {
75 $tax_query[0]['taxonomy'] = 'doc_tag';
76 unset( $tax_query[0]['operator'] );
77 unset( $tax_query[0]['include_children'] );
78 $this->tax_query_block = $tax_query;
79 return $tax_query;
80 },
81 10,
82 5
83 );
84 add_filter(
85 'betterdocs_articles_args',
86 function ( $args, $_term_id, $_origin_args ) {
87 if ( empty( $args['tax_query'] ) ) {
88 $args['tax_query'] = $this->tax_query_block;
89 }
90 return $args;
91 },
92 10,
93 3
94 );
95 }
96
97 $term = ! empty( get_term_by( 'slug', $_term_slug, 'doc_category' ) ) ? get_term_by( 'slug', $_term_slug, 'doc_category' ) : get_term_by( 'slug', $_term_slug, 'doc_tag' );
98
99 // Determine posts per page based on pagination settings
100 $posts_per_page = -1; // default: show all posts
101 if ( $this->attributes['pagination'] && ( $this->attributes['layout'] == 'layout-1' || $this->attributes['layout'] == 'layout-3' || $this->attributes['layout'] == 'layout-4' ) ) {
102 $posts_per_page = isset( $this->attributes['postsPerPageLayoutTwo'] ) && $this->attributes['postsPerPageLayoutTwo'] > 0
103 ? $this->attributes['postsPerPageLayoutTwo']
104 : 10;
105 }
106
107 $_docs_query = [
108 'term_id' => isset( $term->term_id ) ? $term->term_id : 0,
109 'orderby' => $this->attributes['orderby'],
110 'order' => $this->attributes['order'],
111 'kb_slug' => '',
112 'posts_per_page' => $posts_per_page,
113 'term_slug' => isset( $term->slug ) ? $term->slug : ''
114 ];
115
116 $default_params = [
117 'term' => $term,
118 'nested_subcategory' => (bool) $this->attributes['nested_subcategory'],
119 'list_icon_name' => ! empty( $this->attributes['listIconImageUrl'] ) ? [ 'value' => [ 'url' => str_replace( 'blob:', '', $this->attributes['listIconImageUrl'] ) ] ] : ( ! empty( $this->attributes['list_icon'] ) ? [ 'value' => [ 'url' => $this->attributes['list_icon'] ] ] : ( ! empty( betterdocs()->settings->get( 'docs_list_icon' ) ) ? [ 'value' => [ 'url' => betterdocs()->settings->get( 'docs_list_icon' )['url'] ] ] : [] ) ),
120 'query_args' => betterdocs()->query->docs_query_args( $_docs_query ),
121 'title_tag' => $this->attributes['listEntryHeadingTag'] ?? 'h2',
122 'docs_list_title_tag' => $this->attributes['listTitleTag'] ?? 'h2',
123 'layout' => $this->attributes['layout'],
124 'posts_per_page' => $posts_per_page,
125 'list_icon_url' => '',
126 'layout_type' => 'block',
127 'archive_layout' => $this->attributes['layout']
128 ];
129
130 if ( $this->attributes['pagination'] && ( $this->attributes['layout'] == 'layout-1' || $this->attributes['layout'] == 'layout-3' || $this->attributes['layout'] == 'layout-4' ) ) {
131 $page = get_query_var( 'paged' ) != '' ? get_query_var( 'paged' ) : 1;
132
133 // Use postsPerPageLayoutTwo for layouts 2, 3, and 4
134 $posts_per_page = isset( $this->attributes['postsPerPageLayoutTwo'] ) && $this->attributes['postsPerPageLayoutTwo'] > 0
135 ? $this->attributes['postsPerPageLayoutTwo']
136 : 10;
137
138 $default_params['query_args']['paged'] = $page;
139 $default_params['query_args']['posts_per_page'] = $posts_per_page;
140 $default_params['page'] = $page;
141 $default_params['posts_per_page'] = $posts_per_page;
142 $default_params['pagination'] = $this->attributes['pagination'];
143 }
144
145 return $default_params;
146 }
147 }
148