Completed
Push — master ( 8a505e...14bc9b )
by Morris
51:24 queued 31:58
created
core/routes.php 1 patch
Indentation   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -36,44 +36,44 @@  discard block
 block discarded – undo
36 36
 
37 37
 $application = new Application();
38 38
 $application->registerRoutes($this, [
39
-	'routes' => [
40
-		['name' => 'lost#email', 'url' => '/lostpassword/email', 'verb' => 'POST'],
41
-		['name' => 'lost#resetform', 'url' => '/lostpassword/reset/form/{token}/{userId}', 'verb' => 'GET'],
42
-		['name' => 'lost#setPassword', 'url' => '/lostpassword/set/{token}/{userId}', 'verb' => 'POST'],
43
-		['name' => 'user#getDisplayNames', 'url' => '/displaynames', 'verb' => 'POST'],
44
-		['name' => 'avatar#getAvatar', 'url' => '/avatar/{userId}/{size}', 'verb' => 'GET'],
45
-		['name' => 'avatar#deleteAvatar', 'url' => '/avatar/', 'verb' => 'DELETE'],
46
-		['name' => 'avatar#postCroppedAvatar', 'url' => '/avatar/cropped', 'verb' => 'POST'],
47
-		['name' => 'avatar#getTmpAvatar', 'url' => '/avatar/tmp', 'verb' => 'GET'],
48
-		['name' => 'avatar#postAvatar', 'url' => '/avatar/', 'verb' => 'POST'],
49
-		['name' => 'login#tryLogin', 'url' => '/login', 'verb' => 'POST'],
50
-		['name' => 'login#confirmPassword', 'url' => '/login/confirm', 'verb' => 'POST'],
51
-		['name' => 'login#showLoginForm', 'url' => '/login', 'verb' => 'GET'],
52
-		['name' => 'login#logout', 'url' => '/logout', 'verb' => 'GET'],
53
-		['name' => 'ClientFlowLogin#showAuthPickerPage', 'url' => '/login/flow', 'verb' => 'GET'],
54
-		['name' => 'ClientFlowLogin#redirectPage', 'url' => '/login/flow/redirect', 'verb' => 'GET'],
55
-		['name' => 'ClientFlowLogin#generateAppPassword', 'url' => '/login/flow', 'verb' => 'POST'],
56
-		['name' => 'TwoFactorChallenge#selectChallenge', 'url' => '/login/selectchallenge', 'verb' => 'GET'],
57
-		['name' => 'TwoFactorChallenge#showChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'GET'],
58
-		['name' => 'TwoFactorChallenge#solveChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'POST'],
59
-		['name' => 'OCJS#getConfig', 'url' => '/core/js/oc.js', 'verb' => 'GET'],
60
-		['name' => 'Preview#getPreviewByFileId', 'url' => '/core/preview', 'verb' => 'GET'],
61
-		['name' => 'Preview#getPreview', 'url' => '/core/preview.png', 'verb' => 'GET'],
62
-		['name' => 'Css#getCss', 'url' => '/css/{appName}/{fileName}', 'verb' => 'GET'],
63
-		['name' => 'Js#getJs', 'url' => '/js/{appName}/{fileName}', 'verb' => 'GET'],
64
-		['name' => 'contactsMenu#index', 'url' => '/contactsmenu/contacts', 'verb' => 'POST'],
65
-		['name' => 'contactsMenu#findOne', 'url' => '/contactsmenu/findOne', 'verb' => 'POST'],
66
-		['name' => 'AutoComplete#get', 'url' => 'autocomplete/get', 'verb' => 'GET'],
67
-		['name' => 'WalledGarden#get', 'url' => '/204', 'verb' => 'GET'],
68
-	],
69
-	'ocs' => [
70
-		['root' => '/cloud', 'name' => 'OCS#getCapabilities', 'url' => '/capabilities', 'verb' => 'GET'],
71
-		['root' => '', 'name' => 'OCS#getConfig', 'url' => '/config', 'verb' => 'GET'],
72
-		['root' => '/person', 'name' => 'OCS#personCheck', 'url' => '/check', 'verb' => 'POST'],
73
-		['root' => '/identityproof', 'name' => 'OCS#getIdentityProof', 'url' => '/key/{cloudId}', 'verb' => 'GET'],
74
-		['root' => '/core', 'name' => 'Navigation#getAppsNavigation', 'url' => '/navigation/apps', 'verb' => 'GET'],
75
-		['root' => '/core', 'name' => 'Navigation#getSettingsNavigation', 'url' => '/navigation/settings', 'verb' => 'GET'],
76
-	],
39
+    'routes' => [
40
+        ['name' => 'lost#email', 'url' => '/lostpassword/email', 'verb' => 'POST'],
41
+        ['name' => 'lost#resetform', 'url' => '/lostpassword/reset/form/{token}/{userId}', 'verb' => 'GET'],
42
+        ['name' => 'lost#setPassword', 'url' => '/lostpassword/set/{token}/{userId}', 'verb' => 'POST'],
43
+        ['name' => 'user#getDisplayNames', 'url' => '/displaynames', 'verb' => 'POST'],
44
+        ['name' => 'avatar#getAvatar', 'url' => '/avatar/{userId}/{size}', 'verb' => 'GET'],
45
+        ['name' => 'avatar#deleteAvatar', 'url' => '/avatar/', 'verb' => 'DELETE'],
46
+        ['name' => 'avatar#postCroppedAvatar', 'url' => '/avatar/cropped', 'verb' => 'POST'],
47
+        ['name' => 'avatar#getTmpAvatar', 'url' => '/avatar/tmp', 'verb' => 'GET'],
48
+        ['name' => 'avatar#postAvatar', 'url' => '/avatar/', 'verb' => 'POST'],
49
+        ['name' => 'login#tryLogin', 'url' => '/login', 'verb' => 'POST'],
50
+        ['name' => 'login#confirmPassword', 'url' => '/login/confirm', 'verb' => 'POST'],
51
+        ['name' => 'login#showLoginForm', 'url' => '/login', 'verb' => 'GET'],
52
+        ['name' => 'login#logout', 'url' => '/logout', 'verb' => 'GET'],
53
+        ['name' => 'ClientFlowLogin#showAuthPickerPage', 'url' => '/login/flow', 'verb' => 'GET'],
54
+        ['name' => 'ClientFlowLogin#redirectPage', 'url' => '/login/flow/redirect', 'verb' => 'GET'],
55
+        ['name' => 'ClientFlowLogin#generateAppPassword', 'url' => '/login/flow', 'verb' => 'POST'],
56
+        ['name' => 'TwoFactorChallenge#selectChallenge', 'url' => '/login/selectchallenge', 'verb' => 'GET'],
57
+        ['name' => 'TwoFactorChallenge#showChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'GET'],
58
+        ['name' => 'TwoFactorChallenge#solveChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'POST'],
59
+        ['name' => 'OCJS#getConfig', 'url' => '/core/js/oc.js', 'verb' => 'GET'],
60
+        ['name' => 'Preview#getPreviewByFileId', 'url' => '/core/preview', 'verb' => 'GET'],
61
+        ['name' => 'Preview#getPreview', 'url' => '/core/preview.png', 'verb' => 'GET'],
62
+        ['name' => 'Css#getCss', 'url' => '/css/{appName}/{fileName}', 'verb' => 'GET'],
63
+        ['name' => 'Js#getJs', 'url' => '/js/{appName}/{fileName}', 'verb' => 'GET'],
64
+        ['name' => 'contactsMenu#index', 'url' => '/contactsmenu/contacts', 'verb' => 'POST'],
65
+        ['name' => 'contactsMenu#findOne', 'url' => '/contactsmenu/findOne', 'verb' => 'POST'],
66
+        ['name' => 'AutoComplete#get', 'url' => 'autocomplete/get', 'verb' => 'GET'],
67
+        ['name' => 'WalledGarden#get', 'url' => '/204', 'verb' => 'GET'],
68
+    ],
69
+    'ocs' => [
70
+        ['root' => '/cloud', 'name' => 'OCS#getCapabilities', 'url' => '/capabilities', 'verb' => 'GET'],
71
+        ['root' => '', 'name' => 'OCS#getConfig', 'url' => '/config', 'verb' => 'GET'],
72
+        ['root' => '/person', 'name' => 'OCS#personCheck', 'url' => '/check', 'verb' => 'POST'],
73
+        ['root' => '/identityproof', 'name' => 'OCS#getIdentityProof', 'url' => '/key/{cloudId}', 'verb' => 'GET'],
74
+        ['root' => '/core', 'name' => 'Navigation#getAppsNavigation', 'url' => '/navigation/apps', 'verb' => 'GET'],
75
+        ['root' => '/core', 'name' => 'Navigation#getSettingsNavigation', 'url' => '/navigation/settings', 'verb' => 'GET'],
76
+    ],
77 77
 ]);
78 78
 
79 79
 // Post installation check
@@ -82,15 +82,15 @@  discard block
 block discarded – undo
82 82
 // Core ajax actions
83 83
 // Search
84 84
 $this->create('search_ajax_search', '/core/search')
85
-	->actionInclude('core/search/ajax/search.php');
85
+    ->actionInclude('core/search/ajax/search.php');
86 86
 // Routing
87 87
 $this->create('core_ajax_update', '/core/ajax/update.php')
88
-	->actionInclude('core/ajax/update.php');
88
+    ->actionInclude('core/ajax/update.php');
89 89
 
90 90
 // File routes
91 91
 $this->create('files.viewcontroller.showFile', '/f/{fileid}')->action(function($urlParams) {
92
-	$app = new \OCA\Files\AppInfo\Application($urlParams);
93
-	$app->dispatch('ViewController', 'index');
92
+    $app = new \OCA\Files\AppInfo\Application($urlParams);
93
+    $app->dispatch('ViewController', 'index');
94 94
 });
95 95
 
96 96
 // Call routes
@@ -99,57 +99,57 @@  discard block
 block discarded – undo
99 99
  * @suppress PhanUndeclaredClassMethod
100 100
  */
101 101
 $this->create('spreed.pagecontroller.showCall', '/call/{token}')->action(function($urlParams) {
102
-	if (class_exists(\OCA\Spreed\AppInfo\Application::class, false)) {
103
-		$app = new \OCA\Spreed\AppInfo\Application($urlParams);
104
-		$app->dispatch('PageController', 'index');
105
-	} else {
106
-		throw new \OC\HintException('App spreed is not enabled');
107
-	}
102
+    if (class_exists(\OCA\Spreed\AppInfo\Application::class, false)) {
103
+        $app = new \OCA\Spreed\AppInfo\Application($urlParams);
104
+        $app->dispatch('PageController', 'index');
105
+    } else {
106
+        throw new \OC\HintException('App spreed is not enabled');
107
+    }
108 108
 });
109 109
 
110 110
 // Sharing routes
111 111
 $this->create('files_sharing.sharecontroller.showShare', '/s/{token}')->action(function($urlParams) {
112
-	if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) {
113
-		$app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
114
-		$app->dispatch('ShareController', 'showShare');
115
-	} else {
116
-		throw new \OC\HintException('App file sharing is not enabled');
117
-	}
112
+    if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) {
113
+        $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
114
+        $app->dispatch('ShareController', 'showShare');
115
+    } else {
116
+        throw new \OC\HintException('App file sharing is not enabled');
117
+    }
118 118
 });
119 119
 $this->create('files_sharing.sharecontroller.authenticate', '/s/{token}/authenticate')->post()->action(function($urlParams) {
120
-	if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) {
121
-		$app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
122
-		$app->dispatch('ShareController', 'authenticate');
123
-	} else {
124
-		throw new \OC\HintException('App file sharing is not enabled');
125
-	}
120
+    if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) {
121
+        $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
122
+        $app->dispatch('ShareController', 'authenticate');
123
+    } else {
124
+        throw new \OC\HintException('App file sharing is not enabled');
125
+    }
126 126
 });
127 127
 $this->create('files_sharing.sharecontroller.showAuthenticate', '/s/{token}/authenticate')->get()->action(function($urlParams) {
128
-	if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) {
129
-		$app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
130
-		$app->dispatch('ShareController', 'showAuthenticate');
131
-	} else {
132
-		throw new \OC\HintException('App file sharing is not enabled');
133
-	}
128
+    if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) {
129
+        $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
130
+        $app->dispatch('ShareController', 'showAuthenticate');
131
+    } else {
132
+        throw new \OC\HintException('App file sharing is not enabled');
133
+    }
134 134
 });
135 135
 $this->create('files_sharing.sharecontroller.downloadShare', '/s/{token}/download')->get()->action(function($urlParams) {
136
-	if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) {
137
-		$app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
138
-		$app->dispatch('ShareController', 'downloadShare');
139
-	} else {
140
-		throw new \OC\HintException('App file sharing is not enabled');
141
-	}
136
+    if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) {
137
+        $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
138
+        $app->dispatch('ShareController', 'downloadShare');
139
+    } else {
140
+        throw new \OC\HintException('App file sharing is not enabled');
141
+    }
142 142
 });
143 143
 $this->create('files_sharing.publicpreview.directLink', '/s/{token}/preview')->get()->action(function($urlParams) {
144
-	if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) {
145
-		$app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
146
-		$app->dispatch('PublicPreviewController', 'directLink');
147
-	} else {
148
-		throw new \OC\HintException('App file sharing is not enabled');
149
-	}
144
+    if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) {
145
+        $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
146
+        $app->dispatch('PublicPreviewController', 'directLink');
147
+    } else {
148
+        throw new \OC\HintException('App file sharing is not enabled');
149
+    }
150 150
 });
151 151
 
152 152
 // used for heartbeat
153 153
 $this->create('heartbeat', '/heartbeat')->action(function(){
154
-	// do nothing
154
+    // do nothing
155 155
 });
Please login to merge, or discard this patch.
lib/private/TemplateLayout.php 2 patches
Indentation   +282 added lines, -282 removed lines patch added patch discarded remove patch
@@ -45,286 +45,286 @@
 block discarded – undo
45 45
 
