@@ -304,9 +304,9 @@ |
||
304 | 304 | */ |
305 | 305 | public static function linkToRemote($service) { |
306 | 306 | $urlGenerator = \OC::$server->getURLGenerator(); |
307 | - $remoteBase = $urlGenerator->linkTo('', 'remote.php') . '/' . $service; |
|
307 | + $remoteBase = $urlGenerator->linkTo('', 'remote.php').'/'.$service; |
|
308 | 308 | return $urlGenerator->getAbsoluteURL( |
309 | - $remoteBase . (($service[strlen($service) - 1] != '/') ? '/' : '') |
|
309 | + $remoteBase.(($service[strlen($service) - 1] != '/') ? '/' : '') |
|
310 | 310 | ); |
311 | 311 | } |
312 | 312 |
@@ -56,555 +56,555 @@ |
||
56 | 56 | * @since 4.0.0 |
57 | 57 | */ |
58 | 58 | class Util { |
59 | - /** @var \OCP\Share\IManager */ |
|
60 | - private static $shareManager; |
|
61 | - |
|
62 | - /** @var array */ |
|
63 | - private static $scripts = []; |
|
64 | - |
|
65 | - /** @var array */ |
|
66 | - private static $scriptDeps = []; |
|
67 | - |
|
68 | - /** @var array */ |
|
69 | - private static $sortedScriptDeps = []; |
|
70 | - |
|
71 | - /** |
|
72 | - * get the current installed version of Nextcloud |
|
73 | - * @return array |
|
74 | - * @since 4.0.0 |
|
75 | - */ |
|
76 | - public static function getVersion() { |
|
77 | - return \OC_Util::getVersion(); |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * @since 17.0.0 |
|
82 | - */ |
|
83 | - public static function hasExtendedSupport(): bool { |
|
84 | - try { |
|
85 | - /** @var \OCP\Support\Subscription\IRegistry */ |
|
86 | - $subscriptionRegistry = \OC::$server->query(\OCP\Support\Subscription\IRegistry::class); |
|
87 | - return $subscriptionRegistry->delegateHasExtendedSupport(); |
|
88 | - } catch (AppFramework\QueryException $e) { |
|
89 | - } |
|
90 | - return \OC::$server->getConfig()->getSystemValueBool('extendedSupport', false); |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Set current update channel |
|
95 | - * @param string $channel |
|
96 | - * @since 8.1.0 |
|
97 | - */ |
|
98 | - public static function setChannel($channel) { |
|
99 | - \OC::$server->getConfig()->setSystemValue('updater.release.channel', $channel); |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Get current update channel |
|
104 | - * @return string |
|
105 | - * @since 8.1.0 |
|
106 | - */ |
|
107 | - public static function getChannel() { |
|
108 | - return \OC_Util::getChannel(); |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * write a message in the log |
|
113 | - * @param string $app |
|
114 | - * @param string $message |
|
115 | - * @param int $level |
|
116 | - * @since 4.0.0 |
|
117 | - * @deprecated 13.0.0 use log of \OCP\ILogger |
|
118 | - */ |
|
119 | - public static function writeLog($app, $message, $level) { |
|
120 | - $context = ['app' => $app]; |
|
121 | - \OC::$server->getLogger()->log($level, $message, $context); |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * check if sharing is disabled for the current user |
|
126 | - * |
|
127 | - * @return boolean |
|
128 | - * @since 7.0.0 |
|
129 | - * @deprecated 9.1.0 Use \OC::$server->getShareManager()->sharingDisabledForUser |
|
130 | - */ |
|
131 | - public static function isSharingDisabledForUser() { |
|
132 | - if (self::$shareManager === null) { |
|
133 | - self::$shareManager = \OC::$server->getShareManager(); |
|
134 | - } |
|
135 | - |
|
136 | - $user = \OC::$server->getUserSession()->getUser(); |
|
137 | - if ($user !== null) { |
|
138 | - $user = $user->getUID(); |
|
139 | - } |
|
140 | - |
|
141 | - return self::$shareManager->sharingDisabledForUser($user); |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * get l10n object |
|
146 | - * @param string $application |
|
147 | - * @param string|null $language |
|
148 | - * @return \OCP\IL10N |
|
149 | - * @since 6.0.0 - parameter $language was added in 8.0.0 |
|
150 | - */ |
|
151 | - public static function getL10N($application, $language = null) { |
|
152 | - return \OC::$server->getL10N($application, $language); |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * add a css file |
|
157 | - * @param string $application |
|
158 | - * @param string $file |
|
159 | - * @since 4.0.0 |
|
160 | - */ |
|
161 | - public static function addStyle($application, $file = null) { |
|
162 | - \OC_Util::addStyle($application, $file); |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * add a javascript file |
|
167 | - * |
|
168 | - * @param string $application |
|
169 | - * @param string|null $file |
|
170 | - * @param string $afterAppId |
|
171 | - * @since 4.0.0 |
|
172 | - */ |
|
173 | - public static function addScript(string $application, string $file = null, string $afterAppId = 'core'): void { |
|
174 | - if (!empty($application)) { |
|
175 | - $path = "$application/js/$file"; |
|
176 | - } else { |
|
177 | - $path = "js/$file"; |
|
178 | - } |
|
179 | - |
|
180 | - // Inject js translations if we load a script for |
|
181 | - // a specific app that is not core, as those js files |
|
182 | - // need separate handling |
|
183 | - if ($application !== 'core' |
|
184 | - && $file !== null |
|
185 | - && strpos($file, 'l10n') === false) { |
|
186 | - self::addTranslations($application); |
|
187 | - } |
|
188 | - |
|
189 | - // store app in dependency list |
|
190 | - if (!array_key_exists($application, self::$scriptDeps)) { |
|
191 | - self::$scriptDeps[$application] = new AppScriptDependency($application, [$afterAppId]); |
|
192 | - } else { |
|
193 | - self::$scriptDeps[$application]->addDep($afterAppId); |
|
194 | - } |
|
195 | - |
|
196 | - self::$scripts[$application][] = $path; |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * Return the list of scripts injected to the page |
|
201 | - * |
|
202 | - * @return array |
|
203 | - * @since 24.0.0 |
|
204 | - */ |
|
205 | - public static function getScripts(): array { |
|
206 | - // Sort scriptDeps into sortedScriptDeps |
|
207 | - $scriptSort = \OC::$server->get(AppScriptSort::class); |
|
208 | - $sortedScripts = $scriptSort->sort(self::$scripts, self::$scriptDeps); |
|
209 | - |
|
210 | - // Flatten array and remove duplicates |
|
211 | - $sortedScripts = $sortedScripts ? array_merge(...array_values(($sortedScripts))) : []; |
|
212 | - |
|
213 | - // Override core-common and core-main order |
|
214 | - array_unshift($sortedScripts, 'core/js/common', 'core/js/main'); |
|
215 | - |
|
216 | - return array_unique($sortedScripts); |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * Add a translation JS file |
|
221 | - * @param string $application application id |
|
222 | - * @param string $languageCode language code, defaults to the current locale |
|
223 | - * @since 8.0.0 |
|
224 | - */ |
|
225 | - public static function addTranslations($application, $languageCode = null) { |
|
226 | - if (is_null($languageCode)) { |
|
227 | - $languageCode = \OC::$server->getL10NFactory()->findLanguage($application); |
|
228 | - } |
|
229 | - if (!empty($application)) { |
|
230 | - $path = "$application/l10n/$languageCode"; |
|
231 | - } else { |
|
232 | - $path = "l10n/$languageCode"; |
|
233 | - } |
|
234 | - self::$scripts[$application][] = $path; |
|
235 | - } |
|
236 | - |
|
237 | - /** |
|
238 | - * Add a custom element to the header |
|
239 | - * If $text is null then the element will be written as empty element. |
|
240 | - * So use "" to get a closing tag. |
|
241 | - * @param string $tag tag name of the element |
|
242 | - * @param array $attributes array of attributes for the element |
|
243 | - * @param string $text the text content for the element |
|
244 | - * @since 4.0.0 |
|
245 | - */ |
|
246 | - public static function addHeader($tag, $attributes, $text = null) { |
|
247 | - \OC_Util::addHeader($tag, $attributes, $text); |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * Creates an absolute url to the given app and file. |
|
252 | - * @param string $app app |
|
253 | - * @param string $file file |
|
254 | - * @param array $args array with param=>value, will be appended to the returned url |
|
255 | - * The value of $args will be urlencoded |
|
256 | - * @return string the url |
|
257 | - * @since 4.0.0 - parameter $args was added in 4.5.0 |
|
258 | - */ |
|
259 | - public static function linkToAbsolute($app, $file, $args = []) { |
|
260 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
261 | - return $urlGenerator->getAbsoluteURL( |
|
262 | - $urlGenerator->linkTo($app, $file, $args) |
|
263 | - ); |
|
264 | - } |
|
265 | - |
|
266 | - /** |
|
267 | - * Creates an absolute url for remote use. |
|
268 | - * @param string $service id |
|
269 | - * @return string the url |
|
270 | - * @since 4.0.0 |
|
271 | - */ |
|
272 | - public static function linkToRemote($service) { |
|
273 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
274 | - $remoteBase = $urlGenerator->linkTo('', 'remote.php') . '/' . $service; |
|
275 | - return $urlGenerator->getAbsoluteURL( |
|
276 | - $remoteBase . (($service[strlen($service) - 1] != '/') ? '/' : '') |
|
277 | - ); |
|
278 | - } |
|
279 | - |
|
280 | - /** |
|
281 | - * Creates an absolute url for public use |
|
282 | - * @param string $service id |
|
283 | - * @return string the url |
|
284 | - * @since 4.5.0 |
|
285 | - * @deprecated 15.0.0 - use OCP\IURLGenerator |
|
286 | - */ |
|
287 | - public static function linkToPublic($service) { |
|
288 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
289 | - if ($service === 'files') { |
|
290 | - return $urlGenerator->getAbsoluteURL('/s'); |
|
291 | - } |
|
292 | - return $urlGenerator->getAbsoluteURL($urlGenerator->linkTo('', 'public.php').'?service='.$service); |
|
293 | - } |
|
294 | - |
|
295 | - /** |
|
296 | - * Returns the server host name without an eventual port number |
|
297 | - * @return string the server hostname |
|
298 | - * @since 5.0.0 |
|
299 | - */ |
|
300 | - public static function getServerHostName() { |
|
301 | - $host_name = \OC::$server->getRequest()->getServerHost(); |
|
302 | - // strip away port number (if existing) |
|
303 | - $colon_pos = strpos($host_name, ':'); |
|
304 | - if ($colon_pos != false) { |
|
305 | - $host_name = substr($host_name, 0, $colon_pos); |
|
306 | - } |
|
307 | - return $host_name; |
|
308 | - } |
|
309 | - |
|
310 | - /** |
|
311 | - * Returns the default email address |
|
312 | - * @param string $user_part the user part of the address |
|
313 | - * @return string the default email address |
|
314 | - * |
|
315 | - * Assembles a default email address (using the server hostname |
|
316 | - * and the given user part, and returns it |
|
317 | - * Example: when given lostpassword-noreply as $user_part param, |
|
318 | - * and is currently accessed via http(s)://example.com/, |
|
319 | - * it would return '[email protected]' |
|
320 | - * |
|
321 | - * If the configuration value 'mail_from_address' is set in |
|
322 | - * config.php, this value will override the $user_part that |
|
323 | - * is passed to this function |
|
324 | - * @since 5.0.0 |
|
325 | - */ |
|
326 | - public static function getDefaultEmailAddress(string $user_part): string { |
|
327 | - $config = \OC::$server->getConfig(); |
|
328 | - $user_part = $config->getSystemValueString('mail_from_address', $user_part); |
|
329 | - $host_name = self::getServerHostName(); |
|
330 | - $host_name = $config->getSystemValueString('mail_domain', $host_name); |
|
331 | - $defaultEmailAddress = $user_part.'@'.$host_name; |
|
332 | - |
|
333 | - $mailer = \OC::$server->getMailer(); |
|
334 | - if ($mailer->validateMailAddress($defaultEmailAddress)) { |
|
335 | - return $defaultEmailAddress; |
|
336 | - } |
|
337 | - |
|
338 | - // in case we cannot build a valid email address from the hostname let's fallback to 'localhost.localdomain' |
|
339 | - return $user_part.'@localhost.localdomain'; |
|
340 | - } |
|
341 | - |
|
342 | - /** |
|
343 | - * Make a human file size (2048 to 2 kB) |
|
344 | - * @param int $bytes file size in bytes |
|
345 | - * @return string a human readable file size |
|
346 | - * @since 4.0.0 |
|
347 | - */ |
|
348 | - public static function humanFileSize($bytes) { |
|
349 | - return \OC_Helper::humanFileSize($bytes); |
|
350 | - } |
|
351 | - |
|
352 | - /** |
|
353 | - * Make a computer file size (2 kB to 2048) |
|
354 | - * @param string $str file size in a fancy format |
|
355 | - * @return float|false a file size in bytes |
|
356 | - * |
|
357 | - * Inspired by: https://www.php.net/manual/en/function.filesize.php#92418 |
|
358 | - * @since 4.0.0 |
|
359 | - */ |
|
360 | - public static function computerFileSize($str) { |
|
361 | - return \OC_Helper::computerFileSize($str); |
|
362 | - } |
|
363 | - |
|
364 | - /** |
|
365 | - * connects a function to a hook |
|
366 | - * |
|
367 | - * @param string $signalClass class name of emitter |
|
368 | - * @param string $signalName name of signal |
|
369 | - * @param string|object $slotClass class name of slot |
|
370 | - * @param string $slotName name of slot |
|
371 | - * @return bool |
|
372 | - * |
|
373 | - * This function makes it very easy to connect to use hooks. |
|
374 | - * |
|
375 | - * TODO: write example |
|
376 | - * @since 4.0.0 |
|
377 | - * @deprecated 21.0.0 use \OCP\EventDispatcher\IEventDispatcher::addListener |
|
378 | - */ |
|
379 | - public static function connectHook($signalClass, $signalName, $slotClass, $slotName) { |
|
380 | - return \OC_Hook::connect($signalClass, $signalName, $slotClass, $slotName); |
|
381 | - } |
|
382 | - |
|
383 | - /** |
|
384 | - * Emits a signal. To get data from the slot use references! |
|
385 | - * @param string $signalclass class name of emitter |
|
386 | - * @param string $signalname name of signal |
|
387 | - * @param array $params default: array() array with additional data |
|
388 | - * @return bool true if slots exists or false if not |
|
389 | - * |
|
390 | - * TODO: write example |
|
391 | - * @since 4.0.0 |
|
392 | - * @deprecated 21.0.0 use \OCP\EventDispatcher\IEventDispatcher::dispatchTypedEvent |
|
393 | - */ |
|
394 | - public static function emitHook($signalclass, $signalname, $params = []) { |
|
395 | - return \OC_Hook::emit($signalclass, $signalname, $params); |
|
396 | - } |
|
397 | - |
|
398 | - /** |
|
399 | - * Cached encrypted CSRF token. Some static unit-tests of ownCloud compare |
|
400 | - * multiple OC_Template elements which invoke `callRegister`. If the value |
|
401 | - * would not be cached these unit-tests would fail. |
|
402 | - * @var string |
|
403 | - */ |
|
404 | - private static $token = ''; |
|
405 | - |
|
406 | - /** |
|
407 | - * Register an get/post call. This is important to prevent CSRF attacks |
|
408 | - * @since 4.5.0 |
|
409 | - */ |
|
410 | - public static function callRegister() { |
|
411 | - if (self::$token === '') { |
|
412 | - self::$token = \OC::$server->getCsrfTokenManager()->getToken()->getEncryptedValue(); |
|
413 | - } |
|
414 | - return self::$token; |
|
415 | - } |
|
416 | - |
|
417 | - /** |
|
418 | - * Used to sanitize HTML |
|
419 | - * |
|
420 | - * This function is used to sanitize HTML and should be applied on any |
|
421 | - * string or array of strings before displaying it on a web page. |
|
422 | - * |
|
423 | - * @param string|string[] $value |
|
424 | - * @return string|string[] an array of sanitized strings or a single sanitized string, depends on the input parameter. |
|
425 | - * @since 4.5.0 |
|
426 | - */ |
|
427 | - public static function sanitizeHTML($value) { |
|
428 | - return \OC_Util::sanitizeHTML($value); |
|
429 | - } |
|
430 | - |
|
431 | - /** |
|
432 | - * Public function to encode url parameters |
|
433 | - * |
|
434 | - * This function is used to encode path to file before output. |
|
435 | - * Encoding is done according to RFC 3986 with one exception: |
|
436 | - * Character '/' is preserved as is. |
|
437 | - * |
|
438 | - * @param string $component part of URI to encode |
|
439 | - * @return string |
|
440 | - * @since 6.0.0 |
|
441 | - */ |
|
442 | - public static function encodePath($component) { |
|
443 | - return \OC_Util::encodePath($component); |
|
444 | - } |
|
445 | - |
|
446 | - /** |
|
447 | - * Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is. |
|
448 | - * |
|
449 | - * @param array $input The array to work on |
|
450 | - * @param int $case Either MB_CASE_UPPER or MB_CASE_LOWER (default) |
|
451 | - * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8 |
|
452 | - * @return array |
|
453 | - * @since 4.5.0 |
|
454 | - */ |
|
455 | - public static function mb_array_change_key_case($input, $case = MB_CASE_LOWER, $encoding = 'UTF-8') { |
|
456 | - return \OC_Helper::mb_array_change_key_case($input, $case, $encoding); |
|
457 | - } |
|
458 | - |
|
459 | - /** |
|
460 | - * performs a search in a nested array |
|
461 | - * |
|
462 | - * @param array $haystack the array to be searched |
|
463 | - * @param string $needle the search string |
|
464 | - * @param mixed $index optional, only search this key name |
|
465 | - * @return mixed the key of the matching field, otherwise false |
|
466 | - * @since 4.5.0 |
|
467 | - * @deprecated 15.0.0 |
|
468 | - */ |
|
469 | - public static function recursiveArraySearch($haystack, $needle, $index = null) { |
|
470 | - return \OC_Helper::recursiveArraySearch($haystack, $needle, $index); |
|
471 | - } |
|
472 | - |
|
473 | - /** |
|
474 | - * calculates the maximum upload size respecting system settings, free space and user quota |
|
475 | - * |
|
476 | - * @param string $dir the current folder where the user currently operates |
|
477 | - * @param int $free the number of bytes free on the storage holding $dir, if not set this will be received from the storage directly |
|
478 | - * @return int number of bytes representing |
|
479 | - * @since 5.0.0 |
|
480 | - */ |
|
481 | - public static function maxUploadFilesize($dir, $free = null) { |
|
482 | - return \OC_Helper::maxUploadFilesize($dir, $free); |
|
483 | - } |
|
484 | - |
|
485 | - /** |
|
486 | - * Calculate free space left within user quota |
|
487 | - * @param string $dir the current folder where the user currently operates |
|
488 | - * @return int number of bytes representing |
|
489 | - * @since 7.0.0 |
|
490 | - */ |
|
491 | - public static function freeSpace($dir) { |
|
492 | - return \OC_Helper::freeSpace($dir); |
|
493 | - } |
|
494 | - |
|
495 | - /** |
|
496 | - * Calculate PHP upload limit |
|
497 | - * |
|
498 | - * @return int number of bytes representing |
|
499 | - * @since 7.0.0 |
|
500 | - */ |
|
501 | - public static function uploadLimit() { |
|
502 | - return \OC_Helper::uploadLimit(); |
|
503 | - } |
|
504 | - |
|
505 | - /** |
|
506 | - * Returns whether the given file name is valid |
|
507 | - * @param string $file file name to check |
|
508 | - * @return bool true if the file name is valid, false otherwise |
|
509 | - * @deprecated 8.1.0 use \OC\Files\View::verifyPath() |
|
510 | - * @since 7.0.0 |
|
511 | - * @suppress PhanDeprecatedFunction |
|
512 | - */ |
|
513 | - public static function isValidFileName($file) { |
|
514 | - return \OC_Util::isValidFileName($file); |
|
515 | - } |
|
516 | - |
|
517 | - /** |
|
518 | - * Compare two strings to provide a natural sort |
|
519 | - * @param string $a first string to compare |
|
520 | - * @param string $b second string to compare |
|
521 | - * @return int -1 if $b comes before $a, 1 if $a comes before $b |
|
522 | - * or 0 if the strings are identical |
|
523 | - * @since 7.0.0 |
|
524 | - */ |
|
525 | - public static function naturalSortCompare($a, $b) { |
|
526 | - return \OC\NaturalSort::getInstance()->compare($a, $b); |
|
527 | - } |
|
528 | - |
|
529 | - /** |
|
530 | - * Check if a password is required for each public link |
|
531 | - * |
|
532 | - * @param bool $checkGroupMembership Check group membership exclusion |
|
533 | - * @return boolean |
|
534 | - * @since 7.0.0 |
|
535 | - */ |
|
536 | - public static function isPublicLinkPasswordRequired(bool $checkGroupMembership = true) { |
|
537 | - return \OC_Util::isPublicLinkPasswordRequired($checkGroupMembership); |
|
538 | - } |
|
539 | - |
|
540 | - /** |
|
541 | - * check if share API enforces a default expire date |
|
542 | - * @return boolean |
|
543 | - * @since 8.0.0 |
|
544 | - */ |
|
545 | - public static function isDefaultExpireDateEnforced() { |
|
546 | - return \OC_Util::isDefaultExpireDateEnforced(); |
|
547 | - } |
|
548 | - |
|
549 | - protected static $needUpgradeCache = null; |
|
550 | - |
|
551 | - /** |
|
552 | - * Checks whether the current version needs upgrade. |
|
553 | - * |
|
554 | - * @return bool true if upgrade is needed, false otherwise |
|
555 | - * @since 7.0.0 |
|
556 | - */ |
|
557 | - public static function needUpgrade() { |
|
558 | - if (!isset(self::$needUpgradeCache)) { |
|
559 | - self::$needUpgradeCache = \OC_Util::needUpgrade(\OC::$server->getSystemConfig()); |
|
560 | - } |
|
561 | - return self::$needUpgradeCache; |
|
562 | - } |
|
563 | - |
|
564 | - /** |
|
565 | - * Sometimes a string has to be shortened to fit within a certain maximum |
|
566 | - * data length in bytes. substr() you may break multibyte characters, |
|
567 | - * because it operates on single byte level. mb_substr() operates on |
|
568 | - * characters, so does not ensure that the shortend string satisfies the |
|
569 | - * max length in bytes. |
|
570 | - * |
|
571 | - * For example, json_encode is messing with multibyte characters a lot, |
|
572 | - * replacing them with something along "\u1234". |
|
573 | - * |
|
574 | - * This function shortens the string with by $accurancy (-5) from |
|
575 | - * $dataLength characters, until it fits within $dataLength bytes. |
|
576 | - * |
|
577 | - * @since 23.0.0 |
|
578 | - */ |
|
579 | - public static function shortenMultibyteString(string $subject, int $dataLength, int $accuracy = 5): string { |
|
580 | - $temp = mb_substr($subject, 0, $dataLength); |
|
581 | - // json encodes encapsulates the string in double quotes, they need to be substracted |
|
582 | - while ((strlen(json_encode($temp)) - 2) > $dataLength) { |
|
583 | - $temp = mb_substr($temp, 0, -$accuracy); |
|
584 | - } |
|
585 | - return $temp; |
|
586 | - } |
|
587 | - |
|
588 | - /** |
|
589 | - * Check if a function is enabled in the php configuration |
|
590 | - * |
|
591 | - * @since 25.0.0 |
|
592 | - */ |
|
593 | - public static function isFunctionEnabled(string $functionName): bool { |
|
594 | - if (!function_exists($functionName)) { |
|
595 | - return false; |
|
596 | - } |
|
597 | - $ini = \OCP\Server::get(IniGetWrapper::class); |
|
598 | - $disabled = explode(',', $ini->get('disable_functions') ?: ''); |
|
599 | - $disabled = array_map('trim', $disabled); |
|
600 | - if (in_array($functionName, $disabled)) { |
|
601 | - return false; |
|
602 | - } |
|
603 | - $disabled = explode(',', $ini->get('suhosin.executor.func.blacklist') ?: ''); |
|
604 | - $disabled = array_map('trim', $disabled); |
|
605 | - if (in_array($functionName, $disabled)) { |
|
606 | - return false; |
|
607 | - } |
|
608 | - return true; |
|
609 | - } |
|
59 | + /** @var \OCP\Share\IManager */ |
|
60 | + private static $shareManager; |
|
61 | + |
|
62 | + /** @var array */ |
|
63 | + private static $scripts = []; |
|
64 | + |
|
65 | + /** @var array */ |
|
66 | + private static $scriptDeps = []; |
|
67 | + |
|
68 | + /** @var array */ |
|
69 | + private static $sortedScriptDeps = []; |
|
70 | + |
|
71 | + /** |
|
72 | + * get the current installed version of Nextcloud |
|
73 | + * @return array |
|
74 | + * @since 4.0.0 |
|
75 | + */ |
|
76 | + public static function getVersion() { |
|
77 | + return \OC_Util::getVersion(); |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * @since 17.0.0 |
|
82 | + */ |
|
83 | + public static function hasExtendedSupport(): bool { |
|
84 | + try { |
|
85 | + /** @var \OCP\Support\Subscription\IRegistry */ |
|
86 | + $subscriptionRegistry = \OC::$server->query(\OCP\Support\Subscription\IRegistry::class); |
|
87 | + return $subscriptionRegistry->delegateHasExtendedSupport(); |
|
88 | + } catch (AppFramework\QueryException $e) { |
|
89 | + } |
|
90 | + return \OC::$server->getConfig()->getSystemValueBool('extendedSupport', false); |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Set current update channel |
|
95 | + * @param string $channel |
|
96 | + * @since 8.1.0 |
|
97 | + */ |
|
98 | + public static function setChannel($channel) { |
|
99 | + \OC::$server->getConfig()->setSystemValue('updater.release.channel', $channel); |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Get current update channel |
|
104 | + * @return string |
|
105 | + * @since 8.1.0 |
|
106 | + */ |
|
107 | + public static function getChannel() { |
|
108 | + return \OC_Util::getChannel(); |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * write a message in the log |
|
113 | + * @param string $app |
|
114 | + * @param string $message |
|
115 | + * @param int $level |
|
116 | + * @since 4.0.0 |
|
117 | + * @deprecated 13.0.0 use log of \OCP\ILogger |
|
118 | + */ |
|
119 | + public static function writeLog($app, $message, $level) { |
|
120 | + $context = ['app' => $app]; |
|
121 | + \OC::$server->getLogger()->log($level, $message, $context); |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * check if sharing is disabled for the current user |
|
126 | + * |
|
127 | + * @return boolean |
|
128 | + * @since 7.0.0 |
|
129 | + * @deprecated 9.1.0 Use \OC::$server->getShareManager()->sharingDisabledForUser |
|
130 | + */ |
|
131 | + public static function isSharingDisabledForUser() { |
|
132 | + if (self::$shareManager === null) { |
|
133 | + self::$shareManager = \OC::$server->getShareManager(); |
|
134 | + } |
|
135 | + |
|
136 | + $user = \OC::$server->getUserSession()->getUser(); |
|
137 | + if ($user !== null) { |
|
138 | + $user = $user->getUID(); |
|
139 | + } |
|
140 | + |
|
141 | + return self::$shareManager->sharingDisabledForUser($user); |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * get l10n object |
|
146 | + * @param string $application |
|
147 | + * @param string|null $language |
|
148 | + * @return \OCP\IL10N |
|
149 | + * @since 6.0.0 - parameter $language was added in 8.0.0 |
|
150 | + */ |
|
151 | + public static function getL10N($application, $language = null) { |
|
152 | + return \OC::$server->getL10N($application, $language); |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * add a css file |
|
157 | + * @param string $application |
|
158 | + * @param string $file |
|
159 | + * @since 4.0.0 |
|
160 | + */ |
|
161 | + public static function addStyle($application, $file = null) { |
|
162 | + \OC_Util::addStyle($application, $file); |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * add a javascript file |
|
167 | + * |
|
168 | + * @param string $application |
|
169 | + * @param string|null $file |
|
170 | + * @param string $afterAppId |
|
171 | + * @since 4.0.0 |
|
172 | + */ |
|
173 | + public static function addScript(string $application, string $file = null, string $afterAppId = 'core'): void { |
|
174 | + if (!empty($application)) { |
|
175 | + $path = "$application/js/$file"; |
|
176 | + } else { |
|
177 | + $path = "js/$file"; |
|
178 | + } |
|
179 | + |
|
180 | + // Inject js translations if we load a script for |
|
181 | + // a specific app that is not core, as those js files |
|
182 | + // need separate handling |
|
183 | + if ($application !== 'core' |
|
184 | + && $file !== null |
|
185 | + && strpos($file, 'l10n') === false) { |
|
186 | + self::addTranslations($application); |
|
187 | + } |
|
188 | + |
|
189 | + // store app in dependency list |
|
190 | + if (!array_key_exists($application, self::$scriptDeps)) { |
|
191 | + self::$scriptDeps[$application] = new AppScriptDependency($application, [$afterAppId]); |
|
192 | + } else { |
|
193 | + self::$scriptDeps[$application]->addDep($afterAppId); |
|
194 | + } |
|
195 | + |
|
196 | + self::$scripts[$application][] = $path; |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * Return the list of scripts injected to the page |
|
201 | + * |
|
202 | + * @return array |
|
203 | + * @since 24.0.0 |
|
204 | + */ |
|
205 | + public static function getScripts(): array { |
|
206 | + // Sort scriptDeps into sortedScriptDeps |
|
207 | + $scriptSort = \OC::$server->get(AppScriptSort::class); |
|
208 | + $sortedScripts = $scriptSort->sort(self::$scripts, self::$scriptDeps); |
|
209 | + |
|
210 | + // Flatten array and remove duplicates |
|
211 | + $sortedScripts = $sortedScripts ? array_merge(...array_values(($sortedScripts))) : []; |
|
212 | + |
|
213 | + // Override core-common and core-main order |
|
214 | + array_unshift($sortedScripts, 'core/js/common', 'core/js/main'); |
|
215 | + |
|
216 | + return array_unique($sortedScripts); |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * Add a translation JS file |
|
221 | + * @param string $application application id |
|
222 | + * @param string $languageCode language code, defaults to the current locale |
|
223 | + * @since 8.0.0 |
|
224 | + */ |
|
225 | + public static function addTranslations($application, $languageCode = null) { |
|
226 | + if (is_null($languageCode)) { |
|
227 | + $languageCode = \OC::$server->getL10NFactory()->findLanguage($application); |
|
228 | + } |
|
229 | + if (!empty($application)) { |
|
230 | + $path = "$application/l10n/$languageCode"; |
|
231 | + } else { |
|
232 | + $path = "l10n/$languageCode"; |
|
233 | + } |
|
234 | + self::$scripts[$application][] = $path; |
|
235 | + } |
|
236 | + |
|
237 | + /** |
|
238 | + * Add a custom element to the header |
|
239 | + * If $text is null then the element will be written as empty element. |
|
240 | + * So use "" to get a closing tag. |
|
241 | + * @param string $tag tag name of the element |
|
242 | + * @param array $attributes array of attributes for the element |
|
243 | + * @param string $text the text content for the element |
|
244 | + * @since 4.0.0 |
|
245 | + */ |
|
246 | + public static function addHeader($tag, $attributes, $text = null) { |
|
247 | + \OC_Util::addHeader($tag, $attributes, $text); |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * Creates an absolute url to the given app and file. |
|
252 | + * @param string $app app |
|
253 | + * @param string $file file |
|
254 | + * @param array $args array with param=>value, will be appended to the returned url |
|
255 | + * The value of $args will be urlencoded |
|
256 | + * @return string the url |
|
257 | + * @since 4.0.0 - parameter $args was added in 4.5.0 |
|
258 | + */ |
|
259 | + public static function linkToAbsolute($app, $file, $args = []) { |
|
260 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
261 | + return $urlGenerator->getAbsoluteURL( |
|
262 | + $urlGenerator->linkTo($app, $file, $args) |
|
263 | + ); |
|
264 | + } |
|
265 | + |
|
266 | + /** |
|
267 | + * Creates an absolute url for remote use. |
|
268 | + * @param string $service id |
|
269 | + * @return string the url |
|
270 | + * @since 4.0.0 |
|
271 | + */ |
|
272 | + public static function linkToRemote($service) { |
|
273 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
274 | + $remoteBase = $urlGenerator->linkTo('', 'remote.php') . '/' . $service; |
|
275 | + return $urlGenerator->getAbsoluteURL( |
|
276 | + $remoteBase . (($service[strlen($service) - 1] != '/') ? '/' : '') |
|
277 | + ); |
|
278 | + } |
|
279 | + |
|
280 | + /** |
|
281 | + * Creates an absolute url for public use |
|
282 | + * @param string $service id |
|
283 | + * @return string the url |
|
284 | + * @since 4.5.0 |
|
285 | + * @deprecated 15.0.0 - use OCP\IURLGenerator |
|
286 | + */ |
|
287 | + public static function linkToPublic($service) { |
|
288 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
289 | + if ($service === 'files') { |
|
290 | + return $urlGenerator->getAbsoluteURL('/s'); |
|
291 | + } |
|
292 | + return $urlGenerator->getAbsoluteURL($urlGenerator->linkTo('', 'public.php').'?service='.$service); |
|
293 | + } |
|
294 | + |
|
295 | + /** |
|
296 | + * Returns the server host name without an eventual port number |
|
297 | + * @return string the server hostname |
|
298 | + * @since 5.0.0 |
|
299 | + */ |
|
300 | + public static function getServerHostName() { |
|
301 | + $host_name = \OC::$server->getRequest()->getServerHost(); |
|
302 | + // strip away port number (if existing) |
|
303 | + $colon_pos = strpos($host_name, ':'); |
|
304 | + if ($colon_pos != false) { |
|
305 | + $host_name = substr($host_name, 0, $colon_pos); |
|
306 | + } |
|
307 | + return $host_name; |
|
308 | + } |
|
309 | + |
|
310 | + /** |
|
311 | + * Returns the default email address |
|
312 | + * @param string $user_part the user part of the address |
|
313 | + * @return string the default email address |
|
314 | + * |
|
315 | + * Assembles a default email address (using the server hostname |
|
316 | + * and the given user part, and returns it |
|
317 | + * Example: when given lostpassword-noreply as $user_part param, |
|
318 | + * and is currently accessed via http(s)://example.com/, |
|
319 | + * it would return '[email protected]' |
|
320 | + * |
|
321 | + * If the configuration value 'mail_from_address' is set in |
|
322 | + * config.php, this value will override the $user_part that |
|
323 | + * is passed to this function |
|
324 | + * @since 5.0.0 |
|
325 | + */ |
|
326 | + public static function getDefaultEmailAddress(string $user_part): string { |
|
327 | + $config = \OC::$server->getConfig(); |
|
328 | + $user_part = $config->getSystemValueString('mail_from_address', $user_part); |
|
329 | + $host_name = self::getServerHostName(); |
|
330 | + $host_name = $config->getSystemValueString('mail_domain', $host_name); |
|
331 | + $defaultEmailAddress = $user_part.'@'.$host_name; |
|
332 | + |
|
333 | + $mailer = \OC::$server->getMailer(); |
|
334 | + if ($mailer->validateMailAddress($defaultEmailAddress)) { |
|
335 | + return $defaultEmailAddress; |
|
336 | + } |
|
337 | + |
|
338 | + // in case we cannot build a valid email address from the hostname let's fallback to 'localhost.localdomain' |
|
339 | + return $user_part.'@localhost.localdomain'; |
|
340 | + } |
|
341 | + |
|
342 | + /** |
|
343 | + * Make a human file size (2048 to 2 kB) |
|
344 | + * @param int $bytes file size in bytes |
|
345 | + * @return string a human readable file size |
|
346 | + * @since 4.0.0 |
|
347 | + */ |
|
348 | + public static function humanFileSize($bytes) { |
|
349 | + return \OC_Helper::humanFileSize($bytes); |
|
350 | + } |
|
351 | + |
|
352 | + /** |
|
353 | + * Make a computer file size (2 kB to 2048) |
|
354 | + * @param string $str file size in a fancy format |
|
355 | + * @return float|false a file size in bytes |
|
356 | + * |
|
357 | + * Inspired by: https://www.php.net/manual/en/function.filesize.php#92418 |
|
358 | + * @since 4.0.0 |
|
359 | + */ |
|
360 | + public static function computerFileSize($str) { |
|
361 | + return \OC_Helper::computerFileSize($str); |
|
362 | + } |
|
363 | + |
|
364 | + /** |
|
365 | + * connects a function to a hook |
|
366 | + * |
|
367 | + * @param string $signalClass class name of emitter |
|
368 | + * @param string $signalName name of signal |
|
369 | + * @param string|object $slotClass class name of slot |
|
370 | + * @param string $slotName name of slot |
|
371 | + * @return bool |
|
372 | + * |
|
373 | + * This function makes it very easy to connect to use hooks. |
|
374 | + * |
|
375 | + * TODO: write example |
|
376 | + * @since 4.0.0 |
|
377 | + * @deprecated 21.0.0 use \OCP\EventDispatcher\IEventDispatcher::addListener |
|
378 | + */ |
|
379 | + public static function connectHook($signalClass, $signalName, $slotClass, $slotName) { |
|
380 | + return \OC_Hook::connect($signalClass, $signalName, $slotClass, $slotName); |
|
381 | + } |
|
382 | + |
|
383 | + /** |
|
384 | + * Emits a signal. To get data from the slot use references! |
|
385 | + * @param string $signalclass class name of emitter |
|
386 | + * @param string $signalname name of signal |
|
387 | + * @param array $params default: array() array with additional data |
|
388 | + * @return bool true if slots exists or false if not |
|
389 | + * |
|
390 | + * TODO: write example |
|
391 | + * @since 4.0.0 |
|
392 | + * @deprecated 21.0.0 use \OCP\EventDispatcher\IEventDispatcher::dispatchTypedEvent |
|
393 | + */ |
|
394 | + public static function emitHook($signalclass, $signalname, $params = []) { |
|
395 | + return \OC_Hook::emit($signalclass, $signalname, $params); |
|
396 | + } |
|
397 | + |
|
398 | + /** |
|
399 | + * Cached encrypted CSRF token. Some static unit-tests of ownCloud compare |
|
400 | + * multiple OC_Template elements which invoke `callRegister`. If the value |
|
401 | + * would not be cached these unit-tests would fail. |
|
402 | + * @var string |
|
403 | + */ |
|
404 | + private static $token = ''; |
|
405 | + |
|
406 | + /** |
|
407 | + * Register an get/post call. This is important to prevent CSRF attacks |
|
408 | + * @since 4.5.0 |
|
409 | + */ |
|
410 | + public static function callRegister() { |
|
411 | + if (self::$token === '') { |
|
412 | + self::$token = \OC::$server->getCsrfTokenManager()->getToken()->getEncryptedValue(); |
|
413 | + } |
|
414 | + return self::$token; |
|
415 | + } |
|
416 | + |
|
417 | + /** |
|
418 | + * Used to sanitize HTML |
|
419 | + * |
|
420 | + * This function is used to sanitize HTML and should be applied on any |
|
421 | + * string or array of strings before displaying it on a web page. |
|
422 | + * |
|
423 | + * @param string|string[] $value |
|
424 | + * @return string|string[] an array of sanitized strings or a single sanitized string, depends on the input parameter. |
|
425 | + * @since 4.5.0 |
|
426 | + */ |
|
427 | + public static function sanitizeHTML($value) { |
|
428 | + return \OC_Util::sanitizeHTML($value); |
|
429 | + } |
|
430 | + |
|
431 | + /** |
|
432 | + * Public function to encode url parameters |
|
433 | + * |
|
434 | + * This function is used to encode path to file before output. |
|
435 | + * Encoding is done according to RFC 3986 with one exception: |
|
436 | + * Character '/' is preserved as is. |
|
437 | + * |
|
438 | + * @param string $component part of URI to encode |
|
439 | + * @return string |
|
440 | + * @since 6.0.0 |
|
441 | + */ |
|
442 | + public static function encodePath($component) { |
|
443 | + return \OC_Util::encodePath($component); |
|
444 | + } |
|
445 | + |
|
446 | + /** |
|
447 | + * Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is. |
|
448 | + * |
|
449 | + * @param array $input The array to work on |
|
450 | + * @param int $case Either MB_CASE_UPPER or MB_CASE_LOWER (default) |
|
451 | + * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8 |
|
452 | + * @return array |
|
453 | + * @since 4.5.0 |
|
454 | + */ |
|
455 | + public static function mb_array_change_key_case($input, $case = MB_CASE_LOWER, $encoding = 'UTF-8') { |
|
456 | + return \OC_Helper::mb_array_change_key_case($input, $case, $encoding); |
|
457 | + } |
|
458 | + |
|
459 | + /** |
|
460 | + * performs a search in a nested array |
|
461 | + * |
|
462 | + * @param array $haystack the array to be searched |
|
463 | + * @param string $needle the search string |
|
464 | + * @param mixed $index optional, only search this key name |
|
465 | + * @return mixed the key of the matching field, otherwise false |
|
466 | + * @since 4.5.0 |
|
467 | + * @deprecated 15.0.0 |
|
468 | + */ |
|
469 | + public static function recursiveArraySearch($haystack, $needle, $index = null) { |
|
470 | + return \OC_Helper::recursiveArraySearch($haystack, $needle, $index); |
|
471 | + } |
|
472 | + |
|
473 | + /** |
|
474 | + * calculates the maximum upload size respecting system settings, free space and user quota |
|
475 | + * |
|
476 | + * @param string $dir the current folder where the user currently operates |
|
477 | + * @param int $free the number of bytes free on the storage holding $dir, if not set this will be received from the storage directly |
|
478 | + * @return int number of bytes representing |
|
479 | + * @since 5.0.0 |
|
480 | + */ |
|
481 | + public static function maxUploadFilesize($dir, $free = null) { |
|
482 | + return \OC_Helper::maxUploadFilesize($dir, $free); |
|
483 | + } |
|
484 | + |
|
485 | + /** |
|
486 | + * Calculate free space left within user quota |
|
487 | + * @param string $dir the current folder where the user currently operates |
|
488 | + * @return int number of bytes representing |
|
489 | + * @since 7.0.0 |
|
490 | + */ |
|
491 | + public static function freeSpace($dir) { |
|
492 | + return \OC_Helper::freeSpace($dir); |
|
493 | + } |
|
494 | + |
|
495 | + /** |
|
496 | + * Calculate PHP upload limit |
|
497 | + * |
|
498 | + * @return int number of bytes representing |
|
499 | + * @since 7.0.0 |
|
500 | + */ |
|
501 | + public static function uploadLimit() { |
|
502 | + return \OC_Helper::uploadLimit(); |
|
503 | + } |
|
504 | + |
|
505 | + /** |
|
506 | + * Returns whether the given file name is valid |
|
507 | + * @param string $file file name to check |
|
508 | + * @return bool true if the file name is valid, false otherwise |
|
509 | + * @deprecated 8.1.0 use \OC\Files\View::verifyPath() |
|
510 | + * @since 7.0.0 |
|
511 | + * @suppress PhanDeprecatedFunction |
|
512 | + */ |
|
513 | + public static function isValidFileName($file) { |
|
514 | + return \OC_Util::isValidFileName($file); |
|
515 | + } |
|
516 | + |
|
517 | + /** |
|
518 | + * Compare two strings to provide a natural sort |
|
519 | + * @param string $a first string to compare |
|
520 | + * @param string $b second string to compare |
|
521 | + * @return int -1 if $b comes before $a, 1 if $a comes before $b |
|
522 | + * or 0 if the strings are identical |
|
523 | + * @since 7.0.0 |
|
524 | + */ |
|
525 | + public static function naturalSortCompare($a, $b) { |
|
526 | + return \OC\NaturalSort::getInstance()->compare($a, $b); |
|
527 | + } |
|
528 | + |
|
529 | + /** |
|
530 | + * Check if a password is required for each public link |
|
531 | + * |
|
532 | + * @param bool $checkGroupMembership Check group membership exclusion |
|
533 | + * @return boolean |
|
534 | + * @since 7.0.0 |
|
535 | + */ |
|
536 | + public static function isPublicLinkPasswordRequired(bool $checkGroupMembership = true) { |
|
537 | + return \OC_Util::isPublicLinkPasswordRequired($checkGroupMembership); |
|
538 | + } |
|
539 | + |
|
540 | + /** |
|
541 | + * check if share API enforces a default expire date |
|
542 | + * @return boolean |
|
543 | + * @since 8.0.0 |
|
544 | + */ |
|
545 | + public static function isDefaultExpireDateEnforced() { |
|
546 | + return \OC_Util::isDefaultExpireDateEnforced(); |
|
547 | + } |
|
548 | + |
|
549 | + protected static $needUpgradeCache = null; |
|
550 | + |
|
551 | + /** |
|
552 | + * Checks whether the current version needs upgrade. |
|
553 | + * |
|
554 | + * @return bool true if upgrade is needed, false otherwise |
|
555 | + * @since 7.0.0 |
|
556 | + */ |
|
557 | + public static function needUpgrade() { |
|
558 | + if (!isset(self::$needUpgradeCache)) { |
|
559 | + self::$needUpgradeCache = \OC_Util::needUpgrade(\OC::$server->getSystemConfig()); |
|
560 | + } |
|
561 | + return self::$needUpgradeCache; |
|
562 | + } |
|
563 | + |
|
564 | + /** |
|
565 | + * Sometimes a string has to be shortened to fit within a certain maximum |
|
566 | + * data length in bytes. substr() you may break multibyte characters, |
|
567 | + * because it operates on single byte level. mb_substr() operates on |
|
568 | + * characters, so does not ensure that the shortend string satisfies the |
|
569 | + * max length in bytes. |
|
570 | + * |
|
571 | + * For example, json_encode is messing with multibyte characters a lot, |
|
572 | + * replacing them with something along "\u1234". |
|
573 | + * |
|
574 | + * This function shortens the string with by $accurancy (-5) from |
|
575 | + * $dataLength characters, until it fits within $dataLength bytes. |
|
576 | + * |
|
577 | + * @since 23.0.0 |
|
578 | + */ |
|
579 | + public static function shortenMultibyteString(string $subject, int $dataLength, int $accuracy = 5): string { |
|
580 | + $temp = mb_substr($subject, 0, $dataLength); |
|
581 | + // json encodes encapsulates the string in double quotes, they need to be substracted |
|
582 | + while ((strlen(json_encode($temp)) - 2) > $dataLength) { |
|
583 | + $temp = mb_substr($temp, 0, -$accuracy); |
|
584 | + } |
|
585 | + return $temp; |
|
586 | + } |
|
587 | + |
|
588 | + /** |
|
589 | + * Check if a function is enabled in the php configuration |
|
590 | + * |
|
591 | + * @since 25.0.0 |
|
592 | + */ |
|
593 | + public static function isFunctionEnabled(string $functionName): bool { |
|
594 | + if (!function_exists($functionName)) { |
|
595 | + return false; |
|
596 | + } |
|
597 | + $ini = \OCP\Server::get(IniGetWrapper::class); |
|
598 | + $disabled = explode(',', $ini->get('disable_functions') ?: ''); |
|
599 | + $disabled = array_map('trim', $disabled); |
|
600 | + if (in_array($functionName, $disabled)) { |
|
601 | + return false; |
|
602 | + } |
|
603 | + $disabled = explode(',', $ini->get('suhosin.executor.func.blacklist') ?: ''); |
|
604 | + $disabled = array_map('trim', $disabled); |
|
605 | + if (in_array($functionName, $disabled)) { |
|
606 | + return false; |
|
607 | + } |
|
608 | + return true; |
|
609 | + } |
|
610 | 610 | } |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | |
79 | 79 | // default responders |
80 | 80 | $this->responders = [ |
81 | - 'json' => function ($data) { |
|
81 | + 'json' => function($data) { |
|
82 | 82 | if ($data instanceof DataResponse) { |
83 | 83 | $response = new JSONResponse( |
84 | 84 | $data->getData(), |
@@ -153,6 +153,6 @@ discard block |
||
153 | 153 | return $responder($response); |
154 | 154 | } |
155 | 155 | throw new \DomainException('No responder registered for format '. |
156 | - $format . '!'); |
|
156 | + $format.'!'); |
|
157 | 157 | } |
158 | 158 | } |
@@ -38,122 +38,122 @@ |
||
38 | 38 | * @since 6.0.0 |
39 | 39 | */ |
40 | 40 | abstract class Controller { |
41 | - /** |
|
42 | - * app name |
|
43 | - * @var string |
|
44 | - * @since 7.0.0 |
|
45 | - */ |
|
46 | - protected $appName; |
|
47 | - |
|
48 | - /** |
|
49 | - * current request |
|
50 | - * @var \OCP\IRequest |
|
51 | - * @since 6.0.0 |
|
52 | - */ |
|
53 | - protected $request; |
|
54 | - |
|
55 | - /** |
|
56 | - * @var array |
|
57 | - * @since 7.0.0 |
|
58 | - */ |
|
59 | - private $responders; |
|
60 | - |
|
61 | - /** |
|
62 | - * constructor of the controller |
|
63 | - * @param string $appName the name of the app |
|
64 | - * @param IRequest $request an instance of the request |
|
65 | - * @since 6.0.0 - parameter $appName was added in 7.0.0 - parameter $app was removed in 7.0.0 |
|
66 | - */ |
|
67 | - public function __construct($appName, |
|
68 | - IRequest $request) { |
|
69 | - $this->appName = $appName; |
|
70 | - $this->request = $request; |
|
71 | - |
|
72 | - // default responders |
|
73 | - $this->responders = [ |
|
74 | - 'json' => function ($data) { |
|
75 | - if ($data instanceof DataResponse) { |
|
76 | - $response = new JSONResponse( |
|
77 | - $data->getData(), |
|
78 | - $data->getStatus() |
|
79 | - ); |
|
80 | - $dataHeaders = $data->getHeaders(); |
|
81 | - $headers = $response->getHeaders(); |
|
82 | - // do not overwrite Content-Type if it already exists |
|
83 | - if (isset($dataHeaders['Content-Type'])) { |
|
84 | - unset($headers['Content-Type']); |
|
85 | - } |
|
86 | - $response->setHeaders(array_merge($dataHeaders, $headers)); |
|
87 | - |
|
88 | - if ($data->getETag() !== null) { |
|
89 | - $response->setETag($data->getETag()); |
|
90 | - } |
|
91 | - if ($data->getLastModified() !== null) { |
|
92 | - $response->setLastModified($data->getLastModified()); |
|
93 | - } |
|
94 | - |
|
95 | - return $response; |
|
96 | - } |
|
97 | - return new JSONResponse($data); |
|
98 | - } |
|
99 | - ]; |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * Parses an HTTP accept header and returns the supported responder type |
|
105 | - * @param string $acceptHeader |
|
106 | - * @param string $default |
|
107 | - * @return string the responder type |
|
108 | - * @since 7.0.0 |
|
109 | - * @since 9.1.0 Added default parameter |
|
110 | - */ |
|
111 | - public function getResponderByHTTPHeader($acceptHeader, $default = 'json') { |
|
112 | - $headers = explode(',', $acceptHeader); |
|
113 | - |
|
114 | - // return the first matching responder |
|
115 | - foreach ($headers as $header) { |
|
116 | - $header = strtolower(trim($header)); |
|
117 | - |
|
118 | - $responder = str_replace('application/', '', $header); |
|
119 | - |
|
120 | - if (array_key_exists($responder, $this->responders)) { |
|
121 | - return $responder; |
|
122 | - } |
|
123 | - } |
|
124 | - |
|
125 | - // no matching header return default |
|
126 | - return $default; |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * Registers a formatter for a type |
|
132 | - * @param string $format |
|
133 | - * @param \Closure $responder |
|
134 | - * @since 7.0.0 |
|
135 | - */ |
|
136 | - protected function registerResponder($format, \Closure $responder) { |
|
137 | - $this->responders[$format] = $responder; |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * Serializes and formats a response |
|
143 | - * @param mixed $response the value that was returned from a controller and |
|
144 | - * is not a Response instance |
|
145 | - * @param string $format the format for which a formatter has been registered |
|
146 | - * @throws \DomainException if format does not match a registered formatter |
|
147 | - * @return Response |
|
148 | - * @since 7.0.0 |
|
149 | - */ |
|
150 | - public function buildResponse($response, $format = 'json') { |
|
151 | - if (array_key_exists($format, $this->responders)) { |
|
152 | - $responder = $this->responders[$format]; |
|
153 | - |
|
154 | - return $responder($response); |
|
155 | - } |
|
156 | - throw new \DomainException('No responder registered for format '. |
|
157 | - $format . '!'); |
|
158 | - } |
|
41 | + /** |
|
42 | + * app name |
|
43 | + * @var string |
|
44 | + * @since 7.0.0 |
|
45 | + */ |
|
46 | + protected $appName; |
|
47 | + |
|
48 | + /** |
|
49 | + * current request |
|
50 | + * @var \OCP\IRequest |
|
51 | + * @since 6.0.0 |
|
52 | + */ |
|
53 | + protected $request; |
|
54 | + |
|
55 | + /** |
|
56 | + * @var array |
|
57 | + * @since 7.0.0 |
|
58 | + */ |
|
59 | + private $responders; |
|
60 | + |
|
61 | + /** |
|
62 | + * constructor of the controller |
|
63 | + * @param string $appName the name of the app |
|
64 | + * @param IRequest $request an instance of the request |
|
65 | + * @since 6.0.0 - parameter $appName was added in 7.0.0 - parameter $app was removed in 7.0.0 |
|
66 | + */ |
|
67 | + public function __construct($appName, |
|
68 | + IRequest $request) { |
|
69 | + $this->appName = $appName; |
|
70 | + $this->request = $request; |
|
71 | + |
|
72 | + // default responders |
|
73 | + $this->responders = [ |
|
74 | + 'json' => function ($data) { |
|
75 | + if ($data instanceof DataResponse) { |
|
76 | + $response = new JSONResponse( |
|
77 | + $data->getData(), |
|
78 | + $data->getStatus() |
|
79 | + ); |
|
80 | + $dataHeaders = $data->getHeaders(); |
|
81 | + $headers = $response->getHeaders(); |
|
82 | + // do not overwrite Content-Type if it already exists |
|
83 | + if (isset($dataHeaders['Content-Type'])) { |
|
84 | + unset($headers['Content-Type']); |
|
85 | + } |
|
86 | + $response->setHeaders(array_merge($dataHeaders, $headers)); |
|
87 | + |
|
88 | + if ($data->getETag() !== null) { |
|
89 | + $response->setETag($data->getETag()); |
|
90 | + } |
|
91 | + if ($data->getLastModified() !== null) { |
|
92 | + $response->setLastModified($data->getLastModified()); |
|
93 | + } |
|
94 | + |
|
95 | + return $response; |
|
96 | + } |
|
97 | + return new JSONResponse($data); |
|
98 | + } |
|
99 | + ]; |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * Parses an HTTP accept header and returns the supported responder type |
|
105 | + * @param string $acceptHeader |
|
106 | + * @param string $default |
|
107 | + * @return string the responder type |
|
108 | + * @since 7.0.0 |
|
109 | + * @since 9.1.0 Added default parameter |
|
110 | + */ |
|
111 | + public function getResponderByHTTPHeader($acceptHeader, $default = 'json') { |
|
112 | + $headers = explode(',', $acceptHeader); |
|
113 | + |
|
114 | + // return the first matching responder |
|
115 | + foreach ($headers as $header) { |
|
116 | + $header = strtolower(trim($header)); |
|
117 | + |
|
118 | + $responder = str_replace('application/', '', $header); |
|
119 | + |
|
120 | + if (array_key_exists($responder, $this->responders)) { |
|
121 | + return $responder; |
|
122 | + } |
|
123 | + } |
|
124 | + |
|
125 | + // no matching header return default |
|
126 | + return $default; |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * Registers a formatter for a type |
|
132 | + * @param string $format |
|
133 | + * @param \Closure $responder |
|
134 | + * @since 7.0.0 |
|
135 | + */ |
|
136 | + protected function registerResponder($format, \Closure $responder) { |
|
137 | + $this->responders[$format] = $responder; |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * Serializes and formats a response |
|
143 | + * @param mixed $response the value that was returned from a controller and |
|
144 | + * is not a Response instance |
|
145 | + * @param string $format the format for which a formatter has been registered |
|
146 | + * @throws \DomainException if format does not match a registered formatter |
|
147 | + * @return Response |
|
148 | + * @since 7.0.0 |
|
149 | + */ |
|
150 | + public function buildResponse($response, $format = 'json') { |
|
151 | + if (array_key_exists($format, $this->responders)) { |
|
152 | + $responder = $this->responders[$format]; |
|
153 | + |
|
154 | + return $responder($response); |
|
155 | + } |
|
156 | + throw new \DomainException('No responder registered for format '. |
|
157 | + $format . '!'); |
|
158 | + } |
|
159 | 159 | } |
@@ -32,14 +32,14 @@ |
||
32 | 32 | * @since 9.1.0 |
33 | 33 | */ |
34 | 34 | class OCSNotFoundException extends OCSException { |
35 | - /** |
|
36 | - * OCSNotFoundException constructor. |
|
37 | - * |
|
38 | - * @param string $message |
|
39 | - * @param Exception|null $previous |
|
40 | - * @since 9.1.0 |
|
41 | - */ |
|
42 | - public function __construct($message = '', Exception $previous = null) { |
|
43 | - parent::__construct($message, Http::STATUS_NOT_FOUND, $previous); |
|
44 | - } |
|
35 | + /** |
|
36 | + * OCSNotFoundException constructor. |
|
37 | + * |
|
38 | + * @param string $message |
|
39 | + * @param Exception|null $previous |
|
40 | + * @since 9.1.0 |
|
41 | + */ |
|
42 | + public function __construct($message = '', Exception $previous = null) { |
|
43 | + parent::__construct($message, Http::STATUS_NOT_FOUND, $previous); |
|
44 | + } |
|
45 | 45 | } |
@@ -32,14 +32,14 @@ |
||
32 | 32 | * @since 9.1.0 |
33 | 33 | */ |
34 | 34 | class OCSForbiddenException extends OCSException { |
35 | - /** |
|
36 | - * OCSForbiddenException constructor. |
|
37 | - * |
|
38 | - * @param string $message |
|
39 | - * @param Exception|null $previous |
|
40 | - * @since 9.1.0 |
|
41 | - */ |
|
42 | - public function __construct($message = '', Exception $previous = null) { |
|
43 | - parent::__construct($message, Http::STATUS_FORBIDDEN, $previous); |
|
44 | - } |
|
35 | + /** |
|
36 | + * OCSForbiddenException constructor. |
|
37 | + * |
|
38 | + * @param string $message |
|
39 | + * @param Exception|null $previous |
|
40 | + * @since 9.1.0 |
|
41 | + */ |
|
42 | + public function __construct($message = '', Exception $previous = null) { |
|
43 | + parent::__construct($message, Http::STATUS_FORBIDDEN, $previous); |
|
44 | + } |
|
45 | 45 | } |
@@ -32,14 +32,14 @@ |
||
32 | 32 | * @since 9.1.0 |
33 | 33 | */ |
34 | 34 | class OCSBadRequestException extends OCSException { |
35 | - /** |
|
36 | - * OCSBadRequestException constructor. |
|
37 | - * |
|
38 | - * @param string $message |
|
39 | - * @param Exception|null $previous |
|
40 | - * @since 9.1.0 |
|
41 | - */ |
|
42 | - public function __construct($message = '', Exception $previous = null) { |
|
43 | - parent::__construct($message, Http::STATUS_BAD_REQUEST, $previous); |
|
44 | - } |
|
35 | + /** |
|
36 | + * OCSBadRequestException constructor. |
|
37 | + * |
|
38 | + * @param string $message |
|
39 | + * @param Exception|null $previous |
|
40 | + * @since 9.1.0 |
|
41 | + */ |
|
42 | + public function __construct($message = '', Exception $previous = null) { |
|
43 | + parent::__construct($message, Http::STATUS_BAD_REQUEST, $previous); |
|
44 | + } |
|
45 | 45 | } |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | $this->file = $file; |
52 | 52 | $this->setStatus($statusCode); |
53 | 53 | $this->setHeaders(array_merge($this->getHeaders(), $headers)); |
54 | - $this->addHeader('Content-Disposition', 'inline; filename="' . rawurldecode($file->getName()) . '"'); |
|
54 | + $this->addHeader('Content-Disposition', 'inline; filename="'.rawurldecode($file->getName()).'"'); |
|
55 | 55 | |
56 | 56 | $this->setETag($file->getEtag()); |
57 | 57 | $lastModified = new \DateTime(); |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | */ |
66 | 66 | public function callback(IOutput $output) { |
67 | 67 | if ($output->getHttpResponseCode() !== Http::STATUS_NOT_MODIFIED) { |
68 | - $output->setHeader('Content-Length: ' . $this->file->getSize()); |
|
68 | + $output->setHeader('Content-Length: '.$this->file->getSize()); |
|
69 | 69 | $output->setOutput($this->file->getContent()); |
70 | 70 | } |
71 | 71 | } |
@@ -31,40 +31,40 @@ |
||
31 | 31 | * @since 11.0.0 |
32 | 32 | */ |
33 | 33 | class FileDisplayResponse extends Response implements ICallbackResponse { |
34 | - /** @var \OCP\Files\File|\OCP\Files\SimpleFS\ISimpleFile */ |
|
35 | - private $file; |
|
34 | + /** @var \OCP\Files\File|\OCP\Files\SimpleFS\ISimpleFile */ |
|
35 | + private $file; |
|
36 | 36 | |
37 | - /** |
|
38 | - * FileDisplayResponse constructor. |
|
39 | - * |
|
40 | - * @param \OCP\Files\File|\OCP\Files\SimpleFS\ISimpleFile $file |
|
41 | - * @param int $statusCode |
|
42 | - * @param array $headers |
|
43 | - * @since 11.0.0 |
|
44 | - */ |
|
45 | - public function __construct($file, $statusCode = Http::STATUS_OK, |
|
46 | - $headers = []) { |
|
47 | - parent::__construct(); |
|
37 | + /** |
|
38 | + * FileDisplayResponse constructor. |
|
39 | + * |
|
40 | + * @param \OCP\Files\File|\OCP\Files\SimpleFS\ISimpleFile $file |
|
41 | + * @param int $statusCode |
|
42 | + * @param array $headers |
|
43 | + * @since 11.0.0 |
|
44 | + */ |
|
45 | + public function __construct($file, $statusCode = Http::STATUS_OK, |
|
46 | + $headers = []) { |
|
47 | + parent::__construct(); |
|
48 | 48 | |
49 | - $this->file = $file; |
|
50 | - $this->setStatus($statusCode); |
|
51 | - $this->setHeaders(array_merge($this->getHeaders(), $headers)); |
|
52 | - $this->addHeader('Content-Disposition', 'inline; filename="' . rawurldecode($file->getName()) . '"'); |
|
49 | + $this->file = $file; |
|
50 | + $this->setStatus($statusCode); |
|
51 | + $this->setHeaders(array_merge($this->getHeaders(), $headers)); |
|
52 | + $this->addHeader('Content-Disposition', 'inline; filename="' . rawurldecode($file->getName()) . '"'); |
|
53 | 53 | |
54 | - $this->setETag($file->getEtag()); |
|
55 | - $lastModified = new \DateTime(); |
|
56 | - $lastModified->setTimestamp($file->getMTime()); |
|
57 | - $this->setLastModified($lastModified); |
|
58 | - } |
|
54 | + $this->setETag($file->getEtag()); |
|
55 | + $lastModified = new \DateTime(); |
|
56 | + $lastModified->setTimestamp($file->getMTime()); |
|
57 | + $this->setLastModified($lastModified); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * @param IOutput $output |
|
62 | - * @since 11.0.0 |
|
63 | - */ |
|
64 | - public function callback(IOutput $output) { |
|
65 | - if ($output->getHttpResponseCode() !== Http::STATUS_NOT_MODIFIED) { |
|
66 | - $output->setHeader('Content-Length: ' . $this->file->getSize()); |
|
67 | - $output->setOutput($this->file->getContent()); |
|
68 | - } |
|
69 | - } |
|
60 | + /** |
|
61 | + * @param IOutput $output |
|
62 | + * @since 11.0.0 |
|
63 | + */ |
|
64 | + public function callback(IOutput $output) { |
|
65 | + if ($output->getHttpResponseCode() !== Http::STATUS_NOT_MODIFIED) { |
|
66 | + $output->setHeader('Content-Length: ' . $this->file->getSize()); |
|
67 | + $output->setOutput($this->file->getContent()); |
|
68 | + } |
|
69 | + } |
|
70 | 70 | } |
@@ -35,17 +35,17 @@ |
||
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 | 51 | if ($customDataDir !== '') { |
@@ -28,42 +28,42 @@ |
||
28 | 28 | namespace OC\IntegrityCheck\Iterator; |
29 | 29 | |
30 | 30 | class ExcludeFoldersByPathFilterIterator extends \RecursiveFilterIterator { |
31 | - private $excludedFolders; |
|
31 | + private $excludedFolders; |
|
32 | 32 | |
33 | - public function __construct(\RecursiveIterator $iterator, $root = '') { |
|
34 | - parent::__construct($iterator); |
|
33 | + public function __construct(\RecursiveIterator $iterator, $root = '') { |
|
34 | + parent::__construct($iterator); |
|
35 | 35 | |
36 | - $appFolders = \OC::$APPSROOTS; |
|
37 | - foreach ($appFolders as $key => $appFolder) { |
|
38 | - $appFolders[$key] = rtrim($appFolder['path'], '/'); |
|
39 | - } |
|
36 | + $appFolders = \OC::$APPSROOTS; |
|
37 | + foreach ($appFolders as $key => $appFolder) { |
|
38 | + $appFolders[$key] = rtrim($appFolder['path'], '/'); |
|
39 | + } |
|
40 | 40 | |
41 | - $excludedFolders = [ |
|
42 | - rtrim($root . '/data', '/'), |
|
43 | - rtrim($root . '/themes', '/'), |
|
44 | - rtrim($root . '/config', '/'), |
|
45 | - rtrim($root . '/apps', '/'), |
|
46 | - rtrim($root . '/assets', '/'), |
|
47 | - rtrim($root . '/lost+found', '/'), |
|
48 | - // Ignore folders generated by updater since the updater is replaced |
|
49 | - // after the integrity check is run. |
|
50 | - // See https://github.com/owncloud/updater/issues/318#issuecomment-212497846 |
|
51 | - rtrim($root . '/updater', '/'), |
|
52 | - rtrim($root . '/_oc_upgrade', '/'), |
|
53 | - ]; |
|
54 | - $customDataDir = \OC::$server->getConfig()->getSystemValue('datadirectory', ''); |
|
55 | - if ($customDataDir !== '') { |
|
56 | - $excludedFolders[] = rtrim($customDataDir, '/'); |
|
57 | - } |
|
41 | + $excludedFolders = [ |
|
42 | + rtrim($root . '/data', '/'), |
|
43 | + rtrim($root . '/themes', '/'), |
|
44 | + rtrim($root . '/config', '/'), |
|
45 | + rtrim($root . '/apps', '/'), |
|
46 | + rtrim($root . '/assets', '/'), |
|
47 | + rtrim($root . '/lost+found', '/'), |
|
48 | + // Ignore folders generated by updater since the updater is replaced |
|
49 | + // after the integrity check is run. |
|
50 | + // See https://github.com/owncloud/updater/issues/318#issuecomment-212497846 |
|
51 | + rtrim($root . '/updater', '/'), |
|
52 | + rtrim($root . '/_oc_upgrade', '/'), |
|
53 | + ]; |
|
54 | + $customDataDir = \OC::$server->getConfig()->getSystemValue('datadirectory', ''); |
|
55 | + if ($customDataDir !== '') { |
|
56 | + $excludedFolders[] = rtrim($customDataDir, '/'); |
|
57 | + } |
|
58 | 58 | |
59 | - $this->excludedFolders = array_merge($excludedFolders, $appFolders); |
|
60 | - } |
|
59 | + $this->excludedFolders = array_merge($excludedFolders, $appFolders); |
|
60 | + } |
|
61 | 61 | |
62 | - public function accept(): bool { |
|
63 | - return !\in_array( |
|
64 | - $this->current()->getPathName(), |
|
65 | - $this->excludedFolders, |
|
66 | - true |
|
67 | - ); |
|
68 | - } |
|
62 | + public function accept(): bool { |
|
63 | + return !\in_array( |
|
64 | + $this->current()->getPathName(), |
|
65 | + $this->excludedFolders, |
|
66 | + true |
|
67 | + ); |
|
68 | + } |
|
69 | 69 | } |
@@ -32,7 +32,7 @@ |
||
32 | 32 | * @return bool |
33 | 33 | */ |
34 | 34 | private function isValidVersionString($versionString) { |
35 | - return (bool)preg_match('/^[0-9.]+$/', $versionString); |
|
35 | + return (bool) preg_match('/^[0-9.]+$/', $versionString); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |
@@ -30,56 +30,56 @@ |
||
30 | 30 | * @package OC\App\AppStore |
31 | 31 | */ |
32 | 32 | class VersionParser { |
33 | - /** |
|
34 | - * @param string $versionString |
|
35 | - * @return bool |
|
36 | - */ |
|
37 | - private function isValidVersionString($versionString) { |
|
38 | - return (bool)preg_match('/^[0-9.]+$/', $versionString); |
|
39 | - } |
|
33 | + /** |
|
34 | + * @param string $versionString |
|
35 | + * @return bool |
|
36 | + */ |
|
37 | + private function isValidVersionString($versionString) { |
|
38 | + return (bool)preg_match('/^[0-9.]+$/', $versionString); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * Returns the version for a version string |
|
43 | - * |
|
44 | - * @param string $versionSpec |
|
45 | - * @return Version |
|
46 | - * @throws \Exception If the version cannot be parsed |
|
47 | - */ |
|
48 | - public function getVersion($versionSpec) { |
|
49 | - // * indicates that the version is compatible with all versions |
|
50 | - if ($versionSpec === '*') { |
|
51 | - return new Version('', ''); |
|
52 | - } |
|
41 | + /** |
|
42 | + * Returns the version for a version string |
|
43 | + * |
|
44 | + * @param string $versionSpec |
|
45 | + * @return Version |
|
46 | + * @throws \Exception If the version cannot be parsed |
|
47 | + */ |
|
48 | + public function getVersion($versionSpec) { |
|
49 | + // * indicates that the version is compatible with all versions |
|
50 | + if ($versionSpec === '*') { |
|
51 | + return new Version('', ''); |
|
52 | + } |
|
53 | 53 | |
54 | - // Count the amount of =, if it is one then it's either maximum or minimum |
|
55 | - // version. If it is two then it is maximum and minimum. |
|
56 | - $versionElements = explode(' ', $versionSpec); |
|
57 | - $firstVersion = isset($versionElements[0]) ? $versionElements[0] : ''; |
|
58 | - $firstVersionNumber = substr($firstVersion, 2); |
|
59 | - $secondVersion = isset($versionElements[1]) ? $versionElements[1] : ''; |
|
60 | - $secondVersionNumber = substr($secondVersion, 2); |
|
54 | + // Count the amount of =, if it is one then it's either maximum or minimum |
|
55 | + // version. If it is two then it is maximum and minimum. |
|
56 | + $versionElements = explode(' ', $versionSpec); |
|
57 | + $firstVersion = isset($versionElements[0]) ? $versionElements[0] : ''; |
|
58 | + $firstVersionNumber = substr($firstVersion, 2); |
|
59 | + $secondVersion = isset($versionElements[1]) ? $versionElements[1] : ''; |
|
60 | + $secondVersionNumber = substr($secondVersion, 2); |
|
61 | 61 | |
62 | - switch (count($versionElements)) { |
|
63 | - case 1: |
|
64 | - if (!$this->isValidVersionString($firstVersionNumber)) { |
|
65 | - break; |
|
66 | - } |
|
67 | - if (strpos($firstVersion, '>') === 0) { |
|
68 | - return new Version($firstVersionNumber, ''); |
|
69 | - } |
|
70 | - return new Version('', $firstVersionNumber); |
|
71 | - case 2: |
|
72 | - if (!$this->isValidVersionString($firstVersionNumber) || !$this->isValidVersionString($secondVersionNumber)) { |
|
73 | - break; |
|
74 | - } |
|
75 | - return new Version($firstVersionNumber, $secondVersionNumber); |
|
76 | - } |
|
62 | + switch (count($versionElements)) { |
|
63 | + case 1: |
|
64 | + if (!$this->isValidVersionString($firstVersionNumber)) { |
|
65 | + break; |
|
66 | + } |
|
67 | + if (strpos($firstVersion, '>') === 0) { |
|
68 | + return new Version($firstVersionNumber, ''); |
|
69 | + } |
|
70 | + return new Version('', $firstVersionNumber); |
|
71 | + case 2: |
|
72 | + if (!$this->isValidVersionString($firstVersionNumber) || !$this->isValidVersionString($secondVersionNumber)) { |
|
73 | + break; |
|
74 | + } |
|
75 | + return new Version($firstVersionNumber, $secondVersionNumber); |
|
76 | + } |
|
77 | 77 | |
78 | - throw new \Exception( |
|
79 | - sprintf( |
|
80 | - 'Version cannot be parsed: %s', |
|
81 | - $versionSpec |
|
82 | - ) |
|
83 | - ); |
|
84 | - } |
|
78 | + throw new \Exception( |
|
79 | + sprintf( |
|
80 | + 'Version cannot be parsed: %s', |
|
81 | + $versionSpec |
|
82 | + ) |
|
83 | + ); |
|
84 | + } |
|
85 | 85 | } |
@@ -24,36 +24,36 @@ |
||
24 | 24 | use OCP\IL10N; |
25 | 25 | |
26 | 26 | abstract class Bundle { |
27 | - /** @var IL10N */ |
|
28 | - protected $l10n; |
|
27 | + /** @var IL10N */ |
|
28 | + protected $l10n; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @param IL10N $l10n |
|
32 | - */ |
|
33 | - public function __construct(IL10N $l10n) { |
|
34 | - $this->l10n = $l10n; |
|
35 | - } |
|
30 | + /** |
|
31 | + * @param IL10N $l10n |
|
32 | + */ |
|
33 | + public function __construct(IL10N $l10n) { |
|
34 | + $this->l10n = $l10n; |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * Get the identifier of the bundle |
|
39 | - * |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - final public function getIdentifier() { |
|
43 | - return substr(strrchr(get_class($this), '\\'), 1); |
|
44 | - } |
|
37 | + /** |
|
38 | + * Get the identifier of the bundle |
|
39 | + * |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + final public function getIdentifier() { |
|
43 | + return substr(strrchr(get_class($this), '\\'), 1); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Get the name of the bundle |
|
48 | - * |
|
49 | - * @return string |
|
50 | - */ |
|
51 | - abstract public function getName(); |
|
46 | + /** |
|
47 | + * Get the name of the bundle |
|
48 | + * |
|
49 | + * @return string |
|
50 | + */ |
|
51 | + abstract public function getName(); |
|
52 | 52 | |
53 | - /** |
|
54 | - * Get the list of app identifiers in the bundle |
|
55 | - * |
|
56 | - * @return array |
|
57 | - */ |
|
58 | - abstract public function getAppIdentifiers(); |
|
53 | + /** |
|
54 | + * Get the list of app identifiers in the bundle |
|
55 | + * |
|
56 | + * @return array |
|
57 | + */ |
|
58 | + abstract public function getAppIdentifiers(); |
|
59 | 59 | } |