@@ -46,320 +46,320 @@ |
||
| 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' => 99998, |
|
| 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 | - // Accessibility settings |
|
| 205 | - if ($this->appManager->isEnabledForUser('theming', $this->userSession->getUser())) { |
|
| 206 | - $this->add([ |
|
| 207 | - 'type' => 'settings', |
|
| 208 | - 'id' => 'accessibility_settings', |
|
| 209 | - 'order' => 2, |
|
| 210 | - 'href' => $this->urlGenerator->linkToRoute('settings.PersonalSettings.index', ['section' => 'theming']), |
|
| 211 | - 'name' => $l->t('Appearance and accessibility'), |
|
| 212 | - 'icon' => $this->urlGenerator->imagePath('theming', 'accessibility-dark.svg'), |
|
| 213 | - ]); |
|
| 214 | - } |
|
| 215 | - if ($this->isAdmin()) { |
|
| 216 | - // App management |
|
| 217 | - $this->add([ |
|
| 218 | - 'type' => 'settings', |
|
| 219 | - 'id' => 'core_apps', |
|
| 220 | - 'order' => 5, |
|
| 221 | - 'href' => $this->urlGenerator->linkToRoute('settings.AppSettings.viewApps'), |
|
| 222 | - 'icon' => $this->urlGenerator->imagePath('settings', 'apps.svg'), |
|
| 223 | - 'name' => $l->t('Apps'), |
|
| 224 | - ]); |
|
| 225 | - |
|
| 226 | - // Personal settings |
|
| 227 | - $this->add([ |
|
| 228 | - 'type' => 'settings', |
|
| 229 | - 'id' => 'settings', |
|
| 230 | - 'order' => 3, |
|
| 231 | - 'href' => $this->urlGenerator->linkToRoute('settings.PersonalSettings.index'), |
|
| 232 | - 'name' => $l->t('Personal settings'), |
|
| 233 | - 'icon' => $this->urlGenerator->imagePath('settings', 'personal.svg'), |
|
| 234 | - ]); |
|
| 235 | - |
|
| 236 | - // Admin settings |
|
| 237 | - $this->add([ |
|
| 238 | - 'type' => 'settings', |
|
| 239 | - 'id' => 'admin_settings', |
|
| 240 | - 'order' => 4, |
|
| 241 | - 'href' => $this->urlGenerator->linkToRoute('settings.AdminSettings.index', ['section' => 'overview']), |
|
| 242 | - 'name' => $l->t('Administration settings'), |
|
| 243 | - 'icon' => $this->urlGenerator->imagePath('settings', 'admin.svg'), |
|
| 244 | - ]); |
|
| 245 | - } else { |
|
| 246 | - // Personal settings |
|
| 247 | - $this->add([ |
|
| 248 | - 'type' => 'settings', |
|
| 249 | - 'id' => 'settings', |
|
| 250 | - 'order' => 3, |
|
| 251 | - 'href' => $this->urlGenerator->linkToRoute('settings.PersonalSettings.index'), |
|
| 252 | - 'name' => $l->t('Settings'), |
|
| 253 | - 'icon' => $this->urlGenerator->imagePath('settings', 'admin.svg'), |
|
| 254 | - ]); |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - $logoutUrl = \OC_User::getLogoutUrl($this->urlGenerator); |
|
| 258 | - if ($logoutUrl !== '') { |
|
| 259 | - // Logout |
|
| 260 | - $this->add([ |
|
| 261 | - 'type' => 'settings', |
|
| 262 | - 'id' => 'logout', |
|
| 263 | - 'order' => 99999, |
|
| 264 | - 'href' => $logoutUrl, |
|
| 265 | - 'name' => $l->t('Log out'), |
|
| 266 | - 'icon' => $this->urlGenerator->imagePath('core', 'actions/logout.svg'), |
|
| 267 | - ]); |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - if ($this->isSubadmin()) { |
|
| 271 | - // User management |
|
| 272 | - $this->add([ |
|
| 273 | - 'type' => 'settings', |
|
| 274 | - 'id' => 'core_users', |
|
| 275 | - 'order' => 6, |
|
| 276 | - 'href' => $this->urlGenerator->linkToRoute('settings.Users.usersList'), |
|
| 277 | - 'name' => $l->t('Users'), |
|
| 278 | - 'icon' => $this->urlGenerator->imagePath('settings', 'users.svg'), |
|
| 279 | - ]); |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - if ($this->appManager === 'null') { |
|
| 284 | - return; |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - if ($this->userSession->isLoggedIn()) { |
|
| 288 | - $apps = $this->appManager->getEnabledAppsForUser($this->userSession->getUser()); |
|
| 289 | - } else { |
|
| 290 | - $apps = $this->appManager->getInstalledApps(); |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - foreach ($apps as $app) { |
|
| 294 | - if (!$this->userSession->isLoggedIn() && !$this->appManager->isEnabledForUser($app, $this->userSession->getUser())) { |
|
| 295 | - continue; |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - // load plugins and collections from info.xml |
|
| 299 | - $info = $this->appManager->getAppInfo($app); |
|
| 300 | - if (!isset($info['navigations']['navigation'])) { |
|
| 301 | - continue; |
|
| 302 | - } |
|
| 303 | - foreach ($info['navigations']['navigation'] as $key => $nav) { |
|
| 304 | - $nav['type'] = $nav['type'] ?? 'link'; |
|
| 305 | - if (!isset($nav['name'])) { |
|
| 306 | - continue; |
|
| 307 | - } |
|
| 308 | - // Allow settings navigation items with no route entry, all other types require one |
|
| 309 | - if (!isset($nav['route']) && $nav['type'] !== 'settings') { |
|
| 310 | - continue; |
|
| 311 | - } |
|
| 312 | - $role = isset($nav['@attributes']['role']) ? $nav['@attributes']['role'] : 'all'; |
|
| 313 | - if ($role === 'admin' && !$this->isAdmin()) { |
|
| 314 | - continue; |
|
| 315 | - } |
|
| 316 | - $l = $this->l10nFac->get($app); |
|
| 317 | - $id = $nav['id'] ?? $app . ($key === 0 ? '' : $key); |
|
| 318 | - $order = isset($nav['order']) ? $nav['order'] : 100; |
|
| 319 | - $type = $nav['type']; |
|
| 320 | - $route = !empty($nav['route']) ? $this->urlGenerator->linkToRoute($nav['route']) : ''; |
|
| 321 | - $icon = isset($nav['icon']) ? $nav['icon'] : 'app.svg'; |
|
| 322 | - foreach ([$icon, "$app.svg"] as $i) { |
|
| 323 | - try { |
|
| 324 | - $icon = $this->urlGenerator->imagePath($app, $i); |
|
| 325 | - break; |
|
| 326 | - } catch (\RuntimeException $ex) { |
|
| 327 | - // no icon? - ignore it then |
|
| 328 | - } |
|
| 329 | - } |
|
| 330 | - if ($icon === null) { |
|
| 331 | - $icon = $this->urlGenerator->imagePath('core', 'default-app-icon'); |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - $this->add([ |
|
| 335 | - 'id' => $id, |
|
| 336 | - 'order' => $order, |
|
| 337 | - 'href' => $route, |
|
| 338 | - 'icon' => $icon, |
|
| 339 | - 'type' => $type, |
|
| 340 | - 'name' => $l->t($nav['name']), |
|
| 341 | - ]); |
|
| 342 | - } |
|
| 343 | - } |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - private function isAdmin() { |
|
| 347 | - $user = $this->userSession->getUser(); |
|
| 348 | - if ($user !== null) { |
|
| 349 | - return $this->groupManager->isAdmin($user->getUID()); |
|
| 350 | - } |
|
| 351 | - return false; |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - private function isSubadmin() { |
|
| 355 | - $user = $this->userSession->getUser(); |
|
| 356 | - if ($user !== null) { |
|
| 357 | - return $this->groupManager->getSubAdmin()->isSubAdmin($user); |
|
| 358 | - } |
|
| 359 | - return false; |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - public function setUnreadCounter(string $id, int $unreadCounter): void { |
|
| 363 | - $this->unreadCounters[$id] = $unreadCounter; |
|
| 364 | - } |
|
| 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' => 99998, |
|
| 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 | + // Accessibility settings |
|
| 205 | + if ($this->appManager->isEnabledForUser('theming', $this->userSession->getUser())) { |
|
| 206 | + $this->add([ |
|
| 207 | + 'type' => 'settings', |
|
| 208 | + 'id' => 'accessibility_settings', |
|
| 209 | + 'order' => 2, |
|
| 210 | + 'href' => $this->urlGenerator->linkToRoute('settings.PersonalSettings.index', ['section' => 'theming']), |
|
| 211 | + 'name' => $l->t('Appearance and accessibility'), |
|
| 212 | + 'icon' => $this->urlGenerator->imagePath('theming', 'accessibility-dark.svg'), |
|
| 213 | + ]); |
|
| 214 | + } |
|
| 215 | + if ($this->isAdmin()) { |
|
| 216 | + // App management |
|
| 217 | + $this->add([ |
|
| 218 | + 'type' => 'settings', |
|
| 219 | + 'id' => 'core_apps', |
|
| 220 | + 'order' => 5, |
|
| 221 | + 'href' => $this->urlGenerator->linkToRoute('settings.AppSettings.viewApps'), |
|
| 222 | + 'icon' => $this->urlGenerator->imagePath('settings', 'apps.svg'), |
|
| 223 | + 'name' => $l->t('Apps'), |
|
| 224 | + ]); |
|
| 225 | + |
|
| 226 | + // Personal settings |
|
| 227 | + $this->add([ |
|
| 228 | + 'type' => 'settings', |
|
| 229 | + 'id' => 'settings', |
|
| 230 | + 'order' => 3, |
|
| 231 | + 'href' => $this->urlGenerator->linkToRoute('settings.PersonalSettings.index'), |
|
| 232 | + 'name' => $l->t('Personal settings'), |
|
| 233 | + 'icon' => $this->urlGenerator->imagePath('settings', 'personal.svg'), |
|
| 234 | + ]); |
|
| 235 | + |
|
| 236 | + // Admin settings |
|
| 237 | + $this->add([ |
|
| 238 | + 'type' => 'settings', |
|
| 239 | + 'id' => 'admin_settings', |
|
| 240 | + 'order' => 4, |
|
| 241 | + 'href' => $this->urlGenerator->linkToRoute('settings.AdminSettings.index', ['section' => 'overview']), |
|
| 242 | + 'name' => $l->t('Administration settings'), |
|
| 243 | + 'icon' => $this->urlGenerator->imagePath('settings', 'admin.svg'), |
|
| 244 | + ]); |
|
| 245 | + } else { |
|
| 246 | + // Personal settings |
|
| 247 | + $this->add([ |
|
| 248 | + 'type' => 'settings', |
|
| 249 | + 'id' => 'settings', |
|
| 250 | + 'order' => 3, |
|
| 251 | + 'href' => $this->urlGenerator->linkToRoute('settings.PersonalSettings.index'), |
|
| 252 | + 'name' => $l->t('Settings'), |
|
| 253 | + 'icon' => $this->urlGenerator->imagePath('settings', 'admin.svg'), |
|
| 254 | + ]); |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + $logoutUrl = \OC_User::getLogoutUrl($this->urlGenerator); |
|
| 258 | + if ($logoutUrl !== '') { |
|
| 259 | + // Logout |
|
| 260 | + $this->add([ |
|
| 261 | + 'type' => 'settings', |
|
| 262 | + 'id' => 'logout', |
|
| 263 | + 'order' => 99999, |
|
| 264 | + 'href' => $logoutUrl, |
|
| 265 | + 'name' => $l->t('Log out'), |
|
| 266 | + 'icon' => $this->urlGenerator->imagePath('core', 'actions/logout.svg'), |
|
| 267 | + ]); |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + if ($this->isSubadmin()) { |
|
| 271 | + // User management |
|
| 272 | + $this->add([ |
|
| 273 | + 'type' => 'settings', |
|
| 274 | + 'id' => 'core_users', |
|
| 275 | + 'order' => 6, |
|
| 276 | + 'href' => $this->urlGenerator->linkToRoute('settings.Users.usersList'), |
|
| 277 | + 'name' => $l->t('Users'), |
|
| 278 | + 'icon' => $this->urlGenerator->imagePath('settings', 'users.svg'), |
|
| 279 | + ]); |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + if ($this->appManager === 'null') { |
|
| 284 | + return; |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + if ($this->userSession->isLoggedIn()) { |
|
| 288 | + $apps = $this->appManager->getEnabledAppsForUser($this->userSession->getUser()); |
|
| 289 | + } else { |
|
| 290 | + $apps = $this->appManager->getInstalledApps(); |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + foreach ($apps as $app) { |
|
| 294 | + if (!$this->userSession->isLoggedIn() && !$this->appManager->isEnabledForUser($app, $this->userSession->getUser())) { |
|
| 295 | + continue; |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + // load plugins and collections from info.xml |
|
| 299 | + $info = $this->appManager->getAppInfo($app); |
|
| 300 | + if (!isset($info['navigations']['navigation'])) { |
|
| 301 | + continue; |
|
| 302 | + } |
|
| 303 | + foreach ($info['navigations']['navigation'] as $key => $nav) { |
|
| 304 | + $nav['type'] = $nav['type'] ?? 'link'; |
|
| 305 | + if (!isset($nav['name'])) { |
|
| 306 | + continue; |
|
| 307 | + } |
|
| 308 | + // Allow settings navigation items with no route entry, all other types require one |
|
| 309 | + if (!isset($nav['route']) && $nav['type'] !== 'settings') { |
|
| 310 | + continue; |
|
| 311 | + } |
|
| 312 | + $role = isset($nav['@attributes']['role']) ? $nav['@attributes']['role'] : 'all'; |
|
| 313 | + if ($role === 'admin' && !$this->isAdmin()) { |
|
| 314 | + continue; |
|
| 315 | + } |
|
| 316 | + $l = $this->l10nFac->get($app); |
|
| 317 | + $id = $nav['id'] ?? $app . ($key === 0 ? '' : $key); |
|
| 318 | + $order = isset($nav['order']) ? $nav['order'] : 100; |
|
| 319 | + $type = $nav['type']; |
|
| 320 | + $route = !empty($nav['route']) ? $this->urlGenerator->linkToRoute($nav['route']) : ''; |
|
| 321 | + $icon = isset($nav['icon']) ? $nav['icon'] : 'app.svg'; |
|
| 322 | + foreach ([$icon, "$app.svg"] as $i) { |
|
| 323 | + try { |
|
| 324 | + $icon = $this->urlGenerator->imagePath($app, $i); |
|
| 325 | + break; |
|
| 326 | + } catch (\RuntimeException $ex) { |
|
| 327 | + // no icon? - ignore it then |
|
| 328 | + } |
|
| 329 | + } |
|
| 330 | + if ($icon === null) { |
|
| 331 | + $icon = $this->urlGenerator->imagePath('core', 'default-app-icon'); |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + $this->add([ |
|
| 335 | + 'id' => $id, |
|
| 336 | + 'order' => $order, |
|
| 337 | + 'href' => $route, |
|
| 338 | + 'icon' => $icon, |
|
| 339 | + 'type' => $type, |
|
| 340 | + 'name' => $l->t($nav['name']), |
|
| 341 | + ]); |
|
| 342 | + } |
|
| 343 | + } |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + private function isAdmin() { |
|
| 347 | + $user = $this->userSession->getUser(); |
|
| 348 | + if ($user !== null) { |
|
| 349 | + return $this->groupManager->isAdmin($user->getUID()); |
|
| 350 | + } |
|
| 351 | + return false; |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + private function isSubadmin() { |
|
| 355 | + $user = $this->userSession->getUser(); |
|
| 356 | + if ($user !== null) { |
|
| 357 | + return $this->groupManager->getSubAdmin()->isSubAdmin($user); |
|
| 358 | + } |
|
| 359 | + return false; |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + public function setUnreadCounter(string $id, int $unreadCounter): void { |
|
| 363 | + $this->unreadCounters[$id] = $unreadCounter; |
|
| 364 | + } |
|
| 365 | 365 | } |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | |
| 119 | 119 | $result = $this->entries; |
| 120 | 120 | if ($type !== 'all') { |
| 121 | - $result = array_filter($this->entries, function ($entry) use ($type) { |
|
| 121 | + $result = array_filter($this->entries, function($entry) use ($type) { |
|
| 122 | 122 | return $entry['type'] === $type; |
| 123 | 123 | }); |
| 124 | 124 | } |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | * @return array |
| 134 | 134 | */ |
| 135 | 135 | private function proceedNavigation(array $list): array { |
| 136 | - uasort($list, function ($a, $b) { |
|
| 136 | + uasort($list, function($a, $b) { |
|
| 137 | 137 | if (isset($a['order']) && isset($b['order'])) { |
| 138 | 138 | return ($a['order'] < $b['order']) ? -1 : 1; |
| 139 | 139 | } elseif (isset($a['order']) || isset($b['order'])) { |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | continue; |
| 315 | 315 | } |
| 316 | 316 | $l = $this->l10nFac->get($app); |
| 317 | - $id = $nav['id'] ?? $app . ($key === 0 ? '' : $key); |
|
| 317 | + $id = $nav['id'] ?? $app.($key === 0 ? '' : $key); |
|
| 318 | 318 | $order = isset($nav['order']) ? $nav['order'] : 100; |
| 319 | 319 | $type = $nav['type']; |
| 320 | 320 | $route = !empty($nav['route']) ? $this->urlGenerator->linkToRoute($nav['route']) : ''; |
@@ -34,254 +34,254 @@ |
||
| 34 | 34 | use function simplexml_load_file; |
| 35 | 35 | |
| 36 | 36 | class InfoParser { |
| 37 | - /** @var \OCP\ICache|null */ |
|
| 38 | - private $cache; |
|
| 37 | + /** @var \OCP\ICache|null */ |
|
| 38 | + private $cache; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @param ICache|null $cache |
|
| 42 | - */ |
|
| 43 | - public function __construct(ICache $cache = null) { |
|
| 44 | - $this->cache = $cache; |
|
| 45 | - } |
|
| 40 | + /** |
|
| 41 | + * @param ICache|null $cache |
|
| 42 | + */ |
|
| 43 | + public function __construct(ICache $cache = null) { |
|
| 44 | + $this->cache = $cache; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @param string $file the xml file to be loaded |
|
| 49 | - * @return null|array where null is an indicator for an error |
|
| 50 | - */ |
|
| 51 | - public function parse($file) { |
|
| 52 | - if (!file_exists($file)) { |
|
| 53 | - return null; |
|
| 54 | - } |
|
| 47 | + /** |
|
| 48 | + * @param string $file the xml file to be loaded |
|
| 49 | + * @return null|array where null is an indicator for an error |
|
| 50 | + */ |
|
| 51 | + public function parse($file) { |
|
| 52 | + if (!file_exists($file)) { |
|
| 53 | + return null; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - if ($this->cache !== null) { |
|
| 57 | - $fileCacheKey = $file . filemtime($file); |
|
| 58 | - if ($cachedValue = $this->cache->get($fileCacheKey)) { |
|
| 59 | - return json_decode($cachedValue, true); |
|
| 60 | - } |
|
| 61 | - } |
|
| 56 | + if ($this->cache !== null) { |
|
| 57 | + $fileCacheKey = $file . filemtime($file); |
|
| 58 | + if ($cachedValue = $this->cache->get($fileCacheKey)) { |
|
| 59 | + return json_decode($cachedValue, true); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - libxml_use_internal_errors(true); |
|
| 64 | - if ((PHP_VERSION_ID < 80000)) { |
|
| 65 | - $loadEntities = libxml_disable_entity_loader(false); |
|
| 66 | - $xml = simplexml_load_file($file); |
|
| 67 | - libxml_disable_entity_loader($loadEntities); |
|
| 68 | - } else { |
|
| 69 | - $xml = simplexml_load_file($file); |
|
| 70 | - } |
|
| 63 | + libxml_use_internal_errors(true); |
|
| 64 | + if ((PHP_VERSION_ID < 80000)) { |
|
| 65 | + $loadEntities = libxml_disable_entity_loader(false); |
|
| 66 | + $xml = simplexml_load_file($file); |
|
| 67 | + libxml_disable_entity_loader($loadEntities); |
|
| 68 | + } else { |
|
| 69 | + $xml = simplexml_load_file($file); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - if ($xml === false) { |
|
| 73 | - libxml_clear_errors(); |
|
| 74 | - return null; |
|
| 75 | - } |
|
| 76 | - $array = $this->xmlToArray($xml); |
|
| 72 | + if ($xml === false) { |
|
| 73 | + libxml_clear_errors(); |
|
| 74 | + return null; |
|
| 75 | + } |
|
| 76 | + $array = $this->xmlToArray($xml); |
|
| 77 | 77 | |
| 78 | - if (is_null($array)) { |
|
| 79 | - return null; |
|
| 80 | - } |
|
| 78 | + if (is_null($array)) { |
|
| 79 | + return null; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - if (!array_key_exists('info', $array)) { |
|
| 83 | - $array['info'] = []; |
|
| 84 | - } |
|
| 85 | - if (!array_key_exists('remote', $array)) { |
|
| 86 | - $array['remote'] = []; |
|
| 87 | - } |
|
| 88 | - if (!array_key_exists('public', $array)) { |
|
| 89 | - $array['public'] = []; |
|
| 90 | - } |
|
| 91 | - if (!array_key_exists('types', $array)) { |
|
| 92 | - $array['types'] = []; |
|
| 93 | - } |
|
| 94 | - if (!array_key_exists('repair-steps', $array)) { |
|
| 95 | - $array['repair-steps'] = []; |
|
| 96 | - } |
|
| 97 | - if (!array_key_exists('install', $array['repair-steps'])) { |
|
| 98 | - $array['repair-steps']['install'] = []; |
|
| 99 | - } |
|
| 100 | - if (!array_key_exists('pre-migration', $array['repair-steps'])) { |
|
| 101 | - $array['repair-steps']['pre-migration'] = []; |
|
| 102 | - } |
|
| 103 | - if (!array_key_exists('post-migration', $array['repair-steps'])) { |
|
| 104 | - $array['repair-steps']['post-migration'] = []; |
|
| 105 | - } |
|
| 106 | - if (!array_key_exists('live-migration', $array['repair-steps'])) { |
|
| 107 | - $array['repair-steps']['live-migration'] = []; |
|
| 108 | - } |
|
| 109 | - if (!array_key_exists('uninstall', $array['repair-steps'])) { |
|
| 110 | - $array['repair-steps']['uninstall'] = []; |
|
| 111 | - } |
|
| 112 | - if (!array_key_exists('background-jobs', $array)) { |
|
| 113 | - $array['background-jobs'] = []; |
|
| 114 | - } |
|
| 115 | - if (!array_key_exists('two-factor-providers', $array)) { |
|
| 116 | - $array['two-factor-providers'] = []; |
|
| 117 | - } |
|
| 118 | - if (!array_key_exists('commands', $array)) { |
|
| 119 | - $array['commands'] = []; |
|
| 120 | - } |
|
| 121 | - if (!array_key_exists('activity', $array)) { |
|
| 122 | - $array['activity'] = []; |
|
| 123 | - } |
|
| 124 | - if (!array_key_exists('filters', $array['activity'])) { |
|
| 125 | - $array['activity']['filters'] = []; |
|
| 126 | - } |
|
| 127 | - if (!array_key_exists('settings', $array['activity'])) { |
|
| 128 | - $array['activity']['settings'] = []; |
|
| 129 | - } |
|
| 130 | - if (!array_key_exists('providers', $array['activity'])) { |
|
| 131 | - $array['activity']['providers'] = []; |
|
| 132 | - } |
|
| 133 | - if (!array_key_exists('settings', $array)) { |
|
| 134 | - $array['settings'] = []; |
|
| 135 | - } |
|
| 136 | - if (!array_key_exists('admin', $array['settings'])) { |
|
| 137 | - $array['settings']['admin'] = []; |
|
| 138 | - } |
|
| 139 | - if (!array_key_exists('admin-section', $array['settings'])) { |
|
| 140 | - $array['settings']['admin-section'] = []; |
|
| 141 | - } |
|
| 142 | - if (!array_key_exists('personal', $array['settings'])) { |
|
| 143 | - $array['settings']['personal'] = []; |
|
| 144 | - } |
|
| 145 | - if (!array_key_exists('personal-section', $array['settings'])) { |
|
| 146 | - $array['settings']['personal-section'] = []; |
|
| 147 | - } |
|
| 82 | + if (!array_key_exists('info', $array)) { |
|
| 83 | + $array['info'] = []; |
|
| 84 | + } |
|
| 85 | + if (!array_key_exists('remote', $array)) { |
|
| 86 | + $array['remote'] = []; |
|
| 87 | + } |
|
| 88 | + if (!array_key_exists('public', $array)) { |
|
| 89 | + $array['public'] = []; |
|
| 90 | + } |
|
| 91 | + if (!array_key_exists('types', $array)) { |
|
| 92 | + $array['types'] = []; |
|
| 93 | + } |
|
| 94 | + if (!array_key_exists('repair-steps', $array)) { |
|
| 95 | + $array['repair-steps'] = []; |
|
| 96 | + } |
|
| 97 | + if (!array_key_exists('install', $array['repair-steps'])) { |
|
| 98 | + $array['repair-steps']['install'] = []; |
|
| 99 | + } |
|
| 100 | + if (!array_key_exists('pre-migration', $array['repair-steps'])) { |
|
| 101 | + $array['repair-steps']['pre-migration'] = []; |
|
| 102 | + } |
|
| 103 | + if (!array_key_exists('post-migration', $array['repair-steps'])) { |
|
| 104 | + $array['repair-steps']['post-migration'] = []; |
|
| 105 | + } |
|
| 106 | + if (!array_key_exists('live-migration', $array['repair-steps'])) { |
|
| 107 | + $array['repair-steps']['live-migration'] = []; |
|
| 108 | + } |
|
| 109 | + if (!array_key_exists('uninstall', $array['repair-steps'])) { |
|
| 110 | + $array['repair-steps']['uninstall'] = []; |
|
| 111 | + } |
|
| 112 | + if (!array_key_exists('background-jobs', $array)) { |
|
| 113 | + $array['background-jobs'] = []; |
|
| 114 | + } |
|
| 115 | + if (!array_key_exists('two-factor-providers', $array)) { |
|
| 116 | + $array['two-factor-providers'] = []; |
|
| 117 | + } |
|
| 118 | + if (!array_key_exists('commands', $array)) { |
|
| 119 | + $array['commands'] = []; |
|
| 120 | + } |
|
| 121 | + if (!array_key_exists('activity', $array)) { |
|
| 122 | + $array['activity'] = []; |
|
| 123 | + } |
|
| 124 | + if (!array_key_exists('filters', $array['activity'])) { |
|
| 125 | + $array['activity']['filters'] = []; |
|
| 126 | + } |
|
| 127 | + if (!array_key_exists('settings', $array['activity'])) { |
|
| 128 | + $array['activity']['settings'] = []; |
|
| 129 | + } |
|
| 130 | + if (!array_key_exists('providers', $array['activity'])) { |
|
| 131 | + $array['activity']['providers'] = []; |
|
| 132 | + } |
|
| 133 | + if (!array_key_exists('settings', $array)) { |
|
| 134 | + $array['settings'] = []; |
|
| 135 | + } |
|
| 136 | + if (!array_key_exists('admin', $array['settings'])) { |
|
| 137 | + $array['settings']['admin'] = []; |
|
| 138 | + } |
|
| 139 | + if (!array_key_exists('admin-section', $array['settings'])) { |
|
| 140 | + $array['settings']['admin-section'] = []; |
|
| 141 | + } |
|
| 142 | + if (!array_key_exists('personal', $array['settings'])) { |
|
| 143 | + $array['settings']['personal'] = []; |
|
| 144 | + } |
|
| 145 | + if (!array_key_exists('personal-section', $array['settings'])) { |
|
| 146 | + $array['settings']['personal-section'] = []; |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - if (array_key_exists('types', $array)) { |
|
| 150 | - if (is_array($array['types'])) { |
|
| 151 | - foreach ($array['types'] as $type => $v) { |
|
| 152 | - unset($array['types'][$type]); |
|
| 153 | - if (is_string($type)) { |
|
| 154 | - $array['types'][] = $type; |
|
| 155 | - } |
|
| 156 | - } |
|
| 157 | - } else { |
|
| 158 | - $array['types'] = []; |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - if (isset($array['repair-steps']['install']['step']) && is_array($array['repair-steps']['install']['step'])) { |
|
| 162 | - $array['repair-steps']['install'] = $array['repair-steps']['install']['step']; |
|
| 163 | - } |
|
| 164 | - if (isset($array['repair-steps']['pre-migration']['step']) && is_array($array['repair-steps']['pre-migration']['step'])) { |
|
| 165 | - $array['repair-steps']['pre-migration'] = $array['repair-steps']['pre-migration']['step']; |
|
| 166 | - } |
|
| 167 | - if (isset($array['repair-steps']['post-migration']['step']) && is_array($array['repair-steps']['post-migration']['step'])) { |
|
| 168 | - $array['repair-steps']['post-migration'] = $array['repair-steps']['post-migration']['step']; |
|
| 169 | - } |
|
| 170 | - if (isset($array['repair-steps']['live-migration']['step']) && is_array($array['repair-steps']['live-migration']['step'])) { |
|
| 171 | - $array['repair-steps']['live-migration'] = $array['repair-steps']['live-migration']['step']; |
|
| 172 | - } |
|
| 173 | - if (isset($array['repair-steps']['uninstall']['step']) && is_array($array['repair-steps']['uninstall']['step'])) { |
|
| 174 | - $array['repair-steps']['uninstall'] = $array['repair-steps']['uninstall']['step']; |
|
| 175 | - } |
|
| 176 | - if (isset($array['background-jobs']['job']) && is_array($array['background-jobs']['job'])) { |
|
| 177 | - $array['background-jobs'] = $array['background-jobs']['job']; |
|
| 178 | - } |
|
| 179 | - if (isset($array['commands']['command']) && is_array($array['commands']['command'])) { |
|
| 180 | - $array['commands'] = $array['commands']['command']; |
|
| 181 | - } |
|
| 182 | - if (isset($array['two-factor-providers']['provider']) && is_array($array['two-factor-providers']['provider'])) { |
|
| 183 | - $array['two-factor-providers'] = $array['two-factor-providers']['provider']; |
|
| 184 | - } |
|
| 185 | - if (isset($array['activity']['filters']['filter']) && is_array($array['activity']['filters']['filter'])) { |
|
| 186 | - $array['activity']['filters'] = $array['activity']['filters']['filter']; |
|
| 187 | - } |
|
| 188 | - if (isset($array['activity']['settings']['setting']) && is_array($array['activity']['settings']['setting'])) { |
|
| 189 | - $array['activity']['settings'] = $array['activity']['settings']['setting']; |
|
| 190 | - } |
|
| 191 | - if (isset($array['activity']['providers']['provider']) && is_array($array['activity']['providers']['provider'])) { |
|
| 192 | - $array['activity']['providers'] = $array['activity']['providers']['provider']; |
|
| 193 | - } |
|
| 194 | - if (isset($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']) |
|
| 195 | - && is_array($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']) |
|
| 196 | - && !isset($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']['class']) |
|
| 197 | - ) { |
|
| 198 | - $array['collaboration']['collaborators']['searchPlugins'] = $array['collaboration']['collaborators']['searchPlugins']['searchPlugin']; |
|
| 199 | - } |
|
| 200 | - if (isset($array['settings']['admin']) && !is_array($array['settings']['admin'])) { |
|
| 201 | - $array['settings']['admin'] = [$array['settings']['admin']]; |
|
| 202 | - } |
|
| 203 | - if (isset($array['settings']['admin-section']) && !is_array($array['settings']['admin-section'])) { |
|
| 204 | - $array['settings']['admin-section'] = [$array['settings']['admin-section']]; |
|
| 205 | - } |
|
| 206 | - if (isset($array['settings']['personal']) && !is_array($array['settings']['personal'])) { |
|
| 207 | - $array['settings']['personal'] = [$array['settings']['personal']]; |
|
| 208 | - } |
|
| 209 | - if (isset($array['settings']['personal-section']) && !is_array($array['settings']['personal-section'])) { |
|
| 210 | - $array['settings']['personal-section'] = [$array['settings']['personal-section']]; |
|
| 211 | - } |
|
| 149 | + if (array_key_exists('types', $array)) { |
|
| 150 | + if (is_array($array['types'])) { |
|
| 151 | + foreach ($array['types'] as $type => $v) { |
|
| 152 | + unset($array['types'][$type]); |
|
| 153 | + if (is_string($type)) { |
|
| 154 | + $array['types'][] = $type; |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | + } else { |
|
| 158 | + $array['types'] = []; |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + if (isset($array['repair-steps']['install']['step']) && is_array($array['repair-steps']['install']['step'])) { |
|
| 162 | + $array['repair-steps']['install'] = $array['repair-steps']['install']['step']; |
|
| 163 | + } |
|
| 164 | + if (isset($array['repair-steps']['pre-migration']['step']) && is_array($array['repair-steps']['pre-migration']['step'])) { |
|
| 165 | + $array['repair-steps']['pre-migration'] = $array['repair-steps']['pre-migration']['step']; |
|
| 166 | + } |
|
| 167 | + if (isset($array['repair-steps']['post-migration']['step']) && is_array($array['repair-steps']['post-migration']['step'])) { |
|
| 168 | + $array['repair-steps']['post-migration'] = $array['repair-steps']['post-migration']['step']; |
|
| 169 | + } |
|
| 170 | + if (isset($array['repair-steps']['live-migration']['step']) && is_array($array['repair-steps']['live-migration']['step'])) { |
|
| 171 | + $array['repair-steps']['live-migration'] = $array['repair-steps']['live-migration']['step']; |
|
| 172 | + } |
|
| 173 | + if (isset($array['repair-steps']['uninstall']['step']) && is_array($array['repair-steps']['uninstall']['step'])) { |
|
| 174 | + $array['repair-steps']['uninstall'] = $array['repair-steps']['uninstall']['step']; |
|
| 175 | + } |
|
| 176 | + if (isset($array['background-jobs']['job']) && is_array($array['background-jobs']['job'])) { |
|
| 177 | + $array['background-jobs'] = $array['background-jobs']['job']; |
|
| 178 | + } |
|
| 179 | + if (isset($array['commands']['command']) && is_array($array['commands']['command'])) { |
|
| 180 | + $array['commands'] = $array['commands']['command']; |
|
| 181 | + } |
|
| 182 | + if (isset($array['two-factor-providers']['provider']) && is_array($array['two-factor-providers']['provider'])) { |
|
| 183 | + $array['two-factor-providers'] = $array['two-factor-providers']['provider']; |
|
| 184 | + } |
|
| 185 | + if (isset($array['activity']['filters']['filter']) && is_array($array['activity']['filters']['filter'])) { |
|
| 186 | + $array['activity']['filters'] = $array['activity']['filters']['filter']; |
|
| 187 | + } |
|
| 188 | + if (isset($array['activity']['settings']['setting']) && is_array($array['activity']['settings']['setting'])) { |
|
| 189 | + $array['activity']['settings'] = $array['activity']['settings']['setting']; |
|
| 190 | + } |
|
| 191 | + if (isset($array['activity']['providers']['provider']) && is_array($array['activity']['providers']['provider'])) { |
|
| 192 | + $array['activity']['providers'] = $array['activity']['providers']['provider']; |
|
| 193 | + } |
|
| 194 | + if (isset($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']) |
|
| 195 | + && is_array($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']) |
|
| 196 | + && !isset($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']['class']) |
|
| 197 | + ) { |
|
| 198 | + $array['collaboration']['collaborators']['searchPlugins'] = $array['collaboration']['collaborators']['searchPlugins']['searchPlugin']; |
|
| 199 | + } |
|
| 200 | + if (isset($array['settings']['admin']) && !is_array($array['settings']['admin'])) { |
|
| 201 | + $array['settings']['admin'] = [$array['settings']['admin']]; |
|
| 202 | + } |
|
| 203 | + if (isset($array['settings']['admin-section']) && !is_array($array['settings']['admin-section'])) { |
|
| 204 | + $array['settings']['admin-section'] = [$array['settings']['admin-section']]; |
|
| 205 | + } |
|
| 206 | + if (isset($array['settings']['personal']) && !is_array($array['settings']['personal'])) { |
|
| 207 | + $array['settings']['personal'] = [$array['settings']['personal']]; |
|
| 208 | + } |
|
| 209 | + if (isset($array['settings']['personal-section']) && !is_array($array['settings']['personal-section'])) { |
|
| 210 | + $array['settings']['personal-section'] = [$array['settings']['personal-section']]; |
|
| 211 | + } |
|
| 212 | 212 | |
| 213 | - if (isset($array['navigations']['navigation']) && $this->isNavigationItem($array['navigations']['navigation'])) { |
|
| 214 | - $array['navigations']['navigation'] = [$array['navigations']['navigation']]; |
|
| 215 | - } |
|
| 213 | + if (isset($array['navigations']['navigation']) && $this->isNavigationItem($array['navigations']['navigation'])) { |
|
| 214 | + $array['navigations']['navigation'] = [$array['navigations']['navigation']]; |
|
| 215 | + } |
|
| 216 | 216 | |
| 217 | - if ($this->cache !== null) { |
|
| 218 | - $this->cache->set($fileCacheKey, json_encode($array)); |
|
| 219 | - } |
|
| 220 | - return $array; |
|
| 221 | - } |
|
| 217 | + if ($this->cache !== null) { |
|
| 218 | + $this->cache->set($fileCacheKey, json_encode($array)); |
|
| 219 | + } |
|
| 220 | + return $array; |
|
| 221 | + } |
|
| 222 | 222 | |
| 223 | - /** |
|
| 224 | - * @param $data |
|
| 225 | - * @return bool |
|
| 226 | - */ |
|
| 227 | - private function isNavigationItem($data): bool { |
|
| 228 | - // Allow settings navigation items with no route entry |
|
| 229 | - $type = $data['type'] ?? 'link'; |
|
| 230 | - if ($type === 'settings') { |
|
| 231 | - return isset($data['name']); |
|
| 232 | - } |
|
| 233 | - return isset($data['name'], $data['route']); |
|
| 234 | - } |
|
| 223 | + /** |
|
| 224 | + * @param $data |
|
| 225 | + * @return bool |
|
| 226 | + */ |
|
| 227 | + private function isNavigationItem($data): bool { |
|
| 228 | + // Allow settings navigation items with no route entry |
|
| 229 | + $type = $data['type'] ?? 'link'; |
|
| 230 | + if ($type === 'settings') { |
|
| 231 | + return isset($data['name']); |
|
| 232 | + } |
|
| 233 | + return isset($data['name'], $data['route']); |
|
| 234 | + } |
|
| 235 | 235 | |
| 236 | - /** |
|
| 237 | - * @param \SimpleXMLElement $xml |
|
| 238 | - * @return array |
|
| 239 | - */ |
|
| 240 | - public function xmlToArray($xml) { |
|
| 241 | - if (!$xml->children()) { |
|
| 242 | - return (string)$xml; |
|
| 243 | - } |
|
| 236 | + /** |
|
| 237 | + * @param \SimpleXMLElement $xml |
|
| 238 | + * @return array |
|
| 239 | + */ |
|
| 240 | + public function xmlToArray($xml) { |
|
| 241 | + if (!$xml->children()) { |
|
| 242 | + return (string)$xml; |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | - $array = []; |
|
| 246 | - foreach ($xml->children() as $element => $node) { |
|
| 247 | - $totalElement = count($xml->{$element}); |
|
| 245 | + $array = []; |
|
| 246 | + foreach ($xml->children() as $element => $node) { |
|
| 247 | + $totalElement = count($xml->{$element}); |
|
| 248 | 248 | |
| 249 | - if (!isset($array[$element])) { |
|
| 250 | - $array[$element] = $totalElement > 1 ? [] : ""; |
|
| 251 | - } |
|
| 252 | - /** @var \SimpleXMLElement $node */ |
|
| 253 | - // Has attributes |
|
| 254 | - if ($attributes = $node->attributes()) { |
|
| 255 | - $data = [ |
|
| 256 | - '@attributes' => [], |
|
| 257 | - ]; |
|
| 258 | - if (!count($node->children())) { |
|
| 259 | - $value = (string)$node; |
|
| 260 | - if (!empty($value)) { |
|
| 261 | - $data['@value'] = $value; |
|
| 262 | - } |
|
| 263 | - } else { |
|
| 264 | - $data = array_merge($data, $this->xmlToArray($node)); |
|
| 265 | - } |
|
| 266 | - foreach ($attributes as $attr => $value) { |
|
| 267 | - $data['@attributes'][$attr] = (string)$value; |
|
| 268 | - } |
|
| 249 | + if (!isset($array[$element])) { |
|
| 250 | + $array[$element] = $totalElement > 1 ? [] : ""; |
|
| 251 | + } |
|
| 252 | + /** @var \SimpleXMLElement $node */ |
|
| 253 | + // Has attributes |
|
| 254 | + if ($attributes = $node->attributes()) { |
|
| 255 | + $data = [ |
|
| 256 | + '@attributes' => [], |
|
| 257 | + ]; |
|
| 258 | + if (!count($node->children())) { |
|
| 259 | + $value = (string)$node; |
|
| 260 | + if (!empty($value)) { |
|
| 261 | + $data['@value'] = $value; |
|
| 262 | + } |
|
| 263 | + } else { |
|
| 264 | + $data = array_merge($data, $this->xmlToArray($node)); |
|
| 265 | + } |
|
| 266 | + foreach ($attributes as $attr => $value) { |
|
| 267 | + $data['@attributes'][$attr] = (string)$value; |
|
| 268 | + } |
|
| 269 | 269 | |
| 270 | - if ($totalElement > 1) { |
|
| 271 | - $array[$element][] = $data; |
|
| 272 | - } else { |
|
| 273 | - $array[$element] = $data; |
|
| 274 | - } |
|
| 275 | - // Just a value |
|
| 276 | - } else { |
|
| 277 | - if ($totalElement > 1) { |
|
| 278 | - $array[$element][] = $this->xmlToArray($node); |
|
| 279 | - } else { |
|
| 280 | - $array[$element] = $this->xmlToArray($node); |
|
| 281 | - } |
|
| 282 | - } |
|
| 283 | - } |
|
| 270 | + if ($totalElement > 1) { |
|
| 271 | + $array[$element][] = $data; |
|
| 272 | + } else { |
|
| 273 | + $array[$element] = $data; |
|
| 274 | + } |
|
| 275 | + // Just a value |
|
| 276 | + } else { |
|
| 277 | + if ($totalElement > 1) { |
|
| 278 | + $array[$element][] = $this->xmlToArray($node); |
|
| 279 | + } else { |
|
| 280 | + $array[$element] = $this->xmlToArray($node); |
|
| 281 | + } |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | 284 | |
| 285 | - return $array; |
|
| 286 | - } |
|
| 285 | + return $array; |
|
| 286 | + } |
|
| 287 | 287 | } |