PluginProbe
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration / trunk
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration vtrunk
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 1.45 All 41 releases
fluent-boards / app / Hooks / Handlers / ShortcodeHandler.php

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

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