Completed
Pull Request — master (#3008)
by Julius
24:00 queued 10:27
created
lib/private/TemplateLayout.php 2 patches
Indentation   +200 added lines, -200 removed lines patch added patch discarded remove patch
@@ -40,229 +40,229 @@
 block discarded – undo
40 40
 
41 41
 class TemplateLayout extends \OC_Template {
42 42
 
43
-	private static $versionHash = '';
43
+    private static $versionHash = '';
44 44
 
45
-	/**
46
-	 * @var \OCP\IConfig
47
-	 */
48
-	private $config;
45
+    /**
46
+     * @var \OCP\IConfig
47
+     */
48
+    private $config;
49 49
 
50
-	/**
51
-	 * @param string $renderAs
52
-	 * @param string $appId application id
53
-	 */
54
-	public function __construct( $renderAs, $appId = '' ) {
50
+    /**
51
+     * @param string $renderAs
52
+     * @param string $appId application id
53
+     */
54
+    public function __construct( $renderAs, $appId = '' ) {
55 55
 
56
-		// yes - should be injected ....
57
-		$this->config = \OC::$server->getConfig();
56
+        // yes - should be injected ....
57
+        $this->config = \OC::$server->getConfig();
58 58
 
59
-		// Decide which page we show
60
-		if($renderAs == 'user') {
61
-			parent::__construct( 'core', 'layout.user' );
62
-			if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) {
63
-				$this->assign('bodyid', 'body-settings');
64
-			}else{
65
-				$this->assign('bodyid', 'body-user');
66
-			}
59
+        // Decide which page we show
60
+        if($renderAs == 'user') {
61
+            parent::__construct( 'core', 'layout.user' );
62
+            if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) {
63
+                $this->assign('bodyid', 'body-settings');
64
+            }else{
65
+                $this->assign('bodyid', 'body-user');
66
+            }
67 67
 
68
-			// Code integrity notification
69
-			$integrityChecker = \OC::$server->getIntegrityCodeChecker();
70
-			if(\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) {
71
-				\OCP\Util::addScript('core', 'integritycheck-failed-notification');
72
-			}
68
+            // Code integrity notification
69
+            $integrityChecker = \OC::$server->getIntegrityCodeChecker();
70
+            if(\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) {
71
+                \OCP\Util::addScript('core', 'integritycheck-failed-notification');
72
+            }
73 73
 
74
-			// Add navigation entry
75
-			$this->assign( 'application', '');
76
-			$this->assign( 'appid', $appId );
77
-			$navigation = \OC_App::getNavigation();
78
-			$this->assign( 'navigation', $navigation);
79
-			$navigation = \OC_App::getHeaderNavigation();
80
-			$this->assign( 'headernavigation', $navigation);
81
-			$settingsNavigation = \OC_App::getSettingsNavigation();
82
-			$this->assign( 'settingsnavigation', $settingsNavigation);
83
-			foreach($navigation as $entry) {
84
-				if ($entry['active']) {
85
-					$this->assign( 'application', $entry['name'] );
86
-					break;
87
-				}
88
-			}
74
+            // Add navigation entry
75
+            $this->assign( 'application', '');
76
+            $this->assign( 'appid', $appId );
77
+            $navigation = \OC_App::getNavigation();
78
+            $this->assign( 'navigation', $navigation);
79
+            $navigation = \OC_App::getHeaderNavigation();
80
+            $this->assign( 'headernavigation', $navigation);
81
+            $settingsNavigation = \OC_App::getSettingsNavigation();
82
+            $this->assign( 'settingsnavigation', $settingsNavigation);
83
+            foreach($navigation as $entry) {
84
+                if ($entry['active']) {
85
+                    $this->assign( 'application', $entry['name'] );
86
+                    break;
87
+                }
88
+            }
89 89
 			
90
-			foreach($settingsNavigation as $entry) {
91
-				if ($entry['active']) {
92
-					$this->assign( 'application', $entry['name'] );
93
-					break;
94
-				}
95
-			}
96
-			$userDisplayName = \OC_User::getDisplayName();
97
-			$appsMgmtActive = strpos(\OC::$server->getRequest()->getRequestUri(), \OC::$server->getURLGenerator()->linkToRoute('settings.AppSettings.viewApps')) === 0;
98
-			if ($appsMgmtActive) {
99
-				$l = \OC::$server->getL10N('lib');
100
-				$this->assign('application', $l->t('Apps'));
101
-			}
102
-			$this->assign('user_displayname', $userDisplayName);
103
-			$this->assign('user_uid', \OC_User::getUser());
104
-			$this->assign('appsmanagement_active', $appsMgmtActive);
90
+            foreach($settingsNavigation as $entry) {
91
+                if ($entry['active']) {
92
+                    $this->assign( 'application', $entry['name'] );
93
+                    break;
94
+                }
95
+            }
96
+            $userDisplayName = \OC_User::getDisplayName();
97
+            $appsMgmtActive = strpos(\OC::$server->getRequest()->getRequestUri(), \OC::$server->getURLGenerator()->linkToRoute('settings.AppSettings.viewApps')) === 0;
98
+            if ($appsMgmtActive) {
99
+                $l = \OC::$server->getL10N('lib');
100
+                $this->assign('application', $l->t('Apps'));
101
+            }
102
+            $this->assign('user_displayname', $userDisplayName);
103
+            $this->assign('user_uid', \OC_User::getUser());
104
+            $this->assign('appsmanagement_active', $appsMgmtActive);
105 105
 
106
-			if (\OC_User::getUser() === false) {
107
-				$this->assign('userAvatarSet', false);
108
-			} else {
109
-				$this->assign('userAvatarSet', \OC::$server->getAvatarManager()->getAvatar(\OC_User::getUser())->exists());
110
-				$this->assign('userAvatarVersion', \OC::$server->getConfig()->getUserValue(\OC_User::getUser(), 'avatar', 'version', 0));
111
-			}
106
+            if (\OC_User::getUser() === false) {
107
+                $this->assign('userAvatarSet', false);
108
+            } else {
109
+                $this->assign('userAvatarSet', \OC::$server->getAvatarManager()->getAvatar(\OC_User::getUser())->exists());
110
+                $this->assign('userAvatarVersion', \OC::$server->getConfig()->getUserValue(\OC_User::getUser(), 'avatar', 'version', 0));
111
+            }
112 112
 
113
-		} else if ($renderAs == 'error') {
114
-			parent::__construct('core', 'layout.guest', '', false);
115
-			$this->assign('bodyid', 'body-login');
116
-		} else if ($renderAs == 'guest') {
117
-			parent::__construct('core', 'layout.guest');
118
-			$this->assign('bodyid', 'body-login');
119
-		} else {
120
-			parent::__construct('core', 'layout.base');
113
+        } else if ($renderAs == 'error') {
114
+            parent::__construct('core', 'layout.guest', '', false);
115
+            $this->assign('bodyid', 'body-login');
116
+        } else if ($renderAs == 'guest') {
117
+            parent::__construct('core', 'layout.guest');
118
+            $this->assign('bodyid', 'body-login');
119
+        } else {
120
+            parent::__construct('core', 'layout.base');
121 121
 
122
-		}
123
-		// Send the language to our layouts
124
-		$this->assign('language', \OC::$server->getL10NFactory()->findLanguage());
122
+        }
123
+        // Send the language to our layouts
124
+        $this->assign('language', \OC::$server->getL10NFactory()->findLanguage());
125 125
 
126
-		if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
127
-			if (empty(self::$versionHash)) {
128
-				$v = \OC_App::getAppVersions();
129
-				$v['core'] = implode('.', \OCP\Util::getVersion());
130
-				self::$versionHash = md5(implode(',', $v));
131
-			}
132
-		} else {
133
-			self::$versionHash = md5('not installed');
134
-		}
126
+        if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
127
+            if (empty(self::$versionHash)) {
128
+                $v = \OC_App::getAppVersions();
129
+                $v['core'] = implode('.', \OCP\Util::getVersion());
130
+                self::$versionHash = md5(implode(',', $v));
131
+            }
132
+        } else {
133
+            self::$versionHash = md5('not installed');
134
+        }
135 135
 
136
-		// Add the js files
137
-		$jsFiles = self::findJavascriptFiles(\OC_Util::$scripts);
138
-		$this->assign('jsfiles', array());
139
-		if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') {
140
-			if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) {
141
-				$jsConfigHelper = new JSConfigHelper(
142
-					\OC::$server->getL10N('core'),
143
-					\OC::$server->getThemingDefaults(),
144
-					\OC::$server->getAppManager(),
145
-					\OC::$server->getSession(),
146
-					\OC::$server->getUserSession()->getUser(),
147
-					\OC::$server->getConfig(),
148
-					\OC::$server->getGroupManager(),
149
-					\OC::$server->getIniWrapper(),
150
-					\OC::$server->getURLGenerator()
151
-				);
152
-				$this->assign('inline_ocjs', $jsConfigHelper->getConfig());
153
-				$this->assign('foo', 'bar');
154
-			} else {
155
-				$this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash]));
156
-			}
157
-		}
158
-		foreach($jsFiles as $info) {
159
-			$web = $info[1];
160
-			$file = $info[2];
161
-			$this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() );
162
-		}
136
+        // Add the js files
137
+        $jsFiles = self::findJavascriptFiles(\OC_Util::$scripts);
138
+        $this->assign('jsfiles', array());
139
+        if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') {
140
+            if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) {
141
+                $jsConfigHelper = new JSConfigHelper(
142
+                    \OC::$server->getL10N('core'),
143
+                    \OC::$server->getThemingDefaults(),
144
+                    \OC::$server->getAppManager(),
145
+                    \OC::$server->getSession(),
146
+                    \OC::$server->getUserSession()->getUser(),
147
+                    \OC::$server->getConfig(),
148
+                    \OC::$server->getGroupManager(),
149
+                    \OC::$server->getIniWrapper(),
150
+                    \OC::$server->getURLGenerator()
151
+                );
152
+                $this->assign('inline_ocjs', $jsConfigHelper->getConfig());
153
+                $this->assign('foo', 'bar');
154
+            } else {
155
+                $this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash]));
156
+            }
157
+        }
158
+        foreach($jsFiles as $info) {
159
+            $web = $info[1];
160
+            $file = $info[2];
161
+            $this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() );
162
+        }
163 163
 
164
-		try {
165
-			$pathInfo = \OC::$server->getRequest()->getPathInfo();
166
-		} catch (\Exception $e) {
167
-			$pathInfo = '';
168
-		}
164
+        try {
165
+            $pathInfo = \OC::$server->getRequest()->getPathInfo();
166
+        } catch (\Exception $e) {
167
+            $pathInfo = '';
168
+        }
169 169
 
170
-		// Do not initialise scss appdata until we have a fully installed instance
171
-		// Do not load scss for update, errors, installation or login page
172
-		if(\OC::$server->getSystemConfig()->getValue('installed', false)
173
-			&& !\OCP\Util::needUpgrade()
174
-			&& $pathInfo !== ''
175
-			&& !preg_match('/^\/login/', $pathInfo)) {
176
-			$cssFiles = self::findStylesheetFiles(\OC_Util::$styles);
177
-		} else {
178
-			// If we ignore the scss compiler,
179
-			// we need to load the guest css fallback
180
-			\OC_Util::addStyle('guest');
181
-			$cssFiles = self::findStylesheetFiles(\OC_Util::$styles, false);
182
-		}
170
+        // Do not initialise scss appdata until we have a fully installed instance
171
+        // Do not load scss for update, errors, installation or login page
172
+        if(\OC::$server->getSystemConfig()->getValue('installed', false)
173
+            && !\OCP\Util::needUpgrade()
174
+            && $pathInfo !== ''
175
+            && !preg_match('/^\/login/', $pathInfo)) {
176
+            $cssFiles = self::findStylesheetFiles(\OC_Util::$styles);
177
+        } else {
178
+            // If we ignore the scss compiler,
179
+            // we need to load the guest css fallback
180
+            \OC_Util::addStyle('guest');
181
+            $cssFiles = self::findStylesheetFiles(\OC_Util::$styles, false);
182
+        }
183 183
 
184
-		$this->assign('cssfiles', array());
185
-		$this->assign('printcssfiles', []);
186
-		$this->assign('versionHash', self::$versionHash);
187
-		foreach($cssFiles as $info) {
188
-			$web = $info[1];
189
-			$file = $info[2];
184
+        $this->assign('cssfiles', array());
185
+        $this->assign('printcssfiles', []);
186
+        $this->assign('versionHash', self::$versionHash);
187
+        foreach($cssFiles as $info) {
188
+            $web = $info[1];
189
+            $file = $info[2];
190 190
 
191
-			if (substr($file, -strlen('print.css')) === 'print.css') {
192
-				$this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() );
193
-			} else {
194
-				$this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix()  );
195
-			}
196
-		}
197
-	}
191
+            if (substr($file, -strlen('print.css')) === 'print.css') {
192
+                $this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() );
193
+            } else {
194
+                $this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix()  );
195
+            }
196
+        }
197
+    }
198 198
 
199
-	protected function getVersionHashSuffix() {
200
-		if(\OC::$server->getConfig()->getSystemValue('debug', false)) {
201
-			// allows chrome workspace mapping in debug mode
202
-			return "";
203
-		}
199
+    protected function getVersionHashSuffix() {
200
+        if(\OC::$server->getConfig()->getSystemValue('debug', false)) {
201
+            // allows chrome workspace mapping in debug mode
202
+            return "";
203
+        }
204 204
 
205
-		return '?v=' . self::$versionHash;
206
-	}
205
+        return '?v=' . self::$versionHash;
206
+    }
207 207
 
208
-	/**
209
-	 * @param array $styles
210
-	 * @return array
211
-	 */
212
-	static public function findStylesheetFiles($styles, $compileScss = true) {
213
-		// Read the selected theme from the config file
214
-		$theme = \OC_Util::getTheme();
208
+    /**
209
+     * @param array $styles
210
+     * @return array
211
+     */
212
+    static public function findStylesheetFiles($styles, $compileScss = true) {
213
+        // Read the selected theme from the config file
214
+        $theme = \OC_Util::getTheme();
215 215
 
216
-		if($compileScss) {
217
-			$SCSSCacher = new SCSSCacher(
218
-				\OC::$server->getLogger(),
219
-				\OC::$server->getAppDataDir('css'),
220
-				\OC::$server->getURLGenerator(),
221
-				\OC::$server->getSystemConfig()
222
-			);
223
-		} else {
224
-			$SCSSCacher = null;
225
-		}
216
+        if($compileScss) {
217
+            $SCSSCacher = new SCSSCacher(
218
+                \OC::$server->getLogger(),
219
+                \OC::$server->getAppDataDir('css'),
220
+                \OC::$server->getURLGenerator(),
221
+                \OC::$server->getSystemConfig()
222
+            );
223
+        } else {
224
+            $SCSSCacher = null;
225
+        }
226 226
 
227
-		$locator = new \OC\Template\CSSResourceLocator(
228
-			\OC::$server->getLogger(),
229
-			$theme,
230
-			array( \OC::$SERVERROOT => \OC::$WEBROOT ),
231
-			array( \OC::$SERVERROOT => \OC::$WEBROOT ),
232
-			$SCSSCacher);
233
-		$locator->find($styles);
234
-		return $locator->getResources();
235
-	}
227
+        $locator = new \OC\Template\CSSResourceLocator(
228
+            \OC::$server->getLogger(),
229
+            $theme,
230
+            array( \OC::$SERVERROOT => \OC::$WEBROOT ),
231
+            array( \OC::$SERVERROOT => \OC::$WEBROOT ),
232
+            $SCSSCacher);
233
+        $locator->find($styles);
234
+        return $locator->getResources();
235
+    }
236 236
 
237
-	/**
238
-	 * @param array $scripts
239
-	 * @return array
240
-	 */
241
-	static public function findJavascriptFiles($scripts) {
242
-		// Read the selected theme from the config file
243
-		$theme = \OC_Util::getTheme();
237
+    /**
238
+     * @param array $scripts
239
+     * @return array
240
+     */
241
+    static public function findJavascriptFiles($scripts) {
242
+        // Read the selected theme from the config file
243
+        $theme = \OC_Util::getTheme();
244 244
 
245
-		$locator = new \OC\Template\JSResourceLocator(
246
-			\OC::$server->getLogger(),
247
-			$theme,
248
-			array( \OC::$SERVERROOT => \OC::$WEBROOT ),
249
-			array( \OC::$SERVERROOT => \OC::$WEBROOT ));
250
-		$locator->find($scripts);
251
-		return $locator->getResources();
252
-	}
245
+        $locator = new \OC\Template\JSResourceLocator(
246
+            \OC::$server->getLogger(),
247
+            $theme,
248
+            array( \OC::$SERVERROOT => \OC::$WEBROOT ),
249
+            array( \OC::$SERVERROOT => \OC::$WEBROOT ));
250
+        $locator->find($scripts);
251
+        return $locator->getResources();
252
+    }
253 253
 
254
-	/**
255
-	 * Converts the absolute file path to a relative path from \OC::$SERVERROOT
256
-	 * @param string $filePath Absolute path
257
-	 * @return string Relative path
258
-	 * @throws \Exception If $filePath is not under \OC::$SERVERROOT
259
-	 */
260
-	public static function convertToRelativePath($filePath) {
261
-		$relativePath = explode(\OC::$SERVERROOT, $filePath);
262
-		if(count($relativePath) !== 2) {
263
-			throw new \Exception('$filePath is not under the \OC::$SERVERROOT');
264
-		}
254
+    /**
255
+     * Converts the absolute file path to a relative path from \OC::$SERVERROOT
256
+     * @param string $filePath Absolute path
257
+     * @return string Relative path
258
+     * @throws \Exception If $filePath is not under \OC::$SERVERROOT
259
+     */
260
+    public static function convertToRelativePath($filePath) {
261
+        $relativePath = explode(\OC::$SERVERROOT, $filePath);
262
+        if(count($relativePath) !== 2) {
263
+            throw new \Exception('$filePath is not under the \OC::$SERVERROOT');
264
+        }
265 265
 
266
-		return $relativePath[1];
267
-	}
266
+        return $relativePath[1];
267
+    }
268 268
 }
Please login to merge, or discard this patch.
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -51,45 +51,45 @@  discard block
 block discarded – undo
51 51
 	 * @param string $renderAs
52 52
 	 * @param string $appId application id
53 53
 	 */
