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 / Theming / TemplateLoader.php

TemplateLoader.php in FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses 2.6.0, at Modules/Theming/TemplateLoader.php

518 lines 22.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\Theming;
4
5 use FluentCommunity\App\Services\Helper;
6 use FluentCommunity\Framework\Support\Arr;
7
8 class TemplateLoader
9 {
10 public function register()
11 {
12 add_filter('fluent_community/general_portal_vars', function ($vars) {
13 $templateName = get_option('template');
14 if ($templateName == 'blocksy') {
15 $vars['color_switch_cookie_name'] = 'blocksy_current_theme';
16 }
17
18 if ($templateName == 'kadence' && defined('KTP_VERSION')) {
19 if (function_exists('\Kadence\kadence') && \Kadence\kadence()->option('dark_mode_enable') && apply_filters('kadence_dark_mode_enable', true)) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
20 $cookie_name = substr(base_convert(md5(get_site_url()), 16, 32), 0, 12) . '-paletteCookie';
21 $vars['color_switch_cookie_name'] = $cookie_name;
22 }
23 }
24
25 return $vars;
26 });
27
28 add_filter('theme_page_templates', [$this, 'registerTemplate'], 9999);
29 add_filter('template_include', [$this, 'maybeIncludeTemplate'], 99999);
30
31 add_action('fluent_community/theme_content', [$this, 'renderWpContent'], 10, 2);
32
33 // support for blocksy
34 add_action('fluent_community/theme_body_atts', function ($themeName) {
35 if ($themeName == 'blocksy') {
36 echo blocksy_body_attr(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
37 }
38 });
39
40 add_action('fluent_community/template_footer', [$this, 'renderMobileMenu']);
41 }
42
43 public function registerTemplate($templates)
44 {
45 if (wp_is_block_theme()) {
46 return $templates;
47 }
48
49 $templates['fluent-community-frame.php'] = esc_html__('FluentCommunity Frame', 'fluent-community');
50 $templates['fluent-community-frame-full.php'] = esc_html__('FluentCommunity Full Width Frame', 'fluent-community');
51 return $templates;
52 }
53
54 public function maybeIncludeTemplate($template)
55 {
56 // check if the current theme is block based theme or not
57 if (wp_is_block_theme()) {
58 $template_slug = get_page_template_slug();
59 if ($template_slug != 'wp-custom-template-community-template') {
60 return $template;
61 }
62 return $this->loadBlockBasedTemplateAssets($template);
63 }
64
65 global $post;
66
67 if (isset($post->ID)) {
68 $template_slug = get_page_template_slug($post->ID);
69
70 $fluentTemplates = [
71 'fluent-community-frame.php',
72 'fluent-community-frame-full.php',
73 ];
74
75 $template_slug = apply_filters('fluent_community/template_slug', $template_slug);
76
77 if (in_array($template_slug, $fluentTemplates)) {
78 // Determine the absolute path to the template file within your plugin.
79 $plugin_template = plugin_dir_path(__FILE__) . 'templates/' . $template_slug;
80
81 // If the file exists, return its path.
82 if (file_exists($plugin_template)) {
83 $this->loadScriptsAndStyles();
84 return $plugin_template;
85 }
86 }
87 }
88
89 // Otherwise, return the default theme template.
90 return $template;
91 }
92
93 public function loadBlockBasedTemplateAssets($template)
94 {
95 $this->loadScriptsAndStyles();
96 return $template;
97 }
98
99 public function renderWpContent($themeName, $wrapperType = 'default')
100 {
101 switch ($themeName) {
102 case 'blocksy':
103 $this->renderBlocksy();
104 break;
105 case 'astra':
106 $this->renderAstra();
107 break;
108 case 'kadence':
109 $this->renderKadence();
110 break;
111 case 'generatepress':
112 $this->renderGeneratePress();
113 break;
114 case 'oceanwp':
115 $this->renderOceanWP();
116 break;
117 case 'neve':
118 $this->renderNeve();
119 break;
120 case 'hello-elementor':
121 get_template_part('template-parts/single');
122 break;
123 case 'bricks':
124 $this->renderBricks($wrapperType);
125 break;
126 case 'breakdance-zero':
127 $this->renderBreakdance();
128 break;
129 default:
130 $this->renderFallBack($wrapperType);
131 break;
132 }
133 }
134
135 public function loadScriptsAndStyles()
136 {
137 $themeName = get_option('template');
138
139 add_filter('body_class', function ($classes) use ($themeName) {
140 $classes[] = 'fluent_com_wp_pages';
141
142 if (
143 $themeName === 'breakdance-zero' &&
144 !in_array('breakdance', $classes, true)
145 ) {
146 $classes[] = 'breakdance';
147 }
148
149 return $classes;
150 });
151
152 add_action('wp_head', function () use ($themeName) {
153 $isAlignSupportedTheme = in_array($themeName, ['blocksy'], true);
154 ?>
155 <style>
156 html {
157 font-size: 100%;
158 }
159
160 .feed_layout {
161 --global-vw: var(--fcom-main-content-width, 100vw);
162 }
163
164 <?php if(!$isAlignSupportedTheme): ?>
165 .fcom_wp_content .alignfull,
166 .ast-plain-container.ast-no-sidebar .fcom_wp_content .entry-content > .alignfull,
167 .no-sidebar .fcom_wp_content .entry-content .alignfull,
168 body.single-post.content-max-width .fcom_wp_content .entry-content .alignfull, body.page.content-max-width .fcom_wp_content .entry .alignfull /*for neve */
169 {
170 margin-left: calc(50% - (var(--global-vw, 100vw) / 2)) !important;
171 margin-right: calc(50% - (var(--global-vw, 100vw) / 2)) !important;
172 max-width: 100vw !important;
173 width: var(--global-vw, 100vw);
174 padding-left: 0;
175 padding-right: 0;
176 clear: both;
177 }
178
179 <?php endif; ?>
180 </style>
181
182 <?php if(Helper::hasColorScheme()): ?>
183 <script>
184 (function () {
185 var globalStates = localStorage.getItem('fcom_global_storage');
186 if (globalStates) {
187 globalStates = JSON.parse(globalStates);
188 if (globalStates && globalStates.fcom_color_mode == 'dark') {
189 document.documentElement.classList.add('dark');
190 document.documentElement.setAttribute('data-color-mode', 'dark');
191 }
192 }
193 })();
194 </script>
195 <?php endif; ?>
196
197 <?php
198 });
199
200 do_action('fluent_community/enqueue_global_assets', true);
201 }
202
203 private function renderBlocksy()
204 {
205 ?>
206 <main <?php echo blocksy_main_attr(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
207 <?php
208 if (is_singular()) {
209 do_action('blocksy:content:top'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
210 blocksy_before_current_template();
211 get_template_part('template-parts/single');
212 blocksy_after_current_template();
213 do_action('blocksy:content:bottom'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
214 } else {
215 get_template_part('template-parts/archive');
216 }
217 ?>
218 </main>
219 <?php
220 }
221
222 private function renderAstra()
223 {
224 $layout = astra_page_layout();
225 ?>
226 <div id="content" class="site-content">
227 <div class="ast-container">
228 <?php $layout == 'left-sidebar' && get_sidebar(); ?>
229 <div id="primary" <?php astra_primary_class(); ?>>
230 <?php
231 if (is_singular()):
232 astra_primary_content_top();
233 astra_content_page_loop();
234 astra_primary_content_bottom();
235 else:
236 astra_primary_content_top();
237 astra_archive_header();
238 astra_content_loop();
239 astra_pagination();
240 astra_primary_content_bottom();
241 endif;
242 ?>
243 </div><!-- #primary -->
244 <?php $layout == 'right-sidebar' && get_sidebar(); ?>
245 </div>
246 </div>
247 <?php
248 }
249
250 private function renderKadence()
251 {
252 \Kadence\kadence()->print_styles('kadence-content');
253 if (is_singular()) {
254 do_action('kadence_single'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
255 } else {
256 do_action('kadence_archive'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
257 }
258 }
259
260 private function renderGeneratePress()
261 {
262 ?>
263 <div <?php generate_do_attr('page'); ?>>
264 <?php do_action('generate_inside_site_container'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound ?>
265 <div <?php generate_do_attr('site-content'); ?>>
266 <?php do_action('generate_inside_container'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound ?>
267 <div <?php generate_do_attr('content'); ?>>
268 <main <?php generate_do_attr('main'); ?>>
269 <?php if (is_singular()): ?>
270 <?php
271 do_action('generate_before_main_content'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
272 if (generate_has_default_loop()) {
273 while (have_posts()) :
274 the_post();
275 generate_do_template_part('page');
276 endwhile;
277 }
278
279 do_action('generate_after_main_content'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
280 ?>
281 <?php else: ?>
282 <?php
283 do_action('generate_before_main_content'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
284 if (generate_has_default_loop()) {
285 if (have_posts()) :
286 do_action('generate_archive_title'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
287 do_action('generate_before_loop', 'archive'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
288 while (have_posts()) :
289 the_post();
290 generate_do_template_part('archive');
291 endwhile;
292 do_action('generate_after_loop', 'archive'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
293 else :
294 generate_do_template_part('none');
295 endif;
296 }
297 do_action('generate_after_main_content'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
298 ?>
299 <?php endif; ?>
300 </main>
301 </div>
302 <?php
303 do_action('generate_after_primary_content_area'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
304 generate_construct_sidebars(); ?>
305 </div>
306 </div>
307 <?php
308 }
309
310 private function renderOceanWP()
311 {
312 ?>
313 <div id="outer-wrap" class="site clr">
314 <div id="wrap" class="clr">
315 <?php do_action('ocean_before_main'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound ?>
316 <main id="main" class="site-main clr"<?php oceanwp_schema_markup('main'); ?> role="main">
317 <?php do_action('ocean_page_header'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound ?>
318 <?php do_action('ocean_before_content_wrap'); ?>
319 <div id="content-wrap" class="container clr">
320 <?php do_action('ocean_before_primary'); ?>
321 <div id="primary" class="content-area clr">
322 <?php do_action('ocean_before_content'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound ?>
323 <div id="content" class="site-content clr">
324 <?php do_action('ocean_before_content_inner'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound ?>
325 <?php if (is_singular()): ?>
326 <?php
327 // Elementor `single` location.
328 if (!function_exists('elementor_theme_do_location') || !elementor_theme_do_location('single')) {
329 // Start loop.
330 while (have_posts()) :
331 the_post();
332 get_template_part('partials/page/layout');
333 endwhile;
334 }
335 ?>
336
337 <?php else: ?>
338
339 <?php if (have_posts()) :
340 if (!function_exists('elementor_theme_do_location') || !elementor_theme_do_location('archive')) {
341 ?>
342 <div id="blog-entries" class="<?php oceanwp_blog_wrap_classes(); ?>">
343 <?php
344 // Define counter for clearing floats.
345 $oceanwp_count = 0;
346 ?>
347
348 <?php
349 // Loop through posts.
350 while (have_posts()) :
351 the_post();
352 ?>
353
354 <?php
355 // Add to counter.
356 $oceanwp_count++;
357 ?>
358
359 <?php
360 // Get post entry content.
361 get_template_part('partials/entry/layout', get_post_type());
362 ?>
363
364 <?php
365 // Reset counter to clear floats.
366 if (oceanwp_blog_entry_columns() === $oceanwp_count) {
367 $oceanwp_count = 0;
368 }
369 ?>
370
371 <?php endwhile; ?>
372
373 </div><!-- #blog-entries -->
374
375 <?php
376 // Display post pagination.
377 oceanwp_blog_pagination();
378 }
379 ?>
380
381 <?php
382 // No posts found.
383 else :
384 ?>
385
386 <?php
387 // Display no post found notice.
388 get_template_part('partials/none');
389 ?>
390
391 <?php endif; ?>
392
393 <?php endif; ?>
394 <?php do_action('ocean_after_content_inner'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound ?>
395 </div><!-- #content -->
396 <?php do_action('ocean_after_content'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound ?>
397 </div><!-- #primary -->
398 <?php do_action('ocean_after_primary'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound ?>
399 </div><!-- #content-wrap -->
400 <?php do_action('ocean_after_content_wrap'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound ?>
401 </main>
402 <?php do_action('ocean_after_main'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound ?>
403 </div>
404 </div>
405 <?php
406 }
407
408 private function renderNeve()
409 {
410 $container_class = apply_filters('neve_container_class_filter', 'container', 'single-page'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
411 $context = class_exists('WooCommerce', false) && (is_cart() || is_checkout() || is_account_page()) ? 'woo-page' : 'single-page';
412 ?>
413 <div class="<?php echo esc_attr($container_class); ?> single-page-container">
414 <div class="row">
415 <?php do_action('neve_do_sidebar', $context, 'left'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound ?>
416 <div class="nv-single-page-wrap col">
417 <?php
418 do_action('neve_before_page_header'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
419 do_action('neve_page_header', $context); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
420 do_action('neve_before_content', $context); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
421
422 if (have_posts()) {
423 while (have_posts()) {
424 the_post();
425 get_template_part('template-parts/content', 'page');
426 }
427 } else {
428 get_template_part('template-parts/content', 'none');
429 }
430 do_action('neve_after_content', $context); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
431 ?>
432 </div>
433 <?php do_action('neve_do_sidebar', $context, 'right'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound ?>
434 </div>
435 </div>
436 <?php
437 }
438
439 private function renderBricks($wrapperType)
440 {
441 if (defined('BRICKS_VERSION')) {
442 $bricks_data = \Bricks\Helpers::get_bricks_data(get_the_ID(), 'content');
443 if ($bricks_data) {
444 \Bricks\Frontend::render_content($bricks_data);
445 return;
446 }
447 }
448
449 $this->renderFallback($wrapperType);
450 }
451
452 private function renderBreakdance()
453 {
454 if (!function_exists('\\Breakdance\\Render\\render')) {
455 $this->renderFallback();
456 return;
457 }
458
459 $html = \Breakdance\Render\render(get_the_ID());
460 if ($html) {
461 echo $html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
462 }
463 }
464
465 private function renderFallback($wrapperType = 'default')
466 {
467 if (have_posts()) :
468 while (have_posts()) :
469 the_post();
470 ?>
471 <div class="wp_content_wrapper wp_fallback_theme">
472 <?php if ($wrapperType == 'default'): ?>
473 <div class="fcom_wp_content_title">
474 <?php the_title('<h1 class="entry-title">', '</h1>'); ?>
475 </div>
476 <?php endif; ?>
477 <div class="fcom_wp_content_body">
478 <?php the_content(); ?>
479 </div>
480 </div>
481 <?php
482 endwhile;
483 endif;
484 }
485
486 public function renderMobileMenu()
487 {
488 $menuItems = Helper::getMobileMenuItems('wp');
489 if (!$menuItems) {
490 return;
491 }
492 ?>
493 <div class="fcom_mobile_menu">
494 <div class="focm_menu_items">
495 <?php
496 foreach ($menuItems as $menuItem):
497 $permalink = Arr::get($menuItem, 'permalink');
498 if (!$permalink) {
499 $permalink = Helper::getUrlByJsRoute(Arr::get($menuItem, 'route', []));
500 }
501 ?>
502 <div>
503 <a class="focm_menu_item" href="<?php echo esc_url($permalink); ?>">
504 <span class="el-icon">
505 <?php echo Arr::get($menuItem, 'icon_svg'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
506 </span>
507 <?php if ($label = Arr::get($menuItem, 'html')): ?>
508 <span><?php echo wp_kses_post($label); ?></span>
509 <?php endif; ?>
510 </a>
511 </div>
512 <?php endforeach; ?>
513 </div>
514 </div>
515 <?php
516 }
517 }
518