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

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

109 lines 2.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 ArticleSummary extends Block {
8
9 protected $frontend_styles = [
10 'betterdocs-article-summary'
11 ];
12
13 /**
14 * Get block name
15 *
16 * @return string
17 */
18 public function get_name() {
19 return 'article-summary';
20 }
21
22 /**
23 * Get default attributes
24 *
25 * @return array
26 */
27 public function get_default_attributes() {
28 return [
29 'blockId' => '',
30 'customTitle' => '',
31 'showTitle' => true,
32 'titleColor' => '#2c3e50',
33 'titleFontSize' => 16,
34 'titleFontWeight' => '600',
35 'backgroundColor' => '#ffffff',
36 'borderColor' => '#e1e5e9',
37 'borderWidth' => 1,
38 'borderRadius' => 8,
39 'padding' => null,
40 'margin' => null,
41 'contentColor' => '#555555',
42 'contentFontSize' => 14,
43 'contentLineHeight' => 1.6,
44 'loadingColor' => '#666666',
45 'iconColor' => 'inherit',
46 'iconSize' => 14,
47 ];
48 }
49
50 /**
51 * Render the block
52 *
53 * @param array $attributes Block attributes
54 * @param string $content Block content
55 * @return void
56 */
57 public function render( $attributes, $content ) {
58 // For frontend, check if it's a docs post type
59 if ( get_post_type() !== 'docs' ) {
60 return;
61 }
62
63 // Check if Article Summary feature is enabled (skip in editor mode)
64 if ( ! $this->is_editor_mode() ) {
65 $article_summary = betterdocs()->article_summary;
66 if ( ! $article_summary || ! $article_summary->is_enabled() ) {
67 return;
68 }
69 }
70
71 // Use the template with view_params
72 $this->views( 'templates/parts/article-summary' );
73 }
74
75 /**
76 * Check if we're in editor mode
77 *
78 * @return bool
79 */
80 private function is_editor_mode() {
81 // Check if we're in Gutenberg editor
82 return defined( 'REST_REQUEST' ) && REST_REQUEST &&
83 isset( $_REQUEST['context'] ) && $_REQUEST['context'] === 'edit';
84 }
85
86 /**
87 * Get view parameters for the template
88 *
89 * @return array
90 */
91 public function view_params() {
92 // Extract basic attributes
93 $block_id = $this->attributes['blockId'] ?? '';
94 $custom_title = $this->attributes['customTitle'] ?? '';
95 $show_title = $this->attributes['showTitle'] ?? true;
96
97 return [
98 'post_id' => get_the_ID(),
99 'custom_title' => $custom_title,
100 'show_title' => $show_title,
101 'widget_type' => 'blocks',
102 'blockId' => $block_id,
103 'is_editor_mode' => $this->is_editor_mode(),
104 ];
105 }
106
107
108 }
109