| @@ -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 | { |
| @@ -409,9 +432,9 @@ | ||
| 409 | 432 | 'can_view_posts' => true, |
| 410 | 433 | 'can_view_members' => $this->canViewMembers(null), |
| 411 | 434 | 'can_create_post' => false, |
| 412 | 435 | 'can_view_documents' => $hasDocuments && Arr::get($this->settings, 'document_access') == 'everybody', |
| 413 | - 'can_view_media' => $hasMediaGallery && Arr::get($this->settings, 'media_access') == 'everybody' | |
| 436 | + 'can_view_media' => $hasMediaGallery && Arr::get($this->settings, 'media_access') == 'everybody', | |
| 414 | 437 | ]; |
| 415 | 438 | } |
| 416 | 439 | |
| 417 | 440 | return [ |
| @@ -517,16 +540,16 @@ | ||
| 517 | 540 | return ''; |
| 518 | 541 | } |
| 519 | 542 | |
| 520 | 543 | if ($this->logo) { |
| 521 | - return '<img alt="" src="' . $this->logo . '"/>'; | |
| 544 | + return '<img alt="" src="' . esc_url($this->logo) . '"/>'; | |
| 522 | 545 | } |
| 523 | 546 | |
| 524 | - if ($imoji = Arr::get($this->settings, 'emoji')) { | |
| 547 | + if ($imoji = Arr::get($this->settings, 'emoji')) { // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure | |
| 525 | 548 | return '<span class="fcom_emoji">' . $imoji . '</span>'; |
| 526 | 549 | } |
| 527 | 550 | |
| 528 | - if ($svg = Arr::get($this->settings, 'shape_svg')) { | |
| 551 | + if ($svg = Arr::get($this->settings, 'shape_svg')) { // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure | |
| 529 | 552 | return '<span class="fcom_shape"><i class="el-icon">' . $svg . '</i></span>'; |
| 530 | 553 | } |
| 531 | 554 | |
| 532 | 555 | return ''; |
| @@ -552,9 +575,9 @@ | ||
| 552 | 575 | // We have to create one |
| 553 | 576 | $new = Meta::create([ |
| 554 | 577 | 'object_id' => $topicId, |
| 555 | 578 | 'meta_key' => $this->id, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key |
| 556 | - 'object_type' => 'term_space_relation' | |
| 579 | + 'object_type' => 'term_space_relation', | |
| 557 | 580 | ]); |
| 558 | 581 | |
| 559 | 582 | $existIds[] = $new->id; |
| 560 | 583 | } |
| @@ -598,10 +621,10 @@ | ||
| 598 | 621 | while (self::withoutGlobalScopes()->where('slug', $slug)->exists()) { |
| 599 | 622 | if ($count == 5) { |
| 600 | 623 | $count = time(); |
| 601 | 624 | } |
| 602 | - $slug = $title . '-' . ++$slugNum; | |
| 603 | - $count++; | |
| 625 | + $slug = $title . '-' . (++$slugNum); | |
| 626 | + ++$count; | |
| 604 | 627 | } |
| 605 | 628 | |
| 606 | 629 | return $slug; |
| 607 | 630 | } |
| @@ -619,10 +642,10 @@ | ||
| 619 | 642 | [ |
| 620 | 643 | 'title' => __('Posts', 'fluent-community'), |
| 621 | 644 | 'route' => [ |
| 622 | 645 | 'name' => 'space_feeds', |
| 623 | - ] | |
| 624 | - ] | |
| 646 | + ], | |
| 647 | + ], | |
| 625 | 648 | ]; |
| 626 | 649 | |
| 627 | 650 | if (Arr::get($this->permissions, 'can_view_members')) { |
| 628 | 651 | $headerLinks[] = [ |
| @@ -628,9 +651,9 @@ | ||
| 628 | 651 | $headerLinks[] = [ |
| 629 | 652 | 'title' => __('Members', 'fluent-community'), |
| 630 | 653 | 'route' => [ |
| 631 | 654 | 'name' => 'space_members', |
| 632 | - ] | |
| 655 | + ], | |
| 633 | 656 | ]; |
| 634 | 657 | } |
| 635 | 658 | |
| 636 | 659 | $this->header_links = apply_filters('fluent_community/space_header_links', $headerLinks, $this); |
| @@ -642,13 +665,9 @@ | ||
| 642 | 665 | $this->lockscreen_config = LockscreenService::getLockscreenConfig($this, $this->membership, true); |
| 643 | 666 | |
| 644 | 667 | $spaceSettings = $this->settings; |
| 645 | 668 | |
| 646 | - $spaceLinks = Arr::get($spaceSettings, 'links', []); | |
| 647 | - | |
| 648 | - $spaceSettings['links'] = array_values(array_filter($spaceLinks, function ($item) use ($user) { | |
| 649 | - return Helper::isLinkAccessible($item, $user); | |
| 650 | - })); | |
| 669 | + $spaceSettings['links'] = Helper::filterAccessibleLinks(Arr::get($spaceSettings, 'links', []), $user); | |
| 651 | 670 | |
| 652 | 671 | $this->settings = $spaceSettings; |
| 653 | 672 | |
| 654 | 673 | return $this; |