46 46
 class TemplateLayout extends \OC_Template {
47 47
 
48
-	private static $versionHash = '';
49
-
50
-	/**
51
-	 * @var \OCP\IConfig
52
-	 */
53
-	private $config;
54
-
55
-	/**
56
-	 * @param string $renderAs
57
-	 * @param string $appId application id
58
-	 */
59
-	public function __construct( $renderAs, $appId = '' ) {
60
-
61
-		// yes - should be injected ....
62
-		$this->config = \OC::$server->getConfig();
63
-
64
-
65
-		// Decide which page we show
66
-		if($renderAs == 'user') {
67
-			parent::__construct( 'core', 'layout.user' );
68
-			if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) {
69
-				$this->assign('bodyid', 'body-settings');
70
-			}else{
71
-				$this->assign('bodyid', 'body-user');
72
-			}
73
-
74
-			// Code integrity notification
75
-			$integrityChecker = \OC::$server->getIntegrityCodeChecker();
76
-			if(\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) {
77
-				\OCP\Util::addScript('core', 'integritycheck-failed-notification');
78
-			}
79
-
80
-			// Add navigation entry
81
-			$this->assign( 'application', '');
82
-			$this->assign( 'appid', $appId );
83
-			$navigation = \OC::$server->getNavigationManager()->getAll();
84
-			$this->assign( 'navigation', $navigation);
85
-			$settingsNavigation = \OC::$server->getNavigationManager()->getAll('settings');
86
-			$this->assign( 'settingsnavigation', $settingsNavigation);
87
-			foreach($navigation as $entry) {
88
-				if ($entry['active']) {
89
-					$this->assign( 'application', $entry['name'] );
90
-					break;
91
-				}
92
-			}
93
-
94
-			foreach($settingsNavigation as $entry) {
95
-				if ($entry['active']) {
96
-					$this->assign( 'application', $entry['name'] );
97
-					break;
98
-				}
99
-			}
100
-			$userDisplayName = \OC_User::getDisplayName();
101
-			$this->assign('user_displayname', $userDisplayName);
102
-			$this->assign('user_uid', \OC_User::getUser());
103
-
104
-			if (\OC_User::getUser() === false) {
105
-				$this->assign('userAvatarSet', false);
106
-			} else {
107
-				$this->assign('userAvatarSet', \OC::$server->getAvatarManager()->getAvatar(\OC_User::getUser())->exists());
108
-				$this->assign('userAvatarVersion', $this->config->getUserValue(\OC_User::getUser(), 'avatar', 'version', 0));
109
-			}
110
-
111
-			// check if app menu icons should be inverted
112
-			try {
113
-				/** @var \OCA\Theming\Util $util */
114
-				$util = \OC::$server->query(\OCA\Theming\Util::class);
115
-				$this->assign('themingInvertMenu', $util->invertTextColor(\OC::$server->getThemingDefaults()->getColorPrimary()));
116
-			} catch (\OCP\AppFramework\QueryException $e) {
117
-				$this->assign('themingInvertMenu', false);
118
-			}
119
-
120
-		} else if ($renderAs == 'error') {
121
-			parent::__construct('core', 'layout.guest', '', false);
122
-			$this->assign('bodyid', 'body-login');
123
-		} else if ($renderAs == 'guest') {
124
-			parent::__construct('core', 'layout.guest');
125
-			$this->assign('bodyid', 'body-login');
126
-		} else {
127
-			parent::__construct('core', 'layout.base');
128
-
129
-		}
130
-		// Send the language to our layouts
131
-		$lang = \OC::$server->getL10NFactory()->findLanguage();
132
-		$lang = str_replace('_', '-', $lang);
133
-		$this->assign('language', $lang);
134
-
135
-		if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
136
-			if (empty(self::$versionHash)) {
137
-				$v = \OC_App::getAppVersions();
138
-				$v['core'] = implode('.', \OCP\Util::getVersion());
139
-				self::$versionHash = substr(md5(implode(',', $v)), 0, 8);
140
-			}
141
-		} else {
142
-			self::$versionHash = md5('not installed');
143
-		}
144
-
145
-		// Add the js files
146
-		$jsFiles = self::findJavascriptFiles(\OC_Util::$scripts);
147
-		$this->assign('jsfiles', array());
148
-		if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') {
149
-			if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) {
150
-				$jsConfigHelper = new JSConfigHelper(
151
-					\OC::$server->getL10N('lib'),
152
-					\OC::$server->query(Defaults::class),
153
-					\OC::$server->getAppManager(),
154
-					\OC::$server->getSession(),
155
-					\OC::$server->getUserSession()->getUser(),
156
-					$this->config,
157
-					\OC::$server->getGroupManager(),
158
-					\OC::$server->getIniWrapper(),
159
-					\OC::$server->getURLGenerator()
160
-				);
161
-				$this->assign('inline_ocjs', $jsConfigHelper->getConfig());
162
-			} else {
163
-				$this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash]));
164
-			}
165
-		}
166
-		foreach($jsFiles as $info) {
167
-			$web = $info[1];
168
-			$file = $info[2];
169
-			$this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() );
170
-		}
171
-
172
-		try {
173
-			$pathInfo = \OC::$server->getRequest()->getPathInfo();
174
-		} catch (\Exception $e) {
175
-			$pathInfo = '';
176
-		}
177
-
178
-		// Do not initialise scss appdata until we have a fully installed instance
179
-		// Do not load scss for update, errors, installation or login page
180
-		if(\OC::$server->getSystemConfig()->getValue('installed', false)
181
-			&& !\OCP\Util::needUpgrade()
182
-			&& $pathInfo !== ''
183
-			&& !preg_match('/^\/login/', $pathInfo)
184
-			&& $renderAs !== 'error' && $renderAs !== 'guest'
185
-		) {
186
-			$cssFiles = self::findStylesheetFiles(\OC_Util::$styles);
187
-		} else {
188
-			// If we ignore the scss compiler,
189
-			// we need to load the guest css fallback
190
-			\OC_Util::addStyle('guest');
191
-			$cssFiles = self::findStylesheetFiles(\OC_Util::$styles, false);
192
-		}
193
-
194
-		$this->assign('cssfiles', array());
195
-		$this->assign('printcssfiles', []);
196
-		$this->assign('versionHash', self::$versionHash);
197
-		foreach($cssFiles as $info) {
198
-			$web = $info[1];
199
-			$file = $info[2];
200
-
201
-			if (substr($file, -strlen('print.css')) === 'print.css') {
202
-				$this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() );
203
-			} else {
204
-				$this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix($web, $file)  );
205
-			}
206
-		}
207
-	}
208
-
209
-	/**
210
-	 * @param string $path
211
- 	 * @param string $file
212
-	 * @return string
213
-	 */
214
-	protected function getVersionHashSuffix($path = false, $file = false) {
215
-		if ($this->config->getSystemValue('debug', false)) {
216
-			// allows chrome workspace mapping in debug mode
217
-			return "";
218
-		}
219
-		$themingSuffix = '';
220
-		$v = [];
221
-
222
-		if ($this->config->getSystemValue('installed', false)) {
223
-			if (\OC::$server->getAppManager()->isInstalled('theming')) {
224
-				$themingSuffix = '-' . $this->config->getAppValue('theming', 'cachebuster', '0');
225
-			}
226
-			$v = \OC_App::getAppVersions();
227
-		}
228
-
229
-		// Try the webroot path for a match
230
-		if ($path !== false && $path !== '') {
231
-			$appName = $this->getAppNamefromPath($path);
232
-			if(array_key_exists($appName, $v)) {
233
-				$appVersion = $v[$appName];
234
-				return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix;
235
-			}
236
-		}
237
-		// fallback to the file path instead
238
-		if ($file !== false && $file !== '') {
239
-			$appName = $this->getAppNamefromPath($file);
240
-			if(array_key_exists($appName, $v)) {
241
-				$appVersion = $v[$appName];
242
-				return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix;
243
-			}
244
-		}
245
-
246
-		return '?v=' . self::$versionHash . $themingSuffix;
247
-	}
248
-
249
-	/**
250
-	 * @param array $styles
251
-	 * @return array
252
-	 */
253
-	static public function findStylesheetFiles($styles, $compileScss = true) {
254
-		// Read the selected theme from the config file
255
-		$theme = \OC_Util::getTheme();
256
-
257
-		if($compileScss) {
258
-			$SCSSCacher = \OC::$server->query(SCSSCacher::class);
259
-		} else {
260
-			$SCSSCacher = null;
261
-		}
262
-
263
-		$locator = new \OC\Template\CSSResourceLocator(
264
-			\OC::$server->getLogger(),
265
-			$theme,
266
-			array( \OC::$SERVERROOT => \OC::$WEBROOT ),
267
-			array( \OC::$SERVERROOT => \OC::$WEBROOT ),
268
-			$SCSSCacher
269
-		);
270
-		$locator->find($styles);
271
-		return $locator->getResources();
272
-	}
273
-
274
-	/**
275
-	 * @param string $path
276
-	 * @return string|boolean
277
-	 */
278
-	public function getAppNamefromPath($path) {
279
-		if ($path !== '' && is_string($path)) {
280
-			$pathParts = explode('/', $path);
281
-			if ($pathParts[0] === 'css') {
282
-				// This is a scss request
283
-				return $pathParts[1];
284
-			}
285
-			return end($pathParts);
286
-		}
287
-		return false;
288
-
289
-	}
290
-
291
-	/**
292
-	 * @param array $scripts
293
-	 * @return array
294
-	 */
295
-	static public function findJavascriptFiles($scripts) {
296
-		// Read the selected theme from the config file
297
-		$theme = \OC_Util::getTheme();
298
-
299
-		$locator = new \OC\Template\JSResourceLocator(
300
-			\OC::$server->getLogger(),
301
-			$theme,
302
-			array( \OC::$SERVERROOT => \OC::$WEBROOT ),
303
-			array( \OC::$SERVERROOT => \OC::$WEBROOT ),
304
-			new JSCombiner(
305
-				\OC::$server->getAppDataDir('js'),
306
-				\OC::$server->getURLGenerator(),
307
-				\OC::$server->getMemCacheFactory()->createDistributed('JS'),
308
-				\OC::$server->getSystemConfig(),
309
-				\OC::$server->getLogger()
310
-			)
311
-			);
312
-		$locator->find($scripts);
313
-		return $locator->getResources();
314
-	}
315
-
316
-	/**
317
-	 * Converts the absolute file path to a relative path from \OC::$SERVERROOT
318
-	 * @param string $filePath Absolute path
319
-	 * @return string Relative path
320
-	 * @throws \Exception If $filePath is not under \OC::$SERVERROOT
321
-	 */
322
-	public static function convertToRelativePath($filePath) {
323
-		$relativePath = explode(\OC::$SERVERROOT, $filePath);
324
-		if(count($relativePath) !== 2) {
325
-			throw new \Exception('$filePath is not under the \OC::$SERVERROOT');
326
-		}
327
-
328
-		return $relativePath[1];
329
-	}
48
+    private static $versionHash = '';
49
+
50
+    /**
51
+     * @var \OCP\IConfig
52
+     */
53
+    private $config;
54
+
55
+    /**
56
+     * @param string $renderAs
57
+     * @param string $appId application id
58
+     */
59
+    public function __construct( $renderAs, $appId = '' ) {
60
+
61
+        // yes - should be injected ....
62
+        $this->config = \OC::$server->getConfig();
63
+
64
+
65
+        // Decide which page we show
66
+        if($renderAs == 'user') {
67
+            parent::__construct( 'core', 'layout.user' );
68
+            if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) {
69
+                $this->assign('bodyid', 'body-settings');
70
+            }else{
71
+                $this->assign('bodyid', 'body-user');
72
+            }
73
+
74
+            // Code integrity notification
75
+            $integrityChecker = \OC::$server->getIntegrityCodeChecker();
76
+            if(\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) {
77
+                \OCP\Util::addScript('core', 'integritycheck-failed-notification');
78
+            }
79
+
80
+            // Add navigation entry
81
+            $this->assign( 'application', '');
82
+            $this->assign( 'appid', $appId );
83
+            $navigation = \OC::$server->getNavigationManager()->getAll();
84
+            $this->assign( 'navigation', $navigation);
85
+            $settingsNavigation = \OC::$server->getNavigationManager()->getAll('settings');
86
+            $this->assign( 'settingsnavigation', $settingsNavigation);
87
+            foreach($navigation as $entry) {
88
+                if ($entry['active']) {
89
+                    $this->assign( 'application', $entry['name'] );
90
+                    break;
91
+                }
92
+            }
93
+
94
+            foreach($settingsNavigation as $entry) {
95
+                if ($entry['active']) {
96
+                    $this->assign( 'application', $entry['name'] );
97
+                    break;
98
+                }
99
+            }
100
+            $userDisplayName = \OC_User::getDisplayName();
101
+            $this->assign('user_displayname', $userDisplayName);
102
+            $this->assign('user_uid', \OC_User::getUser());
103
+
104
+            if (\OC_User::getUser() === false) {
105
+                $this->assign('userAvatarSet', false);
106
+            } else {
107
+                $this->assign('userAvatarSet', \OC::$server->getAvatarManager()->getAvatar(\OC_User::getUser())->exists());
108
+                $this->assign('userAvatarVersion', $this->config->getUserValue(\OC_User::getUser(), 'avatar', 'version', 0));
109
+            }
110
+
111
+            // check if app menu icons should be inverted
112
+            try {
113
+                /** @var \OCA\Theming\Util $util */
114
+                $util = \OC::$server->query(\OCA\Theming\Util::class);
115
+                $this->assign('themingInvertMenu', $util->invertTextColor(\OC::$server->getThemingDefaults()->getColorPrimary()));
116
+            } catch (\OCP\AppFramework\QueryException $e) {
117
+                $this->assign('themingInvertMenu', false);
118
+            }
119
+
120
+        } else if ($renderAs == 'error') {
121
+            parent::__construct('core', 'layout.guest', '', false);
122
+            $this->assign('bodyid', 'body-login');
123
+        } else if ($renderAs == 'guest') {
124
+            parent::__construct('core', 'layout.guest');
125
+            $this->assign('bodyid', 'body-login');
126
+        } else {
127
+            parent::__construct('core', 'layout.base');
128
+
129
+        }
130
+        // Send the language to our layouts
131
+        $lang = \OC::$server->getL10NFactory()->findLanguage();
132
+        $lang = str_replace('_', '-', $lang);
133
+        $this->assign('language', $lang);
134
+
135
+        if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
136
+            if (empty(self::$versionHash)) {
137
+                $v = \OC_App::getAppVersions();
138
+                $v['core'] = implode('.', \OCP\Util::getVersion());
139
+                self::$versionHash = substr(md5(implode(',', $v)), 0, 8);
140
+            }
141
+        } else {
142
+            self::$versionHash = md5('not installed');
143
+        }
144
+
145
+        // Add the js files
146
+        $jsFiles = self::findJavascriptFiles(\OC_Util::$scripts);
147
+        $this->assign('jsfiles', array());
148
+        if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') {
149
+            if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) {
150
+                $jsConfigHelper = new JSConfigHelper(
151
+                    \OC::$server->getL10N('lib'),
152
+                    \OC::$server->query(Defaults::class),
153
+                    \OC::$server->getAppManager(),
154
+                    \OC::$server->getSession(),
155
+                    \OC::$server->getUserSession()->getUser(),
156
+                    $this->config,
157
+                    \OC::$server->getGroupManager(),
158
+                    \OC::$server->getIniWrapper(),
159
+                    \OC::$server->getURLGenerator()
160
+                );
161
+                $this->assign('inline_ocjs', $jsConfigHelper->getConfig());
162
+            } else {
163
+                $this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash]));
164
+            }
165
+        }
166
+        foreach($jsFiles as $info) {
167
+            $web = $info[1];
168
+            $file = $info[2];
169
+            $this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() );
170
+        }
171
+
172
+        try {
173
+            $pathInfo = \OC::$server->getRequest()->getPathInfo();
174
+        } catch (\Exception $e) {
175
+            $pathInfo = '';
176
+        }
177
+
178
+        // Do not initialise scss appdata until we have a fully installed instance
179
+        // Do not load scss for update, errors, installation or login page
180
+        if(\OC::$server->getSystemConfig()->getValue('installed', false)
181
+            && !\OCP\Util::needUpgrade()
182
+            && $pathInfo !== ''
183
+            && !preg_match('/^\/login/', $pathInfo)
184
+            && $renderAs !== 'error' && $renderAs !== 'guest'
185
+        ) {
186
+            $cssFiles = self::findStylesheetFiles(\OC_Util::$styles);
187
+        } else {
188
+            // If we ignore the scss compiler,
189
+            // we need to load the guest css fallback
190
+            \OC_Util::addStyle('guest');
191
+            $cssFiles = self::findStylesheetFiles(\OC_Util::$styles, false);
192
+        }
193
+
194
+        $this->assign('cssfiles', array());
195
+        $this->assign('printcssfiles', []);
196
+        $this->assign('versionHash', self::$versionHash);
197
+        foreach($cssFiles as $info) {
198
+            $web = $info[1];
199
+            $file = $info[2];
200
+
201
+            if (substr($file, -strlen('print.css')) === 'print.css') {
202
+                $this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() );
203
+            } else {
204
+                $this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix($web, $file)  );
205
+            }
206
+        }
207
+    }
208
+
209
+    /**
210
+     * @param string $path
211
+     * @param string $file
212
+     * @return string
213
+     */
214
+    protected function getVersionHashSuffix($path = false, $file = false) {
215
+        if ($this->config->getSystemValue('debug', false)) {
216
+            // allows chrome workspace mapping in debug mode
217
+            return "";
218
+        }
219
+        $themingSuffix = '';
220
+        $v = [];
221
+
222
+        if ($this->config->getSystemValue('installed', false)) {
223
+            if (\OC::$server->getAppManager()->isInstalled('theming')) {
224
+                $themingSuffix = '-' . $this->config->getAppValue('theming', 'cachebuster', '0');
225
+            }
226
+            $v = \OC_App::getAppVersions();
227
+        }
228
+
229
+        // Try the webroot path for a match
230
+        if ($path !== false && $path !== '') {
231
+            $appName = $this->getAppNamefromPath($path);
232
+            if(array_key_exists($appName, $v)) {
233
+                $appVersion = $v[$appName];
234
+                return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix;
235
+            }
236
+        }
237
+        // fallback to the file path instead
238
+        if ($file !== false && $file !== '') {
239
+            $appName = $this->getAppNamefromPath($file);
240
+            if(array_key_exists($appName, $v)) {
241
+                $appVersion = $v[$appName];
242
+                return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix;
243
+            }
244
+        }
245
+
246
+        return '?v=' . self::$versionHash . $themingSuffix;
247
+    }
248
+
249
+    /**
250
+     * @param array $styles
251
+     * @return array
252
+     */
253
+    static public function findStylesheetFiles($styles, $compileScss = true) {
254
+        // Read the selected theme from the config file
255
+        $theme = \OC_Util::getTheme();
256
+
257
+        if($compileScss) {
258
+            $SCSSCacher = \OC::$server->query(SCSSCacher::class);
259
+        } else {
260
+            $SCSSCacher = null;
261
+        }
262
+
263
+        $locator = new \OC\Template\CSSResourceLocator(
264
+            \OC::$server->getLogger(),
265
+            $theme,
266
+            array( \OC::$SERVERROOT => \OC::$WEBROOT ),
267
+            array( \OC::$SERVERROOT => \OC::$WEBROOT ),
268
+            $SCSSCacher
269
+        );
270
+        $locator->find($styles);
271
+        return $locator->getResources();
272
+    }
273
+
274
+    /**
275
+     * @param string $path
276
+     * @return string|boolean
277
+     */
278
+    public function getAppNamefromPath($path) {
279
+        if ($path !== '' && is_string($path)) {
280
+            $pathParts = explode('/', $path);
281
+            if ($pathParts[0] === 'css') {
282
+                // This is a scss request
283
+                return $pathParts[1];
284
+            }
285
+            return end($pathParts);
286
+        }
287
+        return false;
288
+
289
+    }
290
+
291
+    /**
292
+     * @param array $scripts
293
+     * @return array
294
+     */
295
+    static public function findJavascriptFiles($scripts) {
296
+        // Read the selected theme from the config file
297
+        $theme = \OC_Util::getTheme();
298
+
299
+        $locator = new \OC\Template\JSResourceLocator(
300
+            \OC::$server->getLogger(),
301
+            $theme,
302
+            array( \OC::$SERVERROOT => \OC::$WEBROOT ),
303
+            array( \OC::$SERVERROOT => \OC::$WEBROOT ),
304
+            new JSCombiner(
305
+                \OC::$server->getAppDataDir('js'),
306
+                \OC::$server->getURLGenerator(),
307
+                \OC::$server->getMemCacheFactory()->createDistributed('JS'),
308
+                \OC::$server->getSystemConfig(),
309
+                \OC::$server->getLogger()
310
+            )
311
+            );
312
+        $locator->find($scripts);
313
+        return $locator->getResources();
314
+    }
315
+
316
+    /**
317
+     * Converts the absolute file path to a relative path from \OC::$SERVERROOT
318
+     * @param string $filePath Absolute path
319
+     * @return string Relative path
320
+     * @throws \Exception If $filePath is not under \OC::$SERVERROOT
321
+     */
322
+    public static function convertToRelativePath($filePath) {
323
+        $relativePath = explode(\OC::$SERVERROOT, $filePath);
324
+        if(count($relativePath) !== 2) {
325
+            throw new \Exception('$filePath is not under the \OC::$SERVERROOT');
326
+        }
327
+
328
+        return $relativePath[1];
329
+    }
330 330
 }
Please login to merge, or discard this patch.
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -56,44 +56,44 @@  discard block
 block discarded – undo
56 56
 	 * @param string $renderAs
57 57
 	 * @param string $appId application id
58 58
 	 */
