PluginProbe
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration / 2.0.1
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration v2.0.1
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 2.0.1, at app/Hooks/Handlers/ShortcodeHandler.php

210 lines 7.3 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 = is_rtl();
83 Vite::enqueueStyle($slug . '_public_board_app', 'scss/admin.scss');
84
85 if ($isRtl && !Vite::underDevelopment()) {
86 wp_enqueue_style(
87 $slug . '_public_board_app_rtl',
88 $assets . 'admin/admin-rtl.css',
89 [$slug . '_public_board_app'],
90 FLUENT_BOARDS_PLUGIN_VERSION
91 );
92 }
93
94 // Enqueue merged chunk CSS in production
95 if (!Vite::underDevelopment()) {
96 $styleCssPath = FLUENT_BOARDS_PLUGIN_PATH . 'assets/admin/style.css';
97 if (file_exists($styleCssPath)) {
98 wp_enqueue_style(
99 $slug . '_public_vite_style',
100 $assets . 'admin/style.css',
101 [$slug . '_public_board_app'],
102 FLUENT_BOARDS_PLUGIN_VERSION
103 );
104 }
105 }
106
107 Vite::enqueueStaticScript(
108 $slug . '_public_global_admin',
109 'admin/global_admin.js',
110 [],
111 FLUENT_BOARDS_PLUGIN_VERSION,
112 true
113 );
114
115 Vite::enqueueScript(
116 $slug . '_public_single_board',
117 'admin/single_board.js',
118 ['jquery'],
119 FLUENT_BOARDS_PLUGIN_VERSION,
120 true
121 );
122
123 wp_localize_script(
124 $slug . '_public_single_board',
125 'fluentAddonVars',
126 $isPublicMode ? $this->getPublicAddonVars($app, $boardId, $assets, $isRtl) : $this->getPrivateAddonVars($app)
127 );
128 }
129
130 private function getPublicAddonVars($app, $boardId, $assets, $isRtl)
131 {
132 $boardToken = PublicAccessService::generateAccessToken($boardId);
133 $baseUrl = get_permalink() ?: site_url('/');
134 $baseUrl = rtrim($baseUrl, '/') . '/#/';
135 $guestName = __('Guest', 'fluent-boards');
136
137 return [
138 'slug' => $app->config->get('app.slug'),
139 'nonce' => '',
140 'rest' => [
141 'base_url' => esc_url_raw(rest_url()),
142 'url' => rest_url($app->config->get('app.rest_namespace') . '/' . $app->config->get('app.rest_version')),
143 'nonce' => '',
144 'namespace' => $app->config->get('app.rest_namespace'),
145 'version' => $app->config->get('app.rest_version'),
146 ],
147 'asset_url' => $assets,
148 'admin_url' => '',
149 'base_url' => $baseUrl,
150 'site_url' => site_url('/'),
151 'server_time' => current_datetime()->format('Y-m-d H:i:s P'),
152 'server_time_zone' => current_datetime()->format('P'),
153 'utc_offset' => current_time('timestamp') - strtotime(gmdate('Y-m-d H:i:s')),
154 'trans' => TransStrings::getStrings(),
155 'is_onboarded' => 'yes',
156 'render_in' => 'front',
157 'dashboard_notices'=> [],
158 'is_beta' => false,
159 'advanced_modules' => (object)[],
160 'me' => [
161 'id' => 0,
162 'full_name' => $guestName,
163 'display_name' => $guestName,
164 'email' => '',
165 'photo' => '',
166 'fluent_boards_role' => 'guest',
167 'fluent_boards_capabilities' => [],
168 'is_wp_admin' => 'no',
169 ],
170 'start_of_week' => intval(get_option('start_of_week', 0)),
171 'time_format' => get_option('time_format', 'g:i'),
172 'priorities' => apply_filters('fluent_boards/task_priorities', (new AdminMenuHandler())->getDefaultPriorities()),
173 'wpContentCss' => '',
174 'dashiconsCss' => site_url('/wp-includes/css/dashicons.css'),
175 'fluent_crm_exists' => false,
176 'fluent_roadmap_exists' => false,
177 'has_pro' => false,
178 'upgrade_url' => fluent_boards_get_upgrade_url(),
179 'board_solid_colors' => Constant::BOARD_BACKGROUND_DEFAULT_SOLID_COLORS,
180 'board_gradient_colors' => Constant::BOARD_BACKGROUND_DEFAULT_GRADIENT_COLORS,
181 'is_rtl' => $isRtl,
182 'public_mode' => true,
183 'public_token' => $boardToken,
184 ];
185 }
186
187 private function getPrivateAddonVars($app)
188 {
189 $vars = (new AdminMenuHandler())->getAddonVars($app);
190 $baseUrl = get_permalink() ?: site_url('/');
191 $vars['base_url'] = rtrim($baseUrl, '/') . '/#/';
192 $vars['render_in'] = 'front';
193 $vars['public_mode'] = false;
194 $vars['public_token'] = '';
195
196 return $vars;
197 }
198
199 private function loginRequiredHtml()
200 {
201 $loginUrl = wp_login_url(get_permalink() ?: site_url('/'));
202 return '<p>' . sprintf(
203 // translators: %1$s is the opening login link tag, %2$s is the closing login link tag.
204 esc_html__('Please %1$slog in%2$s to view this board.', 'fluent-boards'),
205 '<a href="' . esc_url($loginUrl) . '">',
206 '</a>'
207 ) . '</p>';
208 }
209 }
210