Completed
Pull Request — master (#8095)
by Julius
17:43
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.
core/routes.php 1 patch
Indentation   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -36,44 +36,44 @@  discard block
 block discarded – undo
36 36
 
37 37
 $application = new Application();
38 38
 $application->registerRoutes($this, [
39
-	'routes' => [
40
-		['name' => 'lost#email', 'url' => '/lostpassword/email', 'verb' => 'POST'],
41
-		['name' => 'lost#resetform', 'url' => '/lostpassword/reset/form/{token}/{userId}', 'verb' => 'GET'],
42
-		['name' => 'lost#setPassword', 'url' => '/lostpassword/set/{token}/{userId}', 'verb' => 'POST'],
43
-		['name' => 'user#getDisplayNames', 'url' => '/displaynames', 'verb' => 'POST'],
44
-		['name' => 'avatar#getAvatar', 'url' => '/avatar/{userId}/{size}', 'verb' => 'GET'],
45
-		['name' => 'avatar#deleteAvatar', 'url' => '/avatar/', 'verb' => 'DELETE'],
46
-		['name' => 'avatar#postCroppedAvatar', 'url' => '/avatar/cropped', 'verb' => 'POST'],
47
-		['name' => 'avatar#getTmpAvatar', 'url' => '/avatar/tmp', 'verb' => 'GET'],
48
-		['name' => 'avatar#postAvatar', 'url' => '/avatar/', 'verb' => 'POST'],
49
-		['name' => 'login#tryLogin', 'url' => '/login', 'verb' => 'POST'],
50
-		['name' => 'login#confirmPassword', 'url' => '/login/confirm', 'verb' => 'POST'],
51
-		['name' => 'login#showLoginForm', 'url' => '/login', 'verb' => 'GET'],
52
-		['name' => 'login#logout', 'url' => '/logout', 'verb' => 'GET'],
53
-		['name' => 'ClientFlowLogin#showAuthPickerPage', 'url' => '/login/flow', 'verb' => 'GET'],
54
-		['name' => 'ClientFlowLogin#redirectPage', 'url' => '/login/flow/redirect', 'verb' => 'GET'],
55
-		['name' => 'ClientFlowLogin#generateAppPassword', 'url' => '/login/flow', 'verb' => 'POST'],
56
-		['name' => 'TwoFactorChallenge#selectChallenge', 'url' => '/login/selectchallenge', 'verb' => 'GET'],
57
-		['name' => 'TwoFactorChallenge#showChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'GET'],
58
-		['name' => 'TwoFactorChallenge#solveChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'POST'],
59
-		['name' => 'OCJS#getConfig', 'url' => '/core/js/oc.js', 'verb' => 'GET'],
60
-		['name' => 'Preview#getPreviewByFileId', 'url' => '/core/preview', 'verb' => 'GET'],
61
-		['name' => 'Preview#getPreview', 'url' => '/core/preview.png', 'verb' => 'GET'],
62
-		['name' => 'Css#getCss', 'url' => '/css/{appName}/{fileName}', 'verb' => 'GET'],
63
-		['name' => 'Js#getJs', 'url' => '/js/{appName}/{fileName}', 'verb' => 'GET'],
64
-		['name' => 'contactsMenu#index', 'url' => '/contactsmenu/contacts', 'verb' => 'POST'],
65
-		['name' => 'contactsMenu#findOne', 'url' => '/contactsmenu/findOne', 'verb' => 'POST'],
66
-		['name' => 'AutoComplete#get', 'url' => 'autocomplete/get', 'verb' => 'GET'],
67
-		['name' => 'WalledGarden#get', 'url' => '/204', 'verb' => 'GET'],
68
-	],
69
-	'ocs' => [
70
-		['root' => '/cloud', 'name' => 'OCS#getCapabilities', 'url' => '/capabilities', 'verb' => 'GET'],
71
-		['root' => '', 'name' => 'OCS#getConfig', 'url' => '/config', 'verb' => 'GET'],
72
-		['root' => '/person', 'name' => 'OCS#personCheck', 'url' => '/check', 'verb' => 'POST'],
73
-		['root' => '/identityproof', 'name' => 'OCS#getIdentityProof', 'url' => '/key/{cloudId}', 'verb' => 'GET'],
74
-		['root' => '/core', 'name' => 'Navigation#getAppsNavigation', 'url' => '/navigation/apps', 'verb' => 'GET'],
75
-		['root' => '/core', 'name' => 'Navigation#getSettingsNavigation', 'url' => '/navigation/settings', 'verb' => 'GET'],
76
-	],
39
+    'routes' => [
40
+        ['name' => 'lost#email', 'url' => '/lostpassword/email', 'verb' => 'POST'],
41
+        ['name' => 'lost#resetform', 'url' => '/lostpassword/reset/form/{token}/{userId}', 'verb' => 'GET'],
42
+        ['name' => 'lost#setPassword', 'url' => '/lostpassword/set/{token}/{userId}', 'verb' => 'POST'],
43
+        ['name' => 'user#getDisplayNames', 'url' => '/displaynames', 'verb' => 'POST'],
44
+        ['name' => 'avatar#getAvatar', 'url' => '/avatar/{userId}/{size}', 'verb' => 'GET'],
45
+        ['name' => 'avatar#deleteAvatar', 'url' => '/avatar/', 'verb' => 'DELETE'],
46
+        ['name' => 'avatar#postCroppedAvatar', 'url' => '/avatar/cropped', 'verb' => 'POST'],
47
+        ['name' => 'avatar#getTmpAvatar', 'url' => '/avatar/tmp', 'verb' => 'GET'],
48
+        ['name' => 'avatar#postAvatar', 'url' => '/avatar/', 'verb' => 'POST'],
49
+        ['name' => 'login#tryLogin', 'url' => '/login', 'verb' => 'POST'],
50
+        ['name' => 'login#confirmPassword', 'url' => '/login/confirm', 'verb' => 'POST'],
51
+        ['name' => 'login#showLoginForm', 'url' => '/login', 'verb' => 'GET'],
52
+        ['name' => 'login#logout', 'url' => '/logout', 'verb' => 'GET'],
53
+        ['name' => 'ClientFlowLogin#showAuthPickerPage', 'url' => '/login/flow', 'verb' => 'GET'],
54
+        ['name' => 'ClientFlowLogin#redirectPage', 'url' => '/login/flow/redirect', 'verb' => 'GET'],
55
+        ['name' => 'ClientFlowLogin#generateAppPassword', 'url' => '/login/flow', 'verb' => 'POST'],
56
+        ['name' => 'TwoFactorChallenge#selectChallenge', 'url' => '/login/selectchallenge', 'verb' => 'GET'],
57
+        ['name' => 'TwoFactorChallenge#showChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'GET'],
58
+        ['name' => 'TwoFactorChallenge#solveChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'POST'],
59
+        ['name' => 'OCJS#getConfig', 'url' => '/core/js/oc.js', 'verb' => 'GET'],
60
+        ['name' => 'Preview#getPreviewByFileId', 'url' => '/core/preview', 'verb' => 'GET'],
61
+        ['name' => 'Preview#getPreview', 'url' => '/core/preview.png', 'verb' => 'GET'],
62
+        ['name' => 'Css#getCss', 'url' => '/css/{appName}/{fileName}', 'verb' => 'GET'],
63
+        ['name' => 'Js#getJs', 'url' => '/js/{appName}/{fileName}', 'verb' => 'GET'],
64
+        ['name' => 'contactsMenu#index', 'url' => '/contactsmenu/contacts', 'verb' => 'POST'],
65
+        ['name' => 'contactsMenu#findOne', 'url' => '/contactsmenu/findOne', 'verb' => 'POST'],
66
+        ['name' => 'AutoComplete#get', 'url' => 'autocomplete/get', 'verb' => 'GET'],
67
+        ['name' => 'WalledGarden#get', 'url' => '/204', 'verb' => 'GET'],
68
+    ],
69
+    'ocs' => [
70
+        ['root' => '/cloud', 'name' => 'OCS#getCapabilities', 'url' => '/capabilities', 'verb' => 'GET'],
71
+        ['root' => '', 'name' => 'OCS#getConfig', 'url' => '/config', 'verb' => 'GET'],
72
+        ['root' => '/person', 'name' => 'OCS#personCheck', 'url' => '/check', 'verb' => 'POST'],
73
+        ['root' => '/identityproof', 'name' => 'OCS#getIdentityProof', 'url' => '/key/{cloudId}', 'verb' => 'GET'],
74
+        ['root' => '/core', 'name' => 'Navigation#getAppsNavigation', 'url' => '/navigation/apps', 'verb' => 'GET'],
75
+        ['root' => '/core', 'name' => 'Navigation#getSettingsNavigation', 'url' => '/navigation/settings', 'verb' => 'GET'],
76
+    ],
77 77
 ]);
78 78
 
79 79
 // Post installation check
@@ -82,15 +82,15 @@  discard block
 block discarded – undo
82 82
 // Core ajax actions
83 83
 // Search
84 84
 $this->create('search_ajax_search', '/core/search')
85
-	->actionInclude('core/search/ajax/search.php');
85
+    ->actionInclude('core/search/ajax/search.php');
86 86
 // Routing
87 87
 $this->create('core_ajax_update', '/core/ajax/update.php')
88
-	->actionInclude('core/ajax/update.php');
88
+    ->actionInclude('core/ajax/update.php');
89 89
 
90 90
 // File routes
91 91
 $this->create('files.viewcontroller.showFile', '/f/{fileid}')->action(function($urlParams) {
92
-	$app = new \OCA\Files\AppInfo\Application($urlParams);
93
-	$app->dispatch('ViewController', 'index');
92
+    $app = new \OCA\Files\AppInfo\Application($urlParams);
93
+    $app->dispatch('ViewController', 'index');
94 94
 });
95 95
 
96 96
 // Call routes
@@ -99,57 +99,57 @@  discard block
 block discarded – undo
99 99
  * @suppress PhanUndeclaredClassMethod
100 100
  */
101 101
 $this->create('spreed.pagecontroller.showCall', '/call/{token}')->action(function($urlParams) {
102
-	if (class_exists(\OCA\Spreed\AppInfo\Application::class, false)) {
103
-		$app = new \OCA\Spreed\AppInfo\Application($urlParams);
104
-		$app->dispatch('PageController', 'index');
105
-	} else {
106
-		throw new \OC\HintException('App spreed is not enabled');
107
-	}
102
+    if (class_exists(\OCA\Spreed\AppInfo\Application::class, false)) {
103
+        $app = new \OCA\Spreed\AppInfo\Application($urlParams);
104
+        $app->dispatch('PageController', 'index');
105
+    } else {
106
+        throw new \OC\HintException('App spreed is not enabled');
107
+    }
108 108
 });
109 109
 
110 110
 // Sharing routes
111 111
 $this->create('files_sharing.sharecontroller.showShare', '/s/{token}')->action(function($urlParams) {
112
-	if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) {
113
-		$app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
114
-		$app->dispatch('ShareController', 'showShare');
115
-	} else {
116
-		throw new \OC\HintException('App file sharing is not enabled');
117
-	}
112
+    if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) {
113
+        $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
114
+        $app->dispatch('ShareController', 'showShare');
115
+    } else {
116
+        throw new \OC\HintException('App file sharing is not enabled');
117
+    }
118 118
 });
119 119
 $this->create('files_sharing.sharecontroller.authenticate', '/s/{token}/authenticate')->post()->action(function($urlParams) {
120
-	if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) {
121
-		$app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
122
-		$app->dispatch('ShareController', 'authenticate');
123
-	} else {
124
-		throw new \OC\HintException('App file sharing is not enabled');
125
-	}
120
+    if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) {
121
+        $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
122
+        $app->dispatch('ShareController', 'authenticate');
123
+    } else {
124
+        throw new \OC\HintException('App file sharing is not enabled');
125
+    }
126 126
 });
127 127
 $this->create('files_sharing.sharecontroller.showAuthenticate', '/s/{token}/authenticate')->get()->action(function($urlParams) {
128
-	if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) {
129
-		$app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
130
-		$app->dispatch('ShareController', 'showAuthenticate');
131
-	} else {
132
-		throw new \OC\HintException('App file sharing is not enabled');
133
-	}
128
+    if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) {
129
+        $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
130
+        $app->dispatch('ShareController', 'showAuthenticate');
131
+    } else {
132
+        throw new \OC\HintException('App file sharing is not enabled');
133
+    }
134 134
 });