54
-	public function __construct( $renderAs, $appId = '' ) {
54
+	public function __construct($renderAs, $appId = '') {
55 55
 
56 56
 		// yes - should be injected ....
57 57
 		$this->config = \OC::$server->getConfig();
58 58
 
59 59
 		// Decide which page we show
60
-		if($renderAs == 'user') {
61
-			parent::__construct( 'core', 'layout.user' );
62
-			if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) {
60
+		if ($renderAs == 'user') {
61
+			parent::__construct('core', 'layout.user');
62
+			if (in_array(\OC_App::getCurrentApp(), ['settings', 'admin', 'help']) !== false) {
63 63
 				$this->assign('bodyid', 'body-settings');
64
-			}else{
64
+			} else {
65 65
 				$this->assign('bodyid', 'body-user');
66 66
 			}
67 67
 
68 68
 			// Code integrity notification
69 69
 			$integrityChecker = \OC::$server->getIntegrityCodeChecker();
70
-			if(\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) {
70
+			if (\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) {
71 71
 				\OCP\Util::addScript('core', 'integritycheck-failed-notification');
72 72
 			}
73 73
 
74 74
 			// Add navigation entry
75
-			$this->assign( 'application', '');
76
-			$this->assign( 'appid', $appId );
75
+			$this->assign('application', '');
76
+			$this->assign('appid', $appId);
77 77
 			$navigation = \OC_App::getNavigation();
78
-			$this->assign( 'navigation', $navigation);
78
+			$this->assign('navigation', $navigation);
79 79
 			$navigation = \OC_App::getHeaderNavigation();
80
-			$this->assign( 'headernavigation', $navigation);
80
+			$this->assign('headernavigation', $navigation);
81 81
 			$settingsNavigation = \OC_App::getSettingsNavigation();
82
-			$this->assign( 'settingsnavigation', $settingsNavigation);
83
-			foreach($navigation as $entry) {
82
+			$this->assign('settingsnavigation', $settingsNavigation);
83
+			foreach ($navigation as $entry) {
84 84
 				if ($entry['active']) {
85
-					$this->assign( 'application', $entry['name'] );
85
+					$this->assign('application', $entry['name']);
86 86
 					break;
87 87
 				}
88 88
 			}
89 89
 			
90
-			foreach($settingsNavigation as $entry) {
90
+			foreach ($settingsNavigation as $entry) {
91 91
 				if ($entry['active']) {
92
-					$this->assign( 'application', $entry['name'] );
92
+					$this->assign('application', $entry['name']);
93 93
 					break;
94 94
 				}
95 95
 			}
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 		// Send the language to our layouts
124 124
 		$this->assign('language', \OC::$server->getL10NFactory()->findLanguage());
125 125
 
126
-		if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
126
+		if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
127 127
 			if (empty(self::$versionHash)) {
128 128
 				$v = \OC_App::getAppVersions();
129 129
 				$v['core'] = implode('.', \OCP\Util::getVersion());
@@ -155,10 +155,10 @@  discard block
 block discarded – undo
155 155
 				$this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash]));
156 156
 			}
157 157
 		}
158
-		foreach($jsFiles as $info) {
158
+		foreach ($jsFiles as $info) {
159 159
 			$web = $info[1];
160 160
 			$file = $info[2];
161
-			$this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() );
161
+			$this->append('jsfiles', $web.'/'.$file.$this->getVersionHashSuffix());
162 162
 		}
163 163
 
164 164
 		try {
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
 
170 170
 		// Do not initialise scss appdata until we have a fully installed instance
171 171
 		// Do not load scss for update, errors, installation or login page
172
-		if(\OC::$server->getSystemConfig()->getValue('installed', false)
172
+		if (\OC::$server->getSystemConfig()->getValue('installed', false)
173 173
 			&& !\OCP\Util::needUpgrade()
174 174
 			&& $pathInfo !== ''
175 175
 			&& !preg_match('/^\/login/', $pathInfo)) {
@@ -184,25 +184,25 @@  discard block
 block discarded – undo
184 184
 		$this->assign('cssfiles', array());
185 185
 		$this->assign('printcssfiles', []);
186 186
 		$this->assign('versionHash', self::$versionHash);
187
-		foreach($cssFiles as $info) {
187
+		foreach ($cssFiles as $info) {
188 188
 			$web = $info[1];
189 189
 			$file = $info[2];
190 190
 
191 191
 			if (substr($file, -strlen('print.css')) === 'print.css') {
192
-				$this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() );
192
+				$this->append('printcssfiles', $web.'/'.$file.$this->getVersionHashSuffix());
193 193
 			} else {
194
-				$this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix()  );
194
+				$this->append('cssfiles', $web.'/'.$file.$this->getVersionHashSuffix());
195 195
 			}
196 196
 		}
197 197
 	}
198 198
 
199 199
 	protected function getVersionHashSuffix() {
200
-		if(\OC::$server->getConfig()->getSystemValue('debug', false)) {
200
+		if (\OC::$server->getConfig()->getSystemValue('debug', false)) {
201 201
 			// allows chrome workspace mapping in debug mode
202 202
 			return "";
203 203
 		}
204 204
 
205
-		return '?v=' . self::$versionHash;
205
+		return '?v='.self::$versionHash;
206 206
 	}
207 207
 
208 208
 	/**
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
 		// Read the selected theme from the config file
214 214
 		$theme = \OC_Util::getTheme();
215 215
 
216
-		if($compileScss) {
216
+		if ($compileScss) {
217 217
 			$SCSSCacher = new SCSSCacher(
218 218
 				\OC::$server->getLogger(),
219 219
 				\OC::$server->getAppDataDir('css'),
@@ -227,8 +227,8 @@  discard block
 block discarded – undo
227 227
 		$locator = new \OC\Template\CSSResourceLocator(
228 228
 			\OC::$server->getLogger(),
229 229
 			$theme,
230
-			array( \OC::$SERVERROOT => \OC::$WEBROOT ),
231
-			array( \OC::$SERVERROOT => \OC::$WEBROOT ),
230
+			array(\OC::$SERVERROOT => \OC::$WEBROOT),
231
+			array(\OC::$SERVERROOT => \OC::$WEBROOT),
232 232
 			$SCSSCacher);
233 233
 		$locator->find($styles);
234 234
 		return $locator->getResources();
@@ -245,8 +245,8 @@  discard block
 block discarded – undo
245 245
 		$locator = new \OC\Template\JSResourceLocator(
246 246
 			\OC::$server->getLogger(),
247 247
 			$theme,
248
-			array( \OC::$SERVERROOT => \OC::$WEBROOT ),
249
-			array( \OC::$SERVERROOT => \OC::$WEBROOT ));
248
+			array(\OC::$SERVERROOT => \OC::$WEBROOT),
249
+			array(\OC::$SERVERROOT => \OC::$WEBROOT));
250 250
 		$locator->find($scripts);
251 251
 		return $locator->getResources();
252 252
 	}
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 	 */
260 260
 	public static function convertToRelativePath($filePath) {
261 261
 		$relativePath = explode(\OC::$SERVERROOT, $filePath);
262
-		if(count($relativePath) !== 2) {
262
+		if (count($relativePath) !== 2) {
263 263
 			throw new \Exception('$filePath is not under the \OC::$SERVERROOT');
264 264
 		}
265 265
 
Please login to merge, or discard this patch.
core/templates/layout.user.php 3 patches
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -111,8 +111,11 @@
 block discarded – undo
111 111
 								<?php foreach($_['navigation'] as $entry): ?>
112 112
 									<?php if($entry['showInHeader']): ?>
113 113
 										<li data-id="<?php p($entry['id']); ?>" class="in-header">
114
-									<?php else: ?>
115
-										<li data-id="<?php p($entry['id']); ?>">
114
+									<?php else {
115
+    : ?>
116
+										<li data-id="<?php p($entry['id']);
117
+}
118
+?>">
116 119
 									<?php endif; ?>
117 120
 									<a href="<?php print_unescaped($entry['href']); ?>" tabindex="3"
118 121
 										<?php if( $entry['active'] ): ?> class="active"<?php endif; ?>>
Please login to merge, or discard this patch.
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -4,9 +4,9 @@  discard block
 block discarded – undo
4 4
 		<meta charset="utf-8">
5 5
 		<title>
6 6
 			<?php
7
-				p(!empty($_['application'])?$_['application'].' - ':'');
8
-				p($theme->getTitle());
9
-			?>
7
+                p(!empty($_['application'])?$_['application'].' - ':'');
8
+                p($theme->getTitle());
9
+            ?>
10 10
 		</title>
11 11
 		<meta http-equiv="X-UA-Compatible" content="IE=edge">
12 12
 		<meta name="referrer" content="never">
@@ -116,9 +116,9 @@  discard block
 block discarded – undo
116 116
 									</li>
117 117
 								<?php endforeach; ?>
118 118
 								<?php
119
-								/* show "More apps" link to app administration directly in app navigation, as last entry */
120
-								if(OC_User::isAdminUser(OC_User::getUser())):
121
-									?>
119
+                                /* show "More apps" link to app administration directly in app navigation, as last entry */
120
+                                if(OC_User::isAdminUser(OC_User::getUser())):
121
+                                    ?>
122 122
 									<li id="apps-management">
123 123
 										<a href="<?php print_unescaped(\OC::$server->getURLGenerator()->linkToRoute('settings.AppSettings.viewApps')); ?>" tabindex="4"
124 124
 											<?php if( $_['appsmanagement_active'] ): ?> class="active"<?php endif; ?>>
Please login to merge, or discard this patch.
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 		<meta charset="utf-8">
5 5
 		<title>
6 6
 			<?php
7
-				p(!empty($_['application'])?$_['application'].' - ':'');
7
+				p(!empty($_['application']) ? $_['application'].' - ' : '');
8 8
 				p($theme->getTitle());
9 9
 			?>
10 10
 		</title>
@@ -14,16 +14,16 @@  discard block
 block discarded – undo
14 14
 		<meta name="apple-itunes-app" content="app-id=<?php p($theme->getiTunesAppId()); ?>">
15 15
 		<meta name="apple-mobile-web-app-capable" content="yes">
16 16
 		<meta name="apple-mobile-web-app-status-bar-style" content="black">
17
-		<meta name="apple-mobile-web-app-title" content="<?php p((!empty($_['application']) && $_['appid']!='files')? $_['application']:$theme->getTitle()); ?>">
17
+		<meta name="apple-mobile-web-app-title" content="<?php p((!empty($_['application']) && $_['appid'] != 'files') ? $_['application'] : $theme->getTitle()); ?>">
18 18
 		<meta name="mobile-web-app-capable" content="yes">
19 19
 		<meta name="theme-color" content="<?php p($theme->getMailHeaderColor()); ?>">
20 20
 		<link rel="icon" href="<?php print_unescaped(image_path($_['appid'], 'favicon.ico')); /* IE11+ supports png */ ?>">
21 21
 		<link rel="apple-touch-icon-precomposed" href="<?php print_unescaped(image_path($_['appid'], 'favicon-touch.png')); ?>">
22 22
 		<link rel="mask-icon" sizes="any" href="<?php print_unescaped(image_path($_['appid'], 'favicon-mask.svg')); ?>" color="#0082c9">
23
-		<?php foreach($_['cssfiles'] as $cssfile): ?>
23
+		<?php foreach ($_['cssfiles'] as $cssfile): ?>
24 24
 			<link rel="stylesheet" href="<?php print_unescaped($cssfile); ?>">
25 25
 		<?php endforeach; ?>
26
-		<?php foreach($_['printcssfiles'] as $cssfile): ?>
26
+		<?php foreach ($_['printcssfiles'] as $cssfile): ?>
27 27
 			<link rel="stylesheet" href="<?php print_unescaped($cssfile); ?>" media="print">
28 28
 		<?php endforeach; ?>
29 29
 		<?php if (isset($_['inline_ocjs'])): ?>
@@ -31,12 +31,12 @@  discard block
 block discarded – undo
31 31
 				<?php print_unescaped($_['inline_ocjs']); ?>
32 32
 			</script>
33 33
 		<?php endif; ?>
34
-		<?php foreach($_['jsfiles'] as $jsfile): ?>
34
+		<?php foreach ($_['jsfiles'] as $jsfile): ?>
35 35
 			<script nonce="<?php p(\OC::$server->getContentSecurityPolicyNonceManager()->getNonce()) ?>" src="<?php print_unescaped($jsfile); ?>"></script>
36 36
 		<?php endforeach; ?>
37 37
 		<?php print_unescaped($_['headers']); ?>
38 38
 	</head>
39
-	<body id="<?php p($_['bodyid']);?>">
39
+	<body id="<?php p($_['bodyid']); ?>">
40 40
 	<?php include('layout.noscript.warning.php'); ?>
41 41
 	<div id="notification-container">
42 42
 		<div id="notification"></div>
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 
55 55
 				<a href="#" class="header-appname-container menutoggle" tabindex="2">
56 56
 					<h1 class="header-appname">
57
-						<?php p(!empty($_['application'])?$_['application']: $l->t('Apps')); ?>
57
+						<?php p(!empty($_['application']) ? $_['application'] : $l->t('Apps')); ?>
58 58
 					</h1>
59 59
 					<div class="icon-caret"></div>
60 60
 				</a>
@@ -62,11 +62,11 @@  discard block
 block discarded – undo
62 62
 				<div id="appmenu">
63 63
 					<ul>
64 64
 						<?php $headerIconCount = 8; ?>
65
-						<?php foreach($_['headernavigation'] as $entry): ?>
65
+						<?php foreach ($_['headernavigation'] as $entry): ?>
66 66
 							<li data-id="<?php p($entry['id']); ?>">
67 67
 								<a href="<?php print_unescaped($entry['href']); ?>" tabindex="3"
68
-									<?php if( $entry['active'] ): ?> class="active"<?php endif; ?>>
69
-									<img src="<?php print_unescaped($entry['icon'] . '?v=' . $_['versionHash']); ?>"  class="app-icon" />
68
+									<?php if ($entry['active']): ?> class="active"<?php endif; ?>>
69
+									<img src="<?php print_unescaped($entry['icon'].'?v='.$_['versionHash']); ?>"  class="app-icon" />
70 70
 									<div class="icon-loading-dark" style="display:none;"></div>
71 71
 									<span>
72 72
 								<?php p($entry['name']); ?>
@@ -74,17 +74,17 @@  discard block
 block discarded – undo
74 74
 								</a>
75 75
 							</li>
76 76
 						<?php endforeach; ?>
77
-							<li id="more-apps" class="menutoggle<?php if (!(count($_['navigation']) > $headerIconCount || (OC_User::isAdminUser(OC_User::getUser()) && count($_['navigation'])>=$headerIconCount))): ?> hidden<?php endif; ?>">
77
+							<li id="more-apps" class="menutoggle<?php if (!(count($_['navigation']) > $headerIconCount || (OC_User::isAdminUser(OC_User::getUser()) && count($_['navigation']) >= $headerIconCount))): ?> hidden<?php endif; ?>">
78 78
 								<a href="#">
79 79
 									<div class="icon-more-white"></div>
80 80
 									<span><?php p($l->t('More apps')); ?></span>
81 81
 								</a>
82 82
 							</li>
83
-							<?php if(OC_User::isAdminUser(OC_User::getUser())):	?>
84
-								<li id="apps-management" <?php if(count($_['navigation'])>$headerIconCount-1): ?>class="hidden"<?php endif; ?>>
83
+							<?php if (OC_User::isAdminUser(OC_User::getUser())):	?>
84
+								<li id="apps-management" <?php if (count($_['navigation']) > $headerIconCount - 1): ?>class="hidden"<?php endif; ?>>
85 85
 									<a href="<?php print_unescaped(\OC::$server->getURLGenerator()->linkToRoute('settings.AppSettings.viewApps')); ?>" tabindex="4"
86
-										<?php if( $_['appsmanagement_active'] ): ?> class="active"<?php endif; ?>>
87
-										<img src="<?php print_unescaped(image_path('settings', 'apps.svg') . '?v=' . $_['versionHash']); ?>" />
86
+										<?php if ($_['appsmanagement_active']): ?> class="active"<?php endif; ?>>
87
+										<img src="<?php print_unescaped(image_path('settings', 'apps.svg').'?v='.$_['versionHash']); ?>" />
88 88
 										<div class="icon-loading-dark" style="display:none;"></div>
89 89
 										<span><?php p($l->t('Apps')); ?></span>
90 90
 									</a>
@@ -96,17 +96,17 @@  discard block
 block discarded – undo
96 96
 				<nav role="navigation"><div id="navigation">
97 97
 						<div id="apps">
98 98
 							<ul>
99
-								<?php foreach($_['navigation'] as $entry): ?>
100
-									<?php if($entry['showInHeader']): ?>
99
+								<?php foreach ($_['navigation'] as $entry): ?>
100
+									<?php if ($entry['showInHeader']): ?>
101 101
 										<li data-id="<?php p($entry['id']); ?>" class="in-header">
102 102
 									<?php else: ?>
103 103
 										<li data-id="<?php p($entry['id']); ?>">
104 104
 									<?php endif; ?>
105 105
 									<a href="<?php print_unescaped($entry['href']); ?>" tabindex="3"
106
-										<?php if( $entry['active'] ): ?> class="active"<?php endif; ?>>
106
+										<?php if ($entry['active']): ?> class="active"<?php endif; ?>>
107 107
 										<svg width="32" height="32" viewBox="0 0 32 32">
108 108
 											<defs><filter id="invert"><feColorMatrix in="SourceGraphic" type="matrix" values="-1 0 0 0 1 0 -1 0 0 1 0 0 -1 0 1 0 0 0 1 0"></feColorMatrix></filter></defs>
109
-											<image x="0" y="0" width="32" height="32" preserveAspectRatio="xMinYMin meet" filter="url(#invert)" xlink:href="<?php print_unescaped($entry['icon'] . '?v=' . $_['versionHash']); ?>"  class="app-icon"></image>
109
+											<image x="0" y="0" width="32" height="32" preserveAspectRatio="xMinYMin meet" filter="url(#invert)" xlink:href="<?php print_unescaped($entry['icon'].'?v='.$_['versionHash']); ?>"  class="app-icon"></image>
110 110
 										</svg>
111 111
 										<div class="icon-loading-dark" style="display:none;"></div>
112 112
 										<span>
@@ -117,14 +117,14 @@  discard block
 block discarded – undo
117 117
 								<?php endforeach; ?>
118 118
 								<?php
119 119
 								/* show "More apps" link to app administration directly in app navigation, as last entry */
120
-								if(OC_User::isAdminUser(OC_User::getUser())):
120
+								if (OC_User::isAdminUser(OC_User::getUser())):
121 121
 									?>
122 122
 									<li id="apps-management">
123 123
 										<a href="<?php print_unescaped(\OC::$server->getURLGenerator()->linkToRoute('settings.AppSettings.viewApps')); ?>" tabindex="4"
124
-											<?php if( $_['appsmanagement_active'] ): ?> class="active"<?php endif; ?>>
124
+											<?php if ($_['appsmanagement_active']): ?> class="active"<?php endif; ?>>
125 125
 											<svg width="32" height="32" viewBox="0 0 32 32" class="app-icon">
126 126
 												<defs><filter id="invert"><feColorMatrix in="SourceGraphic" type="matrix" values="-1 0 0 0 1 0 -1 0 0 1 0 0 -1 0 1 0 0 0 1 0"></feColorMatrix></filter></defs>
127
-												<image x="0" y="0" width="32" height="32" preserveAspectRatio="xMinYMin meet" filter="url(#invert)" xlink:href="<?php print_unescaped(image_path('settings', 'apps.svg') . '?v=' . $_['versionHash']); ?>"></image>
127
+												<image x="0" y="0" width="32" height="32" preserveAspectRatio="xMinYMin meet" filter="url(#invert)" xlink:href="<?php print_unescaped(image_path('settings', 'apps.svg').'?v='.$_['versionHash']); ?>"></image>
128 128
 											</svg>
129 129
 											<div class="icon-loading-dark" style="display:none;"></div>
130 130
 											<span>
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 			<div id="header-right">
144 144
 				<form class="searchbox" action="#" method="post" role="search" novalidate>
145 145
 					<label for="searchbox" class="hidden-visually">
146
-						<?php p($l->t('Search'));?>
146
+						<?php p($l->t('Search')); ?>
147 147
 					</label>
148 148
 					<input id="searchbox" type="search" name="query"
149 149
 						value="" required
@@ -155,8 +155,8 @@  discard block
 block discarded – undo
155 155
 						<div class="avatardiv<?php if ($_['userAvatarSet']) { print_unescaped(' avatardiv-shown'); } else { print_unescaped('" style="display: none'); } ?>">
156 156
 							<?php if ($_['userAvatarSet']): ?>
157 157
 								<img alt="" width="32" height="32"
158
-								src="<?php p(\OC::$server->getURLGenerator()->linkToRoute('core.avatar.getAvatar', ['userId' => $_['user_uid'], 'size' => 32, 'v' => $_['userAvatarVersion']]));?>"
159
-								srcset="<?php p(\OC::$server->getURLGenerator()->linkToRoute('core.avatar.getAvatar', ['userId' => $_['user_uid'], 'size' => 64, 'v' => $_['userAvatarVersion']]));?> 2x, <?php p(\OC::$server->getURLGenerator()->linkToRoute('core.avatar.getAvatar', ['userId' => $_['user_uid'], 'size' => 128, 'v' => $_['userAvatarVersion']]));?> 4x"
158
+								src="<?php p(\OC::$server->getURLGenerator()->linkToRoute('core.avatar.getAvatar', ['userId' => $_['user_uid'], 'size' => 32, 'v' => $_['userAvatarVersion']])); ?>"
159
+								srcset="<?php p(\OC::$server->getURLGenerator()->linkToRoute('core.avatar.getAvatar', ['userId' => $_['user_uid'], 'size' => 64, 'v' => $_['userAvatarVersion']])); ?> 2x, <?php p(\OC::$server->getURLGenerator()->linkToRoute('core.avatar.getAvatar', ['userId' => $_['user_uid'], 'size' => 128, 'v' => $_['userAvatarVersion']])); ?> 4x"
160 160
 								>
161 161
 							<?php endif; ?>
162 162
 						</div>
@@ -165,19 +165,19 @@  discard block
 block discarded – undo
165 165
 					</div>
166 166
 					<div id="expanddiv">
167 167
 					<ul>
168
-					<?php foreach($_['settingsnavigation'] as $entry):?>
168
+					<?php foreach ($_['settingsnavigation'] as $entry):?>
169 169
 						<li>
170 170
 							<a href="<?php print_unescaped($entry['href']); ?>"
171
-								<?php if( $entry["active"] ): ?> class="active"<?php endif; ?>>
172
-								<img alt="" src="<?php print_unescaped($entry['icon'] . '?v=' . $_['versionHash']); ?>">
171
+								<?php if ($entry["active"]): ?> class="active"<?php endif; ?>>
172
+								<img alt="" src="<?php print_unescaped($entry['icon'].'?v='.$_['versionHash']); ?>">
173 173
 								<?php p($entry['name']) ?>
174 174
 							</a>
175 175
 						</li>
176 176
 					<?php endforeach; ?>
177 177
 						<li>
178 178
 							<a id="logout" <?php print_unescaped(OC_User::getLogoutAttribute()); ?>>
179
-								<img alt="" src="<?php print_unescaped(image_path('', 'actions/logout.svg') . '?v=' . $_['versionHash']); ?>">
180
-								<?php p($l->t('Log out'));?>
179
+								<img alt="" src="<?php print_unescaped(image_path('', 'actions/logout.svg').'?v='.$_['versionHash']); ?>">
180
+								<?php p($l->t('Log out')); ?>
181 181
 							</a>
182 182
 						</li>
183 183
 					</ul>
Please login to merge, or discard this patch.
lib/private/legacy/app.php 2 patches
Indentation   +1333 added lines, -1333 removed lines patch added patch discarded remove patch
@@ -61,1337 +61,1337 @@
 block discarded – undo
61 61
  * upgrading and removing apps.
62 62
  */
63 63
 class OC_App {
64
-	static private $appVersion = [];
65
-	static private $adminForms = array();
66
-	static private $personalForms = array();
67
-	static private $appInfo = array();
68
-	static private $appTypes = array();
69
-	static private $loadedApps = array();
70
-	static private $altLogin = array();
71
-	static private $alreadyRegistered = [];
72
-	const officialApp = 200;
73
-
74
-	/**
75
-	 * clean the appId
76
-	 *
77
-	 * @param string|boolean $app AppId that needs to be cleaned
78
-	 * @return string
79
-	 */
80
-	public static function cleanAppId($app) {
81
-		return str_replace(array('\0', '/', '\\', '..'), '', $app);
82
-	}
83
-
84
-	/**
85
-	 * Check if an app is loaded
86
-	 *
87
-	 * @param string $app
88
-	 * @return bool
89
-	 */
90
-	public static function isAppLoaded($app) {
91
-		return in_array($app, self::$loadedApps, true);
92
-	}
93
-
94
-	/**
95
-	 * loads all apps
96
-	 *
97
-	 * @param string[] | string | null $types
98
-	 * @return bool
99
-	 *
100
-	 * This function walks through the ownCloud directory and loads all apps
101
-	 * it can find. A directory contains an app if the file /appinfo/info.xml
102
-	 * exists.
103
-	 *
104
-	 * if $types is set, only apps of those types will be loaded
105
-	 */
106
-	public static function loadApps($types = null) {
107
-		if (\OC::$server->getSystemConfig()->getValue('maintenance', false)) {
108
-			return false;
109
-		}
110
-		// Load the enabled apps here
111
-		$apps = self::getEnabledApps();
112
-
113
-		// Add each apps' folder as allowed class path
114
-		foreach($apps as $app) {
115
-			$path = self::getAppPath($app);
116
-			if($path !== false) {
117
-				self::registerAutoloading($app, $path);
118
-			}
119
-		}
120
-
121
-		// prevent app.php from printing output
122
-		ob_start();
123
-		foreach ($apps as $app) {
124
-			if ((is_null($types) or self::isType($app, $types)) && !in_array($app, self::$loadedApps)) {
125
-				self::loadApp($app);
126
-			}
127
-		}
128
-		ob_end_clean();
129
-
130
-		return true;
131
-	}
132
-
133
-	/**
134
-	 * load a single app
135
-	 *
136
-	 * @param string $app
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
-			self::requireAppFile($app);
151
-			if (self::isType($app, array('authentication'))) {
152
-				// since authentication apps affect the "is app enabled for group" check,
153
-				// the enabled apps cache needs to be cleared to make sure that the
154
-				// next time getEnableApps() is called it will also include apps that were
155
-				// enabled for groups
156
-				self::$enabledAppsCache = array();
157
-			}
158
-			\OC::$server->getEventLogger()->end('load_app_' . $app);
159
-		}
160
-
161
-		$info = self::getAppInfo($app);
162
-		if (!empty($info['activity']['filters'])) {
163
-			foreach ($info['activity']['filters'] as $filter) {
164
-				\OC::$server->getActivityManager()->registerFilter($filter);
165
-			}
166
-		}
167
-		if (!empty($info['activity']['settings'])) {
168
-			foreach ($info['activity']['settings'] as $setting) {
169
-				\OC::$server->getActivityManager()->registerSetting($setting);
170
-			}
171
-		}
172
-		if (!empty($info['activity']['providers'])) {
173
-			foreach ($info['activity']['providers'] as $provider) {
174
-				\OC::$server->getActivityManager()->registerProvider($provider);
175
-			}
176
-		}
177
-	}
178
-
179
-	/**
180
-	 * @internal
181
-	 * @param string $app
182
-	 * @param string $path
183
-	 */
184
-	public static function registerAutoloading($app, $path) {
185
-		$key = $app . '-' . $path;
186
-		if(isset(self::$alreadyRegistered[$key])) {
187
-			return;
188
-		}
189
-		self::$alreadyRegistered[$key] = true;
190
-		// Register on PSR-4 composer autoloader
191
-		$appNamespace = \OC\AppFramework\App::buildAppNamespace($app);
192
-		\OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true);
193
-		if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) {
194
-			\OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true);
195
-		}
196
-
197
-		// Register on legacy autoloader
198
-		\OC::$loader->addValidRoot($path);
199
-	}
200
-
201
-	/**
202
-	 * Load app.php from the given app
203
-	 *
204
-	 * @param string $app app name
205
-	 */
206
-	private static function requireAppFile($app) {
207
-		try {
208
-			// encapsulated here to avoid variable scope conflicts
209
-			require_once $app . '/appinfo/app.php';
210
-		} catch (Error $ex) {
211
-			\OC::$server->getLogger()->logException($ex);
212
-			$blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps();
213
-			if (!in_array($app, $blacklist)) {
214
-				self::disable($app);
215
-			}
216
-		}
217
-	}
218
-
219
-	/**
220
-	 * check if an app is of a specific type
221
-	 *
222
-	 * @param string $app
223
-	 * @param string|array $types
224
-	 * @return bool
225
-	 */
226
-	public static function isType($app, $types) {
227
-		if (is_string($types)) {
228
-			$types = array($types);
229
-		}
230
-		$appTypes = self::getAppTypes($app);
231
-		foreach ($types as $type) {
232
-			if (array_search($type, $appTypes) !== false) {
233
-				return true;
234
-			}
235
-		}
236
-		return false;
237
-	}
238
-
239
-	/**
240
-	 * get the types of an app
241
-	 *
242
-	 * @param string $app
243
-	 * @return array
244
-	 */
245
-	private static function getAppTypes($app) {
246
-		//load the cache
247
-		if (count(self::$appTypes) == 0) {
248
-			self::$appTypes = \OC::$server->getAppConfig()->getValues(false, 'types');
249
-		}
250
-
251
-		if (isset(self::$appTypes[$app])) {
252
-			return explode(',', self::$appTypes[$app]);
253
-		} else {
254
-			return array();
255
-		}
256
-	}
257
-
258
-	/**
259
-	 * read app types from info.xml and cache them in the database
260
-	 */
261
-	public static function setAppTypes($app) {
262
-		$appData = self::getAppInfo($app);
263
-		if(!is_array($appData)) {
264
-			return;
265
-		}
266
-
267
-		if (isset($appData['types'])) {
268
-			$appTypes = implode(',', $appData['types']);
269
-		} else {
270
-			$appTypes = '';
271
-			$appData['types'] = [];
272
-		}
273
-
274
-		\OC::$server->getAppConfig()->setValue($app, 'types', $appTypes);
275
-
276
-		if (\OC::$server->getAppManager()->hasProtectedAppType($appData['types'])) {
277
-			$enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'yes');
278
-			if ($enabled !== 'yes' && $enabled !== 'no') {
279
-				\OC::$server->getAppConfig()->setValue($app, 'enabled', 'yes');
280
-			}
281
-		}
282
-	}
283
-
284
-	/**
285
-	 * check if app is shipped
286
-	 *
287
-	 * @param string $appId the id of the app to check
288
-	 * @return bool
289
-	 *
290
-	 * Check if an app that is installed is a shipped app or installed from the appstore.
291
-	 */
292
-	public static function isShipped($appId) {
293
-		return \OC::$server->getAppManager()->isShipped($appId);
294
-	}
295
-
296
-	/**
297
-	 * get all enabled apps
298
-	 */
299
-	protected static $enabledAppsCache = array();
300
-
301
-	/**
302
-	 * Returns apps enabled for the current user.
303
-	 *
304
-	 * @param bool $forceRefresh whether to refresh the cache
305
-	 * @param bool $all whether to return apps for all users, not only the
306
-	 * currently logged in one
307
-	 * @return string[]
308
-	 */
309
-	public static function getEnabledApps($forceRefresh = false, $all = false) {
310
-		if (!\OC::$server->getSystemConfig()->getValue('installed', false)) {
311
-			return array();
312
-		}
313
-		// in incognito mode or when logged out, $user will be false,
314
-		// which is also the case during an upgrade
315
-		$appManager = \OC::$server->getAppManager();
316
-		if ($all) {
317
-			$user = null;
318
-		} else {
319
-			$user = \OC::$server->getUserSession()->getUser();
320
-		}
321
-
322
-		if (is_null($user)) {
323
-			$apps = $appManager->getInstalledApps();
324
-		} else {
325
-			$apps = $appManager->getEnabledAppsForUser($user);
326
-		}
327
-		$apps = array_filter($apps, function ($app) {
328
-			return $app !== 'files';//we add this manually
329
-		});
330
-		sort($apps);
331
-		array_unshift($apps, 'files');
332
-		return $apps;
333
-	}
334
-
335
-	/**
336
-	 * checks whether or not an app is enabled
337
-	 *
338
-	 * @param string $app app
339
-	 * @return bool
340
-	 *
341
-	 * This function checks whether or not an app is enabled.
342
-	 */
343
-	public static function isEnabled($app) {
344
-		return \OC::$server->getAppManager()->isEnabledForUser($app);
345
-	}
346
-
347
-	/**
348
-	 * enables an app
349
-	 *
350
-	 * @param string $appId
351
-	 * @param array $groups (optional) when set, only these groups will have access to the app
352
-	 * @throws \Exception
353
-	 * @return void
354
-	 *
355
-	 * This function set an app as enabled in appconfig.
356
-	 */
357
-	public function enable($appId,
358
-						   $groups = null) {
359
-		self::$enabledAppsCache = []; // flush
360
-		$l = \OC::$server->getL10N('core');
361
-		$config = \OC::$server->getConfig();
362
-
363
-		// Check if app is already downloaded
364
-		$installer = new Installer(
365
-			\OC::$server->getAppFetcher(),
366
-			\OC::$server->getHTTPClientService(),
367
-			\OC::$server->getTempManager(),
368
-			\OC::$server->getLogger()
369
-		);
370
-		$isDownloaded = $installer->isDownloaded($appId);
371
-
372
-		if(!$isDownloaded) {
373
-			$installer->downloadApp($appId);
374
-		}
375
-
376
-		if (!Installer::isInstalled($appId)) {
377
-			$appId = self::installApp(
378
-				$appId,
379
-				$config,
380
-				$l
381
-			);
382
-			$appPath = self::getAppPath($appId);
383
-			self::registerAutoloading($appId, $appPath);
384
-			$installer->installApp($appId);
385
-		} else {
386
-			// check for required dependencies
387
-			$info = self::getAppInfo($appId);
388
-			self::checkAppDependencies($config, $l, $info);
389
-			$appPath = self::getAppPath($appId);
390
-			self::registerAutoloading($appId, $appPath);
391
-			$installer->installApp($appId);
392
-		}
393
-
394
-		$appManager = \OC::$server->getAppManager();
395
-		if (!is_null($groups)) {
396
-			$groupManager = \OC::$server->getGroupManager();
397
-			$groupsList = [];
398
-			foreach ($groups as $group) {
399
-				$groupItem = $groupManager->get($group);
400
-				if ($groupItem instanceof \OCP\IGroup) {
401
-					$groupsList[] = $groupManager->get($group);
402
-				}
403
-			}
404
-			$appManager->enableAppForGroups($appId, $groupsList);
405
-		} else {
406
-			$appManager->enableApp($appId);
407
-		}
408
-
409
-		$info = self::getAppInfo($appId);
410
-		if(isset($info['settings']) && is_array($info['settings'])) {
411
-			$appPath = self::getAppPath($appId);
412
-			self::registerAutoloading($appId, $appPath);
413
-			\OC::$server->getSettingsManager()->setupSettings($info['settings']);
414
-		}
415
-	}
416
-
417
-	/**
418
-	 * @param string $app
419
-	 * @return bool
420
-	 */
421
-	public static function removeApp($app) {
422
-		if (self::isShipped($app)) {
423
-			return false;
424
-		}
425
-
426
-		$installer = new Installer(
427
-			\OC::$server->getAppFetcher(),
428
-			\OC::$server->getHTTPClientService(),
429
-			\OC::$server->getTempManager(),
430
-			\OC::$server->getLogger()
431
-		);
432
-		return $installer->removeApp($app);
433
-	}
434
-
435
-	/**
436
-	 * This function set an app as disabled in appconfig.
437
-	 *
438
-	 * @param string $app app
439
-	 * @throws Exception
440
-	 */
441
-	public static function disable($app) {
442
-		// flush
443
-		self::$enabledAppsCache = array();
444
-
445
-		// run uninstall steps
446
-		$appData = OC_App::getAppInfo($app);
447
-		if (!is_null($appData)) {
448
-			OC_App::executeRepairSteps($app, $appData['repair-steps']['uninstall']);
449
-		}
450
-
451
-		// emit disable hook - needed anymore ?
452
-		\OC_Hook::emit('OC_App', 'pre_disable', array('app' => $app));
453
-
454
-		// finally disable it
455
-		$appManager = \OC::$server->getAppManager();
456
-		$appManager->disableApp($app);
457
-	}
458
-
459
-	/**
460
-	 * Returns the Settings Navigation
461
-	 *
462
-	 * @return string[]
463
-	 *
464
-	 * This function returns an array containing all settings pages added. The
465
-	 * entries are sorted by the key 'order' ascending.
466
-	 */
467
-	public static function getSettingsNavigation() {
468
-		$l = \OC::$server->getL10N('lib');
469
-		$urlGenerator = \OC::$server->getURLGenerator();
470
-
471
-		$settings = array();
472
-		// by default, settings only contain the help menu
473
-		if (\OC::$server->getSystemConfig()->getValue('knowledgebaseenabled', true)) {
474
-			$settings = array(
475
-				array(
476
-					"id" => "help",
477
-					"order" => 4,
478
-					"href" => $urlGenerator->linkToRoute('settings_help'),
479
-					"name" => $l->t("Help"),
480
-					"icon" => $urlGenerator->imagePath("settings", "help.svg")
481
-				)
482
-			);
483
-		}
484
-
485
-		// if the user is logged-in
486
-		if (\OC::$server->getUserSession()->isLoggedIn()) {
487
-			// personal menu
488
-			$settings[] = array(
489
-				"id" => "personal",
490
-				"order" => 1,
491
-				"href" => $urlGenerator->linkToRoute('settings_personal'),
492
-				"name" => $l->t("Personal"),
493
-				"icon" => $urlGenerator->imagePath("settings", "personal.svg")
494
-			);
495
-
496
-			//SubAdmins are also allowed to access user management
497
-			$userObject = \OC::$server->getUserSession()->getUser();
498
-			$isSubAdmin = false;
499
-			if($userObject !== null) {
500
-				$isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject);
501
-			}
502
-			if ($isSubAdmin) {
503
-				// admin users menu
504
-				$settings[] = array(
505
-					"id" => "core_users",
506
-					"order" => 3,
507
-					"href" => $urlGenerator->linkToRoute('settings_users'),
508
-					"name" => $l->t("Users"),
509
-					"icon" => $urlGenerator->imagePath("settings", "users.svg")
510
-				);
511
-			}
512
-
513
-			// if the user is an admin
514
-			if (OC_User::isAdminUser(OC_User::getUser())) {
515
-				// admin settings
516
-				$settings[] = array(
517
-					"id" => "admin",
518
-					"order" => 2,
519
-					"href" => $urlGenerator->linkToRoute('settings.AdminSettings.index'),
520
-					"name" => $l->t("Admin"),
521
-					"icon" => $urlGenerator->imagePath("settings", "admin.svg")
522
-				);
523
-			}
524
-		}
525
-
526
-		$navigation = self::proceedNavigation($settings);
527
-		return $navigation;
528
-	}
529
-
530
-	// This is private as well. It simply works, so don't ask for more details
531
-	private static function proceedNavigation($list) {
532
-		$headerIconCount = 8;
533
-		if(OC_User::isAdminUser(OC_User::getUser())) {
534
-			$headerIconCount--;
535
-		}
536
-		usort($list, function($a, $b) {
537
-			if (isset($a['order']) && isset($b['order'])) {
538
-				return ($a['order'] < $b['order']) ? -1 : 1;
539
-			} else if (isset($a['order']) || isset($b['order'])) {
540
-				return isset($a['order']) ? -1 : 1;
541
-			} else {
542
-				return ($a['name'] < $b['name']) ? -1 : 1;
543
-			}
544
-		});
545
-
546
-		$activeAppIndex = -1;
547
-		$activeApp = OC::$server->getNavigationManager()->getActiveEntry();
548
-		foreach ($list as $index => &$navEntry) {
549
-			if ($navEntry['id'] == $activeApp) {
550
-				$navEntry['active'] = true;
551
-				$activeAppIndex = $index;
552
-			} else {
553
-				$navEntry['active'] = false;
554
-			}
555
-		}
556
-		unset($navEntry);
557
-
558
-		if($activeAppIndex > ($headerIconCount-1)) {
559
-			$active = $list[$activeAppIndex];
560
-			$lastInHeader = $list[$headerIconCount-1];
561
-			$list[$headerIconCount-1] = $active;
562
-			$list[$activeAppIndex] = $lastInHeader;
563
-		}
564
-
565
-		foreach ($list as $index => &$navEntry) {
566
-			$navEntry['showInHeader'] = false;
567
-			if($index < $headerIconCount) {
568
-				$navEntry['showInHeader'] = true;
569
-			}
570
-		}
571
-
572
-
573
-
574
-		return $list;
575
-	}
576
-
577
-	public static function proceedAppNavigation($entries) {
578
-		$headerIconCount = 8;
579
-		if(OC_User::isAdminUser(OC_User::getUser())) {
580
-			$headerIconCount--;
581
-		}
582
-		$activeAppIndex = -1;
583
-		$list = self::proceedNavigation($entries);
584
-
585
-		$activeApp = OC::$server->getNavigationManager()->getActiveEntry();
586
-		foreach ($list as $index => &$navEntry) {
587
-			if ($navEntry['id'] == $activeApp) {
588
-				$navEntry['active'] = true;
589
-				$activeAppIndex = $index;
590
-			} else {
591
-				$navEntry['active'] = false;
592
-			}
593
-		}
594
-		// move active item to last position
595
-		if($activeAppIndex > ($headerIconCount-1)) {
596
-			$active = $list[$activeAppIndex];
597
-			$lastInHeader = $list[$headerIconCount-1];
598
-			$list[$headerIconCount-1] = $active;
599
-			$list[$activeAppIndex] = $lastInHeader;
600
-		}
601
-		$list = array_slice($list, 0, $headerIconCount);
602
-
603
-		return $list;
604
-	}
605
-
606
-	/**
607
-	 * Get the path where to install apps
608
-	 *
609
-	 * @return string|false
610
-	 */
611
-	public static function getInstallPath() {
612
-		if (\OC::$server->getSystemConfig()->getValue('appstoreenabled', true) == false) {
613
-			return false;
614
-		}
615
-
616
-		foreach (OC::$APPSROOTS as $dir) {
617
-			if (isset($dir['writable']) && $dir['writable'] === true) {
618
-				return $dir['path'];
619
-			}
620
-		}
621
-
622
-		\OCP\Util::writeLog('core', 'No application directories are marked as writable.', \OCP\Util::ERROR);
623
-		return null;
624
-	}
625
-
626
-
627
-	/**
628
-	 * search for an app in all app-directories
629
-	 *
630
-	 * @param string $appId
631
-	 * @return false|string
632
-	 */
633
-	public static function findAppInDirectories($appId) {
634
-		$sanitizedAppId = self::cleanAppId($appId);
635
-		if($sanitizedAppId !== $appId) {
636
-			return false;
637
-		}
638
-		static $app_dir = array();
639
-
640
-		if (isset($app_dir[$appId])) {
641
-			return $app_dir[$appId];
642
-		}
643
-
644
-		$possibleApps = array();
645
-		foreach (OC::$APPSROOTS as $dir) {
646
-			if (file_exists($dir['path'] . '/' . $appId)) {
647
-				$possibleApps[] = $dir;
648
-			}
649
-		}
650
-
651
-		if (empty($possibleApps)) {
652
-			return false;
653
-		} elseif (count($possibleApps) === 1) {
654
-			$dir = array_shift($possibleApps);
655
-			$app_dir[$appId] = $dir;
656
-			return $dir;
657
-		} else {
658
-			$versionToLoad = array();
659
-			foreach ($possibleApps as $possibleApp) {
660
-				$version = self::getAppVersionByPath($possibleApp['path']);
661
-				if (empty($versionToLoad) || version_compare($version, $versionToLoad['version'], '>')) {
662
-					$versionToLoad = array(
663
-						'dir' => $possibleApp,
664
-						'version' => $version,
665
-					);
666
-				}
667
-			}
668
-			$app_dir[$appId] = $versionToLoad['dir'];
669
-			return $versionToLoad['dir'];
670
-			//TODO - write test
671
-		}
672
-	}
673
-
674
-	/**
675
-	 * Get the directory for the given app.
676
-	 * If the app is defined in multiple directories, the first one is taken. (false if not found)
677
-	 *
678
-	 * @param string $appId
679
-	 * @return string|false
680
-	 */
681
-	public static function getAppPath($appId) {
682
-		if ($appId === null || trim($appId) === '') {
683
-			return false;
684
-		}
685
-
686
-		if (($dir = self::findAppInDirectories($appId)) != false) {
687
-			return $dir['path'] . '/' . $appId;
688
-		}
689
-		return false;
690
-	}
691
-
692
-	/**
693
-	 * Get the path for the given app on the access
694
-	 * If the app is defined in multiple directories, the first one is taken. (false if not found)
695
-	 *
696
-	 * @param string $appId
697
-	 * @return string|false
698
-	 */
699
-	public static function getAppWebPath($appId) {
700
-		if (($dir = self::findAppInDirectories($appId)) != false) {
701
-			return OC::$WEBROOT . $dir['url'] . '/' . $appId;
702
-		}
703
-		return false;
704
-	}
705
-
706
-	/**
707
-	 * get the last version of the app from appinfo/info.xml
708
-	 *
709
-	 * @param string $appId
710
-	 * @param bool $useCache
711
-	 * @return string
712
-	 */
713
-	public static function getAppVersion($appId, $useCache = true) {
714
-		if($useCache && isset(self::$appVersion[$appId])) {
715
-			return self::$appVersion[$appId];
716
-		}
717
-
718
-		$file = self::getAppPath($appId);
719
-		self::$appVersion[$appId] = ($file !== false) ? self::getAppVersionByPath($file) : '0';
720
-		return self::$appVersion[$appId];
721
-	}
722
-
723
-	/**
724
-	 * get app's version based on it's path
725
-	 *
726
-	 * @param string $path
727
-	 * @return string
728
-	 */
729
-	public static function getAppVersionByPath($path) {
730
-		$infoFile = $path . '/appinfo/info.xml';
731
-		$appData = self::getAppInfo($infoFile, true);
732
-		return isset($appData['version']) ? $appData['version'] : '';
733
-	}
734
-
735
-
736
-	/**
737
-	 * Read all app metadata from the info.xml file
738
-	 *
739
-	 * @param string $appId id of the app or the path of the info.xml file
740
-	 * @param bool $path
741
-	 * @param string $lang
742
-	 * @return array|null
743
-	 * @note all data is read from info.xml, not just pre-defined fields
744
-	 */
745
-	public static function getAppInfo($appId, $path = false, $lang = null) {
746
-		if ($path) {
747
-			$file = $appId;
748
-		} else {
749
-			if ($lang === null && isset(self::$appInfo[$appId])) {
750
-				return self::$appInfo[$appId];
751
-			}
752
-			$appPath = self::getAppPath($appId);
753
-			if($appPath === false) {
754
-				return null;
755
-			}
756
-			$file = $appPath . '/appinfo/info.xml';
757
-		}
758
-
759
-		$parser = new InfoParser(\OC::$server->getMemCacheFactory()->create('core.appinfo'));
760
-		$data = $parser->parse($file);
761
-
762
-		if (is_array($data)) {
763
-			$data = OC_App::parseAppInfo($data, $lang);
764
-		}
765
-		if(isset($data['ocsid'])) {
766
-			$storedId = \OC::$server->getConfig()->getAppValue($appId, 'ocsid');
767
-			if($storedId !== '' && $storedId !== $data['ocsid']) {
768
-				$data['ocsid'] = $storedId;
769
-			}
770
-		}
771
-
772
-		if ($lang === null) {
773
-			self::$appInfo[$appId] = $data;
774
-		}
775
-
776
-		return $data;
777
-	}
778
-
779
-	/**
780
-	 * Returns the navigation
781
-	 *
782
-	 * @return array
783
-	 *
784
-	 * This function returns an array containing all entries added. The
785
-	 * entries are sorted by the key 'order' ascending. Additional to the keys
786
-	 * given for each app the following keys exist:
787
-	 *   - active: boolean, signals if the user is on this navigation entry
788
-	 */
789
-	public static function getNavigation() {
790
-		$entries = OC::$server->getNavigationManager()->getAll();
791
-		$navigation = self::proceedNavigation($entries);
792
-		return $navigation;
793
-	}
794
-
795
-	/**
796
-	 * Returns the navigation inside the header bar
797
-	 *
798
-	 * @return array
799
-	 *
800
-	 * This function returns an array containing all entries added. The
801
-	 * entries are sorted by the key 'order' ascending. Additional to the keys
802
-	 * given for each app the following keys exist:
803
-	 *   - active: boolean, signals if the user is on this navigation entry
804
-	 */
805
-	public static function getHeaderNavigation() {
806
-		$entries = OC::$server->getNavigationManager()->getAll();
807
-		$navigation = self::proceedAppNavigation($entries);
808
-		return $navigation;
809
-	}
810
-
811
-	/**
812
-	 * get the id of loaded app
813
-	 *
814
-	 * @return string
815
-	 */
816
-	public static function getCurrentApp() {
817
-		$request = \OC::$server->getRequest();
818
-		$script = substr($request->getScriptName(), strlen(OC::$WEBROOT) + 1);
819
-		$topFolder = substr($script, 0, strpos($script, '/'));
820
-		if (empty($topFolder)) {
821
-			$path_info = $request->getPathInfo();
822
-			if ($path_info) {
823
-				$topFolder = substr($path_info, 1, strpos($path_info, '/', 1) - 1);
824
-			}
825
-		}
826
-		if ($topFolder == 'apps') {
827
-			$length = strlen($topFolder);
828
-			return substr($script, $length + 1, strpos($script, '/', $length + 1) - $length - 1);
829
-		} else {
830
-			return $topFolder;
831
-		}
832
-	}
833
-
834
-	/**
835
-	 * @param string $type
836
-	 * @return array
837
-	 */
838
-	public static function getForms($type) {
839
-		$forms = array();
840
-		switch ($type) {
841
-			case 'admin':
842
-				$source = self::$adminForms;
843
-				break;
844
-			case 'personal':
845
-				$source = self::$personalForms;
846
-				break;
847
-			default:
848
-				return array();
849
-		}
850
-		foreach ($source as $form) {
851
-			$forms[] = include $form;
852
-		}
853
-		return $forms;
854
-	}
855
-
856
-	/**
857
-	 * register an admin form to be shown
858
-	 *
859
-	 * @param string $app
860
-	 * @param string $page
861
-	 */
862
-	public static function registerAdmin($app, $page) {
863
-		self::$adminForms[] = $app . '/' . $page . '.php';
864
-	}
865
-
866
-	/**
867
-	 * register a personal form to be shown
868
-	 * @param string $app
869
-	 * @param string $page
870
-	 */
871
-	public static function registerPersonal($app, $page) {
872
-		self::$personalForms[] = $app . '/' . $page . '.php';
873
-	}
874
-
875
-	/**
876
-	 * @param array $entry
877
-	 */
878
-	public static function registerLogIn(array $entry) {
879
-		self::$altLogin[] = $entry;
880
-	}
881
-
882
-	/**
883
-	 * @return array
884
-	 */
885
-	public static function getAlternativeLogIns() {
886
-		return self::$altLogin;
887
-	}
888
-
889
-	/**
890
-	 * get a list of all apps in the apps folder
891
-	 *
892
-	 * @return array an array of app names (string IDs)
893
-	 * @todo: change the name of this method to getInstalledApps, which is more accurate
894
-	 */
895
-	public static function getAllApps() {
896
-
897
-		$apps = array();
898
-
899
-		foreach (OC::$APPSROOTS as $apps_dir) {
900
-			if (!is_readable($apps_dir['path'])) {
901
-				\OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN);
902
-				continue;
903
-			}
904
-			$dh = opendir($apps_dir['path']);
905
-
906
-			if (is_resource($dh)) {
907
-				while (($file = readdir($dh)) !== false) {
908
-
909
-					if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) {
910
-
911
-						$apps[] = $file;
912
-					}
913
-				}
914
-			}
915
-		}
916
-
917
-		return $apps;
918
-	}
919
-
920
-	/**
921
-	 * List all apps, this is used in apps.php
922
-	 *
923
-	 * @return array
924
-	 */
925
-	public function listAllApps() {
926
-		$installedApps = OC_App::getAllApps();
927
-
928
-		//we don't want to show configuration for these
929
-		$blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps();
930
-		$appList = array();
931
-		$langCode = \OC::$server->getL10N('core')->getLanguageCode();
932
-		$urlGenerator = \OC::$server->getURLGenerator();
933
-
934
-		foreach ($installedApps as $app) {
935
-			if (array_search($app, $blacklist) === false) {
936
-
937
-				$info = OC_App::getAppInfo($app, false, $langCode);
938
-				if (!is_array($info)) {
939
-					\OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR);
940
-					continue;
941
-				}
942
-
943
-				if (!isset($info['name'])) {
944
-					\OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR);
945
-					continue;
946
-				}
947
-
948
-				$enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'no');
949
-				$info['groups'] = null;
950
-				if ($enabled === 'yes') {
951
-					$active = true;
952
-				} else if ($enabled === 'no') {
953
-					$active = false;
954
-				} else {
955
-					$active = true;
956
-					$info['groups'] = $enabled;
957
-				}
958
-
959
-				$info['active'] = $active;
960
-
961
-				if (self::isShipped($app)) {
962
-					$info['internal'] = true;
963
-					$info['level'] = self::officialApp;
964
-					$info['removable'] = false;
965
-				} else {
966
-					$info['internal'] = false;
967
-					$info['removable'] = true;
968
-				}
969
-
970
-				$appPath = self::getAppPath($app);
971
-				if($appPath !== false) {
972
-					$appIcon = $appPath . '/img/' . $app . '.svg';
973
-					if (file_exists($appIcon)) {
974
-						$info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, $app . '.svg');
975
-						$info['previewAsIcon'] = true;
976
-					} else {
977
-						$appIcon = $appPath . '/img/app.svg';
978
-						if (file_exists($appIcon)) {
979
-							$info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, 'app.svg');
980
-							$info['previewAsIcon'] = true;
981
-						}
982
-					}
983
-				}
984
-				// fix documentation
985
-				if (isset($info['documentation']) && is_array($info['documentation'])) {
986
-					foreach ($info['documentation'] as $key => $url) {
987
-						// If it is not an absolute URL we assume it is a key
988
-						// i.e. admin-ldap will get converted to go.php?to=admin-ldap
989
-						if (stripos($url, 'https://') !== 0 && stripos($url, 'http://') !== 0) {
990
-							$url = $urlGenerator->linkToDocs($url);
991
-						}
992
-
993
-						$info['documentation'][$key] = $url;
994
-					}
995
-				}
996
-
997
-				$info['version'] = OC_App::getAppVersion($app);
998
-				$appList[] = $info;
999
-			}
1000
-		}
1001
-
1002
-		return $appList;
1003
-	}
1004
-
1005
-	/**
1006
-	 * Returns the internal app ID or false
1007
-	 * @param string $ocsID
1008
-	 * @return string|false
1009
-	 */
1010
-	public static function getInternalAppIdByOcs($ocsID) {
1011
-		if(is_numeric($ocsID)) {
1012
-			$idArray = \OC::$server->getAppConfig()->getValues(false, 'ocsid');
1013
-			if(array_search($ocsID, $idArray)) {
1014
-				return array_search($ocsID, $idArray);
1015
-			}
1016
-		}
1017
-		return false;
1018
-	}
1019
-
1020
-	public static function shouldUpgrade($app) {
1021
-		$versions = self::getAppVersions();
1022
-		$currentVersion = OC_App::getAppVersion($app);
1023
-		if ($currentVersion && isset($versions[$app])) {
1024
-			$installedVersion = $versions[$app];
1025
-			if (!version_compare($currentVersion, $installedVersion, '=')) {
1026
-				return true;
1027
-			}
1028
-		}
1029
-		return false;
1030
-	}
1031
-
1032
-	/**
1033
-	 * Adjust the number of version parts of $version1 to match
1034
-	 * the number of version parts of $version2.
1035
-	 *
1036
-	 * @param string $version1 version to adjust
1037
-	 * @param string $version2 version to take the number of parts from
1038
-	 * @return string shortened $version1
1039
-	 */
1040
-	private static function adjustVersionParts($version1, $version2) {
1041
-		$version1 = explode('.', $version1);
1042
-		$version2 = explode('.', $version2);
1043
-		// reduce $version1 to match the number of parts in $version2
1044
-		while (count($version1) > count($version2)) {
1045
-			array_pop($version1);
1046
-		}
1047
-		// if $version1 does not have enough parts, add some
1048
-		while (count($version1) < count($version2)) {
1049
-			$version1[] = '0';
1050
-		}
1051
-		return implode('.', $version1);
1052
-	}
1053
-
1054
-	/**
1055
-	 * Check whether the current ownCloud version matches the given
1056
-	 * application's version requirements.
1057
-	 *
1058
-	 * The comparison is made based on the number of parts that the
1059
-	 * app info version has. For example for ownCloud 6.0.3 if the
1060
-	 * app info version is expecting version 6.0, the comparison is
1061
-	 * made on the first two parts of the ownCloud version.
1062
-	 * This means that it's possible to specify "requiremin" => 6
1063
-	 * and "requiremax" => 6 and it will still match ownCloud 6.0.3.
1064
-	 *
1065
-	 * @param string $ocVersion ownCloud version to check against
1066
-	 * @param array $appInfo app info (from xml)
1067
-	 *
1068
-	 * @return boolean true if compatible, otherwise false
1069
-	 */
1070
-	public static function isAppCompatible($ocVersion, $appInfo) {
1071
-		$requireMin = '';
1072
-		$requireMax = '';
1073
-		if (isset($appInfo['dependencies']['nextcloud']['@attributes']['min-version'])) {
1074
-			$requireMin = $appInfo['dependencies']['nextcloud']['@attributes']['min-version'];
1075
-		} elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['min-version'])) {
1076
-			$requireMin = $appInfo['dependencies']['owncloud']['@attributes']['min-version'];
1077
-		} else if (isset($appInfo['requiremin'])) {
1078
-			$requireMin = $appInfo['requiremin'];
1079
-		} else if (isset($appInfo['require'])) {
1080
-			$requireMin = $appInfo['require'];
1081
-		}
1082
-
1083
-		if (isset($appInfo['dependencies']['nextcloud']['@attributes']['max-version'])) {
1084
-			$requireMax = $appInfo['dependencies']['nextcloud']['@attributes']['max-version'];
1085
-		} elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['max-version'])) {
1086
-			$requireMax = $appInfo['dependencies']['owncloud']['@attributes']['max-version'];
1087
-		} else if (isset($appInfo['requiremax'])) {
1088
-			$requireMax = $appInfo['requiremax'];
1089
-		}
1090
-
1091
-		if (is_array($ocVersion)) {
1092
-			$ocVersion = implode('.', $ocVersion);
1093
-		}
1094
-
1095
-		if (!empty($requireMin)
1096
-			&& version_compare(self::adjustVersionParts($ocVersion, $requireMin), $requireMin, '<')
1097
-		) {
1098
-
1099
-			return false;
1100
-		}
1101
-
1102
-		if (!empty($requireMax)
1103
-			&& version_compare(self::adjustVersionParts($ocVersion, $requireMax), $requireMax, '>')
1104
-		) {
1105
-			return false;
1106
-		}
1107
-
1108
-		return true;
1109
-	}
1110
-
1111
-	/**
1112
-	 * get the installed version of all apps
1113
-	 */
1114
-	public static function getAppVersions() {
1115
-		static $versions;
1116
-
1117
-		if(!$versions) {
1118
-			$appConfig = \OC::$server->getAppConfig();
1119
-			$versions = $appConfig->getValues(false, 'installed_version');
1120
-		}
1121
-		return $versions;
1122
-	}
1123
-
1124
-	/**
1125
-	 * @param string $app
1126
-	 * @param \OCP\IConfig $config
1127
-	 * @param \OCP\IL10N $l
1128
-	 * @return bool
1129
-	 *
1130
-	 * @throws Exception if app is not compatible with this version of ownCloud
1131
-	 * @throws Exception if no app-name was specified
1132
-	 */
1133
-	public function installApp($app,
1134
-							   \OCP\IConfig $config,
1135
-							   \OCP\IL10N $l) {
1136
-		if ($app !== false) {
1137
-			// check if the app is compatible with this version of ownCloud
1138
-			$info = self::getAppInfo($app);
1139
-			if(!is_array($info)) {
1140
-				throw new \Exception(
1141
-					$l->t('App "%s" cannot be installed because appinfo file cannot be read.',
1142
-						[$info['name']]
1143
-					)
1144
-				);
1145
-			}
1146
-
1147
-			$version = \OCP\Util::getVersion();
1148
-			if (!self::isAppCompatible($version, $info)) {
1149
-				throw new \Exception(
1150
-					$l->t('App "%s" cannot be installed because it is not compatible with this version of the server.',
1151
-						array($info['name'])
1152
-					)
1153
-				);
1154
-			}
1155
-
1156
-			// check for required dependencies
1157
-			self::checkAppDependencies($config, $l, $info);
1158
-
1159
-			$config->setAppValue($app, 'enabled', 'yes');
1160
-			if (isset($appData['id'])) {
1161
-				$config->setAppValue($app, 'ocsid', $appData['id']);
1162
-			}
1163
-
1164
-			if(isset($info['settings']) && is_array($info['settings'])) {
1165
-				$appPath = self::getAppPath($app);
1166
-				self::registerAutoloading($app, $appPath);
1167
-				\OC::$server->getSettingsManager()->setupSettings($info['settings']);
1168
-			}
1169
-
1170
-			\OC_Hook::emit('OC_App', 'post_enable', array('app' => $app));
1171
-		} else {
1172
-			if(empty($appName) ) {
1173
-				throw new \Exception($l->t("No app name specified"));
1174
-			} else {
1175
-				throw new \Exception($l->t("App '%s' could not be installed!", $appName));
1176
-			}
1177
-		}
1178
-
1179
-		return $app;
1180
-	}
1181
-
1182
-	/**
1183
-	 * update the database for the app and call the update script
1184
-	 *
1185
-	 * @param string $appId
1186
-	 * @return bool
1187
-	 */
1188
-	public static function updateApp($appId) {
1189
-		$appPath = self::getAppPath($appId);
1190
-		if($appPath === false) {
1191
-			return false;
1192
-		}
1193
-		$appData = self::getAppInfo($appId);
1194
-		self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']);
1195
-		if (file_exists($appPath . '/appinfo/database.xml')) {
1196
-			OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml');
1197
-		}
1198
-		self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']);
1199
-		self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']);
1200
-		unset(self::$appVersion[$appId]);
1201
-		// run upgrade code
1202
-		if (file_exists($appPath . '/appinfo/update.php')) {
1203
-			self::loadApp($appId);
1204
-			include $appPath . '/appinfo/update.php';
1205
-		}
1206
-		self::setupBackgroundJobs($appData['background-jobs']);
1207
-		if(isset($appData['settings']) && is_array($appData['settings'])) {
1208
-			$appPath = self::getAppPath($appId);
1209
-			self::registerAutoloading($appId, $appPath);
1210
-			\OC::$server->getSettingsManager()->setupSettings($appData['settings']);
1211
-		}
1212
-
1213
-		//set remote/public handlers
1214
-		if (array_key_exists('ocsid', $appData)) {
1215
-			\OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']);
1216
-		} elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) {
1217
-			\OC::$server->getConfig()->deleteAppValue($appId, 'ocsid');
1218
-		}
1219
-		foreach ($appData['remote'] as $name => $path) {
1220
-			\OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path);
1221
-		}
1222
-		foreach ($appData['public'] as $name => $path) {
1223
-			\OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path);
1224
-		}
1225
-
1226
-		self::setAppTypes($appId);
1227
-
1228
-		$version = \OC_App::getAppVersion($appId);
1229
-		\OC::$server->getAppConfig()->setValue($appId, 'installed_version', $version);
1230
-
1231
-		\OC::$server->getEventDispatcher()->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent(
1232
-			ManagerEvent::EVENT_APP_UPDATE, $appId
1233
-		));
1234
-
1235
-		return true;
1236
-	}
1237
-
1238
-	/**
1239
-	 * @param string $appId
1240
-	 * @param string[] $steps
1241
-	 * @throws \OC\NeedsUpdateException
1242
-	 */
1243
-	public static function executeRepairSteps($appId, array $steps) {
1244
-		if (empty($steps)) {
1245
-			return;
1246
-		}
1247
-		// load the app
1248
-		self::loadApp($appId);
1249
-
1250
-		$dispatcher = OC::$server->getEventDispatcher();
1251
-
1252
-		// load the steps
1253
-		$r = new Repair([], $dispatcher);
1254
-		foreach ($steps as $step) {
1255
-			try {
1256
-				$r->addStep($step);
1257
-			} catch (Exception $ex) {
1258
-				$r->emit('\OC\Repair', 'error', [$ex->getMessage()]);
1259
-				\OC::$server->getLogger()->logException($ex);
1260
-			}
1261
-		}
1262
-		// run the steps
1263
-		$r->run();
1264
-	}
1265
-
1266
-	public static function setupBackgroundJobs(array $jobs) {
1267
-		$queue = \OC::$server->getJobList();
1268
-		foreach ($jobs as $job) {
1269
-			$queue->add($job);
1270
-		}
1271
-	}
1272
-
1273
-	/**
1274
-	 * @param string $appId
1275
-	 * @param string[] $steps
1276
-	 */
1277
-	private static function setupLiveMigrations($appId, array $steps) {
1278
-		$queue = \OC::$server->getJobList();
1279
-		foreach ($steps as $step) {
1280
-			$queue->add('OC\Migration\BackgroundRepair', [
1281
-				'app' => $appId,
1282
-				'step' => $step]);
1283
-		}
1284
-	}
1285
-
1286
-	/**
1287
-	 * @param string $appId
1288
-	 * @return \OC\Files\View|false
1289
-	 */
1290
-	public static function getStorage($appId) {
1291
-		if (OC_App::isEnabled($appId)) { //sanity check
1292
-			if (\OC::$server->getUserSession()->isLoggedIn()) {
1293
-				$view = new \OC\Files\View('/' . OC_User::getUser());
1294
-				if (!$view->file_exists($appId)) {
1295
-					$view->mkdir($appId);
1296
-				}
1297
-				return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId);
1298
-			} else {
1299
-				\OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR);
1300
-				return false;
1301
-			}
1302
-		} else {
1303
-			\OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR);
1304
-			return false;
1305
-		}
1306
-	}
1307
-
1308
-	protected static function findBestL10NOption($options, $lang) {
1309
-		$fallback = $similarLangFallback = $englishFallback = false;
1310
-
1311
-		$lang = strtolower($lang);
1312
-		$similarLang = $lang;
1313
-		if (strpos($similarLang, '_')) {
1314
-			// For "de_DE" we want to find "de" and the other way around
1315
-			$similarLang = substr($lang, 0, strpos($lang, '_'));
1316
-		}
1317
-
1318
-		foreach ($options as $option) {
1319
-			if (is_array($option)) {
1320
-				if ($fallback === false) {
1321
-					$fallback = $option['@value'];
1322
-				}
1323
-
1324
-				if (!isset($option['@attributes']['lang'])) {
1325
-					continue;
1326
-				}
1327
-
1328
-				$attributeLang = strtolower($option['@attributes']['lang']);
1329
-				if ($attributeLang === $lang) {
1330
-					return $option['@value'];
1331
-				}
1332
-
1333
-				if ($attributeLang === $similarLang) {
1334
-					$similarLangFallback = $option['@value'];
1335
-				} else if (strpos($attributeLang, $similarLang . '_') === 0) {
1336
-					if ($similarLangFallback === false) {
1337
-						$similarLangFallback =  $option['@value'];
1338
-					}
1339
-				}
1340
-			} else {
1341
-				$englishFallback = $option;
1342
-			}
1343
-		}
1344
-
1345
-		if ($similarLangFallback !== false) {
1346
-			return $similarLangFallback;
1347
-		} else if ($englishFallback !== false) {
1348
-			return $englishFallback;
1349
-		}
1350
-		return (string) $fallback;
1351
-	}
1352
-
1353
-	/**
1354
-	 * parses the app data array and enhanced the 'description' value
1355
-	 *
1356
-	 * @param array $data the app data
1357
-	 * @param string $lang
1358
-	 * @return array improved app data
1359
-	 */
1360
-	public static function parseAppInfo(array $data, $lang = null) {
1361
-
1362
-		if ($lang && isset($data['name']) && is_array($data['name'])) {
1363
-			$data['name'] = self::findBestL10NOption($data['name'], $lang);
1364
-		}
1365
-		if ($lang && isset($data['summary']) && is_array($data['summary'])) {
1366
-			$data['summary'] = self::findBestL10NOption($data['summary'], $lang);
1367
-		}
1368
-		if ($lang && isset($data['description']) && is_array($data['description'])) {
1369
-			$data['description'] = trim(self::findBestL10NOption($data['description'], $lang));
1370
-		} else if (isset($data['description']) && is_string($data['description'])) {
1371
-			$data['description'] = trim($data['description']);
1372
-		} else  {
1373
-			$data['description'] = '';
1374
-		}
1375
-
1376
-		return $data;
1377
-	}
1378
-
1379
-	/**
1380
-	 * @param \OCP\IConfig $config
1381
-	 * @param \OCP\IL10N $l
1382
-	 * @param array $info
1383
-	 * @throws \Exception
1384
-	 */
1385
-	protected static function checkAppDependencies($config, $l, $info) {
1386
-		$dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l);
1387
-		$missing = $dependencyAnalyzer->analyze($info);
1388
-		if (!empty($missing)) {
1389
-			$missingMsg = join(PHP_EOL, $missing);
1390
-			throw new \Exception(
1391
-				$l->t('App "%s" cannot be installed because the following dependencies are not fulfilled: %s',
1392
-					[$info['name'], $missingMsg]
1393
-				)
1394
-			);
1395
-		}
1396
-	}
64
+    static private $appVersion = [];
65
+    static private $adminForms = array();
66
+    static private $personalForms = array();
67
+    static private $appInfo = array();
68
+    static private $appTypes = array();
69
+    static private $loadedApps = array();
70
+    static private $altLogin = array();
71
+    static private $alreadyRegistered = [];
72
+    const officialApp = 200;
73
+
74
+    /**
75
+     * clean the appId
76
+     *
77
+     * @param string|boolean $app AppId that needs to be cleaned
78
+     * @return string
79
+     */
80
+    public static function cleanAppId($app) {
81
+        return str_replace(array('\0', '/', '\\', '..'), '', $app);
82
+    }
83
+
84
+    /**
85
+     * Check if an app is loaded
86
+     *
87
+     * @param string $app
88
+     * @return bool
89
+     */
90
+    public static function isAppLoaded($app) {
91
+        return in_array($app, self::$loadedApps, true);
92
+    }
93
+
94
+    /**
95
+     * loads all apps
96
+     *
97
+     * @param string[] | string | null $types
98
+     * @return bool
99
+     *
100
+     * This function walks through the ownCloud directory and loads all apps
101
+     * it can find. A directory contains an app if the file /appinfo/info.xml
102
+     * exists.
103
+     *
104
+     * if $types is set, only apps of those types will be loaded
105
+     */
106
+    public static function loadApps($types = null) {
107
+        if (\OC::$server->getSystemConfig()->getValue('maintenance', false)) {
108
+            return false;
109
+        }
110
+        // Load the enabled apps here
111
+        $apps = self::getEnabledApps();
112
+
113
+        // Add each apps' folder as allowed class path
114
+        foreach($apps as $app) {
115
+            $path = self::getAppPath($app);
116
+            if($path !== false) {
117
+                self::registerAutoloading($app, $path);
118
+            }
119
+        }
120
+
121
+        // prevent app.php from printing output
122
+        ob_start();
123
+        foreach ($apps as $app) {
124
+            if ((is_null($types) or self::isType($app, $types)) && !in_array($app, self::$loadedApps)) {
125
+                self::loadApp($app);
126
+            }
127
+        }
128
+        ob_end_clean();
129
+
130
+        return true;
131
+    }
132
+
133
+    /**
134
+     * load a single app
135
+     *
136
+     * @param string $app
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
+            self::requireAppFile($app);
151
+            if (self::isType($app, array('authentication'))) {
152
+                // since authentication apps affect the "is app enabled for group" check,
153
+                // the enabled apps cache needs to be cleared to make sure that the
154
+                // next time getEnableApps() is called it will also include apps that were
155
+                // enabled for groups
156
+                self::$enabledAppsCache = array();
157
+            }
158
+            \OC::$server->getEventLogger()->end('load_app_' . $app);
159
+        }
160
+
161
+        $info = self::getAppInfo($app);
162
+        if (!empty($info['activity']['filters'])) {
163
+            foreach ($info['activity']['filters'] as $filter) {
164
+                \OC::$server->getActivityManager()->registerFilter($filter);
165
+            }
166
+        }
167
+        if (!empty($info['activity']['settings'])) {
168
+            foreach ($info['activity']['settings'] as $setting) {
169
+                \OC::$server->getActivityManager()->registerSetting($setting);
170
+            }
171
+        }
172
+        if (!empty($info['activity']['providers'])) {
173
+            foreach ($info['activity']['providers'] as $provider) {
174
+                \OC::$server->getActivityManager()->registerProvider($provider);
175
+            }
176
+        }
177
+    }
178
+
179
+    /**
180
+     * @internal
181
+     * @param string $app
182
+     * @param string $path
183
+     */
184
+    public static function registerAutoloading($app, $path) {
185
+        $key = $app . '-' . $path;
186
+        if(isset(self::$alreadyRegistered[$key])) {
187
+            return;
188
+        }
189
+        self::$alreadyRegistered[$key] = true;
190
+        // Register on PSR-4 composer autoloader
191
+        $appNamespace = \OC\AppFramework\App::buildAppNamespace($app);
192
+        \OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true);
193
+        if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) {
194
+            \OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true);
195
+        }
196
+
197
+        // Register on legacy autoloader
198
+        \OC::$loader->addValidRoot($path);
199
+    }
200
+
201
+    /**
202
+     * Load app.php from the given app
203
+     *
204
+     * @param string $app app name
205
+     */
206
+    private static function requireAppFile($app) {
207
+        try {
208
+            // encapsulated here to avoid variable scope conflicts
209
+            require_once $app . '/appinfo/app.php';
210
+        } catch (Error $ex) {
211
+            \OC::$server->getLogger()->logException($ex);
212
+            $blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps();
213
+            if (!in_array($app, $blacklist)) {
214
+                self::disable($app);
215
+            }
216
+        }
217
+    }
218
+
219
+    /**
220
+     * check if an app is of a specific type
221
+     *
222
+     * @param string $app
223
+     * @param string|array $types
224
+     * @return bool
225
+     */
226
+    public static function isType($app, $types) {
227
+        if (is_string($types)) {
228
+            $types = array($types);
229
+        }
230
+        $appTypes = self::getAppTypes($app);
231
+        foreach ($types as $type) {
232
+            if (array_search($type, $appTypes) !== false) {
233
+                return true;
234
+            }
235
+        }
236
+        return false;
237
+    }
238
+
239
+    /**
240
+     * get the types of an app
241
+     *
242
+     * @param string $app
243
+     * @return array
244
+     */
245
+    private static function getAppTypes($app) {
246
+        //load the cache
247
+        if (count(self::$appTypes) == 0) {
248
+            self::$appTypes = \OC::$server->getAppConfig()->getValues(false, 'types');
249
+        }
250
+
251
+        if (isset(self::$appTypes[$app])) {
252
+            return explode(',', self::$appTypes[$app]);
253
+        } else {
254
+            return array();
255
+        }
256
+    }
257
+
258
+    /**
259
+     * read app types from info.xml and cache them in the database
260
+     */
261
+    public static function setAppTypes($app) {
262
+        $appData = self::getAppInfo($app);
263
+        if(!is_array($appData)) {
264
+            return;
265
+        }
266
+
267
+        if (isset($appData['types'])) {
268
+            $appTypes = implode(',', $appData['types']);
269
+        } else {
270
+            $appTypes = '';
271
+            $appData['types'] = [];
272
+        }
273
+
274
+        \OC::$server->getAppConfig()->setValue($app, 'types', $appTypes);
275
+
276
+        if (\OC::$server->getAppManager()->hasProtectedAppType($appData['types'])) {
277
+            $enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'yes');
278
+            if ($enabled !== 'yes' && $enabled !== 'no') {
279
+                \OC::$server->getAppConfig()->setValue($app, 'enabled', 'yes');
280
+            }
281
+        }
282
+    }
283
+
284
+    /**
285
+     * check if app is shipped
286
+     *
287
+     * @param string $appId the id of the app to check
288
+     * @return bool
289
+     *
290
+     * Check if an app that is installed is a shipped app or installed from the appstore.
291
+     */
292
+    public static function isShipped($appId) {
293
+        return \OC::$server->getAppManager()->isShipped($appId);
294
+    }
295
+
296
+    /**
297
+     * get all enabled apps
298
+     */
299
+    protected static $enabledAppsCache = array();
300
+
301
+    /**
302
+     * Returns apps enabled for the current user.
303
+     *
304
+     * @param bool $forceRefresh whether to refresh the cache
305
+     * @param bool $all whether to return apps for all users, not only the
306
+     * currently logged in one
307
+     * @return string[]
308
+     */
309
+    public static function getEnabledApps($forceRefresh = false, $all = false) {
310
+        if (!\OC::$server->getSystemConfig()->getValue('installed', false)) {
311
+            return array();
312
+        }
313
+        // in incognito mode or when logged out, $user will be false,
314
+        // which is also the case during an upgrade
315
+        $appManager = \OC::$server->getAppManager();
316
+        if ($all) {
317
+            $user = null;
318
+        } else {
319
+            $user = \OC::$server->getUserSession()->getUser();
320
+        }
321
+
322
+        if (is_null($user)) {
323
+            $apps = $appManager->getInstalledApps();
324
+        } else {
325
+            $apps = $appManager->getEnabledAppsForUser($user);
326
+        }
327
+        $apps = array_filter($apps, function ($app) {
328
+            return $app !== 'files';//we add this manually
329
+        });
330
+        sort($apps);
331
+        array_unshift($apps, 'files');
332
+        return $apps;
333
+    }
334
+
335
+    /**
336
+     * checks whether or not an app is enabled
337
+     *
338
+     * @param string $app app
339
+     * @return bool
340
+     *
341
+     * This function checks whether or not an app is enabled.
342
+     */
343
+    public static function isEnabled($app) {
344
+        return \OC::$server->getAppManager()->isEnabledForUser($app);
345
+    }
346
+
347
+    /**
348
+     * enables an app
349
+     *
350
+     * @param string $appId
351
+     * @param array $groups (optional) when set, only these groups will have access to the app
352
+     * @throws \Exception
353
+     * @return void
354
+     *
355
+     * This function set an app as enabled in appconfig.
356
+     */
357
+    public function enable($appId,
358
+                            $groups = null) {
359
+        self::$enabledAppsCache = []; // flush
360
+        $l = \OC::$server->getL10N('core');
361
+        $config = \OC::$server->getConfig();
362
+
363
+        // Check if app is already downloaded
364
+        $installer = new Installer(
365
+            \OC::$server->getAppFetcher(),
366
+            \OC::$server->getHTTPClientService(),
367
+            \OC::$server->getTempManager(),
368
+            \OC::$server->getLogger()
369
+        );
370
+        $isDownloaded = $installer->isDownloaded($appId);
371
+
372
+        if(!$isDownloaded) {
373
+            $installer->downloadApp($appId);
374
+        }
375
+
376
+        if (!Installer::isInstalled($appId)) {
377
+            $appId = self::installApp(
378
+                $appId,
379
+                $config,
380
+                $l
381
+            );
382
+            $appPath = self::getAppPath($appId);
383
+            self::registerAutoloading($appId, $appPath);
384
+            $installer->installApp($appId);
385
+        } else {
386
+            // check for required dependencies
387
+            $info = self::getAppInfo($appId);
388
+            self::checkAppDependencies($config, $l, $info);
389
+            $appPath = self::getAppPath($appId);
390
+            self::registerAutoloading($appId, $appPath);
391
+            $installer->installApp($appId);
392
+        }
393
+
394
+        $appManager = \OC::$server->getAppManager();
395
+        if (!is_null($groups)) {
396
+            $groupManager = \OC::$server->getGroupManager();
397
+            $groupsList = [];
398
+            foreach ($groups as $group) {
399
+                $groupItem = $groupManager->get($group);
400
+                if ($groupItem instanceof \OCP\IGroup) {
401
+                    $groupsList[] = $groupManager->get($group);
402
+                }
403
+            }
404
+            $appManager->enableAppForGroups($appId, $groupsList);
405
+        } else {
406
+            $appManager->enableApp($appId);
407
+        }
408
+
409
+        $info = self::getAppInfo($appId);
410
+        if(isset($info['settings']) && is_array($info['settings'])) {
411
+            $appPath = self::getAppPath($appId);
412
+            self::registerAutoloading($appId, $appPath);
413
+            \OC::$server->getSettingsManager()->setupSettings($info['settings']);
414
+        }
415
+    }
416
+
417
+    /**
418
+     * @param string $app
419
+     * @return bool
420
+     */
421
+    public static function removeApp($app) {
422
+        if (self::isShipped($app)) {
423
+            return false;
424
+        }
425
+
426
+        $installer = new Installer(
427
+            \OC::$server->getAppFetcher(),
428
+            \OC::$server->getHTTPClientService(),
429
+            \OC::$server->getTempManager(),
430
+            \OC::$server->getLogger()
431
+        );
432
+        return $installer->removeApp($app);
433
+    }
434
+
435
+    /**
436
+     * This function set an app as disabled in appconfig.
437
+     *
438
+     * @param string $app app
439
+     * @throws Exception
440
+     */
441
+    public static function disable($app) {
442
+        // flush
443
+        self::$enabledAppsCache = array();
444
+
445
+        // run uninstall steps
446
+        $appData = OC_App::getAppInfo($app);
447
+        if (!is_null($appData)) {
448
+            OC_App::executeRepairSteps($app, $appData['repair-steps']['uninstall']);
449
+        }
450
+
451
+        // emit disable hook - needed anymore ?
452
+        \OC_Hook::emit('OC_App', 'pre_disable', array('app' => $app));
453
+
454
+        // finally disable it
455
+        $appManager = \OC::$server->getAppManager();
456
+        $appManager->disableApp($app);
457
+    }
458
+
459
+    /**
460
+     * Returns the Settings Navigation
461
+     *
462
+     * @return string[]
463
+     *
464
+     * This function returns an array containing all settings pages added. The
465
+     * entries are sorted by the key 'order' ascending.
466
+     */
467
+    public static function getSettingsNavigation() {
468
+        $l = \OC::$server->getL10N('lib');
469
+        $urlGenerator = \OC::$server->getURLGenerator();
470
+
471
+        $settings = array();
472
+        // by default, settings only contain the help menu
473
+        if (\OC::$server->getSystemConfig()->getValue('knowledgebaseenabled', true)) {
474
+            $settings = array(
475
+                array(
476
+                    "id" => "help",
477
+                    "order" => 4,
478
+                    "href" => $urlGenerator->linkToRoute('settings_help'),
479
+                    "name" => $l->t("Help"),
480
+                    "icon" => $urlGenerator->imagePath("settings", "help.svg")
481
+                )
482
+            );
483
+        }
484
+
485
+        // if the user is logged-in
486
+        if (\OC::$server->getUserSession()->isLoggedIn()) {
487
+            // personal menu
488
+            $settings[] = array(
489
+                "id" => "personal",
490
+                "order" => 1,
491
+                "href" => $urlGenerator->linkToRoute('settings_personal'),
492
+                "name" => $l->t("Personal"),
493
+                "icon" => $urlGenerator->imagePath("settings", "personal.svg")
494
+            );
495
+
496
+            //SubAdmins are also allowed to access user management
497
+            $userObject = \OC::$server->getUserSession()->getUser();
498
+            $isSubAdmin = false;
499
+            if($userObject !== null) {
500
+                $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject);
501
+            }
502
+            if ($isSubAdmin) {
503
+                // admin users menu
504
+                $settings[] = array(
505
+                    "id" => "core_users",
506
+                    "order" => 3,
507
+                    "href" => $urlGenerator->linkToRoute('settings_users'),
508
+                    "name" => $l->t("Users"),
509
+                    "icon" => $urlGenerator->imagePath("settings", "users.svg")
510
+                );
511
+            }
512
+
513
+            // if the user is an admin
514
+            if (OC_User::isAdminUser(OC_User::getUser())) {
515
+                // admin settings
516
+                $settings[] = array(
517
+                    "id" => "admin",
518
+                    "order" => 2,
519
+                    "href" => $urlGenerator->linkToRoute('settings.AdminSettings.index'),
520
+                    "name" => $l->t("Admin"),
521
+                    "icon" => $urlGenerator->imagePath("settings", "admin.svg")
522
+                );
523
+            }
524
+        }
525
+
526
+        $navigation = self::proceedNavigation($settings);
527
+        return $navigation;
528
+    }
529
+
530
+    // This is private as well. It simply works, so don't ask for more details
531
+    private static function proceedNavigation($list) {
532
+        $headerIconCount = 8;
533
+        if(OC_User::isAdminUser(OC_User::getUser())) {
534
+            $headerIconCount--;
535
+        }
536
+        usort($list, function($a, $b) {
537
+            if (isset($a['order']) && isset($b['order'])) {
538
+                return ($a['order'] < $b['order']) ? -1 : 1;
539
+            } else if (isset($a['order']) || isset($b['order'])) {
540
+                return isset($a['order']) ? -1 : 1;
541
+            } else {
542
+                return ($a['name'] < $b['name']) ? -1 : 1;
543
+            }
544
+        });
545
+
546
+        $activeAppIndex = -1;
547
+        $activeApp = OC::$server->getNavigationManager()->getActiveEntry();
548
+        foreach ($list as $index => &$navEntry) {
549
+            if ($navEntry['id'] == $activeApp) {
550
+                $navEntry['active'] = true;
551
+                $activeAppIndex = $index;
552
+            } else {
553
+                $navEntry['active'] = false;
554
+            }
555
+        }
556
+        unset($navEntry);
557
+
558
+        if($activeAppIndex > ($headerIconCount-1)) {
559
+            $active = $list[$activeAppIndex];
560
+            $lastInHeader = $list[$headerIconCount-1];
561
+            $list[$headerIconCount-1] = $active;
562
+            $list[$activeAppIndex] = $lastInHeader;
563
+        }
564
+
565
+        foreach ($list as $index => &$navEntry) {
566
+            $navEntry['showInHeader'] = false;
567
+            if($index < $headerIconCount) {
568
+                $navEntry['showInHeader'] = true;
569
+            }
570
+        }
571
+
572
+
573
+
574
+        return $list;
575
+    }
576
+
577
+    public static function proceedAppNavigation($entries) {
578
+        $headerIconCount = 8;
579
+        if(OC_User::isAdminUser(OC_User::getUser())) {
580
+            $headerIconCount--;
581
+        }
582
+        $activeAppIndex = -1;
583
+        $list = self::proceedNavigation($entries);
584
+
585
+        $activeApp = OC::$server->getNavigationManager()->getActiveEntry();
586
+        foreach ($list as $index => &$navEntry) {
587
+            if ($navEntry['id'] == $activeApp) {
588
+                $navEntry['active'] = true;
589
+                $activeAppIndex = $index;
590
+            } else {
591
+                $navEntry['active'] = false;
592
+            }
593
+        }
594
+        // move active item to last position
595
+        if($activeAppIndex > ($headerIconCount-1)) {
596
+            $active = $list[$activeAppIndex];
597
+            $lastInHeader = $list[$headerIconCount-1];
598
+            $list[$headerIconCount-1] = $active;
599
+            $list[$activeAppIndex] = $lastInHeader;
600
+        }
601
+        $list = array_slice($list, 0, $headerIconCount);
602
+
603
+        return $list;
604
+    }
605
+
606
+    /**
607
+     * Get the path where to install apps
608
+     *
609
+     * @return string|false
610
+     */
611
+    public static function getInstallPath() {
612
+        if (\OC::$server->getSystemConfig()->getValue('appstoreenabled', true) == false) {
613
+            return false;
614
+        }
615
+
616
+        foreach (OC::$APPSROOTS as $dir) {
617
+            if (isset($dir['writable']) && $dir['writable'] === true) {
618
+                return $dir['path'];
619
+            }
620
+        }
621
+
622
+        \OCP\Util::writeLog('core', 'No application directories are marked as writable.', \OCP\Util::ERROR);
623
+        return null;
624
+    }
625
+
626
+
627
+    /**
628
+     * search for an app in all app-directories
629
+     *
630
+     * @param string $appId
631
+     * @return false|string
632
+     */
633
+    public static function findAppInDirectories($appId) {
634
+        $sanitizedAppId = self::cleanAppId($appId);
635
+        if($sanitizedAppId !== $appId) {
636
+            return false;
637
+        }
638
+        static $app_dir = array();
639
+
640
+        if (isset($app_dir[$appId])) {
641
+            return $app_dir[$appId];
642
+        }
643
+
644
+        $possibleApps = array();
645
+        foreach (OC::$APPSROOTS as $dir) {
646
+            if (file_exists($dir['path'] . '/' . $appId)) {
647
+                $possibleApps[] = $dir;
648
+            }
649
+        }
650
+
651
+        if (empty($possibleApps)) {
652
+            return false;
653
+        } elseif (count($possibleApps) === 1) {
654
+            $dir = array_shift($possibleApps);
655
+            $app_dir[$appId] = $dir;
656
+            return $dir;
657
+        } else {
658
+            $versionToLoad = array();
659
+            foreach ($possibleApps as $possibleApp) {
660
+                $version = self::getAppVersionByPath($possibleApp['path']);
661
+                if (empty($versionToLoad) || version_compare($version, $versionToLoad['version'], '>')) {
662
+                    $versionToLoad = array(
663
+                        'dir' => $possibleApp,
664
+                        'version' => $version,
665
+                    );
666
+                }
667
+            }
668
+            $app_dir[$appId] = $versionToLoad['dir'];
669
+            return $versionToLoad['dir'];
670
+            //TODO - write test
671
+        }
672
+    }
673
+
674
+    /**
675
+     * Get the directory for the given app.
676
+     * If the app is defined in multiple directories, the first one is taken. (false if not found)
677
+     *
678
+     * @param string $appId
679
+     * @return string|false
680
+     */
681
+    public static function getAppPath($appId) {
682
+        if ($appId === null || trim($appId) === '') {
683
+            return false;
684
+        }
685
+
686
+        if (($dir = self::findAppInDirectories($appId)) != false) {
687
+            return $dir['path'] . '/' . $appId;
688
+        }
689
+        return false;
690
+    }
691
+
692
+    /**
693
+     * Get the path for the given app on the access
694
+     * If the app is defined in multiple directories, the first one is taken. (false if not found)
695
+     *
696
+     * @param string $appId
697
+     * @return string|false
698
+     */
699
+    public static function getAppWebPath($appId) {
700
+        if (($dir = self::findAppInDirectories($appId)) != false) {
701
+            return OC::$WEBROOT . $dir['url'] . '/' . $appId;
702
+        }
703
+        return false;
704
+    }
705
+
706
+    /**
707
+     * get the last version of the app from appinfo/info.xml
708
+     *
709
+     * @param string $appId
710
+     * @param bool $useCache
711
+     * @return string
712
+     */
713
+    public static function getAppVersion($appId, $useCache = true) {
714
+        if($useCache && isset(self::$appVersion[$appId])) {
715
+            return self::$appVersion[$appId];
716
+        }
717
+
718
+        $file = self::getAppPath($appId);
719
+        self::$appVersion[$appId] = ($file !== false) ? self::getAppVersionByPath($file) : '0';
720
+        return self::$appVersion[$appId];
721
+    }
722
+
723
+    /**
724
+     * get app's version based on it's path
725
+     *
726
+     * @param string $path
727
+     * @return string
728
+     */
729
+    public static function getAppVersionByPath($path) {
730
+        $infoFile = $path . '/appinfo/info.xml';
731
+        $appData = self::getAppInfo($infoFile, true);
732
+        return isset($appData['version']) ? $appData['version'] : '';
733
+    }
734
+
735
+
736
+    /**
737
+     * Read all app metadata from the info.xml file
738
+     *
739
+     * @param string $appId id of the app or the path of the info.xml file
740
+     * @param bool $path
741
+     * @param string $lang
742
+     * @return array|null
743
+     * @note all data is read from info.xml, not just pre-defined fields
744
+     */
745
+    public static function getAppInfo($appId, $path = false, $lang = null) {
746
+        if ($path) {
747
+            $file = $appId;
748
+        } else {
749
+            if ($lang === null && isset(self::$appInfo[$appId])) {
750
+                return self::$appInfo[$appId];
751
+            }
752
+            $appPath = self::getAppPath($appId);
753
+            if($appPath === false) {
754
+                return null;
755
+            }
756
+            $file = $appPath . '/appinfo/info.xml';
757
+        }
758
+
759
+        $parser = new InfoParser(\OC::$server->getMemCacheFactory()->create('core.appinfo'));
760
+        $data = $parser->parse($file);
761
+
762
+        if (is_array($data)) {
763
+            $data = OC_App::parseAppInfo($data, $lang);
764
+        }
765
+        if(isset($data['ocsid'])) {
766
+            $storedId = \OC::$server->getConfig()->getAppValue($appId, 'ocsid');
767
+            if($storedId !== '' && $storedId !== $data['ocsid']) {
768
+                $data['ocsid'] = $storedId;
769
+            }
770
+        }
771
+
772
+        if ($lang === null) {
773
+            self::$appInfo[$appId] = $data;
774
+        }
775
+
776
+        return $data;
777
+    }
778
+
779
+    /**
780
+     * Returns the navigation
781
+     *
782
+     * @return array
783
+     *
784
+     * This function returns an array containing all entries added. The
785
+     * entries are sorted by the key 'order' ascending. Additional to the keys
786
+     * given for each app the following keys exist:
787
+     *   - active: boolean, signals if the user is on this navigation entry
788
+     */
789
+    public static function getNavigation() {
790
+        $entries = OC::$server->getNavigationManager()->getAll();
791
+        $navigation = self::proceedNavigation($entries);
792
+        return $navigation;
793
+    }
794
+
795
+    /**
796
+     * Returns the navigation inside the header bar
797
+     *
798
+     * @return array
799
+     *
800
+     * This function returns an array containing all entries added. The
801
+     * entries are sorted by the key 'order' ascending. Additional to the keys
802
+     * given for each app the following keys exist:
803
+     *   - active: boolean, signals if the user is on this navigation entry
804
+     */
805
+    public static function getHeaderNavigation() {
806
+        $entries = OC::$server->getNavigationManager()->getAll();
807
+        $navigation = self::proceedAppNavigation($entries);
808
+        return $navigation;
809
+    }
810
+
811
+    /**
812
+     * get the id of loaded app
813
+     *
814
+     * @return string
815
+     */
816
+    public static function getCurrentApp() {
817
+        $request = \OC::$server->getRequest();
818
+        $script = substr($request->getScriptName(), strlen(OC::$WEBROOT) + 1);
819
+        $topFolder = substr($script, 0, strpos($script, '/'));
820
+        if (empty($topFolder)) {
821
+            $path_info = $request->getPathInfo();
822
+            if ($path_info) {
823
+                $topFolder = substr($path_info, 1, strpos($path_info, '/', 1) - 1);
824
+            }
825
+        }
826
+        if ($topFolder == 'apps') {
827
+            $length = strlen($topFolder);
828
+            return substr($script, $length + 1, strpos($script, '/', $length + 1) - $length - 1);
829
+        } else {
830
+            return $topFolder;
831
+        }
832
+    }
833
+
834
+    /**
835
+     * @param string $type
836
+     * @return array
837
+     */
838
+    public static function getForms($type) {
839
+        $forms = array();
840
+        switch ($type) {
841
+            case 'admin':
842
+                $source = self::$adminForms;
843
+                break;
844
+            case 'personal':
845
+                $source = self::$personalForms;
846
+                break;
847
+            default:
848
+                return array();
849
+        }
850
+        foreach ($source as $form) {
851
+            $forms[] = include $form;
852
+        }
853
+        return $forms;
854
+    }
855
+
856
+    /**
857
+     * register an admin form to be shown
858
+     *
859
+     * @param string $app
860
+     * @param string $page
861
+     */
862
+    public static function registerAdmin($app, $page) {
863
+        self::$adminForms[] = $app . '/' . $page . '.php';
864
+    }
865
+
866
+    /**
867
+     * register a personal form to be shown
868
+     * @param string $app
869
+     * @param string $page
870
+     */
871
+    public static function registerPersonal($app, $page) {
872
+        self::$personalForms[] = $app . '/' . $page . '.php';
873
+    }
874
+
875
+    /**
876
+     * @param array $entry
877
+     */
878
+    public static function registerLogIn(array $entry) {
879
+        self::$altLogin[] = $entry;
880
+    }
881
+
882
+    /**
883
+     * @return array
884
+     */
885
+    public static function getAlternativeLogIns() {
886
+        return self::$altLogin;
887
+    }
888
+
889
+    /**
890
+     * get a list of all apps in the apps folder
891
+     *
892
+     * @return array an array of app names (string IDs)
893
+     * @todo: change the name of this method to getInstalledApps, which is more accurate
894
+     */
895
+    public static function getAllApps() {
896
+
897
+        $apps = array();
898
+
899
+        foreach (OC::$APPSROOTS as $apps_dir) {
900
+            if (!is_readable($apps_dir['path'])) {
901
+                \OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN);
902
+                continue;
903
+            }
904
+            $dh = opendir($apps_dir['path']);
905
+
906
+            if (is_resource($dh)) {
907
+                while (($file = readdir($dh)) !== false) {
908
+
909
+                    if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) {
910
+
911
+                        $apps[] = $file;
912
+                    }
913
+                }
914
+            }
915
+        }
916
+
917
+        return $apps;
918
+    }
919
+
920
+    /**
921
+     * List all apps, this is used in apps.php
922
+     *
923
+     * @return array
924
+     */
925
+    public function listAllApps() {
926
+        $installedApps = OC_App::getAllApps();
927
+
928
+        //we don't want to show configuration for these
929
+        $blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps();
930
+        $appList = array();
931
+        $langCode = \OC::$server->getL10N('core')->getLanguageCode();
932
+        $urlGenerator = \OC::$server->getURLGenerator();
933
+
934
+        foreach ($installedApps as $app) {
935
+            if (array_search($app, $blacklist) === false) {
936
+
937
+                $info = OC_App::getAppInfo($app, false, $langCode);
938
+                if (!is_array($info)) {
939
+                    \OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR);
940
+                    continue;
941
+                }
942
+
943
+                if (!isset($info['name'])) {
944
+                    \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR);
945
+                    continue;
946
+                }
947
+
948
+                $enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'no');
949
+                $info['groups'] = null;
950
+                if ($enabled === 'yes') {
951
+                    $active = true;
952
+                } else if ($enabled === 'no') {
953
+                    $active = false;
954
+                } else {
955
+                    $active = true;
956
+                    $info['groups'] = $enabled;
957
+                }
958
+
959
+                $info['active'] = $active;
960
+
961
+                if (self::isShipped($app)) {
962
+                    $info['internal'] = true;
963
+                    $info['level'] = self::officialApp;
964
+                    $info['removable'] = false;
965
+                } else {
966
+                    $info['internal'] = false;
967
+                    $info['removable'] = true;
968
+                }
969
+
970
+                $appPath = self::getAppPath($app);
971
+                if($appPath !== false) {
972
+                    $appIcon = $appPath . '/img/' . $app . '.svg';
973
+                    if (file_exists($appIcon)) {
974
+                        $info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, $app . '.svg');
975
+                        $info['previewAsIcon'] = true;
976
+                    } else {
977
+                        $appIcon = $appPath . '/img/app.svg';
978
+                        if (file_exists($appIcon)) {
979
+                            $info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, 'app.svg');
980
+                            $info['previewAsIcon'] = true;
981
+                        }
982
+                    }
983
+                }
984
+                // fix documentation
985
+                if (isset($info['documentation']) && is_array($info['documentation'])) {
986
+                    foreach ($info['documentation'] as $key => $url) {
987
+                        // If it is not an absolute URL we assume it is a key
988
+                        // i.e. admin-ldap will get converted to go.php?to=admin-ldap
989
+                        if (stripos($url, 'https://') !== 0 && stripos($url, 'http://') !== 0) {
990
+                            $url = $urlGenerator->linkToDocs($url);
991
+                        }
992
+
993
+                        $info['documentation'][$key] = $url;
994
+                    }
995
+                }
996
+
997
+                $info['version'] = OC_App::getAppVersion($app);
998
+                $appList[] = $info;
999
+            }
1000
+        }
1001
+
1002
+        return $appList;
1003
+    }
1004
+
1005
+    /**
1006
+     * Returns the internal app ID or false
1007
+     * @param string $ocsID
1008
+     * @return string|false
1009
+     */
1010
+    public static function getInternalAppIdByOcs($ocsID) {
1011
+        if(is_numeric($ocsID)) {
1012
+            $idArray = \OC::$server->getAppConfig()->getValues(false, 'ocsid');
1013
+            if(array_search($ocsID, $idArray)) {
1014
+                return array_search($ocsID, $idArray);
1015
+            }
1016
+        }
1017
+        return false;
1018
+    }
1019
+
1020
+    public static function shouldUpgrade($app) {
1021
+        $versions = self::getAppVersions();
1022
+        $currentVersion = OC_App::getAppVersion($app);
1023
+        if ($currentVersion && isset($versions[$app])) {
1024
+            $installedVersion = $versions[$app];
1025
+            if (!version_compare($currentVersion, $installedVersion, '=')) {
1026
+                return true;
1027
+            }
1028
+        }
1029
+        return false;
1030
+    }
1031
+
1032
+    /**
1033
+     * Adjust the number of version parts of $version1 to match
1034
+     * the number of version parts of $version2.
1035
+     *
1036
+     * @param string $version1 version to adjust
1037
+     * @param string $version2 version to take the number of parts from
1038
+     * @return string shortened $version1
1039
+     */
1040
+    private static function adjustVersionParts($version1, $version2) {
1041
+        $version1 = explode('.', $version1);
1042
+        $version2 = explode('.', $version2);
1043
+        // reduce $version1 to match the number of parts in $version2
1044
+        while (count($version1) > count($version2)) {
1045
+            array_pop($version1);
1046
+        }
1047
+        // if $version1 does not have enough parts, add some
1048
+        while (count($version1) < count($version2)) {
1049
+            $version1[] = '0';
1050
+        }
1051
+        return implode('.', $version1);
1052
+    }
1053
+
1054
+    /**
1055
+     * Check whether the current ownCloud version matches the given
1056
+     * application's version requirements.
1057
+     *
1058
+     * The comparison is made based on the number of parts that the
1059
+     * app info version has. For example for ownCloud 6.0.3 if the
1060
+     * app info version is expecting version 6.0, the comparison is
1061
+     * made on the first two parts of the ownCloud version.
1062
+     * This means that it's possible to specify "requiremin" => 6
1063
+     * and "requiremax" => 6 and it will still match ownCloud 6.0.3.
1064
+     *
1065
+     * @param string $ocVersion ownCloud version to check against
1066
+     * @param array $appInfo app info (from xml)
1067
+     *
1068
+     * @return boolean true if compatible, otherwise false
1069
+     */
1070
+    public static function isAppCompatible($ocVersion, $appInfo) {
1071
+        $requireMin = '';
1072
+        $requireMax = '';
1073
+        if (isset($appInfo['dependencies']['nextcloud']['@attributes']['min-version'])) {
1074
+            $requireMin = $appInfo['dependencies']['nextcloud']['@attributes']['min-version'];
1075
+        } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['min-version'])) {
1076
+            $requireMin = $appInfo['dependencies']['owncloud']['@attributes']['min-version'];
1077
+        } else if (isset($appInfo['requiremin'])) {
1078
+            $requireMin = $appInfo['requiremin'];
1079
+        } else if (isset($appInfo['require'])) {
1080
+            $requireMin = $appInfo['require'];
1081
+        }
1082
+
1083
+        if (isset($appInfo['dependencies']['nextcloud']['@attributes']['max-version'])) {
1084
+            $requireMax = $appInfo['dependencies']['nextcloud']['@attributes']['max-version'];
1085
+        } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['max-version'])) {
1086
+            $requireMax = $appInfo['dependencies']['owncloud']['@attributes']['max-version'];
1087
+        } else if (isset($appInfo['requiremax'])) {
1088
+            $requireMax = $appInfo['requiremax'];
1089
+        }
1090
+
1091
+        if (is_array($ocVersion)) {
1092
+            $ocVersion = implode('.', $ocVersion);
1093
+        }
1094
+
1095
+        if (!empty($requireMin)
1096
+            && version_compare(self::adjustVersionParts($ocVersion, $requireMin), $requireMin, '<')
1097
+        ) {
1098
+
1099
+            return false;
1100
+        }
1101
+
1102
+        if (!empty($requireMax)
1103
+            && version_compare(self::adjustVersionParts($ocVersion, $requireMax), $requireMax, '>')
1104
+        ) {
1105
+            return false;
1106
+        }
1107
+
1108
+        return true;
1109
+    }
1110
+
1111
+    /**
1112
+     * get the installed version of all apps
1113
+     */
1114
+    public static function getAppVersions() {
1115
+        static $versions;
1116
+
1117
+        if(!$versions) {
1118
+            $appConfig = \OC::$server->getAppConfig();
1119
+            $versions = $appConfig->getValues(false, 'installed_version');
1120
+        }
1121
+        return $versions;
1122
+    }
1123
+
1124
+    /**
1125
+     * @param string $app
1126
+     * @param \OCP\IConfig $config
1127
+     * @param \OCP\IL10N $l
1128
+     * @return bool
1129
+     *
1130
+     * @throws Exception if app is not compatible with this version of ownCloud
1131
+     * @throws Exception if no app-name was specified
1132
+     */
1133
+    public function installApp($app,
1134
+                                \OCP\IConfig $config,
1135
+                                \OCP\IL10N $l) {
1136
+        if ($app !== false) {
1137
+            // check if the app is compatible with this version of ownCloud
1138
+            $info = self::getAppInfo($app);
1139
+            if(!is_array($info)) {
1140
+                throw new \Exception(
1141
+                    $l->t('App "%s" cannot be installed because appinfo file cannot be read.',
1142
+                        [$info['name']]
1143
+                    )
1144
+                );
1145
+            }
1146
+
1147
+            $version = \OCP\Util::getVersion();
1148
+            if (!self::isAppCompatible($version, $info)) {
1149
+                throw new \Exception(
1150
+                    $l->t('App "%s" cannot be installed because it is not compatible with this version of the server.',
1151
+                        array($info['name'])
1152
+                    )
1153
+                );
1154
+            }
1155
+
1156
+            // check for required dependencies
1157
+            self::checkAppDependencies($config, $l, $info);
1158
+
1159
+            $config->setAppValue($app, 'enabled', 'yes');
1160
+            if (isset($appData['id'])) {
1161
+                $config->setAppValue($app, 'ocsid', $appData['id']);
1162
+            }
1163
+
1164
+            if(isset($info['settings']) && is_array($info['settings'])) {
1165
+                $appPath = self::getAppPath($app);
1166
+                self::registerAutoloading($app, $appPath);
1167
+                \OC::$server->getSettingsManager()->setupSettings($info['settings']);
1168
+            }
1169
+
1170
+            \OC_Hook::emit('OC_App', 'post_enable', array('app' => $app));
1171
+        } else {
1172
+            if(empty($appName) ) {
1173
+                throw new \Exception($l->t("No app name specified"));
1174
+            } else {
1175
+                throw new \Exception($l->t("App '%s' could not be installed!", $appName));
1176
+            }
1177
+        }
1178
+
1179
+        return $app;
1180
+    }
1181
+
1182
+    /**
1183
+     * update the database for the app and call the update script
1184
+     *
1185
+     * @param string $appId
1186
+     * @return bool
1187
+     */
1188
+    public static function updateApp($appId) {
1189
+        $appPath = self::getAppPath($appId);
1190
+        if($appPath === false) {
1191
+            return false;
1192
+        }
1193
+        $appData = self::getAppInfo($appId);
1194
+        self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']);
1195
+        if (file_exists($appPath . '/appinfo/database.xml')) {
1196
+            OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml');
1197
+        }
1198
+        self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']);
1199
+        self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']);
1200
+        unset(self::$appVersion[$appId]);
1201
+        // run upgrade code
1202
+        if (file_exists($appPath . '/appinfo/update.php')) {
1203
+            self::loadApp($appId);
1204
+            include $appPath . '/appinfo/update.php';
1205
+        }
1206
+        self::setupBackgroundJobs($appData['background-jobs']);
1207
+        if(isset($appData['settings']) && is_array($appData['settings'])) {
1208
+            $appPath = self::getAppPath($appId);
1209
+            self::registerAutoloading($appId, $appPath);
1210
+            \OC::$server->getSettingsManager()->setupSettings($appData['settings']);
1211
+        }
1212
+
1213
+        //set remote/public handlers
1214
+        if (array_key_exists('ocsid', $appData)) {
1215
+            \OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']);
1216
+        } elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) {
1217
+            \OC::$server->getConfig()->deleteAppValue($appId, 'ocsid');
1218
+        }
1219
+        foreach ($appData['remote'] as $name => $path) {
1220
+            \OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path);
1221
+        }
1222
+        foreach ($appData['public'] as $name => $path) {
1223
+            \OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path);
1224
+        }
1225
+
1226
+        self::setAppTypes($appId);
1227
+
1228
+        $version = \OC_App::getAppVersion($appId);
1229
+        \OC::$server->getAppConfig()->setValue($appId, 'installed_version', $version);
1230
+
1231
+        \OC::$server->getEventDispatcher()->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent(
1232
+            ManagerEvent::EVENT_APP_UPDATE, $appId
1233
+        ));
1234
+
1235
+        return true;
1236
+    }
1237
+
1238
+    /**
1239
+     * @param string $appId
1240
+     * @param string[] $steps
1241
+     * @throws \OC\NeedsUpdateException
1242
+     */
1243
+    public static function executeRepairSteps($appId, array $steps) {
1244
+        if (empty($steps)) {
1245
+            return;
1246
+        }
1247
+        // load the app
1248
+        self::loadApp($appId);
1249
+
1250
+        $dispatcher = OC::$server->getEventDispatcher();
1251
+
1252
+        // load the steps
1253
+        $r = new Repair([], $dispatcher);
1254
+        foreach ($steps as $step) {
1255
+            try {
1256
+                $r->addStep($step);
1257
+            } catch (Exception $ex) {
1258
+                $r->emit('\OC\Repair', 'error', [$ex->getMessage()]);
1259
+                \OC::$server->getLogger()->logException($ex);
1260
+            }
1261
+        }
1262
+        // run the steps
1263
+        $r->run();
1264
+    }
1265
+
1266
+    public static function setupBackgroundJobs(array $jobs) {
1267
+        $queue = \OC::$server->getJobList();
1268
+        foreach ($jobs as $job) {
1269
+            $queue->add($job);
1270
+        }
1271
+    }
1272
+
1273
+    /**
1274
+     * @param string $appId
1275
+     * @param string[] $steps
1276
+     */
1277
+    private static function setupLiveMigrations($appId, array $steps) {
1278
+        $queue = \OC::$server->getJobList();
1279
+        foreach ($steps as $step) {
1280
+            $queue->add('OC\Migration\BackgroundRepair', [
1281
+                'app' => $appId,
1282
+                'step' => $step]);
1283
+        }
1284
+    }
1285
+
1286
+    /**
1287
+     * @param string $appId
1288
+     * @return \OC\Files\View|false
1289
+     */
1290
+    public static function getStorage($appId) {
1291
+        if (OC_App::isEnabled($appId)) { //sanity check
1292
+            if (\OC::$server->getUserSession()->isLoggedIn()) {
1293
+                $view = new \OC\Files\View('/' . OC_User::getUser());
1294
+                if (!$view->file_exists($appId)) {
1295
+                    $view->mkdir($appId);
1296
+                }
1297
+                return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId);
1298
+            } else {
1299
+                \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR);
1300
+                return false;
1301
+            }
1302
+        } else {
1303
+            \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR);
1304
+            return false;
1305
+        }
1306
+    }
1307
+
1308
+    protected static function findBestL10NOption($options, $lang) {
1309
+        $fallback = $similarLangFallback = $englishFallback = false;
1310
+
1311
+        $lang = strtolower($lang);
1312
+        $similarLang = $lang;
1313
+        if (strpos($similarLang, '_')) {
1314
+            // For "de_DE" we want to find "de" and the other way around
1315
+            $similarLang = substr($lang, 0, strpos($lang, '_'));
1316
+        }
1317
+
1318
+        foreach ($options as $option) {
1319
+            if (is_array($option)) {
1320
+                if ($fallback === false) {
1321
+                    $fallback = $option['@value'];
1322
+                }
1323
+
1324
+                if (!isset($option['@attributes']['lang'])) {
1325
+                    continue;
1326
+                }
1327
+
1328
+                $attributeLang = strtolower($option['@attributes']['lang']);
1329
+                if ($attributeLang === $lang) {
1330
+                    return $option['@value'];
1331
+                }
1332
+
1333
+                if ($attributeLang === $similarLang) {
1334
+                    $similarLangFallback = $option['@value'];
1335
+                } else if (strpos($attributeLang, $similarLang . '_') === 0) {
1336
+                    if ($similarLangFallback === false) {
1337
+                        $similarLangFallback =  $option['@value'];
1338
+                    }
1339
+                }
1340
+            } else {
1341
+                $englishFallback = $option;
1342
+            }
1343
+        }
1344
+
1345
+        if ($similarLangFallback !== false) {
1346
+            return $similarLangFallback;
1347
+        } else if ($englishFallback !== false) {
1348
+            return $englishFallback;
1349
+        }
1350
+        return (string) $fallback;
1351
+    }
1352
+
1353
+    /**
1354
+     * parses the app data array and enhanced the 'description' value
1355
+     *
1356
+     * @param array $data the app data
1357
+     * @param string $lang
1358
+     * @return array improved app data
1359
+     */
1360
+    public static function parseAppInfo(array $data, $lang = null) {
1361
+
1362
+        if ($lang && isset($data['name']) && is_array($data['name'])) {
1363
+            $data['name'] = self::findBestL10NOption($data['name'], $lang);
1364
+        }
1365
+        if ($lang && isset($data['summary']) && is_array($data['summary'])) {
1366
+            $data['summary'] = self::findBestL10NOption($data['summary'], $lang);
1367
+        }
1368
+        if ($lang && isset($data['description']) && is_array($data['description'])) {
1369
+            $data['description'] = trim(self::findBestL10NOption($data['description'], $lang));
1370
+        } else if (isset($data['description']) && is_string($data['description'])) {
1371
+            $data['description'] = trim($data['description']);
1372
+        } else  {
1373
+            $data['description'] = '';
1374
+        }
1375
+
1376
+        return $data;
1377
+    }
1378
+
1379
+    /**
1380
+     * @param \OCP\IConfig $config
1381
+     * @param \OCP\IL10N $l
1382
+     * @param array $info
1383
+     * @throws \Exception
1384
+     */
1385
+    protected static function checkAppDependencies($config, $l, $info) {
1386
+        $dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l);
1387
+        $missing = $dependencyAnalyzer->analyze($info);
1388
+        if (!empty($missing)) {
1389
+            $missingMsg = join(PHP_EOL, $missing);
1390
+            throw new \Exception(
1391
+                $l->t('App "%s" cannot be installed because the following dependencies are not fulfilled: %s',
1392
+                    [$info['name'], $missingMsg]
1393
+                )
1394
+            );
1395
+        }
1396
+    }
1397 1397
 }
