970846624f
This speeds up all pages that don't use the navigation by 0.04sec per app, because we don't need to create the routing anymore, unless we really need to.
79 lines
1.7 KiB
PHP
79 lines
1.7 KiB
PHP
<?php
|
|
/**
|
|
* Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl>
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
* later.
|
|
* See the COPYING-README file.
|
|
*
|
|
*/
|
|
|
|
namespace OC;
|
|
|
|
/**
|
|
* Manages the ownCloud navigation
|
|
*/
|
|
class NavigationManager implements \OCP\INavigationManager {
|
|
protected $entries = array();
|
|
protected $closureEntries = array();
|
|
protected $activeEntry;
|
|
|
|
/**
|
|
* Creates a new navigation entry
|
|
*
|
|
* @param array|\Closure $entry Array containing: id, name, order, icon and href key
|
|
* The use of a closure is preferred, because it will avoid
|
|
* loading the routing of your app, unless required.
|
|
* @return void
|
|
*/
|
|
public function add($entry) {
|
|
if ($entry instanceof \Closure) {
|
|
$this->closureEntries[] = $entry;
|
|
return;
|
|
}
|
|
|
|
$entry['active'] = false;
|
|
if(!isset($entry['icon'])) {
|
|
$entry['icon'] = '';
|
|
}
|
|
$this->entries[] = $entry;
|
|
}
|
|
|
|
/**
|
|
* returns all the added Menu entries
|
|
* @return array an array of the added entries
|
|
*/
|
|
public function getAll() {
|
|
foreach ($this->closureEntries as $c) {
|
|
$this->add($c());
|
|
}
|
|
$this->closureEntries = array();
|
|
return $this->entries;
|
|
}
|
|
|
|
/**
|
|
* removes all the entries
|
|
*/
|
|
public function clear() {
|
|
$this->entries = array();
|
|
$this->closureEntries = array();
|
|
}
|
|
|
|
/**
|
|
* Sets the current navigation entry of the currently running app
|
|
* @param string $id of the app entry to activate (from added $entry)
|
|
*/
|
|
public function setActiveEntry($id) {
|
|
$this->activeEntry = $id;
|
|
}
|
|
|
|
/**
|
|
* gets the active Menu entry
|
|
* @return string id or empty string
|
|
*
|
|
* This function returns the id of the active navigation entry (set by
|
|
* setActiveEntry
|
|
*/
|
|
public function getActiveEntry() {
|
|
return $this->activeEntry;
|
|
}
|
|
}
|