# fluent-community/1.0.98/app/Services/LockscreenService.php

FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS &amp; Online Courses, version 1.0.98. 129 lines.

- Page: https://pluginprobe.com/plugins/fluent-community/1.0.98/code/app/Services/LockscreenService.php
- Raw: https://pluginprobe.com/plugins/fluent-community/1.0.98/raw/app/Services/LockscreenService.php
- Modified: 2024-11-07T12:38:44+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/fluent-community/1.0.98/code/app/Services/LockscreenService.php#L10-L20`.

```php
<?php

namespace FluentCommunity\App\Services;

use FluentCommunity\App\Models\BaseSpace;
use FluentCommunity\Framework\Support\Arr;

class LockscreenService
{
    public static function getLockscreenSettings(BaseSpace $space)
    {
        $defaultSettings = [
            [
                'hidden'            => false,
                'type'              => 'image',
                'label'             => 'Banner',
                'name'              => 'banner',
                'heading'           => 'Banner Heading',
                'heading_color'     => '#FFFFFF',
                'description'       => 'Banner Description',
                'text_color'        => '#FFFFFF',
                'button_text'       => 'Buy Now',
                'button_link'       => '',
                'button_color'      => '#2B2E33',
                'button_text_color' => '#FFFFFF',
                'background_image'  => '',
                'overlay_color'     => '#798398'
            ],
            [
                'hidden'  => false,
                'type'    => 'block',
                'label'   => 'Description',
                'name'    => 'description',
                'content' => 'Description Test'
            ]
        ];

        if ($space->isCourseSpace()) {
            $defaultSettings[] = [
                'hidden' => true,
                'type'   => 'lesson',
                'label'  => 'Lessons',
                'name'   => 'lesson'
            ];
        }

        $defaultSettings[] = [
            'hidden'            => false,
            'type'              => 'image',
            'label'             => 'Call to action',
            'name'              => 'action',
            'heading'           => 'Call to Action Heading',
            'heading_color'     => '#FFFFFF',
            'description'       => 'Call to Action Description',
            'text_color'        => '#FFFFFF',
            'button_text'       => 'Buy Now',
            'button_link'       => '',
            'button_color'      => '#2B2E33',
            'button_text_color' => '#FFFFFF',
            'background_image'  => '',
            'overlay_color'     => '#798398'
        ];

        $settings = $space->getCustomMeta('lockscreen_settings', $defaultSettings);

        foreach ($settings as &$setting) {
            if ($setting['type'] === 'block' && !empty($setting['content'])) {
                $setting['content'] = do_blocks($setting['content']);
            }
        }

        return $settings;
    }

    public static function formatLockscreenFields($settingFields)
    {
        $textFields = ['type', 'name', 'label', 'heading', 'description', 'button_text', 'el_icon'];
        $colorFields = ['heading_color', 'text_color', 'button_color', 'button_text_color', 'overlay_color'];
        $urlFields = ['button_link', 'background_image'];

        $formattedFields = [];

        foreach ($settingFields as $value) {
            $textValues = array_map('sanitize_text_field', Arr::only($value, $textFields));
            $colorValues = array_map('sanitize_hex_color', Arr::only($value, $colorFields));
            $urlValues = array_map('sanitize_url', Arr::only($value, $urlFields));

            $formattedField = array_merge($textValues, $colorValues, $urlValues);

            $formattedField['hidden'] = Arr::isTrue($value, 'hidden');

            if ($value['type'] == 'block') {
                $formattedField['content'] = wp_kses_post(Arr::get($value, 'content'));
            }

            $formattedFields[] = $formattedField;
        }

        return $formattedFields;
    }

    public static function getLockscreenConfig(BaseSpace $space, $membership = null)
    {
        if ($space->privacy != 'private') {
            return null;
        }

        if($membership) {
            if($membership->pivot->status) {
                if($membership->pivot->status == 'pending') {
                    return [
                        'is_pending' => true
                    ];
                }
                return null;
            }
        }

        $showCustom = Arr::get($space->settings, 'custom_lock_screen', 'no') === 'yes';
        $canSendRequest = Arr::get($space->settings, 'can_request_join', 'no') === 'yes';

        return [
            'showCustom'     => $showCustom,
            'canSendRequest' => $canSendRequest,
            'lockScreen'     => $showCustom ? self::getLockscreenSettings($space) : null
        ];
    }
}

```
