Completed
Push — master ( 52012b...54b1f4 )
by Christoph
23:28 queued 11:46
created
lib/public/Util.php 2 patches
Indentation   +465 added lines, -465 removed lines patch added patch discarded remove patch
@@ -57,471 +57,471 @@
 block discarded – undo
57 57
  * @since 4.0.0
58 58
  */
59 59
 class Util {
60
-	/**
61
-	 * @deprecated 14.0.0 use \OCP\ILogger::DEBUG
62
-	 */
63
-	const DEBUG=0;
64
-	/**
65
-	 * @deprecated 14.0.0 use \OCP\ILogger::INFO
66
-	 */
67
-	const INFO=1;
68
-	/**
69
-	 * @deprecated 14.0.0 use \OCP\ILogger::WARN
70
-	 */
71
-	const WARN=2;
72
-	/**
73
-	 * @deprecated 14.0.0 use \OCP\ILogger::ERROR
74
-	 */
75
-	const ERROR=3;
76
-	/**
77
-	 * @deprecated 14.0.0 use \OCP\ILogger::FATAL
78
-	 */
79
-	const FATAL=4;
80
-
81
-	/** \OCP\Share\IManager */
82
-	private static $shareManager;
83
-
84
-	/**
85
-	 * get the current installed version of Nextcloud
86
-	 * @return array
87
-	 * @since 4.0.0
88
-	 */
89
-	public static function getVersion() {
90
-		return \OC_Util::getVersion();
91
-	}
60
+    /**
61
+     * @deprecated 14.0.0 use \OCP\ILogger::DEBUG
62
+     */
63
+    const DEBUG=0;
64
+    /**
65
+     * @deprecated 14.0.0 use \OCP\ILogger::INFO
66
+     */
67
+    const INFO=1;
68
+    /**
69
+     * @deprecated 14.0.0 use \OCP\ILogger::WARN
70
+     */
71
+    const WARN=2;
72
+    /**
73
+     * @deprecated 14.0.0 use \OCP\ILogger::ERROR
74
+     */
75
+    const ERROR=3;
76
+    /**
77
+     * @deprecated 14.0.0 use \OCP\ILogger::FATAL
78
+     */
79
+    const FATAL=4;
80
+
81
+    /** \OCP\Share\IManager */
82
+    private static $shareManager;
83
+
84
+    /**
85
+     * get the current installed version of Nextcloud
86
+     * @return array
87
+     * @since 4.0.0
88
+     */
89
+    public static function getVersion() {
90
+        return \OC_Util::getVersion();
91
+    }
92 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
-	}
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 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
-	 * @param string $application
168
-	 * @param string $file
169
-	 * @since 4.0.0
170
-	 */
171
-	public static function addScript( $application, $file = null ) {
172
-		\OC_Util::addScript( $application, $file );
173
-	}
174
-
175
-	/**
176
-	 * Add a translation JS file
177
-	 * @param string $application application id
178
-	 * @param string $languageCode language code, defaults to the current locale
179
-	 * @since 8.0.0
180
-	 */
181
-	public static function addTranslations($application, $languageCode = null) {
182
-		\OC_Util::addTranslations($application, $languageCode);
183
-	}
184
-
185
-	/**
186
-	 * Add a custom element to the header
187
-	 * If $text is null then the element will be written as empty element.
188
-	 * So use "" to get a closing tag.
189
-	 * @param string $tag tag name of the element
190
-	 * @param array $attributes array of attributes for the element
191
-	 * @param string $text the text content for the element
192
-	 * @since 4.0.0
193
-	 */
194
-	public static function addHeader($tag, $attributes, $text=null) {
195
-		\OC_Util::addHeader($tag, $attributes, $text);
196
-	}
197
-
198
-	/**
199
-	 * Creates an absolute url to the given app and file.
200
-	 * @param string $app app
201
-	 * @param string $file file
202
-	 * @param array $args array with param=>value, will be appended to the returned url
203
-	 * 	The value of $args will be urlencoded
204
-	 * @return string the url
205
-	 * @since 4.0.0 - parameter $args was added in 4.5.0
206
-	 */
207
-	public static function linkToAbsolute( $app, $file, $args = array() ) {
208
-		$urlGenerator = \OC::$server->getURLGenerator();
209
-		return $urlGenerator->getAbsoluteURL(
210
-			$urlGenerator->linkTo($app, $file, $args)
211
-		);
212
-	}
213
-
214
-	/**
215
-	 * Creates an absolute url for remote use.
216
-	 * @param string $service id
217
-	 * @return string the url
218
-	 * @since 4.0.0
219
-	 */
220
-	public static function linkToRemote( $service ) {
221
-		$urlGenerator = \OC::$server->getURLGenerator();
222
-		$remoteBase = $urlGenerator->linkTo('', 'remote.php') . '/' . $service;
223
-		return $urlGenerator->getAbsoluteURL(
224
-			$remoteBase . (($service[strlen($service) - 1] != '/') ? '/' : '')
225
-		);
226
-	}
227
-
228
-	/**
229
-	 * Creates an absolute url for public use
230
-	 * @param string $service id
231
-	 * @return string the url
232
-	 * @since 4.5.0
233
-	 */
234
-	public static function linkToPublic($service) {
235
-		return \OC_Helper::linkToPublic($service);
236
-	}
237
-
238
-	/**
239
-	 * Returns the server host name without an eventual port number
240
-	 * @return string the server hostname
241
-	 * @since 5.0.0
242
-	 */
243
-	public static function getServerHostName() {
244
-		$host_name = \OC::$server->getRequest()->getServerHost();
245
-		// strip away port number (if existing)
246
-		$colon_pos = strpos($host_name, ':');
247
-		if ($colon_pos != FALSE) {
248
-			$host_name = substr($host_name, 0, $colon_pos);
249
-		}
250
-		return $host_name;
251
-	}
252
-
253
-	/**
254
-	 * Returns the default email address
255
-	 * @param string $user_part the user part of the address
256
-	 * @return string the default email address
257
-	 *
258
-	 * Assembles a default email address (using the server hostname
259
-	 * and the given user part, and returns it
260
-	 * Example: when given lostpassword-noreply as $user_part param,
261
-	 *     and is currently accessed via http(s)://example.com/,
262
-	 *     it would return '[email protected]'
263
-	 *
264
-	 * If the configuration value 'mail_from_address' is set in
265
-	 * config.php, this value will override the $user_part that
266
-	 * is passed to this function
267
-	 * @since 5.0.0
268
-	 */
269
-	public static function getDefaultEmailAddress($user_part) {
270
-		$config = \OC::$server->getConfig();
271
-		$user_part = $config->getSystemValue('mail_from_address', $user_part);
272
-		$host_name = self::getServerHostName();
273
-		$host_name = $config->getSystemValue('mail_domain', $host_name);
274
-		$defaultEmailAddress = $user_part.'@'.$host_name;
275
-
276
-		$mailer = \OC::$server->getMailer();
277
-		if ($mailer->validateMailAddress($defaultEmailAddress)) {
278
-			return $defaultEmailAddress;
279
-		}
280
-
281
-		// in case we cannot build a valid email address from the hostname let's fallback to 'localhost.localdomain'
282
-		return $user_part.'@localhost.localdomain';
283
-	}
284
-
285
-	/**
286
-	 * Make a human file size (2048 to 2 kB)
287
-	 * @param int $bytes file size in bytes
288
-	 * @return string a human readable file size
289
-	 * @since 4.0.0
290
-	 */
291
-	public static function humanFileSize($bytes) {
292
-		return \OC_Helper::humanFileSize($bytes);
293
-	}
294
-
295
-	/**
296
-	 * Make a computer file size (2 kB to 2048)
297
-	 * @param string $str file size in a fancy format
298
-	 * @return float a file size in bytes
299
-	 *
300
-	 * Inspired by: http://www.php.net/manual/en/function.filesize.php#92418
301
-	 * @since 4.0.0
302
-	 */
303
-	public static function computerFileSize($str) {
304
-		return \OC_Helper::computerFileSize($str);
305
-	}
306
-
307
-	/**
308
-	 * connects a function to a hook
309
-	 *
310
-	 * @param string $signalClass class name of emitter
311
-	 * @param string $signalName name of signal
312
-	 * @param string|object $slotClass class name of slot
313
-	 * @param string $slotName name of slot
314
-	 * @return bool
315
-	 *
316
-	 * This function makes it very easy to connect to use hooks.
317
-	 *
318
-	 * TODO: write example
319
-	 * @since 4.0.0
320
-	 */
321
-	static public function connectHook($signalClass, $signalName, $slotClass, $slotName) {
322
-		return \OC_Hook::connect($signalClass, $signalName, $slotClass, $slotName);
323
-	}
324
-
325
-	/**
326
-	 * Emits a signal. To get data from the slot use references!
327
-	 * @param string $signalclass class name of emitter
328
-	 * @param string $signalname name of signal
329
-	 * @param array $params default: array() array with additional data
330
-	 * @return bool true if slots exists or false if not
331
-	 *
332
-	 * TODO: write example
333
-	 * @since 4.0.0
334
-	 */
335
-	static public function emitHook($signalclass, $signalname, $params = array()) {
336
-		return \OC_Hook::emit($signalclass, $signalname, $params);
337
-	}
338
-
339
-	/**
340
-	 * Cached encrypted CSRF token. Some static unit-tests of ownCloud compare
341
-	 * multiple OC_Template elements which invoke `callRegister`. If the value
342
-	 * would not be cached these unit-tests would fail.
343
-	 * @var string
344
-	 */
345
-	private static $token = '';
346
-
347
-	/**
348
-	 * Register an get/post call. This is important to prevent CSRF attacks
349
-	 * @since 4.5.0
350
-	 */
351
-	public static function callRegister() {
352
-		if(self::$token === '') {
353
-			self::$token = \OC::$server->getCsrfTokenManager()->getToken()->getEncryptedValue();
354
-		}
355
-		return self::$token;
356
-	}
357
-
358
-	/**
359
-	 * Check an ajax get/post call if the request token is valid. exit if not.
360
-	 * @since 4.5.0
361
-	 * @deprecated 9.0.0 Use annotations based on the app framework.
362
-	 */
363
-	public static function callCheck() {
364
-		if(!\OC::$server->getRequest()->passesStrictCookieCheck()) {
365
-			header('Location: '.\OC::$WEBROOT);
366
-			exit();
367
-		}
368
-
369
-		if (!\OC::$server->getRequest()->passesCSRFCheck()) {
370
-			exit();
371
-		}
372
-	}
373
-
374
-	/**
375
-	 * Used to sanitize HTML
376
-	 *
377
-	 * This function is used to sanitize HTML and should be applied on any
378
-	 * string or array of strings before displaying it on a web page.
379
-	 *
380
-	 * @param string|array $value
381
-	 * @return string|array an array of sanitized strings or a single sanitized string, depends on the input parameter.
382
-	 * @since 4.5.0
383
-	 */
384
-	public static function sanitizeHTML($value) {
385
-		return \OC_Util::sanitizeHTML($value);
386
-	}
387
-
388
-	/**
389
-	 * Public function to encode url parameters
390
-	 *
391
-	 * This function is used to encode path to file before output.
392
-	 * Encoding is done according to RFC 3986 with one exception:
393
-	 * Character '/' is preserved as is.
394
-	 *
395
-	 * @param string $component part of URI to encode
396
-	 * @return string
397
-	 * @since 6.0.0
398
-	 */
399
-	public static function encodePath($component) {
400
-		return \OC_Util::encodePath($component);
401
-	}
402
-
403
-	/**
404
-	 * Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is.
405
-	 *
406
-	 * @param array $input The array to work on
407
-	 * @param int $case Either MB_CASE_UPPER or MB_CASE_LOWER (default)
408
-	 * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8
409
-	 * @return array
410
-	 * @since 4.5.0
411
-	 */
412
-	public static function mb_array_change_key_case($input, $case = MB_CASE_LOWER, $encoding = 'UTF-8') {
413
-		return \OC_Helper::mb_array_change_key_case($input, $case, $encoding);
414
-	}
415
-
416
-	/**
417
-	 * performs a search in a nested array
418
-	 *
419
-	 * @param array $haystack the array to be searched
420
-	 * @param string $needle the search string
421
-	 * @param mixed $index optional, only search this key name
422
-	 * @return mixed the key of the matching field, otherwise false
423
-	 * @since 4.5.0
424
-	 */
425
-	public static function recursiveArraySearch($haystack, $needle, $index = null) {
426
-		return \OC_Helper::recursiveArraySearch($haystack, $needle, $index);
427
-	}
428
-
429
-	/**
430
-	 * calculates the maximum upload size respecting system settings, free space and user quota
431
-	 *
432
-	 * @param string $dir the current folder where the user currently operates
433
-	 * @param int $free the number of bytes free on the storage holding $dir, if not set this will be received from the storage directly
434
-	 * @return int number of bytes representing
435
-	 * @since 5.0.0
436
-	 */
437
-	public static function maxUploadFilesize($dir, $free = null) {
438
-		return \OC_Helper::maxUploadFilesize($dir, $free);
439
-	}
440
-
441
-	/**
442
-	 * Calculate free space left within user quota
443
-	 * @param string $dir the current folder where the user currently operates
444
-	 * @return int number of bytes representing
445
-	 * @since 7.0.0
446
-	 */
447
-	public static function freeSpace($dir) {
448
-		return \OC_Helper::freeSpace($dir);
449
-	}
450
-
451
-	/**
452
-	 * Calculate PHP upload limit
453
-	 *
454
-	 * @return int number of bytes representing
455
-	 * @since 7.0.0
456
-	 */
457
-	public static function uploadLimit() {
458
-		return \OC_Helper::uploadLimit();
459
-	}
460
-
461
-	/**
462
-	 * Returns whether the given file name is valid
463
-	 * @param string $file file name to check
464
-	 * @return bool true if the file name is valid, false otherwise
465
-	 * @deprecated 8.1.0 use \OC\Files\View::verifyPath()
466
-	 * @since 7.0.0
467
-	 * @suppress PhanDeprecatedFunction
468
-	 */
469
-	public static function isValidFileName($file) {
470
-		return \OC_Util::isValidFileName($file);
471
-	}
472
-
473
-	/**
474
-	 * Compare two strings to provide a natural sort
475
-	 * @param string $a first string to compare
476
-	 * @param string $b second string to compare
477
-	 * @return int -1 if $b comes before $a, 1 if $a comes before $b
478
-	 * or 0 if the strings are identical
479
-	 * @since 7.0.0
480
-	 */
481
-	public static function naturalSortCompare($a, $b) {
482
-		return \OC\NaturalSort::getInstance()->compare($a, $b);
483
-	}
484
-
485
-	/**
486
-	 * check if a password is required for each public link
487
-	 * @return boolean
488
-	 * @since 7.0.0
489
-	 */
490
-	public static function isPublicLinkPasswordRequired() {
491
-		return \OC_Util::isPublicLinkPasswordRequired();
492
-	}
493
-
494
-	/**
495
-	 * check if share API enforces a default expire date
496
-	 * @return boolean
497
-	 * @since 8.0.0
498
-	 */
499
-	public static function isDefaultExpireDateEnforced() {
500
-		return \OC_Util::isDefaultExpireDateEnforced();
501
-	}
502
-
503
-	protected static $needUpgradeCache = null;
504
-
505
-	/**
506
-	 * Checks whether the current version needs upgrade.
507
-	 *
508
-	 * @return bool true if upgrade is needed, false otherwise
509
-	 * @since 7.0.0
510
-	 */
511
-	public static function needUpgrade() {
512
-		if (!isset(self::$needUpgradeCache)) {
513
-			self::$needUpgradeCache=\OC_Util::needUpgrade(\OC::$server->getSystemConfig());
514
-		}		
515
-		return self::$needUpgradeCache;
516
-	}
517
-
518
-	/**
519
-	 * is this Internet explorer ?
520
-	 *
521
-	 * @return boolean
522
-	 * @since 14.0.0
523
-	 */
524
-	public static function isIe() {
525
-		return \OC_Util::isIe();
526
-	}
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
+     * @param string $application
168
+     * @param string $file
169
+     * @since 4.0.0
170
+     */
171
+    public static function addScript( $application, $file = null ) {
172
+        \OC_Util::addScript( $application, $file );
173
+    }
174
+
175
+    /**
176
+     * Add a translation JS file
177
+     * @param string $application application id
178
+     * @param string $languageCode language code, defaults to the current locale
179
+     * @since 8.0.0
180
+     */
181
+    public static function addTranslations($application, $languageCode = null) {
182
+        \OC_Util::addTranslations($application, $languageCode);
183
+    }
184
+
185
+    /**
186
+     * Add a custom element to the header
187
+     * If $text is null then the element will be written as empty element.
188
+     * So use "" to get a closing tag.
189
+     * @param string $tag tag name of the element
190
+     * @param array $attributes array of attributes for the element
191
+     * @param string $text the text content for the element
192
+     * @since 4.0.0
193
+     */
194
+    public static function addHeader($tag, $attributes, $text=null) {
195
+        \OC_Util::addHeader($tag, $attributes, $text);
196
+    }
197
+
198
+    /**
199
+     * Creates an absolute url to the given app and file.
200
+     * @param string $app app
201
+     * @param string $file file
202
+     * @param array $args array with param=>value, will be appended to the returned url
203
+     * 	The value of $args will be urlencoded
204
+     * @return string the url
205
+     * @since 4.0.0 - parameter $args was added in 4.5.0
206
+     */
207
+    public static function linkToAbsolute( $app, $file, $args = array() ) {
208
+        $urlGenerator = \OC::$server->getURLGenerator();
209
+        return $urlGenerator->getAbsoluteURL(
210
+            $urlGenerator->linkTo($app, $file, $args)
211
+        );
212
+    }
213
+
214
+    /**
215
+     * Creates an absolute url for remote use.
216
+     * @param string $service id
217
+     * @return string the url
218
+     * @since 4.0.0
219
+     */
220
+    public static function linkToRemote( $service ) {
221
+        $urlGenerator = \OC::$server->getURLGenerator();
222
+        $remoteBase = $urlGenerator->linkTo('', 'remote.php') . '/' . $service;
223
+        return $urlGenerator->getAbsoluteURL(
224
+            $remoteBase . (($service[strlen($service) - 1] != '/') ? '/' : '')
225
+        );
226
+    }
227
+
228
+    /**
229
+     * Creates an absolute url for public use
230
+     * @param string $service id
231
+     * @return string the url
232
+     * @since 4.5.0
233
+     */
234
+    public static function linkToPublic($service) {
235
+        return \OC_Helper::linkToPublic($service);
236
+    }
237
+
238
+    /**
239
+     * Returns the server host name without an eventual port number
240
+     * @return string the server hostname
241
+     * @since 5.0.0
242
+     */
243
+    public static function getServerHostName() {
244
+        $host_name = \OC::$server->getRequest()->getServerHost();
245
+        // strip away port number (if existing)
246
+        $colon_pos = strpos($host_name, ':');
247
+        if ($colon_pos != FALSE) {
248
+            $host_name = substr($host_name, 0, $colon_pos);
249
+        }
250
+        return $host_name;
251
+    }
252
+
253
+    /**
254
+     * Returns the default email address
255
+     * @param string $user_part the user part of the address
256
+     * @return string the default email address
257
+     *
258
+     * Assembles a default email address (using the server hostname
259
+     * and the given user part, and returns it
260
+     * Example: when given lostpassword-noreply as $user_part param,
261
+     *     and is currently accessed via http(s)://example.com/,
262
+     *     it would return '[email protected]'
263
+     *
264
+     * If the configuration value 'mail_from_address' is set in
265
+     * config.php, this value will override the $user_part that
266
+     * is passed to this function
267
+     * @since 5.0.0
268
+     */
269
+    public static function getDefaultEmailAddress($user_part) {
270
+        $config = \OC::$server->getConfig();
271
+        $user_part = $config->getSystemValue('mail_from_address', $user_part);
272
+        $host_name = self::getServerHostName();
273
+        $host_name = $config->getSystemValue('mail_domain', $host_name);
274
+        $defaultEmailAddress = $user_part.'@'.$host_name;
275
+
276
+        $mailer = \OC::$server->getMailer();
277
+        if ($mailer->validateMailAddress($defaultEmailAddress)) {
278
+            return $defaultEmailAddress;
279
+        }
280
+
281
+        // in case we cannot build a valid email address from the hostname let's fallback to 'localhost.localdomain'
282
+        return $user_part.'@localhost.localdomain';
283
+    }
284
+
285
+    /**
286
+     * Make a human file size (2048 to 2 kB)
287
+     * @param int $bytes file size in bytes
288
+     * @return string a human readable file size
289
+     * @since 4.0.0
290
+     */
291
+    public static function humanFileSize($bytes) {
292
+        return \OC_Helper::humanFileSize($bytes);
293
+    }
294
+
295
+    /**
296
+     * Make a computer file size (2 kB to 2048)
297
+     * @param string $str file size in a fancy format
298
+     * @return float a file size in bytes
299
+     *
300
+     * Inspired by: http://www.php.net/manual/en/function.filesize.php#92418
301
+     * @since 4.0.0
302
+     */
303
+    public static function computerFileSize($str) {
304
+        return \OC_Helper::computerFileSize($str);
305
+    }
306
+
307
+    /**
308
+     * connects a function to a hook
309
+     *
310
+     * @param string $signalClass class name of emitter
311
+     * @param string $signalName name of signal
312
+     * @param string|object $slotClass class name of slot
313
+     * @param string $slotName name of slot
314
+     * @return bool
315
+     *
316
+     * This function makes it very easy to connect to use hooks.
317
+     *
318
+     * TODO: write example
319
+     * @since 4.0.0
320
+     */
321
+    static public function connectHook($signalClass, $signalName, $slotClass, $slotName) {
322
+        return \OC_Hook::connect($signalClass, $signalName, $slotClass, $slotName);
323
+    }
324
+
325
+    /**
326
+     * Emits a signal. To get data from the slot use references!
327
+     * @param string $signalclass class name of emitter
328
+     * @param string $signalname name of signal
329
+     * @param array $params default: array() array with additional data
330
+     * @return bool true if slots exists or false if not
331
+     *
332
+     * TODO: write example
333
+     * @since 4.0.0
334
+     */
335
+    static public function emitHook($signalclass, $signalname, $params = array()) {
336
+        return \OC_Hook::emit($signalclass, $signalname, $params);
337
+    }
338
+
339
+    /**
340
+     * Cached encrypted CSRF token. Some static unit-tests of ownCloud compare
341
+     * multiple OC_Template elements which invoke `callRegister`. If the value
342
+     * would not be cached these unit-tests would fail.
343
+     * @var string
344
+     */
345
+    private static $token = '';
346
+
347
+    /**
348
+     * Register an get/post call. This is important to prevent CSRF attacks
349
+     * @since 4.5.0
350
+     */
351
+    public static function callRegister() {
352
+        if(self::$token === '') {
353
+            self::$token = \OC::$server->getCsrfTokenManager()->getToken()->getEncryptedValue();
354
+        }
355
+        return self::$token;
356
+    }
357
+
358
+    /**
359
+     * Check an ajax get/post call if the request token is valid. exit if not.
360
+     * @since 4.5.0
361
+     * @deprecated 9.0.0 Use annotations based on the app framework.
362
+     */
363
+    public static function callCheck() {
364
+        if(!\OC::$server->getRequest()->passesStrictCookieCheck()) {
365
+            header('Location: '.\OC::$WEBROOT);
366
+            exit();
367
+        }
368
+
369
+        if (!\OC::$server->getRequest()->passesCSRFCheck()) {
370
+            exit();
371
+        }
372
+    }
373
+
374
+    /**
375
+     * Used to sanitize HTML
376
+     *
377
+     * This function is used to sanitize HTML and should be applied on any
378
+     * string or array of strings before displaying it on a web page.
379
+     *
380
+     * @param string|array $value
381
+     * @return string|array an array of sanitized strings or a single sanitized string, depends on the input parameter.
382
+     * @since 4.5.0
383
+     */
384
+    public static function sanitizeHTML($value) {
385
+        return \OC_Util::sanitizeHTML($value);
386
+    }
387
+
388
+    /**
389
+     * Public function to encode url parameters
390
+     *
391
+     * This function is used to encode path to file before output.
392
+     * Encoding is done according to RFC 3986 with one exception:
393
+     * Character '/' is preserved as is.
394
+     *
395
+     * @param string $component part of URI to encode
396
+     * @return string
397
+     * @since 6.0.0
398
+     */
399
+    public static function encodePath($component) {
400
+        return \OC_Util::encodePath($component);
401
+    }
402
+
403
+    /**
404
+     * Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is.
405
+     *
406
+     * @param array $input The array to work on
407
+     * @param int $case Either MB_CASE_UPPER or MB_CASE_LOWER (default)
408
+     * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8
409
+     * @return array
410
+     * @since 4.5.0
411
+     */
412
+    public static function mb_array_change_key_case($input, $case = MB_CASE_LOWER, $encoding = 'UTF-8') {
413
+        return \OC_Helper::mb_array_change_key_case($input, $case, $encoding);
414
+    }
415
+
416
+    /**
417
+     * performs a search in a nested array
418
+     *
419
+     * @param array $haystack the array to be searched
420
+     * @param string $needle the search string
421
+     * @param mixed $index optional, only search this key name
422
+     * @return mixed the key of the matching field, otherwise false
423
+     * @since 4.5.0
424
+     */
425
+    public static function recursiveArraySearch($haystack, $needle, $index = null) {
426
+        return \OC_Helper::recursiveArraySearch($haystack, $needle, $index);
427
+    }
428
+
429
+    /**
430
+     * calculates the maximum upload size respecting system settings, free space and user quota
431
+     *
432
+     * @param string $dir the current folder where the user currently operates
433
+     * @param int $free the number of bytes free on the storage holding $dir, if not set this will be received from the storage directly
434
+     * @return int number of bytes representing
435
+     * @since 5.0.0
436
+     */
437
+    public static function maxUploadFilesize($dir, $free = null) {
438
+        return \OC_Helper::maxUploadFilesize($dir, $free);
439
+    }
440
+
441
+    /**
442
+     * Calculate free space left within user quota
443
+     * @param string $dir the current folder where the user currently operates
444
+     * @return int number of bytes representing
445
+     * @since 7.0.0
446
+     */
447
+    public static function freeSpace($dir) {
448
+        return \OC_Helper::freeSpace($dir);
449
+    }
450
+
451
+    /**
452
+     * Calculate PHP upload limit
453
+     *
454
+     * @return int number of bytes representing
455
+     * @since 7.0.0
456
+     */
457
+    public static function uploadLimit() {
458
+        return \OC_Helper::uploadLimit();
459
+    }
460
+
461
+    /**
462
+     * Returns whether the given file name is valid
463
+     * @param string $file file name to check
464
+     * @return bool true if the file name is valid, false otherwise
465
+     * @deprecated 8.1.0 use \OC\Files\View::verifyPath()
466
+     * @since 7.0.0
467
+     * @suppress PhanDeprecatedFunction
468
+     */
469
+    public static function isValidFileName($file) {
470
+        return \OC_Util::isValidFileName($file);
471
+    }
472
+
473
+    /**
474
+     * Compare two strings to provide a natural sort
475
+     * @param string $a first string to compare
476
+     * @param string $b second string to compare
477
+     * @return int -1 if $b comes before $a, 1 if $a comes before $b
478
+     * or 0 if the strings are identical
479
+     * @since 7.0.0
480
+     */
481
+    public static function naturalSortCompare($a, $b) {
482
+        return \OC\NaturalSort::getInstance()->compare($a, $b);
483
+    }
484
+
485
+    /**
486
+     * check if a password is required for each public link
487
+     * @return boolean
488
+     * @since 7.0.0
489
+     */
490
+    public static function isPublicLinkPasswordRequired() {
491
+        return \OC_Util::isPublicLinkPasswordRequired();
492
+    }
493
+
494
+    /**
495
+     * check if share API enforces a default expire date
496
+     * @return boolean
497
+     * @since 8.0.0
498
+     */
499
+    public static function isDefaultExpireDateEnforced() {
500
+        return \OC_Util::isDefaultExpireDateEnforced();
501
+    }
502
+
503
+    protected static $needUpgradeCache = null;
504
+
505
+    /**
506
+     * Checks whether the current version needs upgrade.
507
+     *
508
+     * @return bool true if upgrade is needed, false otherwise
509
+     * @since 7.0.0
510
+     */
511
+    public static function needUpgrade() {
512
+        if (!isset(self::$needUpgradeCache)) {
513
+            self::$needUpgradeCache=\OC_Util::needUpgrade(\OC::$server->getSystemConfig());
514
+        }		
515
+        return self::$needUpgradeCache;
516
+    }
517
+
518
+    /**
519
+     * is this Internet explorer ?
520
+     *
521
+     * @return boolean
522
+     * @since 14.0.0
523
+     */
524
+    public static function isIe() {
525
+        return \OC_Util::isIe();
526
+    }
527 527
 }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -60,23 +60,23 @@  discard block
 block discarded – undo
