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