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 | Modules/Auth/Classes/Invitation.php +55 -8 1.0.922.10.01 View file →
@@ -1,8 +1,9 @@
1 1 <?php
2 2
3 3 namespace FluentCommunity\Modules\Auth\Classes;
4 4
5 +use FluentCommunity\App\Functions\Utility;
5 6 use FluentCommunity\App\Models\Model;
6 7 use FluentCommunity\App\Models\BaseSpace;
7 8 use FluentCommunity\App\Models\User;
8 9 use FluentCommunity\App\Models\XProfile;
@@ -8,13 +9,29 @@
8 9 use FluentCommunity\App\Models\XProfile;
9 10 use FluentCommunity\App\Services\Helper;
10 11 use FluentCommunity\Framework\Support\Arr;
11 12
13 +/**
14 + * @property int $id
15 + * @property int|null $user_id
16 + * @property int|null $post_id
17 + * @property string|null $message
18 + * @property string|null $message_rendered
19 + * @property mixed $meta
20 + * @property string|null $type
21 + * @property int $reactions_count
22 + * @property string|null $status
23 + * @property string|null $created_at
24 + * @property string|null $updated_at
25 + * @property-read User|null $user
26 + * @property-read XProfile|null $xprofile
27 + * @property-read BaseSpace|null $space
28 + */
12 29 class Invitation extends Model
13 30 {
14 31 protected $table = 'fcom_post_comments';
15 32
16 - protected $guarded = ['id'];
33 + protected $guarded = [ 'id' ];
17 34
18 35 protected $fillable = [
19 36 'user_id',
20 37 'post_id',
@@ -24,19 +41,19 @@
24 41 'type',
25 42 'reactions_count',
26 43 'status',
27 44 'created_at',
28 - 'updated_at'
45 + 'updated_at',
29 46 ];
30 47
31 48 protected $searchable = [
32 - 'message'
49 + 'message',
33 50 ];
34 51
35 52 protected $hidden = [
36 53 'parent_id',
37 54 'content_type',
38 - 'is_sticky'
55 + 'is_sticky',
39 56 ];
40 57
41 58 public static function boot()
42 59 {
@@ -75,9 +92,9 @@
75 92 }
76 93
77 94 public function getMetaAttribute($value)
78 95 {
79 - $meta = maybe_unserialize($value);
96 + $meta = Utility::safeUnserialize($value);
80 97
81 98 if (!$meta) {
82 99 $meta = [
83 100 'invitee_name' => '',
@@ -95,9 +112,9 @@
95 112 if ($spaceId) {
96 113 $spaceRole = $user->getSpaceRole(BaseSpace::findOrFail($spaceId));
97 114 $query->where('post_id', $spaceId);
98 115
99 - if (!in_array($spaceRole, ['admin', 'moderator'])) {
116 + if (!in_array($spaceRole, [ 'admin', 'moderator' ])) {
100 117 $query->where('user_id', $user->ID);
101 118 }
102 119 } elseif (!$user->isCommunityModerator()) {
103 120 $query->where('user_id', $user->ID);
@@ -127,9 +144,9 @@
127 144 'user_id' => $inviteeId,
128 145 'post_id' => Arr::get($data, 'space_id'),
129 146 'message' => $data['email'],
130 147 'message_rendered' => $data['token'],
131 - 'meta' => ['role' => $data['role']],
148 + 'meta' => [ 'role' => $data['role'] ],
132 149 'type' => 'invitation',
133 150 'content_type' => $data['content_type'],
134 151 'status' => 'pending',
135 152 ]);
@@ -145,8 +162,38 @@
145 162 public function getAccessUrl()
146 163 {
147 164 return add_query_arg([
148 165 'fcom_action' => 'auth',
149 - 'invitation_token' => $this->message_rendered
166 + 'invitation_token' => $this->message_rendered,
150 167 ], Helper::baseUrl('/'));
168 + }
169 +
170 + public function isValid()
171 + {
172 + if ($this->message) {
173 + return $this->status == 'pending';
174 + }
175 +
176 + if ($this->status != 'active') {
177 + return false;
178 + }
179 +
180 + $meta = $this->meta;
181 +
182 + $expireDate = Arr::get($meta, 'expire_date', '');
183 + $limit = Arr::get($meta, 'limit', 0);
184 +
185 + if ($expireDate && strtotime($expireDate) < strtotime(gmdate('Y-m-d', current_time('timestamp')))) {
186 + $this->status = 'expired';
187 + $this->save();
188 + return false;
189 + }
190 +
191 + if ($limit && $this->reactions_count >= $limit) {
192 + $this->status = 'expired';
193 + $this->save();
194 + return false;
195 + }
196 +
197 + return true;
151 198 }
152 199 }