135 135
 $this->create('files_sharing.sharecontroller.downloadShare', '/s/{token}/download')->get()->action(function($urlParams) {
136
-	if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) {
137
-		$app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
138
-		$app->dispatch('ShareController', 'downloadShare');
139
-	} else {
140
-		throw new \OC\HintException('App file sharing is not enabled');
141
-	}
136
+    if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) {
137
+        $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
138
+        $app->dispatch('ShareController', 'downloadShare');
139
+    } else {
140
+        throw new \OC\HintException('App file sharing is not enabled');
141
+    }
142 142
 });
143 143
 $this->create('files_sharing.publicpreview.directLink', '/s/{token}/preview')->get()->action(function($urlParams) {
144
-	if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) {
145
-		$app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
146
-		$app->dispatch('PublicPreviewController', 'directLink');
147
-	} else {
148
-		throw new \OC\HintException('App file sharing is not enabled');
149
-	}
144
+    if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) {
145
+        $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
146
+        $app->dispatch('PublicPreviewController', 'directLink');
147
+    } else {
148
+        throw new \OC\HintException('App file sharing is not enabled');
149
+    }
150 150
 });
151 151
 
152 152
 // used for heartbeat
153 153
 $this->create('heartbeat', '/heartbeat')->action(function(){
154
-	// do nothing
154
+    // do nothing
155 155
 });
Please login to merge, or discard this patch.
lib/private/legacy/app.php 1 patch
Indentation   +1068 added lines, -1068 removed lines patch added patch discarded remove patch
@@ -62,1072 +62,1072 @@
 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
