PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.10.0
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.10.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
← All changes | app/Services/LockscreenService.php +106 -21 1.1.02.10.0 View file →
@@ -6,9 +6,9 @@
6 6 use FluentCommunity\Framework\Support\Arr;
7 7
8 8 class LockscreenService
9 9 {
10 - public static function getLockscreenSettings(BaseSpace $space)
10 + public static function getLockscreenSettings(BaseSpace $space, $viewOnly = false)
11 11 {
12 12 $defaultSettings = [
13 13 [
14 14 'hidden' => false,
@@ -23,9 +23,10 @@
23 23 'button_link' => '',
24 24 'button_color' => '#2B2E33',
25 25 'button_text_color' => '#FFFFFF',
26 26 'background_image' => '',
27 - 'overlay_color' => '#798398'
27 + 'overlay_color' => '#798398',
28 + 'new_tab' => 'no'
28 29 ],
29 30 [
30 31 'hidden' => false,
31 32 'type' => 'block',
@@ -30,9 +31,9 @@
30 31 'hidden' => false,
31 32 'type' => 'block',
32 33 'label' => 'Description',
33 34 'name' => 'description',
34 - 'content' => 'Description Test'
35 + 'content' => '<!-- wp:paragraph --><p>Description</p><!-- /wp:paragraph -->',
35 36 ]
36 37 ];
37 38
38 39 if ($space->isCourseSpace()) {
@@ -57,50 +58,83 @@
57 58 'button_link' => '',
58 59 'button_color' => '#2B2E33',
59 60 'button_text_color' => '#FFFFFF',
60 61 'background_image' => '',
61 - 'overlay_color' => '#798398'
62 + 'overlay_color' => '#798398',
63 + 'new_tab' => 'no'
62 64 ];
63 65
64 - $settings = $space->getCustomMeta('lockscreen_settings', $defaultSettings);
66 + $settings = (array) $space->getCustomMeta('lockscreen_settings', $defaultSettings);
65 67
66 68 foreach ($settings as &$setting) {
67 - if ($setting['type'] === 'block' && !empty($setting['content'])) {
68 - $setting['content'] = do_blocks($setting['content']);
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);
69 73 }
74 +
75 + if (Arr::get($setting, 'type') == 'image' && empty($setting['new_tab'])) {
76 + $setting['new_tab'] = 'no';
77 + }
70 78 }
71 79
72 - return $settings;
80 + return apply_filters('fluent_community/lockscreen_fields', $settings, $space);
73 81 }
74 82
75 - public static function formatLockscreenFields($settingFields)
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)
76 88 {
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'];
89 + $rendered = do_blocks(strip_shortcodes($content));
80 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 +
81 108 $formattedFields = [];
82 109
83 110 foreach ($settingFields as $value) {
84 111 $textValues = array_map('sanitize_text_field', Arr::only($value, $textFields));
85 - $colorValues = array_map('sanitize_hex_color', Arr::only($value, $colorFields));
86 112 $urlValues = array_map('sanitize_url', Arr::only($value, $urlFields));
87 113
88 - $formattedField = array_merge($textValues, $colorValues, $urlValues);
114 + $formattedField = array_merge($textValues, $urlValues);
89 115
90 116 $formattedField['hidden'] = Arr::isTrue($value, 'hidden');
91 117
92 - if ($value['type'] == 'block') {
93 - $formattedField['content'] = wp_kses_post(Arr::get($value, 'content'));
118 + if (Arr::get($value, 'type') == 'block') {
119 + $formattedField['content'] = CustomSanitizer::santizeEditorBody(Arr::get($value, 'content'));
94 120 }
95 121
96 - $formattedFields[] = $formattedField;
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);
97 131 }
98 132
99 133 return $formattedFields;
100 134 }
101 135
102 - public static function getLockscreenConfig(BaseSpace $space, $membership = null)
136 + public static function getLockscreenConfig(BaseSpace $space, $membership = null, $viewOnly = false)
103 137 {
104 138 if ($space->privacy != 'private') {
105 139 return null;
106 140 }
@@ -116,13 +150,64 @@
116 150 }
117 151 }
118 152
119 153 $showCustom = Arr::get($space->settings, 'custom_lock_screen', 'no') === 'yes';
154 + $showPaywalls = Arr::get($space->settings, 'show_paywalls', 'no') === 'yes' && defined('FLUENTCART_VERSION');
120 155 $canSendRequest = Arr::get($space->settings, 'can_request_join', 'no') === 'yes';
121 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 +
122 163 return [
123 - 'showCustom' => $showCustom,
124 - 'canSendRequest' => $canSendRequest,
125 - 'lockScreen' => $showCustom ? self::getLockscreenSettings($space) : null
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
126 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;
127 212 }
128 213 }