Passed
Push — master ( 25fc25...eec792 )
by Blizzz
14:01 queued 12s
created
core/templates/layout.user.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 		<meta charset="utf-8">
5 5
 		<title>
6 6
 			<?php
7
-				p(!empty($_['application'])?$_['application'].' - ':'');
7
+				p(!empty($_['application']) ? $_['application'].' - ' : '');
8 8
 				p($theme->getTitle());
9 9
 			?>
10 10
 		</title>
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 		<?php } ?>
16 16
 		<meta name="apple-mobile-web-app-capable" content="yes">
17 17
 		<meta name="apple-mobile-web-app-status-bar-style" content="black">
18
-		<meta name="apple-mobile-web-app-title" content="<?php p((!empty($_['application']) && $_['appid'] != 'files')? $_['application']:$theme->getTitle()); ?>">
18
+		<meta name="apple-mobile-web-app-title" content="<?php p((!empty($_['application']) && $_['appid'] != 'files') ? $_['application'] : $theme->getTitle()); ?>">
19 19
 		<meta name="mobile-web-app-capable" content="yes">
20 20
 		<meta name="theme-color" content="<?php p($theme->getColorPrimary()); ?>">
21 21
 		<link rel="icon" href="<?php print_unescaped(image_path($_['appid'], 'favicon.ico')); /* IE11+ supports png */ ?>">
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 		<?php emit_script_loading_tags($_); ?>
28 28
 		<?php print_unescaped($_['headers']); ?>
29 29
 	</head>
30
-	<body id="<?php p($_['bodyid']);?>">
30
+	<body id="<?php p($_['bodyid']); ?>">
31 31
 	<?php include 'layout.noscript.warning.php'; ?>
32 32
 
33 33
 		<?php foreach ($_['initialStates'] as $app => $initialState) { ?>
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 					id="nextcloud">
47 47
 					<div class="logo logo-icon">
48 48
 						<h1 class="hidden-visually">
49
-							<?php p($theme->getName()); ?> <?php p(!empty($_['application'])?$_['application']: $l->t('Apps')); ?>
49
+							<?php p($theme->getName()); ?> <?php p(!empty($_['application']) ? $_['application'] : $l->t('Apps')); ?>
50 50
 						</h1>
51 51
 					</div>
52 52
 				</a>
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 												<circle r="4.5" cx="21" cy="3" fill="black"/>
66 66
 											</mask>
67 67
 										</defs>
68
-										<image x="2" y="0" width="20" height="20" preserveAspectRatio="xMinYMin meet"<?php if ($_['themingInvertMenu']) { ?> filter="url(#invertMenuMain-<?php p($entry['id']); ?>)"<?php } ?> xlink:href="<?php print_unescaped($entry['icon'] . '?v=' . $_['versionHash']); ?>" style="<?php if ($entry['unread'] !== 0) { ?>mask: url("#hole");<?php } ?>" class="app-icon"></image>
68
+										<image x="2" y="0" width="20" height="20" preserveAspectRatio="xMinYMin meet"<?php if ($_['themingInvertMenu']) { ?> filter="url(#invertMenuMain-<?php p($entry['id']); ?>)"<?php } ?> xlink:href="<?php print_unescaped($entry['icon'].'?v='.$_['versionHash']); ?>" style="<?php if ($entry['unread'] !== 0) { ?>mask: url("#hole");<?php } ?>" class="app-icon"></image>
69 69
 										<circle class="app-icon-notification" r="3" cx="21" cy="3" fill="red"/>
70 70
 									</svg>
71 71
 								<div class="unread-counter" aria-hidden="true"><?php p($entry['unread']); ?></div>
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 													<circle r="4.5" cx="17" cy="3" fill="black"/>
102 102
 												</mask>
103 103
 											</defs>
104
-											<image x="0" y="0" width="16" height="16" preserveAspectRatio="xMinYMin meet" filter="url(#invertMenuMore-<?php p($entry['id']); ?>)" xlink:href="<?php print_unescaped($entry['icon'] . '?v=' . $_['versionHash']); ?>" style="<?php if ($entry['unread'] !== 0) { ?>mask: url("#hole");<?php } ?>" class="app-icon"></image>
104
+											<image x="0" y="0" width="16" height="16" preserveAspectRatio="xMinYMin meet" filter="url(#invertMenuMore-<?php p($entry['id']); ?>)" xlink:href="<?php print_unescaped($entry['icon'].'?v='.$_['versionHash']); ?>" style="<?php if ($entry['unread'] !== 0) { ?>mask: url("#hole");<?php } ?>" class="app-icon"></image>
105 105
 											<circle class="app-icon-notification" r="3" cx="17" cy="3" fill="red"/>
106 106
 										</svg>
107 107
 										<div class="unread-counter" aria-hidden="true"><?php p($entry['unread']); ?></div>
@@ -122,14 +122,14 @@  discard block
 block discarded – undo
122 122
 				<div id="contactsmenu">
123 123
 					<div class="icon-contacts menutoggle" tabindex="0" role="button"
124 124
 					aria-haspopup="true" aria-controls="contactsmenu-menu" aria-expanded="false">
125
-						<span class="hidden-visually"><?php p($l->t('Contacts'));?></span>
125
+						<span class="hidden-visually"><?php p($l->t('Contacts')); ?></span>
126 126
 					</div>
127 127
 					<div id="contactsmenu-menu" class="menu"
128
-						aria-label="<?php p($l->t('Contacts menu'));?>"></div>
128
+						aria-label="<?php p($l->t('Contacts menu')); ?>"></div>
129 129
 				</div>
130 130
 				<div id="settings">
131 131
 					<div id="expand" tabindex="0" role="button" class="menutoggle"
132
-						aria-label="<?php p($l->t('Settings'));?>"
132
+						aria-label="<?php p($l->t('Settings')); ?>"
133 133
 						aria-haspopup="true" aria-controls="expanddiv" aria-expanded="false">
134 134
 						<div class="avatardiv<?php if ($_['userAvatarSet']) {
135 135
 				print_unescaped(' avatardiv-shown');
@@ -138,21 +138,21 @@  discard block
 block discarded – undo
138 138
 			} ?>">
