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/Models/Comment.php +37 -19 2.7.02.10.0 View file →
@@ -7,16 +7,36 @@
7 7 use FluentCommunity\App\Models\Activity;
8 8 use FluentCommunity\App\Services\FeedsHelper;
9 9 use FluentCommunity\App\Services\Helper;
10 10
11 +/**
12 + * @property int $id
13 + * @property int|null $user_id
14 + * @property int|null $post_id
15 + * @property int|null $parent_id
16 + * @property string|null $message
17 + * @property string|null $message_rendered
18 + * @property mixed $meta
19 + * @property string|null $type
20 + * @property string|null $content_type
21 + * @property string|null $status
22 + * @property int|null $is_sticky
23 + * @property int $reactions_count
24 + * @property string|null $created_at
25 + * @property string|null $updated_at
26 + * @property-read User|null $user
27 + * @property-read XProfile|null $xprofile
28 + * @property-read Feed|null $post
29 + * @property-read mixed $media
30 + */
11 31 class Comment extends Model
12 32 {
13 33 protected $table = 'fcom_post_comments';
14 34
15 - protected $guarded = ['id'];
35 + protected $guarded = [ 'id' ];
16 36
17 37 protected $casts = [
18 - 'is_sticky' => 'int'
38 + 'is_sticky' => 'int',
19 39 ];
20 40
21 41 protected $fillable = [
22 42 'user_id',
@@ -30,13 +50,13 @@
30 50 'status',
31 51 'is_sticky',
32 52 'reactions_count',
33 53 'created_at',
34 - 'updated_at'
54 + 'updated_at',
35 55 ];
36 56
37 57 protected $searchable = [
38 - 'message'
58 + 'message',
39 59 ];
40 60
41 61 public static function boot()
42 62 {
@@ -57,9 +77,9 @@
57 77 static::deleting(function ($comment) {
58 78 Media::where('sub_object_id', $comment->id)
59 79 ->where('object_source', 'comment')
60 80 ->update([
61 - 'is_active' => 0
81 + 'is_active' => 0,
62 82 ]);
63 83
64 84 $comment->reactions()->delete();
65 85
@@ -152,9 +172,9 @@
152 172 if (
153 173 $user->hasCommunityModeratorAccess() ||
154 174 ($space && $user->hasSpacePermission('edit_any_comment', $space))
155 175 ) {
156 - return $query->whereIn('status', ['published', 'pending']);
176 + return $query->whereIn('status', [ 'published', 'pending' ]);
157 177 }
158 178
159 179 // This is a normal User.
160 180 return $query->where(function ($q) use ($user) {
@@ -175,11 +195,11 @@
175 195 if (!$this->parent_id) {
176 196 return [];
177 197 }
178 198
179 - $parentComment = Comment::select(['user_id'])->find($this->parent_id);
180 - $allUserIds = Comment::where('parent_id', $this->parent_id)
181 - ->select(['user_id'])
199 + $parentComment = self::select([ 'user_id' ])->find($this->parent_id);
200 + $allUserIds = self::where('parent_id', $this->parent_id)
201 + ->select([ 'user_id' ])
182 202 ->distinct('user_id')
183 203 ->when($lastUserId, function ($query) use ($lastUserId) {
184 204 $query->where('user_id', '>', $lastUserId);
185 205 })
@@ -208,9 +228,9 @@
208 228 if (!$meta) {
209 229 $meta = [];
210 230 }
211 231
212 - return $meta;
232 + return Helper::sanitizeStoredMediaPreview($meta);
213 233 }
214 234
215 235 public function getHumanExcerpt($length = 30)
216 236 {
@@ -232,16 +252,14 @@
232 252 } else {
233 253 /* translators: %1$s is the post title and %2$s is the comment author name */
234 254 $emailSubject = \sprintf(__('New reply of a comment in a post on %1$s - %2$s', 'fluent-community'), $this->post->getHumanExcerpt(40), $this->xprofile->display_name);
235 255 }
236 - } else {
237 - if ($feed->title) {
256 + } elseif ($feed->title) {
238 257 /* translators: %1$s is the feed title and %2$s is the comment author name */
239 258 $emailSubject = \sprintf(__('New comment on %1$s - %2$s', 'fluent-community'), $feed->title, $this->xprofile->display_name);
240 - } else {
241 - /* translators: %1$s is the post title and %2$s is the comment author name */
242 - $emailSubject = \sprintf(__('New comment on a post on %1$s - %2$s', 'fluent-community'), $this->post->getHumanExcerpt(40), $this->xprofile->display_name);
243 - }
259 + } else {
260 + /* translators: %1$s is the post title and %2$s is the comment author name */
261 + $emailSubject = \sprintf(__('New comment on a post on %1$s - %2$s', 'fluent-community'), $this->post->getHumanExcerpt(40), $this->xprofile->display_name);
244 262 }
245 263
246 264 return $emailSubject;
247 265 }
@@ -267,18 +285,18 @@
267 285 $renderedMessage = preg_replace('/<a href="([^"]+)">([^<]+)<\/a>/', '<span style="text-decoration: underline !important;">$2</span>', $renderedMessage);
268 286
269 287 $renderedMessage .= FeedsHelper::getMediaHtml($this->meta, $postPermalink);
270 288
271 - $buttonText = $buttonText ?: __('View the comment', 'fluent-community');
289 + $buttonText = $buttonText ? $buttonText : __('View the comment', 'fluent-community');
272 290
273 291 $emailComposer->addBlock('boxed_content', $renderedMessage, [
274 292 'user' => $this->user,
275 293 'permalink' => $postPermalink,
276 - 'post_content' => $postTitle
294 + 'post_content' => $postTitle,
277 295 ]);
278 296
279 297 $emailComposer->addBlock('button', $buttonText, [
280 - 'link' => $postPermalink
298 + 'link' => $postPermalink,
281 299 ]);
282 300
283 301 $emailComposer->setDefaultLogo();
284 302 $emailComposer->setDefaultFooter($withPlaceholder);