PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.10.0
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.10.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
← All changes | app/Http/Controllers/ProfileController.php +49 -32 2.8.02.10.0 View file →
@@ -4,9 +4,8 @@
4 4
5 5 use FluentCommunity\App\Functions\Utility;
6 6 use FluentCommunity\App\Models\Comment;
7 7 use FluentCommunity\App\Models\Feed;
8 -use FluentCommunity\App\Models\NotificationSubscription;
9 8 use FluentCommunity\App\Models\Space;
10 9 use FluentCommunity\App\Models\SpaceGroup;
11 10 use FluentCommunity\App\Models\SpaceUserPivot;
12 11 use FluentCommunity\App\Models\XProfile;
@@ -19,8 +18,9 @@
19 18 use FluentCommunity\Framework\Support\Arr;
20 19 use FluentCommunity\Modules\Course\Model\CourseLesson;
21 20 use FluentCommunity\Modules\Course\Model\CourseTopic;
22 21 use FluentCommunity\Modules\Course\Services\CourseHelper;
22 +use FluentCommunity\Modules\PushNotification\PushNotificationModule;
23 23 use FluentCommunity\Framework\Foundation\Exceptions\HttpException;
24 24
25 25 class ProfileController extends Controller
26 26 {
@@ -75,9 +75,9 @@
75 75 $isAdmin = Helper::isSiteAdmin($currentUserId);
76 76
77 77 if ($isOwn || $isAdmin) {
78 78 $enableUserSync = Utility::getPrivacySetting('enable_user_sync') === 'yes';
79 - $nameArray = explode(' ', trim($xprofile->display_name));
79 + $nameArray = explode(' ', trim((string) $xprofile->display_name));
80 80 $xprofileFirstName = array_shift($nameArray);
81 81 $xprofileLastName = implode(' ', $nameArray);
82 82
83 83 $profile['email'] = $user->user_email;
@@ -205,9 +205,9 @@
205 205
206 206 if (isset($updateData['avatar'])) {
207 207
208 208 if ($xprofile->hasCustomAvatar()) {
209 - $deletedMedias[] = $xprofile->attributes['avatar'];
209 + $deletedMedias[] = Arr::get($xprofile->getAttributes(), 'avatar');
210 210 }
211 211
212 212 $xprofile->avatar = $updateData['avatar'];
213 213
@@ -312,10 +312,13 @@
312 312 $userNameChanged = $userName != $xProfile->username;
313 313 }
314 314
315 315 if (Helper::isFeatureEnabled('user_badge')) {
316 - $badgeSlug = (array)Arr::get($data, 'badge_slugs', []);
317 - $meta['badge_slug'] = $badgeSlug;
316 + $badgeSlug = array_filter((array) Arr::get($data, 'badge_slugs', []), 'is_scalar');
317 + $badgeSlug = array_map('sanitize_text_field', $badgeSlug);
318 +
319 + $definedBadges = (array) Utility::getOption('user_badges', []);
320 + $meta['badge_slug'] = array_values(array_intersect($badgeSlug, array_keys($definedBadges)));
318 321 }
319 322 } else if (Utility::getPrivacySetting('can_customize_username')) {
320 323 $userName = Arr::get($data, 'username');
321 324
@@ -352,10 +355,10 @@
352 355 }
353 356
354 357 $updateData['display_name'] = trim(sanitize_text_field(Arr::get($data, 'first_name') . ' ' . Arr::get($data, 'last_name')));
355 358
356 - $updateData['short_description'] = CustomSanitizer::unslashMarkdown(sanitize_textarea_field(trim(Arr::get($data, 'short_description'))));
357 - $meta['website'] = sanitize_url(Arr::get($data, 'website'));
359 + $updateData['short_description'] = CustomSanitizer::unslashMarkdown(sanitize_textarea_field(trim((string) Arr::get($data, 'short_description', ''))));
360 + $meta['website'] = sanitize_url((string) Arr::get($data, 'website', ''));
358 361 $meta['headline'] = sanitize_text_field(trim(Arr::get($data, 'headline', '')));
359 362 $socialLinks = Arr::get($data, 'social_links', []);
360 363
361 364 $maxDescriptionLength = apply_filters('fluent_community/max_profile_description_length', 5000);
@@ -721,43 +724,47 @@
721 724 $xProfile = $this->verifyAndGetProfile($userName);
722 725
723 726 $globalPreferances = NotificationPref::getGlobalPrefs();
724 727
725 - $userPrefs = NotificationSubscription::where('user_id', $xProfile->user_id)
726 - ->select(['notification_type', 'is_read', 'object_id'])
727 - ->get();
728 + // Read through the same service the save path writes through. These rows
729 + // live in fcom_notification_prefs, keyed by flat keys - space-scoped ones
730 + // carry an '_<space id>' suffix.
731 + $userPrefs = NotificationPref::getUserPrefs($xProfile->user_id);
728 732
733 + $frequencyMaps = [
734 + 0 => 'disabled',
735 + 1 => 'hourly',
736 + 2 => 'daily',
737 + 3 => 'weekly'
738 + ];
739 +
729 740 $userGlobalPrefs = [];
730 741 $spaceWisePrefs = [];
731 - foreach ($userPrefs as $pref) {
732 - if (!$pref->object_id) {
733 - if ($pref->notification_type === 'message_email_frequency') {
734 - $maps = [
735 - 0 => 'disabled',
736 - 1 => 'hourly',
737 - 2 => 'daily',
738 - 3 => 'weekly'
739 - ];
742 + foreach ($userPrefs as $prefKey => $prefValue) {
743 + if ($prefKey === 'message_email_frequency') {
744 + $userGlobalPrefs[$prefKey] = isset($frequencyMaps[$prefValue]) ? $frequencyMaps[$prefValue] : 'default';
745 + continue;
746 + }
740 747
741 - if (isset($maps[$pref->is_read])) {
742 - $userGlobalPrefs[$pref->notification_type] = $maps[$pref->is_read];
743 - } else {
744 - $userGlobalPrefs[$pref->notification_type] = 'default';
745 - }
746 - continue;
748 + if (preg_match('/^(np_by_(?:member|admin)_mail)_(\d+)$/', $prefKey, $matches)) {
749 + $spaceId = (int)$matches[2];
750 +
751 + if (empty($spaceWisePrefs[$spaceId])) {
752 + $spaceWisePrefs[$spaceId] = [];
747 753 }
748 - $userGlobalPrefs[$pref->notification_type] = $pref->is_read ? 'yes' : 'no';
749 - } else {
750 - if (empty($spaceWisePrefs[$pref->object_id])) {
751 - $spaceWisePrefs[$pref->object_id] = [];
752 - }
753 - $spaceWisePrefs[$pref->object_id][$pref->notification_type] = $pref->is_read;
754 +
755 + $spaceWisePrefs[$spaceId][$matches[1]] = $prefValue;
756 + continue;
754 757 }
758 +
759 + $userGlobalPrefs[$prefKey] = $prefValue ? 'yes' : 'no';
755 760 }
756 761
757 762 $messagingConfig = Utility::getOption('_messaging_settings', []);
758 763 $isGlobalPerUser = Arr::get($messagingConfig, 'messaging_email_frequency') == 'disabled';
759 764
765 + $pushAvailable = PushNotificationModule::isAvailable();
766 +
760 767 $userGlobalPrefsDefaults = [
761 768 'digest_mail' => Arr::get($globalPreferances, 'digest_email_status') ? 'yes' : 'no',
762 769 'mention_mail' => Arr::get($globalPreferances, 'mention_mail') ? 'yes' : 'no',
763 770 'reply_my_com_mail' => Arr::get($globalPreferances, 'reply_my_com_mail') ? 'yes' : 'no',
@@ -764,8 +771,17 @@
764 771 'com_my_post_mail' => Arr::get($globalPreferances, 'com_my_post_mail') ? 'yes' : 'no',
765 772 'message_email_frequency' => $isGlobalPerUser ? 'disabled' : 'default'
766 773 ];
767 774
775 + if ($pushAvailable) {
776 + $pushPreferances = NotificationPref::getGlobalPrefs('push');
777 +
778 + $userGlobalPrefsDefaults['com_my_post_push'] = Arr::get($pushPreferances, 'com_my_post_push') ? 'yes' : 'no';
779 + $userGlobalPrefsDefaults['reply_my_com_push'] = Arr::get($pushPreferances, 'reply_my_com_push') ? 'yes' : 'no';
780 + $userGlobalPrefsDefaults['mention_push'] = Arr::get($pushPreferances, 'mention_push') ? 'yes' : 'no';
781 + $userGlobalPrefsDefaults['co_com_push'] = Arr::get($pushPreferances, 'co_com_push') ? 'yes' : 'no';
782 + }
783 +
768 784 $userGlobalPrefs = wp_parse_args($userGlobalPrefs, $userGlobalPrefsDefaults);
769 785
770 786 $profileUserId = $xProfile->user_id;
771 787 $spaceGroups = SpaceGroup::with(['spaces' => function ($query) use ($profileUserId) {
@@ -878,8 +894,9 @@
878 894 'space_prefs' => $spaceWisePrefs,
879 895 'digestEmailDay' => $digestDay,
880 896 'default_messaging_email_frequency' => Arr::get($messagingConfig, 'messaging_email_status') !== 'yes' ? 'no' : Arr::get($messagingConfig, 'messaging_email_frequency'),
881 897 'crm_email_status' => $crmEmailStatus,
898 + 'push_available' => $pushAvailable,
882 899 ];
883 900
884 901 return apply_filters('fluent_community/profile_notification_pref_api_response', $data, $request->all());
885 902 }
@@ -996,9 +1013,9 @@
996 1013 {
997 1014 $xProfile = XProfile::where('username', $userName)->firstOrFail();
998 1015
999 1016 if (!get_current_user_id() || $xProfile->user_id != get_current_user_id()) {
1000 - throw new HttpException(403, __('You are not allowed to access these notification preferences.', 'fluent-community'));
1017 + throw new HttpException(403, esc_html__('You are not allowed to access these notification preferences.', 'fluent-community'));
1001 1018 }
1002 1019
1003 1020 return $xProfile;
1004 1021 }