60 60
 	/**
61 61
 	 * @deprecated 14.0.0 use \OCP\ILogger::DEBUG
62 62
 	 */
63
-	const DEBUG=0;
63
+	const DEBUG = 0;
64 64
 	/**
65 65
 	 * @deprecated 14.0.0 use \OCP\ILogger::INFO
66 66
 	 */
67
-	const INFO=1;
67
+	const INFO = 1;
68 68
 	/**
69 69
 	 * @deprecated 14.0.0 use \OCP\ILogger::WARN
70 70
 	 */
71
-	const WARN=2;
71
+	const WARN = 2;
72 72
 	/**
73 73
 	 * @deprecated 14.0.0 use \OCP\ILogger::ERROR
74 74
 	 */
75
-	const ERROR=3;
75
+	const ERROR = 3;
76 76
 	/**
77 77
 	 * @deprecated 14.0.0 use \OCP\ILogger::FATAL
78 78
 	 */
79
-	const FATAL=4;
79
+	const FATAL = 4;
80 80
 
81 81
 	/** \OCP\Share\IManager */
82 82
 	private static $shareManager;
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
 	 * @since 4.0.0
117 117
 	 * @deprecated 13.0.0 use log of \OCP\ILogger
118 118
 	 */
119
-	public static function writeLog( $app, $message, $level ) {
119
+	public static function writeLog($app, $message, $level) {
120 120
 		$context = ['app' => $app];
121 121
 		\OC::$server->getLogger()->log($level, $message, $context);
122 122
 	}
@@ -158,8 +158,8 @@  discard block
 block discarded – undo
158 158
 	 * @param string $file
159 159
 	 * @since 4.0.0
160 160
 	 */
161
-	public static function addStyle( $application, $file = null ) {
162
-		\OC_Util::addStyle( $application, $file );
161
+	public static function addStyle($application, $file = null) {
162
+		\OC_Util::addStyle($application, $file);
163 163
 	}
164 164
 
165 165
 	/**
@@ -168,8 +168,8 @@  discard block
 block discarded – undo
168 168
 	 * @param string $file
169 169
 	 * @since 4.0.0
170 170
 	 */
171
-	public static function addScript( $application, $file = null ) {
172
-		\OC_Util::addScript( $application, $file );
171
+	public static function addScript($application, $file = null) {
172
+		\OC_Util::addScript($application, $file);
173 173
 	}
174 174
 
175 175
 	/**
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
 	 * @param string $text the text content for the element
192 192
 	 * @since 4.0.0
193 193
 	 */
194
-	public static function addHeader($tag, $attributes, $text=null) {
194
+	public static function addHeader($tag, $attributes, $text = null) {
195 195
 		\OC_Util::addHeader($tag, $attributes, $text);
196 196
 	}
197 197
 
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
 	 * @return string the url
205 205
 	 * @since 4.0.0 - parameter $args was added in 4.5.0
206 206
 	 */
207
-	public static function linkToAbsolute( $app, $file, $args = array() ) {
207
+	public static function linkToAbsolute($app, $file, $args = array()) {
208 208
 		$urlGenerator = \OC::$server->getURLGenerator();
209 209
 		return $urlGenerator->getAbsoluteURL(
210 210
 			$urlGenerator->linkTo($app, $file, $args)
@@ -217,11 +217,11 @@  discard block
 block discarded – undo
217 217
 	 * @return string the url
218 218
 	 * @since 4.0.0
219 219
 	 */
220
-	public static function linkToRemote( $service ) {
220
+	public static function linkToRemote($service) {
221 221
 		$urlGenerator = \OC::$server->getURLGenerator();
222
-		$remoteBase = $urlGenerator->linkTo('', 'remote.php') . '/' . $service;
222
+		$remoteBase = $urlGenerator->linkTo('', 'remote.php').'/'.$service;
223 223
 		return $urlGenerator->getAbsoluteURL(
224
-			$remoteBase . (($service[strlen($service) - 1] != '/') ? '/' : '')
224
+			$remoteBase.(($service[strlen($service) - 1] != '/') ? '/' : '')
225 225
 		);
226 226
 	}
227 227
 
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
 	 * @since 4.5.0
350 350
 	 */
351 351
 	public static function callRegister() {
352
-		if(self::$token === '') {
352
+		if (self::$token === '') {
353 353
 			self::$token = \OC::$server->getCsrfTokenManager()->getToken()->getEncryptedValue();
354 354
 		}
355 355
 		return self::$token;
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
 	 * @deprecated 9.0.0 Use annotations based on the app framework.
362 362
 	 */
363 363
 	public static function callCheck() {
364
-		if(!\OC::$server->getRequest()->passesStrictCookieCheck()) {
364
+		if (!\OC::$server->getRequest()->passesStrictCookieCheck()) {
365 365
 			header('Location: '.\OC::$WEBROOT);
366 366
 			exit();
367 367
 		}
@@ -510,7 +510,7 @@  discard block
 block discarded – undo
510 510
 	 */
511 511
 	public static function needUpgrade() {
512 512
 		if (!isset(self::$needUpgradeCache)) {
513
-			self::$needUpgradeCache=\OC_Util::needUpgrade(\OC::$server->getSystemConfig());
513
+			self::$needUpgradeCache = \OC_Util::needUpgrade(\OC::$server->getSystemConfig());
514 514
 		}		
515 515
 		return self::$needUpgradeCache;
516 516
 	}
Please login to merge, or discard this patch.