| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCommunity\App\Services; |
| 4 |
|
| 5 |
use FluentCommunity\App\Models\BaseSpace; |
| 6 |
use FluentCommunity\Framework\Support\Arr; |
| 7 |
|
| 8 |
class LockscreenService |
| 9 |
{ |
| 10 |
public static function getLockscreenSettings(BaseSpace $space) |
| 11 |
{ |
| 12 |
$defaultSettings = [ |
| 13 |
[ |
| 14 |
'hidden' => false, |
| 15 |
'type' => 'image', |
| 16 |
'label' => 'Banner', |
| 17 |
'name' => 'banner', |
| 18 |
'heading' => 'Banner Heading', |
| 19 |
'heading_color' => '#FFFFFF', |
| 20 |
'description' => 'Banner Description', |
| 21 |
'text_color' => '#FFFFFF', |
| 22 |
'button_text' => 'Buy Now', |
| 23 |
'button_link' => '', |
| 24 |
'button_color' => '#2B2E33', |
| 25 |
'button_text_color' => '#FFFFFF', |
| 26 |
'background_image' => '', |
| 27 |
'overlay_color' => '#798398' |
| 28 |
], |
| 29 |
[ |
| 30 |
'hidden' => false, |
| 31 |
'type' => 'block', |
| 32 |
'label' => 'Description', |
| 33 |
'name' => 'description', |
| 34 |
'content' => 'Description Test' |
| 35 |
] |
| 36 |
]; |
| 37 |
|
| 38 |
if ($space->isCourseSpace()) { |
| 39 |
$defaultSettings[] = [ |
| 40 |
'hidden' => true, |
| 41 |
'type' => 'lesson', |
| 42 |
'label' => 'Lessons', |
| 43 |
'name' => 'lesson' |
| 44 |
]; |
| 45 |
} |
| 46 |
|
| 47 |
$defaultSettings[] = [ |
| 48 |
'hidden' => false, |
| 49 |
'type' => 'image', |
| 50 |
'label' => 'Call to action', |
| 51 |
'name' => 'action', |
| 52 |
'heading' => 'Call to Action Heading', |
| 53 |
'heading_color' => '#FFFFFF', |
| 54 |
'description' => 'Call to Action Description', |
| 55 |
'text_color' => '#FFFFFF', |
| 56 |
'button_text' => 'Buy Now', |
| 57 |
'button_link' => '', |
| 58 |
'button_color' => '#2B2E33', |
| 59 |
'button_text_color' => '#FFFFFF', |
| 60 |
'background_image' => '', |
| 61 |
'overlay_color' => '#798398' |
| 62 |
]; |
| 63 |
|
| 64 |
$settings = $space->getCustomMeta('lockscreen_settings', $defaultSettings); |
| 65 |
|
| 66 |
foreach ($settings as &$setting) { |
| 67 |
if ($setting['type'] === 'block' && !empty($setting['content'])) { |
| 68 |
$setting['content'] = do_blocks($setting['content']); |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
return $settings; |
| 73 |
} |
| 74 |
|
| 75 |
public static function formatLockscreenFields($settingFields) |
| 76 |
{ |
| 77 |
$textFields = ['type', 'name', 'label', 'heading', 'description', 'button_text', 'el_icon']; |
| 78 |
$colorFields = ['heading_color', 'text_color', 'button_color', 'button_text_color', 'overlay_color']; |
| 79 |
$urlFields = ['button_link', 'background_image']; |
| 80 |
|
| 81 |
$formattedFields = []; |
| 82 |
|
| 83 |
foreach ($settingFields as $value) { |
| 84 |
$textValues = array_map('sanitize_text_field', Arr::only($value, $textFields)); |
| 85 |
$colorValues = array_map('sanitize_hex_color', Arr::only($value, $colorFields)); |
| 86 |
$urlValues = array_map('sanitize_url', Arr::only($value, $urlFields)); |
| 87 |
|
| 88 |
$formattedField = array_merge($textValues, $colorValues, $urlValues); |
| 89 |
|
| 90 |
$formattedField['hidden'] = Arr::isTrue($value, 'hidden'); |
| 91 |
|
| 92 |
if ($value['type'] == 'block') { |
| 93 |
$formattedField['content'] = wp_kses_post(Arr::get($value, 'content')); |
| 94 |
} |
| 95 |
|
| 96 |
$formattedFields[] = $formattedField; |
| 97 |
} |
| 98 |
|
| 99 |
return $formattedFields; |
| 100 |
} |
| 101 |
|
| 102 |
public static function getLockscreenConfig(BaseSpace $space, $membership = null) |
| 103 |
{ |
| 104 |
if ($space->privacy != 'private') { |
| 105 |
return null; |
| 106 |
} |
| 107 |
|
| 108 |
if($membership) { |
| 109 |
if($membership->pivot->status) { |
| 110 |
if($membership->pivot->status == 'pending') { |
| 111 |
return [ |
| 112 |
'is_pending' => true |
| 113 |
]; |
| 114 |
} |
| 115 |
return null; |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
$showCustom = Arr::get($space->settings, 'custom_lock_screen', 'no') === 'yes'; |
| 120 |
$canSendRequest = Arr::get($space->settings, 'can_request_join', 'no') === 'yes'; |
| 121 |
|
| 122 |
return [ |
| 123 |
'showCustom' => $showCustom, |
| 124 |
'canSendRequest' => $canSendRequest, |
| 125 |
'lockScreen' => $showCustom ? self::getLockscreenSettings($space) : null |
| 126 |
]; |
| 127 |
} |
| 128 |
} |
| 129 |
|