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

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

133 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
7 class FAQ extends Block {
8 protected $editor_scripts = [
9 'betterdocs-faq',
10 'betterdocs-blocks-editor'
11 ];
12
13 protected $editor_styles = [
14 'betterdocs-faq',
15 'betterdocs-blocks-editor'
16 ];
17
18 protected $frontend_styles = [
19 'betterdocs-faq'
20 ];
21
22 protected $frontend_scripts = [
23 'betterdocs-faq'
24 ];
25
26 /**
27 * unique name of block
28 * @return string
29 */
30 public function get_name() {
31 return 'faq';
32 }
33
34 public function get_default_attributes() {
35 return [
36 'blockId' => '',
37 'resOption' => 'Desktop',
38 'blockRoot' => 'better_docs',
39 'blockMeta' => null,
40 'faqLayout' => 'layout-1',
41 'faqSectionText' => 'Frequently Asked Questions',
42 'faqSectionTitleTag' => 'h2',
43 'faqGroupTitleTag' => 'h3',
44 'faqSectionTitleColor' => null,
45 'includeFaqGroup' => '',
46 'excludeFaqGroup' => '',
47 'faqGroupTitleColor' => null,
48 'faqGroupTitleHoverColor' => null,
49 'faqListColor' => null,
50 'faqContentColor' => null,
51 'faqIconColor' => null,
52 'faqGroupTitleTypography' => null,
53 'faqPerPage' => 9,
54
55 'showButtonIcon' => true,
56 'buttonColor' => '#528ffe'
57 ];
58 }
59
60 public function render( $attributes, $content ) {
61
62 add_filter( 'betterdocs_header_layout_sequence', [ $this, 'header_sequence' ], 10, 4 );
63 $this->views( 'layouts/faq' );
64 remove_filter( 'betterdocs_header_layout_sequence', [ $this, 'header_sequence' ], 10 );
65 }
66
67 public function get_groups_ids( $json ) {
68 $data = json_decode( $json, true );
69 $ids = '';
70 if ( $data !== null ) {
71 $ids = implode( ',', array_column( $data, 'value' ) );
72 }
73
74 return $ids;
75 }
76
77 public function view_params() {
78 $attributes = &$this->attributes;
79
80 // Sanitize the layout attribute to prevent path traversal (LFI).
81 $attributes['faqLayout'] = sanitize_file_name( $attributes['faqLayout'] );
82 $exclude = $this->get_groups_ids( $attributes['excludeFaqGroup'] );
83 $include = $this->get_groups_ids( $attributes['includeFaqGroup'] );
84
85 $terms_query = betterdocs()->query->faq_terms_query_args( $include, $exclude );
86
87 return wp_parse_args(
88 [
89 'enable' => true,
90 'have_posts' => true,
91 'widget' => $this,
92 'layout' => $attributes['faqLayout'],
93 'terms_query_args' => $terms_query,
94 'shortcode_attr' => [
95 'group_exclude' => $exclude,
96 'class' => 'betterdocs-faq-' . $attributes['faqLayout'] . ' ' . $attributes['blockId'],
97 'groups' => $include,
98 'is_gutenberg' => true,
99 'faq_heading' => $attributes['faqSectionText'],
100 'faq_section_title_tag' => $attributes['faqSectionTitleTag'],
101 'faq_group_title_tag' => $attributes['faqGroupTitleTag'],
102 'faq_section_title_color' => $attributes['faqSectionTitleColor'],
103 'include_faq_group' => $this->string_to_array( $attributes['includeFaqGroup'] ),
104 'exclude_faq_group' => $this->string_to_array( $attributes['excludeFaqGroup'] ),
105 'faq_group_title_color' => $attributes['faqGroupTitleColor'],
106 'faq_group_title_hover_color' => $attributes['faqGroupTitleHoverColor'],
107 'faq_list_color' => $attributes['faqListColor'],
108 'faq_content_color' => $attributes['faqContentColor'],
109 'faq_icon_color' => $attributes['faqIconColor'],
110 'faq_group_title_typography' => $attributes['faqGroupTitleTypography'],
111 'faq_per_page' => $attributes['faqPerPage'],
112 'show_button_icon' => $attributes['showButtonIcon'],
113 'button_icon_position' => $attributes['faqLayout'] == 'layout-1' || $attributes['faqLayout'] == 'layout-3' || $attributes['faqLayout'] == 'layout-4' ? 'after' : 'before',
114 'button_color' => $attributes['buttonColor']
115 ]
116
117 ]
118 );
119 }
120
121 public function header_sequence( $_layout_sequence, $layout, $widget_type, $_defined_vars ) {
122 $_new_layout_sequence = [
123 [
124 'class' => 'betterdocs-category-title-counts',
125 'sequence' => [ 'category_title', 'category_counts' ]
126 ],
127 'category_description'
128 ];
129
130 return $_new_layout_sequence;
131 }
132 }
133