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/BaseSpace.php +62 -33 2.5.02.10.0 View file →
@@ -8,8 +8,31 @@
8 8 use FluentCommunity\App\Services\LockscreenService;
9 9 use FluentCommunity\App\Services\Helper;
10 10 use FluentCommunity\Framework\Support\Arr;
11 11
12 +/**
13 + * @property int $id
14 + * @property int|null $created_by
15 + * @property int|null $parent_id
16 + * @property string $title
17 + * @property string $slug
18 + * @property string|null $description
19 + * @property string|null $logo
20 + * @property string|null $cover_photo
21 + * @property string|null $type
22 + * @property string|null $privacy
23 + * @property string|null $status
24 + * @property int|null $serial
25 + * @property array $settings
26 + * @property string|null $created_at
27 + * @property string|null $updated_at
28 + * @property array|null $permissions
29 + * @property string|null $description_rendered
30 + * @property mixed $membership
31 + * @property array|null $topics
32 + * @property array|null $header_links
33 + * @property array|null $lockscreen_config
34 + */
12 35 class BaseSpace extends Model
13 36 {
14 37 protected $table = 'fcom_spaces';
15 38
@@ -14,9 +37,9 @@
14 37 protected $table = 'fcom_spaces';
15 38
16 39 protected static $type = 'community';
17 40
18 - protected $guarded = ['id'];
41 + protected $guarded = [ 'id' ];
19 42
20 43 protected $fillable = [
21 44 'created_by',
22 45 'parent_id',
@@ -28,14 +51,14 @@
28 51 'type',
29 52 'privacy',
30 53 'status',
31 54 'serial',
32 - 'settings'
55 + 'settings',
33 56 ];
34 57
35 58 protected $searchable = [
36 59 'title',
37 - 'description'
60 + 'description',
38 61 ];
39 62
40 63 public $_preloadedMembershipUserId = null;
41 64 public $_preloadedMembership = null;
@@ -65,11 +88,11 @@
65 88 });
66 89
67 90 static::deleting(function ($space) {
68 91 Media::where('sub_object_id', $space->id)
69 - ->whereIn('object_source', ['space_logo', 'space_cover_photo'])
92 + ->whereIn('object_source', [ 'space_logo', 'space_cover_photo' ])
70 93 ->update([
71 - 'is_active' => 0
94 + 'is_active' => 0,
72 95 ]);
73 96 });
74 97 }
75 98
@@ -108,9 +131,9 @@
108 131 }
109 132
110 133 public function scopeOnlyMain($query)
111 134 {
112 - return $query->withoutGlobalScopes()->whereIn('type', ['community', 'course']);
135 + return $query->withoutGlobalScopes()->whereIn('type', [ 'community', 'course' ]);
113 136 }
114 137
115 138 public function scopeFilterByUserId($query, $userId)
116 139 {
@@ -153,15 +176,15 @@
153 176
154 177 public function members()
155 178 {
156 179 return $this->belongsToMany(User::class, 'fcom_space_user', 'space_id', 'user_id')
157 - ->withPivot(['role', 'created_at', 'status']);
180 + ->withPivot([ 'role', 'created_at', 'status' ]);
158 181 }
159 182
160 183 public function x_members()
161 184 {
162 185 return $this->belongsToMany(XProfile::class, 'fcom_space_user', 'space_id', 'user_id', 'id', 'user_id')
163 - ->withPivot(['role', 'created_at', 'status']);
186 + ->withPivot([ 'role', 'created_at', 'status' ]);
164 187 }
165 188
166 189 public function group()
167 190 {
@@ -196,9 +219,9 @@
196 219
197 220 foreach ($spaces as $space) {
198 221 $space->_preloadedMembershipUserId = $userId;
199 222 $pivot = $pivots->get($space->id);
200 - $space->_preloadedMembership = $pivot ? static::pivotToMembership($pivot) : null;
223 + $space->_preloadedMembership = $pivot ? self::pivotToMembership($pivot) : null;
201 224 }
202 225 }
203 226
204 227 private static function pivotToMembership($pivot)
@@ -219,9 +242,9 @@
219 242 if (Helper::isSiteAdmin($userId)) {
220 243 return true;
221 244 }
222 245
223 - $roles = ['admin'];
246 + $roles = [ 'admin' ];
224 247
225 248 if ($checkModerator) {
226 249 if (Helper::isModerator()) {
227 250 return true;
@@ -265,13 +288,13 @@
265 288 if (isset($data['parent_id'])) {
266 289 if (!empty($data['parent_id'])) {
267 290 $group = SpaceGroup::find($data['parent_id']);
268 291 if (!$group) {
269 - throw new \Exception('Invalid group id', 400);
292 + throw new \Exception(esc_html__('Invalid group id', 'fluent-community'), 400);
270 293 }
271 294 $this->parent_id = $group->id;
272 295 } else {
273 - $this->parent_id = NULL;
296 + $this->parent_id = null;
274 297 }
275 298 }
276 299
277 300 if (isset($data['settings'])) {
@@ -290,14 +313,14 @@
290 313 if ($ogImageUrl) {
291 314 $ogImageMedia = Helper::getMediaFromUrl($ogImageUrl);
292 315 if ($ogImageMedia && $ogImageMedia->is_active) {
293 316 unset($settings['og_image']);
294 - } else if ($ogImageMedia) {
317 + } elseif ($ogImageMedia) {
295 318 $ogImageMedia->update([
296 319 'is_active' => true,
297 320 'user_id' => get_current_user_id(),
298 321 'sub_object_id' => $this->id,
299 - 'object_source' => 'space_og_media'
322 + 'object_source' => 'space_og_media',
300 323 ]);
301 324 $settings['og_image'] = $ogImageMedia->public_url;
302 325 } else {
303 326 $settings['og_image'] = sanitize_url($ogImageUrl);
@@ -352,9 +375,9 @@
352 375 }
353 376
354 377 public function isContentSpace()
355 378 {
356 - return in_array($this->type, ['community', 'course']);
379 + return in_array($this->type, [ 'community', 'course' ]);
357 380 }
358 381
359 382 public function getSettingsAttribute($value)
360 383 {
@@ -363,9 +386,16 @@
363 386 if (!$settings) {
364 387 $settings = [];
365 388 }
366 389
367 - return wp_parse_args($settings, $this->defaultSettings());
390 + $settings = wp_parse_args($settings, $this->defaultSettings());
391 +
392 + if (!defined('FLUENT_COMMUNITY_PRO')) {
393 + $settings['document_library'] = 'no';
394 + $settings['media_gallery'] = 'no';
395 + }
396 +
397 + return $settings;
368 398 }
369 399
370 400 public function defaultSettings()
371 401 {
@@ -393,9 +423,10 @@
393 423 public function getPublicPermissions()
394 424 {
395 425 if ($this->privacy == 'public') {
396 426
397 - $hasDocuments = defined('FLUENT_COMMUNITY_PRO') && Arr::get($this->settings, 'document_library') == 'yes';
427 + $hasDocuments = defined('FLUENT_COMMUNITY_PRO') && Arr::get($this->settings, 'document_library') == 'yes';
428 + $hasMediaGallery = defined('FLUENT_COMMUNITY_PRO') && Arr::get($this->settings, 'media_gallery') == 'yes';
398 429
399 430 return [
400 431 'can_view_info' => true,
401 432 'can_view_posts' => true,
@@ -400,9 +431,10 @@
400 431 'can_view_info' => true,
401 432 'can_view_posts' => true,
402 433 'can_view_members' => $this->canViewMembers(null),
403 434 'can_create_post' => false,
404 - 'can_view_documents' => $hasDocuments && Arr::get($this->settings, 'document_access') == 'everybody'
435 + 'can_view_documents' => $hasDocuments && Arr::get($this->settings, 'document_access') == 'everybody',
436 + 'can_view_media' => $hasMediaGallery && Arr::get($this->settings, 'media_access') == 'everybody',
405 437 ];
406 438 }
407 439
408 440 return [
@@ -449,9 +481,10 @@
449 481
450 482 $hasPermission = $permissions[$permission] ?? false;
451 483
452 484 if (!$hasPermission && $exception) {
453 - throw new \Exception('Sorry you do not have permission ' . esc_html($permission), 403);
485 + /* translators: %s is the permission name */
486 + throw new \Exception(esc_html(sprintf(__('Sorry you do not have permission %s', 'fluent-community'), $permission)), 403);
454 487 }
455 488
456 489 return $hasPermission;
457 490 }
@@ -507,16 +540,16 @@
507 540 return '';
508 541 }
509 542
510 543 if ($this->logo) {
511 - return '<img alt="" src="' . $this->logo . '"/>';
544 + return '<img alt="" src="' . esc_url($this->logo) . '"/>';
512 545 }
513 546
514 - if ($imoji = Arr::get($this->settings, 'emoji')) {
547 + if ($imoji = Arr::get($this->settings, 'emoji')) { // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure
515 548 return '<span class="fcom_emoji">' . $imoji . '</span>';
516 549 }
517 550
518 - if ($svg = Arr::get($this->settings, 'shape_svg')) {
551 + if ($svg = Arr::get($this->settings, 'shape_svg')) { // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure
519 552 return '<span class="fcom_shape"><i class="el-icon">' . $svg . '</i></span>';
520 553 }
521 554
522 555 return '';
@@ -542,9 +575,9 @@
542 575 // We have to create one
543 576 $new = Meta::create([
544 577 'object_id' => $topicId,
545 578 'meta_key' => $this->id, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
546 - 'object_type' => 'term_space_relation'
579 + 'object_type' => 'term_space_relation',
547 580 ]);
548 581
549 582 $existIds[] = $new->id;
550 583 }
@@ -588,10 +621,10 @@
588 621 while (self::withoutGlobalScopes()->where('slug', $slug)->exists()) {
589 622 if ($count == 5) {
590 623 $count = time();
591 624 }
592 - $slug = $title . '-' . ++$slugNum;
593 - $count++;
625 + $slug = $title . '-' . (++$slugNum);
626 + ++$count;
594 627 }
595 628
596 629 return $slug;
597 630 }
@@ -609,10 +642,10 @@
609 642 [
610 643 'title' => __('Posts', 'fluent-community'),
611 644 'route' => [
612 645 'name' => 'space_feeds',
613 - ]
614 - ]
646 + ],
647 + ],
615 648 ];
616 649
617 650 if (Arr::get($this->permissions, 'can_view_members')) {
618 651 $headerLinks[] = [
@@ -618,9 +651,9 @@
618 651 $headerLinks[] = [
619 652 'title' => __('Members', 'fluent-community'),
620 653 'route' => [
621 654 'name' => 'space_members',
622 - ]
655 + ],
623 656 ];
624 657 }
625 658
626 659 $this->header_links = apply_filters('fluent_community/space_header_links', $headerLinks, $this);
@@ -632,13 +665,9 @@
632 665 $this->lockscreen_config = LockscreenService::getLockscreenConfig($this, $this->membership, true);
633 666
634 667 $spaceSettings = $this->settings;
635 668
636 - $spaceLinks = Arr::get($spaceSettings, 'links', []);
637 -
638 - $spaceSettings['links'] = array_values(array_filter($spaceLinks, function ($item) use ($user) {
639 - return Helper::isLinkAccessible($item, $user);
640 - }));
669 + $spaceSettings['links'] = Helper::filterAccessibleLinks(Arr::get($spaceSettings, 'links', []), $user);
641 670
642 671 $this->settings = $spaceSettings;
643 672
644 673 return $this;