From: Michael M Slusarz Date: Tue, 31 Aug 2010 23:40:43 +0000 (-0600) Subject: Sidebar is now generated via Application registry calls. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=f848bedd3756ce5a9af2990a36b59a9c1b027aed;p=horde.git Sidebar is now generated via Application registry calls. THE FORMAT OF horde/config/registry.php HAS CHANGED. Namely, sidebar entries have been changed from 'block' (which they are not) to 'sidebar', and a 'sidebar_params' entry has been added for applications that have more than one sidebar tree node addition section. --- diff --git a/ansel/browse_edit.php b/ansel/browse_edit.php index 049640776..4fab2b530 100644 --- a/ansel/browse_edit.php +++ b/ansel/browse_edit.php @@ -10,7 +10,7 @@ require_once dirname(__FILE__) . '/lib/Application.php'; Horde_Registry::appInit('ansel'); // Instantiate the blocks objects. -$blocks = Horde_Block_Collection::singleton('myphotos', array('ansel')); +$blocks = Horde_Block_Collection::singleton(array('ansel')); $layout = Horde_Block_Layout_Manager::singleton('myphotos', $blocks, @unserialize($prefs->getValue('myansel_layout'))); // Handle requested actions. diff --git a/chora/lib/Application.php b/chora/lib/Application.php index 1b9b5eca4..8ec9a2836 100644 --- a/chora/lib/Application.php +++ b/chora/lib/Application.php @@ -205,4 +205,39 @@ class Chora_Application extends Horde_Registry_Application return Chora::getMenu(); } + /* Sidebar method. */ + + /** + * Add node(s) to the sidebar tree. + * + * @param Horde_Tree_Base $tree Tree object. + * @param string $parent The current parent element. + * @param array $params Additional parameters. + * + * @throws Horde_Exception + */ + public function sidebarCreate(Horde_Tree_Base $tree, $parent = null, + array $params = array()) + { + define('CHORA_ERROR_HANDLER', true); + + $arr = array(); + asort($GLOBALS['sourceroots']); + + foreach ($GLOBALS['sourceroots'] as $key => $val) { + if (Chora::checkPerms($key)) { + $tree->addNode($parent . $key, + $parent, + $val['name'], + 1, + false, + array( + 'icon' => Horde_Themes::img('tree/folder.png'), + 'url' => Chora::url('browsedir', '', array('rt' => $key)) + ) + ); + } + } + } + } diff --git a/chora/lib/Block/tree_menu.php b/chora/lib/Block/tree_menu.php deleted file mode 100644 index dc74c72c9..000000000 --- a/chora/lib/Block/tree_menu.php +++ /dev/null @@ -1,33 +0,0 @@ - $val) { - if (Chora::checkPerms($key)) { - $tree->addNode($parent . $key, - $parent, - $val['name'], - $indent + 1, - false, - array( - 'icon' => Horde_Themes::img('tree/folder.png'), - 'url' => Chora::url('browsedir', '', array('rt' => $key)) - ) - ); - } - } - } - -} diff --git a/framework/Block/lib/Horde/Block.php b/framework/Block/lib/Horde/Block.php index f0fb1130d..fcaf444da 100644 --- a/framework/Block/lib/Horde/Block.php +++ b/framework/Block/lib/Horde/Block.php @@ -191,28 +191,6 @@ class Horde_Block } /** - * TODO - */ - public function buildTree($tree, $indent = 0, $parent = null) - { - /* Switch application contexts, if necessary. Return an error - * immediately if pushApp() fails. */ - try { - $app_pushed = $GLOBALS['registry']->pushApp($this->_app, array('check_perms' => true, 'logintasks' => false)); - } catch (Horde_Exception $e) { - return $e->getMessage(); - } - - $this->_buildTree($tree, $indent, $parent); - - /* If we changed application context in the course of this - * call, undo that change now. */ - if ($app_pushed) { - $GLOBALS['registry']->popApp(); - } - } - - /** * Returns the title to go in this block. * * @return string The block title. @@ -242,11 +220,4 @@ class Horde_Block return ''; } - /** - * Returns this block's content. - */ - protected function _buildTree($tree, $indent = 0, $parent = null) - { - } - } diff --git a/framework/Block/lib/Horde/Block/Collection.php b/framework/Block/lib/Horde/Block/Collection.php index 650187148..604f0a1ed 100644 --- a/framework/Block/lib/Horde/Block/Collection.php +++ b/framework/Block/lib/Horde/Block/Collection.php @@ -30,13 +30,6 @@ class Horde_Block_Collection static protected $_blocksCache = array(); /** - * What kind of blocks are we collecting? Defaults to any. - * - * @var string - */ - protected $_type = 'portal'; - - /** * A hash storing the information about all available blocks from * all applications. * @@ -47,17 +40,17 @@ class Horde_Block_Collection /** * Returns a single instance of the Horde_Blocks class. * - * @param string $type The kind of blocks to list. - * @param array $apps The applications whose blocks to list. + * @param array $apps The applications whose blocks to list. * * @return Horde_Block_Collection The Horde_Block_Collection instance. */ static public function singleton($type = null, $apps = array()) { sort($apps); - $signature = serialize(array($type, $apps)); + $signature = hash('md5', serialize($apps)); + if (!isset(self::$_instances[$signature])) { - self::$_instances[$signature] = new self($type, $apps); + self::$_instances[$signature] = new self($apps); } return self::$_instances[$signature]; @@ -66,15 +59,10 @@ class Horde_Block_Collection /** * Constructor. * - * @param string $type The kind of blocks to list. - * @param array $apps The applications whose blocks to list. + * @param array $apps The applications whose blocks to list. */ - public function __construct($type = null, $apps = array()) + public function __construct($apps = array()) { - if (!is_null($type)) { - $this->_type = $type; - } - $signature = serialize($apps); if (isset($_SESSION['horde']['blocks'][$signature])) { $this->_blocks = &$_SESSION['horde']['blocks'][$signature]; @@ -100,16 +88,13 @@ class Horde_Block_Collection continue; } - $block_name = $block_type = null; + $block_name = null; if (is_readable($blockdir . '/' . $file)) { include_once $blockdir . '/' . $file; } - if (!empty($block_name) && - (is_null($block_type) || - is_null($this->_type) || - ($block_type == $this->_type))) { + if (!empty($block_name)) { $this->_blocks[$app][substr($file, 0, -4)]['name'] = $block_name; } } diff --git a/framework/Block/package.xml b/framework/Block/package.xml index 7ba7112e2..d70f5e11c 100644 --- a/framework/Block/package.xml +++ b/framework/Block/package.xml @@ -32,7 +32,8 @@ http://pear.php.net/dtd/package-2.0.xsd"> beta LGPL - * Initial Horde 4 package. + * Removed sidebar-specifc code. + * Initial Horde 4 package. diff --git a/framework/Core/lib/Horde/Config.php b/framework/Core/lib/Horde/Config.php index a01d1b974..e9881b984 100644 --- a/framework/Core/lib/Horde/Config.php +++ b/framework/Core/lib/Horde/Config.php @@ -1557,7 +1557,7 @@ class Horde_Config return array_map(create_function('$val', 'return preg_replace(array("/&#x([0-9a-f]{4});/ie", "/(&[^;]+;)/e"), array("Horde_String::convertCharset(pack(\"H*\", \"$1\"), \"ucs-2\", \"' . $GLOBALS['registry']->getCharset() . '\")", "Horde_String::convertCharset(html_entity_decode(\"$1\", ENT_COMPAT, \"iso-8859-1\"), \"iso-8859-1\", \"' . $GLOBALS['registry']->getCharset() . '\")"), $val);'), $GLOBALS['registry']->nlsconfig['languages']); case 'list-blocks': - $collection = Horde_Block_Collection::singleton('portal'); + $collection = Horde_Block_Collection::singleton(); return $collection->getBlocksList(); case 'list-client-fields': diff --git a/framework/Core/lib/Horde/Core/Sidebar.php b/framework/Core/lib/Horde/Core/Sidebar.php new file mode 100644 index 000000000..11a626121 --- /dev/null +++ b/framework/Core/lib/Horde/Core/Sidebar.php @@ -0,0 +1,174 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Core + */ +class Horde_Core_Sidebar +{ + /** + * Generate the sidebar tree object. + * + * @return Horde_Tree_Base The sidebar tree object. + */ + public function getTree() + { + global $injector, $registry; + + $isAdmin = $registry->isAdmin(); + $menu = $parents = array(); + + foreach ($registry->listApps(array('active', 'admin', 'heading', 'notoolbar', 'sidebar'), true) as $app => $params) { + /* Check if the current user has permisson to see this + * application, and if the application is active. Headings are + * visible to everyone (but get filtered out later if they + * have no children). Administrators always see all + * applications except those marked 'inactive'. */ + if ($isAdmin || + ($params['status'] == 'heading') || + ($registry->hasPermission($app, Horde_Perms::SHOW) && + in_array($params['status'], array('active', 'sidebar')))) { + $menu[$app] = $params; + + if (isset($params['menu_parent'])) { + $children[$params['menu_parent']] = true; + } + } + } + + foreach (array_keys($menu) as $key) { + if (($menu[$key]['status'] == 'heading') && + !isset($children[$key])) { + unset($menu[$key]); + } + } + + // Add the administration menu if the user is an admin. + if ($isAdmin) { + $menu['administration'] = array( + 'name' => _("Administration"), + 'icon' => Horde_Themes::img('administration.png'), + 'status' => 'heading' + ); + + try { + foreach ($registry->callByPackage('horde', 'admin_list') as $method => $val) { + $menu['administration_' . $method] = array( + 'icon' => $val['icon'], + 'menu_parent' => 'administration', + 'name' => Horde::stripAccessKey($val['name']), + 'status' => 'active', + 'url' => Horde::url($registry->applicationWebPath($val['link'], 'horde')), + ); + } + } catch (Horde_Exception $e) {} + } + + if (Horde_Menu::showService('options') && + !($injector->getInstance('Horde_Prefs')->getPrefs() instanceof Horde_Prefs_Session)) { + $menu['options'] = array( + 'icon' => Horde_Themes::img('prefs.png'), + 'name' => _("Options"), + 'status' => 'active' + ); + + /* Get a list of configurable applications. */ + $prefs_apps = $registry->listApps(array('active', 'admin'), true, Horde_Perms::READ); + + if (!empty($prefs_apps['horde'])) { + $menu['options_' . 'horde'] = array( + 'icon' => $registry->get('icon', 'horde'), + 'menu_parent' => 'options', + 'name' => _("Global Options"), + 'status' => 'active', + 'url' => Horde::getServiceLink('options', 'horde') + ); + unset($prefs_apps['horde']); + } + + asort($prefs_apps); + foreach ($prefs_apps as $app => $params) { + $menu['options_' . $app] = array( + 'icon' => $registry->get('icon', $app), + 'menu_parent' => 'options', + 'name' => $params['name'], + 'status' => 'active', + 'url' => Horde::getServiceLink('options', $app) + ); + } + } + + if ($registry->getAuth()) { + $menu['logout'] = array( + 'icon' => Horde_Themes::img('logout.png'), + 'name' => _("Log out"), + 'status' => 'active', + 'url' => Horde::getServiceLink('logout', 'horde') + ); + } else { + $menu['login'] = array( + 'icon' => Horde_Themes::img('login.png'), + 'name' => _("Log in"), + 'status' => 'active', + 'url' => Horde::getServiceLink('login', 'horde') + ); + } + + // Set up the tree. + $tree = $injector->getInstance('Horde_Tree')->getTree('horde_sidebar', 'Javascript', array('jsvar' => 'HordeSidebar.tree')); + + foreach ($menu as $app => $params) { + switch ($params['status']) { + case 'sidebar': + try { + $registry->callAppMethod($params['app'], 'sidebarCreate', array('args' => array($tree, empty($params['menu_parent']) ? null : $params['menu_parent'], isset($params['sidebar_params']) ? $params['sidebar_params'] : array()))); + } catch (Horde_Exception $e) { + Horde::logMessage($e, 'ERR'); + } + break; + + default: + // Need to run the name through gettext since the user's + // locale may not have been loaded when registry.php was + // parsed. + $name = _($params['name']); + + // Headings have no webroot; they're just containers for other + // menu items. + if (isset($params['url'])) { + $url = $params['url']; + } elseif (($params['status'] == 'heading') || + !isset($params['webroot'])) { + $url = null; + } else { + $url = Horde::url($registry->getInitialPage($app)); + } + + $tree->addNode( + $app, + empty($params['menu_parent']) ? null : $params['menu_parent'], + $name, + 0, + false, + array( + 'icon' => strval((isset($params['icon']) ? $params['icon'] : $registry->get('icon', $app))), + 'target' => isset($params['target']) ? $params['target'] : null, + 'url' => $url + ) + ); + break; + } + } + + return $tree; + } + +} diff --git a/framework/Core/lib/Horde/Registry/Application.php b/framework/Core/lib/Horde/Registry/Application.php index cc4807a36..94a331964 100644 --- a/framework/Core/lib/Horde/Registry/Application.php +++ b/framework/Core/lib/Horde/Registry/Application.php @@ -253,6 +253,21 @@ class Horde_Registry_Application // public function prefsSpecialUpdate($ui, $item) {} + // Horde_Core_Sidebar method. + + /** + * Add node(s) to the sidebar tree. + * + * @param Horde_Tree_Base $tree Tree object. + * @param string $parent The current parent element. + * @param array $params Additional parameters. + * + * @throws Horde_Exception + */ + // public function sidebarCreate(Horde_Tree_Base $tree, $parent = null, + // array $params = array()) {} + + // Language change callback. /** diff --git a/framework/Core/package.xml b/framework/Core/package.xml index a179722ed..83ab8400e 100644 --- a/framework/Core/package.xml +++ b/framework/Core/package.xml @@ -202,6 +202,7 @@ Application Framework. + @@ -503,6 +504,7 @@ Application Framework. + diff --git a/gollem/lib/Application.php b/gollem/lib/Application.php index 7d5629da0..f766eaec4 100644 --- a/gollem/lib/Application.php +++ b/gollem/lib/Application.php @@ -195,4 +195,40 @@ class Gollem_Application extends Horde_Registry_Application return Gollem::getMenu(); } + /* Sidebar method. */ + + /** + * Add node(s) to the sidebar tree. + * + * @param Horde_Tree_Base $tree Tree object. + * @param string $parent The current parent element. + * @param array $params Additional parameters. + * + * @throws Horde_Exception + */ + public function sidebarCreate(Horde_Tree_Base $tree, $parent = null, + array $params = array()) + { + // TODO + return; + + $login_url = Horde::applicationUrl('login.php'); + + foreach ($GLOBALS['gollem_backends'] as $key => $val) { + if (Gollem::checkPermissions('backend', Horde_Perms::SHOW, $key)) { + $tree->addNode( + $parent . $key, + $parent, + $val['name'], + 1, + false, + array( + 'icon' => Horde_Themes::img('gollem.png'), + 'url' => $login_url->copy()->add(array('backend_key' => $key, 'change_backend' => 1)) + ) + ); + } + } + } + } diff --git a/gollem/lib/Block/tree_menu.php b/gollem/lib/Block/tree_menu.php deleted file mode 100644 index fd223c3dd..000000000 --- a/gollem/lib/Block/tree_menu.php +++ /dev/null @@ -1,45 +0,0 @@ - - * @package Gollem - */ -class Horde_Block_gollem_tree_menu extends Horde_Block -{ - protected $_app = 'gollem'; - - protected function _buildTree(&$tree, $indent = 0, $parent = null) - { - // TODO - return; - - $login_url = Horde::applicationUrl('login.php'); - - foreach ($GLOBALS['gollem_backends'] as $key => $val) { - if (Gollem::checkPermissions('backend', Horde_Perms::SHOW, $key)) { - $tree->addNode( - $parent . $key, - $parent, - $val['name'], - $indent + 1, - false, - array( - 'icon' => Horde_Themes::img('gollem.png'), - 'url' => $login_url->copy()->add(array('backend_key' => $key, 'change_backend' => 1)) - ) - ); - } - } - } - -} diff --git a/hermes/lib/Application.php b/hermes/lib/Application.php index 476a4eca6..c9482ecda 100644 --- a/hermes/lib/Application.php +++ b/hermes/lib/Application.php @@ -87,4 +87,82 @@ class Hermes_Application extends Horde_Registry_Application return self::$_perms; } + /* Sidebar method. */ + + /** + * Add node(s) to the sidebar tree. + * + * @param Horde_Tree_Base $tree Tree object. + * @param string $parent The current parent element. + * @param array $params Additional parameters. + * + * @throws Horde_Exception + */ + public function sidebarCreate(Horde_Tree_Base $tree, $parent = null, + array $params = array()) + { + switch ($params['id']) { + case 'menu': + $tree->addNode( + $parent . '__add', + $parent, + _("Enter Time"), + 1, + false, + array( + 'icon' => 'hermes.png', + 'url' => Horde::applicationUrl('entry.php') + ) + ); + + $tree->addNode( + $parent . '__search', + $parent, + _("Search Time"), + 1, + false, + array( + 'icon' => 'search.png', + 'url' => Horde::applicationUrl('search.php') + ) + ); + break; + + case 'stopwatch': + Horde::addScriptFile('popup.js', 'horde'); + $entry = Horde::applicationUrl('entry.php'); + + $tree->addNode( + $parent . '__start', + $parent, + _("Start Watch"), + 1, + false, + array( + 'icon' => 'timer-start.png', + 'onclick' => "popup('" . Horde::applicationUrl('start.php') . "', 400, 100); return false;", + 'url' => '#' + ) + ); + + if ($timers = @unserialize($GLOBALS['prefs']->getValue('running_timers', false))) { + foreach ($timers as $i => $timer) { + $hours = round((float)(time() - $i) / 3600, 2); + $tree->addNode( + $parent . '__timer_' . $i, + $parent, + Horde_String::convertCharset($timer['name'], $prefs->getCharset()) . sprintf(" (%s)", $hours), + 1, + false, + array( + 'icon' => 'timer-stop.png', + 'url' => $entry->add('timer', $i) + ) + ); + } + } + break; + } + } + } diff --git a/hermes/lib/Block/tree_menu.php b/hermes/lib/Block/tree_menu.php deleted file mode 100644 index 98e5bc4aa..000000000 --- a/hermes/lib/Block/tree_menu.php +++ /dev/null @@ -1,31 +0,0 @@ -addNode($parent . '__add', - $parent, - _("Enter Time"), - $indent + 1, - false, - array('icon' => 'hermes.png', - 'url' => Horde::applicationUrl('entry.php'))); - $tree->addNode($parent . '__search', - $parent, - _("Search Time"), - $indent + 1, - false, - array('icon' => 'search.png', - 'url' => Horde::applicationUrl('search.php'))); - } - -} diff --git a/hermes/lib/Block/tree_stopwatch.php b/hermes/lib/Block/tree_stopwatch.php deleted file mode 100644 index faf18cdb4..000000000 --- a/hermes/lib/Block/tree_stopwatch.php +++ /dev/null @@ -1,46 +0,0 @@ -addNode($parent . '__start', - $parent, - _("Start Watch"), - $indent + 1, - false, - array('icon' => 'timer-start.png', - 'url' => '#', - 'onclick' => "popup('" . Horde::applicationUrl('start.php') . "', 400, 100); return false;")); - - $timers = @unserialize($prefs->getValue('running_timers', false)); - if ($timers) { - foreach ($timers as $i => $timer) { - $hours = round((float)(time() - $i) / 3600, 2); - $tname = Horde_String::convertCharset($timer['name'], $prefs->getCharset()) . sprintf(" (%s)", $hours); - $tree->addNode($parent . '__timer_' . $i, - $parent, - $tname, - $indent + 1, - false, - array('icon' => 'timer-stop.png', - 'url' => Horde_Util::addParameter($entry, 'timer', $i))); - } - } - } - -} diff --git a/horde/config/registry.php.dist b/horde/config/registry.php.dist index 28fe5979b..4aed999f9 100644 --- a/horde/config/registry.php.dist +++ b/horde/config/registry.php.dist @@ -29,8 +29,14 @@ * menu_parent: (string) The name of the 'heading' group that this app should * show up under. This can be left out or set to null for * top-level items. - * status: (string) 'inactive', 'hidden', 'notoolbar', 'heading', - * 'block', 'admin', or 'active'. + * status: (string) One of the following: + * 'active' + * 'admin' + * 'heading' + * 'hidden' + * 'inactive' + * 'notoolbar' + * 'sidebar' * webroot: (string) The base URI path for the module. * Usually the default should be fine (applications will occur one * level below the horde directory). However, this setting is useful @@ -45,11 +51,13 @@ * jsfs: (string) The base filesystem path for static javascript files. * jsuri: (string) The base URI for static javascript files. * provides: (mixed) Service types the module provides. + * sidebar_prefs: (array) Additional params to pass to the sidebar generation + function. * target: (string) The target frame for the link. * templates: (string) The filesystem path to the templates directory. * themesfs: (string) The base file system directory for the themes. * themesuri: (string) The base URI for the themes. This can be used to serve - * all icons and style sheets from a separate server. + * all icons and style sheets from a separate server. * url: (string) The URL of 'heading' entries. * * @@ -117,10 +125,9 @@ $this->applications['vacation'] = array( 'menu_parent' => 'imp' ); -$this->applications['imp-folders'] = array( - 'status' => 'block', +$this->applications['imp-menu'] = array( + 'status' => 'sidebar', 'app' => 'imp', - 'blockname' => 'tree_folders', 'menu_parent' => 'imp', ); @@ -139,9 +146,8 @@ $this->applications['turba'] = array( ); $this->applications['turba-menu'] = array( - 'status' => 'block', + 'status' => 'sidebar', 'app' => 'turba', - 'blockname' => 'tree_menu', 'menu_parent' => 'turba', ); @@ -155,16 +161,20 @@ $this->applications['kronolith'] = array( ); $this->applications['kronolith-alarms'] = array( - 'status' => 'block', + 'status' => 'sidebar', 'app' => 'kronolith', - 'blockname' => 'tree_alarms', + 'sidebar_params' => array( + 'id' => 'alarms' + ), 'menu_parent' => 'kronolith', ); $this->applications['kronolith-menu'] = array( - 'status' => 'block', + 'status' => 'sidebar', 'app' => 'kronolith', - 'blockname' => 'tree_menu', + 'sidebar_params' => array( + 'id' => 'menu' + ), 'menu_parent' => 'kronolith', ); @@ -178,16 +188,20 @@ $this->applications['nag'] = array( ); $this->applications['nag-alarms'] = array( - 'status' => 'block', + 'status' => 'sidebar', 'app' => 'nag', - 'blockname' => 'tree_alarms', + 'sidebar_params' => array( + 'id' => 'alarms' + ), 'menu_parent' => 'nag', ); $this->applications['nag-menu'] = array( - 'status' => 'block', + 'status' => 'sidebar', 'app' => 'nag', - 'blockname' => 'tree_menu', + 'sidebar_params' => array( + 'id' => 'menu' + ), 'menu_parent' => 'nag', ); @@ -201,9 +215,8 @@ $this->applications['mnemo'] = array( ); $this->applications['mnemo-menu'] = array( - 'status' => 'block', + 'status' => 'sidebar', 'app' => 'mnemo', - 'blockname' => 'tree_menu', 'menu_parent' => 'mnemo', ); @@ -226,9 +239,8 @@ $this->applications['trean'] = array( ); $this->applications['trean-menu'] = array( - 'status' => 'block', + 'status' => 'sidebar', 'app' => 'trean', - 'blockname' => 'tree_menu', 'menu_parent' => 'trean', ); @@ -246,9 +258,8 @@ $this->applications['chora'] = array( ); $this->applications['chora-menu'] = array( - 'status' => 'block', + 'status' => 'sidebar', 'app' => 'chora', - 'blockname' => 'tree_menu', 'menu_parent' => 'chora', ); @@ -262,9 +273,8 @@ $this->applications['whups'] = array( ); $this->applications['whups-menu'] = array( - 'status' => 'block', + 'status' => 'sidebar', 'app' => 'whups', - 'blockname' => 'tree_menu', 'menu_parent' => 'whups', ); @@ -308,9 +318,8 @@ $this->applications['jonah'] = array( ); $this->applications['jonah-menu'] = array( - 'status' => 'block', + 'status' => 'sidebar', 'app' => 'jonah', - 'blockname' => 'tree_menu', 'menu_parent' => 'jonah', ); @@ -365,16 +374,20 @@ $this->applications['hermes'] = array( ); $this->applications['hermes-stopwatch'] = array( - 'status' => 'block', + 'status' => 'sidebar', 'app' => 'hermes', - 'blockname' => 'tree_stopwatch', + 'sidebar_params' => array( + 'id' => 'stopwatch', + ), 'menu_parent' => 'hermes', ); $this->applications['hermes-menu'] = array( - 'status' => 'block', + 'status' => 'sidebar', 'app' => 'hermes', - 'blockname' => 'tree_menu', + 'sidebar_params' => array( + 'id' => 'menu' + ), 'menu_parent' => 'hermes', ); @@ -393,9 +406,8 @@ $this->applications['gollem'] = array( ); $this->applications['gollem-menu'] = array( - 'status' => 'block', + 'status' => 'sidebar', 'app' => 'gollem', - 'blockname' => 'tree_menu', 'menu_parent' => 'gollem', ); diff --git a/horde/docs/UPGRADING b/horde/docs/UPGRADING index bba56698a..d15493712 100644 --- a/horde/docs/UPGRADING +++ b/horde/docs/UPGRADING @@ -51,6 +51,8 @@ Removed support for krb5 authentication driver. Removed Mime Viewer drivers: Enscript & Webcpp. Use 'Srchighlite' instead. +The registry.php file has changed ('status' => 'sidebar'). + Upgrading Horde from 3.3.x to 3.3.5 =================================== diff --git a/horde/lib/Ajax/Application.php b/horde/lib/Ajax/Application.php index 542c2db60..7bade2e66 100644 --- a/horde/lib/Ajax/Application.php +++ b/horde/lib/Ajax/Application.php @@ -21,8 +21,7 @@ class Horde_Ajax_Application extends Horde_Core_Ajax_Application */ public function sidebarUpdate() { - $sidebar = new Horde_Ui_Sidebar(); - return $sidebar->getTree()->renderNodeDefinitions(); + return $sidebar->getInstance('Horde_Core_Sidebar')->getTree()->renderNodeDefinitions(); } } diff --git a/horde/lib/Api.php b/horde/lib/Api.php index 7ba249cb4..c04e71361 100644 --- a/horde/lib/Api.php +++ b/horde/lib/Api.php @@ -10,7 +10,14 @@ class Horde_Api extends Horde_Registry_Api { /** - * Returns a list of adminstrative links + * Returns a list of adminstrative links. + * + * @return array Keys are link labels, values are array with these keys: + *
+     * 'link' - (string) Registry encoded link to page.
+     * 'name' - (string) Gettext label for page.
+     * 'icon' - (string) Graphic for page.
+     * 
*/ public function admin_list() { @@ -18,52 +25,52 @@ class Horde_Api extends Horde_Registry_Api 'configuration' => array( 'link' => '%application%/admin/setup/', 'name' => _("_Setup"), - 'icon' => 'config.png' + 'icon' => Horde_Themes::img('config.png') ), 'users' => array( 'link' => '%application%/admin/user.php', 'name' => _("_Users"), - 'icon' => 'user.png' + 'icon' => Horde_Themes::img('user.png') ), 'groups' => array( 'link' => '%application%/admin/groups.php', 'name' => _("_Groups"), - 'icon' => 'group.png' + 'icon' => Horde_Themes::img('group.png') ), 'perms' => array( 'link' => '%application%/admin/perms/index.php', 'name' => _("_Permissions"), - 'icon' => 'perms.png' + 'icon' => Horde_Themes::img('perms.png') ), 'alarms' => array( 'link' => '%application%/admin/alarms.php', 'name' => _("_Alarms"), - 'icon' => 'alerts/alarm.png' + 'icon' => Horde_Themes::img('alerts/alarm.png') ), 'datatree' => array( 'link' => '%application%/admin/datatree.php', 'name' => _("_DataTree"), - 'icon' => 'datatree.png' + 'icon' => Horde_Themes::img('datatree.png') ), 'sessions' => array( 'link' => '%application%/admin/sessions.php', 'name' => _("Sessions"), - 'icon' => 'user.png' + 'icon' => Horde_Themes::img('user.png') ), 'phpshell' => array( 'link' => '%application%/admin/phpshell.php', 'name' => _("P_HP Shell"), - 'icon' => 'mime/php.png' + 'icon' => Horde_Themes::img('mime/php.png') ), 'sqlshell' => array( 'link' => '%application%/admin/sqlshell.php', 'name' => _("S_QL Shell"), - 'icon' => 'sql.png' + 'icon' => Horde_Themes::img('sql.png') ), 'cmdshell' => array( 'link' => '%application%/admin/cmdshell.php', 'name' => _("_CLI"), - 'icon' => 'shell.png' + 'icon' => Horde_Themes::img('shell.png') ) ); @@ -71,7 +78,7 @@ class Horde_Api extends Horde_Registry_Api $admin['activesync'] = array( 'link' => '%application%/admin/activesync.php', 'name' => _("ActiveSync Devices"), - 'icon' => 'mobile.png' + 'icon' => Horde_Themes::img('mobile.png') ); } diff --git a/horde/lib/Ui/Sidebar.php b/horde/lib/Ui/Sidebar.php deleted file mode 100644 index 2a3c581e9..000000000 --- a/horde/lib/Ui/Sidebar.php +++ /dev/null @@ -1,245 +0,0 @@ - - * @category Horde - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @package Horde - */ -class Horde_Ui_Sidebar -{ - /** - * Generate the sidebar tree object. - * - * @return Horde_Tree The sidebar tree object. - */ - public function getTree() - { - global $conf, $injector, $prefs, $registry, $notification; - - $apps = $cache = $children = $menu = array(); - - $isAdmin = $registry->isAdmin(); - $user = $registry->getAuth(); - foreach ($registry->applications as $app => $params) { - $curr_app = empty($params['app']) - ? $app - : $params['app']; - - if (!isset($cache[$curr_app])) { - /* Check if the current user has permisson to see this - * application, and if the application is active. Headings are - * visible to everyone (but get filtered out later if they - * have no children). Administrators always see all - * applications except those marked 'inactive'. Anyone with - * SHOW permissions can see an application, but READ is needed - * to actually use the application. You can use this - * distinction to show applications to guests that they need - * to log in to use. If you don't want them to see apps they - * can't use, then don't give guests SHOW permissions to - * anything. */ - - /* Don't show applications that aren't installed, even if - * they're configured. - * -OR- - * Don't show blocks of applications that aren't installed. - * -OR- - * Filter out entries that are disabled, hidden or shouldn't - * show up in the menu. */ - if ((isset($params['fileroot']) && - !is_dir($params['fileroot'])) || - (($params['status'] == 'block') && - !is_dir($registry->get('fileroot', $params['app']))) || - (in_array($params['status'], array('hidden', 'inactive', 'notoolbar')))) { - $cache[$curr_app] = false; - } elseif (($params['status'] == 'heading') || - ($isAdmin || - ($registry->hasPermission($curr_app, Horde_Perms::SHOW) && - (($params['status'] == 'active') || - ($params['status'] == 'block'))))) { - $cache[$curr_app] = true; - - // Note that the parent node, if any, has children. - if (isset($params['menu_parent'])) { - $children[$params['menu_parent']] = true; - } - } else { - // Catch anything that fell through, and don't show it. - $cache[$curr_app] = false; - } - } - - if ($cache[$curr_app]) { - $apps[$app] = $params; - } - } - - foreach ($apps as $app => $params) { - // Filter out all headings without children. - if (($params['status'] != 'heading') || !empty($children[$app])) { - $menu[$app] = $params; - } - } - - // Add the administration menu if the user is an admin. - if ($registry->isAdmin()) { - $menu['administration'] = array( - 'name' => _("Administration"), - 'icon' => strval(Horde_Themes::img('administration.png')), - 'status' => 'heading' - ); - - try { - $list = $registry->callByPackage('horde', 'admin_list'); - foreach ($list as $method => $vals) { - $name = Horde::stripAccessKey($vals['name']); - $icon = isset($vals['icon']) - ? Horde_Themes::img($vals['icon']) - : $registry->get('icon'); - - $menu['administration_' . $method] = array( - 'name' => $name, - 'icon' => strval($icon), - 'status' => 'active', - 'menu_parent' => 'administration', - 'url' => Horde::url($registry->applicationWebPath($vals['link'], 'horde')), - ); - } - } catch (Horde_Exception $e) {} - } - - if (Horde_Menu::showService('options') && - ($conf['prefs']['driver'] != '') && - ($conf['prefs']['driver'] != 'none')) { - $menu['options'] = array( - 'name' => _("Options"), - 'icon' => strval(Horde_Themes::img('prefs.png')), - 'status' => 'active' - ); - - /* Get a list of configurable applications. */ - $prefs_apps = array(); - foreach ($registry->applications as $application => $params) { - if (($params['status'] == 'heading') || - ($params['status'] == 'block') || - !file_exists($registry->get('fileroot', $application) . '/config/prefs.php')) { - continue; - } - - /* Check if the current user has permission to see this - * application, and if the application is active. - * Administrators always see all applications. */ - try { - if (($registry->isAdmin() && - ($params['status'] != 'inactive')) || - ($registry->hasPermission($application) && - ($params['status'] == 'active'))) { - $prefs_apps[$application] = _($params['name']); - } - } catch (Horde_Exception $e) { - /* @todo Remove or log instead of notifying when all apps - * have been H4-ified. */ - $notification->push($e); - } - } - - if (!empty($prefs_apps['horde'])) { - $menu['options_' . 'horde'] = array( - 'name' => _("Global Options"), - 'status' => 'active', - 'menu_parent' => 'options', - 'icon' => strval($registry->get('icon', 'horde')), - 'url' => strval(Horde::getServiceLink('options', 'horde')) - ); - unset($prefs_apps['horde']); - } - - asort($prefs_apps); - foreach ($prefs_apps as $app => $name) { - $menu['options_' . $app] = array( - 'name' => $name, - 'status' => 'active', - 'menu_parent' => 'options', - 'icon' => strval($registry->get('icon', $app)), - 'url' => strval(Horde::getServiceLink('options', $app)) - ); - } - } - - if ($registry->getAuth()) { - $menu['logout'] = array( - 'name' => _("Log out"), - 'status' => 'active', - 'icon' => strval(Horde_Themes::img('logout.png')), - 'url' => Horde::getServiceLink('logout', 'horde'), - 'target' => '_parent' - ); - } else { - $menu['login'] = array( - 'name' => _("Log in"), - 'status' => 'active', - 'icon' => strval(Horde_Themes::img('login.png')), - 'url' => Horde::getServiceLink('login', 'horde') - ); - } - - // Set up the tree. - $tree = $injector->getInstance('Horde_Tree')->getTree('horde_sidebar', 'Javascript', array('jsvar' => 'HordeSidebar.tree')); - - foreach ($menu as $app => $params) { - if ($params['status'] == 'block') { - if ($registry->get('status', $params['app']) == 'inactive') { - continue; - } - - try { - $block = Horde_Block_Collection::getBlock($params['app'], $params['blockname']); - } catch (Horde_Exception $e) { - Horde::logMessage($e, 'ERR'); - continue; - } - - try { - $block->buildTree($tree, 0, isset($params['menu_parent']) ? $params['menu_parent'] : null); - } catch (Horde_Exception $e) { - Horde::logMessage($e, 'ERR'); - continue; - } - } else { - // Need to run the name through gettext since the user's - // locale may not have been loaded when registry.php was - // parsed. - $name = _($params['name']); - - // Headings have no webroot; they're just containers for other - // menu items. - if (isset($params['url'])) { - $url = $params['url']; - } elseif (($params['status'] == 'heading') || - !isset($params['webroot'])) { - $url = null; - } else { - $url = Horde::url($params['webroot'] . '/' . (isset($params['initial_page']) ? $params['initial_page'] : '')); - } - - $node_params = array( - 'icon' => strval((isset($params['icon']) ? $params['icon'] : $registry->get('icon', $app))), - 'target' => isset($params['target']) ? $params['target'] : null, - 'url' => $url - ); - - $tree->addNode($app, empty($params['menu_parent']) ? null : $params['menu_parent'], $name, 0, false, $node_params); - } - } - - return $tree; - } - -} diff --git a/horde/services/portal/edit.php b/horde/services/portal/edit.php index d135d6052..95c6e5299 100644 --- a/horde/services/portal/edit.php +++ b/horde/services/portal/edit.php @@ -14,7 +14,7 @@ require_once dirname(__FILE__) . '/../../lib/Application.php'; Horde_Registry::appInit('horde'); // Instantiate the blocks objects. -$blocks = Horde_Block_Collection::singleton('portal'); +$blocks = Horde_Block_Collection::singleton(); $layout_pref = @unserialize($prefs->getValue('portal_layout')); if (!is_array($layout_pref)) { $layout_pref = array(); diff --git a/horde/services/sidebar.php b/horde/services/sidebar.php index 0fb0489ca..5cbdbc9a3 100644 --- a/horde/services/sidebar.php +++ b/horde/services/sidebar.php @@ -19,13 +19,12 @@ Horde_Registry::appInit('horde', array('authentication' => 'none')); /* We may not be in global scope since this file can be included from other * scripts. */ -global $conf, $language, $prefs, $registry; +global $conf, $injector, $language, $prefs, $registry; if (!Horde_Util::getFormData('ajaxui') && ($conf['menu']['always'] || ($registry->getAuth() && $prefs->getValue('show_sidebar')))) { - $sidebar = new Horde_Ui_Sidebar(); - $tree = $sidebar->getTree(); + $tree = $injector->getInstance('Horde_Core_Sidebar')->getTree(); Horde::addScriptFile('prototype.js', 'horde'); Horde::addScriptFile('sidebar.js', 'horde'); diff --git a/horde/templates/admin/menu.inc b/horde/templates/admin/menu.inc index 8fbaf714b..fecaf874d 100644 --- a/horde/templates/admin/menu.inc +++ b/horde/templates/admin/menu.inc @@ -4,10 +4,7 @@ $menu = new Horde_Menu(Horde_Menu::MASK_NONE); try { foreach ($registry->callByPackage('horde', 'admin_list') as $val) { - $img = isset($val['icon']) - ? Horde_Themes::img($val['icon']) - : $registry->get('icon'); - $menu->add(Horde::url($registry->applicationWebPath($val['link'])), $val['name'], $img, ''); + $menu->add(Horde::url($registry->applicationWebPath($val['link'])), $val['name'], $val['icon'], ''); } } catch (Horde_Exception $e) {} diff --git a/imp/lib/Application.php b/imp/lib/Application.php index c514422ff..275489cb5 100644 --- a/imp/lib/Application.php +++ b/imp/lib/Application.php @@ -458,6 +458,95 @@ class IMP_Application extends Horde_Registry_Application return $GLOBALS['injector']->getInstance('IMP_Prefs_Ui')->prefsMenu($ui); } + /* Sidebar method. */ + + /** + * Add node(s) to the sidebar tree. + * + * @param Horde_Tree_Base $tree Tree object. + * @param string $parent The current parent element. + * @param array $params Additional parameters. + * + * @throws Horde_Exception + */ + public function sidebarCreate(Horde_Tree_Base $tree, $parent = null, + array $params = array()) + { + global $injector, $prefs, $registry; + + /* Run filters now */ + if ($prefs->getValue('filter_on_display')) { + $injector->getInstance('IMP_Filter')->filter('INBOX'); + } + + $tree->addNode( + strval($parent) . 'compose', + $parent, + _("New Message"), + 0, + false, + array( + 'icon' => Horde_Themes::img('compose.png'), + 'url' => IMP::composeLink() + ) + ); + + /* Add link to the search page. */ + $tree->addNode( + strval($parent) . 'search', + $parent, + _("Search"), + 0, + false, + array( + 'icon' => Horde_Themes::img('search.png'), + 'url' => Horde::applicationUrl('search.php') + ) + ); + + if ($_SESSION['imp']['protocol'] == 'pop') { + return; + } + + $name_url = Horde::applicationUrl('mailbox.php'); + + /* Initialize the IMP_Tree object. */ + $imaptree = $injector->getInstance('IMP_Imap_Tree'); + $imaptree->setIteratorFilter(IMP_Imap_Tree::FLIST_VFOLDER); + $imaptree->createTree($tree, array( + 'parent' => $parent, + 'poll_info' => true + )); + + /* We want to rewrite the parent node of the INBOX to include new mail + * notification. */ + if (!($url = $registry->get('url', $parent))) { + $url = (($registry->get('status', $parent) == 'heading') || !$registry->get('webroot')) + ? null + : $registry->getInitialPage($parent); + } + + $node_params = array( + 'icon' => $registry->get('icon', $parent), + 'url' => $url + ); + $name = $registry->get('name', $parent); + + if ($imaptree->unseen) { + $node_params['icon'] = Horde_Themes::img('newmail.png'); + $name = sprintf('%s (%s)', $name, $imaptree->unseen); + } + + $tree->addNode( + strval($parent), + $registry->get('menu_parent', $parent), + $name, + 0, + $imaptree->isOpen($parent), + $node_params + ); + } + /* Language change callback. */ /** diff --git a/imp/lib/Block/tree_folders.php b/imp/lib/Block/tree_folders.php deleted file mode 100644 index 78744dfcf..000000000 --- a/imp/lib/Block/tree_folders.php +++ /dev/null @@ -1,101 +0,0 @@ - - * @category Horde - * @license http://www.fsf.org/copyleft/gpl.html GPL - * @package IMP - */ - -$block_name = _("Menu Folder List"); -$block_type = 'tree'; - -class Horde_Block_imp_tree_folders extends Horde_Block -{ - protected $_app = 'imp'; - - protected function _buildTree($tree, $indent = 0, $parent = '') - { - global $injector, $prefs, $registry; - - /* Run filters now */ - if ($prefs->getValue('filter_on_display')) { - $injector->getInstance('IMP_Filter')->filter('INBOX'); - } - - $tree->addNode( - $parent . 'compose', - $parent, - _("New Message"), - $indent, - false, - array( - 'icon' => Horde_Themes::img('compose.png'), - 'url' => IMP::composeLink() - ) - ); - - /* Add link to the search page. */ - $tree->addNode( - $parent . 'search', - $parent, - _("Search"), - $indent, - false, - array( - 'icon' => Horde_Themes::img('search.png'), - 'url' => Horde::applicationUrl('search.php') - ) - ); - - if ($_SESSION['imp']['protocol'] == 'pop') { - return; - } - - $name_url = Horde::applicationUrl('mailbox.php'); - - /* Initialize the IMP_Tree object. */ - $imaptree = $injector->getInstance('IMP_Imap_Tree'); - $imaptree->setIteratorFilter(IMP_Imap_Tree::FLIST_VFOLDER); - $imaptree->createTree($tree, array( - 'indent' => $indent, - 'parent' => $parent, - 'poll_info' => true - )); - - /* We want to rewrite the parent node of the INBOX to include new mail - * notification. */ - if (!($url = $registry->get('url', $parent))) { - $url = (($registry->get('status', $parent) == 'heading') || !$registry->get('webroot')) - ? null - : $registry->getInitialPage($parent); - } - - $node_params = array( - 'icon' => $registry->get('icon', $parent), - 'url' => $url - ); - $name = $registry->get('name', $parent); - - if ($imaptree->unseen) { - $node_params['icon'] = Horde_Themes::img('newmail.png'); - $name = sprintf('%s (%s)', $name, $imaptree->unseen); - } - - $tree->addNode( - $parent, - $registry->get('menu_parent', $parent), - $name, - $indent - 1, - $imaptree->isOpen($parent), - $node_params - ); - } - -} diff --git a/imp/lib/Imap/Tree.php b/imp/lib/Imap/Tree.php index 959cb112f..5ac76e58d 100644 --- a/imp/lib/Imap/Tree.php +++ b/imp/lib/Imap/Tree.php @@ -1467,8 +1467,6 @@ class IMP_Imap_Tree implements ArrayAccess, Iterator * DEFAULT: false * 'editvfolder' - (boolean) Display vfolder edit links? * DEFAULT: false - * 'indent' - (integer) The base level to add nodes to. - * DEFAULT: 0 * 'parent' - (string) The parent object of the current level. * DEFAULT: null (add to base level) * 'poll_info' - (boolean) Include poll information? @@ -1490,7 +1488,6 @@ class IMP_Imap_Tree implements ArrayAccess, Iterator if ($name instanceof Horde_Tree_Base) { $tree = $name; - $indent = $opts['indent']; $parent = $opts['parent']; } else { $tree = $GLOBALS['injector']->getInstance('Horde_Tree')->getTree($name, $opts['render_type'], array( @@ -1499,7 +1496,6 @@ class IMP_Imap_Tree implements ArrayAccess, Iterator 'lines_base' => true, 'nosession' => true )); - $indent = 0; $parent = null; } @@ -1575,7 +1571,7 @@ class IMP_Imap_Tree implements ArrayAccess, Iterator strval($parent) . $val->value, ($val->level) ? strval($parent) . $val->parent : $parent, $label, - $indent + $val->level, + $val->level, $is_open, $params, $after, diff --git a/jonah/lib/Application.php b/jonah/lib/Application.php index 4e6a2dbc2..5e57a60f2 100644 --- a/jonah/lib/Application.php +++ b/jonah/lib/Application.php @@ -93,4 +93,46 @@ class Jonah_Application extends Horde_Registry_Application return Jonah::getMenu(); } + /* Sidebar method. */ + + /** + * Add node(s) to the sidebar tree. + * + * @param Horde_Tree_Base $tree Tree object. + * @param string $parent The current parent element. + * @param array $params Additional parameters. + * + * @throws Horde_Exception + */ + public function sidebarCreate(Horde_Tree_Base $tree, $parent = null, + array $params = array()) + { + if (!Jonah::checkPermissions('jonah:news', Horde_Perms::EDIT) || + !in_array('internal', $GLOBALS['conf']['news']['enable'])) { + return; + } + + $url = Horde::applicationUrl('stories/'); + $news = Jonah_News::factory(); + $channels = $news->getChannels('internal'); + if ($channels instanceof PEAR_Error) { + return; + } + $channels = Jonah::checkPermissions('channels', Horde_Perms::SHOW, $channels); + + foreach ($channels as $channel) { + $tree->addNode( + $parent . $channel['channel_id'], + $parent, + $channel['channel_name'], + 1, + false, + array( + 'icon' => Horde_Themes::img('editstory.png'), + 'url' => $url->add('channel_id', $channel['channel_id']) + ) + ); + } + } + } diff --git a/jonah/lib/Block/tree_menu.php b/jonah/lib/Block/tree_menu.php deleted file mode 100644 index 22a4672a9..000000000 --- a/jonah/lib/Block/tree_menu.php +++ /dev/null @@ -1,43 +0,0 @@ -getChannels('internal'); - if (is_a($channels, 'PEAR_Error')) { - return; - } - $channels = Jonah::checkPermissions('channels', Horde_Perms::SHOW, $channels); - - foreach ($channels as $channel) { - $tree->addNode( - $parent . $channel['channel_id'], - $parent, - $channel['channel_name'], - $indent + 1, - false, - array( - 'icon' => Horde_Themes::img('editstory.png'), - 'url' => $url->add('channel_id', $channel['channel_id']) - ) - ); - } - } - -} diff --git a/kronolith/lib/Application.php b/kronolith/lib/Application.php index aac36b8eb..e3dd66af7 100644 --- a/kronolith/lib/Application.php +++ b/kronolith/lib/Application.php @@ -454,4 +454,104 @@ class Kronolith_Application extends Horde_Registry_Application } } + /* Sidebar method. */ + + /** + * Add node(s) to the sidebar tree. + * + * @param Horde_Tree_Base $tree Tree object. + * @param string $parent The current parent element. + * @param array $params Additional parameters. + * + * @throws Horde_Exception + */ + public function sidebarCreate(Horde_Tree_Base $tree, $parent = null, + array $params = array()) + { + switch ($params['id']) { + case 'alarms': + try { + $alarms = Kronolith::listAlarms(new Horde_Date($_SERVER['REQUEST_TIME']), $GLOBALS['display_calendars'], true); + } catch (Kronolith_Exception $e) { + return; + } + + $alarmCount = 0; + $horde_alarm = $GLOBALS['injector']->getInstance('Horde_Alarm'); + + foreach ($alarms as $calId => $calAlarms) { + foreach ($calAlarms as $event) { + if ($horde_alarm->isSnoozed($event->uid, $GLOBALS['registry']->getAuth())) { + continue; + } + ++$alarmCount; + $tree->addNode( + $parent . $calId . $event->id, + $parent, + htmlspecialchars($event->getTitle(), ENT_COMPAT, $GLOBALS['registry']->getCharset()), + 1, + false, + array( + 'icon' => Horde_Themes::img('alarm.png'), + 'url' => $event->getViewUrl() + ) + ); + } + } + + if ($GLOBALS['registry']->get('url', $parent)) { + $purl = $GLOBALS['registry']->get('url', $parent); + } elseif ($GLOBALS['registry']->get('status', $parent) == 'heading' || + !$GLOBALS['registry']->get('webroot')) { + $purl = null; + } else { + $purl = Horde::url($GLOBALS['registry']->getInitialPage($parent)); + } + + $pnode_name = $GLOBALS['registry']->get('name', $parent); + if ($alarmCount) { + $pnode_name = '' . $pnode_name . ''; + } + + $tree->addNode( + $parent, + $GLOBALS['registry']->get('menu_parent', $parent), + $pnode_name, + 0, + false, + array( + 'icon' => $GLOBALS['registry']->get('icon', $parent), + 'url' => $purl, + ) + ); + break; + + case 'menu': + $menus = array( + array('new', _("New Event"), 'new.png', Horde::applicationUrl('new.php')), + array('day', _("Day"), 'dayview.png', Horde::applicationUrl('day.php')), + array('work', _("Work Week"), 'workweekview.png', Horde::applicationUrl('workweek.php')), + array('week', _("Week"), 'weekview.png', Horde::applicationUrl('week.php')), + array('month', _("Month"), 'monthview.png', Horde::applicationUrl('month.php')), + array('year', _("Year"), 'yearview.png', Horde::applicationUrl('year.php')), + array('search', _("Search"), 'search.png', Horde::applicationUrl('search.php')) + ); + + foreach ($menus as $menu) { + $tree->addNode( + $parent . $menu[0], + $parent, + $menu[1], + 1, + false, + array( + 'icon' => Horde_Themes::img($menu[2]), + 'url' => $menu[3] + ) + ); + } + break; + } + } + } diff --git a/kronolith/lib/Block/tree_alarms.php b/kronolith/lib/Block/tree_alarms.php deleted file mode 100644 index 42b344cc0..000000000 --- a/kronolith/lib/Block/tree_alarms.php +++ /dev/null @@ -1,72 +0,0 @@ -getInstance('Horde_Alarm'); - - $alarmCount = 0; - try { - $alarms = Kronolith::listAlarms(new Horde_Date($_SERVER['REQUEST_TIME']), - $GLOBALS['display_calendars'], - true); - } catch (Exception $e) { - return; - } - foreach ($alarms as $calId => $calAlarms) { - foreach ($calAlarms as $event) { - if ($horde_alarm->isSnoozed($event->uid, $GLOBALS['registry']->getAuth())) { - continue; - } - $alarmCount++; - $tree->addNode( - $parent . $calId . $event->id, - $parent, - htmlspecialchars($event->getTitle(), ENT_COMPAT, $GLOBALS['registry']->getCharset()), - $indent + 1, - false, - array( - 'icon' => Horde_Themes::img('alarm.png'), - 'url' => $event->getViewUrl() - ) - ); - } - } - - if ($GLOBALS['registry']->get('url', $parent)) { - $purl = $GLOBALS['registry']->get('url', $parent); - } elseif ($GLOBALS['registry']->get('status', $parent) == 'heading' || - !$GLOBALS['registry']->get('webroot')) { - $purl = null; - } else { - $purl = Horde::url($GLOBALS['registry']->getInitialPage($parent)); - } - - $pnode_name = $GLOBALS['registry']->get('name', $parent); - if ($alarmCount) { - $pnode_name = '' . $pnode_name . ''; - } - - $tree->addNode( - $parent, - $GLOBALS['registry']->get('menu_parent', $parent), - $pnode_name, - $indent, - false, - array( - 'icon' => $GLOBALS['registry']->get('icon', $parent), - 'url' => $purl, - ) - ); - } - -} diff --git a/kronolith/lib/Block/tree_menu.php b/kronolith/lib/Block/tree_menu.php deleted file mode 100644 index 2319eed33..000000000 --- a/kronolith/lib/Block/tree_menu.php +++ /dev/null @@ -1,40 +0,0 @@ -addNode( - $parent . $menu[0], - $parent, - $menu[1], - $indent + 1, - false, - array( - 'icon' => Horde_Themes::img($menu[2]), - 'url' => $menu[3] - ) - ); - } - } - -} diff --git a/mnemo/lib/Application.php b/mnemo/lib/Application.php index a45754cb7..7bf71dcdc 100644 --- a/mnemo/lib/Application.php +++ b/mnemo/lib/Application.php @@ -117,4 +117,66 @@ class Mnemo_Application extends Horde_Registry_Application return Mnemo::getMenu(); } + /* Sidebar method. */ + + /** + * Add node(s) to the sidebar tree. + * + * @param Horde_Tree_Base $tree Tree object. + * @param string $parent The current parent element. + * @param array $params Additional parameters. + * + * @throws Horde_Exception + */ + public function sidebarCreate(Horde_Tree_Base $tree, $parent = null, + array $params = array()) + { + $add = Horde::applicationUrl('memo.php')->add('actionID', 'add_memo'); + + $tree->addNode( + $parent . '__new', + $parent, + _("New Note"), + 1, + false, + array( + 'icon' => Horde_Themes::img('add.png'), + 'url' => $add + ) + ); + + foreach (Mnemo::listNotepads() as $name => $notepad) { + if ($notepad->get('owner') != $GLOBALS['registry']->getAuth() && + !empty($GLOBALS['conf']['share']['hidden']) && + !in_array($notepad->getName(), $GLOBALS['display_notepads'])) { + + continue; + } + + $tree->addNode( + $parent . $name . '__new', + $parent . '__new', + sprintf(_("in %s"), $notepad->get('name')), + 2, + false, + array( + 'icon' => Horde_Themes::img('add.png'), + 'url' => $add->copy()->add('memolist', $name) + ) + ); + } + + $tree->addNode( + $parent . '__search', + $parent, + _("Search"), + 1, + false, + array( + 'icon' => Horde_Themes::img('search.png'), + 'url' => Horde::applicationUrl('search.php') + ) + ); + } + } diff --git a/mnemo/lib/Block/tree_menu.php b/mnemo/lib/Block/tree_menu.php deleted file mode 100644 index 28b470f03..000000000 --- a/mnemo/lib/Block/tree_menu.php +++ /dev/null @@ -1,64 +0,0 @@ -add('actionID', 'add_memo'); - - $tree->addNode( - $parent . '__new', - $parent, - _("New Note"), - $indent + 1, - false, - array( - 'icon' => Horde_Themes::img('add.png'), - 'url' => $add - ) - ); - - foreach (Mnemo::listNotepads() as $name => $notepad) { - if ($notepad->get('owner') != $GLOBALS['registry']->getAuth() && - !empty($GLOBALS['conf']['share']['hidden']) && - !in_array($notepad->getName(), $GLOBALS['display_notepads'])) { - - continue; - } - - $tree->addNode( - $parent . $name . '__new', - $parent . '__new', - sprintf(_("in %s"), $notepad->get('name')), - $indent + 2, - false, - array( - 'icon' => Horde_Themes::img('add.png'), - 'url' => $add->copy()->add('memolist', $name) - ) - ); - } - - $tree->addNode( - $parent . '__search', - $parent, - _("Search"), - $indent + 1, - false, - array( - 'icon' => Horde_Themes::img('search.png'), - 'url' => Horde::applicationUrl('search.php') - ) - ); - } - -} diff --git a/nag/lib/Application.php b/nag/lib/Application.php index 98235382b..8f3bdfa47 100644 --- a/nag/lib/Application.php +++ b/nag/lib/Application.php @@ -281,4 +281,138 @@ class Nag_Application extends Horde_Registry_Application } } + /* Sidebar method. */ + + /** + * Add node(s) to the sidebar tree. + * + * @param Horde_Tree_Base $tree Tree object. + * @param string $parent The current parent element. + * @param array $params Additional parameters. + * + * @throws Horde_Exception + */ + public function sidebarCreate(Horde_Tree_Base $tree, $parent = null, + array $params = array()) + { + global $registry; + + switch ($params['id']) { + case 'alarms': + // Get any alarms in the next hour. + $now = time(); + $alarms = Nag::listAlarms($now); + if ($alarms instanceof PEAR_Error) { + return; + } + + $alarmCount = 0; + $horde_alarm = $GLOBALS['injector']->getInstance('Horde_Alarm'); + + foreach ($alarms as $taskId => $task) { + if ($horde_alarm->isSnoozed($task->uid, $registry->getAuth())) { + continue; + } + ++$alarmCount; + + $differential = $task->due - $now; + $title = ($differential >= 60) + ? sprintf(_("%s is due in %s"), $task->name, Nag::secondsToString($differential)) + : sprintf(_("%s is due now."), $task->name); + $url = Horde::applicationUrl('view.php')->add(array( + 'task' => $task->id, + 'tasklist' => $task->tasklist + )); + + $tree->addNode( + $parent . $taskId, + $parent, + $task->name, + 1, + false, + array( + 'icon' => Horde_Themes::img('alarm.png'), + 'title' => $title, + 'url' => $url + ) + ); + } + + if ($registry->get('url', $parent)) { + $purl = $registry->get('url', $parent); + } elseif ($registry->get('status', $parent) == 'heading' || + !$registry->get('webroot')) { + $purl = null; + } else { + $purl = Horde::url($registry->getInitialPage($parent)); + } + + $pnode_name = $registry->get('name', $parent); + if ($alarmCount) { + $pnode_name = '' . $pnode_name . ''; + } + + $tree->addNode( + $parent, + $registry->get('menu_parent', $parent), + $pnode_name, + 0, + false, + array( + 'icon' => strval($registry->get('icon', $parent)), + 'url' => $purl + ) + ); + break; + + case 'menu': + $add = Horde::applicationUrl('task.php')->add('actionID', 'add_task'); + + $tree->addNode( + $parent . '__new', + $parent, + _("New Task"), + 1, + false, + array( + 'icon' => Horde_Themes::img('add.png'), + 'url' => $add + ) + ); + + foreach (Nag::listTasklists() as $name => $tasklist) { + if ($tasklist->get('owner') != $registry->getAuth() && + !empty($GLOBALS['conf']['share']['hidden']) && + !in_array($tasklist->getName(), $GLOBALS['display_tasklists'])) { + continue; + } + + $tree->addNode( + $parent . $name . '__new', + $parent . '__new', + sprintf(_("in %s"), $tasklist->get('name')), + 2, + false, + array( + 'icon' => Horde_Themes::img('add.png'), + 'url' => $add->copy()->add('tasklist_id', $name) + ) + ); + } + + $tree->addNode( + $parent . '__search', + $parent, + _("Search"), + 1, + false, + array( + 'icon' => Horde_Themes::img('search.png'), + 'url' => Horde::applicationUrl('search.php') + ) + ); + break; + } + } + } diff --git a/nag/lib/Block/tree_alarms.php b/nag/lib/Block/tree_alarms.php deleted file mode 100644 index 239a64816..000000000 --- a/nag/lib/Block/tree_alarms.php +++ /dev/null @@ -1,79 +0,0 @@ -getInstance('Horde_Alarm'); - - // Get any alarms in the next hour. - $now = time(); - $alarms = Nag::listAlarms($now); - if (is_a($alarms, 'PEAR_Error')) { - return; - } - - $alarmCount = 0; - foreach ($alarms as $taskId => $task) { - if ($horde_alarm->isSnoozed($task->uid, $GLOBALS['registry']->getAuth())) { - continue; - } - $alarmCount++; - $differential = $task->due - $now; - if ($differential >= 60) { - $title = sprintf(_("%s is due in %s"), $task->name, Nag::secondsToString($differential)); - } else { - $title = sprintf(_("%s is due now."), $task->name); - } - - $url = Horde_Util::addParameter(Horde::applicationUrl('view.php'), - array('task' => $task->id, - 'tasklist' => $task->tasklist)); - $tree->addNode( - $parent . $taskId, - $parent, - $task->name, - $indent + 1, - false, - array( - 'icon' => Horde_Themes::img('alarm.png'), - 'title' => $title, - 'url' => $url - ) - ); - } - - if ($GLOBALS['registry']->get('url', $parent)) { - $purl = $GLOBALS['registry']->get('url', $parent); - } elseif ($GLOBALS['registry']->get('status', $parent) == 'heading' || - !$GLOBALS['registry']->get('webroot')) { - $purl = null; - } else { - $purl = Horde::url($GLOBALS['registry']->getInitialPage($parent)); - } - $pnode_params = array( - 'url' => $purl, - 'icon' => (string)$GLOBALS['registry']->get('icon', $parent) - ); - $pnode_name = $GLOBALS['registry']->get('name', $parent); - if ($alarmCount) { - $pnode_name = '' . $pnode_name . ''; - } - - $tree->addNode($parent, - $GLOBALS['registry']->get('menu_parent', $parent), - $pnode_name, - $indent, - false, - $pnode_params); - } - -} diff --git a/nag/lib/Block/tree_menu.php b/nag/lib/Block/tree_menu.php deleted file mode 100644 index 24840bb02..000000000 --- a/nag/lib/Block/tree_menu.php +++ /dev/null @@ -1,61 +0,0 @@ -add('actionID', 'add_task'); - - $tree->addNode( - $parent . '__new', - $parent, - _("New Task"), - $indent + 1, - false, - array( - 'icon' => Horde_Themes::img('add.png'), - 'url' => $add - ) - ); - - foreach (Nag::listTasklists() as $name => $tasklist) { - if ($tasklist->get('owner') != $GLOBALS['registry']->getAuth() && - !empty($GLOBALS['conf']['share']['hidden']) && - !in_array($tasklist->getName(), $GLOBALS['display_tasklists'])) { - continue; - } - $tree->addNode( - $parent . $name . '__new', - $parent . '__new', - sprintf(_("in %s"), $tasklist->get('name')), - $indent + 2, - false, - array( - 'icon' => Horde_Themes::img('add.png'), - 'url' => $add->copy()->add('tasklist_id', $name) - ) - ); - } - - $tree->addNode( - $parent . '__search', - $parent, - _("Search"), - $indent + 1, - false, - array( - 'icon' => Horde_Themes::img('search.png'), - 'url' => Horde::applicationUrl('search.php') - ) - ); - } - -} diff --git a/news/content_edit.php b/news/content_edit.php index 5e9b049c9..a1a8f6773 100644 --- a/news/content_edit.php +++ b/news/content_edit.php @@ -14,7 +14,7 @@ require_once dirname(__FILE__) . '/lib/base.php'; // Instantiate the blocks objects. -$blocks = &Horde_Block_Collection::singleton('news_layout', array('news')); +$blocks = &Horde_Block_Collection::singleton(array('news')); $layout = &Horde_Block_Layout_Manager::singleton('news_layout', $blocks, unserialize($prefs->getValue('news_layout'))); // Handle requested actions. diff --git a/trean/lib/Application.php b/trean/lib/Application.php index 12129bae8..049785d0f 100644 --- a/trean/lib/Application.php +++ b/trean/lib/Application.php @@ -88,4 +88,64 @@ class Trean_Application extends Horde_Registry_Application { return Trean::getMenu(); } + + /* Sidebar method. */ + + /** + * Add node(s) to the sidebar tree. + * + * @param Horde_Tree_Base $tree Tree object. + * @param string $parent The current parent element. + * @param array $params Additional parameters. + * + * @throws Horde_Exception + */ + public function sidebarCreate(Horde_Tree_Base $tree, $parent = null, + array $params = array()) + { + $tree->addNode( + $parent . '__new', + $parent, + _("Add"), + 1, + false, + array( + 'icon' => Horde_Themes::img('add.png'), + 'url' => Horde::applicationUrl('add.php') + ) + ); + + $tree->addNode( + $parent . '__search', + $parent, + _("Search"), + 1, + false, + array( + 'icon' => Horde_Themes::img('search.png'), + 'url' => Horde::applicationUrl('search.php') + ) + ); + + $folders = Trean::listFolders(); + if (!($folders instanceof PEAR_Error)) { + $browse = Horde::applicationUrl('browse.php'); + + foreach ($folders as $folder) { + $parent_id = $folder->getParent(); + $tree->addNode( + $parent . $folder->getId(), + $parent . $parent_id, + $folder->get('name'), + substr_count($folder->getName(), ':') + 1, + false, + array( + 'icon' => Horde_Themes::img('tree/folder.png'), + 'url' => $browse->copy()->add('f', $folder->getId()) + ) + ); + } + } + } + } diff --git a/trean/lib/Block/tree_menu.php b/trean/lib/Block/tree_menu.php deleted file mode 100644 index 11e2dfbd1..000000000 --- a/trean/lib/Block/tree_menu.php +++ /dev/null @@ -1,59 +0,0 @@ -addNode( - $parent . '__new', - $parent, - _("Add"), - $indent + 1, - false, - array( - 'icon' => Horde_Themes::img('add.png'), - 'url' => Horde::applicationUrl('add.php') - ) - ); - - $tree->addNode( - $parent . '__search', - $parent, - _("Search"), - $indent + 1, - false, - array( - 'icon' => Horde_Themes::img('search.png'), - 'url' => Horde::applicationUrl('search.php') - ) - ); - - $folders = Trean::listFolders(); - if ($folders instanceof PEAR_Error) { - $browse = Horde::applicationUrl('browse.php'); - - foreach ($folders as $folder) { - $parent_id = $folder->getParent(); - $tree->addNode( - $parent . $folder->getId(), - $parent . $parent_id, - $folder->get('name'), - $indent + substr_count($folder->getName(), ':') + 1, - false, - array( - 'icon' => Horde_Themes::img('tree/folder.png'), - 'url' => $browse->copy()->add('f', $folder->getId()) - ) - ); - } - } - } - -} diff --git a/turba/lib/Application.php b/turba/lib/Application.php index efa52a441..73b3bd319 100644 --- a/turba/lib/Application.php +++ b/turba/lib/Application.php @@ -455,4 +455,80 @@ class Turba_Application extends Horde_Registry_Application } } + /* Sidebar method. */ + + /** + * Add node(s) to the sidebar tree. + * + * @param Horde_Tree_Base $tree Tree object. + * @param string $parent The current parent element. + * @param array $params Additional parameters. + * + * @throws Horde_Exception + */ + public function sidebarCreate(Horde_Tree_Base $tree, $parent = null, + array $params = array()) + { + $add = Horde::applicationUrl('add.php'); + $browse = Horde::applicationUrl('browse.php'); + + if ($GLOBALS['addSources']) { + $newimg = Horde_Themes::img('menu/new.png'); + + $tree->addNode( + $parent . '__new', + $parent, + _("New Contact"), + 1, + false, + array( + 'icon' => $newimg, + 'url' => $add + ) + ); + + foreach ($GLOBALS['addSources'] as $addressbook => $config) { + $tree->addNode( + $parent . $addressbook . '__new', + $parent . '__new', + sprintf(_("in %s"), $config['title']), + 2, + false, + array( + 'icon' => $newimg, + 'url' => $add->copy()->add('source', $addressbook) + ) + ); + } + } + + foreach (Turba::getAddressBooks() as $addressbook => $config) { + if (!empty($config['browse'])) { + $tree->addNode( + $parent . $addressbook, + $parent, + $config['title'], + 1, + false, + array( + 'icon' => Horde_Themes::img('menu/browse.png'), + 'url' => $browse->copy()->add('source', $addressbook) + ) + ); + } + } + + $tree->addNode( + $parent . '__search', + $parent, + _("Search"), + 1, + false, + array( + 'icon' => Horde_Themes::img('search.png'), + 'url' => Horde::applicationUrl('search.php') + ) + ); + } + } diff --git a/turba/lib/Block/tree_menu.php b/turba/lib/Block/tree_menu.php deleted file mode 100644 index 105408428..000000000 --- a/turba/lib/Block/tree_menu.php +++ /dev/null @@ -1,77 +0,0 @@ -addNode( - $parent . '__new', - $parent, - _("New Contact"), - $indent + 1, - false, - array( - 'icon' => $newimg, - 'url' => $add - ) - ); - - foreach ($GLOBALS['addSources'] as $addressbook => $config) { - $tree->addNode( - $parent . $addressbook . '__new', - $parent . '__new', - sprintf(_("in %s"), $config['title']), - $indent + 2, - false, - array( - 'icon' => $newimg, - 'url' => $add->copy()->add('source', $addressbook) - ) - ); - } - } - - foreach (Turba::getAddressBooks() as $addressbook => $config) { - if (!empty($config['browse'])) { - $tree->addNode( - $parent . $addressbook, - $parent, - $config['title'], - $indent + 1, - false, - array( - 'icon' => Horde_Themes::img('menu/browse.png'), - 'url' => $browse->copy()->add('source', $addressbook) - ) - ); - } - } - - $tree->addNode( - $parent . '__search', - $parent, - _("Search"), - $indent + 1, - false, - array( - 'icon' => Horde_Themes::img('search.png'), - 'url' => Horde::applicationUrl('search.php') - ) - ); - } - -} diff --git a/whups/lib/Application.php b/whups/lib/Application.php index dda5efb16..ceb8d49f6 100644 --- a/whups/lib/Application.php +++ b/whups/lib/Application.php @@ -192,4 +192,43 @@ class Whups_Application extends Horde_Registry_Application return $updated; } + /* Sidebar method. */ + + /** + * Add node(s) to the sidebar tree. + * + * @param Horde_Tree_Base $tree Tree object. + * @param string $parent The current parent element. + * @param array $params Additional parameters. + * + * @throws Horde_Exception + */ + public function sidebarCreate(Horde_Tree_Base $tree, $parent = null, + array $params = array()) + { + $tree->addNode( + $parent . '__new', + $parent, + _("New Ticket"), + 1, + false, + array( + 'icon' => Horde_Themes::img('create.png'), + 'url' => Horde::applicationUrl('ticket/create.php') + ) + ); + + $tree->addNode( + $parent . '__search', + $parent, + _("Search"), + 1, + false, + array( + 'icon' => Horde_Themes::img('search.png'), + 'url' => Horde::applicationUrl('search.php') + ) + ); + } + } diff --git a/whups/lib/Block/tree_menu.php b/whups/lib/Block/tree_menu.php deleted file mode 100644 index 49bbccc74..000000000 --- a/whups/lib/Block/tree_menu.php +++ /dev/null @@ -1,40 +0,0 @@ -addNode( - $parent . '__new', - $parent, - _("New Ticket"), - $indent + 1, - false, - array( - 'icon' => Horde_Themes::img('create.png'), - 'url' => Horde::applicationUrl('ticket/create.php') - ) - ); - - $tree->addNode( - $parent . '__search', - $parent, - _("Search"), - $indent + 1, - false, - array( - 'icon' => Horde_Themes::img('search.png'), - 'url' => Horde::applicationUrl('search.php') - ) - ); - } - -} diff --git a/whups/mybugs_edit.php b/whups/mybugs_edit.php index 9b182c35f..a9f0ee53c 100644 --- a/whups/mybugs_edit.php +++ b/whups/mybugs_edit.php @@ -14,7 +14,7 @@ require_once dirname(__FILE__) . '/lib/Application.php'; Horde_Registry::appInit('whups'); // Instantiate the blocks objects. -$blocks = Horde_Block_Collection::singleton('mybugs', array('whups')); +$blocks = Horde_Block_Collection::singleton(array('whups')); $layout = Horde_Block_Layout_Manager::singleton('mybugs', $blocks, @unserialize($prefs->getValue('mybugs_layout'))); // Handle requested actions.