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 / IntegrationInit.php

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

111 lines 4.0 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;
4
5 use FluentSupport\App\Services\Helper;
6
7 class IntegrationInit
8 {
9 const SUPPORT_ENDPOINT = 'support-tickets';
10
11 public function init()
12 {
13 $this->registerWooCommercePortal();
14 add_action('template_redirect', [$this, 'maybeRedirectPortalUrl']);
15
16 if(defined('FLUENTCRM') && class_exists('\FluentSupport\App\Services\Integrations\FluentCrm\FluentCRMWidgets')) {
17 (new \FluentSupport\App\Services\Integrations\FluentCrm\FluentCRMWidgets())->boot();
18 }
19
20 if (defined('FLUENTFORM') && class_exists('\FluentSupport\App\Services\Integrations\FluentForm\FeedIntegration')) {
21 new \FluentSupport\App\Services\Integrations\FluentForm\FeedIntegration();
22 }
23
24 if (defined('FLUENTCART_VERSION') && class_exists('\FluentSupport\App\Services\Integrations\FluentCart\FluentCart')) {
25 (new \FluentSupport\App\Services\Integrations\FluentCart\FluentCart())->boot();
26 }
27
28 if (defined('FLUENT_BOOKING_VERSION') && class_exists('\FluentSupport\App\Services\Integrations\FluentBooking\FluentBookingService')) {
29 $fluentBookingService = new \FluentSupport\App\Services\Integrations\FluentBooking\FluentBookingService();
30 if ($fluentBookingService->isActive()) {
31 $fluentBookingService->init();
32 }
33 }
34
35 if (defined('FLUENT_COMMUNITY_PLUGIN_VERSION') && class_exists('\FluentSupport\App\Services\Integrations\FluentCommunity\FluentCommunityIntegration')) {
36 (new \FluentSupport\App\Services\Integrations\FluentCommunity\FluentCommunityIntegration())->boot();
37 }
38 }
39
40 private function registerWooCommercePortal()
41 {
42 if (!defined('WC_PLUGIN_FILE')) {
43 return;
44 }
45
46 add_rewrite_endpoint(self::SUPPORT_ENDPOINT, EP_ROOT | EP_PAGES);
47
48 add_filter('woocommerce_get_query_vars', function ($queryVars) {
49 $queryVars[self::SUPPORT_ENDPOINT] = self::SUPPORT_ENDPOINT;
50 return $queryVars;
51 });
52
53 add_filter('woocommerce_account_menu_items', function ($items) {
54 if (Helper::getBusinessSettings('ticket_link_portal') !== 'woocommerce') {
55 return $items;
56 }
57
58 $supportPosition = apply_filters('fluent_support/woo_menu_link_position', 3);
59 if (count($items) <= $supportPosition) {
60 $supportPosition = count($items) - 1;
61 }
62
63 $supportLabel = apply_filters('fluent_support/woo_menu_label', __('Support', 'fluent-support'));
64
65 return array_slice($items, 0, $supportPosition, true)
66 + [self::SUPPORT_ENDPOINT => $supportLabel]
67 + array_slice($items, $supportPosition, null, true);
68 });
69
70 add_action('woocommerce_account_' . self::SUPPORT_ENDPOINT . '_endpoint', function () {
71 if (Helper::getBusinessSettings('ticket_link_portal') === 'woocommerce') {
72 echo do_shortcode('[fluent_support_portal]');
73 }
74 });
75 }
76
77 public function maybeRedirectPortalUrl()
78 {
79 $requestUri = isset($_SERVER['REQUEST_URI']) ? esc_url_raw(wp_unslash($_SERVER['REQUEST_URI'])) : '';
80 if (!$requestUri) {
81 return;
82 }
83
84 $requestPath = trim((string) wp_parse_url($requestUri, PHP_URL_PATH), '/');
85 $pathSegments = explode('/', $requestPath);
86 $hasKnownEndpoint = in_array(self::SUPPORT_ENDPOINT, $pathSegments, true);
87
88 if (!$hasKnownEndpoint && strpos($requestUri, 'fs_view=ticket') === false) {
89 return;
90 }
91
92 $baseUrl = Helper::getPortalBaseUrl();
93 $basePath = trim((string) wp_parse_url($baseUrl, PHP_URL_PATH), '/');
94
95 if ($requestPath === $basePath) {
96 return;
97 }
98
99 $redirectUrl = $baseUrl;
100 $query = (string) wp_parse_url($requestUri, PHP_URL_QUERY);
101
102 if ($query) {
103 $redirectUrl .= '?' . $query;
104 }
105
106 wp_safe_redirect($redirectUrl, 302);
107 exit;
108 }
109
110 }
111