PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.5.0
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.5.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 1.1.0 All 77 releases
fluent-community / app / Services / LockscreenService.php

LockscreenService.php in FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses 2.5.0, at app/Services/LockscreenService.php

195 lines 7.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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, $viewOnly = false)
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 'new_tab' => 'no'
29 ],
30 [
31 'hidden' => false,
32 'type' => 'block',
33 'label' => 'Description',
34 'name' => 'description',
35 'content' => '<!-- wp:paragraph --><p>Description</p><!-- /wp:paragraph -->',
36 ]
37 ];
38
39 if ($space->isCourseSpace()) {
40 $defaultSettings[] = [
41 'hidden' => true,
42 'type' => 'lesson',
43 'label' => 'Lessons',
44 'name' => 'lesson'
45 ];
46 }
47
48 $defaultSettings[] = [
49 'hidden' => false,
50 'type' => 'image',
51 'label' => 'Call to action',
52 'name' => 'action',
53 'heading' => 'Call to Action Heading',
54 'heading_color' => '#FFFFFF',
55 'description' => 'Call to Action Description',
56 'text_color' => '#FFFFFF',
57 'button_text' => 'Buy Now',
58 'button_link' => '',
59 'button_color' => '#2B2E33',
60 'button_text_color' => '#FFFFFF',
61 'background_image' => '',
62 'overlay_color' => '#798398',
63 'new_tab' => 'no'
64 ];
65
66 $settings = (array) $space->getCustomMeta('lockscreen_settings', $defaultSettings);
67
68 foreach ($settings as &$setting) {
69 if ($viewOnly && $setting['type'] === 'block' && !empty($setting['content'])) {
70 $user = Helper::getCurrentUser();
71 $content = apply_filters('the_content', $setting['content']); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
72 $setting['content'] = (new SmartCodeParser())->parse($content, $user);
73 }
74
75 if ($setting['type'] == 'image' && empty($setting['new_tab'])) {
76 $setting['new_tab'] = 'no';
77 }
78 }
79
80 return apply_filters('fluent_community/lockscreen_fields', $settings, $space);
81 }
82
83 public static function formatLockscreenFields($settingFields, $space)
84 {
85 $currentSettings = self::getLockscreenSettings($space);
86
87 $textFields = ['type', 'name', 'label', 'heading', 'description', 'button_text', 'heading_color', 'text_color', 'button_color', 'button_text_color', 'overlay_color', 'new_tab', 'background_color'];
88 $urlFields = ['button_link'];
89
90 $formattedFields = [];
91
92 foreach ($settingFields as $value) {
93 $textValues = array_map('sanitize_text_field', Arr::only($value, $textFields));
94 $urlValues = array_map('sanitize_url', Arr::only($value, $urlFields));
95
96 $formattedField = array_merge($textValues, $urlValues);
97
98 $formattedField['hidden'] = Arr::isTrue($value, 'hidden');
99
100 if ($value['type'] == 'block') {
101 $formattedField['content'] = CustomSanitizer::santizeEditorBody(Arr::get($value, 'content'));
102 }
103
104 if (isset($value['background_image'])) {
105 $bgImage = sanitize_url($value['background_image']);
106 $fieldName = Arr::get($value, 'name');
107 $currentImage = self::getCurrentImage($currentSettings, $fieldName);
108 $bgImageUrl = self::handleMediaUrl($bgImage, $currentImage, $fieldName, $space->id);
109 $formattedField['background_image'] = $bgImageUrl;
110 }
111
112 $formattedFields[] = apply_filters('fluent_community/lockscreen_formatted_field', $formattedField, $value, $space);
113 }
114
115 return $formattedFields;
116 }
117
118 public static function getLockscreenConfig(BaseSpace $space, $membership = null, $viewOnly = false)
119 {
120 if ($space->privacy != 'private') {
121 return null;
122 }
123
124 if($membership) {
125 if($membership->pivot->status) {
126 if($membership->pivot->status == 'pending') {
127 return [
128 'is_pending' => true
129 ];
130 }
131 return null;
132 }
133 }
134
135 $showCustom = Arr::get($space->settings, 'custom_lock_screen', 'no') === 'yes';
136 $showPaywalls = Arr::get($space->settings, 'show_paywalls', 'no') === 'yes' && defined('FLUENTCART_VERSION');
137 $canSendRequest = Arr::get($space->settings, 'can_request_join', 'no') === 'yes';
138
139 $isRedirect = Arr::get($space->settings, 'custom_lock_screen', 'no') == 'redirect' && Arr::get($space->settings, 'onboard_redirect_url', false);
140 $redirectUrl = '';
141 if($isRedirect) {
142 $redirectUrl = Arr::get($space->settings, 'onboard_redirect_url', false);
143 }
144
145 return [
146 'showCustom' => $showCustom,
147 'showPaywalls' => $showPaywalls,
148 'canSendRequest' => $canSendRequest,
149 'lockScreen' => $showCustom ? self::getLockscreenSettings($space, $viewOnly) : null,
150 'redirect_url' => $redirectUrl
151 ];
152 }
153
154 protected static function getCurrentImage($currentSettings, $fieldName)
155 {
156 foreach ($currentSettings as $setting) {
157 if (Arr::get($setting, 'name') === $fieldName) {
158 return Arr::get($setting, 'background_image');
159 }
160 }
161 return null;
162 }
163
164 protected static function handleMediaUrl($url, $currentImage, $fieldName, $spaceId)
165 {
166 $deleteMediaUrls = [];
167
168 if ($url) {
169 $media = Helper::getMediaFromUrl($url);
170 if (!$media || $media->is_active) {
171 return $currentImage;
172 }
173
174 $url = $media->public_url;
175
176 $media->update([
177 'is_active' => true,
178 'user_id' => get_current_user_id(),
179 'sub_object_id' => $spaceId,
180 'object_source' => 'lockscreen_' . $fieldName
181 ]);
182 }
183
184 if ($currentImage) {
185 $deleteMediaUrls[] = $currentImage;
186 }
187
188 do_action('fluent_community/remove_medias_by_url', $deleteMediaUrls, [
189 'sub_object_id' => $spaceId,
190 ]);
191
192 return $url;
193 }
194 }
195