diff options
author | Thomas Müller <DeepDiver1975@users.noreply.github.com> | 2016-12-08 17:43:46 +0100 |
---|---|---|
committer | Lukas Reschke <lukas@statuscode.ch> | 2016-12-22 12:34:41 +0100 |
commit | aa8755bd4b2d5a949a35f1308eefa6d00140a1a7 (patch) | |
tree | 09153939dd285480a1225290d7bde664e41826fa /lib/private/NavigationManager.php | |
parent | 7f8d22e7102293d96c365b380bf1845ff2de6b71 (diff) | |
download | nextcloud-server-aa8755bd4b2d5a949a35f1308eefa6d00140a1a7.tar.gz nextcloud-server-aa8755bd4b2d5a949a35f1308eefa6d00140a1a7.zip |
Add navigation via info.xml (#26785)
* Read navigation information from info.xml
* Load files navigation elements from info.xml
* Add comment about ignoring the exception
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
Diffstat (limited to 'lib/private/NavigationManager.php')
-rw-r--r-- | lib/private/NavigationManager.php | 104 |
1 files changed, 98 insertions, 6 deletions
diff --git a/lib/private/NavigationManager.php b/lib/private/NavigationManager.php index 3e9ddfc6466..79b01a69c49 100644 --- a/lib/private/NavigationManager.php +++ b/lib/private/NavigationManager.php @@ -1,6 +1,6 @@ <?php /** - * @copyright Copyright (c) 2016, ownCloud, Inc. + * @copyright Copyright (c) 2016, ownCloud GmbH * * @author Bart Visscher <bartv@thisnet.nl> * @author Joas Schilling <coding@schilljs.com> @@ -26,13 +26,45 @@ namespace OC; +use OCP\App\IAppManager; +use OCP\IGroupManager; +use OCP\INavigationManager; +use OCP\IURLGenerator; +use OCP\IUserSession; +use OCP\L10N\IFactory; + /** * Manages the ownCloud navigation */ -class NavigationManager implements \OCP\INavigationManager { - protected $entries = array(); - protected $closureEntries = array(); + +class NavigationManager implements INavigationManager { + protected $entries = []; + protected $closureEntries = []; protected $activeEntry; + /** @var bool */ + protected $init = false; + /** @var IAppManager */ + protected $appManager; + /** @var IURLGenerator */ + private $urlGenerator; + /** @var IFactory */ + private $l10nFac; + /** @var IUserSession */ + private $userSession; + /** @var IGroupManager */ + private $groupManager; + + function __construct(IAppManager $appManager = null, + IURLGenerator $urlGenerator = null, + IFactory $l10nFac = null, + IUserSession $userSession = null, + IGroupManager$groupManager = null) { + $this->appManager = $appManager; + $this->urlGenerator = $urlGenerator; + $this->l10nFac = $l10nFac; + $this->userSession = $userSession; + $this->groupManager = $groupManager; + } /** * Creates a new navigation entry @@ -60,6 +92,7 @@ class NavigationManager implements \OCP\INavigationManager { * @return array an array of the added entries */ public function getAll() { + $this->init(); foreach ($this->closureEntries as $c) { $this->add($c()); } @@ -71,8 +104,9 @@ class NavigationManager implements \OCP\INavigationManager { * removes all the entries */ public function clear() { - $this->entries = array(); - $this->closureEntries = array(); + $this->entries = []; + $this->closureEntries = []; + $this->init = false; } /** @@ -93,4 +127,62 @@ class NavigationManager implements \OCP\INavigationManager { public function getActiveEntry() { return $this->activeEntry; } + + private function init() { + if ($this->init) { + return; + } + $this->init = true; + if (is_null($this->appManager)) { + return; + } + foreach ($this->appManager->getInstalledApps() as $app) { + // load plugins and collections from info.xml + $info = $this->appManager->getAppInfo($app); + if (!isset($info['navigation'])) { + continue; + } + $nav = $info['navigation']; + if (!isset($nav['route'])) { + continue; + } + $role = isset($nav['@attributes']['role']) ? $nav['@attributes']['role'] : 'all'; + if ($role === 'admin' && !$this->isAdmin()) { + continue; + } + $l = $this->l10nFac->get($app); + $order = isset($nav['order']) ? $nav['order'] : 100; + $route = $this->urlGenerator->linkToRoute($nav['route']); + $name = isset($nav['name']) ? $nav['name'] : ucfirst($app); + $icon = isset($nav['icon']) ? $nav['icon'] : 'app.svg'; + foreach ([$icon, "$app.svg"] as $i) { + try { + $icon = $this->urlGenerator->imagePath($app, $i); + break; + } catch (\RuntimeException $ex) { + // no icon? - ignore it then + } + } + if (is_null($icon)) { + $icon = $this->urlGenerator->imagePath('core', 'default-app-icon'); + } + + $this->add([ + 'id' => $app, + 'order' => $order, + 'href' => $route, + 'icon' => $icon, + 'name' => $l->t($name), + ]); + } + } + + private function isAdmin() { + $user = $this->userSession->getUser(); + if ($user !== null) { + return $this->groupManager->isAdmin($user->getUID()); + } + return false; + } + } |