|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Axel Helmert <[email protected]> |
|
6
|
|
|
* @author Bart Visscher <[email protected]> |
|
7
|
|
|
* @author Christoph Wurst <[email protected]> |
|
8
|
|
|
* @author Joas Schilling <[email protected]> |
|
9
|
|
|
* @author John Molakvoæ <[email protected]> |
|
10
|
|
|
* @author Kyle Fazzari <[email protected]> |
|
11
|
|
|
* @author Morris Jobke <[email protected]> |
|
12
|
|
|
* @author Robin Appelman <[email protected]> |
|
13
|
|
|
* @author Roeland Jago Douma <[email protected]> |
|
14
|
|
|
* @author Thomas Müller <[email protected]> |
|
15
|
|
|
* @author tux-rampage <[email protected]> |
|
16
|
|
|
* |
|
17
|
|
|
* @license AGPL-3.0 |
|
18
|
|
|
* |
|
19
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
20
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
21
|
|
|
* as published by the Free Software Foundation. |
|
22
|
|
|
* |
|
23
|
|
|
* This program is distributed in the hope that it will be useful, |
|
24
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
25
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
26
|
|
|
* GNU Affero General Public License for more details. |
|
27
|
|
|
* |
|
28
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
29
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
30
|
|
|
* |
|
31
|
|
|
*/ |
|
32
|
|
|
namespace OC\Template; |
|
33
|
|
|
|
|
34
|
|
|
use Psr\Log\LoggerInterface; |
|
35
|
|
|
|
|
36
|
|
|
class CSSResourceLocator extends ResourceLocator { |
|
37
|
|
|
public function __construct(LoggerInterface $logger) { |
|
38
|
|
|
parent::__construct($logger); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param string $style |
|
43
|
|
|
*/ |
|
44
|
|
|
public function doFind($style) { |
|
45
|
|
|
$app = substr($style, 0, strpos($style, '/')); |
|
46
|
|
|
if (strpos($style, '3rdparty') === 0 |
|
|
|
|
|
|
47
|
|
|
&& $this->appendIfExist($this->serverroot, $style.'.css') |
|
48
|
|
|
|| $this->appendIfExist($this->serverroot, 'core/'.$style.'.css') |
|
49
|
|
|
) { |
|
50
|
|
|
return; |
|
51
|
|
|
} |
|
52
|
|
|
$style = substr($style, strpos($style, '/') + 1); |
|
53
|
|
|
$app_path = \OC_App::getAppPath($app); |
|
54
|
|
|
$app_url = \OC_App::getAppWebPath($app); |
|
55
|
|
|
|
|
56
|
|
|
if ($app_path === false && $app_url === false) { |
|
57
|
|
|
$this->logger->error('Could not find resource {resource} to load', [ |
|
58
|
|
|
'resource' => $app . '/' . $style . '.css', |
|
59
|
|
|
'app' => 'cssresourceloader', |
|
60
|
|
|
]); |
|
61
|
|
|
return; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
// Account for the possibility of having symlinks in app path. Doing |
|
65
|
|
|
// this here instead of above as an empty argument to realpath gets |
|
66
|
|
|
// turned into cwd. |
|
67
|
|
|
$app_path = realpath($app_path); |
|
68
|
|
|
|
|
69
|
|
|
$this->append($app_path, $style.'.css', $app_url); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @param string $style |
|
74
|
|
|
*/ |
|
75
|
|
|
public function doFindTheme($style) { |
|
76
|
|
|
$theme_dir = 'themes/'.$this->theme.'/'; |
|
77
|
|
|
$this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$style.'.css') |
|
78
|
|
|
|| $this->appendIfExist($this->serverroot, $theme_dir.$style.'.css') |
|
79
|
|
|
|| $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$style.'.css'); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function append($root, $file, $webRoot = null, $throw = true, $scss = false) { |
|
83
|
|
|
if (!$scss) { |
|
84
|
|
|
parent::append($root, $file, $webRoot, $throw); |
|
85
|
|
|
} else { |
|
86
|
|
|
if (!$webRoot) { |
|
87
|
|
|
$webRoot = $this->findWebRoot($root); |
|
88
|
|
|
|
|
89
|
|
|
if ($webRoot === null) { |
|
90
|
|
|
$webRoot = ''; |
|
91
|
|
|
$this->logger->error('ResourceLocator can not find a web root (root: {root}, file: {file}, webRoot: {webRoot}, throw: {throw})', [ |
|
92
|
|
|
'app' => 'lib', |
|
93
|
|
|
'root' => $root, |
|
94
|
|
|
'file' => $file, |
|
95
|
|
|
'webRoot' => $webRoot, |
|
96
|
|
|
'throw' => $throw ? 'true' : 'false' |
|
97
|
|
|
]); |
|
98
|
|
|
|
|
99
|
|
|
if ($throw && $root === '/') { |
|
100
|
|
|
throw new ResourceNotFoundException($file, $webRoot); |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
$this->resources[] = [$webRoot ?: \OC::$WEBROOT, $webRoot, $file]; |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|