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 / Modules / FeaturesHandler.php

FeaturesHandler.php in FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses 2.10.01, at Modules/FeaturesHandler.php

168 lines 6.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCommunity\Modules;
4
5 use FluentCommunity\App\Services\Helper;
6 use FluentCommunity\App\Vite;
7 use FluentCommunity\Framework\Foundation\Application;
8 use FluentCommunity\Framework\Support\Arr;
9
10 class FeaturesHandler
11 {
12 public function register(Application $app)
13 {
14 add_filter('fluent_community/portal_page_headless', '__return_true');
15
16 $this->registerModules($app);
17
18 add_action('fluent_community/portal_header', [$this, 'maybePushDarkModeScript']);
19 add_action('fluent_community/portal_sidebar', [$this, 'maybePushDarkModeScript']);
20 add_action('init', [$this, 'maybeOembedRequest']);
21
22 add_action('fluent_community/rendering_headless_portal', [$this, 'loadHeadlessPortalAssets']);
23 }
24
25 public function loadHeadlessPortalAssets($data)
26 {
27 add_action('fluent_community/portal_head', function () use ($data) {
28 $cssFiles = Arr::get($data, 'css_files', []);
29 foreach ($cssFiles as $file) {
30 ?>
31 <link rel="stylesheet" href="<?php echo esc_url($file['url']); ?>?version=<?php echo esc_attr(FLUENT_COMMUNITY_PLUGIN_VERSION); ?>" media="screen"/> <?php // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedStylesheet ?>
32 <?php
33 }
34 $jsFiles = Arr::get($data, 'header_js_files', []);
35 foreach ($jsFiles as $file) {
36 $jsVars = Arr::get($file, 'vars', []);
37 foreach ($jsVars as $varKey => $values) {
38 ?>
39 <script>
40 var <?php echo esc_attr($varKey); ?> = <?php echo wp_json_encode($values); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>;
41 </script>
42 <?php } ?>
43 <script type="module" src="<?php echo esc_url(Vite::versionedUrl($file['url'])); ?>" defer="defer"></script> <?php // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript ?>
44 <?php
45 }
46 });
47
48 add_action('fluent_community/before_js_loaded', function () use ($data) {
49 $jsVars = Arr::get($data, 'js_vars', []);
50 ?>
51 <script>
52 <?php foreach ($jsVars as $varKey => $values): ?>
53 var <?php echo esc_attr($varKey); ?> = <?php echo wp_json_encode($values); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>;
54 <?php endforeach; ?>
55 </script>
56 <?php
57 });
58
59 add_action('fluent_community/portal_footer', function () use ($data) {
60 $jsFiles = Arr::get($data, 'js_files', []);
61 foreach ($jsFiles as $file) {
62 ?>
63 <script type="module" src="<?php echo esc_url(Vite::versionedUrl($file['url'])); ?>" defer="defer"></script> <?php // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript ?>
64 <?php
65 }
66 });
67
68 }
69
70 public function maybePushDarkModeScript()
71 {
72
73 }
74
75 public function maybeOembedRequest()
76 {
77 // this is temp hack
78 if (!isset($_GET['url'])) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
79 return;
80 }
81
82 if (defined('REST_REQUEST')) {
83 return;
84 }
85
86 if (!is_user_logged_in()) {
87 return;
88 }
89
90 $requestUrl = Arr::get($_SERVER, 'REQUEST_URI');
91 if (!strpos($requestUrl, 'oembed/1.0/proxy')) {
92 return;
93 }
94
95 global $wp_embed, $wp_scripts;
96 $url = sanitize_url(wp_unslash($_GET['url'] ?? '')); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
97
98 $request = \FluentCommunity\App\App::make('request');
99
100 $args = $request->all();
101 unset($args['url']);
102
103 // Copy maxwidth/maxheight to width/height since WP_oEmbed::fetch() uses these arg names.
104 if (isset($args['maxwidth'])) {
105 $args['width'] = $args['maxwidth'];
106 } else {
107 $args['maxwidth'] = 600;
108 }
109
110 if (isset($args['maxheight'])) {
111 $args['height'] = $args['maxheight'];
112 }
113
114 // Short-circuit process for URLs belonging to the current site.
115 $data = get_oembed_response_data_for_url($url, $args);
116
117 if ($data) {
118 wp_send_json($data, 200);
119 }
120
121 $data = _wp_oembed_get_object()->get_data($url, $args);
122
123 if (false === $data) {
124 // Try using a classic embed, instead.
125 /* @var \WP_Embed $wp_embed */
126 $html = $wp_embed->get_embed_handler_html($args, $url);
127
128 if ($html) {
129 // Check if any scripts were enqueued by the shortcode, and include them in the response.
130 $enqueued_scripts = array();
131
132 foreach ($wp_scripts->queue as $script) {
133 $enqueued_scripts[] = $wp_scripts->registered[$script]->src;
134 }
135
136 wp_send_json(array(
137 'provider_name' => __('Embed Handler', 'fluent-community'),
138 'html' => $html,
139 'scripts' => $enqueued_scripts,
140 ), 200);
141 }
142
143 wp_send_json([
144 'error' => 'not_found',
145 ], 404);
146 }
147
148 /** This filter is documented in wp-includes/class-wp-oembed.php */
149 $data->html = apply_filters('oembed_result', _wp_oembed_get_object()->data2html((object)$data, $url), $url, $args); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
150
151 wp_send_json($data, 200);
152 }
153
154 private function registerModules($app)
155 {
156 if (Helper::isFeatureEnabled('course_module')) {
157 // Regitser the modules here
158 (new \FluentCommunity\Modules\Course\CourseModule())->register($app);
159 }
160
161 if (apply_filters('fluent_community/use_editor_block', true)) {
162 (new \FluentCommunity\Modules\Gutenberg\EditorBlock())->register($app);
163 }
164
165 (new \FluentCommunity\Modules\Auth\AuthModdule())->register($app);
166 }
167 }
168