Completed
Pull Request — master (#5518)
by Morris
15:25
created
lib/public/Util.php 2 patches
Indentation   +649 added lines, -649 removed lines patch added patch discarded remove patch
@@ -57,655 +57,655 @@
 block discarded – undo
57 57
  * @since 4.0.0
58 58
  */
59 59
 class Util {
60
-	// consts for Logging
61
-	const DEBUG=0;
62
-	const INFO=1;
63
-	const WARN=2;
64
-	const ERROR=3;
65
-	const FATAL=4;
66
-
67
-	/** \OCP\Share\IManager */
68
-	private static $shareManager;
69
-
70
-	/**
71
-	 * get the current installed version of ownCloud
72
-	 * @return array
73
-	 * @since 4.0.0
74
-	 */
75
-	public static function getVersion() {
76
-		return(\OC_Util::getVersion());
77
-	}
60
+    // consts for Logging
61
+    const DEBUG=0;
62
+    const INFO=1;
63
+    const WARN=2;
64
+    const ERROR=3;
65
+    const FATAL=4;
66
+
67
+    /** \OCP\Share\IManager */
68
+    private static $shareManager;
69
+
70
+    /**
71
+     * get the current installed version of ownCloud
72
+     * @return array
73
+     * @since 4.0.0
74
+     */
75
+    public static function getVersion() {
76
+        return(\OC_Util::getVersion());
77
+    }
78 78
 	
79
-	/**
80
-	 * Set current update channel
81
-	 * @param string $channel
82
-	 * @since 8.1.0
83
-	 */
84
-	public static function setChannel($channel) {
85
-		\OC::$server->getConfig()->setSystemValue('updater.release.channel', $channel);
86
-	}
79
+    /**
80
+     * Set current update channel
81
+     * @param string $channel
82
+     * @since 8.1.0
83
+     */
84
+    public static function setChannel($channel) {
85
+        \OC::$server->getConfig()->setSystemValue('updater.release.channel', $channel);
86
+    }
87 87
 	
88
-	/**
89
-	 * Get current update channel
90
-	 * @return string
91
-	 * @since 8.1.0
92
-	 */
93
-	public static function getChannel() {
94
-		return \OC_Util::getChannel();
95
-	}
96
-
97
-	/**
98
-	 * send an email
99
-	 * @param string $toaddress
100
-	 * @param string $toname
101
-	 * @param string $subject
102
-	 * @param string $mailtext
103
-	 * @param string $fromaddress
104
-	 * @param string $fromname
105
-	 * @param int $html
106
-	 * @param string $altbody
107
-	 * @param string $ccaddress
108
-	 * @param string $ccname
109
-	 * @param string $bcc
110
-	 * @deprecated 8.1.0 Use \OCP\Mail\IMailer instead
111
-	 * @since 4.0.0
112
-	 */
113
-	public static function sendMail($toaddress, $toname, $subject, $mailtext, $fromaddress, $fromname,
114
-		$html = 0, $altbody = '', $ccaddress = '', $ccname = '', $bcc = '') {
115
-		$mailer = \OC::$server->getMailer();
116
-		$message = $mailer->createMessage();
117
-		$message->setTo([$toaddress => $toname]);
118
-		$message->setSubject($subject);
119
-		$message->setPlainBody($mailtext);
120
-		$message->setFrom([$fromaddress => $fromname]);
121
-		if($html === 1) {
122
-			$message->setHTMLBody($altbody);
123
-		}
124
-
125
-		if($altbody === '') {
126
-			$message->setHTMLBody($mailtext);
127
-			$message->setPlainBody('');
128
-		} else {
129
-			$message->setHtmlBody($mailtext);
130
-			$message->setPlainBody($altbody);
131
-		}
132
-
133
-		if(!empty($ccaddress)) {
134
-			if(!empty($ccname)) {
135
-				$message->setCc([$ccaddress => $ccname]);
136
-			} else {
137
-				$message->setCc([$ccaddress]);
138
-			}
139
-		}
140
-		if(!empty($bcc)) {
141
-			$message->setBcc([$bcc]);
142
-		}
143
-
144
-		$mailer->send($message);
145
-	}
146
-
147
-	/**
148
-	 * write a message in the log
149
-	 * @param string $app
150
-	 * @param string $message
151
-	 * @param int $level
152
-	 * @since 4.0.0
153
-	 * @deprecated 13.0.0 use log of \OCP\ILogger
154
-	 */
155
-	public static function writeLog( $app, $message, $level ) {
156
-		$context = ['app' => $app];
157
-		\OC::$server->getLogger()->log($level, $message, $context);
158
-	}
159
-
160
-	/**
161
-	 * write exception into the log
162
-	 * @param string $app app name
163
-	 * @param \Exception $ex exception to log
164
-	 * @param int $level log level, defaults to \OCP\Util::FATAL
165
-	 * @since ....0.0 - parameter $level was added in 7.0.0
166
-	 * @deprecated 8.2.0 use logException of \OCP\ILogger
167
-	 */
168
-	public static function logException( $app, \Exception $ex, $level = \OCP\Util::FATAL ) {
169
-		\OC::$server->getLogger()->logException($ex, ['app' => $app]);
170
-	}
171
-
172
-	/**
173
-	 * check if sharing is disabled for the current user
174
-	 *
175
-	 * @return boolean
176
-	 * @since 7.0.0
177
-	 * @deprecated 9.1.0 Use \OC::$server->getShareManager()->sharingDisabledForUser
178
-	 */
179
-	public static function isSharingDisabledForUser() {
180
-		if (self::$shareManager === null) {
181
-			self::$shareManager = \OC::$server->getShareManager();
182
-		}
183
-
184
-		$user = \OC::$server->getUserSession()->getUser();
185
-		if ($user !== null) {
186
-			$user = $user->getUID();
187
-		}
188
-
189
-		return self::$shareManager->sharingDisabledForUser($user);
190
-	}
191
-
192
-	/**
193
-	 * get l10n object
194
-	 * @param string $application
195
-	 * @param string|null $language
196
-	 * @return \OCP\IL10N
197
-	 * @since 6.0.0 - parameter $language was added in 8.0.0
198
-	 */
199
-	public static function getL10N($application, $language = null) {
200
-		return \OC::$server->getL10N($application, $language);
201
-	}
202
-
203
-	/**
204
-	 * add a css file
205
-	 * @param string $application
206
-	 * @param string $file
207
-	 * @since 4.0.0
208
-	 */
209
-	public static function addStyle( $application, $file = null ) {
210
-		\OC_Util::addStyle( $application, $file );
211
-	}
212
-
213
-	/**
214
-	 * add a javascript file
215
-	 * @param string $application
216
-	 * @param string $file
217
-	 * @since 4.0.0
218
-	 */
219
-	public static function addScript( $application, $file = null ) {
220
-		\OC_Util::addScript( $application, $file );
221
-	}
222
-
223
-	/**
224
-	 * Add a translation JS file
225
-	 * @param string $application application id
226
-	 * @param string $languageCode language code, defaults to the current locale
227
-	 * @since 8.0.0
228
-	 */
229
-	public static function addTranslations($application, $languageCode = null) {
230
-		\OC_Util::addTranslations($application, $languageCode);
231
-	}
232
-
233
-	/**
234
-	 * Add a custom element to the header
235
-	 * If $text is null then the element will be written as empty element.
236
-	 * So use "" to get a closing tag.
237
-	 * @param string $tag tag name of the element
238
-	 * @param array $attributes array of attributes for the element
239
-	 * @param string $text the text content for the element
240
-	 * @since 4.0.0
241
-	 */
242
-	public static function addHeader($tag, $attributes, $text=null) {
243
-		\OC_Util::addHeader($tag, $attributes, $text);
244
-	}
245
-
246
-	/**
247
-	 * formats a timestamp in the "right" way
248
-	 * @param int $timestamp $timestamp
249
-	 * @param bool $dateOnly option to omit time from the result
250
-	 * @param DateTimeZone|string $timeZone where the given timestamp shall be converted to
251
-	 * @return string timestamp
252
-	 *
253
-	 * @deprecated 8.0.0 Use \OC::$server->query('DateTimeFormatter') instead
254
-	 * @since 4.0.0
255
-	 */
256
-	public static function formatDate($timestamp, $dateOnly=false, $timeZone = null) {
257
-		return(\OC_Util::formatDate($timestamp, $dateOnly, $timeZone));
258
-	}
259
-
260
-	/**
261
-	 * check if some encrypted files are stored
262
-	 * @return bool
263
-	 *
264
-	 * @deprecated 8.1.0 No longer required
265
-	 * @since 6.0.0
266
-	 */
267
-	public static function encryptedFiles() {
268
-		return false;
269
-	}
270
-
271
-	/**
272
-	 * Creates an absolute url to the given app and file.
273
-	 * @param string $app app
274
-	 * @param string $file file
275
-	 * @param array $args array with param=>value, will be appended to the returned url
276
-	 * 	The value of $args will be urlencoded
277
-	 * @return string the url
278
-	 * @since 4.0.0 - parameter $args was added in 4.5.0
279
-	 */
280
-	public static function linkToAbsolute( $app, $file, $args = array() ) {
281
-		$urlGenerator = \OC::$server->getURLGenerator();
282
-		return $urlGenerator->getAbsoluteURL(
283
-			$urlGenerator->linkTo($app, $file, $args)
284
-		);
285
-	}
286
-
287
-	/**
288
-	 * Creates an absolute url for remote use.
289
-	 * @param string $service id
290
-	 * @return string the url
291
-	 * @since 4.0.0
292
-	 */
293
-	public static function linkToRemote( $service ) {
294
-		$urlGenerator = \OC::$server->getURLGenerator();
295
-		$remoteBase = $urlGenerator->linkTo('', 'remote.php') . '/' . $service;
296
-		return $urlGenerator->getAbsoluteURL(
297
-			$remoteBase . (($service[strlen($service) - 1] != '/') ? '/' : '')
298
-		);
299
-	}
300
-
301
-	/**
302
-	 * Creates an absolute url for public use
303
-	 * @param string $service id
304
-	 * @return string the url
305
-	 * @since 4.5.0
306
-	 */
307
-	public static function linkToPublic($service) {
308
-		return \OC_Helper::linkToPublic($service);
309
-	}
310
-
311
-	/**
312
-	 * Creates an url using a defined route
313
-	 * @param string $route
314
-	 * @param array $parameters
315
-	 * @internal param array $args with param=>value, will be appended to the returned url
316
-	 * @return string the url
317
-	 * @deprecated 8.1.0 Use \OC::$server->getURLGenerator()->linkToRoute($route, $parameters)
318
-	 * @since 5.0.0
319
-	 */
320
-	public static function linkToRoute( $route, $parameters = array() ) {
321
-		return \OC::$server->getURLGenerator()->linkToRoute($route, $parameters);
322
-	}
323
-
324
-	/**
325
-	 * Creates an url to the given app and file
326
-	 * @param string $app app
327
-	 * @param string $file file
328
-	 * @param array $args array with param=>value, will be appended to the returned url
329
-	 * 	The value of $args will be urlencoded
330
-	 * @return string the url
331
-	 * @deprecated 8.1.0 Use \OC::$server->getURLGenerator()->linkTo($app, $file, $args)
332
-	 * @since 4.0.0 - parameter $args was added in 4.5.0
333
-	 */
334
-	public static function linkTo( $app, $file, $args = array() ) {
335
-		return \OC::$server->getURLGenerator()->linkTo($app, $file, $args);
336
-	}
337
-
338
-	/**
339
-	 * Returns the server host, even if the website uses one or more reverse proxy
340
-	 * @return string the server host
341
-	 * @deprecated 8.1.0 Use \OCP\IRequest::getServerHost
342
-	 * @since 4.0.0
343
-	 */
344
-	public static function getServerHost() {
345
-		return \OC::$server->getRequest()->getServerHost();
346
-	}
347
-
348
-	/**
349
-	 * Returns the server host name without an eventual port number
350
-	 * @return string the server hostname
351
-	 * @since 5.0.0
352
-	 */
353
-	public static function getServerHostName() {
354
-		$host_name = self::getServerHost();
355
-		// strip away port number (if existing)
356
-		$colon_pos = strpos($host_name, ':');
357
-		if ($colon_pos != FALSE) {
358
-			$host_name = substr($host_name, 0, $colon_pos);
359
-		}
360
-		return $host_name;
361
-	}
362
-
363
-	/**
364
-	 * Returns the default email address
365
-	 * @param string $user_part the user part of the address
366
-	 * @return string the default email address
367
-	 *
368
-	 * Assembles a default email address (using the server hostname
369
-	 * and the given user part, and returns it
370
-	 * Example: when given lostpassword-noreply as $user_part param,
371
-	 *     and is currently accessed via http(s)://example.com/,
372
-	 *     it would return '[email protected]'
373
-	 *
374
-	 * If the configuration value 'mail_from_address' is set in
375
-	 * config.php, this value will override the $user_part that
376
-	 * is passed to this function
377
-	 * @since 5.0.0
378
-	 */
379
-	public static function getDefaultEmailAddress($user_part) {
380
-		$config = \OC::$server->getConfig();
381
-		$user_part = $config->getSystemValue('mail_from_address', $user_part);
382
-		$host_name = self::getServerHostName();
383
-		$host_name = $config->getSystemValue('mail_domain', $host_name);
384
-		$defaultEmailAddress = $user_part.'@'.$host_name;
385
-
386
-		$mailer = \OC::$server->getMailer();
387
-		if ($mailer->validateMailAddress($defaultEmailAddress)) {
388
-			return $defaultEmailAddress;
389
-		}
390
-
391
-		// in case we cannot build a valid email address from the hostname let's fallback to 'localhost.localdomain'
392
-		return $user_part.'@localhost.localdomain';
393
-	}
394
-
395
-	/**
396
-	 * Returns the server protocol. It respects reverse proxy servers and load balancers
397
-	 * @return string the server protocol
398
-	 * @deprecated 8.1.0 Use \OCP\IRequest::getServerProtocol
399
-	 * @since 4.5.0
400
-	 */
401
-	public static function getServerProtocol() {
402
-		return \OC::$server->getRequest()->getServerProtocol();
403
-	}
404
-
405
-	/**
406
-	 * Returns the request uri, even if the website uses one or more reverse proxies
407
-	 * @return string the request uri
408
-	 * @deprecated 8.1.0 Use \OCP\IRequest::getRequestUri
409
-	 * @since 5.0.0
410
-	 */
411
-	public static function getRequestUri() {
412
-		return \OC::$server->getRequest()->getRequestUri();
413
-	}
414
-
415
-	/**
416
-	 * Returns the script name, even if the website uses one or more reverse proxies
417
-	 * @return string the script name
418
-	 * @deprecated 8.1.0 Use \OCP\IRequest::getScriptName
419
-	 * @since 5.0.0
420
-	 */
421
-	public static function getScriptName() {
422
-		return \OC::$server->getRequest()->getScriptName();
423
-	}
424
-
425
-	/**
426
-	 * Creates path to an image
427
-	 * @param string $app app
428
-	 * @param string $image image name
429
-	 * @return string the url
430
-	 * @deprecated 8.1.0 Use \OC::$server->getURLGenerator()->imagePath($app, $image)
431
-	 * @since 4.0.0
432
-	 */
433
-	public static function imagePath( $app, $image ) {
434
-		return \OC::$server->getURLGenerator()->imagePath($app, $image);
435
-	}
436
-
437
-	/**
438
-	 * Make a human file size (2048 to 2 kB)
439
-	 * @param int $bytes file size in bytes
440
-	 * @return string a human readable file size
441
-	 * @since 4.0.0
442
-	 */
443
-	public static function humanFileSize( $bytes ) {
444
-		return(\OC_Helper::humanFileSize( $bytes ));
445
-	}
446
-
447
-	/**
448
-	 * Make a computer file size (2 kB to 2048)
449
-	 * @param string $str file size in a fancy format
450
-	 * @return int a file size in bytes
451
-	 *
452
-	 * Inspired by: http://www.php.net/manual/en/function.filesize.php#92418
453
-	 * @since 4.0.0
454
-	 */
455
-	public static function computerFileSize( $str ) {
456
-		return(\OC_Helper::computerFileSize( $str ));
457
-	}
458
-
459
-	/**
460
-	 * connects a function to a hook
461
-	 *
462
-	 * @param string $signalClass class name of emitter
463
-	 * @param string $signalName name of signal
464
-	 * @param string|object $slotClass class name of slot
465
-	 * @param string $slotName name of slot
466
-	 * @return bool
467
-	 *
468
-	 * This function makes it very easy to connect to use hooks.
469
-	 *
470
-	 * TODO: write example
471
-	 * @since 4.0.0
472
-	 */
473
-	static public function connectHook($signalClass, $signalName, $slotClass, $slotName ) {
474
-		return(\OC_Hook::connect($signalClass, $signalName, $slotClass, $slotName ));
475
-	}
476
-
477
-	/**
478
-	 * Emits a signal. To get data from the slot use references!
479
-	 * @param string $signalclass class name of emitter
480
-	 * @param string $signalname name of signal
481
-	 * @param array $params default: array() array with additional data
482
-	 * @return bool true if slots exists or false if not
483
-	 *
484
-	 * TODO: write example
485
-	 * @since 4.0.0
486
-	 */
487
-	static public function emitHook( $signalclass, $signalname, $params = array()) {
488
-		return(\OC_Hook::emit( $signalclass, $signalname, $params ));
489
-	}
490
-
491
-	/**
492
-	 * Cached encrypted CSRF token. Some static unit-tests of ownCloud compare
493
-	 * multiple OC_Template elements which invoke `callRegister`. If the value
494
-	 * would not be cached these unit-tests would fail.
495
-	 * @var string
496
-	 */
497
-	private static $token = '';
498
-
499
-	/**
500
-	 * Register an get/post call. This is important to prevent CSRF attacks
501
-	 * @since 4.5.0
502
-	 */
503
-	public static function callRegister() {
504
-		if(self::$token === '') {
505
-			self::$token = \OC::$server->getCsrfTokenManager()->getToken()->getEncryptedValue();
506
-		}
507
-		return self::$token;
508
-	}
509
-
510
-	/**
511
-	 * Check an ajax get/post call if the request token is valid. exit if not.
512
-	 * @since 4.5.0
513
-	 * @deprecated 9.0.0 Use annotations based on the app framework.
514
-	 */
515
-	public static function callCheck() {
516
-		if(!\OC::$server->getRequest()->passesStrictCookieCheck()) {
517
-			header('Location: '.\OC::$WEBROOT);
518
-			exit();
519
-		}
520
-
521
-		if (!(\OC::$server->getRequest()->passesCSRFCheck())) {
522
-			exit();
523
-		}
524
-	}
525
-
526
-	/**
527
-	 * Used to sanitize HTML
528
-	 *
529
-	 * This function is used to sanitize HTML and should be applied on any
530
-	 * string or array of strings before displaying it on a web page.
531
-	 *
532
-	 * @param string|array $value
533
-	 * @return string|array an array of sanitized strings or a single sanitized string, depends on the input parameter.
534
-	 * @since 4.5.0
535
-	 */
536
-	public static function sanitizeHTML($value) {
537
-		return \OC_Util::sanitizeHTML($value);
538
-	}
539
-
540
-	/**
541
-	 * Public function to encode url parameters
542
-	 *
543
-	 * This function is used to encode path to file before output.
544
-	 * Encoding is done according to RFC 3986 with one exception:
545
-	 * Character '/' is preserved as is.
546
-	 *
547
-	 * @param string $component part of URI to encode
548
-	 * @return string
549
-	 * @since 6.0.0
550
-	 */
551
-	public static function encodePath($component) {
552
-		return(\OC_Util::encodePath($component));
553
-	}
554
-
555
-	/**
556
-	 * Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is.
557
-	 *
558
-	 * @param array $input The array to work on
559
-	 * @param int $case Either MB_CASE_UPPER or MB_CASE_LOWER (default)
560
-	 * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8
561
-	 * @return array
562
-	 * @since 4.5.0
563
-	 */
564
-	public static function mb_array_change_key_case($input, $case = MB_CASE_LOWER, $encoding = 'UTF-8') {
565
-		return(\OC_Helper::mb_array_change_key_case($input, $case, $encoding));
566
-	}
567
-
568
-	/**
569
-	 * replaces a copy of string delimited by the start and (optionally) length parameters with the string given in replacement.
570
-	 *
571
-	 * @param string $string The input string. Opposite to the PHP build-in function does not accept an array.
572
-	 * @param string $replacement The replacement string.
573
-	 * @param int $start If start is positive, the replacing will begin at the start'th offset into string. If start is negative, the replacing will begin at the start'th character from the end of string.
574
-	 * @param int $length Length of the part to be replaced
575
-	 * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8
576
-	 * @return string
577
-	 * @since 4.5.0
578
-	 * @deprecated 8.2.0 Use substr_replace() instead.
579
-	 */
580
-	public static function mb_substr_replace($string, $replacement, $start, $length = null, $encoding = 'UTF-8') {
581
-		return substr_replace($string, $replacement, $start, $length);
582
-	}
583
-
584
-	/**
585
-	 * Replace all occurrences of the search string with the replacement string
586
-	 *
587
-	 * @param string $search The value being searched for, otherwise known as the needle. String.
588
-	 * @param string $replace The replacement string.
589
-	 * @param string $subject The string or array being searched and replaced on, otherwise known as the haystack.
590
-	 * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8
591
-	 * @param int $count If passed, this will be set to the number of replacements performed.
592
-	 * @return string
593
-	 * @since 4.5.0
594
-	 * @deprecated 8.2.0 Use str_replace() instead.
595
-	 */
596
-	public static function mb_str_replace($search, $replace, $subject, $encoding = 'UTF-8', &$count = null) {
597
-		return str_replace($search, $replace, $subject, $count);
598
-	}
599
-
600
-	/**
601
-	 * performs a search in a nested array
602
-	 *
603
-	 * @param array $haystack the array to be searched
604
-	 * @param string $needle the search string
605
-	 * @param int $index optional, only search this key name
606
-	 * @return mixed the key of the matching field, otherwise false
607
-	 * @since 4.5.0
608
-	 */
609
-	public static function recursiveArraySearch($haystack, $needle, $index = null) {
610
-		return(\OC_Helper::recursiveArraySearch($haystack, $needle, $index));
611
-	}
612
-
613
-	/**
614
-	 * calculates the maximum upload size respecting system settings, free space and user quota
615
-	 *
616
-	 * @param string $dir the current folder where the user currently operates
617
-	 * @param int $free the number of bytes free on the storage holding $dir, if not set this will be received from the storage directly
618
-	 * @return int number of bytes representing
619
-	 * @since 5.0.0
620
-	 */
621
-	public static function maxUploadFilesize($dir, $free = null) {
622
-		return \OC_Helper::maxUploadFilesize($dir, $free);
623
-	}
624
-
625
-	/**
626
-	 * Calculate free space left within user quota
627
-	 * @param string $dir the current folder where the user currently operates
628
-	 * @return int number of bytes representing
629
-	 * @since 7.0.0
630
-	 */
631
-	public static function freeSpace($dir) {
632
-		return \OC_Helper::freeSpace($dir);
633
-	}
634
-
635
-	/**
636
-	 * Calculate PHP upload limit
637
-	 *
638
-	 * @return int number of bytes representing
639
-	 * @since 7.0.0
640
-	 */
641
-	public static function uploadLimit() {
642
-		return \OC_Helper::uploadLimit();
643
-	}
644
-
645
-	/**
646
-	 * Returns whether the given file name is valid
647
-	 * @param string $file file name to check
648
-	 * @return bool true if the file name is valid, false otherwise
649
-	 * @deprecated 8.1.0 use \OC\Files\View::verifyPath()
650
-	 * @since 7.0.0
651
-	 */
652
-	public static function isValidFileName($file) {
653
-		return \OC_Util::isValidFileName($file);
654
-	}
655
-
656
-	/**
657
-	 * Generates a cryptographic secure pseudo-random string
658
-	 * @param int $length of the random string
659
-	 * @return string
660
-	 * @deprecated 8.0.0 Use \OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate($length); instead
661
-	 * @since 7.0.0
662
-	 */
663
-	public static function generateRandomBytes($length = 30) {
664
-		return \OC::$server->getSecureRandom()->generate($length, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS);
665
-	}
666
-
667
-	/**
668
-	 * Compare two strings to provide a natural sort
669
-	 * @param string $a first string to compare
670
-	 * @param string $b second string to compare
671
-	 * @return -1 if $b comes before $a, 1 if $a comes before $b
672
-	 * or 0 if the strings are identical
673
-	 * @since 7.0.0
674
-	 */
675
-	public static function naturalSortCompare($a, $b) {
676
-		return \OC\NaturalSort::getInstance()->compare($a, $b);
677
-	}
678
-
679
-	/**
680
-	 * check if a password is required for each public link
681
-	 * @return boolean
682
-	 * @since 7.0.0
683
-	 */
684
-	public static function isPublicLinkPasswordRequired() {
685
-		return \OC_Util::isPublicLinkPasswordRequired();
686
-	}
687
-
688
-	/**
689
-	 * check if share API enforces a default expire date
690
-	 * @return boolean
691
-	 * @since 8.0.0
692
-	 */
693
-	public static function isDefaultExpireDateEnforced() {
694
-		return \OC_Util::isDefaultExpireDateEnforced();
695
-	}
696
-
697
-	protected static $needUpgradeCache = null;
698
-
699
-	/**
700
-	 * Checks whether the current version needs upgrade.
701
-	 *
702
-	 * @return bool true if upgrade is needed, false otherwise
703
-	 * @since 7.0.0
704
-	 */
705
-	public static function needUpgrade() {
706
-		if (!isset(self::$needUpgradeCache)) {
707
-			self::$needUpgradeCache=\OC_Util::needUpgrade(\OC::$server->getSystemConfig());
708
-		}		
709
-		return self::$needUpgradeCache;
710
-	}
88
+    /**
89
+     * Get current update channel
90
+     * @return string
91
+     * @since 8.1.0
92
+     */
93
+    public static function getChannel() {
94
+        return \OC_Util::getChannel();
95
+    }
96
+
97
+    /**
98
+     * send an email
99
+     * @param string $toaddress
100
+     * @param string $toname
101
+     * @param string $subject
102
+     * @param string $mailtext
103
+     * @param string $fromaddress
104
+     * @param string $fromname
105
+     * @param int $html
106
+     * @param string $altbody
107
+     * @param string $ccaddress
108
+     * @param string $ccname
109
+     * @param string $bcc
110
+     * @deprecated 8.1.0 Use \OCP\Mail\IMailer instead
111
+     * @since 4.0.0
112
+     */
113
+    public static function sendMail($toaddress, $toname, $subject, $mailtext, $fromaddress, $fromname,
114
+        $html = 0, $altbody = '', $ccaddress = '', $ccname = '', $bcc = '') {
115
+        $mailer = \OC::$server->getMailer();
116
+        $message = $mailer->createMessage();
117
+        $message->setTo([$toaddress => $toname]);
118
+        $message->setSubject($subject);
119
+        $message->setPlainBody($mailtext);
120
+        $message->setFrom([$fromaddress => $fromname]);
121
+        if($html === 1) {
122
+            $message->setHTMLBody($altbody);
123
+        }
124
+
125
+        if($altbody === '') {
126
+            $message->setHTMLBody($mailtext);
127
+            $message->setPlainBody('');
128
+        } else {
129
+            $message->setHtmlBody($mailtext);
130
+            $message->setPlainBody($altbody);
131
+        }
132
+
133
+        if(!empty($ccaddress)) {
134
+            if(!empty($ccname)) {
135
+                $message->setCc([$ccaddress => $ccname]);
136
+            } else {
137
+                $message->setCc([$ccaddress]);
138
+            }
139
+        }
140
+        if(!empty($bcc)) {
141
+            $message->setBcc([$bcc]);
142
+        }
143
+
144
+        $mailer->send($message);
145
+    }
146
+
147
+    /**
148
+     * write a message in the log
149
+     * @param string $app
150
+     * @param string $message
151
+     * @param int $level
152
+     * @since 4.0.0
153
+     * @deprecated 13.0.0 use log of \OCP\ILogger
154
+     */
155
+    public static function writeLog( $app, $message, $level ) {
156
+        $context = ['app' => $app];
157
+        \OC::$server->getLogger()->log($level, $message, $context);
158
+    }
159
+
160
+    /**
161
+     * write exception into the log
162
+     * @param string $app app name
163
+     * @param \Exception $ex exception to log
164
+     * @param int $level log level, defaults to \OCP\Util::FATAL
165
+     * @since ....0.0 - parameter $level was added in 7.0.0
166
+     * @deprecated 8.2.0 use logException of \OCP\ILogger
167
+     */
168
+    public static function logException( $app, \Exception $ex, $level = \OCP\Util::FATAL ) {
169
+        \OC::$server->getLogger()->logException($ex, ['app' => $app]);
170
+    }
171
+
172
+    /**
173
+     * check if sharing is disabled for the current user
174
+     *
175
+     * @return boolean
176
+     * @since 7.0.0
177
+     * @deprecated 9.1.0 Use \OC::$server->getShareManager()->sharingDisabledForUser
178
+     */
179
+    public static function isSharingDisabledForUser() {
180
+        if (self::$shareManager === null) {
181
+            self::$shareManager = \OC::$server->getShareManager();
182
+        }
183
+
184
+        $user = \OC::$server->getUserSession()->getUser();
185
+        if ($user !== null) {
186
+            $user = $user->getUID();
187
+        }
188
+
189
+        return self::$shareManager->sharingDisabledForUser($user);
190
+    }
191
+
192
+    /**
193
+     * get l10n object
194
+     * @param string $application
195
+     * @param string|null $language
196
+     * @return \OCP\IL10N
197
+     * @since 6.0.0 - parameter $language was added in 8.0.0
198
+     */
199
+    public static function getL10N($application, $language = null) {
200
+        return \OC::$server->getL10N($application, $language);
201
+    }
202
+
203
+    /**
204
+     * add a css file
205
+     * @param string $application
206
+     * @param string $file
207
+     * @since 4.0.0
208
+     */
209
+    public static function addStyle( $application, $file = null ) {
210
+        \OC_Util::addStyle( $application, $file );
211
+    }
212
+
213
+    /**
214
+     * add a javascript file
215
+     * @param string $application
216
+     * @param string $file
217
+     * @since 4.0.0
218
+     */
219
+    public static function addScript( $application, $file = null ) {
220
+        \OC_Util::addScript( $application, $file );
221
+    }
222
+
223
+    /**
224
+     * Add a translation JS file
225
+     * @param string $application application id
226
+     * @param string $languageCode language code, defaults to the current locale
227
+     * @since 8.0.0
228
+     */
229
+    public static function addTranslations($application, $languageCode = null) {
230
+        \OC_Util::addTranslations($application, $languageCode);
231
+    }
232
+
233
+    /**
234
+     * Add a custom element to the header
235
+     * If $text is null then the element will be written as empty element.
236
+     * So use "" to get a closing tag.
237
+     * @param string $tag tag name of the element
238
+     * @param array $attributes array of attributes for the element
239
+     * @param string $text the text content for the element
240
+     * @since 4.0.0
241
+     */
242
+    public static function addHeader($tag, $attributes, $text=null) {
243
+        \OC_Util::addHeader($tag, $attributes, $text);
244
+    }
245
+
246
+    /**
247
+     * formats a timestamp in the "right" way
248
+     * @param int $timestamp $timestamp
249
+     * @param bool $dateOnly option to omit time from the result
250
+     * @param DateTimeZone|string $timeZone where the given timestamp shall be converted to
251
+     * @return string timestamp
252
+     *
253
+     * @deprecated 8.0.0 Use \OC::$server->query('DateTimeFormatter') instead
254
+     * @since 4.0.0
255
+     */
256
+    public static function formatDate($timestamp, $dateOnly=false, $timeZone = null) {
257
+        return(\OC_Util::formatDate($timestamp, $dateOnly, $timeZone));
258
+    }
259
+
260
+    /**
261
+     * check if some encrypted files are stored
262
+     * @return bool
263
+     *
264
+     * @deprecated 8.1.0 No longer required
265
+     * @since 6.0.0
266
+     */
267
+    public static function encryptedFiles() {
268
+        return false;
269
+    }
270
+
271
+    /**
272
+     * Creates an absolute url to the given app and file.
273
+     * @param string $app app
274
+     * @param string $file file
275
+     * @param array $args array with param=>value, will be appended to the returned url
276
+     * 	The value of $args will be urlencoded
277
+     * @return string the url
278
+     * @since 4.0.0 - parameter $args was added in 4.5.0
279
+     */
280
+    public static function linkToAbsolute( $app, $file, $args = array() ) {
281
+        $urlGenerator = \OC::$server->getURLGenerator();
282
+        return $urlGenerator->getAbsoluteURL(
283
+            $urlGenerator->linkTo($app, $file, $args)
284
+        );
285
+    }
286
+
287
+    /**
288
+     * Creates an absolute url for remote use.
289
+     * @param string $service id
290
+     * @return string the url
291
+     * @since 4.0.0
292
+     */
293
+    public static function linkToRemote( $service ) {
294
+        $urlGenerator = \OC::$server->getURLGenerator();
295
+        $remoteBase = $urlGenerator->linkTo('', 'remote.php') . '/' . $service;
296
+        return $urlGenerator->getAbsoluteURL(
297
+            $remoteBase . (($service[strlen($service) - 1] != '/') ? '/' : '')
298
+        );
299
+    }
300
+
301
+    /**
302
+     * Creates an absolute url for public use
303
+     * @param string $service id
304
+     * @return string the url
305
+     * @since 4.5.0
306
+     */
307
+    public static function linkToPublic($service) {
308
+        return \OC_Helper::linkToPublic($service);
309
+    }
310
+
311
+    /**
312
+     * Creates an url using a defined route
313
+     * @param string $route
314
+     * @param array $parameters
315
+     * @internal param array $args with param=>value, will be appended to the returned url
316
+     * @return string the url
317
+     * @deprecated 8.1.0 Use \OC::$server->getURLGenerator()->linkToRoute($route, $parameters)
318
+     * @since 5.0.0
319
+     */
320
+    public static function linkToRoute( $route, $parameters = array() ) {
321
+        return \OC::$server->getURLGenerator()->linkToRoute($route, $parameters);
322
+    }
323
+
324
+    /**
325
+     * Creates an url to the given app and file
326
+     * @param string $app app
327
+     * @param string $file file
328
+     * @param array $args array with param=>value, will be appended to the returned url
329
+     * 	The value of $args will be urlencoded
330
+     * @return string the url
331
+     * @deprecated 8.1.0 Use \OC::$server->getURLGenerator()->linkTo($app, $file, $args)
332
+     * @since 4.0.0 - parameter $args was added in 4.5.0
333
+     */
334
+    public static function linkTo( $app, $file, $args = array() ) {
335
+        return \OC::$server->getURLGenerator()->linkTo($app, $file, $args);
336
+    }
337
+
338
+    /**
339
+     * Returns the server host, even if the website uses one or more reverse proxy
340
+     * @return string the server host
341
+     * @deprecated 8.1.0 Use \OCP\IRequest::getServerHost
342
+     * @since 4.0.0
343
+     */
344
+    public static function getServerHost() {
345
+        return \OC::$server->getRequest()->getServerHost();
346
+    }
347
+
348
+    /**
349
+     * Returns the server host name without an eventual port number
350
+     * @return string the server hostname
351
+     * @since 5.0.0
352
+     */
353
+    public static function getServerHostName() {
354
+        $host_name = self::getServerHost();
355
+        // strip away port number (if existing)
356
+        $colon_pos = strpos($host_name, ':');
357
+        if ($colon_pos != FALSE) {
358
+            $host_name = substr($host_name, 0, $colon_pos);
359
+        }
360
+        return $host_name;
361
+    }
362
+
363
+    /**
364
+     * Returns the default email address
365
+     * @param string $user_part the user part of the address
366
+     * @return string the default email address
367
+     *
368
+     * Assembles a default email address (using the server hostname
369
+     * and the given user part, and returns it
370
+     * Example: when given lostpassword-noreply as $user_part param,
371
+     *     and is currently accessed via http(s)://example.com/,
372
+     *     it would return '[email protected]'
373
+     *
374
+     * If the configuration value 'mail_from_address' is set in
375
+     * config.php, this value will override the $user_part that
376
+     * is passed to this function
377
+     * @since 5.0.0
378
+     */
379
+    public static function getDefaultEmailAddress($user_part) {
380
+        $config = \OC::$server->getConfig();
381
+        $user_part = $config->getSystemValue('mail_from_address', $user_part);
382
+        $host_name = self::getServerHostName();
383
+        $host_name = $config->getSystemValue('mail_domain', $host_name);
384
+        $defaultEmailAddress = $user_part.'@'.$host_name;
385
+
386
+        $mailer = \OC::$server->getMailer();
387
+        if ($mailer->validateMailAddress($defaultEmailAddress)) {
388
+            return $defaultEmailAddress;
389
+        }
390
+
391
+        // in case we cannot build a valid email address from the hostname let's fallback to 'localhost.localdomain'
392
+        return $user_part.'@localhost.localdomain';
393
+    }
394
+
395
+    /**
396
+     * Returns the server protocol. It respects reverse proxy servers and load balancers
397
+     * @return string the server protocol
398
+     * @deprecated 8.1.0 Use \OCP\IRequest::getServerProtocol
399
+     * @since 4.5.0
400
+     */
401
+    public static function getServerProtocol() {
402
+        return \OC::$server->getRequest()->getServerProtocol();
403
+    }
404
+
405
+    /**
406
+     * Returns the request uri, even if the website uses one or more reverse proxies
407
+     * @return string the request uri
408
+     * @deprecated 8.1.0 Use \OCP\IRequest::getRequestUri
409
+     * @since 5.0.0
410
+     */
411
+    public static function getRequestUri() {
412
+        return \OC::$server->getRequest()->getRequestUri();
413
+    }
414
+
415
+    /**
416
+     * Returns the script name, even if the website uses one or more reverse proxies
417
+     * @return string the script name
418
+     * @deprecated 8.1.0 Use \OCP\IRequest::getScriptName
419
+     * @since 5.0.0
420
+     */
421
+    public static function getScriptName() {
422
+        return \OC::$server->getRequest()->getScriptName();
423
+    }
424
+
425
+    /**
426
+     * Creates path to an image
427
+     * @param string $app app
428
+     * @param string $image image name
429
+     * @return string the url
430
+     * @deprecated 8.1.0 Use \OC::$server->getURLGenerator()->imagePath($app, $image)
431
+     * @since 4.0.0
432
+     */
433
+    public static function imagePath( $app, $image ) {
434
+        return \OC::$server->getURLGenerator()->imagePath($app, $image);
435
+    }
436
+
437
+    /**
438
+     * Make a human file size (2048 to 2 kB)
439
+     * @param int $bytes file size in bytes
440
+     * @return string a human readable file size
441
+     * @since 4.0.0
442
+     */
443
+    public static function humanFileSize( $bytes ) {
444
+        return(\OC_Helper::humanFileSize( $bytes ));
445
+    }
446
+
447
+    /**
448
+     * Make a computer file size (2 kB to 2048)
449
+     * @param string $str file size in a fancy format
450
+     * @return int a file size in bytes
451
+     *
452
+     * Inspired by: http://www.php.net/manual/en/function.filesize.php#92418
453
+     * @since 4.0.0
454
+     */
455
+    public static function computerFileSize( $str ) {
456
+        return(\OC_Helper::computerFileSize( $str ));
457
+    }
458
+
459
+    /**
460
+     * connects a function to a hook
461
+     *
462
+     * @param string $signalClass class name of emitter
463
+     * @param string $signalName name of signal
464
+     * @param string|object $slotClass class name of slot
465
+     * @param string $slotName name of slot
466
+     * @return bool
467
+     *
468
+     * This function makes it very easy to connect to use hooks.
469
+     *
470
+     * TODO: write example
471
+     * @since 4.0.0
472
+     */
473
+    static public function connectHook($signalClass, $signalName, $slotClass, $slotName ) {
474
+        return(\OC_Hook::connect($signalClass, $signalName, $slotClass, $slotName ));
475
+    }
476
+
477
+    /**
478
+     * Emits a signal. To get data from the slot use references!
479
+     * @param string $signalclass class name of emitter
480
+     * @param string $signalname name of signal
481
+     * @param array $params default: array() array with additional data
482
+     * @return bool true if slots exists or false if not
483
+     *
484
+     * TODO: write example
485
+     * @since 4.0.0
486
+     */
487
+    static public function emitHook( $signalclass, $signalname, $params = array()) {
488
+        return(\OC_Hook::emit( $signalclass, $signalname, $params ));
489
+    }
490
+
491
+    /**
492
+     * Cached encrypted CSRF token. Some static unit-tests of ownCloud compare
493
+     * multiple OC_Template elements which invoke `callRegister`. If the value
494
+     * would not be cached these unit-tests would fail.
495
+     * @var string
496
+     */
497
+    private static $token = '';
498
+
499
+    /**
500
+     * Register an get/post call. This is important to prevent CSRF attacks
501
+     * @since 4.5.0
502
+     */
503
+    public static function callRegister() {
504
+        if(self::$token === '') {
505
+            self::$token = \OC::$server->getCsrfTokenManager()->getToken()->getEncryptedValue();
506
+        }
507
+        return self::$token;
508
+    }
509
+
510
+    /**
511
+     * Check an ajax get/post call if the request token is valid. exit if not.
512
+     * @since 4.5.0
513
+     * @deprecated 9.0.0 Use annotations based on the app framework.
514
+     */
515
+    public static function callCheck() {
516
+        if(!\OC::$server->getRequest()->passesStrictCookieCheck()) {
517
+            header('Location: '.\OC::$WEBROOT);
518
+            exit();
519
+        }
520
+
521
+        if (!(\OC::$server->getRequest()->passesCSRFCheck())) {
522
+            exit();
523
+        }
524
+    }
525
+
526
+    /**
527
+     * Used to sanitize HTML
528
+     *
529
+     * This function is used to sanitize HTML and should be applied on any
530
+     * string or array of strings before displaying it on a web page.
531
+     *
532
+     * @param string|array $value
533
+     * @return string|array an array of sanitized strings or a single sanitized string, depends on the input parameter.
534
+     * @since 4.5.0
535
+     */
536
+    public static function sanitizeHTML($value) {
537
+        return \OC_Util::sanitizeHTML($value);
538
+    }
539
+
540
+    /**
541
+     * Public function to encode url parameters
542
+     *
543
+     * This function is used to encode path to file before output.
544
+     * Encoding is done according to RFC 3986 with one exception:
545
+     * Character '/' is preserved as is.
546
+     *
547
+     * @param string $component part of URI to encode
548
+     * @return string
549
+     * @since 6.0.0
550
+     */
551
+    public static function encodePath($component) {
552
+        return(\OC_Util::encodePath($component));
553
+    }
554
+
555
+    /**
556
+     * Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is.
557
+     *
558
+     * @param array $input The array to work on
559
+     * @param int $case Either MB_CASE_UPPER or MB_CASE_LOWER (default)
560
+     * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8
561
+     * @return array
562
+     * @since 4.5.0
563
+     */
564
+    public static function mb_array_change_key_case($input, $case = MB_CASE_LOWER, $encoding = 'UTF-8') {
565
+        return(\OC_Helper::mb_array_change_key_case($input, $case, $encoding));
566
+    }
567
+
568
+    /**
569
+     * replaces a copy of string delimited by the start and (optionally) length parameters with the string given in replacement.
570
+     *
571
+     * @param string $string The input string. Opposite to the PHP build-in function does not accept an array.
572
+     * @param string $replacement The replacement string.
573
+     * @param int $start If start is positive, the replacing will begin at the start'th offset into string. If start is negative, the replacing will begin at the start'th character from the end of string.
574
+     * @param int $length Length of the part to be replaced
575
+     * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8
576
+     * @return string
577
+     * @since 4.5.0
578
+     * @deprecated 8.2.0 Use substr_replace() instead.
579
+     */
580
+    public static function mb_substr_replace($string, $replacement, $start, $length = null, $encoding = 'UTF-8') {
581
+        return substr_replace($string, $replacement, $start, $length);
582
+    }
583
+
584
+    /**
585
+     * Replace all occurrences of the search string with the replacement string
586
+     *
587
+     * @param string $search The value being searched for, otherwise known as the needle. String.
588
+     * @param string $replace The replacement string.
589
+     * @param string $subject The string or array being searched and replaced on, otherwise known as the haystack.
590
+     * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8
591
+     * @param int $count If passed, this will be set to the number of replacements performed.
592
+     * @return string
593
+     * @since 4.5.0
594
+     * @deprecated 8.2.0 Use str_replace() instead.
595
+     */
596
+    public static function mb_str_replace($search, $replace, $subject, $encoding = 'UTF-8', &$count = null) {
597
+        return str_replace($search, $replace, $subject, $count);
598
+    }
599
+
600
+    /**
601
+     * performs a search in a nested array
602
+     *
603
+     * @param array $haystack the array to be searched
604
+     * @param string $needle the search string
605
+     * @param int $index optional, only search this key name
606
+     * @return mixed the key of the matching field, otherwise false
607
+     * @since 4.5.0
608
+     */
609
+    public static function recursiveArraySearch($haystack, $needle, $index = null) {
610
+        return(\OC_Helper::recursiveArraySearch($haystack, $needle, $index));
611
+    }
612
+
613
+    /**
614
+     * calculates the maximum upload size respecting system settings, free space and user quota
615
+     *
616
+     * @param string $dir the current folder where the user currently operates
617
+     * @param int $free the number of bytes free on the storage holding $dir, if not set this will be received from the storage directly
618
+     * @return int number of bytes representing
619
+     * @since 5.0.0
620
+     */
621
+    public static function maxUploadFilesize($dir, $free = null) {
622
+        return \OC_Helper::maxUploadFilesize($dir, $free);
623
+    }
624
+
625
+    /**
626
+     * Calculate free space left within user quota
627
+     * @param string $dir the current folder where the user currently operates
628
+     * @return int number of bytes representing
629
+     * @since 7.0.0
630
+     */
631
+    public static function freeSpace($dir) {
632
+        return \OC_Helper::freeSpace($dir);
633
+    }
634
+
635
+    /**
636
+     * Calculate PHP upload limit
637
+     *
638
+     * @return int number of bytes representing
639
+     * @since 7.0.0
640
+     */
641
+    public static function uploadLimit() {
642
+        return \OC_Helper::uploadLimit();
643
+    }
644
+
645
+    /**
646
+     * Returns whether the given file name is valid
647
+     * @param string $file file name to check
648
+     * @return bool true if the file name is valid, false otherwise
649
+     * @deprecated 8.1.0 use \OC\Files\View::verifyPath()
650
+     * @since 7.0.0
651
+     */
652
+    public static function isValidFileName($file) {
653
+        return \OC_Util::isValidFileName($file);
654
+    }
655
+
656
+    /**
657
+     * Generates a cryptographic secure pseudo-random string
658
+     * @param int $length of the random string
659
+     * @return string
660
+     * @deprecated 8.0.0 Use \OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate($length); instead
661
+     * @since 7.0.0
662
+     */
663
+    public static function generateRandomBytes($length = 30) {
664
+        return \OC::$server->getSecureRandom()->generate($length, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS);
665
+    }
666
+
667
+    /**
668
+     * Compare two strings to provide a natural sort
669
+     * @param string $a first string to compare
670
+     * @param string $b second string to compare
671
+     * @return -1 if $b comes before $a, 1 if $a comes before $b
672
+     * or 0 if the strings are identical
673
+     * @since 7.0.0
674
+     */
675
+    public static function naturalSortCompare($a, $b) {
676
+        return \OC\NaturalSort::getInstance()->compare($a, $b);
677
+    }
678
+
679
+    /**
680
+     * check if a password is required for each public link
681
+     * @return boolean
682
+     * @since 7.0.0
683
+     */
684
+    public static function isPublicLinkPasswordRequired() {
685
+        return \OC_Util::isPublicLinkPasswordRequired();
686
+    }
687
+
688
+    /**
689
+     * check if share API enforces a default expire date
690
+     * @return boolean
691
+     * @since 8.0.0
692
+     */
693
+    public static function isDefaultExpireDateEnforced() {
694
+        return \OC_Util::isDefaultExpireDateEnforced();
695
+    }
696
+
697
+    protected static $needUpgradeCache = null;
698
+
699
+    /**
700
+     * Checks whether the current version needs upgrade.
701
+     *
702
+     * @return bool true if upgrade is needed, false otherwise
703
+     * @since 7.0.0
704
+     */
705
+    public static function needUpgrade() {
706
+        if (!isset(self::$needUpgradeCache)) {
707
+            self::$needUpgradeCache=\OC_Util::needUpgrade(\OC::$server->getSystemConfig());
708
+        }		
709
+        return self::$needUpgradeCache;
710
+    }
711 711
 }
Please login to merge, or discard this patch.
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -58,11 +58,11 @@  discard block
 block discarded – undo
58 58
  */
59 59
 class Util {
60 60
 	// consts for Logging
61
-	const DEBUG=0;
62
-	const INFO=1;
63
-	const WARN=2;
64
-	const ERROR=3;
65
-	const FATAL=4;
61
+	const DEBUG = 0;
62
+	const INFO = 1;
63
+	const WARN = 2;
64
+	const ERROR = 3;
65
+	const FATAL = 4;
66 66
 
67 67
 	/** \OCP\Share\IManager */
68 68
 	private static $shareManager;
@@ -118,11 +118,11 @@  discard block
 block discarded – undo
118 118
 		$message->setSubject($subject);
119 119
 		$message->setPlainBody($mailtext);
120 120
 		$message->setFrom([$fromaddress => $fromname]);
121
-		if($html === 1) {
121
+		if ($html === 1) {
122 122
 			$message->setHTMLBody($altbody);
123 123
 		}
124 124
 
125
-		if($altbody === '') {
125
+		if ($altbody === '') {
126 126
 			$message->setHTMLBody($mailtext);
127 127
 			$message->setPlainBody('');
128 128
 		} else {
@@ -130,14 +130,14 @@  discard block
 block discarded – undo
130 130
 			$message->setPlainBody($altbody);
131 131
 		}
132 132
 
133
-		if(!empty($ccaddress)) {
134
-			if(!empty($ccname)) {
133
+		if (!empty($ccaddress)) {
134
+			if (!empty($ccname)) {
135 135
 				$message->setCc([$ccaddress => $ccname]);
136 136
 			} else {
137 137
 				$message->setCc([$ccaddress]);
138 138
 			}
139 139
 		}
140
-		if(!empty($bcc)) {
140
+		if (!empty($bcc)) {
141 141
 			$message->setBcc([$bcc]);
142 142
 		}
143 143
 
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
 	 * @since 4.0.0
153 153
 	 * @deprecated 13.0.0 use log of \OCP\ILogger
154 154
 	 */
155
-	public static function writeLog( $app, $message, $level ) {
155
+	public static function writeLog($app, $message, $level) {
156 156
 		$context = ['app' => $app];
157 157
 		\OC::$server->getLogger()->log($level, $message, $context);
158 158
 	}
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 	 * @since ....0.0 - parameter $level was added in 7.0.0
166 166
 	 * @deprecated 8.2.0 use logException of \OCP\ILogger
167 167
 	 */
168
-	public static function logException( $app, \Exception $ex, $level = \OCP\Util::FATAL ) {
168
+	public static function logException($app, \Exception $ex, $level = \OCP\Util::FATAL) {
169 169
 		\OC::$server->getLogger()->logException($ex, ['app' => $app]);
170 170
 	}
171 171
 
@@ -206,8 +206,8 @@  discard block
 block discarded – undo
206 206
 	 * @param string $file
207 207
 	 * @since 4.0.0
208 208
 	 */
209
-	public static function addStyle( $application, $file = null ) {
210
-		\OC_Util::addStyle( $application, $file );
209
+	public static function addStyle($application, $file = null) {
210
+		\OC_Util::addStyle($application, $file);
211 211
 	}
212 212
 
213 213
 	/**
@@ -216,8 +216,8 @@  discard block
 block discarded – undo
216 216
 	 * @param string $file
217 217
 	 * @since 4.0.0
218 218
 	 */
219
-	public static function addScript( $application, $file = null ) {
220
-		\OC_Util::addScript( $application, $file );
219
+	public static function addScript($application, $file = null) {
220
+		\OC_Util::addScript($application, $file);
221 221
 	}
222 222
 
223 223
 	/**
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
 	 * @param string $text the text content for the element
240 240
 	 * @since 4.0.0
241 241
 	 */
242
-	public static function addHeader($tag, $attributes, $text=null) {
242
+	public static function addHeader($tag, $attributes, $text = null) {
243 243
 		\OC_Util::addHeader($tag, $attributes, $text);
244 244
 	}
245 245
 
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
 	 * @deprecated 8.0.0 Use \OC::$server->query('DateTimeFormatter') instead
254 254
 	 * @since 4.0.0
255 255
 	 */
256
-	public static function formatDate($timestamp, $dateOnly=false, $timeZone = null) {
256
+	public static function formatDate($timestamp, $dateOnly = false, $timeZone = null) {
257 257
 		return(\OC_Util::formatDate($timestamp, $dateOnly, $timeZone));
258 258
 	}
259 259
 
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
 	 * @return string the url
278 278
 	 * @since 4.0.0 - parameter $args was added in 4.5.0
279 279
 	 */
280
-	public static function linkToAbsolute( $app, $file, $args = array() ) {
280
+	public static function linkToAbsolute($app, $file, $args = array()) {
281 281
 		$urlGenerator = \OC::$server->getURLGenerator();
282 282
 		return $urlGenerator->getAbsoluteURL(
283 283
 			$urlGenerator->linkTo($app, $file, $args)
@@ -290,11 +290,11 @@  discard block
 block discarded – undo
290 290
 	 * @return string the url
291 291
 	 * @since 4.0.0
292 292
 	 */
293
-	public static function linkToRemote( $service ) {
293
+	public static function linkToRemote($service) {
294 294
 		$urlGenerator = \OC::$server->getURLGenerator();
295
-		$remoteBase = $urlGenerator->linkTo('', 'remote.php') . '/' . $service;
295
+		$remoteBase = $urlGenerator->linkTo('', 'remote.php').'/'.$service;
296 296
 		return $urlGenerator->getAbsoluteURL(
297
-			$remoteBase . (($service[strlen($service) - 1] != '/') ? '/' : '')
297
+			$remoteBase.(($service[strlen($service) - 1] != '/') ? '/' : '')
298 298
 		);
299 299
 	}
300 300
 
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
 	 * @deprecated 8.1.0 Use \OC::$server->getURLGenerator()->linkToRoute($route, $parameters)
318 318
 	 * @since 5.0.0
319 319
 	 */
320
-	public static function linkToRoute( $route, $parameters = array() ) {
320
+	public static function linkToRoute($route, $parameters = array()) {
321 321
 		return \OC::$server->getURLGenerator()->linkToRoute($route, $parameters);
322 322
 	}
323 323
 
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
 	 * @deprecated 8.1.0 Use \OC::$server->getURLGenerator()->linkTo($app, $file, $args)
332 332
 	 * @since 4.0.0 - parameter $args was added in 4.5.0
333 333
 	 */
334
-	public static function linkTo( $app, $file, $args = array() ) {
334
+	public static function linkTo($app, $file, $args = array()) {
335 335
 		return \OC::$server->getURLGenerator()->linkTo($app, $file, $args);
336 336
 	}
337 337
 
@@ -430,7 +430,7 @@  discard block
 block discarded – undo
430 430
 	 * @deprecated 8.1.0 Use \OC::$server->getURLGenerator()->imagePath($app, $image)
431 431
 	 * @since 4.0.0
432 432
 	 */
433
-	public static function imagePath( $app, $image ) {
433
+	public static function imagePath($app, $image) {
434 434
 		return \OC::$server->getURLGenerator()->imagePath($app, $image);
435 435
 	}
436 436
 
@@ -440,8 +440,8 @@  discard block
 block discarded – undo
440 440
 	 * @return string a human readable file size
441 441
 	 * @since 4.0.0
442 442
 	 */
443
-	public static function humanFileSize( $bytes ) {
444
-		return(\OC_Helper::humanFileSize( $bytes ));
443
+	public static function humanFileSize($bytes) {
444
+		return(\OC_Helper::humanFileSize($bytes));
445 445
 	}
446 446
 
447 447
 	/**
@@ -452,8 +452,8 @@  discard block
 block discarded – undo
452 452
 	 * Inspired by: http://www.php.net/manual/en/function.filesize.php#92418
453 453
 	 * @since 4.0.0
454 454
 	 */
455
-	public static function computerFileSize( $str ) {
456
-		return(\OC_Helper::computerFileSize( $str ));
455
+	public static function computerFileSize($str) {
456
+		return(\OC_Helper::computerFileSize($str));
457 457
 	}
458 458
 
459 459
 	/**
@@ -470,8 +470,8 @@  discard block
 block discarded – undo
470 470
 	 * TODO: write example
471 471
 	 * @since 4.0.0
472 472
 	 */
473
-	static public function connectHook($signalClass, $signalName, $slotClass, $slotName ) {
474
-		return(\OC_Hook::connect($signalClass, $signalName, $slotClass, $slotName ));
473
+	static public function connectHook($signalClass, $signalName, $slotClass, $slotName) {
474
+		return(\OC_Hook::connect($signalClass, $signalName, $slotClass, $slotName));
475 475
 	}
476 476
 
477 477
 	/**
@@ -484,8 +484,8 @@  discard block
 block discarded – undo
484 484
 	 * TODO: write example
485 485
 	 * @since 4.0.0
486 486
 	 */
487
-	static public function emitHook( $signalclass, $signalname, $params = array()) {
488
-		return(\OC_Hook::emit( $signalclass, $signalname, $params ));
487
+	static public function emitHook($signalclass, $signalname, $params = array()) {
488
+		return(\OC_Hook::emit($signalclass, $signalname, $params));
489 489
 	}
490 490
 
491 491
 	/**
@@ -501,7 +501,7 @@  discard block
 block discarded – undo
501 501
 	 * @since 4.5.0
502 502
 	 */
503 503
 	public static function callRegister() {
504
-		if(self::$token === '') {
504
+		if (self::$token === '') {
505 505
 			self::$token = \OC::$server->getCsrfTokenManager()->getToken()->getEncryptedValue();
506 506
 		}
507 507
 		return self::$token;
@@ -513,7 +513,7 @@  discard block
 block discarded – undo
513 513
 	 * @deprecated 9.0.0 Use annotations based on the app framework.
514 514
 	 */
515 515
 	public static function callCheck() {
516
-		if(!\OC::$server->getRequest()->passesStrictCookieCheck()) {
516
+		if (!\OC::$server->getRequest()->passesStrictCookieCheck()) {
517 517
 			header('Location: '.\OC::$WEBROOT);
518 518
 			exit();
519 519
 		}
@@ -704,7 +704,7 @@  discard block
 block discarded – undo
704 704
 	 */
705 705
 	public static function needUpgrade() {
706 706
 		if (!isset(self::$needUpgradeCache)) {
707
-			self::$needUpgradeCache=\OC_Util::needUpgrade(\OC::$server->getSystemConfig());
707
+			self::$needUpgradeCache = \OC_Util::needUpgrade(\OC::$server->getSystemConfig());
708 708
 		}		
709 709
 		return self::$needUpgradeCache;
710 710
 	}
Please login to merge, or discard this patch.