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

247 lines 9.5 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,
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 ?>
147 <script>
148 (function () {
149 var globalStates = localStorage.getItem('fcom_global_storage');
150 if (globalStates) {
151 globalStates = JSON.parse(globalStates);
152 if (globalStates && globalStates.fcom_color_mode == 'dark') {
153 document.documentElement.classList.add('dark');
154 document.documentElement.setAttribute('data-color-mode', 'dark');
155 }
156 }
157 })();
158 </script>
159 <?php
160 });
161 }
162
163 ob_start();
164 ?>
165 <div class="fcom_wrap fcom_wp_frame">
166 <?php do_action('fluent_community/before_portal_dom'); ?>
167 <div class="fluent_com">
168 <div class="fhr_wrap">
169 <?php if (!$hideCommunityHeader): ?>
170 <?php do_action('fluent_community/portal_header', $contenx); ?>
171 <?php endif; ?>
172 <div class="fhr_content">
173 <div class="fhr_home">
174 <div class="feed_layout">
175 <div class="spaces">
176 <div id="fluent_community_sidebar_menu" class="space_contents">
177 <?php do_action('fluent_community/portal_sidebar', $contenx); ?>
178 </div>
179 </div>
180 <div
181 class="feeds_main fcom_wp_content fcom_fallback_wp_content <?php echo esc_attr($className); ?> <?php echo esc_attr($widthClass); ?>">
182 <?php echo do_blocks($content); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
183 </div>
184 </div>
185 </div>
186 </div>
187 </div>
188 </div>
189 </div>
190 <?php
191
192 add_action('wp_footer', function () {
193 do_action('fluent_community/template_footer');
194 }, 99);
195
196 return ob_get_clean();
197 }
198
199 public function useCommunityTemplate($title, $contentCallback = null)
200 {
201 do_action('fluent_community/enqueue_global_assets', true);
202 $useFullWidth = false;
203 $hideCommunityHeader = false;
204
205 ob_start();
206 ?>
207 <div class="fluent_com">
208 <div class="fhr_wrap">
209 <?php if (!$hideCommunityHeader): ?>
210 <?php do_action('fluent_community/portal_header', 'headless'); ?>
211 <?php endif; ?>
212 <div class="fhr_content">
213 <div class="fhr_home">
214 <div class="feed_layout">
215 <div class="spaces">
216 <div id="fluent_community_sidebar_menu" class="space_contents">
217 <!-- start-->
218 <?php do_action('fluent_community/portal_sidebar', 'headless'); ?>
219 <!-- end-->
220 </div>
221 </div>
222 <div class="fcom_wp_page">
223 <?php if ($title): ?>
224 <div class="fhr_content_layout_header">
225 <div class="fhr_page_title"><?php echo wp_kses_post($title); ?></div>
226 </div>
227 <?php endif; ?>
228 <div
229 class="wp_content_wrapper <?php echo $useFullWidth ? 'wp_content_wrapper_full' : ''; ?>">
230 <div class="wp_content">
231 <?php if ($contentCallback): ?>
232 <?php call_user_func($contentCallback); ?>
233 <?php endif; ?>
234 </div>
235 </div>
236 </div>
237 </div>
238 </div>
239 </div>
240 </div>
241 </div>
242 </div>
243 <?php
244 return ob_get_clean();
245 }
246 }
247