| @@ -1,19 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace FluentSupport\App\Services\Integrations; |
| 4 | 4 | |
| 5 | -use FluentSupport\App\Services\Helper; | |
| 6 | - | |
| 7 | 5 | class IntegrationInit |
| 8 | 6 | { |
| 9 | - const SUPPORT_ENDPOINT = 'support-tickets'; | |
| 10 | - | |
| 11 | 7 | public function init() |
| 12 | 8 | { |
| 13 | - $this->registerWooCommercePortal(); | |
| 14 | - add_action('template_redirect', [$this, 'maybeRedirectPortalUrl']); | |
| 15 | - | |
| 16 | 9 | if(defined('FLUENTCRM') && class_exists('\FluentSupport\App\Services\Integrations\FluentCrm\FluentCRMWidgets')) { |
| 17 | 10 | (new \FluentSupport\App\Services\Integrations\FluentCrm\FluentCRMWidgets())->boot(); |
| 18 | 11 | } |
| 19 | 12 | |
| @@ -23,88 +16,7 @@ | ||
| 23 | 16 | |
| 24 | 17 | if (defined('FLUENTCART_VERSION') && class_exists('\FluentSupport\App\Services\Integrations\FluentCart\FluentCart')) { |
| 25 | 18 | (new \FluentSupport\App\Services\Integrations\FluentCart\FluentCart())->boot(); |
| 26 | 19 | } |
| 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 | 20 | } |
| 109 | 21 | |
| 110 | 22 | } |