From 88ebb15f1d91b82022e02903ab73338065e223b9 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Thu, 8 May 2014 16:24:24 +0200 Subject: [PATCH] Added navigation manager in files app for the sidebar Apps can now register navigation items into the sidebar of the files app. For every sidebar item there is a container. The container's content is rendered based on the script name given at registration time. --- apps/files/index.php | 40 ++++++++++++++++++------- apps/files/lib/app.php | 17 +++++++++++ apps/files/templates/appnavigation.php | 8 ++--- apps/files/templates/index.php | 8 ++++- apps/files_trashbin/appinfo/app.php | 13 ++++++-- apps/files_trashbin/index.php | 37 ++--------------------- apps/files_trashbin/templates/index.php | 7 ----- 7 files changed, 70 insertions(+), 60 deletions(-) diff --git a/apps/files/index.php b/apps/files/index.php index df207582dd..ea57a548a2 100644 --- a/apps/files/index.php +++ b/apps/files/index.php @@ -83,16 +83,37 @@ if (OC_App::isEnabled('files_encryption')) { $encryptionInitStatus = $session->getInitialized(); } -$trashEnabled = \OCP\App::isEnabled('files_trashbin'); -$trashEmpty = true; -if ($trashEnabled) { - $trashEmpty = \OCA\Files_Trashbin\Trashbin::isEmpty($user); -} - $nav = new OCP\Template('files', 'appnavigation', ''); -$nav->assign('trash', $trashEnabled); -$nav->assign('trashEmpty', $trashEmpty); +$navItems = \OCA\Files\App::getNavigationManager()->getAll(); +$nav->assign('navigationItems', $navItems); + +$contentItems = array(); + +function renderScript($appName, $scriptName) { + $content = ''; + $appPath = OC_App::getAppPath($appName); + $scriptPath = $appPath . '/' . $scriptName; + if (file_exists($scriptPath)) { + // TODO: sanitize path / script name ? + ob_start(); + include $scriptPath; + $content = ob_get_contents(); + @ob_end_clean(); + } + return $content; +} + +foreach ($navItems as $item) { + $content = ''; + if (isset($item['script'])) { + $content = renderScript($item['appname'], $item['script']); + } + $contentItem = array(); + $contentItem['appname'] = $item['appname']; + $contentItem['content'] = $content; + $contentItems[] = $contentItem; +} OCP\Util::addscript('files', 'fileactions'); OCP\Util::addscript('files', 'files'); @@ -100,8 +121,6 @@ OCP\Util::addscript('files', 'keyboardshortcuts'); $tmpl = new OCP\Template('files', 'index', 'user'); $tmpl->assign('dir', $dir); $tmpl->assign('permissions', $permissions); -$tmpl->assign('trash', $trashEnabled); -$tmpl->assign('trashEmpty', $trashEmpty); $tmpl->assign('uploadMaxFilesize', $maxUploadFilesize); // minimium of freeSpace and uploadLimit $tmpl->assign('uploadMaxHumanFilesize', OCP\Util::humanFileSize($maxUploadFilesize)); $tmpl->assign('freeSpace', $freeSpace); @@ -116,5 +135,6 @@ $tmpl->assign("allowShareWithLink", $config->getAppValue('core', 'shareapi_allow $tmpl->assign("encryptionInitStatus", $encryptionInitStatus); $tmpl->assign('disableSharing', false); $tmpl->assign('appNavigation', $nav); +$tmpl->assign('appContents', $contentItems); $tmpl->printPage(); diff --git a/apps/files/lib/app.php b/apps/files/lib/app.php index ed4aa32c66..e32225d068 100644 --- a/apps/files/lib/app.php +++ b/apps/files/lib/app.php @@ -30,6 +30,11 @@ class App { */ private $l10n; + /** + * @var \OCP\INavigationManager + */ + private static $navigationManager; + /** * @var \OC\Files\View */ @@ -40,6 +45,18 @@ class App { $this->l10n = $l10n; } + /** + * Returns the app's navigation manager + * + * @return \OCP\INavigationManager + */ + public static function getNavigationManager() { + if (self::$navigationManager === null) { + self::$navigationManager = new \OC\NavigationManager(); + } + return self::$navigationManager; + } + /** * rename a file * diff --git a/apps/files/templates/appnavigation.php b/apps/files/templates/appnavigation.php index 22987ec637..a2fffd4c4b 100644 --- a/apps/files/templates/appnavigation.php +++ b/apps/files/templates/appnavigation.php @@ -1,10 +1,10 @@
diff --git a/apps/files/templates/index.php b/apps/files/templates/index.php index 9ed294e6b6..335e2b2acd 100644 --- a/apps/files/templates/index.php +++ b/apps/files/templates/index.php @@ -1,6 +1,7 @@ printPage(); ?>
+
- +
+ + +
diff --git a/apps/files_trashbin/appinfo/app.php b/apps/files_trashbin/appinfo/app.php index d30a601ef5..a045b1f0f5 100644 --- a/apps/files_trashbin/appinfo/app.php +++ b/apps/files_trashbin/appinfo/app.php @@ -1,7 +1,14 @@ add( + array( + "appname" => 'files_trashbin', + "script" => 'index.php', + "order" => 1, + "name" => $l->t('Deleted files') + ) +); diff --git a/apps/files_trashbin/index.php b/apps/files_trashbin/index.php index 16cd5ecd4c..59258a6cf1 100644 --- a/apps/files_trashbin/index.php +++ b/apps/files_trashbin/index.php @@ -3,45 +3,12 @@ // Check if we are a user OCP\User::checkLoggedIn(); -OCP\App::setActiveNavigationEntry('files_index'); - OCP\Util::addScript('files_trashbin', 'disableDefaultActions'); -OCP\Util::addScript('files', 'fileactions'); -$tmpl = new OCP\Template('files_trashbin', 'index', 'user'); -OCP\Util::addStyle('files', 'files'); +$tmpl = new OCP\Template('files_trashbin', 'index', ''); + OCP\Util::addStyle('files_trashbin', 'trash'); -OCP\Util::addScript('files', 'filesummary'); -OCP\Util::addScript('files', 'breadcrumb'); -OCP\Util::addScript('files', 'filelist'); -// filelist overrides OCP\Util::addScript('files_trashbin', 'filelist'); -OCP\Util::addscript('files', 'files'); OCP\Util::addScript('files_trashbin', 'trash'); -$dir = isset($_GET['dir']) ? stripslashes($_GET['dir']) : ''; - -$isIE8 = false; -preg_match('/MSIE (.*?);/', $_SERVER['HTTP_USER_AGENT'], $matches); -if (count($matches) > 0 && $matches[1] <= 8){ - $isIE8 = true; -} - -// if IE8 and "?dir=path" was specified, reformat the URL to use a hash like "#?dir=path" -if ($isIE8 && isset($_GET['dir'])){ - if ($dir === ''){ - $dir = '/'; - } - header('Location: ' . OCP\Util::linkTo('files_trashbin', 'index.php') . '#?dir=' . \OCP\Util::encodePath($dir)); - exit(); -} - -$tmpl->assign('dir', $dir); -$tmpl->assign('disableSharing', true); - -$nav = new OCP\Template('files', 'appnavigation', ''); -$nav->assign('trash', true); - -$tmpl->assign('appNavigation', $nav); - $tmpl->printPage(); diff --git a/apps/files_trashbin/templates/index.php b/apps/files_trashbin/templates/index.php index 02067385d4..e90162e4d5 100644 --- a/apps/files_trashbin/templates/index.php +++ b/apps/files_trashbin/templates/index.php @@ -1,6 +1,4 @@ -printPage(); ?> -
@@ -8,10 +6,6 @@ - - - - @@ -46,4 +40,3 @@
-