-	 * @deprecated 14.0.0 use \OC::$server->getNavigationManager()->getAll()
590
-	 *
591
-	 * This function returns an array containing all entries added. The
592
-	 * entries are sorted by the key 'order' ascending. Additional to the keys
593
-	 * given for each app the following keys exist:
594
-	 *   - active: boolean, signals if the user is on this navigation entry
595
-	 */
596
-	public static function getNavigation() {
597
-		return OC::$server->getNavigationManager()->getAll();
598
-	}
599
-
600
-	/**
601
-	 * Returns the Settings Navigation
602
-	 *
603
-	 * @return string[]
604
-	 * @deprecated 14.0.0 use \OC::$server->getNavigationManager()->getAll('settings')
605
-	 *
606
-	 * This function returns an array containing all settings pages added. The
607
-	 * entries are sorted by the key 'order' ascending.
608
-	 */
609
-	public static function getSettingsNavigation() {
610
-		return OC::$server->getNavigationManager()->getAll('settings');
611
-	}
612
-
613
-	/**
614
-	 * get the id of loaded app
615
-	 *
616
-	 * @return string
617
-	 */
618
-	public static function getCurrentApp() {
619
-		$request = \OC::$server->getRequest();
620
-		$script = substr($request->getScriptName(), strlen(OC::$WEBROOT) + 1);
621
-		$topFolder = substr($script, 0, strpos($script, '/') ?: 0);
622
-		if (empty($topFolder)) {
623
-			$path_info = $request->getPathInfo();
624
-			if ($path_info) {
625
-				$topFolder = substr($path_info, 1, strpos($path_info, '/', 1) - 1);
626
-			}
627
-		}
628
-		if ($topFolder == 'apps') {
629
-			$length = strlen($topFolder);
630
-			return substr($script, $length + 1, strpos($script, '/', $length + 1) - $length - 1);
631
-		} else {
632
-			return $topFolder;
633
-		}
634
-	}
635
-
636
-	/**
637
-	 * @param string $type
638
-	 * @return array
639
-	 */
640
-	public static function getForms($type) {
641
-		$forms = array();
642
-		switch ($type) {
643
-			case 'admin':
644
-				$source = self::$adminForms;
645
-				break;
646
-			case 'personal':
647
-				$source = self::$personalForms;
648
-				break;
649
-			default:
650
-				return array();
651
-		}
652
-		foreach ($source as $form) {
653
-			$forms[] = include $form;
654
-		}
655
-		return $forms;
656
-	}
657
-
658
-	/**
659
-	 * register an admin form to be shown
660
-	 *
661
-	 * @param string $app
662
-	 * @param string $page
663
-	 */
664
-	public static function registerAdmin($app, $page) {
665
-		self::$adminForms[] = $app . '/' . $page . '.php';
666
-	}
667
-
668
-	/**
669
-	 * register a personal form to be shown
670
-	 * @param string $app
671
-	 * @param string $page
672
-	 */
673
-	public static function registerPersonal($app, $page) {
674
-		self::$personalForms[] = $app . '/' . $page . '.php';
675
-	}
676
-
677
-	/**
678
-	 * @param array $entry
679
-	 */
680
-	public static function registerLogIn(array $entry) {
681
-		self::$altLogin[] = $entry;
682
-	}
683
-
684
-	/**
685
-	 * @return array
686
-	 */
687
-	public static function getAlternativeLogIns() {
688
-		return self::$altLogin;
689
-	}
690
-
691
-	/**
692
-	 * get a list of all apps in the apps folder
693
-	 *
694
-	 * @return array an array of app names (string IDs)
695
-	 * @todo: change the name of this method to getInstalledApps, which is more accurate
696
-	 */
697
-	public static function getAllApps() {
698
-
699
-		$apps = array();
700
-
701
-		foreach (OC::$APPSROOTS as $apps_dir) {
702
-			if (!is_readable($apps_dir['path'])) {
703
-				\OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN);
704
-				continue;
705
-			}
706
-			$dh = opendir($apps_dir['path']);
707
-
708
-			if (is_resource($dh)) {
709
-				while (($file = readdir($dh)) !== false) {
710
-
711
-					if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) {
712
-
713
-						$apps[] = $file;
714
-					}
715
-				}
716
-			}
717
-		}
718
-
719
-		$apps = array_unique($apps);
720
-
721
-		return $apps;
722
-	}
723
-
724
-	/**
725
-	 * List all apps, this is used in apps.php
726
-	 *
727
-	 * @return array
728
-	 */
729
-	public function listAllApps() {
730
-		$installedApps = OC_App::getAllApps();
731
-
732
-		$appManager = \OC::$server->getAppManager();
733
-		//we don't want to show configuration for these
734
-		$blacklist = $appManager->getAlwaysEnabledApps();
735
-		$appList = array();
736
-		$langCode = \OC::$server->getL10N('core')->getLanguageCode();
737
-		$urlGenerator = \OC::$server->getURLGenerator();
738
-
739
-		foreach ($installedApps as $app) {
740
-			if (array_search($app, $blacklist) === false) {
741
-
742
-				$info = OC_App::getAppInfo($app, false, $langCode);
743
-				if (!is_array($info)) {
744
-					\OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR);
745
-					continue;
746
-				}
747
-
748
-				if (!isset($info['name'])) {
749
-					\OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR);
750
-					continue;
751
-				}
752
-
753
-				$enabled = \OC::$server->getConfig()->getAppValue($app, 'enabled', 'no');
754
-				$info['groups'] = null;
755
-				if ($enabled === 'yes') {
756
-					$active = true;
757
-				} else if ($enabled === 'no') {
758
-					$active = false;
759
-				} else {
760
-					$active = true;
761
-					$info['groups'] = $enabled;
762
-				}
763
-
764
-				$info['active'] = $active;
765
-
766
-				if ($appManager->isShipped($app)) {
767
-					$info['internal'] = true;
768
-					$info['level'] = self::officialApp;
769
-					$info['removable'] = false;
770
-				} else {
771
-					$info['internal'] = false;
772
-					$info['removable'] = true;
773
-				}
774
-
775
-				$appPath = self::getAppPath($app);
776
-				if($appPath !== false) {
777
-					$appIcon = $appPath . '/img/' . $app . '.svg';
778
-					if (file_exists($appIcon)) {
779
-						$info['preview'] = $urlGenerator->imagePath($app, $app . '.svg');
780
-						$info['previewAsIcon'] = true;
781
-					} else {
782
-						$appIcon = $appPath . '/img/app.svg';
783
-						if (file_exists($appIcon)) {
784
-							$info['preview'] = $urlGenerator->imagePath($app, 'app.svg');
785
-							$info['previewAsIcon'] = true;
786
-						}
787
-					}
788
-				}
789
-				// fix documentation
790
-				if (isset($info['documentation']) && is_array($info['documentation'])) {
791
-					foreach ($info['documentation'] as $key => $url) {
792
-						// If it is not an absolute URL we assume it is a key
793
-						// i.e. admin-ldap will get converted to go.php?to=admin-ldap
794
-						if (stripos($url, 'https://') !== 0 && stripos($url, 'http://') !== 0) {
795
-							$url = $urlGenerator->linkToDocs($url);
796
-						}
797
-
798
-						$info['documentation'][$key] = $url;
799
-					}
800
-				}
801
-
802
-				$info['version'] = OC_App::getAppVersion($app);
803
-				$appList[] = $info;
804
-			}
805
-		}
806
-
807
-		return $appList;
808
-	}
809
-
810
-	public static function shouldUpgrade($app) {
811
-		$versions = self::getAppVersions();
812
-		$currentVersion = OC_App::getAppVersion($app);
813
-		if ($currentVersion && isset($versions[$app])) {
814
-			$installedVersion = $versions[$app];
815
-			if (!version_compare($currentVersion, $installedVersion, '=')) {
816
-				return true;
817
-			}
818
-		}
819
-		return false;
820
-	}
821
-
822
-	/**
823
-	 * Adjust the number of version parts of $version1 to match
824
-	 * the number of version parts of $version2.
825
-	 *
826
-	 * @param string $version1 version to adjust
827
-	 * @param string $version2 version to take the number of parts from
828
-	 * @return string shortened $version1
829
-	 */
830
-	private static function adjustVersionParts($version1, $version2) {
831
-		$version1 = explode('.', $version1);
832
-		$version2 = explode('.', $version2);
833
-		// reduce $version1 to match the number of parts in $version2
834
-		while (count($version1) > count($version2)) {
835
-			array_pop($version1);
836
-		}
837
-		// if $version1 does not have enough parts, add some
838
-		while (count($version1) < count($version2)) {
839
-			$version1[] = '0';
840
-		}
841
-		return implode('.', $version1);
842
-	}
843
-
844
-	/**
845
-	 * Check whether the current ownCloud version matches the given
846
-	 * application's version requirements.
847
-	 *
848
-	 * The comparison is made based on the number of parts that the
849
-	 * app info version has. For example for ownCloud 6.0.3 if the
850
-	 * app info version is expecting version 6.0, the comparison is
851
-	 * made on the first two parts of the ownCloud version.
852
-	 * This means that it's possible to specify "requiremin" => 6
853
-	 * and "requiremax" => 6 and it will still match ownCloud 6.0.3.
854
-	 *
855
-	 * @param string $ocVersion ownCloud version to check against
856
-	 * @param array $appInfo app info (from xml)
857
-	 *
858
-	 * @return boolean true if compatible, otherwise false
859
-	 */
860
-	public static function isAppCompatible($ocVersion, $appInfo) {
861
-		$requireMin = '';
862
-		$requireMax = '';
863
-		if (isset($appInfo['dependencies']['nextcloud']['@attributes']['min-version'])) {
864
-			$requireMin = $appInfo['dependencies']['nextcloud']['@attributes']['min-version'];
865
-		} elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['min-version'])) {
866
-			$requireMin = $appInfo['dependencies']['owncloud']['@attributes']['min-version'];
867
-		} else if (isset($appInfo['requiremin'])) {
868
-			$requireMin = $appInfo['requiremin'];
869
-		} else if (isset($appInfo['require'])) {
870
-			$requireMin = $appInfo['require'];
871
-		}
872
-
873
-		if (isset($appInfo['dependencies']['nextcloud']['@attributes']['max-version'])) {
874
-			$requireMax = $appInfo['dependencies']['nextcloud']['@attributes']['max-version'];
875
-		} elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['max-version'])) {
876
-			$requireMax = $appInfo['dependencies']['owncloud']['@attributes']['max-version'];
877
-		} else if (isset($appInfo['requiremax'])) {
878
-			$requireMax = $appInfo['requiremax'];
879
-		}
880
-
881
-		if (is_array($ocVersion)) {
882
-			$ocVersion = implode('.', $ocVersion);
883
-		}
884
-
885
-		if (!empty($requireMin)
886
-			&& version_compare(self::adjustVersionParts($ocVersion, $requireMin), $requireMin, '<')
887
-		) {
888
-
889
-			return false;
890
-		}
891
-
892
-		if (!empty($requireMax)
893
-			&& version_compare(self::adjustVersionParts($ocVersion, $requireMax), $requireMax, '>')
894
-		) {
895
-			return false;
896
-		}
897
-
898
-		return true;
899
-	}
900
-
901
-	/**
902
-	 * get the installed version of all apps
903
-	 */
904
-	public static function getAppVersions() {
905
-		static $versions;
906
-
907
-		if(!$versions) {
908
-			$appConfig = \OC::$server->getAppConfig();
909
-			$versions = $appConfig->getValues(false, 'installed_version');
910
-		}
911
-		return $versions;
912
-	}
913
-
914
-	/**
915
-	 * update the database for the app and call the update script
916
-	 *
917
-	 * @param string $appId
918
-	 * @return bool
919
-	 */
920
-	public static function updateApp($appId) {
921
-		$appPath = self::getAppPath($appId);
922
-		if($appPath === false) {
923
-			return false;
924
-		}
925
-		self::registerAutoloading($appId, $appPath);
926
-
927
-		$appData = self::getAppInfo($appId);
928
-		self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']);
929
-
930
-		if (file_exists($appPath . '/appinfo/database.xml')) {
931
-			OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml');
932
-		} else {
933
-			$ms = new MigrationService($appId, \OC::$server->getDatabaseConnection());
934
-			$ms->migrate();
935
-		}
936
-
937
-		self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']);
938
-		self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']);
939
-		// update appversion in app manager
940
-		\OC::$server->getAppManager()->getAppVersion($appId, false);
941
-
942
-		// run upgrade code
943
-		if (file_exists($appPath . '/appinfo/update.php')) {
944
-			self::loadApp($appId);
945
-			include $appPath . '/appinfo/update.php';
946
-		}
947
-		self::setupBackgroundJobs($appData['background-jobs']);
948
-
949
-		//set remote/public handlers
950
-		if (array_key_exists('ocsid', $appData)) {
951
-			\OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']);
952
-		} elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) {
953
-			\OC::$server->getConfig()->deleteAppValue($appId, 'ocsid');
954
-		}
955
-		foreach ($appData['remote'] as $name => $path) {
956
-			\OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path);
957
-		}
958
-		foreach ($appData['public'] as $name => $path) {
959
-			\OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path);
960
-		}
961
-
962
-		self::setAppTypes($appId);
963
-
964
-		$version = \OC_App::getAppVersion($appId);
965
-		\OC::$server->getConfig()->setAppValue($appId, 'installed_version', $version);
966
-
967
-		\OC::$server->getEventDispatcher()->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent(
968
-			ManagerEvent::EVENT_APP_UPDATE, $appId
969
-		));
970
-
971
-		return true;
972
-	}
973
-
974
-	/**
975
-	 * @param string $appId
976
-	 * @param string[] $steps
977
-	 * @throws \OC\NeedsUpdateException
978
-	 */
979
-	public static function executeRepairSteps($appId, array $steps) {
980
-		if (empty($steps)) {
981
-			return;
982
-		}
983
-		// load the app
984
-		self::loadApp($appId);
985
-
986
-		$dispatcher = OC::$server->getEventDispatcher();
987
-
988
-		// load the steps
989
-		$r = new Repair([], $dispatcher);
990
-		foreach ($steps as $step) {
991
-			try {
992
-				$r->addStep($step);
993
-			} catch (Exception $ex) {
994
-				$r->emit('\OC\Repair', 'error', [$ex->getMessage()]);
995
-				\OC::$server->getLogger()->logException($ex);
996
-			}
997
-		}
998
-		// run the steps
999
-		$r->run();
1000
-	}
1001
-
1002
-	public static function setupBackgroundJobs(array $jobs) {
1003
-		$queue = \OC::$server->getJobList();
1004
-		foreach ($jobs as $job) {
1005
-			$queue->add($job);
1006
-		}
1007
-	}
1008
-
1009
-	/**
1010
-	 * @param string $appId
1011
-	 * @param string[] $steps
1012
-	 */
1013
-	private static function setupLiveMigrations($appId, array $steps) {
1014
-		$queue = \OC::$server->getJobList();
1015
-		foreach ($steps as $step) {
1016
-			$queue->add('OC\Migration\BackgroundRepair', [
1017
-				'app' => $appId,
1018
-				'step' => $step]);
1019
-		}
1020
-	}
1021
-
1022
-	/**
1023
-	 * @param string $appId
1024
-	 * @return \OC\Files\View|false
1025
-	 */
1026
-	public static function getStorage($appId) {
1027
-		if (\OC::$server->getAppManager()->isEnabledForUser($appId)) { //sanity check
1028
-			if (\OC::$server->getUserSession()->isLoggedIn()) {
1029
-				$view = new \OC\Files\View('/' . OC_User::getUser());
1030
-				if (!$view->file_exists($appId)) {
1031
-					$view->mkdir($appId);
1032
-				}
1033
-				return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId);
1034
-			} else {
1035
-				\OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR);
1036
-				return false;
1037
-			}
1038
-		} else {
1039
-			\OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR);
1040
-			return false;
1041
-		}
1042
-	}
1043
-
1044
-	protected static function findBestL10NOption($options, $lang) {
1045
-		$fallback = $similarLangFallback = $englishFallback = false;
1046
-
1047
-		$lang = strtolower($lang);
1048
-		$similarLang = $lang;
1049
-		if (strpos($similarLang, '_')) {
1050
-			// For "de_DE" we want to find "de" and the other way around
1051
-			$similarLang = substr($lang, 0, strpos($lang, '_'));
1052
-		}
1053
-
1054
-		foreach ($options as $option) {
1055
-			if (is_array($option)) {
1056
-				if ($fallback === false) {
1057
-					$fallback = $option['@value'];
1058
-				}
1059
-
1060
-				if (!isset($option['@attributes']['lang'])) {
1061
-					continue;
1062
-				}
1063
-
1064
-				$attributeLang = strtolower($option['@attributes']['lang']);
1065
-				if ($attributeLang === $lang) {
1066
-					return $option['@value'];
1067
-				}
1068
-
1069
-				if ($attributeLang === $similarLang) {
1070
-					$similarLangFallback = $option['@value'];
1071
-				} else if (strpos($attributeLang, $similarLang . '_') === 0) {
1072
-					if ($similarLangFallback === false) {
1073
-						$similarLangFallback =  $option['@value'];
1074
-					}
1075
-				}
1076
-			} else {
1077
-				$englishFallback = $option;
1078
-			}
1079
-		}
1080
-
1081
-		if ($similarLangFallback !== false) {
1082
-			return $similarLangFallback;
1083
-		} else if ($englishFallback !== false) {
1084
-			return $englishFallback;
1085
-		}
1086
-		return (string) $fallback;
1087
-	}
1088
-
1089
-	/**
1090
-	 * parses the app data array and enhanced the 'description' value
1091
-	 *
1092
-	 * @param array $data the app data
1093
-	 * @param string $lang
1094
-	 * @return array improved app data
1095
-	 */
1096
-	public static function parseAppInfo(array $data, $lang = null) {
1097
-
1098
-		if ($lang && isset($data['name']) && is_array($data['name'])) {
1099
-			$data['name'] = self::findBestL10NOption($data['name'], $lang);
1100
-		}
1101
-		if ($lang && isset($data['summary']) && is_array($data['summary'])) {
1102
-			$data['summary'] = self::findBestL10NOption($data['summary'], $lang);
1103
-		}
1104
-		if ($lang && isset($data['description']) && is_array($data['description'])) {
1105
-			$data['description'] = trim(self::findBestL10NOption($data['description'], $lang));
1106
-		} else if (isset($data['description']) && is_string($data['description'])) {
1107
-			$data['description'] = trim($data['description']);
1108
-		} else  {
1109
-			$data['description'] = '';
1110
-		}
1111
-
1112
-		return $data;
1113
-	}
1114
-
1115
-	/**
1116
-	 * @param \OCP\IConfig $config
1117
-	 * @param \OCP\IL10N $l
1118
-	 * @param array $info
1119
-	 * @throws \Exception
1120
-	 */
1121
-	public static function checkAppDependencies($config, $l, $info) {
1122
-		$dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l);
1123
-		$missing = $dependencyAnalyzer->analyze($info);
1124
-		if (!empty($missing)) {
1125
-			$missingMsg = implode(PHP_EOL, $missing);
1126
-			throw new \Exception(
1127
-				$l->t('App "%s" cannot be installed because the following dependencies are not fulfilled: %s',
1128
-					[$info['name'], $missingMsg]
1129
-				)
1130
-			);
1131
-		}
1132
-	}
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
+     * @deprecated 14.0.0 use \OC::$server->getNavigationManager()->getAll()
590
+     *
591
+     * This function returns an array containing all entries added. The
592
+     * entries are sorted by the key 'order' ascending. Additional to the keys
593
+     * given for each app the following keys exist:
594
+     *   - active: boolean, signals if the user is on this navigation entry
595
+     */
596
+    public static function getNavigation() {
597
+        return OC::$server->getNavigationManager()->getAll();
598
+    }
599
+
600
+    /**
601
+     * Returns the Settings Navigation
602
+     *
603
+     * @return string[]
604
+     * @deprecated 14.0.0 use \OC::$server->getNavigationManager()->getAll('settings')
605
+     *
606
+     * This function returns an array containing all settings pages added. The
607
+     * entries are sorted by the key 'order' ascending.
608
+     */
609
+    public static function getSettingsNavigation() {
610
+        return OC::$server->getNavigationManager()->getAll('settings');
611
+    }
612
+
613
+    /**
614
+     * get the id of loaded app
615
+     *
616
+     * @return string
617
+     */
618
+    public static function getCurrentApp() {
619
+        $request = \OC::$server->getRequest();
620
+        $script = substr($request->getScriptName(), strlen(OC::$WEBROOT) + 1);
621
+        $topFolder = substr($script, 0, strpos($script, '/') ?: 0);
622
+        if (empty($topFolder)) {
623
+            $path_info = $request->getPathInfo();
624
+            if ($path_info) {
625
+                $topFolder = substr($path_info, 1, strpos($path_info, '/', 1) - 1);
626
+            }
627
+        }
628
+        if ($topFolder == 'apps') {
629
+            $length = strlen($topFolder);
630
+            return substr($script, $length + 1, strpos($script, '/', $length + 1) - $length - 1);
631
+        } else {
632
+            return $topFolder;
633
+        }
634
+    }
635
+
636
+    /**
637
+     * @param string $type
638
+     * @return array
639
+     */
640
+    public static function getForms($type) {
641
+        $forms = array();
642
+        switch ($type) {
643
+            case 'admin':
644
+                $source = self::$adminForms;
645
+                break;
646
+            case 'personal':
647
+                $source = self::$personalForms;
648
+                break;
649
+            default:
650
+                return array();
651
+        }
652
+        foreach ($source as $form) {
653
+            $forms[] = include $form;
654
+        }
655
+        return $forms;
656
+    }
657
+
658
+    /**
659
+     * register an admin form to be shown
660
+     *
661
+     * @param string $app
662
+     * @param string $page
663
+     */
664
+    public static function registerAdmin($app, $page) {
665
+        self::$adminForms[] = $app . '/' . $page . '.php';
666
+    }
667
+
668
+    /**
669
+     * register a personal form to be shown
670
+     * @param string $app
671
+     * @param string $page
672
+     */
673
+    public static function registerPersonal($app, $page) {
674
+        self::$personalForms[] = $app . '/' . $page . '.php';
675
+    }
676
+
677
+    /**
678
+     * @param array $entry
679
+     */
680
+    public static function registerLogIn(array $entry) {
681
+        self::$altLogin[] = $entry;
682
+    }
683
+
684
+    /**
685
+     * @return array
686
+     */
687
+    public static function getAlternativeLogIns() {
688
+        return self::$altLogin;
689
+    }
690
+
691
+    /**
692
+     * get a list of all apps in the apps folder
693
+     *
694
+     * @return array an array of app names (string IDs)
695
+     * @todo: change the name of this method to getInstalledApps, which is more accurate
696
+     */
697
+    public static function getAllApps() {
698
+
699
+        $apps = array();
700
+
701
+        foreach (OC::$APPSROOTS as $apps_dir) {
702
+            if (!is_readable($apps_dir['path'])) {
703
+                \OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN);
704
+                continue;
705
+            }
706
+            $dh = opendir($apps_dir['path']);
707
+
708
+            if (is_resource($dh)) {
709
+                while (($file = readdir($dh)) !== false) {
710
+
711
+                    if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) {
712
+
713
+                        $apps[] = $file;
714
+                    }
715
+                }
716
+            }
717
+        }
718
+
719
+        $apps = array_unique($apps);
720
+
721
+        return $apps;
722
+    }
723
+
724
+    /**
725
+     * List all apps, this is used in apps.php
726
+     *
727
+     * @return array
728
+     */
729
+    public function listAllApps() {
730
+        $installedApps = OC_App::getAllApps();
731
+
732
+        $appManager = \OC::$server->getAppManager();
733
+        //we don't want to show configuration for these
734
+        $blacklist = $appManager->getAlwaysEnabledApps();
735
+        $appList = array();
736
+        $langCode = \OC::$server->getL10N('core')->getLanguageCode();
737
+        $urlGenerator = \OC::$server->getURLGenerator();
738
+
739
+        foreach ($installedApps as $app) {
740
+            if (array_search($app, $blacklist) === false) {
741
+
742
+                $info = OC_App::getAppInfo($app, false, $langCode);
743
+                if (!is_array($info)) {
744
+                    \OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR);
745
+                    continue;
746
+                }
747
+
748
+                if (!isset($info['name'])) {
749
+                    \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR);
750
+                    continue;
751
+                }
752
+
753
+                $enabled = \OC::$server->getConfig()->getAppValue($app, 'enabled', 'no');
754
+                $info['groups'] = null;
755
+                if ($enabled === 'yes') {
756
+                    $active = true;
757
+                } else if ($enabled === 'no') {
758
+                    $active = false;
759
+                } else {
760
+                    $active = true;
761
+                    $info['groups'] = $enabled;
762
+                }
763
+
764
+                $info['active'] = $active;
765
+
766
+                if ($appManager->isShipped($app)) {
767
+                    $info['internal'] = true;
768
+                    $info['level'] = self::officialApp;
769
+                    $info['removable'] = false;
770
+                } else {
771
+                    $info['internal'] = false;
772
+                    $info['removable'] = true;
773
+                }
774
+
775
+                $appPath = self::getAppPath($app);
776
+                if($appPath !== false) {
777
+                    $appIcon = $appPath . '/img/' . $app . '.svg';
778
+                    if (file_exists($appIcon)) {
779
+                        $info['preview'] = $urlGenerator->imagePath($app, $app . '.svg');
780
+                        $info['previewAsIcon'] = true;
781
+                    } else {
782
+                        $appIcon = $appPath . '/img/app.svg';
783
+                        if (file_exists($appIcon)) {
784
+                            $info['preview'] = $urlGenerator->imagePath($app, 'app.svg');
785
+                            $info['previewAsIcon'] = true;
786
+                        }
787
+                    }
788
+                }
789
+                // fix documentation
790
+                if (isset($info['documentation']) && is_array($info['documentation'])) {
791
+                    foreach ($info['documentation'] as $key => $url) {
792
+                        // If it is not an absolute URL we assume it is a key
793
+                        // i.e. admin-ldap will get converted to go.php?to=admin-ldap
794
+                        if (stripos($url, 'https://') !== 0 && stripos($url, 'http://') !== 0) {
795
+                            $url = $urlGenerator->linkToDocs($url);
796
+                        }
797
+
798
+                        $info['documentation'][$key] = $url;
799
+                    }
800
+                }
801
+
802
+                $info['version'] = OC_App::getAppVersion($app);
803
+                $appList[] = $info;
804
+            }
805
+        }
806
+
807
+        return $appList;
808
+    }
809
+
810
+    public static function shouldUpgrade($app) {
811
+        $versions = self::getAppVersions();
812
+        $currentVersion = OC_App::getAppVersion($app);
813
+        if ($currentVersion && isset($versions[$app])) {
814
+            $installedVersion = $versions[$app];
815
+            if (!version_compare($currentVersion, $installedVersion, '=')) {
816
+                return true;
817
+            }
818
+        }
819
+        return false;
820
+    }
821
+
822
+    /**
823
+     * Adjust the number of version parts of $version1 to match
824
+     * the number of version parts of $version2.
825
+     *
826
+     * @param string $version1 version to adjust
827
+     * @param string $version2 version to take the number of parts from
828
+     * @return string shortened $version1
829
+     */
830
+    private static function adjustVersionParts($version1, $version2) {
831
+        $version1 = explode('.', $version1);
832
+        $version2 = explode('.', $version2);
833
+        // reduce $version1 to match the number of parts in $version2
834
+        while (count($version1) > count($version2)) {
835
+            array_pop($version1);
836
+        }
837
+        // if $version1 does not have enough parts, add some
838
+        while (count($version1) < count($version2)) {
839
+            $version1[] = '0';
840
+        }
841
+        return implode('.', $version1);
842
+    }
843
+
844
+    /**
845
+     * Check whether the current ownCloud version matches the given
846
+     * application's version requirements.
847
+     *
848
+     * The comparison is made based on the number of parts that the
849
+     * app info version has. For example for ownCloud 6.0.3 if the
850
+     * app info version is expecting version 6.0, the comparison is
851
+     * made on the first two parts of the ownCloud version.
852
+     * This means that it's possible to specify "requiremin" => 6
853
+     * and "requiremax" => 6 and it will still match ownCloud 6.0.3.
854
+     *
855
+     * @param string $ocVersion ownCloud version to check against
856
+     * @param array $appInfo app info (from xml)
857
+     *
858
+     * @return boolean true if compatible, otherwise false
859
+     */
860
+    public static function isAppCompatible($ocVersion, $appInfo) {
861
+        $requireMin = '';
862
+        $requireMax = '';
863
+        if (isset($appInfo['dependencies']['nextcloud']['@attributes']['min-version'])) {
864
+            $requireMin = $appInfo['dependencies']['nextcloud']['@attributes']['min-version'];
865
+        } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['min-version'])) {
866
+            $requireMin = $appInfo['dependencies']['owncloud']['@attributes']['min-version'];
867
+        } else if (isset($appInfo['requiremin'])) {
868
+            $requireMin = $appInfo['requiremin'];
869
+        } else if (isset($appInfo['require'])) {
870
+            $requireMin = $appInfo['require'];
871
+        }
872
+
873
+        if (isset($appInfo['dependencies']['nextcloud']['@attributes']['max-version'])) {
874
+            $requireMax = $appInfo['dependencies']['nextcloud']['@attributes']['max-version'];
875
+        } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['max-version'])) {
876
+            $requireMax = $appInfo['dependencies']['owncloud']['@attributes']['max-version'];
877
+        } else if (isset($appInfo['requiremax'])) {
878
+            $requireMax = $appInfo['requiremax'];
879
+        }
880
+
881
+        if (is_array($ocVersion)) {
882
+            $ocVersion = implode('.', $ocVersion);
883
+        }
884
+
885
+        if (!empty($requireMin)
886
+            && version_compare(self::adjustVersionParts($ocVersion, $requireMin), $requireMin, '<')
887
+        ) {
888
+
889
+            return false;
890
+        }
891
+
892
+        if (!empty($requireMax)
893
+            && version_compare(self::adjustVersionParts($ocVersion, $requireMax), $requireMax, '>')
894
+        ) {
895
+            return false;
896
+        }
897
+
898
+        return true;
899
+    }
900
+
901
+    /**
902
+     * get the installed version of all apps
903
+     */
904
+    public static function getAppVersions() {
905
+        static $versions;
906
+
907
+        if(!$versions) {
908
+            $appConfig = \OC::$server->getAppConfig();
909
+            $versions = $appConfig->getValues(false, 'installed_version');
910
+        }
911
+        return $versions;
912
+    }
913
+
914
+    /**
915
+     * update the database for the app and call the update script
916
+     *
917
+     * @param string $appId
918
+     * @return bool
919
+     */
920
+    public static function updateApp($appId) {
921
+        $appPath = self::getAppPath($appId);
922
+        if($appPath === false) {
923
+            return false;
924
+        }
925
+        self::registerAutoloading($appId, $appPath);
926
+
927
+        $appData = self::getAppInfo($appId);
928
+        self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']);
929
+
930
+        if (file_exists($appPath . '/appinfo/database.xml')) {
931
+            OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml');
932
+        } else {
933
+            $ms = new MigrationService($appId, \OC::$server->getDatabaseConnection());
934
+            $ms->migrate();
935
+        }
936
+
937
+        self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']);
938
+        self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']);
939
+        // update appversion in app manager
940
+        \OC::$server->getAppManager()->getAppVersion($appId, false);
941
+
942
+        // run upgrade code
943
+        if (file_exists($appPath . '/appinfo/update.php')) {
944
+            self::loadApp($appId);
945
+            include $appPath . '/appinfo/update.php';
946
+        }
947
+        self::setupBackgroundJobs($appData['background-jobs']);
948
+
949
+        //set remote/public handlers
950
+        if (array_key_exists('ocsid', $appData)) {
951
+            \OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']);
952
+        } elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) {
953
+            \OC::$server->getConfig()->deleteAppValue($appId, 'ocsid');
954
+        }
955
+        foreach ($appData['remote'] as $name => $path) {
956
+            \OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path);
957
+        }
958
+        foreach ($appData['public'] as $name => $path) {
959
+            \OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path);
960
+        }
961
+
962
+        self::setAppTypes($appId);
963
+
964
+        $version = \OC_App::getAppVersion($appId);
965
+        \OC::$server->getConfig()->setAppValue($appId, 'installed_version', $version);
966
+
967
+        \OC::$server->getEventDispatcher()->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent(
968
+            ManagerEvent::EVENT_APP_UPDATE, $appId
969
+        ));
970
+
971
+        return true;
972
+    }
973
+
974
+    /**
975
+     * @param string $appId
976
+     * @param string[] $steps
977
+     * @throws \OC\NeedsUpdateException
978
+     */
979
+    public static function executeRepairSteps($appId, array $steps) {
980
+        if (empty($steps)) {
981
+            return;
982
+        }
983
+        // load the app
984
+        self::loadApp($appId);
985
+
986
+        $dispatcher = OC::$server->getEventDispatcher();
987
+
988
+        // load the steps
989
+        $r = new Repair([], $dispatcher);
990
+        foreach ($steps as $step) {
991
+            try {
992
+                $r->addStep($step);
993
+            } catch (Exception $ex) {
994
+                $r->emit('\OC\Repair', 'error', [$ex->getMessage()]);
995
+                \OC::$server->getLogger()->logException($ex);
996
+            }
997
+        }
998
+        // run the steps
999
+        $r->run();
1000
+    }
1001
+
1002
+    public static function setupBackgroundJobs(array $jobs) {
1003
+        $queue = \OC::$server->getJobList();
1004
+        foreach ($jobs as $job) {
1005
+            $queue->add($job);
1006
+        }
1007
+    }
1008
+
1009
+    /**
1010
+     * @param string $appId
1011
+     * @param string[] $steps
1012
+     */
1013
+    private static function setupLiveMigrations($appId, array $steps) {
1014
+        $queue = \OC::$server->getJobList();
1015
+        foreach ($steps as $step) {
1016
+            $queue->add('OC\Migration\BackgroundRepair', [
1017
+                'app' => $appId,
1018
+                'step' => $step]);
1019
+        }
1020
+    }
1021
+
1022
+    /**
1023
+     * @param string $appId
1024
+     * @return \OC\Files\View|false
1025
+     */
1026
+    public static function getStorage($appId) {
1027
+        if (\OC::$server->getAppManager()->isEnabledForUser($appId)) { //sanity check
1028
+            if (\OC::$server->getUserSession()->isLoggedIn()) {
1029
+                $view = new \OC\Files\View('/' . OC_User::getUser());
1030
+                if (!$view->file_exists($appId)) {
1031
+                    $view->mkdir($appId);
1032
+                }
1033
+                return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId);
1034
+            } else {
1035
+                \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR);
1036
+                return false;
1037
+            }
1038
+        } else {
1039
+            \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR);
1040
+            return false;
1041
+        }
1042
+    }
1043
+
1044
+    protected static function findBestL10NOption($options, $lang) {
1045
+        $fallback = $similarLangFallback = $englishFallback = false;
1046
+
1047
+        $lang = strtolower($lang);
1048
+        $similarLang = $lang;
1049
+        if (strpos($similarLang, '_')) {
1050
+            // For "de_DE" we want to find "de" and the other way around
1051
+            $similarLang = substr($lang, 0, strpos($lang, '_'));
1052
+        }
1053
+
1054
+        foreach ($options as $option) {
1055
+            if (is_array($option)) {
1056
+                if ($fallback === false) {
1057
+                    $fallback = $option['@value'];
1058
+                }
1059
+
1060
+                if (!isset($option['@attributes']['lang'])) {
1061
+                    continue;
1062
+                }
1063
+
1064
+                $attributeLang = strtolower($option['@attributes']['lang']);
1065
+                if ($attributeLang === $lang) {
1066
+                    return $option['@value'];
1067
+                }
1068
+
1069
+                if ($attributeLang === $similarLang) {
1070
+                    $similarLangFallback = $option['@value'];
1071
+                } else if (strpos($attributeLang, $similarLang . '_') === 0) {
1072
+                    if ($similarLangFallback === false) {
1073
+                        $similarLangFallback =  $option['@value'];
1074
+                    }
1075
+                }
1076
+            } else {
1077
+                $englishFallback = $option;
1078
+            }
1079
+        }
1080
+
1081
+        if ($similarLangFallback !== false) {
1082
+            return $similarLangFallback;
1083
+        } else if ($englishFallback !== false) {
1084
+            return $englishFallback;
1085
+        }
1086
+        return (string) $fallback;
1087
+    }
1088
+
1089
+    /**
1090
+     * parses the app data array and enhanced the 'description' value
1091
+     *
1092
+     * @param array $data the app data
1093
+     * @param string $lang
1094
+     * @return array improved app data
1095
+     */
1096
+    public static function parseAppInfo(array $data, $lang = null) {
1097
+
1098
+        if ($lang && isset($data['name']) && is_array($data['name'])) {
1099
+            $data['name'] = self::findBestL10NOption($data['name'], $lang);
1100
+        }
1101
+        if ($lang && isset($data['summary']) && is_array($data['summary'])) {
1102
+            $data['summary'] = self::findBestL10NOption($data['summary'], $lang);
1103
+        }
1104
+        if ($lang && isset($data['description']) && is_array($data['description'])) {
1105
+            $data['description'] = trim(self::findBestL10NOption($data['description'], $lang));
1106
+        } else if (isset($data['description']) && is_string($data['description'])) {
1107
+            $data['description'] = trim($data['description']);
1108
+        } else  {
1109
+            $data['description'] = '';
1110
+        }
1111
+
1112
+        return $data;
1113
+    }
1114
+
1115
+    /**
1116
+     * @param \OCP\IConfig $config
1117
+     * @param \OCP\IL10N $l
1118
+     * @param array $info
1119
+     * @throws \Exception
1120
+     */
1121
+    public static function checkAppDependencies($config, $l, $info) {
1122
+        $dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l);
1123
+        $missing = $dependencyAnalyzer->analyze($info);
1124
+        if (!empty($missing)) {
1125
+            $missingMsg = implode(PHP_EOL, $missing);
1126
+            throw new \Exception(
1127
+                $l->t('App "%s" cannot be installed because the following dependencies are not fulfilled: %s',
1128
+                    [$info['name'], $missingMsg]
1129
+                )
1130
+            );
1131
+        }
1132
+    }
1133 1133
 }
