PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / trunk
Fluent Support – Helpdesk & Customer Support Ticket System vtrunk
2.4.0 2.3.2 2.3.1 2.3.0 2.2.1 2.2.0 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.4.0 1.4.1 1.4.2 1.4.5 1.4.6 1.4.7 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 All 68 releases
fluent-support / app / Services / Integrations / FluentCommunity / FluentCommunityIntegration.php

FluentCommunityIntegration.php in Fluent Support – Helpdesk & Customer Support Ticket System trunk, at app/Services/Integrations/FluentCommunity/FluentCommunityIntegration.php

101 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentSupport\App\Services\Integrations\FluentCommunity;
4
5 /**
6 * FluentCommunityIntegration bootstraps the Fluent Support portal
7 * inside the FluentCommunity community portal.
8 *
9 * Activated only when FLUENT_COMMUNITY_PLUGIN_VERSION is defined and
10 * the portal destination is set to fluent_community.
11 */
12 class FluentCommunityIntegration
13 {
14 public function boot()
15 {
16 if (!$this->shouldUseCommunityPortal()) {
17 return;
18 }
19
20 // Register 'support' as a known FC route so FC's Vue router treats
21 // it as a valid path and does not fire the NotFound → all_feeds
22 // redirect chain on client-side navigation.
23 add_filter('fluent_community/app_route_paths', [$this, 'registerSupportRoute']);
24
25 // Handle the support route entirely in the SSR hook — mirrors the
26 add_action('fluent_community/rendering_path_ssr_support', [$this, 'renderSupportPortal']);
27
28 // FC's Vue Router intercepts all portal-domain <a> clicks. Since /support
29 // is not a registered FC Vue route, the router falls through to NotFound
30 // which redirects to all_feeds. This beforeEach guard converts any SPA
31 // navigation to /support into a full page load, which then hits the SSR hook.
32 // Must run on ALL community portal pages, not just the support route.
33 add_action('fluent_community/portal_footer', [$this, 'outputRouterGuard'], 999);
34 }
35
36 public function registerSupportRoute($paths)
37 {
38 $paths[] = 'support';
39 return $paths;
40 }
41
42 public function renderSupportPortal($parts = [])
43 {
44 if (!is_user_logged_in()) {
45 wp_safe_redirect($this->getCommunityAuthUrl());
46 exit;
47 }
48
49 (new PortalRenderer())->render();
50 }
51
52 public function outputRouterGuard()
53 {
54 $supportUrl = \FluentCommunity\App\Services\Helper::baseUrl('support/');
55 ?>
56 <script>
57 (function () {
58 var supportUrl = <?php echo wp_json_encode(esc_url($supportUrl)); ?>;
59
60 function addRouterGuard() {
61 var router = window.fluentFrameworkAppRouter;
62 if (!router || typeof router.beforeEach !== 'function') {
63 return;
64 }
65 router.beforeEach(function (to, from, next) {
66 if (to.path === '/support' || to.path.indexOf('/support/') === 0) {
67 window.location.href = supportUrl;
68 return false;
69 }
70 next();
71 });
72 }
73
74 if (document.readyState === 'loading') {
75 document.addEventListener('DOMContentLoaded', addRouterGuard);
76 } else {
77 addRouterGuard();
78 }
79 })();
80 </script>
81 <?php
82 }
83
84 private function getCommunityAuthUrl()
85 {
86 $supportUrl = \FluentCommunity\App\Services\Helper::baseUrl('support/');
87 $authUrl = \FluentCommunity\App\Services\Helper::getAuthUrl();
88
89 if (!$authUrl) {
90 $authUrl = add_query_arg('fcom_action', 'auth', \FluentCommunity\App\Services\Helper::baseUrl(''));
91 }
92
93 return add_query_arg('redirect_to', $supportUrl, $authUrl);
94 }
95
96 private function shouldUseCommunityPortal()
97 {
98 return \FluentSupport\App\Services\Helper::getBusinessSettings('ticket_link_portal') === 'fluent_community';
99 }
100 }
101