PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.10.01
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.10.01
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/MembersController.php +44 -22 1.0.972.10.01 View file →
@@ -13,9 +13,9 @@
13 13 class MembersController extends Controller
14 14 {
15 15 public function getMembers(Request $request)
16 16 {
17 - $canAccess = Utility::canViewMembersPage();
17 + $start = microtime(true);
18 18 $mention = $request->getSafe('mention', 'sanitize_text_field');
19 19 if($mention && !get_current_user_id()) {
20 20 return $this->sendError([
21 21 'message' => __('You must be logged in to mention someone', 'fluent-community'),
@@ -21,8 +21,11 @@
21 21 'message' => __('You must be logged in to mention someone', 'fluent-community'),
22 22 ]);
23 23 }
24 24
25 + $canAccess = Utility::canViewMembersPage();
26 + $isMod = Helper::isModerator();
27 +
25 28 $members = XProfile::select(ProfileHelper::getXProfilePublicFields())
26 29 ->whereHas('user');
27 30
28 31 if($mention) {
@@ -36,15 +39,16 @@
36 39 'permission_failed' => true
37 40 ]);
38 41 }
39 42 }
43 +
40 44 if (!$space) {
41 45 $spaceId = $request->getSafe('space_id', 'intval');
42 46 if ($spaceId) {
43 - $space = BaseSpace::find($spaceId);
47 + $space = BaseSpace::withoutGlobalScopes()->find($spaceId);
44 48 if (!$space || !Helper::isUserInSpace(get_current_user_id(), $space->id)) {
45 49 return $this->sendError([
46 - 'message' => 'Space not found',
50 + 'message' => __('Space not found', 'fluent-community'),
47 51 'permission_failed' => true
48 52 ]);
49 53 }
50 54 }
@@ -51,9 +55,9 @@
51 55 }
52 56
53 57 if ($space) {
54 58 $members = $members->whereHas('spaces', function ($query) use ($space) {
55 - $query->where('space_id', $space->id);
59 + $query->withoutGlobalScopes()->where('space_id', $space->id);
56 60 });
57 61 }
58 62
59 63 $members = $members->where('status', 'active')
@@ -61,13 +65,15 @@
61 65 ->mentionBy($mention)
62 66 ->limit(10)
63 67 ->get();
64 68
65 - return [
69 + $data = [
66 70 'members' => [
67 71 'data' => $members
68 - ]
72 + ],
73 + 'execution_time' => microtime(true) - $start
69 74 ];
75 + return apply_filters('fluent_community/mention_members_api_response', $data, $request->all());
70 76 }
71 77
72 78 if(!$canAccess) {
73 79 return $this->sendError([
@@ -75,24 +81,39 @@
75 81 'permission_failed' => true
76 82 ]);
77 83 }
78 84
79 - $shortBy = $request->getSafe('sort_by', 'sanitize_text_field', 'last_activity');
85 + $sortBy = $request->getSafe('sort_by', 'sanitize_text_field', 'last_activity');
80 86
81 - if ($shortBy == 'last_activity') {
82 - $members = $members->orderBy('last_activity', 'DESC');
83 - } else {
84 - $members = $members->orderBy($shortBy, 'ASC');
85 - }
87 + $validSortFields = ['last_activity', 'display_name', 'created_at'];
86 88
89 + $sortColumn = in_array($sortBy, $validSortFields, true) ? $sortBy : 'last_activity';
90 +
91 + $defaultDirections = [
92 + 'last_activity' => 'DESC',
93 + 'display_name' => 'ASC',
94 + 'created_at' => 'DESC',
95 + ];
96 +
97 + $sortDir = strtoupper($request->getSafe('sort_dir', 'sanitize_text_field', ''));
98 +
99 + $sortDirection = in_array($sortDir, ['ASC', 'DESC'], true)
100 + ? $sortDir
101 + : $defaultDirections[$sortColumn];
102 +
103 + $members = $members->orderBy($sortColumn, $sortDirection);
104 +
87 105 $members = $members
88 - ->searchBy($request->getSafe('search', 'sanitize_text_field'))
89 - ->orderBy('last_activity', 'DESC');
106 + ->searchBy($request->getSafe('search', 'sanitize_text_field'));
90 107
91 - if(Helper::isModerator()) {
108 + if($isMod) {
92 109 $statuses = $request->getSafe('status', 'sanitize_text_field', 'active');
93 - if ($statuses == 'in_active') {
94 - $statuses = ['pending', 'blocked'];
110 + if ($statuses == 'pending') {
111 + $statuses = ['pending'];
112 + } else if ($statuses == 'blocked') {
113 + $statuses = ['blocked'];
114 + } else if($statuses == 'deactivated') {
115 + $statuses = [''];
95 116 } else {
96 117 $statuses = ['active'];
97 118 }
98 119 $members = $members->whereIn('status', $statuses);
@@ -103,11 +124,12 @@
103 124 do_action_ref_array('fluent_community/members_query_ref', [&$members, $request->all()]);
104 125
105 126 $members = $members->paginate();
106 127
107 - return [
108 - 'members' => $members
109 - ];
128 + return apply_filters('fluent_community/members_api_response', [
129 + 'members' => $members,
130 + 'execution_time' => microtime(true) - $start
131 + ], $members, $request->all());
110 132 }
111 133
112 134 public function patchMember(Request $request, $userId)
113 135 {
@@ -119,9 +141,9 @@
119 141 $wpUser = User::findOrFail($userId);
120 142
121 143 if ($wpUser->isCommunityAdmin() && $newStatus != 'active') {
122 144 return $this->sendError([
123 - 'message' => 'Sorry, you can not change status of another admin. Remove the user from moderators'
145 + 'message' => __('Sorry, you cannot change the status of another admin. Remove the user from moderators', 'fluent-community')
124 146 ]);
125 147 }
126 148
127 149 $xProfile = XProfile::findOrFail($userId);
@@ -134,9 +156,9 @@
134 156 $xProfile->save();
135 157 }
136 158
137 159 return [
138 - 'message' => __('Member status have been updated', 'fluent-community'),
160 + 'message' => __('Member status has been updated', 'fluent-community'),
139 161 'member' => $xProfile
140 162 ];
141 163 }
142 164 }