|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Bart Visscher <[email protected]> |
|
6
|
|
|
* @author Joas Schilling <[email protected]> |
|
7
|
|
|
* @author Morris Jobke <[email protected]> |
|
8
|
|
|
* @author Thomas Müller <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* @license AGPL-3.0 |
|
11
|
|
|
* |
|
12
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
13
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
14
|
|
|
* as published by the Free Software Foundation. |
|
15
|
|
|
* |
|
16
|
|
|
* This program is distributed in the hope that it will be useful, |
|
17
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19
|
|
|
* GNU Affero General Public License for more details. |
|
20
|
|
|
* |
|
21
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
22
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
23
|
|
|
* |
|
24
|
|
|
*/ |
|
25
|
|
|
|
|
26
|
|
|
namespace OC\Template; |
|
27
|
|
|
|
|
28
|
|
|
class JSResourceLocator extends ResourceLocator { |
|
29
|
|
|
|
|
30
|
|
|
/** @var JSCombiner */ |
|
31
|
|
|
protected $jsCombiner; |
|
32
|
|
|
|
|
33
|
|
|
public function __construct(\OCP\ILogger $logger, $theme, array $core_map, array $party_map, JSCombiner $JSCombiner) { |
|
34
|
|
|
parent::__construct($logger, $theme, $core_map, $party_map); |
|
35
|
|
|
|
|
36
|
|
|
$this->jsCombiner = $JSCombiner; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param string $script |
|
41
|
|
|
*/ |
|
42
|
|
|
public function doFind($script) { |
|
43
|
|
|
$theme_dir = 'themes/'.$this->theme.'/'; |
|
44
|
|
|
if (strpos($script, '3rdparty') === 0 |
|
45
|
|
|
&& $this->appendIfExist($this->thirdpartyroot, $script.'.js')) { |
|
46
|
|
|
return; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
if (strpos($script, '/l10n/') !== false) { |
|
50
|
|
|
// For language files we try to load them all, so themes can overwrite |
|
51
|
|
|
// single l10n strings without having to translate all of them. |
|
52
|
|
|
$found = 0; |
|
53
|
|
|
$found += $this->appendIfExist($this->serverroot, 'core/'.$script.'.js'); |
|
54
|
|
|
$found += $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$script.'.js'); |
|
55
|
|
|
$found += $this->appendIfExist($this->serverroot, $script.'.js'); |
|
56
|
|
|
$found += $this->appendIfExist($this->serverroot, $theme_dir.$script.'.js'); |
|
57
|
|
|
$found += $this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$script.'.js'); |
|
58
|
|
|
|
|
59
|
|
|
if ($found) { |
|
60
|
|
|
return; |
|
61
|
|
|
} |
|
62
|
|
|
} else if ($this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$script.'.js') |
|
63
|
|
|
|| $this->appendIfExist($this->serverroot, $theme_dir.$script.'.js') |
|
64
|
|
|
|| $this->appendIfExist($this->serverroot, $script.'.js') |
|
65
|
|
|
|| $this->cacheAndAppendCombineJsonIfExist($this->serverroot, $script.'.json') |
|
66
|
|
|
|| $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$script.'.js') |
|
67
|
|
|
|| $this->appendIfExist($this->serverroot, 'core/'.$script.'.js') |
|
68
|
|
|
|| $this->cacheAndAppendCombineJsonIfExist($this->serverroot, 'core/'.$script.'.json') |
|
69
|
|
|
) { |
|
70
|
|
|
return; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$app = substr($script, 0, strpos($script, '/')); |
|
74
|
|
|
$script = substr($script, strpos($script, '/')+1); |
|
75
|
|
|
$app_path = \OC_App::getAppPath($app); |
|
76
|
|
|
$app_url = \OC_App::getAppWebPath($app); |
|
77
|
|
|
|
|
78
|
|
|
// missing translations files fill be ignored |
|
79
|
|
|
if (strpos($script, 'l10n/') === 0) { |
|
80
|
|
|
$this->appendIfExist($app_path, $script . '.js', $app_url); |
|
|
|
|
|
|
81
|
|
|
return; |
|
82
|
|
|
} |
|
83
|
|
|
if (!$this->cacheAndAppendCombineJsonIfExist($app_path, $script.'.json', $app)) { |
|
84
|
|
|
$this->append($app_path, $script . '.js', $app_url); |
|
|
|
|
|
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @param string $script |
|
90
|
|
|
*/ |
|
91
|
|
|
public function doFindTheme($script) { |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
protected function cacheAndAppendCombineJsonIfExist($root, $file, $app = 'core') { |
|
95
|
|
|
if (is_file($root.'/'.$file)) { |
|
96
|
|
|
if ($this->jsCombiner->process($root, $file, $app)) { |
|
97
|
|
|
$this->append($this->serverroot, $this->jsCombiner->getCachedJS($app, $file), false, false); |
|
|
|
|
|
|
98
|
|
|
} else { |
|
99
|
|
|
// Add all the files from the json |
|
100
|
|
|
$files = $this->jsCombiner->getContent($root, $file); |
|
101
|
|
|
$app_url = \OC_App::getAppWebPath($app); |
|
102
|
|
|
|
|
103
|
|
|
foreach ($files as $jsFile) { |
|
104
|
|
|
$this->append($root, $jsFile, $app_url); |
|
|
|
|
|
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
return true; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
return false; |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|
This check looks for type mismatches where the missing type is
false. This is usually indicative of an error condtion.Consider the follow example
This function either returns a new
DateTimeobject or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returnedfalsebefore passing on the value to another function or method that may not be able to handle afalse.