PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.10.0
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.10.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.10.0, at Modules/Theming/TemplateLoader.php

507 lines 22.2 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 <?php Helper::renderColorSchemePrePaintScript(); ?>
184 <?php endif; ?>
185
186 <?php
187 });
188
189 do_action('fluent_community/enqueue_global_assets', true);
190 }
191
192 private function renderBlocksy()
193 {
194 ?>
195 <main <?php echo blocksy_main_attr(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
196 <?php
197 if (is_singular()) {
198 do_action('blocksy:content:top'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
199 blocksy_before_current_template();
200 get_template_part('template-parts/single');
201 blocksy_after_current_template();
202 do_action('blocksy:content:bottom'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
203 } else {
204 get_template_part('template-parts/archive');
205 }
206 ?>
207 </main>
208 <?php
209 }
210
211 private function renderAstra()
212 {
213 $layout = astra_page_layout();
214 ?>
215 <div id="content" class="site-content">
216 <div class="ast-container">
217 <?php $layout == 'left-sidebar' && get_sidebar(); ?>
218 <div id="primary" <?php astra_primary_class(); ?>>
219 <?php
220 if (is_singular()):
221 astra_primary_content_top();
222 astra_content_page_loop();
223 astra_primary_content_bottom();
224 else:
225 astra_primary_content_top();
226 astra_archive_header();
227 astra_content_loop();
228 astra_pagination();
229 astra_primary_content_bottom();
230 endif;
231 ?>
232 </div><!-- #primary -->
233 <?php $layout == 'right-sidebar' && get_sidebar(); ?>
234 </div>
235 </div>
236 <?php
237 }
238
239 private function renderKadence()
240 {
241 \Kadence\kadence()->print_styles('kadence-content');
242 if (is_singular()) {
243 do_action('kadence_single'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
244 } else {
245 do_action('kadence_archive'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
246 }
247 }
248
249 private function renderGeneratePress()
250 {
251 ?>
252 <div <?php generate_do_attr('page'); ?>>
253 <?php do_action('generate_inside_site_container'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound ?>
254 <div <?php generate_do_attr('site-content'); ?>>
255 <?php do_action('generate_inside_container'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound ?>
256 <div <?php generate_do_attr('content'); ?>>
257 <main <?php generate_do_attr('main'); ?>>
258 <?php if (is_singular()): ?>
259 <?php
260 do_action('generate_before_main_content'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
261 if (generate_has_default_loop()) {
262 while (have_posts()) :
263 the_post();
264 generate_do_template_part('page');
265 endwhile;
266 }
267
268 do_action('generate_after_main_content'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
269 ?>
270 <?php else: ?>
271 <?php
272 do_action('generate_before_main_content'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
273 if (generate_has_default_loop()) {
274 if (have_posts()) :
275 do_action('generate_archive_title'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
276 do_action('generate_before_loop', 'archive'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
277 while (have_posts()) :
278 the_post();
279 generate_do_template_part('archive');
280 endwhile;
281 do_action('generate_after_loop', 'archive'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
282 else :
283 generate_do_template_part('none');
284 endif;
285 }
286 do_action('generate_after_main_content'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
287 ?>
288 <?php endif; ?>
289 </main>
290 </div>
291 <?php
292 do_action('generate_after_primary_content_area'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
293 generate_construct_sidebars(); ?>
294 </div>
295 </div>
296 <?php
297 }
298
299 private function renderOceanWP()
300 {
301 ?>
302 <div id="outer-wrap" class="site clr">
303 <div id="wrap" class="clr">
304 <?php do_action('ocean_before_main'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound ?>
305 <main id="main" class="site-main clr"<?php oceanwp_schema_markup('main'); ?> role="main">
306 <?php do_action('ocean_page_header'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound ?>
307 <?php do_action('ocean_before_content_wrap'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound ?>
308 <div id="content-wrap" class="container clr">
309 <?php do_action('ocean_before_primary'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound ?>
310 <div id="primary" class="content-area clr">
311 <?php do_action('ocean_before_content'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound ?>
312 <div id="content" class="site-content clr">
313 <?php do_action('ocean_before_content_inner'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound ?>
314 <?php if (is_singular()): ?>
315 <?php
316 // Elementor `single` location.
317 if (!function_exists('elementor_theme_do_location') || !elementor_theme_do_location('single')) {
318 // Start loop.
319 while (have_posts()) :
320 the_post();
321 get_template_part('partials/page/layout');
322 endwhile;
323 }
324 ?>
325
326 <?php else: ?>
327
328 <?php if (have_posts()) :
329 if (!function_exists('elementor_theme_do_location') || !elementor_theme_do_location('archive')) {
330 ?>
331 <div id="blog-entries" class="<?php oceanwp_blog_wrap_classes(); ?>">
332 <?php
333 // Define counter for clearing floats.
334 $oceanwp_count = 0;
335 ?>
336
337 <?php
338 // Loop through posts.
339 while (have_posts()) :
340 the_post();
341 ?>
342
343 <?php
344 // Add to counter.
345 $oceanwp_count++;
346 ?>
347
348 <?php
349 // Get post entry content.
350 get_template_part('partials/entry/layout', get_post_type());
351 ?>
352
353 <?php
354 // Reset counter to clear floats.
355 if (oceanwp_blog_entry_columns() === $oceanwp_count) {
356 $oceanwp_count = 0;
357 }
358 ?>
359
360 <?php endwhile; ?>
361
362 </div><!-- #blog-entries -->
363
364 <?php
365 // Display post pagination.
366 oceanwp_blog_pagination();
367 }
368 ?>
369
370 <?php
371 // No posts found.
372 else :
373 ?>
374
375 <?php
376 // Display no post found notice.
377 get_template_part('partials/none');
378 ?>
379
380 <?php endif; ?>
381
382 <?php endif; ?>
383 <?php do_action('ocean_after_content_inner'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound ?>
384 </div><!-- #content -->
385 <?php do_action('ocean_after_content'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound ?>
386 </div><!-- #primary -->
387 <?php do_action('ocean_after_primary'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound ?>
388 </div><!-- #content-wrap -->
389 <?php do_action('ocean_after_content_wrap'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound ?>
390 </main>
391 <?php do_action('ocean_after_main'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound ?>
392 </div>
393 </div>
394 <?php
395 }
396
397 private function renderNeve()
398 {
399 $container_class = apply_filters('neve_container_class_filter', 'container', 'single-page'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
400 $context = class_exists('WooCommerce', false) && (is_cart() || is_checkout() || is_account_page()) ? 'woo-page' : 'single-page';
401 ?>
402 <div class="<?php echo esc_attr($container_class); ?> single-page-container">
403 <div class="row">
404 <?php do_action('neve_do_sidebar', $context, 'left'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound ?>
405 <div class="nv-single-page-wrap col">
406 <?php
407 do_action('neve_before_page_header'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
408 do_action('neve_page_header', $context); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
409 do_action('neve_before_content', $context); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
410
411 if (have_posts()) {
412 while (have_posts()) {
413 the_post();
414 get_template_part('template-parts/content', 'page');
415 }
416 } else {
417 get_template_part('template-parts/content', 'none');
418 }
419 do_action('neve_after_content', $context); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
420 ?>
421 </div>
422 <?php do_action('neve_do_sidebar', $context, 'right'); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound ?>
423 </div>
424 </div>
425 <?php
426 }
427
428 private function renderBricks($wrapperType)
429 {
430 if (defined('BRICKS_VERSION')) {
431 $bricks_data = \Bricks\Helpers::get_bricks_data(get_the_ID(), 'content');
432 if ($bricks_data) {
433 \Bricks\Frontend::render_content($bricks_data);
434 return;
435 }
436 }
437
438 $this->renderFallback($wrapperType);
439 }
440
441 private function renderBreakdance()
442 {
443 if (!function_exists('\\Breakdance\\Render\\render')) {
444 $this->renderFallback();
445 return;
446 }
447
448 $html = \Breakdance\Render\render(get_the_ID());
449 if ($html) {
450 echo $html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
451 }
452 }
453
454 private function renderFallback($wrapperType = 'default')
455 {
456 if (have_posts()) :
457 while (have_posts()) :
458 the_post();
459 ?>
460 <div class="wp_content_wrapper wp_fallback_theme">
461 <?php if ($wrapperType == 'default'): ?>
462 <div class="fcom_wp_content_title">
463 <?php the_title('<h1 class="entry-title">', '</h1>'); ?>
464 </div>
465 <?php endif; ?>
466 <div class="fcom_wp_content_body">
467 <?php the_content(); ?>
468 </div>
469 </div>
470 <?php
471 endwhile;
472 endif;
473 }
474
475 public function renderMobileMenu()
476 {
477 $menuItems = Helper::getMobileMenuItems('wp');
478 if (!$menuItems) {
479 return;
480 }
481 ?>
482 <div class="fcom_mobile_menu">
483 <div class="focm_menu_items">
484 <?php
485 foreach ($menuItems as $menuItem):
486 $permalink = Arr::get($menuItem, 'permalink');
487 if (!$permalink) {
488 $permalink = Helper::getUrlByJsRoute(Arr::get($menuItem, 'route', []));
489 }
490 ?>
491 <div>
492 <a class="focm_menu_item" href="<?php echo esc_url($permalink); ?>">
493 <span class="el-icon">
494 <?php echo Arr::get($menuItem, 'icon_svg'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
495 </span>
496 <?php if ($label = Arr::get($menuItem, 'html')): ?>
497 <span><?php echo wp_kses_post($label); ?></span>
498 <?php endif; ?>
499 </a>
500 </div>
501 <?php endforeach; ?>
502 </div>
503 </div>
504 <?php
505 }
506 }
507