PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 1.10.5
Fluent Support – Helpdesk & Customer Support Ticket System v1.10.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 1.5.5 All 68 releases
fluent-support / app / Hooks / Handlers / Menu.php

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

431 lines 16.8 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\MailBox;
8 use FluentSupport\App\Models\Product;
9 use FluentSupport\App\Models\TicketTag;
10 use FluentSupport\App\Modules\PermissionManager;
11 use FluentSupport\App\Services\Helper;
12 use FluentSupport\App\Services\TransStrings;
13
14 class Menu
15 {
16 public function add()
17 {
18 $currentUserPermissions = PermissionManager::currentUserPermissions();
19
20 if (!$currentUserPermissions) {
21 return;
22 }
23
24 $permission = 'fst_view_dashboard';
25
26 $isAdmin = false;
27
28 if (current_user_can('manage_options')) {
29 $permission = 'manage_options';
30 $isAdmin = true;
31 }
32
33 $menuPosition = 25;
34 if (defined('FLUENTCRM')) {
35 $menuPosition = 4;
36 }
37
38 /*
39 * Filter Fluent Support menu position in WordPress dashboard
40 * @param integer $menuPosition
41 */
42 $menuPosition = apply_filters('fluent_support/admin_menu_position', $menuPosition);
43
44 add_menu_page(
45 __('Fluent Support', 'fluent-support'),
46 __('Fluent Support', 'fluent-support'),
47 $permission,
48 'fluent-support',
49 array($this, 'renderApp'),
50 $this->getMenuIcon(),
51 $menuPosition
52 );
53
54
55 add_submenu_page(
56 'fluent-support',
57 __('Dashboard', 'fluent-support'),
58 __('Dashboard', 'fluent-support'),
59 $permission,
60 'fluent-support',
61 array($this, 'renderApp')
62 );
63
64 add_submenu_page(
65 'fluent-support',
66 __('Tickets', 'fluent-support'),
67 __('Tickets', 'fluent-support'),
68 ($isAdmin) ? 'manage_options' : 'fst_manage_own_tickets',
69 'fluent-support#/tickets',
70 array($this, 'renderApp')
71 );
72
73 add_submenu_page(
74 'fluent-support',
75 __('Workflows', 'fluent-support'),
76 __('Workflows', 'fluent-support'),
77 ($isAdmin) ? 'manage_options' : 'fst_manage_workflows',
78 'fluent-support#/workflows',
79 array($this, 'renderApp')
80 );
81
82 add_submenu_page(
83 'fluent-support',
84 __('Activities', 'fluent-support'),
85 __('Activities', 'fluent-support'),
86 ($isAdmin) ? 'manage_options' : 'fst_view_activity_logs',
87 'fluent-support#/activity',
88 array($this, 'renderApp')
89 );
90
91 add_submenu_page(
92 'fluent-support',
93 __('Settings', 'fluent-support'),
94 __('Settings', 'fluent-support'),
95 ($isAdmin) ? 'manage_options' : 'fst_manage_settings',
96 'fluent-support#/settings',
97 array($this, 'renderApp')
98 );
99
100 add_submenu_page(
101 'fluent-support',
102 __('Reports', 'fluent-support'),
103 __('Reports', 'fluent-support'),
104 ($isAdmin) ? 'manage_options' : 'fst_sensitive_data',
105 'fluent-support#/reports',
106 array($this, 'renderApp')
107 );
108
109 }
110
111 public function renderApp()
112 {
113 $app = App::getInstance();
114
115 $assets = $app['url.assets'];
116
117 $baseUrl = apply_filters('fluent_support/base_url', admin_url('admin.php?page=fluent-support#/'));
118
119 $menuItems = [
120 [
121 'key' => 'dashboard',
122 'label' => __('Dashboard', 'fluent-support'),
123 'permalink' => $baseUrl
124 ],
125 [
126 'key' => 'tickets',
127 'label' => __('Tickets', 'fluent-support'),
128 'permalink' => $baseUrl . 'tickets',
129 ],
130 [
131 'key' => 'reports',
132 'label' => __('Reports', 'fluent-support'),
133 'permalink' => $baseUrl . 'reports'
134 ],
135 ];
136
137 $hasSensitiveAccess = PermissionManager::currentUserCan('fst_sensitive_data');
138 if ($hasSensitiveAccess) {
139 $menuItems[] = [
140 'key' => 'customers',
141 'label' => __('Customers', 'fluent-support'),
142 'permalink' => $baseUrl . 'customers'
143 ];
144 }
145
146 $secondaryItems = [];
147
148 if (PermissionManager::currentUserCan('fst_manage_saved_replies')) {
149 $secondaryItems = [
150 [
151 'key' => 'saved_replies',
152 'label' => __('Saved Replies', 'fluent-support'),
153 'permalink' => $baseUrl . 'saved-replies'
154 ]
155 ];
156 }
157
158 if (PermissionManager::currentUserCan('fst_view_activity_logs')) {
159 $secondaryItems[] = [
160 'key' => 'activity',
161 'label' => __('Activities', 'fluent-support'),
162 'permalink' => $baseUrl . 'activity'
163 ];
164 }
165
166 $canManageSettings = PermissionManager::currentUserCan('fst_manage_settings');
167
168 if ($canManageSettings) {
169 $secondaryItems[] = [
170 'key' => 'mailboxes',
171 'label' => __('Business Inboxes', 'fluent-support'),
172 'permalink' => $baseUrl . 'mailboxes'
173 ];
174 }
175
176 if (PermissionManager::currentUserCan('fst_manage_workflows')) {
177 $secondaryItems[] = [
178 'key' => 'workflows',
179 'label' => __('Workflows', 'fluent-support'),
180 'permalink' => $baseUrl . 'workflows'
181 ];
182 }
183
184 if ($canManageSettings) {
185 $secondaryItems[] = [
186 'key' => 'settings',
187 'label' => __('Global Settings', 'fluent-support'),
188 'permalink' => $baseUrl . 'settings'
189 ];
190 }
191
192 /*
193 * Filter Fluent Support dashboard top-left menu items
194 *
195 * @since v1.0.0
196 *
197 * @param array $menuItems
198 */
199 $menuItems = apply_filters('fluent_support/primary_menu_items', $menuItems);
200
201 /*
202 * Filter Fluent Support dashboard top-right menu items
203 *
204 * @since v1.0.0
205 *
206 * @param array $secondaryItems
207 */
208 $secondaryItems = apply_filters('fluent_support/secondary_menu_items', $secondaryItems);
209
210
211
212 if (!defined('FLUENT_SUPPORT_PRO_DIR_FILE')) {
213 $secondaryItems[] = [
214 'key' => 'upgrade_to_pro',
215 'label' => 'Upgrade to Pro',
216 'permalink' => 'https://fluentsupport.com'
217 ];
218 }
219
220 $app = App::getInstance();
221 $this->enqueueAssets();
222
223 do_action('fluent_support/admin_app_loaded', $app);
224 $app->view->render('admin.menu', [
225 'base_url' => $baseUrl,
226 'logo' => $assets . 'images/logo.svg',
227 'menuItems' => $menuItems,
228 'secondaryItems' => isset($secondaryItems) ? $secondaryItems : [],
229 ]);
230 }
231
232 public function maybeEnqueueAssets()
233 {
234 if (isset($_GET['page']) && $_GET['page'] == 'fluent-support') {
235 $this->enqueueAssets();
236 }
237 }
238
239 public function enqueueAssets()
240 {
241 $app = App::getInstance();
242
243 $assets = $app['url.assets'];
244
245 add_filter('admin_footer_text', function ($text) {
246 return '<span id="footer-thankyou">We value your feedback! If the plugin is helpful, please rate Fluent Support with <a target="_blank" rel="nofollow" href="https://wordpress.org/support/plugin/fluent-support/reviews/#new-post">�
247
248
249
250
251 </a> on WordPress.org. For assistance, check out the <a target="_blank" rel="nofollow" href="https://fluentsupport.com/docs/navigate-with-the-keyboard-shortcut">keyboard shortcuts</a> and <a target="_blank" rel="nofollow" href="https://fluentsupport.com/docs/">documentation</a>.</span>';
252 });
253
254 wp_enqueue_script('dompurify', $assets . 'libs/purify/purify.min.js', [], '2.4.3');
255
256 wp_enqueue_style(
257 'fluent_support_admin_app', $assets . 'admin/css/alpha-admin.css', [], FLUENT_SUPPORT_VERSION
258 );
259
260 $agents = Agent::select(['id', 'first_name', 'last_name'])
261 ->where('person_type', 'agent')
262 ->get()->toArray();
263
264 foreach ($agents as $index => $agent) {
265 $agents[$index]['id'] = strval($agent['id']);
266 }
267
268 $me = Helper::getAgentByUserId(get_current_user_id());
269
270 if (!$me && current_user_can('manage_options')) {
271 // we should create the agent
272 $user = wp_get_current_user();
273 $me = Agent::create([
274 'email' => $user->user_email,
275 'first_name' => $user->first_name,
276 'last_name' => $user->last_name,
277 'user_id' => $user->ID
278 ]);
279 }
280
281 $me->permissions = PermissionManager::currentUserPermissions();
282
283 do_action('fluent_support_loading_app', $app);
284
285 // Editor default styles.
286 add_filter('user_can_richedit', '__return_true');
287 wp_tinymce_inline_scripts();
288 wp_enqueue_editor();
289 wp_enqueue_media();
290
291 wp_enqueue_script(
292 'fluent_support_admin_app_start',
293 $assets . 'admin/js/start.js',
294 array('jquery'),
295 FLUENT_SUPPORT_VERSION,
296 true
297 );
298
299 wp_enqueue_script(
300 'fluent_support_global_admin',
301 $assets . 'admin/js/global_admin.js',
302 array('jquery'),
303 FLUENT_SUPPORT_VERSION,
304 true
305 );
306
307 $integrationDrivers = [];
308 if (!defined('FLUENTSUPPORTPRO')) {
309 $integrationDrivers = [
310 [
311 'key' => 'telegram_settings',
312 'title' => __('Telegram', 'fluent-support'),
313 'description' => __('Send Telegram notifications to Group, Channel or individual person inbox and reply from Telegram inbox', 'fluent-support'),
314 'promo_heading' => __('Get activity notification to Telegram Messenger and reply directly from Telegram inbox', 'fluent-support'),
315 'require_pro' => true
316 ],
317 [
318 'key' => 'slack_settings',
319 'title' => __('Slack', 'fluent-support'),
320 'description' => __('Send ticket activity notifications to slack', 'fluent-support'),
321 'promo_heading' => __('Get activity notification to Slack Channel and keep your support team super engaged', 'fluent-support'),
322 'require_pro' => true
323 ]
324 ];
325 }
326
327 /*
328 * Filter integration driver
329 * @param array $integrationDrivers
330 */
331 $integrationDrivers = apply_filters('fluent_support/integration_drivers', $integrationDrivers);
332
333 $tags = TicketTag::select(['id', 'title'])->get()->toArray();
334
335 $tags = array_map(function ($tag) {
336 $tag['id'] = strval($tag['id']);
337 return $tag;
338 }, $tags);
339
340 $i18ns = TransStrings::getTransStrings();
341 $i18ns['allowed_files_and_size'] = Helper::getFileUploadMessage();
342
343 /*
344 * Filter agent portal localize javascript data
345 *
346 * @since v1.0.0
347 *
348 * @param array $appVars
349 */
350 $appVars = apply_filters('fluent_support_app_vars', array(
351 'slug' => $slug = $app->config->get('app.slug'),
352 'nonce' => wp_create_nonce($slug),
353 'rest' => $this->getRestInfo($app),
354 'brand_logo' => $this->getMenuIcon(),
355 'firstEntry' => '',
356 'lastEntry' => '',
357 'asset_url' => $assets,
358 'support_agents' => $agents,
359 'support_products' => Product::select(['id', 'title'])->get(),
360 'client_priorities' => Helper::customerTicketPriorities(),
361 'ticket_statuses' => Helper::ticketStatuses(),
362 'ticket_statuses_group' => Helper::ticketStatusGroups(),
363 'changeable_ticket_statuses' => Helper::changeableTicketStatuses(),
364 'admin_priorities' => Helper::adminTicketPriorities(),
365 'mailboxes' => MailBox::select(['id', 'name', 'settings'])->get(),
366 'me' => $me,
367 'pref' => [
368 'go_back_after_reply' => 'yes'
369 ],
370 'notification_integrations' => $integrationDrivers,
371 'server_time' => gmdate('Y-m-d\TH:i:sP'),
372 'has_email_parser' => defined('FLUENTSUPPORTPRO_PLUGIN_VERSION'),
373 'ticket_tags' => $tags,
374 'i18n' => $i18ns,
375 'custom_fields' => apply_filters('fluent_support/ticket_custom_fields', []),
376 'has_file_upload' => !!Helper::ticketAcceptedFileMiles(),
377 'repost_export_options' => Helper::getExportOptions(),
378 'enable_draft_mode' => Helper::getBusinessSettings('enable_draft_mode', 'no'),
379 'keyboard_shortcuts' => Helper::getBusinessSettings('keyboard_shortcuts', 'no'),
380 'agent_time_tracking' => Helper::getBusinessSettings('agent_time_tracking', 'no'),
381 'max_file_upload' => Helper::getBusinessSettings('max_file_upload', 3),
382 'ajaxurl' => admin_url('admin-ajax.php'),
383 'auth_provider' => Helper::getAuthProvider(),
384 'fluent_bot_integration' => Helper::fluentBotIntegrationStatus(),
385 ));
386
387 if (defined('FLUENTCRM')) {
388 $appVars['fluentcrm_config'] = Helper::getFluentCRMTagConfig();
389 }
390
391 if (defined('FLUENT_BOARDS')) {
392 $appVars['fluent_boards'] = true;
393 }
394
395 $appVars['has_pro'] = defined('FLUENTSUPPORTPRO_PLUGIN_VERSION');
396 if ($appVars['has_pro']) {
397 $appVars['agent_feedback_rating'] = Helper::getBusinessSettings('agent_feedback_rating', 'no');
398 $appVars['open_ai_integration'] = Helper::openAIIntegrationStatus();
399 }
400
401 wp_localize_script('fluent_support_admin_app_start', 'fluentSupportAdmin', $appVars);
402 }
403
404 protected function getRestInfo($app)
405 {
406 $ns = $app->config->get('app.rest_namespace');
407 $v = $app->config->get('app.rest_version');
408
409 return [
410 'base_url' => esc_url_raw(rest_url()),
411 'url' => rest_url($ns . '/' . $v),
412 'nonce' => wp_create_nonce('wp_rest'),
413 'namespace' => $ns,
414 'version' => $v,
415 ];
416 }
417
418 protected function getMenuIcon()
419 {
420 $app = App::getInstance();
421
422 $assets = $app['path.assets'];
423
424 return 'data:image/svg+xml;base64,' . base64_encode(
425 '<svg width="100" height="100" viewBox="0 0 100 100" fill="none" xmlns="http://www.w3.org/2000/svg">
426 <path d="M90 0C95.5228 1.28852e-06 100 4.47715 100 10V90C100 95.5228 95.5228 100 90 100H10C4.47715 100 0 95.5228 0 90V10C1.28855e-06 4.47715 4.47715 0 10 0H90ZM70.2314 44.8672L70.2266 44.876H69.4941C68.7844 44.876 68.0791 44.9715 67.3965 45.1523L60.3203 47.0508L22.0703 57.3096C21.4826 57.4 20.9177 57.604 20.4023 57.9023H20.3428C18.7515 58.8292 17.7751 60.5292 17.7705 62.3691V81.9424C17.7662 82.0596 17.8564 82.1632 17.9736 82.168C18.0595 82.168 18.1409 82.1224 18.1816 82.041C19.9811 78.7134 22.5589 75.8698 25.7012 73.7539C27.0801 72.7774 28.5854 71.9902 30.1768 71.416C30.6694 71.2352 31.167 71.0821 31.6777 70.9375L34.3682 70.209L70.9092 60.4209L71.6641 60.2129C72.0348 60.1496 72.3973 60.0494 72.75 59.9229C76.7916 58.503 78.9165 54.0818 77.4971 50.04C76.4074 46.9384 73.4817 44.8626 70.1992 44.8535L70.2314 44.8672ZM77.1172 19.3086C76.8415 19.3267 76.5612 19.3583 76.29 19.417C75.9194 19.4532 75.5485 19.5217 75.1914 19.6211L21.79 33.9219C20.1217 34.365 18.7609 35.5766 18.1279 37.1816C18.1189 37.2178 18.1001 37.2588 18.082 37.2949C18.046 37.3851 18.0144 37.4798 17.9873 37.5654C17.9602 37.6513 17.915 37.7422 17.915 37.8281C17.9015 37.8733 17.8928 37.9187 17.8838 37.9639C17.8567 38.0765 17.8118 38.2653 17.8115 38.2979V38.3975C17.7889 38.5105 17.7796 38.6285 17.7705 38.7461V45.6494C17.7705 45.8348 17.7844 46.0164 17.8115 46.1973C17.8343 48.3176 19.5613 50.0217 21.6816 50.0127C21.8895 50.0127 22.0978 49.9951 22.3057 49.959C22.6085 49.9454 22.9113 49.8954 23.2051 49.8096L68.7705 37.5928C69.9958 37.2627 71.2669 37.1404 72.5283 37.2354C76.9635 37.5068 80.8557 40.2878 82.5557 44.3975V25.2637C82.5557 25.0286 82.5425 24.8066 82.5244 24.5986V24.4717C82.5242 21.619 80.2141 19.3087 77.3613 19.3086H77.1172Z" fill="#9CA1A8"/>
427 </svg>'
428 );
429 }
430 }
431