PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 1.1.0
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v1.1.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 1.1.0 All 77 releases
fluent-community / app / Functions / Utility.php

Utility.php in FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses 1.1.0, at app/Functions/Utility.php

1,035 lines 41.1 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\Functions;
4
5 use FluentCommunity\App\App;
6 use FluentCommunity\App\Models\Meta;
7 use FluentCommunity\App\Models\Space;
8 use FluentCommunity\App\Models\SpaceGroup;
9 use FluentCommunity\App\Models\Term;
10 use FluentCommunity\App\Services\FeedsHelper;
11 use FluentCommunity\App\Services\Helper;
12 use FluentCommunity\Framework\Support\Arr;
13 use FluentCommunity\Modules\Course\Model\Course;
14
15 class Utility
16 {
17
18 public static function isDev()
19 {
20 static $isDev = null;
21 if ($isDev !== null) {
22 return $isDev;
23 }
24
25 $config = App::getInstance()->config;
26 $isDev = $config->get('app.env') === 'dev';
27 return $isDev;
28 }
29
30 public static function getApp($instance = null)
31 {
32 return \FluentCommunity\App\App::getInstance($instance);
33 }
34
35 /**
36 * Get Global Fluent Community Option
37 * @param string $key The option name
38 * @param mixed $default the default value of the option if option is not available
39 * @return mixed
40 */
41 public static function getOption($key, $default = null)
42 {
43 return self::getFromCache('option_' . $key, function () use ($key, $default) {
44 $exist = \FluentCommunity\App\Models\Meta::where('object_type', 'option')
45 ->where('meta_key', $key)
46 ->first();
47
48 if ($exist) {
49 return $exist->value;
50 }
51
52 return $default;
53 });
54 }
55
56 /**
57 * Update Global Fluent Community Option
58 * @param string $key The option name
59 * @param mixed $value the value of the option
60 * @return \FluentCommunity\App\Models\Meta
61 */
62 public static function updateOption($key, $value)
63 {
64 $exist = \FluentCommunity\App\Models\Meta::where('object_type', 'option')
65 ->where('meta_key', $key)
66 ->first();
67 if ($exist) {
68 $exist->value = $value;
69 $exist->save();
70
71 } else {
72 $exist = \FluentCommunity\App\Models\Meta::create([
73 'meta_key' => $key,
74 'object_type' => 'option',
75 'value' => $value
76 ]);
77 }
78
79 self::setCache('option_' . $key, $value);
80
81 return $exist;
82 }
83
84 public static function getFeaturesConfig()
85 {
86 static $features = null;
87
88 if ($features) {
89 return $features;
90 }
91
92 $features = self::getOption('fluent_community_features', []);
93
94 $defaults = [
95 'leader_board_module' => 'yes',
96 'course_module' => 'yes',
97 'giphy_module' => 'no',
98 'giphy_api_key' => '',
99 'emoji_module' => 'yes',
100 'cloud_storage' => 'no',
101 'invitation' => 'yes',
102 'user_badge' => 'yes',
103 ];
104
105
106 if (defined('FLUENT_COMMUNITY_CLOUD_STORAGE') && FLUENT_COMMUNITY_CLOUD_STORAGE) {
107 $features['cloud_storage'] = 'yes';
108 }
109
110 $features = wp_parse_args($features, $defaults);
111
112 $hasPro = defined('FLUENT_COMMUNITY_PRO') && FLUENT_COMMUNITY_PRO;
113 if (!$hasPro) {
114 $features['leader_board_module'] = 'no';
115 $features['giphy_module'] = 'no';
116 $features['emoji_module'] = 'no';
117 $features['cloud_storage'] = 'no';
118 $features['user_badge'] = 'no';
119 }
120
121 return $features;
122 }
123
124 /**
125 * @param $key
126 * @param $callback
127 * @param $expire
128 * @return false|mixed
129 * @internal Internal Function
130 */
131 public static function getFromCache($key, $callback = false, $expire = 3600)
132 {
133 $key = 'focm_' . $key;
134
135 $value = wp_cache_get($key, 'fluent_community');
136
137 if ($value !== false) {
138 return $value;
139 }
140
141 if ($callback) {
142 $value = $callback();
143 if ($value) {
144 wp_cache_set($key, $value, 'fluent_community', $expire);
145 }
146 }
147
148 return $value;
149 }
150
151 /**
152 * @param $key
153 * @param $value
154 * @param $expire
155 * @return bool
156 * @internal Internal Function
157 */
158 public static function setCache($key, $value, $expire = 600)
159 {
160 $key = 'focm_' . $key;
161
162 return wp_cache_set($key, $value, 'fluent_community', $expire);
163 }
164
165 /**
166 * @param $key
167 * @return bool
168 * @internal Internal Function
169 */
170 public static function forgetCache($key)
171 {
172 $key = 'focm_' . $key;
173 return wp_cache_delete($key, 'fluent_community');
174 }
175
176 public static function getCustomizationSettings()
177 {
178 static $settings;
179
180 if ($settings) {
181 return $settings;
182 }
183
184 $defaults = [
185 'dark_mode' => 'yes',
186 'fixed_page_header' => 'yes',
187 'show_powered_by' => 'yes',
188 'feed_link_on_sidebar' => 'yes',
189 'fixed_sidebar' => 'no',
190 'icon_on_header_menu' => 'no',
191 'affiliate_id' => '',
192 'rich_post_layout' => 'classic',
193 'post_title_pref' => 'optional',
194 ];
195
196 $settings = self::getOption('customization_settings', $defaults);
197
198 $settings = wp_parse_args($settings, $defaults);
199
200 if (!defined('FLUENT_COMMUNITY_PRO')) {
201 $settings['show_powered_by'] = 'yes';
202 $settings['affiliate_id'] = '';
203 $settings['rich_post_layout'] = 'classic';
204 }
205
206 return $settings;
207 }
208
209 public static function getCustomizationSetting($key)
210 {
211 $settings = self::getCustomizationSettings();
212 return Arr::get($settings, $key);
213 }
214
215 public static function updateCustomizationSettings($settings)
216 {
217 $preSettings = self::getCustomizationSettings();
218 $settings = Arr::only($settings, array_keys($preSettings));
219
220 self::updateOption('customization_settings', $settings);
221
222 return $settings;
223 }
224
225 public static function getPrivacySettings()
226 {
227 static $settings;
228
229 if ($settings) {
230 return $settings;
231 }
232
233 $settings = self::getFromCache('privacy_settings', function () {
234 $defaults = [
235 'members_page_status' => 'everybody', // everybody, logged_in, admin_only
236 'can_customize_username' => 'no',
237 'show_last_activity' => 'yes',
238 'email_auto_login' => 'yes',
239 'user_space_visibility' => 'everybody', // everybody, logged_in, admin_only
240 ];
241
242 $settings = self::getOption('privacy_settings', $defaults);
243
244 $settings = wp_parse_args($settings, $defaults);
245
246 if (!defined('FLUENT_COMMUNITY_PRO')) {
247 $settings['can_customize_username'] = 'no';
248 $settings['email_auto_login'] = 'no';
249 }
250
251 return $settings;
252 });
253
254 return $settings;
255 }
256
257 public static function canViewMembersPage()
258 {
259 $pageStatus = self::getPrivacySetting('members_page_status');
260
261 if ($pageStatus == 'everybody') {
262 return apply_filters('fluent_community/can_view_members_page', true, $pageStatus);
263 }
264
265 if ($pageStatus == 'logged_in') {
266 return apply_filters('fluent_community/can_view_members_page', is_user_logged_in(), $pageStatus);
267 }
268
269 return apply_filters('fluent_community/can_view_members_page', Helper::isModerator(), $pageStatus);
270 }
271
272 public static function getPrivacySetting($key)
273 {
274 $settings = self::getPrivacySettings();
275 return Arr::get($settings, $key);
276 }
277
278 public static function updatePrivacySettings($settings)
279 {
280 $preSettings = self::getPrivacySettings();
281 $settings = Arr::only($settings, array_keys($preSettings));
282
283 self::updateOption('privacy_settings', $settings);
284 self::forgetCache('privacy_settings');
285
286 return $settings;
287 }
288
289 public static function isCustomizationEnabled($key, $matchingValue = 'yes')
290 {
291 $settings = self::getCustomizationSettings();
292 return isset($settings[$key]) && $settings[$key] === $matchingValue;
293 }
294
295 public static function getProductUrl($isPowered = false)
296 {
297 $url = 'https://fluentcommunity.co/';
298 if ($isPowered) {
299 $params = [
300 'utm_source' => 'power_footer',
301 'utm_medium' => 'site',
302 'utm_campaign' => 'powered_by'
303 ];
304 $settings = self::getCustomizationSettings();
305 $affId = Arr::get($settings, 'affiliate_id');
306 if ($affId) {
307 $params['ref'] = $affId;
308 }
309
310 $url = add_query_arg($params, $url);
311 }
312
313 return add_query_arg([
314 'utm_source' => 'plugin',
315 'utm_medium' => 'site',
316 'utm_campaign' => 'pligin_ui'
317 ], $url);
318 }
319
320 /**
321 * Get the email notification settings.
322 *
323 * @return array The email notification settings.
324 */
325 public static function getEmailNotificationSettings()
326 {
327 static $settings;
328 if ($settings) {
329 return $settings;
330 }
331
332 $default = [
333 'com_my_post_mail' => 'yes',
334 'reply_my_com_mail' => 'yes',
335 'mention_mail' => 'yes',
336 'digest_email_status' => 'no',
337 'digest_mail_day' => 'tue',
338 'daily_digest_time' => '09:00',
339 'send_from_email' => '',
340 'send_from_name' => '',
341 'reply_to_email' => '',
342 'reply_to_name' => '',
343 'email_footer' => 'You are getting this email because you are a member of {{site_name_with_url}}.' . PHP_EOL . PHP_EOL . '{{manage_email_notification_url|Manage Your Email Notifications Preference}}.',
344 'disable_powered_by' => 'no',
345 ];
346
347 $settings = array_filter(self::getOption('global_email_settings', $default));
348 $settings = wp_parse_args($settings, $default);
349
350 if (!defined('FLUENT_COMMUNITY_PRO')) {
351 $settings['disable_powered_by'] = 'no';
352 }
353
354 if (empty($settings['email_footer_rendered']) && !empty($settings['email_footer'])) {
355 $settings['email_footer_rendered'] = FeedsHelper::mdToHtml($settings['email_footer']);
356 }
357
358 return $settings;
359 }
360
361 public static function postTitlePref()
362 {
363 $pref = self::getCustomizationSetting('post_title_pref');
364
365 if ($pref == 'disabled') {
366 $pref = '';
367 }
368
369 return apply_filters('fluent_community/has_post_title', $pref);
370 }
371
372 public static function getSpaces($byGroups = false)
373 {
374 if ($byGroups) {
375 return SpaceGroup::orderBy('serial', 'ASC')->with('spaces', function ($q) {
376 $q->orderBy('serial', 'ASC')
377 ->where('type', 'community');
378 })->get();
379 }
380
381 return Space::where('type', 'community')->orderBy('serial', 'ASC')->get();
382 }
383
384 public static function getCourses($byGroups = false)
385 {
386 if ($byGroups) {
387 return SpaceGroup::orderBy('serial', 'ASC')->with('spaces', function ($q) {
388 $q->orderBy('serial', 'ASC')
389 ->where('type', 'course');
390 })->get();
391 }
392
393 return Course::orderBy('serial', 'ASC')->get();
394 }
395
396 public static function getTopics()
397 {
398 static $topics;
399 if ($topics) {
400 return $topics;
401 }
402
403 $key = 'fluent_community_post_topics';
404 $topics = self::getFromCache($key, function () {
405 $topics = Term::where('taxonomy_name', 'post_topic')->orderBy('title', 'ASC')->get();
406
407 /*
408 * object_id = term_id
409 * meta_key = space_id
410 */
411 $topicSpaceRelations = Meta::select(['id', 'object_id', 'meta_key'])->where('object_type', 'term_space_relation')
412 ->get();
413
414 $relations = [];
415 foreach ($topicSpaceRelations as $relation) {
416 if (!isset($relations[$relation->object_id])) {
417 $relations[$relation->object_id] = [];
418 }
419
420 $relations[$relation->object_id][] = $relation->meta_key;
421 }
422
423 $formattedTopics = [];
424 foreach ($topics as $topic) {
425 $formattedTopics[] = [
426 'id' => $topic->id,
427 'title' => $topic->title,
428 'description' => $topic->description,
429 'slug' => $topic->slug,
430 'admin_only' => Arr::get($topic->settings, 'admin_only', 'no'),
431 'space_ids' => isset($relations[$topic->id]) ? $relations[$topic->id] : []
432 ];
433 }
434
435 return $formattedTopics;
436 }, MONTH_IN_SECONDS);
437
438 return $topics;
439 }
440
441 public static function getTopicsBySpaceId($spaceId)
442 {
443 $topics = self::getTopics();
444 $topics = array_filter($topics, function ($topic) use ($spaceId) {
445 return in_array($spaceId, $topic['space_ids']);
446 });
447 return $topics;
448 }
449
450 public static function getMaxRunTime()
451 {
452 if (function_exists('ini_get')) {
453 $maxRunTime = (int)ini_get('max_execution_time');
454 if ($maxRunTime === 0) {
455 $maxRunTime = 60;
456 }
457 } else {
458 $maxRunTime = 30;
459 }
460
461 if ($maxRunTime > 58) {
462 $maxRunTime = 58;
463 }
464
465 $maxRunTime = $maxRunTime - 3;
466
467 return apply_filters('fluent_communutt/max_execution_time', $maxRunTime);
468 }
469
470 public static function getColorSchemas()
471 {
472 $defaultCustom = [
473 'title' => __('Custom', 'fluent-community'),
474 'selectors' => [
475 'body' => [],
476 'fcom_top_menu' => [],
477 'spaces' => []
478 ],
479 ];
480 $shemas = apply_filters('fluent-community/color_schemas', [
481 'lightSkins' => [
482 'default' => [
483 'title' => __('Default', 'fluent-community'),
484 'selectors' => [
485 'body' => [
486 'primary_bg' => '#ffffff',
487 'secondary_bg' => '#f0f2f5',
488 'secondary_content_bg' => '#f0f3f5',
489 'active_bg' => '#f0f3f5',
490 'light_bg' => '#E1E4EA',
491 'deep_bg' => '#222530',
492 'menu_text' => '#545861',
493 'primary_text' => '#19283a',
494 'secondary_text' => '#525866',
495 'text_off' => '#959595',
496 'primary_button' => '#2B2E33',
497 'primary_button_text' => '#ffffff',
498 'primary_border' => '#e3e8ee',
499 'secondary_border' => '#9CA3AF',
500 'highlight_bg' => '#fffce3',
501 'text_link' => '#2271b1',
502 ],
503 'fcom_top_menu' => [
504 'primary_bg' => '#ffffff',
505 'primary_border' => '#e3e8ee',
506 'menu_text' => '#545861',
507 'menu_text_active' => '#545861',
508 'active_bg' => '#f0f3f5',
509 'menu_text_hover' => '#545861',
510 'menu_bg_hover' => '#f0f3f5',
511 ],
512 'spaces' => [
513 'primary_bg' => '#ffffff',
514 'primary_border' => '#e3e8ee',
515 'menu_text' => '#545861',
516 'menu_text_active' => '#545861',
517 'menu_text_hover' => '#545861',
518 'menu_bg_hover' => '#f0f3f5',
519 'active_bg' => '#f0f3f5',
520 ]
521 ],
522 ],
523 'sunset_sands' => [
524 'title' => __('Sunset Sands', 'fluent-community'),
525 'selectors' => [
526 'body' => [
527 'primary_bg' => '#FFFFFF',
528 'secondary_bg' => '#FDF6F0',
529 'secondary_content_bg' => '#FDF6F0',
530 'active_bg' => '#FCF0E6',
531 'light_bg' => '#FAE5D3',
532 'deep_bg' => '#2D2D2D',
533 'menu_text' => '#5D5D5D',
534 'primary_text' => '#333333',
535 'secondary_text' => '#666666',
536 'text_off' => '#999999',
537 'text_link' => '#E67E22',
538 'primary_button' => '#E67E22',
539 'primary_button_text' => '#FFFFFF',
540 'primary_border' => '#EADDD3',
541 'secondary_border' => '#E0D0C3',
542 'highlight_bg' => '#FFF5EC',
543 ],
544 'fcom_top_menu' => [
545 'primary_bg' => '#FFFFFF',
546 'primary_border' => '#EADDD3',
547 'menu_text' => '#5D5D5D',
548 'menu_text_active' => '#E67E22',
549 'active_bg' => '#FFF5EC',
550 'menu_text_hover' => '#E67E22',
551 'menu_bg_hover' => '#FFF5EC',
552 ],
553 'spaces' => [
554 'primary_bg' => '#FFFFFF',
555 'primary_border' => '#EADDD3',
556 'menu_text' => '#5D5D5D',
557 'menu_text_hover' => '#E67E22',
558 'menu_bg_hover' => '#FFF5EC',
559 'menu_text_active' => '#FFFFFF',
560 'active_bg' => '#E67E22',
561 ]
562 ]
563 ],
564 'ocean_blue' => [
565 'title' => __('Ocean Blue', 'fluent-community'),
566 'selectors' => [
567 'body' => [
568 'primary_bg' => '#FFFFFF',
569 'secondary_bg' => '#F0F2F5',
570 'secondary_content_bg' => '#f0f3f5',
571 'active_bg' => '#E7F3FF',
572 'light_bg' => '#F6F9FA',
573 'deep_bg' => '#18191A',
574 'menu_text' => '#65676B',
575 'primary_text' => '#050505',
576 'secondary_text' => '#65676B',
577 'text_off' => '#8A8D91',
578 'text_link' => '#216FDB',
579 'primary_button' => '#1877F2',
580 'primary_button_text' => '#FFFFFF',
581 'primary_border' => '#DADDE1',
582 'secondary_border' => '#CED0D4',
583 'highlight_bg' => '#E7F3FF'
584 ],
585 'fcom_top_menu' => [
586 'primary_bg' => '#FFFFFF',
587 'primary_border' => '#DADDE1',
588 'menu_text' => '#65676B',
589 'menu_text_active' => '#1877F2',
590 'active_bg' => '#E7F3FF',
591 'menu_text_hover' => '#1877F2',
592 'menu_bg_hover' => '#E7F3FF',
593 ],
594 'spaces' => [
595 'primary_bg' => '#FFFFFF',
596 'primary_border' => '#DADDE1',
597 'menu_text' => '#65676B',
598 'menu_text_hover' => '#1877F2',
599 'menu_bg_hover' => '#E7F3FF',
600 'menu_text_active' => '#FFFFFF',
601 'active_bg' => '#1877F2'
602 ]
603 ]
604 ],
605 'sky_blue' => [
606 'title' => __('Sky Blue', 'fluent-community'),
607 'selectors' => [
608 'body' => [
609 'primary_bg' => '#FFFFFF',
610 'secondary_bg' => '#F7F9FA',
611 'secondary_content_bg' => '#f0f3f5',
612 'active_bg' => '#E8F5FD',
613 'light_bg' => '#F7F9FA',
614 'deep_bg' => '#15202B',
615 'menu_text' => '#536471',
616 'primary_text' => '#0F1419',
617 'secondary_text' => '#536471',
618 'text_off' => '#8899A6',
619 'text_link' => '#1D9BF0',
620 'primary_button' => '#1D9BF0',
621 'primary_button_text' => '#FFFFFF',
622 'primary_border' => '#EFF3F4',
623 'secondary_border' => '#CFD9DE',
624 'highlight_bg' => '#E8F5FD'
625 ],
626 'fcom_top_menu' => [
627 'primary_bg' => '#FFFFFF',
628 'primary_border' => '#EFF3F4',
629 'menu_text' => '#536471',
630 'menu_text_active' => '#1D9BF0',
631 'active_bg' => '#E8F5FD',
632 'menu_bg_hover' => '#E8F5FD',
633 'menu_text_hover' => '#536471',
634 ],
635 'spaces' => [
636 'primary_bg' => '#FFFFFF',
637 'primary_border' => '#EFF3F4',
638 'menu_text' => '#536471',
639 'menu_text_hover' => '#1D9BF0',
640 'menu_bg_hover' => '#E8F5FD',
641 'menu_text_active' => '#FFFFFF',
642 'active_bg' => '#1D9BF0'
643 ]
644 ]
645 ],
646 'emerald_essence' => [
647 'title' => __('Emerald Essence', 'fluent-community'),
648 'selectors' => [
649 'body' => [
650 'primary_bg' => '#FFFFFF',
651 'secondary_bg' => '#F0F7F4',
652 'secondary_content_bg' => '#f0f3f5',
653 'active_bg' => '#E3F2ED',
654 'light_bg' => '#F7FAFA',
655 'deep_bg' => '#1A2B32',
656 'menu_text' => '#4A5D5E',
657 'primary_text' => '#1F2937',
658 'secondary_text' => '#4B5563',
659 'text_off' => '#9CA3AF',
660 'text_link' => '#059669',
661 'primary_button' => '#10B981',
662 'primary_button_text' => '#FFFFFF',
663 'primary_border' => '#D1E7DD',
664 'secondary_border' => '#A7C4BC',
665 'highlight_bg' => '#ECFDF5'
666 ],
667 'fcom_top_menu' => [
668 'primary_bg' => '#FFFFFF',
669 'primary_border' => '#D1E7DD',
670 'menu_text' => '#4A5D5E',
671 'menu_text_active' => '#059669',
672 'active_bg' => '#ECFDF5',
673 'menu_bg_hover' => '#ECFDF5',
674 'menu_text_hover' => '#4A5D5E',
675 ],
676 'spaces' => [
677 'primary_bg' => '#FFFFFF',
678 'primary_border' => '#D1E7DD',
679 'menu_text' => '#4A5D5E',
680 'menu_text_hover' => '#059669',
681 'menu_bg_hover' => '#ECFDF5',
682 'menu_text_active' => '#FFFFFF',
683 'active_bg' => '#10B981'
684 ]
685 ]
686 ]
687 ],
688 'darkSkins' => [
689 'default' => [
690 'title' => __('Default (Dark)', 'fluent-community'),
691 'selectors' => [
692 'body' => [
693 'primary_bg' => '#2B2E33',
694 'secondary_bg' => '#191B1F',
695 'secondary_content_bg' => '#42464D',
696 'active_bg' => '#42464D',
697 'light_bg' => '#2B303B',
698 'deep_bg' => '#E1E4EA',
699 'menu_text' => '#E4E7EB',
700 'menu_text_active' => '#E4E7EB',
701 'primary_text' => '#F0F3F5',
702 'secondary_text' => '#99A0AE',
703 'menu_bg_hover' => '#E1E4EA',
704 'text_off' => '#A5A9AD',
705 'text_link' => '#60a5fa',
706 'primary_button' => '#FFFFFF',
707 'primary_button_text' => '#2B2E33',
708 'primary_border' => '#42464D',
709 'secondary_border' => '#A5A9AD',
710 'highlight_bg' => '#2c2c1a',
711 ],
712 'fcom_top_menu' => [
713 'primary_bg' => '#2B2E33',
714 'primary_border' => '#42464D',
715 'menu_text' => '#E4E7EB',
716 'menu_text_active' => '#E4E7EB',
717 'active_bg' => '#42464D',
718 'menu_bg_hover' => '#42464D',
719 'menu_text_hover' => '#E4E7EB',
720 ],
721 'spaces' => [
722 'primary_bg' => '#2B2E33',
723 'primary_border' => '#42464D',
724 'menu_text' => '#E4E7EB',
725 'menu_text_active' => '#E4E7EB',
726 'active_bg' => '#42464D',
727 'menu_bg_hover' => '#42464D',
728 'menu_text_hover' => '#fff',
729 ]
730 ],
731 ],
732 'sunset_sands' => [
733 'title' => __('Sunset Sands (Dark)', 'fluent-community'),
734 'selectors' => [
735 'body' => [
736 'primary_bg' => '#1A1A1A',
737 'secondary_bg' => '#222222',
738 'secondary_content_bg' => '#222222',
739 'active_bg' => '#2A2420',
740 'light_bg' => '#33302E',
741 'deep_bg' => '#111111',
742 'menu_text' => '#B0B0B0',
743 'primary_text' => '#E0E0E0',
744 'secondary_text' => '#A0A0A0',
745 'text_off' => '#707070',
746 'text_link' => '#F39C12',
747 'primary_button' => '#F39C12',
748 'primary_border' => '#3A3632',
749 'primary_button_text' => '#1A1A1A',
750 'secondary_border' => '#4C4D4F',
751 'highlight_bg' => '#2A2420',
752 ],
753 'fcom_top_menu' => [
754 'primary_bg' => '#1A1A1A',
755 'primary_border' => '#3A3632',
756 'menu_text' => '#B0B0B0',
757 'menu_text_active' => '#F39C12',
758 'active_bg' => '#2A2420',
759 'menu_text_hover' => '#F39C12',
760 'menu_bg_hover' => '#2A2420',
761 ],
762 'spaces' => [
763 'primary_bg' => '#1A1A1A',
764 'primary_border' => '#3A3632',
765 'menu_text' => '#B0B0B0',
766 'menu_text_hover' => '#F39C12',
767 'menu_bg_hover' => '#2A2420',
768 'menu_text_active' => '#1A1A1A',
769 'active_bg' => '#F39C12',
770 ]
771 ]
772 ],
773 'ocean_blue' => [
774 'title' => __('Ocean Blue (Dark)', 'fluent-community'),
775 'selectors' => [
776 'body' => [
777 'primary_border' => '#3E4042',
778 'menu_text' => '#B0B3B8',
779 'menu_text_active' => '#2D88FF',
780 'active_bg' => '#263951',
781 'menu_text_hover' => '#2D88FF',
782 'menu_bg_hover' => '#263951',
783 'primary_bg' => '#2B2E33',
784 'secondary_content_bg' => '#42464D',
785 'secondary_bg' => '#191B1F',
786 'light_bg' => '#2B303B',
787 'deep_bg' => '#E1E4EA',
788 'primary_text' => '#F0F3F5',
789 'secondary_text' => '#99A0AE',
790 'text_off' => '#A5A9AD',
791 'primary_button' => '#FFFFFF',
792 'primary_button_text' => '#191B1F',
793 'secondary_border' => '#A5A9AD',
794 'highlight_bg' => '#2c2c1a',
795 'text_link' => '#2d88ff',
796 ],
797 'fcom_top_menu' => [
798 'primary_bg' => '#242526',
799 'primary_border' => '#3E4042',
800 'menu_text' => '#B0B3B8',
801 'menu_text_active' => '#fff',
802 'active_bg' => '#263951',
803 'menu_text_hover' => '#fff',
804 'menu_bg_hover' => '#263951',
805 ],
806 'spaces' => [
807 'primary_bg' => '#242526',
808 'primary_border' => '#3E4042',
809 'menu_text' => '#B0B3B8',
810 'menu_text_hover' => '#2D88FF',
811 'menu_bg_hover' => '#263951',
812 'menu_text_active' => '#FFFFFF',
813 'active_bg' => '#2D88FF'
814 ]
815 ]
816 ],
817 'sky_blue' => [
818 'title' => __('Sky Blue (Dark)', 'fluent-community'),
819 'selectors' => [
820 'body' => [
821 'primary_bg' => '#15202B',
822 'secondary_bg' => '#1E2732',
823 'secondary_content_bg' => '#2C3640',
824 'active_bg' => '#1D2F41',
825 'light_bg' => '#22303C',
826 'deep_bg' => '#E7E9EA',
827 'menu_text' => '#8B98A5',
828 'primary_text' => '#E7E9EA',
829 'secondary_text' => '#8B98A5',
830 'text_off' => '#536471',
831 'text_link' => '#1D9BF0',
832 'primary_button' => '#1D9BF0',
833 'primary_button_text' => '#15202B',
834 'primary_border' => '#38444D',
835 'secondary_border' => '#536471',
836 'highlight_bg' => '#1D2F41'
837 ],
838 'fcom_top_menu' => [
839 'primary_bg' => '#15202B',
840 'primary_border' => '#38444D',
841 'menu_text' => '#8B98A5',
842 'menu_text_active' => '#1D9BF0',
843 'active_bg' => '#1D2F41',
844 'menu_bg_hover' => '#1D2F41',
845 'menu_text_hover' => '#E7E9EA',
846 ],
847 'spaces' => [
848 'primary_bg' => '#15202B',
849 'primary_border' => '#38444D',
850 'menu_text' => '#8B98A5',
851 'menu_text_hover' => '#1D9BF0',
852 'menu_bg_hover' => '#1D2F41',
853 'menu_text_active' => '#FFFFFF',
854 'active_bg' => '#1D9BF0'
855 ]
856 ]
857 ],
858 'emerald_essence' => [
859 'title' => __('Emerald Essence (Dark)', 'fluent-community'),
860 'selectors' => [
861 'body' => [
862 'primary_bg' => '#1A2B32',
863 'secondary_bg' => '#243B43',
864 'secondary_content_bg' => '#2C464F',
865 'active_bg' => '#1E3A31',
866 'light_bg' => '#2A3F48',
867 'deep_bg' => '#E2E8F0',
868 'menu_text' => '#A7BCBF',
869 'primary_text' => '#E2E8F0',
870 'secondary_text' => '#A7BCBF',
871 'text_off' => '#64748B',
872 'text_link' => '#34D399',
873 'primary_button' => '#10B981',
874 'primary_border' => '#2F4C41',
875 'primary_button_text' => '#1A2B32',
876 'secondary_border' => '#3D5C52',
877 'highlight_bg' => '#064E3B'
878 ],
879 'fcom_top_menu' => [
880 'primary_bg' => '#1A2B32',
881 'primary_border' => '#2F4C41',
882 'menu_text' => '#A7BCBF',
883 'menu_text_active' => '#34D399',
884 'active_bg' => '#064E3B',
885 'menu_bg_hover' => '#064E3B',
886 'menu_text_hover' => '#E2E8F0',
887 ],
888 'spaces' => [
889 'primary_bg' => '#1A2B32',
890 'primary_border' => '#2F4C41',
891 'menu_text' => '#A7BCBF',
892 'menu_text_hover' => '#34D399',
893 'menu_bg_hover' => '#064E3B',
894 'menu_text_active' => '#FFFFFF',
895 'active_bg' => '#10B981'
896 ]
897 ]
898 ]
899 ]
900 ]);
901
902 $customSchemaConfig = self::getColorConfig('edit');
903
904 $shemas['lightSkins']['custom'] = [
905 'title' => __('Custom', 'fluent-community'),
906 'selectors' => $customSchemaConfig['light_config'] ?? $defaultCustom
907 ];
908
909 $shemas['darkSkins']['custom'] = [
910 'title' => __('Custom', 'fluent-community'),
911 'selectors' => $customSchemaConfig['dark_config'] ?? $defaultCustom
912 ];
913
914 return $shemas;
915 }
916
917 public static function generateCss($sectors, $prefix = '')
918 {
919 if (!$sectors) {
920 return '';
921 }
922
923 $bodyPrefix = 'body';
924 if ($prefix) {
925 $bodyPrefix = $prefix . ' body';
926 }
927
928 $elementPlusMap = [
929 'primary_text' => '--el-color-primary',
930 'secondary_bg' => '--el-color-white'
931 ];
932
933 $css = '';
934 foreach ($sectors as $selector => $props) {
935 $isBody = $selector === 'body';
936 $prefix = $isBody ? $bodyPrefix : $bodyPrefix . ' .' . $selector;
937 $prefix .= '{';
938
939 $css .= $prefix;
940
941 foreach ($props as $prop => $value) {
942 $cssVar = '--fcom-' . str_replace('_', '-', $prop);
943 $css .= $cssVar . ':' . $value . ';';
944
945 if ($isBody && isset($elementPlusMap[$prop])) {
946 $css .= $elementPlusMap[$prop] . ':' . $value . ';';
947 }
948 }
949 $css .= '} ';
950 }
951
952 return $css;
953 }
954
955 public static function getColorConfig($context = 'view')
956 {
957 return apply_filters('fluent_community/color_schmea_config', [
958 'light_schema' => 'default',
959 'dark_schema' => 'default',
960 'light_config' => [
961 'body' => [],
962 'fcom_top_menu' => [],
963 'spaces' => []
964 ],
965 'dark_config' => [
966 'body' => [],
967 'fcom_top_menu' => [],
968 'spaces' => []
969 ],
970 'version' => FLUENT_COMMUNITY_PLUGIN_VERSION
971 ], $context);
972 }
973
974 public static function getColorCssVariables()
975 {
976 $customSchemaConfig = self::getColorConfig('view');
977
978 if (!empty($customSchemaConfig['cached_css'])) {
979 if ($customSchemaConfig['version'] != FLUENT_COMMUNITY_PLUGIN_VERSION) {
980 do_action('fluent_community/recache_color_schema');
981 }
982
983 return (string)$customSchemaConfig['cached_css'];
984 }
985
986 $schemas = self::getColorSchemas();
987
988 $lightName = Arr::get($customSchemaConfig, 'light_schema', 'default');
989 $darkName = Arr::get($customSchemaConfig, 'dark_schema', 'default');
990
991 $lightCss = self::generateCss(Arr::get($schemas, "lightSkins.$lightName.selectors"));
992 $darkCss = self::generateCss(Arr::get($schemas, "darkSkins.$darkName.selectors"), 'html.dark');
993 return $lightCss . $darkCss;
994 }
995
996 public static function getSuggestedColors()
997 {
998 $pallets = current((array)get_theme_support('editor-color-palette'));
999
1000 $colors = [];
1001
1002 if ($pallets) {
1003 $colors = array_map(function ($color) {
1004 $colorString = Arr::get($color, 'color');
1005 // Trim any whitespace
1006 $colorString = trim($colorString);
1007 // Check if it's a CSS variable
1008 if (strpos($colorString, 'var(') === 0) {
1009 // Extract the fallback color if present
1010 preg_match('/var\(.*,\s*(#[A-Fa-f0-9]{6})\)/', $colorString, $matches);
1011 if (!empty($matches[1])) {
1012 return $matches[1];
1013 }
1014 // If no fallback color, return an empty string
1015 return '';
1016 }
1017
1018 if (preg_match('/#[A-Fa-f0-9]{6}/', $colorString, $matches)) {
1019 return $matches[0];
1020 }
1021
1022 return $colorString;
1023 }, $pallets);
1024
1025 $colors = array_filter($colors);
1026 }
1027
1028 if (!$colors) {
1029 $colors = ['#000000', '#abb8c3', '#ffffff', '#f78da7', '#ff6900', '#fcb900', '#7bdcb5', '#00d084', '#8ed1fc', '#0693e3', '#9b51e0'];
1030 }
1031
1032 return apply_filters('fluent_community/suggested_colors', $colors);
1033 }
1034 }
1035