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 / ArchiveList.php

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

111 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
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' => 'title',
38 'layout' => 'layout-1',
39 'list_icon' => 'far fa-file-alt',
40 'postsPerPageLayoutTwo' => -1,
41 'listIconImageUrl' => '',
42 'pagination' => false
43 ];
44 }
45
46 public function render( $attributes, $content ) {
47 $this->views( 'widgets/block-archive-list' );
48 }
49
50 public function view_params() {
51 global $wp_query;
52 $_term_slug = '';
53 if ( isset( $wp_query->query ) && array_key_exists( 'doc_category', $wp_query->query ) ) {
54 $_term_slug = $wp_query->query['doc_category'];
55 }
56
57 if ( isset( $wp_query->query ) && array_key_exists( 'doc_tag', $wp_query->query ) ) {
58 $_term_slug = $wp_query->query['doc_tag'];
59 add_filter( 'betterdocs_docs_tax_query_args', function ( $tax_query, $_multiple_kb, $_term_slug, $_kb_slug, $_origin_args ) {
60 $tax_query[0]['taxonomy'] = 'doc_tag';
61 unset( $tax_query[0]['operator'] );
62 unset( $tax_query[0]['include_children'] );
63 $this->tax_query_block = $tax_query;
64 return $tax_query;
65 }, 10, 5 );
66 add_filter( 'betterdocs_articles_args', function ( $args, $_term_id, $_origin_args ) {
67 if ( empty( $args['tax_query'] ) ) {
68 $args['tax_query'] = $this->tax_query_block;
69 }
70 return $args;
71 }, 10, 3 );
72 }
73
74 $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' );
75
76 $_docs_query = [
77 'term_id' => isset( $term->term_id ) ? $term->term_id : 0,
78 'orderby' => $this->attributes['orderby'],
79 'order' => $this->attributes['order'],
80 'postsOrderBy' => $this->attributes['orderby'],
81 'postsOrder' => $this->attributes['order'],
82 'kb_slug' => '',
83 'posts_per_page' => $term == false ? 5 : -1,
84 'term_slug' => isset( $term->slug ) ? $term->slug : ''
85 ];
86
87 $default_params = [
88 'term' => $term,
89 'nested_subcategory' => (bool) $this->attributes['nested_subcategory'],
90 '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']]] : [] ) ),
91 'query_args' => betterdocs()->query->docs_query_args( $_docs_query ),
92 'title_tag' => 'h2',
93 'layout' => $this->attributes['layout'],
94 'posts_per_page' => $this->attributes['postsPerPageLayoutTwo'],
95 'list_icon_url' => '',
96 'layout_type' => 'block',
97 'archive_layout' => 'layout-1'
98 ];
99
100 if( $this->attributes['pagination'] && $this->attributes['layout'] == 'layout-1' || $this->attributes['pagination'] && $this->attributes['layout'] == 'layout-3' ) {
101 $page = get_query_var( 'paged' ) != '' ? get_query_var( 'paged' ) : 1;
102 $default_params['query_args']['paged'] = $page;
103 $default_params['query_args']['posts_per_page'] = 10;
104 $default_params['page'] = $page;
105 $default_params['pagination'] = $this->attributes['pagination'];
106 }
107
108 return $default_params;
109 }
110 }
111