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