PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 1.0.96
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v1.0.96
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.96, at app/Hooks/Handlers/PortalHandler.php

1,048 lines 54.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 use FluentCommunity\Modules\Auth\AuthHelper;
22
23 class PortalHandler
24 {
25 protected $currentPath = '';
26
27 protected $slug = null;
28
29 public function register()
30 {
31 /**
32 * Register the portal route
33 */
34 add_action('init', function () {
35 $this->slug = Helper::getPortalSlug();
36 if ($this->slug !== '') {
37 add_rewrite_rule('^' . $this->slug . '/?$', 'index.php?fcom_route=portal_home', 'top'); // For /hooks
38 add_rewrite_rule('^' . $this->slug . '/(.+)/?', 'index.php?fcom_route=$matches[1]', 'top');
39 }
40 });
41
42 add_filter('query_vars', function ($vars) {
43 $vars[] = 'fcom_route';
44 return $vars;
45 });
46
47 add_action('template_redirect', function () {
48 $hook_path = get_query_var('fcom_route');
49 if ($hook_path) {
50 $this->currentPath = $hook_path;
51 $this->renderFullApp();
52 }
53
54 if ($this->slug === '') {
55 global $wp;
56 $currentRequest = $wp->request;
57 if ($hookPath = Helper::getPortalRequestPath($currentRequest)) {
58 $this->currentPath = $hookPath;
59 $this->renderFullApp();
60 }
61 }
62 }, 1);
63
64 add_action('fluent_community/portal_html', function () {
65 App::make('view')->render('portal.portal');
66 });
67
68 add_action('fluent_community/portal_header', function ($context) {
69 $this->getPortalHeader(true, $context);
70 });
71
72 add_action('fluent_community/portal_sidebar', function ($context) {
73 $this->getPortalSidebar(true, $context);
74 });
75
76 // add a link to admin menu which will redirect to /portal
77 add_action('admin_menu', function () {
78 add_menu_page(
79 __('FluentCommunity', 'fluent-community'),
80 __('FluentCommunity', 'fluent-community'),
81 'edit_posts',
82 'fluent-community',
83 [$this, 'showAdminPage'],
84 $this->getMenuIcon(),
85 130
86 );
87 });
88
89 add_action('fluent_community/enqueue_global_assets', function ($useDefaultTheme = true) {
90 wp_enqueue_style('fluent_community_global', Vite::getDynamicSrcUrl('global.scss'), [], time(), 'screen');
91 if ($useDefaultTheme) {
92 wp_enqueue_style('fluent_community_default_theme', Vite::getDynamicSrcUrl('theme-default.scss'), [], FLUENT_COMMUNITY_PLUGIN_VERSION, 'screen');
93 }
94
95 wp_enqueue_script('portal_general', Vite::getStaticSrcUrl('portal_general.js'), [], FLUENT_COMMUNITY_PLUGIN_VERSION, true);
96
97 wp_localize_script('portal_general', 'fcom_portal_general', [
98 'is_wp' => true
99 ]);
100 });
101
102 add_action('admin_bar_menu', function ($wp_admin_bar) {
103 if (!\FluentCommunity\App\Services\Helper::canAccessPortal()) {
104 return;
105 }
106
107 // Add custom link within site name dropdown
108 $wp_admin_bar->add_node(array(
109 'id' => 'fluent-community-link',
110 'title' => __('Visit Community Portal', 'fluent-community'),
111 'href' => \FluentCommunity\App\Services\Helper::baseUrl('/'),
112 'parent' => 'site-name'
113 ));
114 }, 99);
115
116 add_action('fluent_community/top_menu_right_items', [$this, 'renderTopMenuRightItems']);
117
118 add_action('fluent_community/after_portal_sidebar', function () {
119
120 if (did_action('fluent_community/after_header_right_menu_items')) {
121 echo '<div role="region" aria-label="Portal Settings" class="fcom_side_footer">';
122 if (Helper::isSiteAdmin()) {
123 ?>
124 <div style="display: flex;justify-content: space-between;" class="fcom_admin_menu">
125 <?php if (!defined('FLUENT_COMMUNITY_PRO')): ?>
126 <a title="Upgrade to Pro" target="_blank" rel="noopener" class="fcom_inline_icon_link_item"
127 href="<?php echo esc_url(Utility::getProductUrl(true)) ?>">
128 <span class="el-icon">
129 <svg width="126" height="125" viewBox="0 0 126 125" fill="none">
130 <rect x="0.22139" width="125" height="125" rx="17.8571" fill="#4A5FE0"/>
131 <path
132 d="M47.9424 75.1832L61.6888 67.2467L69.6253 80.9931C62.0334 85.3763 52.3256 82.7751 47.9424 75.1832Z"
133 fill="white"/>
134 <path fill-rule="evenodd" clip-rule="evenodd"
135 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"
136 fill="white"/>
137 <path
138 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"
139 fill="white"/>
140 <path
141 d="M64.593 56.4052L50.8466 64.3417L42.9101 50.5953L56.6565 42.6588L64.593 56.4052Z"
142 fill="white"/>
143 <path
144 d="M78.3397 48.4683L64.5933 56.4048L56.6568 42.6584C64.2487 38.2752 73.9565 40.8764 78.3397 48.4683Z"
145 fill="white"/>
146 <path
147 d="M50.847 64.3418L37.1006 72.2783L29.1641 58.5318L42.9105 50.5953L50.847 64.3418Z"
148 fill="white"/>
149 <path
150 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"
151 fill="white"/>
152 </svg>
153 </span>
154 <span>Upgrade</span>
155 </a>
156 <?php else: ?>
157 <a title="Go to /wp-admin" class="fcom_inline_icon_link_item fcom_wp_admin_link"
158 href="<?php echo esc_url(admin_url()); ?>">
159 <span class="el-icon">
160 <svg viewBox="0 0 122.52 122.523"><g fill="currentColor"><path
161 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
162 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
163 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
164 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
165 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>
166 </span>
167 </a>
168 <?php endif; ?>
169 <a title="Portal Settings" class="fcom_inline_icon_link_item"
170 href="<?php echo esc_url(Helper::baseUrl('admin/settings')); ?>">
171 <span class="el-icon">
172 <svg viewBox="0 0 1024 1024" data-v-d2e47025=""><path fill="currentColor"
173 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>
174 </span>
175 <span><?php esc_html_e('Settings', 'fluent-community'); ?></span>
176 </a>
177 </div>
178 <?php
179 } else if (Utility::isCustomizationEnabled('show_powered_by')) {
180 ?>
181 <a target="_blank" rel="noopener" style="font-size: 80%; cursor: pointer;"
182 class="fcom_inline_icon_link_item" href="<?php echo esc_url(Utility::getProductUrl(true)) ?>">
183 <?php echo esc_html('Powered by FluentCommunity', 'fluent-community'); ?>
184 </a>
185 <?php
186 }
187 echo '</div>';
188 return;
189 }
190
191 if (Helper::isSiteAdmin()) {
192 add_action('fluent_community/before_header_menu_items', function () {
193 ?>
194 <li class="top_menu_item fcom_icon_link">
195 <a href="<?php echo esc_url(Helper::baseUrl('admin/settings')); ?>">
196 <span class="el-icon">
197 <svg viewBox="0 0 1024 1024" data-v-d2e47025=""><path fill="currentColor"
198 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>
199 </a>
200 </li>
201 <?php
202 });
203 }
204
205 echo '<div class="fcom_side_footer">';
206 $this->renderTopMenuRightItems();
207 echo '</div>';
208 });
209
210 }
211
212 public function renderTopMenuRightItems()
213 {
214 $auth_url = $this->getAuthUrl();
215 $auth = Helper::getCurrentProfile();
216 $has_color_scheme = Helper::hasColorScheme();
217 $profileLinks = $this->getProfileLinks($auth);
218 ?>
219 <ul class="fcom_user_context_menu_items">
220 <?php if ($has_color_scheme): ?>
221 <li>
222 <span class="fcom_color_mode_core">
223 <span class="fcom_color_mode_action fcom_mode_switch el-icon">
224 <svg class="show_on_light" width="20" height="20" viewBox="0 0 20 20" fill="none"
225 xmlns="http://www.w3.org/2000/svg">
226 <path
227 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"
228 stroke="#525866" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
229 </svg>
230 <svg class="show_on_dark" width="20" height="20" viewBox="0 0 20 20" fill="none"
231 xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#clip0_2906_20675)">
232 <path
233 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"
234 stroke="currentColor" stroke-width="1.5"/><path
235 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"
236 stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/></g><defs><clipPath
237 id="clip0_2906_20675"><rect width="20" height="20"
238 fill="correntColor"/></clipPath></defs>
239 </svg>
240 </span>
241 </span>
242 </li>
243 <?php endif; ?>
244 <li class="top_menu_item fcom_search_holder"></li>
245 <li class="top_menu_item fcom_notification_holder"></li>
246 <?php do_action('fluent_community/before_header_menu_items', $auth); ?>
247 <?php if ($auth): ?>
248 <li class="top_menu_item fcom_menu_item_user">
249 <div class="fcom_user_menu_item">
250 <div class="fcom_profile_extend">
251 <div class="fcom_profile_menu">
252 <div class="user_avatar">
253 <img alt="User Photo" src="<?php echo esc_url($auth->avatar); ?>"/>
254 <span class="avatar_icon">
255 <svg xmlns="http://www.w3.org/2000/svg" height="8" width="8"
256 viewBox="0 0 1024 1024" data-v-d2e47025="">
257 <path fill="currentColor"
258 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>
259 </svg>
260 </span>
261 </div>
262 <span class="user_name">
263 <?php echo esc_html($auth->display_name); ?>
264 </span>
265 <ul class="fcom_profile_sub_menu">
266 <li class="fcom_profile_block">
267 <a href="<?php echo esc_url(Helper::baseUrl('/u/' . $auth->username)); ?>">
268 <div class="fcom_profile_avatar">
269 <img src="<?php echo esc_url($auth->avatar); ?>"
270 alt="<?php echo esc_attr($auth->display_name); ?>">
271 </div>
272 <div class="fcom_user_info">
273 <p class="fcom_user_name"><?php echo esc_html($auth->display_name); ?></p>
274 <p class="fcom_user_email"><?php echo esc_html($auth->user->user_email); ?></p>
275 </div>
276 </a>
277 </li>
278 <?php foreach ($profileLinks as $link): ?>
279 <li>
280 <?php Helper::renderLink($link, 'fcom_menu_link', ''); ?>
281 </li>
282 <?php endforeach; ?>
283 </ul>
284 </div>
285 </div>
286 </li>
287 <?php else: ?>
288 <li class="top_menu_item fcom_login_li">
289 <a class="fcom_login_btn" href="<?php echo esc_url($auth_url); ?>">
290 <span><?php esc_html_e('Login', 'fluent-community'); ?></span>
291 </a>
292 </li>
293 <?php endif; ?>
294 <?php do_action('fluent_community/after_header_right_menu_items', $auth); ?>
295 </ul>
296 <?php
297 }
298
299 protected function appVars()
300 {
301 $userModel = User::where('ID', get_current_user_id())->first();
302 $xprofile = null;
303
304 if ($userModel) {
305 $xprofile = XProfile::where('user_id', get_current_user_id())->first();
306 if (!$xprofile) {
307 $xprofile = $userModel->syncXProfile();
308 }
309 }
310
311 $authData = null;
312 $spaceSlugs = [];
313 $spaceGroups = [];
314
315 if ($userModel && $xprofile) {
316 $wpUser = get_user_by('ID', $userModel->ID);
317
318 if ($userModel->isCommunityModerator()) {
319 $userSpaces = Space::orderBy('serial', 'ASC')->get();
320 $spaceGroups = SpaceGroup::orderBy('serial', 'ASC')
321 ->select(['id', 'title', 'slug', 'settings'])
322 ->get();
323 } else {
324 $userSpaces = Space::orderBy('serial', 'ASC')
325 ->whereHas('members', function ($q) {
326 $q->where('user_id', get_current_user_id())
327 ->where('status', 'active');
328 })
329 ->get();
330
331 $userSpaceParentIds = $userSpaces->pluck('parent_id')->filter()->unique()->toArray();
332
333 $spaceGroups = SpaceGroup::orderBy('serial', 'ASC')
334 ->select(['id', 'title', 'slug', 'settings'])
335 ->whereIn('id', $userSpaceParentIds)
336 ->get();
337 }
338
339 $userSpaces->each(function ($space) use ($userModel) {
340 $userId = get_current_user_id();
341 $space->permissions = $space->getUserPermissions($userModel);
342 $space->membership = $space->getMembership($userId);
343 $space->description_rendered = FeedsHelper::mdToHtml($space->description);
344 if (!$space->membership) {
345 $space->lockscreen_config = LockscreenService::getLockscreenConfig($space, $space->membership);
346 }
347 $space->topics = Utility::getTopicsBySpaceId($space->id);
348 do_action_ref_array('fluent_community/space', [&$space]);
349 });
350
351 $userSpaces = $userSpaces->keyBy('slug');
352
353 $userModel->cacheAccessSpaces();
354
355 $spaceSlugs = $userSpaces->pluck('slug')->toArray();
356
357 $authData = [
358 'id' => $xprofile->user_id,
359 'user_id' => $xprofile->user_id,
360 'username' => $xprofile->username,
361 'display_name' => $xprofile->display_name,
362 'first_name' => $wpUser->first_name ? $wpUser->first_name : $xprofile->getFirstName(),
363 'avatar' => $xprofile->avatar,
364 'total_points' => $xprofile->total_points,
365 'last_activity' => $xprofile->last_activity,
366 'email' => $userModel->user_email,
367 'spaces' => $userSpaces,
368 'community_roles' => $userModel->getCommunityRoles(),
369 'is_verified' => $xprofile->is_verified,
370 'compilation_score' => $xprofile->getCompletionScore(),
371 'meta' => $xprofile->meta
372 ];
373 } else {
374 $authData = [
375 'id' => 0,
376 'user_id' => 0,
377 'spaces' => (object)[],
378 'community_roles' => [],
379 'compilation_score' => 100
380 ];
381 }
382
383 $settings = Helper::generalSettings();
384
385 $onboardSettings = Helper::getOnboardingSettings();
386
387 global $wp_version;
388
389 $isRtl = Helper::isRtl();
390
391 $isAbsoluteUrl = defined('FLUENT_COMMUNITY_PORTAL_SLUG') && FLUENT_COMMUNITY_PORTAL_SLUG == '';
392
393 $portalVars = apply_filters('fluent_community/portal_vars', [
394 'portal_notices' => apply_filters('fluent_community/portal_notices', []),
395 'i18n' => TransStrings::getStrings(),
396 'auth' => $authData,
397 'ajaxurl' => admin_url('admin-ajax.php'),
398 'slug' => 'fluent-community',
399 'rest' => $this->getRestInfo(),
400 'user_id' => $userModel ? $userModel->ID : null,
401 'assets_url' => FLUENT_COMMUNITY_PLUGIN_URL . 'assets/',
402 'permissions' => $userModel ? $userModel->getPermissions() : ['read' => true],
403 'logo' => Arr::get($settings, 'logo'),
404 'site_title' => Arr::get($settings, 'site_title'),
405 'user_membership_slugs' => $spaceSlugs,
406 'block_editor_assets' => [
407 'scripts' => [
408 'react' => Vite::getStaticSrcUrl('libs/isolated-editor/react.production.min.js'),
409 'react-dom' => Vite::getStaticSrcUrl(
410 'libs/isolated-editor/react-dom.production.min.js'
411 ),
412 'isolated-block-editor' => Vite::getStaticSrcUrl('libs/isolated-editor/isolated-block-editor.js')
413 ],
414 'styles' => [
415 $isRtl ? Vite::getStaticSrcUrl('libs/isolated-editor/core.rtl.css') : Vite::getStaticSrcUrl('libs/isolated-editor/core.css'),
416 $isRtl ? Vite::getStaticSrcUrl('libs/isolated-editor/isolated-block-editor.rtl.css') : Vite::getStaticSrcUrl('libs/isolated-editor/isolated-block-editor.css'),
417 includes_url('css/dist/block-editor/content.min.css?ver=' . $wp_version),
418 ]
419 ],
420 'features' => [
421 'disable_global_posts' => Arr::get($settings, 'disable_global_posts', '') == 'yes',
422 'has_survey_poll' => true,
423 'is_onboarding_enabled' => Arr::get($onboardSettings, 'is_onboarding_enabled', 'no') == 'yes',
424 'can_switch_layout' => true,
425 'max_media_per_post' => apply_filters('fluent_community/max_media_per_post', 4),
426 'has_post_title' => Utility::postTitlePref(),
427 'has_course' => Helper::isFeatureEnabled('course_module'),
428 'skicky_sidebar' => Utility::isCustomizationEnabled('fixed_sidebar'),
429 'post_layout' => Utility::getCustomizationSetting('rich_post_layout'),
430 'video_embeder' => apply_filters('fluent_community/has_video_embeder', true),
431 'has_topics' => !!Utility::getTopics()
432 ],
433 'route_classes' => array_filter([
434 'fcom_sticky_header' => Utility::isCustomizationEnabled('fixed_page_header'),
435 'fcom_sticky_sidebar' => Utility::isCustomizationEnabled('fixed_sidebar'),
436 'fcom_has_icon_on_header_menu' => Utility::isCustomizationEnabled('icon_on_header_menu')
437 ]),
438 'urls' => [
439 'site_url' => site_url(),
440 'portal_base' => Helper::baseUrl('/'),
441 'global_search' => Helper::baseUrl(),
442 ],
443 'last_feed_id' => FeedsHelper::getLastFeedId(),
444 'unread_notification_count' => $userModel ? $userModel->getUnreadNotificationCount() : 0,
445 'unread_feed_ids' => $userModel ? $userModel->getUnreadNotificationFeedIds() : [],
446 'date_offset' => time() - current_time('timestamp'),
447 'portal_slug' => Helper::getPortalSlug(true),
448 'mobileMenuItems' => apply_filters('fluent_community/mobile_menu', [
449 [
450 'route' => [
451 'name' => 'all_feeds'
452 ],
453 '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>'
454 ],
455 [
456 'route' => [
457 'name' => 'spaces'
458 ],
459 '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>'
460 ]
461 ]),
462 'socialLinkProviders' => ProfileHelper::socialLinkProviders(),
463 'space_groups' => $spaceGroups,
464 'feed_links' => Helper::getEnabledFeedLinks(),
465 'routing_system' => Helper::getPortalRouteType(),
466 'portal_url' => Helper::baseUrl('/'),
467 'upgrade_url' => 'https://fluentcommunity.co/discount-deal/?utm_source=wp&utm_medium=upgrade&utm_campaign=upgrade',
468 'dateTime18n' => apply_filters('fluent_community/date_time_i18n', [
469 /* translators: weekday. Please keep the serial and format */
470 'weekdays' => __('Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday', 'fluent-community'),
471 /* translators: Months Please keep the serial and format*/
472 'months' => __('January_February_March_April_May_June_July_August_September_October_November_December', 'fluent-community'),
473 /* translators: weekday short Please keep the serial and format*/
474 'weekdaysShort' => __('Sun_Mon_Tue_Wed_Thu_Fri_Sat', 'fluent-community'),
475 /* translators: Months short Please keep the serial and format*/
476 'monthsShort' => __('Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec', 'fluent-community'),
477 /* translators: weekday min Please keep the serial and format*/
478 'weekdaysMin' => __('Su_Mo_Tu_We_Th_Fr_Sa', 'fluent-community'),
479 'relativeTime' => [
480 /* translators: Relative Date Formats. Please do not alter %s*/
481 'future' => __('in %s', 'fluent-community'),
482 /* translators: Relative Date Formats. Please do not alter %s*/
483 'past' => __('%s ago', 'fluent-community'),
484 /* translators: Relative Date Formats.*/
485 's' => __('a few seconds', 'fluent-community'),
486 /* translators: Relative Date Formats.*/
487 'm' => __('a minute', 'fluent-community'),
488 /* translators: Relative Date Formats. Don't alter %d*/
489 'mm' => __('%d minutes', 'fluent-community'),
490 /* translators: Relative Date Formats*/
491 'h' => __('an hour', 'fluent-community'),
492 /* translators: Relative Date Formats. Don't alter %d*/
493 'hh' => __('%d hours', 'fluent-community'),
494 /* translators: Relative Date Formats*/
495 'd' => __('a day', 'fluent-community'),
496 /* translators: Relative Date Formats. Don't alter %d*/
497 'dd' => __('%d days', 'fluent-community'),
498 /* translators: Relative Date Formats*/
499 'M' => __('a month', 'fluent-community'),
500 /* translators: Relative Date Formats. Don't alter %d*/
501 'MM' => __('%d months', 'fluent-community'),
502 /* translators: Relative Date Formats*/
503 'y' => __('a year', 'fluent-community'),
504 /* translators: Relative Date Formats. Don't alter %d*/
505 'yy' => __('%d years', 'fluent-community')
506 ],
507 'relativeTimeMobile' => [
508 /* translators: Relative Date Formats. Please do not alter %s*/
509 'future' => __('in %s', 'fluent-community'),
510 /* translators: Relative Date Formats. Please do not alter %s*/
511 'past' => __('%s ago', 'fluent-community'),
512 /* translators: Relative Date Formats.*/
513 's' => __('few sec', 'fluent-community'),
514 /* translators: Relative Date Formats.*/
515 'm' => __('1min', 'fluent-community'),
516 /* translators: Relative Date Formats. Don't alter %d*/
517 'mm' => __('%dmin', 'fluent-community'),
518 /* translators: Relative Date Formats*/
519 'h' => __('1h', 'fluent-community'),
520 /* translators: Relative Date Formats. Don't alter %d*/
521 'hh' => __('%dh', 'fluent-community'),
522 /* translators: Relative Date Formats*/
523 'd' => __('1d', 'fluent-community'),
524 /* translators: Relative Date Formats. Don't alter %d*/
525 'dd' => __('%dd', 'fluent-community'),
526 /* translators: Relative Date Formats*/
527 'M' => __('1m', 'fluent-community'),
528 /* translators: Relative Date Formats. Don't alter %d*/
529 'MM' => __('%dm', 'fluent-community'),
530 /* translators: Relative Date Formats*/
531 'y' => __('1y', 'fluent-community'),
532 /* translators: Relative Date Formats. Don't alter %d*/
533 'yy' => __('%dy', 'fluent-community')
534 ]
535 ]),
536 'topicsConfig' => Helper::getTopicsConfig(),
537 'is_absolute_url' => $isAbsoluteUrl,
538 'portal_paths' => $isAbsoluteUrl ? Helper::portalRoutePaths() : []
539 ]);
540
541 if ($xprofile) {
542 $portalVars['mobileMenuItems'][] = [
543 'route' => [
544 'name' => 'user_profile',
545 'params' => [
546 'username' => $xprofile->username
547 ]
548 ],
549 'icon' => 'Avatar'
550 ];
551 }
552
553 $portalVars['welcome_banner'] = Helper::getWelcomeBanner($userModel ? 'login' : 'logout');
554
555 if (!$xprofile) {
556 $portalVars['auth_url'] = $this->getAuthUrl();
557 $portalVars['allow_signup'] = !!AuthHelper::isRegistrationEnabled();
558 }
559
560 return $portalVars;
561 }
562
563 protected function getRestInfo()
564 {
565 $app = fluentCommunityApp();
566 $ns = $app->config->get('app.rest_namespace');
567 $v = $app->config->get('app.rest_version');
568
569 return [
570 'base_url' => esc_url_raw(rest_url()),
571 'url' => rest_url($ns . '/' . $v),
572 'nonce' => wp_create_nonce('wp_rest'),
573 'namespace' => $ns,
574 'version' => $v,
575 ];
576 }
577
578 protected function renderFullApp()
579 {
580 if (isset($_REQUEST['fcom_action'])) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
581 $action = sanitize_text_field(wp_unslash($_REQUEST['fcom_action'])); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
582 do_action('fluent_community/portal_action_' . $action, $_GET); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
583 }
584
585 $userId = get_current_user_id();
586
587 if (!$userId) {
588 if (!Helper::isPublicAccessible()) {
589 $url = home_url(add_query_arg($_REQUEST, $GLOBALS['wp']->request)); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
590 $settings = Helper::generalSettings();
591 $authUrl = Arr::get($settings, 'auth_url', '');
592 if ($authUrl) {
593 $authUrl = add_query_arg([
594 'redirect_to' => $url
595 ], $authUrl);
596 } else {
597 $authUrl = $this->getAuthUrl();
598 }
599
600 do_action('fluent_community/portal/not_logged_in', $authUrl);
601 wp_redirect($authUrl);
602 exit();
603 }
604 }
605
606 do_action('fluent_community/portal/viewed');
607 $xprofile = Helper::getCurrentProfile();
608
609 if ($xprofile && $xprofile->status != 'active') {
610 if ($xprofile->status == 'pending') {
611 $this->viewErrorPage('You request is on pending', 'An admin need to approve your join request. Please contact with an admin to get approval');
612 } else {
613 $this->viewErrorPage('Access denied', 'Sorry, You can not access to this portal');
614 }
615 }
616
617 if ($xprofile) {
618 if (!Helper::canAccessPortal()) {
619 $generalSettings = Helper::generalSettings();
620 $this->viewErrorPage('Access Denied', Arr::get($generalSettings, 'restricted_role_content'));
621 }
622 if ($xprofile->user) {
623 $xprofile->user->cacheAccessSpaces();
624 }
625
626 /*
627 * Just in case if username is not sanitized
628 */
629 if ($xprofile->username != CustomSanitizer::sanitizeUserName($xprofile->username)) {
630 $xprofile->username = ProfileHelper::generateUserName($xprofile->user_id);
631 $xprofile->save();
632 }
633
634 do_action('fluent_community/portal_render_for_user', $xprofile);
635 do_action('fluent_communit/track_activity');
636 }
637
638 $data = $this->getAppData();
639 $data = $this->maybePushDynamicMetaData($data);
640
641 $data['isHeadless'] = Helper::isHeadless();
642 $data['a11y_enhancement_style'] = Utility::getCustomizationSetting('a11y_enhancement_style') === 'yes';
643
644 if (!$data['isHeadless']) {
645 $this->loadClassicPortalAssets($data);
646 } else {
647 do_action('fluent_community/rendering_headless_portal', $data);
648 }
649
650 status_header(200);
651 App::make('view')->render('portal_page', $data);
652 exit(200);
653 }
654
655 public function loadClassicPortalAssets($data)
656 {
657 $cssFiles = $data['css_files'];
658
659 unset($cssFiles['fcom_theme_default']);
660
661 foreach ($cssFiles as $fileName => $cssFile) {
662 wp_enqueue_style($fileName, $cssFile['url'], [], FLUENT_COMMUNITY_PLUGIN_VERSION, 'screen');
663 }
664
665 $jsFiles = $data['js_files'];
666 $jsTags = array_keys($jsFiles);
667 add_filter('script_loader_tag', function ($tag, $handle) use ($jsTags) {
668 if (!in_array($handle, $jsTags)) {
669 return $tag;
670 }
671 $tag = str_replace(' src', ' type="module" src', $tag);
672 return $tag;
673 }, 10, 2);
674 foreach ($jsFiles as $fileName => $jsFile) {
675 wp_enqueue_script($fileName, $jsFile['url'], $jsFile['deps'], FLUENT_COMMUNITY_PLUGIN_VERSION, [
676 'in_footer' => true,
677 'strategy' => 'defer',
678 'type' => 'module'
679 ]);
680 }
681
682 foreach ($data['js_vars'] as $varKey => $values) {
683 wp_localize_script('fcom_strat', $varKey, $values);
684 }
685 }
686
687 public function getAppData()
688 {
689
690 $isRtl = Helper::isRtl();
691
692 $userId = get_current_user_id();
693 $url = home_url(add_query_arg($_REQUEST, $GLOBALS['wp']->request)); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
694
695 $appVars = $this->appVars();
696 $generalSettings = Helper::generalSettings();
697 return apply_filters('fluent_community/portal_data_vars', [
698 'title' => Arr::get($generalSettings, 'site_title'),
699 'description' => get_bloginfo('description'),
700 'featured_image' => Arr::get($generalSettings, 'featured_image', ''),
701 'js_files' => [
702 'fcom_strat' => [
703 'url' => Vite::getStaticSrcUrl('start.js'),
704 'deps' => []
705 ],
706 'fcom_app' => [
707 'url' => Vite::getStaticSrcUrl('app.js'),
708 'deps' => []
709 ],
710 'fcom_general' => [
711 'url' => Vite::getStaticSrcUrl('portal_general.js'),
712 'deps' => []
713 ]
714 ],
715 'js_vars' => [
716 'fluentComAdmin' => $appVars,
717 ],
718 'css_files' => array_filter([
719 'fcom_theme_default' => [
720 'url' => Vite::getDynamicSrcUrl('theme-default.scss', $isRtl)
721 ],
722 'fcom_global' => [
723 'url' => Vite::getDynamicSrcUrl('global.scss', $isRtl)
724 ],
725 'fcom_app' => [
726 'url' => Vite::getDynamicSrcUrl('app_css.scss', $isRtl)
727 ],
728 'fcom_vendor' => [
729 'url' => Vite::getDynamicProductionSrcUrl('app.css', $isRtl) // vite automatically build src/app.css for all components also styles inside components
730 ]
731 ]),
732 'url' => $url,
733 'current_route' => $this->currentPath,
734 'contact' => $appVars['auth'],
735 'user' => $userId ? get_user_by('ID', $userId) : null,
736 'route_group' => Helper::getRouteNameByRequestPath($this->currentPath)
737 ]);
738 }
739
740 protected function maybePushDynamicMetaData($data)
741 {
742 $dynamicRoute = Arr::get($data, 'route_group');
743 $validGroups = [
744 'user_profile',
745 'community_view',
746 'course_view',
747 'feed_view'
748 ];
749
750 if (!in_array($dynamicRoute, $validGroups)) {
751 return $data;
752 }
753
754 if ($dynamicRoute == 'user_profile') {
755 $uriParts = explode('/', $this->currentPath);
756 if (count($uriParts) >= 2) {
757 $userName = $uriParts[1];
758 $xProfile = XProfile::where('username', $userName)->first();
759 if ($xProfile) {
760 $data['title'] = esc_html($xProfile->display_name) . ' - ' . $data['title'];
761 if ($xProfile->short_description) {
762 $data['description'] = Helper::getHumanExcerpt($xProfile->short_description, 100);
763 }
764 if ($coverPhoto = Arr::get($xProfile->meta, 'cover_photo')) {
765 $data['featured_image'] = $coverPhoto;
766 }
767 }
768 }
769 return $data;
770 }
771
772 if ($dynamicRoute == 'community_view' || $dynamicRoute == 'course_view') {
773 $uriParts = explode('/', $this->currentPath);
774 if (count($uriParts) >= 2) {
775 $paceSlug = $uriParts[1];
776
777 $space = BaseSpace::query()->withoutGlobalScopes()->where('slug', $paceSlug)->first();
778
779 if ($space && $space->privacy != 'secret') {
780
781 if ($dynamicRoute == 'course_view') {
782 $data['title'] = sprintf(__('Enroll %s', 'fluent-community'), esc_html($space->title) . ' - ' . $data['title']);
783 } else {
784 $data['title'] = sprintf(__('Join %s', 'fluent-community'), esc_html($space->title) . ' - ' . $data['title']);
785 }
786
787 if ($space->description) {
788 $data['description'] = Helper::getHumanExcerpt($space->description, 100);
789 }
790 if ($ogImage = Arr::get($space->settings, 'og_image')) {
791 $data['featured_image'] = $ogImage;
792 } else if ($space->cover_photo) {
793 $data['featured_image'] = $space->cover_photo;
794 }
795 }
796 }
797 return $data;
798 }
799
800 if ($dynamicRoute == 'feed_view') {
801 $uriParts = explode('/', $this->currentPath);
802
803 if (count($uriParts) >= 2) {
804 $postSlug = end($uriParts);
805 $feed = Feed::where('slug', $postSlug)
806 ->with([
807 'xprofile' => function ($q) {
808 $q->select(ProfileHelper::getXProfilePublicFields());
809 },
810 'space'
811 ])
812 ->byUserAccess(get_current_user_id())
813 ->first();
814
815 if (!$feed) {
816 return $data;
817 }
818
819 if ($feed->title) {
820 $data['title'] = esc_html($feed->title) . ' - ' . $data['title'];
821 } else {
822 $data['title'] = esc_html($feed->xprofile->display_name) . ' posted at ' . $data['title'];
823 }
824
825 if ($feed->message) {
826 $data['description'] = esc_html(Helper::getHumanExcerpt($feed->message, 100));
827 }
828
829 if ($mediaPreview = Arr::get($feed->meta, 'media_preview.image')) {
830 $data['featured_image'] = esc_url($mediaPreview);
831 } else if ($feed->space) {
832 $space = $feed->space;
833 if ($ogImage = Arr::get($space->settings, 'og_image')) {
834 $data['featured_image'] = $ogImage;
835 } else if ($space->cover_photo) {
836 $data['featured_image'] = $space->cover_photo;
837 }
838 }
839 }
840
841 return $data;
842 }
843
844 return $data;
845 }
846
847 protected function getMainMenuItems($scope = 'sidebar')
848 {
849 $menuGroups = Helper::getMenuItemsGroup('view');
850
851 $items = Arr::get($menuGroups, 'mainMenuItems', []);
852
853 return apply_filters('fluent_community/main_menu_items', $items, $scope);
854 }
855
856 public function getPortalHeader($echo = false, $context = 'headless')
857 {
858 $settings = Helper::generalSettings();
859 $userId = get_current_user_id();
860
861 if ($userId) {
862 $xprofile = XProfile::where('user_id', get_current_user_id())
863 ->first();
864 } else {
865 $xprofile = null;
866 }
867
868
869 $authUrl = $this->getAuthUrl();
870
871 if ($xprofile) {
872 $xprofile->logout_url = wp_logout_url(Helper::baseUrl());
873 }
874
875 $logo = Arr::get($settings, 'logo', '');
876 $whiteLogo = Arr::get($settings, 'white_logo', '');
877 if (!$whiteLogo) {
878 $whiteLogo = $logo;
879 }
880
881 $data = apply_filters('fluent_community/header_vars', [
882 'portal_url' => Helper::baseUrl('/'),
883 'logo' => $logo,
884 'white_logo' => $whiteLogo,
885 'site_title' => Arr::get($settings, 'site_title'),
886 'profile_url' => $userId ? Helper::baseUrl('u/' . $xprofile->username . '/') : '',
887 'auth' => $xprofile ? $xprofile : null,
888 'auth_url' => $authUrl,
889 'menuItems' => $this->getMainMenuItems('header')
890 ]);
891
892 if ($echo) {
893 App::make('view')->render('portal.header', $data);
894 return;
895 }
896
897 return (string)App::make('view')->make('portal.header', $data);
898 }
899
900 private function getProfileLinks($xprofile = null)
901 {
902 if (!$xprofile) {
903 $xprofile = Helper::getCurrentProfile();
904 }
905
906 $profileLinks = [];
907 $menuGroups = Helper::getMenuItemsGroup('view');
908 if ($xprofile) {
909 $profileLinks = Arr::get($menuGroups, 'profileDropdownItems', []);
910
911 $replaces = [
912 '#{{user_url}}' => Helper::baseUrl('u/' . $xprofile->username),
913 '#user_url' => Helper::baseUrl('u/' . $xprofile->username),
914 '#{{logout_url}}' => wp_logout_url(Helper::baseUrl()),
915 '#logout_url' => wp_logout_url(Helper::baseUrl())
916 ];
917
918 foreach ($profileLinks as &$link) {
919 $slug = Arr::get($link, 'slug', '');
920
921 if ($slug == 'my_spaces') {
922 $link['permalink'] = Helper::baseUrl('u/' . $xprofile->username . '/spaces');
923 } else if ($slug == 'logout') {
924 $link['permalink'] = wp_logout_url(Helper::baseUrl());
925 } else if ($slug == 'profile') {
926 $link['permalink'] = Helper::baseUrl('u/' . $xprofile->username);
927 }
928
929 $link['permalink'] = str_replace(array_keys($replaces), array_values($replaces), $link['permalink']);
930 }
931 }
932
933 return $profileLinks;
934 }
935
936 public function getPortalSidebar($echo = false, $context = 'headless')
937 {
938 $primaryMenuItems = $this->getMainMenuItems('sidebar');
939
940 $userModel = Helper::getCurrentUser();
941 $spaceGroups = Helper::getCommunityMenuGroups($userModel);
942
943 $settingsMenu = apply_filters('fluent_community/settings_menu', [], $userModel);
944
945 $menuGroups = Helper::getMenuItemsGroup('view');
946 $topInlines = Arr::get($menuGroups, 'beforeCommunityMenuItems', []);
947 $bottomLinkGroups = Arr::get($menuGroups, 'afterCommunityLinkGroups', []);
948
949 $data = [
950 'primaryItems' => $primaryMenuItems,
951 'spaceGroups' => $spaceGroups,
952 'settingsItems' => $settingsMenu,
953 'topInlineLinks' => $topInlines,
954 'bottomLinkGroups' => $bottomLinkGroups,
955 'is_admin' => Helper::isSiteAdmin(),
956 'has_color_scheme' => Helper::hasColorScheme(),
957 'context' => $context
958 ];
959
960 if ($echo) {
961 App::make('view')->render('portal.main_sidebar', $data);
962 return;
963 }
964
965 return (string)App::make('view')->make('portal.main_sidebar', $data);
966 }
967
968 protected function getAuthUrl()
969 {
970 return apply_filters('fluent_community/auth/login_url', Helper::getAuthUrl());
971 }
972
973 protected function viewErrorPage($title, $message = '', $showBtn = true)
974 {
975 $data = [
976 'title' => $title,
977 'description' => $message,
978 'btn_txt' => 'Go to home page',
979 'url' => site_url()
980 ];
981
982 if (!$showBtn) {
983 $data['btn_txt'] = '';
984 }
985
986 status_header(200);
987 App::make('view')->render('error_page', $data);
988 exit();
989 }
990
991 public function showAdminPage()
992 {
993
994 $jsTags = ['fluent_community_onboarding'];
995
996 add_filter('script_loader_tag', function ($tag, $handle) use ($jsTags) {
997 if (!in_array($handle, $jsTags)) {
998 return $tag;
999 }
1000 $tag = str_replace(' src', ' type="module" src', $tag);
1001 return $tag;
1002 }, 10, 2);
1003
1004 wp_enqueue_script('fluent_community_onboarding', Vite::getDynamicSrcUrl('Onboarding/onboarding.js'), ['jquery'], FLUENT_COMMUNITY_PLUGIN_VERSION, [
1005 'in_footer' => true,
1006 'strategy' => 'defer',
1007 'type' => 'module'
1008 ]);
1009
1010 wp_enqueue_style('fluent_community_onboarding', Vite::getDynamicSrcUrl('Onboarding/onboarding.scss'), [], FLUENT_COMMUNITY_PLUGIN_VERSION, 'screen');
1011 wp_localize_script('fluent_community_onboarding', 'fluentComAdmin', [
1012 'ajaxurl' => admin_url('admin-ajax.php'),
1013 'rest' => $this->getRestInfo(),
1014 'urls' => [
1015 'site_url' => site_url('/'),
1016 'portal_base' => Helper::baseUrl('/'),
1017 'permalink_url' => admin_url('options-permalink.php')
1018 ],
1019 'logo' => Helper::assetUrl('images/logo.png'),
1020 'is_onboarded' => !!Utility::getOption('onboarding_sub_settings'),
1021 'permalink_structure' => get_option('permalink_structure'),
1022 'is_slug_defined' => defined('FLUENT_COMMUNITY_PORTAL_SLUG'),
1023 'has_pro' => defined('FLUENT_COMMUNITY_PRO_VERSION'),
1024 'upgrade_url' => Utility::getProductUrl(false),
1025 'settings_page_url' => admin_url('admin.php?page=fluent-community'),
1026 'is_license_page' => isset($_GET['license']) && $_GET['license'] === 'yes',
1027 'license_url_page' => defined('FLUENT_COMMUNITY_PRO_VERSION') ? admin_url('admin.php?page=fluent-community&license=yes') : '',
1028 ]);
1029
1030 echo '<div class="wrap"><div id="fcom_onboarding_app"></div></div>';
1031 }
1032
1033 private function getMenuIcon()
1034 {
1035 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">
1036 <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"/>
1037 <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"/>
1038 <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"/>
1039 <path d="M42.593 30.4052L28.8466 38.3417L20.9101 24.5953L34.6565 16.6588L42.593 30.4052Z" fill="white"/>
1040 <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"/>
1041 <path d="M28.847 38.3418L15.1006 46.2783L7.16409 32.5318L20.9105 24.5953L28.847 38.3418Z" fill="white"/>
1042 <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"/>
1043 </svg>');
1044
1045 }
1046
1047 }
1048