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/SpaceController.php +72 -12 2.7.02.10.0 View file →
@@ -159,9 +159,10 @@
159 159 $q->where('user_id', get_current_user_id());
160 160 }])
161 161 ->where(function ($q) {
162 162 $q->whereHas('space_pivot', function ($q) {
163 - $q->where('user_id', get_current_user_id());
163 + $q->where('user_id', get_current_user_id())
164 + ->where('status', 'active');
164 165 })
165 166 ->orWhereIn('privacy', ['public', 'private']);
166 167 })
167 168 ->when($type == 'joined', function ($q) {
@@ -208,11 +209,23 @@
208 209 }
209 210
210 211 public function getAllSpaces(Request $request)
211 212 {
212 - $spaces = Space::paginate();
213 + $currentUser = $this->getUser();
213 214
214 - $currentUser = $this->getUser();
215 + $spacesQuery = Space::query();
216 +
217 + if (!($currentUser && $currentUser->isCommunityModerator())) {
218 + $spacesQuery->where(function ($q) {
219 + $q->whereHas('space_pivot', function ($q) {
220 + $q->where('user_id', get_current_user_id())
221 + ->where('status', 'active');
222 + })
223 + ->orWhereIn('privacy', ['public', 'private']);
224 + });
225 + }
226 + $spaces = $spacesQuery->paginate();
227 +
215 228 $memberCounts = $this->getActiveMemberCounts($spaces->pluck('id')->toArray());
216 229
217 230 foreach ($spaces as $space) {
218 231 $shouldHideMembersCount = Arr::get($space->settings, 'hide_members_count') == 'yes';
@@ -374,8 +387,9 @@
374 387 }
375 388
376 389 public function getMembers(Request $request, $slug)
377 390 {
391 + /** @var Space $space */
378 392 $space = Space::where('slug', $slug)
379 393 ->firstOrFail();
380 394
381 395 $user = $this->getUser();
@@ -413,20 +427,37 @@
413 427 ], $pendingRequests, $request->all());
414 428 }
415 429 }
416 430
431 + $defaultDirections = [
432 + 'last_activity' => 'DESC',
433 + 'display_name' => 'ASC',
434 + 'created_at' => 'DESC',
435 + ];
436 +
437 + $sortBy = $request->getSafe('sort_by', 'sanitize_text_field', 'created_at');
438 + $sortColumn = in_array($sortBy, array_keys($defaultDirections), true) ? $sortBy : 'created_at';
439 + $sortDir = strtoupper($request->getSafe('sort_dir', 'sanitize_text_field', ''));
440 + $sortDirection = in_array($sortDir, ['ASC', 'DESC'], true) ? $sortDir : ($sortColumn === 'created_at' ? 'ASC' : $defaultDirections[$sortColumn]);
441 +
442 + $profileSort = $sortColumn !== 'created_at';
443 + $orderColumn = $profileSort ? 'fcom_xprofile.' . $sortColumn : 'fcom_space_user.created_at';
444 +
417 445 $spaceMembers = SpaceUserPivot::bySpace($space->id)
418 446 ->whereHas('xprofile', function ($q) use ($search) {
419 - return $q->searchBy($search)
420 - ->where('status', 'active');
447 + $q->searchBy($search)->where('status', 'active');
421 448 })
449 + ->where('fcom_space_user.status', 'active')
422 450 ->with(['xprofile' => function ($q) {
423 451 $q->select(ProfileHelper::getXProfilePublicFields());
424 452 }])
425 - ->where('status', 'active')
426 - ->orderBy('created_at', 'ASC')
453 + ->when($profileSort, function ($q) {
454 + $q->join('fcom_xprofile', 'fcom_xprofile.user_id', '=', 'fcom_space_user.user_id')
455 + ->select('fcom_space_user.*');
456 + })
457 + ->orderBy($orderColumn, $sortDirection)
427 458 ->paginate();
428 -
459 +
429 460 return apply_filters('fluent_community/space_members_api_response', [
430 461 'members' => $spaceMembers,
431 462 'pending_count' => $pendingCount
432 463 ], $spaceMembers, $request->all());
@@ -722,8 +753,12 @@
722 753 $userIds = $userQuery->get()
723 754 ->pluck('ID')
724 755 ->toArray();
725 756
757 + if ($userIds) {
758 + update_meta_cache('user', $userIds);
759 + }
760 +
726 761 $users = User::select($selects)
727 762 ->whereIn('ID', $userIds)
728 763 ->paginate(100);
729 764
@@ -817,13 +852,28 @@
817 852 'title' => 'required|unique:fcom_spaces,title',
818 853 'slug' => 'required|unique:fcom_spaces,slug'
819 854 ]);
820 855
856 + $title = sanitize_text_field(Arr::get($data, 'title', ''));
857 + $slug = sanitize_title(Arr::get($data, 'slug', ''));
858 + $desc = sanitize_textarea_field(Arr::get($data, 'description', ''));
821 859
860 + if (!$title) {
861 + return $this->sendError([
862 + 'message' => __('Please enter a valid group title.', 'fluent-community')
863 + ]);
864 + }
865 +
866 + if (!$slug) {
867 + return $this->sendError([
868 + 'message' => __('Please enter a valid group slug.', 'fluent-community')
869 + ]);
870 + }
871 +
822 872 $formattedData = [
823 - 'title' => sanitize_text_field($data['title']),
824 - 'slug' => sanitize_title($data['slug']),
825 - 'description' => sanitize_textarea_field($data['description']),
873 + 'title' => $title,
874 + 'slug' => $slug,
875 + 'description' => $desc,
826 876 'status' => 'active',
827 877 'type' => 'space_group',
828 878 'settings' => [
829 879 'always_show_spaces' => Arr::get($data, 'settings.always_show_spaces', 'yes'),
@@ -944,9 +994,19 @@
944 994 }
945 995
946 996 public function getLockScreenSettings(Request $request, $spaceSlug)
947 997 {
948 - $space = Space::where('slug', $spaceSlug)->firstOrFail();
998 + /** @var Space $space */
999 + $space = Space::where('slug', $spaceSlug)->first();
1000 +
1001 + $userId = $this->getUser() ? $this->getUser()->ID : null;
1002 +
1003 + if (!$space || ($space->privacy == 'secret' && !$space->getMembership($userId) && !$space->isAdmin($userId, true))) {
1004 + return $this->sendError([
1005 + 'message' => __('Space not found', 'fluent-community')
1006 + ], 404);
1007 + }
1008 +
949 1009 $lockscreen = $space->getLockscreen();
950 1010
951 1011 $lockscreen = apply_filters('fluent_community/get_lockscreen_settings', $lockscreen, $space);
952 1012