PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.11.0
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.11.0
2.11.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 All 78 releases
← All changes | app/Models/BaseSpace.php +75 -59 2.6.02.11.0 View file →
@@ -6,10 +6,34 @@
6 6 use FluentCommunity\App\Functions\Utility;
7 7 use FluentCommunity\App\Services\CustomSanitizer;
8 8 use FluentCommunity\App\Services\LockscreenService;
9 9 use FluentCommunity\App\Services\Helper;
10 +use FluentCommunity\App\Services\SpaceMenuService;
10 11 use FluentCommunity\Framework\Support\Arr;
11 12
13 +/**
14 + * @property int $id
15 + * @property int|null $created_by
16 + * @property int|null $parent_id
17 + * @property string $title
18 + * @property string $slug
19 + * @property string|null $description
20 + * @property string|null $logo
21 + * @property string|null $cover_photo
22 + * @property string|null $type
23 + * @property string|null $privacy
24 + * @property string|null $status
25 + * @property int|null $serial
26 + * @property array $settings
27 + * @property string|null $created_at
28 + * @property string|null $updated_at
29 + * @property array|null $permissions
30 + * @property string|null $description_rendered
31 + * @property mixed $membership
32 + * @property array|null $topics
33 + * @property array|null $header_links
34 + * @property array|null $lockscreen_config
35 + */
12 36 class BaseSpace extends Model
13 37 {
14 38 protected $table = 'fcom_spaces';
15 39
@@ -14,9 +38,9 @@
14 38 protected $table = 'fcom_spaces';
15 39
16 40 protected static $type = 'community';
17 41
18 - protected $guarded = ['id'];
42 + protected $guarded = [ 'id' ];
19 43
20 44 protected $fillable = [
21 45 'created_by',
22 46 'parent_id',
@@ -28,14 +52,14 @@
28 52 'type',
29 53 'privacy',
30 54 'status',
31 55 'serial',
32 - 'settings'
56 + 'settings',
33 57 ];
34 58
35 59 protected $searchable = [
36 60 'title',
37 - 'description'
61 + 'description',
38 62 ];
39 63
40 64 public $_preloadedMembershipUserId = null;
41 65 public $_preloadedMembership = null;
@@ -65,11 +89,11 @@
65 89 });
66 90
67 91 static::deleting(function ($space) {
68 92 Media::where('sub_object_id', $space->id)
69 - ->whereIn('object_source', ['space_logo', 'space_cover_photo'])
93 + ->whereIn('object_source', [ 'space_logo', 'space_cover_photo' ])
70 94 ->update([
71 - 'is_active' => 0
95 + 'is_active' => 0,
72 96 ]);
73 97 });
74 98 }
75 99
@@ -108,9 +132,9 @@
108 132 }
109 133
110 134 public function scopeOnlyMain($query)
111 135 {
112 - return $query->withoutGlobalScopes()->whereIn('type', ['community', 'course']);
136 + return $query->withoutGlobalScopes()->whereIn('type', [ 'community', 'course' ]);
113 137 }
114 138
115 139 public function scopeFilterByUserId($query, $userId)
116 140 {
@@ -153,15 +177,15 @@
153 177
154 178 public function members()
155 179 {
156 180 return $this->belongsToMany(User::class, 'fcom_space_user', 'space_id', 'user_id')
157 - ->withPivot(['role', 'created_at', 'status']);
181 + ->withPivot([ 'role', 'created_at', 'status' ]);
158 182 }
159 183
160 184 public function x_members()
161 185 {
162 186 return $this->belongsToMany(XProfile::class, 'fcom_space_user', 'space_id', 'user_id', 'id', 'user_id')
163 - ->withPivot(['role', 'created_at', 'status']);
187 + ->withPivot([ 'role', 'created_at', 'status' ]);
164 188 }
165 189
166 190 public function group()
167 191 {
@@ -196,9 +220,9 @@
196 220
197 221 foreach ($spaces as $space) {
198 222 $space->_preloadedMembershipUserId = $userId;
199 223 $pivot = $pivots->get($space->id);
200 - $space->_preloadedMembership = $pivot ? static::pivotToMembership($pivot) : null;
224 + $space->_preloadedMembership = $pivot ? self::pivotToMembership($pivot) : null;
201 225 }
202 226 }
203 227
204 228 private static function pivotToMembership($pivot)
@@ -219,9 +243,9 @@
219 243 if (Helper::isSiteAdmin($userId)) {
220 244 return true;
221 245 }
222 246
223 - $roles = ['admin'];
247 + $roles = [ 'admin' ];
224 248
225 249 if ($checkModerator) {
226 250 if (Helper::isModerator()) {
227 251 return true;
@@ -269,9 +293,9 @@
269 293 throw new \Exception(esc_html__('Invalid group id', 'fluent-community'), 400);
270 294 }
271 295 $this->parent_id = $group->id;
272 296 } else {
273 - $this->parent_id = NULL;
297 + $this->parent_id = null;
274 298 }
275 299 }
276 300
277 301 if (isset($data['settings'])) {
@@ -283,8 +307,9 @@
283 307 }
284 308
285 309 $exisitingSetting = $this->settings;
286 310 $settings['links'] = Arr::get($exisitingSetting, 'links', []);
311 + $settings[SpaceMenuService::SETTINGS_KEY] = Arr::get($exisitingSetting, SpaceMenuService::SETTINGS_KEY, []);
287 312
288 313 if (isset($settings['og_image'])) {
289 314 $ogImageUrl = Arr::get($settings, 'og_image');
290 315 if ($ogImageUrl) {
@@ -290,14 +315,14 @@
290 315 if ($ogImageUrl) {
291 316 $ogImageMedia = Helper::getMediaFromUrl($ogImageUrl);
292 317 if ($ogImageMedia && $ogImageMedia->is_active) {
293 318 unset($settings['og_image']);
294 - } else if ($ogImageMedia) {
319 + } elseif ($ogImageMedia) {
295 320 $ogImageMedia->update([
296 321 'is_active' => true,
297 322 'user_id' => get_current_user_id(),
298 323 'sub_object_id' => $this->id,
299 - 'object_source' => 'space_og_media'
324 + 'object_source' => 'space_og_media',
300 325 ]);
301 326 $settings['og_image'] = $ogImageMedia->public_url;
302 327 } else {
303 328 $settings['og_image'] = sanitize_url($ogImageUrl);
@@ -352,9 +377,9 @@
352 377 }
353 378
354 379 public function isContentSpace()
355 380 {
356 - return in_array($this->type, ['community', 'course']);
381 + return in_array($this->type, [ 'community', 'course' ]);
357 382 }
358 383
359 384 public function getSettingsAttribute($value)
360 385 {
@@ -363,9 +388,16 @@
363 388 if (!$settings) {
364 389 $settings = [];
365 390 }
366 391
367 - return wp_parse_args($settings, $this->defaultSettings());
392 + $settings = wp_parse_args($settings, $this->defaultSettings());
393 +
394 + if (!defined('FLUENT_COMMUNITY_PRO')) {
395 + $settings['document_library'] = 'no';
396 + $settings['media_gallery'] = 'no';
397 + }
398 +
399 + return $settings;
368 400 }
369 401
370 402 public function defaultSettings()
371 403 {
@@ -393,9 +425,10 @@
393 425 public function getPublicPermissions()
394 426 {
395 427 if ($this->privacy == 'public') {
396 428
397 - $hasDocuments = defined('FLUENT_COMMUNITY_PRO') && Arr::get($this->settings, 'document_library') == 'yes';
429 + $hasDocuments = defined('FLUENT_COMMUNITY_PRO') && Arr::get($this->settings, 'document_library') == 'yes';
430 + $hasMediaGallery = defined('FLUENT_COMMUNITY_PRO') && Arr::get($this->settings, 'media_gallery') == 'yes';
398 431
399 432 return [
400 433 'can_view_info' => true,
401 434 'can_view_posts' => true,
@@ -400,9 +433,10 @@
400 433 'can_view_info' => true,
401 434 'can_view_posts' => true,
402 435 'can_view_members' => $this->canViewMembers(null),
403 436 'can_create_post' => false,
404 - 'can_view_documents' => $hasDocuments && Arr::get($this->settings, 'document_access') == 'everybody'
437 + 'can_view_documents' => $hasDocuments && Arr::get($this->settings, 'document_access') == 'everybody',
438 + 'can_view_media' => $hasMediaGallery && Arr::get($this->settings, 'media_access') == 'everybody',
405 439 ];
406 440 }
407 441
408 442 return [
@@ -461,26 +495,30 @@
461 495 {
462 496 return $this->updateCustomMeta('lockscreen_settings', $settingFields);
463 497 }
464 498
499 + /**
500 + * Sidebar links, emails, invitations, canonical URLs and API payloads all resolve
501 + * through here, so the filter moves every one of them together.
502 + *
503 + * @return string
504 + */
465 505 public function getPermalink()
466 506 {
507 + $permalink = Helper::baseUrl('/');
508 +
467 509 if ($this->type == 'community') {
468 - return Helper::baseUrl('space/' . $this->slug . '/home');
469 - }
470 -
471 - if ($this->type == 'course') {
472 - return Helper::baseUrl('course/' . $this->slug . '/lessons');
473 - }
474 -
475 - if ($this->type == 'sidebar_link') {
476 - $permalink = Arr::get($this->settings, 'permalink');
477 - if ($permalink) {
478 - return $permalink;
510 + $permalink = Helper::baseUrl('space/' . $this->slug . '/home');
511 + } elseif ($this->type == 'course') {
512 + $permalink = Helper::baseUrl('course/' . $this->slug . '/lessons');
513 + } elseif ($this->type == 'sidebar_link') {
514 + $customLink = Arr::get($this->settings, 'permalink');
515 + if ($customLink) {
516 + $permalink = $customLink;
479 517 }
480 518 }
481 519
482 - return Helper::baseUrl('/');
520 + return apply_filters('fluent_community/space_permalink', $permalink, $this);
483 521 }
484 522
485 523 public function getLockscreen()
486 524 {
@@ -508,16 +546,16 @@
508 546 return '';
509 547 }
510 548
511 549 if ($this->logo) {
512 - return '<img alt="" src="' . $this->logo . '"/>';
550 + return '<img alt="" src="' . esc_url($this->logo) . '"/>';
513 551 }
514 552
515 - if ($imoji = Arr::get($this->settings, 'emoji')) {
553 + if ($imoji = Arr::get($this->settings, 'emoji')) { // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure
516 554 return '<span class="fcom_emoji">' . $imoji . '</span>';
517 555 }
518 556
519 - if ($svg = Arr::get($this->settings, 'shape_svg')) {
557 + if ($svg = Arr::get($this->settings, 'shape_svg')) { // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure
520 558 return '<span class="fcom_shape"><i class="el-icon">' . $svg . '</i></span>';
521 559 }
522 560
523 561 return '';
@@ -543,9 +581,9 @@
543 581 // We have to create one
544 582 $new = Meta::create([
545 583 'object_id' => $topicId,
546 584 'meta_key' => $this->id, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
547 - 'object_type' => 'term_space_relation'
585 + 'object_type' => 'term_space_relation',
548 586 ]);
549 587
550 588 $existIds[] = $new->id;
551 589 }
@@ -589,10 +627,10 @@
589 627 while (self::withoutGlobalScopes()->where('slug', $slug)->exists()) {
590 628 if ($count == 5) {
591 629 $count = time();
592 630 }
593 - $slug = $title . '-' . ++$slugNum;
594 - $count++;
631 + $slug = $title . '-' . (++$slugNum);
632 + ++$count;
595 633 }
596 634
597 635 return $slug;
598 636 }
@@ -605,28 +643,10 @@
605 643 $this->description_rendered = wpautop($this->description);
606 644 $this->membership = $this->getMembership($userId);
607 645 $this->topics = Utility::getTopicsBySpaceId($this->id);
608 646
609 - $headerLinks = [
610 - [
611 - 'title' => __('Posts', 'fluent-community'),
612 - 'route' => [
613 - 'name' => 'space_feeds',
614 - ]
615 - ]
616 - ];
647 + $this->header_links = SpaceMenuService::getMenuLinks($this, $user);
617 648
618 - if (Arr::get($this->permissions, 'can_view_members')) {
619 - $headerLinks[] = [
620 - 'title' => __('Members', 'fluent-community'),
621 - 'route' => [
622 - 'name' => 'space_members',
623 - ]
624 - ];
625 - }
626 -
627 - $this->header_links = apply_filters('fluent_community/space_header_links', $headerLinks, $this);
628 -
629 649 if ($this->isAdmin($userId, true)) {
630 650 return $this;
631 651 }
632 652
@@ -633,13 +653,9 @@
633 653 $this->lockscreen_config = LockscreenService::getLockscreenConfig($this, $this->membership, true);
634 654
635 655 $spaceSettings = $this->settings;
636 656
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 - }));
657 + $spaceSettings['links'] = Helper::filterAccessibleLinks(Arr::get($spaceSettings, 'links', []), $user);
642 658
643 659 $this->settings = $spaceSettings;
644 660
645 661 return $this;