PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 4.5.5
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v4.5.5
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.5, at includes/Editors/BlockEditor/Blocks/FAQ.php

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