PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 2.1.2
Fluent Support – Helpdesk & Customer Support Ticket System v2.1.2
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 2.1.2, at app/Hooks/Handlers/Menu.php

518 lines 20.1 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\AgentGroup;
8 use FluentSupport\App\Models\MailBox;
9 use FluentSupport\App\Models\Product;
10 use FluentSupport\App\Models\TagPivot;
11 use FluentSupport\App\Models\TicketTag;
12 use FluentSupport\App\Modules\PermissionManager;
13 use FluentSupport\App\Services\Helper;
14 use FluentSupport\App\Services\TranslationStrings;
15 use FluentSupport\App\Vite;
16
17 class Menu
18 {
19 public function add()
20 {
21 $capability = PermissionManager::getMenuPermission();
22
23 if (!$capability) {
24 return;
25 }
26
27 $menuPosition = 25;
28 if (defined('FLUENTCRM')) {
29 $menuPosition = 4;
30 }
31
32 /*
33 * Filter Fluent Support menu position in WordPress dashboard
34 * @param integer $menuPosition
35 */
36 $menuPosition = apply_filters('fluent_support/admin_menu_position', $menuPosition);
37
38 add_menu_page(
39 __('Fluent Support', 'fluent-support'),
40 __('Fluent Support', 'fluent-support'),
41 $capability,
42 'fluent-support',
43 array($this, 'renderApp'),
44 $this->getMenuIcon(),
45 $menuPosition
46 );
47
48 add_submenu_page(
49 'fluent-support',
50 __('Dashboard', 'fluent-support'),
51 __('Dashboard', 'fluent-support'),
52 $capability,
53 'fluent-support',
54 array($this, 'renderApp')
55 );
56
57 add_submenu_page(
58 'fluent-support',
59 __('Tickets', 'fluent-support'),
60 __('Tickets', 'fluent-support'),
61 $capability,
62 'fluent-support#/tickets',
63 array($this, 'renderApp')
64 );
65
66 if (PermissionManager::currentUserCan('fst_view_all_reports')) {
67 add_submenu_page(
68 'fluent-support',
69 __('Reports', 'fluent-support'),
70 __('Reports', 'fluent-support'),
71 $capability,
72 'fluent-support#/reports',
73 array($this, 'renderApp')
74 );
75 }
76
77 if (PermissionManager::currentUserCan('fst_sensitive_data')) {
78 add_submenu_page(
79 'fluent-support',
80 __('Customers', 'fluent-support'),
81 __('Customers', 'fluent-support'),
82 $capability,
83 'fluent-support#/customers',
84 array($this, 'renderApp')
85 );
86 }
87
88 if (PermissionManager::currentUserCan('fst_view_activity_logs')) {
89 add_submenu_page(
90 'fluent-support',
91 __('Activities', 'fluent-support'),
92 __('Activities', 'fluent-support'),
93 $capability,
94 'fluent-support#/activity',
95 array($this, 'renderApp')
96 );
97 }
98
99 if (PermissionManager::currentUserCan('fst_manage_settings')) {
100 add_submenu_page(
101 'fluent-support',
102 __('Business Inboxes', 'fluent-support'),
103 __('Business Inboxes', 'fluent-support'),
104 $capability,
105 'fluent-support#/mailboxes',
106 array($this, 'renderApp')
107 );
108 }
109
110 if (PermissionManager::currentUserCan('fst_manage_workflows')) {
111 add_submenu_page(
112 'fluent-support',
113 __('Workflows', 'fluent-support'),
114 __('Workflows', 'fluent-support'),
115 $capability,
116 'fluent-support#/workflows',
117 array($this, 'renderApp')
118 );
119 }
120
121 if (PermissionManager::currentUserCan('fst_manage_saved_replies')) {
122 add_submenu_page(
123 'fluent-support',
124 __('Saved Replies', 'fluent-support'),
125 __('Saved Replies', 'fluent-support'),
126 $capability,
127 'fluent-support#/saved-replies',
128 array($this, 'renderApp')
129 );
130 }
131
132 if (PermissionManager::currentUserCan('fst_manage_settings')) {
133 add_submenu_page(
134 'fluent-support',
135 __('Settings', 'fluent-support'),
136 __('Settings', 'fluent-support'),
137 $capability,
138 'fluent-support#/settings',
139 array($this, 'renderApp')
140 );
141 }
142 }
143
144 public function renderApp()
145 {
146 $app = App::getInstance();
147
148 $assets = $app['url.assets'];
149
150 $baseUrl = apply_filters('fluent_support/base_url', admin_url('admin.php?page=fluent-support#/'));
151
152 $menuItems = [
153 [
154 'key' => 'dashboard',
155 'label' => __('Dashboard', 'fluent-support'),
156 'permalink' => $baseUrl
157 ],
158 [
159 'key' => 'tickets',
160 'label' => __('Tickets', 'fluent-support'),
161 'permalink' => $baseUrl . 'tickets',
162 ],
163 [
164 'key' => 'reports',
165 'label' => __('Reports', 'fluent-support'),
166 'permalink' => $baseUrl . 'reports'
167 ],
168 ];
169
170 $canManageSettings = PermissionManager::currentUserCan('fst_manage_settings');
171
172 if ($canManageSettings) {
173 $menuItems[] = [
174 'key' => 'mailboxes',
175 'label' => __('Business Inboxes', 'fluent-support'),
176 'permalink' => $baseUrl . 'mailboxes'
177 ];
178 }
179
180 if (PermissionManager::currentUserCan('fst_view_activity_logs')) {
181 $menuItems[] = [
182 'key' => 'activity',
183 'label' => __('Activities', 'fluent-support'),
184 'permalink' => $baseUrl . 'activity'
185 ];
186 }
187
188 $hasSensitiveAccess = PermissionManager::currentUserCan('fst_sensitive_data');
189 if ($hasSensitiveAccess) {
190 $menuItems[] = [
191 'key' => 'customers',
192 'label' => __('Customers', 'fluent-support'),
193 'permalink' => $baseUrl . 'customers'
194 ];
195 }
196
197 // Build the "More" dropdown children
198 $moreChildren = [];
199
200 if (PermissionManager::currentUserCan('fst_manage_saved_replies')) {
201 $moreChildren['saved_replies'] = [
202 'key' => 'saved_replies',
203 'label' => __('Saved Replies', 'fluent-support'),
204 'permalink' => $baseUrl . 'saved-replies'
205 ];
206 }
207
208 if (PermissionManager::currentUserCan('fst_manage_workflows')) {
209 $moreChildren['workflows'] = [
210 'key' => 'workflows',
211 'label' => __('Workflows', 'fluent-support'),
212 'permalink' => $baseUrl . 'workflows'
213 ];
214 }
215
216 // Add the "More" dropdown if there are children
217 if (!empty($moreChildren)) {
218 $menuItems[] = [
219 'key' => 'more',
220 'label' => __('More', 'fluent-support'),
221 'permalink' => '#',
222 'children' => $moreChildren
223 ];
224 }
225
226 $secondaryItems = [];
227
228 if ($canManageSettings) {
229 $secondaryItems[] = [
230 'key' => 'settings',
231 'label' => __('Global Settings', 'fluent-support'),
232 'permalink' => $baseUrl . 'settings'
233 ];
234 }
235
236 /*
237 * Filter Fluent Support dashboard top-left menu items
238 *
239 * @since v1.0.0
240 *
241 * @param array $menuItems
242 */
243 $menuItems = apply_filters('fluent_support/primary_menu_items', $menuItems);
244
245 /*
246 * Filter Fluent Support dashboard top-right menu items
247 *
248 * @since v1.0.0
249 *
250 * @param array $secondaryItems
251 */
252 $secondaryItems = apply_filters('fluent_support/secondary_menu_items', $secondaryItems);
253
254
255
256 if (!defined('FLUENT_SUPPORT_PRO_DIR_FILE')) {
257 $secondaryItems[] = [
258 'key' => 'upgrade_to_pro',
259 'label' => 'Upgrade to Pro',
260 'permalink' => 'https://fluentsupport.com'
261 ];
262 }
263
264 $app = App::getInstance();
265 $this->enqueueAssets();
266
267 do_action('fluent_support/admin_app_loaded', $app);
268 $app->view->render('admin.menu', [
269 'base_url' => $baseUrl,
270 'logo' => $assets . 'images/logo.svg',
271 'settingsLogo' => $assets . 'images/gear.svg',
272 'upgradeLogo' => $assets . 'images/crown.svg',
273 'assets' => $assets,
274 'menuItems' => $menuItems,
275 'secondaryItems' => isset($secondaryItems) ? $secondaryItems : [],
276 ]);
277 }
278
279 public function maybeEnqueueAssets()
280 {
281 if (isset($_GET['page']) && sanitize_text_field(wp_unslash($_GET['page'])) === 'fluent-support') {
282 add_action('admin_head', [$this, 'printDarkModeInit'], 1);
283 $this->enqueueAssets();
284 }
285 }
286
287 public function printDarkModeInit()
288 {
289 ?>
290 <script>
291 (function () {
292 var savedTheme = localStorage.getItem('fs-theme');
293
294 // Check if dark mode should be active
295 // localStorage stores: 'dark', 'light', or 'system:dark' / 'system:light'
296 var isDark = savedTheme
297 ? savedTheme.split(':').pop() === 'dark'
298 : window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
299
300 if (isDark) {
301 // Apply immediately to <html> to prevent white flash
302 document.documentElement.classList.add('fs-dark-mode');
303
304 // Watch for <body> to appear and apply class as soon as it exists
305 new MutationObserver(function (mutations, observer) {
306 if (document.body) {
307 document.body.classList.add('fs-dark-mode');
308 observer.disconnect();
309 }
310 }).observe(document.documentElement, { childList: true });
311 }
312 })();
313 </script>
314 <?php
315 }
316
317 public function enqueueAssets()
318 {
319 $app = App::getInstance();
320
321 $assets = $app['url.assets'];
322
323 // Inject Vite HMR client for dev mode
324 add_action('admin_head', function () {
325 Vite::injectViteClient();
326 }, 1);
327
328 wp_enqueue_script('dompurify', $assets . 'libs/purify/purify.min.js', [], '2.4.3');
329
330 if (is_rtl()) {
331 wp_enqueue_style('fluent_support_admin_app_rtl', $assets . 'admin/css/alpha-admin-rtl.css', [], FLUENT_SUPPORT_VERSION);
332 } else {
333 wp_enqueue_style('fluent_support_admin_app', Vite::getEnqueuePath('admin/css/alpha-admin.css'), [], FLUENT_SUPPORT_VERSION);
334 }
335
336 $agents = Agent::select(['id', 'first_name', 'last_name'])
337 ->where('person_type', 'agent')
338 ->get()->toArray();
339
340 foreach ($agents as $index => $agent) {
341 $agents[$index]['id'] = strval($agent['id']);
342 }
343
344 $agentGroups = AgentGroup::select(['id', 'title', 'settings'])->get();
345 $groupPivots = TagPivot::where('source_type', 'agent_group')->get();
346 foreach ($agentGroups as $group) {
347 $group->agent_ids = $groupPivots->where('tag_id', $group->id)
348 ->pluck('source_id')
349 ->map(function ($id) { return strval($id); })
350 ->values()
351 ->toArray();
352 }
353
354 $me = Helper::getAgentByUserId(get_current_user_id());
355
356 if (!$me && current_user_can('manage_options')) {
357 // we should create the agent
358 $user = wp_get_current_user();
359 $me = Agent::create([
360 'email' => $user->user_email,
361 'first_name' => $user->first_name,
362 'last_name' => $user->last_name,
363 'user_id' => $user->ID
364 ]);
365 }
366
367 $me->permissions = PermissionManager::currentUserPermissions();
368
369 do_action('fluent_support_loading_app', $app);
370
371 // Editor default styles.
372 add_filter('user_can_richedit', '__return_true');
373 wp_tinymce_inline_scripts();
374 wp_enqueue_editor();
375 wp_enqueue_media();
376
377 wp_enqueue_script(
378 'fluent_support_admin_app_start',
379 Vite::getEnqueuePath('admin/js/start.js'),
380 array('jquery'),
381 FLUENT_SUPPORT_VERSION,
382 true
383 );
384
385 wp_enqueue_script(
386 'fluent_support_global_admin',
387 Vite::getEnqueuePath('admin/js/global_admin.js'),
388 array('jquery'),
389 FLUENT_SUPPORT_VERSION,
390 true
391 );
392
393 $integrationDrivers = [];
394 if (!defined('FLUENTSUPPORTPRO')) {
395 $integrationDrivers = [
396 [
397 'key' => 'telegram_settings',
398 'title' => __('Telegram', 'fluent-support'),
399 'description' => __('Send Telegram notifications to Group, Channel or individual person inbox and reply from Telegram inbox', 'fluent-support'),
400 'promo_heading' => __('Get activity notification to Telegram Messenger and reply directly from Telegram inbox', 'fluent-support'),
401 'require_pro' => true
402 ],
403 [
404 'key' => 'slack_settings',
405 'title' => __('Slack', 'fluent-support'),
406 'description' => __('Send ticket activity notifications to slack', 'fluent-support'),
407 'promo_heading' => __('Get activity notification to Slack Channel and keep your support team super engaged', 'fluent-support'),
408 'require_pro' => true
409 ]
410 ];
411 }
412
413 /*
414 * Filter integration driver
415 * @param array $integrationDrivers
416 */
417 $integrationDrivers = apply_filters('fluent_support/integration_drivers', $integrationDrivers);
418
419 $tags = TicketTag::select(['id', 'title'])->get()->toArray();
420
421 $tags = array_map(function ($tag) {
422 $tag['id'] = strval($tag['id']);
423 return $tag;
424 }, $tags);
425
426 $i18ns = TranslationStrings::getAdminStrings();
427 $i18ns['allowed_files_and_size'] = Helper::getFileUploadMessage();
428
429 /*
430 * Filter agent portal localize javascript data
431 *
432 * @since v1.0.0
433 *
434 * @param array $appVars
435 */
436 $appVars = apply_filters('fluent_support_app_vars', array(
437 'slug' => $slug = $app->config->get('app.slug'),
438 'nonce' => wp_create_nonce($slug),
439 'rest' => $this->getRestInfo($app),
440 'brand_logo' => $this->getMenuIcon(),
441 'firstEntry' => '',
442 'lastEntry' => '',
443 'asset_url' => $assets,
444 'support_agents' => $agents,
445 'agent_groups' => $agentGroups,
446 'support_products' => Product::select(['id', 'title'])->get(),
447 'client_priorities' => Helper::customerTicketPriorities(),
448 'ticket_statuses' => Helper::ticketStatuses(),
449 'ticket_statuses_group' => Helper::ticketStatusGroups(),
450 'changeable_ticket_statuses' => Helper::changeableTicketStatuses(),
451 'admin_priorities' => Helper::adminTicketPriorities(),
452 'mailboxes' => MailBox::select(['id', 'name', 'settings'])->get(),
453 'me' => $me,
454 'pref' => [
455 'go_back_after_reply' => 'yes'
456 ],
457 'notification_integrations' => $integrationDrivers,
458 'server_time' => gmdate('Y-m-d\TH:i:sP'),
459 'has_email_parser' => defined('FLUENTSUPPORTPRO_PLUGIN_VERSION'),
460 'ticket_tags' => $tags,
461 'i18n' => $i18ns,
462 'custom_fields' => apply_filters('fluent_support/ticket_custom_fields', []),
463 'has_file_upload' => !!Helper::ticketAcceptedFileMiles(),
464 'repost_export_options' => Helper::getExportOptions(),
465 'enable_draft_mode' => Helper::getBusinessSettings('enable_draft_mode', 'no'),
466 'keyboard_shortcuts' => Helper::getBusinessSettings('keyboard_shortcuts', 'no'),
467 'agent_time_tracking' => Helper::getBusinessSettings('agent_time_tracking', 'no'),
468 'max_file_upload' => Helper::getBusinessSettings('max_file_upload', 3),
469 'ajaxurl' => admin_url('admin-ajax.php'),
470 'auth_provider' => Helper::getAuthProvider(),
471 'fluent_bot_integration' => Helper::fluentBotIntegrationStatus(),
472 ));
473
474 if (defined('FLUENTCRM')) {
475 $appVars['fluentcrm_config'] = Helper::getFluentCRMTagConfig();
476 }
477
478 if (defined('FLUENT_BOARDS')) {
479 $appVars['fluent_boards'] = true;
480 }
481
482 $appVars['has_pro'] = defined('FLUENTSUPPORTPRO_PLUGIN_VERSION');
483 if ($appVars['has_pro']) {
484 $appVars['agent_feedback_rating'] = Helper::getBusinessSettings('agent_feedback_rating', 'no');
485 $appVars['open_ai_integration'] = Helper::openAIIntegrationStatus();
486 }
487
488 wp_localize_script('fluent_support_admin_app_start', 'fluentSupportAdmin', $appVars);
489 }
490
491 protected function getRestInfo($app)
492 {
493 $ns = $app->config->get('app.rest_namespace');
494 $v = $app->config->get('app.rest_version');
495
496 return [
497 'base_url' => esc_url_raw(rest_url()),
498 'url' => rest_url($ns . '/' . $v),
499 'nonce' => wp_create_nonce('wp_rest'),
500 'namespace' => $ns,
501 'version' => $v,
502 ];
503 }
504
505 protected function getMenuIcon()
506 {
507 $app = App::getInstance();
508
509 $assets = $app['path.assets'];
510
511 return 'data:image/svg+xml;base64,' . base64_encode(
512 '<svg width="100" height="100" viewBox="0 0 100 100" fill="none" xmlns="http://www.w3.org/2000/svg">
513 <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"/>
514 </svg>'
515 );
516 }
517 }
518