139 139
 							<?php if ($_['userAvatarSet']): ?>
140 140
 								<img alt="" width="32" height="32"
141
-								src="<?php p(\OC::$server->getURLGenerator()->linkToRoute('core.avatar.getAvatar', ['userId' => $_['user_uid'], 'size' => 32, 'v' => $_['userAvatarVersion']]));?>"
142
-								srcset="<?php p(\OC::$server->getURLGenerator()->linkToRoute('core.avatar.getAvatar', ['userId' => $_['user_uid'], 'size' => 64, 'v' => $_['userAvatarVersion']]));?> 2x, <?php p(\OC::$server->getURLGenerator()->linkToRoute('core.avatar.getAvatar', ['userId' => $_['user_uid'], 'size' => 128, 'v' => $_['userAvatarVersion']]));?> 4x"
141
+								src="<?php p(\OC::$server->getURLGenerator()->linkToRoute('core.avatar.getAvatar', ['userId' => $_['user_uid'], 'size' => 32, 'v' => $_['userAvatarVersion']])); ?>"
142
+								srcset="<?php p(\OC::$server->getURLGenerator()->linkToRoute('core.avatar.getAvatar', ['userId' => $_['user_uid'], 'size' => 64, 'v' => $_['userAvatarVersion']])); ?> 2x, <?php p(\OC::$server->getURLGenerator()->linkToRoute('core.avatar.getAvatar', ['userId' => $_['user_uid'], 'size' => 128, 'v' => $_['userAvatarVersion']])); ?> 4x"
143 143
 								>
144 144
 							<?php endif; ?>
145 145
 						</div>
146 146
 						<div id="expandDisplayName" class="icon-settings-white"></div>
147 147
 					</div>
148 148
 					<nav class="settings-menu" id="expanddiv" style="display:none;"
149
-						aria-label="<?php p($l->t('Settings menu'));?>">
149
+						aria-label="<?php p($l->t('Settings menu')); ?>">
150 150
 					<ul>
151 151
 					<?php foreach ($_['settingsnavigation'] as $entry):?>
152 152
 						<li data-id="<?php p($entry['id']); ?>">
153 153
 							<a href="<?php print_unescaped($entry['href']); ?>"
154 154
 								<?php if ($entry["active"]): ?> class="active"<?php endif; ?>>