Please login to merge, or discard this patch.
lib/private/TemplateLayout.php 2 patches
Indentation   +282 added lines, -282 removed lines patch added patch discarded remove patch
@@ -45,286 +45,286 @@
 block discarded – undo
45 45
 
46 46
 class TemplateLayout extends \OC_Template {
47 47
 
48
-	private static $versionHash = '';
49
-
50
-	/**
51
-	 * @var \OCP\IConfig
52
-	 */
53
-	private $config;
54
-
55
-	/**
56
-	 * @param string $renderAs
57
-	 * @param string $appId application id
58
-	 */
59
-	public function __construct( $renderAs, $appId = '' ) {
60
-
61
-		// yes - should be injected ....
62
-		$this->config = \OC::$server->getConfig();
63
-
64
-
65
-		// Decide which page we show
66
-		if($renderAs == 'user') {
67
-			parent::__construct( 'core', 'layout.user' );
68
-			if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) {
69
-				$this->assign('bodyid', 'body-settings');
70
-			}else{
71
-				$this->assign('bodyid', 'body-user');
72
-			}
73
-
74
-			// Code integrity notification
75
-			$integrityChecker = \OC::$server->getIntegrityCodeChecker();
76
-			if(\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) {
77
-				\OCP\Util::addScript('core', 'integritycheck-failed-notification');
78
-			}
79
-
80
-			// Add navigation entry
81
-			$this->assign( 'application', '');
82
-			$this->assign( 'appid', $appId );
83
-			$navigation = \OC::$server->getNavigationManager()->getAll();
84
-			$this->assign( 'navigation', $navigation);
85
-			$settingsNavigation = \OC::$server->getNavigationManager()->getAll('settings');
86
-			$this->assign( 'settingsnavigation', $settingsNavigation);
87
-			foreach($navigation as $entry) {
88
-				if ($entry['active']) {
89
-					$this->assign( 'application', $entry['name'] );
90
-					break;
91
-				}
92
-			}
93
-
94
-			foreach($settingsNavigation as $entry) {
95
-				if ($entry['active']) {
96
-					$this->assign( 'application', $entry['name'] );
97
-					break;
98
-				}
99
-			}
100
-			$userDisplayName = \OC_User::getDisplayName();
101
-			$this->assign('user_displayname', $userDisplayName);
102
-			$this->assign('user_uid', \OC_User::getUser());
103
-
104
-			if (\OC_User::getUser() === false) {
105
-				$this->assign('userAvatarSet', false);
106
-			} else {
107
-				$this->assign('userAvatarSet', \OC::$server->getAvatarManager()->getAvatar(\OC_User::getUser())->exists());
108
-				$this->assign('userAvatarVersion', $this->config->getUserValue(\OC_User::getUser(), 'avatar', 'version', 0));
109
-			}
110
-
111
-			// check if app menu icons should be inverted
112
-			try {
113
-				/** @var \OCA\Theming\Util $util */
114
-				$util = \OC::$server->query(\OCA\Theming\Util::class);
115
-				$this->assign('themingInvertMenu', $util->invertTextColor(\OC::$server->getThemingDefaults()->getColorPrimary()));
116
-			} catch (\OCP\AppFramework\QueryException $e) {
117
-				$this->assign('themingInvertMenu', false);
118
-			}
119
-
120
-		} else if ($renderAs == 'error') {
121
-			parent::__construct('core', 'layout.guest', '', false);
122
-			$this->assign('bodyid', 'body-login');
123
-		} else if ($renderAs == 'guest') {
124
-			parent::__construct('core', 'layout.guest');
125
-			$this->assign('bodyid', 'body-login');
126
-		} else {
127
-			parent::__construct('core', 'layout.base');
128
-
129
-		}
130
-		// Send the language to our layouts
131
-		$lang = \OC::$server->getL10NFactory()->findLanguage();
132
-		$lang = str_replace('_', '-', $lang);
133
-		$this->assign('language', $lang);
134
-
135
-		if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
136
-			if (empty(self::$versionHash)) {
137
-				$v = \OC_App::getAppVersions();
138
-				$v['core'] = implode('.', \OCP\Util::getVersion());
139
-				self::$versionHash = substr(md5(implode(',', $v)), 0, 8);
140
-			}
141
-		} else {
142
-			self::$versionHash = md5('not installed');
143
-		}
144
-
145
-		// Add the js files
146
-		$jsFiles = self::findJavascriptFiles(\OC_Util::$scripts);
147
-		$this->assign('jsfiles', array());
148
-		if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') {
149
-			if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) {
150
-				$jsConfigHelper = new JSConfigHelper(
151
-					\OC::$server->getL10N('lib'),
152
-					\OC::$server->query(Defaults::class),
153
-					\OC::$server->getAppManager(),
154
-					\OC::$server->getSession(),
155
-					\OC::$server->getUserSession()->getUser(),
156
-					$this->config,
157
-					\OC::$server->getGroupManager(),
158
-					\OC::$server->getIniWrapper(),
159
-					\OC::$server->getURLGenerator()
160
-				);
161
-				$this->assign('inline_ocjs', $jsConfigHelper->getConfig());
162
-			} else {
163
-				$this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash]));
164
-			}
165
-		}
166
-		foreach($jsFiles as $info) {
167
-			$web = $info[1];
168
-			$file = $info[2];
169
-			$this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() );
170
-		}
171
-
172
-		try {
173
-			$pathInfo = \OC::$server->getRequest()->getPathInfo();
174
-		} catch (\Exception $e) {
175
-			$pathInfo = '';
176
-		}
177
-
178
-		// Do not initialise scss appdata until we have a fully installed instance
179
-		// Do not load scss for update, errors, installation or login page
180
-		if(\OC::$server->getSystemConfig()->getValue('installed', false)
181
-			&& !\OCP\Util::needUpgrade()
182
-			&& $pathInfo !== ''
183
-			&& !preg_match('/^\/login/', $pathInfo)
184
-			&& $renderAs !== 'error' && $renderAs !== 'guest'
185
-		) {
186
-			$cssFiles = self::findStylesheetFiles(\OC_Util::$styles);
187
-		} else {
188
-			// If we ignore the scss compiler,
189
-			// we need to load the guest css fallback
190
-			\OC_Util::addStyle('guest');
191
-			$cssFiles = self::findStylesheetFiles(\OC_Util::$styles, false);
192
-		}
193
-
194
-		$this->assign('cssfiles', array());
195
-		$this->assign('printcssfiles', []);
196
-		$this->assign('versionHash', self::$versionHash);
197
-		foreach($cssFiles as $info) {
198
-			$web = $info[1];
199
-			$file = $info[2];
200
-
201
-			if (substr($file, -strlen('print.css')) === 'print.css') {
202
-				$this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() );
203
-			} else {
204
-				$this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix($web, $file)  );
205
-			}
206
-		}
207
-	}
208
-
209
-	/**
210
-	 * @param string $path
211
- 	 * @param string $file
212
-	 * @return string
213
-	 */
214
-	protected function getVersionHashSuffix($path = false, $file = false) {
215
-		if ($this->config->getSystemValue('debug', false)) {
216
-			// allows chrome workspace mapping in debug mode
217
-			return "";
218
-		}
219
-		$themingSuffix = '';
220
-		$v = [];
221
-
222
-		if ($this->config->getSystemValue('installed', false)) {
223
-			if (\OC::$server->getAppManager()->isInstalled('theming')) {
224
-				$themingSuffix = '-' . $this->config->getAppValue('theming', 'cachebuster', '0');
225
-			}
226
-			$v = \OC_App::getAppVersions();
227
-		}
228
-
229
-		// Try the webroot path for a match
230
-		if ($path !== false && $path !== '') {
231
-			$appName = $this->getAppNamefromPath($path);
232
-			if(array_key_exists($appName, $v)) {
233
-				$appVersion = $v[$appName];
234
-				return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix;
235
-			}
236
-		}
237
-		// fallback to the file path instead
238
-		if ($file !== false && $file !== '') {
239
-			$appName = $this->getAppNamefromPath($file);
240
-			if(array_key_exists($appName, $v)) {
241
-				$appVersion = $v[$appName];
242
-				return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix;
243
-			}
244
-		}
245
-
246
-		return '?v=' . self::$versionHash . $themingSuffix;
247
-	}
248
-
249
-	/**
250
-	 * @param array $styles
251
-	 * @return array
252
-	 */
253
-	static public function findStylesheetFiles($styles, $compileScss = true) {
254
-		// Read the selected theme from the config file
255
-		$theme = \OC_Util::getTheme();
256
-
257
-		if($compileScss) {
258
-			$SCSSCacher = \OC::$server->query(SCSSCacher::class);
259
-		} else {
260
-			$SCSSCacher = null;
261
-		}
262
-
263
-		$locator = new \OC\Template\CSSResourceLocator(
264
-			\OC::$server->getLogger(),
265
-			$theme,
266
-			array( \OC::$SERVERROOT => \OC::$WEBROOT ),
267
-			array( \OC::$SERVERROOT => \OC::$WEBROOT ),
268
-			$SCSSCacher
269
-		);
270
-		$locator->find($styles);
271
-		return $locator->getResources();
272
-	}
273
-
274
-	/**
275
-	 * @param string $path
276
-	 * @return string|boolean
277
-	 */
278
-	public function getAppNamefromPath($path) {
279
-		if ($path !== '' && is_string($path)) {
280
-			$pathParts = explode('/', $path);
281
-			if ($pathParts[0] === 'css') {
282
-				// This is a scss request
283
-				return $pathParts[1];
284
-			}
285
-			return end($pathParts);
286
-		}
287
-		return false;
288
-
289
-	}
290
-
291
-	/**
292
-	 * @param array $scripts
293
-	 * @return array
294
-	 */
295
-	static public function findJavascriptFiles($scripts) {
296
-		// Read the selected theme from the config file
297
-		$theme = \OC_Util::getTheme();
298
-
299
-		$locator = new \OC\Template\JSResourceLocator(
300
-			\OC::$server->getLogger(),
301
-			$theme,
302
-			array( \OC::$SERVERROOT => \OC::$WEBROOT ),
303
-			array( \OC::$SERVERROOT => \OC::$WEBROOT ),
304
-			new JSCombiner(
305
-				\OC::$server->getAppDataDir('js'),
306
-				\OC::$server->getURLGenerator(),
307
-				\OC::$server->getMemCacheFactory()->createDistributed('JS'),
308
-				\OC::$server->getSystemConfig(),
309
-				\OC::$server->getLogger()
310
-			)
311
-			);
312
-		$locator->find($scripts);
313
-		return $locator->getResources();
314
-	}
315
-
316
-	/**
317
-	 * Converts the absolute file path to a relative path from \OC::$SERVERROOT
318
-	 * @param string $filePath Absolute path
319
-	 * @return string Relative path
320
-	 * @throws \Exception If $filePath is not under \OC::$SERVERROOT
321
-	 */
322
-	public static function convertToRelativePath($filePath) {
323
-		$relativePath = explode(\OC::$SERVERROOT, $filePath);
324
-		if(count($relativePath) !== 2) {
325
-			throw new \Exception('$filePath is not under the \OC::$SERVERROOT');
326
-		}
327
-
328
-		return $relativePath[1];
329
-	}
48
+    private static $versionHash = '';
49
+
50
+    /**
51
+     * @var \OCP\IConfig
52
+     */
53
+    private $config;
54
+
55
+    /**
56
+     * @param string $renderAs
57
+     * @param string $appId application id
58
+     */
59
+    public function __construct( $renderAs, $appId = '' ) {
60
+
61
+        // yes - should be injected ....
62
+        $this->config = \OC::$server->getConfig();
63
+
64
+
65
+        // Decide which page we show
66
+        if($renderAs == 'user') {
67
+            parent::__construct( 'core', 'layout.user' );
68
+            if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) {
69
+                $this->assign('bodyid', 'body-settings');
70
+            }else{
71
+                $this->assign('bodyid', 'body-user');
72
+            }
73
+
74
+            // Code integrity notification
75
+            $integrityChecker = \OC::$server->getIntegrityCodeChecker();
76
+            if(\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) {
77
+                \OCP\Util::addScript('core', 'integritycheck-failed-notification');
78
+            }
79
+
80
+            // Add navigation entry
81
+            $this->assign( 'application', '');
82
+            $this->assign( 'appid', $appId );
83
+            $navigation = \OC::$server->getNavigationManager()->getAll();
84
+            $this->assign( 'navigation', $navigation);
85
+            $settingsNavigation = \OC::$server->getNavigationManager()->getAll('settings');
86
+            $this->assign( 'settingsnavigation', $settingsNavigation);
87
+            foreach($navigation as $entry) {
88
+                if ($entry['active']) {
89
+                    $this->assign( 'application', $entry['name'] );
90
+                    break;
91
+                }
92
+            }
93
+
94
+            foreach($settingsNavigation as $entry) {
95
+                if ($entry['active']) {
96
+                    $this->assign( 'application', $entry['name'] );
97
+                    break;
98
+                }
99
+            }
100
+            $userDisplayName = \OC_User::getDisplayName();
101
+            $this->assign('user_displayname', $userDisplayName);
102
+            $this->assign('user_uid', \OC_User::getUser());
103
+
104
+            if (\OC_User::getUser() === false) {
105
+                $this->assign('userAvatarSet', false);
106
+            } else {
107
+                $this->assign('userAvatarSet', \OC::$server->getAvatarManager()->getAvatar(\OC_User::getUser())->exists());
108
+                $this->assign('userAvatarVersion', $this->config->getUserValue(\OC_User::getUser(), 'avatar', 'version', 0));
109
+            }
110
+
111
+            // check if app menu icons should be inverted
112
+            try {
113
+                /** @var \OCA\Theming\Util $util */
114
+                $util = \OC::$server->query(\OCA\Theming\Util::class);
115
+                $this->assign('themingInvertMenu', $util->invertTextColor(\OC::$server->getThemingDefaults()->getColorPrimary()));
116
+            } catch (\OCP\AppFramework\QueryException $e) {
117
+                $this->assign('themingInvertMenu', false);
118
+            }
119
+
120
+        } else if ($renderAs == 'error') {
121
+            parent::__construct('core', 'layout.guest', '', false);
122
+            $this->assign('bodyid', 'body-login');
123
+        } else if ($renderAs == 'guest') {
124
+            parent::__construct('core', 'layout.guest');
125
+            $this->assign('bodyid', 'body-login');
126
+        } else {
127
+            parent::__construct('core', 'layout.base');
128
+
129
+        }
130
+        // Send the language to our layouts
131
+        $lang = \OC::$server->getL10NFactory()->findLanguage();
132
+        $lang = str_replace('_', '-', $lang);
133
+        $this->assign('language', $lang);
134
+
135
+        if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
136
+            if (empty(self::$versionHash)) {
137
+                $v = \OC_App::getAppVersions();
138
+                $v['core'] = implode('.', \OCP\Util::getVersion());
139
+                self::$versionHash = substr(md5(implode(',', $v)), 0, 8);
140
+            }
141
+        } else {
142
+            self::$versionHash = md5('not installed');
143
+        }
144
+
145
+        // Add the js files
146
+        $jsFiles = self::findJavascriptFiles(\OC_Util::$scripts);
147
+        $this->assign('jsfiles', array());
148
+        if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') {
149
+            if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) {
150
+                $jsConfigHelper = new JSConfigHelper(
151
+                    \OC::$server->getL10N('lib'),
152
+                    \OC::$server->query(Defaults::class),
153
+                    \OC::$server->getAppManager(),
154
+                    \OC::$server->getSession(),
155
+                    \OC::$server->getUserSession()->getUser(),
156
+                    $this->config,
157
+                    \OC::$server->getGroupManager(),
158
+                    \OC::$server->getIniWrapper(),
159
+                    \OC::$server->getURLGenerator()
160
+                );
161
+                $this->assign('inline_ocjs', $jsConfigHelper->getConfig());
162
+            } else {
163
+                $this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash]));
164
+            }
165
+        }
166
+        foreach($jsFiles as $info) {
167
+            $web = $info[1];
168
+            $file = $info[2];
169
+            $this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() );
170
+        }
171
+
172
+        try {
173
+            $pathInfo = \OC::$server->getRequest()->getPathInfo();
174
+        } catch (\Exception $e) {
175
+            $pathInfo = '';
176
+        }
177
+
178
+        // Do not initialise scss appdata until we have a fully installed instance
179
+        // Do not load scss for update, errors, installation or login page
180
+        if(\OC::$server->getSystemConfig()->getValue('installed', false)
181
+            && !\OCP\Util::needUpgrade()
182
+            && $pathInfo !== ''
183
+            && !preg_match('/^\/login/', $pathInfo)
184
+            && $renderAs !== 'error' && $renderAs !== 'guest'
185
+        ) {
186
+            $cssFiles = self::findStylesheetFiles(\OC_Util::$styles);
187
+        } else {
188
+            // If we ignore the scss compiler,
189
+            // we need to load the guest css fallback
190
+            \OC_Util::addStyle('guest');
191
+            $cssFiles = self::findStylesheetFiles(\OC_Util::$styles, false);
192
+        }
193
+
194
+        $this->assign('cssfiles', array());
195
+        $this->assign('printcssfiles', []);
196
+        $this->assign('versionHash', self::$versionHash);
197
+        foreach($cssFiles as $info) {
198
+            $web = $info[1];
199
+            $file = $info[2];
200
+
201
+            if (substr($file, -strlen('print.css')) === 'print.css') {
202
+                $this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() );
203
+            } else {
204
+                $this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix($web, $file)  );
205
+            }
206
+        }
207
+    }
208
+
209
+    /**
210
+     * @param string $path
211
+     * @param string $file
212
+     * @return string
213
+     */
214
+    protected function getVersionHashSuffix($path = false, $file = false) {
215
+        if ($this->config->getSystemValue('debug', false)) {
216
+            // allows chrome workspace mapping in debug mode
217
+            return "";
218
+        }
219
+        $themingSuffix = '';
220
+        $v = [];
221
+
222
+        if ($this->config->getSystemValue('installed', false)) {
223
+            if (\OC::$server->getAppManager()->isInstalled('theming')) {
224
+                $themingSuffix = '-' . $this->config->getAppValue('theming', 'cachebuster', '0');
225
+            }
226
+            $v = \OC_App::getAppVersions();
227
+        }
228
+
229
+        // Try the webroot path for a match
230
+        if ($path !== false && $path !== '') {
231
+            $appName = $this->getAppNamefromPath($path);
232
+            if(array_key_exists($appName, $v)) {
233
+                $appVersion = $v[$appName];
234
+                return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix;
235
+            }
236
+        }
237
+        // fallback to the file path instead
238
+        if ($file !== false && $file !== '') {
239
+            $appName = $this->getAppNamefromPath($file);
240
+            if(array_key_exists($appName, $v)) {
241
+                $appVersion = $v[$appName];
242
+                return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix;
243
+            }
244
+        }
245
+
246
+        return '?v=' . self::$versionHash . $themingSuffix;
247
+    }
248
+
249
+    /**
250
+     * @param array $styles
251
+     * @return array
252
+     */
253
+    static public function findStylesheetFiles($styles, $compileScss = true) {
254
+        // Read the selected theme from the config file
255
+        $theme = \OC_Util::getTheme();
256
+
257
+        if($compileScss) {
258
+            $SCSSCacher = \OC::$server->query(SCSSCacher::class);
259
+        } else {
260
+            $SCSSCacher = null;
261
+        }
262
+
263
+        $locator = new \OC\Template\CSSResourceLocator(
264
+            \OC::$server->getLogger(),
265
+            $theme,
266
+            array( \OC::$SERVERROOT => \OC::$WEBROOT ),
267
+            array( \OC::$SERVERROOT => \OC::$WEBROOT ),
268
+            $SCSSCacher
269
+        );
270
+        $locator->find($styles);
271
+        return $locator->getResources();
272
+    }
273
+
274
+    /**
275
+     * @param string $path
276
+     * @return string|boolean
277
+     */
278
+    public function getAppNamefromPath($path) {
279
+        if ($path !== '' && is_string($path)) {
280
+            $pathParts = explode('/', $path);
281
+            if ($pathParts[0] === 'css') {
282
+                // This is a scss request
283
+                return $pathParts[1];
284
+            }
285
+            return end($pathParts);
286
+        }
287
+        return false;
288
+
289
+    }
290
+
291
+    /**
292
+     * @param array $scripts
293
+     * @return array
294
+     */
295
+    static public function findJavascriptFiles($scripts) {
296
+        // Read the selected theme from the config file
297
+        $theme = \OC_Util::getTheme();
298
+
299
+        $locator = new \OC\Template\JSResourceLocator(
300
+            \OC::$server->getLogger(),
301
+            $theme,
302
+            array( \OC::$SERVERROOT => \OC::$WEBROOT ),
303
+            array( \OC::$SERVERROOT => \OC::$WEBROOT ),
304
+            new JSCombiner(
305
+                \OC::$server->getAppDataDir('js'),
306
+                \OC::$server->getURLGenerator(),
307
+                \OC::$server->getMemCacheFactory()->createDistributed('JS'),
308
+                \OC::$server->getSystemConfig(),
309
+                \OC::$server->getLogger()
310
+            )
311
+            );
312
+        $locator->find($scripts);
313
+        return $locator->getResources();
314
+    }
315
+
316
+    /**
317
+     * Converts the absolute file path to a relative path from \OC::$SERVERROOT
318
+     * @param string $filePath Absolute path
319
+     * @return string Relative path
320
+     * @throws \Exception If $filePath is not under \OC::$SERVERROOT
321
+     */
322
+    public static function convertToRelativePath($filePath) {
323
+        $relativePath = explode(\OC::$SERVERROOT, $filePath);
324
+        if(count($relativePath) !== 2) {
325
+            throw new \Exception('$filePath is not under the \OC::$SERVERROOT');
326
+        }
327
+
328
+        return $relativePath[1];
329
+    }
330 330
 }
