PluginProbe
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration / 1.95
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration v1.95
2.1.0 2.0.15 2.0.12 2.0.10 2.0.4 2.0.1 2.0.0 1.95.3 1.95.2 1.95 1.91.6 trunk 1.11 1.12 1.13 1.20 1.21 1.22 1.23 1.30 1.31 1.32 1.35 1.40 1.41 All 42 releases
fluent-boards / app / Hooks / Handlers / ShortcodeHandler.php

ShortcodeHandler.php in FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration 1.95, at app/Hooks/Handlers/ShortcodeHandler.php

206 lines 7.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentBoards\App\Hooks\Handlers;
4
5 use FluentBoards\App\App;
6 use FluentBoards\App\Models\Board;
7 use FluentBoards\App\Services\Helper;
8 use FluentBoards\App\Services\PermissionManager;
9 use FluentBoards\App\Services\PublicAccessService;
10 use FluentBoards\App\Services\TransStrings;
11 use FluentBoards\App\Vite;
12
13 class ShortcodeHandler
14 {
15 public function register()
16 {
17 add_shortcode('fluent_board', [$this, 'renderBoard']);
18 add_shortcode('fluent_board_public', [$this, 'renderPublicBoard']);
19 }
20
21 public function renderPublicBoard($atts = [])
22 {
23 $atts = shortcode_atts([
24 'id' => 0
25 ], (array)$atts, 'fluent_board_public');
26
27 return $this->renderBoardInternal($atts, true);
28 }
29
30 public function renderBoard($atts = [])
31 {
32 $atts = shortcode_atts([
33 'id' => 0,
34 ], (array)$atts, 'fluent_board');
35
36 return $this->renderBoardInternal($atts, false);
37 }
38
39 private function renderBoardInternal($atts, $isPublicMode)
40 {
41 $boardId = absint($atts['id']);
42 if (!$boardId) {
43 return '';
44 }
45
46 $board = Board::where('id', $boardId)->whereNull('archived_at')->first();
47 if (!$board) {
48 return '';
49 }
50
51 if (!$isPublicMode) {
52 if (!is_user_logged_in()) {
53 return $this->loginRequiredHtml();
54 }
55
56 if (!PermissionManager::userHasBoardAccess($boardId)) {
57 return '';
58 }
59 } else {
60 if (!$board->getMetaByKey('public_access_enabled')) {
61 return '';
62 }
63 }
64
65 $this->enqueueAssets($boardId, $isPublicMode);
66
67 return Helper::loadView('frontend.public_board', [
68 'board_id' => $boardId
69 ]);
70 }
71
72 private function enqueueAssets($boardId, $isPublicMode)
73 {
74 $app = App::getInstance();
75 $assets = $app['url.assets'];
76 $slug = $app->config->get('app.slug');
77
78 // Inject Vite HMR client in dev mode
79 Vite::injectViteClient();
80
81 $isRtl = is_rtl();
82 Vite::enqueueStyle($slug . '_public_board_app', 'scss/admin.scss');
83
84 if ($isRtl && !Vite::underDevelopment()) {
85 wp_enqueue_style(
86 $slug . '_public_board_app_rtl',
87 $assets . 'admin/admin-rtl.css',
88 [$slug . '_public_board_app'],
89 FLUENT_BOARDS_PLUGIN_VERSION
90 );
91 }
92
93 // Enqueue merged chunk CSS in production
94 if (!Vite::underDevelopment()) {
95 $styleCssPath = FLUENT_BOARDS_PLUGIN_PATH . 'assets/admin/style.css';
96 if (file_exists($styleCssPath)) {
97 wp_enqueue_style(
98 $slug . '_public_vite_style',
99 $assets . 'admin/style.css',
100 [$slug . '_public_board_app'],
101 FLUENT_BOARDS_PLUGIN_VERSION
102 );
103 }
104 }
105
106 Vite::enqueueStaticScript(
107 $slug . '_public_global_admin',
108 'admin/global_admin.js',
109 [],
110 FLUENT_BOARDS_PLUGIN_VERSION,
111 true
112 );
113
114 Vite::enqueueScript(
115 $slug . '_public_single_board',
116 'admin/single_board.js',
117 ['jquery'],
118 FLUENT_BOARDS_PLUGIN_VERSION,
119 true
120 );
121
122 wp_localize_script(
123 $slug . '_public_single_board',
124 'fluentAddonVars',
125 $isPublicMode ? $this->getPublicAddonVars($app, $boardId, $assets, $isRtl) : $this->getPrivateAddonVars($app)
126 );
127 }
128
129 private function getPublicAddonVars($app, $boardId, $assets, $isRtl)
130 {
131 $boardToken = PublicAccessService::generateAccessToken($boardId);
132 $baseUrl = get_permalink() ?: site_url('/');
133 $baseUrl = rtrim($baseUrl, '/') . '/#/';
134 $guestName = __('Guest', 'fluent-boards');
135
136 return [
137 'slug' => $app->config->get('app.slug'),
138 'nonce' => '',
139 'rest' => [
140 'base_url' => esc_url_raw(rest_url()),
141 'url' => rest_url($app->config->get('app.rest_namespace') . '/' . $app->config->get('app.rest_version')),
142 'nonce' => '',
143 'namespace' => $app->config->get('app.rest_namespace'),
144 'version' => $app->config->get('app.rest_version'),
145 ],
146 'asset_url' => $assets,
147 'admin_url' => '',
148 'base_url' => $baseUrl,
149 'site_url' => site_url('/'),
150 'server_time' => current_datetime()->format('Y-m-d H:i:s P'),
151 'server_time_zone' => current_datetime()->format('P'),
152 'utc_offset' => current_time('timestamp') - strtotime(gmdate('Y-m-d H:i:s')),
153 'trans' => TransStrings::getStrings(),
154 'is_onboarded' => 'yes',
155 'render_in' => 'front',
156 'dashboard_notices'=> [],
157 'is_beta' => false,
158 'advanced_modules' => (object)[],
159 'me' => [
160 'id' => 0,
161 'full_name' => $guestName,
162 'display_name' => $guestName,
163 'email' => '',
164 'photo' => '',
165 'fluent_boards_role' => 'guest',
166 'fluent_boards_capabilities' => [],
167 'is_wp_admin' => 'no',
168 ],
169 'start_of_week' => intval(get_option('start_of_week', 0)),
170 'time_format' => get_option('time_format', 'g:i'),
171 'priorities' => apply_filters('fluent_boards/task_priorities', (new AdminMenuHandler())->getDefaultPriorities()),
172 'wpContentCss' => '',
173 'dashiconsCss' => site_url('/wp-includes/css/dashicons.css'),
174 'fluent_crm_exists' => false,
175 'fluent_roadmap_exists' => false,
176 'has_pro' => false,
177 'is_rtl' => $isRtl,
178 'public_mode' => true,
179 'public_token' => $boardToken,
180 ];
181 }
182
183 private function getPrivateAddonVars($app)
184 {
185 $vars = (new AdminMenuHandler())->getAddonVars($app);
186 $baseUrl = get_permalink() ?: site_url('/');
187 $vars['base_url'] = rtrim($baseUrl, '/') . '/#/';
188 $vars['render_in'] = 'front';
189 $vars['public_mode'] = false;
190 $vars['public_token'] = '';
191
192 return $vars;
193 }
194
195 private function loginRequiredHtml()
196 {
197 $loginUrl = wp_login_url(get_permalink() ?: site_url('/'));
198 return '<p>' . sprintf(
199 // translators: %1$s is the opening login link tag, %2$s is the closing login link tag.
200 esc_html__('Please %1$slog in%2$s to view this board.', 'fluent-boards'),
201 '<a href="' . esc_url($loginUrl) . '">',
202 '</a>'
203 ) . '</p>';
204 }
205 }
206