PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.10.01
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.10.01
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.10.01, at app/Services/LockscreenService.php

214 lines 7.7 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 && Arr::get($setting, 'type') === 'block' && !empty($setting['content'])) {
70 $user = Helper::getCurrentUser();
71 $content = self::renderBlockContent($setting['content']);
72 $setting['content'] = (new SmartCodeParser())->parse($content, $user);
73 }
74
75 if (Arr::get($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 /**
84 * Renders without the_content: a space admin need not hold unfiltered_html, and
85 * the_content's do_shortcode pass would run their shortcodes for every visitor.
86 */
87 protected static function renderBlockContent($content)
88 {
89 $rendered = do_blocks(strip_shortcodes($content));
90
91 // Core skips wpautop for block content to avoid mangling it.
92 if (!has_blocks($content)) {
93 $rendered = wpautop($rendered);
94 }
95
96 $rendered = wptexturize($rendered);
97
98 return wp_filter_content_tags($rendered);
99 }
100
101 public static function formatLockscreenFields($settingFields, $space)
102 {
103 $currentSettings = self::getLockscreenSettings($space);
104
105 $textFields = ['type', 'name', 'label', 'heading', 'description', 'button_text', 'heading_color', 'text_color', 'button_color', 'button_text_color', 'overlay_color', 'new_tab', 'background_color'];
106 $urlFields = ['button_link'];
107
108 $formattedFields = [];
109
110 foreach ($settingFields as $value) {
111 $textValues = array_map('sanitize_text_field', Arr::only($value, $textFields));
112 $urlValues = array_map('sanitize_url', Arr::only($value, $urlFields));
113
114 $formattedField = array_merge($textValues, $urlValues);
115
116 $formattedField['hidden'] = Arr::isTrue($value, 'hidden');
117
118 if (Arr::get($value, 'type') == 'block') {
119 $formattedField['content'] = CustomSanitizer::santizeEditorBody(Arr::get($value, 'content'));
120 }
121
122 if (isset($value['background_image'])) {
123 $bgImage = sanitize_url($value['background_image']);
124 $fieldName = Arr::get($value, 'name');
125 $currentImage = self::getCurrentImage($currentSettings, $fieldName);
126 $bgImageUrl = self::handleMediaUrl($bgImage, $currentImage, $fieldName, $space->id);
127 $formattedField['background_image'] = $bgImageUrl;
128 }
129
130 $formattedFields[] = apply_filters('fluent_community/lockscreen_formatted_field', $formattedField, $value, $space);
131 }
132
133 return $formattedFields;
134 }
135
136 public static function getLockscreenConfig(BaseSpace $space, $membership = null, $viewOnly = false)
137 {
138 if ($space->privacy != 'private') {
139 return null;
140 }
141
142 if($membership) {
143 if($membership->pivot->status) {
144 if($membership->pivot->status == 'pending') {
145 return [
146 'is_pending' => true
147 ];
148 }
149 return null;
150 }
151 }
152
153 $showCustom = Arr::get($space->settings, 'custom_lock_screen', 'no') === 'yes';
154 $showPaywalls = Arr::get($space->settings, 'show_paywalls', 'no') === 'yes' && defined('FLUENTCART_VERSION');
155 $canSendRequest = Arr::get($space->settings, 'can_request_join', 'no') === 'yes';
156
157 $isRedirect = Arr::get($space->settings, 'custom_lock_screen', 'no') == 'redirect' && Arr::get($space->settings, 'onboard_redirect_url', false);
158 $redirectUrl = '';
159 if($isRedirect) {
160 $redirectUrl = Arr::get($space->settings, 'onboard_redirect_url', false);
161 }
162
163 return [
164 'showCustom' => $showCustom,
165 'showPaywalls' => $showPaywalls,
166 'showWelcomeBanner' => Arr::get($space->settings, 'show_welcome_banner', 'no') === 'yes',
167 'canSendRequest' => $canSendRequest,
168 'lockScreen' => $showCustom ? self::getLockscreenSettings($space, $viewOnly) : null,
169 'redirect_url' => $redirectUrl
170 ];
171 }
172
173 protected static function getCurrentImage($currentSettings, $fieldName)
174 {
175 foreach ($currentSettings as $setting) {
176 if (Arr::get($setting, 'name') === $fieldName) {
177 return Arr::get($setting, 'background_image');
178 }
179 }
180 return null;
181 }
182
183 protected static function handleMediaUrl($url, $currentImage, $fieldName, $spaceId)
184 {
185 $deleteMediaUrls = [];
186
187 if ($url) {
188 $media = Helper::getMediaFromUrl($url);
189 if (!$media || $media->is_active) {
190 return $currentImage;
191 }
192
193 $url = $media->public_url;
194
195 $media->update([
196 'is_active' => true,
197 'user_id' => get_current_user_id(),
198 'sub_object_id' => $spaceId,
199 'object_source' => 'lockscreen_' . $fieldName
200 ]);
201 }
202
203 if ($currentImage) {
204 $deleteMediaUrls[] = $currentImage;
205 }
206
207 do_action('fluent_community/remove_medias_by_url', $deleteMediaUrls, [
208 'sub_object_id' => $spaceId,
209 ]);
210
211 return $url;
212 }
213 }
214