@@ -27,104 +27,104 @@ |
||
27 | 27 | use OCP\ICertificate; |
28 | 28 | |
29 | 29 | class Certificate implements ICertificate { |
30 | - protected $name; |
|
31 | - |
|
32 | - protected $commonName; |
|
33 | - |
|
34 | - protected $organization; |
|
35 | - |
|
36 | - protected $serial; |
|
37 | - |
|
38 | - protected $issueDate; |
|
39 | - |
|
40 | - protected $expireDate; |
|
41 | - |
|
42 | - protected $issuerName; |
|
43 | - |
|
44 | - protected $issuerOrganization; |
|
45 | - |
|
46 | - /** |
|
47 | - * @param string $data base64 encoded certificate |
|
48 | - * @param string $name |
|
49 | - * @throws \Exception If the certificate could not get parsed |
|
50 | - */ |
|
51 | - public function __construct($data, $name) { |
|
52 | - $this->name = $name; |
|
53 | - $gmt = new \DateTimeZone('GMT'); |
|
54 | - |
|
55 | - // If string starts with "file://" ignore the certificate |
|
56 | - $query = 'file://'; |
|
57 | - if(strtolower(substr($data, 0, strlen($query))) === $query) { |
|
58 | - throw new \Exception('Certificate could not get parsed.'); |
|
59 | - } |
|
60 | - |
|
61 | - $info = openssl_x509_parse($data); |
|
62 | - if(!is_array($info)) { |
|
63 | - throw new \Exception('Certificate could not get parsed.'); |
|
64 | - } |
|
65 | - |
|
66 | - $this->commonName = isset($info['subject']['CN']) ? $info['subject']['CN'] : null; |
|
67 | - $this->organization = isset($info['subject']['O']) ? $info['subject']['O'] : null; |
|
68 | - $this->issueDate = new \DateTime('@' . $info['validFrom_time_t'], $gmt); |
|
69 | - $this->expireDate = new \DateTime('@' . $info['validTo_time_t'], $gmt); |
|
70 | - $this->issuerName = isset($info['issuer']['CN']) ? $info['issuer']['CN'] : null; |
|
71 | - $this->issuerOrganization = isset($info['issuer']['O']) ? $info['issuer']['O'] : null; |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * @return string |
|
76 | - */ |
|
77 | - public function getName() { |
|
78 | - return $this->name; |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * @return string|null |
|
83 | - */ |
|
84 | - public function getCommonName() { |
|
85 | - return $this->commonName; |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * @return string |
|
90 | - */ |
|
91 | - public function getOrganization() { |
|
92 | - return $this->organization; |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * @return \DateTime |
|
97 | - */ |
|
98 | - public function getIssueDate() { |
|
99 | - return $this->issueDate; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * @return \DateTime |
|
104 | - */ |
|
105 | - public function getExpireDate() { |
|
106 | - return $this->expireDate; |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * @return bool |
|
111 | - */ |
|
112 | - public function isExpired() { |
|
113 | - $now = new \DateTime(); |
|
114 | - return $this->issueDate > $now or $now > $this->expireDate; |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * @return string|null |
|
119 | - */ |
|
120 | - public function getIssuerName() { |
|
121 | - return $this->issuerName; |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * @return string|null |
|
126 | - */ |
|
127 | - public function getIssuerOrganization() { |
|
128 | - return $this->issuerOrganization; |
|
129 | - } |
|
30 | + protected $name; |
|
31 | + |
|
32 | + protected $commonName; |
|
33 | + |
|
34 | + protected $organization; |
|
35 | + |
|
36 | + protected $serial; |
|
37 | + |
|
38 | + protected $issueDate; |
|
39 | + |
|
40 | + protected $expireDate; |
|
41 | + |
|
42 | + protected $issuerName; |
|
43 | + |
|
44 | + protected $issuerOrganization; |
|
45 | + |
|
46 | + /** |
|
47 | + * @param string $data base64 encoded certificate |
|
48 | + * @param string $name |
|
49 | + * @throws \Exception If the certificate could not get parsed |
|
50 | + */ |
|
51 | + public function __construct($data, $name) { |
|
52 | + $this->name = $name; |
|
53 | + $gmt = new \DateTimeZone('GMT'); |
|
54 | + |
|
55 | + // If string starts with "file://" ignore the certificate |
|
56 | + $query = 'file://'; |
|
57 | + if(strtolower(substr($data, 0, strlen($query))) === $query) { |
|
58 | + throw new \Exception('Certificate could not get parsed.'); |
|
59 | + } |
|
60 | + |
|
61 | + $info = openssl_x509_parse($data); |
|
62 | + if(!is_array($info)) { |
|
63 | + throw new \Exception('Certificate could not get parsed.'); |
|
64 | + } |
|
65 | + |
|
66 | + $this->commonName = isset($info['subject']['CN']) ? $info['subject']['CN'] : null; |
|
67 | + $this->organization = isset($info['subject']['O']) ? $info['subject']['O'] : null; |
|
68 | + $this->issueDate = new \DateTime('@' . $info['validFrom_time_t'], $gmt); |
|
69 | + $this->expireDate = new \DateTime('@' . $info['validTo_time_t'], $gmt); |
|
70 | + $this->issuerName = isset($info['issuer']['CN']) ? $info['issuer']['CN'] : null; |
|
71 | + $this->issuerOrganization = isset($info['issuer']['O']) ? $info['issuer']['O'] : null; |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * @return string |
|
76 | + */ |
|
77 | + public function getName() { |
|
78 | + return $this->name; |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * @return string|null |
|
83 | + */ |
|
84 | + public function getCommonName() { |
|
85 | + return $this->commonName; |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * @return string |
|
90 | + */ |
|
91 | + public function getOrganization() { |
|
92 | + return $this->organization; |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * @return \DateTime |
|
97 | + */ |
|
98 | + public function getIssueDate() { |
|
99 | + return $this->issueDate; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * @return \DateTime |
|
104 | + */ |
|
105 | + public function getExpireDate() { |
|
106 | + return $this->expireDate; |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * @return bool |
|
111 | + */ |
|
112 | + public function isExpired() { |
|
113 | + $now = new \DateTime(); |
|
114 | + return $this->issueDate > $now or $now > $this->expireDate; |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * @return string|null |
|
119 | + */ |
|
120 | + public function getIssuerName() { |
|
121 | + return $this->issuerName; |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * @return string|null |
|
126 | + */ |
|
127 | + public function getIssuerOrganization() { |
|
128 | + return $this->issuerOrganization; |
|
129 | + } |
|
130 | 130 | } |
@@ -54,19 +54,19 @@ |
||
54 | 54 | |
55 | 55 | // If string starts with "file://" ignore the certificate |
56 | 56 | $query = 'file://'; |
57 | - if(strtolower(substr($data, 0, strlen($query))) === $query) { |
|
57 | + if (strtolower(substr($data, 0, strlen($query))) === $query) { |
|
58 | 58 | throw new \Exception('Certificate could not get parsed.'); |
59 | 59 | } |
60 | 60 | |
61 | 61 | $info = openssl_x509_parse($data); |
62 | - if(!is_array($info)) { |
|
62 | + if (!is_array($info)) { |
|
63 | 63 | throw new \Exception('Certificate could not get parsed.'); |
64 | 64 | } |
65 | 65 | |
66 | 66 | $this->commonName = isset($info['subject']['CN']) ? $info['subject']['CN'] : null; |
67 | 67 | $this->organization = isset($info['subject']['O']) ? $info['subject']['O'] : null; |
68 | - $this->issueDate = new \DateTime('@' . $info['validFrom_time_t'], $gmt); |
|
69 | - $this->expireDate = new \DateTime('@' . $info['validTo_time_t'], $gmt); |
|
68 | + $this->issueDate = new \DateTime('@'.$info['validFrom_time_t'], $gmt); |
|
69 | + $this->expireDate = new \DateTime('@'.$info['validTo_time_t'], $gmt); |
|
70 | 70 | $this->issuerName = isset($info['issuer']['CN']) ? $info['issuer']['CN'] : null; |
71 | 71 | $this->issuerOrganization = isset($info['issuer']['O']) ? $info['issuer']['O'] : null; |
72 | 72 | } |
@@ -65,13 +65,13 @@ discard block |
||
65 | 65 | * @return string |
66 | 66 | */ |
67 | 67 | private function buildFileNameWithSuffix($absolutePath, $postFix = '') { |
68 | - if($postFix !== '') { |
|
69 | - $postFix = '.' . ltrim($postFix, '.'); |
|
68 | + if ($postFix !== '') { |
|
69 | + $postFix = '.'.ltrim($postFix, '.'); |
|
70 | 70 | $postFix = str_replace(['\\', '/'], '', $postFix); |
71 | 71 | $absolutePath .= '-'; |
72 | 72 | } |
73 | 73 | |
74 | - return $absolutePath . $postFix; |
|
74 | + return $absolutePath.$postFix; |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | |
92 | 92 | // If a postfix got specified sanitize it and create a postfixed |
93 | 93 | // temporary file |
94 | - if($postFix !== '') { |
|
94 | + if ($postFix !== '') { |
|
95 | 95 | $fileNameWithPostfix = $this->buildFileNameWithSuffix($file, $postFix); |
96 | 96 | touch($fileNameWithPostfix); |
97 | 97 | chmod($fileNameWithPostfix, 0600); |
@@ -127,11 +127,11 @@ discard block |
||
127 | 127 | $this->current[] = $uniqueFileName; |
128 | 128 | |
129 | 129 | // Build a name without postfix |
130 | - $path = $this->buildFileNameWithSuffix($uniqueFileName . '-folder', $postFix); |
|
130 | + $path = $this->buildFileNameWithSuffix($uniqueFileName.'-folder', $postFix); |
|
131 | 131 | mkdir($path, 0700); |
132 | 132 | $this->current[] = $path; |
133 | 133 | |
134 | - return $path . '/'; |
|
134 | + return $path.'/'; |
|
135 | 135 | } else { |
136 | 136 | $this->log->warning( |
137 | 137 | 'Can not create a temporary folder in directory {dir}. Check it exists and has correct permissions', |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | if ($dh) { |
191 | 191 | while (($file = readdir($dh)) !== false) { |
192 | 192 | if (substr($file, 0, 7) === self::TMP_PREFIX) { |
193 | - $path = $this->tmpBaseDir . '/' . $file; |
|
193 | + $path = $this->tmpBaseDir.'/'.$file; |
|
194 | 194 | $mtime = filemtime($path); |
195 | 195 | if ($mtime < $cutOfTime) { |
196 | 196 | $files[] = $path; |
@@ -34,246 +34,246 @@ |
||
34 | 34 | use OCP\ITempManager; |
35 | 35 | |
36 | 36 | class TempManager implements ITempManager { |
37 | - /** @var string[] Current temporary files and folders, used for cleanup */ |
|
38 | - protected $current = []; |
|
39 | - /** @var string i.e. /tmp on linux systems */ |
|
40 | - protected $tmpBaseDir; |
|
41 | - /** @var ILogger */ |
|
42 | - protected $log; |
|
43 | - /** @var IConfig */ |
|
44 | - protected $config; |
|
37 | + /** @var string[] Current temporary files and folders, used for cleanup */ |
|
38 | + protected $current = []; |
|
39 | + /** @var string i.e. /tmp on linux systems */ |
|
40 | + protected $tmpBaseDir; |
|
41 | + /** @var ILogger */ |
|
42 | + protected $log; |
|
43 | + /** @var IConfig */ |
|
44 | + protected $config; |
|
45 | 45 | |
46 | - /** Prefix */ |
|
47 | - const TMP_PREFIX = 'oc_tmp_'; |
|
46 | + /** Prefix */ |
|
47 | + const TMP_PREFIX = 'oc_tmp_'; |
|
48 | 48 | |
49 | - /** |
|
50 | - * @param \OCP\ILogger $logger |
|
51 | - * @param \OCP\IConfig $config |
|
52 | - */ |
|
53 | - public function __construct(ILogger $logger, IConfig $config) { |
|
54 | - $this->log = $logger; |
|
55 | - $this->config = $config; |
|
56 | - $this->tmpBaseDir = $this->getTempBaseDir(); |
|
57 | - } |
|
49 | + /** |
|
50 | + * @param \OCP\ILogger $logger |
|
51 | + * @param \OCP\IConfig $config |
|
52 | + */ |
|
53 | + public function __construct(ILogger $logger, IConfig $config) { |
|
54 | + $this->log = $logger; |
|
55 | + $this->config = $config; |
|
56 | + $this->tmpBaseDir = $this->getTempBaseDir(); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * Builds the filename with suffix and removes potential dangerous characters |
|
61 | - * such as directory separators. |
|
62 | - * |
|
63 | - * @param string $absolutePath Absolute path to the file / folder |
|
64 | - * @param string $postFix Postfix appended to the temporary file name, may be user controlled |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - private function buildFileNameWithSuffix($absolutePath, $postFix = '') { |
|
68 | - if($postFix !== '') { |
|
69 | - $postFix = '.' . ltrim($postFix, '.'); |
|
70 | - $postFix = str_replace(['\\', '/'], '', $postFix); |
|
71 | - $absolutePath .= '-'; |
|
72 | - } |
|
59 | + /** |
|
60 | + * Builds the filename with suffix and removes potential dangerous characters |
|
61 | + * such as directory separators. |
|
62 | + * |
|
63 | + * @param string $absolutePath Absolute path to the file / folder |
|
64 | + * @param string $postFix Postfix appended to the temporary file name, may be user controlled |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + private function buildFileNameWithSuffix($absolutePath, $postFix = '') { |
|
68 | + if($postFix !== '') { |
|
69 | + $postFix = '.' . ltrim($postFix, '.'); |
|
70 | + $postFix = str_replace(['\\', '/'], '', $postFix); |
|
71 | + $absolutePath .= '-'; |
|
72 | + } |
|
73 | 73 | |
74 | - return $absolutePath . $postFix; |
|
75 | - } |
|
74 | + return $absolutePath . $postFix; |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Create a temporary file and return the path |
|
79 | - * |
|
80 | - * @param string $postFix Postfix appended to the temporary file name |
|
81 | - * @return string |
|
82 | - */ |
|
83 | - public function getTemporaryFile($postFix = '') { |
|
84 | - if (is_writable($this->tmpBaseDir)) { |
|
85 | - // To create an unique file and prevent the risk of race conditions |
|
86 | - // or duplicated temporary files by other means such as collisions |
|
87 | - // we need to create the file using `tempnam` and append a possible |
|
88 | - // postfix to it later |
|
89 | - $file = tempnam($this->tmpBaseDir, self::TMP_PREFIX); |
|
90 | - $this->current[] = $file; |
|
77 | + /** |
|
78 | + * Create a temporary file and return the path |
|
79 | + * |
|
80 | + * @param string $postFix Postfix appended to the temporary file name |
|
81 | + * @return string |
|
82 | + */ |
|
83 | + public function getTemporaryFile($postFix = '') { |
|
84 | + if (is_writable($this->tmpBaseDir)) { |
|
85 | + // To create an unique file and prevent the risk of race conditions |
|
86 | + // or duplicated temporary files by other means such as collisions |
|
87 | + // we need to create the file using `tempnam` and append a possible |
|
88 | + // postfix to it later |
|
89 | + $file = tempnam($this->tmpBaseDir, self::TMP_PREFIX); |
|
90 | + $this->current[] = $file; |
|
91 | 91 | |
92 | - // If a postfix got specified sanitize it and create a postfixed |
|
93 | - // temporary file |
|
94 | - if($postFix !== '') { |
|
95 | - $fileNameWithPostfix = $this->buildFileNameWithSuffix($file, $postFix); |
|
96 | - touch($fileNameWithPostfix); |
|
97 | - chmod($fileNameWithPostfix, 0600); |
|
98 | - $this->current[] = $fileNameWithPostfix; |
|
99 | - return $fileNameWithPostfix; |
|
100 | - } |
|
92 | + // If a postfix got specified sanitize it and create a postfixed |
|
93 | + // temporary file |
|
94 | + if($postFix !== '') { |
|
95 | + $fileNameWithPostfix = $this->buildFileNameWithSuffix($file, $postFix); |
|
96 | + touch($fileNameWithPostfix); |
|
97 | + chmod($fileNameWithPostfix, 0600); |
|
98 | + $this->current[] = $fileNameWithPostfix; |
|
99 | + return $fileNameWithPostfix; |
|
100 | + } |
|
101 | 101 | |
102 | - return $file; |
|
103 | - } else { |
|
104 | - $this->log->warning( |
|
105 | - 'Can not create a temporary file in directory {dir}. Check it exists and has correct permissions', |
|
106 | - [ |
|
107 | - 'dir' => $this->tmpBaseDir, |
|
108 | - ] |
|
109 | - ); |
|
110 | - return false; |
|
111 | - } |
|
112 | - } |
|
102 | + return $file; |
|
103 | + } else { |
|
104 | + $this->log->warning( |
|
105 | + 'Can not create a temporary file in directory {dir}. Check it exists and has correct permissions', |
|
106 | + [ |
|
107 | + 'dir' => $this->tmpBaseDir, |
|
108 | + ] |
|
109 | + ); |
|
110 | + return false; |
|
111 | + } |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * Create a temporary folder and return the path |
|
116 | - * |
|
117 | - * @param string $postFix Postfix appended to the temporary folder name |
|
118 | - * @return string |
|
119 | - */ |
|
120 | - public function getTemporaryFolder($postFix = '') { |
|
121 | - if (is_writable($this->tmpBaseDir)) { |
|
122 | - // To create an unique directory and prevent the risk of race conditions |
|
123 | - // or duplicated temporary files by other means such as collisions |
|
124 | - // we need to create the file using `tempnam` and append a possible |
|
125 | - // postfix to it later |
|
126 | - $uniqueFileName = tempnam($this->tmpBaseDir, self::TMP_PREFIX); |
|
127 | - $this->current[] = $uniqueFileName; |
|
114 | + /** |
|
115 | + * Create a temporary folder and return the path |
|
116 | + * |
|
117 | + * @param string $postFix Postfix appended to the temporary folder name |
|
118 | + * @return string |
|
119 | + */ |
|
120 | + public function getTemporaryFolder($postFix = '') { |
|
121 | + if (is_writable($this->tmpBaseDir)) { |
|
122 | + // To create an unique directory and prevent the risk of race conditions |
|
123 | + // or duplicated temporary files by other means such as collisions |
|
124 | + // we need to create the file using `tempnam` and append a possible |
|
125 | + // postfix to it later |
|
126 | + $uniqueFileName = tempnam($this->tmpBaseDir, self::TMP_PREFIX); |
|
127 | + $this->current[] = $uniqueFileName; |
|
128 | 128 | |
129 | - // Build a name without postfix |
|
130 | - $path = $this->buildFileNameWithSuffix($uniqueFileName . '-folder', $postFix); |
|
131 | - mkdir($path, 0700); |
|
132 | - $this->current[] = $path; |
|
129 | + // Build a name without postfix |
|
130 | + $path = $this->buildFileNameWithSuffix($uniqueFileName . '-folder', $postFix); |
|
131 | + mkdir($path, 0700); |
|
132 | + $this->current[] = $path; |
|
133 | 133 | |
134 | - return $path . '/'; |
|
135 | - } else { |
|
136 | - $this->log->warning( |
|
137 | - 'Can not create a temporary folder in directory {dir}. Check it exists and has correct permissions', |
|
138 | - [ |
|
139 | - 'dir' => $this->tmpBaseDir, |
|
140 | - ] |
|
141 | - ); |
|
142 | - return false; |
|
143 | - } |
|
144 | - } |
|
134 | + return $path . '/'; |
|
135 | + } else { |
|
136 | + $this->log->warning( |
|
137 | + 'Can not create a temporary folder in directory {dir}. Check it exists and has correct permissions', |
|
138 | + [ |
|
139 | + 'dir' => $this->tmpBaseDir, |
|
140 | + ] |
|
141 | + ); |
|
142 | + return false; |
|
143 | + } |
|
144 | + } |
|
145 | 145 | |
146 | - /** |
|
147 | - * Remove the temporary files and folders generated during this request |
|
148 | - */ |
|
149 | - public function clean() { |
|
150 | - $this->cleanFiles($this->current); |
|
151 | - } |
|
146 | + /** |
|
147 | + * Remove the temporary files and folders generated during this request |
|
148 | + */ |
|
149 | + public function clean() { |
|
150 | + $this->cleanFiles($this->current); |
|
151 | + } |
|
152 | 152 | |
153 | - /** |
|
154 | - * @param string[] $files |
|
155 | - */ |
|
156 | - protected function cleanFiles($files) { |
|
157 | - foreach ($files as $file) { |
|
158 | - if (file_exists($file)) { |
|
159 | - try { |
|
160 | - \OC_Helper::rmdirr($file); |
|
161 | - } catch (\UnexpectedValueException $ex) { |
|
162 | - $this->log->warning( |
|
163 | - "Error deleting temporary file/folder: {file} - Reason: {error}", |
|
164 | - [ |
|
165 | - 'file' => $file, |
|
166 | - 'error' => $ex->getMessage(), |
|
167 | - ] |
|
168 | - ); |
|
169 | - } |
|
170 | - } |
|
171 | - } |
|
172 | - } |
|
153 | + /** |
|
154 | + * @param string[] $files |
|
155 | + */ |
|
156 | + protected function cleanFiles($files) { |
|
157 | + foreach ($files as $file) { |
|
158 | + if (file_exists($file)) { |
|
159 | + try { |
|
160 | + \OC_Helper::rmdirr($file); |
|
161 | + } catch (\UnexpectedValueException $ex) { |
|
162 | + $this->log->warning( |
|
163 | + "Error deleting temporary file/folder: {file} - Reason: {error}", |
|
164 | + [ |
|
165 | + 'file' => $file, |
|
166 | + 'error' => $ex->getMessage(), |
|
167 | + ] |
|
168 | + ); |
|
169 | + } |
|
170 | + } |
|
171 | + } |
|
172 | + } |
|
173 | 173 | |
174 | - /** |
|
175 | - * Remove old temporary files and folders that were failed to be cleaned |
|
176 | - */ |
|
177 | - public function cleanOld() { |
|
178 | - $this->cleanFiles($this->getOldFiles()); |
|
179 | - } |
|
174 | + /** |
|
175 | + * Remove old temporary files and folders that were failed to be cleaned |
|
176 | + */ |
|
177 | + public function cleanOld() { |
|
178 | + $this->cleanFiles($this->getOldFiles()); |
|
179 | + } |
|
180 | 180 | |
181 | - /** |
|
182 | - * Get all temporary files and folders generated by oc older than an hour |
|
183 | - * |
|
184 | - * @return string[] |
|
185 | - */ |
|
186 | - protected function getOldFiles() { |
|
187 | - $cutOfTime = time() - 3600; |
|
188 | - $files = []; |
|
189 | - $dh = opendir($this->tmpBaseDir); |
|
190 | - if ($dh) { |
|
191 | - while (($file = readdir($dh)) !== false) { |
|
192 | - if (substr($file, 0, 7) === self::TMP_PREFIX) { |
|
193 | - $path = $this->tmpBaseDir . '/' . $file; |
|
194 | - $mtime = filemtime($path); |
|
195 | - if ($mtime < $cutOfTime) { |
|
196 | - $files[] = $path; |
|
197 | - } |
|
198 | - } |
|
199 | - } |
|
200 | - } |
|
201 | - return $files; |
|
202 | - } |
|
181 | + /** |
|
182 | + * Get all temporary files and folders generated by oc older than an hour |
|
183 | + * |
|
184 | + * @return string[] |
|
185 | + */ |
|
186 | + protected function getOldFiles() { |
|
187 | + $cutOfTime = time() - 3600; |
|
188 | + $files = []; |
|
189 | + $dh = opendir($this->tmpBaseDir); |
|
190 | + if ($dh) { |
|
191 | + while (($file = readdir($dh)) !== false) { |
|
192 | + if (substr($file, 0, 7) === self::TMP_PREFIX) { |
|
193 | + $path = $this->tmpBaseDir . '/' . $file; |
|
194 | + $mtime = filemtime($path); |
|
195 | + if ($mtime < $cutOfTime) { |
|
196 | + $files[] = $path; |
|
197 | + } |
|
198 | + } |
|
199 | + } |
|
200 | + } |
|
201 | + return $files; |
|
202 | + } |
|
203 | 203 | |
204 | - /** |
|
205 | - * Get the temporary base directory configured on the server |
|
206 | - * |
|
207 | - * @return string Path to the temporary directory or null |
|
208 | - * @throws \UnexpectedValueException |
|
209 | - */ |
|
210 | - public function getTempBaseDir() { |
|
211 | - if ($this->tmpBaseDir) { |
|
212 | - return $this->tmpBaseDir; |
|
213 | - } |
|
204 | + /** |
|
205 | + * Get the temporary base directory configured on the server |
|
206 | + * |
|
207 | + * @return string Path to the temporary directory or null |
|
208 | + * @throws \UnexpectedValueException |
|
209 | + */ |
|
210 | + public function getTempBaseDir() { |
|
211 | + if ($this->tmpBaseDir) { |
|
212 | + return $this->tmpBaseDir; |
|
213 | + } |
|
214 | 214 | |
215 | - $directories = []; |
|
216 | - if ($temp = $this->config->getSystemValue('tempdirectory', null)) { |
|
217 | - $directories[] = $temp; |
|
218 | - } |
|
219 | - if ($temp = \OC::$server->getIniWrapper()->get('upload_tmp_dir')) { |
|
220 | - $directories[] = $temp; |
|
221 | - } |
|
222 | - if ($temp = getenv('TMP')) { |
|
223 | - $directories[] = $temp; |
|
224 | - } |
|
225 | - if ($temp = getenv('TEMP')) { |
|
226 | - $directories[] = $temp; |
|
227 | - } |
|
228 | - if ($temp = getenv('TMPDIR')) { |
|
229 | - $directories[] = $temp; |
|
230 | - } |
|
231 | - if ($temp = sys_get_temp_dir()) { |
|
232 | - $directories[] = $temp; |
|
233 | - } |
|
215 | + $directories = []; |
|
216 | + if ($temp = $this->config->getSystemValue('tempdirectory', null)) { |
|
217 | + $directories[] = $temp; |
|
218 | + } |
|
219 | + if ($temp = \OC::$server->getIniWrapper()->get('upload_tmp_dir')) { |
|
220 | + $directories[] = $temp; |
|
221 | + } |
|
222 | + if ($temp = getenv('TMP')) { |
|
223 | + $directories[] = $temp; |
|
224 | + } |
|
225 | + if ($temp = getenv('TEMP')) { |
|
226 | + $directories[] = $temp; |
|
227 | + } |
|
228 | + if ($temp = getenv('TMPDIR')) { |
|
229 | + $directories[] = $temp; |
|
230 | + } |
|
231 | + if ($temp = sys_get_temp_dir()) { |
|
232 | + $directories[] = $temp; |
|
233 | + } |
|
234 | 234 | |
235 | - foreach ($directories as $dir) { |
|
236 | - if ($this->checkTemporaryDirectory($dir)) { |
|
237 | - return $dir; |
|
238 | - } |
|
239 | - } |
|
235 | + foreach ($directories as $dir) { |
|
236 | + if ($this->checkTemporaryDirectory($dir)) { |
|
237 | + return $dir; |
|
238 | + } |
|
239 | + } |
|
240 | 240 | |
241 | - $temp = tempnam(dirname(__FILE__), ''); |
|
242 | - if (file_exists($temp)) { |
|
243 | - unlink($temp); |
|
244 | - return dirname($temp); |
|
245 | - } |
|
246 | - throw new \UnexpectedValueException('Unable to detect system temporary directory'); |
|
247 | - } |
|
241 | + $temp = tempnam(dirname(__FILE__), ''); |
|
242 | + if (file_exists($temp)) { |
|
243 | + unlink($temp); |
|
244 | + return dirname($temp); |
|
245 | + } |
|
246 | + throw new \UnexpectedValueException('Unable to detect system temporary directory'); |
|
247 | + } |
|
248 | 248 | |
249 | - /** |
|
250 | - * Check if a temporary directory is ready for use |
|
251 | - * |
|
252 | - * @param mixed $directory |
|
253 | - * @return bool |
|
254 | - */ |
|
255 | - private function checkTemporaryDirectory($directory) { |
|
256 | - // suppress any possible errors caused by is_writable |
|
257 | - // checks missing or invalid path or characters, wrong permissions etc |
|
258 | - try { |
|
259 | - if (is_writable($directory)) { |
|
260 | - return true; |
|
261 | - } |
|
262 | - } catch (\Exception $e) { |
|
263 | - } |
|
264 | - $this->log->warning('Temporary directory {dir} is not present or writable', |
|
265 | - ['dir' => $directory] |
|
266 | - ); |
|
267 | - return false; |
|
268 | - } |
|
249 | + /** |
|
250 | + * Check if a temporary directory is ready for use |
|
251 | + * |
|
252 | + * @param mixed $directory |
|
253 | + * @return bool |
|
254 | + */ |
|
255 | + private function checkTemporaryDirectory($directory) { |
|
256 | + // suppress any possible errors caused by is_writable |
|
257 | + // checks missing or invalid path or characters, wrong permissions etc |
|
258 | + try { |
|
259 | + if (is_writable($directory)) { |
|
260 | + return true; |
|
261 | + } |
|
262 | + } catch (\Exception $e) { |
|
263 | + } |
|
264 | + $this->log->warning('Temporary directory {dir} is not present or writable', |
|
265 | + ['dir' => $directory] |
|
266 | + ); |
|
267 | + return false; |
|
268 | + } |
|
269 | 269 | |
270 | - /** |
|
271 | - * Override the temporary base directory |
|
272 | - * |
|
273 | - * @param string $directory |
|
274 | - */ |
|
275 | - public function overrideTempBaseDir($directory) { |
|
276 | - $this->tmpBaseDir = $directory; |
|
277 | - } |
|
270 | + /** |
|
271 | + * Override the temporary base directory |
|
272 | + * |
|
273 | + * @param string $directory |
|
274 | + */ |
|
275 | + public function overrideTempBaseDir($directory) { |
|
276 | + $this->tmpBaseDir = $directory; |
|
277 | + } |
|
278 | 278 | |
279 | 279 | } |
@@ -54,8 +54,7 @@ |
||
54 | 54 | */ |
55 | 55 | public function getBody() { |
56 | 56 | return $this->stream ? |
57 | - $this->response->getBody()->detach(): |
|
58 | - $this->response->getBody()->getContents(); |
|
57 | + $this->response->getBody()->detach() : $this->response->getBody()->getContents(); |
|
59 | 58 | } |
60 | 59 | |
61 | 60 | /** |
@@ -33,57 +33,57 @@ |
||
33 | 33 | * @package OC\Http |
34 | 34 | */ |
35 | 35 | class Response implements IResponse { |
36 | - /** @var ResponseInterface */ |
|
37 | - private $response; |
|
36 | + /** @var ResponseInterface */ |
|
37 | + private $response; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @var bool |
|
41 | - */ |
|
42 | - private $stream; |
|
39 | + /** |
|
40 | + * @var bool |
|
41 | + */ |
|
42 | + private $stream; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @param ResponseInterface $response |
|
46 | - * @param bool $stream |
|
47 | - */ |
|
48 | - public function __construct(ResponseInterface $response, $stream = false) { |
|
49 | - $this->response = $response; |
|
50 | - $this->stream = $stream; |
|
51 | - } |
|
44 | + /** |
|
45 | + * @param ResponseInterface $response |
|
46 | + * @param bool $stream |
|
47 | + */ |
|
48 | + public function __construct(ResponseInterface $response, $stream = false) { |
|
49 | + $this->response = $response; |
|
50 | + $this->stream = $stream; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @return string|resource |
|
55 | - */ |
|
56 | - public function getBody() { |
|
57 | - return $this->stream ? |
|
58 | - $this->response->getBody()->detach(): |
|
59 | - $this->response->getBody()->getContents(); |
|
60 | - } |
|
53 | + /** |
|
54 | + * @return string|resource |
|
55 | + */ |
|
56 | + public function getBody() { |
|
57 | + return $this->stream ? |
|
58 | + $this->response->getBody()->detach(): |
|
59 | + $this->response->getBody()->getContents(); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @return int |
|
64 | - */ |
|
65 | - public function getStatusCode(): int { |
|
66 | - return $this->response->getStatusCode(); |
|
67 | - } |
|
62 | + /** |
|
63 | + * @return int |
|
64 | + */ |
|
65 | + public function getStatusCode(): int { |
|
66 | + return $this->response->getStatusCode(); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * @param string $key |
|
71 | - * @return string |
|
72 | - */ |
|
73 | - public function getHeader(string $key): string { |
|
74 | - $headers = $this->response->getHeader($key); |
|
69 | + /** |
|
70 | + * @param string $key |
|
71 | + * @return string |
|
72 | + */ |
|
73 | + public function getHeader(string $key): string { |
|
74 | + $headers = $this->response->getHeader($key); |
|
75 | 75 | |
76 | - if (count($headers) === 0) { |
|
77 | - return ''; |
|
78 | - } |
|
76 | + if (count($headers) === 0) { |
|
77 | + return ''; |
|
78 | + } |
|
79 | 79 | |
80 | - return $headers[0]; |
|
81 | - } |
|
80 | + return $headers[0]; |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * @return array |
|
85 | - */ |
|
86 | - public function getHeaders(): array { |
|
87 | - return $this->response->getHeaders(); |
|
88 | - } |
|
83 | + /** |
|
84 | + * @return array |
|
85 | + */ |
|
86 | + public function getHeaders(): array { |
|
87 | + return $this->response->getHeaders(); |
|
88 | + } |
|
89 | 89 | } |
@@ -30,25 +30,25 @@ |
||
30 | 30 | parent::__construct($iterator); |
31 | 31 | |
32 | 32 | $appFolders = \OC::$APPSROOTS; |
33 | - foreach($appFolders as $key => $appFolder) { |
|
33 | + foreach ($appFolders as $key => $appFolder) { |
|
34 | 34 | $appFolders[$key] = rtrim($appFolder['path'], '/'); |
35 | 35 | } |
36 | 36 | |
37 | 37 | $excludedFolders = [ |
38 | - rtrim($root . '/data', '/'), |
|
39 | - rtrim($root . '/themes', '/'), |
|
40 | - rtrim($root . '/config', '/'), |
|
41 | - rtrim($root . '/apps', '/'), |
|
42 | - rtrim($root . '/assets', '/'), |
|
43 | - rtrim($root . '/lost+found', '/'), |
|
38 | + rtrim($root.'/data', '/'), |
|
39 | + rtrim($root.'/themes', '/'), |
|
40 | + rtrim($root.'/config', '/'), |
|
41 | + rtrim($root.'/apps', '/'), |
|
42 | + rtrim($root.'/assets', '/'), |
|
43 | + rtrim($root.'/lost+found', '/'), |
|
44 | 44 | // Ignore folders generated by updater since the updater is replaced |
45 | 45 | // after the integrity check is run. |
46 | 46 | // See https://github.com/owncloud/updater/issues/318#issuecomment-212497846 |
47 | - rtrim($root . '/updater', '/'), |
|
48 | - rtrim($root . '/_oc_upgrade', '/'), |
|
47 | + rtrim($root.'/updater', '/'), |
|
48 | + rtrim($root.'/_oc_upgrade', '/'), |
|
49 | 49 | ]; |
50 | 50 | $customDataDir = \OC::$server->getConfig()->getSystemValue('datadirectory', ''); |
51 | - if($customDataDir !== '') { |
|
51 | + if ($customDataDir !== '') { |
|
52 | 52 | $excludedFolders[] = rtrim($customDataDir, '/'); |
53 | 53 | } |
54 | 54 |
@@ -25,45 +25,45 @@ |
||
25 | 25 | namespace OC\IntegrityCheck\Iterator; |
26 | 26 | |
27 | 27 | class ExcludeFoldersByPathFilterIterator extends \RecursiveFilterIterator { |
28 | - private $excludedFolders; |
|
28 | + private $excludedFolders; |
|
29 | 29 | |
30 | - public function __construct(\RecursiveIterator $iterator, $root = '') { |
|
31 | - parent::__construct($iterator); |
|
30 | + public function __construct(\RecursiveIterator $iterator, $root = '') { |
|
31 | + parent::__construct($iterator); |
|
32 | 32 | |
33 | - $appFolders = \OC::$APPSROOTS; |
|
34 | - foreach($appFolders as $key => $appFolder) { |
|
35 | - $appFolders[$key] = rtrim($appFolder['path'], '/'); |
|
36 | - } |
|
33 | + $appFolders = \OC::$APPSROOTS; |
|
34 | + foreach($appFolders as $key => $appFolder) { |
|
35 | + $appFolders[$key] = rtrim($appFolder['path'], '/'); |
|
36 | + } |
|
37 | 37 | |
38 | - $excludedFolders = [ |
|
39 | - rtrim($root . '/data', '/'), |
|
40 | - rtrim($root . '/themes', '/'), |
|
41 | - rtrim($root . '/config', '/'), |
|
42 | - rtrim($root . '/apps', '/'), |
|
43 | - rtrim($root . '/assets', '/'), |
|
44 | - rtrim($root . '/lost+found', '/'), |
|
45 | - // Ignore folders generated by updater since the updater is replaced |
|
46 | - // after the integrity check is run. |
|
47 | - // See https://github.com/owncloud/updater/issues/318#issuecomment-212497846 |
|
48 | - rtrim($root . '/updater', '/'), |
|
49 | - rtrim($root . '/_oc_upgrade', '/'), |
|
50 | - ]; |
|
51 | - $customDataDir = \OC::$server->getConfig()->getSystemValue('datadirectory', ''); |
|
52 | - if($customDataDir !== '') { |
|
53 | - $excludedFolders[] = rtrim($customDataDir, '/'); |
|
54 | - } |
|
38 | + $excludedFolders = [ |
|
39 | + rtrim($root . '/data', '/'), |
|
40 | + rtrim($root . '/themes', '/'), |
|
41 | + rtrim($root . '/config', '/'), |
|
42 | + rtrim($root . '/apps', '/'), |
|
43 | + rtrim($root . '/assets', '/'), |
|
44 | + rtrim($root . '/lost+found', '/'), |
|
45 | + // Ignore folders generated by updater since the updater is replaced |
|
46 | + // after the integrity check is run. |
|
47 | + // See https://github.com/owncloud/updater/issues/318#issuecomment-212497846 |
|
48 | + rtrim($root . '/updater', '/'), |
|
49 | + rtrim($root . '/_oc_upgrade', '/'), |
|
50 | + ]; |
|
51 | + $customDataDir = \OC::$server->getConfig()->getSystemValue('datadirectory', ''); |
|
52 | + if($customDataDir !== '') { |
|
53 | + $excludedFolders[] = rtrim($customDataDir, '/'); |
|
54 | + } |
|
55 | 55 | |
56 | - $this->excludedFolders = array_merge($excludedFolders, $appFolders); |
|
57 | - } |
|
56 | + $this->excludedFolders = array_merge($excludedFolders, $appFolders); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * @return bool |
|
61 | - */ |
|
62 | - public function accept() { |
|
63 | - return !\in_array( |
|
64 | - $this->current()->getPathName(), |
|
65 | - $this->excludedFolders, |
|
66 | - true |
|
67 | - ); |
|
68 | - } |
|
59 | + /** |
|
60 | + * @return bool |
|
61 | + */ |
|
62 | + public function accept() { |
|
63 | + return !\in_array( |
|
64 | + $this->current()->getPathName(), |
|
65 | + $this->excludedFolders, |
|
66 | + true |
|
67 | + ); |
|
68 | + } |
|
69 | 69 | } |
@@ -35,46 +35,46 @@ |
||
35 | 35 | */ |
36 | 36 | class HintException extends \Exception { |
37 | 37 | |
38 | - private $hint; |
|
38 | + private $hint; |
|
39 | 39 | |
40 | - /** |
|
41 | - * HintException constructor. |
|
42 | - * |
|
43 | - * @param string $message The error message. It will be not revealed to the |
|
44 | - * the user (unless the hint is empty) and thus |
|
45 | - * should be not translated. |
|
46 | - * @param string $hint A useful message that is presented to the end |
|
47 | - * user. It should be translated, but must not |
|
48 | - * contain sensitive data. |
|
49 | - * @param int $code |
|
50 | - * @param \Exception|null $previous |
|
51 | - */ |
|
52 | - public function __construct($message, $hint = '', $code = 0, \Exception $previous = null) { |
|
53 | - $this->hint = $hint; |
|
54 | - parent::__construct($message, $code, $previous); |
|
55 | - } |
|
40 | + /** |
|
41 | + * HintException constructor. |
|
42 | + * |
|
43 | + * @param string $message The error message. It will be not revealed to the |
|
44 | + * the user (unless the hint is empty) and thus |
|
45 | + * should be not translated. |
|
46 | + * @param string $hint A useful message that is presented to the end |
|
47 | + * user. It should be translated, but must not |
|
48 | + * contain sensitive data. |
|
49 | + * @param int $code |
|
50 | + * @param \Exception|null $previous |
|
51 | + */ |
|
52 | + public function __construct($message, $hint = '', $code = 0, \Exception $previous = null) { |
|
53 | + $this->hint = $hint; |
|
54 | + parent::__construct($message, $code, $previous); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Returns a string representation of this Exception that includes the error |
|
59 | - * code, the message and the hint. |
|
60 | - * |
|
61 | - * @return string |
|
62 | - */ |
|
63 | - public function __toString() { |
|
64 | - return __CLASS__ . ": [{$this->code}]: {$this->message} ({$this->hint})\n"; |
|
65 | - } |
|
57 | + /** |
|
58 | + * Returns a string representation of this Exception that includes the error |
|
59 | + * code, the message and the hint. |
|
60 | + * |
|
61 | + * @return string |
|
62 | + */ |
|
63 | + public function __toString() { |
|
64 | + return __CLASS__ . ": [{$this->code}]: {$this->message} ({$this->hint})\n"; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * Returns the hint with the intention to be presented to the end user. If |
|
69 | - * an empty hint was specified upon instatiation, the message is returned |
|
70 | - * instead. |
|
71 | - * |
|
72 | - * @return string |
|
73 | - */ |
|
74 | - public function getHint() { |
|
75 | - if (empty($this->hint)) { |
|
76 | - return $this->message; |
|
77 | - } |
|
78 | - return $this->hint; |
|
79 | - } |
|
67 | + /** |
|
68 | + * Returns the hint with the intention to be presented to the end user. If |
|
69 | + * an empty hint was specified upon instatiation, the message is returned |
|
70 | + * instead. |
|
71 | + * |
|
72 | + * @return string |
|
73 | + */ |
|
74 | + public function getHint() { |
|
75 | + if (empty($this->hint)) { |
|
76 | + return $this->message; |
|
77 | + } |
|
78 | + return $this->hint; |
|
79 | + } |
|
80 | 80 | } |
@@ -61,7 +61,7 @@ |
||
61 | 61 | * @return string |
62 | 62 | */ |
63 | 63 | public function __toString() { |
64 | - return __CLASS__ . ": [{$this->code}]: {$this->message} ({$this->hint})\n"; |
|
64 | + return __CLASS__.": [{$this->code}]: {$this->message} ({$this->hint})\n"; |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -26,79 +26,79 @@ |
||
26 | 26 | use OCP\Diagnostics\IEvent; |
27 | 27 | |
28 | 28 | class Event implements IEvent { |
29 | - /** |
|
30 | - * @var string |
|
31 | - */ |
|
32 | - protected $id; |
|
29 | + /** |
|
30 | + * @var string |
|
31 | + */ |
|
32 | + protected $id; |
|
33 | 33 | |
34 | - /** |
|
35 | - * @var float |
|
36 | - */ |
|
37 | - protected $start; |
|
34 | + /** |
|
35 | + * @var float |
|
36 | + */ |
|
37 | + protected $start; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @var float |
|
41 | - */ |
|
42 | - protected $end; |
|
39 | + /** |
|
40 | + * @var float |
|
41 | + */ |
|
42 | + protected $end; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @var string |
|
46 | - */ |
|
47 | - protected $description; |
|
44 | + /** |
|
45 | + * @var string |
|
46 | + */ |
|
47 | + protected $description; |
|
48 | 48 | |
49 | - /** |
|
50 | - * @param string $id |
|
51 | - * @param string $description |
|
52 | - * @param float $start |
|
53 | - */ |
|
54 | - public function __construct($id, $description, $start) { |
|
55 | - $this->id = $id; |
|
56 | - $this->description = $description; |
|
57 | - $this->start = $start; |
|
58 | - } |
|
49 | + /** |
|
50 | + * @param string $id |
|
51 | + * @param string $description |
|
52 | + * @param float $start |
|
53 | + */ |
|
54 | + public function __construct($id, $description, $start) { |
|
55 | + $this->id = $id; |
|
56 | + $this->description = $description; |
|
57 | + $this->start = $start; |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * @param float $time |
|
62 | - */ |
|
63 | - public function end($time) { |
|
64 | - $this->end = $time; |
|
65 | - } |
|
60 | + /** |
|
61 | + * @param float $time |
|
62 | + */ |
|
63 | + public function end($time) { |
|
64 | + $this->end = $time; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * @return float |
|
69 | - */ |
|
70 | - public function getStart() { |
|
71 | - return $this->start; |
|
72 | - } |
|
67 | + /** |
|
68 | + * @return float |
|
69 | + */ |
|
70 | + public function getStart() { |
|
71 | + return $this->start; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @return string |
|
76 | - */ |
|
77 | - public function getId() { |
|
78 | - return $this->id; |
|
79 | - } |
|
74 | + /** |
|
75 | + * @return string |
|
76 | + */ |
|
77 | + public function getId() { |
|
78 | + return $this->id; |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * @return string |
|
83 | - */ |
|
84 | - public function getDescription() { |
|
85 | - return $this->description; |
|
86 | - } |
|
81 | + /** |
|
82 | + * @return string |
|
83 | + */ |
|
84 | + public function getDescription() { |
|
85 | + return $this->description; |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * @return float |
|
90 | - */ |
|
91 | - public function getEnd() { |
|
92 | - return $this->end; |
|
93 | - } |
|
88 | + /** |
|
89 | + * @return float |
|
90 | + */ |
|
91 | + public function getEnd() { |
|
92 | + return $this->end; |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * @return float |
|
97 | - */ |
|
98 | - public function getDuration() { |
|
99 | - if (!$this->end) { |
|
100 | - $this->end = microtime(true); |
|
101 | - } |
|
102 | - return $this->end - $this->start; |
|
103 | - } |
|
95 | + /** |
|
96 | + * @return float |
|
97 | + */ |
|
98 | + public function getDuration() { |
|
99 | + if (!$this->end) { |
|
100 | + $this->end = microtime(true); |
|
101 | + } |
|
102 | + return $this->end - $this->start; |
|
103 | + } |
|
104 | 104 | } |
@@ -134,7 +134,7 @@ |
||
134 | 134 | } |
135 | 135 | if(is_dir($source.'/'.$file)) { |
136 | 136 | $this->addRecursive($path.'/'.$file, $source.'/'.$file); |
137 | - }else{ |
|
137 | + } else{ |
|
138 | 138 | $this->addFile($path.'/'.$file, $source.'/'.$file); |
139 | 139 | } |
140 | 140 | } |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * @param string $source either a local file or string data |
50 | 50 | * @return bool |
51 | 51 | */ |
52 | - public abstract function addFile($path, $source=''); |
|
52 | + public abstract function addFile($path, $source = ''); |
|
53 | 53 | /** |
54 | 54 | * rename a file or folder in the archive |
55 | 55 | * @param string $source |
@@ -126,15 +126,15 @@ discard block |
||
126 | 126 | */ |
127 | 127 | public function addRecursive($path, $source) { |
128 | 128 | $dh = opendir($source); |
129 | - if(is_resource($dh)) { |
|
129 | + if (is_resource($dh)) { |
|
130 | 130 | $this->addFolder($path); |
131 | 131 | while (($file = readdir($dh)) !== false) { |
132 | - if($file === '.' || $file === '..') { |
|
132 | + if ($file === '.' || $file === '..') { |
|
133 | 133 | continue; |
134 | 134 | } |
135 | - if(is_dir($source.'/'.$file)) { |
|
135 | + if (is_dir($source.'/'.$file)) { |
|
136 | 136 | $this->addRecursive($path.'/'.$file, $source.'/'.$file); |
137 | - }else{ |
|
137 | + } else { |
|
138 | 138 | $this->addFile($path.'/'.$file, $source.'/'.$file); |
139 | 139 | } |
140 | 140 | } |
@@ -31,110 +31,110 @@ |
||
31 | 31 | namespace OC\Archive; |
32 | 32 | |
33 | 33 | abstract class Archive { |
34 | - /** |
|
35 | - * @param $source |
|
36 | - */ |
|
37 | - public abstract function __construct($source); |
|
38 | - /** |
|
39 | - * add an empty folder to the archive |
|
40 | - * @param string $path |
|
41 | - * @return bool |
|
42 | - */ |
|
43 | - public abstract function addFolder($path); |
|
44 | - /** |
|
45 | - * add a file to the archive |
|
46 | - * @param string $path |
|
47 | - * @param string $source either a local file or string data |
|
48 | - * @return bool |
|
49 | - */ |
|
50 | - public abstract function addFile($path, $source=''); |
|
51 | - /** |
|
52 | - * rename a file or folder in the archive |
|
53 | - * @param string $source |
|
54 | - * @param string $dest |
|
55 | - * @return bool |
|
56 | - */ |
|
57 | - public abstract function rename($source, $dest); |
|
58 | - /** |
|
59 | - * get the uncompressed size of a file in the archive |
|
60 | - * @param string $path |
|
61 | - * @return int |
|
62 | - */ |
|
63 | - public abstract function filesize($path); |
|
64 | - /** |
|
65 | - * get the last modified time of a file in the archive |
|
66 | - * @param string $path |
|
67 | - * @return int |
|
68 | - */ |
|
69 | - public abstract function mtime($path); |
|
70 | - /** |
|
71 | - * get the files in a folder |
|
72 | - * @param string $path |
|
73 | - * @return array |
|
74 | - */ |
|
75 | - public abstract function getFolder($path); |
|
76 | - /** |
|
77 | - * get all files in the archive |
|
78 | - * @return array |
|
79 | - */ |
|
80 | - public abstract function getFiles(); |
|
81 | - /** |
|
82 | - * get the content of a file |
|
83 | - * @param string $path |
|
84 | - * @return string |
|
85 | - */ |
|
86 | - public abstract function getFile($path); |
|
87 | - /** |
|
88 | - * extract a single file from the archive |
|
89 | - * @param string $path |
|
90 | - * @param string $dest |
|
91 | - * @return bool |
|
92 | - */ |
|
93 | - public abstract function extractFile($path, $dest); |
|
94 | - /** |
|
95 | - * extract the archive |
|
96 | - * @param string $dest |
|
97 | - * @return bool |
|
98 | - */ |
|
99 | - public abstract function extract($dest); |
|
100 | - /** |
|
101 | - * check if a file or folder exists in the archive |
|
102 | - * @param string $path |
|
103 | - * @return bool |
|
104 | - */ |
|
105 | - public abstract function fileExists($path); |
|
106 | - /** |
|
107 | - * remove a file or folder from the archive |
|
108 | - * @param string $path |
|
109 | - * @return bool |
|
110 | - */ |
|
111 | - public abstract function remove($path); |
|
112 | - /** |
|
113 | - * get a file handler |
|
114 | - * @param string $path |
|
115 | - * @param string $mode |
|
116 | - * @return resource |
|
117 | - */ |
|
118 | - public abstract function getStream($path, $mode); |
|
119 | - /** |
|
120 | - * add a folder and all its content |
|
121 | - * @param string $path |
|
122 | - * @param string $source |
|
123 | - */ |
|
124 | - public function addRecursive($path, $source) { |
|
125 | - $dh = opendir($source); |
|
126 | - if(is_resource($dh)) { |
|
127 | - $this->addFolder($path); |
|
128 | - while (($file = readdir($dh)) !== false) { |
|
129 | - if($file === '.' || $file === '..') { |
|
130 | - continue; |
|
131 | - } |
|
132 | - if(is_dir($source.'/'.$file)) { |
|
133 | - $this->addRecursive($path.'/'.$file, $source.'/'.$file); |
|
134 | - }else{ |
|
135 | - $this->addFile($path.'/'.$file, $source.'/'.$file); |
|
136 | - } |
|
137 | - } |
|
138 | - } |
|
139 | - } |
|
34 | + /** |
|
35 | + * @param $source |
|
36 | + */ |
|
37 | + public abstract function __construct($source); |
|
38 | + /** |
|
39 | + * add an empty folder to the archive |
|
40 | + * @param string $path |
|
41 | + * @return bool |
|
42 | + */ |
|
43 | + public abstract function addFolder($path); |
|
44 | + /** |
|
45 | + * add a file to the archive |
|
46 | + * @param string $path |
|
47 | + * @param string $source either a local file or string data |
|
48 | + * @return bool |
|
49 | + */ |
|
50 | + public abstract function addFile($path, $source=''); |
|
51 | + /** |
|
52 | + * rename a file or folder in the archive |
|
53 | + * @param string $source |
|
54 | + * @param string $dest |
|
55 | + * @return bool |
|
56 | + */ |
|
57 | + public abstract function rename($source, $dest); |
|
58 | + /** |
|
59 | + * get the uncompressed size of a file in the archive |
|
60 | + * @param string $path |
|
61 | + * @return int |
|
62 | + */ |
|
63 | + public abstract function filesize($path); |
|
64 | + /** |
|
65 | + * get the last modified time of a file in the archive |
|
66 | + * @param string $path |
|
67 | + * @return int |
|
68 | + */ |
|
69 | + public abstract function mtime($path); |
|
70 | + /** |
|
71 | + * get the files in a folder |
|
72 | + * @param string $path |
|
73 | + * @return array |
|
74 | + */ |
|
75 | + public abstract function getFolder($path); |
|
76 | + /** |
|
77 | + * get all files in the archive |
|
78 | + * @return array |
|
79 | + */ |
|
80 | + public abstract function getFiles(); |
|
81 | + /** |
|
82 | + * get the content of a file |
|
83 | + * @param string $path |
|
84 | + * @return string |
|
85 | + */ |
|
86 | + public abstract function getFile($path); |
|
87 | + /** |
|
88 | + * extract a single file from the archive |
|
89 | + * @param string $path |
|
90 | + * @param string $dest |
|
91 | + * @return bool |
|
92 | + */ |
|
93 | + public abstract function extractFile($path, $dest); |
|
94 | + /** |
|
95 | + * extract the archive |
|
96 | + * @param string $dest |
|
97 | + * @return bool |
|
98 | + */ |
|
99 | + public abstract function extract($dest); |
|
100 | + /** |
|
101 | + * check if a file or folder exists in the archive |
|
102 | + * @param string $path |
|
103 | + * @return bool |
|
104 | + */ |
|
105 | + public abstract function fileExists($path); |
|
106 | + /** |
|
107 | + * remove a file or folder from the archive |
|
108 | + * @param string $path |
|
109 | + * @return bool |
|
110 | + */ |
|
111 | + public abstract function remove($path); |
|
112 | + /** |
|
113 | + * get a file handler |
|
114 | + * @param string $path |
|
115 | + * @param string $mode |
|
116 | + * @return resource |
|
117 | + */ |
|
118 | + public abstract function getStream($path, $mode); |
|
119 | + /** |
|
120 | + * add a folder and all its content |
|
121 | + * @param string $path |
|
122 | + * @param string $source |
|
123 | + */ |
|
124 | + public function addRecursive($path, $source) { |
|
125 | + $dh = opendir($source); |
|
126 | + if(is_resource($dh)) { |
|
127 | + $this->addFolder($path); |
|
128 | + while (($file = readdir($dh)) !== false) { |
|
129 | + if($file === '.' || $file === '..') { |
|
130 | + continue; |
|
131 | + } |
|
132 | + if(is_dir($source.'/'.$file)) { |
|
133 | + $this->addRecursive($path.'/'.$file, $source.'/'.$file); |
|
134 | + }else{ |
|
135 | + $this->addFile($path.'/'.$file, $source.'/'.$file); |
|
136 | + } |
|
137 | + } |
|
138 | + } |
|
139 | + } |
|
140 | 140 | } |
@@ -25,14 +25,14 @@ |
||
25 | 25 | namespace OC; |
26 | 26 | |
27 | 27 | class NaturalSort_DefaultCollator { |
28 | - public function compare($a, $b) { |
|
29 | - $result = strcasecmp($a, $b); |
|
30 | - if ($result === 0) { |
|
31 | - if ($a === $b) { |
|
32 | - return 0; |
|
33 | - } |
|
34 | - return ($a > $b) ? -1 : 1; |
|
35 | - } |
|
36 | - return ($result < 0) ? -1 : 1; |
|
37 | - } |
|
28 | + public function compare($a, $b) { |
|
29 | + $result = strcasecmp($a, $b); |
|
30 | + if ($result === 0) { |
|
31 | + if ($a === $b) { |
|
32 | + return 0; |
|
33 | + } |
|
34 | + return ($a > $b) ? -1 : 1; |
|
35 | + } |
|
36 | + return ($result < 0) ? -1 : 1; |
|
37 | + } |
|
38 | 38 | } |
@@ -61,7 +61,7 @@ |
||
61 | 61 | parent::__construct( 'core', 'layout.user' ); |
62 | 62 | if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) { |
63 | 63 | $this->assign('bodyid', 'body-settings'); |
64 | - }else{ |
|
64 | + } else{ |
|
65 | 65 | $this->assign('bodyid', 'body-user'); |
66 | 66 | } |
67 | 67 |
@@ -53,313 +53,313 @@ |
||
53 | 53 | |
54 | 54 | class TemplateLayout extends \OC_Template { |
55 | 55 | |
56 | - private static $versionHash = ''; |
|
57 | - |
|
58 | - /** |
|
59 | - * @var \OCP\IConfig |
|
60 | - */ |
|
61 | - private $config; |
|
62 | - |
|
63 | - /** |
|
64 | - * @param string $renderAs |
|
65 | - * @param string $appId application id |
|
66 | - */ |
|
67 | - public function __construct($renderAs, $appId = '') { |
|
68 | - |
|
69 | - // yes - should be injected .... |
|
70 | - $this->config = \OC::$server->getConfig(); |
|
71 | - |
|
72 | - if(\OCP\Util::isIE()) { |
|
73 | - \OC_Util::addStyle('ie'); |
|
74 | - } |
|
75 | - |
|
76 | - // Decide which page we show |
|
77 | - if($renderAs === 'user') { |
|
78 | - parent::__construct( 'core', 'layout.user' ); |
|
79 | - if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) { |
|
80 | - $this->assign('bodyid', 'body-settings'); |
|
81 | - }else{ |
|
82 | - $this->assign('bodyid', 'body-user'); |
|
83 | - } |
|
84 | - |
|
85 | - // Add navigation entry |
|
86 | - $this->assign( 'application', ''); |
|
87 | - $this->assign( 'appid', $appId ); |
|
88 | - $navigation = \OC::$server->getNavigationManager()->getAll(); |
|
89 | - $this->assign( 'navigation', $navigation); |
|
90 | - $settingsNavigation = \OC::$server->getNavigationManager()->getAll('settings'); |
|
91 | - $this->assign( 'settingsnavigation', $settingsNavigation); |
|
92 | - foreach($navigation as $entry) { |
|
93 | - if ($entry['active']) { |
|
94 | - $this->assign( 'application', $entry['name'] ); |
|
95 | - break; |
|
96 | - } |
|
97 | - } |
|
98 | - |
|
99 | - foreach($settingsNavigation as $entry) { |
|
100 | - if ($entry['active']) { |
|
101 | - $this->assign( 'application', $entry['name'] ); |
|
102 | - break; |
|
103 | - } |
|
104 | - } |
|
105 | - $userDisplayName = \OC_User::getDisplayName(); |
|
106 | - $this->assign('user_displayname', $userDisplayName); |
|
107 | - $this->assign('user_uid', \OC_User::getUser()); |
|
108 | - |
|
109 | - if (\OC_User::getUser() === false) { |
|
110 | - $this->assign('userAvatarSet', false); |
|
111 | - } else { |
|
112 | - $this->assign('userAvatarSet', \OC::$server->getAvatarManager()->getAvatar(\OC_User::getUser())->exists()); |
|
113 | - $this->assign('userAvatarVersion', $this->config->getUserValue(\OC_User::getUser(), 'avatar', 'version', 0)); |
|
114 | - } |
|
115 | - |
|
116 | - // check if app menu icons should be inverted |
|
117 | - try { |
|
118 | - /** @var \OCA\Theming\Util $util */ |
|
119 | - $util = \OC::$server->query(\OCA\Theming\Util::class); |
|
120 | - $this->assign('themingInvertMenu', $util->invertTextColor(\OC::$server->getThemingDefaults()->getColorPrimary())); |
|
121 | - } catch (\OCP\AppFramework\QueryException $e) { |
|
122 | - $this->assign('themingInvertMenu', false); |
|
123 | - } catch (\OCP\AutoloadNotAllowedException $e) { |
|
124 | - $this->assign('themingInvertMenu', false); |
|
125 | - } |
|
126 | - |
|
127 | - } else if ($renderAs === 'error') { |
|
128 | - parent::__construct('core', 'layout.guest', '', false); |
|
129 | - $this->assign('bodyid', 'body-login'); |
|
130 | - $this->assign('user_displayname', ''); |
|
131 | - $this->assign('user_uid', ''); |
|
132 | - } else if ($renderAs === 'guest') { |
|
133 | - parent::__construct('core', 'layout.guest'); |
|
134 | - \OC_Util::addStyle('guest'); |
|
135 | - $this->assign('bodyid', 'body-login'); |
|
136 | - |
|
137 | - $userDisplayName = \OC_User::getDisplayName(); |
|
138 | - $this->assign('user_displayname', $userDisplayName); |
|
139 | - $this->assign('user_uid', \OC_User::getUser()); |
|
140 | - } else if ($renderAs === 'public') { |
|
141 | - parent::__construct('core', 'layout.public'); |
|
142 | - $this->assign( 'appid', $appId ); |
|
143 | - $this->assign('bodyid', 'body-public'); |
|
144 | - |
|
145 | - /** @var IRegistry $subscription */ |
|
146 | - $subscription = \OC::$server->query(IRegistry::class); |
|
147 | - $showSimpleSignup = $this->config->getSystemValueBool('simpleSignUpLink.shown', true); |
|
148 | - if ($showSimpleSignup && $subscription->delegateHasValidSubscription()) { |
|
149 | - $showSimpleSignup = false; |
|
150 | - } |
|
151 | - $this->assign('showSimpleSignUpLink', $showSimpleSignup); |
|
152 | - } else { |
|
153 | - parent::__construct('core', 'layout.base'); |
|
154 | - |
|
155 | - } |
|
156 | - // Send the language and the locale to our layouts |
|
157 | - $lang = \OC::$server->getL10NFactory()->findLanguage(); |
|
158 | - $locale = \OC::$server->getL10NFactory()->findLocale($lang); |
|
159 | - |
|
160 | - $lang = str_replace('_', '-', $lang); |
|
161 | - $this->assign('language', $lang); |
|
162 | - $this->assign('locale', $locale); |
|
163 | - |
|
164 | - if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
165 | - if (empty(self::$versionHash)) { |
|
166 | - $v = \OC_App::getAppVersions(); |
|
167 | - $v['core'] = implode('.', \OCP\Util::getVersion()); |
|
168 | - self::$versionHash = substr(md5(implode(',', $v)), 0, 8); |
|
169 | - } |
|
170 | - } else { |
|
171 | - self::$versionHash = md5('not installed'); |
|
172 | - } |
|
173 | - |
|
174 | - // Add the js files |
|
175 | - $jsFiles = self::findJavascriptFiles(\OC_Util::$scripts); |
|
176 | - $this->assign('jsfiles', []); |
|
177 | - if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') { |
|
178 | - if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) { |
|
179 | - $jsConfigHelper = new JSConfigHelper( |
|
180 | - \OC::$server->getL10N('lib'), |
|
181 | - \OC::$server->query(Defaults::class), |
|
182 | - \OC::$server->getAppManager(), |
|
183 | - \OC::$server->getSession(), |
|
184 | - \OC::$server->getUserSession()->getUser(), |
|
185 | - $this->config, |
|
186 | - \OC::$server->getGroupManager(), |
|
187 | - \OC::$server->getIniWrapper(), |
|
188 | - \OC::$server->getURLGenerator(), |
|
189 | - \OC::$server->getCapabilitiesManager() |
|
190 | - ); |
|
191 | - $this->assign('inline_ocjs', $jsConfigHelper->getConfig()); |
|
192 | - } else { |
|
193 | - $this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash])); |
|
194 | - } |
|
195 | - } |
|
196 | - foreach($jsFiles as $info) { |
|
197 | - $web = $info[1]; |
|
198 | - $file = $info[2]; |
|
199 | - $this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
200 | - } |
|
201 | - |
|
202 | - try { |
|
203 | - $pathInfo = \OC::$server->getRequest()->getPathInfo(); |
|
204 | - } catch (\Exception $e) { |
|
205 | - $pathInfo = ''; |
|
206 | - } |
|
207 | - |
|
208 | - // Do not initialise scss appdata until we have a fully installed instance |
|
209 | - // Do not load scss for update, errors, installation or login page |
|
210 | - if(\OC::$server->getSystemConfig()->getValue('installed', false) |
|
211 | - && !\OCP\Util::needUpgrade() |
|
212 | - && $pathInfo !== '' |
|
213 | - && !preg_match('/^\/login/', $pathInfo) |
|
214 | - && $renderAs !== 'error' |
|
215 | - ) { |
|
216 | - $cssFiles = self::findStylesheetFiles(\OC_Util::$styles); |
|
217 | - } else { |
|
218 | - // If we ignore the scss compiler, |
|
219 | - // we need to load the guest css fallback |
|
220 | - \OC_Util::addStyle('guest'); |
|
221 | - $cssFiles = self::findStylesheetFiles(\OC_Util::$styles, false); |
|
222 | - } |
|
223 | - |
|
224 | - $this->assign('cssfiles', []); |
|
225 | - $this->assign('printcssfiles', []); |
|
226 | - $this->assign('versionHash', self::$versionHash); |
|
227 | - foreach($cssFiles as $info) { |
|
228 | - $web = $info[1]; |
|
229 | - $file = $info[2]; |
|
230 | - |
|
231 | - if (substr($file, -strlen('print.css')) === 'print.css') { |
|
232 | - $this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
233 | - } else { |
|
234 | - $suffix = $this->getVersionHashSuffix($web, $file); |
|
235 | - |
|
236 | - if (strpos($file, '?v=') == false) { |
|
237 | - $this->append( 'cssfiles', $web.'/'.$file . $suffix); |
|
238 | - } else { |
|
239 | - $this->append( 'cssfiles', $web.'/'.$file . '-' . substr($suffix, 3)); |
|
240 | - } |
|
241 | - |
|
242 | - } |
|
243 | - } |
|
244 | - |
|
245 | - /** @var InitialStateService $initialState */ |
|
246 | - $initialState = \OC::$server->query(InitialStateService::class); |
|
247 | - $this->assign('initialStates', $initialState->getInitialStates()); |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * @param string $path |
|
252 | - * @param string $file |
|
253 | - * @return string |
|
254 | - */ |
|
255 | - protected function getVersionHashSuffix($path = false, $file = false) { |
|
256 | - if ($this->config->getSystemValue('debug', false)) { |
|
257 | - // allows chrome workspace mapping in debug mode |
|
258 | - return ""; |
|
259 | - } |
|
260 | - $themingSuffix = ''; |
|
261 | - $v = []; |
|
262 | - |
|
263 | - if ($this->config->getSystemValue('installed', false)) { |
|
264 | - if (\OC::$server->getAppManager()->isInstalled('theming')) { |
|
265 | - $themingSuffix = '-' . $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
266 | - } |
|
267 | - $v = \OC_App::getAppVersions(); |
|
268 | - } |
|
269 | - |
|
270 | - // Try the webroot path for a match |
|
271 | - if ($path !== false && $path !== '') { |
|
272 | - $appName = $this->getAppNamefromPath($path); |
|
273 | - if(array_key_exists($appName, $v)) { |
|
274 | - $appVersion = $v[$appName]; |
|
275 | - return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix; |
|
276 | - } |
|
277 | - } |
|
278 | - // fallback to the file path instead |
|
279 | - if ($file !== false && $file !== '') { |
|
280 | - $appName = $this->getAppNamefromPath($file); |
|
281 | - if(array_key_exists($appName, $v)) { |
|
282 | - $appVersion = $v[$appName]; |
|
283 | - return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix; |
|
284 | - } |
|
285 | - } |
|
286 | - |
|
287 | - return '?v=' . self::$versionHash . $themingSuffix; |
|
288 | - } |
|
289 | - |
|
290 | - /** |
|
291 | - * @param array $styles |
|
292 | - * @return array |
|
293 | - */ |
|
294 | - static public function findStylesheetFiles($styles, $compileScss = true) { |
|
295 | - // Read the selected theme from the config file |
|
296 | - $theme = \OC_Util::getTheme(); |
|
297 | - |
|
298 | - if($compileScss) { |
|
299 | - $SCSSCacher = \OC::$server->query(SCSSCacher::class); |
|
300 | - } else { |
|
301 | - $SCSSCacher = null; |
|
302 | - } |
|
303 | - |
|
304 | - $locator = new \OC\Template\CSSResourceLocator( |
|
305 | - \OC::$server->getLogger(), |
|
306 | - $theme, |
|
307 | - [ \OC::$SERVERROOT => \OC::$WEBROOT ], |
|
308 | - [ \OC::$SERVERROOT => \OC::$WEBROOT ], |
|
309 | - $SCSSCacher |
|
310 | - ); |
|
311 | - $locator->find($styles); |
|
312 | - return $locator->getResources(); |
|
313 | - } |
|
314 | - |
|
315 | - /** |
|
316 | - * @param string $path |
|
317 | - * @return string|boolean |
|
318 | - */ |
|
319 | - public function getAppNamefromPath($path) { |
|
320 | - if ($path !== '' && is_string($path)) { |
|
321 | - $pathParts = explode('/', $path); |
|
322 | - if ($pathParts[0] === 'css') { |
|
323 | - // This is a scss request |
|
324 | - return $pathParts[1]; |
|
325 | - } |
|
326 | - return end($pathParts); |
|
327 | - } |
|
328 | - return false; |
|
329 | - |
|
330 | - } |
|
331 | - |
|
332 | - /** |
|
333 | - * @param array $scripts |
|
334 | - * @return array |
|
335 | - */ |
|
336 | - static public function findJavascriptFiles($scripts) { |
|
337 | - // Read the selected theme from the config file |
|
338 | - $theme = \OC_Util::getTheme(); |
|
339 | - |
|
340 | - $locator = new \OC\Template\JSResourceLocator( |
|
341 | - \OC::$server->getLogger(), |
|
342 | - $theme, |
|
343 | - [ \OC::$SERVERROOT => \OC::$WEBROOT ], |
|
344 | - [ \OC::$SERVERROOT => \OC::$WEBROOT ], |
|
345 | - \OC::$server->query(JSCombiner::class) |
|
346 | - ); |
|
347 | - $locator->find($scripts); |
|
348 | - return $locator->getResources(); |
|
349 | - } |
|
350 | - |
|
351 | - /** |
|
352 | - * Converts the absolute file path to a relative path from \OC::$SERVERROOT |
|
353 | - * @param string $filePath Absolute path |
|
354 | - * @return string Relative path |
|
355 | - * @throws \Exception If $filePath is not under \OC::$SERVERROOT |
|
356 | - */ |
|
357 | - public static function convertToRelativePath($filePath) { |
|
358 | - $relativePath = explode(\OC::$SERVERROOT, $filePath); |
|
359 | - if(count($relativePath) !== 2) { |
|
360 | - throw new \Exception('$filePath is not under the \OC::$SERVERROOT'); |
|
361 | - } |
|
362 | - |
|
363 | - return $relativePath[1]; |
|
364 | - } |
|
56 | + private static $versionHash = ''; |
|
57 | + |
|
58 | + /** |
|
59 | + * @var \OCP\IConfig |
|
60 | + */ |
|
61 | + private $config; |
|
62 | + |
|
63 | + /** |
|
64 | + * @param string $renderAs |
|
65 | + * @param string $appId application id |
|
66 | + */ |
|
67 | + public function __construct($renderAs, $appId = '') { |
|
68 | + |
|
69 | + // yes - should be injected .... |
|
70 | + $this->config = \OC::$server->getConfig(); |
|
71 | + |
|
72 | + if(\OCP\Util::isIE()) { |
|
73 | + \OC_Util::addStyle('ie'); |
|
74 | + } |
|
75 | + |
|
76 | + // Decide which page we show |
|
77 | + if($renderAs === 'user') { |
|
78 | + parent::__construct( 'core', 'layout.user' ); |
|
79 | + if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) { |
|
80 | + $this->assign('bodyid', 'body-settings'); |
|
81 | + }else{ |
|
82 | + $this->assign('bodyid', 'body-user'); |
|
83 | + } |
|
84 | + |
|
85 | + // Add navigation entry |
|
86 | + $this->assign( 'application', ''); |
|
87 | + $this->assign( 'appid', $appId ); |
|
88 | + $navigation = \OC::$server->getNavigationManager()->getAll(); |
|
89 | + $this->assign( 'navigation', $navigation); |
|
90 | + $settingsNavigation = \OC::$server->getNavigationManager()->getAll('settings'); |
|
91 | + $this->assign( 'settingsnavigation', $settingsNavigation); |
|
92 | + foreach($navigation as $entry) { |
|
93 | + if ($entry['active']) { |
|
94 | + $this->assign( 'application', $entry['name'] ); |
|
95 | + break; |
|
96 | + } |
|
97 | + } |
|
98 | + |
|
99 | + foreach($settingsNavigation as $entry) { |
|
100 | + if ($entry['active']) { |
|
101 | + $this->assign( 'application', $entry['name'] ); |
|
102 | + break; |
|
103 | + } |
|
104 | + } |
|
105 | + $userDisplayName = \OC_User::getDisplayName(); |
|
106 | + $this->assign('user_displayname', $userDisplayName); |
|
107 | + $this->assign('user_uid', \OC_User::getUser()); |
|
108 | + |
|
109 | + if (\OC_User::getUser() === false) { |
|
110 | + $this->assign('userAvatarSet', false); |
|
111 | + } else { |
|
112 | + $this->assign('userAvatarSet', \OC::$server->getAvatarManager()->getAvatar(\OC_User::getUser())->exists()); |
|
113 | + $this->assign('userAvatarVersion', $this->config->getUserValue(\OC_User::getUser(), 'avatar', 'version', 0)); |
|
114 | + } |
|
115 | + |
|
116 | + // check if app menu icons should be inverted |
|
117 | + try { |
|
118 | + /** @var \OCA\Theming\Util $util */ |
|
119 | + $util = \OC::$server->query(\OCA\Theming\Util::class); |
|
120 | + $this->assign('themingInvertMenu', $util->invertTextColor(\OC::$server->getThemingDefaults()->getColorPrimary())); |
|
121 | + } catch (\OCP\AppFramework\QueryException $e) { |
|
122 | + $this->assign('themingInvertMenu', false); |
|
123 | + } catch (\OCP\AutoloadNotAllowedException $e) { |
|
124 | + $this->assign('themingInvertMenu', false); |
|
125 | + } |
|
126 | + |
|
127 | + } else if ($renderAs === 'error') { |
|
128 | + parent::__construct('core', 'layout.guest', '', false); |
|
129 | + $this->assign('bodyid', 'body-login'); |
|
130 | + $this->assign('user_displayname', ''); |
|
131 | + $this->assign('user_uid', ''); |
|
132 | + } else if ($renderAs === 'guest') { |
|
133 | + parent::__construct('core', 'layout.guest'); |
|
134 | + \OC_Util::addStyle('guest'); |
|
135 | + $this->assign('bodyid', 'body-login'); |
|
136 | + |
|
137 | + $userDisplayName = \OC_User::getDisplayName(); |
|
138 | + $this->assign('user_displayname', $userDisplayName); |
|
139 | + $this->assign('user_uid', \OC_User::getUser()); |
|
140 | + } else if ($renderAs === 'public') { |
|
141 | + parent::__construct('core', 'layout.public'); |
|
142 | + $this->assign( 'appid', $appId ); |
|
143 | + $this->assign('bodyid', 'body-public'); |
|
144 | + |
|
145 | + /** @var IRegistry $subscription */ |
|
146 | + $subscription = \OC::$server->query(IRegistry::class); |
|
147 | + $showSimpleSignup = $this->config->getSystemValueBool('simpleSignUpLink.shown', true); |
|
148 | + if ($showSimpleSignup && $subscription->delegateHasValidSubscription()) { |
|
149 | + $showSimpleSignup = false; |
|
150 | + } |
|
151 | + $this->assign('showSimpleSignUpLink', $showSimpleSignup); |
|
152 | + } else { |
|
153 | + parent::__construct('core', 'layout.base'); |
|
154 | + |
|
155 | + } |
|
156 | + // Send the language and the locale to our layouts |
|
157 | + $lang = \OC::$server->getL10NFactory()->findLanguage(); |
|
158 | + $locale = \OC::$server->getL10NFactory()->findLocale($lang); |
|
159 | + |
|
160 | + $lang = str_replace('_', '-', $lang); |
|
161 | + $this->assign('language', $lang); |
|
162 | + $this->assign('locale', $locale); |
|
163 | + |
|
164 | + if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
165 | + if (empty(self::$versionHash)) { |
|
166 | + $v = \OC_App::getAppVersions(); |
|
167 | + $v['core'] = implode('.', \OCP\Util::getVersion()); |
|
168 | + self::$versionHash = substr(md5(implode(',', $v)), 0, 8); |
|
169 | + } |
|
170 | + } else { |
|
171 | + self::$versionHash = md5('not installed'); |
|
172 | + } |
|
173 | + |
|
174 | + // Add the js files |
|
175 | + $jsFiles = self::findJavascriptFiles(\OC_Util::$scripts); |
|
176 | + $this->assign('jsfiles', []); |
|
177 | + if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') { |
|
178 | + if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) { |
|
179 | + $jsConfigHelper = new JSConfigHelper( |
|
180 | + \OC::$server->getL10N('lib'), |
|
181 | + \OC::$server->query(Defaults::class), |
|
182 | + \OC::$server->getAppManager(), |
|
183 | + \OC::$server->getSession(), |
|
184 | + \OC::$server->getUserSession()->getUser(), |
|
185 | + $this->config, |
|
186 | + \OC::$server->getGroupManager(), |
|
187 | + \OC::$server->getIniWrapper(), |
|
188 | + \OC::$server->getURLGenerator(), |
|
189 | + \OC::$server->getCapabilitiesManager() |
|
190 | + ); |
|
191 | + $this->assign('inline_ocjs', $jsConfigHelper->getConfig()); |
|
192 | + } else { |
|
193 | + $this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash])); |
|
194 | + } |
|
195 | + } |
|
196 | + foreach($jsFiles as $info) { |
|
197 | + $web = $info[1]; |
|
198 | + $file = $info[2]; |
|
199 | + $this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
200 | + } |
|
201 | + |
|
202 | + try { |
|
203 | + $pathInfo = \OC::$server->getRequest()->getPathInfo(); |
|
204 | + } catch (\Exception $e) { |
|
205 | + $pathInfo = ''; |
|
206 | + } |
|
207 | + |
|
208 | + // Do not initialise scss appdata until we have a fully installed instance |
|
209 | + // Do not load scss for update, errors, installation or login page |
|
210 | + if(\OC::$server->getSystemConfig()->getValue('installed', false) |
|
211 | + && !\OCP\Util::needUpgrade() |
|
212 | + && $pathInfo !== '' |
|
213 | + && !preg_match('/^\/login/', $pathInfo) |
|
214 | + && $renderAs !== 'error' |
|
215 | + ) { |
|
216 | + $cssFiles = self::findStylesheetFiles(\OC_Util::$styles); |
|
217 | + } else { |
|
218 | + // If we ignore the scss compiler, |
|
219 | + // we need to load the guest css fallback |
|
220 | + \OC_Util::addStyle('guest'); |
|
221 | + $cssFiles = self::findStylesheetFiles(\OC_Util::$styles, false); |
|
222 | + } |
|
223 | + |
|
224 | + $this->assign('cssfiles', []); |
|
225 | + $this->assign('printcssfiles', []); |
|
226 | + $this->assign('versionHash', self::$versionHash); |
|
227 | + foreach($cssFiles as $info) { |
|
228 | + $web = $info[1]; |
|
229 | + $file = $info[2]; |
|
230 | + |
|
231 | + if (substr($file, -strlen('print.css')) === 'print.css') { |
|
232 | + $this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
233 | + } else { |
|
234 | + $suffix = $this->getVersionHashSuffix($web, $file); |
|
235 | + |
|
236 | + if (strpos($file, '?v=') == false) { |
|
237 | + $this->append( 'cssfiles', $web.'/'.$file . $suffix); |
|
238 | + } else { |
|
239 | + $this->append( 'cssfiles', $web.'/'.$file . '-' . substr($suffix, 3)); |
|
240 | + } |
|
241 | + |
|
242 | + } |
|
243 | + } |
|
244 | + |
|
245 | + /** @var InitialStateService $initialState */ |
|
246 | + $initialState = \OC::$server->query(InitialStateService::class); |
|
247 | + $this->assign('initialStates', $initialState->getInitialStates()); |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * @param string $path |
|
252 | + * @param string $file |
|
253 | + * @return string |
|
254 | + */ |
|
255 | + protected function getVersionHashSuffix($path = false, $file = false) { |
|
256 | + if ($this->config->getSystemValue('debug', false)) { |
|
257 | + // allows chrome workspace mapping in debug mode |
|
258 | + return ""; |
|
259 | + } |
|
260 | + $themingSuffix = ''; |
|
261 | + $v = []; |
|
262 | + |
|
263 | + if ($this->config->getSystemValue('installed', false)) { |
|
264 | + if (\OC::$server->getAppManager()->isInstalled('theming')) { |
|
265 | + $themingSuffix = '-' . $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
266 | + } |
|
267 | + $v = \OC_App::getAppVersions(); |
|
268 | + } |
|
269 | + |
|
270 | + // Try the webroot path for a match |
|
271 | + if ($path !== false && $path !== '') { |
|
272 | + $appName = $this->getAppNamefromPath($path); |
|
273 | + if(array_key_exists($appName, $v)) { |
|
274 | + $appVersion = $v[$appName]; |
|
275 | + return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix; |
|
276 | + } |
|
277 | + } |
|
278 | + // fallback to the file path instead |
|
279 | + if ($file !== false && $file !== '') { |
|
280 | + $appName = $this->getAppNamefromPath($file); |
|
281 | + if(array_key_exists($appName, $v)) { |
|
282 | + $appVersion = $v[$appName]; |
|
283 | + return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix; |
|
284 | + } |
|
285 | + } |
|
286 | + |
|
287 | + return '?v=' . self::$versionHash . $themingSuffix; |
|
288 | + } |
|
289 | + |
|
290 | + /** |
|
291 | + * @param array $styles |
|
292 | + * @return array |
|
293 | + */ |
|
294 | + static public function findStylesheetFiles($styles, $compileScss = true) { |
|
295 | + // Read the selected theme from the config file |
|
296 | + $theme = \OC_Util::getTheme(); |
|
297 | + |
|
298 | + if($compileScss) { |
|
299 | + $SCSSCacher = \OC::$server->query(SCSSCacher::class); |
|
300 | + } else { |
|
301 | + $SCSSCacher = null; |
|
302 | + } |
|
303 | + |
|
304 | + $locator = new \OC\Template\CSSResourceLocator( |
|
305 | + \OC::$server->getLogger(), |
|
306 | + $theme, |
|
307 | + [ \OC::$SERVERROOT => \OC::$WEBROOT ], |
|
308 | + [ \OC::$SERVERROOT => \OC::$WEBROOT ], |
|
309 | + $SCSSCacher |
|
310 | + ); |
|
311 | + $locator->find($styles); |
|
312 | + return $locator->getResources(); |
|
313 | + } |
|
314 | + |
|
315 | + /** |
|
316 | + * @param string $path |
|
317 | + * @return string|boolean |
|
318 | + */ |
|
319 | + public function getAppNamefromPath($path) { |
|
320 | + if ($path !== '' && is_string($path)) { |
|
321 | + $pathParts = explode('/', $path); |
|
322 | + if ($pathParts[0] === 'css') { |
|
323 | + // This is a scss request |
|
324 | + return $pathParts[1]; |
|
325 | + } |
|
326 | + return end($pathParts); |
|
327 | + } |
|
328 | + return false; |
|
329 | + |
|
330 | + } |
|
331 | + |
|
332 | + /** |
|
333 | + * @param array $scripts |
|
334 | + * @return array |
|
335 | + */ |
|
336 | + static public function findJavascriptFiles($scripts) { |
|
337 | + // Read the selected theme from the config file |
|
338 | + $theme = \OC_Util::getTheme(); |
|
339 | + |
|
340 | + $locator = new \OC\Template\JSResourceLocator( |
|
341 | + \OC::$server->getLogger(), |
|
342 | + $theme, |
|
343 | + [ \OC::$SERVERROOT => \OC::$WEBROOT ], |
|
344 | + [ \OC::$SERVERROOT => \OC::$WEBROOT ], |
|
345 | + \OC::$server->query(JSCombiner::class) |
|
346 | + ); |
|
347 | + $locator->find($scripts); |
|
348 | + return $locator->getResources(); |
|
349 | + } |
|
350 | + |
|
351 | + /** |
|
352 | + * Converts the absolute file path to a relative path from \OC::$SERVERROOT |
|
353 | + * @param string $filePath Absolute path |
|
354 | + * @return string Relative path |
|
355 | + * @throws \Exception If $filePath is not under \OC::$SERVERROOT |
|
356 | + */ |
|
357 | + public static function convertToRelativePath($filePath) { |
|
358 | + $relativePath = explode(\OC::$SERVERROOT, $filePath); |
|
359 | + if(count($relativePath) !== 2) { |
|
360 | + throw new \Exception('$filePath is not under the \OC::$SERVERROOT'); |
|
361 | + } |
|
362 | + |
|
363 | + return $relativePath[1]; |
|
364 | + } |
|
365 | 365 | } |
@@ -69,36 +69,36 @@ discard block |
||
69 | 69 | // yes - should be injected .... |
70 | 70 | $this->config = \OC::$server->getConfig(); |
71 | 71 | |
72 | - if(\OCP\Util::isIE()) { |
|
72 | + if (\OCP\Util::isIE()) { |
|
73 | 73 | \OC_Util::addStyle('ie'); |
74 | 74 | } |
75 | 75 | |
76 | 76 | // Decide which page we show |
77 | - if($renderAs === 'user') { |
|
78 | - parent::__construct( 'core', 'layout.user' ); |
|
79 | - if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) { |
|
77 | + if ($renderAs === 'user') { |
|
78 | + parent::__construct('core', 'layout.user'); |
|
79 | + if (in_array(\OC_App::getCurrentApp(), ['settings', 'admin', 'help']) !== false) { |
|
80 | 80 | $this->assign('bodyid', 'body-settings'); |
81 | - }else{ |
|
81 | + } else { |
|
82 | 82 | $this->assign('bodyid', 'body-user'); |
83 | 83 | } |
84 | 84 | |
85 | 85 | // Add navigation entry |
86 | - $this->assign( 'application', ''); |
|
87 | - $this->assign( 'appid', $appId ); |
|
86 | + $this->assign('application', ''); |
|
87 | + $this->assign('appid', $appId); |
|
88 | 88 | $navigation = \OC::$server->getNavigationManager()->getAll(); |
89 | - $this->assign( 'navigation', $navigation); |
|
89 | + $this->assign('navigation', $navigation); |
|
90 | 90 | $settingsNavigation = \OC::$server->getNavigationManager()->getAll('settings'); |
91 | - $this->assign( 'settingsnavigation', $settingsNavigation); |
|
92 | - foreach($navigation as $entry) { |
|
91 | + $this->assign('settingsnavigation', $settingsNavigation); |
|
92 | + foreach ($navigation as $entry) { |
|
93 | 93 | if ($entry['active']) { |
94 | - $this->assign( 'application', $entry['name'] ); |
|
94 | + $this->assign('application', $entry['name']); |
|
95 | 95 | break; |
96 | 96 | } |
97 | 97 | } |
98 | 98 | |
99 | - foreach($settingsNavigation as $entry) { |
|
99 | + foreach ($settingsNavigation as $entry) { |
|
100 | 100 | if ($entry['active']) { |
101 | - $this->assign( 'application', $entry['name'] ); |
|
101 | + $this->assign('application', $entry['name']); |
|
102 | 102 | break; |
103 | 103 | } |
104 | 104 | } |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | $this->assign('user_uid', \OC_User::getUser()); |
140 | 140 | } else if ($renderAs === 'public') { |
141 | 141 | parent::__construct('core', 'layout.public'); |
142 | - $this->assign( 'appid', $appId ); |
|
142 | + $this->assign('appid', $appId); |
|
143 | 143 | $this->assign('bodyid', 'body-public'); |
144 | 144 | |
145 | 145 | /** @var IRegistry $subscription */ |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | $this->assign('language', $lang); |
162 | 162 | $this->assign('locale', $locale); |
163 | 163 | |
164 | - if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
164 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
165 | 165 | if (empty(self::$versionHash)) { |
166 | 166 | $v = \OC_App::getAppVersions(); |
167 | 167 | $v['core'] = implode('.', \OCP\Util::getVersion()); |
@@ -193,10 +193,10 @@ discard block |
||
193 | 193 | $this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash])); |
194 | 194 | } |
195 | 195 | } |
196 | - foreach($jsFiles as $info) { |
|
196 | + foreach ($jsFiles as $info) { |
|
197 | 197 | $web = $info[1]; |
198 | 198 | $file = $info[2]; |
199 | - $this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
199 | + $this->append('jsfiles', $web.'/'.$file.$this->getVersionHashSuffix()); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | try { |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | |
208 | 208 | // Do not initialise scss appdata until we have a fully installed instance |
209 | 209 | // Do not load scss for update, errors, installation or login page |
210 | - if(\OC::$server->getSystemConfig()->getValue('installed', false) |
|
210 | + if (\OC::$server->getSystemConfig()->getValue('installed', false) |
|
211 | 211 | && !\OCP\Util::needUpgrade() |
212 | 212 | && $pathInfo !== '' |
213 | 213 | && !preg_match('/^\/login/', $pathInfo) |
@@ -224,19 +224,19 @@ discard block |
||
224 | 224 | $this->assign('cssfiles', []); |
225 | 225 | $this->assign('printcssfiles', []); |
226 | 226 | $this->assign('versionHash', self::$versionHash); |
227 | - foreach($cssFiles as $info) { |
|
227 | + foreach ($cssFiles as $info) { |
|
228 | 228 | $web = $info[1]; |
229 | 229 | $file = $info[2]; |
230 | 230 | |
231 | 231 | if (substr($file, -strlen('print.css')) === 'print.css') { |
232 | - $this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
232 | + $this->append('printcssfiles', $web.'/'.$file.$this->getVersionHashSuffix()); |
|
233 | 233 | } else { |
234 | 234 | $suffix = $this->getVersionHashSuffix($web, $file); |
235 | 235 | |
236 | 236 | if (strpos($file, '?v=') == false) { |
237 | - $this->append( 'cssfiles', $web.'/'.$file . $suffix); |
|
237 | + $this->append('cssfiles', $web.'/'.$file.$suffix); |
|
238 | 238 | } else { |
239 | - $this->append( 'cssfiles', $web.'/'.$file . '-' . substr($suffix, 3)); |
|
239 | + $this->append('cssfiles', $web.'/'.$file.'-'.substr($suffix, 3)); |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | } |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | |
263 | 263 | if ($this->config->getSystemValue('installed', false)) { |
264 | 264 | if (\OC::$server->getAppManager()->isInstalled('theming')) { |
265 | - $themingSuffix = '-' . $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
265 | + $themingSuffix = '-'.$this->config->getAppValue('theming', 'cachebuster', '0'); |
|
266 | 266 | } |
267 | 267 | $v = \OC_App::getAppVersions(); |
268 | 268 | } |
@@ -270,21 +270,21 @@ discard block |
||
270 | 270 | // Try the webroot path for a match |
271 | 271 | if ($path !== false && $path !== '') { |
272 | 272 | $appName = $this->getAppNamefromPath($path); |
273 | - if(array_key_exists($appName, $v)) { |
|
273 | + if (array_key_exists($appName, $v)) { |
|
274 | 274 | $appVersion = $v[$appName]; |
275 | - return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix; |
|
275 | + return '?v='.substr(md5($appVersion), 0, 8).$themingSuffix; |
|
276 | 276 | } |
277 | 277 | } |
278 | 278 | // fallback to the file path instead |
279 | 279 | if ($file !== false && $file !== '') { |
280 | 280 | $appName = $this->getAppNamefromPath($file); |
281 | - if(array_key_exists($appName, $v)) { |
|
281 | + if (array_key_exists($appName, $v)) { |
|
282 | 282 | $appVersion = $v[$appName]; |
283 | - return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix; |
|
283 | + return '?v='.substr(md5($appVersion), 0, 8).$themingSuffix; |
|
284 | 284 | } |
285 | 285 | } |
286 | 286 | |
287 | - return '?v=' . self::$versionHash . $themingSuffix; |
|
287 | + return '?v='.self::$versionHash.$themingSuffix; |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | /** |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | // Read the selected theme from the config file |
296 | 296 | $theme = \OC_Util::getTheme(); |
297 | 297 | |
298 | - if($compileScss) { |
|
298 | + if ($compileScss) { |
|
299 | 299 | $SCSSCacher = \OC::$server->query(SCSSCacher::class); |
300 | 300 | } else { |
301 | 301 | $SCSSCacher = null; |
@@ -304,8 +304,8 @@ discard block |
||
304 | 304 | $locator = new \OC\Template\CSSResourceLocator( |
305 | 305 | \OC::$server->getLogger(), |
306 | 306 | $theme, |
307 | - [ \OC::$SERVERROOT => \OC::$WEBROOT ], |
|
308 | - [ \OC::$SERVERROOT => \OC::$WEBROOT ], |
|
307 | + [\OC::$SERVERROOT => \OC::$WEBROOT], |
|
308 | + [\OC::$SERVERROOT => \OC::$WEBROOT], |
|
309 | 309 | $SCSSCacher |
310 | 310 | ); |
311 | 311 | $locator->find($styles); |
@@ -340,8 +340,8 @@ discard block |
||
340 | 340 | $locator = new \OC\Template\JSResourceLocator( |
341 | 341 | \OC::$server->getLogger(), |
342 | 342 | $theme, |
343 | - [ \OC::$SERVERROOT => \OC::$WEBROOT ], |
|
344 | - [ \OC::$SERVERROOT => \OC::$WEBROOT ], |
|
343 | + [\OC::$SERVERROOT => \OC::$WEBROOT], |
|
344 | + [\OC::$SERVERROOT => \OC::$WEBROOT], |
|
345 | 345 | \OC::$server->query(JSCombiner::class) |
346 | 346 | ); |
347 | 347 | $locator->find($scripts); |
@@ -356,7 +356,7 @@ discard block |
||
356 | 356 | */ |
357 | 357 | public static function convertToRelativePath($filePath) { |
358 | 358 | $relativePath = explode(\OC::$SERVERROOT, $filePath); |
359 | - if(count($relativePath) !== 2) { |
|
359 | + if (count($relativePath) !== 2) { |
|
360 | 360 | throw new \Exception('$filePath is not under the \OC::$SERVERROOT'); |
361 | 361 | } |
362 | 362 |