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/Models/BaseSpace.php +59 -31 2.6.012.10.01 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;
@@ -269,9 +292,9 @@
269 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 [
@@ -508,16 +540,16 @@
508 540 return '';
509 541 }
510 542
511 543 if ($this->logo) {
512 - return '<img alt="" src="' . $this->logo . '"/>';
544 + return '<img alt="" src="' . esc_url($this->logo) . '"/>';
513 545 }
514 546
515 - if ($imoji = Arr::get($this->settings, 'emoji')) {
547 + if ($imoji = Arr::get($this->settings, 'emoji')) { // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure
516 548 return '<span class="fcom_emoji">' . $imoji . '</span>';
517 549 }
518 550
519 - if ($svg = Arr::get($this->settings, 'shape_svg')) {
551 + if ($svg = Arr::get($this->settings, 'shape_svg')) { // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure
520 552 return '<span class="fcom_shape"><i class="el-icon">' . $svg . '</i></span>';
521 553 }
522 554
523 555 return '';
@@ -543,9 +575,9 @@
543 575 // We have to create one
544 576 $new = Meta::create([
545 577 'object_id' => $topicId,
546 578 'meta_key' => $this->id, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
547 - 'object_type' => 'term_space_relation'
579 + 'object_type' => 'term_space_relation',
548 580 ]);
549 581
550 582 $existIds[] = $new->id;
551 583 }
@@ -589,10 +621,10 @@
589 621 while (self::withoutGlobalScopes()->where('slug', $slug)->exists()) {
590 622 if ($count == 5) {
591 623 $count = time();
592 624 }
593 - $slug = $title . '-' . ++$slugNum;
594 - $count++;
625 + $slug = $title . '-' . (++$slugNum);
626 + ++$count;
595 627 }
596 628
597 629 return $slug;
598 630 }
@@ -610,10 +642,10 @@
610 642 [
611 643 'title' => __('Posts', 'fluent-community'),
612 644 'route' => [
613 645 'name' => 'space_feeds',
614 - ]
615 - ]
646 + ],
647 + ],
616 648 ];
617 649
618 650 if (Arr::get($this->permissions, 'can_view_members')) {
619 651 $headerLinks[] = [
@@ -619,9 +651,9 @@
619 651 $headerLinks[] = [
620 652 'title' => __('Members', 'fluent-community'),
621 653 'route' => [
622 654 'name' => 'space_members',
623 - ]
655 + ],
624 656 ];
625 657 }
626 658
627 659 $this->header_links = apply_filters('fluent_community/space_header_links', $headerLinks, $this);
@@ -633,13 +665,9 @@
633 665 $this->lockscreen_config = LockscreenService::getLockscreenConfig($this, $this->membership, true);
634 666
635 667 $spaceSettings = $this->settings;
636 668
637 - $spaceLinks = Arr::get($spaceSettings, 'links', []);
638 -
639 - $spaceSettings['links'] = array_values(array_filter($spaceLinks, function ($item) use ($user) {
640 - return Helper::isLinkAccessible($item, $user);
641 - }));
669 + $spaceSettings['links'] = Helper::filterAccessibleLinks(Arr::get($spaceSettings, 'links', []), $user);
642 670
643 671 $this->settings = $spaceSettings;
644 672
645 673 return $this;