PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 1.0.98
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v1.0.98
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.0.98, at app/Functions/Utility.php

1,001 lines 39.7 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_border' => '#e3e8ee',
498 'secondary_border' => '#9CA3AF',
499 'highlight_bg' => '#fffce3',
500 'text_link' => '#2271b1',
501 ],
502 'fcom_top_menu' => [
503 'primary_bg' => '#ffffff',
504 'primary_border' => '#e3e8ee',
505 'menu_text' => '#545861',
506 'menu_text_active' => '#545861',
507 'active_bg' => '#f0f3f5',
508 'menu_text_hover' => '#545861',
509 'menu_bg_hover' => '#f0f3f5',
510 ],
511 'spaces' => [
512 'primary_bg' => '#ffffff',
513 'primary_border' => '#e3e8ee',
514 'menu_text' => '#545861',
515 'menu_text_active' => '#545861',
516 'menu_text_hover' => '#545861',
517 'menu_bg_hover' => '#f0f3f5',
518 'active_bg' => '#f0f3f5',
519 ]
520 ],
521 ],
522 'sunset_sands' => [
523 'title' => __('Sunset Sands', 'fluent-community'),
524 'selectors' => [
525 'body' => [
526 'primary_bg' => '#FFFFFF',
527 'secondary_bg' => '#FDF6F0',
528 'secondary_content_bg' => '#FDF6F0',
529 'active_bg' => '#FCF0E6',
530 'light_bg' => '#FAE5D3',
531 'deep_bg' => '#2D2D2D',
532 'menu_text' => '#5D5D5D',
533 'primary_text' => '#333333',
534 'secondary_text' => '#666666',
535 'text_off' => '#999999',
536 'text_link' => '#E67E22',
537 'primary_button' => '#E67E22',
538 'primary_border' => '#EADDD3',
539 'secondary_border' => '#E0D0C3',
540 'highlight_bg' => '#FFF5EC',
541 ],
542 'fcom_top_menu' => [
543 'primary_bg' => '#FFFFFF',
544 'primary_border' => '#EADDD3',
545 'menu_text' => '#5D5D5D',
546 'menu_text_active' => '#E67E22',
547 'active_bg' => '#FFF5EC',
548 'menu_text_hover' => '#E67E22',
549 'menu_bg_hover' => '#FFF5EC',
550 ],
551 'spaces' => [
552 'primary_bg' => '#FFFFFF',
553 'primary_border' => '#EADDD3',
554 'menu_text' => '#5D5D5D',
555 'menu_text_hover' => '#E67E22',
556 'menu_bg_hover' => '#FFF5EC',
557 'menu_text_active' => '#FFFFFF',
558 'active_bg' => '#E67E22',
559 ]
560 ]
561 ],
562 'ocean_blue' => [
563 'title' => __('Ocean Blue', 'fluent-community'),
564 'selectors' => [
565 'body' => [
566 'primary_bg' => '#FFFFFF',
567 'secondary_bg' => '#F0F2F5',
568 'secondary_content_bg' => '#f0f3f5',
569 'active_bg' => '#E7F3FF',
570 'light_bg' => '#F6F9FA',
571 'deep_bg' => '#18191A',
572 'menu_text' => '#65676B',
573 'primary_text' => '#050505',
574 'secondary_text' => '#65676B',
575 'text_off' => '#8A8D91',
576 'text_link' => '#216FDB',
577 'primary_button' => '#1877F2',
578 'primary_border' => '#DADDE1',
579 'secondary_border' => '#CED0D4',
580 'highlight_bg' => '#E7F3FF'
581 ],
582 'fcom_top_menu' => [
583 'primary_bg' => '#FFFFFF',
584 'primary_border' => '#DADDE1',
585 'menu_text' => '#65676B',
586 'menu_text_active' => '#1877F2',
587 'active_bg' => '#E7F3FF',
588 'menu_text_hover' => '#1877F2',
589 'menu_bg_hover' => '#E7F3FF',
590 ],
591 'spaces' => [
592 'primary_bg' => '#FFFFFF',
593 'primary_border' => '#DADDE1',
594 'menu_text' => '#65676B',
595 'menu_text_hover' => '#1877F2',
596 'menu_bg_hover' => '#E7F3FF',
597 'menu_text_active' => '#FFFFFF',
598 'active_bg' => '#1877F2'
599 ]
600 ]
601 ],
602 'sky_blue' => [
603 'title' => __('Sky Blue', 'fluent-community'),
604 'selectors' => [
605 'body' => [
606 'primary_bg' => '#FFFFFF',
607 'secondary_bg' => '#F7F9FA',
608 'secondary_content_bg' => '#f0f3f5',
609 'active_bg' => '#E8F5FD',
610 'light_bg' => '#F7F9FA',
611 'deep_bg' => '#15202B',
612 'menu_text' => '#536471',
613 'primary_text' => '#0F1419',
614 'secondary_text' => '#536471',
615 'text_off' => '#8899A6',
616 'text_link' => '#1D9BF0',
617 'primary_button' => '#1D9BF0',
618 'primary_border' => '#EFF3F4',
619 'secondary_border' => '#CFD9DE',
620 'highlight_bg' => '#E8F5FD'
621 ],
622 'fcom_top_menu' => [
623 'primary_bg' => '#FFFFFF',
624 'primary_border' => '#EFF3F4',
625 'menu_text' => '#536471',
626 'menu_text_active' => '#1D9BF0',
627 'active_bg' => '#E8F5FD',
628 'menu_bg_hover' => '#E8F5FD',
629 'menu_text_hover' => '#536471',
630 ],
631 'spaces' => [
632 'primary_bg' => '#FFFFFF',
633 'primary_border' => '#EFF3F4',
634 'menu_text' => '#536471',
635 'menu_text_hover' => '#1D9BF0',
636 'menu_bg_hover' => '#E8F5FD',
637 'menu_text_active' => '#FFFFFF',
638 'active_bg' => '#1D9BF0'
639 ]
640 ]
641 ],
642 'emerald_essence' => [
643 'title' => __('Emerald Essence', 'fluent-community'),
644 'selectors' => [
645 'body' => [
646 'primary_bg' => '#FFFFFF',
647 'secondary_bg' => '#F0F7F4',
648 'secondary_content_bg' => '#f0f3f5',
649 'active_bg' => '#E3F2ED',
650 'light_bg' => '#F7FAFA',
651 'deep_bg' => '#1A2B32',
652 'menu_text' => '#4A5D5E',
653 'primary_text' => '#1F2937',
654 'secondary_text' => '#4B5563',
655 'text_off' => '#9CA3AF',
656 'text_link' => '#059669',
657 'primary_button' => '#10B981',
658 'primary_border' => '#D1E7DD',
659 'secondary_border' => '#A7C4BC',
660 'highlight_bg' => '#ECFDF5'
661 ],
662 'fcom_top_menu' => [
663 'primary_bg' => '#FFFFFF',
664 'primary_border' => '#D1E7DD',
665 'menu_text' => '#4A5D5E',
666 'menu_text_active' => '#059669',
667 'active_bg' => '#ECFDF5',
668 'menu_bg_hover' => '#ECFDF5',
669 'menu_text_hover' => '#4A5D5E',
670 ],
671 'spaces' => [
672 'primary_bg' => '#FFFFFF',
673 'primary_border' => '#D1E7DD',
674 'menu_text' => '#4A5D5E',
675 'menu_text_hover' => '#059669',
676 'menu_bg_hover' => '#ECFDF5',
677 'menu_text_active' => '#FFFFFF',
678 'active_bg' => '#10B981'
679 ]
680 ]
681 ]
682 ],
683 'darkSkins' => [
684 'default' => [
685 'title' => __('Default (Dark)', 'fluent-community'),
686 'selectors' => [
687 'body' => [
688 'primary_bg' => '#2B2E33',
689 'secondary_bg' => '#191B1F',
690 'secondary_content_bg' => '#42464D',
691 'active_bg' => '#42464D',
692 'light_bg' => '#2B303B',
693 'deep_bg' => '#E1E4EA',
694 'menu_text' => '#E4E7EB',
695 'menu_text_active' => '#E4E7EB',
696 'primary_text' => '#F0F3F5',
697 'secondary_text' => '#99A0AE',
698 'menu_bg_hover' => '#E1E4EA',
699 'text_off' => '#A5A9AD',
700 'text_link' => '#60a5fa',
701 'primary_button' => '#FFFFFF',
702 'primary_border' => '#42464D',
703 'secondary_border' => '#A5A9AD',
704 'highlight_bg' => '#2c2c1a',
705 ],
706 'fcom_top_menu' => [
707 'primary_bg' => '#2B2E33',
708 'primary_border' => '#42464D',
709 'menu_text' => '#E4E7EB',
710 'menu_text_active' => '#E4E7EB',
711 'active_bg' => '#42464D',
712 'menu_bg_hover' => '#42464D',
713 'menu_text_hover' => '#E4E7EB',
714 ],
715 'spaces' => [
716 'primary_bg' => '#2B2E33',
717 'primary_border' => '#42464D',
718 'menu_text' => '#E4E7EB',
719 'menu_text_active' => '#E4E7EB',
720 'active_bg' => '#42464D',
721 'menu_bg_hover' => '#42464D',
722 'menu_text_hover' => '#fff',
723 ]
724 ],
725 ],
726 'sunset_sands' => [
727 'title' => __('Sunset Sands (Dark)', 'fluent-community'),
728 'selectors' => [
729 'body' => [
730 'primary_bg' => '#1A1A1A',
731 'secondary_bg' => '#222222',
732 'secondary_content_bg' => '#222222',
733 'active_bg' => '#2A2420',
734 'light_bg' => '#33302E',
735 'deep_bg' => '#111111',
736 'menu_text' => '#B0B0B0',
737 'primary_text' => '#E0E0E0',
738 'secondary_text' => '#A0A0A0',
739 'text_off' => '#707070',
740 'text_link' => '#F39C12',
741 'primary_button' => '#F39C12',
742 'primary_border' => '#3A3632',
743 'secondary_border' => '#4C4D4F',
744 'highlight_bg' => '#2A2420',
745 ],
746 'fcom_top_menu' => [
747 'primary_bg' => '#1A1A1A',
748 'primary_border' => '#3A3632',
749 'menu_text' => '#B0B0B0',
750 'menu_text_active' => '#F39C12',
751 'active_bg' => '#2A2420',
752 'menu_text_hover' => '#F39C12',
753 'menu_bg_hover' => '#2A2420',
754 ],
755 'spaces' => [
756 'primary_bg' => '#1A1A1A',
757 'primary_border' => '#3A3632',
758 'menu_text' => '#B0B0B0',
759 'menu_text_hover' => '#F39C12',
760 'menu_bg_hover' => '#2A2420',
761 'menu_text_active' => '#1A1A1A',
762 'active_bg' => '#F39C12',
763 ]
764 ]
765 ],
766 'ocean_blue' => [
767 'title' => __('Ocean Blue (Dark)', 'fluent-community'),
768 'selectors' => [
769 'body' => [
770 'primary_border' => '#3E4042',
771 'menu_text' => '#B0B3B8',
772 'menu_text_active' => '#2D88FF',
773 'active_bg' => '#263951',
774 'menu_text_hover' => '#2D88FF',
775 'menu_bg_hover' => '#263951',
776 'primary_bg' => '#2B2E33',
777 'secondary_content_bg' => '#42464D',
778 'secondary_bg' => '#191B1F',
779 'light_bg' => '#2B303B',
780 'deep_bg' => '#E1E4EA',
781 'primary_text' => '#F0F3F5',
782 'secondary_text' => '#99A0AE',
783 'text_off' => '#A5A9AD',
784 'primary_button' => '#FFFFFF',
785 'secondary_border' => '#A5A9AD',
786 'highlight_bg' => '#2c2c1a',
787 'text_link' => '#2d88ff',
788 ],
789 'fcom_top_menu' => [
790 'primary_bg' => '#242526',
791 'primary_border' => '#3E4042',
792 'menu_text' => '#B0B3B8',
793 'menu_text_active' => '#fff',
794 'active_bg' => '#263951',
795 'menu_text_hover' => '#fff',
796 'menu_bg_hover' => '#263951',
797 ],
798 'spaces' => [
799 'primary_bg' => '#242526',
800 'primary_border' => '#3E4042',
801 'menu_text' => '#B0B3B8',
802 'menu_text_hover' => '#2D88FF',
803 'menu_bg_hover' => '#263951',
804 'menu_text_active' => '#FFFFFF',
805 'active_bg' => '#2D88FF'
806 ]
807 ]
808 ],
809 'sky_blue' => [
810 'title' => __('Sky Blue (Dark)', 'fluent-community'),
811 'selectors' => [
812 'body' => [
813 'primary_bg' => '#15202B',
814 'secondary_bg' => '#1E2732',
815 'secondary_content_bg' => '#2C3640',
816 'active_bg' => '#1D2F41',
817 'light_bg' => '#22303C',
818 'deep_bg' => '#E7E9EA',
819 'menu_text' => '#8B98A5',
820 'primary_text' => '#E7E9EA',
821 'secondary_text' => '#8B98A5',
822 'text_off' => '#536471',
823 'text_link' => '#1D9BF0',
824 'primary_button' => '#1D9BF0',
825 'primary_border' => '#38444D',
826 'secondary_border' => '#536471',
827 'highlight_bg' => '#1D2F41'
828 ],
829 'fcom_top_menu' => [
830 'primary_bg' => '#15202B',
831 'primary_border' => '#38444D',
832 'menu_text' => '#8B98A5',
833 'menu_text_active' => '#1D9BF0',
834 'active_bg' => '#1D2F41',
835 'menu_bg_hover' => '#1D2F41',
836 'menu_text_hover' => '#E7E9EA',
837 ],
838 'spaces' => [
839 'primary_bg' => '#15202B',
840 'primary_border' => '#38444D',
841 'menu_text' => '#8B98A5',
842 'menu_text_hover' => '#1D9BF0',
843 'menu_bg_hover' => '#1D2F41',
844 'menu_text_active' => '#FFFFFF',
845 'active_bg' => '#1D9BF0'
846 ]
847 ]
848 ],
849 'emerald_essence' => [
850 'title' => __('Emerald Essence (Dark)', 'fluent-community'),
851 'selectors' => [
852 'body' => [
853 'primary_bg' => '#1A2B32',
854 'secondary_bg' => '#243B43',
855 'secondary_content_bg' => '#2C464F',
856 'active_bg' => '#1E3A31',
857 'light_bg' => '#2A3F48',
858 'deep_bg' => '#E2E8F0',
859 'menu_text' => '#A7BCBF',
860 'primary_text' => '#E2E8F0',
861 'secondary_text' => '#A7BCBF',
862 'text_off' => '#64748B',
863 'text_link' => '#34D399',
864 'primary_button' => '#10B981',
865 'primary_border' => '#2F4C41',
866 'secondary_border' => '#3D5C52',
867 'highlight_bg' => '#064E3B'
868 ],
869 'fcom_top_menu' => [
870 'primary_bg' => '#1A2B32',
871 'primary_border' => '#2F4C41',
872 'menu_text' => '#A7BCBF',
873 'menu_text_active' => '#34D399',
874 'active_bg' => '#064E3B',
875 'menu_bg_hover' => '#064E3B',
876 'menu_text_hover' => '#E2E8F0',
877 ],
878 'spaces' => [
879 'primary_bg' => '#1A2B32',
880 'primary_border' => '#2F4C41',
881 'menu_text' => '#A7BCBF',
882 'menu_text_hover' => '#34D399',
883 'menu_bg_hover' => '#064E3B',
884 'menu_text_active' => '#FFFFFF',
885 'active_bg' => '#10B981'
886 ]
887 ]
888 ]
889 ]
890 ]);
891
892 $customSchemaConfig = self::getColorConfig('edit');
893
894 $shemas['lightSkins']['custom'] = [
895 'title' => __('Custom', 'fluent-community'),
896 'selectors' => $customSchemaConfig['light_config'] ?? $defaultCustom
897 ];
898
899 $shemas['darkSkins']['custom'] = [
900 'title' => __('Custom', 'fluent-community'),
901 'selectors' => $customSchemaConfig['dark_config'] ?? $defaultCustom
902 ];
903
904 return $shemas;
905 }
906
907 public static function generateCss($sectors, $prefix = '')
908 {
909 if (!$sectors) {
910 return '';
911 }
912
913 $bodyPrefix = 'body';
914 if ($prefix) {
915 $bodyPrefix = $prefix . ' body';
916 }
917
918 $elementPlusMap = [
919 'primary_text' => '--el-color-primary',
920 'secondary_bg' => '--el-color-white'
921 ];
922
923 $css = '';
924 foreach ($sectors as $selector => $props) {
925 $isBody = $selector === 'body';
926 $prefix = $isBody ? $bodyPrefix : $bodyPrefix . ' .' . $selector;
927 $prefix .= '{';
928
929 $css .= $prefix;
930
931 foreach ($props as $prop => $value) {
932 $cssVar = '--fcom-' . str_replace('_', '-', $prop);
933 $css .= $cssVar . ':' . $value . ';';
934
935 if ($isBody && isset($elementPlusMap[$prop])) {
936 $css .= $elementPlusMap[$prop] . ':' . $value . ';';
937 }
938 }
939 $css .= '} ';
940 }
941
942 return $css;
943 }
944
945 public static function getColorConfig($context = 'view')
946 {
947 return apply_filters('fluent_community/color_schmea_config', [
948 'light_schema' => 'default',
949 'dark_schema' => 'default',
950 'light_config' => [
951 'body' => [],
952 'fcom_top_menu' => [],
953 'spaces' => []
954 ],
955 'dark_config' => [
956 'body' => [],
957 'fcom_top_menu' => [],
958 'spaces' => []
959 ],
960 'version' => FLUENT_COMMUNITY_PLUGIN_VERSION
961 ], $context);
962 }
963
964 public static function getColorCssVariables()
965 {
966 $customSchemaConfig = self::getColorConfig('view');
967
968 if (!empty($customSchemaConfig['cached_css'])) {
969 if ($customSchemaConfig['version'] != FLUENT_COMMUNITY_PLUGIN_VERSION) {
970 do_action('fluent_community/recache_color_schema');
971 }
972
973 return (string)$customSchemaConfig['cached_css'];
974 }
975
976 $schemas = self::getColorSchemas();
977
978 $lightName = Arr::get($customSchemaConfig, 'light_schema', 'default');
979 $darkName = Arr::get($customSchemaConfig, 'dark_schema', 'default');
980
981 $lightCss = self::generateCss(Arr::get($schemas, "lightSkins.$lightName.selectors"));
982 $darkCss = self::generateCss(Arr::get($schemas, "darkSkins.$darkName.selectors"), 'html.dark');
983 return $lightCss . $darkCss;
984 }
985
986 public static function getSuggestedColors()
987 {
988 $pallets = current((array)get_theme_support('editor-color-palette'));
989 if ($pallets) {
990 $colors = array_map(function ($color) {
991 return $color['color'];
992 }, $pallets);
993 } else {
994 $colors =
995 ['#000000', '#abb8c3', '#ffffff', '#f78da7', '#ff6900', '#fcb900', '#7bdcb5', '#00d084', '#8ed1fc', '#0693e3', '#9b51e0'];
996 }
997
998 return apply_filters('fluent_community/suggested_colors', $colors);
999 }
1000 }
1001