PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 1.0.94
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v1.0.94
2.11.0 2.10.0 2.10.01 2.9.1 2.9.0 2.8.1 2.8.0 2.7.7 2.7.5 2.7.0 2.6.01 2.6.0 2.5.0 2.4.01 trunk 1.0.90 1.0.91 1.0.92 1.0.93 1.0.94 1.0.95 1.0.96 1.0.97 1.0.98 1.0.99 All 78 releases
fluent-community / app / Hooks / Handlers / PortalHandler.php

PortalHandler.php in FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses 1.0.94, at app/Hooks/Handlers/PortalHandler.php

1,014 lines 52.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCommunity\App\Hooks\Handlers;
4
5 use FluentCommunity\App\App;
6 use FluentCommunity\App\Functions\Utility;
7 use FluentCommunity\App\Models\Space;
8 use FluentCommunity\App\Models\Feed;
9 use FluentCommunity\App\Models\BaseSpace;
10 use FluentCommunity\App\Models\SpaceGroup;
11 use FluentCommunity\App\Models\User;
12 use FluentCommunity\App\Models\XProfile;
13 use FluentCommunity\App\Services\CustomSanitizer;
14 use FluentCommunity\App\Services\Helper;
15 use FluentCommunity\App\Services\LockscreenService;
16 use FluentCommunity\App\Services\ProfileHelper;
17 use FluentCommunity\App\Services\TransStrings;
18 use FluentCommunity\App\Vite;
19 use FluentCommunity\Framework\Support\Arr;
20 use FluentCommunity\App\Services\FeedsHelper;
21
22 class PortalHandler
23 {
24 protected $currentPath = '';
25
26 protected $slug = null;
27
28 public function register()
29 {
30 /**
31 * Register the portal route
32 */
33 add_action('init', function () {
34 $this->slug = Helper::getPortalSlug();
35 if ($this->slug !== '') {
36 add_rewrite_rule('^' . $this->slug . '/?$', 'index.php?fcom_route=portal_home', 'top'); // For /hooks
37 add_rewrite_rule('^' . $this->slug . '/(.+)/?', 'index.php?fcom_route=$matches[1]', 'top');
38 }
39 });
40
41 add_filter('query_vars', function ($vars) {
42 $vars[] = 'fcom_route';
43 return $vars;
44 });
45
46 add_action('template_redirect', function () {
47 $hook_path = get_query_var('fcom_route');
48 if ($hook_path) {
49 $this->currentPath = $hook_path;
50 $this->renderFullApp();
51 }
52
53 if ($this->slug === '') {
54 global $wp;
55 $currentRequest = $wp->request;
56 if ($hookPath = Helper::getPortalRequestPath($currentRequest)) {
57 $this->currentPath = $hookPath;
58 $this->renderFullApp();
59 }
60 }
61 }, 1);
62
63 add_action('fluent_community/portal_html', function () {
64 App::make('view')->render('portal.portal');
65 });
66
67 add_action('fluent_community/portal_header', function ($context) {
68 $this->getPortalHeader(true, $context);
69 });
70
71 add_action('fluent_community/portal_sidebar', function ($context) {
72 $this->getPortalSidebar(true, $context);
73 });
74
75 // add a link to admin menu which will redirect to /portal
76 add_action('admin_menu', function () {
77 add_menu_page(
78 __('FluentCommunity', 'fluent-community'),
79 __('FluentCommunity', 'fluent-community'),
80 'edit_posts',
81 'fluent-community',
82 [$this, 'showAdminPage'],
83 $this->getMenuIcon(),
84 130
85 );
86 });
87
88 add_action('fluent_community/enqueue_global_assets', function ($useDefaultTheme = true) {
89 wp_enqueue_style('fluent_community_global', Vite::getDynamicSrcUrl('global.scss'), [], time(), 'screen');
90 if ($useDefaultTheme) {
91 wp_enqueue_style('fluent_community_default_theme', Vite::getDynamicSrcUrl('theme-default.scss'), [], FLUENT_COMMUNITY_PLUGIN_VERSION, 'screen');
92 }
93
94 wp_enqueue_script('portal_general', Vite::getStaticSrcUrl('portal_general.js'), [], FLUENT_COMMUNITY_PLUGIN_VERSION, true);
95
96 wp_localize_script('portal_general', 'fcom_portal_general', [
97 'is_wp' => true
98 ]);
99 });
100
101 add_action('admin_bar_menu', function ($wp_admin_bar) {
102 if (!\FluentCommunity\App\Services\Helper::canAccessPortal()) {
103 return;
104 }
105
106 // Add custom link within site name dropdown
107 $wp_admin_bar->add_node(array(
108 'id' => 'fluent-community-link',
109 'title' => __('Visit Community Portal', 'fluent-community'),
110 'href' => \FluentCommunity\App\Services\Helper::baseUrl('/'),
111 'parent' => 'site-name'
112 ));
113 }, 99);
114
115 add_action('fluent_community/top_menu_right_items', [$this, 'renderTopMenuRightItems']);
116
117 add_action('fluent_community/after_portal_sidebar', function () {
118
119 if (did_action('fluent_community/after_header_right_menu_items')) {
120 echo '<div role="region" aria-label="Portal Settings" class="fcom_side_footer">';
121 if (Helper::isSiteAdmin()) {
122 ?>
123 <div style="display: flex;justify-content: space-between;" class="fcom_admin_menu">
124 <?php if (!defined('FLUENT_COMMUNITY_PRO')): ?>
125 <a title="Upgrade to Pro" target="_blank" rel="noopener" class="fcom_inline_icon_link_item"
126 href="<?php echo esc_url(Utility::getProductUrl(true)) ?>">
127 <span class="el-icon">
128 <svg width="126" height="125" viewBox="0 0 126 125" fill="none">
129 <rect x="0.22139" width="125" height="125" rx="17.8571" fill="#4A5FE0"/>
130 <path
131 d="M47.9424 75.1832L61.6888 67.2467L69.6253 80.9931C62.0334 85.3763 52.3256 82.7751 47.9424 75.1832Z"
132 fill="white"/>
133 <path fill-rule="evenodd" clip-rule="evenodd"
134 d="M75.4348 59.3101L61.6884 67.2466L69.6249 80.993L83.3713 73.0565L75.4348 59.3101ZM89.1821 51.3734L75.4356 59.3099L83.3721 73.0564L97.1186 65.1199L89.1821 51.3734Z"
135 fill="white"/>
136 <path
137 d="M89.182 51.3736C92.978 49.182 97.8319 50.4826 100.023 54.2786L103.992 61.1518L97.1185 65.12L89.182 51.3736Z"
138 fill="white"/>
139 <path
140 d="M64.593 56.4052L50.8466 64.3417L42.9101 50.5953L56.6565 42.6588L64.593 56.4052Z"
141 fill="white"/>
142 <path
143 d="M78.3397 48.4683L64.5933 56.4048L56.6568 42.6584C64.2487 38.2752 73.9565 40.8764 78.3397 48.4683Z"
144 fill="white"/>
145 <path
146 d="M50.847 64.3418L37.1006 72.2783L29.1641 58.5318L42.9105 50.5953L50.847 64.3418Z"
147 fill="white"/>
148 <path
149 d="M37.1011 72.2783C33.3051 74.4699 28.4512 73.1693 26.2596 69.3733L22.2913 62.5001L29.1646 58.5319L37.1011 72.2783Z"
150 fill="white"/>
151 </svg>
152 </span>
153 <span>Upgrade</span>
154 </a>
155 <?php else: ?>
156 <a title="Go to /wp-admin" class="fcom_inline_icon_link_item fcom_wp_admin_link"
157 href="<?php echo esc_url(admin_url()); ?>">
158 <span class="el-icon">
159 <svg viewBox="0 0 122.52 122.523"><g fill="currentColor"><path
160 d="m8.708 61.26c0 20.802 12.089 38.779 29.619 47.298l-25.069-68.686c-2.916 6.536-4.55 13.769-4.55 21.388z"/><path
161 d="m96.74 58.608c0-6.495-2.333-10.993-4.334-14.494-2.664-4.329-5.161-7.995-5.161-12.324 0-4.831 3.664-9.328 8.825-9.328.233 0 .454.029.681.042-9.35-8.566-21.807-13.796-35.489-13.796-18.36 0-34.513 9.42-43.91 23.688 1.233.037 2.395.063 3.382.063 5.497 0 14.006-.667 14.006-.667 2.833-.167 3.167 3.994.337 4.329 0 0-2.847.335-6.015.501l19.138 56.925 11.501-34.493-8.188-22.434c-2.83-.166-5.511-.501-5.511-.501-2.832-.166-2.5-4.496.332-4.329 0 0 8.679.667 13.843.667 5.496 0 14.006-.667 14.006-.667 2.835-.167 3.168 3.994.337 4.329 0 0-2.853.335-6.015.501l18.992 56.494 5.242-17.517c2.272-7.269 4.001-12.49 4.001-16.989z"/><path
162 d="m62.184 65.857-15.768 45.819c4.708 1.384 9.687 2.141 14.846 2.141 6.12 0 11.989-1.058 17.452-2.979-.141-.225-.269-.464-.374-.724z"/><path
163 d="m107.376 36.046c.226 1.674.354 3.471.354 5.404 0 5.333-.996 11.328-3.996 18.824l-16.053 46.413c15.624-9.111 26.133-26.038 26.133-45.426.001-9.137-2.333-17.729-6.438-25.215z"/><path
164 d="m61.262 0c-33.779 0-61.262 27.481-61.262 61.26 0 33.783 27.483 61.263 61.262 61.263 33.778 0 61.265-27.48 61.265-61.263-.001-33.779-27.487-61.26-61.265-61.26zm0 119.715c-32.23 0-58.453-26.223-58.453-58.455 0-32.23 26.222-58.451 58.453-58.451 32.229 0 58.45 26.221 58.45 58.451 0 32.232-26.221 58.455-58.45 58.455z"/></g></svg>
165 </span>
166 </a>
167 <?php endif; ?>
168 <a title="Portal Settings" class="fcom_inline_icon_link_item"
169 href="<?php echo esc_url(Helper::baseUrl('admin/settings')); ?>">
170 <span class="el-icon">
171 <svg viewBox="0 0 1024 1024" data-v-d2e47025=""><path fill="currentColor"
172 d="M600.704 64a32 32 0 0 1 30.464 22.208l35.2 109.376c14.784 7.232 28.928 15.36 42.432 24.512l112.384-24.192a32 32 0 0 1 34.432 15.36L944.32 364.8a32 32 0 0 1-4.032 37.504l-77.12 85.12a357.12 357.12 0 0 1 0 49.024l77.12 85.248a32 32 0 0 1 4.032 37.504l-88.704 153.6a32 32 0 0 1-34.432 15.296L708.8 803.904c-13.44 9.088-27.648 17.28-42.368 24.512l-35.264 109.376A32 32 0 0 1 600.704 960H423.296a32 32 0 0 1-30.464-22.208L357.696 828.48a351.616 351.616 0 0 1-42.56-24.64l-112.32 24.256a32 32 0 0 1-34.432-15.36L79.68 659.2a32 32 0 0 1 4.032-37.504l77.12-85.248a357.12 357.12 0 0 1 0-48.896l-77.12-85.248A32 32 0 0 1 79.68 364.8l88.704-153.6a32 32 0 0 1 34.432-15.296l112.32 24.256c13.568-9.152 27.776-17.408 42.56-24.64l35.2-109.312A32 32 0 0 1 423.232 64H600.64zm-23.424 64H446.72l-36.352 113.088-24.512 11.968a294.113 294.113 0 0 0-34.816 20.096l-22.656 15.36-116.224-25.088-65.28 113.152 79.68 88.192-1.92 27.136a293.12 293.12 0 0 0 0 40.192l1.92 27.136-79.808 88.192 65.344 113.152 116.224-25.024 22.656 15.296a294.113 294.113 0 0 0 34.816 20.096l24.512 11.968L446.72 896h130.688l36.48-113.152 24.448-11.904a288.282 288.282 0 0 0 34.752-20.096l22.592-15.296 116.288 25.024 65.28-113.152-79.744-88.192 1.92-27.136a293.12 293.12 0 0 0 0-40.256l-1.92-27.136 79.808-88.128-65.344-113.152-116.288 24.96-22.592-15.232a287.616 287.616 0 0 0-34.752-20.096l-24.448-11.904L577.344 128zM512 320a192 192 0 1 1 0 384 192 192 0 0 1 0-384m0 64a128 128 0 1 0 0 256 128 128 0 0 0 0-256"></path></svg>
173 </span>
174 <span><?php esc_html_e('Settings', 'fluent-community'); ?></span>
175 </a>
176 </div>
177 <?php
178 } else if (Utility::isCustomizationEnabled('show_powered_by')) {
179 ?>
180 <a target="_blank" rel="noopener" style="font-size: 80%; cursor: pointer;"
181 class="fcom_inline_icon_link_item" href="<?php echo esc_url(Utility::getProductUrl(true)) ?>">
182 <?php echo esc_html('Powered by FluentCommunity', 'fluent-community'); ?>
183 </a>
184 <?php
185 }
186 echo '</div>';
187 return;
188 }
189
190 if (Helper::isSiteAdmin()) {
191 add_action('fluent_community/before_header_menu_items', function () {
192 ?>
193 <li class="top_menu_item fcom_icon_link">
194 <a href="<?php echo esc_url(Helper::baseUrl('admin/settings')); ?>">
195 <span class="el-icon">
196 <svg viewBox="0 0 1024 1024" data-v-d2e47025=""><path fill="currentColor"
197 d="M600.704 64a32 32 0 0 1 30.464 22.208l35.2 109.376c14.784 7.232 28.928 15.36 42.432 24.512l112.384-24.192a32 32 0 0 1 34.432 15.36L944.32 364.8a32 32 0 0 1-4.032 37.504l-77.12 85.12a357.12 357.12 0 0 1 0 49.024l77.12 85.248a32 32 0 0 1 4.032 37.504l-88.704 153.6a32 32 0 0 1-34.432 15.296L708.8 803.904c-13.44 9.088-27.648 17.28-42.368 24.512l-35.264 109.376A32 32 0 0 1 600.704 960H423.296a32 32 0 0 1-30.464-22.208L357.696 828.48a351.616 351.616 0 0 1-42.56-24.64l-112.32 24.256a32 32 0 0 1-34.432-15.36L79.68 659.2a32 32 0 0 1 4.032-37.504l77.12-85.248a357.12 357.12 0 0 1 0-48.896l-77.12-85.248A32 32 0 0 1 79.68 364.8l88.704-153.6a32 32 0 0 1 34.432-15.296l112.32 24.256c13.568-9.152 27.776-17.408 42.56-24.64l35.2-109.312A32 32 0 0 1 423.232 64H600.64zm-23.424 64H446.72l-36.352 113.088-24.512 11.968a294.113 294.113 0 0 0-34.816 20.096l-22.656 15.36-116.224-25.088-65.28 113.152 79.68 88.192-1.92 27.136a293.12 293.12 0 0 0 0 40.192l1.92 27.136-79.808 88.192 65.344 113.152 116.224-25.024 22.656 15.296a294.113 294.113 0 0 0 34.816 20.096l24.512 11.968L446.72 896h130.688l36.48-113.152 24.448-11.904a288.282 288.282 0 0 0 34.752-20.096l22.592-15.296 116.288 25.024 65.28-113.152-79.744-88.192 1.92-27.136a293.12 293.12 0 0 0 0-40.256l-1.92-27.136 79.808-88.128-65.344-113.152-116.288 24.96-22.592-15.232a287.616 287.616 0 0 0-34.752-20.096l-24.448-11.904L577.344 128zM512 320a192 192 0 1 1 0 384 192 192 0 0 1 0-384m0 64a128 128 0 1 0 0 256 128 128 0 0 0 0-256"></path></svg>
198 </a>
199 </li>
200 <?php
201 });
202 }
203
204 echo '<div class="fcom_side_footer">';
205 $this->renderTopMenuRightItems();
206 echo '</div>';
207 });
208
209 }
210
211 public function renderTopMenuRightItems()
212 {
213 $auth_url = $this->getAuthUrl();
214 $auth = Helper::getCurrentProfile();
215 $has_color_scheme = Helper::hasColorScheme();
216 $profileLinks = $this->getProfileLinks($auth);
217 ?>
218 <ul class="fcom_user_context_menu_items">
219 <?php if ($has_color_scheme): ?>
220 <li>
221 <span class="fcom_color_mode_core">
222 <span class="fcom_color_mode_action fcom_mode_switch el-icon">
223 <svg class="show_on_light" width="20" height="20" viewBox="0 0 20 20" fill="none"
224 xmlns="http://www.w3.org/2000/svg">
225 <path
226 d="M17.9163 11.7317C16.9166 12.2654 15.7748 12.5681 14.5623 12.5681C10.6239 12.5681 7.43128 9.37543 7.43128 5.43705C7.43128 4.22456 7.73388 3.08274 8.2677 2.08301C4.72272 2.91382 2.08301 6.09562 2.08301 9.89393C2.08301 14.3246 5.67476 17.9163 10.1054 17.9163C13.9038 17.9163 17.0855 15.2767 17.9163 11.7317Z"
227 stroke="#525866" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
228 </svg>
229 <svg class="show_on_dark" width="20" height="20" viewBox="0 0 20 20" fill="none"
230 xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#clip0_2906_20675)">
231 <path
232 d="M14.1663 10.0007C14.1663 12.3018 12.3009 14.1673 9.99967 14.1673C7.69849 14.1673 5.83301 12.3018 5.83301 10.0007C5.83301 7.69946 7.69849 5.83398 9.99967 5.83398C12.3009 5.83398 14.1663 7.69946 14.1663 10.0007Z"
233 stroke="currentColor" stroke-width="1.5"/><path
234 d="M9.99984 1.66699V2.91699M9.99984 17.0837V18.3337M15.8922 15.8931L15.0083 15.0092M4.99089 4.99137L4.107 4.10749M18.3332 10.0003H17.0832M2.9165 10.0003H1.6665M15.8926 4.10758L15.0087 4.99147M4.99129 15.0093L4.10741 15.8932"
235 stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/></g><defs><clipPath
236 id="clip0_2906_20675"><rect width="20" height="20"
237 fill="correntColor"/></clipPath></defs>
238 </svg>
239 </span>
240 </span>
241 </li>
242 <?php endif; ?>
243 <li class="top_menu_item fcom_search_holder"></li>
244 <li class="top_menu_item fcom_notification_holder"></li>
245 <?php do_action('fluent_community/before_header_menu_items', $auth); ?>
246 <?php if ($auth): ?>
247 <li class="top_menu_item fcom_menu_item_user">
248 <div class="fcom_user_menu_item">
249 <div class="fcom_profile_extend">
250 <div class="fcom_profile_menu">
251 <div class="user_avatar">
252 <img alt="User Photo" src="<?php echo esc_url($auth->avatar); ?>"/>
253 <span class="avatar_icon">
254 <svg xmlns="http://www.w3.org/2000/svg" height="8" width="8"
255 viewBox="0 0 1024 1024" data-v-d2e47025="">
256 <path fill="currentColor"
257 d="M104.704 338.752a64 64 0 0 1 90.496 0l316.8 316.8 316.8-316.8a64 64 0 0 1 90.496 90.496L557.248 791.296a64 64 0 0 1-90.496 0L104.704 429.248a64 64 0 0 1 0-90.496z"></path>
258 </svg>
259 </span>
260 </div>
261 <span class="user_name">
262 <?php echo esc_html($auth->display_name); ?>
263 </span>
264 <ul class="fcom_profile_sub_menu">
265 <li class="fcom_profile_block">
266 <a href="<?php echo esc_url(Helper::baseUrl('/u/' . $auth->username)); ?>">
267 <div class="fcom_profile_avatar">
268 <img src="<?php echo esc_url($auth->avatar); ?>"
269 alt="<?php echo esc_attr($auth->display_name); ?>">
270 </div>
271 <div class="fcom_user_info">
272 <p class="fcom_user_name"><?php echo esc_html($auth->display_name); ?></p>
273 <p class="fcom_user_email"><?php echo esc_html($auth->user->user_email); ?></p>
274 </div>
275 </a>
276 </li>
277 <?php foreach ($profileLinks as $link): ?>
278 <li>
279 <?php Helper::renderLink($link, 'fcom_menu_link', ''); ?>
280 </li>
281 <?php endforeach; ?>
282 </ul>
283 </div>
284 </div>
285 </li>
286 <?php else: ?>
287 <li class="top_menu_item fcom_login_li">
288 <a class="fcom_login_btn" href="<?php echo esc_url($auth_url); ?>">
289 <span><?php esc_html_e('Login', 'fluent-community'); ?></span>
290 </a>
291 </li>
292 <?php endif; ?>
293 <?php do_action('fluent_community/after_header_right_menu_items', $auth); ?>
294 </ul>
295 <?php
296 }
297
298 protected function appVars()
299 {
300 $userModel = User::where('ID', get_current_user_id())->first();
301 $xprofile = null;
302
303 if ($userModel) {
304 $xprofile = XProfile::where('user_id', get_current_user_id())->first();
305 if (!$xprofile) {
306 $xprofile = $userModel->syncXProfile();
307 }
308 }
309
310 $authData = null;
311 $spaceSlugs = [];
312 $spaceGroups = [];
313
314 if ($userModel && $xprofile) {
315 $wpUser = get_user_by('ID', $userModel->ID);
316
317 if ($userModel->isCommunityModerator()) {
318 $userSpaces = Space::orderBy('serial', 'ASC')->get();
319 $spaceGroups = SpaceGroup::orderBy('serial', 'ASC')
320 ->select(['id', 'title', 'slug', 'settings'])
321 ->get();
322 } else {
323 $userSpaces = Space::orderBy('serial', 'ASC')
324 ->whereHas('members', function ($q) {
325 $q->where('user_id', get_current_user_id())
326 ->where('status', 'active');
327 })
328 ->get();
329
330 $userSpaceParentIds = $userSpaces->pluck('parent_id')->filter()->unique()->toArray();
331
332 $spaceGroups = SpaceGroup::orderBy('serial', 'ASC')
333 ->select(['id', 'title', 'slug', 'settings'])
334 ->whereIn('id', $userSpaceParentIds)
335 ->get();
336 }
337
338 $userSpaces->each(function ($space) use ($userModel) {
339 $userId = get_current_user_id();
340 $space->permissions = $space->getUserPermissions($userModel);
341 $space->membership = $space->getMembership($userId);
342 $space->description_rendered = FeedsHelper::mdToHtml($space->description);
343 if (!$space->membership) {
344 $space->lockscreen_config = LockscreenService::getLockscreenConfig($space, $space->membership);
345 }
346 $space->topics = Utility::getTopicsBySpaceId($space->id);
347 do_action_ref_array('fluent_community/space', [&$space]);
348 });
349
350 $userSpaces = $userSpaces->keyBy('slug');
351
352 $userModel->cacheAccessSpaces();
353
354 $spaceSlugs = $userSpaces->pluck('slug')->toArray();
355
356 $authData = [
357 'id' => $xprofile->user_id,
358 'user_id' => $xprofile->user_id,
359 'username' => $xprofile->username,
360 'display_name' => $xprofile->display_name,
361 'first_name' => $wpUser->first_name ? $wpUser->first_name : $xprofile->getFirstName(),
362 'avatar' => $xprofile->avatar,
363 'total_points' => $xprofile->total_points,
364 'last_activity' => $xprofile->last_activity,
365 'email' => $userModel->user_email,
366 'spaces' => $userSpaces,
367 'community_roles' => $userModel->getCommunityRoles(),
368 'is_verified' => $xprofile->is_verified,
369 'compilation_score' => $xprofile->getCompletionScore(),
370 'meta' => $xprofile->meta
371 ];
372 } else {
373 $authData = [
374 'id' => 0,
375 'user_id' => 0,
376 'spaces' => (object)[],
377 'community_roles' => [],
378 'compilation_score' => 100
379 ];
380 }
381
382 $settings = Helper::generalSettings();
383
384 $onboardSettings = Helper::getOnboardingSettings();
385
386 global $wp_version;
387
388 $isRtl = Helper::isRtl();
389
390 $portalVars = apply_filters('fluent_community/portal_vars', [
391 'portal_notices' => apply_filters('fluent_community/portal_notices', []),
392 'i18n' => TransStrings::getStrings(),
393 'auth' => $authData,
394 'ajaxurl' => admin_url('admin-ajax.php'),
395 'slug' => 'fluent-community',
396 'rest' => $this->getRestInfo(),
397 'user_id' => $userModel ? $userModel->ID : null,
398 'assets_url' => FLUENT_COMMUNITY_PLUGIN_URL . 'assets/',
399 'permissions' => $userModel ? $userModel->getPermissions() : ['read' => true],
400 'logo' => Arr::get($settings, 'logo'),
401 'site_title' => Arr::get($settings, 'site_title'),
402 'user_membership_slugs' => $spaceSlugs,
403 'block_editor_assets' => [
404 'scripts' => [
405 'react' => Vite::getStaticSrcUrl('libs/isolated-editor/react.production.min.js'),
406 'react-dom' => Vite::getStaticSrcUrl(
407 'libs/isolated-editor/react-dom.production.min.js'
408 ),
409 'isolated-block-editor' => Vite::getStaticSrcUrl('libs/isolated-editor/isolated-block-editor.js')
410 ],
411 'styles' => [
412 $isRtl ? Vite::getStaticSrcUrl('libs/isolated-editor/core.rtl.css') : Vite::getStaticSrcUrl('libs/isolated-editor/core.css'),
413 $isRtl ? Vite::getStaticSrcUrl('libs/isolated-editor/isolated-block-editor.rtl.css') : Vite::getStaticSrcUrl('libs/isolated-editor/isolated-block-editor.css'),
414 includes_url('css/dist/block-editor/content.min.css?ver=' . $wp_version),
415 ]
416 ],
417 'features' => [
418 'disable_global_posts' => Arr::get($settings, 'disable_global_posts', '') == 'yes',
419 'has_survey_poll' => true,
420 'is_onboarding_enabled' => Arr::get($onboardSettings, 'is_onboarding_enabled', 'no') == 'yes',
421 'can_switch_layout' => true,
422 'max_media_per_post' => apply_filters('fluent_community/max_media_per_post', 4),
423 'max_topic_per_post' => apply_filters('fluent_community/max_topic_per_post', 5),
424 'has_post_title' => Utility::postTitlePref(),
425 'has_course' => Helper::isFeatureEnabled('course_module'),
426 'skicky_sidebar' => Utility::isCustomizationEnabled('fixed_sidebar'),
427 'post_layout' => Utility::getCustomizationSetting('rich_post_layout'),
428 'video_embeder' => apply_filters('fluent_community/has_video_embeder', true),
429 'has_topics' => !!Utility::getTopics()
430 ],
431 'route_classes' => array_filter([
432 'fcom_sticky_header' => Utility::isCustomizationEnabled('fixed_page_header'),
433 'fcom_sticky_sidebar' => Utility::isCustomizationEnabled('fixed_sidebar'),
434 'fcom_has_icon_on_header_menu' => Utility::isCustomizationEnabled('icon_on_header_menu')
435 ]),
436 'urls' => [
437 'site_url' => site_url(),
438 'portal_base' => Helper::baseUrl('/'),
439 'global_search' => Helper::baseUrl(),
440 ],
441 'last_feed_id' => FeedsHelper::getLastFeedId(),
442 'unread_notification_count' => $userModel ? $userModel->getUnreadNotificationCount() : 0,
443 'unread_feed_ids' => $userModel ? $userModel->getUnreadNotificationFeedIds() : [],
444 'date_offset' => time() - current_time('timestamp'),
445 'portal_slug' => Helper::getPortalSlug(true),
446 'mobileMenuItems' => apply_filters('fluent_community/mobile_menu', [
447 [
448 'route' => [
449 'name' => 'all_feeds'
450 ],
451 'icon_svg' => '<svg width="20" height="18" viewBox="0 0 20 18" fill="none"><path fill-rule="evenodd" clip-rule="evenodd" d="M10 13.166H10.0075H10Z" fill="currentColor"></path><path d="M10 13.166H10.0075" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path><path d="M16.6666 6.08301V10.2497C16.6666 13.3924 16.6666 14.9637 15.6903 15.94C14.714 16.9163 13.1426 16.9163 9.99992 16.9163C6.85722 16.9163 5.28587 16.9163 4.30956 15.94C3.33325 14.9637 3.33325 13.3924 3.33325 10.2497V6.08301" stroke="currentColor" stroke-width="1.5"></path><path d="M18.3333 7.74967L14.714 4.27925C12.4918 2.14842 11.3807 1.08301 9.99996 1.08301C8.61925 1.08301 7.50814 2.14842 5.28592 4.27924L1.66663 7.74967" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"></path></svg>'
452 ],
453 [
454 'route' => [
455 'name' => 'spaces'
456 ],
457 'icon_svg' => '<svg version="1.1" viewBox="0 0 128 128" xml:space="preserve"><g><path d="M64,42c-13.2,0-24,10.8-24,24s10.8,24,24,24s24-10.8,24-24S77.2,42,64,42z M64,82c-8.8,0-16-7.2-16-16s7.2-16,16-16 s16,7.2,16,16S72.8,82,64,82z"></path><path d="M64,100.8c-14.9,0-29.2,6.2-39.4,17.1l-2.7,2.9l5.8,5.5l2.7-2.9c8.8-9.4,20.7-14.6,33.6-14.6s24.8,5.2,33.6,14.6l2.7,2.9 l5.8-5.5l-2.7-2.9C93.2,107.1,78.9,100.8,64,100.8z"></path><path d="M97,47.9v8c9.4,0,18.1,3.8,24.6,10.7l5.8-5.5C119.6,52.7,108.5,47.9,97,47.9z"></path><path d="M116.1,20c0-10.5-8.6-19.1-19.1-19.1S77.9,9.5,77.9,20S86.5,39.1,97,39.1S116.1,30.5,116.1,20z M85.9,20 c0-6.1,5-11.1,11.1-11.1s11.1,5,11.1,11.1s-5,11.1-11.1,11.1S85.9,26.1,85.9,20z"></path><path d="M31,47.9c-11.5,0-22.6,4.8-30.4,13.2l5.8,5.5c6.4-6.9,15.2-10.7,24.6-10.7V47.9z"></path><path d="M50.1,20C50.1,9.5,41.5,0.9,31,0.9S11.9,9.5,11.9,20S20.5,39.1,31,39.1S50.1,30.5,50.1,20z M31,31.1 c-6.1,0-11.1-5-11.1-11.1S24.9,8.9,31,8.9s11.1,5,11.1,11.1S37.1,31.1,31,31.1z"></path></g></svg>'
458 ]
459 ]),
460 'socialLinkProviders' => ProfileHelper::socialLinkProviders(),
461 'space_groups' => $spaceGroups,
462 'feed_links' => Helper::getEnabledFeedLinks(),
463 'routing_system' => Helper::getPortalRouteType(),
464 'portal_url' => Helper::baseUrl('/'),
465 'upgrade_url' => 'https://fluentcommunity.co/?utm_source=wp&utm_medium=upgrade&utm_campaign=upgrade',
466 'dateTime18n' => apply_filters('fluent_community/date_time_i18n', [
467 /* translators: weekday. Please keep the serial and format */
468 'weekdays' => __('Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday', 'fluent-community'),
469 /* translators: Months Please keep the serial and format*/
470 'months' => __('January_February_March_April_May_June_July_August_September_October_November_December', 'fluent-community'),
471 /* translators: weekday short Please keep the serial and format*/
472 'weekdaysShort' => __('Sun_Mon_Tue_Wed_Thu_Fri_Sat', 'fluent-community'),
473 /* translators: Months short Please keep the serial and format*/
474 'monthsShort' => __('Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec', 'fluent-community'),
475 /* translators: weekday min Please keep the serial and format*/
476 'weekdaysMin' => __('Su_Mo_Tu_We_Th_Fr_Sa', 'fluent-community'),
477 'relativeTime' => [
478 /* translators: Relative Date Formats. Please do not alter %s*/
479 'future' => __('in %s', 'fluent-community'),
480 /* translators: Relative Date Formats. Please do not alter %s*/
481 'past' => __('%s ago', 'fluent-community'),
482 /* translators: Relative Date Formats.*/
483 's' => __('a few seconds', 'fluent-community'),
484 /* translators: Relative Date Formats.*/
485 'm' => __('a minute', 'fluent-community'),
486 /* translators: Relative Date Formats. Don't alter %d*/
487 'mm' => __('%d minutes', 'fluent-community'),
488 /* translators: Relative Date Formats*/
489 'h' => __('an hour', 'fluent-community'),
490 /* translators: Relative Date Formats. Don't alter %d*/
491 'hh' => __('%d hours', 'fluent-community'),
492 /* translators: Relative Date Formats*/
493 'd' => __('a day', 'fluent-community'),
494 /* translators: Relative Date Formats. Don't alter %d*/
495 'dd' => __('%d days', 'fluent-community'),
496 /* translators: Relative Date Formats*/
497 'M' => __('a month', 'fluent-community'),
498 /* translators: Relative Date Formats. Don't alter %d*/
499 'MM' => __('%d months', 'fluent-community'),
500 /* translators: Relative Date Formats*/
501 'y' => __('a year', 'fluent-community'),
502 /* translators: Relative Date Formats. Don't alter %d*/
503 'yy' => __('%d years', 'fluent-community')
504 ]
505 ])
506 ]);
507
508 if ($xprofile) {
509 $portalVars['mobileMenuItems'][] = [
510 'route' => [
511 'name' => 'user_profile',
512 'params' => [
513 'username' => $xprofile->username
514 ]
515 ],
516 'icon' => 'Avatar'
517 ];
518 }
519
520 $portalVars['welcome_banner'] = Helper::getWelcomeBanner($userModel ? 'login' : 'logout');
521
522 if (!$xprofile) {
523 $portalVars['auth_url'] = $this->getAuthUrl();
524 }
525
526 return $portalVars;
527 }
528
529 protected function getRestInfo()
530 {
531 $app = fluentCommunityApp();
532 $ns = $app->config->get('app.rest_namespace');
533 $v = $app->config->get('app.rest_version');
534
535 return [
536 'base_url' => esc_url_raw(rest_url()),
537 'url' => rest_url($ns . '/' . $v),
538 'nonce' => wp_create_nonce('wp_rest'),
539 'namespace' => $ns,
540 'version' => $v,
541 ];
542 }
543
544 protected function renderFullApp()
545 {
546 if (isset($_REQUEST['fcom_action'])) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
547 $action = sanitize_text_field(wp_unslash($_REQUEST['fcom_action'])); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
548 do_action('fluent_community/portal_action_' . $action, $_GET); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
549 }
550
551 $userId = get_current_user_id();
552
553 if (!$userId) {
554 if (!Helper::isPublicAccessible()) {
555 $url = home_url(add_query_arg($_REQUEST, $GLOBALS['wp']->request)); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
556 $settings = Helper::generalSettings();
557 $authUrl = Arr::get($settings, 'auth_url', '');
558 if ($authUrl) {
559 $authUrl = add_query_arg([
560 'redirect_to' => $url
561 ], $authUrl);
562 } else {
563 $authUrl = $this->getAuthUrl();
564 }
565
566 do_action('fluent_community/portal/not_logged_in', $authUrl);
567 wp_redirect($authUrl);
568 exit();
569 }
570 }
571
572 do_action('fluent_community/portal/viewed');
573 $xprofile = Helper::getCurrentProfile();
574
575 if ($xprofile && $xprofile->status != 'active') {
576 if ($xprofile->status == 'pending') {
577 $this->viewErrorPage('You request is on pending', 'An admin need to approve your join request. Please contact with an admin to get approval');
578 } else {
579 $this->viewErrorPage('Access denied', 'Sorry, You can not access to this portal');
580 }
581 }
582
583 if ($xprofile) {
584 if (!Helper::canAccessPortal()) {
585 $generalSettings = Helper::generalSettings();
586 $this->viewErrorPage('Access Denied', Arr::get($generalSettings, 'restricted_role_content'));
587 }
588 if ($xprofile->user) {
589 $xprofile->user->cacheAccessSpaces();
590 }
591
592 /*
593 * Just in case if username is not sanitized
594 */
595 if ($xprofile->username != CustomSanitizer::sanitizeUserName($xprofile->username)) {
596 $xprofile->username = ProfileHelper::generateUserName($xprofile->user_id);
597 $xprofile->save();
598 }
599
600 do_action('fluent_community/portal_render_for_user', $xprofile);
601 do_action('fluent_communit/track_activity');
602 }
603
604 $data = $this->getAppData();
605 $data = $this->maybePushDynamicMetaData($data);
606
607 $data['isHeadless'] = Helper::isHeadless();
608 $data['a11y_enhancement_style'] = Utility::getCustomizationSetting('a11y_enhancement_style') === 'yes';
609
610 if (!$data['isHeadless']) {
611 $this->loadClassicPortalAssets($data);
612 } else {
613 do_action('fluent_community/rendering_headless_portal', $data);
614 }
615
616 status_header(200);
617 App::make('view')->render('portal_page', $data);
618 exit(200);
619 }
620
621 public function loadClassicPortalAssets($data)
622 {
623 $cssFiles = $data['css_files'];
624
625 unset($cssFiles['fcom_theme_default']);
626
627 foreach ($cssFiles as $fileName => $cssFile) {
628 wp_enqueue_style($fileName, $cssFile['url'], [], FLUENT_COMMUNITY_PLUGIN_VERSION, 'screen');
629 }
630
631 $jsFiles = $data['js_files'];
632 $jsTags = array_keys($jsFiles);
633 add_filter('script_loader_tag', function ($tag, $handle) use ($jsTags) {
634 if (!in_array($handle, $jsTags)) {
635 return $tag;
636 }
637 $tag = str_replace(' src', ' type="module" src', $tag);
638 return $tag;
639 }, 10, 2);
640 foreach ($jsFiles as $fileName => $jsFile) {
641 wp_enqueue_script($fileName, $jsFile['url'], $jsFile['deps'], FLUENT_COMMUNITY_PLUGIN_VERSION, [
642 'in_footer' => true,
643 'strategy' => 'defer',
644 'type' => 'module'
645 ]);
646 }
647
648 foreach ($data['js_vars'] as $varKey => $values) {
649 wp_localize_script('fcom_strat', $varKey, $values);
650 }
651 }
652
653 public function getAppData()
654 {
655
656 $isRtl = Helper::isRtl();
657
658 $userId = get_current_user_id();
659 $url = home_url(add_query_arg($_REQUEST, $GLOBALS['wp']->request)); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
660
661 $appVars = $this->appVars();
662 $generalSettings = Helper::generalSettings();
663 return apply_filters('fluent_community/portal_data_vars', [
664 'title' => Arr::get($generalSettings, 'site_title'),
665 'description' => get_bloginfo('description'),
666 'featured_image' => Arr::get($generalSettings, 'featured_image', ''),
667 'js_files' => [
668 'fcom_strat' => [
669 'url' => Vite::getStaticSrcUrl('start.js'),
670 'deps' => []
671 ],
672 'fcom_app' => [
673 'url' => Vite::getStaticSrcUrl('app.js'),
674 'deps' => []
675 ],
676 'fcom_general' => [
677 'url' => Vite::getStaticSrcUrl('portal_general.js'),
678 'deps' => []
679 ]
680 ],
681 'js_vars' => [
682 'fluentComAdmin' => $appVars,
683 ],
684 'css_files' => array_filter([
685 'fcom_theme_default' => [
686 'url' => Vite::getDynamicSrcUrl('theme-default.scss', $isRtl)
687 ],
688 'fcom_global' => [
689 'url' => Vite::getDynamicSrcUrl('global.scss', $isRtl)
690 ],
691 'fcom_app' => [
692 'url' => Vite::getDynamicSrcUrl('app_css.scss', $isRtl)
693 ],
694 'fcom_vendor' => [
695 'url' => Vite::getDynamicProductionSrcUrl('app.css', $isRtl) // vite automatically build src/app.css for all components also styles inside components
696 ]
697 ]),
698 'url' => $url,
699 'current_route' => $this->currentPath,
700 'contact' => $appVars['auth'],
701 'user' => $userId ? get_user_by('ID', $userId) : null,
702 'route_group' => Helper::getRouteNameByRequestPath($this->currentPath)
703 ]);
704 }
705
706 protected function maybePushDynamicMetaData($data)
707 {
708 $dynamicRoute = Arr::get($data, 'route_group');
709 $validGroups = [
710 'user_profile',
711 'community_view',
712 'course_view',
713 'feed_view'
714 ];
715
716 if (!in_array($dynamicRoute, $validGroups)) {
717 return $data;
718 }
719
720 if ($dynamicRoute == 'user_profile') {
721 $uriParts = explode('/', $this->currentPath);
722 if (count($uriParts) >= 2) {
723 $userName = $uriParts[1];
724 $xProfile = XProfile::where('username', $userName)->first();
725 if ($xProfile) {
726 $data['title'] = esc_html($xProfile->display_name) . ' - ' . $data['title'];
727 if ($xProfile->short_description) {
728 $data['description'] = Helper::getHumanExcerpt($xProfile->short_description, 100);
729 }
730 if ($coverPhoto = Arr::get($xProfile->meta, 'cover_photo')) {
731 $data['featured_image'] = $coverPhoto;
732 }
733 }
734 }
735 return $data;
736 }
737
738 if ($dynamicRoute == 'community_view' || $dynamicRoute == 'course_view') {
739 $uriParts = explode('/', $this->currentPath);
740 if (count($uriParts) >= 2) {
741 $paceSlug = $uriParts[1];
742
743 $space = BaseSpace::query()->withoutGlobalScopes()->where('slug', $paceSlug)->first();
744
745 if ($space && $space->privacy != 'secret') {
746
747 if ($dynamicRoute == 'course_view') {
748 $data['title'] = sprintf(__('Enroll %s', 'fluent-community'), esc_html($space->title) . ' - ' . $data['title']);
749 } else {
750 $data['title'] = sprintf(__('Join %s', 'fluent-community'), esc_html($space->title) . ' - ' . $data['title']);
751 }
752
753 if ($space->description) {
754 $data['description'] = Helper::getHumanExcerpt($space->description, 100);
755 }
756 if ($ogImage = Arr::get($space->settings, 'og_image')) {
757 $data['featured_image'] = $ogImage;
758 } else if ($space->cover_photo) {
759 $data['featured_image'] = $space->cover_photo;
760 }
761 }
762 }
763 return $data;
764 }
765
766 if ($dynamicRoute == 'feed_view') {
767 $uriParts = explode('/', $this->currentPath);
768
769 if (count($uriParts) >= 2) {
770 $postSlug = end($uriParts);
771 $feed = Feed::where('slug', $postSlug)
772 ->with([
773 'xprofile' => function ($q) {
774 $q->select(ProfileHelper::getXProfilePublicFields());
775 },
776 'space'
777 ])
778 ->byUserAccess(get_current_user_id())
779 ->first();
780
781 if (!$feed) {
782 return $data;
783 }
784
785 if ($feed->title) {
786 $data['title'] = esc_html($feed->title) . ' - ' . $data['title'];
787 } else {
788 $data['title'] = esc_html($feed->xprofile->display_name) . ' posted at ' . $data['title'];
789 }
790
791 if ($feed->message) {
792 $data['description'] = esc_html(Helper::getHumanExcerpt($feed->message, 100));
793 }
794
795 if ($mediaPreview = Arr::get($feed->meta, 'media_preview.image')) {
796 $data['featured_image'] = esc_url($mediaPreview);
797 } else if ($feed->space) {
798 $space = $feed->space;
799 if ($ogImage = Arr::get($space->settings, 'og_image')) {
800 $data['featured_image'] = $ogImage;
801 } else if ($space->cover_photo) {
802 $data['featured_image'] = $space->cover_photo;
803 }
804 }
805 }
806
807 return $data;
808 }
809
810 return $data;
811 }
812
813 protected function getMainMenuItems($scope = 'sidebar')
814 {
815 $menuGroups = Helper::getMenuItemsGroup('view');
816
817 $items = Arr::get($menuGroups, 'mainMenuItems', []);
818
819 return apply_filters('fluent_community/main_menu_items', $items, $scope);
820 }
821
822 public function getPortalHeader($echo = false, $context = 'headless')
823 {
824 $settings = Helper::generalSettings();
825 $userId = get_current_user_id();
826
827 if ($userId) {
828 $xprofile = XProfile::where('user_id', get_current_user_id())
829 ->first();
830 } else {
831 $xprofile = null;
832 }
833
834
835 $authUrl = $this->getAuthUrl();
836
837 if ($xprofile) {
838 $xprofile->logout_url = wp_logout_url(Helper::baseUrl());
839 }
840
841 $logo = Arr::get($settings, 'logo', '');
842 $whiteLogo = Arr::get($settings, 'white_logo', '');
843 if (!$whiteLogo) {
844 $whiteLogo = $logo;
845 }
846
847 $data = apply_filters('fluent_community/header_vars', [
848 'portal_url' => Helper::baseUrl('/'),
849 'logo' => $logo,
850 'white_logo' => $whiteLogo,
851 'site_title' => Arr::get($settings, 'site_title'),
852 'profile_url' => $userId ? Helper::baseUrl('u/' . $xprofile->username . '/') : '',
853 'auth' => $xprofile ? $xprofile : null,
854 'auth_url' => $authUrl,
855 'menuItems' => $this->getMainMenuItems('header')
856 ]);
857
858 if ($echo) {
859 App::make('view')->render('portal.header', $data);
860 return;
861 }
862
863 return (string)App::make('view')->make('portal.header', $data);
864 }
865
866 private function getProfileLinks($xprofile = null)
867 {
868 if (!$xprofile) {
869 $xprofile = Helper::getCurrentProfile();
870 }
871
872 $profileLinks = [];
873 $menuGroups = Helper::getMenuItemsGroup('view');
874 if ($xprofile) {
875 $profileLinks = Arr::get($menuGroups, 'profileDropdownItems', []);
876
877 $replaces = [
878 '#{{user_url}}' => Helper::baseUrl('u/' . $xprofile->username),
879 '#user_url' => Helper::baseUrl('u/' . $xprofile->username),
880 '#{{logout_url}}' => wp_logout_url(Helper::baseUrl()),
881 '#logout_url' => wp_logout_url(Helper::baseUrl())
882 ];
883
884 foreach ($profileLinks as &$link) {
885 $slug = Arr::get($link, 'slug', '');
886
887 if ($slug == 'my_spaces') {
888 $link['permalink'] = Helper::baseUrl('u/' . $xprofile->username . '/spaces');
889 } else if ($slug == 'logout') {
890 $link['permalink'] = wp_logout_url(Helper::baseUrl());
891 } else if ($slug == 'profile') {
892 $link['permalink'] = Helper::baseUrl('u/' . $xprofile->username);
893 }
894
895 $link['permalink'] = str_replace(array_keys($replaces), array_values($replaces), $link['permalink']);
896 }
897 }
898
899 return $profileLinks;
900 }
901
902 public function getPortalSidebar($echo = false, $context = 'headless')
903 {
904 $primaryMenuItems = $this->getMainMenuItems('sidebar');
905
906 $userModel = Helper::getCurrentUser();
907 $spaceGroups = Helper::getCommunityMenuGroups($userModel);
908
909 $settingsMenu = apply_filters('fluent_community/settings_menu', [], $userModel);
910
911 $menuGroups = Helper::getMenuItemsGroup('view');
912 $topInlines = Arr::get($menuGroups, 'beforeCommunityMenuItems', []);
913 $bottomLinkGroups = Arr::get($menuGroups, 'afterCommunityLinkGroups', []);
914
915 $data = [
916 'primaryItems' => $primaryMenuItems,
917 'spaceGroups' => $spaceGroups,
918 'settingsItems' => $settingsMenu,
919 'topInlineLinks' => $topInlines,
920 'bottomLinkGroups' => $bottomLinkGroups,
921 'is_admin' => Helper::isSiteAdmin(),
922 'has_color_scheme' => Helper::hasColorScheme(),
923 'context' => $context
924 ];
925
926 if ($echo) {
927 App::make('view')->render('portal.main_sidebar', $data);
928 return;
929 }
930
931 return (string)App::make('view')->make('portal.main_sidebar', $data);
932 }
933
934 protected function getAuthUrl()
935 {
936 return apply_filters('fluent_community/auth/login_url', Helper::baseUrl('?fcom_action=auth&form=login'));
937 }
938
939 protected function viewErrorPage($title, $message = '', $showBtn = true)
940 {
941 $data = [
942 'title' => $title,
943 'description' => $message,
944 'btn_txt' => 'Go to home page',
945 'url' => site_url()
946 ];
947
948 if (!$showBtn) {
949 $data['btn_txt'] = '';
950 }
951
952 status_header(200);
953 App::make('view')->render('error_page', $data);
954 exit();
955 }
956
957 public function showAdminPage()
958 {
959
960 $jsTags = ['fluent_community_onboarding'];
961
962 add_filter('script_loader_tag', function ($tag, $handle) use ($jsTags) {
963 if (!in_array($handle, $jsTags)) {
964 return $tag;
965 }
966 $tag = str_replace(' src', ' type="module" src', $tag);
967 return $tag;
968 }, 10, 2);
969
970 wp_enqueue_script('fluent_community_onboarding', Vite::getDynamicSrcUrl('Onboarding/onboarding.js'), ['jquery'], FLUENT_COMMUNITY_PLUGIN_VERSION, [
971 'in_footer' => true,
972 'strategy' => 'defer',
973 'type' => 'module'
974 ]);
975
976 wp_enqueue_style('fluent_community_onboarding', Vite::getDynamicSrcUrl('Onboarding/onboarding.scss'), [], FLUENT_COMMUNITY_PLUGIN_VERSION, 'screen');
977 wp_localize_script('fluent_community_onboarding', 'fluentComAdmin', [
978 'ajaxurl' => admin_url('admin-ajax.php'),
979 'rest' => $this->getRestInfo(),
980 'urls' => [
981 'site_url' => site_url('/'),
982 'portal_base' => Helper::baseUrl('/'),
983 'permalink_url' => admin_url('options-permalink.php')
984 ],
985 'logo' => Helper::assetUrl('images/logo.png'),
986 'is_onboarded' => !!Utility::getOption('onboarding_sub_settings'),
987 'permalink_structure' => get_option('permalink_structure'),
988 'is_slug_defined' => defined('FLUENT_COMMUNITY_PORTAL_SLUG'),
989 'has_pro' => defined('FLUENT_COMMUNITY_PRO_VERSION'),
990 'upgrade_url' => Utility::getProductUrl(false),
991 'settings_page_url' => admin_url('admin.php?page=fluent-community'),
992 'is_license_page' => isset($_GET['license']) && $_GET['license'] === 'yes',
993 'license_url_page' => defined('FLUENT_COMMUNITY_PRO_VERSION') ? admin_url('admin.php?page=fluent-community&license=yes') : '',
994 ]);
995
996 echo '<div class="wrap"><div id="fcom_onboarding_app"></div></div>';
997 }
998
999 private function getMenuIcon()
1000 {
1001 return 'data:image/svg+xml;base64,' . base64_encode('<svg width="82" height="71" viewBox="0 0 82 71" fill="none" xmlns="http://www.w3.org/2000/svg">
1002 <path d="M25.9424 49.1832L39.6888 41.2467L47.6253 54.9931C40.0334 59.3763 30.3256 56.7751 25.9424 49.1832Z" fill="white"/>
1003 <path fill-rule="evenodd" clip-rule="evenodd" d="M53.4348 33.3101L39.6884 41.2466L47.6249 54.993L61.3713 47.0565L53.4348 33.3101ZM67.1821 25.3734L53.4356 33.3099L61.3721 47.0564L75.1186 39.1199L67.1821 25.3734Z" fill="white"/>
1004 <path d="M67.182 25.3736C70.978 23.182 75.8319 24.4826 78.0235 28.2786L81.9917 35.1518L75.1185 39.12L67.182 25.3736Z" fill="white"/>
1005 <path d="M42.593 30.4052L28.8466 38.3417L20.9101 24.5953L34.6565 16.6588L42.593 30.4052Z" fill="white"/>
1006 <path d="M56.3397 22.4683L42.5933 30.4048L34.6568 16.6584C42.2487 12.2752 51.9565 14.8764 56.3397 22.4683Z" fill="white"/>
1007 <path d="M28.847 38.3418L15.1006 46.2783L7.16409 32.5318L20.9105 24.5953L28.847 38.3418Z" fill="white"/>
1008 <path d="M15.1011 46.2783C11.3051 48.4699 6.4512 47.1693 4.25959 43.3733L0.291343 36.5001L7.16456 32.5319L15.1011 46.2783Z" fill="white"/>
1009 </svg>');
1010
1011 }
1012
1013 }
1014