| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* All registered action's handlers should be in app\Hooks\Handlers, |
| 5 |
* addAction is similar to add_action and addCustomAction is just a |
| 6 |
* wrapper over add_action which will add a prefix to the hook name |
| 7 |
* using the plugin slug to make it unique in all wordpress plugins, |
| 8 |
* ex: $app->addCustomAction('foo', ['FooHandler', 'handleFoo']) is |
| 9 |
* equivalent to add_action('slug-foo', ['FooHandler', 'handleFoo']). |
| 10 |
*/ |
| 11 |
|
| 12 |
/** |
| 13 |
* @var $app FluentSupport\Framework\Foundation\Application |
| 14 |
*/ |
| 15 |
|
| 16 |
use FluentSupport\App\App; |
| 17 |
|
| 18 |
require_once 'Handlers/AuthHandler.php'; |
| 19 |
|
| 20 |
(new \FluentSupport\App\Hooks\Handlers\AuthHandler)->init(); |
| 21 |
|
| 22 |
$app->addCustomAction('handle_exception', 'ExceptionHandler@handle'); |
| 23 |
|
| 24 |
$app->addAction('admin_menu', 'Menu@add'); |
| 25 |
$app->addAction('admin_enqueue_scripts', 'Menu@maybeEnqueueAssets'); |
| 26 |
|
| 27 |
add_shortcode('fluent_support_portal', function () { |
| 28 |
return (new \FluentSupport\App\Hooks\Handlers\CustomerPortalHandler())->renderPortal(); |
| 29 |
}); |
| 30 |
|
| 31 |
add_shortcode('fluent_support_admin_portal', function () { |
| 32 |
$app = App::getInstance(); |
| 33 |
$assets = $app['url.assets']; |
| 34 |
wp_enqueue_style('fluent_support_login_style', $assets.'admin/css/all_public.css'); |
| 35 |
if (!get_current_user_id()) { |
| 36 |
$return = '<div class="fst_login"><h3>'.__('Please Login', 'fluent-support').'</h3>'; |
| 37 |
$return .= do_shortcode('[fluent_support_login]'); |
| 38 |
$return .= '</div>'; |
| 39 |
return $return; |
| 40 |
} |
| 41 |
|
| 42 |
$currentUserPermissions = \FluentSupport\App\Modules\PermissionManager::currentUserPermissions(); |
| 43 |
if (!$currentUserPermissions) { |
| 44 |
return __('Sorry, You do not have permission to this page', 'fluent-support'); |
| 45 |
} |
| 46 |
|
| 47 |
add_filter('fluent_support/base_url', function ($url) { |
| 48 |
global $wp; |
| 49 |
return home_url(add_query_arg(array(), $wp->request)) . '/#/'; |
| 50 |
}); |
| 51 |
|
| 52 |
add_filter('fluent_support/secondary_menu_items', function ($items) { |
| 53 |
global $wp; |
| 54 |
$items[] = [ |
| 55 |
'key' => 'logout', |
| 56 |
'label' => __('Logout', 'fluent-support'), |
| 57 |
'permalink' => wp_logout_url(home_url(add_query_arg(array(), $wp->request))) |
| 58 |
]; |
| 59 |
return $items; |
| 60 |
}); |
| 61 |
|
| 62 |
ob_start(); |
| 63 |
echo '<div class="fst_front">'; |
| 64 |
(new \FluentSupport\App\Hooks\Handlers\Menu())->renderApp(); |
| 65 |
echo '</div>'; |
| 66 |
return ob_get_clean(); |
| 67 |
}); |
| 68 |
|
| 69 |
// init integrations |
| 70 |
(new \FluentSupport\App\Services\Integrations\IntegrationInit())->init(); |
| 71 |
|
| 72 |
// Activities |
| 73 |
(new \FluentSupport\App\Hooks\Handlers\ActivityLogger())->init(); |
| 74 |
|
| 75 |
/* |
| 76 |
* Email Notification Hooks |
| 77 |
*/ |
| 78 |
|
| 79 |
$app->addAction('fluent_support/ticket_created', 'EmailNotificationHandler@ticketCreated', 10, 2); |
| 80 |
$app->addAction('fluent_support/response_added_by_agent', 'EmailNotificationHandler@agentReplied', 10, 3); |
| 81 |
$app->addAction('fluent_support/response_added_by_customer', 'EmailNotificationHandler@customerReplied', 10, 3); |
| 82 |
$app->addAction('fluent_support/ticket_closed_by_agent', 'EmailNotificationHandler@closedByAgent', 10, 2); |
| 83 |
|
| 84 |
// Cleanup |
| 85 |
$app->addAction('fluent_support_hourly_tasks', 'CleanupHandler@initHourlyTasks'); |
| 86 |
$app->addAction('fluent_support_daily_tasks', 'CleanupHandler@initDailyTasks'); |
| 87 |
$app->addAction('fluent_support/deleting_ticket', 'CleanupHandler@deleteTicketAttachments'); |
| 88 |
|
| 89 |
if(isset($_GET['fs_view'])) { |
| 90 |
$app->addAction('init', 'ExternalPages@route'); |
| 91 |
} |
| 92 |
|
| 93 |
if (isset($_GET['fst_file'])) { |
| 94 |
add_action('init', function () { |
| 95 |
(new \FluentSupport\App\Hooks\Handlers\ExternalPages())->view_attachment(); |
| 96 |
}); |
| 97 |
} |
| 98 |
|
| 99 |
// require the CLI |
| 100 |
if ( defined( 'WP_CLI' ) && WP_CLI ) { |
| 101 |
\WP_CLI::add_command( 'fluent_support', '\FluentSupport\App\Hooks\CLI\FluentCli' ); |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
(new \FluentSupport\App\Hooks\Handlers\PermissionFilterManager)->init(); |
| 106 |
|
| 107 |
|