[Pkg-owncloud-commits] [owncloud] 144/172: Added navigation manager in files app for the sidebar

David Prévot taffit at moszumanska.debian.org
Sun May 18 20:09:50 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository owncloud.

commit 88ebb15f1d91b82022e02903ab73338065e223b9
Author: Vincent Petry <pvince81 at owncloud.com>
Date:   Thu May 8 16:24:24 2014 +0200

    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 df20758..ea57a54 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 ed4aa32..e32225d 100644
--- a/apps/files/lib/app.php
+++ b/apps/files/lib/app.php
@@ -31,6 +31,11 @@ class App {
 	private $l10n;
 
 	/**
+	 * @var \OCP\INavigationManager
+	 */
+	private static $navigationManager;
+
+	/**
 	 * @var \OC\Files\View
 	 */
 	private $view;
@@ -41,6 +46,18 @@ class App {
 	}
 
 	/**
+	 * 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
 	 *
 	 * @param string $dir
diff --git a/apps/files/templates/appnavigation.php b/apps/files/templates/appnavigation.php
index 22987ec..a2fffd4 100644
--- a/apps/files/templates/appnavigation.php
+++ b/apps/files/templates/appnavigation.php
@@ -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">
diff --git a/apps/files/templates/index.php b/apps/files/templates/index.php
index 9ed294e..335e2b2 100644
--- a/apps/files/templates/index.php
+++ b/apps/files/templates/index.php
@@ -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'])):?>
@@ -110,7 +111,12 @@
 		<?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 -->
diff --git a/apps/files_trashbin/appinfo/app.php b/apps/files_trashbin/appinfo/app.php
index d30a601..a045b1f 100644
--- a/apps/files_trashbin/appinfo/app.php
+++ b/apps/files_trashbin/appinfo/app.php
@@ -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')
+	)
+);
diff --git a/apps/files_trashbin/index.php b/apps/files_trashbin/index.php
index 16cd5ec..59258a6 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 0206738..e90162e 100644
--- a/apps/files_trashbin/templates/index.php
+++ b/apps/files_trashbin/templates/index.php
@@ -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>

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list