Please login to merge, or discard this patch.
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -56,44 +56,44 @@  discard block
 block discarded – undo
56 56
 	 * @param string $renderAs
57 57
 	 * @param string $appId application id
58 58
 	 */
59
-	public function __construct( $renderAs, $appId = '' ) {
59
+	public function __construct($renderAs, $appId = '') {
60 60
 
61 61
 		// yes - should be injected ....
62 62
 		$this->config = \OC::$server->getConfig();
63 63
 
64 64
 
65 65
 		// Decide which page we show
66
-		if($renderAs == 'user') {
67
-			parent::__construct( 'core', 'layout.user' );
68
-			if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) {
66
+		if ($renderAs == 'user') {
67
+			parent::__construct('core', 'layout.user');
68
+			if (in_array(\OC_App::getCurrentApp(), ['settings', 'admin', 'help']) !== false) {
69 69
 				$this->assign('bodyid', 'body-settings');
70
-			}else{
70
+			} else {
71 71
 				$this->assign('bodyid', 'body-user');
72 72
 			}
73 73
 
74 74
 			// Code integrity notification
75 75
 			$integrityChecker = \OC::$server->getIntegrityCodeChecker();
76
-			if(\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) {
76
+			if (\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) {
77 77
 				\OCP\Util::addScript('core', 'integritycheck-failed-notification');
78 78
 			}
79 79
 
80 80
 			// Add navigation entry
81
-			$this->assign( 'application', '');
82
-			$this->assign( 'appid', $appId );
81
+			$this->assign('application', '');
82
+			$this->assign('appid', $appId);
83 83
 			$navigation = \OC::$server->getNavigationManager()->getAll();
84
-			$this->assign( 'navigation', $navigation);
84
+			$this->assign('navigation', $navigation);
85 85
 			$settingsNavigation = \OC::$server->getNavigationManager()->getAll('settings');
86
-			$this->assign( 'settingsnavigation', $settingsNavigation);
87
-			foreach($navigation as $entry) {
86
+			$this->assign('settingsnavigation', $settingsNavigation);
87
+			foreach ($navigation as $entry) {
88 88
 				if ($entry['active']) {
89
-					$this->assign( 'application', $entry['name'] );
89
+					$this->assign('application', $entry['name']);
90 90
 					break;
91 91
 				}
92 92
 			}
93 93
 
94
-			foreach($settingsNavigation as $entry) {
94
+			foreach ($settingsNavigation as $entry) {
95 95
 				if ($entry['active']) {
96
-					$this->assign( 'application', $entry['name'] );
96
+					$this->assign('application', $entry['name']);
97 97
 					break;
98 98
 				}
99 99
 			}
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 		$lang = str_replace('_', '-', $lang);
133 133
 		$this->assign('language', $lang);
134 134
 
135
-		if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
135
+		if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
136 136
 			if (empty(self::$versionHash)) {
137 137
 				$v = \OC_App::getAppVersions();
138 138
 				$v['core'] = implode('.', \OCP\Util::getVersion());
@@ -163,10 +163,10 @@  discard block
 block discarded – undo
163 163
 				$this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash]));
164 164
 			}
165 165
 		}
166
-		foreach($jsFiles as $info) {
166
+		foreach ($jsFiles as $info) {
167 167
 			$web = $info[1];
168 168
 			$file = $info[2];
169
-			$this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() );
169
+			$this->append('jsfiles', $web.'/'.$file.$this->getVersionHashSuffix());
170 170
 		}
171 171
 
172 172
 		try {
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
 
178 178
 		// Do not initialise scss appdata until we have a fully installed instance
179 179
 		// Do not load scss for update, errors, installation or login page
180
-		if(\OC::$server->getSystemConfig()->getValue('installed', false)
180
+		if (\OC::$server->getSystemConfig()->getValue('installed', false)
181 181
 			&& !\OCP\Util::needUpgrade()
182 182
 			&& $pathInfo !== ''
183 183
 			&& !preg_match('/^\/login/', $pathInfo)
@@ -194,14 +194,14 @@  discard block
 block discarded – undo
194 194
 		$this->assign('cssfiles', array());
195 195
 		$this->assign('printcssfiles', []);
196 196
 		$this->assign('versionHash', self::$versionHash);
197
-		foreach($cssFiles as $info) {
197
+		foreach ($cssFiles as $info) {
198 198
 			$web = $info[1];
199 199
 			$file = $info[2];
200 200
 
201 201
 			if (substr($file, -strlen('print.css')) === 'print.css') {
202
-				$this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() );
202
+				$this->append('printcssfiles', $web.'/'.$file.$this->getVersionHashSuffix());
203 203
 			} else {
204
-				$this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix($web, $file)  );
204
+				$this->append('cssfiles', $web.'/'.$file.$this->getVersionHashSuffix($web, $file));
205 205
 			}
206 206
 		}
207 207
 	}
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
 
222 222
 		if ($this->config->getSystemValue('installed', false)) {
223 223
 			if (\OC::$server->getAppManager()->isInstalled('theming')) {
224
-				$themingSuffix = '-' . $this->config->getAppValue('theming', 'cachebuster', '0');
224
+				$themingSuffix = '-'.$this->config->getAppValue('theming', 'cachebuster', '0');
225 225
 			}
226 226
 			$v = \OC_App::getAppVersions();
227 227
 		}
@@ -229,21 +229,21 @@  discard block
 block discarded – undo
229 229
 		// Try the webroot path for a match
230 230
 		if ($path !== false && $path !== '') {
231 231
 			$appName = $this->getAppNamefromPath($path);
232
-			if(array_key_exists($appName, $v)) {
232
+			if (array_key_exists($appName, $v)) {
233 233
 				$appVersion = $v[$appName];
234
-				return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix;
234
+				return '?v='.substr(md5($appVersion), 0, 8).$themingSuffix;
235 235
 			}
236 236
 		}
237 237
 		// fallback to the file path instead
238 238
 		if ($file !== false && $file !== '') {
239 239
 			$appName = $this->getAppNamefromPath($file);
240
-			if(array_key_exists($appName, $v)) {
240
+			if (array_key_exists($appName, $v)) {
241 241
 				$appVersion = $v[$appName];
242
-				return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix;
242
+				return '?v='.substr(md5($appVersion), 0, 8).$themingSuffix;
243 243
 			}
244 244
 		}
245 245
 
246
-		return '?v=' . self::$versionHash . $themingSuffix;
246
+		return '?v='.self::$versionHash.$themingSuffix;
247 247
 	}
248 248
 
249 249
 	/**
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
 		// Read the selected theme from the config file
255 255
 		$theme = \OC_Util::getTheme();
256 256
 
257
-		if($compileScss) {
257
+		if ($compileScss) {
258 258
 			$SCSSCacher = \OC::$server->query(SCSSCacher::class);
259 259
 		} else {
260 260
 			$SCSSCacher = null;
@@ -263,8 +263,8 @@  discard block
 block discarded – undo
263 263
 		$locator = new \OC\Template\CSSResourceLocator(
264 264
 			\OC::$server->getLogger(),
265 265
 			$theme,
266
-			array( \OC::$SERVERROOT => \OC::$WEBROOT ),
267
-			array( \OC::$SERVERROOT => \OC::$WEBROOT ),
266
+			array(\OC::$SERVERROOT => \OC::$WEBROOT),
267
+			array(\OC::$SERVERROOT => \OC::$WEBROOT),
268 268
 			$SCSSCacher
269 269
 		);
270 270
 		$locator->find($styles);
@@ -299,8 +299,8 @@  discard block
 block discarded – undo
299 299
 		$locator = new \OC\Template\JSResourceLocator(
300 300
 			\OC::$server->getLogger(),
301 301
 			$theme,
302
-			array( \OC::$SERVERROOT => \OC::$WEBROOT ),
303
-			array( \OC::$SERVERROOT => \OC::$WEBROOT ),
302
+			array(\OC::$SERVERROOT => \OC::$WEBROOT),
303
+			array(\OC::$SERVERROOT => \OC::$WEBROOT),
304 304
 			new JSCombiner(
305 305
 				\OC::$server->getAppDataDir('js'),
306 306
 				\OC::$server->getURLGenerator(),
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
 	 */
322 322
 	public static function convertToRelativePath($filePath) {
323 323
 		$relativePath = explode(\OC::$SERVERROOT, $filePath);
324
-		if(count($relativePath) !== 2) {
324
+		if (count($relativePath) !== 2) {
325 325
 			throw new \Exception('$filePath is not under the \OC::$SERVERROOT');
326 326
 		}
327 327
 
Please login to merge, or discard this patch.
core/Controller/NavigationController.php 1 patch
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -30,63 +30,63 @@
 block discarded – undo
30 30
 
31 31
 class NavigationController extends OCSController {
32 32
 
33
-	/** @var INavigationManager */
34
-	private $navigationManager;
33
+    /** @var INavigationManager */
34
+    private $navigationManager;
35 35
 
36
-	/** @var IURLGenerator */
37
-	private $urlGenerator;
36
+    /** @var IURLGenerator */
37
+    private $urlGenerator;
38 38
 
39
-	public function __construct(string $appName, IRequest $request, INavigationManager $navigationManager, IURLGenerator $urlGenerator) {
40
-		parent::__construct($appName, $request);
41
-		$this->navigationManager = $navigationManager;
42
-		$this->urlGenerator = $urlGenerator;
43
-	}
39
+    public function __construct(string $appName, IRequest $request, INavigationManager $navigationManager, IURLGenerator $urlGenerator) {
40
+        parent::__construct($appName, $request);
41
+        $this->navigationManager = $navigationManager;
42
+        $this->urlGenerator = $urlGenerator;
43
+    }
44 44
 
45
-	/**
46
-	 * @NoAdminRequired
47
-	 * @NoCSRFRequired
48
-	 *
49
-	 * @param bool $absolute
50
-	 * @return DataResponse
51
-	 */
52
-	public function getAppsNavigation(bool $absolute = false): DataResponse {
53
-		$navigation = $this->navigationManager->getAll();
54
-		if ($absolute) {
55
-			$navigation = $this->rewriteToAbsoluteUrls($navigation);
56
-		}
57
-		return new DataResponse($navigation);
58
-	}
45
+    /**
46
+     * @NoAdminRequired
47
+     * @NoCSRFRequired
48
+     *
49
+     * @param bool $absolute
50
+     * @return DataResponse
51
+     */
52
+    public function getAppsNavigation(bool $absolute = false): DataResponse {
53
+        $navigation = $this->navigationManager->getAll();
54
+        if ($absolute) {
55
+            $navigation = $this->rewriteToAbsoluteUrls($navigation);
56
+        }
57
+        return new DataResponse($navigation);
58
+    }
59 59
 
60
-	/**
61
-	 * @NoAdminRequired
62
-	 * @NoCSRFRequired
63
-	 *
64
-	 * @param bool $absolute
65
-	 * @return DataResponse
66
-	 */
67
-	public function getSettingsNavigation(bool $absolute = false): DataResponse {
68
-		$navigation = $this->navigationManager->getAll('settings');
69
-		if ($absolute) {
70
-			$navigation = $this->rewriteToAbsoluteUrls($navigation);
71
-		}
72
-		return new DataResponse($navigation);
73
-	}
60
+    /**
61
+     * @NoAdminRequired
62
+     * @NoCSRFRequired
63
+     *
64
+     * @param bool $absolute
65
+     * @return DataResponse
66
+     */
67
+    public function getSettingsNavigation(bool $absolute = false): DataResponse {
68
+        $navigation = $this->navigationManager->getAll('settings');
69
+        if ($absolute) {
70
+            $navigation = $this->rewriteToAbsoluteUrls($navigation);
71
+        }
72
+        return new DataResponse($navigation);
73
+    }
74 74
 
75
-	/**
76
-	 * Rewrite href attribute of navigation entries to an absolute URL
77
-	 *
78
-	 * @param array $navigation
79
-	 * @return array
80
-	 */
81
-	private function rewriteToAbsoluteUrls(array $navigation): array {
82
-		foreach ($navigation as &$entry) {
83
-			if (0 !== strpos($entry['href'], $this->urlGenerator->getBaseUrl())) {
84
-				$entry['href'] = $this->urlGenerator->getAbsoluteURL($entry['href']);
85
-			}
86
-			if (0 !== strpos($entry['icon'], $this->urlGenerator->getBaseUrl())) {
87
-				$entry['icon'] = $this->urlGenerator->getAbsoluteURL($entry['icon']);
88
-			}
89
-		}
90
-		return $navigation;
91
-	}
75
+    /**
76
+     * Rewrite href attribute of navigation entries to an absolute URL
77
+     *
78
+     * @param array $navigation
79
+     * @return array
80
+     */
81
+    private function rewriteToAbsoluteUrls(array $navigation): array {
82
+        foreach ($navigation as &$entry) {
83
+            if (0 !== strpos($entry['href'], $this->urlGenerator->getBaseUrl())) {
84
+                $entry['href'] = $this->urlGenerator->getAbsoluteURL($entry['href']);
85
+            }
86
+            if (0 !== strpos($entry['icon'], $this->urlGenerator->getBaseUrl())) {
87
+                $entry['icon'] = $this->urlGenerator->getAbsoluteURL($entry['icon']);
88
+            }
89
+        }
90
+        return $navigation;
91
+    }
92 92
 }
Please login to merge, or discard this patch.