]> source.dussan.org Git - nextcloud-server.git/commitdiff
Added navigation manager in files app for the sidebar
authorVincent Petry <pvince81@owncloud.com>
Thu, 8 May 2014 14:24:24 +0000 (16:24 +0200)
committerVincent Petry <pvince81@owncloud.com>
Thu, 15 May 2014 15:51:04 +0000 (17:51 +0200)
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
apps/files/lib/app.php
apps/files/templates/appnavigation.php
apps/files/templates/index.php
apps/files_trashbin/appinfo/app.php
apps/files_trashbin/index.php
apps/files_trashbin/templates/index.php

index df207582dd6dd428539ba531bcc68a64794f69c3..ea57a548a22ab9f766ea21f14aa7366fd37ffc8b 100644 (file)
@@ -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();
index ed4aa32c66246bb0058f1a76d94b6c7c392d6c4a..e32225d06805451ae98c85f8d2873182e5942a71 100644 (file)
@@ -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
         *
index 22987ec637c774651b5fc373c4d00206e48218a8..a2fffd4c4b2a601db3a079c1710890f4bd39140b 100644 (file)
@@ -1,10 +1,10 @@
 <div id="app-navigation">
        <ul>
-               <li class="allfiles"><a href="<?php p(OC_Helper::linkTo('files', '')) ?>"><?php p($l->t('All Files'));?></a></li>
+               <li class="nav-allfiles"><a href="<?php p(OC_Helper::linkTo('files', '')) ?>"><?php p($l->t('All Files'));?></a></li>
                <li class="sep"></li>
-               <?php if ($_['trash'] ): ?>
-               <li class="trash"><a href="<?php p(OC_Helper::linkTo('files_trashbin', 'index.php')) ?>"><?php p($l->t('Deleted files'));?></a></li>
-               <?php endif; ?>
+               <?php foreach ($_['navigationItems'] as $item) { ?>
+               <li class="nav-<?php p($item['appname']) ?>"><a href="<?php p(isset($item['href']) ? $item['href'] : '#') ?>"><?php p($item['name']);?></a></li>
+               <?php } ?>
        </ul>
        <div id="app-settings">
                <div id="app-settings-header">
index 9ed294e6b6fa200082e9d6c689961257e3bdb958..335e2b2acd78a8a07949500416ae6abe1ed0a3d7 100644 (file)
@@ -1,6 +1,7 @@
 <?php /** @var $l OC_L10N */ ?>
 <?php $_['appNavigation']->printPage(); ?>
 <div id="app-content">
+<div id="app-content-files">
 <div id="controls">
                <div class="actions creatable hidden">
                        <?php if(!isset($_['dirToken'])):?>
                <?php p($l->t('Current scanning'));?> <span id='scan-current'></span>
        </p>
 </div>
-
+</div><!-- closing app-content-files -->
+       <?php foreach ($_['appContents'] as $content) { ?>
+       <div id="app-content-<?php p($content['appname']) ?>" class="hidden">
+       <?php print_unescaped($content['content']) ?>
+       </div>
+       <?php } ?>
 </div><!-- closing app-content -->
 
 <!-- config hints for javascript -->
index d30a601ef564c0282fdbed5715cf62f394cd114d..a045b1f0f515436c72f413f6bbe91cdd474a3154 100644 (file)
@@ -1,7 +1,14 @@
 <?php
-
-//OC::$CLASSPATH['OCA\Files_Trashbin\Hooks'] = 'files_trashbin/lib/hooks.php';
-//OC::$CLASSPATH['OCA\Files_Trashbin\Trashbin'] = 'files_trashbin/lib/trash.php';
+$l = OC_L10N::get('files_trashbin');
 
 // register hooks
 \OCA\Files_Trashbin\Trashbin::registerHooks();
+
+\OCA\Files\App::getNavigationManager()->add(
+       array(
+               "appname" => 'files_trashbin',
+               "script" => 'index.php',
+               "order" => 1,
+               "name" => $l->t('Deleted files')
+       )
+);
index 16cd5ecd4cdd8a0f9747329e5727637bcb32fe48..59258a6cf16acea700703517f27521e93009b2c1 100644 (file)
@@ -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();
index 02067385d4eef4751f829ae4a77d056128a185bf..e90162e4d5407a00a3ed37d37be33b87a4fb9c77 100644 (file)
@@ -1,6 +1,4 @@
 <?php /** @var $l OC_L10N */ ?>
-<?php $_['appNavigation']->printPage(); ?>
-<div id="app-content">
 <div id="controls">
        <div id="file_action_panel"></div>
 </div>
@@ -8,10 +6,6 @@
 
 <div id="emptycontent" class="hidden"><?php p($l->t('Nothing in here. Your trash bin is empty!'))?></div>
 
-<input type="hidden" id="permissions" value="0">
-<input type="hidden" id="disableSharing" data-status="<?php p($_['disableSharing']); ?>">
-<input type="hidden" name="dir" value="<?php p($_['dir']) ?>" id="dir">
-
 <table id="filestable">
        <thead>
                <tr>
@@ -46,4 +40,3 @@
        <tfoot>
        </tfoot>
 </table>
-</div>