PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 1.4.0
Fluent Support – Helpdesk & Customer Support Ticket System v1.4.0
2.4.5 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 All 69 releases
fluent-support / app / Hooks / Handlers / CustomerPortalHandler.php

CustomerPortalHandler.php in Fluent Support – Helpdesk & Customer Support Ticket System 1.4.0, at app/Hooks/Handlers/CustomerPortalHandler.php

126 lines 5.5 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\Hooks\Handlers;
4
5 use FluentSupport\App\App;
6 use FluentSupport\App\Models\Agent;
7 use FluentSupport\App\Models\Customer;
8 use FluentSupport\App\Models\Product;
9 use FluentSupport\App\Modules\PermissionManager;
10 use FluentSupport\App\Services\EmailNotification\Settings;
11 use FluentSupport\App\Services\Helper;
12 use FluentSupport\App\Services\TransStrings;
13 use FluentSupport\Framework\Support\Arr;
14
15 class CustomerPortalHandler
16 {
17 public function renderPortal()
18 {
19 if (static::customerStatus() && static::customerStatus()->status === 'inactive') {
20 return '<div id="fluent_support_client_app" style="text-align: center;"><h3 class="fs_customer_restriction">' . __('You don’t have permission to view the tickets', 'fluent-support') . '</h3></div>';
21 } else if (PermissionManager::currentUserPermissions()) {
22 $adminPortalUrl = Helper::getPortalAdminBaseUrl();
23 return '<div style="text-align: center;"><h3>' . __('Customer Portal is only accessible by Customers. Looks like you are a support staff', 'fluent-support') . '</h3><a href="' . $adminPortalUrl . '">' . __('Go to Support Admin Page', 'fluent-support') . '</a></div>';
24 } else if ($this->hasCustomerPortalAccess()) {
25 $this->enqueueScripts();
26 return '<div id="fluent_support_client_app"><h3 class="fs_loading_text">' . __('Loading Customer Portal. Please wait...', 'fluent-support') . '</h3></div>';
27 } else {
28 $businessSettings = Helper::getBusinessSettings();
29 return do_shortcode(Arr::get($businessSettings, 'login_message', ''));
30 }
31 }
32
33 public function enqueueScripts()
34 {
35 $app = App::getInstance();
36
37 $ns = $app->config->get('app.rest_namespace');
38 $v = $app->config->get('app.rest_version');
39 $slug = $app->config->get('app.slug');
40
41 $restInfo = [
42 'base_url' => esc_url_raw(rest_url()),
43 'url' => rest_url($ns . '/' . $v . '/customer-portal'),
44 'nonce' => wp_create_nonce('wp_rest'),
45 'namespace' => $ns,
46 'version' => $v,
47 ];
48
49 $assets = $app['url.assets'];
50
51 wp_enqueue_script('fs_tk_customer_portal', $assets . 'portal/js/app.js', ['jquery'], FLUENT_SUPPORT_VERSION);
52 wp_enqueue_style('fs_tk_customer_portal', $assets . 'portal/css/app.css', [], FLUENT_SUPPORT_VERSION);
53
54 $i18ns = [
55 'Create a New Ticket' => __('Create a New Ticket', 'fluent-support'),
56 'Conversation' => __('Conversation', 'fluent-support'),
57 'Click Here to Write a reply' => __('Click Here to Write a reply', 'fluent-support'),
58 'All' => __('All', 'fluent-support'),
59 'Open' => __('Open', 'fluent-support'),
60 'Closed' => __('Closed', 'fluent-support'),
61 'Date' => __('Date', 'fluent-support'),
62 'Status' => __('Status', 'fluent-support'),
63 'Next' => __('Next', 'fluent-support'),
64 'Prev' => __('Prev', 'fluent-support'),
65 'Subject' => __('Subject', 'fluent-support'),
66 'Ticket Details' => __('Ticket Details', 'fluent-support'),
67 'Priority' => __('Priority', 'fluent-support'),
68 'Related Product/Service' => __('Related Product/Service', 'fluent-support'),
69 'agent_and_officials_can_see' => __('Only you and official support agents can view this conversations', 'fluent-support'),
70 ];
71
72 $i18ns['allowed_files_and_size'] = Helper::getFileUploadMessage();
73
74 $data = [
75 'rest' => $restInfo,
76 'nonce' => wp_create_nonce($slug),
77 'support_products' => Product::select(['id', 'title'])->get(),
78 'customer_ticket_priorities' => Helper::customerTicketPriorities(),
79 'view_tickets_url' => '#/',
80 'i18n' => $i18ns,
81 'fallback_image' => $assets . 'images/file.png',
82 'has_file_upload' => !!Helper::ticketAcceptedFileMiles()
83 ];
84
85 if ($this->isSignedTicketView()) {
86 $data['intended_ticket_hash'] = sanitize_text_field($_REQUEST['support_hash']);
87 $data['view_tickets_url'] = Helper::getPortalBaseUrl() . '/#';
88 } else {
89 add_filter('user_can_richedit', '__return_true');
90 }
91
92 wp_tinymce_inline_scripts();
93 wp_enqueue_editor();
94
95 $data = apply_filters('fluent_support/customer_portal_vars', $data);
96
97 wp_localize_script('fs_tk_customer_portal', 'fs_customer_portal', $data);
98 }
99
100 public function hasCustomerPortalAccess()
101 {
102 $userId = get_current_user_id();
103
104 if ($userId) {
105 return true;
106 }
107
108 return $this->isSignedTicketView();
109 }
110
111 protected static function customerStatus()
112 {
113 $user = get_current_user_id();
114 return Customer::where('user_id', $user)->select(['status'])->first();
115 }
116
117 protected function isSignedTicketView()
118 {
119 if (!Helper::isPublicSignedTicketEnabled()) {
120 return false;
121 }
122
123 return isset($_REQUEST['fs_view']) && $_REQUEST['fs_view'] == 'ticket' && isset($_REQUEST['support_hash']) && isset($_REQUEST['ticket_id']);
124 }
125 }
126