59
-	public function __construct( $renderAs, $appId = '' ) {
59
+	public function __construct($renderAs, $appId = '') {
60 60
 
61 61
 		// yes - should be injected ....
62 62
 		$this->config = \OC::$server->getConfig();
63 63
 
64 64
 
65 65
 		// Decide which page we show
66
-		if($renderAs == 'user') {
67
-			parent::__construct( 'core', 'layout.user' );
68
-			if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) {
66
+		if ($renderAs == 'user') {
67
+			parent::__construct('core', 'layout.user');
68
+			if (in_array(\OC_App::getCurrentApp(), ['settings', 'admin', 'help']) !== false) {
69 69
 				$this->assign('bodyid', 'body-settings');
70
-			}else{
70
+			} else {
71 71
 				$this->assign('bodyid', 'body-user');
72 72
 			}
73 73
 
74 74
 			// Code integrity notification
75 75
 			$integrityChecker = \OC::$server->getIntegrityCodeChecker();
76
-			if(\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) {
76
+			if (\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) {
77 77
 				\OCP\Util::addScript('core', 'integritycheck-failed-notification');
78 78
 			}
79 79
 
80 80
 			// Add navigation entry
81
-			$this->assign( 'application', '');
82
-			$this->assign( 'appid', $appId );
81
+			$this->assign('application', '');
82
+			$this->assign('appid', $appId);
83 83
 			$navigation = \OC::$server->getNavigationManager()->getAll();
84
-			$this->assign( 'navigation', $navigation);
84
+			$this->assign('navigation', $navigation);
85 85
 			$settingsNavigation = \OC::$server->getNavigationManager()->getAll('settings');
86
-			$this->assign( 'settingsnavigation', $settingsNavigation);
87
-			foreach($navigation as $entry) {
86
+			$this->assign('settingsnavigation', $settingsNavigation);
87
+			foreach ($navigation as $entry) {
88 88
 				if ($entry['active']) {
89
-					$this->assign( 'application', $entry['name'] );
89
+					$this->assign('application', $entry['name']);
90 90
 					break;
91 91
 				}
92 92
 			}
93 93
 
94
-			foreach($settingsNavigation as $entry) {
94
+			foreach ($settingsNavigation as $entry) {
95 95
 				if ($entry['active']) {
96
-					$this->assign( 'application', $entry['name'] );
96
+					$this->assign('application', $entry['name']);
97 97
 					break;
98 98
 				}
99 99
 			}
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 		$lang = str_replace('_', '-', $lang);
133 133
 		$this->assign('language', $lang);
134 134
 
135
-		if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
135
+		if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
136 136
 			if (empty(self::$versionHash)) {
137 137
 				$v = \OC_App::getAppVersions();
138 138
 				$v['core'] = implode('.', \OCP\Util::getVersion());
@@ -163,10 +163,10 @@  discard block
 block discarded – undo
163 163
 				$this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash]));
164 164
 			}
165 165
 		}
166
-		foreach($jsFiles as $info) {
166
+		foreach ($jsFiles as $info) {
167 167
 			$web = $info[1];
168 168
 			$file = $info[2];
169
-			$this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() );
169
+			$this->append('jsfiles', $web.'/'.$file.$this->getVersionHashSuffix());
170 170
 		}
171 171
 
172 172
 		try {
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
 
178 178
 		// Do not initialise scss appdata until we have a fully installed instance
179 179
 		// Do not load scss for update, errors, installation or login page
180
-		if(\OC::$server->getSystemConfig()->getValue('installed', false)
180
+		if (\OC::$server->getSystemConfig()->getValue('installed', false)
181 181
 			&& !\OCP\Util::needUpgrade()
182 182
 			&& $pathInfo !== ''
183 183
 			&& !preg_match('/^\/login/', $pathInfo)
@@ -194,14 +194,14 @@  discard block
 block discarded – undo
194 194
 		$this->assign('cssfiles', array());
195 195
 		$this->assign('printcssfiles', []);
196 196
 		$this->assign('versionHash', self::$versionHash);
197
-		foreach($cssFiles as $info) {
197
+		foreach ($cssFiles as $info) {
198 198
 			$web = $info[1];
199 199
 			$file = $info[2];
200 200
 
201 201
 			if (substr($file, -strlen('print.css')) === 'print.css') {
202
-				$this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() );
202
+				$this->append('printcssfiles', $web.'/'.$file.$this->getVersionHashSuffix());
203 203
 			} else {
204
-				$this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix($web, $file)  );
204
+				$this->append('cssfiles', $web.'/'.$file.$this->getVersionHashSuffix($web, $file));
205 205
 			}
206 206
 		}
207 207
 	}
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
 
222 222
 		if ($this->config->getSystemValue('installed', false)) {
223 223
 			if (\OC::$server->getAppManager()->isInstalled('theming')) {
224
-				$themingSuffix = '-' . $this->config->getAppValue('theming', 'cachebuster', '0');
224
+				$themingSuffix = '-'.$this->config->getAppValue('theming', 'cachebuster', '0');
225 225
 			}
226 226
 			$v = \OC_App::getAppVersions();
227 227
 		}
@@ -229,21 +229,21 @@  discard block
 block discarded – undo
229 229
 		// Try the webroot path for a match
230 230
 		if ($path !== false && $path !== '') {
231 231
 			$appName = $this->getAppNamefromPath($path);
232
-			if(array_key_exists($appName, $v)) {
232
+			if (array_key_exists($appName, $v)) {
233 233
 				$appVersion = $v[$appName];
234
-				return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix;
234
+				return '?v='.substr(md5($appVersion), 0, 8).$themingSuffix;
235 235
 			}
236 236
 		}
237 237
 		// fallback to the file path instead
238 238
 		if ($file !== false && $file !== '') {
239 239
 			$appName = $this->getAppNamefromPath($file);
240
-			if(array_key_exists($appName, $v)) {
240
+			if (array_key_exists($appName, $v)) {
241 241
 				$appVersion = $v[$appName];
242
-				return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix;
242
+				return '?v='.substr(md5($appVersion), 0, 8).$themingSuffix;
243 243
 			}
244 244
 		}
245 245
 
246
-		return '?v=' . self::$versionHash . $themingSuffix;
246
+		return '?v='.self::$versionHash.$themingSuffix;
247 247
 	}
248 248
 
249 249
 	/**
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
 		// Read the selected theme from the config file
255 255
 		$theme = \OC_Util::getTheme();
256 256
 
257
-		if($compileScss) {
257
+		if ($compileScss) {
258 258
 			$SCSSCacher = \OC::$server->query(SCSSCacher::class);
259 259
 		} else {
260 260
 			$SCSSCacher = null;
@@ -263,8 +263,8 @@  discard block
 block discarded – undo
263 263
 		$locator = new \OC\Template\CSSResourceLocator(
264 264
 			\OC::$server->getLogger(),
265 265
 			$theme,
266
-			array( \OC::$SERVERROOT => \OC::$WEBROOT ),
267
-			array( \OC::$SERVERROOT => \OC::$WEBROOT ),
266
+			array(\OC::$SERVERROOT => \OC::$WEBROOT),
267
+			array(\OC::$SERVERROOT => \OC::$WEBROOT),
268 268
 			$SCSSCacher
269 269
 		);
270 270
 		$locator->find($styles);
@@ -299,8 +299,8 @@  discard block
 block discarded – undo
299 299
 		$locator = new \OC\Template\JSResourceLocator(
300 300
 			\OC::$server->getLogger(),
301 301
 			$theme,
302
-			array( \OC::$SERVERROOT => \OC::$WEBROOT ),
303
-			array( \OC::$SERVERROOT => \OC::$WEBROOT ),
302
+			array(\OC::$SERVERROOT => \OC::$WEBROOT),
303
+			array(\OC::$SERVERROOT => \OC::$WEBROOT),
304 304
 			new JSCombiner(
305 305
 				\OC::$server->getAppDataDir('js'),
306 306
 				\OC::$server->getURLGenerator(),
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
 	 */
322 322
 	public static function convertToRelativePath($filePath) {
323 323
 		$relativePath = explode(\OC::$SERVERROOT, $filePath);
324
-		if(count($relativePath) !== 2) {
324
+		if (count($relativePath) !== 2) {
325 325
 			throw new \Exception('$filePath is not under the \OC::$SERVERROOT');
326 326
 		}
327 327
 
Please login to merge, or discard this patch.
core/Controller/NavigationController.php 1 patch
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -30,63 +30,63 @@
 block discarded – undo
30 30
 
31 31
 class NavigationController extends OCSController {
32 32
 
33
-	/** @var INavigationManager */
34
-	private $navigationManager;
33
+    /** @var INavigationManager */
34
+    private $navigationManager;
35 35
 
36
-	/** @var IURLGenerator */
37
-	private $urlGenerator;
36
+    /** @var IURLGenerator */
37
+    private $urlGenerator;
38 38
 
39
-	public function __construct(string $appName, IRequest $request, INavigationManager $navigationManager, IURLGenerator $urlGenerator) {
40
-		parent::__construct($appName, $request);
41
-		$this->navigationManager = $navigationManager;
42
-		$this->urlGenerator = $urlGenerator;
43
-	}
39
+    public function __construct(string $appName, IRequest $request, INavigationManager $navigationManager, IURLGenerator $urlGenerator) {
40
+        parent::__construct($appName, $request);
41
+        $this->navigationManager = $navigationManager;
42
+        $this->urlGenerator = $urlGenerator;
43
+    }
44 44
 
45
-	/**
46
-	 * @NoAdminRequired
47
-	 * @NoCSRFRequired
48
-	 *
49
-	 * @param bool $absolute
50
-	 * @return DataResponse
51
-	 */
52
-	public function getAppsNavigation(bool $absolute = false): DataResponse {
53
-		$navigation = $this->navigationManager->getAll();
54
-		if ($absolute) {
55
-			$navigation = $this->rewriteToAbsoluteUrls($navigation);
56
-		}
57
-		return new DataResponse($navigation);
58
-	}
45
+    /**
46
+     * @NoAdminRequired
47
+     * @NoCSRFRequired
48
+     *
49
+     * @param bool $absolute
50
+     * @return DataResponse
51
+     */
52
+    public function getAppsNavigation(bool $absolute = false): DataResponse {
53
+        $navigation = $this->navigationManager->getAll();
54
+        if ($absolute) {
55
+            $navigation = $this->rewriteToAbsoluteUrls($navigation);
56
+        }
57
+        return new DataResponse($navigation);
58
+    }
59 59
 
60
-	/**
61
-	 * @NoAdminRequired
62
-	 * @NoCSRFRequired
63
-	 *
64
-	 * @param bool $absolute
65
-	 * @return DataResponse
66
-	 */
67
-	public function getSettingsNavigation(bool $absolute = false): DataResponse {
68
-		$navigation = $this->navigationManager->getAll('settings');
69
-		if ($absolute) {
70
-			$navigation = $this->rewriteToAbsoluteUrls($navigation);
71
-		}
72
-		return new DataResponse($navigation);
73
-	}
60
+    /**
61
+     * @NoAdminRequired
62
+     * @NoCSRFRequired
63
+     *
64
+     * @param bool $absolute
65
+     * @return DataResponse
66
+     */
67
+    public function getSettingsNavigation(bool $absolute = false): DataResponse {
68
+        $navigation = $this->navigationManager->getAll('settings');
69
+        if ($absolute) {
70
+            $navigation = $this->rewriteToAbsoluteUrls($navigation);
71
+        }
72
+        return new DataResponse($navigation);
73
+    }
74 74
 
75
-	/**
76
-	 * Rewrite href attribute of navigation entries to an absolute URL
77
-	 *
78
-	 * @param array $navigation
79
-	 * @return array
80
-	 */
81
-	private function rewriteToAbsoluteUrls(array $navigation): array {
82
-		foreach ($navigation as &$entry) {
83
-			if (0 !== strpos($entry['href'], $this->urlGenerator->getBaseUrl())) {
84
-				$entry['href'] = $this->urlGenerator->getAbsoluteURL($entry['href']);
85
-			}
86
-			if (0 !== strpos($entry['icon'], $this->urlGenerator->getBaseUrl())) {
87
-				$entry['icon'] = $this->urlGenerator->getAbsoluteURL($entry['icon']);
88
-			}
89
-		}
90
-		return $navigation;
91
-	}
75
+    /**
76
+     * Rewrite href attribute of navigation entries to an absolute URL
77
+     *
78
+     * @param array $navigation
79
+     * @return array
80
+     */
81
+    private function rewriteToAbsoluteUrls(array $navigation): array {
82
+        foreach ($navigation as &$entry) {
83
+            if (0 !== strpos($entry['href'], $this->urlGenerator->getBaseUrl())) {
84
+                $entry['href'] = $this->urlGenerator->getAbsoluteURL($entry['href']);
85
+            }
86
+            if (0 !== strpos($entry['icon'], $this->urlGenerator->getBaseUrl())) {
87
+                $entry['icon'] = $this->urlGenerator->getAbsoluteURL($entry['icon']);
88
+            }
89
+        }
90
+        return $navigation;
91
+    }
92 92
 }
Please login to merge, or discard this patch.
lib/public/INavigationManager.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -39,31 +39,31 @@
 block discarded – undo
39 39
  * @since 6.0.0
40 40
  */
41 41
 interface INavigationManager {
42
-	/**
43
-	 * Creates a new navigation entry
44
-	 *
45
-	 * @param array|\Closure $entry Array containing: id, name, order, icon and href key
46
-	 *					The use of a closure is preferred, because it will avoid
47
-	 * 					loading the routing of your app, unless required.
48
-	 * @return void
49
-	 * @since 6.0.0
50
-	 */
51
-	public function add($entry);
42
+    /**
43
+     * Creates a new navigation entry
44
+     *
45
+     * @param array|\Closure $entry Array containing: id, name, order, icon and href key
46
+     *					The use of a closure is preferred, because it will avoid
47
+     * 					loading the routing of your app, unless required.
48
+     * @return void
49
+     * @since 6.0.0
50
+     */
51
+    public function add($entry);
52 52
 
53
-	/**
54
-	 * Sets the current navigation entry of the currently running app
55
-	 * @param string $appId id of the app entry to activate (from added $entry)
56
-	 * @return void
57
-	 * @since 6.0.0
58
-	 */
59
-	public function setActiveEntry($appId);
53
+    /**
54
+     * Sets the current navigation entry of the currently running app
55
+     * @param string $appId id of the app entry to activate (from added $entry)
56
+     * @return void
57
+     * @since 6.0.0
58
+     */
59
+    public function setActiveEntry($appId);
60 60
 
61
-	/**
62
-	 * Get a list of navigation entries
63
-	 *
64
-	 * @param string $type type of the navigation entries
65
-	 * @return array
66
-	 * @since 14.0.0
67
-	 */
68
-	public function getAll(string $type = 'link'): array;
61
+    /**
62
+     * Get a list of navigation entries
63
+     *
64
+     * @param string $type type of the navigation entries
65
+     * @return array
66
+     * @since 14.0.0
67
+     */
68
+    public function getAll(string $type = 'link'): array;
69 69
 }
Please login to merge, or discard this patch.
lib/private/NavigationManager.php 1 patch
Indentation   +260 added lines, -260 removed lines patch added patch discarded remove patch
@@ -44,290 +44,290 @@
 block discarded – undo
44 44
  */
45 45
 
46 46
 class NavigationManager implements INavigationManager {
47
-	protected $entries = [];
48
-	protected $closureEntries = [];
49
-	protected $activeEntry;
50
-	/** @var bool */
51
-	protected $init = false;
52
-	/** @var IAppManager|AppManager */
53
-	protected $appManager;
54
-	/** @var IURLGenerator */
55
-	private $urlGenerator;
56
-	/** @var IFactory */
57
-	private $l10nFac;
58
-	/** @var IUserSession */
59
-	private $userSession;
60
-	/** @var IGroupManager|Manager */
61
-	private $groupManager;
62
-	/** @var IConfig */
63
-	private $config;
47
+    protected $entries = [];
48
+    protected $closureEntries = [];
49
+    protected $activeEntry;
50
+    /** @var bool */
51
+    protected $init = false;
52
+    /** @var IAppManager|AppManager */
53
+    protected $appManager;
54
+    /** @var IURLGenerator */
55
+    private $urlGenerator;
56
+    /** @var IFactory */
57
+    private $l10nFac;
58
+    /** @var IUserSession */
59
+    private $userSession;
60
+    /** @var IGroupManager|Manager */
61
+    private $groupManager;
62
+    /** @var IConfig */
63
+    private $config;
64 64
 
65
-	public function __construct(IAppManager $appManager,
66
-						 IURLGenerator $urlGenerator,
67
-						 IFactory $l10nFac,
68
-						 IUserSession $userSession,
69
-						 IGroupManager $groupManager,
70
-						 IConfig $config) {
71
-		$this->appManager = $appManager;
72
-		$this->urlGenerator = $urlGenerator;
73
-		$this->l10nFac = $l10nFac;
74
-		$this->userSession = $userSession;
75
-		$this->groupManager = $groupManager;
76
-		$this->config = $config;
77
-	}
65
+    public function __construct(IAppManager $appManager,
66
+                            IURLGenerator $urlGenerator,
67
+                            IFactory $l10nFac,
68
+                            IUserSession $userSession,
69
+                            IGroupManager $groupManager,
70
+                            IConfig $config) {
71
+        $this->appManager = $appManager;
72
+        $this->urlGenerator = $urlGenerator;
73
+        $this->l10nFac = $l10nFac;
74
+        $this->userSession = $userSession;
75
+        $this->groupManager = $groupManager;
76
+        $this->config = $config;
77
+    }
78 78
 
79
-	/**
80
-	 * Creates a new navigation entry
81
-	 *
82
-	 * @param array|\Closure $entry Array containing: id, name, order, icon and href key
83
-	 *					The use of a closure is preferred, because it will avoid
84
-	 * 					loading the routing of your app, unless required.
85
-	 * @return void
86
-	 */
87
-	public function add($entry) {
88
-		if ($entry instanceof \Closure) {
89
-			$this->closureEntries[] = $entry;
90
-			return;
91
-		}
79
+    /**
80
+     * Creates a new navigation entry
81
+     *
82
+     * @param array|\Closure $entry Array containing: id, name, order, icon and href key
83
+     *					The use of a closure is preferred, because it will avoid
84
+     * 					loading the routing of your app, unless required.
85
+     * @return void
86
+     */
87
+    public function add($entry) {
88
+        if ($entry instanceof \Closure) {
89
+            $this->closureEntries[] = $entry;
90
+            return;
91
+        }
92 92
 
93
-		$entry['active'] = false;
94
-		if(!isset($entry['icon'])) {
95
-			$entry['icon'] = '';
96
-		}
97
-		if(!isset($entry['classes'])) {
98
-			$entry['classes'] = '';
99
-		}
100
-		if(!isset($entry['type'])) {
101
-			$entry['type'] = 'link';
102
-		}
103
-		$this->entries[] = $entry;
104
-	}
93
+        $entry['active'] = false;
94
+        if(!isset($entry['icon'])) {
95
+            $entry['icon'] = '';
96
+        }
97
+        if(!isset($entry['classes'])) {
98
+            $entry['classes'] = '';
99
+        }
100
+        if(!isset($entry['type'])) {
101
+            $entry['type'] = 'link';
102
+        }
103
+        $this->entries[] = $entry;
104
+    }
105 105
 
106
-	/**
107
-	 * Get a list of navigation entries
108
-	 *
109
-	 * @param string $type type of the navigation entries
110
-	 * @return array
111
-	 */
112
-	public function getAll(string $type = 'link'): array {
113
-		$this->init();
114
-		foreach ($this->closureEntries as $c) {
115
-			$this->add($c());
116
-		}
117
-		$this->closureEntries = array();
106
+    /**
107
+     * Get a list of navigation entries
108
+     *
109
+     * @param string $type type of the navigation entries
110
+     * @return array
111
+     */
112
+    public function getAll(string $type = 'link'): array {
113
+        $this->init();
114
+        foreach ($this->closureEntries as $c) {
115
+            $this->add($c());
116
+        }
117
+        $this->closureEntries = array();
118 118
 
119
-		$result = $this->entries;
120
-		if ($type !== 'all') {
121
-			$result = array_filter($this->entries, function($entry) use ($type) {
122
-				return $entry['type'] === $type;
123
-			});
124
-		}
119
+        $result = $this->entries;
120
+        if ($type !== 'all') {
121
+            $result = array_filter($this->entries, function($entry) use ($type) {
122
+                return $entry['type'] === $type;
123
+            });
124
+        }
125 125
 
126
-		return $this->proceedNavigation($result);
127
-	}
126
+        return $this->proceedNavigation($result);
127
+    }
128 128
 
129
-	/**
130
-	 * Sort navigation entries by order, name and set active flag
131
-	 *
132
-	 * @param array $list
133
-	 * @return array
134
-	 */
135
-	private function proceedNavigation(array $list): array {
136
-		usort($list, function($a, $b) {
137
-			if (isset($a['order']) && isset($b['order'])) {
138
-				return ($a['order'] < $b['order']) ? -1 : 1;
139
-			} else if (isset($a['order']) || isset($b['order'])) {
140
-				return isset($a['order']) ? -1 : 1;
141
-			} else {
142
-				return ($a['name'] < $b['name']) ? -1 : 1;
143
-			}
144
-		});
129
+    /**
130
+     * Sort navigation entries by order, name and set active flag
131
+     *
132
+     * @param array $list
133
+     * @return array
134
+     */
135
+    private function proceedNavigation(array $list): array {
136
+        usort($list, function($a, $b) {
137
+            if (isset($a['order']) && isset($b['order'])) {
138
+                return ($a['order'] < $b['order']) ? -1 : 1;
139
+            } else if (isset($a['order']) || isset($b['order'])) {
140
+                return isset($a['order']) ? -1 : 1;
141
+            } else {
142
+                return ($a['name'] < $b['name']) ? -1 : 1;
143
+            }
144
+        });
145 145
 
146
-		$activeApp = $this->getActiveEntry();
147
-		if ($activeApp !== null) {
148
-			foreach ($list as $index => &$navEntry) {
149
-				if ($navEntry['id'] == $activeApp) {
150
-					$navEntry['active'] = true;
151
-				} else {
152
-					$navEntry['active'] = false;
153
-				}
154
-			}
155
-			unset($navEntry);
156
-		}
146
+        $activeApp = $this->getActiveEntry();
147
+        if ($activeApp !== null) {
148
+            foreach ($list as $index => &$navEntry) {
149
+                if ($navEntry['id'] == $activeApp) {
150
+                    $navEntry['active'] = true;
151
+                } else {
152
+                    $navEntry['active'] = false;
153
+                }
154
+            }
155
+            unset($navEntry);
156
+        }
157 157
 
158
-		return $list;
159
-	}
158
+        return $list;
159
+    }
160 160
 
161 161
 
162
-	/**
163
-	 * removes all the entries
164
-	 */
165
-	public function clear($loadDefaultLinks = true) {
166
-		$this->entries = [];
167
-		$this->closureEntries = [];
168
-		$this->init = !$loadDefaultLinks;
169
-	}
162
+    /**
163
+     * removes all the entries
164
+     */
165
+    public function clear($loadDefaultLinks = true) {
166
+        $this->entries = [];
167
+        $this->closureEntries = [];
168
+        $this->init = !$loadDefaultLinks;
169
+    }
170 170
 
171
-	/**
172
-	 * Sets the current navigation entry of the currently running app
173
-	 * @param string $id of the app entry to activate (from added $entry)
174
-	 */
175
-	public function setActiveEntry($id) {
176
-		$this->activeEntry = $id;
177
-	}
171
+    /**
172
+     * Sets the current navigation entry of the currently running app
173
+     * @param string $id of the app entry to activate (from added $entry)
174
+     */
175
+    public function setActiveEntry($id) {
176
+        $this->activeEntry = $id;
177
+    }
178 178
 
179
-	/**
180
-	 * gets the active Menu entry
181
-	 * @return string id or empty string
182
-	 *
183
-	 * This function returns the id of the active navigation entry (set by
184
-	 * setActiveEntry
185
-	 */
186
-	public function getActiveEntry() {
187
-		return $this->activeEntry;
188
-	}
179
+    /**
180
+     * gets the active Menu entry
181
+     * @return string id or empty string
182
+     *
183
+     * This function returns the id of the active navigation entry (set by
184
+     * setActiveEntry
185
+     */
186
+    public function getActiveEntry() {
187
+        return $this->activeEntry;
188
+    }
189 189
 
190
-	private function init() {
191
-		if ($this->init) {
192
-			return;
193
-		}
194
-		$this->init = true;
190
+    private function init() {
191
+        if ($this->init) {
192
+            return;
193
+        }
194
+        $this->init = true;
195 195
 
196
-		$l = $this->l10nFac->get('lib');
197
-		if ($this->config->getSystemValue('knowledgebaseenabled', true)) {
198
-			$this->add([
199
-				'type' => 'settings',
200
-				'id' => 'help',
201
-				'order' => 5,
202
-				'href' => $this->urlGenerator->linkToRoute('settings_help'),
203
-				'name' => $l->t('Help'),
204
-				'icon' => $this->urlGenerator->imagePath('settings', 'help.svg'),
205
-			]);
206
-		}
196
+        $l = $this->l10nFac->get('lib');
197
+        if ($this->config->getSystemValue('knowledgebaseenabled', true)) {
198
+            $this->add([
199
+                'type' => 'settings',
200
+                'id' => 'help',
201
+                'order' => 5,
202
+                'href' => $this->urlGenerator->linkToRoute('settings_help'),
203
+                'name' => $l->t('Help'),
204
+                'icon' => $this->urlGenerator->imagePath('settings', 'help.svg'),
205
+            ]);
206
+        }
207 207
 
208
-		if ($this->userSession->isLoggedIn()) {
209
-			if ($this->isAdmin()) {
210
-				// App management
211
-				$this->add([
212
-					'type' => 'settings',
213
-					'id' => 'core_apps',
214
-					'order' => 3,
215
-					'href' => $this->urlGenerator->linkToRoute('settings.AppSettings.viewApps'),
216
-					'icon' => $this->urlGenerator->imagePath('settings', 'apps.svg'),
217
-					'name' => $l->t('Apps'),
218
-				]);
219
-			}
208
+        if ($this->userSession->isLoggedIn()) {
209
+            if ($this->isAdmin()) {
210
+                // App management
211
+                $this->add([
212
+                    'type' => 'settings',
213
+                    'id' => 'core_apps',
214
+                    'order' => 3,
215
+                    'href' => $this->urlGenerator->linkToRoute('settings.AppSettings.viewApps'),
216
+                    'icon' => $this->urlGenerator->imagePath('settings', 'apps.svg'),
217
+                    'name' => $l->t('Apps'),
218
+                ]);
219
+            }
220 220
 
221
-			// Personal and (if applicable) admin settings
222
-			$this->add([
223
-				'type' => 'settings',
224
-				'id' => 'settings',
225
-				'order' => 1,
226
-				'href' => $this->urlGenerator->linkToRoute('settings.PersonalSettings.index'),
227
-				'name' => $l->t('Settings'),
228
-				'icon' => $this->urlGenerator->imagePath('settings', 'admin.svg'),
229
-			]);
221
+            // Personal and (if applicable) admin settings
222
+            $this->add([
223
+                'type' => 'settings',
224
+                'id' => 'settings',
225
+                'order' => 1,
226
+                'href' => $this->urlGenerator->linkToRoute('settings.PersonalSettings.index'),
227
+                'name' => $l->t('Settings'),
228
+                'icon' => $this->urlGenerator->imagePath('settings', 'admin.svg'),
229
+            ]);
230 230
 
231
-			$logoutUrl = \OC_User::getLogoutUrl($this->urlGenerator);
232
-			if($logoutUrl !== '') {
233
-				// Logout
234
-				$this->add([
235
-					'type' => 'settings',
236
-					'id' => 'logout',
237
-					'order' => 99999,
238
-					'href' => $logoutUrl,
239
-					'name' => $l->t('Log out'),
240
-					'icon' => $this->urlGenerator->imagePath('core', 'actions/logout.svg'),
241
-				]);
242
-			}
231
+            $logoutUrl = \OC_User::getLogoutUrl($this->urlGenerator);
232
+            if($logoutUrl !== '') {
233
+                // Logout
234
+                $this->add([
235
+                    'type' => 'settings',
236
+                    'id' => 'logout',
237
+                    'order' => 99999,
238
+                    'href' => $logoutUrl,
239
+                    'name' => $l->t('Log out'),
240
+                    'icon' => $this->urlGenerator->imagePath('core', 'actions/logout.svg'),
241
+                ]);
242
+            }
243 243
 
244
-			if ($this->isSubadmin()) {
245
-				// User management
246
-				$this->add([
247
-					'type' => 'settings',
248
-					'id' => 'core_users',
249
-					'order' => 4,
250
-					'href' => $this->urlGenerator->linkToRoute('settings_users'),
251
-					'name' => $l->t('Users'),
252
-					'icon' => $this->urlGenerator->imagePath('settings', 'users.svg'),
253
-				]);
254
-			}
255
-		}
244
+            if ($this->isSubadmin()) {
245
+                // User management
246
+                $this->add([
247
+                    'type' => 'settings',
248
+                    'id' => 'core_users',
249
+                    'order' => 4,
250
+                    'href' => $this->urlGenerator->linkToRoute('settings_users'),
251
+                    'name' => $l->t('Users'),
252
+                    'icon' => $this->urlGenerator->imagePath('settings', 'users.svg'),
253
+                ]);
254
+            }
255
+        }
256 256
 
257
-		if ($this->appManager === 'null') {
258
-			return;
259
-		}
257
+        if ($this->appManager === 'null') {
258
+            return;
259
+        }
260 260
 
261
-		if ($this->userSession->isLoggedIn()) {
262
-			$apps = $this->appManager->getEnabledAppsForUser($this->userSession->getUser());
263
-		} else {
264
-			$apps = $this->appManager->getInstalledApps();
265
-		}
261
+        if ($this->userSession->isLoggedIn()) {
262
+            $apps = $this->appManager->getEnabledAppsForUser($this->userSession->getUser());
263
+        } else {
264
+            $apps = $this->appManager->getInstalledApps();
265
+        }
266 266
 
267
-		foreach ($apps as $app) {
268
-			if (!$this->userSession->isLoggedIn() && !$this->appManager->isEnabledForUser($app, $this->userSession->getUser())) {
269
-				continue;
270
-			}
267
+        foreach ($apps as $app) {
268
+            if (!$this->userSession->isLoggedIn() && !$this->appManager->isEnabledForUser($app, $this->userSession->getUser())) {
269
+                continue;
270
+            }
271 271
 
272
-			// load plugins and collections from info.xml
273
-			$info = $this->appManager->getAppInfo($app);
274
-			if (empty($info['navigations'])) {
275
-				continue;
276
-			}
277
-			foreach ($info['navigations'] as $nav) {
278
-				if (!isset($nav['name'])) {
279
-					continue;
280
-				}
281
-				if (!isset($nav['route'])) {
282
-					continue;
283
-				}
284
-				$role = isset($nav['@attributes']['role']) ? $nav['@attributes']['role'] : 'all';
285
-				if ($role === 'admin' && !$this->isAdmin()) {
286
-					continue;
287
-				}
288
-				$l = $this->l10nFac->get($app);
289
-				$id = isset($nav['id']) ? $nav['id'] : $app;
290
-				$order = isset($nav['order']) ? $nav['order'] : 100;
291
-				$type = isset($nav['type']) ? $nav['type'] : 'link';
292
-				$route = $this->urlGenerator->linkToRoute($nav['route']);
293
-				$icon = isset($nav['icon']) ? $nav['icon'] : 'app.svg';
294
-				foreach ([$icon, "$app.svg"] as $i) {
295
-					try {
296
-						$icon = $this->urlGenerator->imagePath($app, $i);
297
-						break;
298
-					} catch (\RuntimeException $ex) {
299
-						// no icon? - ignore it then
300
-					}
301
-				}
302
-				if ($icon === null) {
303
-					$icon = $this->urlGenerator->imagePath('core', 'default-app-icon');
304
-				}
272
+            // load plugins and collections from info.xml
273
+            $info = $this->appManager->getAppInfo($app);
274
+            if (empty($info['navigations'])) {
275
+                continue;
276
+            }
277
+            foreach ($info['navigations'] as $nav) {
278
+                if (!isset($nav['name'])) {
279
+                    continue;
280
+                }
281
+                if (!isset($nav['route'])) {
282
+                    continue;
283
+                }
284
+                $role = isset($nav['@attributes']['role']) ? $nav['@attributes']['role'] : 'all';
285
+                if ($role === 'admin' && !$this->isAdmin()) {
286
+                    continue;
287
+                }
288
+                $l = $this->l10nFac->get($app);
289
+                $id = isset($nav['id']) ? $nav['id'] : $app;
290
+                $order = isset($nav['order']) ? $nav['order'] : 100;
291
+                $type = isset($nav['type']) ? $nav['type'] : 'link';
292
+                $route = $this->urlGenerator->linkToRoute($nav['route']);
293
+                $icon = isset($nav['icon']) ? $nav['icon'] : 'app.svg';
294
+                foreach ([$icon, "$app.svg"] as $i) {
295
+                    try {
296
+                        $icon = $this->urlGenerator->imagePath($app, $i);
297
+                        break;
298
+                    } catch (\RuntimeException $ex) {
299
+                        // no icon? - ignore it then
300
+                    }
301
+                }
302
+                if ($icon === null) {
303
+                    $icon = $this->urlGenerator->imagePath('core', 'default-app-icon');
304
+                }
305 305
 
306
-				$this->add([
307
-					'id' => $id,
308
-					'order' => $order,
309
-					'href' => $route,
310
-					'icon' => $icon,
311
-					'type' => $type,
312
-					'name' => $l->t($nav['name']),
313
-				]);
314
-			}
315
-		}
316
-	}
306
+                $this->add([
307
+                    'id' => $id,
308
+                    'order' => $order,
309
+                    'href' => $route,
310
+                    'icon' => $icon,
311
+                    'type' => $type,
312
+                    'name' => $l->t($nav['name']),
313
+                ]);
314
+            }
315
+        }
316
+    }
317 317
 
318
-	private function isAdmin() {
319
-		$user = $this->userSession->getUser();
320
-		if ($user !== null) {
321
-			return $this->groupManager->isAdmin($user->getUID());
322
-		}
323
-		return false;
324
-	}
318
+    private function isAdmin() {
319
+        $user = $this->userSession->getUser();
320
+        if ($user !== null) {
321
+            return $this->groupManager->isAdmin($user->getUID());
322
+        }
323
+        return false;
324
+    }
325 325
 
326
-	private function isSubadmin() {
327
-		$user = $this->userSession->getUser();
328
-		if ($user !== null) {
329
-			return $this->groupManager->getSubAdmin()->isSubAdmin($user);
330
-		}
331
-		return false;
332
-	}
326
+    private function isSubadmin() {
327
+        $user = $this->userSession->getUser();
328
+        if ($user !== null) {
329
+            return $this->groupManager->getSubAdmin()->isSubAdmin($user);
330
+        }
331
+        return false;
332
+    }
333 333
 }
Please login to merge, or discard this patch.
lib/private/legacy/app.php 1 patch
Indentation   +1070 added lines, -1070 removed lines patch added patch discarded remove patch
@@ -62,1074 +62,1074 @@
 block discarded – undo
62 62
  * upgrading and removing apps.
63 63
  */
64 64
 class OC_App {
65
-	static private $adminForms = array();
66
-	static private $personalForms = array();
67
-	static private $appTypes = array();
68
-	static private $loadedApps = array();
69
-	static private $altLogin = array();
70
-	static private $alreadyRegistered = [];
71
-	const officialApp = 200;
72
-
73
-	/**
74
-	 * clean the appId
75
-	 *
76
-	 * @param string|boolean $app AppId that needs to be cleaned
77
-	 * @return string
78
-	 */
79
-	public static function cleanAppId($app) {
80
-		return str_replace(array('\0', '/', '\\', '..'), '', $app);
81
-	}
82
-
83
-	/**
84
-	 * Check if an app is loaded
85
-	 *
86
-	 * @param string $app
87
-	 * @return bool
88
-	 */
89
-	public static function isAppLoaded($app) {
90
-		return in_array($app, self::$loadedApps, true);
91
-	}
92
-
93
-	/**
94
-	 * loads all apps
95
-	 *
96
-	 * @param string[] | string | null $types
97
-	 * @return bool
98
-	 *
99
-	 * This function walks through the ownCloud directory and loads all apps
100
-	 * it can find. A directory contains an app if the file /appinfo/info.xml
101
-	 * exists.
102
-	 *
103
-	 * if $types is set, only apps of those types will be loaded
104
-	 */
105
-	public static function loadApps($types = null) {
106
-		if (\OC::$server->getSystemConfig()->getValue('maintenance', false)) {
107
-			return false;
108
-		}
109
-		// Load the enabled apps here
110
-		$apps = self::getEnabledApps();
111
-
112
-		// Add each apps' folder as allowed class path
113
-		foreach($apps as $app) {
114
-			$path = self::getAppPath($app);
115
-			if($path !== false) {
116
-				self::registerAutoloading($app, $path);
117
-			}
118
-		}
119
-
120
-		// prevent app.php from printing output
121
-		ob_start();
122
-		foreach ($apps as $app) {
123
-			if ((is_null($types) or self::isType($app, $types)) && !in_array($app, self::$loadedApps)) {
124
-				self::loadApp($app);
125
-			}
126
-		}
127
-		ob_end_clean();
128
-
129
-		return true;
130
-	}
131
-
132
-	/**
133
-	 * load a single app
134
-	 *
135
-	 * @param string $app
136
-	 * @throws Exception
137
-	 */
138
-	public static function loadApp($app) {
139
-		self::$loadedApps[] = $app;
140
-		$appPath = self::getAppPath($app);
141
-		if($appPath === false) {
142
-			return;
143
-		}
144
-
145
-		// in case someone calls loadApp() directly
146
-		self::registerAutoloading($app, $appPath);
147
-
148
-		if (is_file($appPath . '/appinfo/app.php')) {
149
-			\OC::$server->getEventLogger()->start('load_app_' . $app, 'Load app: ' . $app);
150
-			try {
151
-				self::requireAppFile($app);
152
-			} catch (Error $ex) {
153
-				\OC::$server->getLogger()->logException($ex);
154
-				if (!\OC::$server->getAppManager()->isShipped($app)) {
155
-					// Only disable apps which are not shipped
156
-					self::disable($app);
157
-				}
158
-			}
159
-			if (self::isType($app, array('authentication'))) {
160
-				// since authentication apps affect the "is app enabled for group" check,
161
-				// the enabled apps cache needs to be cleared to make sure that the
162
-				// next time getEnableApps() is called it will also include apps that were
163
-				// enabled for groups
164
-				self::$enabledAppsCache = array();
165
-			}
166
-			\OC::$server->getEventLogger()->end('load_app_' . $app);
167
-		}
168
-
169
-		$info = self::getAppInfo($app);
170
-		if (!empty($info['activity']['filters'])) {
171
-			foreach ($info['activity']['filters'] as $filter) {
172
-				\OC::$server->getActivityManager()->registerFilter($filter);
173
-			}
174
-		}
175
-		if (!empty($info['activity']['settings'])) {
176
-			foreach ($info['activity']['settings'] as $setting) {
177
-				\OC::$server->getActivityManager()->registerSetting($setting);
178
-			}
179
-		}
180
-		if (!empty($info['activity']['providers'])) {
181
-			foreach ($info['activity']['providers'] as $provider) {
182
-				\OC::$server->getActivityManager()->registerProvider($provider);
183
-			}
184
-		}
185
-
186
-		if (!empty($info['settings']['admin'])) {
187
-			foreach ($info['settings']['admin'] as $setting) {
188
-				\OC::$server->getSettingsManager()->registerSetting('admin', $setting);
189
-			}
190
-		}
191
-		if (!empty($info['settings']['admin-section'])) {
192
-			foreach ($info['settings']['admin-section'] as $section) {
193
-				\OC::$server->getSettingsManager()->registerSection('admin', $section);
194
-			}
195
-		}
196
-		if (!empty($info['settings']['personal'])) {
197
-			foreach ($info['settings']['personal'] as $setting) {
198
-				\OC::$server->getSettingsManager()->registerSetting('personal', $setting);
199
-			}
200
-		}
201
-		if (!empty($info['settings']['personal-section'])) {
202
-			foreach ($info['settings']['personal-section'] as $section) {
203
-				\OC::$server->getSettingsManager()->registerSection('personal', $section);
204
-			}
205
-		}
206
-
207
-		if (!empty($info['collaboration']['plugins'])) {
208
-			// deal with one or many plugin entries
209
-			$plugins = isset($info['collaboration']['plugins']['plugin']['@value']) ?
210
-				[$info['collaboration']['plugins']['plugin']] : $info['collaboration']['plugins']['plugin'];
211
-			foreach ($plugins as $plugin) {
212
-				if($plugin['@attributes']['type'] === 'collaborator-search') {
213
-					$pluginInfo = [
214
-						'shareType' => $plugin['@attributes']['share-type'],
215
-						'class' => $plugin['@value'],
216
-					];
217
-					\OC::$server->getCollaboratorSearch()->registerPlugin($pluginInfo);
218
-				} else if ($plugin['@attributes']['type'] === 'autocomplete-sort') {
219
-					\OC::$server->getAutoCompleteManager()->registerSorter($plugin['@value']);
220
-				}
221
-			}
222
-		}
223
-	}
224
-
225
-	/**
226
-	 * @internal
227
-	 * @param string $app
228
-	 * @param string $path
229
-	 */
230
-	public static function registerAutoloading($app, $path) {
231
-		$key = $app . '-' . $path;
232
-		if(isset(self::$alreadyRegistered[$key])) {
233
-			return;
234
-		}
235
-
236
-		self::$alreadyRegistered[$key] = true;
237
-
238
-		// Register on PSR-4 composer autoloader
239
-		$appNamespace = \OC\AppFramework\App::buildAppNamespace($app);
240
-		\OC::$server->registerNamespace($app, $appNamespace);
241
-
242
-		if (file_exists($path . '/composer/autoload.php')) {
243
-			require_once $path . '/composer/autoload.php';
244
-		} else {
245
-			\OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true);
246
-			// Register on legacy autoloader
247
-			\OC::$loader->addValidRoot($path);
248
-		}
249
-
250
-		// Register Test namespace only when testing
251
-		if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) {
252
-			\OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true);
253
-		}
254
-	}
255
-
256
-	/**
257
-	 * Load app.php from the given app
258
-	 *
259
-	 * @param string $app app name
260
-	 * @throws Error
261
-	 */
262
-	private static function requireAppFile($app) {
263
-		// encapsulated here to avoid variable scope conflicts
264
-		require_once $app . '/appinfo/app.php';
265
-	}
266
-
267
-	/**
268
-	 * check if an app is of a specific type
269
-	 *
270
-	 * @param string $app
271
-	 * @param string|array $types
272
-	 * @return bool
273
-	 */
274
-	public static function isType($app, $types) {
275
-		if (is_string($types)) {
276
-			$types = array($types);
277
-		}
278
-		$appTypes = self::getAppTypes($app);
279
-		foreach ($types as $type) {
280
-			if (array_search($type, $appTypes) !== false) {
281
-				return true;
282
-			}
283
-		}
284
-		return false;
285
-	}
286
-
287
-	/**
288
-	 * get the types of an app
289
-	 *
290
-	 * @param string $app
291
-	 * @return array
292
-	 */
293
-	private static function getAppTypes($app) {
294
-		//load the cache
295
-		if (count(self::$appTypes) == 0) {
296
-			self::$appTypes = \OC::$server->getAppConfig()->getValues(false, 'types');
297
-		}
298
-
299
-		if (isset(self::$appTypes[$app])) {
300
-			return explode(',', self::$appTypes[$app]);
301
-		} else {
302
-			return array();
303
-		}
304
-	}
305
-
306
-	/**
307
-	 * read app types from info.xml and cache them in the database
308
-	 */
309
-	public static function setAppTypes($app) {
310
-		$appData = self::getAppInfo($app);
311
-		if(!is_array($appData)) {
312
-			return;
313
-		}
314
-
315
-		if (isset($appData['types'])) {
316
-			$appTypes = implode(',', $appData['types']);
317
-		} else {
318
-			$appTypes = '';
319
-			$appData['types'] = [];
320
-		}
321
-
322
-		\OC::$server->getConfig()->setAppValue($app, 'types', $appTypes);
323
-
324
-		if (\OC::$server->getAppManager()->hasProtectedAppType($appData['types'])) {
325
-			$enabled = \OC::$server->getConfig()->getAppValue($app, 'enabled', 'yes');
326
-			if ($enabled !== 'yes' && $enabled !== 'no') {
327
-				\OC::$server->getConfig()->setAppValue($app, 'enabled', 'yes');
328
-			}
329
-		}
330
-	}
331
-
332
-	/**
333
-	 * get all enabled apps
334
-	 */
335
-	protected static $enabledAppsCache = array();
336
-
337
-	/**
338
-	 * Returns apps enabled for the current user.
339
-	 *
340
-	 * @param bool $forceRefresh whether to refresh the cache
341
-	 * @param bool $all whether to return apps for all users, not only the
342
-	 * currently logged in one
343
-	 * @return string[]
344
-	 */
345
-	public static function getEnabledApps($forceRefresh = false, $all = false) {
346
-		if (!\OC::$server->getSystemConfig()->getValue('installed', false)) {
347
-			return array();
348
-		}
349
-		// in incognito mode or when logged out, $user will be false,
350
-		// which is also the case during an upgrade
351
-		$appManager = \OC::$server->getAppManager();
352
-		if ($all) {
353
-			$user = null;
354
-		} else {
355
-			$user = \OC::$server->getUserSession()->getUser();
356
-		}
357
-
358
-		if (is_null($user)) {
359
-			$apps = $appManager->getInstalledApps();
360
-		} else {
361
-			$apps = $appManager->getEnabledAppsForUser($user);
362
-		}
363
-		$apps = array_filter($apps, function ($app) {
364
-			return $app !== 'files';//we add this manually
365
-		});
366
-		sort($apps);
367
-		array_unshift($apps, 'files');
368
-		return $apps;
369
-	}
370
-
371
-	/**
372
-	 * checks whether or not an app is enabled
373
-	 *
374
-	 * @param string $app app
375
-	 * @return bool
376
-	 * @deprecated 13.0.0 use \OC::$server->getAppManager()->isEnabledForUser($appId)
377
-	 *
378
-	 * This function checks whether or not an app is enabled.
379
-	 */
380
-	public static function isEnabled($app) {
381
-		return \OC::$server->getAppManager()->isEnabledForUser($app);
382
-	}
383
-
384
-	/**
385
-	 * enables an app
386
-	 *
387
-	 * @param string $appId
388
-	 * @param array $groups (optional) when set, only these groups will have access to the app
389
-	 * @throws \Exception
390
-	 * @return void
391
-	 *
392
-	 * This function set an app as enabled in appconfig.
393
-	 */
394
-	public function enable($appId,
395
-						   $groups = null) {
396
-		self::$enabledAppsCache = []; // flush
397
-
398
-		// Check if app is already downloaded
399
-		$installer = \OC::$server->query(Installer::class);
400
-		$isDownloaded = $installer->isDownloaded($appId);
401
-
402
-		if(!$isDownloaded) {
403
-			$installer->downloadApp($appId);
404
-		}
405
-
406
-		$installer->installApp($appId);
407
-
408
-		$appManager = \OC::$server->getAppManager();
409
-		if (!is_null($groups)) {
410
-			$groupManager = \OC::$server->getGroupManager();
411
-			$groupsList = [];
412
-			foreach ($groups as $group) {
413
-				$groupItem = $groupManager->get($group);
414
-				if ($groupItem instanceof \OCP\IGroup) {
415
-					$groupsList[] = $groupManager->get($group);
416
-				}
417
-			}
418
-			$appManager->enableAppForGroups($appId, $groupsList);
419
-		} else {
420
-			$appManager->enableApp($appId);
421
-		}
422
-	}
423
-
424
-	/**
425
-	 * This function set an app as disabled in appconfig.
426
-	 *
427
-	 * @param string $app app
428
-	 * @throws Exception
429
-	 */
430
-	public static function disable($app) {
431
-		// flush
432
-		self::$enabledAppsCache = array();
433
-
434
-		// run uninstall steps
435
-		$appData = OC_App::getAppInfo($app);
436
-		if (!is_null($appData)) {
437
-			OC_App::executeRepairSteps($app, $appData['repair-steps']['uninstall']);
438
-		}
439
-
440
-		// emit disable hook - needed anymore ?
441
-		\OC_Hook::emit('OC_App', 'pre_disable', array('app' => $app));
442
-
443
-		// finally disable it
444
-		$appManager = \OC::$server->getAppManager();
445
-		$appManager->disableApp($app);
446
-	}
447
-
448
-	/**
449
-	 * Get the path where to install apps
450
-	 *
451
-	 * @return string|false
452
-	 */
453
-	public static function getInstallPath() {
454
-		if (\OC::$server->getSystemConfig()->getValue('appstoreenabled', true) == false) {
455
-			return false;
456
-		}
457
-
458
-		foreach (OC::$APPSROOTS as $dir) {
459
-			if (isset($dir['writable']) && $dir['writable'] === true) {
460
-				return $dir['path'];
461
-			}
462
-		}
463
-
464
-		\OCP\Util::writeLog('core', 'No application directories are marked as writable.', \OCP\Util::ERROR);
465
-		return null;
466
-	}
467
-
468
-
469
-	/**
470
-	 * search for an app in all app-directories
471
-	 *
472
-	 * @param string $appId
473
-	 * @return false|string
474
-	 */
475
-	public static function findAppInDirectories($appId) {
476
-		$sanitizedAppId = self::cleanAppId($appId);
477
-		if($sanitizedAppId !== $appId) {
478
-			return false;
479
-		}
480
-		static $app_dir = array();
481
-
482
-		if (isset($app_dir[$appId])) {
483
-			return $app_dir[$appId];
484
-		}
485
-
486
-		$possibleApps = array();
487
-		foreach (OC::$APPSROOTS as $dir) {
488
-			if (file_exists($dir['path'] . '/' . $appId)) {
489
-				$possibleApps[] = $dir;
490
-			}
491
-		}
492
-
493
-		if (empty($possibleApps)) {
494
-			return false;
495
-		} elseif (count($possibleApps) === 1) {
496
-			$dir = array_shift($possibleApps);
497
-			$app_dir[$appId] = $dir;
498
-			return $dir;
499
-		} else {
500
-			$versionToLoad = array();
501
-			foreach ($possibleApps as $possibleApp) {
502
-				$version = self::getAppVersionByPath($possibleApp['path']);
503
-				if (empty($versionToLoad) || version_compare($version, $versionToLoad['version'], '>')) {
504
-					$versionToLoad = array(
505
-						'dir' => $possibleApp,
506
-						'version' => $version,
507
-					);
508
-				}
509
-			}
510
-			$app_dir[$appId] = $versionToLoad['dir'];
511
-			return $versionToLoad['dir'];
512
-			//TODO - write test
513
-		}
514
-	}
515
-
516
-	/**
517
-	 * Get the directory for the given app.
518
-	 * If the app is defined in multiple directories, the first one is taken. (false if not found)
519
-	 *
520
-	 * @param string $appId
521
-	 * @return string|false
522
-	 */
523
-	public static function getAppPath($appId) {
524
-		if ($appId === null || trim($appId) === '') {
525
-			return false;
526
-		}
527
-
528
-		if (($dir = self::findAppInDirectories($appId)) != false) {
529
-			return $dir['path'] . '/' . $appId;
530
-		}
531
-		return false;
532
-	}
533
-
534
-	/**
535
-	 * Get the path for the given app on the access
536
-	 * If the app is defined in multiple directories, the first one is taken. (false if not found)
537
-	 *
538
-	 * @param string $appId
539
-	 * @return string|false
540
-	 */
541
-	public static function getAppWebPath($appId) {
542
-		if (($dir = self::findAppInDirectories($appId)) != false) {
543
-			return OC::$WEBROOT . $dir['url'] . '/' . $appId;
544
-		}
545
-		return false;
546
-	}
547
-
548
-	/**
549
-	 * get the last version of the app from appinfo/info.xml
550
-	 *
551
-	 * @param string $appId
552
-	 * @param bool $useCache
553
-	 * @return string
554
-	 * @deprecated 14.0.0 use \OC::$server->getAppManager()->getAppVersion()
555
-	 */
556
-	public static function getAppVersion($appId, $useCache = true) {
557
-		return \OC::$server->getAppManager()->getAppVersion($appId, $useCache);
558
-	}
559
-
560
-	/**
561
-	 * get app's version based on it's path
562
-	 *
563
-	 * @param string $path
564
-	 * @return string
565
-	 */
566
-	public static function getAppVersionByPath($path) {
567
-		$infoFile = $path . '/appinfo/info.xml';
568
-		$appData = \OC::$server->getAppManager()->getAppInfo($infoFile, true);
569
-		return isset($appData['version']) ? $appData['version'] : '';
570
-	}
571
-
572
-
573
-	/**
574
-	 * Read all app metadata from the info.xml file
575
-	 *
576
-	 * @param string $appId id of the app or the path of the info.xml file
577
-	 * @param bool $path
578
-	 * @param string $lang
579
-	 * @return array|null
580
-	 * @note all data is read from info.xml, not just pre-defined fields
581
-	 * @deprecated 14.0.0 use \OC::$server->getAppManager()->getAppInfo()
582
-	 */
583
-	public static function getAppInfo($appId, $path = false, $lang = null) {
584
-		return \OC::$server->getAppManager()->getAppInfo($appId, $path, $lang);
585
-	}
586
-
587
-	/**
588
-	 * Returns the navigation
589
-	 *
590
-	 * @return array
591
-	 * @deprecated 14.0.0 use \OC::$server->getNavigationManager()->getAll()
592
-	 *
593
-	 * This function returns an array containing all entries added. The
594
-	 * entries are sorted by the key 'order' ascending. Additional to the keys
595
-	 * given for each app the following keys exist:
596
-	 *   - active: boolean, signals if the user is on this navigation entry
597
-	 */
598
-	public static function getNavigation() {
599
-		return OC::$server->getNavigationManager()->getAll();
600
-	}
601
-
602
-	/**
603
-	 * Returns the Settings Navigation
604
-	 *
605
-	 * @return string[]
606
-	 * @deprecated 14.0.0 use \OC::$server->getNavigationManager()->getAll('settings')
607
-	 *
608
-	 * This function returns an array containing all settings pages added. The
609
-	 * entries are sorted by the key 'order' ascending.
610
-	 */
611
-	public static function getSettingsNavigation() {
612
-		return OC::$server->getNavigationManager()->getAll('settings');
613
-	}
614
-
615
-	/**
616
-	 * get the id of loaded app
617
-	 *
618
-	 * @return string
619
-	 */
620
-	public static function getCurrentApp() {
621
-		$request = \OC::$server->getRequest();
622
-		$script = substr($request->getScriptName(), strlen(OC::$WEBROOT) + 1);
623
-		$topFolder = substr($script, 0, strpos($script, '/') ?: 0);
624
-		if (empty($topFolder)) {
625
-			$path_info = $request->getPathInfo();
626
-			if ($path_info) {
627
-				$topFolder = substr($path_info, 1, strpos($path_info, '/', 1) - 1);
628
-			}
629
-		}
630
-		if ($topFolder == 'apps') {
631
-			$length = strlen($topFolder);
632
-			return substr($script, $length + 1, strpos($script, '/', $length + 1) - $length - 1);
633
-		} else {
634
-			return $topFolder;
635
-		}
636
-	}
637
-
638
-	/**
639
-	 * @param string $type
640
-	 * @return array
641
-	 */
642
-	public static function getForms($type) {
643
-		$forms = array();
644
-		switch ($type) {
645
-			case 'admin':
646
-				$source = self::$adminForms;
647
-				break;
648
-			case 'personal':
649
-				$source = self::$personalForms;
650
-				break;
651
-			default:
652
-				return array();
653
-		}
654
-		foreach ($source as $form) {
655
-			$forms[] = include $form;
656
-		}
657
-		return $forms;
658
-	}
659
-
660
-	/**
661
-	 * register an admin form to be shown
662
-	 *
663
-	 * @param string $app
664
-	 * @param string $page
665
-	 */
666
-	public static function registerAdmin($app, $page) {
667
-		self::$adminForms[] = $app . '/' . $page . '.php';
668
-	}
669
-
670
-	/**
671
-	 * register a personal form to be shown
672
-	 * @param string $app
673
-	 * @param string $page
674
-	 */
675
-	public static function registerPersonal($app, $page) {
676
-		self::$personalForms[] = $app . '/' . $page . '.php';
677
-	}
678
-
679
-	/**
680
-	 * @param array $entry
681
-	 */
682
-	public static function registerLogIn(array $entry) {
683
-		self::$altLogin[] = $entry;
684
-	}
685
-
686
-	/**
687
-	 * @return array
688
-	 */
689
-	public static function getAlternativeLogIns() {
690
-		return self::$altLogin;
691
-	}
692
-
693
-	/**
694
-	 * get a list of all apps in the apps folder
695
-	 *
696
-	 * @return array an array of app names (string IDs)
697
-	 * @todo: change the name of this method to getInstalledApps, which is more accurate
698
-	 */
699
-	public static function getAllApps() {
700
-
701
-		$apps = array();
702
-
703
-		foreach (OC::$APPSROOTS as $apps_dir) {
704
-			if (!is_readable($apps_dir['path'])) {
705
-				\OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN);
706
-				continue;
707
-			}
708
-			$dh = opendir($apps_dir['path']);
709
-
710
-			if (is_resource($dh)) {
711
-				while (($file = readdir($dh)) !== false) {
712
-
713
-					if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) {
714
-
715
-						$apps[] = $file;
716
-					}
717
-				}
718
-			}
719
-		}
720
-
721
-		$apps = array_unique($apps);
722
-
723
-		return $apps;
724
-	}
725
-
726
-	/**
727
-	 * List all apps, this is used in apps.php
728
-	 *
729
-	 * @return array
730
-	 */
731
-	public function listAllApps() {
732
-		$installedApps = OC_App::getAllApps();
733
-
734
-		$appManager = \OC::$server->getAppManager();
735
-		//we don't want to show configuration for these
736
-		$blacklist = $appManager->getAlwaysEnabledApps();
737
-		$appList = array();
738
-		$langCode = \OC::$server->getL10N('core')->getLanguageCode();
739
-		$urlGenerator = \OC::$server->getURLGenerator();
740
-
741
-		foreach ($installedApps as $app) {
742
-			if (array_search($app, $blacklist) === false) {
743
-
744
-				$info = OC_App::getAppInfo($app, false, $langCode);
745
-				if (!is_array($info)) {
746
-					\OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR);
747
-					continue;
748
-				}
749
-
750
-				if (!isset($info['name'])) {
751
-					\OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR);
752
-					continue;
753
-				}
754
-
755
-				$enabled = \OC::$server->getConfig()->getAppValue($app, 'enabled', 'no');
756
-				$info['groups'] = null;
757
-				if ($enabled === 'yes') {
758
-					$active = true;
759
-				} else if ($enabled === 'no') {
760
-					$active = false;
761
-				} else {
762
-					$active = true;
763
-					$info['groups'] = $enabled;
764
-				}
765
-
766
-				$info['active'] = $active;
767
-
768
-				if ($appManager->isShipped($app)) {
769
-					$info['internal'] = true;
770
-					$info['level'] = self::officialApp;
771
-					$info['removable'] = false;
772
-				} else {
773
-					$info['internal'] = false;
774
-					$info['removable'] = true;
775
-				}
776
-
777
-				$appPath = self::getAppPath($app);
778
-				if($appPath !== false) {
779
-					$appIcon = $appPath . '/img/' . $app . '.svg';
780
-					if (file_exists($appIcon)) {
781
-						$info['preview'] = $urlGenerator->imagePath($app, $app . '.svg');
782
-						$info['previewAsIcon'] = true;
783
-					} else {
784
-						$appIcon = $appPath . '/img/app.svg';
785
-						if (file_exists($appIcon)) {
786
-							$info['preview'] = $urlGenerator->imagePath($app, 'app.svg');
787
-							$info['previewAsIcon'] = true;
788
-						}
789
-					}
790
-				}
791
-				// fix documentation
792
-				if (isset($info['documentation']) && is_array($info['documentation'])) {
793
-					foreach ($info['documentation'] as $key => $url) {
794
-						// If it is not an absolute URL we assume it is a key
795
-						// i.e. admin-ldap will get converted to go.php?to=admin-ldap
796
-						if (stripos($url, 'https://') !== 0 && stripos($url, 'http://') !== 0) {
797
-							$url = $urlGenerator->linkToDocs($url);
798
-						}
799
-
800
-						$info['documentation'][$key] = $url;
801
-					}
802
-				}
803
-
804
-				$info['version'] = OC_App::getAppVersion($app);
805
-				$appList[] = $info;
806
-			}
807
-		}
808
-
809
-		return $appList;
810
-	}
811
-
812
-	public static function shouldUpgrade($app) {
813
-		$versions = self::getAppVersions();
814
-		$currentVersion = OC_App::getAppVersion($app);
815
-		if ($currentVersion && isset($versions[$app])) {
816
-			$installedVersion = $versions[$app];
817
-			if (!version_compare($currentVersion, $installedVersion, '=')) {
818
-				return true;
819
-			}
820
-		}
821
-		return false;
822
-	}
823
-
824
-	/**
825
-	 * Adjust the number of version parts of $version1 to match
826
-	 * the number of version parts of $version2.
827
-	 *
828
-	 * @param string $version1 version to adjust
829
-	 * @param string $version2 version to take the number of parts from
830
-	 * @return string shortened $version1
831
-	 */
832
-	private static function adjustVersionParts($version1, $version2) {
833
-		$version1 = explode('.', $version1);
834
-		$version2 = explode('.', $version2);
835
-		// reduce $version1 to match the number of parts in $version2
836
-		while (count($version1) > count($version2)) {
837
-			array_pop($version1);
838
-		}
839
-		// if $version1 does not have enough parts, add some
840
-		while (count($version1) < count($version2)) {
841
-			$version1[] = '0';
842
-		}
843
-		return implode('.', $version1);
844
-	}
845
-
846
-	/**
847
-	 * Check whether the current ownCloud version matches the given
848
-	 * application's version requirements.
849
-	 *
850
-	 * The comparison is made based on the number of parts that the
851
-	 * app info version has. For example for ownCloud 6.0.3 if the
852
-	 * app info version is expecting version 6.0, the comparison is
853
-	 * made on the first two parts of the ownCloud version.
854
-	 * This means that it's possible to specify "requiremin" => 6
855
-	 * and "requiremax" => 6 and it will still match ownCloud 6.0.3.
856
-	 *
857
-	 * @param string $ocVersion ownCloud version to check against
858
-	 * @param array $appInfo app info (from xml)
859
-	 *
860
-	 * @return boolean true if compatible, otherwise false
861
-	 */
862
-	public static function isAppCompatible($ocVersion, $appInfo) {
863
-		$requireMin = '';
864
-		$requireMax = '';
865
-		if (isset($appInfo['dependencies']['nextcloud']['@attributes']['min-version'])) {
866
-			$requireMin = $appInfo['dependencies']['nextcloud']['@attributes']['min-version'];
867
-		} elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['min-version'])) {
868
-			$requireMin = $appInfo['dependencies']['owncloud']['@attributes']['min-version'];
869
-		} else if (isset($appInfo['requiremin'])) {
870
-			$requireMin = $appInfo['requiremin'];
871
-		} else if (isset($appInfo['require'])) {
872
-			$requireMin = $appInfo['require'];
873
-		}
874
-
875
-		if (isset($appInfo['dependencies']['nextcloud']['@attributes']['max-version'])) {
876
-			$requireMax = $appInfo['dependencies']['nextcloud']['@attributes']['max-version'];
877
-		} elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['max-version'])) {
878
-			$requireMax = $appInfo['dependencies']['owncloud']['@attributes']['max-version'];
879
-		} else if (isset($appInfo['requiremax'])) {
880
-			$requireMax = $appInfo['requiremax'];
881
-		}
882
-
883
-		if (is_array($ocVersion)) {
884
-			$ocVersion = implode('.', $ocVersion);
885
-		}
886
-
887
-		if (!empty($requireMin)
888
-			&& version_compare(self::adjustVersionParts($ocVersion, $requireMin), $requireMin, '<')
889
-		) {
890
-
891
-			return false;
892
-		}
893
-
894
-		if (!empty($requireMax)
895
-			&& version_compare(self::adjustVersionParts($ocVersion, $requireMax), $requireMax, '>')
896
-		) {
897
-			return false;
898
-		}
899
-
900
-		return true;
901
-	}
902
-
903
-	/**
904
-	 * get the installed version of all apps
905
-	 */
906
-	public static function getAppVersions() {
907
-		static $versions;
908
-
909
-		if(!$versions) {
910
-			$appConfig = \OC::$server->getAppConfig();
911
-			$versions = $appConfig->getValues(false, 'installed_version');
912
-		}
913
-		return $versions;
914
-	}
915
-
916
-	/**
917
-	 * update the database for the app and call the update script
918
-	 *
919
-	 * @param string $appId
920
-	 * @return bool
921
-	 */
922
-	public static function updateApp($appId) {
923
-		$appPath = self::getAppPath($appId);
924
-		if($appPath === false) {
925
-			return false;
926
-		}
927
-		self::registerAutoloading($appId, $appPath);
928
-
929
-		$appData = self::getAppInfo($appId);
930
-		self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']);
931
-
932
-		if (file_exists($appPath . '/appinfo/database.xml')) {
933
-			OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml');
934
-		} else {
935
-			$ms = new MigrationService($appId, \OC::$server->getDatabaseConnection());
936
-			$ms->migrate();
937
-		}
938
-
939
-		self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']);
940
-		self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']);
941
-		// update appversion in app manager
942
-		\OC::$server->getAppManager()->getAppVersion($appId, false);
943
-
944
-		// run upgrade code
945
-		if (file_exists($appPath . '/appinfo/update.php')) {
946
-			self::loadApp($appId);
947
-			include $appPath . '/appinfo/update.php';
948
-		}
949
-		self::setupBackgroundJobs($appData['background-jobs']);
950
-
951
-		//set remote/public handlers
952
-		if (array_key_exists('ocsid', $appData)) {
953
-			\OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']);
954
-		} elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) {
955
-			\OC::$server->getConfig()->deleteAppValue($appId, 'ocsid');
956
-		}
957
-		foreach ($appData['remote'] as $name => $path) {
958
-			\OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path);
959
-		}
960
-		foreach ($appData['public'] as $name => $path) {
961
-			\OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path);
962
-		}
963
-
964
-		self::setAppTypes($appId);
965
-
966
-		$version = \OC_App::getAppVersion($appId);
967
-		\OC::$server->getConfig()->setAppValue($appId, 'installed_version', $version);
968
-
969
-		\OC::$server->getEventDispatcher()->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent(
970
-			ManagerEvent::EVENT_APP_UPDATE, $appId
971
-		));
972
-
973
-		return true;
974
-	}
975
-
976
-	/**
977
-	 * @param string $appId
978
-	 * @param string[] $steps
979
-	 * @throws \OC\NeedsUpdateException
980
-	 */
981
-	public static function executeRepairSteps($appId, array $steps) {
982
-		if (empty($steps)) {
983
-			return;
984
-		}
985
-		// load the app
986
-		self::loadApp($appId);
987
-
988
-		$dispatcher = OC::$server->getEventDispatcher();
989
-
990
-		// load the steps
991
-		$r = new Repair([], $dispatcher);
992
-		foreach ($steps as $step) {
993
-			try {
994
-				$r->addStep($step);
995
-			} catch (Exception $ex) {
996
-				$r->emit('\OC\Repair', 'error', [$ex->getMessage()]);
997
-				\OC::$server->getLogger()->logException($ex);
998
-			}
999
-		}
1000
-		// run the steps
1001
-		$r->run();
1002
-	}
1003
-
1004
-	public static function setupBackgroundJobs(array $jobs) {
1005
-		$queue = \OC::$server->getJobList();
1006
-		foreach ($jobs as $job) {
1007
-			$queue->add($job);
1008
-		}
1009
-	}
1010
-
1011
-	/**
1012
-	 * @param string $appId
1013
-	 * @param string[] $steps
1014
-	 */
1015
-	private static function setupLiveMigrations($appId, array $steps) {
1016
-		$queue = \OC::$server->getJobList();
1017
-		foreach ($steps as $step) {
1018
-			$queue->add('OC\Migration\BackgroundRepair', [
1019
-				'app' => $appId,
1020
-				'step' => $step]);
1021
-		}
1022
-	}
1023
-
1024
-	/**
1025
-	 * @param string $appId
1026
-	 * @return \OC\Files\View|false
1027
-	 */
1028
-	public static function getStorage($appId) {
1029
-		if (\OC::$server->getAppManager()->isEnabledForUser($appId)) { //sanity check
1030
-			if (\OC::$server->getUserSession()->isLoggedIn()) {
1031
-				$view = new \OC\Files\View('/' . OC_User::getUser());
1032
-				if (!$view->file_exists($appId)) {
1033
-					$view->mkdir($appId);
1034
-				}
1035
-				return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId);
1036
-			} else {
1037
-				\OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR);
1038
-				return false;
1039
-			}
1040
-		} else {
1041
-			\OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR);
1042
-			return false;
1043
-		}
1044
-	}
1045
-
1046
-	protected static function findBestL10NOption($options, $lang) {
1047
-		$fallback = $similarLangFallback = $englishFallback = false;
1048
-
1049
-		$lang = strtolower($lang);
1050
-		$similarLang = $lang;
1051
-		if (strpos($similarLang, '_')) {
1052
-			// For "de_DE" we want to find "de" and the other way around
1053
-			$similarLang = substr($lang, 0, strpos($lang, '_'));
1054
-		}
1055
-
1056
-		foreach ($options as $option) {
1057
-			if (is_array($option)) {
1058
-				if ($fallback === false) {
1059
-					$fallback = $option['@value'];
1060
-				}
1061
-
1062
-				if (!isset($option['@attributes']['lang'])) {
1063
-					continue;
1064
-				}
1065
-
1066
-				$attributeLang = strtolower($option['@attributes']['lang']);
1067
-				if ($attributeLang === $lang) {
1068
-					return $option['@value'];
1069
-				}
1070
-
1071
-				if ($attributeLang === $similarLang) {
1072
-					$similarLangFallback = $option['@value'];
1073
-				} else if (strpos($attributeLang, $similarLang . '_') === 0) {
1074
-					if ($similarLangFallback === false) {
1075
-						$similarLangFallback =  $option['@value'];
1076
-					}
1077
-				}
1078
-			} else {
1079
-				$englishFallback = $option;
1080
-			}
1081
-		}
1082
-
1083
-		if ($similarLangFallback !== false) {
1084
-			return $similarLangFallback;
1085
-		} else if ($englishFallback !== false) {
1086
-			return $englishFallback;
1087
-		}
1088
-		return (string) $fallback;
1089
-	}
1090
-
1091
-	/**
1092
-	 * parses the app data array and enhanced the 'description' value
1093
-	 *
1094
-	 * @param array $data the app data
1095
-	 * @param string $lang
1096
-	 * @return array improved app data
1097
-	 */
1098
-	public static function parseAppInfo(array $data, $lang = null) {
1099
-
1100
-		if ($lang && isset($data['name']) && is_array($data['name'])) {
1101
-			$data['name'] = self::findBestL10NOption($data['name'], $lang);
1102
-		}
1103
-		if ($lang && isset($data['summary']) && is_array($data['summary'])) {
1104
-			$data['summary'] = self::findBestL10NOption($data['summary'], $lang);
1105
-		}
1106
-		if ($lang && isset($data['description']) && is_array($data['description'])) {
1107
-			$data['description'] = trim(self::findBestL10NOption($data['description'], $lang));
1108
-		} else if (isset($data['description']) && is_string($data['description'])) {
1109
-			$data['description'] = trim($data['description']);
1110
-		} else  {
1111
-			$data['description'] = '';
1112
-		}
1113
-
1114
-		return $data;
1115
-	}
1116
-
1117
-	/**
1118
-	 * @param \OCP\IConfig $config
1119
-	 * @param \OCP\IL10N $l
1120
-	 * @param array $info
1121
-	 * @throws \Exception
1122
-	 */
1123
-	public static function checkAppDependencies($config, $l, $info) {
1124
-		$dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l);
1125
-		$missing = $dependencyAnalyzer->analyze($info);
1126
-		if (!empty($missing)) {
1127
-			$missingMsg = implode(PHP_EOL, $missing);
1128
-			throw new \Exception(
1129
-				$l->t('App "%s" cannot be installed because the following dependencies are not fulfilled: %s',
1130
-					[$info['name'], $missingMsg]
1131
-				)
1132
-			);
1133
-		}
1134
-	}
65
+    static private $adminForms = array();
66
+    static private $personalForms = array();
67
+    static private $appTypes = array();
68
+    static private $loadedApps = array();
69
+    static private $altLogin = array();
70
+    static private $alreadyRegistered = [];
71
+    const officialApp = 200;
72
+
73
+    /**
74
+     * clean the appId
75
+     *
76
+     * @param string|boolean $app AppId that needs to be cleaned
77
+     * @return string
78
+     */
79
+    public static function cleanAppId($app) {
80
+        return str_replace(array('\0', '/', '\\', '..'), '', $app);
81
+    }
82
+
83
+    /**
84
+     * Check if an app is loaded
85
+     *
86
+     * @param string $app
87
+     * @return bool
88
+     */
89
+    public static function isAppLoaded($app) {
90
+        return in_array($app, self::$loadedApps, true);
91
+    }
92
+
93
+    /**
94
+     * loads all apps
95
+     *
96
+     * @param string[] | string | null $types
97
+     * @return bool
98
+     *
99
+     * This function walks through the ownCloud directory and loads all apps
100
+     * it can find. A directory contains an app if the file /appinfo/info.xml
101
+     * exists.
102
+     *
103
+     * if $types is set, only apps of those types will be loaded
104
+     */
105
+    public static function loadApps($types = null) {
106
+        if (\OC::$server->getSystemConfig()->getValue('maintenance', false)) {
107
+            return false;
108
+        }
109
+        // Load the enabled apps here
110
+        $apps = self::getEnabledApps();
111
+
112
+        // Add each apps' folder as allowed class path
113
+        foreach($apps as $app) {
114
+            $path = self::getAppPath($app);
115
+            if($path !== false) {
116
+                self::registerAutoloading($app, $path);
117
+            }
118
+        }
119
+
120
+        // prevent app.php from printing output
121
+        ob_start();
122
+        foreach ($apps as $app) {
123
+            if ((is_null($types) or self::isType($app, $types)) && !in_array($app, self::$loadedApps)) {
124
+                self::loadApp($app);
125
+            }
126
+        }
127
+        ob_end_clean();
128
+
129
+        return true;
130
+    }
131
+
132
+    /**
133
+     * load a single app
134
+     *
135
+     * @param string $app
136
+     * @throws Exception
137
+     */
138
+    public static function loadApp($app) {
139
+        self::$loadedApps[] = $app;
140
+        $appPath = self::getAppPath($app);
141
+        if($appPath === false) {
142
+            return;
143
+        }
144
+
145
+        // in case someone calls loadApp() directly
146
+        self::registerAutoloading($app, $appPath);
147
+
148
+        if (is_file($appPath . '/appinfo/app.php')) {
149
+            \OC::$server->getEventLogger()->start('load_app_' . $app, 'Load app: ' . $app);
150
+            try {
151
+                self::requireAppFile($app);
152
+            } catch (Error $ex) {
153
+                \OC::$server->getLogger()->logException($ex);
154
+                if (!\OC::$server->getAppManager()->isShipped($app)) {
155
+                    // Only disable apps which are not shipped
156
+                    self::disable($app);
157
+                }
158
+            }
159
+            if (self::isType($app, array('authentication'))) {
160
+                // since authentication apps affect the "is app enabled for group" check,
161
+                // the enabled apps cache needs to be cleared to make sure that the
162
+                // next time getEnableApps() is called it will also include apps that were
163
+                // enabled for groups
164
+                self::$enabledAppsCache = array();
165
+            }
166
+            \OC::$server->getEventLogger()->end('load_app_' . $app);
167
+        }
168
+
169
+        $info = self::getAppInfo($app);
170
+        if (!empty($info['activity']['filters'])) {
171
+            foreach ($info['activity']['filters'] as $filter) {
172
+                \OC::$server->getActivityManager()->registerFilter($filter);
173
+            }
174
+        }
175
+        if (!empty($info['activity']['settings'])) {
176
+            foreach ($info['activity']['settings'] as $setting) {
177
+                \OC::$server->getActivityManager()->registerSetting($setting);
178
+            }
179
+        }
180
+        if (!empty($info['activity']['providers'])) {
181
+            foreach ($info['activity']['providers'] as $provider) {
182
+                \OC::$server->getActivityManager()->registerProvider($provider);
183
+            }
184
+        }
185
+
186
+        if (!empty($info['settings']['admin'])) {
187
+            foreach ($info['settings']['admin'] as $setting) {
188
+                \OC::$server->getSettingsManager()->registerSetting('admin', $setting);
189
+            }
190
+        }
191
+        if (!empty($info['settings']['admin-section'])) {
192
+            foreach ($info['settings']['admin-section'] as $section) {
193
+                \OC::$server->getSettingsManager()->registerSection('admin', $section);
194
+            }
195
+        }
196
+        if (!empty($info['settings']['personal'])) {
197
+            foreach ($info['settings']['personal'] as $setting) {
198
+                \OC::$server->getSettingsManager()->registerSetting('personal', $setting);
199
+            }
200
+        }
201
+        if (!empty($info['settings']['personal-section'])) {
202
+            foreach ($info['settings']['personal-section'] as $section) {
203
+                \OC::$server->getSettingsManager()->registerSection('personal', $section);
204
+            }
205
+        }
206
+
207
+        if (!empty($info['collaboration']['plugins'])) {
208
+            // deal with one or many plugin entries
209
+            $plugins = isset($info['collaboration']['plugins']['plugin']['@value']) ?
210
+                [$info['collaboration']['plugins']['plugin']] : $info['collaboration']['plugins']['plugin'];
211
+            foreach ($plugins as $plugin) {
212
+                if($plugin['@attributes']['type'] === 'collaborator-search') {
213
+                    $pluginInfo = [
214
+                        'shareType' => $plugin['@attributes']['share-type'],
215
+                        'class' => $plugin['@value'],
216
+                    ];
217
+                    \OC::$server->getCollaboratorSearch()->registerPlugin($pluginInfo);
218
+                } else if ($plugin['@attributes']['type'] === 'autocomplete-sort') {
219
+                    \OC::$server->getAutoCompleteManager()->registerSorter($plugin['@value']);
220
+                }
221
+            }
222
+        }
223
+    }
224
+
225
+    /**
226
+     * @internal
227
+     * @param string $app
228
+     * @param string $path
229
+     */
230
+    public static function registerAutoloading($app, $path) {
231
+        $key = $app . '-' . $path;
232
+        if(isset(self::$alreadyRegistered[$key])) {
233
+            return;
234
+        }
235
+
236
+        self::$alreadyRegistered[$key] = true;
237
+
238
+        // Register on PSR-4 composer autoloader
239
+        $appNamespace = \OC\AppFramework\App::buildAppNamespace($app);
240
+        \OC::$server->registerNamespace($app, $appNamespace);
241
+
242
+        if (file_exists($path . '/composer/autoload.php')) {
243
+            require_once $path . '/composer/autoload.php';
244
+        } else {
245
+            \OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true);
246
+            // Register on legacy autoloader
247
+            \OC::$loader->addValidRoot($path);
248
+        }
249
+
250
+        // Register Test namespace only when testing
251
+        if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) {
252
+            \OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true);
253
+        }
254
+    }
255
+
256
+    /**
257
+     * Load app.php from the given app
258
+     *
259
+     * @param string $app app name
260
+     * @throws Error
261
+     */
262
+    private static function requireAppFile($app) {
263
+        // encapsulated here to avoid variable scope conflicts
264
+        require_once $app . '/appinfo/app.php';
265
+    }
266
+
267
+    /**
268
+     * check if an app is of a specific type
269
+     *
270
+     * @param string $app
271
+     * @param string|array $types
272
+     * @return bool
273
+     */
274
+    public static function isType($app, $types) {
275
+        if (is_string($types)) {
276
+            $types = array($types);
277
+        }
278
+        $appTypes = self::getAppTypes($app);
279
+        foreach ($types as $type) {
280
+            if (array_search($type, $appTypes) !== false) {
281
+                return true;
282
+            }
283
+        }
284
+        return false;
285
+    }
286
+
287
+    /**
288
+     * get the types of an app
289
+     *
290
+     * @param string $app
291
+     * @return array
292
+     */
293
+    private static function getAppTypes($app) {
294
+        //load the cache
295
+        if (count(self::$appTypes) == 0) {
296
+            self::$appTypes = \OC::$server->getAppConfig()->getValues(false, 'types');
297
+        }
298
+
299
+        if (isset(self::$appTypes[$app])) {
300
+            return explode(',', self::$appTypes[$app]);
301
+        } else {
302
+            return array();
303
+        }
304
+    }
305
+
306
+    /**
307
+     * read app types from info.xml and cache them in the database
308
+     */
309
+    public static function setAppTypes($app) {
310
+        $appData = self::getAppInfo($app);
311
+        if(!is_array($appData)) {
312
+            return;
313
+        }
314
+
315
+        if (isset($appData['types'])) {
316
+            $appTypes = implode(',', $appData['types']);
317
+        } else {
318
+            $appTypes = '';
319
+            $appData['types'] = [];
320
+        }
321
+
322
+        \OC::$server->getConfig()->setAppValue($app, 'types', $appTypes);
323
+
324
+        if (\OC::$server->getAppManager()->hasProtectedAppType($appData['types'])) {
325
+            $enabled = \OC::$server->getConfig()->getAppValue($app, 'enabled', 'yes');
326
+            if ($enabled !== 'yes' && $enabled !== 'no') {
327
+                \OC::$server->getConfig()->setAppValue($app, 'enabled', 'yes');
328
+            }
329
+        }
330
+    }
331
+
332
+    /**
333
+     * get all enabled apps
334
+     */
335
+    protected static $enabledAppsCache = array();
336
+
337
+    /**
338
+     * Returns apps enabled for the current user.
339
+     *
340
+     * @param bool $forceRefresh whether to refresh the cache
341
+     * @param bool $all whether to return apps for all users, not only the
342
+     * currently logged in one
343
+     * @return string[]
344
+     */
345
+    public static function getEnabledApps($forceRefresh = false, $all = false) {
346
+        if (!\OC::$server->getSystemConfig()->getValue('installed', false)) {
347
+            return array();
348
+        }
349
+        // in incognito mode or when logged out, $user will be false,
350
+        // which is also the case during an upgrade
351
+        $appManager = \OC::$server->getAppManager();
352
+        if ($all) {
353
+            $user = null;
354
+        } else {
355
+            $user = \OC::$server->getUserSession()->getUser();
356
+        }
357
+
358
+        if (is_null($user)) {
359
+            $apps = $appManager->getInstalledApps();
360
+        } else {
361
+            $apps = $appManager->getEnabledAppsForUser($user);
362
+        }
363
+        $apps = array_filter($apps, function ($app) {
364
+            return $app !== 'files';//we add this manually
365
+        });
366
+        sort($apps);
367
+        array_unshift($apps, 'files');
368
+        return $apps;
369
+    }
370
+
371
+    /**
372
+     * checks whether or not an app is enabled
373
+     *
374
+     * @param string $app app
375
+     * @return bool
376
+     * @deprecated 13.0.0 use \OC::$server->getAppManager()->isEnabledForUser($appId)
377
+     *
378
+     * This function checks whether or not an app is enabled.
379
+     */
380
+    public static function isEnabled($app) {
381
+        return \OC::$server->getAppManager()->isEnabledForUser($app);
382
+    }
383
+
384
+    /**
385
+     * enables an app
386
+     *
387
+     * @param string $appId
388
+     * @param array $groups (optional) when set, only these groups will have access to the app
389
+     * @throws \Exception
390
+     * @return void
391
+     *
392
+     * This function set an app as enabled in appconfig.
393
+     */
394
+    public function enable($appId,
395
+                            $groups = null) {
396
+        self::$enabledAppsCache = []; // flush
397
+
398
+        // Check if app is already downloaded
399
+        $installer = \OC::$server->query(Installer::class);
400
+        $isDownloaded = $installer->isDownloaded($appId);
401
+
402
+        if(!$isDownloaded) {
403
+            $installer->downloadApp($appId);
404
+        }
405
+
406
+        $installer->installApp($appId);
407
+
408
+        $appManager = \OC::$server->getAppManager();
409
+        if (!is_null($groups)) {
410
+            $groupManager = \OC::$server->getGroupManager();
411
+            $groupsList = [];
412
+            foreach ($groups as $group) {
413
+                $groupItem = $groupManager->get($group);
414
+                if ($groupItem instanceof \OCP\IGroup) {
415
+                    $groupsList[] = $groupManager->get($group);
416
+                }
417
+            }
418
+            $appManager->enableAppForGroups($appId, $groupsList);
419
+        } else {
420
+            $appManager->enableApp($appId);
421
+        }
422
+    }
423
+
424
+    /**
425
+     * This function set an app as disabled in appconfig.
426
+     *
427
+     * @param string $app app
428
+     * @throws Exception
429
+     */
430
+    public static function disable($app) {
431
+        // flush
432
+        self::$enabledAppsCache = array();
433
+
434
+        // run uninstall steps
435
+        $appData = OC_App::getAppInfo($app);
436
+        if (!is_null($appData)) {
437
+            OC_App::executeRepairSteps($app, $appData['repair-steps']['uninstall']);
438
+        }
439
+
440
+        // emit disable hook - needed anymore ?
441
+        \OC_Hook::emit('OC_App', 'pre_disable', array('app' => $app));
442
+
443
+        // finally disable it
444
+        $appManager = \OC::$server->getAppManager();
445
+        $appManager->disableApp($app);
446
+    }
447
+
448
+    /**
449
+     * Get the path where to install apps
450
+     *
451
+     * @return string|false
452
+     */
453
+    public static function getInstallPath() {
454
+        if (\OC::$server->getSystemConfig()->getValue('appstoreenabled', true) == false) {
455
+            return false;
456
+        }
457
+
458
+        foreach (OC::$APPSROOTS as $dir) {
459
+            if (isset($dir['writable']) && $dir['writable'] === true) {
460
+                return $dir['path'];
461
+            }
462
+        }
463
+
464
+        \OCP\Util::writeLog('core', 'No application directories are marked as writable.', \OCP\Util::ERROR);
465
+        return null;
466
+    }
467
+
468
+
469
+    /**
470
+     * search for an app in all app-directories
471
+     *
472
+     * @param string $appId
473
+     * @return false|string
474
+     */
475
+    public static function findAppInDirectories($appId) {
476
+        $sanitizedAppId = self::cleanAppId($appId);
477
+        if($sanitizedAppId !== $appId) {
478
+            return false;
479
+        }
480
+        static $app_dir = array();
481
+
482
+        if (isset($app_dir[$appId])) {
483
+            return $app_dir[$appId];
484
+        }
485
+
486
+        $possibleApps = array();
487
+        foreach (OC::$APPSROOTS as $dir) {
488
+            if (file_exists($dir['path'] . '/' . $appId)) {
489
+                $possibleApps[] = $dir;
490
+            }
491
+        }
492
+
493
+        if (empty($possibleApps)) {
494
+            return false;
495
+        } elseif (count($possibleApps) === 1) {
496
+            $dir = array_shift($possibleApps);
497
+            $app_dir[$appId] = $dir;
498
+            return $dir;
499
+        } else {
500
+            $versionToLoad = array();
501
+            foreach ($possibleApps as $possibleApp) {
502
+                $version = self::getAppVersionByPath($possibleApp['path']);
503
+                if (empty($versionToLoad) || version_compare($version, $versionToLoad['version'], '>')) {
504
+                    $versionToLoad = array(
505
+                        'dir' => $possibleApp,
506
+                        'version' => $version,
507
+                    );
508
+                }
509
+            }
510
+            $app_dir[$appId] = $versionToLoad['dir'];
511
+            return $versionToLoad['dir'];
512
+            //TODO - write test
513
+        }
514
+    }
515
+
516
+    /**
517
+     * Get the directory for the given app.
518
+     * If the app is defined in multiple directories, the first one is taken. (false if not found)
519
+     *
520
+     * @param string $appId
521
+     * @return string|false
522
+     */
523
+    public static function getAppPath($appId) {
524
+        if ($appId === null || trim($appId) === '') {
525
+            return false;
526
+        }
527
+
528
+        if (($dir = self::findAppInDirectories($appId)) != false) {
529
+            return $dir['path'] . '/' . $appId;
530
+        }
531
+        return false;
532
+    }
533
+
534
+    /**
535
+     * Get the path for the given app on the access
536
+     * If the app is defined in multiple directories, the first one is taken. (false if not found)
537
+     *
538
+     * @param string $appId
539
+     * @return string|false
540
+     */
541
+    public static function getAppWebPath($appId) {
542
+        if (($dir = self::findAppInDirectories($appId)) != false) {
543
+            return OC::$WEBROOT . $dir['url'] . '/' . $appId;
544
+        }
545
+        return false;
546
+    }
547
+
548
+    /**
549
+     * get the last version of the app from appinfo/info.xml
550
+     *
551
+     * @param string $appId
552
+     * @param bool $useCache
553
+     * @return string
554
+     * @deprecated 14.0.0 use \OC::$server->getAppManager()->getAppVersion()
555
+     */
556
+    public static function getAppVersion($appId, $useCache = true) {
557
+        return \OC::$server->getAppManager()->getAppVersion($appId, $useCache);
558
+    }
559
+
560
+    /**
561
+     * get app's version based on it's path
562
+     *
563
+     * @param string $path
564
+     * @return string
565
+     */
566
+    public static function getAppVersionByPath($path) {
567
+        $infoFile = $path . '/appinfo/info.xml';
568
+        $appData = \OC::$server->getAppManager()->getAppInfo($infoFile, true);
569
+        return isset($appData['version']) ? $appData['version'] : '';
570
+    }
571
+
572
+
573
+    /**
574
+     * Read all app metadata from the info.xml file
575
+     *
576
+     * @param string $appId id of the app or the path of the info.xml file
577
+     * @param bool $path
578
+     * @param string $lang
579
+     * @return array|null
580
+     * @note all data is read from info.xml, not just pre-defined fields
581
+     * @deprecated 14.0.0 use \OC::$server->getAppManager()->getAppInfo()
582
+     */
583
+    public static function getAppInfo($appId, $path = false, $lang = null) {
584
+        return \OC::$server->getAppManager()->getAppInfo($appId, $path, $lang);
585
+    }
586
+
587
+    /**
588
+     * Returns the navigation
589
+     *
590
+     * @return array
591
+     * @deprecated 14.0.0 use \OC::$server->getNavigationManager()->getAll()
592
+     *
593
+     * This function returns an array containing all entries added. The
594
+     * entries are sorted by the key 'order' ascending. Additional to the keys
595
+     * given for each app the following keys exist:
596
+     *   - active: boolean, signals if the user is on this navigation entry
597
+     */
598
+    public static function getNavigation() {
599
+        return OC::$server->getNavigationManager()->getAll();
600
+    }
601
+
602
+    /**
603
+     * Returns the Settings Navigation
604
+     *
605
+     * @return string[]
606
+     * @deprecated 14.0.0 use \OC::$server->getNavigationManager()->getAll('settings')
607
+     *
608
+     * This function returns an array containing all settings pages added. The
609
+     * entries are sorted by the key 'order' ascending.
610
+     */
611
+    public static function getSettingsNavigation() {
612
+        return OC::$server->getNavigationManager()->getAll('settings');
613
+    }
614
+
615
+    /**
616
+     * get the id of loaded app
617
+     *
618
+     * @return string
619
+     */
620
+    public static function getCurrentApp() {
621
+        $request = \OC::$server->getRequest();
622
+        $script = substr($request->getScriptName(), strlen(OC::$WEBROOT) + 1);
623
+        $topFolder = substr($script, 0, strpos($script, '/') ?: 0);
624
+        if (empty($topFolder)) {
625
+            $path_info = $request->getPathInfo();
626
+            if ($path_info) {
627
+                $topFolder = substr($path_info, 1, strpos($path_info, '/', 1) - 1);
628
+            }
629
+        }
630
+        if ($topFolder == 'apps') {
631
+            $length = strlen($topFolder);
632
+            return substr($script, $length + 1, strpos($script, '/', $length + 1) - $length - 1);
633
+        } else {
634
+            return $topFolder;
635
+        }
636
+    }
637
+
638
+    /**
639
+     * @param string $type
640
+     * @return array
641
+     */
642
+    public static function getForms($type) {
643
+        $forms = array();
644
+        switch ($type) {
645
+            case 'admin':
646
+                $source = self::$adminForms;
647
+                break;
648
+            case 'personal':
649
+                $source = self::$personalForms;
650
+                break;
651
+            default:
652
+                return array();
653
+        }
654
+        foreach ($source as $form) {
655
+            $forms[] = include $form;
656
+        }
657
+        return $forms;
658
+    }
659
+
660
+    /**
661
+     * register an admin form to be shown
662
+     *
663
+     * @param string $app
664
+     * @param string $page
665
+     */
666
+    public static function registerAdmin($app, $page) {
667
+        self::$adminForms[] = $app . '/' . $page . '.php';
668
+    }
669
+
670
+    /**
671
+     * register a personal form to be shown
672
+     * @param string $app
673
+     * @param string $page
674
+     */
675
+    public static function registerPersonal($app, $page) {
676
+        self::$personalForms[] = $app . '/' . $page . '.php';
677
+    }
678
+
679
+    /**
680
+     * @param array $entry
681
+     */
682
+    public static function registerLogIn(array $entry) {
683
+        self::$altLogin[] = $entry;
684
+    }
685
+
686
+    /**
687
+     * @return array
688
+     */
689
+    public static function getAlternativeLogIns() {
690
+        return self::$altLogin;
691
+    }
692
+
693
+    /**
694
+     * get a list of all apps in the apps folder
695
+     *
696
+     * @return array an array of app names (string IDs)
697
+     * @todo: change the name of this method to getInstalledApps, which is more accurate
698
+     */
699
+    public static function getAllApps() {
700
+
701
+        $apps = array();
702
+
703
+        foreach (OC::$APPSROOTS as $apps_dir) {
704
+            if (!is_readable($apps_dir['path'])) {
705
+                \OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN);
706
+                continue;
707
+            }
708
+            $dh = opendir($apps_dir['path']);
709
+
710
+            if (is_resource($dh)) {
711
+                while (($file = readdir($dh)) !== false) {
712
+
713
+                    if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) {
714
+
715
+                        $apps[] = $file;
716
+                    }
717
+                }
718
+            }
719
+        }
720
+
721
+        $apps = array_unique($apps);
722
+
723
+        return $apps;
724
+    }
725
+
726
+    /**
727
+     * List all apps, this is used in apps.php
728
+     *
729
+     * @return array
730
+     */
731
+    public function listAllApps() {
732
+        $installedApps = OC_App::getAllApps();
733
+
734
+        $appManager = \OC::$server->getAppManager();
735
+        //we don't want to show configuration for these
736
+        $blacklist = $appManager->getAlwaysEnabledApps();
737
+        $appList = array();
738
+        $langCode = \OC::$server->getL10N('core')->getLanguageCode();
739
+        $urlGenerator = \OC::$server->getURLGenerator();
740
+
741
+        foreach ($installedApps as $app) {
742
+            if (array_search($app, $blacklist) === false) {
743
+
744
+                $info = OC_App::getAppInfo($app, false, $langCode);
745
+                if (!is_array($info)) {
746
+                    \OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR);
747
+                    continue;
748
+                }
749
+
750
+                if (!isset($info['name'])) {
751
+                    \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR);
752
+                    continue;
753
+                }
754
+
755
+                $enabled = \OC::$server->getConfig()->getAppValue($app, 'enabled', 'no');
756
+                $info['groups'] = null;
757
+                if ($enabled === 'yes') {
758
+                    $active = true;
759
+                } else if ($enabled === 'no') {
760
+                    $active = false;
761
+                } else {
762
+                    $active = true;
763
+                    $info['groups'] = $enabled;
764
+                }
765
+
766
+                $info['active'] = $active;
767
+
768
+                if ($appManager->isShipped($app)) {
769
+                    $info['internal'] = true;
770
+                    $info['level'] = self::officialApp;
771
+                    $info['removable'] = false;
772
+                } else {
773
+                    $info['internal'] = false;
774
+                    $info['removable'] = true;
775
+                }
776
+
777
+                $appPath = self::getAppPath($app);
778
+                if($appPath !== false) {
779
+                    $appIcon = $appPath . '/img/' . $app . '.svg';
780
+                    if (file_exists($appIcon)) {
781
+                        $info['preview'] = $urlGenerator->imagePath($app, $app . '.svg');
782
+                        $info['previewAsIcon'] = true;
783
+                    } else {
784
+                        $appIcon = $appPath . '/img/app.svg';
785
+                        if (file_exists($appIcon)) {
786
+                            $info['preview'] = $urlGenerator->imagePath($app, 'app.svg');
787
+                            $info['previewAsIcon'] = true;
788
+                        }
789
+                    }
790
+                }
791
+                // fix documentation
792
+                if (isset($info['documentation']) && is_array($info['documentation'])) {
793
+                    foreach ($info['documentation'] as $key => $url) {
794
+                        // If it is not an absolute URL we assume it is a key
795
+                        // i.e. admin-ldap will get converted to go.php?to=admin-ldap
796
+                        if (stripos($url, 'https://') !== 0 && stripos($url, 'http://') !== 0) {
797
+                            $url = $urlGenerator->linkToDocs($url);
798
+                        }
799
+
800
+                        $info['documentation'][$key] = $url;
801
+                    }
802
+                }
803
+
804
+                $info['version'] = OC_App::getAppVersion($app);
805
+                $appList[] = $info;
806
+            }
807
+        }
808
+
809
+        return $appList;
810
+    }
811
+
812
+    public static function shouldUpgrade($app) {
813
+        $versions = self::getAppVersions();
814
+        $currentVersion = OC_App::getAppVersion($app);
815
+        if ($currentVersion && isset($versions[$app])) {
816
+            $installedVersion = $versions[$app];
817
+            if (!version_compare($currentVersion, $installedVersion, '=')) {
818
+                return true;
819
+            }
820
+        }
821
+        return false;
822
+    }
823
+
824
+    /**
825
+     * Adjust the number of version parts of $version1 to match
826
+     * the number of version parts of $version2.
827
+     *
828
+     * @param string $version1 version to adjust
829
+     * @param string $version2 version to take the number of parts from
830
+     * @return string shortened $version1
831
+     */
832
+    private static function adjustVersionParts($version1, $version2) {
833
+        $version1 = explode('.', $version1);
834
+        $version2 = explode('.', $version2);
835
+        // reduce $version1 to match the number of parts in $version2
836
+        while (count($version1) > count($version2)) {
837
+            array_pop($version1);
838
+        }
839
+        // if $version1 does not have enough parts, add some
840
+        while (count($version1) < count($version2)) {
841
+            $version1[] = '0';
842
+        }
843
+        return implode('.', $version1);
844
+    }
845
+
846
+    /**
847
+     * Check whether the current ownCloud version matches the given
848
+     * application's version requirements.
849
+     *
850
+     * The comparison is made based on the number of parts that the
851
+     * app info version has. For example for ownCloud 6.0.3 if the
852
+     * app info version is expecting version 6.0, the comparison is
853
+     * made on the first two parts of the ownCloud version.
854
+     * This means that it's possible to specify "requiremin" => 6
855
+     * and "requiremax" => 6 and it will still match ownCloud 6.0.3.
856
+     *
857
+     * @param string $ocVersion ownCloud version to check against
858
+     * @param array $appInfo app info (from xml)
859
+     *
860
+     * @return boolean true if compatible, otherwise false
861
+     */
862
+    public static function isAppCompatible($ocVersion, $appInfo) {
863
+        $requireMin = '';
864
+        $requireMax = '';
865
+        if (isset($appInfo['dependencies']['nextcloud']['@attributes']['min-version'])) {
866
+            $requireMin = $appInfo['dependencies']['nextcloud']['@attributes']['min-version'];
867
+        } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['min-version'])) {
868
+            $requireMin = $appInfo['dependencies']['owncloud']['@attributes']['min-version'];
869
+        } else if (isset($appInfo['requiremin'])) {
870
+            $requireMin = $appInfo['requiremin'];
871
+        } else if (isset($appInfo['require'])) {
872
+            $requireMin = $appInfo['require'];
873
+        }
874
+
875
+        if (isset($appInfo['dependencies']['nextcloud']['@attributes']['max-version'])) {
876
+            $requireMax = $appInfo['dependencies']['nextcloud']['@attributes']['max-version'];
877
+        } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['max-version'])) {
878
+            $requireMax = $appInfo['dependencies']['owncloud']['@attributes']['max-version'];
879
+        } else if (isset($appInfo['requiremax'])) {
880
+            $requireMax = $appInfo['requiremax'];
881
+        }
882
+
883
+        if (is_array($ocVersion)) {
884
+            $ocVersion = implode('.', $ocVersion);
885
+        }
886
+
887
+        if (!empty($requireMin)
888
+            && version_compare(self::adjustVersionParts($ocVersion, $requireMin), $requireMin, '<')
889
+        ) {
890
+
891
+            return false;
892
+        }
893
+
894
+        if (!empty($requireMax)
895
+            && version_compare(self::adjustVersionParts($ocVersion, $requireMax), $requireMax, '>')
896
+        ) {
897
+            return false;
898
+        }
899
+
900
+        return true;
901
+    }
902
+
903
+    /**
904
+     * get the installed version of all apps
905
+     */
906
+    public static function getAppVersions() {
907
+        static $versions;
908
+
909
+        if(!$versions) {
910
+            $appConfig = \OC::$server->getAppConfig();
911
+            $versions = $appConfig->getValues(false, 'installed_version');
912
+        }
913
+        return $versions;
914
+    }
915
+
916
+    /**
917
+     * update the database for the app and call the update script
918
+     *
919
+     * @param string $appId
920
+     * @return bool
921
+     */
922
+    public static function updateApp($appId) {
923
+        $appPath = self::getAppPath($appId);
924
+        if($appPath === false) {
925
+            return false;
926
+        }
927
+        self::registerAutoloading($appId, $appPath);
928
+
929
+        $appData = self::getAppInfo($appId);
930
+        self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']);
931
+
932
+        if (file_exists($appPath . '/appinfo/database.xml')) {
933
+            OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml');
934
+        } else {
935
+            $ms = new MigrationService($appId, \OC::$server->getDatabaseConnection());
936
+            $ms->migrate();
937
+        }
938
+
939
+        self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']);
940
+        self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']);
941
+        // update appversion in app manager
942
+        \OC::$server->getAppManager()->getAppVersion($appId, false);
943
+
944
+        // run upgrade code
945
+        if (file_exists($appPath . '/appinfo/update.php')) {
946
+            self::loadApp($appId);
947
+            include $appPath . '/appinfo/update.php';
948
+        }
949
+        self::setupBackgroundJobs($appData['background-jobs']);
950
+
951
+        //set remote/public handlers
952
+        if (array_key_exists('ocsid', $appData)) {
953
+            \OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']);
954
+        } elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) {
955
+            \OC::$server->getConfig()->deleteAppValue($appId, 'ocsid');
956
+        }
957
+        foreach ($appData['remote'] as $name => $path) {
958
+            \OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path);
959
+        }
960
+        foreach ($appData['public'] as $name => $path) {
961
+            \OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path);
962
+        }
963
+
964
+        self::setAppTypes($appId);
965
+
966
+        $version = \OC_App::getAppVersion($appId);
967
+        \OC::$server->getConfig()->setAppValue($appId, 'installed_version', $version);
968
+
969
+        \OC::$server->getEventDispatcher()->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent(
970
+            ManagerEvent::EVENT_APP_UPDATE, $appId
971
+        ));
972
+
973
+        return true;
974
+    }
975
+
976
+    /**
977
+     * @param string $appId
978
+     * @param string[] $steps
979
+     * @throws \OC\NeedsUpdateException
980
+     */
981
+    public static function executeRepairSteps($appId, array $steps) {
982
+        if (empty($steps)) {
983
+            return;
984
+        }
985
+        // load the app
986
+        self::loadApp($appId);
987
+
988
+        $dispatcher = OC::$server->getEventDispatcher();
989
+
990
+        // load the steps
991
+        $r = new Repair([], $dispatcher);
992
+        foreach ($steps as $step) {
993
+            try {
994
+                $r->addStep($step);
995
+            } catch (Exception $ex) {
996
+                $r->emit('\OC\Repair', 'error', [$ex->getMessage()]);
997
+                \OC::$server->getLogger()->logException($ex);
998
+            }
999
+        }
1000
+        // run the steps
1001
+        $r->run();
1002
+    }
1003
+
1004
+    public static function setupBackgroundJobs(array $jobs) {
1005
+        $queue = \OC::$server->getJobList();
1006
+        foreach ($jobs as $job) {
1007
+            $queue->add($job);
1008
+        }
1009
+    }
1010
+
1011
+    /**
1012
+     * @param string $appId
1013
+     * @param string[] $steps
1014
+     */
1015
+    private static function setupLiveMigrations($appId, array $steps) {
1016
+        $queue = \OC::$server->getJobList();
1017
+        foreach ($steps as $step) {
1018
+            $queue->add('OC\Migration\BackgroundRepair', [
1019
+                'app' => $appId,
1020
+                'step' => $step]);
1021
+        }
1022
+    }
1023
+
1024
+    /**
1025
+     * @param string $appId
1026
+     * @return \OC\Files\View|false
1027
+     */
1028
+    public static function getStorage($appId) {
1029
+        if (\OC::$server->getAppManager()->isEnabledForUser($appId)) { //sanity check
1030
+            if (\OC::$server->getUserSession()->isLoggedIn()) {
1031
+                $view = new \OC\Files\View('/' . OC_User::getUser());
1032
+                if (!$view->file_exists($appId)) {
1033
+                    $view->mkdir($appId);
1034
+                }
1035
+                return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId);
1036
+            } else {
1037
+                \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR);
1038
+                return false;
1039
+            }
1040
+        } else {
1041
+            \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR);
1042
+            return false;
1043
+        }
1044
+    }
1045
+
1046
+    protected static function findBestL10NOption($options, $lang) {
1047
+        $fallback = $similarLangFallback = $englishFallback = false;
1048
+
1049
+        $lang = strtolower($lang);
1050
+        $similarLang = $lang;
1051
+        if (strpos($similarLang, '_')) {
1052
+            // For "de_DE" we want to find "de" and the other way around
1053
+            $similarLang = substr($lang, 0, strpos($lang, '_'));
1054
+        }
1055
+
1056
+        foreach ($options as $option) {
1057
+            if (is_array($option)) {
1058
+                if ($fallback === false) {
1059
+                    $fallback = $option['@value'];
1060
+                }
1061
+
1062
+                if (!isset($option['@attributes']['lang'])) {
1063
+                    continue;
1064
+                }
1065
+
1066
+                $attributeLang = strtolower($option['@attributes']['lang']);
1067
+                if ($attributeLang === $lang) {
1068
+                    return $option['@value'];
1069
+                }
1070
+
1071
+                if ($attributeLang === $similarLang) {
1072
+                    $similarLangFallback = $option['@value'];
1073
+                } else if (strpos($attributeLang, $similarLang . '_') === 0) {
1074
+                    if ($similarLangFallback === false) {
1075
+                        $similarLangFallback =  $option['@value'];
1076
+                    }
1077
+                }
1078
+            } else {
1079
+                $englishFallback = $option;
1080
+            }
1081
+        }
1082
+
1083
+        if ($similarLangFallback !== false) {
1084
+            return $similarLangFallback;
1085
+        } else if ($englishFallback !== false) {
1086
+            return $englishFallback;
1087
+        }
1088
+        return (string) $fallback;
1089
+    }
1090
+
1091
+    /**
1092
+     * parses the app data array and enhanced the 'description' value
1093
+     *
1094
+     * @param array $data the app data
1095
+     * @param string $lang
1096
+     * @return array improved app data
1097
+     */
1098
+    public static function parseAppInfo(array $data, $lang = null) {
1099
+
1100
+        if ($lang && isset($data['name']) && is_array($data['name'])) {
1101
+            $data['name'] = self::findBestL10NOption($data['name'], $lang);
1102
+        }
1103
+        if ($lang && isset($data['summary']) && is_array($data['summary'])) {
1104
+            $data['summary'] = self::findBestL10NOption($data['summary'], $lang);
1105
+        }
1106
+        if ($lang && isset($data['description']) && is_array($data['description'])) {
1107
+            $data['description'] = trim(self::findBestL10NOption($data['description'], $lang));
1108
+        } else if (isset($data['description']) && is_string($data['description'])) {
1109
+            $data['description'] = trim($data['description']);
1110
+        } else  {
1111
+            $data['description'] = '';
1112
+        }
1113
+
1114
+        return $data;
1115
+    }
1116
+
1117
+    /**
1118
+     * @param \OCP\IConfig $config
1119
+     * @param \OCP\IL10N $l
1120
+     * @param array $info
1121
+     * @throws \Exception
1122
+     */
1123
+    public static function checkAppDependencies($config, $l, $info) {
1124
+        $dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l);
1125
+        $missing = $dependencyAnalyzer->analyze($info);
1126
+        if (!empty($missing)) {
1127
+            $missingMsg = implode(PHP_EOL, $missing);
1128
+            throw new \Exception(
1129
+                $l->t('App "%s" cannot be installed because the following dependencies are not fulfilled: %s',
1130
+                    [$info['name'], $missingMsg]
1131
+                )
1132
+            );
1133
+        }
1134
+    }
1135 1135
 }
Please login to merge, or discard this patch.