@@ -31,111 +31,111 @@ |
||
31 | 31 | |
32 | 32 | class JSResourceLocator extends ResourceLocator { |
33 | 33 | |
34 | - /** @var JSCombiner */ |
|
35 | - protected $jsCombiner; |
|
36 | - |
|
37 | - public function __construct(LoggerInterface $logger, $theme, array $core_map, array $party_map, JSCombiner $JSCombiner) { |
|
38 | - parent::__construct($logger, $theme, $core_map, $party_map); |
|
39 | - |
|
40 | - $this->jsCombiner = $JSCombiner; |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * @param string $script |
|
45 | - */ |
|
46 | - public function doFind($script) { |
|
47 | - $theme_dir = 'themes/'.$this->theme.'/'; |
|
48 | - if (strpos($script, '3rdparty') === 0 |
|
49 | - && $this->appendIfExist($this->thirdpartyroot, $script.'.js')) { |
|
50 | - return; |
|
51 | - } |
|
52 | - |
|
53 | - // Extracting the appId and the script file name |
|
54 | - $app = substr($script, 0, strpos($script, '/')); |
|
55 | - $scriptName = basename($script); |
|
56 | - |
|
57 | - if (strpos($script, '/l10n/') !== false) { |
|
58 | - // For language files we try to load them all, so themes can overwrite |
|
59 | - // single l10n strings without having to translate all of them. |
|
60 | - $found = 0; |
|
61 | - $found += $this->appendIfExist($this->serverroot, 'core/'.$script.'.js'); |
|
62 | - $found += $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$script.'.js'); |
|
63 | - $found += $this->appendIfExist($this->serverroot, $script.'.js'); |
|
64 | - $found += $this->appendIfExist($this->serverroot, $theme_dir.$script.'.js'); |
|
65 | - $found += $this->appendIfExist($this->serverroot, 'apps/'.$script.'.js'); |
|
66 | - $found += $this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$script.'.js'); |
|
67 | - |
|
68 | - if ($found) { |
|
69 | - return; |
|
70 | - } |
|
71 | - } elseif ($this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$script.'.js') |
|
72 | - || $this->appendIfExist($this->serverroot, $theme_dir.$script.'.js') |
|
73 | - || $this->appendIfExist($this->serverroot, $script.'.js') |
|
74 | - || $this->appendIfExist($this->serverroot, $theme_dir . "dist/$app-$scriptName.js") |
|
75 | - || $this->appendIfExist($this->serverroot, "dist/$app-$scriptName.js") |
|
76 | - || $this->appendIfExist($this->serverroot, 'apps/'.$script.'.js') |
|
77 | - || $this->cacheAndAppendCombineJsonIfExist($this->serverroot, $script.'.json') |
|
78 | - || $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$script.'.js') |
|
79 | - || $this->appendIfExist($this->serverroot, 'core/'.$script.'.js') |
|
80 | - || (strpos($scriptName, '/') === -1 && ($this->appendIfExist($this->serverroot, $theme_dir . "dist/core-$scriptName.js") |
|
81 | - || $this->appendIfExist($this->serverroot, "dist/core-$scriptName.js"))) |
|
82 | - || $this->cacheAndAppendCombineJsonIfExist($this->serverroot, 'core/'.$script.'.json') |
|
83 | - ) { |
|
84 | - return; |
|
85 | - } |
|
86 | - |
|
87 | - $script = substr($script, strpos($script, '/') + 1); |
|
88 | - $app_path = \OC_App::getAppPath($app); |
|
89 | - $app_url = \OC_App::getAppWebPath($app); |
|
90 | - |
|
91 | - if ($app_path !== false) { |
|
92 | - // Account for the possibility of having symlinks in app path. Only |
|
93 | - // do this if $app_path is set, because an empty argument to realpath |
|
94 | - // gets turned into cwd. |
|
95 | - $app_path = realpath($app_path); |
|
96 | - } |
|
97 | - |
|
98 | - // missing translations files fill be ignored |
|
99 | - if (strpos($script, 'l10n/') === 0) { |
|
100 | - $this->appendIfExist($app_path, $script . '.js', $app_url); |
|
101 | - return; |
|
102 | - } |
|
103 | - |
|
104 | - if ($app_path === false && $app_url === false) { |
|
105 | - $this->logger->error('Could not find resource {resource} to load', [ |
|
106 | - 'resource' => $app . '/' . $script . '.js', |
|
107 | - 'app' => 'jsresourceloader', |
|
108 | - ]); |
|
109 | - return; |
|
110 | - } |
|
111 | - |
|
112 | - if (!$this->cacheAndAppendCombineJsonIfExist($app_path, $script.'.json', $app)) { |
|
113 | - $this->append($app_path, $script . '.js', $app_url); |
|
114 | - } |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * @param string $script |
|
119 | - */ |
|
120 | - public function doFindTheme($script) { |
|
121 | - } |
|
122 | - |
|
123 | - protected function cacheAndAppendCombineJsonIfExist($root, $file, $app = 'core') { |
|
124 | - if (is_file($root.'/'.$file)) { |
|
125 | - if ($this->jsCombiner->process($root, $file, $app)) { |
|
126 | - $this->append($this->serverroot, $this->jsCombiner->getCachedJS($app, $file), false, false); |
|
127 | - } else { |
|
128 | - // Add all the files from the json |
|
129 | - $files = $this->jsCombiner->getContent($root, $file); |
|
130 | - $app_url = \OC_App::getAppWebPath($app); |
|
131 | - |
|
132 | - foreach ($files as $jsFile) { |
|
133 | - $this->append($root, $jsFile, $app_url); |
|
134 | - } |
|
135 | - } |
|
136 | - return true; |
|
137 | - } |
|
138 | - |
|
139 | - return false; |
|
140 | - } |
|
34 | + /** @var JSCombiner */ |
|
35 | + protected $jsCombiner; |
|
36 | + |
|
37 | + public function __construct(LoggerInterface $logger, $theme, array $core_map, array $party_map, JSCombiner $JSCombiner) { |
|
38 | + parent::__construct($logger, $theme, $core_map, $party_map); |
|
39 | + |
|
40 | + $this->jsCombiner = $JSCombiner; |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * @param string $script |
|
45 | + */ |
|
46 | + public function doFind($script) { |
|
47 | + $theme_dir = 'themes/'.$this->theme.'/'; |
|
48 | + if (strpos($script, '3rdparty') === 0 |
|
49 | + && $this->appendIfExist($this->thirdpartyroot, $script.'.js')) { |
|
50 | + return; |
|
51 | + } |
|
52 | + |
|
53 | + // Extracting the appId and the script file name |
|
54 | + $app = substr($script, 0, strpos($script, '/')); |
|
55 | + $scriptName = basename($script); |
|
56 | + |
|
57 | + if (strpos($script, '/l10n/') !== false) { |
|
58 | + // For language files we try to load them all, so themes can overwrite |
|
59 | + // single l10n strings without having to translate all of them. |
|
60 | + $found = 0; |
|
61 | + $found += $this->appendIfExist($this->serverroot, 'core/'.$script.'.js'); |
|
62 | + $found += $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$script.'.js'); |
|
63 | + $found += $this->appendIfExist($this->serverroot, $script.'.js'); |
|
64 | + $found += $this->appendIfExist($this->serverroot, $theme_dir.$script.'.js'); |
|
65 | + $found += $this->appendIfExist($this->serverroot, 'apps/'.$script.'.js'); |
|
66 | + $found += $this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$script.'.js'); |
|
67 | + |
|
68 | + if ($found) { |
|
69 | + return; |
|
70 | + } |
|
71 | + } elseif ($this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$script.'.js') |
|
72 | + || $this->appendIfExist($this->serverroot, $theme_dir.$script.'.js') |
|
73 | + || $this->appendIfExist($this->serverroot, $script.'.js') |
|
74 | + || $this->appendIfExist($this->serverroot, $theme_dir . "dist/$app-$scriptName.js") |
|
75 | + || $this->appendIfExist($this->serverroot, "dist/$app-$scriptName.js") |
|
76 | + || $this->appendIfExist($this->serverroot, 'apps/'.$script.'.js') |
|
77 | + || $this->cacheAndAppendCombineJsonIfExist($this->serverroot, $script.'.json') |
|
78 | + || $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$script.'.js') |
|
79 | + || $this->appendIfExist($this->serverroot, 'core/'.$script.'.js') |
|
80 | + || (strpos($scriptName, '/') === -1 && ($this->appendIfExist($this->serverroot, $theme_dir . "dist/core-$scriptName.js") |
|
81 | + || $this->appendIfExist($this->serverroot, "dist/core-$scriptName.js"))) |
|
82 | + || $this->cacheAndAppendCombineJsonIfExist($this->serverroot, 'core/'.$script.'.json') |
|
83 | + ) { |
|
84 | + return; |
|
85 | + } |
|
86 | + |
|
87 | + $script = substr($script, strpos($script, '/') + 1); |
|
88 | + $app_path = \OC_App::getAppPath($app); |
|
89 | + $app_url = \OC_App::getAppWebPath($app); |
|
90 | + |
|
91 | + if ($app_path !== false) { |
|
92 | + // Account for the possibility of having symlinks in app path. Only |
|
93 | + // do this if $app_path is set, because an empty argument to realpath |
|
94 | + // gets turned into cwd. |
|
95 | + $app_path = realpath($app_path); |
|
96 | + } |
|
97 | + |
|
98 | + // missing translations files fill be ignored |
|
99 | + if (strpos($script, 'l10n/') === 0) { |
|
100 | + $this->appendIfExist($app_path, $script . '.js', $app_url); |
|
101 | + return; |
|
102 | + } |
|
103 | + |
|
104 | + if ($app_path === false && $app_url === false) { |
|
105 | + $this->logger->error('Could not find resource {resource} to load', [ |
|
106 | + 'resource' => $app . '/' . $script . '.js', |
|
107 | + 'app' => 'jsresourceloader', |
|
108 | + ]); |
|
109 | + return; |
|
110 | + } |
|
111 | + |
|
112 | + if (!$this->cacheAndAppendCombineJsonIfExist($app_path, $script.'.json', $app)) { |
|
113 | + $this->append($app_path, $script . '.js', $app_url); |
|
114 | + } |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * @param string $script |
|
119 | + */ |
|
120 | + public function doFindTheme($script) { |
|
121 | + } |
|
122 | + |
|
123 | + protected function cacheAndAppendCombineJsonIfExist($root, $file, $app = 'core') { |
|
124 | + if (is_file($root.'/'.$file)) { |
|
125 | + if ($this->jsCombiner->process($root, $file, $app)) { |
|
126 | + $this->append($this->serverroot, $this->jsCombiner->getCachedJS($app, $file), false, false); |
|
127 | + } else { |
|
128 | + // Add all the files from the json |
|
129 | + $files = $this->jsCombiner->getContent($root, $file); |
|
130 | + $app_url = \OC_App::getAppWebPath($app); |
|
131 | + |
|
132 | + foreach ($files as $jsFile) { |
|
133 | + $this->append($root, $jsFile, $app_url); |
|
134 | + } |
|
135 | + } |
|
136 | + return true; |
|
137 | + } |
|
138 | + |
|
139 | + return false; |
|
140 | + } |
|
141 | 141 | } |
@@ -71,13 +71,13 @@ discard block |
||
71 | 71 | } elseif ($this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$script.'.js') |
72 | 72 | || $this->appendIfExist($this->serverroot, $theme_dir.$script.'.js') |
73 | 73 | || $this->appendIfExist($this->serverroot, $script.'.js') |
74 | - || $this->appendIfExist($this->serverroot, $theme_dir . "dist/$app-$scriptName.js") |
|
74 | + || $this->appendIfExist($this->serverroot, $theme_dir."dist/$app-$scriptName.js") |
|
75 | 75 | || $this->appendIfExist($this->serverroot, "dist/$app-$scriptName.js") |
76 | 76 | || $this->appendIfExist($this->serverroot, 'apps/'.$script.'.js') |
77 | 77 | || $this->cacheAndAppendCombineJsonIfExist($this->serverroot, $script.'.json') |
78 | 78 | || $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$script.'.js') |
79 | 79 | || $this->appendIfExist($this->serverroot, 'core/'.$script.'.js') |
80 | - || (strpos($scriptName, '/') === -1 && ($this->appendIfExist($this->serverroot, $theme_dir . "dist/core-$scriptName.js") |
|
80 | + || (strpos($scriptName, '/') === -1 && ($this->appendIfExist($this->serverroot, $theme_dir."dist/core-$scriptName.js") |
|
81 | 81 | || $this->appendIfExist($this->serverroot, "dist/core-$scriptName.js"))) |
82 | 82 | || $this->cacheAndAppendCombineJsonIfExist($this->serverroot, 'core/'.$script.'.json') |
83 | 83 | ) { |
@@ -97,20 +97,20 @@ discard block |
||
97 | 97 | |
98 | 98 | // missing translations files fill be ignored |
99 | 99 | if (strpos($script, 'l10n/') === 0) { |
100 | - $this->appendIfExist($app_path, $script . '.js', $app_url); |
|
100 | + $this->appendIfExist($app_path, $script.'.js', $app_url); |
|
101 | 101 | return; |
102 | 102 | } |
103 | 103 | |
104 | 104 | if ($app_path === false && $app_url === false) { |
105 | 105 | $this->logger->error('Could not find resource {resource} to load', [ |
106 | - 'resource' => $app . '/' . $script . '.js', |
|
106 | + 'resource' => $app.'/'.$script.'.js', |
|
107 | 107 | 'app' => 'jsresourceloader', |
108 | 108 | ]); |
109 | 109 | return; |
110 | 110 | } |
111 | 111 | |
112 | 112 | if (!$this->cacheAndAppendCombineJsonIfExist($app_path, $script.'.json', $app)) { |
113 | - $this->append($app_path, $script . '.js', $app_url); |
|
113 | + $this->append($app_path, $script.'.js', $app_url); |
|
114 | 114 | } |
115 | 115 | } |
116 | 116 |