PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.5.0
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.5.0
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.5.0, at Modules/Gutenberg/EditorBlock.php

246 lines 9.4 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 'editor_script' => 'custom-layout-block-editor',
56 'editor_style' => 'custom-layout-block-editor-style',
57 'style' => 'fluent_community_global',
58 'render_callback' => [$this, 'render'],
59 'supports' => [
60 'html' => false
61 ],
62 'attributes' => array(
63 'showPageHeader' => array(
64 'type' => 'boolean',
65 'default' => true,
66 ),
67 'useFullWidth' => array(
68 'type' => 'boolean',
69 'default' => false,
70 ),
71 'hideCommunityHeader' => array(
72 'type' => 'boolean',
73 'default' => false,
74 ),
75 'useBuildInTheme' => array(
76 'type' => 'boolean',
77 'default' => true,
78 ),
79 ),
80 )
81 );
82 }
83
84 $this->registerBuiltInTemplate();
85 }
86
87 private function registerBuiltInTemplate()
88 {
89 if (!wp_is_block_theme() || !function_exists('\register_block_template')) {
90 return;
91 }
92
93 $supportedPostTypes = apply_filters('fluent_communuty/block_templates_post_types', ['page', 'post']);
94
95 register_block_template('fluent-community//frame-template', [
96 'title' => __('FluentCommunity Page Template', 'fluent-community'),
97 'description' => __('A Page Template that render your WP content into FluentCommunity UI Frame', 'fluent-community'),
98 'content' => '<!-- wp:fluent-community/page-layout --><!-- wp:post-title /--><!-- wp:post-content /--><!-- /wp:fluent-community/page-layout -->',
99 'post_types' => $supportedPostTypes
100 ]);
101
102 add_filter('get_block_templates', function ($templates) {
103 if (isset($templates['fluent-community//frame-template'])) {
104 return array_values($templates);
105 }
106 return $templates;
107 });
108
109 }
110
111 public function render($attributes, $content)
112 {
113 static $isLoaded;
114 if ($isLoaded) {
115 return 'Layout is already loaded before';
116 }
117
118 if (!$isLoaded) {
119 $isLoaded = true;
120 }
121
122 $contenx = 'wp';
123 if (isset($_REQUEST['context']) && $_REQUEST['context'] == 'edit' && Helper::isSiteAdmin()) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
124 $contenx = 'block_editor';
125 }
126
127 $useBuildInTheme = $attributes['useBuildInTheme'] ?? false;
128
129 do_action('fluent_community/enqueue_global_assets', $useBuildInTheme);
130 $useFullWidth = $attributes['useFullWidth'] ?? true;
131 $hideCommunityHeader = false;
132 $className = Arr::get($attributes, 'className', '');
133
134 $widthClass = $useFullWidth ? 'fcom_template_full' : 'fcom_template_standard';
135
136 $disableDarkMode = Arr::has($attributes, 'disableDarkMode');
137
138 if ($disableDarkMode) {
139 add_filter('body_class', function ($classes) {
140 $classes[] = 'fcom_disable_dark_mode';
141 return $classes;
142 });
143 } else if (Helper::hasColorScheme()) {
144 add_action('wp_head', function () {
145 ?>
146 <script>
147 (function () {
148 var globalStates = localStorage.getItem('fcom_global_storage');
149 if (globalStates) {
150 globalStates = JSON.parse(globalStates);
151 if (globalStates && globalStates.fcom_color_mode == 'dark') {
152 document.documentElement.classList.add('dark');
153 document.documentElement.setAttribute('data-color-mode', 'dark');
154 }
155 }
156 })();
157 </script>
158 <?php
159 });
160 }
161
162 ob_start();
163 ?>
164 <div class="fcom_wrap fcom_wp_frame">
165 <?php do_action('fluent_community/before_portal_dom'); ?>
166 <div class="fluent_com">
167 <div class="fhr_wrap">
168 <?php if (!$hideCommunityHeader): ?>
169 <?php do_action('fluent_community/portal_header', $contenx); ?>
170 <?php endif; ?>
171 <div class="fhr_content">
172 <div class="fhr_home">
173 <div class="feed_layout">
174 <div class="spaces">
175 <div id="fluent_community_sidebar_menu" class="space_contents">
176 <?php do_action('fluent_community/portal_sidebar', $contenx); ?>
177 </div>
178 </div>
179 <div
180 class="feeds_main fcom_wp_content fcom_fallback_wp_content <?php echo esc_attr($className); ?> <?php echo esc_attr($widthClass); ?>">
181 <?php echo do_blocks($content); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
182 </div>
183 </div>
184 </div>
185 </div>
186 </div>
187 </div>
188 </div>
189 <?php
190
191 add_action('wp_footer', function () {
192 do_action('fluent_community/template_footer');
193 }, 99);
194
195 return ob_get_clean();
196 }
197
198 public function useCommunityTemplate($title, $contentCallback = null)
199 {
200 do_action('fluent_community/enqueue_global_assets', true);
201 $useFullWidth = false;
202 $hideCommunityHeader = false;
203
204 ob_start();
205 ?>
206 <div class="fluent_com">
207 <div class="fhr_wrap">
208 <?php if (!$hideCommunityHeader): ?>
209 <?php do_action('fluent_community/portal_header', 'headless'); ?>
210 <?php endif; ?>
211 <div class="fhr_content">
212 <div class="fhr_home">
213 <div class="feed_layout">
214 <div class="spaces">
215 <div id="fluent_community_sidebar_menu" class="space_contents">
216 <!-- start-->
217 <?php do_action('fluent_community/portal_sidebar', 'headless'); ?>
218 <!-- end-->
219 </div>
220 </div>
221 <div class="fcom_wp_page">
222 <?php if ($title): ?>
223 <div class="fhr_content_layout_header">
224 <div class="fhr_page_title"><?php echo wp_kses_post($title); ?></div>
225 </div>
226 <?php endif; ?>
227 <div
228 class="wp_content_wrapper <?php echo $useFullWidth ? 'wp_content_wrapper_full' : ''; ?>">
229 <div class="wp_content">
230 <?php if ($contentCallback): ?>
231 <?php call_user_func($contentCallback); ?>
232 <?php endif; ?>
233 </div>
234 </div>
235 </div>
236 </div>
237 </div>
238 </div>
239 </div>
240 </div>
241 </div>
242 <?php
243 return ob_get_clean();
244 }
245 }
246