155
-								<img alt="" src="<?php print_unescaped($entry['icon'] . '?v=' . $_['versionHash']); ?>">
155
+								<img alt="" src="<?php print_unescaped($entry['icon'].'?v='.$_['versionHash']); ?>">
156 156
 								<?php p($entry['name']) ?>
157 157
 							</a>
158 158
 						</li>
Please login to merge, or discard this patch.
lib/public/INavigationManager.php 1 patch
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -38,65 +38,65 @@
 block discarded – undo
38 38
  */
39 39
 interface INavigationManager {
40 40
 
41
-	/**
42
-	 * Navigation entries of the app navigation
43
-	 * @since 16.0.0
44
-	 */
45
-	public const TYPE_APPS = 'link';
41
+    /**
42
+     * Navigation entries of the app navigation
43
+     * @since 16.0.0
44
+     */
45
+    public const TYPE_APPS = 'link';
46 46
 
47
-	/**
48
-	 * Navigation entries of the settings navigation
49
-	 * @since 16.0.0
50
-	 */
51
-	public const TYPE_SETTINGS = 'settings';
47
+    /**
48
+     * Navigation entries of the settings navigation
49
+     * @since 16.0.0
50
+     */
51
+    public const TYPE_SETTINGS = 'settings';
52 52
 
53
-	/**
54
-	 * Navigation entries for public page footer navigation
55
-	 * @since 16.0.0
56
-	 */
57
-	public const TYPE_GUEST = 'guest';
53
+    /**
54
+     * Navigation entries for public page footer navigation
55
+     * @since 16.0.0
56
+     */
57
+    public const TYPE_GUEST = 'guest';
58 58
 
59
-	/**
60
-	 * Creates a new navigation entry
61
-	 *
62
-	 * @param array|\Closure $entry Array containing: id, name, order, icon and href key
63
-	 *					The use of a closure is preferred, because it will avoid
64
-	 * 					loading the routing of your app, unless required.
65
-	 * @return void
66
-	 * @since 6.0.0
67
-	 */
68
-	public function add($entry);
59
+    /**
60
+     * Creates a new navigation entry
61
+     *
62
+     * @param array|\Closure $entry Array containing: id, name, order, icon and href key
63
+     *					The use of a closure is preferred, because it will avoid
64
+     * 					loading the routing of your app, unless required.
65
+     * @return void
66
+     * @since 6.0.0
67
+     */
68
+    public function add($entry);
69 69
 
70
-	/**
71
-	 * Sets the current navigation entry of the currently running app
72
-	 * @param string $appId id of the app entry to activate (from added $entry)
73
-	 * @return void
74
-	 * @since 6.0.0
75
-	 */
76
-	public function setActiveEntry($appId);
70
+    /**
71
+     * Sets the current navigation entry of the currently running app
72
+     * @param string $appId id of the app entry to activate (from added $entry)
73
+     * @return void
74
+     * @since 6.0.0
75
+     */
76
+    public function setActiveEntry($appId);
77 77
 
78
-	/**
79
-	 * Get the current navigation entry of the currently running app
80
-	 * @return string
81
-	 * @since 20.0.0
82
-	 */
83
-	public function getActiveEntry();
78
+    /**
79
+     * Get the current navigation entry of the currently running app
80
+     * @return string
81
+     * @since 20.0.0
82
+     */
83
+    public function getActiveEntry();
84 84
 
85
-	/**
86
-	 * Get a list of navigation entries
87
-	 *
88
-	 * @param string $type type of the navigation entries
89
-	 * @return array
90
-	 * @since 14.0.0
91
-	 */
92
-	public function getAll(string $type = self::TYPE_APPS): array;
85
+    /**
86
+     * Get a list of navigation entries
87
+     *
88
+     * @param string $type type of the navigation entries
89
+     * @return array
90
+     * @since 14.0.0
91
+     */
92
+    public function getAll(string $type = self::TYPE_APPS): array;
93 93
 
94
-	/**
95
-	 * Set an unread counter for navigation entries
96
-	 *
97
-	 * @param string $id id of the navigation entry
98
-	 * @param int $unreadCounter Number of unread entries (0 to hide the counter which is the default)
99
-	 * @since 22.0.0
100
-	 */
101
-	public function setUnreadCounter(string $id, int $unreadCounter): void;
94
+    /**
95
+     * Set an unread counter for navigation entries
96
+     *
97
+     * @param string $id id of the navigation entry
98
+     * @param int $unreadCounter Number of unread entries (0 to hide the counter which is the default)
99
+     * @since 22.0.0
100
+     */
101
+    public function setUnreadCounter(string $id, int $unreadCounter): void;
102 102
 }