Please login to merge, or discard this patch.
Spacing   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -111,9 +111,9 @@  discard block
 block discarded – undo
111 111
 		$apps = self::getEnabledApps();
112 112
 
113 113
 		// Add each apps' folder as allowed class path
114
-		foreach($apps as $app) {
114
+		foreach ($apps as $app) {
115 115
 			$path = self::getAppPath($app);
116
-			if($path !== false) {
116
+			if ($path !== false) {
117 117
 				self::registerAutoloading($app, $path);
118 118
 			}
119 119
 		}
@@ -138,15 +138,15 @@  discard block
 block discarded – undo
138 138
 	public static function loadApp($app) {
139 139
 		self::$loadedApps[] = $app;
140 140
 		$appPath = self::getAppPath($app);
141
-		if($appPath === false) {
141
+		if ($appPath === false) {
142 142
 			return;
143 143
 		}
144 144
 
145 145
 		// in case someone calls loadApp() directly
146 146
 		self::registerAutoloading($app, $appPath);
147 147
 
148
-		if (is_file($appPath . '/appinfo/app.php')) {
149
-			\OC::$server->getEventLogger()->start('load_app_' . $app, 'Load app: ' . $app);
148
+		if (is_file($appPath.'/appinfo/app.php')) {
149
+			\OC::$server->getEventLogger()->start('load_app_'.$app, 'Load app: '.$app);
150 150
 			self::requireAppFile($app);
151 151
 			if (self::isType($app, array('authentication'))) {
152 152
 				// since authentication apps affect the "is app enabled for group" check,
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 				// enabled for groups
156 156
 				self::$enabledAppsCache = array();
157 157
 			}
158
-			\OC::$server->getEventLogger()->end('load_app_' . $app);
158
+			\OC::$server->getEventLogger()->end('load_app_'.$app);
159 159
 		}
160 160
 
161 161
 		$info = self::getAppInfo($app);
@@ -182,16 +182,16 @@  discard block
 block discarded – undo
182 182
 	 * @param string $path
183 183
 	 */
184 184
 	public static function registerAutoloading($app, $path) {
185
-		$key = $app . '-' . $path;
186
-		if(isset(self::$alreadyRegistered[$key])) {
185
+		$key = $app.'-'.$path;
186
+		if (isset(self::$alreadyRegistered[$key])) {
187 187
 			return;
188 188
 		}
189 189
 		self::$alreadyRegistered[$key] = true;
190 190
 		// Register on PSR-4 composer autoloader
191 191
 		$appNamespace = \OC\AppFramework\App::buildAppNamespace($app);
192
-		\OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true);
192
+		\OC::$composerAutoloader->addPsr4($appNamespace.'\\', $path.'/lib/', true);
193 193
 		if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) {
194
-			\OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true);
194
+			\OC::$composerAutoloader->addPsr4($appNamespace.'\\Tests\\', $path.'/tests/', true);
195 195
 		}
196 196
 
197 197
 		// Register on legacy autoloader
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
 	private static function requireAppFile($app) {
207 207
 		try {
208 208
 			// encapsulated here to avoid variable scope conflicts
209
-			require_once $app . '/appinfo/app.php';
209
+			require_once $app.'/appinfo/app.php';
210 210
 		} catch (Error $ex) {
211 211
 			\OC::$server->getLogger()->logException($ex);
212 212
 			$blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps();
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
 	 */
261 261
 	public static function setAppTypes($app) {
262 262
 		$appData = self::getAppInfo($app);
263
-		if(!is_array($appData)) {
263
+		if (!is_array($appData)) {
264 264
 			return;
265 265
 		}
266 266
 
@@ -324,8 +324,8 @@  discard block
 block discarded – undo
324 324
 		} else {
325 325
 			$apps = $appManager->getEnabledAppsForUser($user);
326 326
 		}
327
-		$apps = array_filter($apps, function ($app) {
328
-			return $app !== 'files';//we add this manually
327
+		$apps = array_filter($apps, function($app) {
328
+			return $app !== 'files'; //we add this manually
329 329
 		});
330 330
 		sort($apps);
331 331
 		array_unshift($apps, 'files');
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
 		);
370 370
 		$isDownloaded = $installer->isDownloaded($appId);
371 371
 
372
-		if(!$isDownloaded) {
372
+		if (!$isDownloaded) {
373 373
 			$installer->downloadApp($appId);
374 374
 		}
375 375
 
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
 		}
408 408
 
409 409
 		$info = self::getAppInfo($appId);
410
-		if(isset($info['settings']) && is_array($info['settings'])) {
410
+		if (isset($info['settings']) && is_array($info['settings'])) {
411 411
 			$appPath = self::getAppPath($appId);
412 412
 			self::registerAutoloading($appId, $appPath);
413 413
 			\OC::$server->getSettingsManager()->setupSettings($info['settings']);
@@ -496,7 +496,7 @@  discard block
 block discarded – undo
496 496
 			//SubAdmins are also allowed to access user management
497 497
 			$userObject = \OC::$server->getUserSession()->getUser();
498 498
 			$isSubAdmin = false;
499
-			if($userObject !== null) {
499
+			if ($userObject !== null) {
500 500
 				$isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject);
501 501
 			}
502 502
 			if ($isSubAdmin) {
@@ -530,7 +530,7 @@  discard block
 block discarded – undo
530 530
 	// This is private as well. It simply works, so don't ask for more details
531 531
 	private static function proceedNavigation($list) {
532 532
 		$headerIconCount = 8;
533
-		if(OC_User::isAdminUser(OC_User::getUser())) {
533
+		if (OC_User::isAdminUser(OC_User::getUser())) {
534 534
 			$headerIconCount--;
535 535
 		}
536 536
 		usort($list, function($a, $b) {
@@ -555,16 +555,16 @@  discard block
 block discarded – undo
555 555
 		}
556 556
 		unset($navEntry);
557 557
 
558
-		if($activeAppIndex > ($headerIconCount-1)) {
558
+		if ($activeAppIndex > ($headerIconCount - 1)) {
559 559
 			$active = $list[$activeAppIndex];
560
-			$lastInHeader = $list[$headerIconCount-1];
561
-			$list[$headerIconCount-1] = $active;
560
+			$lastInHeader = $list[$headerIconCount - 1];
561
+			$list[$headerIconCount - 1] = $active;
562 562
 			$list[$activeAppIndex] = $lastInHeader;
563 563
 		}
564 564
 
565 565
 		foreach ($list as $index => &$navEntry) {
566 566
 			$navEntry['showInHeader'] = false;
567
-			if($index < $headerIconCount) {
567
+			if ($index < $headerIconCount) {
568 568
 				$navEntry['showInHeader'] = true;
569 569
 			}
570 570
 		}
@@ -576,7 +576,7 @@  discard block
 block discarded – undo
576 576
 
577 577
 	public static function proceedAppNavigation($entries) {
578 578
 		$headerIconCount = 8;
579
-		if(OC_User::isAdminUser(OC_User::getUser())) {
579
+		if (OC_User::isAdminUser(OC_User::getUser())) {
580 580
 			$headerIconCount--;
581 581
 		}
582 582
 		$activeAppIndex = -1;
@@ -592,10 +592,10 @@  discard block
 block discarded – undo
592 592
 			}
593 593
 		}
594 594
 		// move active item to last position
595
-		if($activeAppIndex > ($headerIconCount-1)) {
595
+		if ($activeAppIndex > ($headerIconCount - 1)) {
596 596
 			$active = $list[$activeAppIndex];
597
-			$lastInHeader = $list[$headerIconCount-1];
598
-			$list[$headerIconCount-1] = $active;
597
+			$lastInHeader = $list[$headerIconCount - 1];
598
+			$list[$headerIconCount - 1] = $active;
599 599
 			$list[$activeAppIndex] = $lastInHeader;
600 600
 		}
601 601
 		$list = array_slice($list, 0, $headerIconCount);
@@ -632,7 +632,7 @@  discard block
 block discarded – undo
632 632
 	 */
633 633
 	public static function findAppInDirectories($appId) {
634 634
 		$sanitizedAppId = self::cleanAppId($appId);
635
-		if($sanitizedAppId !== $appId) {
635
+		if ($sanitizedAppId !== $appId) {
636 636
 			return false;
637 637
 		}
638 638
 		static $app_dir = array();
@@ -643,7 +643,7 @@  discard block
 block discarded – undo
643 643
 
644 644
 		$possibleApps = array();
645 645
 		foreach (OC::$APPSROOTS as $dir) {
646
-			if (file_exists($dir['path'] . '/' . $appId)) {
646
+			if (file_exists($dir['path'].'/'.$appId)) {
647 647
 				$possibleApps[] = $dir;
648 648
 			}
649 649
 		}
@@ -684,7 +684,7 @@  discard block
 block discarded – undo
684 684
 		}
685 685
 
686 686
 		if (($dir = self::findAppInDirectories($appId)) != false) {
687
-			return $dir['path'] . '/' . $appId;
687
+			return $dir['path'].'/'.$appId;
688 688
 		}
689 689
 		return false;
690 690
 	}
@@ -698,7 +698,7 @@  discard block
 block discarded – undo
698 698
 	 */
699 699
 	public static function getAppWebPath($appId) {
700 700
 		if (($dir = self::findAppInDirectories($appId)) != false) {
701
-			return OC::$WEBROOT . $dir['url'] . '/' . $appId;
701
+			return OC::$WEBROOT.$dir['url'].'/'.$appId;
702 702
 		}
703 703
 		return false;
704 704
 	}
@@ -711,7 +711,7 @@  discard block
 block discarded – undo
711 711
 	 * @return string
712 712
 	 */
713 713
 	public static function getAppVersion($appId, $useCache = true) {
714
-		if($useCache && isset(self::$appVersion[$appId])) {
714
+		if ($useCache && isset(self::$appVersion[$appId])) {
715 715
 			return self::$appVersion[$appId];
716 716
 		}
717 717
 
@@ -727,7 +727,7 @@  discard block
 block discarded – undo
727 727
 	 * @return string
728 728
 	 */
729 729
 	public static function getAppVersionByPath($path) {
730
-		$infoFile = $path . '/appinfo/info.xml';
730
+		$infoFile = $path.'/appinfo/info.xml';
731 731
 		$appData = self::getAppInfo($infoFile, true);
732 732
 		return isset($appData['version']) ? $appData['version'] : '';
733 733
 	}
@@ -750,10 +750,10 @@  discard block
 block discarded – undo
750 750
 				return self::$appInfo[$appId];
751 751
 			}
752 752
 			$appPath = self::getAppPath($appId);
753
-			if($appPath === false) {
753
+			if ($appPath === false) {
754 754
 				return null;
755 755
 			}
756
-			$file = $appPath . '/appinfo/info.xml';
756
+			$file = $appPath.'/appinfo/info.xml';
757 757
 		}
758 758
 
759 759
 		$parser = new InfoParser(\OC::$server->getMemCacheFactory()->create('core.appinfo'));
@@ -762,9 +762,9 @@  discard block
 block discarded – undo
762 762
 		if (is_array($data)) {
763 763
 			$data = OC_App::parseAppInfo($data, $lang);
764 764
 		}
765
-		if(isset($data['ocsid'])) {
765
+		if (isset($data['ocsid'])) {
766 766
 			$storedId = \OC::$server->getConfig()->getAppValue($appId, 'ocsid');
767
-			if($storedId !== '' && $storedId !== $data['ocsid']) {
767
+			if ($storedId !== '' && $storedId !== $data['ocsid']) {
768 768
 				$data['ocsid'] = $storedId;
769 769
 			}
770 770
 		}
@@ -860,7 +860,7 @@  discard block
 block discarded – undo
860 860
 	 * @param string $page
861 861
 	 */
862 862
 	public static function registerAdmin($app, $page) {
863
-		self::$adminForms[] = $app . '/' . $page . '.php';
863
+		self::$adminForms[] = $app.'/'.$page.'.php';
864 864
 	}
865 865
 
866 866
 	/**
@@ -869,7 +869,7 @@  discard block
 block discarded – undo
869 869
 	 * @param string $page
870 870
 	 */
871 871
 	public static function registerPersonal($app, $page) {
872
-		self::$personalForms[] = $app . '/' . $page . '.php';
872
+		self::$personalForms[] = $app.'/'.$page.'.php';
873 873
 	}
874 874
 
875 875
 	/**
@@ -898,7 +898,7 @@  discard block
 block discarded – undo
898 898
 
899 899
 		foreach (OC::$APPSROOTS as $apps_dir) {
900 900
 			if (!is_readable($apps_dir['path'])) {
901
-				\OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN);
901
+				\OCP\Util::writeLog('core', 'unable to read app folder : '.$apps_dir['path'], \OCP\Util::WARN);
902 902
 				continue;
903 903
 			}
904 904
 			$dh = opendir($apps_dir['path']);
@@ -906,7 +906,7 @@  discard block
 block discarded – undo
906 906
 			if (is_resource($dh)) {
907 907
 				while (($file = readdir($dh)) !== false) {
908 908
 
909
-					if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) {
909
+					if ($file[0] != '.' and is_dir($apps_dir['path'].'/'.$file) and is_file($apps_dir['path'].'/'.$file.'/appinfo/info.xml')) {
910 910
 
911 911
 						$apps[] = $file;
912 912
 					}
@@ -936,12 +936,12 @@  discard block
 block discarded – undo
936 936
 
937 937
 				$info = OC_App::getAppInfo($app, false, $langCode);
938 938
 				if (!is_array($info)) {
939
-					\OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR);
939
+					\OCP\Util::writeLog('core', 'Could not read app info file for app "'.$app.'"', \OCP\Util::ERROR);
940 940
 					continue;
941 941
 				}
942 942
 
943 943
 				if (!isset($info['name'])) {
944
-					\OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR);
944
+					\OCP\Util::writeLog('core', 'App id "'.$app.'" has no name in appinfo', \OCP\Util::ERROR);
945 945
 					continue;
946 946
 				}
947 947
 
@@ -968,13 +968,13 @@  discard block
 block discarded – undo
968 968
 				}
969 969
 
970 970
 				$appPath = self::getAppPath($app);
971
-				if($appPath !== false) {
972
-					$appIcon = $appPath . '/img/' . $app . '.svg';
971
+				if ($appPath !== false) {
972
+					$appIcon = $appPath.'/img/'.$app.'.svg';
973 973
 					if (file_exists($appIcon)) {
974
-						$info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, $app . '.svg');
974
+						$info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, $app.'.svg');
975 975
 						$info['previewAsIcon'] = true;
976 976
 					} else {
977
-						$appIcon = $appPath . '/img/app.svg';
977
+						$appIcon = $appPath.'/img/app.svg';
978 978
 						if (file_exists($appIcon)) {
979 979
 							$info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, 'app.svg');
980 980
 							$info['previewAsIcon'] = true;
@@ -1008,9 +1008,9 @@  discard block
 block discarded – undo
1008 1008
 	 * @return string|false
1009 1009
 	 */
1010 1010
 	public static function getInternalAppIdByOcs($ocsID) {
1011
-		if(is_numeric($ocsID)) {
1011
+		if (is_numeric($ocsID)) {
1012 1012
 			$idArray = \OC::$server->getAppConfig()->getValues(false, 'ocsid');
1013
-			if(array_search($ocsID, $idArray)) {
1013
+			if (array_search($ocsID, $idArray)) {
1014 1014
 				return array_search($ocsID, $idArray);
1015 1015
 			}
1016 1016
 		}
@@ -1114,7 +1114,7 @@  discard block
 block discarded – undo
1114 1114
 	public static function getAppVersions() {
1115 1115
 		static $versions;
1116 1116
 
1117
-		if(!$versions) {
1117
+		if (!$versions) {
1118 1118
 			$appConfig = \OC::$server->getAppConfig();
1119 1119
 			$versions = $appConfig->getValues(false, 'installed_version');
1120 1120
 		}
@@ -1136,7 +1136,7 @@  discard block
 block discarded – undo
1136 1136
 		if ($app !== false) {
1137 1137
 			// check if the app is compatible with this version of ownCloud
1138 1138
 			$info = self::getAppInfo($app);
1139
-			if(!is_array($info)) {
1139
+			if (!is_array($info)) {
1140 1140
 				throw new \Exception(
1141 1141
 					$l->t('App "%s" cannot be installed because appinfo file cannot be read.',
1142 1142
 						[$info['name']]
@@ -1161,7 +1161,7 @@  discard block
 block discarded – undo
1161 1161
 				$config->setAppValue($app, 'ocsid', $appData['id']);
1162 1162
 			}
1163 1163
 
1164
-			if(isset($info['settings']) && is_array($info['settings'])) {
1164
+			if (isset($info['settings']) && is_array($info['settings'])) {
1165 1165
 				$appPath = self::getAppPath($app);
1166 1166
 				self::registerAutoloading($app, $appPath);
1167 1167
 				\OC::$server->getSettingsManager()->setupSettings($info['settings']);
@@ -1169,7 +1169,7 @@  discard block
 block discarded – undo
1169 1169
 
1170 1170
 			\OC_Hook::emit('OC_App', 'post_enable', array('app' => $app));
1171 1171
 		} else {
1172
-			if(empty($appName) ) {
1172
+			if (empty($appName)) {
1173 1173
 				throw new \Exception($l->t("No app name specified"));
1174 1174
 			} else {
1175 1175
 				throw new \Exception($l->t("App '%s' could not be installed!", $appName));
@@ -1187,24 +1187,24 @@  discard block
 block discarded – undo
1187 1187
 	 */
1188 1188
 	public static function updateApp($appId) {
1189 1189
 		$appPath = self::getAppPath($appId);
1190
-		if($appPath === false) {
1190
+		if ($appPath === false) {
1191 1191
 			return false;
1192 1192
 		}
1193 1193
 		$appData = self::getAppInfo($appId);
1194 1194
 		self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']);
1195
-		if (file_exists($appPath . '/appinfo/database.xml')) {
1196
-			OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml');
1195
+		if (file_exists($appPath.'/appinfo/database.xml')) {
1196
+			OC_DB::updateDbFromStructure($appPath.'/appinfo/database.xml');
1197 1197
 		}
1198 1198
 		self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']);
1199 1199
 		self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']);
1200 1200
 		unset(self::$appVersion[$appId]);
1201 1201
 		// run upgrade code
1202
-		if (file_exists($appPath . '/appinfo/update.php')) {
1202
+		if (file_exists($appPath.'/appinfo/update.php')) {
1203 1203
 			self::loadApp($appId);
1204
-			include $appPath . '/appinfo/update.php';
1204
+			include $appPath.'/appinfo/update.php';
1205 1205
 		}
1206 1206
 		self::setupBackgroundJobs($appData['background-jobs']);
1207
-		if(isset($appData['settings']) && is_array($appData['settings'])) {
1207
+		if (isset($appData['settings']) && is_array($appData['settings'])) {
1208 1208
 			$appPath = self::getAppPath($appId);
1209 1209
 			self::registerAutoloading($appId, $appPath);
1210 1210
 			\OC::$server->getSettingsManager()->setupSettings($appData['settings']);
@@ -1213,14 +1213,14 @@  discard block
 block discarded – undo
1213 1213
 		//set remote/public handlers
1214 1214
 		if (array_key_exists('ocsid', $appData)) {
1215 1215
 			\OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']);
1216
-		} elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) {
1216
+		} elseif (\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) {
1217 1217
 			\OC::$server->getConfig()->deleteAppValue($appId, 'ocsid');
1218 1218
 		}
1219 1219
 		foreach ($appData['remote'] as $name => $path) {
1220
-			\OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path);
1220
+			\OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $appId.'/'.$path);
1221 1221
 		}
1222 1222
 		foreach ($appData['public'] as $name => $path) {
1223
-			\OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path);
1223
+			\OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $appId.'/'.$path);
1224 1224
 		}
1225 1225
 
1226 1226
 		self::setAppTypes($appId);
@@ -1290,17 +1290,17 @@  discard block
 block discarded – undo
1290 1290
 	public static function getStorage($appId) {
1291 1291
 		if (OC_App::isEnabled($appId)) { //sanity check
1292 1292
 			if (\OC::$server->getUserSession()->isLoggedIn()) {
1293
-				$view = new \OC\Files\View('/' . OC_User::getUser());
1293
+				$view = new \OC\Files\View('/'.OC_User::getUser());
1294 1294
 				if (!$view->file_exists($appId)) {
1295 1295
 					$view->mkdir($appId);
1296 1296
 				}
1297
-				return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId);
1297
+				return new \OC\Files\View('/'.OC_User::getUser().'/'.$appId);
1298 1298
 			} else {
1299
-				\OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR);
1299
+				\OCP\Util::writeLog('core', 'Can\'t get app storage, app '.$appId.', user not logged in', \OCP\Util::ERROR);
1300 1300
 				return false;
1301 1301
 			}
1302 1302
 		} else {
1303
-			\OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR);
1303
+			\OCP\Util::writeLog('core', 'Can\'t get app storage, app '.$appId.' not enabled', \OCP\Util::ERROR);
1304 1304
 			return false;
1305 1305
 		}
1306 1306
 	}
@@ -1332,9 +1332,9 @@  discard block
 block discarded – undo
1332 1332
 
1333 1333
 				if ($attributeLang === $similarLang) {
1334 1334
 					$similarLangFallback = $option['@value'];
1335
-				} else if (strpos($attributeLang, $similarLang . '_') === 0) {
1335
+				} else if (strpos($attributeLang, $similarLang.'_') === 0) {
1336 1336
 					if ($similarLangFallback === false) {
1337
-						$similarLangFallback =  $option['@value'];
1337
+						$similarLangFallback = $option['@value'];
1338 1338
 					}
1339 1339
 				}
1340 1340
 			} else {
@@ -1369,7 +1369,7 @@  discard block
 block discarded – undo
1369 1369
 			$data['description'] = trim(self::findBestL10NOption($data['description'], $lang));
1370 1370
 		} else if (isset($data['description']) && is_string($data['description'])) {
1371 1371
 			$data['description'] = trim($data['description']);
1372
-		} else  {
1372
+		} else {
1373 1373
 			$data['description'] = '';
1374 1374
 		}
1375 1375
 
Please login to merge, or discard this patch.