PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.10.01
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.10.01
2.10.0 2.10.01 2.9.1 2.9.0 2.8.1 2.8.0 2.7.7 2.7.5 2.7.0 2.6.01 2.6.0 2.5.0 2.4.01 trunk 1.0.90 1.0.91 1.0.92 1.0.93 1.0.94 1.0.95 1.0.96 1.0.97 1.0.98 1.0.99 1.1.0 All 77 releases
fluent-community / Modules / Gutenberg / EditorBlock.php

EditorBlock.php in FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses 2.10.01, at Modules/Gutenberg/EditorBlock.php

234 lines 9.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCommunity\Modules\Gutenberg;
4
5 use FluentCommunity\App\Services\Helper;
6 use FluentCommunity\App\Vite;
7 use FluentCommunity\Framework\Support\Arr;
8
9 class EditorBlock
10 {
11 public function register($app)
12 {
13 add_action('init', [$this, 'registerBlock']);
14 }
15
16 public function registerBlock()
17 {
18 global $pagenow;
19
20 $asset_file = include(plugin_dir_path(__FILE__) . 'build/index.asset.php');
21 wp_register_style(
22 'custom-layout-block-editor-style',
23 plugins_url('build/index.css', __FILE__),
24 array(),
25 $asset_file['version']
26 );
27
28 wp_register_style('fluent_community_global', Vite::getStaticSrcUrl('global.css', Helper::isRtl()), [], FLUENT_COMMUNITY_PLUGIN_VERSION, 'screen');
29
30 wp_register_script(
31 'custom-layout-block-editor',
32 plugins_url('build/index.js', __FILE__),
33 $asset_file['dependencies'],
34 $asset_file['version'],
35 true
36 );
37
38 wp_localize_script(
39 'custom-layout-block-editor',
40 'fluentCommunityBlockEditor',
41 array(
42 'blockEditor' => array(
43 'isGutenberg' => true,
44 'isBlockEditor' => true,
45 'isPage' => $pagenow == 'post.php' || $pagenow == 'post-new.php',
46 'isPostType' => get_post_type(),
47 ),
48 )
49 );
50
51 if (function_exists('\register_block_type')) {
52 \register_block_type(
53 'fluent-community/page-layout',
54 array(
55 'api_version' => '3', // WP core uses int but stub declares string
56 'editor_script' => 'custom-layout-block-editor',
57 'editor_style' => 'custom-layout-block-editor-style',
58 'style' => 'fluent_community_global',
59 'render_callback' => [$this, 'render'],
60 'supports' => [
61 'html' => false
62 ],
63 'attributes' => array(
64 'showPageHeader' => array(
65 'type' => 'boolean',
66 'default' => true,
67 ),
68 'useFullWidth' => array(
69 'type' => 'boolean',
70 'default' => false,
71 ),
72 'hideCommunityHeader' => array(
73 'type' => 'boolean',
74 'default' => false,
75 ),
76 'useBuildInTheme' => array(
77 'type' => 'boolean',
78 'default' => true,
79 ),
80 ),
81 )
82 );
83 }
84
85 $this->registerBuiltInTemplate();
86 }
87
88 private function registerBuiltInTemplate()
89 {
90 if (!wp_is_block_theme() || !function_exists('\register_block_template')) {
91 return;
92 }
93
94 $supportedPostTypes = apply_filters('fluent_communuty/block_templates_post_types', ['page', 'post']);
95
96 register_block_template('fluent-community//frame-template', [
97 'title' => __('FluentCommunity Page Template', 'fluent-community'),
98 'description' => __('A Page Template that render your WP content into FluentCommunity UI Frame', 'fluent-community'),
99 'content' => '<!-- wp:fluent-community/page-layout --><!-- wp:post-title /--><!-- wp:post-content /--><!-- /wp:fluent-community/page-layout -->',
100 'post_types' => $supportedPostTypes
101 ]);
102
103 add_filter('get_block_templates', function ($templates) {
104 if (isset($templates['fluent-community//frame-template'])) {
105 return array_values($templates);
106 }
107 return $templates;
108 });
109
110 }
111
112 public function render($attributes, $content)
113 {
114 static $isLoaded;
115 if ($isLoaded) {
116 return esc_html__('Layout is already loaded before', 'fluent-community');
117 }
118
119 if (!$isLoaded) {
120 $isLoaded = true;
121 }
122
123 $contenx = 'wp';
124 if (isset($_REQUEST['context']) && $_REQUEST['context'] == 'edit' && Helper::isSiteAdmin()) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
125 $contenx = 'block_editor';
126 }
127
128 $useBuildInTheme = $attributes['useBuildInTheme'] ?? false;
129
130 do_action('fluent_community/enqueue_global_assets', $useBuildInTheme);
131 $useFullWidth = $attributes['useFullWidth'] ?? true;
132 $hideCommunityHeader = false;
133 $className = Arr::get($attributes, 'className', '');
134
135 $widthClass = $useFullWidth ? 'fcom_template_full' : 'fcom_template_standard';
136
137 $disableDarkMode = Arr::has($attributes, 'disableDarkMode');
138
139 if ($disableDarkMode) {
140 add_filter('body_class', function ($classes) {
141 $classes[] = 'fcom_disable_dark_mode';
142 return $classes;
143 });
144 } else if (Helper::hasColorScheme()) {
145 add_action('wp_head', function () {
146 Helper::renderColorSchemePrePaintScript();
147 });
148 }
149
150 ob_start();
151 ?>
152 <div class="fcom_wrap fcom_wp_frame">
153 <?php do_action('fluent_community/before_portal_dom'); ?>
154 <div class="fluent_com">
155 <div class="fhr_wrap">
156 <?php if (!$hideCommunityHeader): ?>
157 <?php do_action('fluent_community/portal_header', $contenx); ?>
158 <?php endif; ?>
159 <div class="fhr_content">
160 <div class="fhr_home">
161 <div class="feed_layout">
162 <div class="spaces fcom_space_list">
163 <div id="fluent_community_sidebar_menu" class="space_contents">
164 <?php do_action('fluent_community/portal_sidebar', $contenx); ?>
165 </div>
166 </div>
167 <div
168 class="feeds_main fcom_wp_content fcom_fallback_wp_content <?php echo esc_attr($className); ?> <?php echo esc_attr($widthClass); ?>">
169 <?php echo do_blocks($content); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
170 </div>
171 </div>
172 </div>
173 </div>
174 </div>
175 </div>
176 </div>
177 <?php
178
179 add_action('wp_footer', function () {
180 do_action('fluent_community/template_footer');
181 }, 99);
182
183 return ob_get_clean();
184 }
185
186 public function useCommunityTemplate($title, $contentCallback = null)
187 {
188 do_action('fluent_community/enqueue_global_assets', true);
189 $useFullWidth = false;
190 $hideCommunityHeader = false;
191
192 ob_start();
193 ?>
194 <div class="fluent_com">
195 <div class="fhr_wrap">
196 <?php if (!$hideCommunityHeader): ?>
197 <?php do_action('fluent_community/portal_header', 'headless'); ?>
198 <?php endif; ?>
199 <div class="fhr_content">
200 <div class="fhr_home">
201 <div class="feed_layout">
202 <div class="spaces fcom_space_list">
203 <div id="fluent_community_sidebar_menu" class="space_contents">
204 <!-- start-->
205 <?php do_action('fluent_community/portal_sidebar', 'headless'); ?>
206 <!-- end-->
207 </div>
208 </div>
209 <div class="fcom_wp_page">
210 <?php if ($title): ?>
211 <div class="fhr_content_layout_header">
212 <div class="fhr_page_title"><?php echo wp_kses_post($title); ?></div>
213 </div>
214 <?php endif; ?>
215 <div
216 class="wp_content_wrapper <?php echo $useFullWidth ? 'wp_content_wrapper_full' : ''; ?>">
217 <div class="wp_content">
218 <?php if ($contentCallback): ?>
219 <?php call_user_func($contentCallback); ?>
220 <?php endif; ?>
221 </div>
222 </div>
223 </div>
224 </div>
225 </div>
226 </div>
227 </div>
228 </div>
229 </div>
230 <?php
231 return ob_get_clean();
232 }
233 }
234