PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.6.0
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.6.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 / Vite.php

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

126 lines 3.5 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;
4
5 use FluentCommunity\App\Functions\Utility;
6
7 class Vite
8 {
9 protected static $moduleScripts = [];
10 protected static $resourceURL = 'https://localhost:4444/src/';
11 protected static $assetsURL = FLUENT_COMMUNITY_PLUGIN_URL . 'assets/';
12
13 private static function isDev()
14 {
15 return Utility::isDev();
16 }
17
18 public static function enqueueScript($handle, $src, $dependency = [], $version = false, $inFooter = false)
19 {
20 static::$moduleScripts [] = $handle;
21 $src = static::generateSrc($src);
22 wp_enqueue_script($handle, $src, $dependency, $version, $inFooter);
23 static::addModuleToScript();
24 }
25
26 public static function enqueueStyle($handle, $src, $dependency = [], $version = false, $media = 'all')
27 {
28 $src = static::generateSrc($src);
29 wp_enqueue_style($handle, $src, $dependency, $version, $media);
30 }
31
32 public static function enqueueStaticScript($handle, $src, $dependency = [], $version = false, $inFooter = false)
33 {
34 $src = static::getStaticSrcUrl($src);
35 wp_enqueue_script($handle, $src, $dependency, $version, $inFooter);
36 }
37
38 public static function enqueueStaticStyle($handle, $src, $dependency = [], $version = false, $media = 'all')
39 {
40 $src = static::getStaticSrcUrl($src);
41 wp_enqueue_style($handle, $src, $dependency, $version, $media);
42 }
43
44 private static function parseManifest()
45 {
46 static $manifest;
47 if ($manifest) {
48 return $manifest;
49 }
50
51 $config = App::getInstance()->config;
52 $manifest = $config->get('app.manifest');
53
54 if (!$manifest) {
55 throw new \Exception('Manifest config could not be found on the app config');
56 }
57
58 return $manifest;
59 }
60
61 private static function addModuleToScript()
62 {
63 add_filter('script_loader_tag', function ($tag, $handle, $src) {
64 return $tag;
65 }, 10, 3);
66 }
67
68 private static function generateSrc($src, $isRtl = null)
69 {
70 if (!static::isDev()) {
71 $manifest = static::parseManifest();
72 $src = 'src/' . $src;
73 $mainSrc = isset($manifest[$src]) ? $manifest[$src] : false;
74
75 if ($mainSrc) {
76 if (isset($mainSrc['css'])) {
77 foreach ($mainSrc['css'] as $css) {
78 wp_enqueue_style($css . '_css', static::$assetsURL . $css, [], '1.0.0', 'all');
79 }
80 }
81
82 if ($isRtl) {
83 $file = $manifest[$src]['file'];
84 $file = str_replace('.css', '.rtl.css', $file);
85 return static::$assetsURL . $file;
86 }
87
88 return static::$assetsURL . $manifest[$src]['file'];
89 }
90 }
91
92 return static::$resourceURL . $src;
93 }
94
95 public static function getStaticSrcUrl($src, $isRtl = null)
96 {
97 if ($isRtl) {
98 $src = str_replace('.css', '.rtl.css', $src);
99 }
100
101 return static::$assetsURL . $src;
102 }
103
104 public static function getDynamicSrcUrl($src, $isRtl = null)
105 {
106 return static::generateSrc($src, $isRtl);
107 }
108
109 public static function getDynamicProductionSrcUrl($src, $isRtl = null)
110 {
111 if (!static::isDev()) {
112 return static::generateSrc($src, $isRtl);
113 }
114
115 return false;
116 }
117
118 public static function getAssetsUrl()
119 {
120 if (!static::isDev()) {
121 return static::$assetsURL;
122 }
123 return static::$resourceURL;
124 }
125 }
126