Please login to merge, or discard this patch.
lib/private/NavigationManager.php 1 patch
Indentation   +283 added lines, -283 removed lines patch added patch discarded remove patch
@@ -46,287 +46,287 @@
 block discarded – undo
46 46
  */
47 47
 
48 48
 class NavigationManager implements INavigationManager {
49
-	protected $entries = [];
50
-	protected $closureEntries = [];
51
-	protected $activeEntry;
52
-	protected $unreadCounters = [];
53
-
54
-	/** @var bool */
55
-	protected $init = false;
56
-	/** @var IAppManager|AppManager */
57
-	protected $appManager;
58
-	/** @var IURLGenerator */
59
-	private $urlGenerator;
60
-	/** @var IFactory */
61
-	private $l10nFac;
62
-	/** @var IUserSession */
63
-	private $userSession;
64
-	/** @var IGroupManager|Manager */
65
-	private $groupManager;
66
-	/** @var IConfig */
67
-	private $config;
68
-
69
-	public function __construct(IAppManager $appManager,
70
-						 IURLGenerator $urlGenerator,
71
-						 IFactory $l10nFac,
72
-						 IUserSession $userSession,
73
-						 IGroupManager $groupManager,
74
-						 IConfig $config) {
75
-		$this->appManager = $appManager;
76
-		$this->urlGenerator = $urlGenerator;
77
-		$this->l10nFac = $l10nFac;
78
-		$this->userSession = $userSession;
79
-		$this->groupManager = $groupManager;
80
-		$this->config = $config;
81
-	}
82
-
83
-	/**
84
-	 * @inheritDoc
85
-	 */
86
-	public function add($entry) {
87
-		if ($entry instanceof \Closure) {
88
-			$this->closureEntries[] = $entry;
89
-			return;
90
-		}
91
-
92
-		$entry['active'] = false;
93
-		if (!isset($entry['icon'])) {
94
-			$entry['icon'] = '';
95
-		}
96
-		if (!isset($entry['classes'])) {
97
-			$entry['classes'] = '';
98
-		}
99
-		if (!isset($entry['type'])) {
100
-			$entry['type'] = 'link';
101
-		}
102
-
103
-		$id = $entry['id'];
104
-		$entry['unread'] = isset($this->unreadCounters[$id]) ? $this->unreadCounters[$id] : 0;
105
-
106
-		$this->entries[$id] = $entry;
107
-	}
108
-
109
-	/**
110
-	 * @inheritDoc
111
-	 */
112
-	public function getAll(string $type = 'link'): array {
113
-		$this->init();
114
-		foreach ($this->closureEntries as $c) {
115
-			$this->add($c());
116
-		}
117
-		$this->closureEntries = [];
118
-
119
-		$result = $this->entries;
120
-		if ($type !== 'all') {
121
-			$result = array_filter($this->entries, function ($entry) use ($type) {
122
-				return $entry['type'] === $type;
123
-			});
124
-		}
125
-
126
-		return $this->proceedNavigation($result);
127
-	}
128
-
129
-	/**
130
-	 * Sort navigation entries by order, name and set active flag
131
-	 *
132
-	 * @param array $list
133
-	 * @return array
134
-	 */
135
-	private function proceedNavigation(array $list): array {
136
-		uasort($list, function ($a, $b) {
137
-			if (isset($a['order']) && isset($b['order'])) {
138
-				return ($a['order'] < $b['order']) ? -1 : 1;
139
-			} elseif (isset($a['order']) || isset($b['order'])) {
140
-				return isset($a['order']) ? -1 : 1;
141
-			} else {
142
-				return ($a['name'] < $b['name']) ? -1 : 1;
143
-			}
144
-		});
145
-
146
-		$activeApp = $this->getActiveEntry();
147
-		if ($activeApp !== null) {
148
-			foreach ($list as $index => &$navEntry) {
149
-				if ($navEntry['id'] == $activeApp) {
150
-					$navEntry['active'] = true;
151
-				} else {
152
-					$navEntry['active'] = false;
153
-				}
154
-			}
155
-			unset($navEntry);
156
-		}
157
-
158
-		return $list;
159
-	}
160
-
161
-
162
-	/**
163
-	 * removes all the entries
164
-	 */
165
-	public function clear($loadDefaultLinks = true) {
166
-		$this->entries = [];
167
-		$this->closureEntries = [];
168
-		$this->init = !$loadDefaultLinks;
169
-	}
170
-
171
-	/**
172
-	 * @inheritDoc
173
-	 */
174
-	public function setActiveEntry($id) {
175
-		$this->activeEntry = $id;
176
-	}
177
-
178
-	/**
179
-	 * @inheritDoc
180
-	 */
181
-	public function getActiveEntry() {
182
-		return $this->activeEntry;
183
-	}
184
-
185
-	private function init() {
186
-		if ($this->init) {
187
-			return;
188
-		}
189
-		$this->init = true;
190
-
191
-		$l = $this->l10nFac->get('lib');
192
-		if ($this->config->getSystemValue('knowledgebaseenabled', true)) {
193
-			$this->add([
194
-				'type' => 'settings',
195
-				'id' => 'help',
196
-				'order' => 6,
197
-				'href' => $this->urlGenerator->linkToRoute('settings.Help.help'),
198
-				'name' => $l->t('Help'),
199
-				'icon' => $this->urlGenerator->imagePath('settings', 'help.svg'),
200
-			]);
201
-		}
202
-
203
-		if ($this->userSession->isLoggedIn()) {
204
-			if ($this->isAdmin()) {
205
-				// App management
206
-				$this->add([
207
-					'type' => 'settings',
208
-					'id' => 'core_apps',
209
-					'order' => 4,
210
-					'href' => $this->urlGenerator->linkToRoute('settings.AppSettings.viewApps'),
211
-					'icon' => $this->urlGenerator->imagePath('settings', 'apps.svg'),
212
-					'name' => $l->t('Apps'),
213
-				]);
214
-			}
215
-
216
-			// Personal and (if applicable) admin settings
217
-			$this->add([
218
-				'type' => 'settings',
219
-				'id' => 'settings',
220
-				'order' => 2,
221
-				'href' => $this->urlGenerator->linkToRoute('settings.PersonalSettings.index'),
222
-				'name' => $l->t('Settings'),
223
-				'icon' => $this->urlGenerator->imagePath('settings', 'admin.svg'),
224
-			]);
225
-
226
-			$logoutUrl = \OC_User::getLogoutUrl($this->urlGenerator);
227
-			if ($logoutUrl !== '') {
228
-				// Logout
229
-				$this->add([
230
-					'type' => 'settings',
231
-					'id' => 'logout',
232
-					'order' => 99999,
233
-					'href' => $logoutUrl,
234
-					'name' => $l->t('Log out'),
235
-					'icon' => $this->urlGenerator->imagePath('core', 'actions/logout.svg'),
236
-				]);
237
-			}
238
-
239
-			if ($this->isSubadmin()) {
240
-				// User management
241
-				$this->add([
242
-					'type' => 'settings',
243
-					'id' => 'core_users',
244
-					'order' => 5,
245
-					'href' => $this->urlGenerator->linkToRoute('settings.Users.usersList'),
246
-					'name' => $l->t('Users'),
247
-					'icon' => $this->urlGenerator->imagePath('settings', 'users.svg'),
248
-				]);
249
-			}
250
-		}
251
-
252
-		if ($this->appManager === 'null') {
253
-			return;
254
-		}
255
-
256
-		if ($this->userSession->isLoggedIn()) {
257
-			$apps = $this->appManager->getEnabledAppsForUser($this->userSession->getUser());
258
-		} else {
259
-			$apps = $this->appManager->getInstalledApps();
260
-		}
261
-
262
-		foreach ($apps as $app) {
263
-			if (!$this->userSession->isLoggedIn() && !$this->appManager->isEnabledForUser($app, $this->userSession->getUser())) {
264
-				continue;
265
-			}
266
-
267
-			// load plugins and collections from info.xml
268
-			$info = $this->appManager->getAppInfo($app);
269
-			if (!isset($info['navigations']['navigation'])) {
270
-				continue;
271
-			}
272
-			foreach ($info['navigations']['navigation'] as $key => $nav) {
273
-				if (!isset($nav['name'])) {
274
-					continue;
275
-				}
276
-				if (!isset($nav['route'])) {
277
-					continue;
278
-				}
279
-				$role = isset($nav['@attributes']['role']) ? $nav['@attributes']['role'] : 'all';
280
-				if ($role === 'admin' && !$this->isAdmin()) {
281
-					continue;
282
-				}
283
-				$l = $this->l10nFac->get($app);
284
-				$id = $nav['id'] ?? $app . ($key === 0 ? '' : $key);
285
-				$order = isset($nav['order']) ? $nav['order'] : 100;
286
-				$type = isset($nav['type']) ? $nav['type'] : 'link';
287
-				$route = $nav['route'] !== '' ? $this->urlGenerator->linkToRoute($nav['route']) : '';
288
-				$icon = isset($nav['icon']) ? $nav['icon'] : 'app.svg';
289
-				foreach ([$icon, "$app.svg"] as $i) {
290
-					try {
291
-						$icon = $this->urlGenerator->imagePath($app, $i);
292
-						break;
293
-					} catch (\RuntimeException $ex) {
294
-						// no icon? - ignore it then
295
-					}
296
-				}
297
-				if ($icon === null) {
298
-					$icon = $this->urlGenerator->imagePath('core', 'default-app-icon');
299
-				}
300
-
301
-				$this->add([
302
-					'id' => $id,
303
-					'order' => $order,
304
-					'href' => $route,
305
-					'icon' => $icon,
306
-					'type' => $type,
307
-					'name' => $l->t($nav['name']),
308
-				]);
309
-			}
310
-		}
311
-	}
312
-
313
-	private function isAdmin() {
314
-		$user = $this->userSession->getUser();
315
-		if ($user !== null) {
316
-			return $this->groupManager->isAdmin($user->getUID());
317
-		}
318
-		return false;
319
-	}
320
-
321
-	private function isSubadmin() {
322
-		$user = $this->userSession->getUser();
323
-		if ($user !== null) {
324
-			return $this->groupManager->getSubAdmin()->isSubAdmin($user);
325
-		}
326
-		return false;
327
-	}
328
-
329
-	public function setUnreadCounter(string $id, int $unreadCounter): void {
330
-		$this->unreadCounters[$id] = $unreadCounter;
331
-	}
49
+    protected $entries = [];
50
+    protected $closureEntries = [];
51
+    protected $activeEntry;
52
+    protected $unreadCounters = [];
53
+
54
+    /** @var bool */
55
+    protected $init = false;
56
+    /** @var IAppManager|AppManager */
57
+    protected $appManager;
58
+    /** @var IURLGenerator */
59
+    private $urlGenerator;
60
+    /** @var IFactory */
61
+    private $l10nFac;
62
+    /** @var IUserSession */
63
+    private $userSession;
64
+    /** @var IGroupManager|Manager */
65
+    private $groupManager;
66
+    /** @var IConfig */
67
+    private $config;
68
+
69
+    public function __construct(IAppManager $appManager,
70
+                            IURLGenerator $urlGenerator,
71
+                            IFactory $l10nFac,
72
+                            IUserSession $userSession,
73
+                            IGroupManager $groupManager,
74
+                            IConfig $config) {
75
+        $this->appManager = $appManager;
76
+        $this->urlGenerator = $urlGenerator;
77
+        $this->l10nFac = $l10nFac;
78
+        $this->userSession = $userSession;
79
+        $this->groupManager = $groupManager;
80
+        $this->config = $config;
81
+    }
82
+
83
+    /**
84
+     * @inheritDoc
85
+     */
86
+    public function add($entry) {
87
+        if ($entry instanceof \Closure) {
88
+            $this->closureEntries[] = $entry;
89
+            return;
90
+        }
91
+
92
+        $entry['active'] = false;
93
+        if (!isset($entry['icon'])) {
94
+            $entry['icon'] = '';
95
+        }
96
+        if (!isset($entry['classes'])) {
97
+            $entry['classes'] = '';
98
+        }
99
+        if (!isset($entry['type'])) {
100
+            $entry['type'] = 'link';
101
+        }
102
+
103
+        $id = $entry['id'];
104
+        $entry['unread'] = isset($this->unreadCounters[$id]) ? $this->unreadCounters[$id] : 0;
105
+
106
+        $this->entries[$id] = $entry;
107
+    }
108
+
109
+    /**
110
+     * @inheritDoc
111
+     */
112
+    public function getAll(string $type = 'link'): array {
113
+        $this->init();
114
+        foreach ($this->closureEntries as $c) {
115
+            $this->add($c());
116
+        }
117
+        $this->closureEntries = [];
118
+
119
+        $result = $this->entries;
120
+        if ($type !== 'all') {
121
+            $result = array_filter($this->entries, function ($entry) use ($type) {
122
+                return $entry['type'] === $type;
123
+            });
124
+        }
125
+
126
+        return $this->proceedNavigation($result);
127
+    }
128
+
129
+    /**
130
+     * Sort navigation entries by order, name and set active flag
131
+     *
132
+     * @param array $list
133
+     * @return array
134
+     */
135
+    private function proceedNavigation(array $list): array {
136
+        uasort($list, function ($a, $b) {
137
+            if (isset($a['order']) && isset($b['order'])) {
138
+                return ($a['order'] < $b['order']) ? -1 : 1;
139
+            } elseif (isset($a['order']) || isset($b['order'])) {
140
+                return isset($a['order']) ? -1 : 1;
141
+            } else {
142
+                return ($a['name'] < $b['name']) ? -1 : 1;
143
+            }
144
+        });
145
+
146
+        $activeApp = $this->getActiveEntry();
147
+        if ($activeApp !== null) {
148
+            foreach ($list as $index => &$navEntry) {
149
+                if ($navEntry['id'] == $activeApp) {
150
+                    $navEntry['active'] = true;
151
+                } else {
152
+                    $navEntry['active'] = false;
153
+                }
154
+            }
155
+            unset($navEntry);
156
+        }
157
+
158
+        return $list;
159
+    }
160
+
161
+
162
+    /**
163
+     * removes all the entries
164
+     */
165
+    public function clear($loadDefaultLinks = true) {
166
+        $this->entries = [];
167
+        $this->closureEntries = [];
168
+        $this->init = !$loadDefaultLinks;
169
+    }
170
+
171
+    /**
172
+     * @inheritDoc
173
+     */
174
+    public function setActiveEntry($id) {
175
+        $this->activeEntry = $id;
176
+    }
177
+
178
+    /**
179
+     * @inheritDoc
180
+     */
181
+    public function getActiveEntry() {
182
+        return $this->activeEntry;
183
+    }
184
+
185
+    private function init() {
186
+        if ($this->init) {
187
+            return;
188
+        }
189
+        $this->init = true;
190
+
191
+        $l = $this->l10nFac->get('lib');
192
+        if ($this->config->getSystemValue('knowledgebaseenabled', true)) {
193
+            $this->add([
194
+                'type' => 'settings',
195
+                'id' => 'help',
196
+                'order' => 6,
197
+                'href' => $this->urlGenerator->linkToRoute('settings.Help.help'),
198
+                'name' => $l->t('Help'),
199
+                'icon' => $this->urlGenerator->imagePath('settings', 'help.svg'),
200
+            ]);
201
+        }
202
+
203
+        if ($this->userSession->isLoggedIn()) {
204
+            if ($this->isAdmin()) {
205
+                // App management
206
+                $this->add([
207
+                    'type' => 'settings',
208
+                    'id' => 'core_apps',
209
+                    'order' => 4,
210
+                    'href' => $this->urlGenerator->linkToRoute('settings.AppSettings.viewApps'),
211
+                    'icon' => $this->urlGenerator->imagePath('settings', 'apps.svg'),
212
+                    'name' => $l->t('Apps'),
213
+                ]);
214
+            }
215
+
216
+            // Personal and (if applicable) admin settings
217
+            $this->add([
218
+                'type' => 'settings',
219
+                'id' => 'settings',
220
+                'order' => 2,
221
+                'href' => $this->urlGenerator->linkToRoute('settings.PersonalSettings.index'),
222
+                'name' => $l->t('Settings'),
223
+                'icon' => $this->urlGenerator->imagePath('settings', 'admin.svg'),
224
+            ]);
225
+
226
+            $logoutUrl = \OC_User::getLogoutUrl($this->urlGenerator);
227
+            if ($logoutUrl !== '') {
228
+                // Logout
229
+                $this->add([
230
+                    'type' => 'settings',
231
+                    'id' => 'logout',
232
+                    'order' => 99999,
233
+                    'href' => $logoutUrl,
234
+                    'name' => $l->t('Log out'),
235
+                    'icon' => $this->urlGenerator->imagePath('core', 'actions/logout.svg'),
236
+                ]);
237
+            }
238
+
239
+            if ($this->isSubadmin()) {
240
+                // User management
241
+                $this->add([
242
+                    'type' => 'settings',
243
+                    'id' => 'core_users',
244
+                    'order' => 5,
245
+                    'href' => $this->urlGenerator->linkToRoute('settings.Users.usersList'),
246
+                    'name' => $l->t('Users'),
247
+                    'icon' => $this->urlGenerator->imagePath('settings', 'users.svg'),
248
+                ]);
249
+            }
250
+        }
251
+
252
+        if ($this->appManager === 'null') {
253
+            return;
254
+        }
255
+
256
+        if ($this->userSession->isLoggedIn()) {
257
+            $apps = $this->appManager->getEnabledAppsForUser($this->userSession->getUser());
258
+        } else {
259
+            $apps = $this->appManager->getInstalledApps();
260
+        }
261
+
262
+        foreach ($apps as $app) {
263
+            if (!$this->userSession->isLoggedIn() && !$this->appManager->isEnabledForUser($app, $this->userSession->getUser())) {
264
+                continue;
265
+            }
266
+
267
+            // load plugins and collections from info.xml
268
+            $info = $this->appManager->getAppInfo($app);
269
+            if (!isset($info['navigations']['navigation'])) {
270
+                continue;
271
+            }
272
+            foreach ($info['navigations']['navigation'] as $key => $nav) {
273
+                if (!isset($nav['name'])) {
274
+                    continue;
275
+                }
276
+                if (!isset($nav['route'])) {
277
+                    continue;
278
+                }
279
+                $role = isset($nav['@attributes']['role']) ? $nav['@attributes']['role'] : 'all';
280
+                if ($role === 'admin' && !$this->isAdmin()) {
281
+                    continue;
282
+                }
283
+                $l = $this->l10nFac->get($app);
284
+                $id = $nav['id'] ?? $app . ($key === 0 ? '' : $key);
285
+                $order = isset($nav['order']) ? $nav['order'] : 100;
286
+                $type = isset($nav['type']) ? $nav['type'] : 'link';
287
+                $route = $nav['route'] !== '' ? $this->urlGenerator->linkToRoute($nav['route']) : '';
288
+                $icon = isset($nav['icon']) ? $nav['icon'] : 'app.svg';
289
+                foreach ([$icon, "$app.svg"] as $i) {
290
+                    try {
291
+                        $icon = $this->urlGenerator->imagePath($app, $i);
292
+                        break;
293
+                    } catch (\RuntimeException $ex) {
294
+                        // no icon? - ignore it then
295
+                    }
296
+                }
297
+                if ($icon === null) {
298
+                    $icon = $this->urlGenerator->imagePath('core', 'default-app-icon');
299
+                }
300
+
301
+                $this->add([
302
+                    'id' => $id,
303
+                    'order' => $order,
304
+                    'href' => $route,
305
+                    'icon' => $icon,
306
+                    'type' => $type,
307
+                    'name' => $l->t($nav['name']),
308
+                ]);
309
+            }
310
+        }
311
+    }
312
+
313
+    private function isAdmin() {
314
+        $user = $this->userSession->getUser();
315
+        if ($user !== null) {
316
+            return $this->groupManager->isAdmin($user->getUID());
317
+        }
318
+        return false;
319
+    }
320
+
321
+    private function isSubadmin() {
322
+        $user = $this->userSession->getUser();
323
+        if ($user !== null) {
324
+            return $this->groupManager->getSubAdmin()->isSubAdmin($user);
325
+        }
326
+        return false;
327
+    }
328
+
329
+    public function setUnreadCounter(string $id, int $unreadCounter): void {
330
+        $this->unreadCounters[$id] = $unreadCounter;
331
+    }
332 332
 }
Please login to merge, or discard this patch.